text
stringlengths 0
3.34M
|
---|
ivmodelFormula <- function(formula,data,subset,
beta0=0,alpha=0.05,k=c(0,1),
heteroSE = FALSE, clusterID = NULL,
deltarange=NULL, na.action = na.omit) {
if(!inherits(formula,"formula")) {
stop("method is only for formula objects!")
}
# code gratefully stolen from ivreg() (package AER).
if (missing(data))
data <- environment(formula)
mf = match.call()
m <- match(c("formula", "data", "subset", "na.action"), names(mf), 0)
mf <- mf[c(1, m)]
mf$drop.unused.levels <- TRUE
formula <- as.Formula(formula)
stopifnot(length(formula)[1] == 1L, length(formula)[2] %in%
1:2)
has_dot <- function(formula) inherits(try(terms(formula),silent = TRUE), "try-error")
if (has_dot(formula)) {
f1 <- formula(formula, rhs = 1)
f2 <- formula(formula, lhs = 0, rhs = 2)
if (!has_dot(f1) & has_dot(f2)) {
formula <- as.Formula(f1, update(formula(formula, lhs = 0, rhs = 1), f2))
}
}
mf$formula <- formula
mf[[1]] <- as.name("model.frame")
mf <- eval(mf, parent.frame())
Y <- model.response(mf, "numeric"); Y = matrix(as.numeric(Y),length(Y),1)
mt <- terms(formula, data = data)
mtX <- terms(formula, data = data, rhs = 1)
X <- model.matrix(mtX, mf)
mtZ <- delete.response(terms(formula, data = data, rhs = 2))
Z <- model.matrix(mtZ, mf)
if("(Intercept)" %in% colnames(X)) {
intercept=TRUE
X = X[,!(colnames(X) %in% "(Intercept)"),drop=FALSE]
Z = Z[,!(colnames(Z) %in% "(Intercept)"),drop=FALSE]
if(dim(Z)[2] < 1) stop("There aren't any instruments!")
} else{
intercept=FALSE
}
# Parse X and Z into D, X, and Z
whichD = !(colnames(X) %in% colnames(Z))
D = X[,whichD,drop=FALSE]
if(dim(D)[2] != 1) {
stop("There must be exacty one endogenous variable! Please specify the formula correctly!")
}
unname(Z);unname(D); unname(Y)
if(sum(!whichD) == 0) {
ivmodel(Y=Y,D=D,Z=Z,intercept=intercept,
beta0=beta0,alpha=alpha,k=k,
heteroSE=heteroSE,clusterID=clusterID,
deltarange=deltarange, na.action=na.action)
} else {
unname(X)
X = X[,!whichD,drop=FALSE]
whichZ = !(colnames(Z) %in% colnames(X))
Z = Z[,whichZ,drop=FALSE]
ivmodel(Y=Y,D=D,Z=Z,X=X,intercept=intercept,
beta0=beta0,alpha=alpha,k=k,
heteroSE=heteroSE,clusterID=clusterID,
deltarange=deltarange, na.action=na.action)
}
} |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
! This file was ported from Lean 3 source module data.complex.exponential
! leanprover-community/mathlib commit 372edc36e5d2caafdd135769e0136b5a59186834
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Data.Complex.Basic
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential, trigonometric and hyperbolic trigonometric functions
This file contains the definitions of the real and complex exponential, sine, cosine, tangent,
hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
-/
@[inherit_doc]
local notation "abs'" => Abs.abs
open IsAbsoluteValue
open Classical BigOperators ComplexConjugate
section
open Real IsAbsoluteValue Finset
section
variable {Ξ± : Type _} {Ξ² : Type _} [Ring Ξ²] [LinearOrderedField Ξ±] [Archimedean Ξ±] {abv : Ξ² β Ξ±}
[IsAbsoluteValue abv]
theorem isCauSeq_of_decreasing_bounded (f : β β Ξ±) {a : Ξ±} {m : β} (ham : β n β₯ m, |f n| β€ a)
(hnm : β n β₯ m, f n.succ β€ f n) : IsCauSeq abs f := fun Ξ΅ Ξ΅0 => by
let β¨k, hkβ© := Archimedean.arch a Ξ΅0
have h : β l, β n β₯ m, a - l β’ Ξ΅ < f n :=
β¨k + k + 1, fun n hnm =>
lt_of_lt_of_le
(show a - (k + (k + 1)) β’ Ξ΅ < -|f n| from
lt_neg.1 <|
lt_of_le_of_lt (ham n hnm)
(by
rw [neg_sub, lt_sub_iff_add_lt, add_nsmul, add_nsmul, one_nsmul]
exact add_lt_add_of_le_of_lt hk (lt_of_le_of_lt hk (lt_add_of_pos_right _ Ξ΅0))))
(neg_le.2 <| abs_neg (f n) βΈ le_abs_self _)β©
let l := Nat.find h
have hl : β n : β, n β₯ m β f n > a - l β’ Ξ΅ := Nat.find_spec h
have hl0 : l β 0 := fun hl0 =>
not_lt_of_ge (ham m le_rfl)
(lt_of_lt_of_le (by have := hl m (le_refl m); simpa [hl0] using this) (le_abs_self (f m)))
cases' not_forall.1 (Nat.find_min h (Nat.pred_lt hl0)) with i hi
rw [not_imp, not_lt] at hi
exists i
intro j hj
have hfij : f j β€ f i := (Nat.rel_of_forall_rel_succ_of_le_of_le (Β· β₯ Β·) hnm hi.1 hj).le
rw [abs_of_nonpos (sub_nonpos.2 hfij), neg_sub, sub_lt_iff_lt_add']
calc
f i β€ a - Nat.pred l β’ Ξ΅ := hi.2
_ = a - l β’ Ξ΅ + Ξ΅ := by
conv =>
rhs
rw [β Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hl0), succ_nsmul', sub_add,
add_sub_cancel]
_ < f j + Ξ΅ := add_lt_add_right (hl j (le_trans hi.1 hj)) _
#align is_cau_of_decreasing_bounded isCauSeq_of_decreasing_bounded
theorem isCauSeq_of_mono_bounded (f : β β Ξ±) {a : Ξ±} {m : β} (ham : β n β₯ m, |f n| β€ a)
(hnm : β n β₯ m, f n β€ f n.succ) : IsCauSeq abs f := by
refine'
@Eq.ndrecOn (β β Ξ±) _ (IsCauSeq abs) _ _
(-β¨_, @isCauSeq_of_decreasing_bounded _ _ _ (fun n => -f n) a m (by simpa) (by simpa)β© :
CauSeq Ξ± abs).2
ext
exact neg_neg _
#align is_cau_of_mono_bounded isCauSeq_of_mono_bounded
end
section NoArchimedean
variable {Ξ± : Type _} {Ξ² : Type _} [Ring Ξ²] [LinearOrderedField Ξ±] {abv : Ξ² β Ξ±}
[IsAbsoluteValue abv]
theorem isCauSeq_series_of_abv_le_of_isCauSeq {f : β β Ξ²} {g : β β Ξ±} (n : β) :
(β m, n β€ m β abv (f m) β€ g m) β
(IsCauSeq abs fun n => β i in range n, g i) β IsCauSeq abv fun n => β i in range n, f i := by
intro hm hg Ξ΅ Ξ΅0
cases' hg (Ξ΅ / 2) (div_pos Ξ΅0 (by norm_num)) with i hi
exists max n i
intro j ji
have hiβ := hi j (le_trans (le_max_right n i) ji)
have hiβ := hi (max n i) (le_max_right n i)
have sub_le :=
abs_sub_le (β k in range j, g k) (β k in range i, g k) (β k in range (max n i), g k)
have := add_lt_add hiβ hiβ
rw [abs_sub_comm (β k in range (max n i), g k), add_halves Ξ΅] at this
refine' lt_of_le_of_lt (le_trans (le_trans _ (le_abs_self _)) sub_le) this
generalize hk : j - max n i = k
clear this hiβ hiβ hi Ξ΅0 Ξ΅ hg sub_le
rw [tsub_eq_iff_eq_add_of_le ji] at hk
rw [hk]
dsimp only
clear hk ji j
induction' k with k' hi
Β· simp [abv_zero abv]
Β· simp only [Nat.succ_add, Nat.succ_eq_add_one, Finset.sum_range_succ_comm]
simp only [add_assoc, sub_eq_add_neg]
refine le_trans (abv_add _ _ _) ?_
simp only [sub_eq_add_neg] at hi
refine add_le_add (hm _ (le_add_of_nonneg_of_le (Nat.zero_le _) (le_max_left _ _))) hi
#align is_cau_series_of_abv_le_cau isCauSeq_series_of_abv_le_of_isCauSeq
theorem isCauSeq_series_of_abv_isCauSeq {f : β β Ξ²} :
(IsCauSeq abs fun m => β n in range m, abv (f n)) β IsCauSeq abv fun m => β n in range m, f n :=
isCauSeq_series_of_abv_le_of_isCauSeq 0 fun _ _ => le_rfl
#align is_cau_series_of_abv_cau isCauSeq_series_of_abv_isCauSeq
end NoArchimedean
section
variable {Ξ± : Type _} [LinearOrderedField Ξ±] [Archimedean Ξ±]
theorem isCauSeq_geo_series {Ξ² : Type _} [Ring Ξ²] [Nontrivial Ξ²] {abv : Ξ² β Ξ±} [IsAbsoluteValue abv]
(x : Ξ²) (hx1 : abv x < 1) : IsCauSeq abv fun n => β m in range n, x ^ m :=
have hx1' : abv x β 1 := fun h => by simp [h, lt_irrefl] at hx1
isCauSeq_series_of_abv_isCauSeq
(by
simp only [abv_pow abv, geom_sum_eq hx1']
conv in _ / _ => rw [β neg_div_neg_eq, neg_sub, neg_sub]
refine' @isCauSeq_of_mono_bounded _ _ _ _ ((1 : Ξ±) / (1 - abv x)) 0 _ _
Β· intro n hn
rw [abs_of_nonneg]
refine'
div_le_div_of_le (le_of_lt <| sub_pos.2 hx1)
(sub_le_self _ (abv_pow abv x n βΈ abv_nonneg _ _))
refine' div_nonneg (sub_nonneg.2 _) (sub_nonneg.2 <| le_of_lt hx1)
clear hn
induction' n with n ih
Β· simp
Β· rw [pow_succ, β one_mul (1 : Ξ±)]
refine' mul_le_mul (le_of_lt hx1) ih (abv_pow abv x n βΈ abv_nonneg _ _) (by norm_num)
Β· intro n _
refine' div_le_div_of_le (le_of_lt <| sub_pos.2 hx1) (sub_le_sub_left _ _)
rw [βone_mul (abv x ^ n), pow_succ]
exact mul_le_mul_of_nonneg_right (le_of_lt hx1) (pow_nonneg (abv_nonneg _ _) _))
#align is_cau_geo_series isCauSeq_geo_series
theorem isCauSeq_geo_series_const (a : Ξ±) {x : Ξ±} (hx1 : |x| < 1) :
IsCauSeq abs fun m => β n in range m, (a * x ^ n) := by
have : IsCauSeq abs fun m => a * β n in range m, (x ^ n) :=
(CauSeq.const abs a *
(show CauSeq Ξ± abs from β¨fun n => β m in range n, x ^ m, isCauSeq_geo_series x hx1β©)).2
simpa [mul_sum] using this
#align is_cau_geo_series_const isCauSeq_geo_series_const
variable {Ξ² : Type _} [Ring Ξ²] {abv : Ξ² β Ξ±} [IsAbsoluteValue abv]
theorem series_ratio_test {f : β β Ξ²} (n : β) (r : Ξ±) (hr0 : 0 β€ r) (hr1 : r < 1)
(h : β m, n β€ m β abv (f m.succ) β€ r * abv (f m)) : IsCauSeq abv fun m => β n in range m, f n :=
by
have har1 : |r| < 1 := by rwa [abs_of_nonneg hr0]
refine'
isCauSeq_series_of_abv_le_of_isCauSeq n.succ _
(isCauSeq_geo_series_const (abv (f n.succ) * rβ»ΒΉ ^ n.succ) har1)
intro m hmn
cases' Classical.em (r = 0) with r_zero r_ne_zero
Β· have m_pos := lt_of_lt_of_le (Nat.succ_pos n) hmn
have := h m.pred (Nat.le_of_succ_le_succ (by rwa [Nat.succ_pred_eq_of_pos m_pos]))
simpa [r_zero, Nat.succ_pred_eq_of_pos m_pos, pow_succ] using this
generalize hk : m - n.succ = k
have r_pos : 0 < r := lt_of_le_of_ne hr0 (Ne.symm r_ne_zero)
replace hk : m = k + n.succ := (tsub_eq_iff_eq_add_of_le hmn).1 hk
induction' k with k ih generalizing m n
Β· rw [hk, Nat.zero_add, mul_right_comm, inv_pow _ _, β div_eq_mul_inv, mul_div_cancel]
exact le_refl _
exact (ne_of_lt (pow_pos r_pos _)).symm
Β· have kn : k + n.succ β₯ n.succ := by
rw [β zero_add n.succ]; exact add_le_add (Nat.zero_le _) (by simp)
erw [hk, Nat.succ_add, pow_succ' r, β mul_assoc]
refine
le_trans (by rw [mul_comm] <;> exact h _ (Nat.le_of_succ_le kn))
(mul_le_mul_of_nonneg_right ?_ hr0)
exact ih _ h _ (by simp) rfl
#align series_ratio_test series_ratio_test
theorem sum_range_diag_flip {Ξ± : Type _} [AddCommMonoid Ξ±] (n : β) (f : β β β β Ξ±) :
(β m in range n, β k in range (m + 1), f k (m - k)) =
β m in range n, β k in range (n - m), f m k := by
rw [sum_sigma', sum_sigma']
exact
sum_bij (fun a _ => β¨a.2, a.1 - a.2β©)
(fun a ha =>
have hβ : a.1 < n := mem_range.1 (mem_sigma.1 ha).1
have hβ : a.2 < Nat.succ a.1 := mem_range.1 (mem_sigma.1 ha).2
mem_sigma.2
β¨mem_range.2 (lt_of_lt_of_le hβ hβ),
mem_range.2 ((tsub_lt_tsub_iff_right (Nat.le_of_lt_succ hβ)).2 hβ)β©)
(fun _ _ => rfl)
(fun β¨aβ, aββ© β¨bβ, bββ© ha hb h =>
have ha : aβ < n β§ aβ β€ aβ :=
β¨mem_range.1 (mem_sigma.1 ha).1, Nat.le_of_lt_succ (mem_range.1 (mem_sigma.1 ha).2)β©
have hb : bβ < n β§ bβ β€ bβ :=
β¨mem_range.1 (mem_sigma.1 hb).1, Nat.le_of_lt_succ (mem_range.1 (mem_sigma.1 hb).2)β©
have h : aβ = bβ β§ _ := by simpa using h
have h' : aβ = bβ - bβ + aβ := (tsub_eq_iff_eq_add_of_le ha.2).1 (eq_of_heq h.2)
Sigma.mk.inj_iff.2 β¨tsub_add_cancel_of_le hb.2 βΈ h'.symm βΈ h.1 βΈ rfl, heq_of_eq h.1β©)
fun β¨aβ, aββ© ha =>
have ha : aβ < n β§ aβ < n - aβ :=
β¨mem_range.1 (mem_sigma.1 ha).1, mem_range.1 (mem_sigma.1 ha).2β©
β¨β¨aβ + aβ, aββ©,
β¨mem_sigma.2
β¨mem_range.2 (lt_tsub_iff_right.1 ha.2),
mem_range.2 (Nat.lt_succ_of_le (Nat.le_add_left _ _))β©,
Sigma.mk.inj_iff.2 β¨rfl, heq_of_eq (add_tsub_cancel_right _ _).symmβ©β©β©
#align sum_range_diag_flip sum_range_diag_flip
end
section NoArchimedean
variable {Ξ± : Type _} {Ξ² : Type _} [LinearOrderedField Ξ±] {abv : Ξ² β Ξ±}
section
variable [Semiring Ξ²] [IsAbsoluteValue abv]
theorem abv_sum_le_sum_abv {Ξ³ : Type _} (f : Ξ³ β Ξ²) (s : Finset Ξ³) :
abv (β k in s, f k) β€ β k in s, abv (f k) :=
haveI := Classical.decEq Ξ³
Finset.induction_on s (by simp [abv_zero abv]) fun a s has ih => by
rw [sum_insert has, sum_insert has]; exact le_trans (abv_add abv _ _) (add_le_add_left ih _)
#align abv_sum_le_sum_abv abv_sum_le_sum_abv
end
section
variable [Ring Ξ²] [IsAbsoluteValue abv]
theorem cauchy_product {a b : β β Ξ²} (ha : IsCauSeq abs fun m => β n in range m, abv (a n))
(hb : IsCauSeq abv fun m => β n in range m, b n) (Ξ΅ : Ξ±) (Ξ΅0 : 0 < Ξ΅) :
β i : β,
β j β₯ i,
abv
(((β k in range j, a k) * β k in range j, b k) -
β n in range j, β m in range (n + 1), a m * b (n - m)) <
Ξ΅ :=
let β¨Q, hQβ© := CauSeq.bounded β¨_, hbβ©
let β¨P, hPβ© := CauSeq.bounded β¨_, haβ©
have hP0 : 0 < P := lt_of_le_of_lt (abs_nonneg _) (hP 0)
have hPΞ΅0 : 0 < Ξ΅ / (2 * P) := div_pos Ξ΅0 (mul_pos (show (2 : Ξ±) > 0 by norm_num) hP0)
let β¨N, hNβ© := CauSeq.cauchyβ β¨_, hbβ© hPΞ΅0
have hQΞ΅0 : 0 < Ξ΅ / (4 * Q) :=
div_pos Ξ΅0 (mul_pos (show (0 : Ξ±) < 4 by norm_num) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0)))
let β¨M, hMβ© := CauSeq.cauchyβ β¨_, haβ© hQΞ΅0
β¨2 * (max N M + 1), fun K hK =>
by
have hβ :
(β m in range K, β k in range (m + 1), a k * b (m - k)) =
β m in range K, β n in range (K - m), a m * b n :=
by simpa using sum_range_diag_flip K fun m n => a m * b n
have hβ :
(fun i => β k in range (K - i), a i * b k) = fun i => a i * β k in range (K - i), b k := by
simp [Finset.mul_sum]
have hβ :
(β i in range K, a i * β k in range (K - i), b k) =
(β i in range K, a i * ((β k in range (K - i), b k) - β k in range K, b k)) +
β i in range K, a i * β k in range K, b k :=
by rw [β sum_add_distrib]; simp [(mul_add _ _ _).symm]
have two_mul_two : (4 : Ξ±) = 2 * 2 := by norm_num
have hQ0 : Q β 0 := fun h => by simp [h, lt_irrefl] at hQΞ΅0
have h2Q0 : 2 * Q β 0 := mul_ne_zero two_ne_zero hQ0
have hΞ΅ : Ξ΅ / (2 * P) * P + Ξ΅ / (4 * Q) * (2 * Q) = Ξ΅ := by
rw [β div_div, div_mul_cancel _ (Ne.symm (ne_of_lt hP0)), two_mul_two, mul_assoc, β div_div,
div_mul_cancel _ h2Q0, add_halves]
have hNMK : max N M + 1 < K :=
lt_of_lt_of_le (by rw [two_mul]; exact lt_add_of_pos_left _ (Nat.succ_pos _)) hK
have hKN : N < K :=
calc
N β€ max N M := le_max_left _ _
_ < max N M + 1 := (Nat.lt_succ_self _)
_ < K := hNMK
have hsumlesum :
(β i in range (max N M + 1),
abv (a i) * abv ((β k in range (K - i), b k) - β k in range K, b k)) β€
β i in range (max N M + 1), abv (a i) * (Ξ΅ / (2 * P)) :=
sum_le_sum fun m hmJ =>
mul_le_mul_of_nonneg_left
(le_of_lt
(hN (K - m)
(le_tsub_of_add_le_left
(le_trans
(by
rw [two_mul]
exact
add_le_add (le_of_lt (mem_range.1 hmJ))
(le_trans (le_max_left _ _) (le_of_lt (lt_add_one _))))
hK))
K (le_of_lt hKN)))
(abv_nonneg abv _)
have hsumltP : (β n in range (max N M + 1), abv (a n)) < P :=
calc
(β n in range (max N M + 1), abv (a n)) = |β n in range (max N M + 1), abv (a n)| :=
Eq.symm (abs_of_nonneg (sum_nonneg fun x _ => abv_nonneg abv (a x)))
_ < P := hP (max N M + 1)
rw [hβ, hβ, hβ, sum_mul, β sub_sub, sub_right_comm, sub_self, zero_sub, abv_neg abv]
refine' lt_of_le_of_lt (abv_sum_le_sum_abv _ _) _
suffices
(β i in range (max N M + 1),
abv (a i) * abv ((β k in range (K - i), b k) - β k in range K, b k)) +
((β i in range K, abv (a i) * abv ((β k in range (K - i), b k) - β k in range K, b k)) -
β i in range (max N M + 1),
abv (a i) * abv ((β k in range (K - i), b k) - β k in range K, b k)) <
Ξ΅ / (2 * P) * P + Ξ΅ / (4 * Q) * (2 * Q)
by
rw [hΞ΅] at this
simpa [abv_mul abv] using this
refine'
add_lt_add
(lt_of_le_of_lt hsumlesum
(by rw [β sum_mul, mul_comm]; exact (mul_lt_mul_left hPΞ΅0).mpr hsumltP))
_
rw [sum_range_sub_sum_range (le_of_lt hNMK)]
calc
(β i in (range K).filter fun k => max N M + 1 β€ k,
abv (a i) * abv ((β k in range (K - i), b k) - β k in range K, b k)) β€
β i in (range K).filter fun k => max N M + 1 β€ k, abv (a i) * (2 * Q) :=
sum_le_sum fun n _ =>
by
refine' mul_le_mul_of_nonneg_left _ (abv_nonneg _ _)
rw [sub_eq_add_neg]
refine' le_trans (abv_add _ _ _) _
rw [two_mul, abv_neg abv]
exact add_le_add (le_of_lt (hQ _)) (le_of_lt (hQ _))
_ < Ξ΅ / (4 * Q) * (2 * Q) := by
rw [β sum_mul, β sum_range_sub_sum_range (le_of_lt hNMK)];
refine'
(mul_lt_mul_right <| by
rw [two_mul]
exact
add_pos (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))
(lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))).2
(lt_of_le_of_lt (le_abs_self _)
(hM _ (le_trans (Nat.le_succ_of_le (le_max_right _ _)) (le_of_lt hNMK)) _
(Nat.le_succ_of_le (le_max_right _ _))))
β©
#align cauchy_product cauchy_product
end
end NoArchimedean
end
open Finset
open CauSeq
namespace Complex
theorem isCauSeq_abs_exp (z : β) :
IsCauSeq Abs.abs fun n => β m in range n, abs (z ^ m / m.factorial) :=
let β¨n, hnβ© := exists_nat_gt (abs z)
have hn0 : (0 : β) < n := lt_of_le_of_lt (abs.nonneg _) hn
series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff hn0, one_mul]) fun m hm => by
rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ, mul_comm m.succ, Nat.cast_mul, β div_div,
mul_div_assoc, mul_div_right_comm, map_mul, map_divβ, abs_cast_nat]
exact
mul_le_mul_of_nonneg_right
(div_le_div_of_le_left (abs.nonneg _) hn0 (Nat.cast_le.2 (le_trans hm (Nat.le_succ _))))
(abs.nonneg _)
#align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp
noncomputable section
theorem isCauSeq_exp (z : β) : IsCauSeq abs fun n => β m in range n, z ^ m / m.factorial :=
isCauSeq_series_of_abv_isCauSeq (isCauSeq_abs_exp z)
#align complex.is_cau_exp Complex.isCauSeq_exp
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
----@[pp_nodot] Porting note: removed Porting note: removed
def exp' (z : β) : CauSeq β Complex.abs :=
β¨fun n => β m in range n, z ^ m / m.factorial, isCauSeq_exp zβ©
#align complex.exp' Complex.exp'
/-- The complex exponential function, defined via its Taylor series -/
--@[pp_nodot] Porting note: removed
--Porting note: removed `irreducible` attribute, so I can prove things
def exp (z : β) : β :=
CauSeq.lim (exp' z)
#align complex.exp Complex.exp
/-- The complex sine function, defined via `exp` -/
--@[pp_nodot] Porting note: removed
def sin (z : β) : β :=
(exp (-z * I) - exp (z * I)) * I / 2
#align complex.sin Complex.sin
/-- The complex cosine function, defined via `exp` -/
--@[pp_nodot] Porting note: removed
def cos (z : β) : β :=
(exp (z * I) + exp (-z * I)) / 2
#align complex.cos Complex.cos
/-- The complex tangent function, defined as `sin z / cos z` -/
--@[pp_nodot] Porting note: removed
def tan (z : β) : β :=
sin z / cos z
#align complex.tan Complex.tan
/-- The complex hyperbolic sine function, defined via `exp` -/
--@[pp_nodot] Porting note: removed
def sinh (z : β) : β :=
(exp z - exp (-z)) / 2
#align complex.sinh Complex.sinh
/-- The complex hyperbolic cosine function, defined via `exp` -/
--@[pp_nodot] Porting note: removed
def cosh (z : β) : β :=
(exp z + exp (-z)) / 2
#align complex.cosh Complex.cosh
/-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/
--@[pp_nodot] Porting note: removed
def tanh (z : β) : β :=
sinh z / cosh z
#align complex.tanh Complex.tanh
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
--@[pp_nodot] Porting note: removed
nonrec def exp (x : β) : β :=
(exp x).re
#align real.exp Real.exp
/-- The real sine function, defined as the real part of the complex sine -/
--@[pp_nodot] Porting note: removed
nonrec def sin (x : β) : β :=
(sin x).re
#align real.sin Real.sin
/-- The real cosine function, defined as the real part of the complex cosine -/
--@[pp_nodot] Porting note: removed
nonrec def cos (x : β) : β :=
(cos x).re
#align real.cos Real.cos
/-- The real tangent function, defined as the real part of the complex tangent -/
--@[pp_nodot] Porting note: removed
nonrec def tan (x : β) : β :=
(tan x).re
#align real.tan Real.tan
/-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/
--@[pp_nodot] Porting note: removed
nonrec def sinh (x : β) : β :=
(sinh x).re
#align real.sinh Real.sinh
/-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/
--@[pp_nodot] Porting note: removed
nonrec def cosh (x : β) : β :=
(cosh x).re
#align real.cosh Real.cosh
/-- The real hypebolic tangent function, defined as the real part of
the complex hyperbolic tangent -/
--@[pp_nodot] Porting note: removed
nonrec def tanh (x : β) : β :=
(tanh x).re
#align real.tanh Real.tanh
end
end Real
namespace Complex
variable (x y : β)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine' lim_eq_of_equiv_const fun Ξ΅ Ξ΅0 => β¨1, fun j hj => _β©
convert (config := .unfoldSameFun) Ξ΅0 -- porting note: Ξ΅0 : Ξ΅ > 0 but goal is _ < Ξ΅
cases' j with j j
Β· exact absurd hj (not_le_of_gt zero_lt_one)
Β· dsimp [exp']
induction' j with j ih
Β· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
Β· rw [β ih (by simp [show 1 = Nat.succ 0 from rfl, Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
#align complex.exp_zero Complex.exp_zero
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : β j : β, (β m in range j, (x + y) ^ m / m.factorial) =
β i in range j, β k in range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine' Finset.sum_congr rfl fun m _ => _
rw [add_pow, div_eq_mul_inv, sum_mul]
refine' Finset.sum_congr rfl fun I hi => _
have hβ : (m.choose I : β) β 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have hβ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [β hβ, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : β), mul_assoc, mul_left_comm (m.choose I : β)β»ΒΉ,
mul_comm (m.choose I : β)]
rw [inv_mul_cancel hβ]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y)
#align complex.exp_add Complex.exp_add
--Porting note: New definition
/-- the exponential function as a monoid hom from `Multiplicative β` to `β` -/
noncomputable def expMonoidHom : MonoidHom (Multiplicative β) β :=
{ toFun := fun z => exp (Multiplicative.toAdd z),
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List β) : exp l.sum = (l.map exp).prod :=
@MonoidHom.map_list_prod (Multiplicative β) β _ _ expMonoidHom l
#align complex.exp_list_sum Complex.exp_list_sum
theorem exp_multiset_sum (s : Multiset β) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative β) β _ _ expMonoidHom s
#align complex.exp_multiset_sum Complex.exp_multiset_sum
theorem exp_sum {Ξ± : Type _} (s : Finset Ξ±) (f : Ξ± β β) :
exp (β x in s, f x) = β x in s, exp (f x) :=
@map_prod (Multiplicative β) Ξ± β _ _ _ _ expMonoidHom f s
#align complex.exp_sum Complex.exp_sum
theorem exp_nat_mul (x : β) : β n : β, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ', Nat.cast_add_one, add_mul, exp_add, β exp_nat_mul _ n, one_mul]
#align complex.exp_nat_mul Complex.exp_nat_mul
theorem exp_ne_zero : exp x β 0 := fun h =>
zero_ne_one <| by rw [β exp_zero, β add_neg_self x, exp_add, h]; simp
#align complex.exp_ne_zero Complex.exp_ne_zero
theorem exp_neg : exp (-x) = (exp x)β»ΒΉ := by
rw [β mul_right_inj' (exp_ne_zero x), β exp_add]; simp [mul_inv_cancel (exp_ne_zero x)]
#align complex.exp_neg Complex.exp_neg
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
#align complex.exp_sub Complex.exp_sub
theorem exp_int_mul (z : β) (n : β€) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
. simp [exp_nat_mul]
. simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
#align complex.exp_int_mul Complex.exp_int_mul
@[simp]
@[simp]
theorem ofReal_exp_ofReal_re (x : β) : ((exp x).re : β) = exp x :=
eq_conj_iff_re.1 <| by rw [β exp_conj, conj_ofReal]
#align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re
@[simp, norm_cast]
theorem ofReal_exp (x : β) : (Real.exp x : β) = exp x :=
ofReal_exp_ofReal_re _
#align complex.of_real_exp Complex.ofReal_exp
@[simp]
theorem exp_ofReal_im (x : β) : (exp x).im = 0 := by rw [β ofReal_exp_ofReal_re, ofReal_im]
#align complex.exp_of_real_im Complex.exp_ofReal_im
theorem exp_ofReal_re (x : β) : (exp x).re = Real.exp x :=
rfl
#align complex.exp_of_real_re Complex.exp_ofReal_re
theorem two_sinh : 2 * sinh x = exp x - exp (-x) :=
mul_div_cancel' _ two_ne_zero
#align complex.two_sinh Complex.two_sinh
theorem two_cosh : 2 * cosh x = exp x + exp (-x) :=
mul_div_cancel' _ two_ne_zero
#align complex.two_cosh Complex.two_cosh
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
#align complex.sinh_zero Complex.sinh_zero
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul]
#align complex.sinh_neg Complex.sinh_neg
private theorem sinh_add_aux {a b c d : β} :
(a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring
theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [β mul_right_inj' (two_ne_zero' β), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, β
mul_assoc, two_sinh, mul_left_comm, two_sinh, β mul_right_inj' (two_ne_zero' β), mul_add,
mul_left_comm, two_cosh, β mul_assoc, two_cosh]
exact sinh_add_aux
#align complex.sinh_add Complex.sinh_add
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
#align complex.cosh_zero Complex.cosh_zero
@[simp]
theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg]
#align complex.cosh_neg Complex.cosh_neg
private theorem cosh_add_aux {a b c d : β} :
(a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring
theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [β mul_right_inj' (two_ne_zero' β), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, β
mul_assoc, two_cosh, β mul_assoc, two_sinh, β mul_right_inj' (two_ne_zero' β), mul_add,
mul_left_comm, two_cosh, mul_left_comm, two_sinh]
exact cosh_add_aux
#align complex.cosh_add Complex.cosh_add
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
#align complex.sinh_sub Complex.sinh_sub
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
#align complex.cosh_sub Complex.cosh_sub
theorem sinh_conj : sinh (conj x) = conj (sinh x) := by
rw [sinh, β RingHom.map_neg, exp_conj, exp_conj, β RingHom.map_sub, sinh, map_divβ]
--Porting note: not nice
simp [β one_add_one_eq_two]
#align complex.sinh_conj Complex.sinh_conj
@[simp]
theorem ofReal_sinh_ofReal_re (x : β) : ((sinh x).re : β) = sinh x :=
eq_conj_iff_re.1 <| by rw [β sinh_conj, conj_ofReal]
#align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re
@[simp, norm_cast]
theorem ofReal_sinh (x : β) : (Real.sinh x : β) = sinh x :=
ofReal_sinh_ofReal_re _
#align complex.of_real_sinh Complex.ofReal_sinh
@[simp]
theorem sinh_of_real_im (x : β) : (sinh x).im = 0 := by rw [β ofReal_sinh_ofReal_re, ofReal_im]
#align complex.sinh_of_real_im Complex.sinh_of_real_im
theorem sinh_of_real_re (x : β) : (sinh x).re = Real.sinh x :=
rfl
#align complex.sinh_of_real_re Complex.sinh_of_real_re
theorem cosh_conj : cosh (conj x) = conj (cosh x) := by
rw [cosh, β RingHom.map_neg, exp_conj, exp_conj, β RingHom.map_add, cosh, map_divβ]
--Porting note: not nice
simp [β one_add_one_eq_two]
#align complex.cosh_conj Complex.cosh_conj
theorem ofReal_cosh_ofReal_re (x : β) : ((cosh x).re : β) = cosh x :=
eq_conj_iff_re.1 <| by rw [β cosh_conj, conj_ofReal]
#align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re
@[simp, norm_cast]
theorem ofReal_cosh (x : β) : (Real.cosh x : β) = cosh x :=
ofReal_cosh_ofReal_re _
#align complex.of_real_cosh Complex.ofReal_cosh
@[simp]
theorem cosh_ofReal_im (x : β) : (cosh x).im = 0 := by rw [β ofReal_cosh_ofReal_re, ofReal_im]
#align complex.cosh_of_real_im Complex.cosh_ofReal_im
@[simp]
theorem cosh_ofReal_re (x : β) : (cosh x).re = Real.cosh x :=
rfl
#align complex.cosh_of_real_re Complex.cosh_ofReal_re
theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
rfl
#align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh
@[simp]
theorem tanh_zero : tanh 0 = 0 := by simp [tanh]
#align complex.tanh_zero Complex.tanh_zero
@[simp]
theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div]
#align complex.tanh_neg Complex.tanh_neg
theorem tanh_conj : tanh (conj x) = conj (tanh x) := by
rw [tanh, sinh_conj, cosh_conj, β map_divβ, tanh]
#align complex.tanh_conj Complex.tanh_conj
@[simp]
theorem ofReal_tanh_ofReal_re (x : β) : ((tanh x).re : β) = tanh x :=
eq_conj_iff_re.1 <| by rw [β tanh_conj, conj_ofReal]
#align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re
@[simp, norm_cast]
theorem ofReal_tanh (x : β) : (Real.tanh x : β) = tanh x :=
ofReal_tanh_ofReal_re _
#align complex.of_real_tanh Complex.ofReal_tanh
@[simp]
theorem tanh_ofReal_im (x : β) : (tanh x).im = 0 := by rw [β ofReal_tanh_ofReal_re, ofReal_im]
#align complex.tanh_of_real_im Complex.tanh_ofReal_im
theorem tanh_ofReal_re (x : β) : (tanh x).re = Real.tanh x :=
rfl
#align complex.tanh_of_real_re Complex.tanh_ofReal_re
@[simp]
theorem cosh_add_sinh : cosh x + sinh x = exp x := by
rw [β mul_right_inj' (two_ne_zero' β), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul]
#align complex.cosh_add_sinh Complex.cosh_add_sinh
@[simp]
theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh]
#align complex.sinh_add_cosh Complex.sinh_add_cosh
@[simp]
theorem exp_sub_cosh : exp x - cosh x = sinh x :=
sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm
#align complex.exp_sub_cosh Complex.exp_sub_cosh
@[simp]
theorem exp_sub_sinh : exp x - sinh x = cosh x :=
sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm
#align complex.exp_sub_sinh Complex.exp_sub_sinh
@[simp]
theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by
rw [β mul_right_inj' (two_ne_zero' β), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul]
#align complex.cosh_sub_sinh Complex.cosh_sub_sinh
@[simp]
theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [β neg_sub, cosh_sub_sinh]
#align complex.sinh_sub_cosh Complex.sinh_sub_cosh
@[simp]
theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by
rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, β exp_add, add_neg_self, exp_zero]
#align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq
theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by
rw [β cosh_sq_sub_sinh_sq x]
ring
#align complex.cosh_sq Complex.cosh_sq
theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by
rw [β cosh_sq_sub_sinh_sq x]
ring
#align complex.sinh_sq Complex.sinh_sq
theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq]
#align complex.cosh_two_mul Complex.cosh_two_mul
theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by
rw [two_mul, sinh_add]
ring
#align complex.sinh_two_mul Complex.sinh_two_mul
theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [β h1, cosh_add x (2 * x)]
simp only [cosh_two_mul, sinh_two_mul]
have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring
rw [h2, sinh_sq]
ring
#align complex.cosh_three_mul Complex.cosh_three_mul
theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [β h1, sinh_add x (2 * x)]
simp only [cosh_two_mul, sinh_two_mul]
have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring
rw [h2, cosh_sq]
ring
#align complex.sinh_three_mul Complex.sinh_three_mul
@[simp]
theorem sin_zero : sin 0 = 0 := by simp [sin]
#align complex.sin_zero Complex.sin_zero
@[simp]
theorem sin_neg : sin (-x) = -sin x := by
simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul]
#align complex.sin_neg Complex.sin_neg
theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I :=
mul_div_cancel' _ two_ne_zero
#align complex.two_sin Complex.two_sin
theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) :=
mul_div_cancel' _ two_ne_zero
#align complex.two_cos Complex.two_cos
theorem sinh_mul_I : sinh (x * I) = sin x * I := by
rw [β mul_right_inj' (two_ne_zero' β), two_sinh, β mul_assoc, two_sin, mul_assoc, I_mul_I,
mul_neg_one, neg_sub, neg_mul_eq_neg_mul]
set_option linter.uppercaseLean3 false in
#align complex.sinh_mul_I Complex.sinh_mul_I
theorem cosh_mul_I : cosh (x * I) = cos x := by
rw [β mul_right_inj' (two_ne_zero' β), two_cosh, two_cos, neg_mul_eq_neg_mul]
set_option linter.uppercaseLean3 false in
#align complex.cosh_mul_I Complex.cosh_mul_I
theorem tanh_mul_I : tanh (x * I) = tan x * I := by
rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan]
set_option linter.uppercaseLean3 false in
#align complex.tanh_mul_I Complex.tanh_mul_I
theorem cos_mul_I : cos (x * I) = cosh x := by rw [β cosh_mul_I]; ring_nf; simp
set_option linter.uppercaseLean3 false in
#align complex.cos_mul_I Complex.cos_mul_I
theorem sin_mul_I : sin (x * I) = sinh x * I := by
have h : I * sin (x * I) = -sinh x :=
by
rw [mul_comm, β sinh_mul_I]
ring_nf
simp
rw [β neg_neg (sinh x), β h]
ext <;> simp
set_option linter.uppercaseLean3 false in
#align complex.sin_mul_I Complex.sin_mul_I
theorem tan_mul_I : tan (x * I) = tanh x * I := by
rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh]
set_option linter.uppercaseLean3 false in
#align complex.tan_mul_I Complex.tan_mul_I
theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by
rw [β mul_left_inj' I_ne_zero, β sinh_mul_I, add_mul, add_mul, mul_right_comm, β sinh_mul_I,
mul_assoc, β sinh_mul_I, β cosh_mul_I, β cosh_mul_I, sinh_add]
#align complex.sin_add Complex.sin_add
@[simp]
theorem cos_zero : cos 0 = 1 := by simp [cos]
#align complex.cos_zero Complex.cos_zero
@[simp]
theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm]
#align complex.cos_neg Complex.cos_neg
private theorem cos_add_aux {a b c d : β} :
(a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring
theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by
rw [β cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I,
mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg]
#align complex.cos_add Complex.cos_add
theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by
simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
#align complex.sin_sub Complex.sin_sub
theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by
simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
#align complex.cos_sub Complex.cos_sub
theorem sin_add_mul_I (x y : β) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by
rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc]
set_option linter.uppercaseLean3 false in
#align complex.sin_add_mul_I Complex.sin_add_mul_I
theorem sin_eq (z : β) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by
convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm
#align complex.sin_eq Complex.sin_eq
theorem cos_add_mul_I (x y : β) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by
rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc]
set_option linter.uppercaseLean3 false in
#align complex.cos_add_mul_I Complex.cos_add_mul_I
theorem cos_eq (z : β) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by
convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm
#align complex.cos_eq Complex.cos_eq
theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by
have s1 := sin_add ((x + y) / 2) ((x - y) / 2)
have s2 := sin_sub ((x + y) / 2) ((x - y) / 2)
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, half_add_self] at s1
rw [div_sub_div_same, β sub_add, add_sub_cancel', half_add_self] at s2
rw [s1, s2]
ring
#align complex.sin_sub_sin Complex.sin_sub_sin
theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by
have s1 := cos_add ((x + y) / 2) ((x - y) / 2)
have s2 := cos_sub ((x + y) / 2) ((x - y) / 2)
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, half_add_self] at s1
rw [div_sub_div_same, β sub_add, add_sub_cancel', half_add_self] at s2
rw [s1, s2]
ring
#align complex.cos_sub_cos Complex.cos_sub_cos
theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by
have h2 : (2 : β) β 0 := by norm_num
calc
cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_
_ =
cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) +
(cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) :=
?_
_ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_
Β· congr <;> field_simp [h2]
Β· rw [cos_add, cos_sub]
ring
#align complex.cos_add_cos Complex.cos_add_cos
theorem sin_conj : sin (conj x) = conj (sin x) := by
rw [β mul_left_inj' I_ne_zero, β sinh_mul_I, β conj_neg_I, β RingHom.map_mul, β RingHom.map_mul,
sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg]
#align complex.sin_conj Complex.sin_conj
@[simp]
theorem ofReal_sin_ofReal_re (x : β) : ((sin x).re : β) = sin x :=
eq_conj_iff_re.1 <| by rw [β sin_conj, conj_ofReal]
#align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re
@[simp, norm_cast]
theorem ofReal_sin (x : β) : (Real.sin x : β) = sin x :=
ofReal_sin_ofReal_re _
#align complex.of_real_sin Complex.ofReal_sin
@[simp]
theorem sin_ofReal_im (x : β) : (sin x).im = 0 := by rw [β ofReal_sin_ofReal_re, ofReal_im]
#align complex.sin_of_real_im Complex.sin_ofReal_im
theorem sin_ofReal_re (x : β) : (sin x).re = Real.sin x :=
rfl
#align complex.sin_of_real_re Complex.sin_ofReal_re
theorem cos_conj : cos (conj x) = conj (cos x) := by
rw [β cosh_mul_I, β conj_neg_I, β RingHom.map_mul, β cosh_mul_I, cosh_conj, mul_neg, cosh_neg]
#align complex.cos_conj Complex.cos_conj
@[simp]
theorem ofReal_cos_ofReal_re (x : β) : ((cos x).re : β) = cos x :=
eq_conj_iff_re.1 <| by rw [β cos_conj, conj_ofReal]
#align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re
@[simp, norm_cast]
theorem ofReal_cos (x : β) : (Real.cos x : β) = cos x :=
ofReal_cos_ofReal_re _
#align complex.of_real_cos Complex.ofReal_cos
@[simp]
theorem cos_ofReal_im (x : β) : (cos x).im = 0 := by rw [β ofReal_cos_ofReal_re, ofReal_im]
#align complex.cos_of_real_im Complex.cos_ofReal_im
theorem cos_ofReal_re (x : β) : (cos x).re = Real.cos x :=
rfl
#align complex.cos_of_real_re Complex.cos_ofReal_re
@[simp]
theorem tan_zero : tan 0 = 0 := by simp [tan]
#align complex.tan_zero Complex.tan_zero
theorem tan_eq_sin_div_cos : tan x = sin x / cos x :=
rfl
#align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos
theorem tan_mul_cos {x : β} (hx : cos x β 0) : tan x * cos x = sin x := by
rw [tan_eq_sin_div_cos, div_mul_cancel _ hx]
#align complex.tan_mul_cos Complex.tan_mul_cos
@[simp]
theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div]
#align complex.tan_neg Complex.tan_neg
theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, β map_divβ, tan]
#align complex.tan_conj Complex.tan_conj
@[simp]
theorem ofReal_tan_ofReal_re (x : β) : ((tan x).re : β) = tan x :=
eq_conj_iff_re.1 <| by rw [β tan_conj, conj_ofReal]
#align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re
@[simp, norm_cast]
theorem ofReal_tan (x : β) : (Real.tan x : β) = tan x :=
ofReal_tan_ofReal_re _
#align complex.of_real_tan Complex.ofReal_tan
@[simp]
theorem tan_of_real_im (x : β) : (tan x).im = 0 := by rw [β ofReal_tan_ofReal_re, ofReal_im]
#align complex.tan_of_real_im Complex.tan_of_real_im
theorem tan_of_real_re (x : β) : (tan x).re = Real.tan x :=
rfl
#align complex.tan_of_real_re Complex.tan_of_real_re
theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by
rw [β cosh_add_sinh, sinh_mul_I, cosh_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.cos_add_sin_I Complex.cos_add_sin_I
theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by
rw [neg_mul, β cosh_sub_sinh, sinh_mul_I, cosh_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.cos_sub_sin_I Complex.cos_sub_sin_I
@[simp]
theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 :=
Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm])
(cosh_sq_sub_sinh_sq (x * I))
#align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq
@[simp]
theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq]
#align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq
theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, β sq, β sq]
#align complex.cos_two_mul' Complex.cos_two_mul'
theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by
rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), β sub_add, sub_add_eq_add_sub,
two_mul]
#align complex.cos_two_mul Complex.cos_two_mul
theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by
rw [two_mul, sin_add, two_mul, add_mul, mul_comm]
#align complex.sin_two_mul Complex.sin_two_mul
theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by
simp [cos_two_mul, div_add_div_same, mul_div_cancel_left, two_ne_zero, -one_div]
#align complex.cos_sq Complex.cos_sq
theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [β sin_sq_add_cos_sq x, add_sub_cancel']
#align complex.cos_sq' Complex.cos_sq'
theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [β sin_sq_add_cos_sq x, add_sub_cancel]
#align complex.sin_sq Complex.sin_sq
theorem inv_one_add_tan_sq {x : β} (hx : cos x β 0) : (1 + tan x ^ 2)β»ΒΉ = cos x ^ 2 := by
have : cos x ^ 2 β 0 := pow_ne_zero 2 hx
rw [tan_eq_sin_div_cos, div_pow]
field_simp [this]
#align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq
theorem tan_sq_div_one_add_tan_sq {x : β} (hx : cos x β 0) :
tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by
simp only [β tan_mul_cos hx, mul_pow, β inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul]
#align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq
theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [β h1, cos_add x (2 * x)]
simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq]
have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring
rw [h2, cos_sq']
ring
#align complex.cos_three_mul Complex.cos_three_mul
theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by
have h1 : x + 2 * x = 3 * x := by ring
rw [β h1, sin_add x (2 * x)]
simp only [cos_two_mul, sin_two_mul, cos_sq']
have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring
rw [h2, cos_sq']
ring
#align complex.sin_three_mul Complex.sin_three_mul
theorem exp_mul_I : exp (x * I) = cos x + sin x * I :=
(cos_add_sin_I _).symm
set_option linter.uppercaseLean3 false in
#align complex.exp_mul_I Complex.exp_mul_I
theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.exp_add_mul_I Complex.exp_add_mul_I
theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by
rw [β exp_add_mul_I, re_add_im]
#align complex.exp_eq_exp_re_mul_sin_add_cos Complex.exp_eq_exp_re_mul_sin_add_cos
theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by
rw [exp_eq_exp_re_mul_sin_add_cos]
simp [exp_ofReal_re, cos_ofReal_re]
#align complex.exp_re Complex.exp_re
theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by
rw [exp_eq_exp_re_mul_sin_add_cos]
simp [exp_ofReal_re, sin_ofReal_re]
#align complex.exp_im Complex.exp_im
@[simp]
theorem exp_ofReal_mul_I_re (x : β) : (exp (x * I)).re = Real.cos x := by
simp [exp_mul_I, cos_ofReal_re]
set_option linter.uppercaseLean3 false in
#align complex.exp_of_real_mul_I_re Complex.exp_ofReal_mul_I_re
@[simp]
theorem exp_ofReal_mul_I_im (x : β) : (exp (x * I)).im = Real.sin x := by
simp [exp_mul_I, sin_ofReal_re]
set_option linter.uppercaseLean3 false in
#align complex.exp_of_real_mul_I_im Complex.exp_ofReal_mul_I_im
/-- **De Moivre's formula** -/
theorem cos_add_sin_mul_I_pow (n : β) (z : β) :
(cos z + sin z * I) ^ n = cos (βn * z) + sin (βn * z) * I := by
rw [β exp_mul_I, β exp_mul_I]
induction' n with n ih
Β· rw [pow_zero, Nat.cast_zero, zero_mul, zero_mul, exp_zero]
Β· rw [pow_succ', ih, Nat.cast_succ, add_mul, add_mul, one_mul, exp_add]
set_option linter.uppercaseLean3 false in
#align complex.cos_add_sin_mul_I_pow Complex.cos_add_sin_mul_I_pow
end Complex
namespace Real
open Complex
variable (x y : β)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
#align real.exp_zero Real.exp_zero
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
#align real.exp_add Real.exp_add
--Porting note: New definition
/-- the exponential function as a monoid hom from `Multiplicative β` to `β` -/
noncomputable def expMonoidHom : MonoidHom (Multiplicative β) β :=
{ toFun := fun x => exp (Multiplicative.toAdd x),
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List β) : exp l.sum = (l.map exp).prod :=
@MonoidHom.map_list_prod (Multiplicative β) β _ _ expMonoidHom l
#align real.exp_list_sum Real.exp_list_sum
theorem exp_multiset_sum (s : Multiset β) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative β) β _ _ expMonoidHom s
#align real.exp_multiset_sum Real.exp_multiset_sum
theorem exp_sum {Ξ± : Type _} (s : Finset Ξ±) (f : Ξ± β β) :
exp (β x in s, f x) = β x in s, exp (f x) :=
@map_prod (Multiplicative β) Ξ± β _ _ _ _ expMonoidHom f s
#align real.exp_sum Real.exp_sum
nonrec theorem exp_nat_mul (x : β) (n : β) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
#align real.exp_nat_mul Real.exp_nat_mul
nonrec theorem exp_ne_zero : exp x β 0 := fun h =>
exp_ne_zero x <| by rw [exp, β ofReal_inj] at h; simp_all
#align real.exp_ne_zero Real.exp_ne_zero
nonrec theorem exp_neg : exp (-x) = (exp x)β»ΒΉ :=
ofReal_injective <| by simp [exp_neg]
#align real.exp_neg Real.exp_neg
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
#align real.exp_sub Real.exp_sub
@[simp]
theorem sin_zero : sin 0 = 0 := by simp [sin]
#align real.sin_zero Real.sin_zero
@[simp]
theorem sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul]
#align real.sin_neg Real.sin_neg
nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y :=
ofReal_injective <| by simp [sin_add]
#align real.sin_add Real.sin_add
@[simp]
theorem cos_zero : cos 0 = 1 := by simp [cos]
#align real.cos_zero Real.cos_zero
@[simp]
theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg]
#align real.cos_neg Real.cos_neg
@[simp]
theorem cos_abs : cos (|x|) = cos x := by
cases le_total x 0 <;> simp only [*, _root_.abs_of_nonneg, abs_of_nonpos, cos_neg]
#align real.cos_abs Real.cos_abs
nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y :=
ofReal_injective <| by simp [cos_add]
#align real.cos_add Real.cos_add
theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by
simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
#align real.sin_sub Real.sin_sub
theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by
simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
#align real.cos_sub Real.cos_sub
nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) :=
ofReal_injective <| by simp [sin_sub_sin]
#align real.sin_sub_sin Real.sin_sub_sin
nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) :=
ofReal_injective <| by simp [cos_sub_cos]
#align real.cos_sub_cos Real.cos_sub_cos
nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) :=
ofReal_injective <| by simp [cos_add_cos]
#align real.cos_add_cos Real.cos_add_cos
nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x :=
ofReal_injective <| by simp [tan_eq_sin_div_cos]
#align real.tan_eq_sin_div_cos Real.tan_eq_sin_div_cos
theorem tan_mul_cos {x : β} (hx : cos x β 0) : tan x * cos x = sin x := by
rw [tan_eq_sin_div_cos, div_mul_cancel _ hx]
#align real.tan_mul_cos Real.tan_mul_cos
@[simp]
theorem tan_zero : tan 0 = 0 := by simp [tan]
#align real.tan_zero Real.tan_zero
@[simp]
theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div]
#align real.tan_neg Real.tan_neg
@[simp]
nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 :=
ofReal_injective (by simp [sin_sq_add_cos_sq])
#align real.sin_sq_add_cos_sq Real.sin_sq_add_cos_sq
@[simp]
theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq]
#align real.cos_sq_add_sin_sq Real.cos_sq_add_sin_sq
theorem sin_sq_le_one : sin x ^ 2 β€ 1 := by
rw [β sin_sq_add_cos_sq x]; exact le_add_of_nonneg_right (sq_nonneg _)
#align real.sin_sq_le_one Real.sin_sq_le_one
theorem cos_sq_le_one : cos x ^ 2 β€ 1 := by
rw [β sin_sq_add_cos_sq x]; exact le_add_of_nonneg_left (sq_nonneg _)
#align real.cos_sq_le_one Real.cos_sq_le_one
theorem abs_sin_le_one : |sin x| β€ 1 :=
abs_le_one_iff_mul_self_le_one.2 <| by simp only [β sq, sin_sq_le_one]
#align real.abs_sin_le_one Real.abs_sin_le_one
theorem abs_cos_le_one : |cos x| β€ 1 :=
abs_le_one_iff_mul_self_le_one.2 <| by simp only [β sq, cos_sq_le_one]
#align real.abs_cos_le_one Real.abs_cos_le_one
theorem sin_le_one : sin x β€ 1 :=
(abs_le.1 (abs_sin_le_one _)).2
#align real.sin_le_one Real.sin_le_one
theorem cos_le_one : cos x β€ 1 :=
(abs_le.1 (abs_cos_le_one _)).2
#align real.cos_le_one Real.cos_le_one
theorem neg_one_le_sin : -1 β€ sin x :=
(abs_le.1 (abs_sin_le_one _)).1
#align real.neg_one_le_sin Real.neg_one_le_sin
theorem neg_one_le_cos : -1 β€ cos x :=
(abs_le.1 (abs_cos_le_one _)).1
#align real.neg_one_le_cos Real.neg_one_le_cos
nonrec theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 :=
ofReal_injective <| by simp [cos_two_mul]
#align real.cos_two_mul Real.cos_two_mul
nonrec theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 :=
ofReal_injective <| by simp [cos_two_mul']
#align real.cos_two_mul' Real.cos_two_mul'
nonrec theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x :=
ofReal_injective <| by simp [sin_two_mul]
#align real.sin_two_mul Real.sin_two_mul
nonrec theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 :=
ofReal_injective <| by simp [cos_sq]
#align real.cos_sq Real.cos_sq
theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [β sin_sq_add_cos_sq x, add_sub_cancel']
#align real.cos_sq' Real.cos_sq'
theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 :=
eq_sub_iff_add_eq.2 <| sin_sq_add_cos_sq _
#align real.sin_sq Real.sin_sq
theorem abs_sin_eq_sqrt_one_sub_cos_sq (x : β) : |sin x| = sqrt (1 - cos x ^ 2) := by
rw [β sin_sq, sqrt_sq_eq_abs]
#align real.abs_sin_eq_sqrt_one_sub_cos_sq Real.abs_sin_eq_sqrt_one_sub_cos_sq
theorem abs_cos_eq_sqrt_one_sub_sin_sq (x : β) : |cos x| = sqrt (1 - sin x ^ 2) := by
rw [β cos_sq', sqrt_sq_eq_abs]
#align real.abs_cos_eq_sqrt_one_sub_sin_sq Real.abs_cos_eq_sqrt_one_sub_sin_sq
theorem inv_one_add_tan_sq {x : β} (hx : cos x β 0) : (1 + tan x ^ 2)β»ΒΉ = cos x ^ 2 :=
have : Complex.cos x β 0 := mt (congr_arg re) hx
ofReal_inj.1 <| by simpa using Complex.inv_one_add_tan_sq this
#align real.inv_one_add_tan_sq Real.inv_one_add_tan_sq
theorem tan_sq_div_one_add_tan_sq {x : β} (hx : cos x β 0) :
tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by
simp only [β tan_mul_cos hx, mul_pow, β inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul]
#align real.tan_sq_div_one_add_tan_sq Real.tan_sq_div_one_add_tan_sq
theorem inv_sqrt_one_add_tan_sq {x : β} (hx : 0 < cos x) : (sqrt (1 + tan x ^ 2))β»ΒΉ = cos x := by
rw [β sqrt_sq hx.le, β sqrt_inv, inv_one_add_tan_sq hx.ne']
#align real.inv_sqrt_one_add_tan_sq Real.inv_sqrt_one_add_tan_sq
theorem tan_div_sqrt_one_add_tan_sq {x : β} (hx : 0 < cos x) :
tan x / sqrt (1 + tan x ^ 2) = sin x := by
rw [β tan_mul_cos hx.ne', β inv_sqrt_one_add_tan_sq hx, div_eq_mul_inv]
#align real.tan_div_sqrt_one_add_tan_sq Real.tan_div_sqrt_one_add_tan_sq
nonrec theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by
rw [β ofReal_inj]; simp [cos_three_mul]
#align real.cos_three_mul Real.cos_three_mul
nonrec theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by
rw [β ofReal_inj]; simp [sin_three_mul]
#align real.sin_three_mul Real.sin_three_mul
/-- The definition of `sinh` in terms of `exp`. -/
nonrec theorem sinh_eq (x : β) : sinh x = (exp x - exp (-x)) / 2 :=
ofReal_injective <| by simp [Complex.sinh]
#align real.sinh_eq Real.sinh_eq
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
#align real.sinh_zero Real.sinh_zero
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul]
#align real.sinh_neg Real.sinh_neg
nonrec theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [β ofReal_inj]; simp [sinh_add]
#align real.sinh_add Real.sinh_add
/-- The definition of `cosh` in terms of `exp`. -/
theorem cosh_eq (x : β) : cosh x = (exp x + exp (-x)) / 2 :=
eq_div_of_mul_eq two_ne_zero <| by
rw [cosh, exp, exp, Complex.ofReal_neg, Complex.cosh, mul_two, β Complex.add_re, β mul_two,
div_mul_cancel _ (two_ne_zero' β), Complex.add_re]
#align real.cosh_eq Real.cosh_eq
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
#align real.cosh_zero Real.cosh_zero
@[simp]
theorem cosh_neg : cosh (-x) = cosh x :=
ofReal_inj.1 <| by simp
#align real.cosh_neg Real.cosh_neg
@[simp]
theorem cosh_abs : cosh (|x|) = cosh x := by
cases le_total x 0 <;> simp [*, _root_.abs_of_nonneg, abs_of_nonpos]
#align real.cosh_abs Real.cosh_abs
nonrec theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [β ofReal_inj]; simp [cosh_add]
#align real.cosh_add Real.cosh_add
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
#align real.sinh_sub Real.sinh_sub
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
#align real.cosh_sub Real.cosh_sub
nonrec theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
ofReal_inj.1 <| by simp [tanh_eq_sinh_div_cosh]
#align real.tanh_eq_sinh_div_cosh Real.tanh_eq_sinh_div_cosh
@[simp]
theorem tanh_zero : tanh 0 = 0 := by simp [tanh]
#align real.tanh_zero Real.tanh_zero
@[simp]
theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div]
#align real.tanh_neg Real.tanh_neg
@[simp]
theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [β ofReal_inj]; simp
#align real.cosh_add_sinh Real.cosh_add_sinh
@[simp]
theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh]
#align real.sinh_add_cosh Real.sinh_add_cosh
@[simp]
theorem exp_sub_cosh : exp x - cosh x = sinh x :=
sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm
#align real.exp_sub_cosh Real.exp_sub_cosh
@[simp]
theorem exp_sub_sinh : exp x - sinh x = cosh x :=
sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm
#align real.exp_sub_sinh Real.exp_sub_sinh
@[simp]
theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by
rw [β ofReal_inj]
simp
#align real.cosh_sub_sinh Real.cosh_sub_sinh
@[simp]
theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [β neg_sub, cosh_sub_sinh]
#align real.sinh_sub_cosh Real.sinh_sub_cosh
@[simp]
theorem cosh_sq_sub_sinh_sq (x : β) : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [β ofReal_inj]; simp
#align real.cosh_sq_sub_sinh_sq Real.cosh_sq_sub_sinh_sq
nonrec theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [β ofReal_inj]; simp [cosh_sq]
#align real.cosh_sq Real.cosh_sq
theorem cosh_sq' : cosh x ^ 2 = 1 + sinh x ^ 2 :=
(cosh_sq x).trans (add_comm _ _)
#align real.cosh_sq' Real.cosh_sq'
nonrec theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [β ofReal_inj]; simp [sinh_sq]
#align real.sinh_sq Real.sinh_sq
nonrec theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by
rw [β ofReal_inj]; simp [cosh_two_mul]
#align real.cosh_two_mul Real.cosh_two_mul
nonrec theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by
rw [β ofReal_inj]; simp [sinh_two_mul]
#align real.sinh_two_mul Real.sinh_two_mul
nonrec theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by
rw [β ofReal_inj]; simp [cosh_three_mul]
#align real.cosh_three_mul Real.cosh_three_mul
nonrec theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by
rw [β ofReal_inj]; simp [sinh_three_mul]
#align real.sinh_three_mul Real.sinh_three_mul
open IsAbsoluteValue
/-- This is an intermediate result that is later replaced by `Real.add_one_le_exp`; use that lemma
instead. -/
theorem add_one_le_exp_of_nonneg {x : β} (hx : 0 β€ x) : x + 1 β€ exp x :=
calc
x + 1 β€ CauSeq.lim (β¨fun n : β => ((exp' x) n).re, isCauSeq_re (exp' x)β© : CauSeq β Abs.abs) :=
le_lim
(CauSeq.le_of_exists
β¨2, fun j hj =>
show x + (1 : β) β€ (β m in range j, ((x : β) ^ m / m.factorial)).re by
have hβ : (((fun m : β => ((x : β) ^ m / m.factorial)) β Nat.succ) 0).re = x :=
by simp [show Nat.succ 0 = 1 from rfl, Complex.ofReal_re]
have hβ : ((x : β) ^ 0 / (Nat.factorial 0)).re = 1 := by simp
erw [β tsub_add_cancel_of_le hj, sum_range_succ', sum_range_succ', add_re, add_re, hβ,
hβ, add_assoc, β coe_reAddGroupHom, reAddGroupHom.map_sum,
coe_reAddGroupHom]
refine' le_add_of_nonneg_of_le (sum_nonneg fun m _ => _) le_rfl
rw [β ofReal_pow, β ofReal_nat_cast, β ofReal_div, ofReal_re]
exact div_nonneg (pow_nonneg hx _) (Nat.cast_nonneg _)β©)
_ = exp x := by rw [exp, Complex.exp, β cauSeqRe, lim_re]
#align real.add_one_le_exp_of_nonneg Real.add_one_le_exp_of_nonneg
theorem one_le_exp {x : β} (hx : 0 β€ x) : 1 β€ exp x := by linarith [add_one_le_exp_of_nonneg hx]
#align real.one_le_exp Real.one_le_exp
theorem exp_pos (x : β) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one β one_le_exp) fun h => by
rw [β neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
#align real.exp_pos Real.exp_pos
@[simp]
theorem abs_exp (x : β) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
#align real.abs_exp Real.abs_exp
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [β sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
#align real.exp_strict_mono Real.exp_strictMono
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
#align real.exp_monotone Real.exp_monotone
@[simp]
theorem exp_lt_exp {x y : β} : exp x < exp y β x < y :=
exp_strictMono.lt_iff_lt
#align real.exp_lt_exp Real.exp_lt_exp
@[simp]
theorem exp_le_exp {x y : β} : exp x β€ exp y β x β€ y :=
exp_strictMono.le_iff_le
#align real.exp_le_exp Real.exp_le_exp
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
#align real.exp_injective Real.exp_injective
@[simp]
theorem exp_eq_exp {x y : β} : exp x = exp y β x = y :=
exp_injective.eq_iff
#align real.exp_eq_exp Real.exp_eq_exp
@[simp]
theorem exp_eq_one_iff : exp x = 1 β x = 0 :=
exp_injective.eq_iff' exp_zero
#align real.exp_eq_one_iff Real.exp_eq_one_iff
@[simp]
theorem one_lt_exp_iff {x : β} : 1 < exp x β 0 < x := by rw [β exp_zero, exp_lt_exp]
#align real.one_lt_exp_iff Real.one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : β} : exp x < 1 β x < 0 := by rw [β exp_zero, exp_lt_exp]
#align real.exp_lt_one_iff Real.exp_lt_one_iff
@[simp]
theorem exp_le_one_iff {x : β} : exp x β€ 1 β x β€ 0 :=
exp_zero βΈ exp_le_exp
#align real.exp_le_one_iff Real.exp_le_one_iff
@[simp]
theorem one_le_exp_iff {x : β} : 1 β€ exp x β 0 β€ x :=
exp_zero βΈ exp_le_exp
#align real.one_le_exp_iff Real.one_le_exp_iff
/-- `real.cosh` is always positive -/
theorem cosh_pos (x : β) : 0 < Real.cosh x :=
(cosh_eq x).symm βΈ half_pos (add_pos (exp_pos x) (exp_pos (-x)))
#align real.cosh_pos Real.cosh_pos
theorem sinh_lt_cosh : sinh x < cosh x :=
lt_of_pow_lt_pow 2 (cosh_pos _).le <| (cosh_sq x).symm βΈ lt_add_one _
#align real.sinh_lt_cosh Real.sinh_lt_cosh
end Real
namespace Complex
theorem sum_div_factorial_le {Ξ± : Type _} [LinearOrderedField Ξ±] (n j : β) (hn : 0 < n) :
(β m in filter (fun k => n β€ k) (range j),
(1 / m.factorial : Ξ±)) β€ n.succ / (n.factorial * n) :=
calc
(β m in filter (fun k => n β€ k) (range j), (1 / m.factorial : Ξ±)) =
β m in range (j - n), (1 / ((m + n).factorial : Ξ±)) :=
sum_bij (fun m _ => m - n)
(fun m hm =>
mem_range.2 <|
(tsub_lt_tsub_iff_right (by simp at hm; tauto)).2 (by simp at hm; tauto))
(fun m hm => by rw [tsub_add_cancel_of_le]; simp at *; tauto)
(fun aβ aβ haβ haβ h => by
rwa [tsub_eq_iff_eq_add_of_le, tsub_add_eq_add_tsub, eq_comm, tsub_eq_iff_eq_add_of_le,
add_left_inj, eq_comm] at h <;>
simp at * <;> aesop)
fun b hb =>
β¨b + n,
mem_filter.2 β¨mem_range.2 <| lt_tsub_iff_right.mp (mem_range.1 hb), Nat.le_add_left _ _β©,
by dsimp; rw [add_tsub_cancel_right]β©
_ β€ β m in range (j - n), ((n.factorial : Ξ±) * (n.succ : Ξ±) ^ m)β»ΒΉ := by
refine' sum_le_sum fun m _ => _
rw [one_div, inv_le_inv]
Β· rw [β Nat.cast_pow, β Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
Β· exact Nat.cast_pos.2 (Nat.factorial_pos _)
Β· exact mul_pos (Nat.cast_pos.2 (Nat.factorial_pos _))
(pow_pos (Nat.cast_pos.2 (Nat.succ_pos _)) _)
_ = (n.factorial : Ξ±)β»ΒΉ * β m in range (j - n), (n.succ : Ξ±)β»ΒΉ ^ m := by
simp [mul_inv, mul_sum.symm, sum_mul.symm, -Nat.factorial_succ, mul_comm, inv_pow]
_ = ((n.succ : Ξ±) - n.succ * (n.succ : Ξ±)β»ΒΉ ^ (j - n)) / (n.factorial * n) :=
by
have hβ : (n.succ : Ξ±) β 1 :=
@Nat.cast_one Ξ± _ βΈ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have hβ : (n.succ : Ξ±) β 0 := Nat.cast_ne_zero.2 (Nat.succ_ne_zero _)
have hβ : (n.factorial * n : Ξ±) β 0 :=
mul_ne_zero (Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.factorial_pos _)))
(Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 hn))
have hβ : (n.succ - 1 : Ξ±) = n := by simp
rw [geom_sum_inv hβ hβ, eq_div_iff_mul_eq hβ, mul_comm _ (n.factorial * n : Ξ±),
β mul_assoc (n.factorialβ»ΒΉ : Ξ±), β mul_inv_rev, hβ, β mul_assoc (n.factorial * n : Ξ±),
mul_comm (n : Ξ±) n.factorial, mul_inv_cancel hβ, one_mul, mul_comm]
_ β€ n.succ / (n.factorial * n : Ξ±) :=
by
refine' Iff.mpr (div_le_div_right (mul_pos _ _)) _
exact Nat.cast_pos.2 (Nat.factorial_pos _)
exact Nat.cast_pos.2 hn
exact
sub_le_self _
(mul_nonneg (Nat.cast_nonneg _) (pow_nonneg (inv_nonneg.2 (Nat.cast_nonneg _)) _))
#align complex.sum_div_factorial_le Complex.sum_div_factorial_le
theorem exp_bound {x : β} (hx : abs x β€ 1) {n : β} (hn : 0 < n) :
abs (exp x - β m in range n, x ^ m / m.factorial) β€
abs x ^ n * ((n.succ : β) * (n.factorial * n : β)β»ΒΉ) := by
rw [β lim_const (abv := Complex.abs) (β m in range n, _), exp, sub_eq_add_neg,
β lim_neg, lim_add, β lim_abs]
refine' lim_le (CauSeq.le_of_exists β¨n, fun j hj => _β©)
simp_rw [β sub_eq_add_neg]
show
abs ((β m in range j, x ^ m / m.factorial) - β m in range n, x ^ m / m.factorial) β€
abs x ^ n * ((n.succ : β) * (n.factorial * n : β)β»ΒΉ)
rw [sum_range_sub_sum_range hj]
calc
abs (β m in (range j).filter fun k => n β€ k, (x ^ m / m.factorial : β)) =
abs (β m in (range j).filter fun k => n β€ k, (x ^ n * (x ^ (m - n) / m.factorial) : β)) :=
by
refine' congr_arg abs (sum_congr rfl fun m hm => _)
rw [mem_filter, mem_range] at hm
rw [β mul_div_assoc, β pow_add, add_tsub_cancel_of_le hm.2]
_ β€ β m in filter (fun k => n β€ k) (range j), abs (x ^ n * (x ^ (m - n) / m.factorial)) :=
(abv_sum_le_sum_abv (abv := Complex.abs) _ _)
_ β€ β m in filter (fun k => n β€ k) (range j), abs x ^ n * (1 / m.factorial) :=
by
refine' sum_le_sum fun m _ => _
rw [map_mul, map_pow, map_divβ, abs_cast_nat]
refine' mul_le_mul_of_nonneg_left ((div_le_div_right _).2 _) _
Β· exact Nat.cast_pos.2 (Nat.factorial_pos _)
Β· rw [abv_pow abs]
exact pow_le_one _ (abs.nonneg _) hx
Β· exact pow_nonneg (abs.nonneg _) _
_ = abs x ^ n * β m in (range j).filter fun k => n β€ k, (1 / m.factorial : β) := by
simp [abs_mul, abv_pow abs, abs_div, mul_sum.symm]
_ β€ abs x ^ n * (n.succ * (n.factorial * n : β)β»ΒΉ) :=
mul_le_mul_of_nonneg_left (sum_div_factorial_le _ _ hn) (pow_nonneg (abs.nonneg _) _)
#align complex.exp_bound Complex.exp_bound
theorem exp_bound' {x : β} {n : β} (hx : abs x / n.succ β€ 1 / 2) :
abs (exp x - β m in range n, x ^ m / m.factorial) β€ abs x ^ n / n.factorial * 2 := by
rw [β lim_const (abv := Complex.abs) (β m in range n, _),
exp, sub_eq_add_neg, β lim_neg, lim_add, β lim_abs]
refine' lim_le (CauSeq.le_of_exists β¨n, fun j hj => _β©)
simp_rw [β sub_eq_add_neg]
show abs ((β m in range j, x ^ m / m.factorial) - β m in range n, x ^ m / m.factorial) β€
abs x ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
abs (β i : β in range k, x ^ (n + i) / ((n + i).factorial : β)) β€
β i : β in range k, abs (x ^ (n + i) / ((n + i).factorial : β)) :=
abv_sum_le_sum_abv _ _
_ β€ β i : β in range k, abs x ^ (n + i) / (n + i).factorial := by
simp [Complex.abs_cast_nat, map_divβ, abv_pow abs]
_ β€ β i : β in range k, abs x ^ (n + i) / ((n.factorial : β) * (n.succ : β) ^ i) := ?_
_ = β i : β in range k, abs x ^ n / n.factorial * (abs x ^ i / (n.succ : β) ^ i) := ?_
_ β€ abs x ^ n / βn.factorial * 2 := ?_
Β· refine' sum_le_sum fun m _ => div_le_div (pow_nonneg (abs.nonneg x) (n + m)) le_rfl _ _
Β· exact_mod_cast mul_pos n.factorial_pos (pow_pos n.succ_pos _)
Β· exact_mod_cast Nat.factorial_mul_pow_le_factorial
Β· refine' Finset.sum_congr rfl fun _ _ => _
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
Β· rw [β mul_sum]
apply mul_le_mul_of_nonneg_left
Β· simp_rw [β div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
Β· trans (-1 : β)
Β· -- Porting note: was linarith
simp [Nat.succ_eq_add_one] at hx
rw [mul_comm, β le_div_iff]
simp [hx]
. norm_num [this, hx]
simp [hx]
. exact zero_lt_two
Β· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
exact
div_nonneg (pow_nonneg (abs.nonneg x) k)
(pow_nonneg (add_nonneg n.cast_nonneg zero_le_one) k)
Β· -- Porting note: was linarith
simp [Nat.succ_eq_add_one] at hx
simp
apply lt_of_le_of_lt hx
norm_num
Β· -- Porting note: was linarith
intro h
simp at h
simp [h] at hx
norm_num at hx
Β· exact div_nonneg (pow_nonneg (abs.nonneg x) n) (Nat.cast_nonneg n.factorial)
#align complex.exp_bound' Complex.exp_bound'
theorem abs_exp_sub_one_le {x : β} (hx : abs x β€ 1) : abs (exp x - 1) β€ 2 * abs x :=
calc
abs (exp x - 1) = abs (exp x - β m in range 1, x ^ m / m.factorial) := by simp [sum_range_succ]
_ β€ abs x ^ 1 * ((Nat.succ 1 : β) * ((Nat.factorial 1) * (1 : β) : β)β»ΒΉ) :=
(exp_bound hx (by decide))
_ = 2 * abs x := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul]
#align complex.abs_exp_sub_one_le Complex.abs_exp_sub_one_le
theorem abs_exp_sub_one_sub_id_le {x : β} (hx : abs x β€ 1) : abs (exp x - 1 - x) β€ abs x ^ 2 :=
calc
abs (exp x - 1 - x) = abs (exp x - β m in range 2, x ^ m / m.factorial) := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc]
_ β€ abs x ^ 2 * ((Nat.succ 2 : β) * (Nat.factorial 2 * (2 : β) : β)β»ΒΉ) :=
(exp_bound hx (by decide))
_ β€ abs x ^ 2 * 1 := (mul_le_mul_of_nonneg_left (by norm_num) (sq_nonneg (abs x)))
_ = abs x ^ 2 := by rw [mul_one]
#align complex.abs_exp_sub_one_sub_id_le Complex.abs_exp_sub_one_sub_id_le
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : β} (hx : |x| β€ 1) {n : β} (hn : 0 < n) :
|exp x - β m in range n, x ^ m / m.factorial| β€ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : Complex.abs x β€ 1 := by exact_mod_cast hx
convert exp_bound hxc hn using 2 <;>
--Porting note: was `norm_cast`
simp only [β abs_ofReal, β ofReal_sub, β ofReal_exp, β ofReal_sum, β ofReal_pow,
β ofReal_div, β ofReal_nat_cast]
#align real.exp_bound Real.exp_bound
theorem exp_bound' {x : β} (h1 : 0 β€ x) (h2 : x β€ 1) {n : β} (hn : 0 < n) :
Real.exp x β€ (β m in Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| β€ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
#align real.exp_bound' Real.exp_bound'
theorem abs_exp_sub_one_le {x : β} (hx : |x| β€ 1) : |exp x - 1| β€ 2 * |x| := by
have : abs' x β€ 1 := by exact_mod_cast hx
--Porting note: was
--exact_mod_cast Complex.abs_exp_sub_one_le (x := x) this
have := Complex.abs_exp_sub_one_le (x := x) (by simpa using this)
rw [β ofReal_exp, β ofReal_one, β ofReal_sub, abs_ofReal, abs_ofReal] at this
exact this
#align real.abs_exp_sub_one_le Real.abs_exp_sub_one_le
theorem abs_exp_sub_one_sub_id_le {x : β} (hx : |x| β€ 1) : |exp x - 1 - x| β€ x ^ 2 := by
rw [β _root_.sq_abs]
--Porting note: was
--exact_mod_cast Complex.abs_exp_sub_one_sub_id_le this
have : Complex.abs x β€ 1 := by exact_mod_cast hx
have := Complex.abs_exp_sub_one_sub_id_le this
rw [β ofReal_one, β ofReal_exp, β ofReal_sub, β ofReal_sub, abs_ofReal, abs_ofReal] at this
exact this
#align real.abs_exp_sub_one_sub_id_le Real.abs_exp_sub_one_sub_id_le
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r βΆ exp x` as `n βΆ β`,
for any `r`. -/
noncomputable def expNear (n : β) (x r : β) : β :=
(β m in range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
#align real.exp_near Real.expNear
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
#align real.exp_near_zero Real.expNear_zero
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv]
ac_rfl
#align real.exp_near_succ Real.expNear_succ
theorem expNear_sub (n x rβ rβ) : expNear n x rβ -
expNear n x rβ = x ^ n / n.factorial * (rβ - rβ) := by
simp [expNear, mul_sub]
#align real.exp_near_sub Real.expNear_sub
theorem exp_approx_end (n m : β) (x : β) (eβ : n + 1 = m) (h : |x| β€ 1) :
|exp x - expNear m x 0| β€ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp [expNear]
convert exp_bound (n := m) h ?_ using 1
field_simp [mul_comm]
linarith
#align real.exp_approx_end Real.exp_approx_end
theorem exp_approx_succ {n} {x aβ bβ : β} (m : β) (eβ : n + 1 = m) (aβ bβ : β)
(e : |1 + x / m * aβ - aβ| β€ bβ - |x| / m * bβ)
(h : |exp x - expNear m x aβ| β€ |x| ^ m / m.factorial * bβ) :
|exp x - expNear n x aβ| β€ |x| ^ n / n.factorial * bβ := by
refine' (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans _)
subst eβ; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := abs' x ^ n / β(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
Β· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, β pow_abs, mul_inv]
ac_rfl
Β· simp [div_nonneg, abs_nonneg]
#align real.exp_approx_succ Real.exp_approx_succ
theorem exp_approx_end' {n} {x a b : β} (m : β) (eβ : n + 1 = m) (rm : β) (er : βm = rm)
(h : |x| β€ 1) (e : |1 - a| β€ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| β€ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ eβ _ _ (by simpa using e) (exp_approx_end _ _ _ eβ h)
#align real.exp_approx_end' Real.exp_approx_end'
theorem exp_1_approx_succ_eq {n} {aβ bβ : β} {m : β} (en : n + 1 = m) {rm : β} (er : βm = rm)
(h : |exp 1 - expNear m 1 ((aβ - 1) * rm)| β€ |1| ^ m / m.factorial * (bβ * rm)) :
|exp 1 - expNear n 1 aβ| β€ |1| ^ n / n.factorial * bβ := by
subst er
refine' exp_approx_succ _ en _ _ _ h
field_simp [show (m : β) β 0 by norm_cast; linarith]
#align real.exp_1_approx_succ_eq Real.exp_1_approx_succ_eq
theorem exp_approx_start (x a b : β) (h : |exp x - expNear 0 x a| β€ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| β€ b := by simpa using h
#align real.exp_approx_start Real.exp_approx_start
theorem cos_bound {x : β} (hx : |x| β€ 1) : |cos x - (1 - x ^ 2 / 2)| β€ |x| ^ 4 * (5 / 96) :=
calc
|cos x - (1 - x ^ 2 / 2)| = Complex.abs (Complex.cos x - (1 - (x : β) ^ 2 / 2)) := by
rw [β abs_ofReal]; simp
_ = Complex.abs ((Complex.exp (x * I) + Complex.exp (-x * I) - (2 - (x : β) ^ 2)) / 2) := by
simp [Complex.cos, sub_div, add_div, neg_div, div_self (two_ne_zero' β)]
_ = abs
(((Complex.exp (x * I) - β m in range 4, (x * I) ^ m / m.factorial) +
(Complex.exp (-x * I) - β m in range 4, (-x * I) ^ m / m.factorial)) / 2) :=
(congr_arg Complex.abs
(congr_arg (fun x : β => x / 2)
(by
simp only [sum_range_succ]
simp [pow_succ]
apply Complex.ext <;> simp [div_eq_mul_inv, normSq] <;> ring_nf
)))
_ β€ abs ((Complex.exp (x * I) - β m in range 4, (x * I) ^ m / m.factorial) / 2) +
abs ((Complex.exp (-x * I) - β m in range 4, (-x * I) ^ m / m.factorial) / 2) :=
by rw [add_div]; exact Complex.abs.add_le _ _
_ = abs (Complex.exp (x * I) - β m in range 4, (x * I) ^ m / m.factorial) / 2 +
abs (Complex.exp (-x * I) - β m in range 4, (-x * I) ^ m / m.factorial) / 2 :=
by simp [map_divβ]
_ β€ Complex.abs (x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : β) : β)β»ΒΉ) / 2 +
Complex.abs (-x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : β) : β)β»ΒΉ) / 2 :=
(add_le_add ((div_le_div_right (by norm_num)).2 (Complex.exp_bound (by simpa) (by decide)))
((div_le_div_right (by norm_num)).2 (Complex.exp_bound (by simpa) (by decide))))
_ β€ |x| ^ 4 * (5 / 96) := by norm_num
#align real.cos_bound Real.cos_bound
theorem sin_bound {x : β} (hx : |x| β€ 1) : |sin x - (x - x ^ 3 / 6)| β€ |x| ^ 4 * (5 / 96) :=
calc
|sin x - (x - x ^ 3 / 6)| = Complex.abs (Complex.sin x - (x - x ^ 3 / 6 : β)) := by
rw [β abs_ofReal]; simp
_ = Complex.abs (((Complex.exp (-x * I) - Complex.exp (x * I)) * I -
(2 * x - x ^ 3 / 3 : β)) / 2) := by
simp [Complex.sin, sub_div, add_div, neg_div, mul_div_cancel_left _ (two_ne_zero' β), div_div,
show (3 : β) * 2 = 6 by norm_num]
_ = Complex.abs (((Complex.exp (-x * I) - β m in range 4, (-x * I) ^ m / m.factorial) -
(Complex.exp (x * I) - β m in range 4, (x * I) ^ m / m.factorial)) * I / 2) :=
(congr_arg Complex.abs
(congr_arg (fun x : β => x / 2)
(by
simp only [sum_range_succ]
simp [pow_succ]
apply Complex.ext <;> simp [div_eq_mul_inv, normSq]; ring)))
_ β€ abs ((Complex.exp (-x * I) - β m in range 4, (-x * I) ^ m / m.factorial) * I / 2) +
abs (-((Complex.exp (x * I) - β m in range 4, (x * I) ^ m / m.factorial) * I) / 2) :=
by rw [sub_mul, sub_eq_add_neg, add_div]; exact Complex.abs.add_le _ _
_ = abs (Complex.exp (x * I) - β m in range 4, (x * I) ^ m / m.factorial) / 2 +
abs (Complex.exp (-x * I) - β m in range 4, (-x * I) ^ m / m.factorial) / 2 :=
by simp [add_comm, map_divβ]
_ β€ Complex.abs (x * I) ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : β) : β)β»ΒΉ) / 2 +
Complex.abs (-x * I) ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : β) : β)β»ΒΉ) / 2 :=
(add_le_add ((div_le_div_right (by norm_num)).2 (Complex.exp_bound (by simpa) (by decide)))
((div_le_div_right (by norm_num)).2 (Complex.exp_bound (by simpa) (by decide))))
_ β€ |x| ^ 4 * (5 / 96) := by norm_num
#align real.sin_bound Real.sin_bound
theorem cos_pos_of_le_one {x : β} (hx : |x| β€ 1) : 0 < cos x :=
calc 0 < 1 - x ^ 2 / 2 - |x| ^ 4 * (5 / 96) :=
sub_pos.2 <|
lt_sub_iff_add_lt.2
(calc
|x| ^ 4 * (5 / 96) + x ^ 2 / 2 β€ 1 * (5 / 96) + 1 / 2 :=
add_le_add (mul_le_mul_of_nonneg_right (pow_le_one _ (abs_nonneg _) hx) (by norm_num))
((div_le_div_right (by norm_num)).2
(by
rw [sq, β abs_mul_self, abs_mul]
exact mul_le_one hx (abs_nonneg _) hx))
_ < 1 := by norm_num)
_ β€ cos x := sub_le_comm.1 (abs_sub_le_iff.1 (cos_bound hx)).2
#align real.cos_pos_of_le_one Real.cos_pos_of_le_one
theorem sin_pos_of_pos_of_le_one {x : β} (hx0 : 0 < x) (hx : x β€ 1) : 0 < sin x :=
calc 0 < x - x ^ 3 / 6 - |x| ^ 4 * (5 / 96) :=
sub_pos.2 <| lt_sub_iff_add_lt.2
(calc
|x| ^ 4 * (5 / 96) + x ^ 3 / 6 β€ x * (5 / 96) + x / 6 :=
add_le_add
(mul_le_mul_of_nonneg_right
(calc
|x| ^ 4 β€ |x| ^ 1 :=
pow_le_pow_of_le_one (abs_nonneg _)
(by rwa [_root_.abs_of_nonneg (le_of_lt hx0)]) (by decide)
_ = x := by simp [_root_.abs_of_nonneg (le_of_lt hx0)]
)
(by norm_num))
((div_le_div_right (by norm_num)).2
(calc
x ^ 3 β€ x ^ 1 := pow_le_pow_of_le_one (le_of_lt hx0) hx (by decide)
_ = x := pow_one _
))
--Porting note : was `_ < x := by linarith`
_ = x * (7 / 32) := by ring
_ < x := (mul_lt_iff_lt_one_right hx0).2 (by norm_num))
_ β€ sin x :=
sub_le_comm.1 (abs_sub_le_iff.1 (sin_bound (by rwa [_root_.abs_of_nonneg (le_of_lt hx0)]))).2
#align real.sin_pos_of_pos_of_le_one Real.sin_pos_of_pos_of_le_one
theorem sin_pos_of_pos_of_le_two {x : β} (hx0 : 0 < x) (hx : x β€ 2) : 0 < sin x :=
have : x / 2 β€ 1 := (div_le_iff (by norm_num)).mpr (by simpa)
calc
0 < 2 * sin (x / 2) * cos (x / 2) :=
mul_pos (mul_pos (by norm_num) (sin_pos_of_pos_of_le_one (half_pos hx0) this))
(cos_pos_of_le_one (by rwa [_root_.abs_of_nonneg (le_of_lt (half_pos hx0))]))
_ = sin x := by rw [β sin_two_mul, two_mul, add_halves]
#align real.sin_pos_of_pos_of_le_two Real.sin_pos_of_pos_of_le_two
theorem cos_one_le : cos 1 β€ 2 / 3 :=
calc
cos 1 β€ |(1 : β)| ^ 4 * (5 / 96) + (1 - 1 ^ 2 / 2) :=
sub_le_iff_le_add.1 (abs_sub_le_iff.1 (cos_bound (by simp))).1
_ β€ 2 / 3 := by norm_num
#align real.cos_one_le Real.cos_one_le
theorem cos_one_pos : 0 < cos 1 :=
cos_pos_of_le_one (le_of_eq abs_one)
#align real.cos_one_pos Real.cos_one_pos
theorem cos_two_neg : cos 2 < 0 :=
calc cos 2 = cos (2 * 1) := congr_arg cos (mul_one _).symm
_ = _ := (Real.cos_two_mul 1)
_ β€ 2 * (2 / 3) ^ 2 - 1 :=
(sub_le_sub_right
(mul_le_mul_of_nonneg_left
(by
rw [sq, sq]
exact mul_self_le_mul_self (le_of_lt cos_one_pos) cos_one_le)
zero_le_two) _)
_ < 0 := by norm_num
#align real.cos_two_neg Real.cos_two_neg
--Porting note: removed `(h1 : 0 β€ x)` because it is no longer used
theorem exp_bound_div_one_sub_of_interval_approx {x : β} (h2 : x β€ 1) :
(β j : β in Finset.range 3, x ^ j / j.factorial) +
x ^ 3 * ((3 : β) + 1) / ((3 : β).factorial * (3 : β)) β€
β j in Finset.range 3, x ^ j :=
calc
(β j : β in Finset.range 3, x ^ j / j.factorial) +
x ^ 3 * ((3 : β) + 1) / ((3 : β).factorial * (3 : β))
= (2 / 9) * x ^ 3 + x ^ 2 / 2 + x + 1 := by simp [Finset.sum]; ring
_ β€ x ^ 2 + x + 1 := sub_nonneg.1 <|
calc 0 β€ x^2 * (2 / 9) * (9 / 4 - x) :=
mul_nonneg (mul_nonneg (pow_two_nonneg _) (by norm_num : (0 : β) β€ 2 / 9))
(sub_nonneg.2 (le_trans h2 (by norm_num)))
_ = _ := by ring
_ = _ := by simp [Finset.sum]; ring
#align real.exp_bound_div_one_sub_of_interval_approx Real.exp_bound_div_one_sub_of_interval_approxβ
theorem exp_bound_div_one_sub_of_interval {x : β} (h1 : 0 β€ x) (h2 : x < 1) :
Real.exp x β€ 1 / (1 - x) :=
haveI h : (β j in Finset.range 3, x ^ j) β€ 1 / (1 - x) :=
by
norm_num [Finset.sum]
have h1x : 0 < 1 - x := by simpa
rw [inv_eq_one_div, le_div_iff h1x]
norm_num [β add_assoc, mul_sub_left_distrib, mul_one, add_mul, sub_add_eq_sub_sub,
pow_succ' x 2]
have hx3 : 0 β€ x ^ 3 := by
norm_num
simp [h1]
simp [Finset.sum]
linarith
(exp_bound' h1 h2.le <| by linarith).trans
((exp_bound_div_one_sub_of_interval_approx h2.le).trans h)
#align real.exp_bound_div_one_sub_of_interval Real.exp_bound_div_one_sub_of_interval
theorem one_sub_le_exp_minus_of_pos {y : β} (h : 0 β€ y) : 1 - y β€ Real.exp (-y) := by
rw [Real.exp_neg]
have r1 : (1 - y) * Real.exp y β€ 1 :=
by
cases le_or_lt (1 - y) 0
Β· have h'' : (1 - y) * y.exp β€ 0 := by
rw [mul_nonpos_iff]
right
exact β¨by assumption, y.exp_pos.leβ©
linarith
have hy1 : y < 1 := by linarith
rw [β le_div_iff' βΉ0 < 1 - yβΊ]
exact exp_bound_div_one_sub_of_interval h hy1
rw [inv_eq_one_div]
rw [le_div_iff' y.exp_pos]
rwa [mul_comm] at r1
#align real.one_sub_le_exp_minus_of_pos Real.one_sub_le_exp_minus_of_pos
theorem add_one_le_exp_of_nonpos {x : β} (h : x β€ 0) : x + 1 β€ Real.exp x := by
rw [add_comm]
have h1 : 0 β€ -x := by linarith
simpa using one_sub_le_exp_minus_of_pos h1
#align real.add_one_le_exp_of_nonpos Real.add_one_le_exp_of_nonpos
theorem add_one_le_exp (x : β) : x + 1 β€ Real.exp x := by
cases' le_or_lt 0 x with h h
Β· exact Real.add_one_le_exp_of_nonneg h
exact add_one_le_exp_of_nonpos h.le
#align real.add_one_le_exp Real.add_one_le_exp
theorem one_sub_div_pow_le_exp_neg {n : β} {t : β} (ht' : t β€ n) : (1 - t / n) ^ n β€ exp (-t) := by
rcases eq_or_ne n 0 with (rfl | hn)
Β· simp
rwa [Nat.cast_zero] at ht'
convert pow_le_pow_of_le_left ?_ (add_one_le_exp (-(t / n))) n using 2
Β· abel
Β· rw [β Real.exp_nat_mul]
congr 1
field_simp [(Nat.cast_ne_zero (R := β)).mpr hn]
ring_nf
Β· rwa [add_comm, β sub_eq_add_neg, sub_nonneg, div_le_one]
positivity
#align real.one_sub_div_pow_le_exp_neg Real.one_sub_div_pow_le_exp_neg
end Real
namespace Tactic
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `real.exp` is always positive. -/
@[positivity Real.exp _]
def evalExp : Mathlib.Meta.Positivity.PositivityExt where eval {_ _} _ _ e := do
let (.app _ (a : Q(β))) β withReducible (whnf e) | throwError "not Real.exp"
pure (.positive (q(Real.exp_pos $a) : Lean.Expr))
end Tactic
namespace Complex
@[simp]
theorem abs_cos_add_sin_mul_I (x : β) : abs (cos x + sin x * I) = 1 := by
have := Real.sin_sq_add_cos_sq x
simp_all [add_comm, abs, normSq, sq, sin_ofReal_re, cos_ofReal_re, mul_re]
set_option linter.uppercaseLean3 false in
#align complex.abs_cos_add_sin_mul_I Complex.abs_cos_add_sin_mul_I
@[simp]
theorem abs_exp_ofReal (x : β) : abs (exp x) = Real.exp x := by
rw [β ofReal_exp]
exact abs_of_nonneg (le_of_lt (Real.exp_pos _))
#align complex.abs_exp_of_real Complex.abs_exp_ofReal
@[simp]
theorem abs_exp_ofReal_mul_I (x : β) : abs (exp (x * I)) = 1 := by
rw [exp_mul_I, abs_cos_add_sin_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.abs_exp_of_real_mul_I Complex.abs_exp_ofReal_mul_I
theorem abs_exp (z : β) : abs (exp z) = Real.exp z.re := by
rw [exp_eq_exp_re_mul_sin_add_cos, map_mul, abs_exp_ofReal, abs_cos_add_sin_mul_I, mul_one]
#align complex.abs_exp Complex.abs_exp
theorem abs_exp_eq_iff_re_eq {x y : β} : abs (exp x) = abs (exp y) β x.re = y.re := by
rw [abs_exp, abs_exp, Real.exp_eq_exp]
#align complex.abs_exp_eq_iff_re_eq Complex.abs_exp_eq_iff_re_eq
end Complex
|
options(bitmapType='cairo')
args <- commandArgs(trailingOnly=TRUE)
#args<-c(
#"/scratch/cqs/shengq1/brown/20170410_heatmap/result/TNF/TNF.gff.filelist",
#"blue",
#"TNF",
#"TRUE",
#getting mapped tables
gffFiles<-read.table(args[1], header=F, stringsAsFactor=F, sep="\t")
#set the plot color
plot_color= args[2]
#set the plot name
plot_name= args[3]
#set rpm
rpm_string = args[4]
if(rpm_string == "TRUE"){
rpm=TRUE
}else{
rpm= FALSE
}
print('RPM is:')
print(rpm_string)
plotHeatmaps <- function(mapped_data,plot_color,plot_path,names_list,rpm=TRUE){
if(rpm == TRUE){
y_title = 'rpm/bp'
}else{
y_title = 'raw reads/bp'
}
#setting up color scaling
colorSpectrum <- colorRampPalette(c("white",plot_color))(100)
minq <- function(x) { quantile(x, ra.rm=TRUE,prob=0.6) }
minValue = min(unlist(lapply(mapped_data, minq)))
print(paste('min value is', minValue))
maxq <- function(x) { quantile(x, ra.rm=TRUE,prob=0.95) }
maxValue = max(unlist(lapply(mapped_data, maxq)))
print(paste('max value is', maxValue))
color_cuts <- seq(minValue,maxValue,length=100)
trueMin = min(unlist(lapply(mapped_data, min)))
trueMax = max(unlist(lapply(mapped_data, max)))
color_cuts <- c(trueMin, color_cuts,trueMax)
colorSpectrum <- c(colorSpectrum[1],colorSpectrum)
referenceOrder = order(apply(mapped_data[[1]],1,mean,na.rm=TRUE))
png(filename=plot_path,width = 1500,height = 1600)
layout(matrix(data=c(1:length(mapped_data)),nrow=1))
for(mapIndex in c(1:length(mapped_data))){
data_matrix=mapped_data[[mapIndex]]
image(1:ncol(data_matrix),1:nrow(data_matrix),t(data_matrix[referenceOrder,]),breaks=color_cuts,col=colorSpectrum,xaxt="n",yaxt="n",xlab="",ylab="",main=names_list[mapIndex])
}
dev.off()
}
mapped_tables=lapply(gffFiles$V1, read.delim)
trans <- function(x) { as.matrix(x[,3:ncol(x)]) }
mapped_data<-lapply(mapped_tables, trans)
plot_path = paste0(plot_name,'.unscaled_heat.png')
print(plot_path)
plotHeatmaps(mapped_data,plot_color,plot_path,gffFiles$V2,rpm)
|
lemma csqrt_square: assumes "0 < Re b \<or> (Re b = 0 \<and> 0 \<le> Im b)" shows "csqrt (b^2) = b" |
(*
This file is a part of IsarMathLib -
a library of formalized mathematics for Isabelle/Isar.
Copyright (C) 2005, 2006 Slawomir Kolodynski
This program is free software; Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)
section \<open>Finite sets\<close>
theory Finite1 imports ZF.EquivClass ZF.Finite func1 ZF1
begin
text\<open>This theory extends Isabelle standard \<open>Finite\<close> theory.
It is obsolete and should not be used for new development.
Use the \<open>Finite_ZF\<close> instead.\<close>
subsection\<open>Finite powerset\<close>
text\<open>In this section we consider various properties of \<open>Fin\<close>
datatype (even though there are no datatypes in ZF set theory).\<close>
(*text{*Intersection of a collection is contained in every element
of the collection.*}
lemma ZF11: assumes A: "A \<in> M" shows "\<Inter>M \<subseteq> A";
proof
fix x;
assume A1: "x \<in> \<Inter>M"
from A1 A show "x \<in> A" ..
qed;
text{*Intersection of a nonempty collection $M$ of subsets of
$X$ is a subset of $X$. *}
lemma ZF12: assumes A1: "\<forall>A\<in> M. A\<subseteq>X" and A2:"M\<noteq>0"
shows "(\<Inter> M) \<subseteq> X";
proof -;
from A2 have "\<forall> A\<in> M. (\<Inter> M \<subseteq> A)" using ZF11 by simp;
with A1 A2 show "(\<Inter> M) \<subseteq> X" by fast;
qed; *)
text\<open>In \<open>Topology_ZF\<close> theory we consider
induced topology that is
obtained by taking a subset of a topological space. To show that a topology
restricted to a subset is also a topology
on that subset we may need a fact that
if $T$ is a collection of sets and $A$ is a set then every finite collection
$\{ V_i \}$ is of the form $V_i=U_i \cap A$, where $\{U_i\}$ is a finite
subcollection of $T$. This is one of those trivial
facts that require suprisingly
long formal proof.
Actually, the need for this fact is avoided by requiring intersection
two open sets to be open (rather than intersection of
a finite number of open sets).
Still, the fact is left here as an example of a proof by induction.
We will use \<open>Fin_induct\<close> lemma from Finite.thy.
First we define a property of
finite sets that we want to show.\<close>
definition
"Prfin(T,A,M) \<equiv> ( (M = 0) | (\<exists>N\<in> Fin(T). \<forall>V\<in> M. \<exists> U\<in> N. (V = U\<inter>A)))"
text\<open>Now we show the main induction step in a separate lemma. This will make
the proof of the theorem FinRestr below look short and nice.
The premises of the \<open>ind_step\<close> lemma are those needed by
the main induction step in
lemma \<open>Fin_induct\<close> (see standard Isabelle's Finite.thy).\<close>
lemma ind_step: assumes A: "\<forall> V\<in> TA. \<exists> U\<in>T. V=U\<inter>A"
and A1: "W\<in>TA" and A2: "M\<in> Fin(TA)"
and A3: "W\<notin>M" and A4: "Prfin(T,A,M)"
shows "Prfin(T,A,cons(W,M))"
proof -
{ assume A7: "M=0" have "Prfin(T, A, cons(W, M))"
proof-
from A1 A obtain U where A5: "U\<in>T" and A6: "W=U\<inter>A" by fast
let ?N = "{U}"
from A5 have T1: "?N \<in> Fin(T)" by simp
from A7 A6 have T2: "\<forall>V\<in> cons(W,M). \<exists> U\<in>?N. V=U\<inter>A" by simp
from A7 T1 T2 show "Prfin(T, A, cons(W, M))"
using Prfin_def by auto
qed }
moreover
{ assume A8:"M\<noteq>0" have "Prfin(T, A, cons(W, M))"
proof-
from A1 A obtain U where A5: "U\<in>T" and A6:"W=U\<inter>A" by fast
from A8 A4 obtain N0
where A9: "N0\<in> Fin(T)" and A10: "\<forall>V\<in> M. \<exists> U0\<in> N0. (V = U0\<inter>A)"
using Prfin_def by auto
let ?N = "cons(U,N0)"
from A5 A9 have "?N \<in> Fin(T)" by simp
moreover from A10 A6 have "\<forall>V\<in> cons(W,M). \<exists> U\<in>?N. V=U\<inter>A" by simp
ultimately have "\<exists> N\<in> Fin(T).\<forall>V\<in> cons(W,M). \<exists> U\<in>N. V=U\<inter>A" by auto
with A8 show "Prfin(T, A, cons(W, M))"
using Prfin_def by simp
qed }
ultimately show ?thesis by auto
qed
text\<open>Now we are ready to prove the statement we need.\<close>
theorem FinRestr0: assumes A: "\<forall> V \<in> TA. \<exists> U\<in> T. V=U\<inter>A"
shows "\<forall> M\<in> Fin(TA). Prfin(T,A,M)"
proof -
{ fix M
assume "M \<in> Fin(TA)"
moreover have "Prfin(T,A,0)" using Prfin_def by simp
moreover
{ fix W M assume "W\<in>TA" "M\<in> Fin(TA)" "W\<notin>M" "Prfin(T,A,M)"
with A have "Prfin(T,A,cons(W,M))" by (rule ind_step) }
ultimately have "Prfin(T,A,M)" by (rule Fin_induct)
} thus ?thesis by simp
qed
text\<open>This is a different form of the above theorem:\<close>
theorem ZF1FinRestr:
assumes A1:"M\<in> Fin(TA)" and A2: "M\<noteq>0"
and A3: "\<forall> V\<in> TA. \<exists> U\<in> T. V=U\<inter>A"
shows "\<exists>N\<in> Fin(T). (\<forall>V\<in> M. \<exists> U\<in> N. (V = U\<inter>A)) \<and> N\<noteq>0"
proof -
from A3 A1 have "Prfin(T,A,M)" using FinRestr0 by blast
then have "\<exists>N\<in> Fin(T). \<forall>V\<in> M. \<exists> U\<in> N. (V = U\<inter>A)"
using A2 Prfin_def by simp
then obtain N where
D1:"N\<in> Fin(T) \<and> (\<forall>V\<in> M. \<exists> U\<in> N. (V = U\<inter>A))" by auto
with A2 have "N\<noteq>0" by auto
with D1 show ?thesis by auto
qed
text\<open>Purely technical lemma used in \<open>Topology_ZF_1\<close> to show
that if a topology is $T_2$, then it is $T_1$.\<close>
lemma Finite1_L2:
assumes A:"\<exists>U V. (U\<in>T \<and> V\<in>T \<and> x\<in>U \<and> y\<in>V \<and> U\<inter>V=0)"
shows "\<exists>U\<in>T. (x\<in>U \<and> y\<notin>U)"
proof -
from A obtain U V where D1:"U\<in>T \<and> V\<in>T \<and> x\<in>U \<and> y\<in>V \<and> U\<inter>V=0" by auto
with D1 show ?thesis by auto
qed
text\<open>A collection closed with respect to taking a union of two sets
is closed under taking finite unions. Proof by induction with
the induction step formulated in a separate lemma.\<close>
lemma Finite1_L3_IndStep:
assumes A1:"\<forall>A B. ((A\<in>C \<and> B\<in>C) \<longrightarrow> A\<union>B\<in>C)"
and A2: "A\<in>C" and A3: "N\<in>Fin(C)" and A4:"A\<notin>N" and A5:"\<Union>N \<in> C"
shows "\<Union>cons(A,N) \<in> C"
proof -
have "\<Union> cons(A,N) = A\<union> \<Union>N" by blast
with A1 A2 A5 show ?thesis by simp
qed
text\<open>The lemma: a collection closed with respect to taking a union of two sets
is closed under taking finite unions.\<close>
lemma Finite1_L3:
assumes A1: "0 \<in> C" and A2: "\<forall>A B. ((A\<in>C \<and> B\<in>C) \<longrightarrow> A\<union>B\<in>C)" and
A3: "N\<in> Fin(C)"
shows "\<Union>N\<in>C"
proof -
note A3
moreover from A1 have "\<Union>0 \<in> C" by simp
moreover
{ fix A N
assume "A\<in>C" "N\<in>Fin(C)" "A\<notin>N" "\<Union>N \<in> C"
with A2 have "\<Union>cons(A,N) \<in> C" by (rule Finite1_L3_IndStep) }
ultimately show "\<Union>N\<in> C" by (rule Fin_induct)
qed
text\<open>A collection closed with respect to taking a intersection of two sets
is closed under taking finite intersections.
Proof by induction with
the induction step formulated in a separate lemma. This is sligltly more
involved than the union case in \<open>Finite1_L3\<close>, because the intersection
of empty collection is undefined (or should be treated as such).
To simplify notation we define the property to be proven for finite sets
as a separate notion.
\<close>
definition
"IntPr(T,N) \<equiv> (N = 0 | \<Inter>N \<in> T)"
text\<open>The induction step.\<close>
lemma Finite1_L4_IndStep:
assumes A1: "\<forall>A B. ((A\<in>T \<and> B\<in>T) \<longrightarrow> A\<inter>B\<in>T)"
and A2: "A\<in>T" and A3:"N\<in>Fin(T)" and A4:"A\<notin>N" and A5:"IntPr(T,N)"
shows "IntPr(T,cons(A,N))"
proof -
{ assume A6: "N=0"
with A2 have "IntPr(T,cons(A,N))"
using IntPr_def by simp }
moreover
{ assume A7: "N\<noteq>0" have "IntPr(T, cons(A, N))"
proof -
from A7 A5 A2 A1 have "\<Inter>N \<inter> A \<in> T" using IntPr_def by simp
moreover from A7 have "\<Inter>cons(A, N) = \<Inter>N \<inter> A" by auto
ultimately show "IntPr(T, cons(A, N))" using IntPr_def by simp
qed }
ultimately show ?thesis by auto
qed
text\<open>The lemma.\<close>
lemma Finite1_L4:
assumes A1: "\<forall>A B. A\<in>T \<and> B\<in>T \<longrightarrow> A\<inter>B \<in> T"
and A2: "N\<in>Fin(T)"
shows "IntPr(T,N)"
proof -
note A2
moreover have "IntPr(T,0)" using IntPr_def by simp
moreover
{ fix A N
assume "A\<in>T" "N\<in>Fin(T)" "A\<notin>N" "IntPr(T,N)"
with A1 have "IntPr(T,cons(A,N))" by (rule Finite1_L4_IndStep) }
ultimately show "IntPr(T,N)" by (rule Fin_induct)
qed
text\<open>Next is a restatement of the above lemma that
does not depend on the IntPr meta-function.\<close>
lemma Finite1_L5:
assumes A1: "\<forall>A B. ((A\<in>T \<and> B\<in>T) \<longrightarrow> A\<inter>B\<in>T)"
and A2: "N\<noteq>0" and A3: "N\<in>Fin(T)"
shows "\<Inter>N \<in> T"
proof -
from A1 A3 have "IntPr(T,N)" using Finite1_L4 by simp
with A2 show ?thesis using IntPr_def by simp
qed
text\<open>The images of finite subsets by a meta-function are finite.
For example in topology if we have a finite collection of sets, then closing
each of them results in a finite collection of closed sets. This is a very
useful lemma with many unexpected applications.
The proof is by induction. The next lemma is the induction step.\<close>
lemma fin_image_fin_IndStep:
assumes "\<forall>V\<in>B. K(V)\<in>C"
and "U\<in>B" and "N\<in>Fin(B)" and "U\<notin>N" and "{K(V). V\<in>N}\<in>Fin(C)"
shows "{K(V). V\<in>cons(U,N)} \<in> Fin(C)"
using assms by simp
text\<open>The lemma:\<close>
lemma fin_image_fin:
assumes A1: "\<forall>V\<in>B. K(V)\<in>C" and A2: "N\<in>Fin(B)"
shows "{K(V). V\<in>N} \<in> Fin(C)"
proof -
note A2
moreover have "{K(V). V\<in>0} \<in> Fin(C)" by simp
moreover
{ fix U N
assume "U\<in>B" "N\<in>Fin(B)" "U\<notin>N" "{K(V). V\<in>N}\<in>Fin(C)"
with A1 have "{K(V). V\<in>cons(U,N)} \<in> Fin(C)"
by (rule fin_image_fin_IndStep) }
ultimately show ?thesis by (rule Fin_induct)
qed
text\<open>The image of a finite set is finite.\<close>
lemma Finite1_L6A: assumes A1: "f:X\<rightarrow>Y" and A2: "N \<in> Fin(X)"
shows "f``(N) \<in> Fin(Y)"
proof -
from A1 have "\<forall>x\<in>X. f`(x) \<in> Y"
using apply_type by simp
moreover note A2
ultimately have "{f`(x). x\<in>N} \<in> Fin(Y)"
by (rule fin_image_fin)
with A1 A2 show ?thesis
using FinD func_imagedef by simp
qed
text\<open>If the set defined by a meta-function is finite, then every set
defined by a composition of this meta function with another one is finite.\<close>
lemma Finite1_L6B:
assumes A1: "\<forall>x\<in>X. a(x) \<in> Y" and A2: "{b(y).y\<in>Y} \<in> Fin(Z)"
shows "{b(a(x)).x\<in>X} \<in> Fin(Z)"
proof -
from A1 have "{b(a(x)).x\<in>X} \<subseteq> {b(y).y\<in>Y}" by auto
with A2 show ?thesis using Fin_subset_lemma by blast
qed
text\<open>If the set defined by a meta-function is finite, then every set
defined by a composition of this meta function with another one is finite.\<close>
lemma Finite1_L6C:
assumes A1: "\<forall>y\<in>Y. b(y) \<in> Z" and A2: "{a(x). x\<in>X} \<in> Fin(Y)"
shows "{b(a(x)).x\<in>X} \<in> Fin(Z)"
proof -
let ?N = "{a(x). x\<in>X}"
from A1 A2 have "{b(y). y \<in> ?N} \<in> Fin(Z)"
by (rule fin_image_fin)
moreover have "{b(a(x)). x\<in>X} = {b(y). y\<in> ?N}"
by auto
ultimately show ?thesis by simp
qed
text\<open>Cartesian product of finite sets is finite.\<close>
lemma Finite1_L12: assumes A1: "A \<in> Fin(A)" and A2: "B \<in> Fin(B)"
shows "A\<times>B \<in> Fin(A\<times>B)"
proof -
have T1:"\<forall>a\<in>A. \<forall>b\<in>B. {\<langle> a,b\<rangle>} \<in> Fin(A\<times>B)" by simp
have "\<forall>a\<in>A. {{\<langle> a,b\<rangle>}. b \<in> B} \<in> Fin(Fin(A\<times>B))"
proof
fix a assume A3: "a \<in> A"
with T1 have "\<forall>b\<in>B. {\<langle> a,b\<rangle>} \<in> Fin(A\<times>B)"
by simp
moreover note A2
ultimately show "{{\<langle> a,b\<rangle>}. b \<in> B} \<in> Fin(Fin(A\<times>B))"
by (rule fin_image_fin)
qed
then have "\<forall>a\<in>A. \<Union> {{\<langle> a,b\<rangle>}. b \<in> B} \<in> Fin(A\<times>B)"
using Fin_UnionI by simp
moreover have
"\<forall>a\<in>A. \<Union> {{\<langle> a,b\<rangle>}. b \<in> B} = {a}\<times> B" by blast
ultimately have "\<forall>a\<in>A. {a}\<times> B \<in> Fin(A\<times>B)" by simp
moreover note A1
ultimately have "{{a}\<times> B. a\<in>A} \<in> Fin(Fin(A\<times>B))"
by (rule fin_image_fin)
then have "\<Union>{{a}\<times> B. a\<in>A} \<in> Fin(A\<times>B)"
using Fin_UnionI by simp
moreover have "\<Union>{{a}\<times> B. a\<in>A} = A\<times>B" by blast
ultimately show ?thesis by simp
qed
text\<open>We define the characterisic meta-function that is the identity
on a set and assigns a default value everywhere else.\<close>
definition
"Characteristic(A,default,x) \<equiv> (if x\<in>A then x else default)"
text\<open>A finite subset is a finite subset of itself.\<close>
lemma Finite1_L13:
assumes A1:"A \<in> Fin(X)" shows "A \<in> Fin(A)"
proof -
{ assume "A=0" hence "A \<in> Fin(A)" by simp }
moreover
{ assume A2: "A\<noteq>0" then obtain c where D1:"c\<in>A"
by auto
then have "\<forall>x\<in>X. Characteristic(A,c,x) \<in> A"
using Characteristic_def by simp
moreover note A1
ultimately have
"{Characteristic(A,c,x). x\<in>A} \<in> Fin(A)" by (rule fin_image_fin)
moreover from D1 have
"{Characteristic(A,c,x). x\<in>A} = A" using Characteristic_def by simp
ultimately have "A \<in> Fin(A)" by simp }
ultimately show ?thesis by blast
qed
text\<open>Cartesian product of finite subsets is a finite subset of
cartesian product.\<close>
lemma Finite1_L14: assumes A1: "A \<in> Fin(X)" "B \<in> Fin(Y)"
shows "A\<times>B \<in> Fin(X\<times>Y)"
proof -
from A1 have "A\<times>B \<subseteq> X\<times>Y" using FinD by auto
then have "Fin(A\<times>B) \<subseteq> Fin(X\<times>Y)" using Fin_mono by simp
moreover from A1 have "A\<times>B \<in> Fin(A\<times>B)"
using Finite1_L13 Finite1_L12 by simp
ultimately show ?thesis by auto
qed
text\<open>The next lemma is needed in the \<open>Group_ZF_3\<close> theory in a
couple of places.\<close>
lemma Finite1_L15:
assumes A1: "{b(x). x\<in>A} \<in> Fin(B)" "{c(x). x\<in>A} \<in> Fin(C)"
and A2: "f : B\<times>C\<rightarrow>E"
shows "{f`\<langle> b(x),c(x)\<rangle>. x\<in>A} \<in> Fin(E)"
proof -
from A1 have "{b(x). x\<in>A}\<times>{c(x). x\<in>A} \<in> Fin(B\<times>C)"
using Finite1_L14 by simp
moreover have
"{\<langle> b(x),c(x)\<rangle>. x\<in>A} \<subseteq> {b(x). x\<in>A}\<times>{c(x). x\<in>A}"
by blast
ultimately have T0: "{\<langle> b(x),c(x)\<rangle>. x\<in>A} \<in> Fin(B\<times>C)"
by (rule Fin_subset_lemma)
with A2 have T1: "f``{\<langle> b(x),c(x)\<rangle>. x\<in>A} \<in> Fin(E)"
using Finite1_L6A by auto
from T0 have "\<forall>x\<in>A. \<langle> b(x),c(x)\<rangle> \<in> B\<times>C"
using FinD by auto
with A2 have
"f``{\<langle> b(x),c(x)\<rangle>. x\<in>A} = {f`\<langle> b(x),c(x)\<rangle>. x\<in>A}"
using func1_1_L17 by simp
with T1 show ?thesis by simp
qed
text\<open>Singletons are in the finite powerset.\<close>
lemma Finite1_L16: assumes "x\<in>X" shows "{x} \<in> Fin(X)"
using assms emptyI consI by simp
text\<open>A special case of \<open>Finite1_L15\<close> where the second
set is a singleton. In \<open>Group_ZF_3\<close> theory this corresponds
to the situation where we multiply by a constant.\<close>
lemma Finite1_L16AA: assumes "{b(x). x\<in>A} \<in> Fin(B)"
and "c\<in>C" and "f : B\<times>C\<rightarrow>E"
shows "{f`\<langle> b(x),c\<rangle>. x\<in>A} \<in> Fin(E)"
proof -
from assms have
"\<forall>y\<in>B. f`\<langle>y,c\<rangle> \<in> E"
"{b(x). x\<in>A} \<in> Fin(B)"
using apply_funtype by auto
then show ?thesis by (rule Finite1_L6C)
qed
text\<open>First order version of the induction for the finite powerset.\<close>
lemma Finite1_L16B: assumes A1: "P(0)" and A2: "B\<in>Fin(X)"
and A3: "\<forall>A\<in>Fin(X).\<forall>x\<in>X. x\<notin>A \<and> P(A)\<longrightarrow>P(A\<union>{x})"
shows "P(B)"
proof -
note \<open>B\<in>Fin(X)\<close> and \<open>P(0)\<close>
moreover
{ fix A x
assume "x \<in> X" "A \<in> Fin(X)" "x \<notin> A" "P(A)"
moreover have "cons(x,A) = A\<union>{x}" by auto
moreover note A3
ultimately have "P(cons(x,A))" by simp }
ultimately show "P(B)" by (rule Fin_induct)
qed
subsection\<open>Finite range functions\<close>
text\<open>In this section we define functions
$f : X\rightarrow Y$, with the property that $f(X)$ is
a finite subset of $Y$. Such functions play a important
role in the construction of real numbers in the \<open>Real_ZF\<close> series.
\<close>
text\<open>Definition of finite range functions.\<close>
definition
"FinRangeFunctions(X,Y) \<equiv> {f:X\<rightarrow>Y. f``(X) \<in> Fin(Y)}"
text\<open>Constant functions have finite range.\<close>
lemma Finite1_L17: assumes "c\<in>Y" and "X\<noteq>0"
shows "ConstantFunction(X,c) \<in> FinRangeFunctions(X,Y)"
using assms func1_3_L1 func_imagedef func1_3_L2 Finite1_L16
FinRangeFunctions_def by simp
text\<open>Finite range functions have finite range.\<close>
lemma Finite1_L18: assumes "f \<in> FinRangeFunctions(X,Y)"
shows "{f`(x). x\<in>X} \<in> Fin(Y)"
using assms FinRangeFunctions_def func_imagedef by simp
text\<open>An alternative form of the definition of finite range functions.\<close>
lemma Finite1_L19: assumes "f:X\<rightarrow>Y"
and "{f`(x). x\<in>X} \<in> Fin(Y)"
shows "f \<in> FinRangeFunctions(X,Y)"
using assms func_imagedef FinRangeFunctions_def by simp
text\<open>A composition of a finite range function with another function is
a finite range function.\<close>
lemma Finite1_L20: assumes A1:"f \<in> FinRangeFunctions(X,Y)"
and A2: "g : Y\<rightarrow>Z"
shows "g O f \<in> FinRangeFunctions(X,Z)"
proof -
from A1 A2 have "g``{f`(x). x\<in>X} \<in> Fin(Z)"
using Finite1_L18 Finite1_L6A
by simp
with A1 A2 have "{(g O f)`(x). x\<in>X} \<in> Fin(Z)"
using FinRangeFunctions_def apply_funtype
func1_1_L17 comp_fun_apply by auto
with A1 A2 show ?thesis using
FinRangeFunctions_def comp_fun Finite1_L19
by auto
qed
text\<open>Image of any subset of the domain of a finite range function is finite.\<close>
lemma Finite1_L21:
assumes "f \<in> FinRangeFunctions(X,Y)" and "A\<subseteq>X"
shows "f``(A) \<in> Fin(Y)"
proof -
from assms have "f``(X) \<in> Fin(Y)" "f``(A) \<subseteq> f``(X)"
using FinRangeFunctions_def func1_1_L8
by auto
then show "f``(A) \<in> Fin(Y)" using Fin_subset_lemma
by blast
qed
end
|
[STATEMENT]
lemma compactin_euclidean_iff [simp]: "compactin euclidean S \<longleftrightarrow> compact S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. compactin euclidean S = compact S
[PROOF STEP]
by (simp add: compact_eq_Heine_Borel compactin_def) meson |
Later , Kody and Meri go to Mexico to celebrate their twentieth wedding anniversary , where Meri discussed her sadness about her infertility problems and the jealousy that has arisen from Kody 's engagement to Robyn . Kody proposes in vitro fertilisation , but she turns down the idea as she is only interested in a naturally occurring conception . As Robyn 's wedding approaches , the three sister wives help Robyn prepare , and they begin to bond . However , Kody upsets his wives when he reveals he secretly chose Robyn 's wedding dress himself , which makes Christine feel so betrayed that she angrily walks away in mid @-@ interview . Kody eventually apologizes , and the five reconcile . The first season finale ends with the wedding of Kody and Robyn , where Meri , Janelle , and Christine present her with a <unk> ring to welcome her into the family .
|
\documentclass[12pt]{article}
\usepackage[table]{xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{adjustbox}
\makeatletter
\def\ScaleIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
% fonts
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textgreek}
\usepackage[greek,english]{babel}
\usepackage{amsmath}
% Code highlight and colors
\usepackage{listings}
\lstset{
numbers=left,
tabsize=1,
basicstyle=\small\ttfamily,
breaklines=true
}
\usepackage{booktabs, tabularx, longtable}
\usepackage{csquotes}
\usepackage{authblk}
% Geometry block
\usepackage[letterpaper]{geometry}
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\title{Complex Ecological Networks}
\author[1,2]{Mathilde~Besson}
\author[1,2]{Eva~Delmas*}
\author[1,2]{TimothΓ©e~Poisot}
\author[2,3]{Dominique~Gravel}
\affil[1]{UniversitΓ© de MontrΓ©al, DΓ©partement de Sciences Biologiques}
\affil[2]{QuΓ©bec Centre for Biodiversity Sciences}
\affil[3]{UniversitΓ© de Sherbrooke, DΓ©partement de Biologie}
\begin{document}
\maketitle
\begin{abstract}
Introduction to ecological network
\end{abstract}
% pandoc-xnos: macro to create a caption without a prefix
\makeatletter
\long\def\@makenoprefixcaption#1#2{
\vskip\abovecaptionskip
\sbox\@tempboxa{#2}
\ifdim \wd\@tempboxa >\hsize
#2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}
\fi
\vskip\belowcaptionskip}
\makeatother
% pandoc-fignos: save original macros
\makeatletter
\let\@oldmakecaption=\@makecaption
\let\oldthefigure=\thefigure
\let\oldtheHfigure=\theHfigure
\makeatother
% pandoc-fignos: environment disables figure caption prefixes
\makeatletter
\newcounter{figno}
\newenvironment{no-prefix-figure-caption}{
\let\@makecaption=\@makenoprefixcaption
\renewcommand\thefigure{x.\thefigno}
\renewcommand\theHfigure{x.\thefigno}
\stepcounter{figno}
}{
\let\thefigure=\oldthefigure
\let\theHfigure=\oldtheHfigure
\let\@makecaption=\@oldmakecaption
\addtocounter{figure}{-1}
}
\makeatother
% pandoc-xnos: cleveref fakery
\newcommand{\plusnamesingular}{}
\newcommand{\starnamesingular}{}
\newcommand{\xrefname}[1]{\protect\renewcommand{\plusnamesingular}{#1}}
\newcommand{\Xrefname}[1]{\protect\renewcommand{\starnamesingular}{#1}}
\providecommand{\cref}{\plusnamesingular~\ref}
\providecommand{\Cref}{\starnamesingular~\ref}
\providecommand{\crefformat}[2]{}
\providecommand{\Crefformat}[2]{}
% pandoc-xnos: cleveref formatting
\crefformat{figure}{fig.~#2#1#3}
\Crefformat{figure}{Figure~#2#1#3}
\crefformat{table}{table~#2#1#3}
\Crefformat{table}{Table~#2#1#3}
\crefformat{equation}{eq.~#2#1#3}
\Crefformat{equation}{Equation~#2#1#3}
\section{Glossary}\label{glossary}
Adjacency matrix: square matrix representing species interactions. If
two species \(i\) and \(j\) interact, the intersection of the matrix at
\({i,j}\) will be 1, and if no interaction.
Assembly rules: Ecological processes that lead to a specific species'
composition of a community, \emph{e.g.} competition, predator-prey
interactions, arrival history, etc.
\textbf{Bipartite / Unipartite network} The entire representation of the
adjacency matrix offers an \emph{unipartite} network representation,
where the hierarchy between nodes and their position into the network is
not always visible (\emph{Figure 1}). On the contrary, a bipartite or
k-partite network is a hierarchical representation of the network
(\emph{Figure 2}), where nodes are separated depending on their position
or function into the network (\emph{e.g} pollinator-plant as bipartite
network).
Ecological interactions: Every type of contact between two species that
alters the abundance, biomass and/or behavior of one or both species.
Interactions can be trophic, mutualistic or antagonistic, directed or
undirected, weighted or unweighted.
Ecosystem functioning: Biotic and abiotic processes that regulate
ecosystem, allowing energy and matter flux between trophic levels and
between ecosystems, \emph{e.g.} biogeochemical cycles.
Graph theory: Mathematical framework used to model the relationship
between the objects of a network
Network structure: General shape of a network. It is commonly measured
using connectance, link distribution, general architecture (nestedness
and modularity), etc.
Nodes/Links, Vertices/Edges: Following graph theory, species are
represented as nodes (or vertices), and interactions between them are
represented by links (or edges).
Phylogenetic signal: tendency of phylogenetically close species to have
similar traits.
\section{Nomenclature}\label{nomenclature}
\(N\) population size
\(r\) growth rate
\(A\) adjacency matrix
\(\alpha\) interaction strength
\section{}\label{section}
\subsection{Introduction}\label{introduction}
In ecological systems (\emph{e.g.} communities), interactions between
components (\emph{e.g.} species) are organized in ways that are
non-random and constrained by sets of rules (see section X). The
organization of these interactions drives or changes some properties of
the community, such as its stability, productivity, or ability to resist
extinctions, which eventually feedback on the system organization. This
constant interplay between interaction organization and system functions
results in signatures on the system structure (\emph{e.g.} invariance in
key features of the system structure, see section X). Detecting and
analyzing these signatures gives us information on the system itself.
Studying the structure of ecological systems is necessary to gain
insights on the fundamental rules and processes that govern ecosystem
formation, maintenance and functioning.
The way interactions are organized can be studied by investigating the
structure of ecological networks. Designed to analyze the structure of a
studied system, the \emph{graph theory} is a mathematical framework
which seemed to be largely appropriate to answer ecological questions.
Every system can be abstracted by a \emph{graph}, a representation of
the system components organization (\emph{Figure 1a}). These components
are called \emph{nodes} and are linked together by \emph{edges}. These
combinations form the structure of the studied system. In an ecological
system, nodes can be individuals, populations, communities or landscape
patches and edges can represent trophic links, energetic flux, etc,
every kind of interaction. Both nodes and edges can carry additional
information such as weight (\emph{e.g.} species abundance, intensity of
the gene flow between two populations, etc.), location in space and
time, edges direction and sign and nodes labels (\emph{e.g.} species
identity). Specific informations can be attached to edges, modifying the
characteristics of the graph. Graphs can be \emph{directed} (\emph{i.e}
interaction goes from A to B) or \emph{undirected}, \emph{weighted}
(\emph{i.e} different strength of interaction among the network) or
\emph{unweighted} (\emph{Figures 1 and 2}). This information is
summarized mathematically in the \emph{adjacency matrix} (typically
named \(A\), see definition in glossary) (\emph{Figure 1b}). In this
paper, for simplicity, time and space, we decided to mostly focus on
\emph{Species Interaction Networks} (SIN). Ecological system such as
landscape, genetic or nutrient networks are not represented here, but
they can be studying following the same framework defined further
{[}\emph{ref}{]}.
Describing and understanding the structure of species interaction
networks is an active, and growing, field of ecological research. In
this contribution, we will give an overview of some of the most
prominent findings and areas of research from the last decade. Starting
from a discussion of some invariant properties of the structure of
species interaction networks, we will then discuss how this structure
affects ecological properties. We will follow by a discussion of the
ways ecological networks can be studied under familiar concepts from
ecological theory, and finally how this approach scales up to larger
temporal or spatial scales.
\begin{no-prefix-figure-caption}
\begin{figure}
\centering
\includegraphics[width=1.00000\textwidth]{Figures/figure1.pdf}
\caption{Figure 1: Graphical representation of a fictional ecological
network (a), where species are represented by circles and their directed
interactions by arrows. The representation is build from the adjacency
matrix (b). In an unipartite representation as this one, each species is
represented both as a column and a row. 1 indicates an interaction
between two species (e.g.~the green square in (b)), and 0 indicates the
absence of interaction. This matrix allows to calculate network
characteristics such as the connectance (c) and the degree distribution
(d). (c) represents the level of connection into the network and is
calculated as shown in the figure. (d) represents the distribution of
interaction per species. The circles size is relative to the amount of
interactions a species have (d1). This distribution is non-random and
generally follows a power-law distribution (d2). The network can be
split into subnets composed of 3 species, called motif (e). Among the 13
different possible motifs, we only represented the most commonly found
in natural communities.}
\end{figure}
\end{no-prefix-figure-caption}
\subsection{Invariants in ecological
networks}\label{invariants-in-ecological-networks}
One striking particularity of ecological networks is their consistency:
even though they depict interactions between different organisms across
all sorts of ecosystems, they all tend to look the same (Jordano,
Bascompte and Olesen, 2003). Remarkably, even when interactions among
species themselves vary (see section \textbf{x}), the overall network
structure tends to remain unchanged (Kemp, Evans, Augustyn and Ellis,
2017). Most ecological networks have a very specific degree distribution
(Williams, 2011) (\emph{Figure 1d}), whereby most species have a small
number of interactions, and a small proportions of species have a large
number of interactions. In food webs, which represent interactions
between preys and their predators, there is a well-described
relationship between the number of species and the number of
interactions: the number of interactions (\(L\)) increases
proportionally to the number of species (\(S\)) raised to some exponent,
or \(L \propto S^k\). Martinez (1992) suggested that this exponent is
approximately equal to 2, \emph{i.e.} the number of interactions is
proportional to the squared number of species. Brose, Ostling, Harrison
and Martinez (2004) show that this general relationship holds even
across space: it is possible to estimate how many interactions a species
will establish across its entire range. In some other instances,
networks may differ on some aspect of their structure, despite obeying
to a shared underlying principle. For example, Fortuna, Stouffer and
Olesen \emph{et al.} (2010) show that in networks with a low connectance
(\emph{Figure 1c}), nestedness (the degree to which the diet of
specialists and generalists overlaps -- \emph{Figure 2}) and modularity
(the tendency of species to form densely aggregated clusters --
\emph{Figure 2}) are positively correlated. In networks with higher
connectance, this became the opposite: networks with a large number of
interactions were either nested (and not modular) or modular (and not
nested). In the recent years, it emerged that many aspects of network
structure covary with connectance (Poisot and Gravel, 2014; Chagnon,
2015): this suggests that simply knowing how many species there are, and
how many interactions they establish, is already very informative about
the network structure.
\begin{no-prefix-figure-caption}
\begin{figure}
\centering
\includegraphics[width=1.00000\textwidth]{Figures/figure2.pdf}
\caption{Figure 2: Network topology, example of a fictional
plant-pollinator network. (a) shows a perfectly nested network, where
specialists pollinators are visiting plants embedded into the diet of
more generalist pollinators. (b) shows a perfectly modular network,
where sub-groups of species interact more strongly with each over than
with the rest of the network. (c) shows a random network. Two
representations are possibles. Top: Bipartite representation using nodes
and edges ; Bottom: Ordered interaction matrix. Here, we used striped
yellow squares instead of 1 for presence of interaction and empty
squares in absence of interaction.}
\end{figure}
\end{no-prefix-figure-caption}
Another remarkable generality of network structure is the distribution
of particular shapes of interconnection between three-species subsets.
Milo (2002) found that networks (not just ecological but other types of
networks such as neuronal or electronical networks as well) can be
characterized by the over or under representation of some of these
three-species subset, which they called motifs (\emph{Figure 1e}).
Motifs can be more broadly defined as being particular shapes of
interconnection between three or more nodes in networks at a frequency
significantly higher than those found in randomized networks.
Three-species motifs represent the simplest building blocks of networks,
and more importantly the typical interaction found in communities. As
such, they offer the possibility to integrate and test theories
developed on simple modules (\emph{e.g.} omnivory, McCann, Hastings and
Huxel (1998), Holt (1997)) in larger, more realistic networks. Food
webs, for example, are characterized by an over representation of linear
food chains and omnivory and an under representation of apparent and
exploitative competition (Bascompte and MeliΓ‘n, 2005; Camacho, Stouffer
and Amaral, 2007). Stouffer and Bascompte (2010) found that this
distribution promotes stability in food webs, with over-represented
motifs being more stable in isolation and correlated with higher
stability in large realistic communities, and conversely. Motifs can
also be used to characterize species role in networks. From the 13
different three-species motifs emerge 30 unique positions for species to
occupy in these motifs, representing how the species is embedded in its
community. The different positions a species will occupy, and the
frequency with which it will occupy these different positions in
networks are called species motif role (Stouffer, Sales-Pardo, Sirer and
Bascompte, 2012). These roles have been shown to be evolutionary
conserved in food webs (Stouffer, Sales-Pardo, Sirer and Bascompte,
2012) and to have less variability in time than expected in
host-parasitoids bipartite networks (Baker, Kaartinen, Roslin and
Stouffer, 2015).
Another invariant network property lies in species phylogeny. Phylogeny
is a key determinant of ecological network structure, allowing the
understanding of species position and interactions into the community.
Phylogenetically close species indeed inherit traits from their common
ancestors (\emph{e.g.} body size, habitat, defensive strategy, metabolic
type, phenology), increasing their propensity to interact with the same
group of species or with similar species. This conservatism of
interactions has been found to hold across different types of
interactions such as antagonistic or mutualistic interactions (Fontaine
and ThΓ©bault, 2015). However, every species role, such as host or
parasite in antagonistic interaction, prey or predator in food web and
plant or pollinator/seed disperser in mutualistic interaction, do not
provide the same links structure. For instance, closely related host
tend to share parasites, while closely related parasites, because of
competition for resources, tend to have different hosts species
(Krasnov, Fortuna and Mouillot \emph{et al.}, 2012). The conservatism of
interactions is consequently unequal all over the network. Following the
logic that closely related species interact with the same group of
species, Rezende, Albert, Fortuna and Bascompte (2009) shown that
phylogenetic structure of ecological networks explains almost entirely
the formation and composition of modules in the network, and the
connections between them. For the same reasons that conservatism of
interactions is asymmetrical, the link between phylogenetic signal and
module composition is different depending on the species role (Krasnov,
Fortuna and Mouillot \emph{et al.}, 2012), and species that are modules
connector are usually phylogenetically close. Cattin, Bersier and
BanaΕ‘ek-Richter \emph{et al.} (2004) also found, using a
niche-hierarchic model, that diet is constrained by the phylogenetic
origin of consumers. The nested structure of trophic networks, generated
by the diet structuration, is then influenced by the phylogenetic signal
of interacting species and the compatibility of their traits. In
contrast, the nested structure of mutualistic networks would be a
consequence of trait complementary between species (Rezende, Jordano and
Bascompte, 2007). For now, mechanisms underlying the
nestedness-phylogeny relationship remain to be further investigated.
Moreover, because of species plasticity, phylogeny alone does not fully
the structure and evolution of ecological networks.
\subsection{From structure to
properties}\label{from-structure-to-properties}
The relationship between ecological network structure and stability
remains a contemporary topic of discussion. First, MacArthur (1955) and
Elton (1958) observed in natural ecosystems that diverse communities
have a more stable dynamic than simple ones. Using a mathematical model
based on random ecological networks, May (1972) undermined this
hypothesis. Taking into account not only species diversity but also the
connectance and the interaction strengths in the network, he found that,
contrarily to the way of thinking at this time, diversity was
destabilizing communities. This kick in the anthill was the beginning of
a prolific complexity-stability debate, highly oriented on trophic
networks (McCann, 2000; see Allesina and Tang, 2015). Two different
approaches of the stability have emerged: one based on the general
complexity-stability relationship and dynamics among species in
communities and the second one based on the communities ability to
resist biotic and abiotic changes. The both use different notions and
definitions of stability, inducing different ways to study it (see
{\textbf{???}}). Despite their dissimilarities, these approaches are not
totally independent and have allowed highlighting that species diversity
has no direct influence on communities stability. However, the structure
of ecological network such as interactions distribution and strength
seems to play a crucial role (Yodzis, 1981). The links distribution of
ecological networks follows a power-law distribution (Montoya and SolΓ©,
2002), meaning that few species are highly connected to the rest of the
community and a large number of species are weakly connected to others.
This organization combined with the myriad of weak interactions found
across ecological networks, called the weak interaction effect (Berlow,
1999), buffers species variations and then stabilizes the entire
community (Bascompte, MeliΓ‘n and Sala, 2005; Jacquet, Moritz and
Morissette \emph{et al.}, 2016). Other parameters, such as the
predator-prey body-mass ratio (Emmerson and Raffaelli, 2004; Brose,
Jonsson and Berlow \emph{et al.}, 2006) or network architecture
(Montoya, Pimm and SolΓ©, 2006; ThΓ©bault and Fontaine, 2010), determine
the distribution and strength of interactions and then contribute to the
stability of ecological networks.
Perturbations in ecological communities, generally caused by landscape
fragmentation, habitat loss, species loss or invasion, induce a decrease
of species diversity. This loss of diversity is explained by extinctions
of species due directly or indirectly to a first species loss
(\emph{i.e.} secondary extinctions or cascade of extinctions). These
extinctions are used to measure the robustness of ecological communities
and to explore what happen when a species is removed or changed in a
network. The use of dynamic-based models led to highlight the fact that
the probability of secondary extinctions increases with the community
size (Lundberg, Ranta and Kaitala, 2008), and decreases with the network
connectance (Dunne, Williams and Martinez, 2002). Then, the focus on
species removal have allowed to understand that the loss of an highly
connected species, also called hub, induces a higher rate of secondary
extinctions than the loss of a random, weakly connected species (SolΓ©
and Montoya, 2001). However, even if a species is weakly directly
connected, if it represents a highway of energy-flow in the network
(carbon, nitrogen or biomass), its loss will have similar impact in term
of secondary extinctions than the loss of an hug (Allesina and Bodini,
2004). The network architecture also affects the community response to
perturbations. For instance, thanks to their structural properties
(hight nestedness and connectance, Jordano, Bascompte and Olesen
(2003)), mutualistic networks persist longer than randomly structured
networks (Memmott, Waser and Price, 2004 ; Fortuna and Bascompte, 2006).
On the other hand, presence of modules in the community structure limits
propagation of perturbations across the rest of the network and then
secondary extinctions (Stouffer and Bascompte, 2010).
The consequences of the erosion of biodiversity for ecosystem
functioning has been for almost three decades a central problematic for
ecologists. While the hypothesis that an increase in species diversity
results in an increased productivity dates back to Darwin (Darwin,
1859), the emergence of experimental ecology and the shift from
observation in natural systems to the quantification of ecology has made
possible to develop a quite general theory for what is now called the
biodiversity-ecosystem functioning (BEF) relationship. In a trophic
group (\emph{i.e.} a group of species that all belong to the same
trophic level, \emph{e.g.} producers or herbivores), the loss of
diversity results in a loss of efficiency to capture the shared resource
compartment (Loreau, 2010) (\emph{e.g.} nutrients for producers, or
producers for herbivores). This leading to a decrease in productivity or
other index of functioning. Yet, when the trophic group under focus is
coupled to other(s), the action of diversity on functioning is more
variable (Duffy, Cardinale and France \emph{et al.}, 2007). This makes
the BEF relationship unpredictable in real-world communities, composed
of several trophic groups that are virtually never differentiable -- as
intraguild predation and omnivory blurr the frontier between levels. The
multiplicity of the factors influencing the BEF relationship calls for a
more general framework that allows the integration of the theories
developped for trophic group and for simple modules or sub-systems. By
mapping transfer of biomass and energy and/or constraints on organism
through the different compartments that compose a natural community,
ecological networks -- and food webs in particular -- offer the
possibility to perform this integration. Analyses performed on simulated
food-webs with unchanged diversity have already shown that interactions,
and more specifically their structure, have a significative influence on
functioning (Thebault and Loreau, 2003; ThΓ©bault, Huber and Loreau,
2007; Poisot, Mouquet and Gravel, 2013). The structure of interactions
translates the distribution of different types of properties important
for ecosystem functioning, such as the presence of omnivory, the
generality of species, the modularity of the food-web, etc.
\subsection{Linking interactions to ecological
mechanisms}\label{linking-interactions-to-ecological-mechanisms}
It is worth remembering that ecological interactions are the direct
expression of ecological mechanisms. A pollinator is able to effectively
reach the nectar in a plant because the traits of the two organisms
match, because they have compatible phenologies, and because they occur
in the same environment. A virus can infect its host because it is able
to attach to the cell surface, effectively penetrate it, and hijack the
cellular machinery to its benefit. Interactions that are not allowed
because trait values do not match have been called \enquote{forbidden
links} (Olesen, Bascompte and Dupont \emph{et al.}, 2011). This prompted
a search for \enquote{linkage rules} (Bartomeus, 2013) in ecological
networks, \emph{i.e.} the relationships that must exist between traits
borne by two organisms in order for an interaction between them to
exist. These can be identified from existing data on traits and
interactions (Bartomeus, Gravel and Tylianakis \emph{et al.}, 2016), and
then used to generate realistic ecological networks (Crea, Ali and
Rader, 2015). GonzΓ‘lez-Varo and Traveset (2016) point out that
interactions are happening between individuals: this requires to
consider how the traits are distributed at the individual scale, but
also how different behaviors may allow organisms to overcome some of the
forbidden links. Although traits are an important part of what makes
interactions happen, they are only relevant insofar as the organisms are
able to encounter one another. The importance of neutral dynamics
(\emph{i.e.} how abundances of different species can determine the
probability that they can interact, based on how often they would bump
into one another by chance) is, somewhat counter-intuitively, great.
Canard, Mouquet and Marescot \emph{et al.} (2012) reveals that
simulating food web dynamics by using only population abundances to
predict interactions yields realistic food webs. In a host-parasite
system, local abundances has also been identified as a key predictor of
species interactions (Canard, Mouquet and Mouillot \emph{et al.}, 2014).
Speaking more broadly, because interactions emerge from all of these
ecological mechanisms, there is a need to develop a deeper understanding
of their variability (Poisot, Stouffer and Gravel, 2015). Beyond the
fundamental advance that this represents, this would allow to predict
interactions based on external information (Morales-Castilla, Matias,
Gravel and AraΓΊjo, 2015).
The realization of an interaction between individuals from the same or
different populations within a community also have ecological
consequences as it modifies the dynamics of at least one of the
interacting populations, and through it, emerging properties. If we
consider for instance a population A, its dynamics is not the same when
it multiplies in isolation -- where it can grow exponentially if
resources are unlimited (Malthus, 1798) or logistically otherwise
(Verhulst, 1938) -- or when it is embedded in a real-world community,
composed of several species interacting with one another through
different mechanisms (Chesson and Kuang, 2008). It can lose individuals
to predation, have parasitism increase its death rate and at the same
time see its establishment eased through facilitation. It then becomes
necessary to account for interactions when studying the dynamic a
population, community stability or ecosystem functioning. But the effect
of interactions on populations dynamics is not always straightforward,
both in terms of directionality and intensity, as there is different
types of interactions and multiple factors influence their probability
of occurrence and strength. Since the seminal work of May (1972), the
analysis of these effects has been a prolific field of ecology, feeding
in particular the famous \enquote{complexity-stability debate} (see
Allesina and Tang (2015) for an overview). Including interactions in
population dynamics analyses can be done by using model of the following
general form:
\[
\frac{1}{N_i}\frac{\text{d}}{\text{d}t}N_i = r_i \times \sum_j A_{ij} \alpha_{i,j} N_j \,
\]
wherein the adjacency matrix \(A\) (\(n*n\)), list the realized
interactions in a given community composed of \(n\) species.
\(A_{ij} \neq 0\) when species \(i\) and \(j\) interact and \(0\)
otherwise. \(\alpha_{ij}\) quantifies the strength of the interaction.
This equation model populations abundance \(N\) but can easily be
adapted to model biomass flows by replacing populations' abundances by
their biomasses \(B_i\) (see for instance Williams, Brose and Martinez
(2007)).
Ecological networks are also spatially and temporally variable
(TrΓΈjelsgaard and Olesen, 2016). There are two drivers to this
variability: changes in species composition, and changes in the way
these species interact (Poisot, Canard and Mouillot \emph{et al.},
2012). Changes in species alone are able to generate variation in
network properties (Havens, 1992). Spatial variation in network
structure can also reflect deep-time constraints; for example,
Dalsgaard, TrΓΈjelsgaard and MartΓn GonzΓ‘lez \emph{et al.} (2013) reveal
that historical climate change trends have a signature on the nestedness
and modularity of pollination networks. Even when the same species are
present, interactions between them can vary. Carstensen, Sabatino,
TrΓΈjelsgaard and Morellato (2014) and TrΓΈjelsgaard, Jordano, Carstensen
and Olesen (2015) investigated this phenomenon in mutualistic networks.
Interaction turnover results from variations in partner fidelity (some
species pairs are extremely closely associated), but also from
variations in the local environment in which the species interact.
Interestingly, and as mentioned in section \textbf{x}, networks
overwhelmingly tend to conserve their structure even when interactions
within them change. DΓaz-Castelazo, GuimarΓ£es and Jordano \emph{et al.}
(2010) surveyed a pollination network over 10 years, and found important
species turnover during this period. Nevertheless, the network retained
its structure because species where replaced by their functional
equivalent; a generalist pollinator often succeeded to another
generalist pollinator. Conversely, species tend to retain their role in
different communities: Baker, Kaartinen, Roslin and Stouffer (2015) show
that species keep occupying the same position in the network across
space, regardless of the species they interact with at every location.
\subsection{From the regional species pool to local structured
communities}\label{from-the-regional-species-pool-to-local-structured-communities}
Describing the different local communities that occur at macroecological
scales through their ecological networks represent an additional layer
of information compared to simple species lists. As such, ecological
networks are a powerful tool to shed new light on the processes
underlying species distribution (Cazelles, AraΓΊjo, Mouquet and Gravel,
2016). Until recently, the prevailing idea was that at large scales, the
role of biotic interactions was very small compared to that of abiotic
conditions, and thought to only be important locally (Pearson and
Dawson, 2003; Boulangeat, Gravel and Thuiller, 2012). Empirical
observations of species-environment relationship are then used to
understand species physiological tolerance to environmental conditions
and potentially predict their range under different scenarios of climate
change (e.g. AraΓΊjo, Thuiller and Pearson, 2006). While these climate
envelope models provide a useful approximation of species potential
distribution (Pearson, Dawson, Berry and Harrison, 2002), there is
mounting evidences that biotic interactions -- both positive and
negative -- play a critical role in shaping communities not only at
local scales (Boulangeat, Gravel and Thuiller, 2012), but also at
macroecological scales (Davis, Lawton, Shorrocks and Jenkinson, 1998;
AraΓΊjo and Luoto, 2007; Heikkinen, Luoto and Virkkala \emph{et al.},
2007; Gotelli, Graves and Rahbek, 2010; AraΓΊjo, Rozenfeld, Rahbek and
Marquet, 2011). So far, the role of interactions in shaping species
distribution is mainly estimated from co-occurrence data, used to build
joint species distribution models (JSDM) (Pollock, Tingley and Morris
\emph{et al.}, 2014). But there are limitations to this approach. For
instance, it does not allow to distinguish between co-occurrence caused
by biotic interactions and correlated responses to unmeasured
environmental variables (Pollock, Tingley and Morris \emph{et al.},
2014). Conversely, the lack of association between species is no
evidence of absence of interaction (Cazelles, AraΓΊjo, Mouquet and
Gravel, 2016). To move from empirical-based species distribution models
(SDM) toward theory-driven SDM, further work is needed. In particular,
developing methods allowing to include prior information about the
underlying ecological network when building (J)SDM could help sheding
light on the the fundamental processes underlying species distribution
and thus making more accurate predictions (Cazelles, AraΓΊjo, Mouquet and
Gravel, 2016). Additionally, Poisot, GuΓ©veneux-Julien and Fortin
\emph{et al.} (2017) recently showed that biotic interactions respond to
environmental conditions on their own, independently of species.
Ecological networks also offer an ideal framework to study the
conditions for the maintenance of biodiversity in communities through
species coexistence. Gause (1934) predicted that species that shared
similar ecologies could not live together in the same area. This
competitive exclusion principle states that the the strongest competitor
will eventually come to dominate the other species and drive them to
local extinction. This stands in contradiction with the existence of
ecological communities containing species that overlap in some extent in
their resources or consumers. Phytoplanktonic communities are a
paradigmatic example of this paradox (Hutchinson, 1961), as they exhibit
a high biodiversity while species are competing for a limited number of
shared resources (e.g.~light, nitrate). The use of consumer-resources
models has allowed to highlight some mechanisms improving species
coexistence (Chesson, 2000). These mechanisms are based on species
traits that either decrease fitness differences (equalizing mechanisms)
and/or increase niche differentiation between species (stabilizing
mechanisms). The coupling of this type of model with the representation
of ecological communities as their underlying network of interactions
has brought new perspective on species coexistence, as it is allowing to
integrate these mechanisms in large realistic communities. Using this
methodological framework, Martinez, Williams and Dunne (2006) showed
that the global non-random structure of the food webs improved community
persistence. The distribution of motifs in food webs (Stouffer and
Bascompte, 2010, see section `Invariants in ecological networks') as
well as species' role within motifs (Stouffer, Sales-Pardo, Sirer and
Bascompte, 2012) are related to community persistence. In mutualistic
networks, the nested structure has been shown to minimize competition
relatively to competition (Bastolla, Fortuna and Pascual-GarcΓa \emph{et
al.}, 2009; Sugihara and Ye, 2009). In these networks, the asymmetry of
dependences -- the fact that when one species \(A\) depends strongly on
another species \(B\) as resource for food or pollination, the other
species (\(B\)) only weakly depends on \(A\) -- also increase
persistence (Bascompte, Jordano and Olesen, 2006). This type of approach
also allowed to highlight the interplay between traits and structure. As
an example, Brose, Williams and Martinez (2006) showed that the
allometric scaling of metabolic rates of species improve community
persistence when the organization of the food webs is such that
predator--prey body mass ratios are different from zero.
Ecologists have also questioned the way communities are formed and the
hypothetical set of rules embedding this assembly. Diamond (1975)
defined emblematic rules to understand community structure and assembly.
In this continuity, network framework allows to explore in detail
processes influencing ecological communities assembly. CapitΓ‘n, Cuesta
and Bascompte (2009), for instance, have retraced the pathway of the
community assembly process through an assembly graph, based on graph
theory. It allows to follow step by step every possible path in
community assembly from, for instance, 0 to 21 species among 3 trophic
levels, and highlight underlying mechanisms. For food webs especially,
mechanistic models such as niche model (Williams and Martinez, 2000) and
the cascade model (Cohen, 1989) originally constructed to understand
networks structure, have actually be used to understand community
assembly and the impact of invasion. Using also network framework,
(VerdΓΊ and ValienteβBanuet, 2008) found that nested community provides
generalists species which facilitate the presence of other species into
the network. At the same time, thanks to an experimental network study,
(Olesen, Bascompte, Elberling and Jordano, 2008) have observed that new
arrival species tend to interact more easily with already well-connected
or generalist species. These kind of results could let us think about
the Drake's controversial idea Drake (1991) that species arrival history
would be a \emph{important} factor driving community assembly (Drake,
1991). Thanks to community network, Campbell, Yang, Albert and Shea
(2011) shown that history assembly process is and important factor for
mutualistic networks. Community assembly have however, a myriad of
different drivers, such as dispersion, interaction strength and
phylogeny distance between species composing communities (Montoya and
SolΓ©, 2003; Kraft, Cornwell, Webb and Ackerly, 2007; Maherali and
Klironomos, 2007; Leibold, Chase and Ernest, 2017). Based on these
drivers, distinct types of models have been developed to predict
community assembly dynamics (Tilman, 2004; Gravel, Canham, Beaudet and
Messier, 2006; Souza, Bezerra and Longhi, 2016). In one hand,
niche-based theory models use coexistence theory and niche
differentiation. In the other hand, neutral theory models are based on
species dynamics (migration, extinction and speciation) under stochastic
processes. Theses two types of model are actually complementary,
offering processes explanation at the metacommunity level (niche theory)
and at the phylogenetic level (neutral theory) {[}\emph{ref}{]}. Network
framework in community assembly have brought the field one step further
and makes links between other ecological fields, such as disassembly
prediction (see Bascompte and Stouffer, 2009) or co-evolutionary
processes (Nuismer, Jordano and Bascompte, 2013) much more easier.
\subsection{Conclusion}\label{conclusion}
As networks and graph theory allowed to understand breakdown into
electricity system in United States or the structure and functioning of
social network, it is also a powerful tool to investigate ecological
questions. As long as the studying system contains interactions, links
or connections, the graph theory provides a perfectly adapted simple
framework to characterize complicated networks such as ecological
networks. Indices such as connectance, degree distribution of network
topology serve as basic measurements to describe systems. Using theses
indices, this framework facilitates comparison between different
ecological networks. And the relatively important number of network
studies leads to a myriads of ways to sample, analyze and interpret them
(see Delmas, Besson and Brice \emph{et al.}, 2017).
Studying ecological networks have however a larger purpose than just
their description and classification. Basic measurements are correlated
to several environmental factors and network analysis appears to be
helpful in different ecological fields. As we seen through this paper,
it can be used to study dynamics of ecological systems and their
responses to changes, according to their stability over time or the BEF
relationships in the system. It also highlight the understanding of
mechanisms underlying ecological properties such as community assembly,
coexistence and species distribution. Network studies were a key to
reveal relationships between different properties of ecological network
such as trait and structure.
\section*{References}\label{references}
\addcontentsline{toc}{section}{References}
\hypertarget{refs}{}
\hypertarget{ref-alle04wdw}{}
Allesina, S. and Bodini, A. (2004) `Who dominates whom in the ecosystem?
Energy flow bottlenecks and cascading extinctions', \emph{Journal of
Theoretical Biology}, 230(3), pp. 351--358. doi:
\href{https://doi.org/10.1016/j.jtbi.2004.05.009}{10.1016/j.jtbi.2004.05.009}.
\hypertarget{ref-alle15sra}{}
Allesina, S. and Tang, S. (2015) `The stability--complexity relationship
at age 40: a random matrix perspective', \emph{Population Ecology},
57(1), pp. 63--75. doi:
\href{https://doi.org/10.1007/s10144-014-0471-0}{10.1007/s10144-014-0471-0}.
\hypertarget{ref-arau07ibi}{}
AraΓΊjo, M. B. and Luoto, M. (2007) `The importance of biotic
interactions for modelling species distributions under climate change',
\emph{Global Ecology and Biogeography}, 16(6), pp. 743--753. doi:
\href{https://doi.org/10.1111/j.1466-8238.2007.00359.x}{10.1111/j.1466-8238.2007.00359.x}.
\hypertarget{ref-arau11usc}{}
AraΓΊjo, M. B., Rozenfeld, A., Rahbek, C. and Marquet, P. A. (2011)
`Using species co-occurrence networks to assess the impacts of climate
change', \emph{Ecography}, 34(6), pp. 897--908. doi:
\href{https://doi.org/10.1111/j.1600-0587.2011.06919.x}{10.1111/j.1600-0587.2011.06919.x}.
\hypertarget{ref-arau06cwd}{}
AraΓΊjo, M. B., Thuiller, W. and Pearson, R. G. (2006) `Climate warming
and the decline of amphibians and reptiles in Europe', \emph{Journal of
Biogeography}, 33(10), pp. 1712--1728. doi:
\href{https://doi.org/10.1111/j.1365-2699.2006.01482.x}{10.1111/j.1365-2699.2006.01482.x}.
\hypertarget{ref-bake15srf}{}
Baker, N. J., Kaartinen, R., Roslin, T. and Stouffer, D. B. (2015)
`Species' roles in food webs show fidelity across a highly variable oak
forest', \emph{Ecography}, 38(2), pp. 130--139. doi:
\href{https://doi.org/10.1111/ecog.00913}{10.1111/ecog.00913}.
\hypertarget{ref-bart13ulr}{}
Bartomeus, I. (2013) `Understanding linkage rules in plant-pollinator
networks by using hierarchical models that incorporate pollinator
detectability and plant traits', \emph{PloS one}, 8(7), p. e69200.
Available at:
\url{http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0069200}
(Accessed: 21 February 2017).
\hypertarget{ref-bart16cfi}{}
Bartomeus, I., Gravel, D. and Tylianakis, J. M. \emph{et al.} (2016) `A
common framework for identifying linkage rules across different types of
interactions', \emph{Functional Ecology}, 30(12), pp. 1894--1903.
Available at:
\url{http://onlinelibrary.wiley.com/doi/10.1111/1365-2435.12666/full}
(Accessed: 21 February 2017).
\hypertarget{ref-basc05stm}{}
Bascompte, J. and MeliΓ‘n, C. J. (2005) `Simple trophic modules for
complex food webs', \emph{Ecology}, 86(11), pp. 2868--2873. doi:
\href{https://doi.org/10.1890/05-0101}{10.1890/05-0101}.
\hypertarget{ref-basc09adea}{}
Bascompte, J. and Stouffer, D. B. (2009) `The assembly and disassembly
of ecological networks', \emph{Philosophical Transactions of the Royal
Society B: Biological Sciences}, 364(1524), pp. 1781--1787. doi:
\href{https://doi.org/10.1098/rstb.2008.0226}{10.1098/rstb.2008.0226}.
\hypertarget{ref-basc06acn}{}
Bascompte, J., Jordano, P. and Olesen, J. M. (2006) `Asymmetric
Coevolutionary Networks Facilitate Biodiversity Maintenance',
\emph{Science}, 312(5772), pp. 431--433. doi:
\href{https://doi.org/10.1126/science.1123412}{10.1126/science.1123412}.
\hypertarget{ref-basc05isc}{}
Bascompte, J., MeliΓ‘n, C. J. and Sala, E. (2005) `Interaction strength
combinations and the overfishing of a marine food web',
\emph{Proceedings of the National Academy of Sciences of the United
States of America}, 102(15), pp. 5443--5447. doi:
\href{https://doi.org/10.1073/pnas.0501562102}{10.1073/pnas.0501562102}.
\hypertarget{ref-bast09amn}{}
Bastolla, U., Fortuna, M. A. and Pascual-GarcΓa, A. \emph{et al.} (2009)
`The architecture of mutualistic networks minimizes competition and
increases biodiversity', \emph{Nature}, 458(7241), pp. 1018--1020. doi:
\href{https://doi.org/10.1038/nature07950}{10.1038/nature07950}.
\hypertarget{ref-berl99sew}{}
Berlow, E. L. (1999) `Strong effects of weak interactions in ecological
communities', \emph{Nature}, 398(6725), pp. 330--334. doi:
\href{https://doi.org/10.1038/18672}{10.1038/18672}.
\hypertarget{ref-boul12adb}{}
Boulangeat, I., Gravel, D. and Thuiller, W. (2012) `Accounting for
dispersal and biotic interactions to disentangle the drivers of species
distributions and their abundances', \emph{Ecology Letters}, 15(6), pp.
584--593. doi:
\href{https://doi.org/10.1111/j.1461-0248.2012.01772.x}{10.1111/j.1461-0248.2012.01772.x}.
\hypertarget{ref-bros06cbr}{}
Brose, U., Jonsson, T. and Berlow, E. L. \emph{et al.} (2006)
`Consumer--Resource Body-Size Relationships in Natural Food Webs',
\emph{Ecology}, 87(10), pp. 2411--2417. doi:
\href{https://doi.org/10.1890/0012-9658(2006)87\%5B2411:CBRINF\%5D2.0.CO;2}{10.1890/0012-9658(2006)87{[}2411:CBRINF{]}2.0.CO;2}.
\hypertarget{ref-bros04uss}{}
Brose, U., Ostling, A., Harrison, K. and Martinez, N. D. (2004) `Unified
spatial scaling of species and their trophic interactions',
\emph{Nature}, 428(6979), pp. 167--171. doi:
\href{https://doi.org/10.1038/nature02297}{10.1038/nature02297}.
\hypertarget{ref-bros06ase}{}
Brose, U., Williams, R. J. and Martinez, N. D. (2006) `Allometric
scaling enhances stability in complex food webs', \emph{Ecology
Letters}, 9(11), pp. 1228--1236. doi:
\href{https://doi.org/10.1111/j.1461-0248.2006.00978.x}{10.1111/j.1461-0248.2006.00978.x}.
\hypertarget{ref-cama07qal}{}
Camacho, J., Stouffer, D. and Amaral, L. (2007) `Quantitative analysis
of the local structure of food webs', \emph{Journal of Theoretical
Biology}, 246(2), pp. 260--268. doi:
\href{https://doi.org/10.1016/j.jtbi.2006.12.036}{10.1016/j.jtbi.2006.12.036}.
\hypertarget{ref-camp11nmp}{}
Campbell, C., Yang, S., Albert, R. and Shea, K. (2011) `A network model
for plant--pollinator community assembly', \emph{Proceedings of the
National Academy of Sciences}, 108(1), pp. 197--202. doi:
\href{https://doi.org/10.1073/pnas.1008204108}{10.1073/pnas.1008204108}.
\hypertarget{ref-cana14een}{}
Canard, E. F., Mouquet, N. and Mouillot, D. \emph{et al.} (2014)
`Empirical evaluation of neutral interactions in host-parasite
networks', \emph{The American Naturalist}, 183(4), pp. 468--479. doi:
\href{https://doi.org/10.1086/675363}{10.1086/675363}.
\hypertarget{ref-cana12esp}{}
Canard, E., Mouquet, N. and Marescot, L. \emph{et al.} (2012) `Emergence
of Structural Patterns in Neutral Trophic Networks', \emph{PLOS ONE},
7(8), p. e38295. doi:
\href{https://doi.org/10.1371/journal.pone.0038295}{10.1371/journal.pone.0038295}.
\hypertarget{ref-capi09sme}{}
CapitΓ‘n, J. A., Cuesta, J. A. and Bascompte, J. (2009) `Statistical
Mechanics of Ecosystem Assembly', \emph{Physical Review Letters},
103(16), p. 168101. doi:
\href{https://doi.org/10.1103/PhysRevLett.103.168101}{10.1103/PhysRevLett.103.168101}.
\hypertarget{ref-cars14bdp}{}
Carstensen, D. W., Sabatino, M., TrΓΈjelsgaard, K. and Morellato, L. P.
C. (2014) `Beta Diversity of Plant-Pollinator Networks and the Spatial
Turnover of Pairwise Interactions', \emph{PLoS ONE}, 9(11), p. e112903.
doi:
\href{https://doi.org/10.1371/journal.pone.0112903}{10.1371/journal.pone.0112903}.
\hypertarget{ref-catt04pca}{}
Cattin, M.-F., Bersier, L.-F. and BanaΕ‘ek-Richter, C. \emph{et al.}
(2004) `Phylogenetic constraints and adaptation explain food-web
structure', \emph{Nature}, 427(6977), pp. 835--839. doi:
\href{https://doi.org/10.1038/nature02327}{10.1038/nature02327}.
\hypertarget{ref-caze16tsc}{}
Cazelles, K., AraΓΊjo, M. B., Mouquet, N. and Gravel, D. (2016) `A theory
for species co-occurrence in interaction networks', \emph{Theoretical
Ecology}, 9(1), pp. 39--48. doi:
\href{https://doi.org/10.1007/s12080-015-0281-9}{10.1007/s12080-015-0281-9}.
\hypertarget{ref-chag15cte}{}
Chagnon, P.-L. (2015) `Characterizing topology of ecological networks
along gradients: the limits of metrics' standardization',
\emph{Ecological Complexity}, 22, pp. 36--39. Available at:
\url{http://www.sciencedirect.com/science/article/pii/S1476945X15000070}
(Accessed: 21 February 2017).
\hypertarget{ref-ches00mms}{}
Chesson, P. (2000) `Mechanisms of Maintenance of Species Diversity',
\emph{Annual Review of Ecology and Systematics}, 31(1), pp. 343--366.
doi:
\href{https://doi.org/10.1146/annurev.ecolsys.31.1.343}{10.1146/annurev.ecolsys.31.1.343}.
\hypertarget{ref-ches08ipc}{}
Chesson, P. and Kuang, J. J. (2008) `The interaction between predation
and competition', \emph{Nature}, 456(7219), pp. 235--238. doi:
\href{https://doi.org/10.1038/nature07248}{10.1038/nature07248}.
\hypertarget{ref-cohe89fwc}{}
Cohen, J. E. (1989) `Food webs and community structure',
\emph{Perspectives in ecological theory}, pp. 181--202.
\hypertarget{ref-crea15nme}{}
Crea, C., Ali, R. A. and Rader, R. (2015) `A new model for ecological
networks using species-level traits', \emph{Methods in Ecology and
Evolution}. Available at:
\url{http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12471/pdf}
(Accessed: 21 February 2017).
\hypertarget{ref-dals13hci}{}
Dalsgaard, B., TrΓΈjelsgaard, K. and MartΓn GonzΓ‘lez, A. M. \emph{et al.}
(2013) `Historical climate-change influences modularity and nestedness
of pollination networks', \emph{Ecography}, 36(12), pp. 1331--1340. doi:
\href{https://doi.org/10.1111/j.1600-0587.2013.00201.x}{10.1111/j.1600-0587.2013.00201.x}.
\hypertarget{ref-darw59osm}{}
Darwin, C. (1859) \emph{On the Origin of Species by Means of Natural
Selection, or Preservation of Favoured Races in the Struggle for Life.}
John Murray, London.
\hypertarget{ref-davi98isr}{}
Davis, A. J., Lawton, J. H., Shorrocks, B. and Jenkinson, L. S. (1998)
`Individualistic species responses invalidate simple physiological
models of community dynamics under global environmental change',
\emph{Journal of Animal Ecology}, 67(4), pp. 600--612. doi:
\href{https://doi.org/10.1046/j.1365-2656.1998.00223.x}{10.1046/j.1365-2656.1998.00223.x}.
\hypertarget{ref-delm17aen}{}
Delmas, E., Besson, M. and Brice, M.-H. \emph{et al.} (2017) `Analyzing
ecological networks of species interactions', pp. --. doi:
\href{https://doi.org/10.1101/112540}{10.1101/112540}.
\hypertarget{ref-diam75asc}{}
Diamond, J. M. (1975) `Assembly of species communities', in
\emph{Ecology and evolution of communities}. Harvard University Press,
Cambridge, Massachusetts, US: M. L. Cody and J. M. Diamond, editors, pp.
342--444.
\hypertarget{ref-diaz10cmn}{}
DΓaz-Castelazo, C., GuimarΓ£es, P. R. and Jordano, P. \emph{et al.}
(2010) `Changes of a mutualistic network over time: reanalysis over a
10-year period', \emph{Ecology}, 91(3), pp. 793--801. Available at:
\url{http://www.jstor.org/stable/25661111} (Accessed: 21 February 2017).
\hypertarget{ref-drak91cms}{}
Drake, J. A. (1991) `Community-Assembly Mechanics and the Structure of
an Experimental Species Ensemble', \emph{The American Naturalist},
137(1), pp. 1--26. doi:
\href{https://doi.org/10.1086/285143}{10.1086/285143}.
\hypertarget{ref-duff07frb}{}
Duffy, J. E., Cardinale, B. J. and France, K. E. \emph{et al.} (2007)
`The functional role of biodiversity in ecosystems: incorporating
trophic complexity', \emph{Ecology Letters}, 10(6), pp. 522--538. doi:
\href{https://doi.org/10.1111/j.1461-0248.2007.01037.x}{10.1111/j.1461-0248.2007.01037.x}.
\hypertarget{ref-dunn02nsb}{}
Dunne, J. A., Williams, R. J. and Martinez, N. D. (2002) `Network
structure and biodiversity loss in food webs: robustness increases with
connectance', \emph{Ecology Letters}, 5(4), pp. 558--567. doi:
\href{https://doi.org/10.1046/j.1461-0248.2002.00354.x}{10.1046/j.1461-0248.2002.00354.x}.
\hypertarget{ref-elto58rc}{}
Elton, C. C. (1958) `The Reasons for Conservation', in \emph{The Ecology
of Invasions by Animals and Plants}. Springer Netherlands, pp. 143--153.
doi:
\href{https://doi.org/10.1007/978-94-009-5851-7_8}{10.1007/978-94-009-5851-7\_8}.
\hypertarget{ref-emme04pbs}{}
Emmerson, M. C. and Raffaelli, D. (2004) `Predator--prey body size,
interaction strength and the stability of a real food web',
\emph{Journal of Animal Ecology}, 73(3), pp. 399--409. doi:
\href{https://doi.org/10.1111/j.0021-8790.2004.00818.x}{10.1111/j.0021-8790.2004.00818.x}.
\hypertarget{ref-font15cce}{}
Fontaine, C. and ThΓ©bault, E. (2015) `Comparing the conservatism of
ecological interactions in plant--pollinator and plant--herbivore
networks', \emph{Population Ecology}, 57(1), pp. 29--36. doi:
\href{https://doi.org/10.1007/s10144-014-0473-y}{10.1007/s10144-014-0473-y}.
\hypertarget{ref-fort06hls}{}
Fortuna, M. A. and Bascompte, J. (2006) `Habitat loss and the structure
of plant-animal mutualistic networks: Mutualistic networks and habitat
loss', \emph{Ecology Letters}, 9(3), pp. 281--286. doi:
\href{https://doi.org/10.1111/j.1461-0248.2005.00868.x}{10.1111/j.1461-0248.2005.00868.x}.
\hypertarget{ref-fort10nme}{}
Fortuna, M. A., Stouffer, D. B. and Olesen, J. M. \emph{et al.} (2010)
`Nestedness versus modularity in ecological networks: two sides of the
same coin?', \emph{Journal of Animal Ecology}, 79(4), pp. 811--817. doi:
\href{https://doi.org/10.1111/j.1365-2656.2010.01688.x}{10.1111/j.1365-2656.2010.01688.x}.
\hypertarget{ref-gaus34eav}{}
Gause, G. F. (1934) `Experimental analysis of Vito Volterra's
mathematical theory of the struggle for existence', \emph{Science},
79(2036), pp. 16--17. Available at:
\url{http://faculty.jsd.claremont.edu/dmcfarlane/bio146mcfarlane/papers/Gause_paramecium.pdf}
(Accessed: 23 August 2017).
\hypertarget{ref-gonz16llf}{}
GonzΓ‘lez-Varo, J. P. and Traveset, A. (2016) `The Labile Limits of
Forbidden Interactions', \emph{Trends in Ecology \& Evolution}, 31(9),
pp. 700--710. doi:
\href{https://doi.org/10.1016/j.tree.2016.06.009}{10.1016/j.tree.2016.06.009}.
\hypertarget{ref-gote10mss}{}
Gotelli, N. J., Graves, G. R. and Rahbek, C. (2010) `Macroecological
signals of species interactions in the Danish avifauna',
\emph{Proceedings of the National Academy of Sciences}, 107(11), pp.
5030--5035. doi:
\href{https://doi.org/10.1073/pnas.0914089107}{10.1073/pnas.0914089107}.
\hypertarget{ref-grav06rnn}{}
Gravel, D., Canham, C. D., Beaudet, M. and Messier, C. (2006)
`Reconciling niche and neutrality: the continuum hypothesis',
\emph{Ecology Letters}, 9(4), pp. 399--409. doi:
\href{https://doi.org/10.1111/j.1461-0248.2006.00884.x}{10.1111/j.1461-0248.2006.00884.x}.
\hypertarget{ref-have92ssn}{}
Havens, K. (1992) `Scale and structure in natural food webs',
\emph{Science (New York, N.Y.)}, 257(5073), pp. 1107--1109. doi:
\href{https://doi.org/10.1126/science.257.5073.1107}{10.1126/science.257.5073.1107}.
\hypertarget{ref-heik07bii}{}
Heikkinen, R. K., Luoto, M. and Virkkala, R. \emph{et al.} (2007)
`Biotic interactions improve prediction of boreal bird distributions at
macro-scales', \emph{Global Ecology and Biogeography}, 16(6), pp.
754--763. doi:
\href{https://doi.org/10.1111/j.1466-8238.2007.00345.x}{10.1111/j.1466-8238.2007.00345.x}.
\hypertarget{ref-holt97cm}{}
Holt, R. D. (1997) `Community modules', \emph{A.C. Gange, V.K. Brown
(Eds.), Multitrophic interactions in Terrestrial Ecosystems, 6th
Symposium of the British Ecological Society, Blackwell Science}, pp.
333--350.
\hypertarget{ref-hutc61pp}{}
Hutchinson, G. E. (1961) `The Paradox of the Plankton', \emph{The
American Naturalist}, 95(882), pp. 137--145. doi:
\href{https://doi.org/10.1086/282171}{10.1086/282171}.
\hypertarget{ref-jacq16ncr}{}
Jacquet, C., Moritz, C. and Morissette, L. \emph{et al.} (2016) `No
complexity--stability relationship in empirical ecosystems',
\emph{Nature Communications}, 7, p. 12573. doi:
\href{https://doi.org/10.1038/ncomms12573}{10.1038/ncomms12573}.
\hypertarget{ref-jord03ipc}{}
Jordano, P., Bascompte, J. and Olesen, J. M. (2003) `Invariant
properties in coevolutionary networks of plant--animal interactions',
\emph{Ecology Letters}, 6(1), pp. 69--81. doi:
\href{https://doi.org/10.1046/j.1461-0248.2003.00403.x}{10.1046/j.1461-0248.2003.00403.x}.
\hypertarget{ref-kemp17ian}{}
Kemp, J. E., Evans, D. M., Augustyn, W. J. and Ellis, A. G. (2017)
`Invariant antagonistic network structure despite high spatial and
temporal turnover of interactions', \emph{Ecography}, pp. n/a--n/a. doi:
\href{https://doi.org/10.1111/ecog.02150}{10.1111/ecog.02150}.
\hypertarget{ref-kraf07tec}{}
Kraft, N., Cornwell, W., Webb, C. and Ackerly, D. (2007) `Trait
Evolution, Community Assembly, and the Phylogenetic Structure of
Ecological Communities.', \emph{The American Naturalist}, 170(2), pp.
271--283. doi: \href{https://doi.org/10.1086/519400}{10.1086/519400}.
\hypertarget{ref-kras12psm}{}
Krasnov, B. R., Fortuna, M. A. and Mouillot, D. \emph{et al.} (2012)
`Phylogenetic Signal in Module Composition and Species Connectivity in
Compartmentalized Host-Parasite Networks', \emph{The American
Naturalist}, 179(4), pp. 501--511. doi:
\href{https://doi.org/10.1086/664612}{10.1086/664612}.
\hypertarget{ref-leib17caf}{}
Leibold, M. A., Chase, J. M. and Ernest, S. K. M. (2017) `Community
assembly and the functioning of ecosystems: how metacommunity processes
alter ecosystems attributes', \emph{Ecology}, 98(4), pp. 909--919. doi:
\href{https://doi.org/10.1002/ecy.1697}{10.1002/ecy.1697}.
\hypertarget{ref-lore10lbe}{}
Loreau, M. (2010) `Linking biodiversity and ecosystems: towards a
unifying ecological theory', \emph{Philosophical Transactions of the
Royal Society B: Biological Sciences}, 365(1537), pp. 49--60. doi:
\href{https://doi.org/10.1098/rstb.2009.0155}{10.1098/rstb.2009.0155}.
\hypertarget{ref-lund08sll}{}
Lundberg, P., Ranta, E. and Kaitala, V. (2008) `Species loss leads to
community closure', \emph{Ecology Letters}, 3(6), pp. 465--468. doi:
\href{https://doi.org/10.1111/j.1461-0248.2000.00170.x}{10.1111/j.1461-0248.2000.00170.x}.
\hypertarget{ref-maca55fap}{}
MacArthur, R. (1955) `Fluctuations of Animal Populations and a Measure
of Community Stability', \emph{Ecology}, 36(3), p. 533. doi:
\href{https://doi.org/10.2307/1929601}{10.2307/1929601}.
\hypertarget{ref-mahe07ipf}{}
Maherali, H. and Klironomos, J. N. (2007) `Influence of Phylogeny on
Fungal Community Assembly and Ecosystem Functioning', \emph{Science},
316(5832), pp. 1746--1748. doi:
\href{https://doi.org/10.1126/science.1143082}{10.1126/science.1143082}.
\hypertarget{ref-malt98epp}{}
Malthus, T. R. (1798) `An Essay on the Principle of Population, as it
Affects the Future Improvement of Society: With Remarks on the
Speculations of Mr. Godwin, Mr. Condorcet, and Other Writers.'
\hypertarget{ref-mart92ccc}{}
Martinez, N. D. (1992) `Constant Connectance in Community Food Webs',
\emph{The American Naturalist}, 139(6), pp. 1208--1218. Available at:
\url{http://www.jstor.org/stable/2462337} (Accessed: 21 February 2017).
\hypertarget{ref-mart06dcp}{}
Martinez, N. D., Williams, R. J. and Dunne, J. A. (2006) `Diversity,
complexity, and persistence in large model ecosystems', \emph{Ecological
networks: linking structure to dynamics in food webs}, pp. 163--185.
Available at:
\url{https://books.google.com/books?hl=en\&lr=\&id=YpQRDAAAQBAJ\&oi=fnd\&pg=PA163\&dq=\%22spatial+e\%EF\%AC\%80ects,+and+evolutionary\%22+\%22of+diversity+and+complexity+in+the+functioning+and+stability+of\%22+\%22(Hutchinson+1959).+However,+the+apparent+inevitability+of+this\%22+\%22diversity/complexity+and+stability+(for+review,+see+Dunne+et+al.\%22+\&ots=K4c5g6-yd-\&sig=QXohTQ7JTQ88WJRhNBOYrGb640E}
(Accessed: 11 May 2017).
\hypertarget{ref-may72wlc}{}
May, R. M. (1972) `Will a Large Complex System be Stable?',
\emph{Nature}, 238(5364), pp. 413--414. doi:
\href{https://doi.org/10.1038/238413a0}{10.1038/238413a0}.
\hypertarget{ref-mcca00dd}{}
McCann, K. S. (2000) `The diversity--stability debate', \emph{Nature},
405(6783), pp. 228--233. doi:
\href{https://doi.org/10.1038/35012234}{10.1038/35012234}.
\hypertarget{ref-mcca98wti}{}
McCann, K., Hastings, A. and Huxel, G. R. (1998) `Weak trophic
interactions and the balance of nature', \emph{Nature}, 395(6704), pp.
794--798. doi: \href{https://doi.org/10.1038/27427}{10.1038/27427}.
\hypertarget{ref-memm04tpn}{}
Memmott, J., Waser, N. M. and Price, M. V. (2004) `Tolerance of
pollination networks to species extinctions', \emph{Proceedings of the
Royal Society B: Biological Sciences}, 271(1557), pp. 2605--2611. doi:
\href{https://doi.org/10.1098/rspb.2004.2909}{10.1098/rspb.2004.2909}.
\hypertarget{ref-milo02nms}{}
Milo, R. (2002) `Network Motifs: Simple Building Blocks of Complex
Networks', \emph{Science}, 298(5594), pp. 824--827. doi:
\href{https://doi.org/10.1126/science.298.5594.824}{10.1126/science.298.5594.824}.
\hypertarget{ref-mont02swp}{}
Montoya, J. M. and SolΓ©, R. V. (2002) `Small World Patterns in Food
Webs', \emph{Journal of Theoretical Biology}, 214(3), pp. 405--412. doi:
\href{https://doi.org/10.1006/jtbi.2001.2460}{10.1006/jtbi.2001.2460}.
\hypertarget{ref-mont03tpf}{}
Montoya, J. M. and SolΓ©, R. V. (2003) `Topological properties of food
webs: from real data to community assembly models', \emph{Oikos},
102(3), pp. 614--622. doi:
\href{https://doi.org/10.1034/j.1600-0706.2003.12031.x}{10.1034/j.1600-0706.2003.12031.x}.
\hypertarget{ref-mont06ent}{}
Montoya, J. M., Pimm, S. L. and SolΓ©, R. V. (2006) `Ecological networks
and their fragility', \emph{Nature}, 442(7100), pp. 259--264. doi:
\href{https://doi.org/10.1038/nature04927}{10.1038/nature04927}.
\hypertarget{ref-mora15ibi}{}
Morales-Castilla, I., Matias, M. G., Gravel, D. and AraΓΊjo, M. B. (2015)
`Inferring biotic interactions from proxies', \emph{Trends in Ecology \&
Evolution}, 30(6), pp. 347--356. doi:
\href{https://doi.org/10.1016/j.tree.2015.03.014}{10.1016/j.tree.2015.03.014}.
\hypertarget{ref-nuis13cam}{}
Nuismer, S. L., Jordano, P. and Bascompte, J. (2013) `COEVOLUTION AND
THE ARCHITECTURE OF MUTUALISTIC NETWORKS: COEVOLVING NETWORKS',
\emph{Evolution}, 67(2), pp. 338--354. doi:
\href{https://doi.org/10.1111/j.1558-5646.2012.01801.x}{10.1111/j.1558-5646.2012.01801.x}.
\hypertarget{ref-oles11mfl}{}
Olesen, J. M., Bascompte, J. and Dupont, Y. L. \emph{et al.} (2011)
`Missing and forbidden links in mutualistic networks', \emph{Proceedings
of the Royal Society of London B: Biological Sciences}, 278(1706), pp.
725--732. Available at:
\url{http://rspb.royalsocietypublishing.org/content/278/1706/725.short}
(Accessed: 21 February 2017).
\hypertarget{ref-oles08tdpb}{}
Olesen, J. M., Bascompte, J., Elberling, H. and Jordano, P. (2008)
`TEMPORAL DYNAMICS IN A POLLINATION NETWORK', \emph{Ecology}, 89(6), pp.
1573--1582. doi:
\href{https://doi.org/10.1890/07-0451.1}{10.1890/07-0451.1}.
\hypertarget{ref-pear03pic}{}
Pearson, R. G. and Dawson, T. P. (2003) `Predicting the impacts of
climate change on the distribution of species: are bioclimate envelope
models useful?', \emph{Global Ecology and Biogeography}, 12(5), pp.
361--371. doi:
\href{https://doi.org/10.1046/j.1466-822X.2003.00042.x}{10.1046/j.1466-822X.2003.00042.x}.
\hypertarget{ref-pear02sse}{}
Pearson, R. G., Dawson, T. P., Berry, P. M. and Harrison, P. A. (2002)
`SPECIES: A Spatial Evaluation of Climate Impact on the Envelope of
Species', \emph{Ecological Modelling}, 154(3), pp. 289--300. doi:
\href{https://doi.org/10.1016/S0304-3800(02)00056-X}{10.1016/S0304-3800(02)00056-X}.
\hypertarget{ref-pois14wen}{}
Poisot, T. and Gravel, D. (2014) `When is an ecological network complex?
Connectance drives degree distribution and emerging network properties',
\emph{PeerJ}, 2, p. e251. doi:
\href{https://doi.org/10.7717/peerj.251}{10.7717/peerj.251}.
\hypertarget{ref-pois12dsi}{}
Poisot, T., Canard, E. and Mouillot, D. \emph{et al.} (2012) `The
dissimilarity of species interaction networks', \emph{Ecology Letters},
15(12), pp. 1353--1361. doi:
\href{https://doi.org/10.1111/ele.12002}{10.1111/ele.12002}.
\hypertarget{ref-pois17hpt}{}
Poisot, T., GuΓ©veneux-Julien, C. and Fortin, M.-J. \emph{et al.} (2017)
`Hosts, parasites and their interactions respond to different climatic
variables: POISOT et al.', \emph{Global Ecology and Biogeography},
26(8), pp. 942--951. doi:
\href{https://doi.org/10.1111/geb.12602}{10.1111/geb.12602}.
\hypertarget{ref-pois13tcd}{}
Poisot, T., Mouquet, N. and Gravel, D. (2013) `Trophic complementarity
drives the biodiversity-ecosystem functioning relationship in food
webs', \emph{Ecology Letters}, 16(7), pp. 853--861. doi:
\href{https://doi.org/10.1111/ele.12118}{10.1111/ele.12118}.
\hypertarget{ref-pois15swe}{}
Poisot, T., Stouffer, D. B. and Gravel, D. (2015) `Beyond species: why
ecological interaction networks vary through space and time',
\emph{Oikos}, 124(3), pp. 243--251. doi:
\href{https://doi.org/10.1111/oik.01719}{10.1111/oik.01719}.
\hypertarget{ref-poll14ucm}{}
Pollock, L. J., Tingley, R. and Morris, W. K. \emph{et al.} (2014)
`Understanding co-occurrence by modelling species simultaneously with a
Joint Species Distribution Model (JSDM)', \emph{Methods in Ecology and
Evolution}, 5(5), pp. 397--406. doi:
\href{https://doi.org/10.1111/2041-210X.12180}{10.1111/2041-210X.12180}.
\hypertarget{ref-reze09cmf}{}
Rezende, E. L., Albert, E. M., Fortuna, M. A. and Bascompte, J. (2009)
`Compartments in a marine food web associated with phylogeny, body mass,
and habitat structure', \emph{Ecology Letters}, 12(8), pp. 779--788.
doi:
\href{https://doi.org/10.1111/j.1461-0248.2009.01327.x}{10.1111/j.1461-0248.2009.01327.x}.
\hypertarget{ref-reze07epc}{}
Rezende, E. L., Jordano, P. and Bascompte, J. (2007) `Effects of
phenotypic complementarity and phylogeny on the nested structure of
mutualistic networks', \emph{Oikos}, 116(11), pp. 1919--1929. doi:
\href{https://doi.org/10.1111/j.0030-1299.2007.16029.x}{10.1111/j.0030-1299.2007.16029.x}.
\hypertarget{ref-sole01cfe}{}
SolΓ©, R. V. and Montoya, M. (2001) `Complexity and fragility in
ecological networks', \emph{Proceedings of the Royal Society of London
B: Biological Sciences}, 268(1480), pp. 2039--2045. doi:
\href{https://doi.org/10.1098/rspb.2001.1767}{10.1098/rspb.2001.1767}.
\hypertarget{ref-souz16qca}{}
Souza, A. F., Bezerra, A. D. and Longhi, S. J. (2016) `Quasi-neutral
community assembly: Evidence from niche overlap, phylogenetic, and trait
distribution analyses of a subtropical forest in South America',
\emph{Perspectives in Plant Ecology, Evolution and Systematics}, 23, pp.
1--10. doi:
\href{https://doi.org/10.1016/j.ppees.2016.09.006}{10.1016/j.ppees.2016.09.006}.
\hypertarget{ref-stou10ufp}{}
Stouffer, D. B. and Bascompte, J. (2010) `Understanding food-web
persistence from local to global scales', \emph{Ecology Letters}, 13(2),
pp. 154--161. doi:
\href{https://doi.org/10.1111/j.1461-0248.2009.01407.x}{10.1111/j.1461-0248.2009.01407.x}.
\hypertarget{ref-stou12ecs}{}
Stouffer, D. B., Sales-Pardo, M., Sirer, M. I. and Bascompte, J. (2012)
`Evolutionary Conservation of Species' Roles in Food Webs',
\emph{Science}, 335(6075), pp. 1489--1492. doi:
\href{https://doi.org/10.1126/science.1216556}{10.1126/science.1216556}.
\hypertarget{ref-sugi09csc}{}
Sugihara, G. and Ye, H. (2009) `Complex systems: Cooperative network
dynamics', \emph{Nature}, 458(7241), pp. 979--980. doi:
\href{https://doi.org/10.1038/458979a}{10.1038/458979a}.
\hypertarget{ref-theb03fcb}{}
Thebault, E. and Loreau, M. (2003) `Food-web constraints on
biodiversity-ecosystem functioning relationships', \emph{Proceedings of
the National Academy of Sciences}, 100(25), pp. 14949--14954. doi:
\href{https://doi.org/10.1073/pnas.2434847100}{10.1073/pnas.2434847100}.
\hypertarget{ref-theb10sec}{}
ThΓ©bault, E. and Fontaine, C. (2010) `Stability of Ecological
Communities and the Architecture of Mutualistic and Trophic Networks',
\emph{Science}, 329(5993), pp. 853--856. doi:
\href{https://doi.org/10.1126/science.1188321}{10.1126/science.1188321}.
\hypertarget{ref-theb07cee}{}
ThΓ©bault, E., Huber, V. and Loreau, M. (2007) `Cascading extinctions and
ecosystem functioning: contrasting effects of diversity depending on
food web structure', \emph{Oikos}, 116(1), pp. 163--173. doi:
\href{https://doi.org/10.1111/j.2006.0030-1299.15007.x}{10.1111/j.2006.0030-1299.15007.x}.
\hypertarget{ref-tilm04ntn}{}
Tilman, D. (2004) `Niche tradeoffs, neutrality, and community structure:
A stochastic theory of resource competition, invasion, and community
assembly', \emph{Proceedings of the National Academy of Sciences of the
United States of America}, 101(30), pp. 10854--10861. doi:
\href{https://doi.org/10.1073/pnas.0403458101}{10.1073/pnas.0403458101}.
\hypertarget{ref-troj16enm}{}
TrΓΈjelsgaard, K. and Olesen, J. M. (2016) `Ecological networks in
motion: micro- and macroscopic variability across scales',
\emph{Functional Ecology}, 30(12), pp. 1926--1935. doi:
\href{https://doi.org/10.1111/1365-2435.12710}{10.1111/1365-2435.12710}.
\hypertarget{ref-troj15gvm}{}
TrΓΈjelsgaard, K., Jordano, P., Carstensen, D. W. and Olesen, J. M.
(2015) `Geographical variation in mutualistic networks: similarity,
turnover and partner fidelity', \emph{Proceedings of the Royal Society
B: Biological Sciences}, 282(1802), pp. 20142925--20142925. doi:
\href{https://doi.org/10.1098/rspb.2014.2925}{10.1098/rspb.2014.2925}.
\hypertarget{ref-verd08nap}{}
VerdΓΊ, M. and ValienteβBanuet, A. (2008) `The Nested Assembly of Plant
Facilitation Networks Prevents Species Extinctions', \emph{The American
Naturalist}, 172(6), pp. 751--760. doi:
\href{https://doi.org/10.1086/593003}{10.1086/593003}.
\hypertarget{ref-verh38nlq}{}
Verhulst, P. (1938) `Notice sur la loi que la population suit dans son
accroissement', \emph{Curr. Math. Phys}, 10.
\hypertarget{ref-will11bmc}{}
Williams, R. J. (2011) `Biology, Methodology or Chance? The Degree
Distributions of Bipartite Ecological Networks', \emph{PLoS One}. Edited
by J. Langowski, 6(3), p. e17645. doi:
\href{https://doi.org/10.1371/journal.pone.0017645}{10.1371/journal.pone.0017645}.
\hypertarget{ref-will00srya}{}
Williams, R. J. and Martinez, N. D. (2000) `Simple rules yield complex
food webs', \emph{Nature}, 404(6774), pp. 180--183. doi:
\href{https://doi.org/10.1038/35004572}{10.1038/35004572}.
\hypertarget{ref-will07hyi}{}
Williams, R. J., Brose, U. and Martinez, N. D. (2007) `Homage to Yodzis
and Innes 1992: scaling up feeding-based population dynamics to complex
ecological networks', in \emph{From energetics to ecosystems: the
dynamics and structure of ecological systems}. Springer, pp. 37--51.
Available at:
\url{http://link.springer.com/content/pdf/10.1007/978-1-4020-5337-5_2.pdf}
(Accessed: 26 May 2016).
\hypertarget{ref-yodz81sre}{}
Yodzis, P. (1981) `The stability of real ecosystems', \emph{Nature},
289(5799), pp. 674--676. doi:
\href{https://doi.org/10.1038/289674a0}{10.1038/289674a0}.
\end{document}
|
theory FilteredList
imports MoreCoinductiveList2
begin
subsection \<open>More on filtered lists\<close>
text \<open>We will reason about (co-inductive) lists with distinct elements.
However, for our setting, this 'distinct' property only holds on the list after filtering.
For this reason, we need some additional lemmas.\<close>
text \<open>Taking a sublist preserves distinctness after filtering.\<close>
lemma ldistinct_lfilter_ltake[intro]:
assumes "ldistinct (lfilter P xs)"
shows "ldistinct (lfilter P (ltake x xs))"
using assms
by(induct xs,force,force
,(* sledgehammer found this gem to prove the inductive step via lfilter_lappend_lfinite!
We will use this strategy ourselves later on *)
metis lappend_ltake_ldrop ldistinct_lappend lfilter_lappend_lfinite lfinite_LConsI lfinite_ltake)
text \<open>The function lfind is used in multiple proofs, all are introduced to prove ltake_lfilter.\<close>
definition lfind where "lfind P lst = (LEAST i. P (lst $ i))"
lemma lfilter_lfind:
assumes "lfilter P lst \<noteq> LNil"
shows "P (lst $ lfind P lst)" (is ?g1)
"P (lst $ y) \<Longrightarrow> lfind P lst \<le> y" (is "?a \<Longrightarrow> ?g2")
"lfind P lst < llength lst" (is ?g3)
proof -
let ?I = "{n. enat n < llength lst \<and> P (lst $ n)}"
let ?xs = lst
from assms[unfolded lfilter_conv_lnths] lset_LNil
have "lset (lnths lst {n. enat n < llength lst \<and> P (lst $ n)}) \<noteq> {}" by auto
hence "{?xs $ i |i. enat i < llength ?xs \<and> i \<in> ?I} \<noteq> {}" using lset_lnths[of ?xs ?I] by metis
then obtain i where p:"P (lst $ i)" "i < llength lst" by auto
from p show ?g1 using LeastI lfind_def by metis
from p show "?a \<Longrightarrow> ?g2" using Least_le lfind_def by metis
from p show ?g3 using Least_le lfind_def by (metis enat_ord_simps(1) le_less_trans)
qed
lemma ltake_lfind_lset:
assumes "x \<in> lset (ltake (enat (lfind P lst)) lst)"
shows "\<not> P x"
proof(cases "lfilter P (ltake (enat (lfind P lst)) lst) = LNil")
case True
then show ?thesis using assms unfolding lfilter_eq_LNil by auto
next
case False
from assms[unfolded in_lset_conv_lnth] obtain n where
n:"enat n < llength (ltake (enat (lfind P lst)) lst)" "ltake (enat (lfind P lst)) lst $ n = x"
by blast
{ assume a:"P x"
(* The idea of this {block} is that the element n must come after (lfind P lst) by lfilter_lfind(2)
but this contradicts n(1).
However, in the last step when writing this proof, sledgehammer found one that didn't use
any of my previous steps, so here's a one-liner: *)
from n Coinductive_List.lset_ltake False a enat_ord_simps(1) leD lfilter_empty_conv lfilter_lfind(2,3) llength_ltake' lnth_ltake subset_eq
have False by metis
}
then show ?thesis by blast
qed
lemma ltake_lfind_conv:
assumes "lfilter P lst \<noteq> LNil"
shows "ltake (lfind P lst) lst = ltakeWhile (Not o P) lst" (is "?t1 = ?t2")
"ldrop (lfind P lst) lst = ldropWhile (Not o P) lst" (is "?t3 = ?t4")
proof -
have lfin:"lfinite ?t1" by simp
have [simp]:"min (enat (lfind P lst)) (llength lst) = (lfind P lst)"
using lfilter_lfind(3)[OF assms] by (metis min.strict_order_iff)
have l1:"llength ?t1 = lfind P lst" by simp
from ltake_lfind_lset ltakeWhile_all
have t:"ltakeWhile (Not o P) ?t1 = ?t1" unfolding o_def by metis
have inset:"lset (ltake (enat (lfind P lst)) lst) \<subseteq> {x. (Not \<circ> P) x}"
using ltake_lfind_lset[of _ P lst] by auto (* for use in ltakeWhile_lappend2 *)
have isnull:"ltakeWhile (Not \<circ> P) (ldrop (enat (lfind P lst)) lst) = LNil"
apply(cases "ldrop (enat (lfind P lst)) lst")
using lfilter_lfind(1)[OF assms] lhd_ldrop[OF lfilter_lfind(3)[OF assms]]
by auto
have "ltakeWhile (Not o P) ?t1 = ltakeWhile (Not o P) (lappend ?t1 ?t3)"
unfolding ltakeWhile_lappend2[OF inset] isnull lappend_LNil2 t..
hence leneq:"llength ?t1 = llength ?t2" using t l1 lappend_ltake_ldrop by metis
have "lappend ?t1 ?t3 = lappend ?t2 ?t4"
unfolding lappend_ltakeWhile_ldropWhile[of "Not \<circ> P" lst]
lappend_ltake_ldrop[of "lfind P lst" lst]
by simp
from this[unfolded lappend_eq_lappend_conv[OF leneq]] lfin
show "?t1 = ?t2" "?t3 = ?t4" by auto
qed
lemma lfilter_hdtl:
assumes "lfilter P lst \<noteq> LNil"
shows "\<exists> n. LCons (lhd (lfilter P lst)) LNil = lfilter P (ltake (enat n) lst) \<and>
ltl (lfilter P lst) = lfilter P (ldrop (enat n) lst)"
proof(standard,standard)
note * = lfilter_lfind[OF assms]
let ?n = "Suc (lfind P lst)"
let ?ltake = "ltake (enat ?n) lst"
have ltake:"lappend (ltakeWhile (Not \<circ> P) ?ltake) (ldropWhile (Not \<circ> P) ?ltake) = ?ltake"
(is "lappend ?ltw ?ldw = _")
using lappend_ltakeWhile_ldropWhile by blast
have "llength ?ldw \<le> 1"
unfolding ldropWhile_lappend ltake_Suc_conv_snoc_lnth[OF *(3)]
using ltake_lfind_lset[of _ P lst] by (auto intro:* simp:one_eSuc)
hence null:"lnull (ltl (ldropWhile (Not \<circ> P) ?ltake))"
unfolding llength_eq_0[symmetric] llength_ltl
by (metis dual_order.order_iff_strict enat_ile epred_0 epred_1 iless_Suc_eq le_zero_eq one_eSuc one_enat_def)
have e:"enat (lfind P lst) < enat (Suc (lfind P lst))" by auto
from * have "P (?ltake $ lfind P lst)" using lnth_ltake[OF e] by metis
hence nonnull:"\<not> lnull (lfilter P ?ltake)" unfolding lnull_lfilter
by (metis "*"(3) e in_lset_conv_lnth leI llength_ltake' ltake_all)
show a:"LCons (lhd (lfilter P lst)) LNil = lfilter P ?ltake" (is "?lhs = ?rhs")
proof -
have "lhd (lfilter P ?ltake) = lhd (lfilter P lst)"
by(rule lprefix_lhdD[OF lprefix_lfilterI[OF ltake_is_lprefix] nonnull])
hence h:"lhd ?lhs = lhd ?rhs" by simp
have "ltl ?rhs = LNil"
unfolding ltl_lfilter using null by (metis lfilter_LNil llist.collapse(1))
hence t:"ltl ?lhs = ltl ?rhs" by simp
have flt:"?rhs \<noteq> LNil" using nonnull by fastforce
show ?thesis by(rule llist_eq_lcons[of ?lhs ?rhs,OF _ flt h t],auto)
qed
from lappend_ltake_ldrop[of ?n lst] lappend_ltakeWhile_ldropWhile[of "Not \<circ> P" lst]
have "lappend (ltake ?n lst) (ldrop ?n lst) = lappend (ltakeWhile (Not \<circ> P) lst) (ldropWhile (Not \<circ> P) lst)"
by auto
from ltake_lfind_conv(2)[OF assms]
have "ltl (ldropWhile (Not \<circ> P) lst) = ldrop (enat (Suc (lfind P lst))) lst"
unfolding ldrop_eSuc_conv_ltl eSuc_enat[symmetric] by simp
thus "ltl (lfilter P lst) = lfilter P (ldrop (enat ?n) lst)" unfolding ltl_lfilter by metis
qed
lemma ltake_lfilter:
shows "\<exists> n. ltake (enat x) (lfilter P lst) = lfilter P (ltake (enat n) lst) \<and> ldrop (enat x) (lfilter P lst) = lfilter P (ldrop (enat n) lst)"
proof(induct x)
case 0
then show ?case by (metis LNil_eq_ltake_iff ldrop_enat ldropn_0 lfilter_code(1) zero_enat_def)
next
let ?fP = "lfilter P"
case (Suc x)
then obtain n where n:"ltake (enat x) (?fP lst) = ?fP (ltake (enat n) lst)"
"ldrop (enat x) (lfilter P lst) = lfilter P (ldrop (enat n) lst)" by blast
consider "lfilter P (ldrop (enat n) lst) \<noteq> LNil \<and> x < llength (?fP lst)" |
"lfilter P (ldrop (enat n) lst) = LNil" | "x \<ge> llength (?fP lst)" by force
then show ?case proof(cases)
case 1
hence *:"lfilter P (ldrop (enat n) lst) \<noteq> LNil" "enat x < llength (lfilter P lst)" by auto
from lappend_ltake_ldrop have "lst = lappend (ltake (enat n) lst) (ldrop (enat n) lst)" by metis
from lfilter_hdtl[OF *(1)] obtain delta where
delta:"LCons (lhd (?fP (ldrop (enat n) lst))) LNil = ?fP (ltake (enat delta) (ldrop (enat n) lst))"
"ltl (lfilter P (ldrop (enat n) lst)) = lfilter P (ldrop (enat delta) (ldrop (enat n) lst))" by blast
have "ltake (enat (Suc x)) (?fP lst) = lappend (?fP (ltake (enat n) lst)) (LCons (?fP lst $ x) LNil)"
using n ltake_Suc_conv_snoc_lnth * by metis
also have "?fP lst $ x = ?fP lst $ (the_enat x)" by auto
also have "\<dots> = lhd (ldrop x (?fP lst))" using lhd_ldrop[symmetric] *(2) by metis
also have "\<dots> = lhd (?fP (ldrop (enat n) lst))" using n by metis
also note delta(1)
finally have take_part:"ltake (enat (Suc x)) (?fP lst) = ?fP (ltake (enat (n + delta)) lst)"
using ltake_plus_conv_lappend
by (metis infinite_small_llength lfilter_lappend_lfinite llength_ltake' ltake_all min.strict_order_iff not_less plus_enat_simps(1))
have "ldrop (enat (Suc x)) (?fP lst) = ltl (ldrop x (?fP lst))" by (simp add: ltl_ldropn ldrop_eSuc_ltl ldrop_enat)
also have "ldrop x (?fP lst) = ?fP (ldrop (enat n) lst)" using n by metis
also note delta(2)
also have "lfilter P (ldrop (enat delta) (ldrop (enat n) lst)) = lfilter P (ldrop (enat delta + enat n) lst)"
by simp
also have "(enat delta + enat n) = enat (n + delta)" by simp
finally have drop_part:"ldrop (enat (Suc x)) (?fP lst) = ?fP (ldrop (enat (n + delta)) lst)".
from take_part drop_part show ?thesis by blast
next
case 2
note * = 2 lappend_ltake_ldrop[of "enat n" lst] Suc_llength infinite_small_llength
lappend_LNil2 leI lfilter_lappend_lfinite llength_ltake' min.strict_order_iff n
have take_part:"ltake (enat (Suc x)) (?fP lst) = ?fP (ltake (enat n) lst)"
using * by (smt (z3) ltake_all)
from 2 have drop_part:"ldrop (enat (Suc x)) (?fP lst) = ?fP (ldrop (enat n) lst)"
using * by (smt (z3) ldrop_all)
from take_part drop_part show ?thesis by blast
next
case 3
then show ?thesis using n dual_order.order_iff_strict eSuc_enat iless_Suc_eq le_less_trans ltake_all ldrop_all
by metis
qed
qed
lemma filter_obtain_two:
assumes "i < j" "j < length (filter P lst)"
shows "\<exists> i2 j2. i2 < j2 \<and> j2 < length lst \<and> lst ! i2 = filter P lst ! i \<and> lst ! j2 = filter P lst ! j"
using assms
proof(induct lst arbitrary: i j)
case (Cons a lst)
then obtain jprev where jprev:"j = Suc jprev" using lessE by metis
show ?case proof(cases "P a")
case True
hence lnth[simp]:"length (filter P (a # lst)) = Suc (length (filter P lst))" by auto
show ?thesis proof(cases i)
case 0
from jprev True Cons(3) have "jprev < length (filter P lst) " by auto
from nth_mem[OF this]
have "filter P lst ! jprev \<in> set lst" by auto
from this[unfolded in_set_conv_nth] obtain j2 where
"j2<length lst" "lst ! j2 = filter P lst ! jprev" by blast
hence "0 < Suc j2" "Suc j2 < length (a # lst)"
"(a # lst) ! 0 = filter P (a # lst) ! i"
"(a # lst) ! Suc j2 = filter P (a # lst) ! j" using 0 True jprev by auto
then show ?thesis by blast
next
case (Suc nat)
then obtain jprev where jprev:"j = Suc jprev" using Cons lessE by metis
hence "nat < jprev" "jprev < length (filter P lst)" using Cons Suc lnth by auto
from Cons(1)[OF this] obtain i2 j2 where "i2 < j2" "j2 < length lst"
"lst ! i2 = filter P lst ! nat" "lst ! j2 = filter P lst ! jprev" by blast
hence "Suc i2 < Suc j2" "Suc j2 < length (a # lst)"
"(a # lst) ! Suc i2 = filter P (a # lst) ! Suc nat"
"(a # lst) ! Suc j2 = filter P (a # lst) ! Suc jprev" using lnth by auto
then show ?thesis unfolding jprev[symmetric] Suc[symmetric] by blast
qed
next
case False
hence [simp]: "filter P (a # lst) = filter P lst" by auto
from Cons(1)[OF Cons(2)] Cons(3)[unfolded this]
obtain i2 j2 where "i2 < j2" "j2 < length lst"
"lst ! i2 = filter P lst ! i" "lst ! j2 = filter P lst ! j" by blast
hence "Suc i2 < Suc j2" "Suc j2 < length (a # lst)"
"(a # lst) ! Suc i2 = filter P (a # lst) ! i"
"(a # lst) ! Suc j2 = filter P (a # lst) ! j" by (auto simp:False)
then show ?thesis by blast
qed
qed auto
lemma ldistinct_lfilterI:
assumes "\<And> i j. i < llength lst \<Longrightarrow> j < llength lst \<Longrightarrow> lst $ i = lst $ j \<Longrightarrow> P (lst $ i) \<Longrightarrow> i = j"
shows "ldistinct (lfilter P lst)"
proof -
{ fix i j
assume *: "enat i < llength (lfilter P lst)"
"enat j < llength (lfilter P lst)"
"lfilter P lst $ i = lfilter P lst $ j"
"i < j"
hence "lfilter P lst $ i \<in> lset (lfilter P lst)"
unfolding in_lset_conv_lnth by auto
with lset_lfilter
have P:"P (lfilter P lst $ i)" by auto
let ?maxij = "Suc (max i j)"
from ltake_lfilter obtain maxij where
maxij:"ltake ?maxij (lfilter P lst) = lfilter P (ltake (enat maxij) lst)"
by blast
let ?lst = "ltake (enat maxij) lst"
have "lfinite ?lst" by auto
define flst where "flst = list_of ?lst"
hence flst:"llist_of flst = ?lst" by auto
let ?flst = "llist_of flst"
from * P
have "enat i < llength (lfilter P ?flst)"
"enat j < llength (lfilter P ?flst)"
"lfilter P ?flst $ i = lfilter P ?flst $ j"
and P2:"P (lfilter P ?lst $ i)"
unfolding maxij[symmetric] flst by (auto simp add: lnth_ltake)
hence "i < length (filter P flst)"
"j < length (filter P flst)"
and eq_ij: "filter P flst ! i = filter P flst ! j"
unfolding llength_llist_of lfilter_llist_of lnth_llist_of by auto
with filter_obtain_two[OF *(4) this(2)] obtain i2 j2
where "i2 < length flst" "j2 < length flst"
"flst ! i2 = filter P flst ! i"
"flst ! j2 = filter P flst ! j"
and ineq:"i2<j2"
by auto
hence "i2 < llength ?flst" "j2 < llength ?flst" "?flst $ i2 = ?flst $ j2" "?flst $ i2 = lfilter P ?flst $ i" "i2<j2"
unfolding llength_llist_of lfilter_llist_of lnth_llist_of eq_ij by auto
hence "enat i2 < llength lst" "enat j2 < llength lst" "lst $ i2 = lst $ j2" "P (lst $ i2)"
using P2 unfolding flst by (auto simp add: lnth_ltake)
from assms[OF this]
have False using ineq by auto
}
thus ?thesis unfolding ldistinct_conv_lnth by (smt (z3) le_cases3 less_le)
qed
lemma ldistinct_lfilterE:
assumes "ldistinct (lfilter P lst)" "e = lst $ i" "e = lst $ j"
"i < llength lst" "j < llength lst" "P e"
shows "i = j"
proof -
let ?maxij = "Suc (max i j)"
let ?lst = "ltake (enat ?maxij) lst"
have jle:"j < length (list_of (ltake (enat (Suc (max i j))) lst))" using assms(4,5)
apply(subst length_list_of_conv_the_enat,force)
by(cases "llength lst", auto simp:min_enat2_conv_enat min_enat1_conv_enat)
have ile:"i < length (list_of (ltake (enat (Suc (max i j))) lst))" using assms(4,5)
apply(subst length_list_of_conv_the_enat,force)
by(cases "llength lst", auto simp:min_enat2_conv_enat min_enat1_conv_enat)
have "enat i < ?maxij" "enat j < ?maxij" by auto
from this[THEN lnth_ltake,of lst] assms
have "ldistinct (lfilter P ?lst)" "e = ?lst $ i" "e = ?lst $ j" by auto
hence d:"distinct (filter P (list_of ?lst))"
"(list_of ?lst) ! j = e" "(list_of ?lst) ! i = e"
using lfilter_llist_of[of P "list_of ?lst"] by auto
show ?thesis by(rule distinct_filterD[OF d(1) jle ile assms(6) d(2,3)])
qed
lemma ldistinct_lfilter_conv:
"ldistinct (lfilter P lst) = (\<forall> i j. i < llength lst \<longrightarrow> j < llength lst \<longrightarrow> P (lst $ i) \<longrightarrow> lst $ i = lst $ j \<longrightarrow> i = j)"
proof
show "ldistinct (lfilter P lst) \<Longrightarrow> \<forall>i j. enat i < llength lst \<longrightarrow> enat j < llength lst \<longrightarrow> P (lst $ i) \<longrightarrow> lst $ i = lst $ j \<longrightarrow> i = j"
by (auto simp add: ldistinct_lfilterE)
show "\<forall>i j. enat i < llength lst \<longrightarrow> enat j < llength lst \<longrightarrow> P (lst $ i) \<longrightarrow> lst $ i = lst $ j \<longrightarrow> i = j \<Longrightarrow> ldistinct (lfilter P lst) "
using ldistinct_lfilterI by blast
qed
end |
Formal statement is: lemma map_poly_map_poly: assumes "f 0 = 0" "g 0 = 0" shows "map_poly f (map_poly g p) = map_poly (f \<circ> g) p" Informal statement is: If $f(0) = 0$ and $g(0) = 0$, then $f(g(p)) = (f \circ g)(p)$. |
import Data.Nat
import Data.Vect
import Language.Reflection
%language ElabReflection
fc : FC
fc = EmptyFC
quoteTest : TTImp -> TTImp -> List Decl
quoteTest f arg = `[ myFunc : ~(IApp fc f arg) ]
axes : (n : Nat) -> {auto gt : GT n 0} -> {auto lte : LTE n 4} -> Vect n String
axes 1 = ["x"]
axes 2 = "y" :: axes 1
axes 3 = "z" :: axes 2
axes 4 = "w" :: axes 3
axes (S (S (S (S (S _))))) {lte} = absurd lte
mkPoint : (n : Nat) -> {auto gt : GT n 0} -> {auto lte : LTE n 4} -> Decl
mkPoint n
= let type = "Point" ++ show n ++ "D" in
let mkMainUN = NS (MkNS ["Main"]) . UN . Basic in
IRecord emptyFC Nothing Public
(MkRecord emptyFC (mkMainUN type) [] (mkMainUN ("Mk" ++ type))
(toList $ map (\axis => MkIField emptyFC MW ExplicitArg (UN (Field axis)) `(Double)) (axes n)))
logDecls : TTImp -> Elab (Int -> Int)
logDecls v
= do declare [IClaim EmptyFC MW Public []
(MkTy EmptyFC EmptyFC `{ Main.foo }
`(Int -> Int -> Int) )]
declare `[ foo x y = x + y ]
declare [ mkPoint 3 ]
declare `[ multBy : Int -> Int
multBy x = x * ~(v) ]
declare `[ myplus : Nat -> Nat -> Nat
myplus Z y = y
myplus (S k) y = S (myplus k y) ]
check `( multBy )
mkMult : Int -> Int
mkMult = %runElab logDecls `(4)
point : Point3D
point = MkPoint3D 1.0 2.0 3.0
|
import Data.List.Views
-- total
isSuffix : Eq a => List a -> List a -> Bool
isSuffix input1 input2 with (MkPair (snocList input1) (snocList input2))
isSuffix [] input2 | (Empty, s) = True
isSuffix input1 [] | (s, Empty) = False
isSuffix (xs ++ [x]) (ys ++ [y]) | (MkPair (Snoc x xs xsrec) (Snoc y ys ysrec))
= if x == y
then isSuffix xs ys | (MkPair xsrec ysrec)
else False
|
using MIDI
const N_OCTAVES = 8
const RANGE_MIN = name_to_pitch("C0")
const NOTE_RANGE = [Note(RANGE_MIN+i, 127, 0, 0) for i in 0:N_OCTAVES*12]
const RANGE_MAX = NOTE_RANGE[end]
const MIDDLE_C = Note(name_to_pitch("C4"), 127, 0, 0)
const NOTE_LETTERS = 'A', 'B', 'C', 'D', 'E', 'F', 'G'
const SHARP = 'β―'
|
-- Contributors : Adarsh, Anurag, Nikhesh, Sainiranjan.
import Mathlib
import PnP2023.Lec_02_03.InductiveTypes
/-!
Vectors, i.e., lists of a fixed length, can be defined in (at least) two ways. One way is as an indexed inductive type `Vec`, as we saw in lecture and is in the file `InductiveTypes.lean`.
A different definition is as a subtype `Vector` of lists consisting of those of a fixed length. This is the definition used in `mathlib` and is recalled below.
```lean
/-- `Vector Ξ± n` is the type of lists of length `n` with elements of type `Ξ±`. -/
def Vector (Ξ± : Type u) (n : β) :=
{ l : List Ξ± // l.length = n }
```
In this lab, you will relate the two definitions by constructing functions that convert between the two definitions and prove that these functions are inverses of each other.
-/
universe u
/-- Convert a `Vector` to a `Vec` -/
def Vec.ofVector {Ξ± : Type u}: (n : β) β Vector Ξ± n β Vec Ξ± n
| 0, _ => Vec.nil
| k + 1, β¨ head :: tail, h β© => by
have h1 : tail.length = k := by
simp [List.length_cons] at h
assumption
apply Vec.cons head (Vec.ofVector k β¨ tail, h1β© )
/-- Convert a `Vec` to a `Vector` -/
def Vec.toVector {Ξ± : Type u}: (n : β) β Vec Ξ± n β Vector Ξ± n
| 0, _ => β¨ [], rfl β©
| k + 1, Vec.cons head tail => β¨ head :: (Vec.toVector k tail).val, by
simp [List.length]; apply (Vec.toVector k tail).propertyβ©
/-- Mapping a `Vec` to a `Vector` and back gives the original `Vec` -/
theorem Vec.ofVector.toVector {Ξ± : Type u} (n : β) (v : Vec Ξ± n) :
Vec.ofVector n (Vec.toVector n v) = v :=
match n with
| 0 => by
rw [Vec.ofVector]
match v with
| Vec.nil => rfl
| k + 1 => by
match v with
| Vec.cons head tail =>
simp [Vec.ofVector]
apply Vec.ofVector.toVector k tail
/-- Mapping a `Vector` to a `Vec` and back gives the original `Vector` -/
theorem Vec.toVector.ofVector {Ξ± : Type u} (n : β) (v : Vector Ξ± n) :
Vec.toVector n (Vec.ofVector n v) = v :=
match n with
| 0 => by
rw [Vec.toVector]
match v with
| Vector.nil => rfl
| k + 1 => by
match v with
| β¨ head :: tail, hβ© =>
simp[toVector]
simp[ofVector] |
/-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under MIT license as described in the file LICENSE.
Authors: Eric Wieser
-/
import geometric_algebra.from_mathlib.basic
import linear_algebra.clifford_algebra.conjugation
import algebra.module.opposites
variables {R : Type*} [comm_ring R]
variables {M : Type*} [add_comm_group M] [module R M]
variables {Q : quadratic_form R M}
/-!
# Conjugations
This file contains additional lemmas about `clifford_algebra.reverse` and `clifford_algebra.involute`.
As more and more goes into Mathlib, this file will become smaller and spaller.
The links above will take you to the collection of mathlib theorems.
-/
namespace clifford_algebra
section reverse
open mul_opposite
/-- helper lemma for expanding the sign of reverse -/
lemma reverse_prod_sign_aux (n : β) :
(-1 : R)^((n + 1)*(n + 1 + 1)/2) = (-1 : R)^(n*(n + 1)/2) * (-1 : R)^(n + 1) :=
begin
-- work with just the exponents
rw βpow_add,
conv_rhs { rw neg_one_pow_eq_pow_mod_two },
conv_lhs { rw neg_one_pow_eq_pow_mod_two },
congr' 1,
-- work through the ugly nat proof
rw [add_mul, one_mul, mul_add _ (n + 1), mul_one, add_assoc, add_assoc n 1 1, βadd_assoc n n, βmul_two, βmul_two],
have : 0 < 2 := by linarith,
rw [nat.add_div_eq_of_add_mod_lt _, nat.add_div_eq_of_add_mod_lt _, nat.mul_div_cancel _ this, nat.mul_div_cancel _ this],
-- extra goals created by `add_div_eq_of_add_mod_lt`
{ rw [nat.mul_mod_left, nat.mul_mod_left, zero_add],
exact this },
{ rw [nat.add_mod (n * 2), nat.mul_mod_left, nat.mul_mod_left, add_zero, nat.zero_mod, add_zero],
exact nat.mod_lt _ this },
end
/-- TODO: this needs an assumption that the vectors are othogonal -/
lemma reverse_prod_map_sign (l : list M):
reverse (l.map $ ΞΉ Q).prod = ((-1 : R)^(l.length*(l.length + 1)/2)) β’ (l.map $ ΞΉ Q).prod :=
begin
induction l with x xs hxs,
{ simp },
simp [hxs, reverse_prod_sign_aux, mul_smul],
congr,
sorry, -- this needs to be an assumption
end
end reverse
end clifford_algebra
|
Formal statement is: lemma open_Collect_ex: "(\<And>i. open {x. P i x}) \<Longrightarrow> open {x. \<exists>i. P i x}" Informal statement is: If each set $\{x \mid P_i(x)\}$ is open, then so is the set $\{x \mid \exists i. P_i(x)\}$. |
library(sf)
library(RPostgreSQL)
library(data.table)
con <- dbConnect(PostgreSQL(), dbname = "retail_typology", user = "user", password = "pwd")
boundaries <- st_read("~/Dropbox/liverpool/boundaries/new_boundaries/all_boundaries_fin.gpkg", stringsAsFactors = F)
boundaries_area <- data.table(cluster_id = boundaries$id, retail_area = as.numeric(st_area(boundaries)) / 10000)
oas <- st_read("~/Dropbox/liverpool/GIS_Data/OAs_2011/oas11.shp", stringsAsFactors = F)
catchments_oa <- fread("~/Dropbox/liverpool/retail_typology/data/catchments_oa_lookup.csv", stringsAsFactors = F)
oas_area <- data.table(oa11 = oas$code, area = as.numeric(st_area(oas)) / 10000)
oas_area <- oas_area[, sum(area), by = "oa11"]
setnames(oas_area, "V1", "area")
catchments_oa[oas_area, area := i.area, on = "oa11"]
catchments_area <- catchments_oa[, sum(area), keyby = "cluster_id"]
setnames(catchments_area, "V1", "catch_area")
out <- catchments_area[boundaries_area, on = "cluster_id", nomatch = 0]
fwrite(out, "~/Dropbox/liverpool/retail_typology/analysis/indicators/size.csv")
##### 2. Morphology ####################################################################################################
# roeck_test = 1 - concave_area / circle_area
morph_ind <- dbGetQuery(con, "SELECT id cluster_id, ST_Area(ST_MinimumBoundingCircle(geom)) circle_area, ST_Perimeter(geom) locoh_perimeter FROM boundaries")
setDT(morph_ind)
morph_ind[out, retail_area := i.retail_area, on = "cluster_id"]
morph_ind <- morph_ind[!is.na(retail_area), ]
morph_ind[, circle_area := circle_area / 10^4]
morph_ind[, locoh_perimeter := locoh_perimeter / 1000]
morph_ind[, roek := 1 - retail_area / circle_area]
fwrite(morph_ind, "~/Dropbox/liverpool/retail_typology/analysis/indicators/morphology.csv")
|
State Before: K : Type u
instβΒ³ : CommRing K
instβΒ² : IsDomain K
p : β
instβΒΉ : Fact (Nat.Prime p)
instβ : CharP K p
x y : β Γ K
xβ : β z, (β(frobenius K p)^[y.fst + z]) x.snd = (β(frobenius K p)^[x.fst + z]) y.snd
z : β
H : (β(frobenius K p)^[y.fst + z]) x.snd = (β(frobenius K p)^[x.fst + z]) y.snd
β’ (β(frobenius K p)^[z]) ((β(frobenius K p)^[y.fst]) x.snd) = (β(frobenius K p)^[z]) ((β(frobenius K p)^[x.fst]) y.snd) State After: no goals Tactic: simpa only [add_comm, iterate_add] using H |
State Before: β’ Irrational Ο State After: this : Irrational (sqrt β5)
β’ Irrational Ο Tactic: have := Nat.Prime.irrational_sqrt (show Nat.Prime 5 by norm_num) State Before: this : Irrational (sqrt β5)
β’ Irrational Ο State After: thisβ : Irrational (sqrt β5)
this : Irrational (β1 + sqrt β5)
β’ Irrational Ο Tactic: have := this.rat_add 1 State Before: thisβ : Irrational (sqrt β5)
this : Irrational (β1 + sqrt β5)
β’ Irrational Ο State After: thisβΒΉ : Irrational (sqrt β5)
thisβ : Irrational (β1 + sqrt β5)
this : Irrational (β0.5 * (β1 + sqrt β5))
β’ Irrational Ο Tactic: have := this.rat_mul (show (0.5 : β) β 0 by norm_num) State Before: thisβΒΉ : Irrational (sqrt β5)
thisβ : Irrational (β1 + sqrt β5)
this : Irrational (β0.5 * (β1 + sqrt β5))
β’ Irrational Ο State After: case h.e'_1
thisβΒΉ : Irrational (sqrt β5)
thisβ : Irrational (β1 + sqrt β5)
this : Irrational (β0.5 * (β1 + sqrt β5))
β’ Ο = β0.5 * (β1 + sqrt β5) Tactic: convert this State Before: case h.e'_1
thisβΒΉ : Irrational (sqrt β5)
thisβ : Irrational (β1 + sqrt β5)
this : Irrational (β0.5 * (β1 + sqrt β5))
β’ Ο = β0.5 * (β1 + sqrt β5) State After: case h.e'_1
thisβΒΉ : Irrational (sqrt β5)
thisβ : Irrational (β1 + sqrt β5)
this : Irrational (β0.5 * (β1 + sqrt β5))
β’ Ο = 1 / 2 * (1 + sqrt 5) Tactic: norm_num State Before: case h.e'_1
thisβΒΉ : Irrational (sqrt β5)
thisβ : Irrational (β1 + sqrt β5)
this : Irrational (β0.5 * (β1 + sqrt β5))
β’ Ο = 1 / 2 * (1 + sqrt 5) State After: no goals Tactic: field_simp State Before: β’ Nat.Prime 5 State After: no goals Tactic: norm_num State Before: thisβ : Irrational (sqrt β5)
this : Irrational (β1 + sqrt β5)
β’ 0.5 β 0 State After: no goals Tactic: norm_num |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import sys
import torch
import numpy as np
from torch.utils.data import DataLoader
from torchvision.datasets import MNIST
import torchvision.transforms as transforms
parser = argparse.ArgumentParser(description='PyTorch GMVAE')
# TRAINING PARAMS
parser.add_argument('--epochs', type=int, default=1500, metavar='',
help='Amount of epochs for training (default: 100)')
parser.add_argument('--batch_size', type=int, default=100, metavar='',
help='Batch size for SGD (default: 100)')
parser.add_argument('--lrate', type=float, default=0.01, metavar="",
help="Learning rate (default: 0.01")
parser.add_argument('--use_cuda', action='store_true', dest='use_cuda',
help="Shall cuda be used (default: False)")
argv = parser.parse_args()
sys.argv = [sys.argv[0]]
from ummon import *
import ummon.utils as uu
from ummon.unsupervised import UnsupervisedTrainer
from ummon.logger import Logger
from ummon.trainingstate import Trainingstate
from gmvae import GMVAE
from gmvae import NegVariationalLowerBound
torch.manual_seed(4)
if __name__ == '__main__':
def binarize(x, double = False):
'''
Binarize Image
'''
m = torch.distributions.Uniform(0, 1)
xb = m.sample(x.size())
bin_image = (x > xb).float() * 1
if double == True:
return bin_image.double()
else:
return bin_image
# MNIST
transform = transforms.Compose([transforms.ToTensor(), binarize])
mnist_data = MNIST("/ext/data/mnist", train=True, transform=transform, target_transform=None, download=True)
mnist_data_test = MNIST("/ext/data/mnist", train=False, transform=transform, target_transform=None, download=True)
trainloader = DataLoader(mnist_data, batch_size=argv.batch_size, shuffle=True, sampler=None, batch_sampler=None, num_workers=2)
# MODEL
gmvae = GMVAE()
# INTANTIATE LOSS
criterion = NegVariationalLowerBound(gmvae, size_average=False)
# INSTANTIATE OPTIMIZER
optimizer = torch.optim.Adam(gmvae.parameters())
# LOAD TRAINING STATE
try:
ts = Trainingstate("MNIST_GMVAE.pth.tar")
except FileNotFoundError:
ts = Trainingstate()
with Logger(loglevel=10, logdir='.', log_batch_interval=20) as lg:
# EARLY STOPPING
earlystop = StepLR_earlystop(optimizer, ts, gmvae, step_size=100, nsteps=5, patience=20, logger=lg)
# CREATE A TRAINER
my_trainer = UnsupervisedTrainer(lg,
gmvae,
criterion,
optimizer,
scheduler = earlystop,
trainingstate = ts,
model_filename="MNIST_GMVAE",
use_cuda= argv.use_cuda,
after_eval_hook = criterion.compute_special_losses)
# START TRAINING
trainingsstate = my_trainer.fit(dataloader_training=trainloader,
epochs=argv.epochs,
validation_set=mnist_data_test)
# def register_nan_checks_(model):
# def check_grad(module, input, output):
# if not hasattr(module, "weight"):
# return
# if module.weight is None or module.weight.grad is None:
# return
# # if (module.weight.grad.abs() == 0).any():
# # print('Gradient in ' + type(module).__name__)
# # print(module.weight.grad)
# # print(module.extra_repr)
# #if (module.weight.grad.abs() > 1.).any():
# # print('Gradient in ' + type(module).__name__)
# # print(module.weight.grad)
# # print(module.extra_repr)
# if (module.weight.grad != module.weight.grad).any():
# print('NaN Gradients in ' + type(module).__name__)
# print(module.weight.grad)
# print(module.extra_repr)
# if module.weight.grad.abs().max() > 10000.:
# print('Exploding Gradients in ' + type(module).__name__)
# print(module.weight.grad)
# print(module.extra_repr)
# handles = []
# for module in model.modules():
# handles.append(module.register_forward_hook(check_grad))
# return handles
#
# register_nan_checks_(gmvae)
|
Today, much of our personal freedom and the power to guarantee and maintain a free society depends on cryptographic primitives (e.g., digital signatures and encryption) incorporated in the security protocols of today's Internet used for securing many daily tasks such as messaging, online banking or sending e-mails. While anticipated regulations like the upcoming EU General Data Protection Regulation (GDPR) promote the usage of cryptography to protect sensitive data, revelations about activities of governmental agencies have revealed worryingly information. Examples include subverting cryptographic software products, subverting certification authorities, backdooring cryptographic schemes, or influencing and weakening cryptographic standardization processes. Besides providing governmental institutions means to spy on citizens, such practices are highly vulnerable to also be exploited by non-governmental attackers.
Many of the public-key cryptographic schemes used to secure today's Internet were not designed with the functionality and the security requirements in mind that come along with tomorrow's envisioned use-cases on the Internet. This requires novel and typically more advanced cryptographic schemes that consider aspects that were not known or of interest in the early days of the Internet. Cryptography for a future-proof Internet needs to consider a potentially huge number of devices to which data is communicated simultaneously and shared selectively and needs to be flexible enough to work on both ends of the spectrum, i.e., resource constrained IoT devices as well as cloud-powered services. What is more, new security aspects such as readiness for a post-quantum era as well as the increasing importance of cryptographic schemes which are resilient against threats due to subversion as well as surveillance (as mentioned before) are of high relevance.
PROFET targets at designing public-key cryptography capable to secure tomorrow's Internet which will encompass paradigms such as cloud computing, the IoT and distributed ledgers as essential ingredients. We thereby want to specifically put our focus on two highly important issues for the future: (1) designing security models and cryptographic schemes that are surveillance and subversion resilient by design, e.g., provide strong notions such as forward security and post-compromise security, and (2) designing cryptographic schemes that remain secure in the presence of powerful quantum computers, i.e., schemes that provide post-quantum security. We will one the one hand work on foundational aspects, but also investigate the application of our techniques to certain problems encountered in the IoT and cloud application scenarios.
The project is led by Dr. Daniel Slamanig at the AIT Austrian Institute of Technology and the research is carried out together with the Security and Privacy group from Prof. Matteo Maffei at TU Wien.
This project receives funding from the Internet Privatstiftung Austria (IPA) under the netidee SCIENCE program under FWF project number P 31621. |
[GOAL]
Ξ± : Type u
f g : Filter Ξ±
s t : Set Ξ±
β’ f = g β β (s : Set Ξ±), s β f β s β g
[PROOFSTEP]
simp only [filter_eq_iff, ext_iff, Filter.mem_sets]
[GOAL]
Ξ± : Type u
f g : Filter Ξ±
sβ t : Set Ξ±
Ξ² : Type v
s : Ξ² β Set Ξ±
is : Set Ξ²
hf : Set.Finite is
β’ β (i : Ξ²) (_ : i β β
), s i β f β β (i : Ξ²), i β β
β s i β f
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
Ξ² : Type v
s : Ξ² β Set Ξ±
is : Set Ξ²
hf : Set.Finite is
aβ : Ξ²
sβ : Set Ξ²
xβΒΉ : Β¬aβ β sβ
xβ : Set.Finite sβ
hs : β (i : Ξ²) (_ : i β sβ), s i β f β β (i : Ξ²), i β sβ β s i β f
β’ β (i : Ξ²) (_ : i β insert aβ sβ), s i β f β β (i : Ξ²), i β insert aβ sβ β s i β f
[PROOFSTEP]
simp [hs]
[GOAL]
Ξ± : Type u
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
hfin : Set.Finite s
β’ ββ s β f β β (U : Set Ξ±), U β s β U β f
[PROOFSTEP]
rw [sInter_eq_biInter, biInter_mem hfin]
[GOAL]
Ξ± : Type u
f g : Filter Ξ±
s t : Set Ξ±
P Q : Set Ξ± β Prop
hP : Antitone P
hQ : Antitone Q
β’ ((β u, u β f β§ P u) β§ β u, u β f β§ Q u) β β u, u β f β§ P u β§ Q u
[PROOFSTEP]
constructor
[GOAL]
case mp
Ξ± : Type u
f g : Filter Ξ±
s t : Set Ξ±
P Q : Set Ξ± β Prop
hP : Antitone P
hQ : Antitone Q
β’ ((β u, u β f β§ P u) β§ β u, u β f β§ Q u) β β u, u β f β§ P u β§ Q u
[PROOFSTEP]
rintro β¨β¨u, huf, hPuβ©, v, hvf, hQvβ©
[GOAL]
case mp.intro.intro.intro.intro.intro
Ξ± : Type u
f g : Filter Ξ±
s t : Set Ξ±
P Q : Set Ξ± β Prop
hP : Antitone P
hQ : Antitone Q
u : Set Ξ±
huf : u β f
hPu : P u
v : Set Ξ±
hvf : v β f
hQv : Q v
β’ β u, u β f β§ P u β§ Q u
[PROOFSTEP]
exact β¨u β© v, inter_mem huf hvf, hP (inter_subset_left _ _) hPu, hQ (inter_subset_right _ _) hQvβ©
[GOAL]
case mpr
Ξ± : Type u
f g : Filter Ξ±
s t : Set Ξ±
P Q : Set Ξ± β Prop
hP : Antitone P
hQ : Antitone Q
β’ (β u, u β f β§ P u β§ Q u) β (β u, u β f β§ P u) β§ β u, u β f β§ Q u
[PROOFSTEP]
rintro β¨u, huf, hPu, hQuβ©
[GOAL]
case mpr.intro.intro.intro
Ξ± : Type u
f g : Filter Ξ±
s t : Set Ξ±
P Q : Set Ξ± β Prop
hP : Antitone P
hQ : Antitone Q
u : Set Ξ±
huf : u β f
hPu : P u
hQu : Q u
β’ (β u, u β f β§ P u) β§ β u, u β f β§ Q u
[PROOFSTEP]
exact β¨β¨u, huf, hPuβ©, u, huf, hQuβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Filter Ξ±)
β’ univ β {s | {t | s β t} β f}
[PROOFSTEP]
simp only [mem_setOf_eq, univ_sets, β Filter.mem_sets, setOf_true]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
β’ Β¬f β€ g β β s, s β g β§ Β¬s β f
[PROOFSTEP]
simp_rw [le_def, not_forall, exists_prop]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
β’ U β generate s β β t x, Set.Finite t β§ ββ t β U
[PROOFSTEP]
constructor
[GOAL]
case mp
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
β’ U β generate s β β t x, Set.Finite t β§ ββ t β U
[PROOFSTEP]
intro h
[GOAL]
case mpr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
β’ (β t x, Set.Finite t β§ ββ t β U) β U β generate s
[PROOFSTEP]
intro h
[GOAL]
case mp
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
h : U β generate s
β’ β t x, Set.Finite t β§ ββ t β U
[PROOFSTEP]
induction h
[GOAL]
case mp.basic
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ : Set Ξ±
aβ : sβ β s
β’ β t x, Set.Finite t β§ ββ t β sβ
case mp.univ
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
β’ β t x, Set.Finite t β§ ββ t β univ
case mp.superset
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ tβ : Set Ξ±
aβΒΉ : GenerateSets s sβ
aβ : sβ β tβ
a_ihβ : β t x, Set.Finite t β§ ββ t β sβ
β’ β t x, Set.Finite t β§ ββ t β tβ
case mp.inter
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ tβ : Set Ξ±
aβΒΉ : GenerateSets s sβ
aβ : GenerateSets s tβ
a_ihβΒΉ : β t x, Set.Finite t β§ ββ t β sβ
a_ihβ : β t x, Set.Finite t β§ ββ t β tβ
β’ β t x, Set.Finite t β§ ββ t β sβ β© tβ
[PROOFSTEP]
case basic V V_in => exact β¨{ V }, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subsetβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U V : Set Ξ±
V_in : V β s
β’ β t x, Set.Finite t β§ ββ t β V
[PROOFSTEP]
case basic V V_in => exact β¨{ V }, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subsetβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U V : Set Ξ±
V_in : V β s
β’ β t x, Set.Finite t β§ ββ t β V
[PROOFSTEP]
exact β¨{ V }, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subsetβ©
[GOAL]
case mp.univ
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
β’ β t x, Set.Finite t β§ ββ t β univ
case mp.superset
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ tβ : Set Ξ±
aβΒΉ : GenerateSets s sβ
aβ : sβ β tβ
a_ihβ : β t x, Set.Finite t β§ ββ t β sβ
β’ β t x, Set.Finite t β§ ββ t β tβ
case mp.inter
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ tβ : Set Ξ±
aβΒΉ : GenerateSets s sβ
aβ : GenerateSets s tβ
a_ihβΒΉ : β t x, Set.Finite t β§ ββ t β sβ
a_ihβ : β t x, Set.Finite t β§ ββ t β tβ
β’ β t x, Set.Finite t β§ ββ t β sβ β© tβ
[PROOFSTEP]
case univ => exact β¨β
, empty_subset _, finite_empty, subset_univ _β©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
β’ β t x, Set.Finite t β§ ββ t β univ
[PROOFSTEP]
case univ => exact β¨β
, empty_subset _, finite_empty, subset_univ _β©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
β’ β t x, Set.Finite t β§ ββ t β univ
[PROOFSTEP]
exact β¨β
, empty_subset _, finite_empty, subset_univ _β©
[GOAL]
case mp.superset
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ tβ : Set Ξ±
aβΒΉ : GenerateSets s sβ
aβ : sβ β tβ
a_ihβ : β t x, Set.Finite t β§ ββ t β sβ
β’ β t x, Set.Finite t β§ ββ t β tβ
case mp.inter
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ tβ : Set Ξ±
aβΒΉ : GenerateSets s sβ
aβ : GenerateSets s tβ
a_ihβΒΉ : β t x, Set.Finite t β§ ββ t β sβ
a_ihβ : β t x, Set.Finite t β§ ββ t β tβ
β’ β t x, Set.Finite t β§ ββ t β sβ β© tβ
[PROOFSTEP]
case superset V W _ hVW hV =>
rcases hV with β¨t, hts, ht, htVβ©
exact β¨t, hts, ht, htV.trans hVWβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U V W : Set Ξ±
aβ : GenerateSets s V
hVW : V β W
hV : β t x, Set.Finite t β§ ββ t β V
β’ β t x, Set.Finite t β§ ββ t β W
[PROOFSTEP]
case superset V W _ hVW hV =>
rcases hV with β¨t, hts, ht, htVβ©
exact β¨t, hts, ht, htV.trans hVWβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U V W : Set Ξ±
aβ : GenerateSets s V
hVW : V β W
hV : β t x, Set.Finite t β§ ββ t β V
β’ β t x, Set.Finite t β§ ββ t β W
[PROOFSTEP]
rcases hV with β¨t, hts, ht, htVβ©
[GOAL]
case intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
s : Set (Set Ξ±)
U V W : Set Ξ±
aβ : GenerateSets s V
hVW : V β W
t : Set (Set Ξ±)
hts : t β s
ht : Set.Finite t
htV : ββ t β V
β’ β t x, Set.Finite t β§ ββ t β W
[PROOFSTEP]
exact β¨t, hts, ht, htV.trans hVWβ©
[GOAL]
case mp.inter
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβΒΉ t : Set Ξ±
s : Set (Set Ξ±)
U sβ tβ : Set Ξ±
aβΒΉ : GenerateSets s sβ
aβ : GenerateSets s tβ
a_ihβΒΉ : β t x, Set.Finite t β§ ββ t β sβ
a_ihβ : β t x, Set.Finite t β§ ββ t β tβ
β’ β t x, Set.Finite t β§ ββ t β sβ β© tβ
[PROOFSTEP]
case inter V W _ _ hV hW =>
rcases hV, hW with β¨β¨t, hts, ht, htVβ©, u, hus, hu, huWβ©
exact β¨t βͺ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huWβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U V W : Set Ξ±
aβΒΉ : GenerateSets s V
aβ : GenerateSets s W
hV : β t x, Set.Finite t β§ ββ t β V
hW : β t x, Set.Finite t β§ ββ t β W
β’ β t x, Set.Finite t β§ ββ t β V β© W
[PROOFSTEP]
case inter V W _ _ hV hW =>
rcases hV, hW with β¨β¨t, hts, ht, htVβ©, u, hus, hu, huWβ©
exact β¨t βͺ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huWβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U V W : Set Ξ±
aβΒΉ : GenerateSets s V
aβ : GenerateSets s W
hV : β t x, Set.Finite t β§ ββ t β V
hW : β t x, Set.Finite t β§ ββ t β W
β’ β t x, Set.Finite t β§ ββ t β V β© W
[PROOFSTEP]
rcases hV, hW with β¨β¨t, hts, ht, htVβ©, u, hus, hu, huWβ©
[GOAL]
case intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
s : Set (Set Ξ±)
U V W : Set Ξ±
aβΒΉ : GenerateSets s V
aβ : GenerateSets s W
t : Set (Set Ξ±)
hts : t β s
ht : Set.Finite t
htV : ββ t β V
u : Set (Set Ξ±)
hus : u β s
hu : Set.Finite u
huW : ββ u β W
β’ β t x, Set.Finite t β§ ββ t β V β© W
[PROOFSTEP]
exact β¨t βͺ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huWβ©
[GOAL]
case mpr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
h : β t x, Set.Finite t β§ ββ t β U
β’ U β generate s
[PROOFSTEP]
rcases h with β¨t, hts, tfin, hβ©
[GOAL]
case mpr.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
s : Set (Set Ξ±)
U : Set Ξ±
t : Set (Set Ξ±)
hts : t β s
tfin : Set.Finite t
h : ββ t β U
β’ U β generate s
[PROOFSTEP]
exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
β’ univ = univ β© univ
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
β’ β {x y : Set Ξ±}, x β {s | β a, a β f β§ β b, b β g β§ s = a β© b} β x β y β y β {s | β a, a β f β§ β b, b β g β§ s = a β© b}
[PROOFSTEP]
rintro x y β¨a, ha, b, hb, rflβ© xy
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
y a : Set Ξ±
ha : a β f
b : Set Ξ±
hb : b β g
xy : a β© b β y
β’ y β {s | β a, a β f β§ β b, b β g β§ s = a β© b}
[PROOFSTEP]
refine' β¨a βͺ y, mem_of_superset ha (subset_union_left a y), b βͺ y, mem_of_superset hb (subset_union_left b y), _β©
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
y a : Set Ξ±
ha : a β f
b : Set Ξ±
hb : b β g
xy : a β© b β y
β’ y = (a βͺ y) β© (b βͺ y)
[PROOFSTEP]
rw [β inter_union_distrib_right, union_eq_self_of_subset_left xy]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
β’ β {x y : Set Ξ±},
x β {s | β a, a β f β§ β b, b β g β§ s = a β© b} β
y β {s | β a, a β f β§ β b, b β g β§ s = a β© b} β x β© y β {s | β a, a β f β§ β b, b β g β§ s = a β© b}
[PROOFSTEP]
rintro x y β¨a, ha, b, hb, rflβ© β¨c, hc, d, hd, rflβ©
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
a : Set Ξ±
ha : a β f
b : Set Ξ±
hb : b β g
c : Set Ξ±
hc : c β f
d : Set Ξ±
hd : d β g
β’ a β© b β© (c β© d) β {s | β a, a β f β§ β b, b β g β§ s = a β© b}
[PROOFSTEP]
refine' β¨a β© c, inter_mem ha hc, b β© d, inter_mem hb hd, _β©
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
a : Set Ξ±
ha : a β f
b : Set Ξ±
hb : b β g
c : Set Ξ±
hc : c β f
d : Set Ξ±
hd : d β g
β’ a β© b β© (c β© d) = a β© c β© (b β© d)
[PROOFSTEP]
ac_rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t s : Set Ξ±
β’ s β β€ β s = univ
[PROOFSTEP]
rw [mem_top_iff_forall, eq_univ_iff_forall]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
β’ NeBot (f β g) β NeBot f β¨ NeBot g
[PROOFSTEP]
simp only [neBot_iff, not_and_or, Ne.def, sup_eq_bot_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
β’ Β¬Disjoint f f β NeBot f
[PROOFSTEP]
rw [disjoint_self, neBot_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t x : Set Ξ±
f : ΞΉ β Filter Ξ±
β’ x β iSup f β β (i : ΞΉ), x β f i
[PROOFSTEP]
simp only [β Filter.mem_sets, iSup_sets_eq, iff_self_iff, mem_iInter]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
β’ NeBot (β¨ (i : ΞΉ), f i) β β i, NeBot (f i)
[PROOFSTEP]
simp [neBot_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
I_fin : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
hU : β (i : βI), V i β U
β’ U β β¨
(i : ΞΉ), s i
[PROOFSTEP]
haveI := I_fin.fintype
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
I_fin : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
hU : β (i : βI), V i β U
this : Fintype βI
β’ U β β¨
(i : ΞΉ), s i
[PROOFSTEP]
refine' mem_of_superset (iInter_mem.2 fun i => _) hU
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
I_fin : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
hU : β (i : βI), V i β U
this : Fintype βI
i : βI
β’ V i β β¨
(i : ΞΉ), s i
[PROOFSTEP]
exact mem_iInf_of_mem (i : ΞΉ) (hV _)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
β’ U β β¨
(i : ΞΉ), s i β β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
constructor
[GOAL]
case mp
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
β’ U β β¨
(i : ΞΉ), s i β β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
rw [iInf_eq_generate, mem_generate_iff]
[GOAL]
case mp
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
β’ (β t x, Set.Finite t β§ ββ t β U) β β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
rintro β¨t, tsub, tfin, tinterβ©
[GOAL]
case mp.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
t : Set (Set Ξ±)
tsub : t β β (i : ΞΉ), (s i).sets
tfin : Set.Finite t
tinter : ββ t β U
β’ β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with β¨I, Ifin, Ο, Οfin, Οsub, rflβ©
[GOAL]
case mp.intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : ββ β (i : β{i | i β I}), Ο i β U
β’ β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
rw [sInter_iUnion] at tinter
[GOAL]
case mp.intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
β’ β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
set V := fun i => U βͺ ββ Ο i with hV
[GOAL]
case mp.intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
β’ β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
have V_in : β i, V i β s i := by
rintro i
have : ββ Ο i β s i := by
rw [sInter_mem (Οfin _)]
apply Οsub
exact mem_of_superset this (subset_union_right _ _)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
β’ β (i : β{i | i β I}), V i β s βi
[PROOFSTEP]
rintro i
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
i : β{i | i β I}
β’ V i β s βi
[PROOFSTEP]
have : ββ Ο i β s i := by
rw [sInter_mem (Οfin _)]
apply Οsub
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
i : β{i | i β I}
β’ ββ Ο i β s βi
[PROOFSTEP]
rw [sInter_mem (Οfin _)]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
i : β{i | i β I}
β’ β (U : Set Ξ±), U β Ο i β U β s βi
[PROOFSTEP]
apply Οsub
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
i : β{i | i β I}
this : ββ Ο i β s βi
β’ V i β s βi
[PROOFSTEP]
exact mem_of_superset this (subset_union_right _ _)
[GOAL]
case mp.intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
V_in : β (i : β{i | i β I}), V i β s βi
β’ β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i
[PROOFSTEP]
refine' β¨I, Ifin, V, V_in, _β©
[GOAL]
case mp.intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
Ο : β{i | i β I} β Set (Set Ξ±)
Οfin : β (i : β{i | i β I}), Set.Finite (Ο i)
Οsub : β (i : β{i | i β I}), Ο i β (s βi).sets
tsub : β (i : β{i | i β I}), Ο i β β (i : ΞΉ), (s i).sets
tfin : Set.Finite (β (i : β{i | i β I}), Ο i)
tinter : β (i : β{i | i β I}), ββ Ο i β U
V : β{i | i β I} β Set Ξ± := fun i => U βͺ ββ Ο i
hV : V = fun i => U βͺ ββ Ο i
V_in : β (i : β{i | i β I}), V i β s βi
β’ U = β (i : βI), V i
[PROOFSTEP]
rwa [hV, β union_iInter, union_eq_self_of_subset_right]
[GOAL]
case mpr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
β’ (β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i) β U β β¨
(i : ΞΉ), s i
[PROOFSTEP]
rintro β¨I, Ifin, V, V_in, rflβ©
[GOAL]
case mpr.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
Ifin : Set.Finite I
V : βI β Set Ξ±
V_in : β (i : βI), V i β s βi
β’ β (i : βI), V i β β¨
(i : ΞΉ), s i
[PROOFSTEP]
exact mem_iInf_of_iInter Ifin V_in Subset.rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
β’ U β β¨
(i : ΞΉ), s i β
β I,
Set.Finite I β§
β V,
(β (i : ΞΉ), V i β s i) β§
(β (i : ΞΉ), Β¬i β I β V i = univ) β§ U = β (i : ΞΉ) (_ : i β I), V i β§ U = β (i : ΞΉ), V i
[PROOFSTEP]
simp only [mem_iInf, SetCoe.forall', biInter_eq_iInter]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
β’ (β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i) β
β I,
Set.Finite I β§
β V, (β (i : ΞΉ), V i β s i) β§ (β (i : ΞΉ), Β¬i β I β V i = univ) β§ U = β (x : βI), V βx β§ U = β (i : ΞΉ), V i
[PROOFSTEP]
refine' β¨_, fun β¨I, If, V, hVs, _, hVU, _β© => β¨I, If, fun i => V i, fun i => hVs i, hVUβ©β©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
U : Set Ξ±
β’ (β I, Set.Finite I β§ β V, (β (i : βI), V i β s βi) β§ U = β (i : βI), V i) β
β I,
Set.Finite I β§
β V, (β (i : ΞΉ), V i β s i) β§ (β (i : ΞΉ), Β¬i β I β V i = univ) β§ U = β (x : βI), V βx β§ U = β (i : ΞΉ), V i
[PROOFSTEP]
rintro β¨I, If, V, hV, rflβ©
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
If : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
β’ β I_1,
Set.Finite I_1 β§
β V_1,
(β (i : ΞΉ), V_1 i β s i) β§
(β (i : ΞΉ), Β¬i β I_1 β V_1 i = univ) β§
β (i : βI), V i = β (x : βI_1), V_1 βx β§ β (i : βI), V i = β (i : ΞΉ), V_1 i
[PROOFSTEP]
refine' β¨I, If, fun i => if hi : i β I then V β¨i, hiβ© else univ, fun i => _, fun i hi => _, _β©
[GOAL]
case intro.intro.intro.intro.refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
If : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
i : ΞΉ
β’ (fun i => if hi : i β I then V { val := i, property := hi } else univ) i β s i
[PROOFSTEP]
dsimp only
[GOAL]
case intro.intro.intro.intro.refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
If : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
i : ΞΉ
β’ (if hi : i β I then V { val := i, property := hi } else univ) β s i
[PROOFSTEP]
split_ifs
[GOAL]
case pos
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
If : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
i : ΞΉ
hβ : i β I
β’ V { val := i, property := hβ } β s i
case neg
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
If : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
i : ΞΉ
hβ : Β¬i β I
β’ univ β s i
[PROOFSTEP]
exacts [hV _, univ_mem]
[GOAL]
case intro.intro.intro.intro.refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
If : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
i : ΞΉ
hi : Β¬i β I
β’ (fun i => if hi : i β I then V { val := i, property := hi } else univ) i = univ
[PROOFSTEP]
exact dif_neg hi
[GOAL]
case intro.intro.intro.intro.refine'_3
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type u_2
s : ΞΉ β Filter Ξ±
I : Set ΞΉ
If : Set.Finite I
V : βI β Set Ξ±
hV : β (i : βI), V i β s βi
β’ β (i : βI), V i = β (x : βI), (fun i => if hi : i β I then V { val := i, property := hi } else univ) βx β§
β (i : βI), V i = β (i : ΞΉ), (fun i => if hi : i β I then V { val := i, property := hi } else univ) i
[PROOFSTEP]
simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta, iInter_univ, inter_univ,
eq_self_iff_true, true_and_iff]
[GOAL]
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±β
sβ t : Set Ξ±β
ΞΉ : Type u_2
instβ : Finite ΞΉ
Ξ± : Type u_3
f : ΞΉ β Filter Ξ±
s : Set Ξ±
β’ s β β¨
(i : ΞΉ), f i β β t, (β (i : ΞΉ), t i β f i) β§ s = β (i : ΞΉ), t i
[PROOFSTEP]
refine' β¨exists_iInter_of_mem_iInf, _β©
[GOAL]
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±β
sβ t : Set Ξ±β
ΞΉ : Type u_2
instβ : Finite ΞΉ
Ξ± : Type u_3
f : ΞΉ β Filter Ξ±
s : Set Ξ±
β’ (β t, (β (i : ΞΉ), t i β f i) β§ s = β (i : ΞΉ), t i) β s β β¨
(i : ΞΉ), f i
[PROOFSTEP]
rintro β¨t, ht, rflβ©
[GOAL]
case intro.intro
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±β
s tβ : Set Ξ±β
ΞΉ : Type u_2
instβ : Finite ΞΉ
Ξ± : Type u_3
f : ΞΉ β Filter Ξ±
t : ΞΉ β Set Ξ±
ht : β (i : ΞΉ), t i β f i
β’ β (i : ΞΉ), t i β β¨
(i : ΞΉ), f i
[PROOFSTEP]
exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ s t : Set Ξ±
β’ π s β€ π t β s β t
[PROOFSTEP]
simp only [le_principal_iff, iff_self_iff, mem_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ s t : Set Ξ±
β’ π s = π t β s = t
[PROOFSTEP]
simp only [le_antisymm_iff, le_principal_iff, mem_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ s t : Set Ξ±
β’ s β t β§ t β s β s β€ t β§ t β€ s
[PROOFSTEP]
rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
β’ β€ β€ π univ
[PROOFSTEP]
simp only [le_principal_iff, mem_top, eq_self_iff_true]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
S : Set (Set Ξ±)
f : Filter Ξ±
β’ f β€ generate S β f β€ β¨
(s : Set Ξ±) (_ : s β S), π s
[PROOFSTEP]
simp [le_generate_iff, le_principal_iff, subset_def]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
β’ Disjoint f g β β s, s β f β§ β t, t β g β§ Disjoint s t
[PROOFSTEP]
simp only [disjoint_iff, β empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ β
]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ gβ : Filter Ξ±
s t : Set Ξ±
f g : Filter Ξ±
β’ f β g = β₯ β β U, U β f β§ β V, V β g β§ U β© V = β
[PROOFSTEP]
simp only [β disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : ΞΉ β Filter Ξ±
hd : Pairwise (Disjoint on l)
β’ β s, (β (i : ΞΉ), s i β l i) β§ Pairwise (Disjoint on s)
[PROOFSTEP]
have : β i j, i β j β β (s : { s // s β l i }) (t : { t // t β l j }), Disjoint s.1 t.1
[GOAL]
case this
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : ΞΉ β Filter Ξ±
hd : Pairwise (Disjoint on l)
β’ β (i j : ΞΉ), i β j β β s t, Disjoint βs βt
[PROOFSTEP]
simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : ΞΉ β Filter Ξ±
hd : Pairwise (Disjoint on l)
this : β (i j : ΞΉ), i β j β β s t, Disjoint βs βt
β’ β s, (β (i : ΞΉ), s i β l i) β§ Pairwise (Disjoint on s)
[PROOFSTEP]
choose! s t hst using this
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : ΞΉ β Filter Ξ±
hd : Pairwise (Disjoint on l)
s : (i : ΞΉ) β ΞΉ β { s // s β l i }
t : ΞΉ β (j : ΞΉ) β { t // t β l j }
hst : β (i j : ΞΉ), i β j β Disjoint β(s i j) β(t i j)
β’ β s, (β (i : ΞΉ), s i β l i) β§ Pairwise (Disjoint on s)
[PROOFSTEP]
refine' β¨fun i => β j, s i j β© t j i, fun i => _, fun i j hij => _β©
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : ΞΉ β Filter Ξ±
hd : Pairwise (Disjoint on l)
s : (i : ΞΉ) β ΞΉ β { s // s β l i }
t : ΞΉ β (j : ΞΉ) β { t // t β l j }
hst : β (i j : ΞΉ), i β j β Disjoint β(s i j) β(t i j)
i : ΞΉ
β’ (fun i => β (j : ΞΉ), β(s i j) β© β(t j i)) i β l i
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : ΞΉ β Filter Ξ±
hd : Pairwise (Disjoint on l)
s : (i : ΞΉ) β ΞΉ β { s // s β l i }
t : ΞΉ β (j : ΞΉ) β { t // t β l j }
hst : β (i j : ΞΉ), i β j β Disjoint β(s i j) β(t i j)
i j : ΞΉ
hij : i β j
β’ (Disjoint on fun i => β (j : ΞΉ), β(s i j) β© β(t j i)) i j
[PROOFSTEP]
exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2,
(hst _ _ hij).mono ((iInter_subset _ j).trans (inter_subset_left _ _))
((iInter_subset _ i).trans (inter_subset_right _ _))]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
s tβ : Set Ξ±
ΞΉ : Type u_2
l : ΞΉ β Filter Ξ±
t : Set ΞΉ
hd : PairwiseDisjoint t l
ht : Set.Finite t
β’ β s, (β (i : ΞΉ), s i β l i) β§ PairwiseDisjoint t s
[PROOFSTEP]
haveI := ht.to_subtype
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
s tβ : Set Ξ±
ΞΉ : Type u_2
l : ΞΉ β Filter Ξ±
t : Set ΞΉ
hd : PairwiseDisjoint t l
ht : Set.Finite t
this : Finite βt
β’ β s, (β (i : ΞΉ), s i β l i) β§ PairwiseDisjoint t s
[PROOFSTEP]
rcases(hd.subtype _ _).exists_mem_filter_of_disjoint with β¨s, hsl, hsdβ©
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
ΞΉ : Type u_2
l : ΞΉ β Filter Ξ±
t : Set ΞΉ
hd : PairwiseDisjoint t l
ht : Set.Finite t
this : Finite βt
s : βt β Set Ξ±
hsl : β (i : βt), s i β l βi
hsd : Pairwise (Disjoint on s)
β’ β s, (β (i : ΞΉ), s i β l i) β§ PairwiseDisjoint t s
[PROOFSTEP]
lift s to (i : t) β { s // s β l i } using hsl
[GOAL]
case intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
ΞΉ : Type u_2
l : ΞΉ β Filter Ξ±
t : Set ΞΉ
hd : PairwiseDisjoint t l
ht : Set.Finite t
this : Finite βt
s : (i : βt) β { s // s β l βi }
hsd : Pairwise (Disjoint on fun i => β(s i))
β’ β s, (β (i : ΞΉ), s i β l i) β§ PairwiseDisjoint t s
[PROOFSTEP]
[email protected]_pi_extension ΞΉ (fun i => { s // s β l i }) _ _ s with β¨s, rflβ©
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ tβ : Set Ξ±
ΞΉ : Type u_2
l : ΞΉ β Filter Ξ±
t : Set ΞΉ
hd : PairwiseDisjoint t l
ht : Set.Finite t
this : Finite βt
s : (i : ΞΉ) β { s // s β l i }
hsd : Pairwise (Disjoint on fun i => β((fun i => s βi) i))
β’ β s, (β (i : ΞΉ), s i β l i) β§ PairwiseDisjoint t s
[PROOFSTEP]
exact β¨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _β©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
instβΒΉ : Subsingleton Ξ±
l : Filter Ξ±
instβ : NeBot l
β’ l = β€
[PROOFSTEP]
refine' top_unique fun s hs => _
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
instβΒΉ : Subsingleton Ξ±
l : Filter Ξ±
instβ : NeBot l
s : Set Ξ±
hs : s β l
β’ s β β€
[PROOFSTEP]
obtain rfl : s = univ
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
instβΒΉ : Subsingleton Ξ±
l : Filter Ξ±
instβ : NeBot l
s : Set Ξ±
hs : s β l
β’ s = univ
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
instβΒΉ : Subsingleton Ξ±
l : Filter Ξ±
instβ : NeBot l
hs : univ β l
β’ univ β β€
[PROOFSTEP]
exact Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
instβΒΉ : Subsingleton Ξ±
l : Filter Ξ±
instβ : NeBot l
hs : univ β l
β’ univ β β€
[PROOFSTEP]
exact univ_mem
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
instβ : Nonempty Ξ±
s : Set Ξ±
hs : s β β€
β’ Set.Nonempty s
[PROOFSTEP]
rwa [mem_top.1 hs, β nonempty_iff_univ_nonempty]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : ΞΉ β Prop
l : Filter Ξ±
h : β {s : Set Ξ±}, s β l β β i, p i β§ s β f i
β’ l = β¨
(i : ΞΉ) (_ : p i), f i
[PROOFSTEP]
rw [iInf_subtype']
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : ΞΉ β Prop
l : Filter Ξ±
h : β {s : Set Ξ±}, s β l β β i, p i β§ s β f i
β’ l = β¨
(x : { i // p i }), f βx
[PROOFSTEP]
exact eq_iInf_of_mem_iff_exists_mem <| fun {_} => by simp only [Subtype.exists, h, exists_prop]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : ΞΉ β Prop
l : Filter Ξ±
h : β {s : Set Ξ±}, s β l β β i, p i β§ s β f i
xβ : Set Ξ±
β’ xβ β l β β i, xβ β f βi
[PROOFSTEP]
simp only [Subtype.exists, h, exists_prop]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
ne : Nonempty ΞΉ
i : ΞΉ
β’ β {x y : Set Ξ±}, x β β (i : ΞΉ), (f i).sets β x β y β y β β (i : ΞΉ), (f i).sets
[PROOFSTEP]
simp only [mem_iUnion, exists_imp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
ne : Nonempty ΞΉ
i : ΞΉ
β’ β {x y : Set Ξ±} (x_1 : ΞΉ), x β (f x_1).sets β x β y β β i, y β (f i).sets
[PROOFSTEP]
exact fun i hx hxy => β¨i, mem_of_superset hx hxyβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
ne : Nonempty ΞΉ
i : ΞΉ
β’ β {x y : Set Ξ±}, x β β (i : ΞΉ), (f i).sets β y β β (i : ΞΉ), (f i).sets β x β© y β β (i : ΞΉ), (f i).sets
[PROOFSTEP]
simp only [mem_iUnion, exists_imp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
ne : Nonempty ΞΉ
i : ΞΉ
β’ β {x y : Set Ξ±} (x_1 : ΞΉ), x β (f x_1).sets β β (x_2 : ΞΉ), y β (f x_2).sets β β i, x β© y β (f i).sets
[PROOFSTEP]
intro x y a hx b hy
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
ne : Nonempty ΞΉ
i : ΞΉ
x y : Set Ξ±
a : ΞΉ
hx : x β (f a).sets
b : ΞΉ
hy : y β (f b).sets
β’ β i, x β© y β (f i).sets
[PROOFSTEP]
rcases h a b with β¨c, ha, hbβ©
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
ne : Nonempty ΞΉ
i : ΞΉ
x y : Set Ξ±
a : ΞΉ
hx : x β (f a).sets
b : ΞΉ
hy : y β (f b).sets
c : ΞΉ
ha : f a β₯ f c
hb : f b β₯ f c
β’ β i, x β© y β (f i).sets
[PROOFSTEP]
exact β¨c, inter_mem (ha hx) (hb hy)β©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
ne : Nonempty ΞΉ
i : ΞΉ
u : Filter Ξ± :=
{ sets := β (i : ΞΉ), (f i).sets, univ_sets := (_ : univ β β (i : ΞΉ), (f i).sets), sets_of_superset := ?m.89808,
inter_sets := ?m.89809 }
this : u = iInf f
β’ u.sets = β (i : ΞΉ), (f i).sets
[PROOFSTEP]
simp only
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
h : Directed (fun x x_1 => x β₯ x_1) f
instβ : Nonempty ΞΉ
s : Set Ξ±
β’ s β iInf f β β i, s β f i
[PROOFSTEP]
simp only [β Filter.mem_sets, iInf_sets_eq h, mem_iUnion]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
f : Ξ² β Filter Ξ±
s : Set Ξ²
h : DirectedOn (f β»ΒΉ'o fun x x_1 => x β₯ x_1) s
ne : Set.Nonempty s
t : Set Ξ±
β’ t β β¨
(i : Ξ²) (_ : i β s), f i β β i, i β s β§ t β f i
[PROOFSTEP]
haveI := ne.to_subtype
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
f : Ξ² β Filter Ξ±
s : Set Ξ²
h : DirectedOn (f β»ΒΉ'o fun x x_1 => x β₯ x_1) s
ne : Set.Nonempty s
t : Set Ξ±
this : Nonempty βs
β’ t β β¨
(i : Ξ²) (_ : i β s), f i β β i, i β s β§ t β f i
[PROOFSTEP]
simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
f : Ξ² β Filter Ξ±
s : Set Ξ²
h : DirectedOn (f β»ΒΉ'o fun x x_1 => x β₯ x_1) s
ne : Set.Nonempty s
t : Set Ξ±
β’ t β (β¨
(i : Ξ²) (_ : i β s), f i).sets β t β β (i : Ξ²) (_ : i β s), (f i).sets
[PROOFSTEP]
simp [mem_biInf_of_directed h ne]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type u_2
f : ΞΉ β Filter Ξ±
β’ (β¨
(i : ΞΉ), f i).sets = β (t : Finset ΞΉ), (β¨
(i : ΞΉ) (_ : i β t), f i).sets
[PROOFSTEP]
rw [iInf_eq_iInf_finset, iInf_sets_eq]
[GOAL]
case h
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type u_2
f : ΞΉ β Filter Ξ±
β’ Directed (fun x x_1 => x β₯ x_1) fun t => β¨
(i : ΞΉ) (_ : i β t), f i
[PROOFSTEP]
exact directed_of_sup fun _ _ => biInf_mono
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
β’ (β¨
(i : ΞΉ), f i).sets = β (t : Finset (PLift ΞΉ)), (β¨
(i : PLift ΞΉ) (_ : i β t), f i.down).sets
[PROOFSTEP]
rw [β iInf_sets_eq_finite, β Equiv.plift.surjective.iInf_comp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
β’ (β¨
(x : PLift ΞΉ), f (βEquiv.plift x)).sets = (β¨
(i : PLift ΞΉ), f i.down).sets
[PROOFSTEP]
rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
fβ fβ : Filter (Filter Ξ±)
x : Set Ξ±
β’ x β join fβ β join fβ β x β join (fβ β fβ)
[PROOFSTEP]
simp only [mem_sup, mem_join]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Sort w
f : ΞΉ β Filter (Filter Ξ±)
x : Set Ξ±
β’ x β β¨ (x : ΞΉ), join (f x) β x β join (β¨ (x : ΞΉ), f x)
[PROOFSTEP]
simp only [mem_iSup, mem_join]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
β’ β (x y z : Filter Ξ±), (x β y) β (x β z) β€ x β y β z
[PROOFSTEP]
intro x y z s
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
x y z : Filter Ξ±
s : Set Ξ±
β’ s β x β y β z β s β (x β y) β (x β z)
[PROOFSTEP]
simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
x y z : Filter Ξ±
s : Set Ξ±
β’ s β x β
β (x_1 : Set Ξ±),
x_1 β y β β (x_2 : Set Ξ±), x_2 β z β s = x_1 β© x_2 β β tβ, tβ β x β§ tβ β y β§ β tβ, tβ β x β§ tβ β z β§ s = tβ β© tβ
[PROOFSTEP]
rintro hs tβ htβ tβ htβ rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
s t : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
x y z : Filter Ξ±
tβ : Set Ξ±
htβ : tβ β y
tβ : Set Ξ±
htβ : tβ β z
hs : tβ β© tβ β x
β’ β tβ_1, tβ_1 β x β§ tβ_1 β y β§ β tβ_1, tβ_1 β x β§ tβ_1 β z β§ tβ β© tβ = tβ_1 β© tβ_1
[PROOFSTEP]
exact
β¨tβ, x.sets_of_superset hs (inter_subset_left tβ tβ), htβ, tβ, x.sets_of_superset hs (inter_subset_right tβ tβ), htβ,
rflβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
hβ : t β (sInf s).sets
β’ t β β¨
(b : Filter Ξ±) (_ : b β s), f β b
[PROOFSTEP]
rw [iInf_subtype']
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
hβ : t β (sInf s).sets
β’ t β β¨
(x : { b // b β s }), f β βx
[PROOFSTEP]
rw [sInf_eq_iInf', iInf_sets_eq_finite, mem_iUnion] at hβ
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
hβ : β i, t β (β¨
(i_1 : βs) (_ : i_1 β i), βi_1).sets
β’ t β β¨
(x : { b // b β s }), f β βx
[PROOFSTEP]
obtain β¨u, huβ© := hβ
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
u : Finset βs
hu : t β (β¨
(i : βs) (_ : i β u), βi).sets
β’ t β β¨
(x : { b // b β s }), f β βx
[PROOFSTEP]
rw [β Finset.inf_eq_iInf] at hu
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
u : Finset βs
hu : t β (Finset.inf u fun i => βi).sets
β’ t β β¨
(x : { b // b β s }), f β βx
[PROOFSTEP]
suffices β¨
i : s, f β βi β€ f β u.inf fun i => βi from this β¨hβ, huβ©
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
u : Finset βs
hu : t β (Finset.inf u fun i => βi).sets
β’ β¨
(i : βs), f β βi β€ f β Finset.inf u fun i => βi
[PROOFSTEP]
refine' Finset.induction_on u (le_sup_of_le_right le_top) _
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
u : Finset βs
hu : t β (Finset.inf u fun i => βi).sets
β’ β β¦a : βsβ¦ {s_1 : Finset βs},
Β¬a β s_1 β
(β¨
(i : βs), f β βi β€ f β Finset.inf s_1 fun i => βi) β
β¨
(i : βs), f β βi β€ f β Finset.inf (insert a s_1) fun i => βi
[PROOFSTEP]
rintro β¨iβ© u _ ih
[GOAL]
case intro.mk
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
uβ : Finset βs
hu : t β (Finset.inf uβ fun i => βi).sets
i : Filter Ξ±
propertyβ : i β s
u : Finset βs
aβ : Β¬{ val := i, property := propertyβ } β u
ih : β¨
(i : βs), f β βi β€ f β Finset.inf u fun i => βi
β’ β¨
(i : βs), f β βi β€ f β Finset.inf (insert { val := i, property := propertyβ } u) fun i => βi
[PROOFSTEP]
rw [Finset.inf_insert, sup_inf_left]
[GOAL]
case intro.mk
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
srcβ : CompleteLattice (Filter Ξ±) := instCompleteLatticeFilter
f : Filter Ξ±
s : Set (Filter Ξ±)
t : Set Ξ±
xβ : t β f β sInf s
hβ : t β f.sets
uβ : Finset βs
hu : t β (Finset.inf uβ fun i => βi).sets
i : Filter Ξ±
propertyβ : i β s
u : Finset βs
aβ : Β¬{ val := i, property := propertyβ } β u
ih : β¨
(i : βs), f β βi β€ f β Finset.inf u fun i => βi
β’ β¨
(i : βs), f β βi β€ (f β β{ val := i, property := propertyβ }) β (f β Finset.inf u fun i => βi)
[PROOFSTEP]
exact le_inf (iInf_le _ _) ih
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
t : Set Ξ²
β’ t β β¨
(a : Ξ±) (_ : a β s), f a β β p, (β (a : Ξ±), a β s β p a β f a) β§ t = β (a : Ξ±) (_ : a β s), p a
[PROOFSTEP]
simp only [β Finset.set_biInter_coe, biInter_eq_iInter, iInf_subtype']
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
t : Set Ξ²
β’ t β β¨
(x : { i // i β s }), f βx β β p, (β (a : Ξ±), a β s β p a β f a) β§ t = β (x : ββs), p βx
[PROOFSTEP]
refine' β¨fun h => _, _β©
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
t : Set Ξ²
h : t β β¨
(x : { i // i β s }), f βx
β’ β p, (β (a : Ξ±), a β s β p a β f a) β§ t = β (x : ββs), p βx
[PROOFSTEP]
rcases(mem_iInf_of_finite _).1 h with β¨p, hp, rflβ©
[GOAL]
case refine'_1.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
p : { i // i β s } β Set Ξ²
hp : β (i : { i // i β s }), p i β f βi
h : β (i : { i // i β s }), p i β β¨
(x : { i // i β s }), f βx
β’ β p_1, (β (a : Ξ±), a β s β p_1 a β f a) β§ β (i : { i // i β s }), p i = β (x : ββs), p_1 βx
[PROOFSTEP]
refine' β¨fun a => if h : a β s then p β¨a, hβ© else univ, fun a ha => by simpa [ha] using hp β¨a, haβ©, _β©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
p : { i // i β s } β Set Ξ²
hp : β (i : { i // i β s }), p i β f βi
h : β (i : { i // i β s }), p i β β¨
(x : { i // i β s }), f βx
a : Ξ±
ha : a β s
β’ (fun a => if h : a β s then p { val := a, property := h } else univ) a β f a
[PROOFSTEP]
simpa [ha] using hp β¨a, haβ©
[GOAL]
case refine'_1.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
p : { i // i β s } β Set Ξ²
hp : β (i : { i // i β s }), p i β f βi
h : β (i : { i // i β s }), p i β β¨
(x : { i // i β s }), f βx
β’ β (i : { i // i β s }), p i = β (x : ββs), (fun a => if h : a β s then p { val := a, property := h } else univ) βx
[PROOFSTEP]
refine' iInter_congr_of_surjective id surjective_id _
[GOAL]
case refine'_1.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
p : { i // i β s } β Set Ξ²
hp : β (i : { i // i β s }), p i β f βi
h : β (i : { i // i β s }), p i β β¨
(x : { i // i β s }), f βx
β’ β (x : { i // i β s }), (fun a => if h : a β s then p { val := a, property := h } else univ) β(id x) = p x
[PROOFSTEP]
rintro β¨a, haβ©
[GOAL]
case refine'_1.intro.intro.mk
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
p : { i // i β s } β Set Ξ²
hp : β (i : { i // i β s }), p i β f βi
h : β (i : { i // i β s }), p i β β¨
(x : { i // i β s }), f βx
a : Ξ±
ha : a β s
β’ (fun a => if h : a β s then p { val := a, property := h } else univ) β(id { val := a, property := ha }) =
p { val := a, property := ha }
[PROOFSTEP]
simp [ha]
[GOAL]
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
t : Set Ξ²
β’ (β p, (β (a : Ξ±), a β s β p a β f a) β§ t = β (x : ββs), p βx) β t β β¨
(x : { i // i β s }), f βx
[PROOFSTEP]
rintro β¨p, hpf, rflβ©
[GOAL]
case refine'_2.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
s : Finset Ξ±
f : Ξ± β Filter Ξ²
p : Ξ± β Set Ξ²
hpf : β (a : Ξ±), a β s β p a β f a
β’ β (x : ββs), p βx β β¨
(x : { i // i β s }), f βx
[PROOFSTEP]
exact iInter_mem.2 fun a => mem_iInf_of_mem a (hpf a a.2)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
instβ : Nonempty ΞΉ
hd : Directed (fun x x_1 => x β₯ x_1) f
β’ Β¬NeBot (iInf f) β Β¬β (i : ΞΉ), NeBot (f i)
[PROOFSTEP]
simpa only [not_forall, not_neBot, β empty_mem_iff_bot, mem_iInf_of_directed hd] using id
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
hn : Nonempty Ξ±
hd : Directed (fun x x_1 => x β₯ x_1) f
hb : β (i : ΞΉ), NeBot (f i)
β’ NeBot (iInf f)
[PROOFSTEP]
cases isEmpty_or_nonempty ΞΉ
[GOAL]
case inl
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
hn : Nonempty Ξ±
hd : Directed (fun x x_1 => x β₯ x_1) f
hb : β (i : ΞΉ), NeBot (f i)
hβ : IsEmpty ΞΉ
β’ NeBot (iInf f)
[PROOFSTEP]
constructor
[GOAL]
case inl.ne'
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
hn : Nonempty Ξ±
hd : Directed (fun x x_1 => x β₯ x_1) f
hb : β (i : ΞΉ), NeBot (f i)
hβ : IsEmpty ΞΉ
β’ iInf f β β₯
[PROOFSTEP]
simp [iInf_of_empty f, top_ne_bot]
[GOAL]
case inr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
hn : Nonempty Ξ±
hd : Directed (fun x x_1 => x β₯ x_1) f
hb : β (i : ΞΉ), NeBot (f i)
hβ : Nonempty ΞΉ
β’ NeBot (iInf f)
[PROOFSTEP]
exact iInf_neBot_of_directed' hd hb
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
s : Set Ξ±
hs : s β iInf f
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
β’ p s
[PROOFSTEP]
rw [mem_iInf_finite'] at hs
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
s : Set Ξ±
hs : β t, s β β¨
(i : PLift ΞΉ) (_ : i β t), f i.down
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
β’ p s
[PROOFSTEP]
simp only [β Finset.inf_eq_iInf] at hs
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
s : Set Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
hs : β t, s β Finset.inf t fun a => f a.down
β’ p s
[PROOFSTEP]
rcases hs with β¨is, hisβ©
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
s : Set Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
is : Finset (PLift ΞΉ)
his : s β Finset.inf is fun a => f a.down
β’ p s
[PROOFSTEP]
induction is using Finset.induction_on generalizing s
[GOAL]
case intro.empty
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
s : Set Ξ±
his : s β Finset.inf β
fun a => f a.down
β’ p s
case intro.insert
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβΒΉ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
aβΒ² : PLift ΞΉ
sβ : Finset (PLift ΞΉ)
aβΒΉ : Β¬aβΒ² β sβ
aβ : β {s : Set Ξ±}, (s β Finset.inf sβ fun a => f a.down) β p s
s : Set Ξ±
his : s β Finset.inf (insert aβΒ² sβ) fun a => f a.down
β’ p s
[PROOFSTEP]
case empty => rwa [mem_top.1 his]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
s : Set Ξ±
his : s β Finset.inf β
fun a => f a.down
β’ p s
[PROOFSTEP]
case empty => rwa [mem_top.1 his]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
s : Set Ξ±
his : s β Finset.inf β
fun a => f a.down
β’ p s
[PROOFSTEP]
rwa [mem_top.1 his]
[GOAL]
case intro.insert
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβΒΉ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
aβΒ² : PLift ΞΉ
sβ : Finset (PLift ΞΉ)
aβΒΉ : Β¬aβΒ² β sβ
aβ : β {s : Set Ξ±}, (s β Finset.inf sβ fun a => f a.down) β p s
s : Set Ξ±
his : s β Finset.inf (insert aβΒ² sβ) fun a => f a.down
β’ p s
[PROOFSTEP]
case insert ih =>
rw [Finset.inf_insert, mem_inf_iff] at his
rcases his with β¨sβ, hsβ, sβ, hsβ, rflβ©
exact ins hsβ (ih hsβ)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβΒΉ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
aβΒΉ : PLift ΞΉ
sβ : Finset (PLift ΞΉ)
aβ : Β¬aβΒΉ β sβ
ih : β {s : Set Ξ±}, (s β Finset.inf sβ fun a => f a.down) β p s
s : Set Ξ±
his : s β Finset.inf (insert aβΒΉ sβ) fun a => f a.down
β’ p s
[PROOFSTEP]
case insert ih =>
rw [Finset.inf_insert, mem_inf_iff] at his
rcases his with β¨sβ, hsβ, sβ, hsβ, rflβ©
exact ins hsβ (ih hsβ)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβΒΉ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
aβΒΉ : PLift ΞΉ
sβ : Finset (PLift ΞΉ)
aβ : Β¬aβΒΉ β sβ
ih : β {s : Set Ξ±}, (s β Finset.inf sβ fun a => f a.down) β p s
s : Set Ξ±
his : s β Finset.inf (insert aβΒΉ sβ) fun a => f a.down
β’ p s
[PROOFSTEP]
rw [Finset.inf_insert, mem_inf_iff] at his
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβΒΉ t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
aβΒΉ : PLift ΞΉ
sβ : Finset (PLift ΞΉ)
aβ : Β¬aβΒΉ β sβ
ih : β {s : Set Ξ±}, (s β Finset.inf sβ fun a => f a.down) β p s
s : Set Ξ±
his : β tβ, tβ β f aβΒΉ.down β§ β tβ, (tβ β Finset.inf sβ fun a => f a.down) β§ s = tβ β© tβ
β’ p s
[PROOFSTEP]
rcases his with β¨sβ, hsβ, sβ, hsβ, rflβ©
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
f : ΞΉ β Filter Ξ±
p : Set Ξ± β Prop
uni : p univ
ins : β {i : ΞΉ} {sβ sβ : Set Ξ±}, sβ β f i β p sβ β p (sβ β© sβ)
aβΒΉ : PLift ΞΉ
sβ : Finset (PLift ΞΉ)
aβ : Β¬aβΒΉ β sβ
ih : β {s : Set Ξ±}, (s β Finset.inf sβ fun a => f a.down) β p s
sβ : Set Ξ±
hsβ : sβ β f aβΒΉ.down
sβ : Set Ξ±
hsβ : sβ β Finset.inf sβ fun a => f a.down
β’ p (sβ β© sβ)
[PROOFSTEP]
exact ins hsβ (ih hsβ)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ s t : Set Ξ±
β’ π s β π t β€ π (s β© t)
[PROOFSTEP]
simp only [le_principal_iff, mem_inf_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ s t : Set Ξ±
β’ β tβ, tβ β π s β§ β tβ, tβ β π t β§ s β© t = tβ β© tβ
[PROOFSTEP]
exact β¨s, Subset.rfl, t, Subset.rfl, rflβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ s t : Set Ξ±
β’ π (s β© t) β€ π s β π t
[PROOFSTEP]
simp [le_inf_iff, inter_subset_left, inter_subset_right]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ tβ s t u : Set Ξ±
β’ u β π s β π t β u β π (s βͺ t)
[PROOFSTEP]
simp only [union_subset_iff, mem_sup, mem_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
f g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Sort w
s : ΞΉ β Set Ξ±
x : Set Ξ±
β’ x β β¨ (x : ΞΉ), π (s x) β x β π (β (i : ΞΉ), s i)
[PROOFSTEP]
simp only [mem_iSup, mem_principal, iUnion_subset_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t s : Set Ξ±
β’ π s β π sαΆ = β₯
[PROOFSTEP]
rw [inf_principal, inter_compl_self, principal_empty]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
sβ t s : Set Ξ±
β’ π s β π sαΆ = β€
[PROOFSTEP]
rw [sup_principal, union_compl_self, principal_univ]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
f : Filter Ξ±
s t : Set Ξ±
β’ s β f β π t β tαΆ βͺ s β f
[PROOFSTEP]
simp only [β le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, β
(isCompl_principal (t β© sαΆ)).le_right_iff, compl_inter, compl_compl]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
f : Filter Ξ±
s t : Set Ξ±
β’ s β f β π t β {x | x β t β x β s} β f
[PROOFSTEP]
simp only [mem_inf_principal', imp_iff_not_or]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ tβ : Set Ξ±
f : Filter Ξ±
s t : Set Ξ±
β’ tαΆ βͺ s β f β {x | Β¬x β t β¨ x β s} β f
[PROOFSTEP]
rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : ΞΉ β Filter Ξ±
s : Set Ξ±
β’ β¨ (i : ΞΉ), f i β π s = (β¨ (i : ΞΉ), f i) β π s
[PROOFSTEP]
ext
[GOAL]
case a
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβΒΉ t : Set Ξ±
f : ΞΉ β Filter Ξ±
s sβ : Set Ξ±
β’ sβ β β¨ (i : ΞΉ), f i β π s β sβ β (β¨ (i : ΞΉ), f i) β π s
[PROOFSTEP]
simp only [mem_iSup, mem_inf_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : Filter Ξ±
s : Set Ξ±
β’ f β π s = β₯ β sαΆ β f
[PROOFSTEP]
rw [β empty_mem_iff_bot, mem_inf_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : Filter Ξ±
s : Set Ξ±
β’ {x | x β s β x β β
} β f β sαΆ β f
[PROOFSTEP]
rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
f : Filter Ξ±
s : Set Ξ±
h : f β π sαΆ = β₯
β’ s β f
[PROOFSTEP]
rwa [inf_principal_eq_bot, compl_compl] at h
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t s : Set Ξ±
f : Filter Ξ±
β’ π s β€ f β β (V : Set Ξ±), V β f β s β V
[PROOFSTEP]
change (β V, V β f β V β _) β _
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ g : Filter Ξ±
sβ t s : Set Ξ±
f : Filter Ξ±
β’ (β (V : Set Ξ±), V β f β V β π s) β β (V : Set Ξ±), V β f β s β V
[PROOFSTEP]
simp_rw [mem_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type w
s : Finset ΞΉ
f : ΞΉ β Set Ξ±
β’ β¨
(i : ΞΉ) (_ : i β s), π (f i) = π (β (i : ΞΉ) (_ : i β s), f i)
[PROOFSTEP]
induction' s using Finset.induction_on with i s _ hs
[GOAL]
case empty
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type w
f : ΞΉ β Set Ξ±
β’ β¨
(i : ΞΉ) (_ : i β β
), π (f i) = π (β (i : ΞΉ) (_ : i β β
), f i)
[PROOFSTEP]
simp
[GOAL]
case insert
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type w
f : ΞΉ β Set Ξ±
i : ΞΉ
s : Finset ΞΉ
aβ : Β¬i β s
hs : β¨
(i : ΞΉ) (_ : i β s), π (f i) = π (β (i : ΞΉ) (_ : i β s), f i)
β’ β¨
(i_1 : ΞΉ) (_ : i_1 β insert i s), π (f i_1) = π (β (i_1 : ΞΉ) (_ : i_1 β insert i s), f i_1)
[PROOFSTEP]
rw [Finset.iInf_insert, Finset.set_biInter_insert, hs, inf_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type w
instβ : Finite ΞΉ
f : ΞΉ β Set Ξ±
β’ β¨
(i : ΞΉ), π (f i) = π (β (i : ΞΉ), f i)
[PROOFSTEP]
cases nonempty_fintype ΞΉ
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
s t : Set Ξ±
ΞΉ : Type w
instβ : Finite ΞΉ
f : ΞΉ β Set Ξ±
valβ : Fintype ΞΉ
β’ β¨
(i : ΞΉ), π (f i) = π (β (i : ΞΉ), f i)
[PROOFSTEP]
simpa using iInf_principal_finset Finset.univ f
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type w
s : Set ΞΉ
hs : Set.Finite s
f : ΞΉ β Set Ξ±
β’ β¨
(i : ΞΉ) (_ : i β s), π (f i) = π (β (i : ΞΉ) (_ : i β s), f i)
[PROOFSTEP]
lift s to Finset ΞΉ using hs
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ g : Filter Ξ±
sβ t : Set Ξ±
ΞΉ : Type w
f : ΞΉ β Set Ξ±
s : Finset ΞΉ
β’ β¨
(i : ΞΉ) (_ : i β βs), π (f i) = π (β (i : ΞΉ) (_ : i β βs), f i)
[PROOFSTEP]
exact_mod_cast iInf_principal_finset s f
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
t : NeBot f
p : Prop
h : p
β’ (βαΆ (x : Ξ±) in f, p) β p
[PROOFSTEP]
simp [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
t : NeBot f
p : Prop
h : Β¬p
β’ (βαΆ (x : Ξ±) in f, p) β p
[PROOFSTEP]
simpa [h] using t.ne
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p q : Ξ± β Prop
h : βαΆ (x : Ξ±) in f, p x β q x
hq : βαΆ (x : Ξ±) in f, q x
β’ βαΆ (x : Ξ±) in f, q x β p x
[PROOFSTEP]
simpa only [Iff.comm] using h
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : Filter Ξ±
p : ΞΉ β Ξ± β Prop
β’ (βαΆ (x : Ξ±) in l, β (i : ΞΉ), p i x) β β (i : ΞΉ), βαΆ (x : Ξ±) in l, p i x
[PROOFSTEP]
cases nonempty_fintype ΞΉ
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
ΞΉ : Type u_2
instβ : Finite ΞΉ
l : Filter Ξ±
p : ΞΉ β Ξ± β Prop
valβ : Fintype ΞΉ
β’ (βαΆ (x : Ξ±) in l, β (i : ΞΉ), p i x) β β (i : ΞΉ), βαΆ (x : Ξ±) in l, p i x
[PROOFSTEP]
simpa only [Filter.Eventually, setOf_forall] using iInter_mem
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
ΞΉ : Type u_2
I : Set ΞΉ
hI : Set.Finite I
l : Filter Ξ±
p : ΞΉ β Ξ± β Prop
β’ (βαΆ (x : Ξ±) in l, β (i : ΞΉ), i β I β p i x) β β (i : ΞΉ), i β I β βαΆ (x : Ξ±) in l, p i x
[PROOFSTEP]
simpa only [Filter.Eventually, setOf_forall] using biInter_mem hI
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p : Prop
q : Ξ± β Prop
h : p
β’ (βαΆ (x : Ξ±) in f, p β¨ q x) β p β¨ βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p : Prop
q : Ξ± β Prop
h : Β¬p
β’ (βαΆ (x : Ξ±) in f, p β¨ q x) β p β¨ βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p : Ξ± β Prop
q : Prop
β’ (βαΆ (x : Ξ±) in f, p x β¨ q) β (βαΆ (x : Ξ±) in f, p x) β¨ q
[PROOFSTEP]
simp only [@or_comm _ q, eventually_or_distrib_left]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p : Prop
q : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in f, p β q x) β p β βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp only [imp_iff_not_or, eventually_or_distrib_left]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p q : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
hq : βαΆ (x : Ξ±) in f, q x
β’ βαΆ (x : Ξ±) in f, p x β§ q x
[PROOFSTEP]
refine' mt (fun h => hq.mp <| h.mono _) hp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p q : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
hq : βαΆ (x : Ξ±) in f, q x
h : βαΆ (x : Ξ±) in f, Β¬(fun x => p x β§ q x) x
β’ β (x : Ξ±), Β¬(fun x => p x β§ q x) x β q x β Β¬(fun x => p x) x
[PROOFSTEP]
exact fun x hpq hq hp => hpq β¨hp, hqβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p q : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
hq : βαΆ (x : Ξ±) in f, q x
β’ βαΆ (x : Ξ±) in f, p x β§ q x
[PROOFSTEP]
simpa only [and_comm] using hq.and_eventually hp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
β’ β x, p x
[PROOFSTEP]
by_contra H
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
H : Β¬β x, p x
β’ False
[PROOFSTEP]
replace H : βαΆ x in f, Β¬p x
[GOAL]
case H
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
H : Β¬β x, p x
β’ βαΆ (x : Ξ±) in f, Β¬p x
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
H : βαΆ (x : Ξ±) in f, Β¬p x
β’ False
[PROOFSTEP]
exact eventually_of_forall (not_exists.1 H)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
hp : βαΆ (x : Ξ±) in f, p x
H : βαΆ (x : Ξ±) in f, Β¬p x
β’ False
[PROOFSTEP]
exact hp H
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
H : β {q : Ξ± β Prop}, (βαΆ (x : Ξ±) in f, q x) β β x, p x β§ q x
hp : βαΆ (x : Ξ±) in f, Β¬(fun x => p x) x
β’ False
[PROOFSTEP]
simpa only [and_not_self_iff, exists_false] using H hp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
P : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in f, P x) β β {U : Set Ξ±}, U β f β β x, x β U β§ P x
[PROOFSTEP]
simp only [frequently_iff_forall_eventually_exists_and, exists_prop, @and_comm (P _)]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
P : Ξ± β Prop
β’ (β {q : Ξ± β Prop}, (βαΆ (x : Ξ±) in f, q x) β β x, q x β§ P x) β β {U : Set Ξ±}, U β f β β x, x β U β§ P x
[PROOFSTEP]
rfl
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
β’ (Β¬βαΆ (x : Ξ±) in f, p x) β βαΆ (x : Ξ±) in f, Β¬p x
[PROOFSTEP]
simp [Filter.Frequently]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f : Filter Ξ±
β’ (Β¬βαΆ (x : Ξ±) in f, p x) β βαΆ (x : Ξ±) in f, Β¬p x
[PROOFSTEP]
simp only [Filter.Frequently, not_not]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
β’ (βαΆ (x : Ξ±) in f, True) β NeBot f
[PROOFSTEP]
simp [Filter.Frequently, -not_eventually, eventually_false_iff_eq_bot, neBot_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
β’ Β¬βαΆ (x : Ξ±) in f, False
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
instβ : NeBot f
p : Prop
h : p
β’ (βαΆ (x : Ξ±) in f, p) β p
[PROOFSTEP]
simpa [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
instβ : NeBot f
p : Prop
h : Β¬p
β’ (βαΆ (x : Ξ±) in f, p) β p
[PROOFSTEP]
simp [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p q : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in f, p x β¨ q x) β (βαΆ (x : Ξ±) in f, p x) β¨ βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp only [Filter.Frequently, β not_and_or, not_or, eventually_and]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
instβ : NeBot f
p : Prop
q : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in f, p β¨ q x) β p β¨ βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
instβ : NeBot f
p : Ξ± β Prop
q : Prop
β’ (βαΆ (x : Ξ±) in f, p x β¨ q) β (βαΆ (x : Ξ±) in f, p x) β¨ q
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p q : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in f, p x β q x) β (βαΆ (x : Ξ±) in f, p x) β βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp [imp_iff_not_or, not_eventually, frequently_or_distrib]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
instβ : NeBot f
p : Prop
q : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in f, p β q x) β p β βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
instβ : NeBot f
p : Ξ± β Prop
q : Prop
β’ (βαΆ (x : Ξ±) in f, p x β q) β (βαΆ (x : Ξ±) in f, p x) β q
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p : Ξ± β Prop
q : Prop
β’ (βαΆ (x : Ξ±) in f, p x β q) β (βαΆ (x : Ξ±) in f, p x) β q
[PROOFSTEP]
simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p : Prop
q : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in f, p β§ q x) β p β§ βαΆ (x : Ξ±) in f, q x
[PROOFSTEP]
simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, not_imp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
p : Ξ± β Prop
q : Prop
β’ (βαΆ (x : Ξ±) in f, p x β§ q) β (βαΆ (x : Ξ±) in f, p x) β§ q
[PROOFSTEP]
simp only [@and_comm _ q, frequently_and_distrib_left]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
β’ Β¬βαΆ (x : Ξ±) in β₯, p x
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in β€, p x) β β x, p x
[PROOFSTEP]
simp [Filter.Frequently]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
a : Set Ξ±
p : Ξ± β Prop
β’ (βαΆ (x : Ξ±) in π a, p x) β β x, x β a β§ p x
[PROOFSTEP]
simp [Filter.Frequently, not_forall]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
f g : Filter Ξ±
β’ (βαΆ (x : Ξ±) in f β g, p x) β (βαΆ (x : Ξ±) in f, p x) β¨ βαΆ (x : Ξ±) in g, p x
[PROOFSTEP]
simp only [Filter.Frequently, eventually_sup, not_and_or]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
fs : Set (Filter Ξ±)
β’ (βαΆ (x : Ξ±) in sSup fs, p x) β β f, f β fs β§ βαΆ (x : Ξ±) in f, p x
[PROOFSTEP]
simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
p : Ξ± β Prop
fs : Ξ² β Filter Ξ±
β’ (βαΆ (x : Ξ±) in β¨ (b : Ξ²), fs b, p x) β β b, βαΆ (x : Ξ±) in fs b, p x
[PROOFSTEP]
simp only [Filter.Frequently, eventually_iSup, not_forall]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
r : Ξ± β Ξ² β Prop
l : Filter Ξ±
instβ : NeBot l
h : βαΆ (x : Ξ±) in l, β y, r x y
β’ β f, βαΆ (x : Ξ±) in l, r x (f x)
[PROOFSTEP]
haveI : Nonempty Ξ² :=
let β¨_, hxβ© := h.exists;
hx.nonempty
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
r : Ξ± β Ξ² β Prop
l : Filter Ξ±
instβ : NeBot l
h : βαΆ (x : Ξ±) in l, β y, r x y
this : Nonempty Ξ²
β’ β f, βαΆ (x : Ξ±) in l, r x (f x)
[PROOFSTEP]
choose! f hf using fun x (hx : β y, r x y) => hx
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
r : Ξ± β Ξ² β Prop
l : Filter Ξ±
instβ : NeBot l
h : βαΆ (x : Ξ±) in l, β y, r x y
this : Nonempty Ξ²
f : Ξ± β Ξ²
hf : β (x : Ξ±), (β y, r x y) β r x (f x)
β’ β f, βαΆ (x : Ξ±) in l, r x (f x)
[PROOFSTEP]
exact β¨f, h.mono hfβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s : Set Ξ±
l : Filter Ξ±
β’ s =αΆ [l] univ β s β l
[PROOFSTEP]
simp [eventuallyEq_set]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
l : Filter Ξ±
f f' : Ξ± β Ξ²
hf : f =αΆ [l] f'
g g' : Ξ± β Ξ³
hg : g =αΆ [l] g'
β’ β (x : Ξ±), g x = g' x β f x = f' x β (fun x => (f x, g x)) x = (fun x => (f' x, g' x)) x
[PROOFSTEP]
intros
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
l : Filter Ξ±
f f' : Ξ± β Ξ²
hf : f =αΆ [l] f'
g g' : Ξ± β Ξ³
hg : g =αΆ [l] g'
xβ : Ξ±
aβΒΉ : g xβ = g' xβ
aβ : f xβ = f' xβ
β’ (fun x => (f x, g x)) xβ = (fun x => (f' x, g' x)) xβ
[PROOFSTEP]
simp only [*]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s : Set Ξ±
l : Filter Ξ±
β’ (βαΆ (x : Ξ±) in l, x β s β x β β
) β βαΆ (x : Ξ±) in l, Β¬x β s
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s t : Set Ξ±
l : Filter Ξ±
β’ s β© t =αΆ [l] s β βαΆ (x : Ξ±) in l, x β s β x β t
[PROOFSTEP]
simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s t : Set Ξ±
l : Filter Ξ±
β’ s β© t =αΆ [l] t β βαΆ (x : Ξ±) in l, x β t β x β s
[PROOFSTEP]
rw [inter_comm, inter_eventuallyEq_left]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : AddGroup Ξ²
f g : Ξ± β Ξ²
l : Filter Ξ±
h : f =αΆ [l] g
β’ f - g =αΆ [l] 0
[PROOFSTEP]
simpa using ((EventuallyEq.refl l f).sub h).symm
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : AddGroup Ξ²
f g : Ξ± β Ξ²
l : Filter Ξ±
h : f - g =αΆ [l] 0
β’ f =αΆ [l] g
[PROOFSTEP]
simpa using h.add (EventuallyEq.refl l g)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : LE Ξ²
l : Filter Ξ±
f f' g g' : Ξ± β Ξ²
Hβ : f β€αΆ [l] g
hfβ : f =αΆ [l] f'
hgβ : g =αΆ [l] g'
x : Ξ±
hf : f x = f' x
hg : g x = g' x
H : f x β€ g x
β’ f' x β€ g' x
[PROOFSTEP]
rwa [hf, hg] at H
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : PartialOrder Ξ²
l : Filter Ξ±
f g : Ξ± β Ξ²
β’ f =αΆ [l] g β f β€αΆ [l] g β§ g β€αΆ [l] f
[PROOFSTEP]
simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s t : Set Ξ±
l : Filter Ξ±
β’ t β l β π s β l β π s β€ l β π t
[PROOFSTEP]
simp only [le_inf_iff, inf_le_left, true_and_iff, le_principal_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s t : Set Ξ±
l : Filter Ξ±
β’ s =αΆ [l] t β l β π s = l β π t
[PROOFSTEP]
simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβΒ³ : MulZeroClass Ξ²
instβΒ² : PartialOrder Ξ²
instβΒΉ : PosMulMono Ξ²
instβ : MulPosMono Ξ²
l : Filter Ξ±
fβ fβ gβ gβ : Ξ± β Ξ²
hf : fβ β€αΆ [l] fβ
hg : gβ β€αΆ [l] gβ
hgβ : 0 β€αΆ [l] gβ
hfβ : 0 β€αΆ [l] fβ
β’ fβ * gβ β€αΆ [l] fβ * gβ
[PROOFSTEP]
filter_upwards [hf, hg, hgβ, hfβ] with x using _root_.mul_le_mul
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβΒ³ : Mul Ξ²
instβΒ² : Preorder Ξ²
instβΒΉ : CovariantClass Ξ² Ξ² (fun x x_1 => x * x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass Ξ² Ξ² (swap fun x x_1 => x * x_1) fun x x_1 => x β€ x_1
l : Filter Ξ±
fβ fβ gβ gβ : Ξ± β Ξ²
hf : fβ β€αΆ [l] fβ
hg : gβ β€αΆ [l] gβ
β’ fβ * gβ β€αΆ [l] fβ * gβ
[PROOFSTEP]
filter_upwards [hf, hg] with x hfx hgx using _root_.mul_le_mul' hfx hgx
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : OrderedSemiring Ξ²
l : Filter Ξ±
f g : Ξ± β Ξ²
hf : 0 β€αΆ [l] f
hg : 0 β€αΆ [l] g
β’ 0 β€αΆ [l] f * g
[PROOFSTEP]
filter_upwards [hf, hg] with x using _root_.mul_nonneg
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : SemilatticeSup Ξ²
l : Filter Ξ±
fβ fβ gβ gβ : Ξ± β Ξ²
hf : fβ β€αΆ [l] fβ
hg : gβ β€αΆ [l] gβ
β’ fβ β gβ β€αΆ [l] fβ β gβ
[PROOFSTEP]
filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : SemilatticeSup Ξ²
l : Filter Ξ±
f g h : Ξ± β Ξ²
hf : f β€αΆ [l] h
hg : g β€αΆ [l] h
β’ f β g β€αΆ [l] h
[PROOFSTEP]
filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
hf : Injective m
h : m '' s β map m f
β’ s β f
[PROOFSTEP]
rwa [β preimage_image_eq s hf]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
β’ range m β map m f
[PROOFSTEP]
rw [β image_univ]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
β’ m '' univ β map m f
[PROOFSTEP]
exact image_mem_map univ_mem
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ²
β’ m β»ΒΉ' univ β univ
[PROOFSTEP]
simp only [subset_univ, preimage_univ]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
l : Filter Ξ²
p : Ξ± β Prop
s : Set Ξ±
xβ : s β comap f l
t : Set Ξ²
ht : t β l
hts : f β»ΒΉ' t β s
y : Ξ²
hy : y β t
x : Ξ±
hx : f x = y
β’ f x β t
[PROOFSTEP]
rwa [hx]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
l : Filter Ξ²
p : Ξ± β Prop
sβ : Set Ξ±
x : Ξ±
s : Set Ξ²
F : Filter (Ξ± Γ Ξ²)
β’ s β comap (Prod.mk x) F β {p | p.fst = x β p.snd β s} β F
[PROOFSTEP]
simp_rw [mem_comap', Prod.ext_iff, and_imp, @forall_swap Ξ² (_ = _), forall_eq, eq_comm]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
l : Filter Ξ²
p : Ξ± β Prop
s : Set Ξ±
β’ (βαΆ (a : Ξ±) in comap f l, p a) β βαΆ (b : Ξ²) in l, β a, f a = b β§ p a
[PROOFSTEP]
simp only [Filter.Frequently, eventually_comap, not_exists, not_and]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
l : Filter Ξ²
p : Ξ± β Prop
s : Set Ξ±
β’ s β comap f l β (f '' sαΆ)αΆ β l
[PROOFSTEP]
simp only [mem_comap'', kernImage_eq_compl]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
l : Filter Ξ²
p : Ξ± β Prop
s : Set Ξ±
β’ sαΆ β comap f l β (f '' s)αΆ β l
[PROOFSTEP]
rw [mem_comap_iff_compl, compl_compl]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
β’ kernImage m univ = univ
[PROOFSTEP]
simp [kernImage_eq_compl]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
β’ β {x y : Set Ξ²}, x β kernImage m '' f.sets β x β y β y β kernImage m '' f.sets
[PROOFSTEP]
rintro _ t β¨s, hs, rflβ© hst
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
t : Set Ξ²
s : Set Ξ±
hs : s β f.sets
hst : kernImage m s β t
β’ t β kernImage m '' f.sets
[PROOFSTEP]
refine β¨s βͺ m β»ΒΉ' t, mem_of_superset hs (subset_union_left s _), ?_β©
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
t : Set Ξ²
s : Set Ξ±
hs : s β f.sets
hst : kernImage m s β t
β’ kernImage m (s βͺ m β»ΒΉ' t) = t
[PROOFSTEP]
rw [kernImage_union_preimage, union_eq_right_iff_subset.mpr hst]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
β’ β {x y : Set Ξ²}, x β kernImage m '' f.sets β y β kernImage m '' f.sets β x β© y β kernImage m '' f.sets
[PROOFSTEP]
rintro _ _ β¨sβ, hβ, rflβ© β¨sβ, hβ, rflβ©
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
sβ : Set Ξ±
hβ : sβ β f.sets
sβ : Set Ξ±
hβ : sβ β f.sets
β’ kernImage m sβ β© kernImage m sβ β kernImage m '' f.sets
[PROOFSTEP]
exact β¨sβ β© sβ, f.inter_sets hβ hβ, Set.preimage_kernImage.u_infβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
s : Set Ξ²
β’ s β kernMap m f β β t, tαΆ β f β§ m '' t = sαΆ
[PROOFSTEP]
rw [mem_kernMap, compl_surjective.exists]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
s : Set Ξ²
β’ (β x, xαΆ β f β§ kernImage m xαΆ = s) β β t, tαΆ β f β§ m '' t = sαΆ
[PROOFSTEP]
refine exists_congr (fun x β¦ and_congr_right fun _ β¦ ?_)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
s : Set Ξ²
x : Set Ξ±
xβ : xαΆ β f
β’ kernImage m xαΆ = s β m '' x = sαΆ
[PROOFSTEP]
rw [kernImage_compl, compl_eq_comm, eq_comm]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
s : Set Ξ²
β’ sαΆ β kernMap m f β β t, tαΆ β f β§ m '' t = s
[PROOFSTEP]
simp_rw [mem_kernMap_iff_compl, compl_compl]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
a : Ξ±
s : Set Ξ±
β’ s β π {a} β s β pure a
[PROOFSTEP]
simp only [mem_pure, mem_principal, singleton_subset_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
a : Ξ±
m : Ξ± β Filter Ξ²
β’ bind (pure a) m = m a
[PROOFSTEP]
simp only [Bind.bind, bind, map_pure, join_pure]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
instβ : NeBot f
c : Ξ²
β’ map (fun x => c) f = pure c
[PROOFSTEP]
ext s
[GOAL]
case a
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
instβ : NeBot f
c : Ξ²
s : Set Ξ²
β’ s β map (fun x => c) f β s β pure c
[PROOFSTEP]
by_cases h : c β s
[GOAL]
case pos
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
instβ : NeBot f
c : Ξ²
s : Set Ξ²
h : c β s
β’ s β map (fun x => c) f β s β pure c
[PROOFSTEP]
simp [h]
[GOAL]
case neg
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
instβ : NeBot f
c : Ξ²
s : Set Ξ²
h : Β¬c β s
β’ s β map (fun x => c) f β s β pure c
[PROOFSTEP]
simp [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
m : Ξ³ β Ξ²
n : Ξ² β Ξ±
s : Set Ξ³
β’ sαΆ β comap m (comap n f) β sαΆ β comap (n β m) f
[PROOFSTEP]
simp only [compl_mem_comap, image_image, (Β· β Β·)]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
Ο : Ξ± β Ξ²
ΞΈ : Ξ± β Ξ³
Ο : Ξ² β Ξ΄
Ο : Ξ³ β Ξ΄
H : Ο β Ο = Ο β ΞΈ
F : Filter Ξ±
β’ map Ο (map Ο F) = map Ο (map ΞΈ F)
[PROOFSTEP]
rw [Filter.map_map, H, β Filter.map_map]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
Ο : Ξ± β Ξ²
ΞΈ : Ξ± β Ξ³
Ο : Ξ² β Ξ΄
Ο : Ξ³ β Ξ΄
H : Ο β Ο = Ο β ΞΈ
G : Filter Ξ΄
β’ comap Ο (comap Ο G) = comap ΞΈ (comap Ο G)
[PROOFSTEP]
rw [Filter.comap_comap, H, β Filter.comap_comap]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
b : Ξ²
β’ comap m (pure b) = π (m β»ΒΉ' {b})
[PROOFSTEP]
rw [β principal_singleton, comap_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
β’ comap m g β€ f β g β€ kernMap m f
[PROOFSTEP]
simp [Filter.le_def, mem_comap'', mem_kernMap, -mem_comap]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
s : Set Ξ±
β’ kernMap m (π s) = π (kernImage m s)
[PROOFSTEP]
refine eq_of_forall_le_iff (fun g β¦ ?_)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
gβ gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
s : Set Ξ±
g : Filter Ξ²
β’ g β€ kernMap m (π s) β g β€ π (kernImage m s)
[PROOFSTEP]
rw [β comap_le_iff_le_kernMap, le_principal_iff, le_principal_iff, mem_comap'']
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
β’ map f β€ = π (range f)
[PROOFSTEP]
rw [β principal_univ, map_principal, image_univ]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
l : Filter Ξ±
β’ l β€ comap f β€
[PROOFSTEP]
rw [comap_top]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
l : Filter Ξ±
β’ l β€ β€
[PROOFSTEP]
exact le_top
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
s : Set Ξ±
xβ : s β β₯
β’ m β»ΒΉ' β
β s
[PROOFSTEP]
simp only [empty_subset, preimage_empty]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
h : NeBot (comap m g)
β’ NeBot g
[PROOFSTEP]
rw [neBot_iff] at *
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
h : comap m g β β₯
β’ g β β₯
[PROOFSTEP]
contrapose! h
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
h : g = β₯
β’ comap m g = β₯
[PROOFSTEP]
rw [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
h : g = β₯
β’ comap m β₯ = β₯
[PROOFSTEP]
exact comap_bot
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
β’ comap m (g β π (range m)) = comap m g
[PROOFSTEP]
simpa only [le_principal_iff, comap_inf, comap_principal, preimage_range, principal_univ, inf_eq_left] using le_top
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
h : Disjoint gβ gβ
β’ Disjoint (comap m gβ) (comap m gβ)
[PROOFSTEP]
simp only [disjoint_iff, β comap_inf, h.eq_bot, comap_bot]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
s : Set (Filter Ξ²)
m : Ξ± β Ξ²
β’ comap m (sSup s) = β¨ (f : Filter Ξ²) (_ : f β s), comap m f
[PROOFSTEP]
simp only [sSup_eq_iSup, comap_iSup, eq_self_iff_true]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
β’ comap m (gβ β gβ) = comap m gβ β comap m gβ
[PROOFSTEP]
rw [sup_eq_iSup, comap_iSup, iSup_bool_eq, Bool.cond_true, Bool.cond_false]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
β’ map m (comap m f) = f β π (range m)
[PROOFSTEP]
refine' le_antisymm (le_inf map_comap_le <| le_principal_iff.2 range_mem_map) _
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
β’ f β π (range m) β€ map m (comap m f)
[PROOFSTEP]
rintro t' β¨t, ht, subβ©
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
tβ : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
t' t : Set Ξ²
ht : t β f
sub : m β»ΒΉ' t β m β»ΒΉ' t'
β’ t' β f β π (range m)
[PROOFSTEP]
refine' mem_inf_principal.2 (mem_of_superset ht _)
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
tβ : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
t' t : Set Ξ²
ht : t β f
sub : m β»ΒΉ' t β m β»ΒΉ' t'
β’ t β {x | x β range m β x β t'}
[PROOFSTEP]
rintro _ hxt β¨x, rflβ©
[GOAL]
case intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
tβ : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
t' t : Set Ξ²
ht : t β f
sub : m β»ΒΉ' t β m β»ΒΉ' t'
x : Ξ±
hxt : m x β t
β’ m x β t'
[PROOFSTEP]
exact sub hxt
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
s : Set Ξ²
β’ map Subtype.val (comap Subtype.val f) = f β π s
[PROOFSTEP]
rw [map_comap, Subtype.range_val]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
hf : range m β f
β’ map m (comap m f) = f
[PROOFSTEP]
rw [map_comap, inf_eq_left.2 (le_principal_iff.2 hf)]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
hf : Surjective f
l : Filter Ξ²
β’ range f β l
[PROOFSTEP]
simp only [hf.range_eq, univ_mem]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
s : Set Ξ±
f : Filter Ξ±
β’ map Subtype.val (comap Subtype.val f) = f β π s
[PROOFSTEP]
rw [map_comap, Subtype.range_coe]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
c : Ξ² β Ξ±
h : range c β f
W : Set Ξ²
W_in : W β comap c f
β’ c '' W β f
[PROOFSTEP]
rw [β map_comap_of_mem h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
c : Ξ² β Ξ±
h : range c β f
W : Set Ξ²
W_in : W β comap c f
β’ c '' W β map c (comap c f)
[PROOFSTEP]
exact image_mem_map W_in
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
U : Set Ξ±
h : U β f
W : Set βU
W_in : W β comap Subtype.val f
β’ range Subtype.val β f
[PROOFSTEP]
simp [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
m : Ξ± β Ξ²
h : Injective m
s : Set Ξ±
hs : s β f
β’ m β»ΒΉ' (m '' s) β s
[PROOFSTEP]
simp only [preimage_image_eq s h, Subset.rfl]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
inj : Injective m
large : range m β f
S : Set Ξ±
β’ S β comap m f β m '' S β f
[PROOFSTEP]
rw [β image_mem_map_iff inj, map_comap_of_mem large]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
gβ gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f g : Filter Ξ±
m : Ξ± β Ξ²
hm : Injective m
β’ map m f β€ map m g β f β€ g
[PROOFSTEP]
rw [map_le_iff_le_comap, comap_map hm]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
gβ gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
f g : Filter Ξ±
m : Ξ± β Ξ²
s : Set Ξ±
hsf : s β f
hsg : s β g
hm : InjOn m s
β’ map m f = map m g β f = g
[PROOFSTEP]
simp only [le_antisymm_iff, map_le_map_iff_of_injOn hsf hsg hm, map_le_map_iff_of_injOn hsg hsf hm]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
β’ NeBot (comap m f) β β (t : Set Ξ²), t β f β β a, m a β t
[PROOFSTEP]
simp only [β forall_mem_nonempty_iff_neBot, mem_comap, forall_exists_index, and_imp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
β’ (β (s : Set Ξ±) (x : Set Ξ²), x β f β m β»ΒΉ' x β s β Set.Nonempty s) β β (t : Set Ξ²), t β f β β a, m a β t
[PROOFSTEP]
exact β¨fun h t t_in => h (m β»ΒΉ' t) t t_in Subset.rfl, fun h s t ht hst => (h t ht).imp hstβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
β’ NeBot (comap m f) β βαΆ (y : Ξ²) in f, y β range m
[PROOFSTEP]
simp only [comap_neBot_iff, frequently_iff, mem_range, @and_comm (_ β _), exists_exists_eq_and]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
hm : Surjective m
β’ comap m f = β₯ β f = β₯
[PROOFSTEP]
rw [comap_eq_bot_iff_compl_range, hm.range_eq, compl_univ, empty_mem_iff_bot]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
h : Surjective m
β’ Disjoint (comap m gβ) (comap m gβ) β Disjoint gβ gβ
[PROOFSTEP]
rw [disjoint_iff, disjoint_iff, β comap_inf, comap_surjective_eq_bot h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
β’ NeBot (comap Prod.fst f) β NeBot f β§ Nonempty Ξ²
[PROOFSTEP]
cases isEmpty_or_nonempty Ξ²
[GOAL]
case inl
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
hβ : IsEmpty Ξ²
β’ NeBot (comap Prod.fst f) β NeBot f β§ Nonempty Ξ²
[PROOFSTEP]
rw [filter_eq_bot_of_isEmpty (f.comap _), β not_iff_not]
[GOAL]
case inl
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
hβ : IsEmpty Ξ²
β’ Β¬NeBot β₯ β Β¬(NeBot f β§ Nonempty Ξ²)
[PROOFSTEP]
simp [*]
[GOAL]
case inr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ±
hβ : Nonempty Ξ²
β’ NeBot (comap Prod.fst f) β NeBot f β§ Nonempty Ξ²
[PROOFSTEP]
simp [comap_neBot_iff_frequently, *]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
β’ NeBot (comap Prod.snd f) β Nonempty Ξ± β§ NeBot f
[PROOFSTEP]
cases' isEmpty_or_nonempty Ξ± with hΞ± hΞ±
[GOAL]
case inl
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
hΞ± : IsEmpty Ξ±
β’ NeBot (comap Prod.snd f) β Nonempty Ξ± β§ NeBot f
[PROOFSTEP]
rw [filter_eq_bot_of_isEmpty (f.comap _), β not_iff_not]
[GOAL]
case inl
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
hΞ± : IsEmpty Ξ±
β’ Β¬NeBot β₯ β Β¬(Nonempty Ξ± β§ NeBot f)
[PROOFSTEP]
simp
[GOAL]
case inr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
hΞ± : Nonempty Ξ±
β’ NeBot (comap Prod.snd f) β Nonempty Ξ± β§ NeBot f
[PROOFSTEP]
simp [comap_neBot_iff_frequently, hΞ±]
[GOAL]
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ fβ fβ : Filter Ξ±β
g gβ gβ : Filter Ξ²
m : Ξ±β β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±β
t : Set Ξ²
ΞΉ : Type u_2
Ξ± : ΞΉ β Type u_3
i : ΞΉ
f : Filter (Ξ± i)
β’ NeBot (comap (eval i) f) β (β (j : ΞΉ), Nonempty (Ξ± j)) β§ NeBot f
[PROOFSTEP]
cases' isEmpty_or_nonempty (β j, Ξ± j) with H H
[GOAL]
case inl
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ fβ fβ : Filter Ξ±β
g gβ gβ : Filter Ξ²
m : Ξ±β β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±β
t : Set Ξ²
ΞΉ : Type u_2
Ξ± : ΞΉ β Type u_3
i : ΞΉ
f : Filter (Ξ± i)
H : IsEmpty ((j : ΞΉ) β Ξ± j)
β’ NeBot (comap (eval i) f) β (β (j : ΞΉ), Nonempty (Ξ± j)) β§ NeBot f
[PROOFSTEP]
rw [filter_eq_bot_of_isEmpty (f.comap _), β not_iff_not]
[GOAL]
case inl
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ fβ fβ : Filter Ξ±β
g gβ gβ : Filter Ξ²
m : Ξ±β β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±β
t : Set Ξ²
ΞΉ : Type u_2
Ξ± : ΞΉ β Type u_3
i : ΞΉ
f : Filter (Ξ± i)
H : IsEmpty ((j : ΞΉ) β Ξ± j)
β’ Β¬NeBot β₯ β Β¬((β (j : ΞΉ), Nonempty (Ξ± j)) β§ NeBot f)
[PROOFSTEP]
simp [β Classical.nonempty_pi]
[GOAL]
case inr
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ fβ fβ : Filter Ξ±β
g gβ gβ : Filter Ξ²
m : Ξ±β β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±β
t : Set Ξ²
ΞΉ : Type u_2
Ξ± : ΞΉ β Type u_3
i : ΞΉ
f : Filter (Ξ± i)
H : Nonempty ((j : ΞΉ) β Ξ± j)
β’ NeBot (comap (eval i) f) β (β (j : ΞΉ), Nonempty (Ξ± j)) β§ NeBot f
[PROOFSTEP]
have : β j, Nonempty (Ξ± j) := Classical.nonempty_pi.1 H
[GOAL]
case inr
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ fβ fβ : Filter Ξ±β
g gβ gβ : Filter Ξ²
m : Ξ±β β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±β
t : Set Ξ²
ΞΉ : Type u_2
Ξ± : ΞΉ β Type u_3
i : ΞΉ
f : Filter (Ξ± i)
H : Nonempty ((j : ΞΉ) β Ξ± j)
this : β (j : ΞΉ), Nonempty (Ξ± j)
β’ NeBot (comap (eval i) f) β (β (j : ΞΉ), Nonempty (Ξ± j)) β§ NeBot f
[PROOFSTEP]
simp [comap_neBot_iff_frequently, *]
[GOAL]
Ξ±β : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
fβ fβ fβ : Filter Ξ±β
g gβ gβ : Filter Ξ²
m : Ξ±β β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±β
t : Set Ξ²
ΞΉ : Type u_2
Ξ± : ΞΉ β Type u_3
instβ : β (j : ΞΉ), Nonempty (Ξ± j)
i : ΞΉ
f : Filter (Ξ± i)
β’ NeBot (comap (eval i) f) β NeBot f
[PROOFSTEP]
simp [comap_eval_neBot_iff', *]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
hf : NeBot f
s : Set Ξ±
hs : m '' s β f
β’ NeBot (comap m f β π s)
[PROOFSTEP]
refine' β¨compl_compl s βΈ mt mem_of_eq_bot _β©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
t : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
hf : NeBot f
s : Set Ξ±
hs : m '' s β f
β’ Β¬sαΆ β comap m f
[PROOFSTEP]
rintro β¨t, ht, htsβ©
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
tβ : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
hf : NeBot f
s : Set Ξ±
hs : m '' s β f
t : Set Ξ²
ht : t β f
hts : m β»ΒΉ' t β sαΆ
β’ False
[PROOFSTEP]
rcases hf.nonempty_of_mem (inter_mem hs ht) with β¨_, β¨x, hxs, rflβ©, hxtβ©
[GOAL]
case intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
mβ : Ξ± β Ξ²
m' : Ξ² β Ξ³
sβ : Set Ξ±
tβ : Set Ξ²
f : Filter Ξ²
m : Ξ± β Ξ²
hf : NeBot f
s : Set Ξ±
hs : m '' s β f
t : Set Ξ²
ht : t β f
hts : m β»ΒΉ' t β sαΆ
x : Ξ±
hxs : x β s
hxt : m x β t
β’ False
[PROOFSTEP]
exact absurd hxs (hts hxt)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
β’ map m f = β₯ β f = β₯
[PROOFSTEP]
rw [β empty_mem_iff_bot, β empty_mem_iff_bot]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
β’ β
β map m f β β
β f
[PROOFSTEP]
exact id
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
h : f = β₯
β’ map m f = β₯
[PROOFSTEP]
simp only [h, map_bot]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ±
β’ NeBot (map f F) β NeBot F
[PROOFSTEP]
simp only [neBot_iff, Ne, map_eq_bot_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
β’ ββ (comap f F).sets = β (U : Set Ξ²) (_ : U β F), f β»ΒΉ' U
[PROOFSTEP]
ext x
[GOAL]
case h
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
x : Ξ±
β’ x β ββ (comap f F).sets β x β β (U : Set Ξ²) (_ : U β F), f β»ΒΉ' U
[PROOFSTEP]
suffices (β (A : Set Ξ±) (B : Set Ξ²), B β F β f β»ΒΉ' B β A β x β A) β β B : Set Ξ², B β F β f x β B by
simp only [mem_sInter, mem_iInter, Filter.mem_sets, mem_comap, this, and_imp, exists_prop, mem_preimage, exists_imp]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
x : Ξ±
this : (β (A : Set Ξ±) (B : Set Ξ²), B β F β f β»ΒΉ' B β A β x β A) β β (B : Set Ξ²), B β F β f x β B
β’ x β ββ (comap f F).sets β x β β (U : Set Ξ²) (_ : U β F), f β»ΒΉ' U
[PROOFSTEP]
simp only [mem_sInter, mem_iInter, Filter.mem_sets, mem_comap, this, and_imp, exists_prop, mem_preimage, exists_imp]
[GOAL]
case h
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
x : Ξ±
β’ (β (A : Set Ξ±) (B : Set Ξ²), B β F β f β»ΒΉ' B β A β x β A) β β (B : Set Ξ²), B β F β f x β B
[PROOFSTEP]
constructor
[GOAL]
case h.mp
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
x : Ξ±
β’ (β (A : Set Ξ±) (B : Set Ξ²), B β F β f β»ΒΉ' B β A β x β A) β β (B : Set Ξ²), B β F β f x β B
[PROOFSTEP]
intro h U U_in
[GOAL]
case h.mp
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
x : Ξ±
h : β (A : Set Ξ±) (B : Set Ξ²), B β F β f β»ΒΉ' B β A β x β A
U : Set Ξ²
U_in : U β F
β’ f x β U
[PROOFSTEP]
simpa only [Subset.rfl, forall_prop_of_true, mem_preimage] using h (f β»ΒΉ' U) U U_in
[GOAL]
case h.mpr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
x : Ξ±
β’ (β (B : Set Ξ²), B β F β f x β B) β β (A : Set Ξ±) (B : Set Ξ²), B β F β f β»ΒΉ' B β A β x β A
[PROOFSTEP]
intro h V U U_in f_U_V
[GOAL]
case h.mpr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ fβ : Filter Ξ±
g gβ gβ : Filter Ξ²
m : Ξ± β Ξ²
m' : Ξ² β Ξ³
s : Set Ξ±
t : Set Ξ²
f : Ξ± β Ξ²
F : Filter Ξ²
x : Ξ±
h : β (B : Set Ξ²), B β F β f x β B
V : Set Ξ±
U : Set Ξ²
U_in : U β F
f_U_V : f β»ΒΉ' U β V
β’ x β V
[PROOFSTEP]
exact f_U_V (h U U_in)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : ΞΉ β Filter Ξ±
m : Ξ± β Ξ²
hf : Directed (fun x x_1 => x β₯ x_1) f
instβ : Nonempty ΞΉ
s : Set Ξ²
hs : m β»ΒΉ' s β iInf f
i : ΞΉ
hi : m β»ΒΉ' s β f i
β’ map m (f i) β€ π s
[PROOFSTEP]
simp only [le_principal_iff, mem_map]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : ΞΉ β Filter Ξ±
m : Ξ± β Ξ²
hf : Directed (fun x x_1 => x β₯ x_1) f
instβ : Nonempty ΞΉ
s : Set Ξ²
hs : m β»ΒΉ' s β iInf f
i : ΞΉ
hi : m β»ΒΉ' s β f i
β’ m β»ΒΉ' s β f i
[PROOFSTEP]
assumption
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
ΞΉ : Type w
f : ΞΉ β Filter Ξ±
m : Ξ± β Ξ²
p : ΞΉ β Prop
h : DirectedOn (f β»ΒΉ'o fun x x_1 => x β₯ x_1) {x | p x}
ne : β i, p i
β’ map m (β¨
(i : ΞΉ) (_ : p i), f i) = β¨
(i : ΞΉ) (_ : p i), map m (f i)
[PROOFSTEP]
haveI := nonempty_subtype.2 ne
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
ΞΉ : Type w
f : ΞΉ β Filter Ξ±
m : Ξ± β Ξ²
p : ΞΉ β Prop
h : DirectedOn (f β»ΒΉ'o fun x x_1 => x β₯ x_1) {x | p x}
ne : β i, p i
this : Nonempty { a // p a }
β’ map m (β¨
(i : ΞΉ) (_ : p i), f i) = β¨
(i : ΞΉ) (_ : p i), map m (f i)
[PROOFSTEP]
simp only [iInf_subtype']
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉβ : Sort x
ΞΉ : Type w
f : ΞΉ β Filter Ξ±
m : Ξ± β Ξ²
p : ΞΉ β Prop
h : DirectedOn (f β»ΒΉ'o fun x x_1 => x β₯ x_1) {x | p x}
ne : β i, p i
this : Nonempty { a // p a }
β’ map m (β¨
(x : { i // p i }), f βx) = β¨
(x : { i // p i }), map m (f βx)
[PROOFSTEP]
exact map_iInf_eq h.directed_val
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
m : Ξ± β Ξ²
h : Injective m
β’ map m (f β g) = map m f β map m g
[PROOFSTEP]
refine' map_inf_le.antisymm _
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
m : Ξ± β Ξ²
h : Injective m
β’ map m f β map m g β€ map m (f β g)
[PROOFSTEP]
rintro t β¨sβ, hsβ, sβ, hsβ, ht : m β»ΒΉ' t = sβ β© sββ©
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
m : Ξ± β Ξ²
h : Injective m
t : Set Ξ²
sβ : Set Ξ±
hsβ : sβ β f
sβ : Set Ξ±
hsβ : sβ β g
ht : m β»ΒΉ' t = sβ β© sβ
β’ t β map m f β map m g
[PROOFSTEP]
refine' mem_inf_of_inter (image_mem_map hsβ) (image_mem_map hsβ) _
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
m : Ξ± β Ξ²
h : Injective m
t : Set Ξ²
sβ : Set Ξ±
hsβ : sβ β f
sβ : Set Ξ±
hsβ : sβ β g
ht : m β»ΒΉ' t = sβ β© sβ
β’ m '' sβ β© m '' sβ β t
[PROOFSTEP]
rw [β image_inter h, image_subset_iff, ht]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f g : Filter Ξ±
m : Ξ± β Ξ²
t : Set Ξ±
htf : t β f
htg : t β g
h : InjOn m t
β’ map m (f β g) = map m f β map m g
[PROOFSTEP]
lift f to Filter t using htf
[GOAL]
case intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Filter Ξ±
m : Ξ± β Ξ²
t : Set Ξ±
htg : t β g
h : InjOn m t
f : Filter βt
β’ map m (map Subtype.val f β g) = map m (map Subtype.val f) β map m g
[PROOFSTEP]
lift g to Filter t using htg
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
t : Set Ξ±
h : InjOn m t
f g : Filter βt
β’ map m (map Subtype.val f β map Subtype.val g) = map m (map Subtype.val f) β map m (map Subtype.val g)
[PROOFSTEP]
replace h : Injective (m β ((β) : t β Ξ±)) := h.injective
[GOAL]
case intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
t : Set Ξ±
f g : Filter βt
h : Injective (m β Subtype.val)
β’ map m (map Subtype.val f β map Subtype.val g) = map m (map Subtype.val f) β map m (map Subtype.val g)
[PROOFSTEP]
simp only [map_map, β map_inf Subtype.coe_injective, map_inf h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
hm : Injective m
fβ fβ : Filter Ξ±
β’ Disjoint (map m fβ) (map m fβ) β Disjoint fβ fβ
[PROOFSTEP]
simp only [disjoint_iff, β map_inf hm, map_eq_bot_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
e : Ξ± β Ξ²
f : Filter Ξ²
β’ map (βe) (map (βe.symm) f) = map (βe) (comap (βe) f)
[PROOFSTEP]
rw [map_map, e.self_comp_symm, map_id, map_comap_of_surjective e.surjective]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
β’ map f (F β comap f G) = map f F β G
[PROOFSTEP]
apply le_antisymm
[GOAL]
case a
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
β’ map f (F β comap f G) β€ map f F β G
[PROOFSTEP]
calc
map f (F β comap f G) β€ map f F β (map f <| comap f G) := map_inf_le
_ β€ map f F β G := inf_le_inf_left (map f F) map_comap_le
[GOAL]
case a
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
β’ map f F β G β€ map f (F β comap f G)
[PROOFSTEP]
rintro U β¨V, V_in, W, β¨Z, Z_in, hZβ©, hβ©
[GOAL]
case a.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
U : Set Ξ²
V : Set Ξ±
V_in : V β F
W : Set Ξ±
h : f β»ΒΉ' U = V β© W
Z : Set Ξ²
Z_in : Z β G
hZ : f β»ΒΉ' Z β W
β’ U β map f F β G
[PROOFSTEP]
apply mem_inf_of_inter (image_mem_map V_in) Z_in
[GOAL]
case a.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
U : Set Ξ²
V : Set Ξ±
V_in : V β F
W : Set Ξ±
h : f β»ΒΉ' U = V β© W
Z : Set Ξ²
Z_in : Z β G
hZ : f β»ΒΉ' Z β W
β’ f '' V β© Z β U
[PROOFSTEP]
calc
f '' V β© Z = f '' (V β© f β»ΒΉ' Z) := by rw [image_inter_preimage]
_ β f '' (V β© W) := (image_subset _ (inter_subset_inter_right _ βΉ_βΊ))
_ = f '' (f β»ΒΉ' U) := by rw [h]
_ β U := image_preimage_subset f U
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
U : Set Ξ²
V : Set Ξ±
V_in : V β F
W : Set Ξ±
h : f β»ΒΉ' U = V β© W
Z : Set Ξ²
Z_in : Z β G
hZ : f β»ΒΉ' Z β W
β’ f '' V β© Z = f '' (V β© f β»ΒΉ' Z)
[PROOFSTEP]
rw [image_inter_preimage]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
U : Set Ξ²
V : Set Ξ±
V_in : V β F
W : Set Ξ±
h : f β»ΒΉ' U = V β© W
Z : Set Ξ²
Z_in : Z β G
hZ : f β»ΒΉ' Z β W
β’ f '' (V β© W) = f '' (f β»ΒΉ' U)
[PROOFSTEP]
rw [h]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
F : Filter Ξ±
G : Filter Ξ²
β’ map f (comap f G β F) = G β map f F
[PROOFSTEP]
simp only [Filter.push_pull, inf_comm]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s : Set Ξ±
β’ π s = map Subtype.val β€
[PROOFSTEP]
simp
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
F : Filter Ξ±
s : Set Ξ±
β’ F β π s = β₯ β comap Subtype.val F = β₯
[PROOFSTEP]
rw [principal_eq_map_coe_top s, β Filter.push_pull', inf_top_eq, map_eq_bot_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
a : Ξ±
β’ f β€ pure a β {a} β f
[PROOFSTEP]
rw [β principal_singleton, le_principal_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Ξ± β Ξ²)
g : Filter Ξ±
s : Set Ξ²
β’ s β seq f g β β u, u β f β§ β t, t β g β§ Set.seq u t β s
[PROOFSTEP]
simp only [mem_seq_def, seq_subset, exists_prop, iff_self_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Ξ± β Ξ²
f : Filter Ξ±
β’ seq (pure g) f = map g f
[PROOFSTEP]
refine' le_antisymm (le_map fun s hs => _) (le_seq fun s hs t ht => _)
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Ξ± β Ξ²
f : Filter Ξ±
s : Set Ξ±
hs : s β f
β’ g '' s β seq (pure g) f
[PROOFSTEP]
rw [β singleton_seq]
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Ξ± β Ξ²
f : Filter Ξ±
s : Set Ξ±
hs : s β f
β’ Set.seq {g} s β seq (pure g) f
[PROOFSTEP]
apply seq_mem_seq _ hs
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Ξ± β Ξ²
f : Filter Ξ±
s : Set Ξ±
hs : s β f
β’ {g} β pure g
[PROOFSTEP]
exact singleton_mem_pure
[GOAL]
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Ξ± β Ξ²
f : Filter Ξ±
s : Set (Ξ± β Ξ²)
hs : s β pure g
t : Set Ξ±
ht : t β f
β’ Set.seq s t β map g f
[PROOFSTEP]
refine' sets_of_superset (map g f) (image_mem_map ht) _
[GOAL]
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Ξ± β Ξ²
f : Filter Ξ±
s : Set (Ξ± β Ξ²)
hs : s β pure g
t : Set Ξ±
ht : t β f
β’ g '' t β Set.seq s t
[PROOFSTEP]
rintro b β¨a, ha, rflβ©
[GOAL]
case refine'_2.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
g : Ξ± β Ξ²
f : Filter Ξ±
s : Set (Ξ± β Ξ²)
hs : s β pure g
t : Set Ξ±
ht : t β f
a : Ξ±
ha : a β t
β’ g a β Set.seq s t
[PROOFSTEP]
exact β¨g, hs, a, ha, rflβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Ξ± β Ξ²)
a : Ξ±
β’ seq f (pure a) = map (fun g => g a) f
[PROOFSTEP]
refine' le_antisymm (le_map fun s hs => _) (le_seq fun s hs t ht => _)
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Ξ± β Ξ²)
a : Ξ±
s : Set (Ξ± β Ξ²)
hs : s β f
β’ (fun g => g a) '' s β seq f (pure a)
[PROOFSTEP]
rw [β seq_singleton]
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Ξ± β Ξ²)
a : Ξ±
s : Set (Ξ± β Ξ²)
hs : s β f
β’ Set.seq s {a} β seq f (pure a)
[PROOFSTEP]
exact seq_mem_seq hs singleton_mem_pure
[GOAL]
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Ξ± β Ξ²)
a : Ξ±
s : Set (Ξ± β Ξ²)
hs : s β f
t : Set Ξ±
ht : t β pure a
β’ Set.seq s t β map (fun g => g a) f
[PROOFSTEP]
refine' sets_of_superset (map (fun g : Ξ± β Ξ² => g a) f) (image_mem_map hs) _
[GOAL]
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Ξ± β Ξ²)
a : Ξ±
s : Set (Ξ± β Ξ²)
hs : s β f
t : Set Ξ±
ht : t β pure a
β’ (fun g => g a) '' s β Set.seq s t
[PROOFSTEP]
rintro b β¨g, hg, rflβ©
[GOAL]
case refine'_2.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter (Ξ± β Ξ²)
a : Ξ±
s : Set (Ξ± β Ξ²)
hs : s β f
t : Set Ξ±
ht : t β pure a
g : Ξ± β Ξ²
hg : g β s
β’ (fun g => g a) g β Set.seq s t
[PROOFSTEP]
exact β¨g, hg, a, ht, rflβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
β’ seq h (seq g x) = seq (seq (map (fun x x_1 => x β x_1) h) g) x
[PROOFSTEP]
refine' le_antisymm (le_seq fun s hs t ht => _) (le_seq fun s hs t ht => _)
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ± β Ξ³)
hs : s β seq (map (fun x x_1 => x β x_1) h) g
t : Set Ξ±
ht : t β x
β’ Set.seq s t β seq h (seq g x)
[PROOFSTEP]
rcases mem_seq_iff.1 hs with β¨u, hu, v, hv, hsβ©
[GOAL]
case refine'_1.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ± β Ξ³)
hsβ : s β seq (map (fun x x_1 => x β x_1) h) g
t : Set Ξ±
ht : t β x
u : Set ((Ξ± β Ξ²) β Ξ± β Ξ³)
hu : u β map (fun x x_1 => x β x_1) h
v : Set (Ξ± β Ξ²)
hv : v β g
hs : Set.seq u v β s
β’ Set.seq s t β seq h (seq g x)
[PROOFSTEP]
rcases mem_map_iff_exists_image.1 hu with β¨w, hw, huβ©
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ± β Ξ³)
hsβ : s β seq (map (fun x x_1 => x β x_1) h) g
t : Set Ξ±
ht : t β x
u : Set ((Ξ± β Ξ²) β Ξ± β Ξ³)
huβ : u β map (fun x x_1 => x β x_1) h
v : Set (Ξ± β Ξ²)
hv : v β g
hs : Set.seq u v β s
w : Set (Ξ² β Ξ³)
hw : w β h
hu : (fun x x_1 => x β x_1) '' w β u
β’ Set.seq s t β seq h (seq g x)
[PROOFSTEP]
refine' mem_of_superset _ (Set.seq_mono ((Set.seq_mono hu Subset.rfl).trans hs) Subset.rfl)
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ± β Ξ³)
hsβ : s β seq (map (fun x x_1 => x β x_1) h) g
t : Set Ξ±
ht : t β x
u : Set ((Ξ± β Ξ²) β Ξ± β Ξ³)
huβ : u β map (fun x x_1 => x β x_1) h
v : Set (Ξ± β Ξ²)
hv : v β g
hs : Set.seq u v β s
w : Set (Ξ² β Ξ³)
hw : w β h
hu : (fun x x_1 => x β x_1) '' w β u
β’ Set.seq (Set.seq ((fun x x_1 => x β x_1) '' w) v) t β seq h (seq g x)
[PROOFSTEP]
rw [β Set.seq_seq]
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ± β Ξ³)
hsβ : s β seq (map (fun x x_1 => x β x_1) h) g
t : Set Ξ±
ht : t β x
u : Set ((Ξ± β Ξ²) β Ξ± β Ξ³)
huβ : u β map (fun x x_1 => x β x_1) h
v : Set (Ξ± β Ξ²)
hv : v β g
hs : Set.seq u v β s
w : Set (Ξ² β Ξ³)
hw : w β h
hu : (fun x x_1 => x β x_1) '' w β u
β’ Set.seq w (Set.seq v t) β seq h (seq g x)
[PROOFSTEP]
exact seq_mem_seq hw (seq_mem_seq hv ht)
[GOAL]
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ² β Ξ³)
hs : s β h
t : Set Ξ²
ht : t β seq g x
β’ Set.seq s t β seq (seq (map (fun x x_1 => x β x_1) h) g) x
[PROOFSTEP]
rcases mem_seq_iff.1 ht with β¨u, hu, v, hv, htβ©
[GOAL]
case refine'_2.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ² β Ξ³)
hs : s β h
t : Set Ξ²
htβ : t β seq g x
u : Set (Ξ± β Ξ²)
hu : u β g
v : Set Ξ±
hv : v β x
ht : Set.seq u v β t
β’ Set.seq s t β seq (seq (map (fun x x_1 => x β x_1) h) g) x
[PROOFSTEP]
refine' mem_of_superset _ (Set.seq_mono Subset.rfl ht)
[GOAL]
case refine'_2.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ² β Ξ³)
hs : s β h
t : Set Ξ²
htβ : t β seq g x
u : Set (Ξ± β Ξ²)
hu : u β g
v : Set Ξ±
hv : v β x
ht : Set.seq u v β t
β’ Set.seq s (Set.seq u v) β seq (seq (map (fun x x_1 => x β x_1) h) g) x
[PROOFSTEP]
rw [Set.seq_seq]
[GOAL]
case refine'_2.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
x : Filter Ξ±
g : Filter (Ξ± β Ξ²)
h : Filter (Ξ² β Ξ³)
s : Set (Ξ² β Ξ³)
hs : s β h
t : Set Ξ²
htβ : t β seq g x
u : Set (Ξ± β Ξ²)
hu : u β g
v : Set Ξ±
hv : v β x
ht : Set.seq u v β t
β’ Set.seq (Set.seq ((fun x x_1 => x β x_1) '' s) u) v β seq (seq (map (fun x x_1 => x β x_1) h) g) x
[PROOFSTEP]
exact seq_mem_seq (seq_mem_seq (image_mem_map hs) hu) hv
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
β’ seq (map Prod.mk f) g = seq (map (fun b a => (a, b)) g) f
[PROOFSTEP]
refine' le_antisymm (le_seq fun s hs t ht => _) (le_seq fun s hs t ht => _)
[GOAL]
case refine'_1
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ± β Ξ± Γ Ξ²)
hs : s β map (fun b a => (a, b)) g
t : Set Ξ±
ht : t β f
β’ Set.seq s t β seq (map Prod.mk f) g
[PROOFSTEP]
rcases mem_map_iff_exists_image.1 hs with β¨u, hu, hsβ©
[GOAL]
case refine'_1.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ± β Ξ± Γ Ξ²)
hsβ : s β map (fun b a => (a, b)) g
t : Set Ξ±
ht : t β f
u : Set Ξ²
hu : u β g
hs : (fun b a => (a, b)) '' u β s
β’ Set.seq s t β seq (map Prod.mk f) g
[PROOFSTEP]
refine' mem_of_superset _ (Set.seq_mono hs Subset.rfl)
[GOAL]
case refine'_1.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ± β Ξ± Γ Ξ²)
hsβ : s β map (fun b a => (a, b)) g
t : Set Ξ±
ht : t β f
u : Set Ξ²
hu : u β g
hs : (fun b a => (a, b)) '' u β s
β’ Set.seq ((fun b a => (a, b)) '' u) t β seq (map Prod.mk f) g
[PROOFSTEP]
rw [β Set.prod_image_seq_comm]
[GOAL]
case refine'_1.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ± β Ξ± Γ Ξ²)
hsβ : s β map (fun b a => (a, b)) g
t : Set Ξ±
ht : t β f
u : Set Ξ²
hu : u β g
hs : (fun b a => (a, b)) '' u β s
β’ Set.seq (Prod.mk '' t) u β seq (map Prod.mk f) g
[PROOFSTEP]
exact seq_mem_seq (image_mem_map ht) hu
[GOAL]
case refine'_2
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ² β Ξ± Γ Ξ²)
hs : s β map Prod.mk f
t : Set Ξ²
ht : t β g
β’ Set.seq s t β seq (map (fun b a => (a, b)) g) f
[PROOFSTEP]
rcases mem_map_iff_exists_image.1 hs with β¨u, hu, hsβ©
[GOAL]
case refine'_2.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ² β Ξ± Γ Ξ²)
hsβ : s β map Prod.mk f
t : Set Ξ²
ht : t β g
u : Set Ξ±
hu : u β f
hs : Prod.mk '' u β s
β’ Set.seq s t β seq (map (fun b a => (a, b)) g) f
[PROOFSTEP]
refine' mem_of_superset _ (Set.seq_mono hs Subset.rfl)
[GOAL]
case refine'_2.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ² β Ξ± Γ Ξ²)
hsβ : s β map Prod.mk f
t : Set Ξ²
ht : t β g
u : Set Ξ±
hu : u β f
hs : Prod.mk '' u β s
β’ Set.seq (Prod.mk '' u) t β seq (map (fun b a => (a, b)) g) f
[PROOFSTEP]
rw [Set.prod_image_seq_comm]
[GOAL]
case refine'_2.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
s : Set (Ξ² β Ξ± Γ Ξ²)
hsβ : s β map Prod.mk f
t : Set Ξ²
ht : t β g
u : Set Ξ±
hu : u β f
hs : Prod.mk '' u β s
β’ Set.seq ((fun b a => (a, b)) '' t) u β seq (map (fun b a => (a, b)) g) f
[PROOFSTEP]
exact seq_mem_seq (image_mem_map ht) hu
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ : Filter Ξ±
gβ gβ : Ξ± β Filter Ξ²
hf : fβ β€ fβ
hg : gβ β€αΆ [fβ] gβ
β’ bind fβ gβ β€ bind fβ gβ
[PROOFSTEP]
refine' le_trans (fun s hs => _) (join_mono <| map_mono hf)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ : Filter Ξ±
gβ gβ : Ξ± β Filter Ξ²
hf : fβ β€ fβ
hg : gβ β€αΆ [fβ] gβ
s : Set Ξ²
hs : s β join (map gβ fβ)
β’ s β bind fβ gβ
[PROOFSTEP]
simp only [mem_join, mem_bind', mem_map] at hs β’
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ : Filter Ξ±
gβ gβ : Ξ± β Filter Ξ²
hf : fβ β€ fβ
hg : gβ β€αΆ [fβ] gβ
s : Set Ξ²
hs : gβ β»ΒΉ' {t | s β t} β fβ
β’ {a | s β gβ a} β fβ
[PROOFSTEP]
filter_upwards [hg, hs] with _ hx hs using hx hs
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Ξ± β Filter Ξ²
sβ s : Set Ξ²
β’ (s β bind f fun x => g x β π sβ) β s β bind f g β π sβ
[PROOFSTEP]
simp only [mem_bind, mem_inf_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
s : Set Ξ±
f : Ξ± β Filter Ξ²
β’ join (map f (π s)) = β¨ (x : Ξ±) (_ : x β s), f x
[PROOFSTEP]
simp only [sSup_image, join_principal_eq_sSup, map_principal, eq_self_iff_true]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
fs : List Ξ²'
t : Set (List Ξ±')
β’ t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
[PROOFSTEP]
constructor
[GOAL]
case mp
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
fs : List Ξ²'
t : Set (List Ξ±')
β’ t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
[PROOFSTEP]
induction fs generalizing t
[GOAL]
case mp.nil
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
t : Set (List Ξ±')
β’ t β traverse f [] β β us, Forallβ (fun b s => s β f b) [] us β§ sequence us β t
case mp.cons
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
headβ : Ξ²'
tailβ : List Ξ²'
tail_ihβ : β (t : Set (List Ξ±')), t β traverse f tailβ β β us, Forallβ (fun b s => s β f b) tailβ us β§ sequence us β t
t : Set (List Ξ±')
β’ t β traverse f (headβ :: tailβ) β β us, Forallβ (fun b s => s β f b) (headβ :: tailβ) us β§ sequence us β t
[PROOFSTEP]
case nil =>
simp only [sequence, mem_pure, imp_self, forallβ_nil_left_iff, exists_eq_left, Set.pure_def, singleton_subset_iff,
traverse_nil]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
t : Set (List Ξ±')
β’ t β traverse f [] β β us, Forallβ (fun b s => s β f b) [] us β§ sequence us β t
[PROOFSTEP]
case nil =>
simp only [sequence, mem_pure, imp_self, forallβ_nil_left_iff, exists_eq_left, Set.pure_def, singleton_subset_iff,
traverse_nil]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
t : Set (List Ξ±')
β’ t β traverse f [] β β us, Forallβ (fun b s => s β f b) [] us β§ sequence us β t
[PROOFSTEP]
simp only [sequence, mem_pure, imp_self, forallβ_nil_left_iff, exists_eq_left, Set.pure_def, singleton_subset_iff,
traverse_nil]
[GOAL]
case mp.cons
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
headβ : Ξ²'
tailβ : List Ξ²'
tail_ihβ : β (t : Set (List Ξ±')), t β traverse f tailβ β β us, Forallβ (fun b s => s β f b) tailβ us β§ sequence us β t
t : Set (List Ξ±')
β’ t β traverse f (headβ :: tailβ) β β us, Forallβ (fun b s => s β f b) (headβ :: tailβ) us β§ sequence us β t
[PROOFSTEP]
case cons b fs ih =>
intro ht
rcases mem_seq_iff.1 ht with β¨u, hu, v, hv, htβ©
rcases mem_map_iff_exists_image.1 hu with β¨w, hw, hwuβ©
rcases ih v hv with β¨us, hus, huβ©
exact β¨w :: us, Forallβ.cons hw hus, (Set.seq_mono hwu hu).trans htβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
b : Ξ²'
fs : List Ξ²'
ih : β (t : Set (List Ξ±')), t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
t : Set (List Ξ±')
β’ t β traverse f (b :: fs) β β us, Forallβ (fun b s => s β f b) (b :: fs) us β§ sequence us β t
[PROOFSTEP]
case cons b fs ih =>
intro ht
rcases mem_seq_iff.1 ht with β¨u, hu, v, hv, htβ©
rcases mem_map_iff_exists_image.1 hu with β¨w, hw, hwuβ©
rcases ih v hv with β¨us, hus, huβ©
exact β¨w :: us, Forallβ.cons hw hus, (Set.seq_mono hwu hu).trans htβ©
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
b : Ξ²'
fs : List Ξ²'
ih : β (t : Set (List Ξ±')), t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
t : Set (List Ξ±')
β’ t β traverse f (b :: fs) β β us, Forallβ (fun b s => s β f b) (b :: fs) us β§ sequence us β t
[PROOFSTEP]
intro ht
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
b : Ξ²'
fs : List Ξ²'
ih : β (t : Set (List Ξ±')), t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
t : Set (List Ξ±')
ht : t β traverse f (b :: fs)
β’ β us, Forallβ (fun b s => s β f b) (b :: fs) us β§ sequence us β t
[PROOFSTEP]
rcases mem_seq_iff.1 ht with β¨u, hu, v, hv, htβ©
[GOAL]
case intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
b : Ξ²'
fs : List Ξ²'
ih : β (t : Set (List Ξ±')), t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
t : Set (List Ξ±')
htβ : t β traverse f (b :: fs)
u : Set (List Ξ±' β List Ξ±')
hu : u β cons <$> f b
v : Set (List Ξ±')
hv : v β (fun x => List.traverse f fs) ()
ht : Set.seq u v β t
β’ β us, Forallβ (fun b s => s β f b) (b :: fs) us β§ sequence us β t
[PROOFSTEP]
rcases mem_map_iff_exists_image.1 hu with β¨w, hw, hwuβ©
[GOAL]
case intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
b : Ξ²'
fs : List Ξ²'
ih : β (t : Set (List Ξ±')), t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
t : Set (List Ξ±')
htβ : t β traverse f (b :: fs)
u : Set (List Ξ±' β List Ξ±')
hu : u β cons <$> f b
v : Set (List Ξ±')
hv : v β (fun x => List.traverse f fs) ()
ht : Set.seq u v β t
w : Set Ξ±'
hw : w β f b
hwu : cons '' w β u
β’ β us, Forallβ (fun b s => s β f b) (b :: fs) us β§ sequence us β t
[PROOFSTEP]
rcases ih v hv with β¨us, hus, huβ©
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
b : Ξ²'
fs : List Ξ²'
ih : β (t : Set (List Ξ±')), t β traverse f fs β β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t
t : Set (List Ξ±')
htβ : t β traverse f (b :: fs)
u : Set (List Ξ±' β List Ξ±')
huβ : u β cons <$> f b
v : Set (List Ξ±')
hv : v β (fun x => List.traverse f fs) ()
ht : Set.seq u v β t
w : Set Ξ±'
hw : w β f b
hwu : cons '' w β u
us : List (Set Ξ±')
hus : Forallβ (fun b s => s β f b) fs us
hu : sequence us β v
β’ β us, Forallβ (fun b s => s β f b) (b :: fs) us β§ sequence us β t
[PROOFSTEP]
exact β¨w :: us, Forallβ.cons hw hus, (Set.seq_mono hwu hu).trans htβ©
[GOAL]
case mpr
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
fs : List Ξ²'
t : Set (List Ξ±')
β’ (β us, Forallβ (fun b s => s β f b) fs us β§ sequence us β t) β t β traverse f fs
[PROOFSTEP]
rintro β¨us, hus, hsβ©
[GOAL]
case mpr.intro.intro
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
Ξ±' Ξ²' Ξ³' : Type u
f : Ξ²' β Filter Ξ±'
s : Ξ³' β Set Ξ±'
fs : List Ξ²'
t : Set (List Ξ±')
us : List (Set Ξ±')
hus : Forallβ (fun b s => s β f b) fs us
hs : sequence us β t
β’ t β traverse f fs
[PROOFSTEP]
exact mem_of_superset (mem_traverse _ _ hus) hs
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
l : Filter Ξ²
β’ Tendsto f β₯ l
[PROOFSTEP]
simp [Tendsto]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
mab : Ξ± β Ξ²
mba : Ξ² β Ξ±
f : Filter Ξ±
g : Filter Ξ²
hβ : mab β mba =αΆ [g] id
hβ : Tendsto mba g f
β’ g β€ map mab f
[PROOFSTEP]
rw [β @map_id _ g, β map_congr hβ, β map_map]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
mab : Ξ± β Ξ²
mba : Ξ² β Ξ±
f : Filter Ξ±
g : Filter Ξ²
hβ : mab β mba =αΆ [g] id
hβ : Tendsto mba g f
β’ map mab (map mba g) β€ map mab f
[PROOFSTEP]
exact map_mono hβ
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
instβ : IsEmpty Ξ±
f : Ξ± β Ξ²
la : Filter Ξ±
lb : Filter Ξ²
β’ Tendsto f la lb
[PROOFSTEP]
simp only [filter_eq_bot_of_isEmpty la, tendsto_bot]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
fβ fβ : Ξ± β Ξ²
lβ : Filter Ξ±
lβ : Filter Ξ²
hl : fβ =αΆ [lβ] fβ
β’ Tendsto fβ lβ lβ β Tendsto fβ lβ lβ
[PROOFSTEP]
rw [Tendsto, Tendsto, map_congr hl]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ² β Ξ³
g : Ξ± β Ξ²
x : Filter Ξ±
y : Filter Ξ³
β’ Tendsto f (map g x) y β Tendsto (f β g) x y
[PROOFSTEP]
rw [Tendsto, Tendsto, map_map]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
g : Ξ² β Ξ³
a : Filter Ξ±
c : Filter Ξ³
h : Tendsto (g β f) a c
β’ map g (map f a) β€ c
[PROOFSTEP]
rwa [map_map]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
g : Filter Ξ²
i : Ξ³ β Ξ±
h : range i β f
β’ Tendsto (m β i) (comap i f) g β Tendsto m f g
[PROOFSTEP]
rw [Tendsto, β map_compose]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
m : Ξ± β Ξ²
f : Filter Ξ±
g : Filter Ξ²
i : Ξ³ β Ξ±
h : range i β f
β’ (map m β map i) (comap i f) β€ g β Tendsto m f g
[PROOFSTEP]
simp only [(Β· β Β·), map_comap_of_mem h, Tendsto]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
g : Ξ² β Ξ³
a : Filter Ξ±
b : Filter Ξ²
c : Filter Ξ³
hfg : Tendsto (g β f) a c
hg : comap g c β€ b
β’ Tendsto f a b
[PROOFSTEP]
rw [tendsto_iff_comap] at hfg β’
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
g : Ξ² β Ξ³
a : Filter Ξ±
b : Filter Ξ²
c : Filter Ξ³
hfg : a β€ comap (g β f) c
hg : comap g c β€ b
β’ a β€ comap f b
[PROOFSTEP]
calc
a β€ comap (g β f) c := hfg
_ β€ comap f b := by simpa [comap_comap] using comap_mono hg
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
g : Ξ² β Ξ³
a : Filter Ξ±
b : Filter Ξ²
c : Filter Ξ³
hfg : a β€ comap (g β f) c
hg : comap g c β€ b
β’ comap (g β f) c β€ comap f b
[PROOFSTEP]
simpa [comap_comap] using comap_mono hg
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
Ο : Ξ± β Ξ²
Ο : Ξ² β Ξ±
eq : Ο β Ο = id
hΟ : Tendsto Ο f g
hΟ : Tendsto Ο g f
β’ comap Ο g = f
[PROOFSTEP]
refine' ((comap_mono <| map_le_iff_le_comap.1 hΟ).trans _).antisymm (map_le_iff_le_comap.1 hΟ)
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
Ο : Ξ± β Ξ²
Ο : Ξ² β Ξ±
eq : Ο β Ο = id
hΟ : Tendsto Ο f g
hΟ : Tendsto Ο g f
β’ comap Ο (comap Ο f) β€ f
[PROOFSTEP]
rw [comap_comap, eq, comap_id]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
Ο : Ξ± β Ξ²
Ο : Ξ² β Ξ±
eq : Ο β Ο = id
hΟ : Tendsto Ο f g
hΟ : Tendsto Ο g f
β’ map Ο f = g
[PROOFSTEP]
refine' le_antisymm hΟ (le_trans _ (map_mono hΟ))
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Filter Ξ±
g : Filter Ξ²
Ο : Ξ± β Ξ²
Ο : Ξ² β Ξ±
eq : Ο β Ο = id
hΟ : Tendsto Ο f g
hΟ : Tendsto Ο g f
β’ g β€ map Ο (map Ο g)
[PROOFSTEP]
rw [map_map, eq, map_id]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
x : Filter Ξ±
yβ yβ : Filter Ξ²
β’ Tendsto f x (yβ β yβ) β Tendsto f x yβ β§ Tendsto f x yβ
[PROOFSTEP]
simp only [Tendsto, le_inf_iff, iff_self_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
x : Filter Ξ±
y : ΞΉ β Filter Ξ²
β’ Tendsto f x (β¨
(i : ΞΉ), y i) β β (i : ΞΉ), Tendsto f x (y i)
[PROOFSTEP]
simp only [Tendsto, iff_self_iff, le_iInf_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
xβ xβ : Filter Ξ±
y : Filter Ξ²
β’ Tendsto f (xβ β xβ) y β Tendsto f xβ y β§ Tendsto f xβ y
[PROOFSTEP]
simp only [Tendsto, map_sup, sup_le_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
x : ΞΉ β Filter Ξ±
y : Filter Ξ²
β’ Tendsto f (β¨ (i : ΞΉ), x i) y β β (i : ΞΉ), Tendsto f (x i) y
[PROOFSTEP]
simp only [Tendsto, map_iSup, iSup_le_iff]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
l : Filter Ξ±
s : Set Ξ²
β’ Tendsto f l (π s) β βαΆ (a : Ξ±) in l, f a β s
[PROOFSTEP]
simp only [Tendsto, le_principal_iff, mem_map', Filter.Eventually]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
s : Set Ξ±
t : Set Ξ²
β’ Tendsto f (π s) (π t) β β (a : Ξ±), a β s β f a β t
[PROOFSTEP]
simp only [tendsto_principal, eventually_principal]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
a : Filter Ξ±
b : Ξ²
β’ Tendsto f a (pure b) β βαΆ (x : Ξ±) in a, f x = b
[PROOFSTEP]
simp only [Tendsto, le_pure_iff, mem_map', mem_singleton_iff, Filter.Eventually]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
f : Ξ± β Ξ²
s : Set Ξ²
l : Filter Ξ±
t : Set Ξ²
β’ t β map f (l β π (f β»ΒΉ' s)) β t β map f l β π s
[PROOFSTEP]
simp only [mem_map', mem_inf_principal, mem_setOf_eq, mem_preimage]
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
lβ : Filter Ξ±
lβ : Filter Ξ²
f g : Ξ± β Ξ²
p : Ξ± β Prop
instβ : (x : Ξ±) β Decidable (p x)
hβ : Tendsto f (lβ β π {x | p x}) lβ
hβ : Tendsto g (lβ β π {x | Β¬p x}) lβ
β’ Tendsto (fun x => if p x then f x else g x) lβ lβ
[PROOFSTEP]
simp only [tendsto_def, mem_inf_principal] at *
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
lβ : Filter Ξ±
lβ : Filter Ξ²
f g : Ξ± β Ξ²
p : Ξ± β Prop
instβ : (x : Ξ±) β Decidable (p x)
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | p x} β x β f β»ΒΉ' s} β lβ
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | Β¬p x} β x β g β»ΒΉ' s} β lβ
β’ β (s : Set Ξ²), s β lβ β (fun x => if p x then f x else g x) β»ΒΉ' s β lβ
[PROOFSTEP]
intro s hs
[GOAL]
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
lβ : Filter Ξ±
lβ : Filter Ξ²
f g : Ξ± β Ξ²
p : Ξ± β Prop
instβ : (x : Ξ±) β Decidable (p x)
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | p x} β x β f β»ΒΉ' s} β lβ
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | Β¬p x} β x β g β»ΒΉ' s} β lβ
s : Set Ξ²
hs : s β lβ
β’ (fun x => if p x then f x else g x) β»ΒΉ' s β lβ
[PROOFSTEP]
filter_upwards [hβ s hs, hβ s hs] with x hpβ hpβ
[GOAL]
case h
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
lβ : Filter Ξ±
lβ : Filter Ξ²
f g : Ξ± β Ξ²
p : Ξ± β Prop
instβ : (x : Ξ±) β Decidable (p x)
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | p x} β x β f β»ΒΉ' s} β lβ
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | Β¬p x} β x β g β»ΒΉ' s} β lβ
s : Set Ξ²
hs : s β lβ
x : Ξ±
hpβ : p x β x β f β»ΒΉ' s
hpβ : Β¬p x β x β g β»ΒΉ' s
β’ x β (fun x => if p x then f x else g x) β»ΒΉ' s
[PROOFSTEP]
rw [mem_preimage]
[GOAL]
case h
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
lβ : Filter Ξ±
lβ : Filter Ξ²
f g : Ξ± β Ξ²
p : Ξ± β Prop
instβ : (x : Ξ±) β Decidable (p x)
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | p x} β x β f β»ΒΉ' s} β lβ
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | Β¬p x} β x β g β»ΒΉ' s} β lβ
s : Set Ξ²
hs : s β lβ
x : Ξ±
hpβ : p x β x β f β»ΒΉ' s
hpβ : Β¬p x β x β g β»ΒΉ' s
β’ (if p x then f x else g x) β s
[PROOFSTEP]
split_ifs with h
[GOAL]
case pos
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
lβ : Filter Ξ±
lβ : Filter Ξ²
f g : Ξ± β Ξ²
p : Ξ± β Prop
instβ : (x : Ξ±) β Decidable (p x)
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | p x} β x β f β»ΒΉ' s} β lβ
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | Β¬p x} β x β g β»ΒΉ' s} β lβ
s : Set Ξ²
hs : s β lβ
x : Ξ±
hpβ : p x β x β f β»ΒΉ' s
hpβ : Β¬p x β x β g β»ΒΉ' s
h : p x
β’ f x β s
case neg
Ξ± : Type u
Ξ² : Type v
Ξ³ : Type w
Ξ΄ : Type u_1
ΞΉ : Sort x
lβ : Filter Ξ±
lβ : Filter Ξ²
f g : Ξ± β Ξ²
p : Ξ± β Prop
instβ : (x : Ξ±) β Decidable (p x)
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | p x} β x β f β»ΒΉ' s} β lβ
hβ : β (s : Set Ξ²), s β lβ β {x | x β {x | Β¬p x} β x β g β»ΒΉ' s} β lβ
s : Set Ξ²
hs : s β lβ
x : Ξ±
hpβ : p x β x β f β»ΒΉ' s
hpβ : Β¬p x β x β g β»ΒΉ' s
h : Β¬p x
β’ g x β s
[PROOFSTEP]
exacts [hpβ h, hpβ h]
|
#include <boost/log/sources/severity_logger.hpp>
|
import .Winston
Image(height, width, a::Winston.FramedPlot) =
Image(height, width, ImageFileData(a))
function ImageFileData(a::Winston.FramedPlot)
filename = tempname()*".pdf"
Winston.savefig(a, filename)
r = read(filename)
rm(filename)
ImageFileData(r, :pdf)
end |
using Base.Enums
using MLStyle.Render
using DataStructures
struct Field
name :: Any # an expr to represent the field name from IN_FIELDS.
make :: Any
var :: Symbol
typ :: Any
end
function query_routine(assigns :: OrderedDict{Symbol, Any},
fn_in_fields :: Vector{Field},
fn_returns :: Any,
result; infer_type = true)
@assert haskey(assigns, FN_OUT_FIELDS)
fn_arguments = map(x -> x.var, fn_in_fields)
fn_arg_types = Expr(:vect, map(x -> x.typ, fn_in_fields)...)
function (inner_expr)
let_seq = [
Expr(:(=), Expr(:tuple, IN_FIELDS, IN_TYPES, IN_SOURCE), inner_expr),
(:($name = $value) for (name, value) in assigns)...,
:(@inline $FN($(fn_arguments...)) = $fn_returns),
]
if infer_type
let type_infer = :($FN_RETURN_TYPES = $type_unpack($length($FN_OUT_FIELDS, ), $return_type($FN, $fn_arg_types)))
push!(let_seq, type_infer)
end
end
Expr(:let,
Expr(
:block,
let_seq...
),
result
)
end
end
# visitor to process the pattern `_.x, _,"x", _.(1)` inside an expression
function mk_visit(fields :: Dict{Any, Field}, assigns :: OrderedDict{Symbol, Any})
visit = expr ->
@match expr begin
Expr(:. , :_, q :: QuoteNode) && Do(a = q.value) ||
Expr(:., :_, Expr(:tuple, a)) =>
@match a begin
a :: Int =>
let field = get!(fields, a) do
var_sym = gen_sym(a)
Field(
a,
Expr(:ref, RECORD, a),
var_sym,
Expr(:ref, IN_TYPES, a)
)
end
field.var
end
::String && Do(b = Symbol(a)) ||
b::Symbol =>
let field = get!(fields, b) do
idx_sym = gen_sym()
var_sym = gen_sym(b)
assigns[idx_sym] = Expr(:call, findfirst, x -> x === b, IN_FIELDS)
Field(
b,
Expr(:ref, RECORD, idx_sym),
var_sym,
Expr(:ref, IN_TYPES, idx_sym)
)
end
field.var
end
end
Expr(head, args...) => Expr(head, map(visit, args)...)
a => a
end
end
function fn_apply(fields :: Vector{Field})
Expr(
:let,
let let_seq = (:($(field.var) = $(field.make)) for field in fields)
Expr(:block, let_seq...)
end,
let args = (field.var for field in fields)
:($FN($(args...)))
end
)
end
function generate_where(args :: AbstractArray)
pred_in_fields = Dict{Any, Field}()
assigns = OrderedDict{Symbol, Any}(FN_OUT_FIELDS => IN_FIELDS)
visit = mk_visit(pred_in_fields, assigns)
pred = foldl(args, init=true) do last, arg
boolean = visit(arg)
if last === true
boolean
else
Expr(:&&, last, boolean)
end
end
fields :: Vector{Field} = pred_in_fields |> values |> collect
# where expression generation
query_routine(
assigns,
fields,
pred,
Expr(:tuple,
IN_FIELDS,
IN_TYPES,
:($RECORD for $RECORD in $IN_SOURCE if $(fn_apply(fields)))
);
infer_type = false
)
end
function generate_select(args :: AbstractArray)
map_in_fields = Dict{Any, Field}()
assigns = OrderedDict{Symbol, Any}()
fn_return_elts :: Vector{Any} = []
fn_return_fields :: Vector{Any} = []
visit = mk_visit(map_in_fields, assigns)
# process selectors
predicate_process(arg) =
@match arg begin
:(!$pred($ (args...) )) && Do(ab=true) ||
:($pred($ (args...) )) && Do(ab=false) ||
:(!$pred) && Do(ab=true, args=[]) ||
:($pred) && Do(ab=false, args=[]) =>
let idx_sym = gen_sym()
assigns[idx_sym] =
Expr(
:call,
findall,
ab ?
:(@inline function ($ARG,) !$pred($string($ARG,), $(args...)) end) :
:(@inline function ($ARG,) $pred($string($ARG,), $(args...)) end)
, IN_FIELDS
)
idx_sym
end
end
foreach(args) do arg
@match arg begin
:_ =>
let field = get!(map_in_fields, all) do
var_sym = gen_sym()
push!(fn_return_elts, Expr(:..., var_sym))
push!(fn_return_fields, Expr(:..., IN_FIELDS))
Field(
all,
RECORD,
var_sym,
:($Tuple{$IN_TYPES...})
)
end
nothing
end
:(_.($(args...))) =>
let indices = map(predicate_process, args)
if haskey(map_in_fields, arg)
throw("The columns `$(string(arg))` are selected twice!")
elseif !isempty(indices)
idx_sym = gen_sym()
var_sym = gen_sym()
field = begin
assigns[idx_sym] =
length(indices) === 1 ?
indices[1] :
Expr(:call, intersect, indices...)
push!(fn_return_elts, Expr(:..., var_sym))
push!(fn_return_fields, Expr(:..., Expr(:ref, IN_FIELDS, idx_sym)))
Field(
arg,
Expr(:ref, RECORD, idx_sym),
var_sym,
Expr(:curly, Tuple, Expr(:..., Expr(:ref, IN_TYPES, idx_sym)))
)
end
map_in_fields[arg] = field
nothing
end
end
:($a => $new_field) || a && Do(new_field = Symbol(string(a))) =>
let new_value = visit(a)
push!(fn_return_fields, QuoteNode(new_field))
push!(fn_return_elts, new_value)
nothing
end
end
end
fields = map_in_fields |> values |> collect
assigns[FN_OUT_FIELDS] = Expr(:vect, fn_return_fields...)
# select expression generation
query_routine(
assigns,
fields,
Expr(:tuple, fn_return_elts...),
Expr(
:tuple,
FN_OUT_FIELDS,
FN_RETURN_TYPES,
:($(fn_apply(fields)) for $RECORD in $IN_SOURCE)
); infer_type = true
)
end
function generate_groupby(args :: AbstractArray, having_args :: Union{Nothing, AbstractArray} = nothing)
group_in_fields = Dict{Any, Field}()
having_in_fields = Dict{Any, Field}()
assigns = OrderedDict{Symbol, Any}()
visit_group_fn = mk_visit(group_in_fields, assigns)
visit_having = mk_visit(having_in_fields, assigns)
group_fn_return_vars = []
group_fn_return_elts = []
foreach(args) do arg
@match arg begin
:($b => $a) || b && Do(a = Symbol(string(b))) =>
let field = a
push!(group_fn_return_vars, a)
push!(group_fn_return_elts, visit_group_fn(b))
nothing
end
end
end
cond_expr = having_args === nothing ? nothing :
let cond =
foldl(having_args) do last, arg
Expr(:&&, last, visit_having(arg))
end
quote
if !($cond)
continue
end
end
end
group_fn_return_fields = map(QuoteNode, group_fn_return_vars)
ngroup_key = length(group_fn_return_vars)
group_fields = group_in_fields |> values |> collect
bindings_inside_for_loop = [
(:($(field.var) = $(field.make)) for field in group_fields)...,
(:($(field.var) = $(field.make)) for (key, field) in having_in_fields if !haskey(group_in_fields, key))...
]
assigns[FN_OUT_FIELDS] = Expr(:vect, group_fn_return_fields...)
group_fn_required_vars = [field.var for field in values(group_in_fields)]
group_key_lhs = Expr(:tuple, group_fn_return_vars...)
group_key_rhs = Expr(:call, FN, group_fn_required_vars...)
# groupby expression generation
query_routine(
assigns,
group_fields,
Expr(:tuple, group_fn_return_elts...),
let out_fields = Expr(:vcat, FN_OUT_FIELDS, IN_FIELDS),
out_types = Expr(:vcat, FN_RETURN_TYPES, AGG_TYPES)
quote
$AGG_TYPES = [$Vector{each} for each in $IN_TYPES]
$GROUPS = $Dict{$Tuple{$FN_RETURN_TYPES...}, $Tuple{$AGG_TYPES...}}()
$N = $length($IN_FIELDS,)
for $RECORD in $IN_SOURCE
$(bindings_inside_for_loop...)
$GROUP_KEY = $group_key_lhs = $group_key_rhs
$cond_expr
$AGG =
$get!($GROUPS, $GROUP_KEY) do
Tuple(typ[] for typ in $IN_TYPES)
end
($push!).($AGG, $RECORD,)
end
(
$out_fields,
$out_types,
((k..., v...) for (k, v) in $GROUPS)
)
end
end
)
end
|
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudriashov, YaΓ«l Dillies
-/
import algebra.order.invertible
import algebra.order.module
import linear_algebra.affine_space.midpoint
import linear_algebra.affine_space.affine_subspace
import linear_algebra.ray
/-!
# Convex sets and functions in vector spaces
In a π-vector space, we define the following objects and properties.
* `segment π x y`: Closed segment joining `x` and `y`.
* `open_segment π x y`: Open segment joining `x` and `y`.
* `convex π s`: A set `s` is convex if for any two points `x y β s` it includes `segment π x y`.
* `std_simplex π ΞΉ`: The standard simplex in `ΞΉ β π` (currently requires `fintype ΞΉ`). It is the
intersection of the positive quadrant with the hyperplane `s.sum = 1`.
We also provide various equivalent versions of the definitions above, prove that some specific sets
are convex.
## Notations
We provide the following notation:
* `[x -[π] y] = segment π x y` in locale `convex`
## TODO
Generalize all this file to affine spaces.
Should we rename `segment` and `open_segment` to `convex.Icc` and `convex.Ioo`? Should we also
define `clopen_segment`/`convex.Ico`/`convex.Ioc`?
-/
variables {π E F Ξ² : Type*}
open linear_map set
open_locale big_operators classical pointwise
/-! ### Segment -/
section ordered_semiring
variables [ordered_semiring π] [add_comm_monoid E]
section has_smul
variables (π) [has_smul π E]
/-- Segments in a vector space. -/
def segment (x y : E) : set E :=
{z : E | β (a b : π) (ha : 0 β€ a) (hb : 0 β€ b) (hab : a + b = 1), a β’ x + b β’ y = z}
/-- Open segment in a vector space. Note that `open_segment π x x = {x}` instead of being `β
` when
the base semiring has some element between `0` and `1`. -/
def open_segment (x y : E) : set E :=
{z : E | β (a b : π) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1), a β’ x + b β’ y = z}
localized "notation `[` x ` -[` π `] ` y `]` := segment π x y" in convex
lemma segment_eq_imageβ (x y : E) :
[x -[π] y] = (Ξ» p : π Γ π, p.1 β’ x + p.2 β’ y) '' {p | 0 β€ p.1 β§ 0 β€ p.2 β§ p.1 + p.2 = 1} :=
by simp only [segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc]
lemma open_segment_eq_imageβ (x y : E) :
open_segment π x y =
(Ξ» p : π Γ π, p.1 β’ x + p.2 β’ y) '' {p | 0 < p.1 β§ 0 < p.2 β§ p.1 + p.2 = 1} :=
by simp only [open_segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc]
lemma segment_symm (x y : E) : [x -[π] y] = [y -[π] x] :=
set.ext $ Ξ» z,
β¨Ξ» β¨a, b, ha, hb, hab, Hβ©, β¨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans Hβ©,
Ξ» β¨a, b, ha, hb, hab, Hβ©, β¨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans Hβ©β©
lemma open_segment_symm (x y : E) :
open_segment π x y = open_segment π y x :=
set.ext $ Ξ» z,
β¨Ξ» β¨a, b, ha, hb, hab, Hβ©, β¨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans Hβ©,
Ξ» β¨a, b, ha, hb, hab, Hβ©, β¨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans Hβ©β©
lemma open_segment_subset_segment (x y : E) :
open_segment π x y β [x -[π] y] :=
Ξ» z β¨a, b, ha, hb, hab, hzβ©, β¨a, b, ha.le, hb.le, hab, hzβ©
lemma segment_subset_iff {x y : E} {s : set E} :
[x -[π] y] β s β β a b : π, 0 β€ a β 0 β€ b β a + b = 1 β a β’ x + b β’ y β s :=
β¨Ξ» H a b ha hb hab, H β¨a, b, ha, hb, hab, rflβ©,
Ξ» H z β¨a, b, ha, hb, hab, hzβ©, hz βΈ H a b ha hb habβ©
lemma open_segment_subset_iff {x y : E} {s : set E} :
open_segment π x y β s β β a b : π, 0 < a β 0 < b β a + b = 1 β a β’ x + b β’ y β s :=
β¨Ξ» H a b ha hb hab, H β¨a, b, ha, hb, hab, rflβ©,
Ξ» H z β¨a, b, ha, hb, hab, hzβ©, hz βΈ H a b ha hb habβ©
end has_smul
open_locale convex
section mul_action_with_zero
variables (π) [mul_action_with_zero π E]
lemma left_mem_segment (x y : E) : x β [x -[π] y] :=
β¨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]β©
lemma right_mem_segment (x y : E) : y β [x -[π] y] :=
segment_symm π y x βΈ left_mem_segment π y x
end mul_action_with_zero
section module
variables (π) [module π E] {x y z : E} {s : set E}
@[simp] lemma segment_same (x : E) : [x -[π] x] = {x} :=
set.ext $ Ξ» z, β¨Ξ» β¨a, b, ha, hb, hab, hzβ©,
by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
Ξ» h, mem_singleton_iff.1 h βΈ left_mem_segment π z zβ©
lemma insert_endpoints_open_segment (x y : E) :
insert x (insert y (open_segment π x y)) = [x -[π] y] :=
begin
simp only [subset_antisymm_iff, insert_subset, left_mem_segment, right_mem_segment,
open_segment_subset_segment, true_and],
rintro z β¨a, b, ha, hb, hab, rflβ©,
refine hb.eq_or_gt.imp _ (Ξ» hb', ha.eq_or_gt.imp _ _),
{ rintro rfl,
rw add_zero at hab,
rw [hab, one_smul, zero_smul, add_zero] },
{ rintro rfl,
rw zero_add at hab,
rw [hab, one_smul, zero_smul, zero_add] },
{ exact Ξ» ha', β¨a, b, ha', hb', hab, rflβ© }
end
variables {π}
lemma mem_open_segment_of_ne_left_right (hx : x β z) (hy : y β z) (hz : z β [x -[π] y]) :
z β open_segment π x y :=
begin
rw [β insert_endpoints_open_segment] at hz,
exact ((hz.resolve_left hx.symm).resolve_left hy.symm)
end
lemma open_segment_subset_iff_segment_subset (hx : x β s) (hy : y β s) :
open_segment π x y β s β [x -[π] y] β s :=
by simp only [β insert_endpoints_open_segment, insert_subset, *, true_and]
end module
end ordered_semiring
open_locale convex
section ordered_ring
variables [ordered_ring π]
section add_comm_group
variables (π) [add_comm_group E] [add_comm_group F] [module π E] [module π F]
section densely_ordered
variables [nontrivial π] [densely_ordered π]
@[simp] lemma open_segment_same (x : E) :
open_segment π x x = {x} :=
set.ext $ Ξ» z, β¨Ξ» β¨a, b, ha, hb, hab, hzβ©,
by simpa only [β add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
Ξ» (h : z = x), begin
obtain β¨a, haβ, haββ© := densely_ordered.dense (0 : π) 1 zero_lt_one,
refine β¨a, 1 - a, haβ, sub_pos_of_lt haβ, add_sub_cancel'_right _ _, _β©,
rw [βadd_smul, add_sub_cancel'_right, one_smul, h],
endβ©
end densely_ordered
lemma segment_eq_image (x y : E) : [x -[π] y] = (Ξ» ΞΈ : π, (1 - ΞΈ) β’ x + ΞΈ β’ y) '' Icc (0 : π) 1 :=
set.ext $ Ξ» z,
β¨Ξ» β¨a, b, ha, hb, hab, hzβ©,
β¨b, β¨hb, hab βΈ le_add_of_nonneg_left haβ©, hab βΈ hz βΈ by simp only [add_sub_cancel]β©,
Ξ» β¨ΞΈ, β¨hΞΈβ, hΞΈββ©, hzβ©, β¨1-ΞΈ, ΞΈ, sub_nonneg.2 hΞΈβ, hΞΈβ, sub_add_cancel _ _, hzβ©β©
lemma open_segment_eq_image (x y : E) :
open_segment π x y = (Ξ» (ΞΈ : π), (1 - ΞΈ) β’ x + ΞΈ β’ y) '' Ioo (0 : π) 1 :=
set.ext $ Ξ» z,
β¨Ξ» β¨a, b, ha, hb, hab, hzβ©,
β¨b, β¨hb, hab βΈ lt_add_of_pos_left _ haβ©, hab βΈ hz βΈ by simp only [add_sub_cancel]β©,
Ξ» β¨ΞΈ, β¨hΞΈβ, hΞΈββ©, hzβ©, β¨1 - ΞΈ, ΞΈ, sub_pos.2 hΞΈβ, hΞΈβ, sub_add_cancel _ _, hzβ©β©
lemma segment_eq_image' (x y : E) :
[x -[π] y] = (Ξ» (ΞΈ : π), x + ΞΈ β’ (y - x)) '' Icc (0 : π) 1 :=
by { convert segment_eq_image π x y, ext ΞΈ, simp only [smul_sub, sub_smul, one_smul], abel }
lemma open_segment_eq_image' (x y : E) :
open_segment π x y = (Ξ» (ΞΈ : π), x + ΞΈ β’ (y - x)) '' Ioo (0 : π) 1 :=
by { convert open_segment_eq_image π x y, ext ΞΈ, simp only [smul_sub, sub_smul, one_smul], abel }
lemma segment_eq_image_line_map (x y : E) :
[x -[π] y] = affine_map.line_map x y '' Icc (0 : π) 1 :=
by { convert segment_eq_image π x y, ext, exact affine_map.line_map_apply_module _ _ _ }
lemma open_segment_eq_image_line_map (x y : E) :
open_segment π x y = affine_map.line_map x y '' Ioo (0 : π) 1 :=
by { convert open_segment_eq_image π x y, ext, exact affine_map.line_map_apply_module _ _ _ }
lemma segment_image (f : E ββ[π] F) (a b : E) : f '' [a -[π] b] = [f a -[π] f b] :=
set.ext (Ξ» x, by simp_rw [segment_eq_image, mem_image, exists_exists_and_eq_and, map_add, map_smul])
@[simp] lemma open_segment_image (f : E ββ[π] F) (a b : E) :
f '' open_segment π a b = open_segment π (f a) (f b) :=
set.ext (Ξ» x, by simp_rw [open_segment_eq_image, mem_image, exists_exists_and_eq_and, map_add,
map_smul])
lemma mem_segment_translate (a : E) {x b c} : a + x β [a + b -[π] a + c] β x β [b -[π] c] :=
begin
rw [segment_eq_image', segment_eq_image'],
refine exists_congr (Ξ» ΞΈ, and_congr iff.rfl _),
simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj],
end
@[simp] lemma mem_open_segment_translate (a : E) {x b c : E} :
a + x β open_segment π (a + b) (a + c) β x β open_segment π b c :=
begin
rw [open_segment_eq_image', open_segment_eq_image'],
refine exists_congr (Ξ» ΞΈ, and_congr iff.rfl _),
simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj],
end
lemma segment_translate_preimage (a b c : E) : (Ξ» x, a + x) β»ΒΉ' [a + b -[π] a + c] = [b -[π] c] :=
set.ext $ Ξ» x, mem_segment_translate π a
lemma open_segment_translate_preimage (a b c : E) :
(Ξ» x, a + x) β»ΒΉ' open_segment π (a + b) (a + c) = open_segment π b c :=
set.ext $ Ξ» x, mem_open_segment_translate π a
lemma segment_translate_image (a b c : E) : (Ξ» x, a + x) '' [b -[π] c] = [a + b -[π] a + c] :=
segment_translate_preimage π a b c βΈ image_preimage_eq _ $ add_left_surjective a
lemma open_segment_translate_image (a b c : E) :
(Ξ» x, a + x) '' open_segment π b c = open_segment π (a + b) (a + c) :=
open_segment_translate_preimage π a b c βΈ image_preimage_eq _ $ add_left_surjective a
end add_comm_group
end ordered_ring
lemma same_ray_of_mem_segment [ordered_comm_ring π] [add_comm_group E] [module π E]
{x y z : E} (h : x β [y -[π] z]) : same_ray π (x - y) (z - x) :=
begin
rw segment_eq_image' at h,
rcases h with β¨ΞΈ, β¨hΞΈβ, hΞΈββ©, rflβ©,
simpa only [add_sub_cancel', β sub_sub, sub_smul, one_smul]
using (same_ray_nonneg_smul_left (z - y) hΞΈβ).nonneg_smul_right (sub_nonneg.2 hΞΈβ)
end
section linear_ordered_ring
variables [linear_ordered_ring π]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module π E] [module π F]
lemma midpoint_mem_segment [invertible (2 : π)] (x y : E) :
midpoint π x y β [x -[π] y] :=
begin
rw segment_eq_image_line_map,
exact β¨β
2, β¨inv_of_nonneg.mpr zero_le_two, inv_of_le_one one_le_twoβ©, rflβ©,
end
lemma mem_segment_sub_add [invertible (2 : π)] (x y : E) :
x β [x-y -[π] x+y] :=
begin
convert @midpoint_mem_segment π _ _ _ _ _ _ _,
rw midpoint_sub_add
end
lemma mem_segment_add_sub [invertible (2 : π)] (x y : E) :
x β [x+y -[π] x-y] :=
begin
convert @midpoint_mem_segment π _ _ _ _ _ _ _,
rw midpoint_add_sub
end
@[simp] lemma left_mem_open_segment_iff [densely_ordered π] [no_zero_smul_divisors π E] {x y : E} :
x β open_segment π x y β x = y :=
begin
split,
{ rintro β¨a, b, ha, hb, hab, hxβ©,
refine smul_right_injective _ hb.ne' ((add_right_inj (a β’ x)).1 _),
rw [hx, βadd_smul, hab, one_smul] },
{ rintro rfl,
rw open_segment_same,
exact mem_singleton _ }
end
@[simp] lemma right_mem_open_segment_iff [densely_ordered π] [no_zero_smul_divisors π E] {x y : E} :
y β open_segment π x y β x = y :=
by rw [open_segment_symm, left_mem_open_segment_iff, eq_comm]
end add_comm_group
end linear_ordered_ring
section linear_ordered_field
variables [linear_ordered_field π]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module π E] [module π F] {x y z : E}
lemma mem_segment_iff_same_ray : x β [y -[π] z] β same_ray π (x - y) (z - x) :=
begin
refine β¨same_ray_of_mem_segment, Ξ» h, _β©,
rcases h.exists_eq_smul_add with β¨a, b, ha, hb, hab, hxy, hzxβ©,
rw [add_comm, sub_add_sub_cancel] at hxy hzx,
rw [β mem_segment_translate _ (-x), neg_add_self],
refine β¨b, a, hb, ha, add_comm a b βΈ hab, _β©,
rw [β sub_eq_neg_add, β neg_sub, hxy, β sub_eq_neg_add, hzx, smul_neg, smul_comm, neg_add_self]
end
lemma mem_segment_iff_div : x β [y -[π] z] β
β a b : π, 0 β€ a β§ 0 β€ b β§ 0 < a + b β§ (a / (a + b)) β’ y + (b / (a + b)) β’ z = x :=
begin
split,
{ rintro β¨a, b, ha, hb, hab, rflβ©,
use [a, b, ha, hb],
simp * },
{ rintro β¨a, b, ha, hb, hab, rflβ©,
refine β¨a / (a + b), b / (a + b), div_nonneg ha hab.le, div_nonneg hb hab.le, _, rflβ©,
rw [β add_div, div_self hab.ne'] }
end
lemma mem_open_segment_iff_div : x β open_segment π y z β
β a b : π, 0 < a β§ 0 < b β§ (a / (a + b)) β’ y + (b / (a + b)) β’ z = x :=
begin
split,
{ rintro β¨a, b, ha, hb, hab, rflβ©,
use [a, b, ha, hb],
rw [hab, div_one, div_one] },
{ rintro β¨a, b, ha, hb, rflβ©,
have hab : 0 < a + b, from add_pos ha hb,
refine β¨a / (a + b), b / (a + b), div_pos ha hab, div_pos hb hab, _, rflβ©,
rw [β add_div, div_self hab.ne'] }
end
end add_comm_group
end linear_ordered_field
/-!
#### Segments in an ordered space
Relates `segment`, `open_segment` and `set.Icc`, `set.Ico`, `set.Ioc`, `set.Ioo`
-/
section ordered_semiring
variables [ordered_semiring π]
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid E] [module π E] [ordered_smul π E]
lemma segment_subset_Icc {x y : E} (h : x β€ y) : [x -[π] y] β Icc x y :=
begin
rintro z β¨a, b, ha, hb, hab, rflβ©,
split,
calc
x = a β’ x + b β’ x :(convex.combo_self hab _).symm
... β€ a β’ x + b β’ y : add_le_add_left (smul_le_smul_of_nonneg h hb) _,
calc
a β’ x + b β’ y
β€ a β’ y + b β’ y : add_le_add_right (smul_le_smul_of_nonneg h ha) _
... = y : convex.combo_self hab _,
end
end ordered_add_comm_monoid
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid E] [module π E] [ordered_smul π E]
lemma open_segment_subset_Ioo {x y : E} (h : x < y) : open_segment π x y β Ioo x y :=
begin
rintro z β¨a, b, ha, hb, hab, rflβ©,
split,
calc
x = a β’ x + b β’ x : (convex.combo_self hab _).symm
... < a β’ x + b β’ y : add_lt_add_left (smul_lt_smul_of_pos h hb) _,
calc
a β’ x + b β’ y
< a β’ y + b β’ y : add_lt_add_right (smul_lt_smul_of_pos h ha) _
... = y : convex.combo_self hab _,
end
end ordered_cancel_add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid E] [module π E] [ordered_smul π E] {π}
lemma segment_subset_interval (x y : E) : [x -[π] y] β interval x y :=
begin
cases le_total x y,
{ rw interval_of_le h,
exact segment_subset_Icc h },
{ rw [interval_of_ge h, segment_symm],
exact segment_subset_Icc h }
end
lemma convex.min_le_combo (x y : E) {a b : π} (ha : 0 β€ a) (hb : 0 β€ b) (hab : a + b = 1) :
min x y β€ a β’ x + b β’ y :=
(segment_subset_interval x y β¨_, _, ha, hb, hab, rflβ©).1
lemma convex.combo_le_max (x y : E) {a b : π} (ha : 0 β€ a) (hb : 0 β€ b) (hab : a + b = 1) :
a β’ x + b β’ y β€ max x y :=
(segment_subset_interval x y β¨_, _, ha, hb, hab, rflβ©).2
end linear_ordered_add_comm_monoid
end ordered_semiring
section linear_ordered_field
variables [linear_ordered_field π]
lemma Icc_subset_segment {x y : π} : Icc x y β [x -[π] y] :=
begin
rintro z β¨hxz, hyzβ©,
obtain rfl | h := (hxz.trans hyz).eq_or_lt,
{ rw segment_same,
exact hyz.antisymm hxz },
rw βsub_nonneg at hxz hyz,
rw βsub_pos at h,
refine β¨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, _, _β©,
{ rw [βadd_div, sub_add_sub_cancel, div_self h.ne'] },
{ rw [smul_eq_mul, smul_eq_mul, βmul_div_right_comm, βmul_div_right_comm, βadd_div,
div_eq_iff h.ne', add_comm, sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub] }
end
@[simp] lemma segment_eq_Icc {x y : π} (h : x β€ y) : [x -[π] y] = Icc x y :=
(segment_subset_Icc h).antisymm Icc_subset_segment
lemma Ioo_subset_open_segment {x y : π} : Ioo x y β open_segment π x y :=
Ξ» z hz, mem_open_segment_of_ne_left_right hz.1.ne hz.2.ne'
(Icc_subset_segment $ Ioo_subset_Icc_self hz)
@[simp] lemma open_segment_eq_Ioo {x y : π} (h : x < y) : open_segment π x y = Ioo x y :=
(open_segment_subset_Ioo h).antisymm Ioo_subset_open_segment
lemma segment_eq_Icc' (x y : π) : [x -[π] y] = Icc (min x y) (max x y) :=
begin
cases le_total x y,
{ rw [segment_eq_Icc h, max_eq_right h, min_eq_left h] },
{ rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h] }
end
lemma open_segment_eq_Ioo' {x y : π} (hxy : x β y) :
open_segment π x y = Ioo (min x y) (max x y) :=
begin
cases hxy.lt_or_lt,
{ rw [open_segment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le] },
{ rw [open_segment_symm, open_segment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le] }
end
lemma segment_eq_interval (x y : π) : [x -[π] y] = interval x y :=
segment_eq_Icc' _ _
/-- A point is in an `Icc` iff it can be expressed as a convex combination of the endpoints. -/
lemma convex.mem_Icc {x y : π} (h : x β€ y) {z : π} :
z β Icc x y β β (a b : π), 0 β€ a β§ 0 β€ b β§ a + b = 1 β§ a * x + b * y = z :=
begin
rw βsegment_eq_Icc h,
simp_rw [βexists_prop],
refl,
end
/-- A point is in an `Ioo` iff it can be expressed as a strict convex combination of the endpoints.
-/
lemma convex.mem_Ioo {x y : π} (h : x < y) {z : π} :
z β Ioo x y β β (a b : π), 0 < a β§ 0 < b β§ a + b = 1 β§ a * x + b * y = z :=
begin
rw βopen_segment_eq_Ioo h,
simp_rw [βexists_prop],
refl,
end
/-- A point is in an `Ioc` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
lemma convex.mem_Ioc {x y : π} (h : x < y) {z : π} :
z β Ioc x y β β (a b : π), 0 β€ a β§ 0 < b β§ a + b = 1 β§ a * x + b * y = z :=
begin
split,
{ rintro hz,
obtain β¨a, b, ha, hb, hab, rflβ© := (convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz),
obtain rfl | hb' := hb.eq_or_lt,
{ rw add_zero at hab,
rw [hab, one_mul, zero_mul, add_zero] at hz,
exact (hz.1.ne rfl).elim },
{ exact β¨a, b, ha, hb', hab, rflβ© } },
{ rintro β¨a, b, ha, hb, hab, rflβ©,
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc] },
{ exact Ioo_subset_Ioc_self ((convex.mem_Ioo h).2 β¨a, b, ha', hb, hab, rflβ©) } }
end
/-- A point is in an `Ico` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
lemma convex.mem_Ico {x y : π} (h : x < y) {z : π} :
z β Ico x y β β (a b : π), 0 < a β§ 0 β€ b β§ a + b = 1 β§ a * x + b * y = z :=
begin
split,
{ rintro hz,
obtain β¨a, b, ha, hb, hab, rflβ© := (convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz),
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rw [hab, one_mul, zero_mul, zero_add] at hz,
exact (hz.2.ne rfl).elim },
{ exact β¨a, b, ha', hb, hab, rflβ© } },
{ rintro β¨a, b, ha, hb, hab, rflβ©,
obtain rfl | hb' := hb.eq_or_lt,
{ rw add_zero at hab,
rwa [hab, one_mul, zero_mul, add_zero, left_mem_Ico] },
{ exact Ioo_subset_Ico_self ((convex.mem_Ioo h).2 β¨a, b, ha, hb', hab, rflβ©) } }
end
end linear_ordered_field
/-! ### Convexity of sets -/
section ordered_semiring
variables [ordered_semiring π]
section add_comm_monoid
variables [add_comm_monoid E] [add_comm_monoid F]
section has_smul
variables (π) [has_smul π E] [has_smul π F] (s : set E)
/-- Convexity of sets. -/
def convex : Prop :=
β β¦x y : Eβ¦, x β s β y β s β β β¦a b : πβ¦, 0 β€ a β 0 β€ b β a + b = 1 β
a β’ x + b β’ y β s
variables {π s}
lemma convex_iff_segment_subset :
convex π s β β β¦x yβ¦, x β s β y β s β [x -[π] y] β s :=
forallβ_congr $ Ξ» x y hx hy, (segment_subset_iff _).symm
lemma convex.segment_subset (h : convex π s) {x y : E} (hx : x β s) (hy : y β s) :
[x -[π] y] β s :=
convex_iff_segment_subset.1 h hx hy
lemma convex.open_segment_subset (h : convex π s) {x y : E} (hx : x β s) (hy : y β s) :
open_segment π x y β s :=
(open_segment_subset_segment π x y).trans (h.segment_subset hx hy)
/-- Alternative definition of set convexity, in terms of pointwise set operations. -/
lemma convex_iff_pointwise_add_subset :
convex π s β β β¦a b : πβ¦, 0 β€ a β 0 β€ b β a + b = 1 β a β’ s + b β’ s β s :=
iff.intro
begin
rintro hA a b ha hb hab w β¨au, bv, β¨u, hu, rflβ©, β¨v, hv, rflβ©, rflβ©,
exact hA hu hv ha hb hab
end
(Ξ» h x y hx hy a b ha hb hab,
(h ha hb hab) (set.add_mem_add β¨_, hx, rflβ© β¨_, hy, rflβ©))
alias convex_iff_pointwise_add_subset β convex.set_combo_subset _
lemma convex_empty : convex π (β
: set E) :=
Ξ» x y, false.elim
lemma convex_univ : convex π (set.univ : set E) := Ξ» _ _ _ _ _ _ _ _ _, trivial
lemma convex.inter {t : set E} (hs : convex π s) (ht : convex π t) : convex π (s β© t) :=
Ξ» x y (hx : x β s β© t) (hy : y β s β© t) a b (ha : 0 β€ a) (hb : 0 β€ b) (hab : a + b = 1),
β¨hs hx.left hy.left ha hb hab, ht hx.right hy.right ha hb habβ©
lemma convex_sInter {S : set (set E)} (h : β s β S, convex π s) : convex π (ββ S) :=
assume x y hx hy a b ha hb hab s hs,
h s hs (hx s hs) (hy s hs) ha hb hab
lemma convex_Inter {ΞΉ : Sort*} {s : ΞΉ β set E} (h : β i, convex π (s i)) : convex π (β i, s i) :=
(sInter_range s) βΈ convex_sInter $ forall_range_iff.2 h
lemma convex_Interβ {ΞΉ : Sort*} {ΞΊ : ΞΉ β Sort*} {s : Ξ i, ΞΊ i β set E}
(h : β i j, convex π (s i j)) :
convex π (β i j, s i j) :=
convex_Inter $ Ξ» i, convex_Inter $ h i
lemma convex.prod {s : set E} {t : set F} (hs : convex π s) (ht : convex π t) :
convex π (s ΓΛ’ t) :=
begin
intros x y hx hy a b ha hb hab,
apply mem_prod.2,
exact β¨hs (mem_prod.1 hx).1 (mem_prod.1 hy).1 ha hb hab,
ht (mem_prod.1 hx).2 (mem_prod.1 hy).2 ha hb habβ©
end
lemma convex_pi {ΞΉ : Type*} {E : ΞΉ β Type*} [Ξ i, add_comm_monoid (E i)]
[Ξ i, has_smul π (E i)] {s : set ΞΉ} {t : Ξ i, set (E i)} (ht : β i, convex π (t i)) :
convex π (s.pi t) :=
Ξ» x y hx hy a b ha hb hab i hi, ht i (hx i hi) (hy i hi) ha hb hab
lemma directed.convex_Union {ΞΉ : Sort*} {s : ΞΉ β set E} (hdir : directed (β) s)
(hc : β β¦i : ΞΉβ¦, convex π (s i)) :
convex π (β i, s i) :=
begin
rintro x y hx hy a b ha hb hab,
rw mem_Union at β’ hx hy,
obtain β¨i, hxβ© := hx,
obtain β¨j, hyβ© := hy,
obtain β¨k, hik, hjkβ© := hdir i j,
exact β¨k, hc (hik hx) (hjk hy) ha hb habβ©,
end
lemma directed_on.convex_sUnion {c : set (set E)} (hdir : directed_on (β) c)
(hc : β β¦A : set Eβ¦, A β c β convex π A) :
convex π (ββc) :=
begin
rw sUnion_eq_Union,
exact (directed_on_iff_directed.1 hdir).convex_Union (Ξ» A, hc A.2),
end
end has_smul
section module
variables [module π E] [module π F] {s : set E}
lemma convex_iff_open_segment_subset :
convex π s β β β¦x yβ¦, x β s β y β s β open_segment π x y β s :=
convex_iff_segment_subset.trans $ forallβ_congr $ Ξ» x y hx hy,
(open_segment_subset_iff_segment_subset hx hy).symm
lemma convex_iff_forall_pos :
convex π s β β β¦x yβ¦, x β s β y β s β β β¦a b : πβ¦, 0 < a β 0 < b β a + b = 1
β a β’ x + b β’ y β s :=
convex_iff_open_segment_subset.trans $ forallβ_congr $ Ξ» x y hx hy,
open_segment_subset_iff π
lemma convex_iff_pairwise_pos :
convex π s β s.pairwise (Ξ» x y, β β¦a b : πβ¦, 0 < a β 0 < b β a + b = 1 β a β’ x + b β’ y β s) :=
begin
refine convex_iff_forall_pos.trans β¨Ξ» h x hx y hy _, h hx hy, _β©,
intros h x y hx hy a b ha hb hab,
obtain rfl | hxy := eq_or_ne x y,
{ rwa convex.combo_self hab },
{ exact h hx hy hxy ha hb hab },
end
protected lemma set.subsingleton.convex {s : set E} (h : s.subsingleton) : convex π s :=
convex_iff_pairwise_pos.mpr (h.pairwise _)
lemma convex_singleton (c : E) : convex π ({c} : set E) :=
subsingleton_singleton.convex
lemma convex_segment (x y : E) : convex π [x -[π] y] :=
begin
rintro p q β¨ap, bp, hap, hbp, habp, rflβ© β¨aq, bq, haq, hbq, habq, rflβ© a b ha hb hab,
refine β¨a * ap + b * aq, a * bp + b * bq,
add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq),
add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), _, _β©,
{ rw [add_add_add_comm, βmul_add, βmul_add, habp, habq, mul_one, mul_one, hab] },
{ simp_rw [add_smul, mul_smul, smul_add],
exact add_add_add_comm _ _ _ _ }
end
lemma convex_open_segment (a b : E) : convex π (open_segment π a b) :=
begin
rw convex_iff_open_segment_subset,
rintro p q β¨ap, bp, hap, hbp, habp, rflβ© β¨aq, bq, haq, hbq, habq, rflβ© z β¨a, b, ha, hb, hab, rflβ©,
refine β¨a * ap + b * aq, a * bp + b * bq,
add_pos (mul_pos ha hap) (mul_pos hb haq),
add_pos (mul_pos ha hbp) (mul_pos hb hbq), _, _β©,
{ rw [add_add_add_comm, βmul_add, βmul_add, habp, habq, mul_one, mul_one, hab] },
{ simp_rw [add_smul, mul_smul, smul_add],
exact add_add_add_comm _ _ _ _ }
end
lemma convex.linear_image (hs : convex π s) (f : E ββ[π] F) : convex π (f '' s) :=
begin
intros x y hx hy a b ha hb hab,
obtain β¨x', hx', rflβ© := mem_image_iff_bex.1 hx,
obtain β¨y', hy', rflβ© := mem_image_iff_bex.1 hy,
exact β¨a β’ x' + b β’ y', hs hx' hy' ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]β©,
end
lemma convex.is_linear_image (hs : convex π s) {f : E β F} (hf : is_linear_map π f) :
convex π (f '' s) :=
hs.linear_image $ hf.mk' f
lemma convex.linear_preimage {s : set F} (hs : convex π s) (f : E ββ[π] F) :
convex π (f β»ΒΉ' s) :=
begin
intros x y hx hy a b ha hb hab,
rw [mem_preimage, f.map_add, f.map_smul, f.map_smul],
exact hs hx hy ha hb hab,
end
lemma convex.is_linear_preimage {s : set F} (hs : convex π s) {f : E β F} (hf : is_linear_map π f) :
convex π (f β»ΒΉ' s) :=
hs.linear_preimage $ hf.mk' f
lemma convex.add {t : set E} (hs : convex π s) (ht : convex π t) : convex π (s + t) :=
by { rw β add_image_prod, exact (hs.prod ht).is_linear_image is_linear_map.is_linear_map_add }
lemma convex.vadd (hs : convex π s) (z : E) : convex π (z +α΅₯ s) :=
by { simp_rw [βimage_vadd, vadd_eq_add, βsingleton_add], exact (convex_singleton _).add hs }
lemma convex.translate (hs : convex π s) (z : E) : convex π ((Ξ» x, z + x) '' s) := hs.vadd _
/-- The translation of a convex set is also convex. -/
lemma convex.translate_preimage_right (hs : convex π s) (z : E) : convex π ((Ξ» x, z + x) β»ΒΉ' s) :=
begin
intros x y hx hy a b ha hb hab,
have h := hs hx hy ha hb hab,
rwa [smul_add, smul_add, add_add_add_comm, βadd_smul, hab, one_smul] at h,
end
/-- The translation of a convex set is also convex. -/
lemma convex.translate_preimage_left (hs : convex π s) (z : E) : convex π ((Ξ» x, x + z) β»ΒΉ' s) :=
by simpa only [add_comm] using hs.translate_preimage_right z
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid Ξ²] [module π Ξ²] [ordered_smul π Ξ²]
lemma convex_Iic (r : Ξ²) : convex π (Iic r) :=
Ξ» x y hx hy a b ha hb hab,
calc
a β’ x + b β’ y
β€ a β’ r + b β’ r
: add_le_add (smul_le_smul_of_nonneg hx ha) (smul_le_smul_of_nonneg hy hb)
... = r : convex.combo_self hab _
lemma convex_Ici (r : Ξ²) : convex π (Ici r) := @convex_Iic π Ξ²α΅α΅ _ _ _ _ r
lemma convex_Icc (r s : Ξ²) : convex π (Icc r s) :=
Ici_inter_Iic.subst ((convex_Ici r).inter $ convex_Iic s)
lemma convex_halfspace_le {f : E β Ξ²} (h : is_linear_map π f) (r : Ξ²) :
convex π {w | f w β€ r} :=
(convex_Iic r).is_linear_preimage h
lemma convex_halfspace_ge {f : E β Ξ²} (h : is_linear_map π f) (r : Ξ²) :
convex π {w | r β€ f w} :=
(convex_Ici r).is_linear_preimage h
lemma convex_hyperplane {f : E β Ξ²} (h : is_linear_map π f) (r : Ξ²) :
convex π {w | f w = r} :=
begin
simp_rw le_antisymm_iff,
exact (convex_halfspace_le h r).inter (convex_halfspace_ge h r),
end
end ordered_add_comm_monoid
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid Ξ²] [module π Ξ²] [ordered_smul π Ξ²]
lemma convex_Iio (r : Ξ²) : convex π (Iio r) :=
begin
intros x y hx hy a b ha hb hab,
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rwa [zero_smul, zero_add, hab, one_smul] },
rw mem_Iio at hx hy,
calc
a β’ x + b β’ y
< a β’ r + b β’ r
: add_lt_add_of_lt_of_le (smul_lt_smul_of_pos hx ha') (smul_le_smul_of_nonneg hy.le hb)
... = r : convex.combo_self hab _
end
lemma convex_Ioi (r : Ξ²) : convex π (Ioi r) := @convex_Iio π Ξ²α΅α΅ _ _ _ _ r
lemma convex_Ioo (r s : Ξ²) : convex π (Ioo r s) :=
Ioi_inter_Iio.subst ((convex_Ioi r).inter $ convex_Iio s)
lemma convex_Ico (r s : Ξ²) : convex π (Ico r s) :=
Ici_inter_Iio.subst ((convex_Ici r).inter $ convex_Iio s)
lemma convex_Ioc (r s : Ξ²) : convex π (Ioc r s) :=
Ioi_inter_Iic.subst ((convex_Ioi r).inter $ convex_Iic s)
lemma convex_halfspace_lt {f : E β Ξ²} (h : is_linear_map π f) (r : Ξ²) :
convex π {w | f w < r} :=
(convex_Iio r).is_linear_preimage h
lemma convex_halfspace_gt {f : E β Ξ²} (h : is_linear_map π f) (r : Ξ²) :
convex π {w | r < f w} :=
(convex_Ioi r).is_linear_preimage h
end ordered_cancel_add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid Ξ²] [module π Ξ²] [ordered_smul π Ξ²]
lemma convex_interval (r s : Ξ²) : convex π (interval r s) :=
convex_Icc _ _
end linear_ordered_add_comm_monoid
end module
end add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid E] [ordered_add_comm_monoid Ξ²] [module π E]
[ordered_smul π E] {s : set E} {f : E β Ξ²}
lemma monotone_on.convex_le (hf : monotone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | f x β€ r} :=
Ξ» x y hx hy a b ha hb hab, β¨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (convex.combo_le_max x y ha hb hab)).trans
(max_rec' _ hx.2 hy.2)β©
lemma monotone_on.convex_lt (hf : monotone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | f x < r} :=
Ξ» x y hx hy a b ha hb hab, β¨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (convex.combo_le_max x y ha hb hab)).trans_lt
(max_rec' _ hx.2 hy.2)β©
lemma monotone_on.convex_ge (hf : monotone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | r β€ f x} :=
@monotone_on.convex_le π Eα΅α΅ Ξ²α΅α΅ _ _ _ _ _ _ _ hf.dual hs r
lemma monotone_on.convex_gt (hf : monotone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | r < f x} :=
@monotone_on.convex_lt π Eα΅α΅ Ξ²α΅α΅ _ _ _ _ _ _ _ hf.dual hs r
lemma antitone_on.convex_le (hf : antitone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | f x β€ r} :=
@monotone_on.convex_ge π E Ξ²α΅α΅ _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_lt (hf : antitone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | f x < r} :=
@monotone_on.convex_gt π E Ξ²α΅α΅ _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_ge (hf : antitone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | r β€ f x} :=
@monotone_on.convex_le π E Ξ²α΅α΅ _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_gt (hf : antitone_on f s) (hs : convex π s) (r : Ξ²) :
convex π {x β s | r < f x} :=
@monotone_on.convex_lt π E Ξ²α΅α΅ _ _ _ _ _ _ _ hf hs r
lemma monotone.convex_le (hf : monotone f) (r : Ξ²) :
convex π {x | f x β€ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma monotone.convex_lt (hf : monotone f) (r : Ξ²) :
convex π {x | f x β€ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma monotone.convex_ge (hf : monotone f ) (r : Ξ²) :
convex π {x | r β€ f x} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_ge convex_univ r)
lemma monotone.convex_gt (hf : monotone f) (r : Ξ²) :
convex π {x | f x β€ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma antitone.convex_le (hf : antitone f) (r : Ξ²) :
convex π {x | f x β€ r} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_le convex_univ r)
lemma antitone.convex_lt (hf : antitone f) (r : Ξ²) :
convex π {x | f x < r} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_lt convex_univ r)
lemma antitone.convex_ge (hf : antitone f) (r : Ξ²) :
convex π {x | r β€ f x} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_ge convex_univ r)
lemma antitone.convex_gt (hf : antitone f) (r : Ξ²) :
convex π {x | r < f x} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_gt convex_univ r)
end linear_ordered_add_comm_monoid
section add_comm_group
variables [add_comm_group E] [module π E] {s t : set E}
lemma convex.combo_eq_vadd {a b : π} {x y : E} (h : a + b = 1) :
a β’ x + b β’ y = b β’ (y - x) + x :=
calc
a β’ x + b β’ y = (b β’ y - b β’ x) + (a β’ x + b β’ x) : by abel
... = b β’ (y - x) + x : by rw [smul_sub, convex.combo_self h]
end add_comm_group
end ordered_semiring
section ordered_comm_semiring
variables [ordered_comm_semiring π]
section add_comm_monoid
variables [add_comm_monoid E] [add_comm_monoid F] [module π E] [module π F] {s : set E}
lemma convex.smul (hs : convex π s) (c : π) : convex π (c β’ s) :=
hs.linear_image (linear_map.lsmul _ _ c)
lemma convex.smul_preimage (hs : convex π s) (c : π) : convex π ((Ξ» z, c β’ z) β»ΒΉ' s) :=
hs.linear_preimage (linear_map.lsmul _ _ c)
lemma convex.affinity (hs : convex π s) (z : E) (c : π) : convex π ((Ξ» x, z + c β’ x) '' s) :=
by simpa only [βimage_smul, βimage_vadd, image_image] using (hs.smul c).vadd z
end add_comm_monoid
end ordered_comm_semiring
section ordered_ring
variables [ordered_ring π]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module π E] [module π F] {s t : set E}
lemma convex.add_smul_mem (hs : convex π s) {x y : E} (hx : x β s) (hy : x + y β s)
{t : π} (ht : t β Icc (0 : π) 1) : x + t β’ y β s :=
begin
have h : x + t β’ y = (1 - t) β’ x + t β’ (x + y),
{ rw [smul_add, βadd_assoc, βadd_smul, sub_add_cancel, one_smul] },
rw h,
exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _),
end
lemma convex.smul_mem_of_zero_mem (hs : convex π s) {x : E} (zero_mem : (0 : E) β s) (hx : x β s)
{t : π} (ht : t β Icc (0 : π) 1) : t β’ x β s :=
by simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht
lemma convex.add_smul_sub_mem (h : convex π s) {x y : E} (hx : x β s) (hy : y β s)
{t : π} (ht : t β Icc (0 : π) 1) : x + t β’ (y - x) β s :=
begin
apply h.segment_subset hx hy,
rw segment_eq_image',
exact mem_image_of_mem _ ht,
end
/-- Affine subspaces are convex. -/
lemma affine_subspace.convex (Q : affine_subspace π E) : convex π (Q : set E) :=
begin
intros x y hx hy a b ha hb hab,
rw [eq_sub_of_add_eq hab, β affine_map.line_map_apply_module],
exact affine_map.line_map_mem b hx hy,
end
/--
Applying an affine map to an affine combination of two points yields
an affine combination of the images.
-/
lemma convex.combo_affine_apply {a b : π} {x y : E} {f : E βα΅[π] F} (h : a + b = 1) :
f (a β’ x + b β’ y) = a β’ f x + b β’ f y :=
begin
simp only [convex.combo_eq_vadd h, β vsub_eq_sub],
exact f.apply_line_map _ _ _,
end
/-- The preimage of a convex set under an affine map is convex. -/
lemma convex.affine_preimage (f : E βα΅[π] F) {s : set F} (hs : convex π s) :
convex π (f β»ΒΉ' s) :=
begin
intros x y xs ys a b ha hb hab,
rw [mem_preimage, convex.combo_affine_apply hab],
exact hs xs ys ha hb hab,
end
/-- The image of a convex set under an affine map is convex. -/
lemma convex.affine_image (f : E βα΅[π] F) (hs : convex π s) : convex π (f '' s) :=
begin
rintro x y β¨x', β¨hx', hx'fβ©β© β¨y', β¨hy', hy'fβ©β© a b ha hb hab,
refine β¨a β’ x' + b β’ y', β¨hs hx' hy' ha hb hab, _β©β©,
rw [convex.combo_affine_apply hab, hx'f, hy'f]
end
lemma convex.neg (hs : convex π s) : convex π (-s) :=
hs.is_linear_preimage is_linear_map.is_linear_map_neg
lemma convex.sub (hs : convex π s) (ht : convex π t) : convex π (s - t) :=
by { rw sub_eq_add_neg, exact hs.add ht.neg }
end add_comm_group
end ordered_ring
section linear_ordered_field
variables [linear_ordered_field π]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module π E] [module π F] {s : set E}
/-- Alternative definition of set convexity, using division. -/
lemma convex_iff_div :
convex π s β β β¦x y : Eβ¦, x β s β y β s β β β¦a b : πβ¦,
0 β€ a β 0 β€ b β 0 < a + b β (a / (a + b)) β’ x + (b / (a + b)) β’ y β s :=
begin
simp only [convex_iff_segment_subset, subset_def, mem_segment_iff_div],
refine forallβ_congr (Ξ» x y hx hy, β¨Ξ» H a b ha hb hab, H _ β¨a, b, ha, hb, hab, rflβ©, _β©),
rintro H _ β¨a, b, ha, hb, hab, rflβ©,
exact H ha hb hab
end
lemma convex.mem_smul_of_zero_mem (h : convex π s) {x : E} (zero_mem : (0 : E) β s)
(hx : x β s) {t : π} (ht : 1 β€ t) :
x β t β’ s :=
begin
rw mem_smul_set_iff_inv_smul_memβ (zero_lt_one.trans_le ht).ne',
exact h.smul_mem_of_zero_mem zero_mem hx β¨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one htβ©,
end
lemma convex.add_smul (h_conv : convex π s) {p q : π} (hp : 0 β€ p) (hq : 0 β€ q) :
(p + q) β’ s = p β’ s + q β’ s :=
begin
obtain rfl | hs := s.eq_empty_or_nonempty,
{ simp_rw [smul_set_empty, add_empty] },
obtain rfl | hp' := hp.eq_or_lt,
{ rw [zero_add, zero_smul_set hs, zero_add] },
obtain rfl | hq' := hq.eq_or_lt,
{ rw [add_zero, zero_smul_set hs, add_zero] },
ext,
split,
{ rintro β¨v, hv, rflβ©,
exact β¨p β’ v, q β’ v, smul_mem_smul_set hv, smul_mem_smul_set hv, (add_smul _ _ _).symmβ© },
{ rintro β¨vβ, vβ, β¨vββ, hββ, rflβ©, β¨vββ, hββ, rflβ©, rflβ©,
have hpq := add_pos hp' hq',
exact mem_smul_set.2 β¨_, h_conv hββ hββ (div_pos hp' hpq).le (div_pos hq' hpq).le
(by rw [βdiv_self hpq.ne', add_div] : p / (p + q) + q / (p + q) = 1),
by simp only [β mul_smul, smul_add, mul_div_cancel' _ hpq.ne']β© }
end
end add_comm_group
end linear_ordered_field
/-!
#### Convex sets in an ordered space
Relates `convex` and `ord_connected`.
-/
section
lemma set.ord_connected.convex_of_chain [ordered_semiring π] [ordered_add_comm_monoid E]
[module π E] [ordered_smul π E] {s : set E} (hs : s.ord_connected) (h : is_chain (β€) s) :
convex π s :=
begin
refine convex_iff_segment_subset.mpr (Ξ» x y hx hy, _),
obtain hxy | hyx := h.total hx hy,
{ exact (segment_subset_Icc hxy).trans (hs.out hx hy) },
{ rw segment_symm,
exact (segment_subset_Icc hyx).trans (hs.out hy hx) }
end
lemma set.ord_connected.convex [ordered_semiring π] [linear_ordered_add_comm_monoid E] [module π E]
[ordered_smul π E] {s : set E} (hs : s.ord_connected) :
convex π s :=
hs.convex_of_chain $ is_chain_of_trichotomous s
lemma convex_iff_ord_connected [linear_ordered_field π] {s : set π} :
convex π s β s.ord_connected :=
begin
simp_rw [convex_iff_segment_subset, segment_eq_interval, ord_connected_iff_interval_subset],
exact forall_congr (Ξ» x, forall_swap)
end
alias convex_iff_ord_connected β convex.ord_connected _
end
/-! #### Convexity of submodules/subspaces -/
section submodule
open submodule
lemma submodule.convex [ordered_semiring π] [add_comm_monoid E] [module π E] (K : submodule π E) :
convex π (βK : set E) :=
by { repeat {intro}, refine add_mem (smul_mem _ _ _) (smul_mem _ _ _); assumption }
lemma subspace.convex [linear_ordered_field π] [add_comm_group E] [module π E] (K : subspace π E) :
convex π (βK : set E) :=
K.convex
end submodule
/-! ### Simplex -/
section simplex
variables (π) (ΞΉ : Type*) [ordered_semiring π] [fintype ΞΉ]
/-- The standard simplex in the space of functions `ΞΉ β π` is the set of vectors with non-negative
coordinates with total sum `1`. This is the free object in the category of convex spaces. -/
def std_simplex : set (ΞΉ β π) :=
{f | (β x, 0 β€ f x) β§ β x, f x = 1}
lemma std_simplex_eq_inter :
std_simplex π ΞΉ = (β x, {f | 0 β€ f x}) β© {f | β x, f x = 1} :=
by { ext f, simp only [std_simplex, set.mem_inter_eq, set.mem_Inter, set.mem_set_of_eq] }
lemma convex_std_simplex : convex π (std_simplex π ΞΉ) :=
begin
refine Ξ» f g hf hg a b ha hb hab, β¨Ξ» x, _, _β©,
{ apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1] },
{ erw [finset.sum_add_distrib, β finset.smul_sum, β finset.smul_sum, hf.2, hg.2,
smul_eq_mul, smul_eq_mul, mul_one, mul_one],
exact hab }
end
variable {ΞΉ}
lemma ite_eq_mem_std_simplex (i : ΞΉ) : (Ξ» j, ite (i = j) (1:π) 0) β std_simplex π ΞΉ :=
β¨Ξ» j, by simp only; split_ifs; norm_num, by rw [finset.sum_ite_eq, if_pos (finset.mem_univ _)]β©
end simplex
|
classdef StiffnessPlaneStressVoigtTensor < SymmetricFourthOrderPlaneStressVoigtTensor ...
& StiffnessDescriptor
end |
C ---------------------------------------------------------------------
C stupid fix for C binding...
C don't know why character varaibles NAME and OPTS are segmenting
C when called from C
C
INTEGER FUNCTION XILAENV( N1 )
INTEGER N1
XILAENV = ILAENV( 1, "DGETRI", "", N1, -1, -1, -1 )
END
C ---------------------------------------------------------------------
|
[STATEMENT]
lemma overdamped_door:
assumes "b\<^sup>2 + a * 4 > 0" and "a < 0" and "b \<le> 0"
shows "PRE (\<lambda>s. s$1 = 0)
HP (LOOP open_door; (x\<acute>=((*\<^sub>V) (A a b)) & G) INV (\<lambda>s. 0 \<le> s$1))
POST (\<lambda>s. 0 \<le> s $ 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. PRE(\<lambda>s. s $ 1 = 0) HP (LOOP (\<lambda>s. {s. 0 < s $ 1 \<and> s $ 2 = 0}) ; x\<acute>=\<lambda>t. (*\<^sub>V) (A a b) & G on \<lambda>s. {t. 0 \<le> t} UNIV @ 0 INV (\<lambda>s. 0 \<le> s $ 1) ) POST \<lambda>s. 0 \<le> s $ 1
[PROOF STEP]
apply(rule fbox_loopI, simp_all add: le_fun_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<forall>x. 0 \<le> x $ 1 \<longrightarrow> (|(\<lambda>s. {s. 0 < s $ 1 \<and> s $ 2 = 0})] |x\<acute>=\<lambda>t. (*\<^sub>V) (A a b) & G on \<lambda>s. Collect ((\<le>) 0) UNIV @ 0] (\<lambda>s. 0 \<le> s $ 1)) x
[PROOF STEP]
apply(subst local_flow.fbox_g_ode_subset[OF local_flow_mtx_hOsc[OF assms(1)]])
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<And>x. a \<noteq> 0
2. \<And>x s. s \<in> UNIV \<Longrightarrow> 0 \<in> Collect ((\<le>) 0) \<and> is_interval (Collect ((\<le>) 0)) \<and> Collect ((\<le>) 0) \<subseteq> UNIV
3. \<forall>x. 0 \<le> x $ 1 \<longrightarrow> (|(\<lambda>s. {s. 0 < s $ 1 \<and> s $ 2 = 0})] (\<lambda>s. s \<in> UNIV \<longrightarrow> (\<forall>t\<in>Collect ((\<le>) 0). (\<forall>\<tau>\<in>down (Collect ((\<le>) 0)) t. G (((1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)), exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))], [a * exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - a * exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)), (b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))]]) *\<^sub>V s)) \<longrightarrow> 0 \<le> ((1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)), exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))], [a * exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - a * exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)), (b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))]]) *\<^sub>V s $ 1))) x
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
0 < b\<^sup>2 + a * 4
a < 0
b \<le> 0
goal (3 subgoals):
1. \<And>x. a \<noteq> 0
2. \<And>x s. s \<in> UNIV \<Longrightarrow> 0 \<in> Collect ((\<le>) 0) \<and> is_interval (Collect ((\<le>) 0)) \<and> Collect ((\<le>) 0) \<subseteq> UNIV
3. \<forall>x. 0 \<le> x $ 1 \<longrightarrow> (|(\<lambda>s. {s. 0 < s $ 1 \<and> s $ 2 = 0})] (\<lambda>s. s \<in> UNIV \<longrightarrow> (\<forall>t\<in>Collect ((\<le>) 0). (\<forall>\<tau>\<in>down (Collect ((\<le>) 0)) t. G (((1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)), exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))], [a * exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - a * exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)), (b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (\<tau> * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))]]) *\<^sub>V s)) \<longrightarrow> 0 \<le> ((1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)), exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))], [a * exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - a * exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2)), (b + sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b + sqrt (b\<^sup>2 + 4 * a)) / 2)) - (b - sqrt (b\<^sup>2 + 4 * a)) / 2 * exp (t * ((b - sqrt (b\<^sup>2 + 4 * a)) / 2))]]) *\<^sub>V s $ 1))) x
[PROOF STEP]
apply(simp_all add: le_fun_def fbox_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>0 < b\<^sup>2 + a * 4; a < 0; b \<le> 0\<rbrakk> \<Longrightarrow> (\<exists>x. 0 \<le> x $ 1) \<longrightarrow> (\<forall>s'. 0 < s' $ 1 \<and> s' $ 2 = 0 \<longrightarrow> (\<forall>t\<ge>0. (\<forall>\<tau>. 0 \<le> \<tau> \<and> \<tau> \<le> t \<longrightarrow> G (((1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2, exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2)], [a * exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - a * exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2), (b + sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2]]) *\<^sub>V s')) \<longrightarrow> 0 \<le> ((1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2, exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2)], [a * exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - a * exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2), (b + sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2]]) *\<^sub>V s' $ 1))
[PROOF STEP]
unfolding sq_mtx_scaleR_eq UNIV_2 sq_mtx_vec_mult_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>0 < b\<^sup>2 + a * 4; a < 0; b \<le> 0\<rbrakk> \<Longrightarrow> (\<exists>x. 0 \<le> x $ 1) \<longrightarrow> (\<forall>s'. 0 < s' $ 1 \<and> s' $ 2 = 0 \<longrightarrow> (\<forall>t\<ge>0. (\<forall>\<tau>. 0 \<le> \<tau> \<and> \<tau> \<le> t \<longrightarrow> G (\<chi>i. \<Sum>j\<in>insert 1 (skip 2). to_mtx (\<chi>i j. (1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2, exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2)], [a * exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - a * exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2), (b + sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (\<tau> * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2]] $$ i $ j) $$ i $ j * s' $ j)) \<longrightarrow> 0 \<le> (\<chi>i. \<Sum>j\<in>insert 1 (skip 2). to_mtx (\<chi>i j. (1 / sqrt (b\<^sup>2 + a * 4)) *\<^sub>R mtx [[(b + sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2, exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2)], [a * exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) - a * exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2), (b + sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b + sqrt (b\<^sup>2 + 4 * a)) / 2) / 2 - (b - sqrt (b\<^sup>2 + 4 * a)) * exp (t * (b - sqrt (b\<^sup>2 + 4 * a)) / 2) / 2]] $$ i $ j) $$ i $ j * s' $ j) $ 1))
[PROOF STEP]
by (clarsimp simp: overdamped_door_arith) |
Require Coq.Lists.List.
Require Coq.Lists.SetoidList.
Theorem InA_In : forall (A : Type) (x : A) (xs : list A),
SetoidList.InA (@eq _) x xs -> List.In x xs.
Proof.
induction xs as [|y ys]. {
intros H_in.
inversion H_in.
} {
intros H_in.
inversion H_in.
subst; simpl in *; auto.
subst; simpl in *; auto.
}
Qed.
Lemma InMapPair : forall (A B : Type) (x : A) (y : B) es,
List.In (x, y) es ->
List.In x (List.map fst es) /\ List.In y (List.map snd es).
Proof.
induction es as [|f fs]. {
intros H_f0.
inversion H_f0.
} {
intros H_in0.
destruct H_in0 as [H_inL|H_inR]. {
constructor; (left; destruct f as [f0 f1]; rewrite H_inL; reflexivity).
} {
constructor; (right; destruct (IHfs H_inR) as [H0 H1]; auto).
}
}
Qed.
|
totalLen : List String -> Nat
totalLen xs = foldr (\el, acc => length el + acc) 0 xs
|
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-- | TODO
module SatOpt.Utility where
import Data.Packed.Matrix (buildMatrix, liftMatrix2)
import Data.Packed.Vector (dim, zipVectorWith)
import Numeric.LinearAlgebra.Data
import Numeric.LinearAlgebra.HMatrix
zipMatrixWith ::(Element a, Element b, Element c)
=> (a -> b -> c)
-> Matrix a
-> Matrix b
-> Matrix c
zipMatrixWith f = liftMatrix2 (zipVectorWith f)
sample2D :: (a -> a -> b) -> [a] -> [a] -> [[b]]
sample2D f xs ys = [[f x y | y <- ys] | x <- xs]
sample2DM :: (Element a, Element b, Indexable (Vector a) a)
=> (a -> a -> b)
-> Vector a
-> Vector a
-> Matrix b
sample2DM f vx vy = buildMatrix (dim vx) (dim vy) (\(i, j) -> f (vx ! i) (vy ! j))
square :: Num a => a -> a
square x = x * x
clamp :: Double -> Double
clamp x
| x > 1 = 1
| x < 0 = 0
| otherwise = x
norm :: Floating a => a -> a -> a
norm x y = sqrt $ square x + square y
|
Born in Spirit Lake , Iowa , Bedell was educated in Spirit Lake public schools . He graduated from Spirit Lake High School in 1939 , where he earned spending money with a business in the midst of the Great Depression . His business involved braiding dog hairs around fishhooks , the result of which could be sold as trout flies . He began tying the fly @-@ fishing lures in his bedroom , then he moved the business into his parents ' basement . In time , he got space above a grocery store to continue the business full @-@ time .
|
[STATEMENT]
lemma less_list_code [code]:
"xs < ([]::'a::{equal, order} list) \<longleftrightarrow> False"
"[] < (x::'a::{equal, order}) # xs \<longleftrightarrow> True"
"(x::'a::{equal, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (xs < []) = False &&& ([] < x # xs) = True &&& (x # xs < y # ys) = (x < y \<or> x = y \<and> xs < ys)
[PROOF STEP]
by simp_all |
(*
* Copyright 2014, NICTA
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(NICTA_BSD)
*)
theory int_promotion
imports "CParser.CTranslation"
begin
external_file "int_promotion.c"
install_C_file "int_promotion.c"
context int_promotion
begin
thm f_body_def
lemma "\<Gamma> \<turnstile> \<lbrace> True \<rbrace> \<acute>ret__int :== CALL f() \<lbrace> \<acute>ret__int = 1 \<rbrace>"
apply vcg
apply simp
done
end
end
|
mutable struct Table{A,B} # A!=B
f::Dict{A,B}
inv::Dict{B,A}
end
function Table{A,B}()where {A,B}
return Table{A,B}(Dict{A,B}(),Dict{B,A}())
end
function insert!(t::Table{A,B},a::A,b::B)where {A,B}
t.f[a]=b
t.inv[b]=a
end
function Base.haskey(t::Table{A,B},a::A)where {A,B}
return haskey(t.f,a)
end
function Base.haskey(t::Table{A,B},b::B)where {A,B}
return haskey(t.inv,b)
end
function Base.getindex(t::Table{A,B},a::A)where {A,B}
return t.f[a]
end
function Base.getindex(t::Table{A,B},b::B)where {A,B}
return t.inv[b]
end
|
SUBROUTINE RDMSGB(LUNIT,MESG,IRET)
C$$$ SUBPROGRAM DOCUMENTATION BLOCK
C
C SUBPROGRAM: RDMSGB
C PRGMMR: ATOR ORG: NP12 DATE: 2005-11-29
C
C ABSTRACT: THIS SUBROUTINE READS THE NEXT BUFR MESSAGE FROM LOGICAL
C UNIT LUNIT AS AN ARRAY OF BYTES, WHICH ARE THEN TRANSFERRED TO
C AN ARRAY OF INTEGER WORDS FOR OUTPUT.
C
C PROGRAM HISTORY LOG:
C 2005-11-29 J. ATOR -- ORIGINAL AUTHOR
C DART $Id$
C
C USAGE: CALL RDMSGB (LUNIT, MESG, IRET)
C INPUT ARGUMENT LIST:
C LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
C
C OUTPUT ARGUMENT LIST:
C MESG - *-WORD ARRAY CONTAINING BUFR MESSAGE READ FROM LUNIT
C IRET - INTEGER: RETURN CODE:
C 0 = normal return
C -1 = end-of-file encountered while reading
C from LUNIT
C -2 = I/O error encountered while reading
C from LUNIT
C
C INPUT FILES:
C UNIT "LUNIT" - BUFR FILE
C
C REMARKS:
C THIS ROUTINE CALLS: ICHKSTR IUPBS01 LMSG
C THIS ROUTINE IS CALLED BY: READMG
C Normally not called by any application
C programs.
C
C ATTRIBUTES:
C LANGUAGE: FORTRAN 77
C MACHINE: PORTABLE TO ALL PLATFORMS
C
C$$$
INCLUDE 'bufrlib.prm'
DIMENSION MESG(*)
CHARACTER*8 SEC0
CHARACTER*1 CBAY(8*MXMSGLD4)
DIMENSION JBAY(MXMSGLD4)
EQUIVALENCE (CBAY(1),JBAY(1),SEC0)
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
SEC0 = ' '
READ(LUNIT,END=100,ERR=200)
. SEC0,(CBAY(I),I=9,IUPBS01(JBAY,'LENM'))
C Confirm that the first 4 bytes of CBAY contain 'BUFR' encoded in
C CCITT IA5 (i.e. ASCII). Note that, since CBAY(1) is equivalenced
C to SEC0, then CBAY already contains the entire BUFR message!
IF(ICHKSTR('BUFR',CBAY,4).NE.0) GOTO 200
C Transfer the message from CBAY into MESG.
DO I=1,LMSG(SEC0)
MESG(I) = JBAY(I)
ENDDO
IRET = 0
RETURN
100 IRET = -1
RETURN
200 IRET = -2
RETURN
END
|
module Fuml.Base.LinearRegression where
import Numeric.LinearAlgebra
-- | Ordinary least squares
ols :: [(Vector Double, Double)] -> Vector Double
ols xys =
let x = fromRows $ map fst xys
y = col $ map snd xys
betaMat = inv (tr' x <> x) <> tr' x <> y
in tr' betaMat ! 0
-- | Weighted ordinary least squares
wols :: Vector Double -> [(Vector Double, Double)] -> Vector Double
wols wvs xys =
let w = diag wvs
x = fromRows $ map fst xys
y = col $ map snd xys
betaMat = inv (tr' x <> w <> x) <> tr' x <> w <> y
in tr' betaMat ! 0
-- | Ridge regression
ridge :: Matrix Double -> [(Vector Double, Double)] -> Vector Double
ridge gamma xys =
let x = fromRows $ map fst xys
y = col $ map snd xys
betaMat = inv (tr' x <> x + tr' gamma <> gamma) <> tr' x <> y
in tr' betaMat ! 0
|
Require Import Omega.
Require Import Bool.
Require Import RelationClasses.
From sflib Require Import sflib.
From Paco Require Import paco.
From PromisingLib Require Import Axioms.
From PromisingLib Require Import Basic.
From PromisingLib Require Import DataStructure.
From PromisingLib Require Import DenseOrder.
From PromisingLib Require Import Language.
From PromisingLib Require Import Loc.
Require Import Event.
Require Import Time.
Require Import View.
Require Import Cell.
Require Import Memory.
Require Import TView.
Require Import Local.
Require Import Thread.
Require Import Pred.
Require Import Trace.
Require Import MemoryMerge.
Require Import PromiseConsistent.
Require Import PFConsistent.
Require Import ReorderCancel.
Require Import MemoryProps.
Require Import OrderedTimes.
Require Import Mapping.
Require Import CapFlex.
Require Import GoodFuture.
Require Import Cover.
Set Implicit Arguments.
Section CONCRETEMAX.
Lemma map_ident_concrete_promises mem prom tm (f: Loc.t -> Time.t -> Time.t -> Prop)
(MAX: concrete_promise_max_timemap mem prom tm)
(IDENT: forall loc ts (TS: Time.le ts (tm loc)), f loc ts ts)
(MAPLT: mapping_map_lt f)
(CLOSED: Memory.closed mem)
(MLE: Memory.le prom mem)
:
promises_map f prom prom.
Proof.
assert (CONCRETE: map_ident_concrete f mem).
{ ii. inv CONCRETE. eapply MAX in GET. auto. }
econs.
{ i. exists to, from, msg. splits; auto.
{ eapply mapping_map_lt_non_collapsable; eauto. }
{ eapply IDENT. eapply MAX in GET; eauto. }
{ eapply map_ident_concrete_closed_message; eauto.
eapply MLE in GET. eapply CLOSED; eauto. }
}
{ i. exists fto, ffrom, fmsg. splits; auto.
{ eapply IDENT. eapply MAX in GET; eauto. }
{ eapply IDENT. transitivity fto.
{ eapply memory_get_ts_le; eauto. }
{ eapply MAX in GET; eauto. }
}
}
Qed.
Lemma memory_ident_map_concrete_max f mem fmem
(MEM: memory_map f mem fmem)
(IDENT: forall loc to fto (MAP: f loc to fto), to = fto)
loc max fmax
(CLOSED: Memory.closed mem)
(MAX: Memory.max_concrete_ts mem loc max)
(FMAX: Memory.max_concrete_ts fmem loc fmax)
:
Time.le max fmax.
Proof.
eapply Memory.max_concrete_ts_spec in MAX; eauto.
{ des. eapply MEM in GET. des; ss. inv MSG. inv MSGLE.
eapply Memory.max_concrete_ts_spec in GET; eauto. des.
eapply IDENT in TO. subst. auto. }
{ eapply CLOSED. }
Qed.
Lemma memory_ident_map_concrete_promise_max_timemap
f mem_src mem_tgt prom_src prom_tgt tm_src tm_tgt
(MAXSRC: concrete_promise_max_timemap mem_src prom_src tm_src)
(MAXTGT: concrete_promise_max_timemap mem_tgt prom_tgt tm_tgt)
(LOCAL: promises_map f prom_tgt prom_src)
(MEM: memory_map f mem_tgt mem_src)
(IDENT: forall loc to fto (MAP: f loc to fto), to = fto)
:
TimeMap.le tm_tgt tm_src.
Proof.
ii. specialize (MAXTGT loc). inv MAXTGT. des.
{ eapply MEM in GET. des; ss.
eapply IDENT in TO. subst. inv MSG. inv MSGLE.
eapply MAXSRC in GET. auto. }
{ eapply LOCAL in GET. des; ss.
eapply IDENT in TO. subst.
eapply MAXSRC in GET. auto. }
Qed.
End CONCRETEMAX.
Definition pf_consistent_strong lang (e0:Thread.t lang): Prop :=
forall mem1 sc1
(CAP: Memory.cap (Thread.memory e0) mem1),
exists e1,
(<<STEPS0: rtc (tau (@pred_step ThreadEvent.is_cancel lang)) (Thread.mk _ (Thread.state e0) (Thread.local e0) sc1 mem1) e1>>) /\
(<<NORESERVE: no_reserves (Local.promises (Thread.local e1))>>) /\
exists e2,
(<<STEPS1: rtc (tau (@pred_step ((promise_free /1\ (fun e => ~ ThreadEvent.is_cancel e)) /1\ no_sc) lang)) e1 e2>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e2)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e2) st'>>)) \/
(<<PROMISES: (Local.promises (Thread.local e2)) = Memory.bot>>))).
Lemma pf_consistent_pf_consistent_strong lang (th: Thread.t lang)
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent th)
:
pf_consistent_strong th.
Proof.
assert (INHABITED: Memory.inhabited (Thread.memory th)).
{ inv MEM. auto. }
ii. exploit Memory.max_concrete_timemap_exists; eauto. intros MAX. des.
ii. exploit Memory.max_concrete_timemap_exists.
{ eapply le_inhabited; eauto. eapply Memory.cap_le; eauto. refl. }
i. des. exploit CONSISTENT; eauto. i.
assert (exists e2,
(<<STEPS: rtc (tau (Thread.step true))
(Thread.mk _ (Thread.state th) (Thread.local th)
tm0 mem1) e2 >>) /\
(<<NORESERVES: no_reserves (Local.promises (Thread.local e2))>>) /\
(__guard__ ((exists e3, (<< FAILURE: Thread.step true ThreadEvent.failure e2 e3 >>)) \/
(<<PROMISES: Local.promises (Thread.local e2) = Memory.bot >>)))).
{ des.
- exploit Thread.rtc_tau_step_future.
+ eapply rtc_implies; [|apply STEPS].
i. inv H. econs; eauto. econs; eauto.
+ ss. eapply Local.cap_wf; eauto.
+ ss. eapply Memory.max_concrete_timemap_closed; eauto.
+ ss. eapply Memory.cap_closed; eauto.
+ i. des.
destruct e2. destruct local. inv WF2. ss.
exploit reserves_cancelable; eauto. i. des.
esplits.
* etrans.
{ eapply STEPS. }
{ eapply rtc_implies; [|apply STEPS0].
i. inv H. inv TSTEP. inv STEP.
unfold ThreadEvent.is_cancel in SAT. des_ifs.
inv STEP0; inv STEP.
- econs; eauto. econs; eauto. econs; eauto.
- inv LOCAL. }
* ss.
* left. inv FAILURE; inv STEP. inv LOCAL. inv LOCAL0.
exists (Thread.mk _ st2 (Local.mk tview proms1) sc2 mem0).
ss. econs 2. econs; eauto. econs; eauto. econs; eauto.
eapply cancels_promises_decrease in STEPS0; auto. ss.
ii. eapply CONSISTENT0; eauto.
- unguard. esplits; eauto. rewrite PROMISES. ii.
rewrite Memory.bot_get in GET. clarify. }
clear x. des.
eapply pf_step_promise_free_step_rtc in STEPS.
eapply steps_cancels_not_cancels in STEPS; cycle 1. des.
exploit Thread.rtc_cancel_step_future.
{ eapply STEPS1. }
{ ss. eapply Local.cap_wf; eauto. }
{ ss. eapply Memory.max_concrete_timemap_closed; eauto. }
{ ss. eapply Memory.cap_closed; eauto. }
i. des. ss.
eapply rtc_implies with (R2 := tau (@pred_step ThreadEvent.is_cancel lang)) in STEPS1; cycle 1.
{ clear. i. inv H. econs.
{ econs; eauto.
{ econs; eauto. }
{ ss. }
}
{ ss. }
}
destruct th1. exploit no_sc_any_sc_rtc; try apply STEPS1; ss.
{ i. unfold ThreadEvent.is_cancel in PR. des_ifs. }
i. des. instantiate (1:=sc1) in STEP. clear STEPS1.
eexists. splits.
{ eapply STEP. }
{ ss. ii. clarify.
eapply steps_not_cancel_reserves_same in STEPS2; eauto.
unguard. des.
- eapply NORESERVES; eauto.
- rewrite PROMISES in *. erewrite Memory.bot_get in STEPS2. clarify. }
eapply hold_or_not with (Q := no_sc) in STEPS2. des.
- destruct e2. ss.
exploit no_sc_any_sc_rtc; try eapply HOLD; eauto.
{ ss. i. des. auto. } i. des.
esplits.
+ eapply pred_step_rtc_mon; try eapply STEP0. i. ss.
+ ss. unguard. des.
* left. ss. inv FAILURE; inv STEP1. inv LOCAL. eauto.
* right. esplits; eauto.
- exploit Thread.rtc_tau_step_future.
{ eapply thread_steps_pred_steps. eapply STEPS0. }
{ ss. }
{ ss. }
{ ss. } i. des.
inv STEP0.
exploit Thread.step_future; eauto. i. des.
assert (PROMS: Local.promise_consistent (Thread.local e3)).
{ eapply rtc_tau_step_promise_consistent.
- eapply thread_steps_pred_steps. eapply STEPS1.
- unguard. des.
+ inv FAILURE; inv STEP0. inv LOCAL. inv LOCAL0. ss.
+ ii. rewrite PROMISES in PROMISE.
rewrite Memory.bot_get in PROMISE. clarify.
- eauto.
- eauto.
- eauto. }
assert (NOPROMISE: (Local.promises (Thread.local e2')) = Memory.bot).
{ apply Memory.ext. i. rewrite Memory.bot_get.
destruct (Memory.get loc ts (Local.promises (Thread.local e2')))
as [[from [val released|]]|] eqn:GET; auto; cycle 1.
- exfalso.
eapply step_not_cancel_reserves_same in GET; cycle 1.
+ econs.
* econs; eauto.
* instantiate (1:=promise_free /1\ (fun e => ~ ThreadEvent.is_cancel e)). ss.
+ ss.
+ des. eapply steps_not_cancel_reserves_same in GET; eauto.
des. eapply NORESERVES; eauto.
- exfalso.
exploit pf_step_rtc_promises_decrease.
{ eapply STEPS0. }
{ i. ss. des. auto. }
{ econs; eauto. } ss. i.
exploit pf_step_rtc_promises_decrease.
{ eapply STEP. }
{ i. unfold ThreadEvent.is_cancel in *. des_ifs. }
{ ss. eauto. }
ss. i. inv x2.
ss. unfold no_sc in BREAKQ. des_ifs; try by (exfalso; eauto).
+ des; clarify. apply NNPP in BREAKQ.
inv STEP1; inv STEP0. ss. inv LOCAL. inv LOCAL0. ss.
eapply PROMS in GET. ss. des_ifs. ss.
hexploit max_concrete_timemap_get; eauto.
* inv WF. eapply Memory.cap_le; eauto.
* i. eapply Time.lt_strorder. eapply TimeFacts.lt_le_lt; eauto.
+ inv STEP1; inv STEP0. ss. inv LOCAL. inv LOCAL0. ss.
eapply PROMS in GET. ss. des_ifs. ss.
hexploit max_concrete_timemap_get; eauto.
* inv WF. eapply Memory.cap_le; eauto.
* i. eapply Time.lt_strorder. eapply TimeFacts.lt_le_lt; eauto.
}
destruct e2'. destruct local. ss.
eapply no_sc_any_sc_rtc in STEPS0; ss; cycle 1.
{ i. des; ss. } des.
esplits.
* eapply pred_step_rtc_mon; eauto. i. ss.
* unguard. ss. eauto.
Qed.
Definition cancel_normal_trace (tr: Trace.t): Prop :=
exists tr_cancel tr_normal,
(<<EQ: tr = tr_cancel ++ tr_normal>>) /\
(<<CANCEL: List.Forall (fun em => <<SAT: ThreadEvent.is_cancel (snd em)>>) tr_cancel>>) /\
(<<NORMAL: List.Forall (fun em => <<SAT: (fun e => ~ ThreadEvent.is_cancel e) (snd em)>>) tr_normal>>).
Definition pf_consistent_strong_aux lang (e0:Thread.t lang): Prop :=
forall mem1
(CAP: Memory.cap (Thread.memory e0) mem1),
exists tr e1 times,
(<<STEPS: Trace.steps tr (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot mem1) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free /1\ no_sc /1\ (wf_time_evt (fun loc to => List.In to (times loc)))) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) tr >>) /\
(<<CANCEL: cancel_normal_trace tr>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
((<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>)))).
Lemma pf_consistent_strong_pf_consistent_strong_aux lang (th: Thread.t lang)
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_strong th)
:
pf_consistent_strong_aux th.
Proof.
ii. exploit CONSISTENT; eauto. i. des.
eapply pred_steps_trace_steps in STEPS0. des.
eapply pred_steps_trace_steps in STEPS1. des.
hexploit (trace_times_list_exists (tr ++ tr0)); eauto. i. des.
eexists (tr ++ tr0), e2, times. esplits; eauto.
{ eapply Trace.steps_trans; eauto. }
{ eapply list_Forall_sum.
{ eapply WFTIME. }
{ instantiate (1:=(fun em => <<SAT: (promise_free /1\ no_sc) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>)).
eapply Forall_app.
{ eapply List.Forall_impl; eauto. i. ss. destruct a. ss. des.
destruct t0; ss. des_ifs. }
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto. }
}
{ i. ss. des. splits; auto. }
}
{ unfold cancel_normal_trace. esplits; eauto.
{ eapply List.Forall_impl; eauto. i. ss. des; auto. }
{ eapply List.Forall_impl; eauto. i. ss. des; auto. }
}
Qed.
Definition certification_times (times : Loc.t -> list Time.t)
(f: Loc.t -> nat -> (Time.t -> Time.t -> Prop))
(max: TimeMap.t)
(maxmap: TimeMap.t)
(loc: Loc.t) (fts: Time.t): Prop :=
((<<IN: List.In fts (times loc)>>) /\ (<<TS: Time.le fts (max loc)>>)) \/
(exists ts n,
(<<IN: List.In ts (times loc)>>) /\ (<<TS: Time.lt (max loc) ts>>)
/\ (<<MAX: Time.lt (maxmap loc) (incr_time_seq n)>>)
/\ (<<MAP: f loc n ts fts>>)).
Lemma certification_times_well_ordered times f max maxmap tm
(MAP: forall loc n
(TS: Time.lt (maxmap loc) (incr_time_seq n)),
cap_flex_map_loc
(max loc)
(tm loc)
(incr_time_seq n) (times loc) (f loc n))
(TM: forall loc, Time.lt (maxmap loc) (tm loc))
(MAXMAP: TimeMap.le max maxmap)
:
forall loc, well_ordered (certification_times times f max maxmap loc).
Proof.
i. hexploit (@increasing_join_well_ordered
incr_time_seq
(fun n fts =>
(exists ts,
(<<IN: List.In ts (times loc)>>)
/\ (<<TS: Time.lt (max loc) ts>>)
/\ (<<MAX: Time.lt (maxmap loc) (incr_time_seq n)>>)
/\ (<<MAP: f loc n ts fts>>)))).
{ i. eapply incr_time_seq_lt; eauto. }
{ eapply incr_time_seq_diverge. }
{ i. des. exploit MAP; eauto. intros FLEXMAP.
eapply ((cap_flex_map_loc_bound FLEXMAP)); try apply MAP0. auto. }
{ i. destruct (classic (Time.lt (maxmap loc) (incr_time_seq n))).
{ specialize (MAP _ _ H). eapply mapped_well_ordered.
{ eapply MAP. }
{ eapply (finite_well_ordered (times loc)). }
i. des. esplits; eauto.
}
{ eapply sub_well_ordered.
{ eapply empty_well_ordered. }
i. des; ss.
}
}
intros WO.
eapply sub_well_ordered.
{ eapply join_well_ordered.
{ eapply WO. }
{ eapply (finite_well_ordered (times loc)). }
}
{ i. unfold certification_times in *. des; eauto. left. esplits; eauto. }
Qed.
Definition pf_consistent_flex lang (e0:Thread.t lang)
(tr : Trace.t) (times : Loc.t -> list Time.t)
(f: Loc.t -> nat -> (Time.t -> Time.t -> Prop))
: Prop :=
forall max
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
(<<MAP: forall loc n
(TS: Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq n)),
cap_flex_map_loc
(max loc)
(Time.incr (Memory.max_ts loc (Thread.memory e0)))
(incr_time_seq n) (times loc) (f loc n)>>) /\
(<<CONSISTENT: forall mem1 (tm: Loc.t -> nat)
(TM: forall loc, Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq (tm loc)))
(CAP: cap_flex (Thread.memory e0) mem1 (fun loc => incr_time_seq (tm loc))),
exists ftr e1,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot mem1) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ wf_time_evt (fun loc => certification_times times f max (Memory.max_timemap (Thread.memory e0)) loc)) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map (fun loc => f loc (tm loc)) (snd fem) (snd em)) tr ftr>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
(<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>)))>>).
Lemma pf_consistent_strong_aux_pf_consistent_flex lang (th: Thread.t lang)
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_strong_aux th)
:
exists tr times f, <<CONSISTENT: pf_consistent_flex th tr times f>> /\ <<CANCELNORMAL: cancel_normal_trace tr>>.
Proof.
exploit Memory.cap_exists; eauto. i. des.
exploit CONSISTENT; eauto. i. des. exists tr, times.
hexploit (@concrete_promise_max_timemap_exists
((Thread.memory th))
((Local.promises (Thread.local th)))).
{ eapply MEM. } intros [max MAX]. des.
hexploit (@choice
(Loc.t * nat)
(Time.t -> Time.t -> Prop)
(fun locn f =>
let (loc, n) := locn in
forall
(TS: Time.lt (Memory.max_ts loc (Thread.memory th)) (incr_time_seq n)),
cap_flex_map_loc
(max loc)
(Time.incr (Memory.max_ts loc (Thread.memory th)))
(incr_time_seq n) (times loc) f)).
{ intros [loc n].
destruct (classic (Time.lt (Memory.max_ts loc (Thread.memory th)) (incr_time_seq n))).
{ des. hexploit (@cap_flex_map_loc_exists
(max loc)
(Time.incr (Memory.max_ts loc (Thread.memory th)))
(incr_time_seq n)).
{ eapply TimeFacts.le_lt_lt.
{ eapply concrete_promise_max_ts_max_ts; eauto. eapply WF. }
{ eapply Time.incr_spec. }
}
{ eapply TimeFacts.le_lt_lt.
{ eapply concrete_promise_max_ts_max_ts; eauto. eapply WF. }
{ auto. }
}
i. des. eauto. }
{ exists bot2. i. exfalso. eapply H. auto. }
}
intros [f SPEC]. des. exists (fun loc ts => f (loc, ts)). splits; auto. ii.
assert (max0 = max).
{ eapply concrete_promise_max_timemap_inj; eauto. } subst. econs.
{ ii. specialize (SPEC (loc, n)). ss. eauto. }
ii. assert (MAP: cap_flex_map
max
(fun loc => Time.incr (Memory.max_ts loc (Thread.memory th)))
(fun loc => incr_time_seq (tm loc))
times (fun loc => f (loc, tm loc))).
{ eapply cap_flex_map_locwise. i.
eapply (SPEC (loc, tm loc)). eauto. }
assert (IDENT: map_ident_concrete (fun loc => f (loc, tm loc)) (Thread.memory th)).
{ ii. inv CONCRETE. eapply MAX in GET. eapply MAP; eauto. }
destruct e1. ss.
hexploit trace_steps_map.
{ eapply mapping_map_lt_map_le. eapply MAP. }
{ eapply MAP. }
{ eapply mapping_map_lt_map_eq. eapply MAP. }
{ eapply wf_time_mapped_mappable.
{ eapply List.Forall_impl; eauto. i. ss. des; eauto. }
{ eapply cap_flex_map_complete; eauto. }
}
{ eapply STEPS. }
{ ss. }
{ ss. }
{ ss. }
{ eapply Local.cap_wf; eauto. }
{ instantiate (1:=mem1). instantiate (1:=(Thread.local th)).
eapply cap_flex_wf; eauto. }
{ eapply cap_flex_closed; eauto. }
{ eapply Memory.cap_closed; eauto. }
{ eapply Memory.closed_timemap_bot.
eapply cap_flex_closed in CAP0; auto. eapply CAP0. }
{ eapply Memory.closed_timemap_bot.
eapply Memory.cap_closed in CAP; auto. eapply CAP. }
{ econs.
{ refl. }
{ eapply map_ident_concrete_closed_tview; eauto. eapply WF. }
{ eapply map_ident_concrete_promises; eauto.
{ i. eapply MAP; eauto. }
{ eapply MAP. }
{ eapply WF. }
}
}
{ exploit (@Memory.max_concrete_timemap_exists (Thread.memory th)).
{ eapply MEM. } i. des.
eapply concrete_messages_le_cap_flex_memory_map.
{ refl. }
{ eauto. }
{ ii. eapply concrete_promise_max_ts_max_concrete_ts; eauto. }
{ instantiate (1:=(fun loc => Time.incr (Memory.max_ts loc (Thread.memory th)))).
i. eapply Time.incr_spec. }
{ eapply TM. }
{ eapply cap_cap_flex; eauto. }
{ eauto. }
{ eauto. }
{ eauto. }
{ eauto. }
}
{ eapply mapping_map_lt_collapsable_unwritable. eapply MAP. }
{ eapply timemap_bot_map. eapply MAP. }
{ refl. } i. des.
exists ftr, (Thread.mk _ state flc1 fsc1 fmem1). splits; auto.
{ eapply List.Forall_forall. i.
cut ((promise_free /1\ no_sc) (snd x) /\ ThreadEvent.get_machine_event (snd x) = MachineEvent.silent).
{ i. des. splits; auto.
{ eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss. des.
eapply wf_time_evt_map in EVENT; eauto. eapply wf_time_evt_mon; try apply EVENT.
i. ss. des. destruct (Time.le_lt_dec ts (max x1)).
{ left. assert (ts = x2).
{ eapply mapping_map_lt_map_eq.
{ eapply MAP. }
{ ss. eapply MAP. eauto. }
{ eauto. }
}
subst. splits; auto.
}
{ right. esplits; eauto. }
}
}
eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss. des.
destruct x, a. ss. inv EVENT; ss. inv KIND; ss.
splits; auto. inv MSG0; ss. inv MSG; ss. inv MAP1; ss.
}
{ eapply list_Forall2_impl; eauto. i. ss. des. auto. }
{ ss. unguard. des; eauto.
{ left. esplits; eauto. eapply failure_step_map; eauto.
{ eapply mapping_map_lt_map_le. eapply MAP. }
{ eapply mapping_map_lt_map_eq. eapply MAP. }
}
{ right. splits.
{ inv LOCAL. erewrite PROMISES in *. eapply bot_promises_map; eauto. }
}
}
Qed.
Definition pf_consistent_super_strong_easy lang (e0:Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
: Prop :=
forall cap (tm: Loc.t -> nat) max
(CAPTM: forall loc, Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq (tm loc)))
(CAP: cap_flex (Thread.memory e0) cap (fun loc => incr_time_seq (tm loc)))
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
exists ftr e1 f,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot cap) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<CANCELNORMAL: cancel_normal_trace ftr>>) /\
(<<MAPLT: mapping_map_lt f>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max loc))
(MAP: f loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max loc) fts) (MAP: f loc ts fts),
Time.lt (max loc) ts /\ Time.le (incr_time_seq (tm loc)) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f (snd fem) (snd em)) tr ftr>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
(<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>))).
Lemma pf_consistent_super_strong_easy_same_sc lang (e0: Thread.t lang) tr times sc
(CONSISTENT: pf_consistent_super_strong_easy e0 tr times)
:
pf_consistent_super_strong_easy (Thread.mk _ (Thread.state e0) (Thread.local e0) sc (Thread.memory e0)) tr times.
Proof.
ii. exploit CONSISTENT; eauto.
Qed.
Definition pf_consistent_super_strong_easy_mon lang e0 tr certimes0 certimes1
(CONSISTENT: @pf_consistent_super_strong_easy
lang e0 tr certimes0)
(LE: certimes0 <2= certimes1)
:
pf_consistent_super_strong_easy e0 tr certimes1.
Proof.
ii. exploit CONSISTENT; eauto. i. des. esplits; eauto.
eapply List.Forall_impl; eauto. i. ss. des. splits; eauto.
eapply wf_time_evt_mon; eauto.
Qed.
Lemma memory_times_wf_exists (mem: Memory.t)
:
exists times_mem,
(<<MWF: memory_times_wf times_mem mem>>) /\
(<<MEMWO: forall loc, well_ordered (times_mem loc)>>).
Proof.
hexploit (choice
(fun loc times =>
(<<WF: forall to from msg
(GET: Memory.get loc to mem = Some (from, msg)),
times from /\ times to>>) /\ (<<WO: well_ordered times>>))).
{ intros loc. hexploit (Cell.finite (mem loc)). i. des.
set (f := (fun to => match (Memory.get loc to mem) with
| Some (from, _) => from
| _ => Time.bot
end)).
set (froms:=List.map f dom).
hexploit (finite_well_ordered (dom++froms)). intros WO. esplits; try apply WO.
i. ss. dup GET. eapply H in GET. split.
{ eapply List.in_map with (f:=f) in GET. unfold f in GET. erewrite GET0 in *.
eapply List.in_or_app; eauto. }
{ eapply List.in_or_app; eauto. }
}
i. des. exists f. splits.
{ ii. specialize (H loc). des. apply WF in GET. auto. }
{ apply H; eauto. }
Qed.
Lemma pf_consistent_flex_super_strong_easy
lang (th: Thread.t lang) tr times f
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_flex th tr times f)
(CANCELNORMAL: cancel_normal_trace tr)
:
exists certimes,
(<<WO: forall loc, well_ordered (certimes loc)>>) /\
(<<MWF: memory_times_wf certimes (Thread.memory th)>>) /\
(<<DIVERGE: forall loc n, certimes loc (incr_time_seq n)>>) /\
(<<CONSISTENT: pf_consistent_super_strong_easy th tr certimes>>).
Proof.
hexploit (@concrete_promise_max_timemap_exists
((Thread.memory th))
((Local.promises (Thread.local th)))).
{ eapply MEM. } intros [max MAX]. specialize (CONSISTENT _ MAX). des.
hexploit (memory_times_wf_exists (Thread.memory th)). i. des.
exists ((certification_times times f max (Memory.max_timemap (Thread.memory th))) \2/ times_mem \2/ (fun loc => incr_times)). splits.
{ i. eapply join_well_ordered.
{ eapply join_well_ordered; eauto.
eapply certification_times_well_ordered; eauto.
{ i. eapply MAP. auto. }
{ i. ss. eapply Time.incr_spec. }
{ ii. eapply concrete_promise_max_ts_max_ts; eauto. eapply WF. }
}
eapply incr_times_well_ordered.
}
{ ii. eapply MWF in GET. des; auto. }
{ i. right. unfold incr_times. eauto. }
ii. assert (max0 = max).
{ eapply concrete_promise_max_timemap_inj; eauto. } subst.
hexploit CONSISTENT0; eauto. i. des.
assert (MAPALL: cap_flex_map
max
(fun loc => Time.incr (Memory.max_ts loc (Thread.memory th)))
(fun loc => incr_time_seq (tm loc))
times (fun loc => f loc (tm loc))).
{ eapply cap_flex_map_locwise; eauto. }
eexists _, _, (fun loc => f loc (tm loc)). splits; eauto.
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto.
eapply wf_time_evt_mon; try apply SAT0; eauto. }
{ unfold cancel_normal_trace in *. des. subst.
eapply List.Forall2_app_inv_l in TRACE. des. esplits; eauto.
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
destruct a, x. ss. eapply List.Forall_forall in IN; eauto. ss. inv SAT; ss.
inv KIND; ss; des_ifs. inv MSG. }
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
destruct a, x. ss. eapply List.Forall_forall in IN; eauto. ss. inv SAT; ss.
inv KIND; ss; des_ifs. inv MSG. }
}
{ eapply MAPALL. }
{ i. eapply MAPALL in TS; eauto.
eapply mapping_map_lt_inj.
{ eapply MAPALL; eauto. }
{ ss. eauto. }
{ eauto. }
}
{ i. destruct (Time.le_lt_dec ts (max loc)).
{ dup l. eapply MAPALL in l; eauto.
exploit mapping_map_lt_map_eq.
{ eapply MAPALL. }
{ eapply MAP0. }
{ eapply l. }
i. subst. timetac.
}
{ split; auto. eapply (cap_flex_map_bound MAPALL) in l; eauto. }
}
{ eapply list_Forall2_impl; eauto. i. eapply tevent_map_tevent_map_weak; eauto. }
Qed.
Require Import PreReserve.
Definition pf_consistent_special lang (e0:Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
: Prop :=
forall cap (tm: Loc.t -> nat) max
(CAPTM: forall loc, Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq (tm loc)))
(CAP: cap_flex (Thread.memory e0) cap (fun loc => incr_time_seq (tm loc)))
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
exists ftr e1,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot cap) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<CANCELNORMAL: cancel_normal_trace ftr>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak (fun loc ts fts => ts = fts /\ Time.le ts (max loc)) (snd fem) (snd em)) tr ftr>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
(<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>))).
Lemma pf_consistent_speciali_strong_easy
lang (th: Thread.t lang) tr times
(CONSISTENT: pf_consistent_special th tr times)
:
pf_consistent_super_strong_easy th tr times.
Proof.
ii. exploit CONSISTENT; eauto. i. des. esplits; eauto.
{ ii. des. subst. auto. }
{ ii. ss. des. auto. }
{ ii. ss. des. subst. exfalso. timetac. }
Qed.
Lemma pf_consistent_speciali_events_map
lang (th: Thread.t lang) tr0 tr1 times
(CONSISTENT: pf_consistent_special th tr0 times)
(EVENTS: List.Forall2 (fun em fem => tevent_map_weak ident_map (snd fem) (snd em)) tr0 tr1)
:
pf_consistent_special th tr1 times.
Proof.
ii. exploit CONSISTENT; eauto. i. des. esplits; eauto.
eapply list_Forall2_compose.
{ eapply list_Forall2_rev; eauto. }
{ eauto. }
{ i. ss. eapply tevent_map_weak_rev with (f1:=ident_map) in SAT0; ss.
eapply tevent_map_weak_compose; eauto. i. ss. inv MAP0. des; auto. }
Qed.
Definition pf_consistent_super_strong_split lang (e0:Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
: Prop :=
forall cap (tm: Loc.t -> nat) max
(CAPTM: forall loc, Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq (tm loc)))
(CAP: cap_flex (Thread.memory e0) cap (fun loc => incr_time_seq (tm loc)))
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
exists ftr e1 f,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot cap) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<CANCELNORMAL: cancel_normal_trace ftr>>) /\
(<<SPLIT:
forall ftr0 ftr1 e_mid
(FTRACE: ftr = ftr0 ++ ftr1)
(NORMAL: List.Forall (fun em => ~ ThreadEvent.is_cancel (snd em)) ftr1)
(STEPS0: Trace.steps ftr0 (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot cap) e_mid)
(STEPS1: Trace.steps ftr1 e_mid e1)
,
exists ftr_reserve ftr_cancel e2,
(<<STEPS: Trace.steps ftr_reserve e_mid e2>>) /\
(<<RESERVE: List.Forall (fun em => <<SAT: (ThreadEvent.is_reserve /1\ wf_time_evt times) (snd em)>>) ftr_reserve>>) /\
(<<CANCEL: List.Forall (fun em => <<SAT: (ThreadEvent.is_cancel /1\ wf_time_evt times) (snd em)>>) ftr_cancel>>) /\
(<<CONSISTENT: pf_consistent_special e2 (ftr_cancel ++ ftr1) times>>) /\
(<<CANCELNORMAL: cancel_normal_trace (ftr_cancel ++ ftr1)>>)>>) /\
(<<MAPLT: mapping_map_lt f>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max loc))
(MAP: f loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max loc) fts) (MAP: f loc ts fts),
Time.lt (max loc) ts /\ Time.le (incr_time_seq (tm loc)) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f (snd fem) (snd em)) tr ftr>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
(<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>))).
Lemma cap_flex_memory_times_wf times mem cap tm
(MEMWF: memory_times_wf times mem)
(CAP: cap_flex mem cap tm)
(TM: forall loc, Time.lt (Memory.max_ts loc mem) (tm loc))
(IN: forall loc, times loc (tm loc))
(CLOSED: Memory.closed mem)
:
memory_times_wf times cap.
Proof.
ii. eapply cap_flex_inv in GET; eauto. des.
{ eapply MEMWF; eauto. }
{ inv GET0. eapply MEMWF in GET3. eapply MEMWF in GET4. des. auto. }
{ subst. split; auto. exploit Memory.max_ts_spec.
{ eapply CLOSED. }
i. des. eapply MEMWF in GET0. des. eauto.
}
Qed.
Lemma list_Forall_refl_Forall2 A (P: A -> A -> Prop) (l: list A)
(FORALL: List.Forall (fun a => P a a) l)
:
List.Forall2 P l l.
Proof.
ginduction l; eauto. i. inv FORALL. econs; eauto.
Qed.
Lemma ident_map_compose_tevent_weak f te0 te1 te2
(MAP0: tevent_map_weak f te1 te0)
(MAP1: tevent_map_weak ident_map te2 te1)
:
tevent_map_weak f te2 te0.
Proof.
inv MAP0; inv MAP1; econs.
{ inv FROM0. auto. }
{ inv TO0. auto. }
{ inv TO0. etrans; eauto. }
{ inv TO0. eauto. }
{ inv FROM0. eauto. }
{ inv TO0. eauto. }
{ inv FROM0. eauto. }
{ inv TO0. eauto. }
Qed.
Lemma ident_map_compose_tevent_weak2 f te0 te1 te2
(MAP0: tevent_map_weak ident_map te1 te0)
(MAP1: tevent_map_weak f te2 te1)
:
tevent_map_weak f te2 te0.
Proof.
inv MAP0; inv MAP1; econs.
{ inv FROM. auto. }
{ inv TO. auto. }
{ inv TO. eauto. etrans; eauto. }
{ inv TO. eauto. }
{ inv FROM. eauto. }
{ inv TO. eauto. }
{ inv FROM. eauto. }
{ inv TO. eauto. }
Qed.
Lemma ident_map_pf_consistent_super_strong_easy
lang (th0 th1: Thread.t lang) tr times
(CONSISTENT: pf_consistent_special th0 tr times)
(WF0: Local.wf (Thread.local th0) (Thread.memory th0))
(MEM0: Memory.closed (Thread.memory th0))
(WF1: Local.wf (Thread.local th1) (Thread.memory th1))
(MEM1: Memory.closed (Thread.memory th1))
(MAP: thread_map ident_map th0 th1)
:
pf_consistent_special th1 tr times.
Proof.
ii.
assert (exists (tm_src: Loc.t -> nat),
(<<CAPTMSRC: forall loc,
Time.lt (Memory.max_ts loc (Thread.memory th0)) (incr_time_seq (tm_src loc))>>) /\
(<<TMLE: forall loc, Time.le (incr_time_seq (tm loc)) (incr_time_seq (tm_src loc))>>)).
{ exploit (choice (fun loc n =>
(<<CAPTMSRC:
Time.lt (Memory.max_ts loc (Thread.memory th0)) (incr_time_seq n)>>) /\
(<<TMLE: Time.le (incr_time_seq (tm loc)) (incr_time_seq n)>>))).
{ i. hexploit (@incr_time_seq_diverge
(Time.join
(Memory.max_ts x (Thread.memory th0))
(incr_time_seq (tm x)))). i. des.
exists n. splits; auto.
{ eapply TimeFacts.le_lt_lt; eauto. eapply Time.join_l. }
{ left. eapply TimeFacts.le_lt_lt; eauto. eapply Time.join_r. }
}
i. des. exists f. splits.
{ i. specialize (x0 loc). des; auto. }
{ i. specialize (x0 loc). des; auto. }
}
des.
exploit (@concrete_promise_max_timemap_exists (Thread.memory th0) (Local.promises (Thread.local th0))).
{ eapply MEM0. }
i. des.
assert (MAXLE: TimeMap.le tm0 max).
{ inv MAP. ss. inv LOCAL. eapply memory_ident_map_concrete_promise_max_timemap; eauto. }
exploit (@cap_flex_exists (Thread.memory th0) (fun loc => incr_time_seq (tm_src loc))); eauto.
i. des.
exploit CONSISTENT; eauto. i. des. inv MAP. ss.
destruct e1. ss. hexploit trace_steps_map.
{ eapply ident_map_le; eauto. }
{ eapply ident_map_bot; eauto. }
{ eapply ident_map_eq; eauto. }
{ eapply List.Forall_forall. i. eapply ident_map_mappable_evt. }
{ eapply STEPS. }
{ ss. }
{ ss. }
{ ss. }
{ eapply cap_flex_wf; eauto. }
{ eapply cap_flex_wf; try apply CAP; eauto. }
{ eapply cap_flex_closed; eauto. }
{ eapply cap_flex_closed; eauto. }
{ eapply Memory.closed_timemap_bot; eauto.
eapply cap_flex_closed; eauto. }
{ eapply Memory.closed_timemap_bot; eauto.
eapply cap_flex_closed; eauto. }
all: eauto.
{ econs.
{ i. eapply cap_flex_inv in GET; try apply CAP0; eauto. des; auto.
eapply MEM in GET. des; auto. right. esplits; eauto.
eapply CAP in GET; eauto. }
{ i. left.
exists (incr_time_seq (tm_src loc)), Time.bot, (incr_time_seq (tm_src loc)), Time.bot.
splits; auto; ss.
{ eapply Time.bot_spec. }
{ eapply Memory.max_ts_spec in GET. des.
erewrite (@cap_flex_max_ts fmem cap) in MAX1; eauto. ss.
etrans; eauto. }
i. eapply cap_flex_covered; eauto.
}
}
{ eapply mapping_map_lt_collapsable_unwritable. eapply ident_map_lt. }
{ eapply ident_map_timemap. }
{ refl. }
i. des. esplits.
{ eauto. }
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss. des.
destruct a, x. ss. unfold ident_map in *.
inv EVENT; ss; des; subst; auto. splits; auto.
inv KIND; ss. inv MSG0; auto. inv MSG; auto. inv MAP0; ss. }
{ clear - CANCELNORMAL TRACE0. unfold cancel_normal_trace in *. des.
subst. eapply List.Forall2_app_inv_l in TRACE0. des. subst. esplits; eauto.
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss.
destruct a, x. ss. inv EVENT; ss. inv KIND; ss; des_ifs. inv MSG. }
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss.
destruct a, x. ss. inv EVENT; ss. inv KIND; ss; des_ifs. inv MSG. }
}
{ eapply list_Forall2_compose.
{ eapply TRACE. }
{ eapply TRACE0. }
i. ss. des. eapply tevent_map_tevent_map_weak in EVENT.
eapply tevent_map_weak_compose; eauto.
i. ss. des; subst. inv MAP1. split; auto. etrans; eauto.
}
{ i. unguard. des.
{ left. ss. esplits; eauto. eapply failure_step_map; eauto.
{ eapply ident_map_le. }
{ eapply ident_map_eq. }
}
{ right. ss. inv LOCAL0.
rewrite PROMISES in *. eapply bot_promises_map in PROMISES0; auto. }
}
Qed.
Lemma pf_consistent_flex_super_strong_easy_split
lang (th: Thread.t lang) tr times
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_super_strong_easy th tr times)
(CANCELNORMAL: cancel_normal_trace tr)
(MWF: memory_times_wf times (Thread.memory th))
(DIVERGE: forall loc n, times loc (incr_time_seq n))
:
pf_consistent_super_strong_split th tr times.
Proof.
ii. exploit CONSISTENT; eauto. i. des. esplits; eauto.
i. subst. exploit Trace.steps_future; try apply STEPS0; eauto; ss.
{ eapply cap_flex_wf; eauto. }
{ eapply Memory.closed_timemap_bot; eauto.
eapply cap_flex_closed; eauto. }
{ eapply cap_flex_closed; eauto. } i. des.
eapply Forall_app_inv in EVENTS. des.
destruct e_mid, e1. ss.
assert (sc = TimeMap.bot).
{ eapply no_sc_same_sc_traced in STEPS0; eauto.
eapply List.Forall_impl; eauto. i. ss. des; auto. } subst.
hexploit can_reserve_all_needed.
{ instantiate (1:=times). i. hexploit (incr_time_seq_diverge ts).
i. des. esplits; eauto. }
{ instantiate (1:=memory).
eapply memory_times_wf_traced in STEPS0; eauto.
{ ss. eapply cap_flex_memory_times_wf; eauto. ss. }
{ eapply List.Forall_impl; eauto. i. ss. des; auto. }
}
{ eapply STEPS1. }
{ eapply list_Forall_sum.
{ eapply FORALL2. }
{ eapply NORMAL. }
i. ss. des; auto.
}
{ eauto. }
{ eauto. }
{ eauto. }
i. des. exists tr_reserve, tr_cancel. esplits; eauto.
{ ii. exploit (CAP0 cap0).
{ eapply CAP1. } i. des.
eexists (tr_cancel ++ ftr1), _. esplits.
{ eapply Trace.steps_trans.
{ eapply CANCELSTEPS. }
{ eapply STEPS2. }
}
{ eapply Forall_app; eauto.
eapply List.Forall_impl; eauto. i. ss. des.
destruct a. ss. destruct t0; ss. des_ifs.
}
{ unfold cancel_normal_trace. esplits; eauto.
eapply List.Forall_impl; eauto. i. ss. des; auto.
}
{ eauto. }
{ ss. }
}
{ unfold cancel_normal_trace. esplits; eauto.
eapply List.Forall_impl; eauto. i. ss. des; auto. }
Qed.
Definition pf_consistent_super_strong_aux lang (e0:Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
: Prop :=
forall cap (tm: Loc.t -> nat) max
(CAPTM: forall loc, Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq (tm loc)))
(CAP: cap_flex (Thread.memory e0) cap (fun loc => incr_time_seq (tm loc)))
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
exists ftr e1 f,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot cap) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ no_read_msgs (fun loc ts => ~ (covered loc ts (Local.promises (Thread.local e0)) \/ concrete_promised (Thread.memory e0) loc ts \/ Time.lt (incr_time_seq (tm loc)) ts))
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (incr_time_seq (tm loc))>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<CANCELNORMAL: cancel_normal_trace ftr>>) /\
(<<SPLIT:
forall ftr0 ftr1 e_mid
(FTRACE: ftr = ftr0 ++ ftr1)
(STEPS0: Trace.steps ftr0 (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot cap) e_mid)
(STEPS1: Trace.steps ftr1 e_mid e1)
(NORMAL: List.Forall (fun em => ~ ThreadEvent.is_cancel (snd em)) ftr1),
exists ftr_reserve ftr_cancel e2,
(<<STEPS: Trace.steps ftr_reserve e_mid e2>>) /\
(<<RESERVE: List.Forall (fun em => <<SAT: (ThreadEvent.is_reserve
/1\ wf_time_evt times
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (incr_time_seq (tm loc))>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))) (snd em)>>) ftr_reserve>>) /\
(<<CANCEL: List.Forall (fun em => <<SAT: (ThreadEvent.is_cancel /1\ wf_time_evt times) (snd em)>>) ftr_cancel>>) /\
(<<CONSISTENT: pf_consistent_special e2 (ftr_cancel ++ ftr1) times>>) /\
(<<CANCELNORMAL: cancel_normal_trace (ftr_cancel ++ ftr1)>>)>>) /\
(<<MAPLT: mapping_map_lt f>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max loc))
(MAP: f loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max loc) fts) (MAP: f loc ts fts),
Time.lt (max loc) ts /\ Time.le (incr_time_seq (tm loc)) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f (snd fem) (snd em)) tr ftr>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
(<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>))).
Lemma pf_consistent_super_strong_easy_aux
lang (th: Thread.t lang) tr times
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_super_strong_split th tr times)
:
pf_consistent_super_strong_aux th tr times.
Proof.
ii. exploit CONSISTENT; eauto. i. des.
assert (MLE: Memory.le (Local.promises (Thread.local th)) cap).
{ etrans.
{ eapply WF. }
{ eapply CAP. }
}
esplits; eauto.
{ exploit write_not_in_traced; eauto.
intros WRITENOTIN.
exploit no_read_unreadable_traced; eauto.
intros NOREAD. ss.
esplits; eauto.
eapply list_Forall_sum.
{ eapply list_Forall_sum.
{ eapply WRITENOTIN. }
{ eapply NOREAD. }
instantiate (1:=fun lce => (no_read_msgs (fun loc ts => ~ (covered loc ts (Local.promises (Thread.local th)) \/ concrete_promised (Thread.memory th) loc ts \/ Time.lt (incr_time_seq (tm loc)) ts))
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (incr_time_seq (tm loc))>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local th))>>))) (snd lce)).
i. ss. splits.
{ eapply no_read_msgs_mon; eauto. i.
eapply not_or_and in PR. des.
eapply not_or_and in PR0. des. econs.
{ eapply unwritable_eq; eauto. econs; eauto.
eapply cap_flex_covered; eauto. ss. econs; eauto.
{ ss. destruct (Time.bot_spec x2); auto. inv H.
exfalso. eapply PR0. econs. eapply MEM. }
{ ss. destruct (Time.le_lt_dec x2 (incr_time_seq (tm x0))); ss. }
}
{ i. eapply PR0.
eapply cap_flex_inv in GET; eauto. des; ss. econs; eauto. }
}
{ eapply write_not_in_mon_bot; eauto. i. des.
eapply unwritable_eq; eauto. econs; eauto.
eapply cap_flex_covered; eauto. ss. }
}
{ eapply EVENTS. }
{ i. ss. des. splits; auto. }
}
{ i. exploit SPLIT; eauto. i. des. esplits; eauto.
exploit write_not_in_traced.
{ eapply Trace.steps_trans.
{ eapply STEPS0. }
{ eapply STEPS2. }
}
{ eauto. }
i. ss.
eapply list_Forall_sum.
{ eapply RESERVE. }
{ eapply Forall_app_inv in x0. des. eapply FORALL2. }
i. ss. des. splits; auto.
{ eapply write_not_in_mon_bot; eauto. i. des.
eapply unwritable_eq; eauto. econs; eauto.
eapply cap_flex_covered; eauto. ss. }
}
Qed.
Definition pf_consistent_super_strong_aux2 lang (e0:Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
: Prop :=
forall mem1 tm max
(FUTURE: Memory.future_weak (Thread.memory e0) mem1)
(CLOSED: Memory.closed mem1)
(LOCAL: Local.wf (Thread.local e0) mem1)
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
exists ftr e1 f,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot mem1) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ no_read_msgs (fun loc ts => ~ (covered loc ts (Local.promises (Thread.local e0)) \/ concrete_promised (Thread.memory e0) loc ts \/ Time.lt (tm loc) ts))
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<CANCELNORMAL: cancel_normal_trace ftr>>) /\
(<<SPLIT:
forall ftr0 ftr1
(FTRACE: ftr = ftr0 ++ ftr1)
(NORMAL: List.Forall (fun em => ~ ThreadEvent.is_cancel (snd em)) ftr1),
exists ftr_reserve ftr_cancel e2,
(<<STEPS: Trace.steps (ftr0 ++ ftr_reserve) (Thread.mk _ (Thread.state e0) (Thread.local e0) TimeMap.bot mem1) e2>>) /\
(<<RESERVE: List.Forall (fun em => <<SAT: (ThreadEvent.is_reserve
/1\ wf_time_evt times
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))) (snd em)>>) ftr_reserve>>) /\
(<<CANCEL: List.Forall (fun em => <<SAT: (ThreadEvent.is_cancel /1\ wf_time_evt times) (snd em)>>) ftr_cancel>>) /\
(<<CONSISTENT: pf_consistent_special e2 (ftr_cancel ++ ftr1) times>>) /\
(<<CANCELNORMAL: cancel_normal_trace (ftr_cancel ++ ftr1)>>)>>) /\
(<<MAPLT: mapping_map_lt f>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max loc))
(MAP: f loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max loc) fts) (MAP: f loc ts fts),
Time.lt (max loc) ts /\ Time.le (tm loc) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f (snd fem) (snd em)) tr ftr>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
((<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>)))).
Lemma thread_trace_trace_match_map lang (ttr: ThreadTrace.t lang) (tr: Trace.t)
(MATCH: List.Forall2
(fun the lce =>
(Thread.local (fst the)) = (fst lce) /\
(snd the) = (snd lce)) ttr tr)
:
tr = List.map (fun the => ((Thread.local (fst the)), snd the)) ttr.
Proof.
ginduction ttr; eauto; i; ss.
{ inv MATCH. ss. }
{ inv MATCH. f_equal; eauto. destruct a, y. ss. des. clarify. }
Qed.
Lemma pf_consistent_super_strong_aux_aux2
lang (th: Thread.t lang) tr times
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_super_strong_aux th tr times)
:
pf_consistent_super_strong_aux2 th tr times.
Proof.
ii.
assert (TM: exists (ftm: Loc.t -> nat),
forall loc,
(<<TM0: Time.lt (Memory.max_ts loc (Thread.memory th)) (incr_time_seq (ftm loc))>>) /\
(<<TM1: Time.lt (Memory.max_ts loc mem1) (incr_time_seq (ftm loc))>>) /\
(<<TM2: Time.le (tm loc) (incr_time_seq (ftm loc))>>)).
{ eapply (choice
(fun loc n =>
(<<TM0: Time.lt (Memory.max_ts loc (Thread.memory th)) (incr_time_seq n)>>) /\
(<<TM1: Time.lt (Memory.max_ts loc mem1) (incr_time_seq n)>>) /\
(<<TM2: Time.le (tm loc) (incr_time_seq n)>>))).
intros loc. hexploit (incr_time_seq_diverge
(Time.join (Time.join
(Memory.max_ts loc (Thread.memory th))
(Memory.max_ts loc mem1))
(tm loc))).
i. des. exists n. splits.
{ eapply TimeFacts.le_lt_lt; eauto. etrans.
{ eapply Time.join_l. }
eapply Time.join_l. }
{ eapply TimeFacts.le_lt_lt; eauto. etrans.
{ eapply Time.join_r. }
eapply Time.join_l. }
{ left. eapply TimeFacts.le_lt_lt; eauto.
eapply Time.join_r. }
}
des.
hexploit (@cap_flex_exists (Thread.memory th) (fun loc => incr_time_seq (ftm loc))); eauto.
{ i. eapply TM. }
intros [cap CAP]. des.
exploit CONSISTENT; eauto.
{ i. eapply TM. }
i. des.
exploit ThreadTrace.trace_steps_thread_trace_steps; eauto. i. des.
hexploit (@cap_flex_future_memory_map (Thread.memory th)); eauto.
{ i. eapply TM. }
{ i. left. eapply TM. }
intros MEMORY. destruct e1. ss.
hexploit thread_trace_steps_map.
{ eapply ident_map_le; eauto. }
{ eapply ident_map_bot; eauto. }
{ eapply ident_map_eq; eauto. }
{ eapply List.Forall_forall. i. eapply ident_map_mappable_evt. }
{ eapply STEPS0. }
{ ss. }
{ ss. }
{ ss. }
{ eapply cap_flex_wf; eauto. }
{ eapply LOCAL. }
{ eauto. }
{ eapply cap_flex_closed; eauto. i. eapply TM. }
{ eapply Memory.closed_timemap_bot; eauto. eapply CLOSED. }
{ eapply Memory.closed_timemap_bot; eauto.
eapply cap_flex_closed; eauto. i. eapply TM. }
{ econs; eauto.
{ eapply ident_map_local. }
{ eapply mapping_map_lt_collapsable_unwritable. eapply ident_map_lt. }
{ eapply ident_map_timemap. }
{ refl. }
}
i. des.
exploit ThreadTrace.thread_trace_steps_trace_steps; eauto. i. des.
assert (LCTRACE: List.Forall2
(fun em fem : Local.t * ThreadEvent.t => tevent_map ident_map (snd fem) (snd em)) ftr tr0).
{ eapply list_Forall2_compose.
{ eapply list_Forall2_rev. eauto. }
{ eapply list_Forall2_compose.
{ eauto. }
{ eauto. }
simpl. i.
instantiate (1:=fun em fem => tevent_map ident_map (snd fem) (snd em)).
ss. des. rewrite SAT2 in *. auto.
}
i. ss. des. rewrite SAT2 in *. auto.
}
assert (FEVENTS: List.Forall
(fun em : Local.t * ThreadEvent.t =>
((((promise_free (snd em) /\ no_sc (snd em)) /\
no_read_msgs
(fun (loc : Loc.t) (ts : Time.t) =>
~
(covered loc ts (Local.promises (Thread.local th)) \/
concrete_promised (Thread.memory th) loc ts \/ Time.lt (tm loc) ts))
(snd em)) /\
write_not_in
(fun (loc : Loc.t) (ts : Time.t) =>
Time.le ts (tm loc) /\ ~ covered loc ts (Local.promises (Thread.local th)))
(snd em)) /\ wf_time_evt times (snd em)) /\
ThreadEvent.get_machine_event (snd em) = MachineEvent.silent) tr0).
{ esplits; eauto.
eapply List.Forall_forall. i.
eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss. des.
destruct a, x. ss. splits; auto.
{ inv SAT; ss. inv FROM. inv TO. inv KIND; ss.
inv MSG0; ss. inv MSG; ss. inv MAP1; ss. }
{ inv SAT; ss. }
{ inv SAT; ss.
{ inv TO. ii. eapply SAT3. ii. eapply H. des; auto.
right. right. eapply TimeFacts.le_lt_lt; eauto. apply TM. }
{ inv FROM. ii. eapply SAT3. ii. eapply H. des; auto.
right. right. eapply TimeFacts.le_lt_lt; eauto. apply TM. }
}
{ inv SAT; ss.
{ inv TO. inv FROM. inv KIND; ss. ii. eapply SAT2; eauto.
des. split; auto. red. etrans; eauto. eapply TM. }
{ inv TO. inv FROM. ii. eapply SAT2; eauto.
des. split; auto. red. etrans; eauto. eapply TM. }
{ inv TO. inv FROM. ii. eapply SAT2; eauto.
des. split; auto. red. etrans; eauto. eapply TM. }
}
{ inv SAT; ss.
{ inv FROM. inv TO. auto. }
{ inv FROM. inv TO. auto. }
{ inv FROM. inv TO. auto. }
}
{ inv SAT; ss. }
}
esplits; eauto.
{ unfold cancel_normal_trace in *. des. subst.
eapply List.Forall2_app_inv_l in LCTRACE. des. subst. esplits; eauto.
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
destruct a, x. ss. eapply List.Forall_forall in IN; eauto. ss. inv SAT; ss.
inv KIND; ss; des_ifs. inv MSG. }
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
destruct a, x. ss. eapply List.Forall_forall in IN; eauto. ss. inv SAT; ss.
inv KIND; ss; des_ifs. inv MSG. }
}
{ i. subst.
assert (exists l1 l2 e_mid fe_mid,
(<<EQ: ftr = l1 ++ l2>>) /\
(<<STEPSCAP1: Trace.steps
l1
(Thread.mk _ (Thread.state th) (Thread.local th) TimeMap.bot cap) e_mid>>) /\
(<<STEPSCAP2: Trace.steps
l2
e_mid
(Thread.mk _ state local sc memory)>>) /\
(<<STEPSMEM: Trace.steps
ftr1
(Thread.mk _ (Thread.state th) (Thread.local th) TimeMap.bot mem1) fe_mid>>) /\
(<<MAP: thread_map ident_map e_mid fe_mid>>) /\
(<<LCTRACE0: List.Forall2
(fun em fem => tevent_map ident_map (snd fem) (snd em))
l1 ftr1>>) /\
(<<LCTRACE1: List.Forall2
(fun em fem => tevent_map ident_map (snd fem) (snd em))
l2 ftr2>>)).
{ clear SPLIT CANCELNORMAL EVENTS x1 CAP MAPLT MAPIDENT BOUND FEVENTS.
eapply List.Forall2_app_inv_r in MATCH0. des. subst.
eapply List.Forall2_app_inv_r in TRACE0. des. subst.
eapply ThreadTrace.steps_separate in STEPS0. des.
eapply ThreadTrace.steps_separate in STEPS1. des.
eapply ThreadTrace.thread_trace_steps_trace_steps in STEPS3.
dup STEPS4. eapply ThreadTrace.thread_trace_steps_trace_steps in STEPS4.
eapply ThreadTrace.thread_trace_steps_trace_steps in STEPS0. des.
assert (ftr1 = tr0).
{ eapply thread_trace_trace_match_map in MATCH2.
eapply thread_trace_trace_match_map in MATCH0. subst. auto. }
subst.
assert (ftr = tr2 ++ tr1).
{ eapply thread_trace_trace_match_map in MATCH.
eapply thread_trace_trace_match_map in MATCH4.
eapply thread_trace_trace_match_map in MATCH3. subst.
eapply List.map_app. }
subst. esplits; eauto.
{ destruct l3.
{ inv TRACE1. inv MATCH1. inv NORMAL. inv MATCH3.
inv STEPS5; ss. inv STEPS0; ss. }
{ inv TRACE1. inv MATCH1. inv MATCH3.
inv STEPS5; ss. inv STEPS1; ss. clarify. ss. des. auto. }
}
{ eapply list_Forall2_compose.
{ eapply list_Forall2_rev. eapply MATCH4. }
{ eapply list_Forall2_compose.
{ eapply TRACE0. }
{ eauto. }
{ simpl. i. instantiate (1:=fun em fem =>tevent_map ident_map (snd fem) (snd em)).
ss. des. rewrite SAT2 in *. auto. }
}
{ i. ss. des. rewrite SAT2 in *. auto. }
}
{ eapply list_Forall2_compose.
{ eapply list_Forall2_rev. eapply MATCH3. }
{ eapply list_Forall2_compose.
{ eapply TRACE1. }
{ eauto. }
{ simpl. i. instantiate (1:=fun em fem =>tevent_map ident_map (snd fem) (snd em)).
ss. des. rewrite SAT2 in *. auto. }
}
{ i. ss. des. rewrite SAT2 in *. auto. }
}
}
clear LCTRACE. des. exploit SPLIT; eauto.
{ clear - LCTRACE1 NORMAL.
eapply List.Forall_forall. i. eapply list_Forall2_in2 in H; eauto.
des. eapply List.Forall_forall in IN; eauto. ss.
destruct b, x. ss. inv SAT; ss.
inv KIND; ss; des_ifs. inv MSG. }
i. des.
inv MAP0. destruct e2. ss.
exploit Trace.steps_future; try apply STEPSCAP1; eauto.
{ eapply cap_flex_wf; eauto. }
{ eapply Memory.closed_timemap_bot; eauto.
eapply cap_flex_closed; eauto. i. eapply TM. }
{ eapply cap_flex_closed; eauto. i. eapply TM. } i. des. ss.
exploit Trace.steps_future; try apply STEPSMEM; eauto.
{ eapply Memory.closed_timemap_bot; eauto. eapply CLOSED. } i. des. ss.
hexploit trace_steps_map; try apply STEPS3.
{ eapply ident_map_le; eauto. }
{ eapply ident_map_bot; eauto. }
{ eapply ident_map_eq; eauto. }
{ eapply List.Forall_forall. i. eapply ident_map_mappable_evt. }
{ ss. }
{ ss. }
{ ss. }
{ eauto. }
{ eapply WF0. }
all: eauto. i. des.
eexists ftr, ftr_cancel, _. splits.
{ eapply Trace.steps_trans.
{ eapply STEPSMEM. }
{ eapply STEPS4. }
}
{ clear - TM RESERVE TRACE1. eapply List.Forall_forall. i.
eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss. des.
destruct a, x. ss. unfold ident_map in *.
inv EVENT; ss; des; subst; eauto. inv MSG; inv KIND; ss. splits; auto.
ii. eapply IN0; eauto. des. splits; auto. etrans; eauto. eapply TM. }
{ eauto. }
{ eapply pf_consistent_speciali_events_map with (tr1 := ftr_cancel ++ ftr2) in CONSISTENT0; cycle 1.
{ eapply list_Forall2_app.
{ eapply list_Forall_refl_Forall2; eauto. eapply List.Forall_forall.
ii. destruct x. ss. destruct t0; econs; ss. }
{ eapply list_Forall2_impl; eauto. i. eapply tevent_map_tevent_map_weak; eauto. }
}
{ eapply Trace.steps_future in STEPS3; eauto. des.
eapply Trace.steps_future in STEPS4; eauto. des.
eapply ident_map_pf_consistent_super_strong_easy; eauto.
econs; eauto.
eapply mapping_map_lt_collapsable_unwritable; eauto. eapply ident_map_lt; eauto.
}
}
{ exists ftr_cancel, ftr2. splits; auto.
eapply List.Forall_impl; eauto. i. ss. des. auto. }
}
{ ii. exploit BOUND; eauto. i. des. split; auto.
etrans; eauto. eapply TM. }
{ eapply list_Forall2_compose; eauto. i. ss. des.
eapply ident_map_compose_tevent_weak; eauto.
eapply tevent_map_tevent_map_weak; eauto.
}
{ ss. unguard. des.
{ left. esplits; eauto. eapply failure_step_map; eauto.
{ eapply ident_map_le. }
{ eapply ident_map_eq. }
{ inv MAP. auto. }
}
{ right. inv MAP. inv LOCAL0. rewrite PROMISES in *.
eapply bot_promises_map; eauto. }
}
Qed.
Lemma pf_consistent_super_strong_easy_promise_consistent lang (e0: Thread.t lang) tr times
(CONSISTENT: pf_consistent_super_strong_easy e0 tr times)
(CLOSED: Memory.closed (Thread.memory e0))
(LOCAL: Local.wf (Thread.local e0) (Thread.memory e0))
:
Local.promise_consistent (Thread.local e0).
Proof.
hexploit (@concrete_promise_max_timemap_exists
(Thread.memory e0)
(Local.promises (Thread.local e0))); eauto.
{ eapply CLOSED. } i. des.
assert (exists (f: Loc.t -> nat),
forall loc,
Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq (f loc))).
{ eapply (choice
(fun loc n =>
Time.lt (Memory.max_ts loc (Thread.memory e0)) (incr_time_seq n))).
i. eapply incr_time_seq_diverge; eauto. }
des.
exploit (@cap_flex_exists
(Thread.memory e0)
(fun loc => incr_time_seq (f loc))); eauto. i. des.
exploit CONSISTENT; eauto. i. des.
eapply Trace.steps_promise_consistent in STEPS; eauto; ss.
{ unguard. des.
{ inv LOCAL0. ss. }
{ ii. erewrite PROMISES in *. erewrite Memory.bot_get in *. ss. }
}
{ eapply cap_flex_wf; eauto. }
{ eapply Memory.closed_timemap_bot; eauto.
eapply cap_flex_closed; eauto. }
{ eapply cap_flex_closed; eauto. }
Qed.
Definition pf_consistent_super_strong lang (e0:Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
: Prop :=
forall mem1 tm sc max
(FUTURE: Memory.future_weak (Thread.memory e0) mem1)
(CLOSED: Memory.closed mem1)
(LOCAL: Local.wf (Thread.local e0) mem1)
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
exists ftr e1 f,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) sc mem1) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ no_read_msgs (fun loc ts => ~ (covered loc ts (Local.promises (Thread.local e0)) \/ concrete_promised (Thread.memory e0) loc ts \/ Time.lt (tm loc) ts))
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<CANCELNORMAL: cancel_normal_trace ftr>>) /\
(<<SPLIT:
forall ftr0 ftr1
(FTRACE: ftr = ftr0 ++ ftr1)
(NORMAL: List.Forall (fun em => ~ ThreadEvent.is_cancel (snd em)) ftr1),
exists ftr_reserve ftr_cancel e2,
(<<STEPS: Trace.steps (ftr0 ++ ftr_reserve) (Thread.mk _ (Thread.state e0) (Thread.local e0) sc mem1) e2>>) /\
(<<RESERVE: List.Forall (fun em => <<SAT: (ThreadEvent.is_reserve
/1\ wf_time_evt times
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))) (snd em)>>) ftr_reserve>>) /\
(<<CANCEL: List.Forall (fun em => <<SAT: (ThreadEvent.is_cancel /1\ wf_time_evt times) (snd em)>>) ftr_cancel>>) /\
(<<CONSISTENT: pf_consistent_super_strong_easy e2 (ftr_cancel ++ ftr1) times>>) /\
(<<PROMCONSISTENT: Local.promise_consistent (Thread.local e2)>>) /\
(<<CANCELNORMAL: cancel_normal_trace (ftr_cancel ++ ftr1)>>) /\
(<<GOOD: good_future tm mem1 (Thread.memory e2)>>) /\
(<<SC: (Thread.sc e2) = sc>>)>>) /\
(<<MAPLT: mapping_map_lt f>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max loc))
(MAP: f loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max loc) fts) (MAP: f loc ts fts),
Time.lt (max loc) ts /\ Time.le (tm loc) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f (snd fem) (snd em)) tr ftr>>) /\
(<<GOOD: good_future tm mem1 (Thread.memory e1)>>) /\
(<<SC: (Thread.sc e1) = sc>>) /\
(<<PROMCONSISTENT: Local.promise_consistent (Thread.local e1)>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)) \/
((<<PROMISES: (Local.promises (Thread.local e1)) = Memory.bot>>) /\
(<<WRITES: forall loc from to val released
(GET: Memory.get loc to (Local.promises (Thread.local e0)) = Some (from, Message.concrete val released)),
exists th e,
(<<WRITING: promise_writing_event loc from to val released e>>) /\
(<<IN: List.In (th, e) ftr>>)>>)))).
Lemma pf_consistent_super_strong_aux2_super_strong
lang (th: Thread.t lang) tr times
(WF: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_super_strong_aux2 th tr times)
:
pf_consistent_super_strong th tr times.
Proof.
ii. set (tm0:=TimeMap.join tm (fun loc => Time.incr (Memory.max_ts loc mem1))).
assert (TM0: forall loc, Time.lt (Memory.max_ts loc mem1) (tm0 loc)).
{ i. eapply TimeFacts.lt_le_lt.
{ eapply Time.incr_spec. }
{ eapply Time.join_r. }
}
assert (TM1: TimeMap.le tm tm0).
{ eapply TimeMap.join_l. }
exploit (CONSISTENT mem1 tm0 max); eauto. i. des. destruct e1. ss.
dup STEPS. eapply no_sc_any_sc_traced in STEPS; eauto; cycle 1.
{ eapply List.Forall_impl; eauto. i. ss. des. auto. } des.
esplits; eauto.
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto.
{ eapply no_read_msgs_mon; eauto. ii. eapply PR. des; auto.
right. right. eapply TimeFacts.le_lt_lt; eauto. }
{ eapply write_not_in_mon; eauto. ii. des. split; auto.
red. etrans; eauto. }
}
{ i. subst.
exploit SPLIT; eauto. i. des. destruct e2. ss.
assert (NOSC: List.Forall (fun em => no_sc (snd em)) (ftr0 ++ ftr_reserve)).
{ eapply Forall_app.
{ eapply Forall_app_inv in EVENTS. des.
eapply List.Forall_impl; eauto. i. ss. des. auto. }
{ eapply List.Forall_impl; eauto. i. ss. des.
destruct a. ss. destruct t0; ss. }
}
dup STEPS.
eapply no_sc_any_sc_traced in STEPS; eauto; cycle 1. des.
esplits; eauto.
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto.
eapply write_not_in_mon; eauto. i. ss. des. splits; auto. etrans; eauto. }
{ eapply pf_consistent_speciali_strong_easy in CONSISTENT0; eauto. }
{ eapply Trace.steps_future in STEPS2; eauto.
{ ss. des. eapply pf_consistent_speciali_strong_easy in CONSISTENT0; eauto.
eapply pf_consistent_super_strong_easy_promise_consistent in CONSISTENT0; eauto. }
{ ss. eapply Memory.closed_timemap_bot. eapply CLOSED. }
}
{ eapply good_future_mon with (tm1:=tm0); auto.
eapply write_not_in_good_future_traced in STEPS2; eauto.
{ ss. eapply Memory.closed_timemap_bot; eauto. eapply CLOSED. }
{ eapply Forall_app.
{ eapply Forall_app_inv in EVENTS. des. ss.
eapply List.Forall_impl; eauto. i. ss. des.
eapply write_not_in_mon; eauto. ii. des. split; auto.
ii. eapply PROM. eapply memory_le_covered; eauto. eapply LOCAL. }
{ eapply List.Forall_impl; eauto. i. ss. des.
eapply write_not_in_mon; eauto. ii. des. split; auto.
ii. eapply PROM. eapply memory_le_covered; eauto. eapply LOCAL. }
}
}
{ ss. eapply no_sc_same_sc_traced in STEPS3; eauto. }
}
{ ii. exploit BOUND; eauto. i. des. splits; auto. etrans; eauto. }
{ eapply good_future_mon with (tm1:=tm0); auto.
eapply write_not_in_good_future_traced in STEPS0; eauto.
{ ss. eapply Memory.closed_timemap_bot; eauto. eapply CLOSED. }
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto.
eapply write_not_in_mon; eauto. ii. des. split; auto.
ii. eapply PR0. eapply memory_le_covered; eauto. eapply LOCAL. }
}
{ eapply no_sc_same_sc_traced in STEPS1; eauto.
eapply List.Forall_impl; eauto. i. ss. des. auto. }
{ unguard. des.
{ inv LOCAL0. ss. }
{ ss. eapply Local.bot_promise_consistent; eauto. }
}
{ ss. unguard. des; eauto. right. splits; auto.
i. eapply steps_promise_decrease_promise_writing_event in STEPS1; eauto.
des; eauto. ss. erewrite PROMISES in *. erewrite Memory.bot_get in *. ss. }
Qed.
Lemma pf_consistent_super_strong_not_easy lang (th: Thread.t lang)
tr times
(LOCAL: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: pf_consistent_super_strong_easy th tr times)
(CANCELNORMAL: cancel_normal_trace tr)
(MWF: memory_times_wf times (Thread.memory th))
(DIVERGE: forall loc n, times loc (incr_time_seq n))
:
pf_consistent_super_strong th tr times.
Proof.
eapply pf_consistent_super_strong_aux2_super_strong; eauto.
eapply pf_consistent_super_strong_aux_aux2; eauto.
eapply pf_consistent_super_strong_easy_aux; eauto.
eapply pf_consistent_flex_super_strong_easy_split; eauto.
Qed.
Lemma consistent_pf_consistent_super_strong lang (th: Thread.t lang)
(LOCAL: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
(CONSISTENT: Thread.consistent th)
:
exists tr certimes,
(<<WO: forall loc, well_ordered (certimes loc)>>) /\
<<CONSISTENT: pf_consistent_super_strong th tr certimes>>.
Proof.
eapply consistent_pf_consistent in CONSISTENT; eauto.
eapply pf_consistent_pf_consistent_strong in CONSISTENT; eauto.
eapply pf_consistent_strong_pf_consistent_strong_aux in CONSISTENT; eauto.
eapply pf_consistent_strong_aux_pf_consistent_flex in CONSISTENT; eauto. des.
eapply pf_consistent_flex_super_strong_easy in CONSISTENT0; eauto. des.
eapply pf_consistent_super_strong_not_easy in CONSISTENT; eauto.
Qed.
Lemma pf_consistent_super_strong_consistent lang (th: Thread.t lang)
(LOCAL: Local.wf (Thread.local th) (Thread.memory th))
(MEM: Memory.closed (Thread.memory th))
tr certimes
(CONSISTENT: pf_consistent_super_strong th tr certimes)
:
Thread.consistent th.
Proof.
hexploit (@concrete_promise_max_timemap_exists
((Thread.memory th))
((Local.promises (Thread.local th)))).
{ eapply MEM. } intros [max MAX]. des.
ii. exploit (CONSISTENT mem1 sc1 sc1).
{ eapply Memory.cap_future_weak; eauto. }
{ eapply Memory.cap_closed; eauto. }
{ eapply Local.cap_wf; eauto. }
{ eauto. }
i. des.
eapply pred_steps_trace_steps2 in STEPS; cycle 1.
{ instantiate (1:=fun _ => True). eapply List.Forall_impl; eauto.
i. ss. des. splits; auto. }
eapply thread_steps_pred_steps in STEPS.
unguard. des.
{ destruct e1. ss. left. econs. esplits; eauto. }
{ right. esplits; eauto. }
Qed.
Definition pf_consistent_super_strong_mon lang e0 tr certimes0 certimes1
(CONSISTENT: @pf_consistent_super_strong
lang e0 tr certimes0)
(LE: certimes0 <2= certimes1)
:
pf_consistent_super_strong e0 tr certimes1.
Proof.
ii. exploit CONSISTENT; eauto. i. des. esplits; eauto.
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto.
eapply wf_time_evt_mon; eauto. }
{ i. exploit SPLIT; eauto. i. des. exists ftr_reserve, ftr_cancel, e2. splits; ss.
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto.
eapply wf_time_evt_mon; eauto. }
{ eapply List.Forall_impl; eauto. i. ss. des. splits; auto.
eapply wf_time_evt_mon; eauto. }
{ eapply pf_consistent_super_strong_easy_mon; eauto. }
}
Qed.
Lemma promises_bot_certify_nil_easy times lang (th: Thread.t lang)
(PROMISES: (Local.promises (Thread.local th)) = Memory.bot)
:
pf_consistent_super_strong_easy th [] times.
Proof.
ii. eexists [], _, bot3. esplits; eauto.
{ exists [], []. splits; ss. }
{ ii. ss. }
{ ii. ss. }
{ ii. ss. }
{ right. ss. }
Qed.
Lemma failure_certify_nil_easy times lang (th: Thread.t lang) st'
(FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang th) st')
(LOCAL: Local.failure_step (Thread.local th))
:
pf_consistent_super_strong_easy th [] times.
Proof.
ii. eexists [], _, bot3. esplits; eauto.
{ exists [], []. splits; ss. }
{ ii. ss. }
{ ii. ss. }
{ ii. ss. }
{ left. ss. esplits; eauto. }
Qed.
Lemma promises_bot_certify_nil times lang (th: Thread.t lang)
(PROMISES: (Local.promises (Thread.local th)) = Memory.bot)
:
pf_consistent_super_strong th [] times.
Proof.
ii. eexists [], _, bot3. esplits; eauto.
{ exists [], []. splits; ss. }
{ i. destruct ftr0; ss. subst. esplits; eauto.
{ ss. eapply promises_bot_certify_nil_easy; ss. }
{ ss. ii. erewrite PROMISES in *. erewrite Memory.bot_get in *. ss. }
{ exists [], []. splits; ss. }
{ refl. }
}
{ ii. ss. }
{ ii. ss. }
{ ii. ss. }
{ refl. }
{ eapply Local.bot_promise_consistent; eauto. }
{ right. ss. splits; auto. i.
rewrite PROMISES in *. erewrite Memory.bot_get in *. ss. }
Qed.
Lemma failure_certify_nil times lang (th: Thread.t lang) st'
(FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang th) st')
(LOCAL: Local.failure_step (Thread.local th))
:
pf_consistent_super_strong th [] times.
Proof.
ii. eexists [], _, bot3. esplits; eauto.
{ exists [], []. splits; ss. }
{ i. destruct ftr0; ss. subst. esplits; eauto.
{ ss. inv LOCAL. eapply failure_certify_nil_easy; eauto. }
{ inv LOCAL. ss. }
{ exists [], []. splits; ss. }
{ refl. }
}
{ ii. ss. }
{ ii. ss. }
{ ii. ss. }
{ refl. }
{ inv LOCAL. ss. }
{ left. ss. esplits; eauto. }
Qed.
Lemma certify_nil_promises_bot_or_failure times lang (th: Thread.t lang)
(CONSISTENT: pf_consistent_super_strong th [] times)
(CLOSED: Memory.closed (Thread.memory th))
(LOCAL: Local.wf (Thread.local th) (Thread.memory th))
:
(<<PROMISES: (Local.promises (Thread.local th)) = Memory.bot>>) \/
exists st',
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang th) st'>>) /\
(<<LOCAL: Local.failure_step (Thread.local th)>>).
Proof.
exploit concrete_promise_max_timemap_exists.
{ eapply CLOSED. } i. des.
exploit (CONSISTENT (Thread.memory th) TimeMap.bot (Thread.sc th) tm); eauto.
{ refl. } i. des. inv TRACE. inv STEPS; ss.
unguard. des; eauto.
Qed.
Lemma good_future_future_future mem0 mem_good0 mem_good1 tm
(f0: Loc.t -> Time.t -> Time.t -> Prop)
(IDENT: forall loc to fto (MAP: f0 loc to fto), to = fto)
(MAPBOT: mapping_map_bot f0)
(GOOD: memory_map f0 mem0 mem_good0)
(FUTURE: Memory.future_weak mem_good0 mem_good1)
(CLOSED: Memory.closed mem0)
(TM0: forall loc, Time.lt (Memory.max_ts loc mem_good1) (tm loc))
(TM1: forall loc, Time.lt (Memory.max_ts loc mem0) (tm loc))
:
exists mem1,
(<<CAP: cap_flex mem0 mem1 tm>>) /\
(<<MAP: memory_map ident_map mem1 mem_good1>>).
Proof.
exploit (@cap_flex_exists mem0 tm); eauto. intros [mem1 CAP].
exists mem1. splits; auto. econs.
{ i. eapply cap_flex_inv in GET; eauto. des; auto.
apply GOOD in GET. des; auto. destruct fmsg as [val freleased|]; cycle 1.
{ inv MSGLE. inv MSG. auto. }
eapply Memory.future_weak_get1 in GET; eauto. des.
dup MSG. dup MSGLE. dup MSG_LE.
inv MSG; inv MSGLE; inv MSG_LE; auto.
right. esplits; cycle 3.
{ eauto. }
{ eapply IDENT; eauto. }
{ eapply message_map_incr; eauto. }
{ econs; eauto. }
}
{ i. left. exists (tm loc), Time.bot, (tm loc), Time.bot. splits; ss.
{ eapply Time.bot_spec. }
{ eapply Memory.max_ts_spec in GET. des. left.
eapply TimeFacts.le_lt_lt; eauto. }
{ i. erewrite cap_flex_covered in ITV; eauto. }
}
Qed.
Lemma good_future_consistent times lang st lc_src lc_tgt sc_src sc_tgt mem_src mem_tgt tr
(f: Loc.t -> Time.t -> Time.t -> Prop)
(CONSISTENT: pf_consistent_super_strong
(Thread.mk lang st lc_tgt sc_tgt mem_tgt)
tr times)
(IDENT: forall loc to fto (MAP: f loc to fto), to = fto)
(MAPBOT: mapping_map_bot f)
(LOCALSRC: Local.wf lc_src mem_src)
(LOCALTGT: Local.wf lc_tgt mem_tgt)
(MEMSRC: Memory.closed mem_src)
(MEMTGT: Memory.closed mem_tgt)
(LOCAL: local_map f lc_tgt lc_src)
(MEM: memory_map f mem_tgt mem_src)
max_tgt
(MAXTGT: concrete_promise_max_timemap mem_tgt (Local.promises lc_tgt) max_tgt)
(MWF: memory_times_wf times mem_src)
(DIVERGE: forall loc n, times loc (incr_time_seq n))
:
exists tr_good f_good,
(<<MAPLT: mapping_map_lt f_good>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max_tgt loc))
(MAP: f_good loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max_tgt loc) fts) (MAP: f_good loc ts fts),
Time.lt (max_tgt loc) ts /\ Time.lt (Memory.max_ts loc mem_tgt) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f_good (snd fem) (snd em)) tr tr_good>>) /\
(<<CONSISTENT:
pf_consistent_super_strong (Thread.mk lang st lc_src sc_src mem_src) tr_good times>>)
.
Proof.
hexploit (CONSISTENT mem_tgt (fun loc => Time.incr (Time.join (Memory.max_ts loc mem_tgt) (Memory.max_ts loc mem_src))) sc_tgt); eauto.
{ refl. } ss.
intros [tr_good [e1_good [f_good [STEPSGOOD [EVENTSGOOD [CANCELNORMALGOOD [SPLITGOOD [MAPLTGOOD [IDENTGOOD [BOUNDGOOD [TRACEGOOD [GOODFUTURE [SCGOOD GOODEND]]]]]]]]]]]]]. des.
exists tr_good, f_good. splits; auto.
{ i. eapply BOUNDGOOD in MAP; eauto. des. splits; eauto.
eapply TimeFacts.lt_le_lt; eauto. eapply TimeFacts.le_lt_lt.
{ eapply Time.join_l. }
{ eapply Time.incr_spec. }
}
eapply pf_consistent_super_strong_not_easy; eauto. ii. ss.
assert (MAXMAP: TimeMap.le max_tgt max).
{ eapply memory_ident_map_concrete_promise_max_timemap; eauto.
eapply LOCAL. }
set (tm0 := TimeMap.join (fun loc => incr_time_seq (tm loc))
(fun loc => Time.incr
(Time.join
(max loc)
(Time.join
(Memory.max_ts loc cap)
(Memory.max_ts loc mem_tgt))))).
assert (TM0: forall loc, Time.lt (Memory.max_ts loc cap) (tm0 loc)).
{ i. unfold tm0. eapply TimeFacts.le_lt_lt.
{ eapply Time.join_l. } eapply TimeFacts.le_lt_lt.
{ eapply Time.join_r. } eapply TimeFacts.lt_le_lt.
{ eapply Time.incr_spec. }
{ eapply Time.join_r. }
}
assert (TM1: forall loc, Time.lt (Memory.max_ts loc mem_tgt) (tm0 loc)).
{ i. unfold tm0. eapply TimeFacts.le_lt_lt.
{ eapply Time.join_r. } eapply TimeFacts.le_lt_lt.
{ eapply Time.join_r. } eapply TimeFacts.lt_le_lt.
{ eapply Time.incr_spec. }
{ eapply Time.join_r. }
}
assert (TM2: TimeMap.le (fun loc => incr_time_seq (tm loc)) tm0).
{ eapply TimeMap.join_l. }
assert (TM3: forall loc, Time.lt (max loc) (tm0 loc)).
{ i. unfold tm0. eapply TimeFacts.le_lt_lt.
{ eapply Time.join_l. } eapply TimeFacts.lt_le_lt.
{ eapply Time.incr_spec. }
{ eapply Time.join_r. }
}
exploit (@good_future_future_future mem_tgt mem_src cap); eauto.
{ eapply cap_flex_future_weak; eauto. }
i. des.
exploit (CONSISTENT mem1 tm0 TimeMap.bot); eauto.
{ ss. eapply cap_flex_future_weak; eauto. }
{ eapply cap_flex_closed; eauto. }
{ ss. eapply cap_flex_wf; eauto. }
ss. i. des. destruct e1. ss.
hexploit trace_steps_map.
{ eapply ident_map_le; eauto. }
{ eapply ident_map_bot; eauto. }
{ eapply ident_map_eq; eauto. }
{ eapply List.Forall_forall. i. eapply ident_map_mappable_evt. }
{ eauto. }
{ ss. }
{ ss. }
{ ss. }
{ eapply cap_flex_wf; eauto. }
{ eapply cap_flex_wf; try apply CAP; eauto. }
{ eapply cap_flex_closed; eauto. }
{ eapply cap_flex_closed; eauto. }
{ eapply Memory.closed_timemap_bot.
eapply cap_flex_closed; eauto. }
{ eapply Memory.closed_timemap_bot.
eapply cap_flex_closed; eauto. }
{ eapply local_map_incr; eauto. eapply ident_map_lt; eauto. }
{ eauto. }
{ eapply mapping_map_lt_collapsable_unwritable; eauto. eapply ident_map_lt. }
{ eapply ident_map_timemap. }
{ refl. }
i. des.
eexists ftr0, _, (fun loc ts0 ts2 => exists ts1, <<TS0: f_good loc ts1 ts0>> /\ <<TS1: f0 loc ts1 ts2>>).
esplits; eauto; ss.
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. ss. des. destruct a, x. ss.
inv EVENT; splits; ss.
{ inv KIND; ss. inv MSG0; ss. inv MSG; ss. inv MAP1; ss. }
{ inv FROM. inv TO. auto. }
{ inv FROM. inv TO. auto. }
{ inv FROM. inv TO. auto. }
}
{ clear - CANCELNORMAL TRACE0. unfold cancel_normal_trace in *. des. subst.
eapply List.Forall2_app_inv_l in TRACE0. des. subst. esplits; eauto.
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. destruct a, x. ss. inv EVENT; ss.
inv KIND; ss; des_ifs. inv MSG. }
{ eapply List.Forall_forall. i. eapply list_Forall2_in in H; eauto. des.
eapply List.Forall_forall in IN; eauto. destruct a, x. ss. inv EVENT; ss.
inv KIND; ss; des_ifs. inv MSG. }
}
{ ii. des. erewrite <- (MAPLTGOOD loc ts0 ts1 t0 t1); eauto. }
{ ii. des.
destruct (Time.le_lt_dec fts (max_tgt loc)).
{ dup l. eapply MAPIDENT in l; cycle 1; eauto. subst.
destruct (Time.le_lt_dec ts (max_tgt loc)).
{ dup l. eapply IDENTGOOD in l; eauto. }
{ dup l. eapply BOUNDGOOD in l; eauto. des. timetac. }
}
{ dup l. eapply BOUND in l; cycle 1; eauto. des.
exfalso. eapply Time.lt_strorder. eapply TimeFacts.le_lt_lt.
{ eapply l1. } eapply TimeFacts.le_lt_lt.
{ eapply TS. }
auto.
}
}
{ ii. des.
destruct (Time.le_lt_dec fts (max_tgt loc)).
{ dup l. eapply MAPIDENT in l; cycle 1; eauto. subst.
exfalso. eapply Time.lt_strorder. eapply TimeFacts.le_lt_lt.
{ eapply l0. } eapply TimeFacts.le_lt_lt.
{ eapply MAXMAP. }
auto.
}
{ dup l. eapply BOUND in l; cycle 1; eauto. des. splits; eauto.
destruct (Time.le_lt_dec ts (max_tgt loc)).
{ dup l2. eapply IDENTGOOD in l2; eauto. subst. timetac. }
{ dup l2. eapply BOUNDGOOD in l2; eauto. des.
eapply TimeFacts.le_lt_lt.
{ eapply concrete_promise_max_ts_max_ts; eauto. eapply LOCALSRC. } eapply TimeFacts.le_lt_lt.
{ eapply Time.join_r. } eapply TimeFacts.lt_le_lt.
{ eapply Time.incr_spec. }
eauto.
}
}
}
{ dup TRACEGOOD. dup TRACE. dup TRACE0.
eapply list_Forall2_compose.
{ eapply list_Forall2_rev. eapply TRACEGOOD. }
{ eapply list_Forall2_compose.
{ eapply TRACE. }
{ eapply TRACE0. }
simpl. instantiate (1:=fun the fthe => tevent_map_weak f0 (snd fthe) (snd the)).
i. ss. des. eapply tevent_map_tevent_map_weak in EVENT.
eapply tevent_map_weak_compose; eauto.
i. inv MAP1. auto.
}
i. ss. eapply tevent_map_weak_rev in SAT0.
{ instantiate (1:=fun loc ts fts => f_good loc fts ts) in SAT0.
eapply tevent_map_weak_compose; eauto.
i. ss. eauto. }
{ i. ss. }
}
{ clear GOODEND0. unguard. des.
{ left. esplits; eauto. eapply failure_step_map; eauto.
{ eapply ident_map_le. }
{ eapply ident_map_eq. }
}
{ inv LOCAL0. right. rewrite PROMISES in *.
eapply bot_promises_map in PROMISES0; eauto. }
}
Qed.
Inductive relaxed_writing_event
(loc: Loc.t) (to: Time.t) (val: Const.t)
: forall (e: ThreadEvent.t), Prop :=
| relaxed_event_write
from released ord
(ORD: Ordering.le ord Ordering.relaxed)
:
relaxed_writing_event
loc to val
(ThreadEvent.write loc from to val released ord)
| relaxed_event_update
from releasedw valr releasedr ordr ordw
(ORD: Ordering.le ordw Ordering.relaxed)
:
relaxed_writing_event
loc to val
(ThreadEvent.update loc from to valr val releasedr releasedw ordr ordw)
.
Hint Constructors relaxed_writing_event.
Lemma pf_consistent_super_strong_same_sc lang (e0: Thread.t lang) tr times sc
(CONSISTENT: pf_consistent_super_strong e0 tr times)
:
pf_consistent_super_strong (Thread.mk _ (Thread.state e0) (Thread.local e0) sc (Thread.memory e0)) tr times.
Proof.
ii. exploit CONSISTENT; eauto.
Qed.
Fixpoint map_somes A B (f: A -> option B) (l: list A): list B :=
match l with
| [] => []
| hd :: tl =>
match (f hd) with
| Some b => b :: map_somes f tl
| None => map_somes f tl
end
end.
Lemma map_somes_in A B (f: A -> option B) l a b
(IN: List.In a l)
(APP: f a = Some b)
:
List.In b (map_somes f l).
Proof.
ginduction l; eauto. i. ss. des.
{ subst. erewrite APP. ss. auto. }
{ eapply IHl in IN; eauto. destruct (f a); ss; auto. }
Qed.
Lemma map_somes_in_rev A B (f: A -> option B) l b
(IN: List.In b (map_somes f l))
:
exists a,
(<<IN: List.In a l>>) /\
(<<APP: f a = Some b>>).
Proof.
ginduction l; eauto; ss. i. destruct (f a) eqn:EQ.
{ ss. des; subst.
{ esplits; eauto. }
{ eapply IHl in IN. des. esplits; eauto. }
}
{ eapply IHl in IN. des. esplits; eauto. }
Qed.
Lemma map_somes_split A B (f: A -> option B) l0 l1
:
map_somes f (l0 ++ l1) =
map_somes f l0 ++ map_somes f l1.
Proof.
ginduction l0; ss; eauto. i. destruct (f a); ss.
f_equal. eapply IHl0; eauto.
Qed.
Lemma map_somes_split_inv A B (f: A -> option B) l fl0 fl1
(MAP: map_somes f l = fl0 ++ fl1)
:
exists l0 l1,
(<<EQ: l = l0 ++ l1>>) /\
(<<MAP0: map_somes f l0 = fl0>>) /\
(<<MAP1: map_somes f l1 = fl1>>).
Proof.
ginduction l; eauto.
{ i. ss. destruct fl0; ss. destruct fl1; ss. exists [], []. splits; auto. }
{ i. ss. destruct (f a) eqn:EQ.
{ destruct fl0; ss.
{ destruct fl1; ss. inv MAP.
exists [], (a::l). splits; auto.
ss. rewrite EQ. auto.
}
{ inv MAP. eapply IHl in H1. des. subst.
exists (a::l0), l1. splits; auto.
ss. rewrite EQ. auto.
}
}
{ eapply IHl in MAP. des. subst.
exists (a::l0), l1. splits; ss. rewrite EQ. auto. }
}
Qed.
Lemma map_somes_one A B (f: A -> option B) l b
(MAP: map_somes f l = [b])
:
exists l0 a l1,
(<<EQ: l = l0 ++ a :: l1>>) /\
(<<MAP0: map_somes f l0 = []>>) /\
(<<MAP1: f a = Some b>>) /\
(<<MAP2: map_somes f l1 = []>>).
Proof.
ginduction l; eauto.
{ i. ss. }
{ i. ss. destruct (f a) eqn:EQ.
{ inv MAP. exists [], a, l. splits; auto. }
{ eapply IHl in MAP. des. subst.
exists (a::l0), a0, l1. splits; ss.
rewrite EQ. auto.
}
}
Qed.
Lemma map_somes_split_inv_one A B (f: A -> option B) l fl0 fl1 b
(MAP: map_somes f l = fl0 ++ b :: fl1)
:
exists l0 a l1,
(<<EQ: l = (l0 ++ [a]) ++ l1>>) /\
(<<MAP0: map_somes f l0 = fl0>>) /\
(<<MAP1: f a = Some b>>) /\
(<<MAP2: map_somes f l1 = fl1>>).
Proof.
eapply map_somes_split_inv in MAP. des. subst.
replace (b::fl1) with ([b]++fl1) in MAP2; auto.
eapply map_somes_split_inv in MAP2. des. subst.
eapply map_somes_one in MAP1. des. subst.
exists (l0 ++ l1), a, (l4 ++ l3). splits; auto.
{ repeat erewrite <- List.app_assoc. auto. }
{ erewrite map_somes_split. erewrite MAP1.
erewrite List.app_nil_end. auto. }
{ erewrite map_somes_split. erewrite MAP3. ss. }
Qed.
Definition writing_loc_prom (prom: Memory.t)
(te: ThreadEvent.t): option (Loc.t * Time.t) :=
match te with
| ThreadEvent.write loc _ to _ _ ord =>
if Ordering.le ord Ordering.relaxed then
match Memory.get loc to prom with
| Some (_, Message.concrete _ _) => Some (loc, to)
| _ => None
end
else None
| ThreadEvent.update loc _ to _ _ _ _ _ ord =>
if Ordering.le ord Ordering.relaxed then
match Memory.get loc to prom with
| Some (_, Message.concrete _ _) => Some (loc, to)
| _ => None
end
else None
| _ => None
end.
Lemma final_event_trace_post te tr0 tr1
(FINAL: final_event_trace te tr1)
:
final_event_trace te (tr0 ++ tr1).
Proof.
ginduction tr0; eauto. i. ss. econs; eauto.
Qed.
Lemma cancel_normal_normals_after_normal tr0 lc te tr1
(CANCELNORMAL: cancel_normal_trace (tr0 ++ (lc, te) :: tr1))
(NORMAL: ~ ThreadEvent.is_cancel te)
:
List.Forall (fun em => <<SAT: (fun e => ~ ThreadEvent.is_cancel e) (snd em)>>) tr1.
Proof.
unfold cancel_normal_trace in *. des.
eapply List.Forall_forall. ii.
eapply List.in_split in H. des. subst.
ginduction tr_cancel.
{ i. ss. subst. eapply List.Forall_forall in NORMAL0; eauto.
eapply List.in_or_app. right. ss. right.
eapply List.in_or_app. right. ss. auto. }
{ i. inv CANCEL. destruct tr0.
{ ss. inv EQ. ss. }
ss. inv EQ. eapply IHtr_cancel; eauto.
}
Qed.
Lemma no_concrete_promise_concrete_decrease_write prom0 mem0 loc from to val released prom1 mem1 kind
(WRITE: Memory.write prom0 mem0 loc from to val released prom1 mem1 kind)
loc0 ts0 from0 val0 released0
(GET: Memory.get loc0 ts0 prom1 = Some (from0, Message.concrete val0 released0))
:
exists from1 released1,
(<<GET: Memory.get loc0 ts0 prom0 = Some (from1, Message.concrete val0 released1)>>).
Proof.
inv WRITE. erewrite Memory.remove_o in GET; eauto. des_ifs. guardH o.
inv PROMISE.
{ erewrite Memory.add_o in GET; eauto. des_ifs.
{ ss. unguard. des; clarify. }
{ esplits; eauto. }
}
{ erewrite Memory.split_o in GET; eauto. des_ifs.
{ ss. unguard. des; clarify. }
{ ss. unguard. des; clarify. eapply Memory.split_get0 in PROMISES. des.
eapply Memory.remove_get1 in GET2; eauto. }
{ esplits; eauto. }
}
{ erewrite Memory.lower_o in GET; eauto. des_ifs.
{ ss. unguard. des; clarify. }
{ esplits; eauto. }
}
{ erewrite Memory.remove_o in GET; eauto. des_ifs. }
Qed.
Lemma no_concrete_promise_concrete_decrease_steps lang (th0 th1: Thread.t lang) tr
(STEPS: Trace.steps tr th0 th1)
(NOPROMISE: List.Forall (fun em => <<SAT: (promise_free \1/ ThreadEvent.is_reserve) (snd em)>>) tr)
loc ts from val released
(GET: Memory.get loc ts (Local.promises (Thread.local th1)) =
Some (from, Message.concrete val released))
:
exists from0 released0,
(<<GET: Memory.get loc ts (Local.promises (Thread.local th0)) =
Some (from0, Message.concrete val released0)>>).
Proof.
ginduction STEPS; eauto. i. subst. inv NOPROMISE. guardH H1. ss.
eapply IHSTEPS in GET; eauto. des. inv STEP.
{ unguard. inv STEP0; ss. inv LOCAL. inv PROMISE; ss.
{ des_ifs; des; ss. erewrite Memory.add_o in GET0; eauto. des_ifs. eauto. }
{ des; ss; clarify. }
{ clear H1. erewrite Memory.lower_o in GET0; eauto. des_ifs; eauto.
ss. des; clarify. eapply Memory.lower_get0 in PROMISES; eauto.
des. inv MSG_LE. esplits; eauto. }
{ des; ss. erewrite Memory.remove_o in GET0; eauto. des_ifs; eauto. }
}
{ inv STEP0. inv LOCAL; eauto.
{ inv LOCAL0; ss; eauto. }
{ inv LOCAL0; ss; eauto.
eapply no_concrete_promise_concrete_decrease_write; eauto. }
{ inv LOCAL1; ss; eauto. inv LOCAL2; ss; eauto.
eapply no_concrete_promise_concrete_decrease_write; eauto. }
{ inv LOCAL0; ss; eauto. }
{ inv LOCAL0; ss; eauto. }
}
Qed.
Lemma write_become_unchangable prom0 mem0 loc from to val released prom1 mem1 kind
(WRITE: Memory.write prom0 mem0 loc from to val released prom1 mem1 kind)
:
unchangable mem1 prom1 loc to from (Message.concrete val released).
Proof.
inv WRITE. eapply Memory.remove_get0 in REMOVE. des.
eapply Memory.promise_get0 in PROMISE.
{ des. econs; eauto. }
{ inv PROMISE; ss. }
Qed.
Definition writing_loc
(te: ThreadEvent.t): option (Loc.t * Time.t) :=
match te with
| ThreadEvent.write loc _ to _ _ _ => Some (loc, to)
| ThreadEvent.update loc _ to _ _ _ _ _ _ => Some (loc, to)
| _ => None
end.
Lemma writed_unchangable lang (th0 th1: Thread.t lang) tr lc we loc ts
(STEPS: Trace.steps tr th0 th1)
(IN: List.In (lc, we) tr)
(WRITING: writing_loc we = Some (loc, ts))
:
exists from msg,
(<<UNCH: unchangable (Thread.memory th1) (Local.promises (Thread.local th1)) loc ts from msg>>).
Proof.
ginduction STEPS; eauto; ss. i. subst. ss. des.
{ clarify. inv STEP; inv STEP0; inv LOCAL; ss.
{ clarify. inv LOCAL0. eapply write_become_unchangable in WRITE.
eapply unchangable_trace_steps_increase in STEPS; eauto. }
{ clarify. inv LOCAL2. eapply write_become_unchangable in WRITE.
eapply unchangable_trace_steps_increase in STEPS; eauto. }
}
{ exploit IHSTEPS; eauto. }
Qed.
Definition pf_consistent_super_strong_promises_list lang (e0:Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
(pl: list (Loc.t * Time.t))
: Prop :=
(<<COMPLETE: forall loc from to val released
(GET: Memory.get loc to (Local.promises (Thread.local e0)) = Some (from, Message.concrete val released)),
List.In (loc, to) pl>>) /\
(<<CONSISTENT: forall
pl0 loc to pl1
(PROMISES: pl = pl0 ++ (loc, to) :: pl1)
mem1 tm sc max
(FUTURE: Memory.future_weak (Thread.memory e0) mem1)
(CLOSED: Memory.closed mem1)
(LOCAL: Local.wf (Thread.local e0) mem1)
(MWF: memory_times_wf times mem1)
(MAX: concrete_promise_max_timemap
((Thread.memory e0))
((Local.promises (Thread.local e0)))
max),
(exists ftr0 ftr1 ftr_reserve ftr_cancel e1 f we val,
(<<STEPS: Trace.steps (ftr0 ++ ftr_reserve) (Thread.mk _ (Thread.state e0) (Thread.local e0) sc mem1) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: ((promise_free \1/ ThreadEvent.is_reserve)
/1\ no_sc
/1\ no_read_msgs (fun loc ts => ~ (covered loc ts (Local.promises (Thread.local e0)) \/ concrete_promised (Thread.memory e0) loc ts \/ Time.lt (tm loc) ts))
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) (ftr0 ++ ftr_reserve) >>) /\
(<<RESERVE: List.Forall (fun em => <<SAT: (ThreadEvent.is_reserve
/1\ wf_time_evt times
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))) (snd em)>>) ftr_reserve>>) /\
(<<CANCEL: List.Forall (fun em => <<SAT: (ThreadEvent.is_cancel /1\ wf_time_evt times) (snd em)>>) ftr_cancel>>) /\
(<<EVENTSCERT: List.Forall (fun em => <<SAT: ((promise_free \1/ ThreadEvent.is_reserve)
/1\ no_sc
/1\ no_read_msgs (fun loc ts => ~ (covered loc ts (Local.promises (Thread.local e0)) \/ concrete_promised (Thread.memory e0) loc ts \/ Time.lt (tm loc) ts))
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) (ftr_cancel ++ ftr1) >>) /\
(<<CONSISTENT: pf_consistent_super_strong e1 (ftr_cancel ++ ftr1) times>>) /\
(<<PROMCONSISTENT: Local.promise_consistent (Thread.local e1)>>) /\
(<<MAPLT: mapping_map_lt f>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max loc))
(MAP: f loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max loc) fts) (MAP: f loc ts fts),
Time.lt (max loc) ts /\ Time.le (tm loc) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f (snd fem) (snd em)) tr (ftr0 ++ ftr1)>>) /\
(<<GOOD: good_future tm mem1 (Thread.memory e1)>>) /\
(<<SC: (Thread.sc e1) = sc>>) /\
(<<FINAL: final_event_trace we (ftr0 ++ ftr_reserve)>>) /\
(<<WRITING: relaxed_writing_event loc to val we>>) /\
(<<SOUND: forall loc0 from0 to0 val0 released0
(GET: Memory.get loc0 to0 (Local.promises (Thread.local e1)) = Some (from0, Message.concrete val0 released0)),
exists from0' released0',
(<<GET: Memory.get loc0 to0 (Local.promises (Thread.local e0)) = Some (from0', Message.concrete val0 released0')>>)>>) /\
(<<WRITTEN: forall loc0 to0
(IN: List.In (loc0, to0) (pl0 ++ [(loc, to)])),
Memory.get loc0 to0 (Local.promises (Thread.local e1)) = None>>)) \/
(exists ftr e1 f,
(<<STEPS: Trace.steps ftr (Thread.mk _ (Thread.state e0) (Thread.local e0) sc mem1) e1>>) /\
(<<EVENTS: List.Forall (fun em => <<SAT: (promise_free
/1\ no_sc
/1\ no_read_msgs (fun loc ts => ~ (covered loc ts (Local.promises (Thread.local e0)) \/ concrete_promised (Thread.memory e0) loc ts \/ Time.lt (tm loc) ts))
/1\ write_not_in (fun loc ts => (<<TS: Time.le ts (tm loc)>>) /\ (<<PROM: ~ covered loc ts (Local.promises (Thread.local e0))>>))
/1\ wf_time_evt times) (snd em)>> /\ <<TAU: ThreadEvent.get_machine_event (snd em) = MachineEvent.silent>>) ftr >>) /\
(<<CANCELNORMAL: cancel_normal_trace ftr>>) /\
(<<MAPLT: mapping_map_lt f>>) /\
(<<MAPIDENT: forall loc ts fts
(TS: Time.le fts (max loc))
(MAP: f loc ts fts),
ts = fts>>) /\
(<<BOUND: forall loc ts fts (TS: Time.lt (max loc) fts) (MAP: f loc ts fts),
Time.lt (max loc) ts /\ Time.le (tm loc) fts>>) /\
(<<TRACE: List.Forall2 (fun em fem => tevent_map_weak f (snd fem) (snd em)) tr ftr>>) /\
(<<GOOD: good_future tm mem1 (Thread.memory e1)>>) /\
(<<SC: (Thread.sc e1) = sc>>) /\
(<<PROMCONSISTENT: Local.promise_consistent (Thread.local e1)>>) /\
(__guard__((exists st',
(<<LOCAL: Local.failure_step (Thread.local e1)>>) /\
(<<FAILURE: Language.step lang ProgramEvent.failure (@Thread.state lang e1) st'>>)))))
>>)
.
Lemma pf_consistent_super_strong_promises_list_exists lang (e0: Thread.t lang)
(tr : Trace.t)
(times: Loc.t -> (Time.t -> Prop))
(CONSISTENT: pf_consistent_super_strong e0 tr times)
(CLOSED: Memory.closed (Thread.memory e0))
(LOCAL: Local.wf (Thread.local e0) (Thread.memory e0))
(DIVERGE: forall loc n, times loc (incr_time_seq n))
:
exists pl,
(<<PROMISES: pf_consistent_super_strong_promises_list e0 tr times pl>>)
.
Proof.
assert (exists dom,
(<<SOUND: forall loc to
(IN: List.In (loc, to) dom),
exists from val released,
(<<GET: Memory.get loc to (Local.promises (Thread.local e0)) = Some (from, Message.concrete val released)>>)>>) /\
(<<COMPLETE: forall loc from to val released
(GET: Memory.get loc to (Local.promises (Thread.local e0)) = Some (from, Message.concrete val released)),
List.In (loc, to) dom>>)).
{ inv LOCAL. inv FINITE.
hexploit (list_filter_exists
(fun (locto: Loc.t * Time.t) =>
let (loc, to) := locto in
exists from val released,
Memory.get loc to (Local.promises (Thread.local e0)) = Some (from, Message.concrete val released)) x).
{ i. des. exists l'. splits.
{ i. eapply COMPLETE in IN. des. esplits; eauto. }
{ i. eapply COMPLETE. esplits; eauto. }
}
}
des.
set (pl := map_somes (fun lce => writing_loc_prom (Local.promises (Thread.local e0)) (snd lce)) tr).
destruct (classic (exists loc ts,
(<<IN: List.In (loc, ts) dom>>) /\
(<<NIN: ~ List.In (loc, ts) pl>>))) as [EXIST|ALL].
{ exists dom. split.
{ ii. eapply COMPLETE in GET. auto. }
ii. exploit CONSISTENT; eauto. i. des. right. esplits; eauto.
unguard. des; eauto. exfalso.
eapply SOUND in IN. des.
exploit WRITES; eauto. i. des.
eapply list_Forall2_in in IN; eauto. des. destruct a. ss.
assert (WRITE: writing_loc_prom (Local.promises (Thread.local e0)) t0 = Some (loc0, ts)).
{ inv WRITING; inv SAT; ss.
{ rewrite ORD. replace ts with to0 in *.
{ erewrite GET. auto. }
eapply MAPIDENT; eauto.
eapply MAX in GET. auto. }
{ rewrite ORD. replace ts with to0 in *.
{ erewrite GET. auto. }
eapply MAPIDENT; eauto.
eapply MAX in GET. auto. }
}
eapply NIN. eapply map_somes_in; eauto.
}
{ exists pl. split.
{ ii. eapply COMPLETE in GET. eapply NNPP. ii.
eapply ALL. esplits; eauto. }
ii. left. exploit (@CONSISTENT mem1 tm sc max); eauto.
hexploit map_somes_split_inv_one; try apply PROMISES. i. des. subst.
dup TRACE.
eapply List.Forall2_app_inv_l in TRACE. des. subst.
dup TRACE. eapply List.Forall2_app_inv_l in TRACE. des. subst.
inv TRACE3. inv H3. destruct y, a. ss.
assert (TO: forall fto (MAP: f loc to fto), to = fto).
{ i. destruct (Time.le_lt_dec fto (max loc)).
{ eapply MAPIDENT; eauto. }
dup l. eapply BOUND in l; eauto. des.
exfalso. eapply Time.lt_strorder. eapply TimeFacts.lt_le_lt.
{ eapply l. }
unfold writing_loc_prom in MAP1. des_ifs.
{ eapply MAX in Heq0. auto. }
{ eapply MAX in Heq0. auto. }
}
assert (WRITING: exists val0,
(<<WRITING: relaxed_writing_event loc to val0 t0>>)).
{ unfold writing_loc_prom in MAP1. des_ifs.
{ inv H1; ss. replace fto with to; eauto. }
{ inv H1; ss. replace fto with to; eauto. }
} des.
hexploit SPLIT; eauto.
{ clear - WRITING0 CANCELNORMAL. erewrite <- List.app_assoc in CANCELNORMAL.
eapply cancel_normal_normals_after_normal; eauto. inv WRITING0; ss. } i. des.
eexists (l1'0 ++ [(t, t0)]), l2', ftr_reserve, ftr_cancel. esplits; eauto.
{ eapply Forall_app.
{ eapply Forall_app_inv in EVENTS. des.
eapply List.Forall_impl; eauto. i. ss. des. splits; auto. }
{ eapply List.Forall_impl; eauto. i. ss. des. destruct a. ss. splits; auto.
{ destruct t4; ss. }
{ destruct t4; ss. }
{ destruct t4; ss. }
}
}
{ eapply Forall_app.
{ eapply List.Forall_impl; eauto. i. ss. des. destruct a. ss. splits; auto.
{ destruct t4; ss. destruct kind; ss; des_ifs. auto. }
{ destruct t4; ss. }
{ destruct t4; ss. }
{ destruct t4; ss. des_ifs. }
{ destruct t4; ss. }
}
{ eapply Forall_app_inv in EVENTS. des.
eapply List.Forall_impl; eauto. i. ss. des. splits; auto. }
}
{ destruct e2. eapply no_sc_any_sc_traced in STEPS0; ss.
{ des. exploit Trace.steps_future; try apply STEPS1; eauto; ss.
{ instantiate (1:=TimeMap.bot). ss.
eapply Memory.closed_timemap_bot; eauto. eapply CLOSED0. }
i. des. hexploit pf_consistent_super_strong_same_sc.
{ eapply pf_consistent_super_strong_not_easy; try apply CONSISTENT0; eauto.
{ ss. eapply memory_times_wf_traced in STEPS1; eauto. eapply Forall_app.
{ eapply Forall_app_inv in EVENTS. des. eapply List.Forall_impl; eauto.
i. ss. des; auto. }
{ eapply List.Forall_impl; eauto. i. ss. des; auto. }
}
}
i. eauto. }
{ eapply Forall_app.
{ eapply Forall_app_inv in EVENTS. des. eapply List.Forall_impl; eauto.
i. ss. des; auto. }
{ eapply List.Forall_impl; eauto. i. ss. des; auto.
destruct a. ss. destruct t4; ss. }
}
}
{ erewrite <- List.app_assoc. eapply final_event_trace_post.
econs. eapply List.Forall_impl; eauto. i. ss.
des. destruct a. unfold ThreadEvent.is_reserve in *. des_ifs. }
{ i. eapply no_concrete_promise_concrete_decrease_steps in STEPS0; eauto.
eapply Forall_app.
{ eapply Forall_app_inv in EVENTS. des.
eapply List.Forall_impl; eauto. i. ss. des. splits; auto. }
{ eapply List.Forall_impl; eauto. i. ss. des. destruct a. ss. splits; auto. }
}
{ i. assert (WRITED: exists flc fwe,
(<<IN: List.In (flc, fwe) (l0 ++ [(t1, t2)])>>) /\
(<<WRITING: writing_loc_prom (Local.promises (Thread.local e0)) fwe = Some (loc0, to0)>>)).
{ apply List.in_app_or in IN. des.
{ eapply map_somes_in_rev in IN. des. destruct a. ss. esplits; eauto.
eapply List.in_or_app; eauto. }
{ inv IN; clarify. esplits; eauto.
eapply List.in_or_app; ss; eauto. }
} des.
assert (TO0: forall fto (MAP: f loc0 to0 fto), to0 = fto).
{ i. destruct (Time.le_lt_dec fto (max loc0)).
{ eapply MAPIDENT; eauto. }
dup l. eapply BOUND in l; eauto. des.
exfalso. eapply Time.lt_strorder. eapply TimeFacts.lt_le_lt.
{ eapply l. }
clear - WRITING MAX.
unfold writing_loc_prom in WRITING. des_ifs.
{ eapply MAX in Heq0. auto. }
{ eapply MAX in Heq0. auto. }
}
assert (WRITED: exists lc we,
(<<IN: List.In (lc, we) (l1'0 ++ [(t, t0)])>>) /\
(<<WRITING: writing_loc we = Some (loc0, to0)>>)).
{ eapply list_Forall2_in2 in IN0; eauto. des. destruct b. ss. esplits; eauto.
clear - TO0 WRITING SAT.
unfold writing_loc_prom in WRITING. des_ifs.
{ inv SAT; ss. eapply TO0 in TO. subst. auto. }
{ inv SAT; ss. eapply TO0 in TO. subst. auto. }
}
des. eapply writed_unchangable in STEPS0; cycle 1.
{ eapply List.in_or_app. left. eauto. }
{ eauto. }
{ des. inv UNCH. auto. }
}
}
Qed.
|
The Coldrum Long Barrow , also known as the Coldrum Stones and the <unk> Stones , is a chambered long barrow located near to the village of Trottiscliffe in the south @-@ eastern English county of Kent . Constructed circa 4000 BCE , during Britain 's Early Neolithic period , today it survives only in a ruined state .
|
text \<open> Version 0.5, last changed 2019-01-30
(C) fovefi ltd, www.fovefi.co
(author: Lukas Bulwahn [[email protected]], comments by Manfred Kerber [[email protected]])
Dually licenced under
Creative Commons Attribution (CC-BY) 4.0 [https://creativecommons.org/licenses/by/4.0/]
ISC License (1-clause BSD License) [https://www.isc.org/downloads/software-support-policy/isc-license/]
See LICENSE files for details.
(Rationale for this dual licence: http://arxiv.org/abs/1107.3212)
In the following, an executable definition of the percentile function is given that is
close to the one used in OpenSIMM, a system with a standard implementation for the computation
of risk.
\<close>
theory Percentile_Code
imports Percentile
begin
section \<open>Code Generation of Percentile\<close>
paragraph \<open>The percentile definition close to the Java implementation\<close>
text \<open> In the Java code follows a check that the level is below 1 - 1/(2*size).
* If not, it throws an exception. In the Isabelle implementation (there is no exception
* handling in Isabelle), the code is underspecified, that is, no specific values will be
* returned for larger values. This will be fixed in the definition of the percentile function
* in the next section.
\<close>
text \<open> An integer greater equal 0 considered as a real number is the same as the integer first considered
as a natural number and this then considered as a real number. \<close>
lemma real_of_int:
assumes "0 \<le> i"
shows "real_of_int i = real (nat i)"
by (simp add: assms)
text \<open> The value of the minimum of the domain of equidistant point is determined. \<close>
lemma Min_equidistant_points_on_unit_interval_of_bounded:
fixes x :: real
assumes "ys \<noteq> []"
assumes "1 / (2 * length ys) < x"
assumes "x \<le> 1 - 1 / (2 * length ys)"
shows "Min {x' \<in> dom (equidistant_points_on_unit_interval_of ys). x \<le> x'} = (ceiling (length ys * x - 0.5) + 0.5) / length ys"
(is "Min ?A = ?expr")
proof (rule Min_eqI)
text \<open>let ?A = "{x' \<in> dom (equidistant_points_on_unit_interval_of ys). x \<le> x'}"\<close>
show "finite ?A" by simp
show "?expr \<le> y" if "y \<in> ?A" for y
proof -
from that \<open>ys \<noteq> []\<close> obtain n where "y = (real n + 1 / 2) / real (length ys)" and "x \<le> y"
unfolding equidistant_points_on_unit_interval_of_def
apply auto done
obtain i where "i = int n" by auto
from this \<open>y = _\<close> have y: "y = (real_of_int i + 1 / 2) / real (length ys)"
by simp
have "i \<ge> ceiling (length ys * x - 0.5)"
proof -
have "x \<le> (real_of_int i + 1 / 2) / real (length ys)"
using \<open>x \<le> y\<close> y by blast
from this have "length ys * x \<le> (real_of_int i + 1 / 2)"
apply -
apply (frule mult_left_mono[where c="real (length ys)"])
apply simp
by (simp add: assms(1))
find_theorems "_ * _ \<le> _ * _"
from this have "length ys * x - 1 / 2 \<le> real_of_int i" by linarith
from this show ?thesis
by (simp add: ceiling_le)
qed
from this y have "y \<ge> (real_of_int (ceiling (length ys * x - 0.5)) + 1 / 2) / real (length ys)"
apply simp
find_theorems "_ / _ \<le> _ / _"
apply (rule divide_right_mono)
apply simp
apply simp
done
from this show ?thesis by simp
qed
show "?expr \<in> ?A"
proof -
from assms have "0 \<le> real (length ys) * x - 1 / 2"
apply auto
by (simp add: Groups.mult_ac(2) divide_less_eq)
from this have "0 \<le> \<lceil>real (length ys) * x - 1 / 2\<rceil>" by simp
from this have a: "real_of_int \<lceil>real (length ys) * x - 1 / 2\<rceil> = real (nat \<lceil>real (length ys) * x - 1 / 2\<rceil>)"
by simp
have b: "nat \<lceil>real (length ys) * x - 1 / 2\<rceil> \<in> {0..<length ys}"
proof -
have "real (length ys) * x - 1 / 2 \<le> (length ys - 1)"
proof -
have "real (length ys) * x - 1 / 2 \<le> real (length ys) * (1 - 1 / real (2 * length ys)) - 1 / 2"
using assms(1, 3) by simp
also have "\<dots> = real (length ys) - 1"
apply auto
apply (subst right_diff_distrib)
apply simp
by (simp add: assms(1))
also have "\<dots> = real (length ys - 1)"
by (metis One_nat_def Suc_pred assms(1) diff_Suc_Suc diff_is_0_eq length_greater_0_conv of_nat_1 of_nat_diff zero_diff)
finally show ?thesis .
qed
text \<open>have "\<lceil>real (length ys) * x - 1 / 2\<rceil> \<ge> 0" s_orry\<close>
from this have a: "\<lceil>real (length ys) * x - 1 / 2\<rceil> \<le> \<lceil>real (length ys - 1)\<rceil>"
using ceiling_mono by blast
have "\<lceil>real (length ys - 1)\<rceil> = int (length ys - 1)" by simp
from a this have "nat \<lceil>real (length ys) * x - 1 / 2\<rceil> < length ys"
by (smt assms(1) int_nat_eq length_greater_0_conv nat_less_le of_nat_0_less_iff of_nat_1 of_nat_diff of_nat_less_imp_less zero_less_diff)
from this show ?thesis
apply auto done
qed
have "(real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> + 5 / 10) / real (length ys)
\<in> dom (equidistant_points_on_unit_interval_of ys)"
unfolding dom_equidistant_points_on_unit_interval_of
apply auto
apply (subst a)
apply (rule image_eqI)
apply (rule refl)
apply (rule b) done
find_theorems "dom (equidistant_points_on_unit_interval_of _)"
moreover have "x \<le> (real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> + 5 / 10) / real (length ys)"
proof -
have "real (length ys) > 0" (* only need \<ge> *)
by (simp add: assms)
have a: "real (length ys) * x - 5 / 10 \<le> real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil>"
by linarith
have "x \<le> ((real (length ys) * x - 5 / 10) + 5 / 10) / real (length ys)"
using \<open>real (length ys) > 0\<close> by auto
also have "\<dots> \<le> (real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> + 5 / 10) / real (length ys)"
using \<open>real (length ys) > 0\<close> a
apply -
apply (rule divide_right_mono)
apply linarith
apply simp done
finally show ?thesis .
qed
ultimately show ?thesis by auto
qed
qed
text \<open> A property of the ceiling function. \<close>
lemma ceiling_minus_leq:
assumes "a + b \<ge> 1"
shows "real_of_int \<lceil>x - a\<rceil> - b \<le> x"
using assms by linarith
text \<open> Relationship between floor and ceiling (floor plus 1 is less equal ceiling). \<close>
lemma floor_leq_ceiling:
fixes x :: real
assumes "x \<notin> real_of_int ` UNIV"
shows "1 + real_of_int (floor x) \<le> real_of_int (ceiling x)"
using assms by (smt UNIV_I ceiling_correct image_eqI int_less_real_le le_floor_iff)
text \<open> If i < y for two integers then i \<le> y - 1 (when converted to real).\<close>
lemma less_to_leq:
fixes y :: real
assumes "real i < y"
assumes "y \<in> real_of_int ` UNIV"
shows "real i \<le> y - 1"
proof -
from assms(2) obtain j where "y = real_of_int j"
apply auto done
obtain k where "j = int k"
by (smt \<open>y = real_of_int j\<close> assms(1) int_less_real_le nat_0_le of_int_1 of_nat_0_le_iff)
from this \<open>y = _\<close> assms(1) show ?thesis by auto
qed
text \<open> The value of the maximum of the domain of equidistant point is determined. \<close>
lemma Max_equidistant_points_on_unit_interval_of_bounded:
fixes x :: real
assumes "ys \<noteq> []"
assumes "1 / (2 * length ys) < x" "x \<le> 1 - 1 / (2 * length ys)"
shows "Max {x' \<in> dom (equidistant_points_on_unit_interval_of ys). x' < x} = (ceiling (length ys * x - 0.5) - 0.5) / length ys"
(is "_ = ?expr")
proof -
let ?A = "{x' \<in> (\<lambda>x. (1 / length ys) * (x + 0.5)) ` {0..<length ys}. x' < x}"
have "Max ?A = ?expr"
find_theorems "_ ` _" "Max"
proof (rule Max_eqI)
show "finite ?A" by simp
show "y \<le> ?expr" if "y \<in> ?A" for y
proof -
show ?thesis
proof (cases "real (length ys) * x - 1 / 2 \<in> range real_of_int")
case True
from that obtain i where "i \<in> {0..<length ys}"
and y: "y = 1 / real (length ys) * (real i + 5 / 10)" and "y < x" by auto
have "(real i + 5 / 10) < real (length ys) * x"
by (metis \<open>y < x\<close> assms(1) divide_less_eq length_greater_0_conv mult.commute mult_numeral_1 numeral_One of_nat_0_less_iff times_divide_eq_right y)
from this have "real i < real (length ys) * x - 0.5"
by linarith
from this have "real i \<le> real (length ys) * x - 1.5"
apply -
apply (frule less_to_leq)
apply (simp add: True)
by linarith
from this have "(real i + 5 / 10) \<le> real (length ys) * x - 1"
apply simp done
have "1 / real (length ys) > 0" by (simp add: assms(1))
from this assms y have y2: "y \<le> 1 / real (length ys) * (real (length ys) * x - 1)"
using \<open>real i + 5 / 10 \<le> real (length ys) * x - 1\<close> real_mult_le_cancel_iff2 by blast
have "real (length ys) * x - 1 / 2 \<le> real_of_int \<lceil>real (length ys) * x - 1 / 2\<rceil>"
by simp
from this have "real (length ys) * x - 1 \<le> real_of_int \<lceil>real (length ys) * x - 1 / 2\<rceil> - 1 / 2"
proof -
have "real (length ys) * x - 1 = (real (length ys) * x - 1 / 2) - 1 / 2" by simp
also have "\<dots> \<le> real_of_int \<lceil>real (length ys) * x - 1 / 2\<rceil> - 1 / 2"
by linarith
finally show ?thesis .
qed
from this y2 show ?thesis
apply auto
find_theorems "?a \<le> ?b \<Longrightarrow> ?b \<le> ?c \<Longrightarrow> ?a \<le> ?c"
apply (rule order.trans)
apply assumption
apply (rule divide_right_mono)
apply simp apply simp done
find_theorems "_ / _ \<le> _ / _"
next
case False
then show ?thesis
proof -
have "y \<le> 1 / real (length ys) * (real_of_int \<lfloor>real (length ys) * x - 5 / 10\<rfloor> + 5 / 10)"
proof -
from that obtain i where "i \<in> {0..<length ys}"
and "y = 1 / real (length ys) * (real i + 5 / 10)" and "y \<le> x" by auto
have "i \<le> \<lfloor>real (length ys) * x - 5 / 10\<rfloor>"
proof -
have a: "1 / real (length ys) * (real i + 5 / 10) \<le> x"
using \<open>y = _\<close> \<open>y \<le> x\<close> by blast
have "(real i + 5 / 10) \<le> real (length ys) * x"
proof -
have "(real i + 5 / 10) = real (length ys) * (1 / real (length ys) * (real i + 5 / 10))"
by (simp add: assms(1))
also have "\<dots> \<le> real (length ys) * x"
using a mult_left_mono of_nat_0_le_iff by blast
finally show ?thesis .
qed
from this have "real i \<le> real (length ys) * x - 5 / 10" by linarith
from this show ?thesis by linarith
qed
from this \<open>y = _\<close> show ?thesis
proof -
have "real (length ys) > 0" by (simp add: assms(1))
from \<open>i \<le> floor _\<close> have "(real i + 5 / 10) \<le> real_of_int \<lfloor>real (length ys) * x - 5 / 10\<rfloor> + 5 / 10"
by linarith
from this \<open>y = _\<close> \<open>real (length ys) > 0\<close> show ?thesis
using real_mult_le_cancel_iff2 by fastforce
qed
qed
also have "\<dots> \<le> (real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> - 5 / 10) / real (length ys)"
proof -
from False
have "(real_of_int \<lfloor>real (length ys) * x - 5 / 10\<rfloor> + 5 / 10) \<le> (real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> - 5 / 10)"
apply simp
apply (rule floor_leq_ceiling)
apply assumption
done
from this show ?thesis
apply simp
apply (rule divide_right_mono)
apply simp apply simp done
qed
finally show ?thesis .
qed
qed qed
show "?expr \<in> ?A"
proof -
have "?expr \<in> (\<lambda>x. 1 / real (length ys) * (real x + 5 / 10)) ` {0..<length ys}"
proof
have "real (length ys) * x - 1 / 2 > 0"
by (metis assms(1) assms(2) diff_gt_0_iff_gt divide_divide_eq_left divide_less_eq length_greater_0_conv mult.commute of_nat_0_less_iff of_nat_mult of_nat_numeral)
from this have "nat \<lceil>real (length ys) * x - 1 / 2\<rceil> \<ge> 1"
by linarith
from this show "(real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> - 5 / 10) / real (length ys) =
1 / real (length ys) * (real (nat \<lceil>real (length ys) * x - 5 / 10\<rceil> - 1) + 5 / 10)"
using \<open>ys \<noteq> []\<close>
apply auto done
have "real (length ys) \<ge> 0" by auto
have "x \<le> 1"
by (smt assms(3) divide_less_0_1_iff of_nat_0_le_iff)
from this have "real (length ys) * x \<le> length ys"
by (simp add: mult_left_le)
from this \<open>real (length ys) \<ge> 0\<close> have "real (length ys) * x \<le> length ys + 1 / 2"
by linarith
from this have "real (length ys) * x - 1 / 2 \<le> length ys"
by fastforce
from this show "nat \<lceil>real (length ys) * x - 5 / 10\<rceil> - 1 \<in> {0..<length ys}"
apply auto
using \<open>1 \<le> nat \<lceil>real (length ys) * x - 1 / 2\<rceil>\<close> by linarith
qed
moreover have "?expr < x"
proof -
have "real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> < real (length ys) * x + 5 / 10"
by linarith
then have "real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> < x * real (length ys) + 5 / 10"
by (simp add: mult.commute)
have "real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> - 5 / 10 < x * real (length ys)"
using \<open>real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> < x * real (length ys) + 5 / 10\<close> by linarith
from this show "(real_of_int \<lceil>real (length ys) * x - 5 / 10\<rceil> - 5 / 10) / real (length ys) < x"
apply auto
by (simp add: assms(1) divide_less_eq)
qed
ultimately show ?thesis by auto
qed
qed
from this show ?thesis
unfolding equidistant_points_on_unit_interval_of_def by simp
qed
text \<open> The lemma determines the values of equidistant point on the unit interval. \<close>
lemma equidistant_points_on_unit_interval_of_eq_nth2:
fixes i :: int
assumes "0 \<le> i" "nat i < length ys"
shows "the (equidistant_points_on_unit_interval_of ys ((real_of_int i + 5 / 10) / size ys)) = ys ! (nat i)"
proof -
let ?xs = "map (\<lambda>x. (real x + 1 / 2) / real (length ys)) [0..<length ys]"
have "distinct ?xs" by (auto intro!: inj_onI simp add: distinct_map)
have eq: "(real_of_int i + 1 / 2) / real (length ys) = ?xs ! nat i"
using assms by auto
show ?thesis
unfolding equidistant_points_on_unit_interval_of_def
apply simp
apply (subst eq)
thm map_of_zip_nth
apply (subst map_of_zip_nth)
apply simp
apply (rule \<open>distinct ?xs\<close>)
apply (rule assms)
apply simp done
qed
text \<open> The lemma gives an alternative characterization of the values of equidistant point on the unit interval. \<close>
lemma equidistant_points_on_unit_interval_of_eq_nth1:
fixes i :: int
assumes "1 \<le> i" "i \<le> length ys"
shows "the (equidistant_points_on_unit_interval_of ys ((real_of_int i - 5 / 10) / size ys)) = ys ! nat (i - 1)"
proof -
(* todo: size ys = real (length ys); which is better to write down? *)
let ?f = "\<lambda>x. the (equidistant_points_on_unit_interval_of ys (x / size ys))"
have "?f (real_of_int i - 5 / 10) = ?f (real_of_int (i - 1) + 5 / 10)" by force
also have "\<dots> = ys ! nat (i - 1)"
using assms by (simp only: equidistant_points_on_unit_interval_of_eq_nth2)
finally show ?thesis .
qed
text \<open> The definition contains an executable version of the percentile function which is close to the
Java implementation in the OpenSIMM implementation. \<close>
definition percentile_impl :: "real list \<Rightarrow> real \<Rightarrow> real"
where
"percentile_impl values level =
(let (size :: real) = (real (length values));
(sorted :: (real list)) = sort values;
i = (ceiling (size * level - 0.5));
(lower :: real) = (i - 0.5) / size;
(upper ::real) = (i + 0.5) / size;
\<comment>\<open>Note that we convert i to a nat since we want to use it
as an index in a list. This means that we automatically
have values greater equal 0\<close>
(lower_value :: real) = sorted ! (nat (i-1));
(upper_value :: real) = sorted ! (nat i)
in lower_value + (level - lower) * (upper_value - lower_value) / (upper - lower))"
text \<open> The lemma states the equivalence of the abstract definition of the percentile function from
the Percentile theory and the computational version in the standard interval, except the left limit. \<close>
lemma percentile_java_equiv_except_left:
assumes "values \<noteq> []"
assumes "1 / real (2 * length values) < level" (* todo: lesseq instead of less *)
assumes "level \<le> 1 - 1 / real (2 * length values)"
shows "Percentile.percentile values level = percentile_impl values level"
proof -
from assms(2) have "level \<noteq> 1 / real (2 * length values)" by blast
let ?def = "(let p = equidistant_points_on_unit_interval_of (sort values);
(x1, x2) = (Max {x' \<in> dom p. x' < level}, Min {x' \<in> dom p. level \<le> x'});
(y1, y2) = (the (p x1), the (p x2))
in linear (x1, y1) (x2, y2) level)"
{
fix size sorted i lower upper lower_value upper_value
assume "size = real (length values)"
assume "sorted = sort values"
assume "i = \<lceil>size * level - 5 / 10\<rceil>"
assume "lower = (real_of_int i - 5 / 10) / size"
assume "upper = (real_of_int i + 5 / 10) / size"
assume "lower_value = sorted ! nat (i - 1)"
assume "upper_value = sorted ! nat i"
have "length values = length sorted" and "sorted \<noteq> []" (* is this noteq Nil fact needed? *) and "length sorted > 0"
using \<open>sorted = _\<close> \<open>_ \<noteq> []\<close> apply auto
by (metis length_0_conv length_sort) (* todo: find a better lemma *)
have "lower_value + (level - lower) * (upper_value - lower_value) / (upper - lower) =
linear (lower, lower_value) (upper, upper_value) level"
apply (subst linear_eq[symmetric]) ..
also have "\<dots> = ?def"
proof -
have b1: "0 \<le> \<lceil>real (length sorted) * level - 5 / 10\<rceil>"
proof -
have "- 1 / 2 \<le> real (length sorted) * level - 5 / 10"
apply simp
by (meson assms(2) le_less_trans less_eq_real_def of_nat_0_le_iff zero_le_divide_1_iff zero_le_mult_iff)
(* strange proof? *)
from this show ?thesis by linarith
qed
have b2: "nat \<lceil>real (length sorted) * level - 5 / 10\<rceil> < length sorted"
proof -
have "real (length sorted) * level \<le> real (length sorted) - 1 / 2"
proof -
from assms(3) have "level \<le> 1 - 1 / real (2 * length sorted)"
using \<open>length values = length sorted\<close> by simp
from this have "real (length sorted) * level \<le> real (length sorted) * (1 - 1 / real (2 * length sorted))"
using \<open>0 < length sorted\<close> by auto
also have "\<dots> = real (length sorted) - 1 / 2"
apply simp
by (metis \<open>length values = length sorted\<close> \<open>size = real (length values)\<close> assms(1)
length_0_conv mult.commute mult.right_neutral mult_cancel_left
nonzero_mult_divide_mult_cancel_left of_nat_eq_iff of_nat_mult
right_diff_distrib' times_divide_eq_right)
finally show ?thesis .
qed
from this show ?thesis
using b1 by linarith
qed
have b3: "1 \<le> \<lceil>real (length sorted) * level - 5 / 10\<rceil>"
proof -
show ?thesis
using assms(2) \<open>length _ = _\<close> \<open>length sorted > 0\<close>
by (simp add: Groups.mult_ac(2) divide_less_eq)
qed
from b2 have b4: "\<lceil>real (length sorted) * level - 5 / 10\<rceil> \<le> int (length sorted)" by simp
have "Max {x' \<in> dom (equidistant_points_on_unit_interval_of sorted). x' < level} = lower"
using \<open>lower = _\<close> \<open>i = _\<close> \<open>size = _\<close> \<open>length values = _\<close>
apply (subst Max_equidistant_points_on_unit_interval_of_bounded)
prefer 4
apply simp
using \<open>sorted \<noteq> []\<close> apply blast
using assms(2) apply auto[1]
using assms(3) by auto
moreover have "Min {x' \<in> dom (equidistant_points_on_unit_interval_of sorted). level \<le> x'} = upper"
using \<open>upper = _\<close> \<open>i = _\<close> \<open>size = _\<close> \<open>length values = _\<close>
apply (subst Min_equidistant_points_on_unit_interval_of_bounded)
prefer 4
apply simp
using \<open>sorted \<noteq> []\<close> apply blast
using assms(2) apply auto[1]
using assms(3) by auto
moreover have "the (equidistant_points_on_unit_interval_of sorted lower) = lower_value"
using \<open>i = _\<close> \<open>size = _\<close> \<open>lower_value = _\<close> \<open>lower = _\<close> \<open>length values = _\<close>
apply (simp only:)
apply (subst equidistant_points_on_unit_interval_of_eq_nth1)
apply (rule b3)
apply (rule b4)
apply simp
done
moreover have "the (equidistant_points_on_unit_interval_of sorted upper) = upper_value"
using \<open>i = _\<close> \<open>size = _\<close> \<open>upper_value = _\<close> \<open>upper = _\<close> \<open>length values = _\<close>
apply (simp only:)
apply (subst equidistant_points_on_unit_interval_of_eq_nth2)
apply (rule b1)
apply (rule b2)
apply simp done
ultimately show ?thesis
using \<open>sorted = _\<close> by simp
qed
finally have "lower_value + (level - lower) * (upper_value - lower_value) / (upper - lower) =
?def" by simp (* intermediate proof step not needed? change proof structure? *)
}
from this \<open>level \<noteq> _\<close> show ?thesis
by (simp add: percentile_alternative_pseudo_def percentile_impl_def)
qed
text \<open> The lemma states the equivalence of the abstract definition of the percentile function from
the Percentile theory and the computational version in the standard interval for the left limit. \<close>
lemma percentile_java_equiv_left:
assumes "values \<noteq> []"
assumes "1 / real (2 * length values) = level"
shows "Percentile.percentile values level = percentile_impl values level"
proof -
have "(length values) * level = 1/2" using assms by auto
then have ceil: "ceiling ((length values) * level - 0.5) = 0" using ceiling_def
by (simp add: \<open>real (length values) * level = 1 / 2\<close>)
have "(sort values)!0 = (sort values)!(nat (0-1))" by simp
then have "percentile_impl values level = (sort values)!0" using ceil
by (metis add.commute add.left_neutral diff_self div_0 mult_zero_right
nat_zero_as_int percentile_impl_def)
have "length values = length (sort values)" by simp
have left_most: "(\<lambda>x. (1 / length values) * (x + 0.5)) 0 = level"
using \<open>real (length values) * level = 1 / 2\<close> add_divide_distrib eq_divide_eq_1 mult_cancel_right1
nonzero_mult_div_cancel_left times_divide_eq_left assms by auto
have "level = ((map (\<lambda>x. (1 /length values) * (x + 0.5)) [0..<length values]))!0"
using assms(1) left_most by auto
then have "level \<in> set (map (\<lambda>x. (1 /length values) * (x + 0.5)) [0..<length values])"
using assms(1) by force
then have "level \<in> set (map (\<lambda>x. (1 /length values) * (x + 0.5)) [0..<length values])"
using left_most by blast
then have "level \<in> dom (equidistant_points_on_unit_interval_of (sort values))"
using equidistant_points_on_unit_interval_of_def
by simp
then have "neighbors (equidistant_points_on_unit_interval_of (sort values)) level = (level, level)"
using defined_point_neighbors_eq finite_equidistant_points_on_unit_interval_of by blast
then have "linear_interpolation (equidistant_points_on_unit_interval_of (sort values)) level = (sort values)!0"
using one_point_interpolation \<open>length values = length (sort values)\<close>
\<open>level \<in> dom (equidistant_points_on_unit_interval_of (sort values))\<close> assms(1)
equidistant_points_on_unit_interval_of_eq_nth2 finite_equidistant_points_on_unit_interval_of
left_most length_greater_0_conv mult_cancel_right1 nat_zero_as_int of_nat_eq_0_iff
real_of_int times_divide_eq_left
proof -
have f1: "(0::int) \<le> 0"
by auto
have f3: "length values \<noteq> 0 \<longrightarrow> (5 / 10 + real_of_int 0) / (of_nat_1 (length (sort values))) = 1 * (5 / 10) / (if length values = 0 then 0 else of_nat_1 (length values))"
by auto
have f4: "1 / (if length values = 0 then 0 else (length values)) * (5 / 10) = level"
using left_most by auto
have "\<forall>x1. real_of_int x1 + 5 / 10 = 5 / 10 + real_of_int x1"
by auto
then have "length values \<noteq> 0 \<longrightarrow> linear_interpolation (equidistant_points_on_unit_interval_of (sort values)) level = sort values ! 0"
using f4 f3 f1 \<open>\<And>c b a. b / c * a = b * a / c\<close> \<open>length values = length (sort values)\<close>
\<open>level \<in> dom (equidistant_points_on_unit_interval_of (sort values))\<close> \<open>values \<noteq> []\<close>
equidistant_points_on_unit_interval_of_eq_nth2 finite_equidistant_points_on_unit_interval_of
length_greater_0_conv nat_zero_as_int one_point_interpolation
by (smt divide_inverse_commute divide_numeral_1 inverse_divide of_int_0)
then show ?thesis
using \<open>values \<noteq> []\<close> by fastforce
qed
then have "Percentile.percentile values level = (sort values)!0" using linear_interpolation_def
using one_point_interpolation by (simp add: percentile_def)
then show ?thesis
by (simp add: \<open>percentile_impl values level = sort values ! 0\<close>)
qed
text \<open> The theorem states the equivalence of the abstract definition of the percentile function from
the Percentile theory and the computational version in the standard interval\<close>
theorem percentile_java_equiv:
assumes "values \<noteq> []"
assumes "1 / real (2 * length values) \<le> level"
assumes "level \<le> 1 - 1 / real (2 * length values)"
shows "Percentile.percentile values level = percentile_impl values level"
using assms less_eq_real_def percentile_java_equiv_except_left percentile_java_equiv_left by blast
export_code percentile_impl in Scala
end
|
"""
niw_hyperparams(ΞΊ::Float32, m::AbstractArray{Float32}, Ξ½::Float32, Ο::AbstractArray{Float32})
[Normal Inverse Wishart](https://en.wikipedia.org/wiki/Normal-inverse-Wishart_distribution)
"""
struct niw_hyperparams <: distribution_hyper_params
ΞΊ::Float32
m::AbstractArray{Float32}
Ξ½::Float32
Ο::AbstractArray{Float32}
end
mutable struct niw_sufficient_statistics <: sufficient_statistics
N::Float32
points_sum::AbstractArray{Float32,1}
S::AbstractArray{Float32,2}
end
function calc_posterior(prior:: niw_hyperparams, suff_statistics::niw_sufficient_statistics)
if suff_statistics.N == 0
return prior
end
ΞΊ = prior.ΞΊ + suff_statistics.N
Ξ½ = prior.Ξ½ + suff_statistics.N
m = (prior.m.*prior.ΞΊ + suff_statistics.points_sum) / ΞΊ
Ο = (prior.Ξ½ * prior.Ο + prior.ΞΊ*prior.m*prior.m' -ΞΊ*m*m'+ suff_statistics.S) / Ξ½
Ο = Matrix(Hermitian(Ο))
return niw_hyperparams(ΞΊ,m,Ξ½,Ο)
end
function sample_distribution(hyperparams::niw_hyperparams)
Ξ£ = rand(Distributions.InverseWishart(hyperparams.Ξ½, hyperparams.Ξ½* hyperparams.Ο))
ΞΌ = rand(Distributions.MvNormal(hyperparams.m, Ξ£/hyperparams.ΞΊ))
invΞ£ = inv(Ξ£)
chol = cholesky(Hermitian(invΞ£))
return mv_gaussian(ΞΌ,Ξ£,invΞ£,logdet(Ξ£),chol.U)
end
function create_sufficient_statistics(hyper::niw_hyperparams,posterior::niw_hyperparams,points::AbstractArray{Float32,2}, pts_to_group = 0)
if size(points,2) == 0
return niw_sufficient_statistics(size(points,2),zeros(Float32,length(hyper.m)),zeros(Float32,length(hyper.m),length(hyper.m)))
end
pts = copy(points)
points_sum = sum(pts, dims = 2)[:]
S = pts * pts'
return niw_sufficient_statistics(size(points,2),points_sum,S)
end
function log_marginal_likelihood(hyper::niw_hyperparams, posterior_hyper::niw_hyperparams, suff_stats::niw_sufficient_statistics)
D = length(suff_stats.points_sum)
logpi = log(pi)
return -suff_stats.N*D*0.5*logpi +
log_multivariate_gamma(posterior_hyper.Ξ½/2, D)-
log_multivariate_gamma(hyper.Ξ½/2, D) +
(hyper.Ξ½/2)*(D*log(hyper.Ξ½)+logdet(hyper.Ο))-
(posterior_hyper.Ξ½/2)*(D*log(posterior_hyper.Ξ½) + logdet(posterior_hyper.Ο)) +
(D/2)*(log(hyper.ΞΊ/posterior_hyper.ΞΊ))
end
function aggregate_suff_stats(suff_l::niw_sufficient_statistics, suff_r::niw_sufficient_statistics)
return niw_sufficient_statistics(suff_l.N+suff_r.N, suff_l.points_sum + suff_r.points_sum, suff_l.S+suff_r.S)
end
|
--
-- An instance of this template must have a $Export section and the export_terminals option
--
-- Macros that may be redefined in an instance of this template
--
-- $eof_token
-- $additional_interfaces
-- $super_stream_class -- subclass com.ibm.lpg.LpgLexStream for getKind
-- $prs_stream_class -- use /.PrsStream./ if not subclassing
-- $super_class
--
-- B E G I N N I N G O F T E M P L A T E LexerTemplateF
--
%Options programming_language=java,margin=4
%Options table
%options action-block=("*.java", "/.", "./")
%options ParseTable=lpg.runtime.ParseTable
%Options prefix=Char_
--
-- This template requires that the name of the EOF token be set
-- to EOF and that the prefix be "Char_" to be consistent with
-- KeywordTemplateD.
--
%Eof
EOF
%End
--
-- This template also requires that the name of the parser EOF
-- Token to be exported be set to EOF_TOKEN
--
%Export
EOF_TOKEN
%End
%Define
--
-- Macros that are be needed in an instance of this template
--
$eof_token /.$_EOF_TOKEN./
$additional_interfaces /../
$super_stream_class /.$file_prefix$LpgLexStream./
$prs_stream_class /.IPrsStream./
$super_class /.Object./
$prs_stream /. // macro prs_stream is deprecated. Use function getPrsStream
getPrsStream()./
$setSym1 /. // macro setSym1 is deprecated. Use function setResult
lexParser.setSym1./
$setResult /. // macro setResult is deprecated. Use function setResult
lexParser.setSym1./
$getSym /. // macro getSym is deprecated. Use function getLastToken
lexParser.getSym./
$getToken /. // macro getToken is deprecated. Use function getToken
lexParser.getToken./
$getLeftSpan /. // macro getLeftSpan is deprecated. Use function getLeftSpan
lexParser.getFirstToken./
$getRightSpan /. // macro getRightSpan is deprecated. Use function getRightSpan
lexParser.getLastToken./
--
-- Macros useful for specifying actions
--
$Header
/.
//
// Rule $rule_number: $rule_text
//
./
$DefaultAction
/.$Header$case $rule_number: { ./
$BeginAction /.$DefaultAction./
$EndAction
/. break;
}./
$BeginJava
/.$BeginAction
$symbol_declarations./
$EndJava /.$EndAction./
$NoAction
/.$Header$case $rule_number:
break; ./
$BeginActions
/.
public void ruleAction(int ruleNumber)
{
switch(ruleNumber)
{./
$SplitActions
/.
default:
ruleAction$rule_number(ruleNumber);
break;
}
return;
}
public void ruleAction$rule_number(int ruleNumber)
{
switch (ruleNumber)
{./
$EndActions
/.
default:
break;
}
return;
}./
%End
%Globals
/.import lpg.runtime.*;
./
%End
%Headers
/.
public class $action_type extends $super_class implements RuleAction$additional_interfaces
{
private $super_stream_class lexStream;
private static ParseTable prs = new $prs_type();
public ParseTable getParseTable() { return prs; }
private LexParser lexParser = new LexParser();
public LexParser getParser() { return lexParser; }
public int getToken(int i) { return lexParser.getToken(i); }
public int getRhsFirstTokenIndex(int i) { return lexParser.getFirstToken(i); }
public int getRhsLastTokenIndex(int i) { return lexParser.getLastToken(i); }
public int getLeftSpan() { return lexParser.getToken(1); }
public int getRightSpan() { return lexParser.getLastToken(); }
public void resetKeywordLexer()
{
if (kwLexer == null)
this.kwLexer = new $kw_lexer_class(lexStream.getInputChars(), $_IDENTIFIER);
else this.kwLexer.setInputChars(lexStream.getInputChars());
}
public void reset(String filename, int tab) throws java.io.IOException
{
lexStream = new $super_stream_class(filename, tab);
lexParser.reset((ILexStream) lexStream, prs, (RuleAction) this);
resetKeywordLexer();
}
public void reset(char[] input_chars, String filename)
{
reset(input_chars, filename, 1);
}
public void reset(char[] input_chars, String filename, int tab)
{
lexStream = new $super_stream_class(input_chars, filename, tab);
lexParser.reset((ILexStream) lexStream, prs, (RuleAction) this);
resetKeywordLexer();
}
public $action_type(String filename, int tab) throws java.io.IOException
{
reset(filename, tab);
}
public $action_type(char[] input_chars, String filename, int tab)
{
reset(input_chars, filename, tab);
}
public $action_type(char[] input_chars, String filename)
{
reset(input_chars, filename, 1);
}
public $action_type() {}
public ILexStream getILexStream() { return lexStream; }
/**
* @deprecated replaced by {@link #getILexStream()}
*/
public ILexStream getLexStream() { return lexStream; }
private void initializeLexer($prs_stream_class prsStream, int start_offset, int end_offset)
{
if (lexStream.getInputChars() == null)
throw new NullPointerException("LexStream was not initialized");
lexStream.setPrsStream(prsStream);
prsStream.makeToken(start_offset, end_offset, 0); // Token list must start with a bad token
}
private void addEOF($prs_stream_class prsStream, int end_offset)
{
prsStream.makeToken(end_offset, end_offset, $eof_token); // and end with the end of file token
prsStream.setStreamLength(prsStream.getSize());
}
public void lexer($prs_stream_class prsStream)
{
lexer(null, prsStream);
}
public void lexer(Monitor monitor, $prs_stream_class prsStream)
{
initializeLexer(prsStream, 0, -1);
lexParser.parseCharacters(monitor); // Lex the input characters
addEOF(prsStream, lexStream.getStreamIndex());
}
public void lexer($prs_stream_class prsStream, int start_offset, int end_offset)
{
lexer(null, prsStream, start_offset, end_offset);
}
public void lexer(Monitor monitor, $prs_stream_class prsStream, int start_offset, int end_offset)
{
if (start_offset <= 1)
initializeLexer(prsStream, 0, -1);
else initializeLexer(prsStream, start_offset - 1, start_offset - 1);
lexParser.parseCharacters(monitor, start_offset, end_offset);
addEOF(prsStream, (end_offset >= lexStream.getStreamIndex() ? lexStream.getStreamIndex() : end_offset + 1));
}
public IPrsStream.Range incrementalLexer(char[] input_chars, int start_change_offset, int end_change_offset) {
int offset_adjustment = input_chars.length - lexStream.getStreamLength();
//*System.out.println("The offset adjustment is " + offset_adjustment);
if (start_change_offset <= 0 && start_change_offset < input_chars.length)
throw new IndexOutOfBoundsException("The start offset " + start_change_offset +
" is out of bounds for range 0.." + (input_chars.length - 1));
if (end_change_offset <= 0 && end_change_offset < input_chars.length)
throw new IndexOutOfBoundsException("The end offset " + end_change_offset +
" is out of bounds for range 0.." + (input_chars.length - 1));
//
// Get the potential list of tokens to be rescanned
//
java.util.ArrayList<IToken> affected_tokens = lexStream.getIPrsStream().incrementalResetAtCharacterOffset(start_change_offset);
//
// If the change occured between the first two affected tokens (or adjunct) and not immediately
// on the characted after the first token (or adjunct), restart the scanning after the first
// affected token. Otherwise, rescan the first token.
//
int affected_index = 0;
int repair_offset = start_change_offset;
if (affected_tokens.size() > 0) {
if (affected_tokens.get(0).getEndOffset() + 1 < start_change_offset) {
repair_offset = affected_tokens.get(0).getEndOffset() + 1;
if (affected_tokens.get(0) instanceof Token)
lexStream.getIPrsStream().makeToken(affected_tokens.get(0), 0);
else lexStream.getIPrsStream().makeAdjunct(affected_tokens.get(0), 0);
affected_index++;
}
else repair_offset = affected_tokens.get(0).getStartOffset();
}
lexStream.setInputChars(input_chars);
lexStream.setStreamLength(input_chars.length);
lexStream.computeLineOffsets(repair_offset);
int first_new_token_index = lexStream.getIPrsStream().getTokens().size(),
first_new_adjunct_index = lexStream.getIPrsStream().getAdjuncts().size();
resetKeywordLexer();
lexParser.resetTokenStream(repair_offset);
int next_offset;
do {
//*System.out.println("Scanning token starting at " + (lexStream.peek() - 1));
next_offset = lexParser.incrementalParseCharacters();
//*System.out.print("***Remaining string: \"");
//*for (int i = next_offset; i < input_chars.length; i++)
//*System.out.print(input_chars[i]);
//*System.out.println("\"");
while (affected_index < affected_tokens.size() &&
affected_tokens.get(affected_index).getStartOffset() + offset_adjustment < next_offset)
//*{
//*System.out.println("---Skipping token " + affected_index + ": \"" + affected_tokens.get(affected_index).toString() +
//*"\" starting at adjusted offset " + (affected_tokens.get(affected_index).getStartOffset() + offset_adjustment));
affected_index++;
//*}
} while(next_offset <= end_change_offset && // still in the damage region and ...
(affected_index < affected_tokens.size() && // not resynchronized with a token in the list of affected tokens
affected_tokens.get(affected_index).getStartOffset() + offset_adjustment != next_offset));
//
// If any new tokens were added, compute the first and the last one.
//
IToken first_new_token = null,
last_new_token = null;
if (first_new_token_index < lexStream.getIPrsStream().getTokens().size()) {
first_new_token = lexStream.getIPrsStream().getTokenAt(first_new_token_index);
last_new_token = lexStream.getIPrsStream().getTokenAt(lexStream.getIPrsStream().getTokens().size() - 1);
}
//
// If an adjunct was added prior to the first real token, chose it instead as the first token.
// Similarly, if adjucts were added after the last token, chose the last adjunct added as the last token.
//
if (first_new_adjunct_index < lexStream.getIPrsStream().getAdjuncts().size()) {
if (first_new_token == null ||
lexStream.getIPrsStream().getAdjunctAt(first_new_adjunct_index).getStartOffset() <
first_new_token.getStartOffset()) {
first_new_token = lexStream.getIPrsStream().getAdjunctAt(first_new_adjunct_index);
}
if (last_new_token == null ||
lexStream.getIPrsStream().getAdjunctAt(lexStream.getIPrsStream().getAdjuncts().size() - 1).getEndOffset() >
last_new_token.getEndOffset()) {
last_new_token = lexStream.getIPrsStream().getAdjunctAt(lexStream.getIPrsStream().getAdjuncts().size() - 1);
}
}
//
// For all remainng tokens (and adjuncts) in the list of affected tokens add them to the
// list of tokens (and adjuncts).
//
for (int i = affected_index; i < affected_tokens.size(); i++) {
if (affected_tokens.get(i) instanceof Token)
lexStream.getIPrsStream().makeToken(affected_tokens.get(i), offset_adjustment);
else lexStream.getIPrsStream().makeAdjunct(affected_tokens.get(i), offset_adjustment);
//*System.out.println("+++Added affected token " + i + ": \"" + affected_tokens.get(i).toString() +
//*"\" starting at adjusted offset " + (affected_tokens.get(i).getStartOffset() + offset_adjustment));
}
return new IPrsStream.Range(lexStream.getIPrsStream(), first_new_token, last_new_token);
}
/**
* If a parse stream was not passed to this Lexical analyser then we
* simply report a lexical error. Otherwise, we produce a bad token.
*/
public void reportLexicalError(int startLoc, int endLoc) {
IPrsStream prs_stream = lexStream.getIPrsStream();
if (prs_stream == null)
lexStream.reportLexicalError(startLoc, endLoc);
else {
//
// Remove any token that may have been processed that fall in the
// range of the lexical error... then add one error token that spans
// the error range.
//
for (int i = prs_stream.getSize() - 1; i > 0; i--) {
if (prs_stream.getStartOffset(i) >= startLoc)
prs_stream.removeLastToken();
else break;
}
prs_stream.makeToken(startLoc, endLoc, 0); // add an error token to the prsStream
}
}
./
%End
%Rules
/.$BeginActions./
%End
%Trailers
/.
$EndActions
}
./
%End
--
-- E N D O F T E M P L A T E
--
|
lemma in_bigtheta_zero_iff [simp]: "f \<in> \<Theta>[F](\<lambda>x. 0) \<longleftrightarrow> eventually (\<lambda>x. f x = 0) F" |
(* This program is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1 *)
(* of the License, or (at your option) any later version. *)
(* *)
(* This program is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Lesser General Public *)
(* License along with this program; if not, write to the Free *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA *)
(* Computation Tree Logic (CTL) and Timed Computation Tree Logic (TCTL) *)
Set Implicit Arguments.
Unset Strict Implicit.
Require Import Streams.
Require Import time_clocks. (* Temporal notions for discrete time *)
(****************************************************************************)
(* Hypothesis: type Label with label Tick *)
(* Inductive Label : Set := L1 : Label | ... | Ln : Label | Tick : Label. *)
(****************************************************************************)
Section TemporalOperators_Ind.
(* Temporal operators with inductive types: definitions and properties *)
Variable S : Set. (* States *)
Variable tr : S -> Label -> S -> Prop. (* Transitions *)
(* Reachable states form "Sini" with transitions "tr" *)
Inductive RState (Sini : S) : S -> Prop :=
| rsIni : RState Sini Sini
| rsNext :
forall (s1 s2 : S) (l : Label),
RState Sini s1 -> tr s1 l s2 -> RState Sini s2.
(* Reachable states form "Sini" with transitions "tr" in time units *)
Inductive RState_T (Sini : S) : S -> Instant -> Prop :=
| rsIni_T : RState_T Sini Sini time0
| rsTime_T :
forall (s1 s2 : S) (t : Instant),
RState_T Sini s1 t -> tr s1 Tick s2 -> RState_T Sini s2 (Inc t)
| rsNoTime_T :
forall (s1 s2 : S) (l : Label) (t : Instant),
RState_T Sini s1 t -> l <> Tick -> tr s1 l s2 -> RState_T Sini s2 t.
(**************************************************************************)
(* Invariants and Reachability *)
(**************************************************************************)
(* Init => FA[] P *)
Definition ForAll (Sini : S) (P : S -> Prop) :=
forall s : S, RState Sini s -> P s.
(* Init => FA[](bound t) P *)
Definition ForAll_T (Sini : S) (P : S -> Prop) (bound : Instant -> Prop) :=
forall (s : S) (t : Instant), bound t -> RState_T Sini s t -> P s.
(* Init => EX<> P *)
Inductive Exists (Sini : S) (P : S -> Prop) : Prop :=
exists_ : forall s : S, RState Sini s -> P s -> Exists Sini P.
(* Init => EX<>(bound t) P *)
Inductive Exists_T (Sini : S) (P : S -> Prop) (bound : Instant -> Prop) :
Prop :=
exists_T :
forall (s : S) (t : Instant),
bound t -> RState_T Sini s t -> P s -> Exists_T Sini P bound.
(**************************************************************************)
(* Some Properties *)
(**************************************************************************)
Theorem Mon_I :
forall (Sini : S) (Pg Pp : S -> Prop),
ForAll Sini Pg -> (forall s : S, Pg s -> Pp s) -> ForAll Sini Pp.
Proof.
unfold ForAll in |- *; intros.
apply H0.
apply H; assumption.
Qed.
Theorem Mon_I_T :
forall (Sini : S) (Pg Pp : S -> Prop) (bound : Instant -> Prop),
ForAll_T Sini Pg bound ->
(forall s : S, Pg s -> Pp s) -> ForAll_T Sini Pp bound.
Proof.
unfold ForAll_T in |- *; intros.
apply H0.
apply (H s t); assumption.
Qed.
Theorem Conj :
forall (Sini : S) (P1 P2 : S -> Prop),
ForAll Sini P1 -> ForAll Sini P2 -> ForAll Sini (fun s : S => P1 s /\ P2 s).
Proof.
unfold ForAll in |- *; intros.
split; [ apply H | apply H0 ]; assumption.
Qed.
Theorem Conj_T :
forall (Sini : S) (P1 P2 : S -> Prop) (bound : Instant -> Prop),
ForAll_T Sini P1 bound ->
ForAll_T Sini P2 bound -> ForAll_T Sini (fun s : S => P1 s /\ P2 s) bound.
Proof.
unfold ForAll_T in |- *; intros.
split; [ apply (H s t) | apply (H0 s t) ]; assumption.
Qed.
Theorem Mon_I_EX :
forall (Sini : S) (Pg Pp : S -> Prop),
Exists Sini Pg -> (forall s : S, Pg s -> Pp s) -> Exists Sini Pp.
Proof.
intros.
inversion_clear H.
apply (exists_ H1 (H0 s H2)).
Qed.
Theorem Mon_I_EX_T :
forall (Sini : S) (Pg Pp : S -> Prop) (bound : Instant -> Prop),
Exists_T Sini Pg bound ->
(forall s : S, Pg s -> Pp s) -> Exists_T Sini Pp bound.
Proof.
intros.
inversion_clear H.
apply (exists_T H1 H2 (H0 s H3)).
Qed.
Lemma RState_Trans :
forall s1 s2 s3 : S, RState s1 s2 -> RState s2 s3 -> RState s1 s3.
Proof.
intros.
elim H0; [ assumption | intros ].
apply (rsNext H2 H3).
Qed.
Lemma RState_Trans_T :
forall (s1 s2 s3 : S) (t1 t2 : Instant),
RState_T s1 s2 t1 -> RState_T s2 s3 t2 -> RState_T s1 s3 (plus_Ck t1 t2).
Proof.
simple induction 2; unfold plus_Ck in |- *; intros.
rewrite (plus_comm t1 time0); unfold time0 in |- *; simpl in |- *;
assumption.
unfold Inc in |- *; unfold plus_Ck in |- *;
rewrite (plus_assoc t1 t tick).
apply (rsTime_T H2 H3).
apply (rsNoTime_T H2 H3 H4).
Qed.
Theorem StepsEX :
forall (s1 s2 : S) (P : S -> Prop),
RState s1 s2 -> Exists s2 P -> Exists s1 P.
Proof.
intros.
inversion H0.
apply (exists_ (RState_Trans H H1) H2).
Qed.
Require Import Classical.
Theorem ForAll_EX :
forall (Sini : S) (P : S -> Prop),
ForAll Sini P <-> ~ Exists Sini (fun s : S => ~ P s).
Proof.
unfold not in |- *; unfold ForAll in |- *; red in |- *; intros; split;
intros.
inversion H0.
apply (H2 (H s H1)).
elim (classic (P s));
[ trivial | intro; absurd (Exists Sini (fun s : S => P s -> False)) ].
assumption.
apply exists_ with (1 := H0); assumption.
Qed.
Theorem ForAll_EX_T :
forall (Sini : S) (P : S -> Prop) (bound : Instant -> Prop),
ForAll_T Sini P bound <-> ~ Exists_T Sini (fun s : S => ~ P s) bound.
Proof.
unfold not in |- *; unfold ForAll_T in |- *; red in |- *; intros; split;
intros.
inversion H0.
apply (H3 (H s t H1 H2)).
elim (classic (P s));
[ trivial
| intro; absurd (Exists_T Sini (fun s : S => P s -> False) bound) ].
assumption.
apply exists_T with (2 := H1); assumption.
Qed.
(**************************************************************************)
(* Other Definitions *)
(**************************************************************************)
(* FA[] (Q => FA[] P) *)
Definition ForAll_from (Sini : S) (Q P : S -> Prop) :=
ForAll Sini (fun s : S => Q s -> ForAll s P).
(* (s:S) (RState Sini s) -> (Q s) -> (ForAll s P). *)
(* FA[] (Q => FA[](bound t) P) *)
Definition ForAll_from_T (Sini : S) (Q P : S -> Prop)
(bound : Instant -> Prop) :=
ForAll Sini (fun s : S => Q s -> ForAll_T s P bound).
(* (s:S) (RState Sini s) -> (Q s) -> (ForAll_T s P bound). *)
(* FA[] (Q => EX<> P) *)
Definition Exists_from (Sini : S) (Q P : S -> Prop) :=
ForAll Sini (fun s : S => Q s -> Exists s P).
(* (s:S) (RState Sini s) -> (Q s) -> (Exists s P). *)
(* FA[] (Q => EX<>(bound t) P) *)
Definition Exists_from_T (Sini : S) (Q P : S -> Prop)
(bound : Instant -> Prop) :=
ForAll Sini (fun s : S => Q s -> Exists_T s P bound).
(* (s:S) (RState Sini s) -> (Q s) -> (Exists_T s P bound). *)
End TemporalOperators_Ind.
Infix "^" := Cons.
Section TemporalOperators_CTL.
(* CTL operators with co-inductives types: definitions and properties *)
Variable S : Set. (* States *)
Variable tr : S -> Label -> S -> Prop. (* Transitions *)
Notation SPath := (Stream S) (only parsing).
CoInductive ForAllS (P : Stream S -> Prop) : Stream S -> Prop :=
forallS :
forall (x : Stream S) (s : S),
P (s ^ x) -> ForAllS P x -> ForAllS P (s ^ x).
Inductive ExistsS (P : Stream S -> Prop) : Stream S -> Prop :=
| Here : forall x : Stream S, P x -> ExistsS P x
| Further :
forall (x : Stream S) (s : S), ExistsS P x -> ExistsS P (s ^ x).
(* Ejecution traces *)
CoInductive isTrace : Stream S -> Prop :=
is_trace :
forall (x : Stream S) (s1 s2 : S) (l : Label),
tr s1 l s2 -> isTrace (s2 ^ x) -> isTrace (s1 ^ s2 ^ x).
Definition isTraceFrom (Sini : S) (x : Stream S) :=
Sini = hd x /\ isTrace x.
(* Operator Until *)
Inductive Until (P Q : Stream S -> Prop) : Stream S -> Prop :=
| UntilFurther :
forall (s : S) (x : Stream S),
P (s ^ x) -> Until P Q x -> Until P Q (s ^ x)
| UntilHere : forall x : Stream S, Q x -> Until P Q x.
Inductive EX_Until (Sini : S) (P Q : Stream S -> Prop) : Prop :=
ExUntil :
forall x : Stream S,
isTraceFrom Sini x -> Until P Q x -> EX_Until Sini P Q.
Definition FA_Until (Sini : S) (P Q : Stream S -> Prop) :=
forall x : Stream S, isTraceFrom Sini x -> Until P Q x.
(* Init => FA[] P *)
Definition Always (Sini : S) (P : Stream S -> Prop) :=
forall x : Stream S, isTraceFrom Sini x -> ForAllS P x.
(* Init => FA<> P *)
Definition Inevitable (Sini : S) (P : Stream S -> Prop) :=
forall x : Stream S, isTraceFrom Sini x -> ExistsS P x.
(* Init => EX<> P *)
Inductive Posible (Sini : S) (P : Stream S -> Prop) : Prop :=
posible :
forall x : Stream S,
isTraceFrom Sini x -> ExistsS P x -> Posible Sini P.
(* Init => EX[] P *)
Inductive SafePath (Sini : S) (P : Stream S -> Prop) : Prop :=
safePath :
forall x : Stream S,
isTraceFrom Sini x -> ForAllS P x -> SafePath Sini P.
(**************************************************************************)
(* Some Properties *)
(**************************************************************************)
Theorem Equiv1 :
forall (Sini : S) (P : Stream S -> Prop),
Posible Sini P <-> EX_Until Sini (fun _ : Stream S => True) P.
Proof.
unfold iff in |- *; intros; split; intro.
inversion_clear H.
apply ExUntil with (P := fun _ : Stream S => True) (1 := H0).
elim H1; intros.
constructor 2; assumption.
constructor 1; trivial.
inversion_clear H.
apply posible with (1 := H0).
elim H1; intros.
constructor 2; assumption.
constructor 1; assumption.
Qed.
Theorem Equiv2 :
forall (Sini : S) (P : Stream S -> Prop),
Inevitable Sini P <-> FA_Until Sini (fun _ : Stream S => True) P.
Proof.
unfold iff, Inevitable, FA_Until in |- *; intros; split; intros.
elim (H x H0); intros.
constructor 2; assumption.
constructor 1; trivial.
elim (H x H0); intros.
constructor 2; assumption.
constructor 1; assumption.
Qed.
Lemma ConsTrace :
forall (s1 s2 : S) (x z : Stream S),
isTraceFrom s2 z ->
isTraceFrom s1 (s1 ^ s2 ^ x) -> isTraceFrom s1 (s1 ^ z).
Proof.
unfold isTraceFrom in |- *; simpl in |- *.
simple destruct z; simple destruct 1; simple destruct 3; simpl in |- *;
intros.
compute in H0; rewrite H0 in H4.
inversion_clear H4.
split; [ trivial | apply (is_trace H5 H1) ].
Qed.
Lemma notPosible :
forall (P : Stream S -> Prop) (s1 : S),
~ Posible s1 P ->
forall (z : Stream S) (s2 : S),
isTraceFrom s1 (s1 ^ s2 ^ z) -> ~ Posible s2 P.
Proof.
unfold not at 2 in |- *; intros.
elim H1; intros.
apply H; cut (isTraceFrom s1 (s1 ^ x)).
intro H4; apply (posible (P:=P) H4).
apply Further; assumption.
apply ConsTrace with (1 := H2) (2 := H0); assumption.
Qed.
Theorem Equiv3 :
forall (Sini : S) (P : Stream S -> Prop),
Always Sini P <-> ~ Posible Sini (fun s : Stream S => ~ P s).
Proof.
unfold iff, Always, not in |- *; intros; split.
intros H H0; inversion_clear H0.
generalize (H x H1); elim H2; intros.
inversion_clear H3 in H0.
apply (H0 H4).
inversion_clear H4.
apply (H3 H6).
generalize Sini; cofix u.
simple destruct x; intros; constructor.
elim (classic (P (s ^ s0))); [ trivial | intros ].
absurd (Posible Sini0 (fun s : Stream S => ~ P s)).
assumption.
apply posible with (1 := H0).
constructor 1; assumption.
elim H0; simpl in |- *; intros.
apply (u (hd s0)); intros.
generalize H0; clear H0; generalize H3; clear H3.
rewrite <- H1; case s0; simpl in |- *; intros.
apply (notPosible (P:=fun s : Stream S => ~ P s) H H0); assumption.
inversion_clear H2; simpl in |- *.
unfold isTraceFrom in |- *; split; trivial.
Qed.
Lemma not_EX :
forall (P : Stream S -> Prop) (x : Stream S) (s : S),
~ ExistsS P (s ^ x) -> ~ ExistsS P x.
Proof.
unfold not in |- *; intros.
apply (H (Further s H0)).
Qed.
Theorem Equiv4 :
forall (Sini : S) (P : Stream S -> Prop),
SafePath Sini P <-> ~ Inevitable Sini (fun s : Stream S => ~ P s).
Proof.
unfold iff, Inevitable, not in |- *; intros; split.
intro sp; inversion sp; intros.
generalize H0; elim (H1 x H); intros.
inversion_clear H3 in H2.
apply (H2 H4).
apply H3; inversion_clear H4; assumption.
intro H;
elim
(not_all_ex_not (Stream S)
(fun x : Stream S =>
isTraceFrom Sini x -> ExistsS (fun s : Stream S => P s -> False) x)
H).
intros.
generalize
(not_imply_elim2 (isTraceFrom Sini x)
(ExistsS (fun s : Stream S => ~ P s) x) H0).
generalize
(not_imply_elim (isTraceFrom Sini x)
(ExistsS (fun s : Stream S => ~ P s) x) H0);
intros.
apply safePath with (1 := H1).
generalize H1; clear H1; generalize H2; clear H2.
generalize x; generalize Sini; cofix u.
simple destruct x0; intros; constructor.
elim (classic (P (s ^ s0))); [ trivial | intro ].
elim (H2 (Here (P:=fun s : Stream S => ~ P s) H3)).
apply u with (Sini := hd s0).
generalize H2; clear H2; case s0; unfold not in |- *; intros.
apply (not_EX H2 H3).
elim H1; intros ig trace; inversion_clear trace.
unfold isTraceFrom in |- *; split; trivial.
Qed.
Theorem Mon_I_S :
forall (x : Stream S) (Pg Pp : Stream S -> Prop),
ForAllS Pg x -> (forall s : Stream S, Pg s -> Pp s) -> ForAllS Pp x.
Proof.
cofix u; intro x; case x; intros.
case H; constructor.
apply (H0 (s1 ^ x0) H1).
apply (u x0 Pg Pp H2 H0).
Qed.
Theorem Conj_S :
forall (x : Stream S) (P1 P2 : Stream S -> Prop),
ForAllS P1 x ->
ForAllS P2 x -> ForAllS (fun s : Stream S => P1 s /\ P2 s) x.
Proof.
cofix u; intro x; case x; intros.
inversion_clear H; inversion_clear H0.
constructor; [ split | apply (u s0) ]; assumption.
Qed.
Theorem Mon_I_EX_S :
forall (x : Stream S) (Pg Pp : Stream S -> Prop),
ExistsS Pg x -> (forall s : Stream S, Pg s -> Pp s) -> ExistsS Pp x.
Proof.
simple induction 1; intros.
constructor 1; apply (H1 x0 H0).
constructor 2; apply (H1 H2).
Qed.
Theorem OneStep_EX :
forall (x : Stream S) (P : Stream S -> Prop),
ExistsS P x -> forall s : S, ExistsS P (s ^ x).
Proof.
intros; constructor 2; assumption.
Qed.
End TemporalOperators_CTL.
Section TemporalOperators_TCTL.
(* TCTL operators with co-inductives types: definitions and properties *)
Variable S : Set. (* States *)
Variable tr : S -> Label -> S -> Prop. (* Transitions *)
Variable bound : Instant -> Prop. (* Location invariants *)
Notation State_T := (S * Instant)%type (only parsing).
Notation SPath_T := (Stream (S * Instant)) (only parsing).
(* Ejecution traces *)
CoInductive isTrace_T : Stream (S * Instant) -> Prop :=
| isTraceTick :
forall (x : Stream (S * Instant)) (s1 s2 : S) (t : Instant),
tr s1 Tick s2 ->
isTrace_T ((s2, Inc t) ^ x) -> isTrace_T ((s1, t) ^ (s2, Inc t) ^ x)
| isTraceDisc :
forall (x : Stream (S * Instant)) (s1 s2 : S)
(t : Instant) (l : Label),
tr s1 l s2 ->
l <> Tick ->
isTrace_T ((s2, t) ^ x) -> isTrace_T ((s1, t) ^ (s2, t) ^ x).
Definition isTraceFrom_T (Sini : S * Instant) (x : Stream (S * Instant)) :=
Sini = hd x /\ isTrace_T x.
(* Until operator *)
Inductive Until_bound (P Q : Stream (S * Instant) -> Prop) :
Stream (S * Instant) -> Prop :=
| UntilFurther_bound :
forall (s : S * Instant) (x : Stream (S * Instant)),
P (s ^ x) -> Until_bound P Q x -> Until_bound P Q (s ^ x)
| UntilHere_bound :
forall (s : S) (t : Instant) (x : Stream (S * Instant)),
bound t -> Q ((s, t) ^ x) -> Until_bound P Q ((s, t) ^ x).
Inductive EX_Until_bound (Sini : S * Instant)
(P Q : Stream (S * Instant) -> Prop) : Prop :=
ExUntil_bound :
forall x : Stream (S * Instant),
isTraceFrom_T Sini x -> Until_bound P Q x -> EX_Until_bound Sini P Q.
Definition FA_Until_bound (Sini : S * Instant)
(P Q : Stream (S * Instant) -> Prop) :=
forall x : Stream (S * Instant),
isTraceFrom_T Sini x -> Until_bound P Q x.
(* Init => FA[](bound t) P *)
Definition Always_T (Sini : S * Instant)
(P : Stream (S * Instant) -> Prop) :=
forall x : Stream (S * Instant),
isTraceFrom_T Sini x ->
ForAllS (fun s : Stream (S * Instant) => bound (snd (hd s)) -> P s) x.
(* Init => FA<>(bound t) P *)
Definition Inevitable_T (Sini : S * Instant)
(P : Stream (S * Instant) -> Prop) :=
forall x : Stream (S * Instant),
isTraceFrom_T Sini x ->
ExistsS (fun s : Stream (S * Instant) => bound (snd (hd s)) /\ P s) x.
(* Init => EX<>(bound t) P *)
Inductive Posible_T (Sini : S * Instant) (P : Stream (S * Instant) -> Prop)
: Prop :=
posible_T :
forall x : Stream (S * Instant),
isTraceFrom_T Sini x ->
ExistsS (fun s : Stream (S * Instant) => bound (snd (hd s)) /\ P s) x ->
Posible_T Sini P.
(* Init => EX[](bound t) P *)
Inductive SafePath_T (Sini : S * Instant)
(P : Stream (S * Instant) -> Prop) : Prop :=
safePath_T :
forall x : Stream (S * Instant),
isTraceFrom_T Sini x ->
ForAllS (fun s : Stream (S * Instant) => bound (snd (hd s)) -> P s) x ->
SafePath_T Sini P.
(**************************************************************************)
(* Some Properties *)
(**************************************************************************)
Theorem Equiv1_T :
forall (Sini : S * Instant) (P : Stream (S * Instant) -> Prop),
Posible_T Sini P <->
EX_Until_bound Sini (fun _ : Stream (S * Instant) => True) P.
Proof.
unfold iff in |- *; intros; split; intro.
inversion_clear H.
apply
ExUntil_bound with (P := fun _ : Stream (S * Instant) => True) (1 := H0).
elim H1.
simple destruct x0; simpl in |- *.
simple destruct p; simple destruct 1; simpl in |- *; intros.
constructor 2; assumption.
simple destruct s; intros.
constructor 1; trivial.
inversion_clear H.
apply posible_T with (1 := H0).
elim H1.
simple destruct s; intros.
constructor 2; assumption.
intros; constructor 1; simpl in |- *; split; assumption.
Qed.
Theorem Equiv2_T :
forall (Sini : S * Instant) (P : Stream (S * Instant) -> Prop),
Inevitable_T Sini P <->
FA_Until_bound Sini (fun _ : Stream (S * Instant) => True) P.
Proof.
unfold iff, Inevitable_T, FA_Until_bound in |- *; intros; split; intros.
elim (H x H0); simple destruct x0.
simple destruct p; intros.
elim H1; intros.
constructor 2; assumption.
constructor 1; trivial.
elim (H x H0); intros.
constructor 2; assumption.
constructor 1; split; assumption.
Qed.
Lemma ConsTrace_T :
forall (s1 s2 : S * Instant) (x z : Stream (S * Instant)),
isTraceFrom_T s2 z ->
isTraceFrom_T s1 (s1 ^ s2 ^ x) -> isTraceFrom_T s1 (s1 ^ z).
Proof.
unfold isTraceFrom_T in |- *; simpl in |- *.
simple destruct z; simple destruct 1; simple destruct 3; simpl in |- *;
intros.
compute in H0; rewrite H0 in H4.
inversion_clear H4 in H1.
split; [ trivial | apply (isTraceTick H5 H1) ].
split; [ trivial | apply (isTraceDisc H5 H6 H1) ].
Qed.
Lemma notPosible_T :
forall (P : Stream (S * Instant) -> Prop) (s1 : S * Instant),
~ Posible_T s1 P ->
forall (z : Stream (S * Instant)) (s2 : S * Instant),
isTraceFrom_T s1 (s1 ^ s2 ^ z) -> ~ Posible_T s2 P.
Proof.
unfold not at 2 in |- *; intros.
elim H1; intros.
apply H; cut (isTraceFrom_T s1 (s1 ^ x)).
intro H4; apply (posible_T (P:=P) H4).
apply Further; assumption.
apply ConsTrace_T with (1 := H2) (2 := H0); assumption.
Qed.
Theorem Equiv3_T :
forall (Sini : S * Instant) (P : Stream (S * Instant) -> Prop),
Always_T Sini P <->
~ Posible_T Sini (fun s : Stream (S * Instant) => ~ P s).
Proof.
unfold iff, Always_T, not in |- *; intros; split.
intros H H0; inversion_clear H0.
generalize (H x H1); elim H2; intros.
inversion_clear H3 in H0.
elim H0; intros.
elim (H6 (H4 H3)).
inversion_clear H4.
apply (H3 H6).
generalize Sini; cofix u.
simple destruct x; intros; constructor.
intro; elim (classic (P (p ^ s))); [ trivial | intros ].
absurd (Posible_T Sini0 (fun s : Stream (S * Instant) => ~ P s)).
assumption.
apply posible_T with (1 := H0).
constructor 1; split; assumption.
elim H0; simpl in |- *; intros.
apply (u (hd s)); intros.
generalize H0; clear H0; generalize H3; clear H3.
rewrite <- H1; case s; simpl in |- *; intros.
apply (notPosible_T (P:=fun s : Stream (S * Instant) => ~ P s) H H0);
assumption.
unfold isTraceFrom_T in |- *; inversion_clear H2; simpl in |- *.
split; trivial.
split; trivial.
Qed.
Theorem Equiv4_T :
forall (Sini : S * Instant) (P : Stream (S * Instant) -> Prop),
SafePath_T Sini P <->
~ Inevitable_T Sini (fun s : Stream (S * Instant) => ~ P s).
Proof.
unfold iff, Inevitable_T, not in |- *; intros; split.
intro sp; inversion sp; intros.
generalize H0; elim (H1 x H); intros.
inversion_clear H3 in H2.
elim H2; intros.
apply (H6 (H4 H3)).
apply H3; inversion_clear H4; assumption.
intro H;
elim
(not_all_ex_not (Stream (S * Instant))
(fun x : Stream (S * Instant) =>
isTraceFrom_T Sini x ->
ExistsS
(fun s : Stream (S * Instant) =>
bound (snd (hd s)) /\ (P s -> False)) x) H).
intros.
generalize
(not_imply_elim2 (isTraceFrom_T Sini x)
(ExistsS
(fun s : Stream (S * Instant) =>
bound (snd (hd s)) /\ (P s -> False)) x) H0).
generalize
(not_imply_elim (isTraceFrom_T Sini x)
(ExistsS
(fun s : Stream (S * Instant) =>
bound (snd (hd s)) /\ (P s -> False)) x) H0);
intros.
apply safePath_T with (1 := H1).
generalize H1; clear H1; generalize H2; clear H2.
generalize x; generalize Sini; cofix u.
simple destruct x0; intros; constructor.
elim (classic (P (p ^ s))); [ trivial | intros ].
cut
(ExistsS
(fun s0 : Stream (S * Instant) =>
bound (snd (hd s0)) /\ (P s0 -> False)) (p ^ s)).
intro ex; elim (H2 ex).
apply
Here
with
(P := fun s : Stream (S * Instant) =>
bound (snd (hd s)) /\ (P s -> False)).
split; assumption.
apply u with (Sini := hd s).
generalize H2; clear H2; case s; unfold not in |- *; intros.
apply (not_EX H2 H3).
unfold isTraceFrom_T in |- *; elim H1; intros ig trace;
inversion_clear trace.
split; trivial.
split; trivial.
Qed.
End TemporalOperators_TCTL.
|
from mmdet.apis import inference_detector, init_detector, show_result_pyplot
import json
import glob
import cv2
import os
import numpy as np
from pycocotools.mask import encode, decode
# 1. Load your model and weights
config = "work_dirs/mask_rcnn_r101_fpn_1x_coco/mask_rcnn_r101_fpn_1x_coco.py"
checkpoint = "work_dirs/mask_rcnn_r101_fpn_1x_coco/epoch_200.pth"
# 2. Initialize the model
model = init_detector(config, checkpoint, device="cuda:0")
with open("dataset/test_img_ids.json") as f:
data = json.load(f)
test_id = {}
i = 0
for image in glob.glob("dataset/test/" + "*.png"):
test_image = image.replace("dataset/test\\", "")
test_id[data[i]["file_name"]] = data[i]["id"]
i += 1
print(test_id)
# Use the results from your model to generate the output json file
result_to_json = []
# for each test image
for image in glob.glob("dataset/test/" + "*.png"):
img_name = image.replace("dataset/test/", "")
image_id = test_id[img_name]
img_path = os.path.join("dataset/test/", img_name)
img = cv2.imread(img_path)
pred = inference_detector(model, img)
print(img_name)
# show_result_pyplot(model,img_path, pred,score_thr=0)
# add each detection box infomation into list
box_result, seg_result = pred
for i in range(len(box_result)):
for j in range(len(box_result[i])):
det_box_info = dict()
# print(number)
# An integer to identify the image
det_box_info["image_id"] = image_id
bbox = box_result[i][j][0:4].tolist()
bbox[2] = bbox[2] - bbox[0]
bbox[3] = bbox[3] - bbox[1]
# A list ( [left_x, top_y, width, height] )
det_box_info["bbox"] = bbox
# A float number between 0 ~ 1 which means the confidence of the bbox
det_box_info["score"] = float(box_result[i][j][4])
# An integer which means the label class
det_box_info["category_id"] = 1
seg = encode(np.asfortranarray(seg_result[i][j]))
seg["counts"] = seg["counts"].decode("utf-8")
det_box_info["segmentation"] = seg
result_to_json.append(det_box_info)
print(det_box_info)
# print(result_to_json)
# Write the list to answer.json
json_object = json.dumps(result_to_json, indent=4)
with open("answer.json", "w") as outfile:
outfile.write(json_object)
|
(*
Copyright 2016 Luxembourg University
Copyright 2017 Luxembourg University
Copyright 2018 Luxembourg University
This file is part of Velisarios.
Velisarios is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Velisarios is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Velisarios. If not, see <http://www.gnu.org/licenses/>.
Authors: Vincent Rahli
Ivana Vukotic
*)
Require Export PBFT_A_1_7.
Require Export PBFT_A_1_10.
Section PBFT_A_1_11.
Local Open Scope eo.
Local Open Scope proc.
Context { pbft_context : PBFTcontext }.
Context { pbft_auth : PBFTauth }.
Context { pbft_keys : PBFTinitial_keys }.
Context { pbft_hash : PBFThash }.
Context { pbft_hash_axioms : PBFThash_axioms }.
(* the difference with PBFT_A_1_7 is that we have here [replica_has_correct_trace]
instead of [isCorrect] *)
Lemma PBFT_A_1_7_v2 :
forall (eo : EventOrdering)
(e : Event)
(L : list Event)
(i : Rep)
(rd : RequestData)
(st : PBFTstate),
authenticated_messages_were_sent_or_byz_usys eo PBFTsys
-> In e L
-> exists_at_most_f_faulty L F
-> PBFTcorrect_keys eo
-> loc e = PBFTreplica i
-> state_sm_on_event (PBFTreplicaSM i) e = Some st
-> committed_log rd (log st) = true
->
exists (R : list Rep),
no_repeats R
/\ F < length R
/\ nodes_have_correct_traces_before R L
/\ forall (k : Rep),
In k R
->
exists (e' : Event) (st' : PBFTstate),
e' βΌ e
/\ loc e' = PBFTreplica k
/\ state_sm_on_event (PBFTreplicaSM k) e' = Some st'
/\ prepared_log rd (log st') = true.
Proof.
introv sendbyz ieL atmostbyz ckeys eqloc eqst comm.
apply is_committed_log_implies_is_committed_entry in comm; exrepnd; subst.
apply is_committed_entry_implies in comm1; repnd.
apply is_prepared_entry_implies in comm2; exrepnd.
assert (well_formed_log (log st)) as wfL by (eauto 3 with pbft).
assert (well_formed_log_entry entry) as wfe by (eapply well_formed_log_entry_if_in; eauto).
pose proof (select_good_guys_before eo (entry2com_senders entry) L F) as sel.
repeat (autodimp sel hyp);
try (apply implies_no_repeats_entry2com_senders; eauto 3 with pbft eo);[].
destruct sel as [G sel]; repnd; simpl in *.
rewrite length_entry2com_senders in sel1.
exists G; dands; auto; try omega;
try (complete (introv w z u v; subst; allrw in_map_iff; exrepnd; subst;
eapply sel; eauto));[].
introv ik.
applydup sel0 in ik.
pose proof (in_entry2com_senders_implies_commit_in_log k entry (log st)) as expl.
repeat (autodimp expl hyp);[].
exrepnd.
dup expl1 as ilog.
eapply commits_are_received_or_generated in expl1;[|eauto];auto.
exrepnd.
apply or_comm in expl3; repndors;[|].
- destruct com, b; simpl in *.
subst i0 k.
pose proof (PBFT_A_1_6 eo e i s v a0 d st) as q.
repeat (autodimp q hyp);[].
exists e st; dands; eauto 2 with eo;
try (complete (rewrite <- expl2; auto));
try (complete (eapply sel; eauto; eauto 3 with eo;
allrw; apply in_map_iff; eexists; dands; eauto)).
- exrepnd.
applydup localLe_implies_loc in expl1.
pose proof (ckeys e' i st1) as ck1; repeat (autodimp ck1 hyp); eauto 3 with eo pbft;[].
pose proof (commit_received_from_good_replica_was_in_log
eo e' k com i) as w.
repeat (autodimp w hyp); try congruence;
try (complete (introv w z; eapply sel; eauto 3 with pbft eo));[].
exrepnd.
destruct com, b; simpl in *.
subst i0.
pose proof (PBFT_A_1_6 eo e'0 k s v a0 d st0) as q.
repeat (autodimp q hyp);[].
exists e'0 st0; dands; eauto 4 with eo;
try (complete (rewrite <- expl2; auto));
try (complete (apply (sel e'0 e); eauto; eauto 4 with eo;
allrw; apply in_map_iff; eexists; dands; eauto)).
Qed.
Hint Resolve PBFT_A_1_7_v2 : pbft.
Lemma PBFT_A_1_11 :
forall (eo : EventOrdering)
(e1 : Event)
(e2 : Event)
(i : Rep)
(j : Rep)
(n : SeqNum)
(v1 : View)
(v2 : View)
(d1 : PBFTdigest)
(d2 : PBFTdigest)
(st1 : PBFTstate)
(st2 : PBFTstate),
authenticated_messages_were_sent_or_byz_usys eo PBFTsys
-> PBFTcorrect_keys eo
-> exists_at_most_f_faulty [e1,e2] F
-> loc e1 = PBFTreplica i
-> loc e2 = PBFTreplica j
-> state_sm_on_event (PBFTreplicaSM i) e1 = Some st1
-> state_sm_on_event (PBFTreplicaSM j) e2 = Some st2
-> committed_log (request_data v1 n d1) (log st1) = true
-> committed_log (request_data v2 n d2) (log st2) = true
-> d1 = d2.
Proof.
introv auth ckeys atMost loci locj eqst1 eqst2 comm1 comm2.
eapply PBFT_A_1_7_v2 in comm1; try exact eqst1; auto; eauto 2 with pbft; simpl; tcsp;[].
eapply PBFT_A_1_7_v2 in comm2; try exact eqst2; auto; eauto 2 with pbft; simpl; tcsp;[].
exrepnd.
pose proof (A_1_10 eo e1 e2 R0 R n v1 v2 d1 d2) as q;
repeat (autodimp q hyp); eauto 3 with pbft eo;[|];
unfold more_than_F_have_prepared_before; dands; auto.
Qed.
End PBFT_A_1_11.
|
------------------------------------------------------------------------------
-- Testing the translation of the logical constants
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LogicalConstants where
infix 5 Β¬_
infixr 4 _β§_
infixr 3 _β¨_
infixr 2 _β_
infixr 1 _β_ _β_
------------------------------------------------------------------------------
-- Propositional logic
-- The logical constants
-- The logical constants are hard-coded in our implementation,
-- i.e. the following symbols must be used (it is possible to use Agda
-- non-dependent function space β instead of β).
postulate
β₯ β€ : Set -- N.B. the name of the tautology symbol is "\top" not T.
Β¬_ : Set β Set -- N.B. the right hole.
_β§_ _β¨_ : Set β Set β Set
_β_ _β_ _β_ : Set β Set β Set
-- We postulate some formulae (which are translated as 0-ary
-- predicates).
postulate A B C : Set
-- Testing the conditional using the non-dependent function type.
postulate AβA : A β A
{-# ATP prove AβA #-}
-- Testing the conditional using the hard-coded function type.
postulate AβA : A β A
{-# ATP prove AβA #-}
-- The introduction and elimination rules for the propositional
-- connectives are theorems.
postulate
βI : (A β B) β A β B
βE : (A β B) β A β B
β§I : A β B β A β§ B
β§Eβ : A β§ B β A
β§Eβ : A β§ B β B
β¨Iβ : A β A β¨ B
β¨Iβ : B β A β¨ B
β¨E : (A β C) β (B β C) β A β¨ B β C
β₯E : β₯ β A
Β¬E : (Β¬ A β β₯) β A
{-# ATP prove βI #-}
{-# ATP prove βE #-}
{-# ATP prove β§I #-}
{-# ATP prove β§Eβ #-}
{-# ATP prove β§Eβ #-}
{-# ATP prove β¨Iβ #-}
{-# ATP prove β¨Iβ #-}
{-# ATP prove β¨E #-}
{-# ATP prove β₯E #-}
{-# ATP prove Β¬E #-}
-- Testing other logical constants.
postulate
thmβ : A β§ β€ β A
thmβ : A β¨ β₯ β A
thmβ : A β A
thmβ : A β A
{-# ATP prove thmβ #-}
{-# ATP prove thmβ #-}
{-# ATP prove thmβ #-}
{-# ATP prove thmβ #-}
------------------------------------------------------------------------------
-- Predicate logic
--- The universe of discourse.
postulate D : Set
-- The propositional equality is hard-coded in our implementation, i.e. the
-- following symbol must be used.
postulate _β‘_ : D β D β Set
-- Testing propositional equality.
postulate refl : β {x} β x β‘ x
{-# ATP prove refl #-}
-- The quantifiers are hard-coded in our implementation, i.e. the
-- following symbols must be used (it is possible to use Agda
-- dependent function space β x β A instead of β).
postulate
β : (A : D β Set) β Set
β : (A : D β Set) β Set
-- We postulate some formulae and propositional functions.
postulate
AΒΉ BΒΉ : D β Set
AΒ² : D β D β Set
-- The introduction and elimination rules for the quantifiers are
-- theorems.
postulate
βIβ : ((x : D) β AΒΉ x) β β AΒΉ
βIβ : ((x : D) β AΒΉ x) β β x β AΒΉ x
βEβ : (t : D) β β AΒΉ β AΒΉ t
βEβ : (t : D) β (β x β AΒΉ x) β AΒΉ t
{-# ATP prove βIβ #-}
{-# ATP prove βIβ #-}
{-# ATP prove βEβ #-}
{-# ATP prove βEβ #-}
postulate βI : (t : D) β AΒΉ t β β AΒΉ
{-# ATP prove βI #-}
postulate βE : β AΒΉ β ((x : D) β AΒΉ x β A) β A
{-# ATP prove βE #-}
|
meta def my_tac : tactic unit :=
`[ repeat { { left, assumption } <|> right <|> assumption } ]
example (p q r : Prop) (hp : p) : p β¨ q β¨ r :=
by my_tac
example (p q r : Prop) (hq : q) : p β¨ q β¨ r :=
by my_tac
example (p q r : Prop) (hr : r) : p β¨ q β¨ r :=
by my_tac
|
A thriving, integrated and inclusive multi-cultural community in Richmond upon Thames and surrounding boroughs.
Our mission is to be the leading charity working to secure racial equality and inclusion in, and celebrate and strengthen the multi-cultural nature of, the Richmond upon Thames community and communities in surrounding boroughs.
More than 26,000 people living in Richmond come from minority ethnic groups. At EMAG we hear daily about people facing disadvantage because of their racial background. Often this arises from a lack of understanding and difficulties in communicating. There are also frequent instances of racial intolerance and racial harassment.
We therefore carry out work and activities to help improve race relations and to help ethnic monitory groups to settle into the areas where they live. Living in a new country is not easy as there are many barriers. Getting used to a new language and local customs are not easy in addition to facing discrimination. We also work with local bodies such as the Police, Richmond Council and the Citizens Advisory Bureau in an advisory and practical capacity.
We work with Ethnic Minority Communities and encourage them to set up self-help groups. We empower them to access their rights and the services available which meet the needs of a diverse community.
We support people who face racial disadvantage.
We give free advice and support to people from minority ethnic groups.
We support victims of racial harassment.
We promote equality of opportunity and good relations between people of different racial groups.
We promote and support the development of self-help groups.
We work in partnership with statutory and other organisations to eliminate unlawful discrimination.
We identify community needs and persuade service providers to meet them.
We recruit and train volunteers.
We manage a lunch club for minority ethnic elders.
Promote equality of opportunity and good relations between persons of different racial groups.
At EMAG we are committed to successful multi-racial communities and we aim to help people who experience racism and to support people who are new to life in Britain.
We work with a range of people and they include all ethnic minorities including Eastern Europeans of all ages.
Our partners play an important role in our work from funding, supporting and helping us deliver services to our users. |
program compute_areas
use iso_fortran_env, only: compiler_version, compiler_options
use class_Circle
use class_Polygon
use class_Rhombus
use class_Square
implicit none
type(Circle) :: c
type(Polygon) :: p
type(Rhombus) :: r
type(Square) :: s
print '(4a)', 'This file was compiled by ', &
compiler_version(), ' using the options ', &
compiler_options()
c = Circle(2.5293)
p = Polygon(19, 1.29312)
r = Rhombus(5.0, 7.8912)
s = Square(10.0)
call c%print
call p%print
call r%print
call s%print
end program
|
-- To run:
--
-- stack build :hardware-examples
--
-- stack build :hardware-trace >& ~/Haskell/concat/hardware/out/o1
--
-- You might also want to use stack's --file-watch flag for automatic recompilation.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -dsuppress-idinfo #-}
{-# OPTIONS_GHC -dsuppress-uniques #-}
{-# OPTIONS_GHC -dsuppress-module-prefixes #-}
-- {-# OPTIONS_GHC -ddump-simpl #-}
-- {-# OPTIONS_GHC -ddump-rule-rewrites #-}
-- {-# OPTIONS_GHC -fsimpl-tick-factor=250 #-} -- default 100
-- {-# OPTIONS -fplugin-opt=ConCat.Plugin:trace #-}
{-# OPTIONS_GHC -fno-do-lambda-eta-expansion #-}
module Main where
import Control.Applicative (liftA2,liftA3)
import Data.Complex
import Data.List (mapAccumL)
import GHC.Float (int2Double) -- TEMP
import GHC.Generics hiding (S)
-- import ShapedTypes.FFT
import ConCat.Pair
import ConCat.FFT
import ConCat.Misc ((:*),R,sqr,magSqr,Unop,Binop,inNew,inNew2,(:+))
import ConCat.Circuit (GenBuses(..),(:>),Ty(..),Buses(..))
import qualified ConCat.RunCircuit as RC
import ConCat.Syntactic (Syn,render)
import ConCat.AltCat (Ok2,ccc,(:**:)(..),toCcc')
import qualified ConCat.AltCat as A
import ConCat.Rebox () -- necessary for reboxing rules to fire
import ConCat.Hardware.Verilog
import ConCat.Rep
import ConCat.Nat
import ConCat.Shaped
main :: IO ()
main = sequence_
[ putChar '\n' -- return ()
-- Unary
, runVerilog' "neg" $ \ (x :: Int) -> - x -- Yields bit inversion, not 2's complement!
, runVerilog' "odd" $ \ (x :: Int) -> x `mod` 2
-- Binary
, runVerilog' "adder" $ \ (x :: Int, y :: Int) -> x + y
-- Conditional
, runVerilog' "cond" $ \ (p :: Bool, x :: Int, y :: Int) -> if p then x else y
-- FFT, via functor composition
-- , runVerilog' "fft_fc_pair" $ \ ( pr :: (UPair (Complex Double)) ) -> fft pr
, runVerilog' "fft_fc_pair" $ \ ( (x0::(Complex Double)) :# x1 ) -> fft (x0 :# x1)
-- , runVerilog' "fft_fc_quad" $ \ ( fc :: ( (Pair :.: Pair) (Complex Float) )) -> fft fc
-- TODO: Understand why only the second alternative, below, works.
-- (The other two cause a compilation time-out error.)
-- , runVerilog' "fft_fc_octet" $ \ ( fc :: ( ((Pair :.: Pair) :.: (Pair :.: Pair)) (Complex Float) )) -> fft fc
, runVerilog' "fft_fc_rb3" $ fft @(RBin N3) @Float
-- , runVerilog' "fft_fc_rb3" $ fft @((Pair :.: Pair) :.: (Pair :.: Pair)) @Float
-- , runCirc "fft-rb3" $ ccc $ fft @(RBin N3) @Double
]
{--------------------------------------------------------------------
Testing utilities
--------------------------------------------------------------------}
runVerilog' :: (GenBuses a, GenBuses b) => String -> (a -> b) -> IO ()
runVerilog' _ _ = error "runVerilog' called directly"
{-# NOINLINE runVerilog' #-}
{-# RULES "runVerilog'"
forall n f. runVerilog' n f = runVerilog n $ toCcc' f #-}
|
(*<*)
theory Tree2 imports Tree begin
(*>*)
text{*\noindent In Exercise~\ref{ex:Tree} we defined a function
@{term"flatten"} from trees to lists. The straightforward version of
@{term"flatten"} is based on @{text"@"} and is thus, like @{term"rev"},
quadratic. A linear time version of @{term"flatten"} again reqires an extra
argument, the accumulator. Define *}
(*<*)primrec(*>*)flatten2 :: "'a tree \<Rightarrow> 'a list \<Rightarrow> 'a list"(*<*)where
"flatten2 Tip xs = xs" |
"flatten2 (Node l x r) xs = flatten2 l (x#(flatten2 r xs))"
(*>*)
text{*\noindent and prove*}
(*<*)
end
(*>*)
|
open import Common.Reflect
open import Common.Prelude
open import Common.Equality
data Maybe A : Set where
nothing : Maybe A
just : A β Maybe A
_<$>_ : β {A B} β (A β B) β Maybe A β Maybe B
f <$> just x = just (f x)
f <$> nothing = nothing
_==_ = primQNameEquality
-- This is awkward!
awkwardUnquoteNat : Term β Maybe Nat
awkwardUnquoteNat (con z []) =
if z == quote Nat.zero
then just 0
else nothing
awkwardUnquoteNat (con s (arg _ n β· [])) =
if s == quote Nat.suc
then suc <$> awkwardUnquoteNat n
else nothing
awkwardUnquoteNat v = nothing
testAwkward : just 10 β‘ awkwardUnquoteNat (quoteTerm 10)
testAwkward = refl
-- This is nicer!
pattern `zero = con (quote Nat.zero) []
pattern `suc n = con (quote Nat.suc) (arg _ n β· [])
unquoteNat : Term β Maybe Nat
unquoteNat `zero = just zero
unquoteNat (`suc n) = suc <$> unquoteNat n
unquoteNat _ = nothing
test : just 10 β‘ unquoteNat (quoteTerm 10)
test = refl
|
% This is based on the LLNCS.DEM the demonstration file of
% the LaTeX macro package from Springer-Verlag
% for Lecture Notes in Computer Science,
% version 2.4 for LaTeX2e as of 16. April 2010
%
% See http://www.springer.com/computer/lncs/lncs+authors?SGWID=0-40209-0-0-0
% for the full guidelines.
%
\documentclass{llncs}
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{url}
\usepackage{listings}
\usepackage[pass]{geometry}
% \usepackage{vmargin}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amsfonts,amssymb,cite,float,graphicx}
% \usepackage[tight,footnotesize]{subfigure}
\usepackage[usenames]{color}
\usepackage{algorithm,algorithmic}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{multicol}
\usepackage{float}
\usepackage{mathtools}
\doublespacing
\begin{document}
\title{Protecting Communications with Reinforcement Learning in a Multi-Agent Game}
%
\titlerunning{Hamiltonian Mechanics} % abbreviated title (for running head)
% also used for the TOC unless
% \toctitle is used
%
\author{Faris Sbahi\inst{1} \and Barrett Ames\inst{2}}
%
\authorrunning{Faris Sbahi et al.} % abbreviated author list (for running head)
%
%%%% list of authors for the TOC (use if author list has to be modified)
%\tocauthor{Ivar Ekeland, Roger Temam, Jeffrey Dean, David Grove,
%Craig Chambers, Kim B. Bruce, and Elisa Bertino}
%
\institute{Primary\\
\email{[email protected]}
\and
Consultant\\
\email{[email protected]}}
\maketitle % typeset the title of the contribution
\begin{abstract}
Here we explore the ability of reinforcement learning (RL) agents to cooperate to establish a secure communication protocol in the face of an adversary without explicit communication. Hence, we construct a general sum mixed cooperative-competitive game to study the effectiveness of various multi-agent RL algorithms to perform in this environment. We compare our results with parallel experiments involving generative adversarial networks. We conclude that the Multi-Agent Deep Deterministic Policy Gradient algorithm prescribed in \cite{lowe2017multi} converges toward the desired behavior of securing protected communications in a period of time with which the other RL algorithms do not, and furthermore it represents a stronger result than the one involving GANs.
\keywords{reinforcement learning, multi-agent, communication, cryptography, generative adversarial networks, multi-agent actor-critic}
\end{abstract}
%
\section{Introduction}
%
%1. What problem does your project address? If you have chosen an application area, please remember that I may not be an expert in the application you have chosen, so be sure to describe the application area clearly.
%
%2. What methods did you use to address the problem?
%
%3. What is the reason you picked the methods you picked? Can you justify theoretically or empirically that this was the best choice?
%
%4. How did you validate your results?
%
%5. What difficulties did you encounter and how did you try to overcome them?
%
%6. What would be the next step if you were to extend this project?
%
%7. What did you learn from this?
%
%8. How did your consultant contribute to your project?
%
Reinforcement learning (RL) has been applied to increasingly complex tasks, ranging from Atari games to robotics. In most cases, the single-agent paradigm is pervasive given that predicting the behavior of other actors is unneeded.
Nevertheless, studying multi-agent systems is increasingly important if we expect to scale RL to interactive systems rather than applying the technique in a vacuum. We may expect that some sort of emergent, co-evolutionary behavior would evolve in a multi-agent setting. Hence, we can ask questions pertaining to social dilemmas\cite{leibo2017multi} and language\cite{foerster2016learning}, reaching Nash equilbria in cooperative or competitive games\cite{pinto2017robust}, or the ability to develop communication to achieve cooperative control tasks\cite{gupta2017cooperative} or even solve riddles\cite{foerster2016learning}.
Here we consider a mixed cooperative-competitive where an agent must communicate to another agent in the presence of an adversary. We find this worth considering because it allows us to study (1) the effectiveness of various RL and non-RL algorithms in a Markov game (defined below) of this type, (2) whether agents can protect their communications without being provided with an explicit cryptographic algorithm, and more broadly (3) whether and/or what kind of equilibria we observe depending on our algorithm and reward structures.
Ultimately, we show that the simple multi-agent extensions of popular reinforcement learning algorithms perform poorly while the Multi-Agent Deep Deterministic Policy Gradient algorithm developed in \cite{lowe2017multi} produces a competitive game. Furthermore, the GAN context described in \cite{abadi2016learning} seems to allow for protected communications between agents but we'll argue that it's likely because of the limited decryption capability one might expect in this setup.
%Hence, the goal of this paper is to take the cryptography game defined in \cite{abadi2016learning} which is suitable for GANs, then to revise and modify it as a Markov game so it is suitable for the multi-agent RL context, and finally to evaluate the effectiveness of various MARL algorithms in this setting.
\subsection{The Problem}
%
The general game is simple.
We seek to define 3 agents Alice, Bob, and Eve such that Alice communicates a message to Bob who must reconstruct the message. Furthermore, adversary Eve observes the channel and additionally seeks to reconstruct the message. Hence, Alice and Bob should be penalized based off of Eve's reconstruction and rewarded based off of Bob's. Furthermore, Alice and Bob use a symmetric, randomly generated key (not available to Eve) to encode their message in a manner with which they define.
\section{Methods}
\subsection{Markov Games}
First, we must extend the traditional Markov Decision Process (MDP) to the multi-agent setting. This is well documented and termed as a Markov Game\cite{leibo2017multi}. An $N$-agent Markov game is given by a collection states $\{ S \}$ with which any agent can take, in addition to actions $\{ A_1 \cdots A_N \}$ and observations $\{ O_1 \cdots O_N \}$. The $i$th agent uses a stochastic policy $\pi_i : O_i \times A_i \rightarrow [0,1]$ which takes the agent to the next state according to the state transition function $\mathcal{T}: S \times A_1 \times \cdots \times A_N \rightarrow S$. Similarly, the $i$th agent obtains rewards as a function of the state and action, and receives an observation. Each agent seeks to maximize its total expected return $R_i = \sum_{t=0}^T \gamma^t r_i^t$ where $r_i : S \times A_i \rightarrow \mathbb{R}$ is the reward associated with the taken action with $\gamma$ as the discount factor and $T$ the time horizon.
%
\subsection{Extending Popular Single-Agent Algorithms}
With this notation in mind, we can readily popular single-agent algorithms to the multi-agent paradigm.
$Q$-learning uses an action-value function for a policy which can be written recursively as $Q^\pi(s,a)= \mathbb{E}_{s'}[r(s,a) + \gamma \mathbb{E}_{a'}[Q^\pi(s', a')]]$. Hence, $Q$-learning can be extended by simply allowing each agent to learn its independently optimal $Q_i$.
Policy gradient can likewise be extended for example by approximating by again having each agent learn its own $Q_i$.
\subsection{Multi-Agent Deep Deterministic Policy Gradient}
Multi-Agent Deep Deterministic Policy Gradient is described by Lowe et. al\cite{lowe2017multi} and is noteworthy because it adopts centralized training with decentralized execution. Hence, it is an actor-critic policy gradient algorithm where the centralized critic is augmented with information about the policies of other agents. The motivation is that if the actions taken by all agents are known, then environment is stationary even as the policies change. So, the centralized $Q$ action-value function takes in the inputs of all agents and outputs the $Q$-value for each agent.
\section{Theoretical Matters}
There are clear issues with the popular single-agent extensions.
First, in the case of $Q$-learning, when each agent updates its individual $Q_i$ the environment appears non-stationary hence violating the Markov property. Furthermore, experience replay in the case of DQN is no longer useful because of each agent's policy being dependent on the policy implemented by the other agents.
Furthermore, policy gradient methods are known to be of high-variance and this is exacerbated in multi-agent settings\cite{lowe2017multi}.
Conceptually, it's clear why MADDPG is particularly useful in our case. If training is centralized and the policies are used to train each agent in our cryptography game, then we can expect added competition and the ability for each agent to uncover motivations in its competitor.
\section{Experiments}
\subsection{GANs}
Following the experimental setup defined in \cite{abadi2016learning}, we setup a mirror experiment with code written in TensorFlow to observe whether neural networks can learn to protect communications between one another.
In summary, we had Alice, Bob, and Eve represented as neural networks. Alice has inputs $P$ and $K$ corresponding to the plaintext message and symmetric key and output $C$ the ciphertext. Bob has inputs $C$ and $K$ with output $P_B$ which is Bob's decryption of $P$. Finally, Eve simply has input $C$ and output $P_E$.
Eve has the simple loss function which corresponds to the L1 distance between $P_E$ and $P$. Alice and Bob share the loss function which corresponds to L1 distance between $P_B$ and $P$ minus $(N/2 - \text{Eve L1 error})^2/(N/2)^2$ where $N$ is the length of $P$. The authors note the peculiarity of this loss function.
In addition to this peculiarity, the authors concede that they had to cut a number of corners to achieve the expected behavior. Note also that the agents are trained in an alternating pattern, switch back and forth between training Eve and then Alice and Bob together. Each epoch represents having trained both parties once.
In our experiments we let the size of the plaintext and key be 4 and the range of values each of the four entries can be -1 to 1. As in Figure 1, we found that the adversary quickly loses ability to decrypt and Alice and Bob converge to an effective protocol. Nevertheless, in all of our experimentations we found that once Eve drifted away from being able to decrypt the message, it never erred back away from randomness. Hence, this may represent a weakness of adversaries in this setup.
\begin{figure}
\centering
\includegraphics[width=\textwidth]{GAN_anc.png}
\caption{Results observed using GANs}
\end{figure}
\subsection{DQN and Policy Gradient}
We omit any charts because we failed to have either algorithm converge to expected behavior in our experimentation given the number of episodes that time permitted i.e. Adam and Bob could not communicate without Eve fully decrypting the message.
Nevertheless, this fits well with our theoretical considerations. We used an open source multi-agent reinforcement learning testbed (\url{https://github.com/sisl/MADRL}) to gather these results.
\subsection{Multi-Agent Deep Deterministic Policy Gradient}
Here we used OpenAI Gym and OpenAI multi-agent-environment-specific code to define our environment and cryptography game. Furthermore, we use TensorFlow to develop the MADDPG algorithm. We validated the algorithm by testing it on a "predator-prey" environment open sourced by OpenAI. We trained the algorithm for 1000 episodes with 1000 steps per episode on a GPU-compute optimized instance on AWS.
We defined our Markov game as analogously as possible to above. We allowed for size $N$ symmetric keys and plaintexts with $N$ values ranging from -1 to 1. Hence, we uniformly at random select initial values for each of these in $[-1, 1]$. Furthermore, we allow a continuous action space across this range for each agent; we define an action to be a length $N$ message that is broadcasted to all agents. Hence, ideally, Alice and Bob can arrange some coded manner of speaking with one another that uses the hidden information (key) and hence won't be learned by Eve. We choose $N=4$ to be consistent. Alice and Bob are rewarded for minimizing the difference between Bob's interpretation of Alice's broadcast message and the original messaged and penalized for Eve's correct interpretation of the message. Eve is rewarded for its correct interpretation of the message.
Now, applying the MADDPG algorithm described above, we noticed that after a few hundred episodes Adam and Bob would pull away from the adversary. Nevertheless, it remains a competitive game and Eve often is able to recover. This may represent Alice and Bob creating a simple coded-language policy which doesn't combine the key and hence can be learned by Eve.
Ultimately, Adam and Bob generally are able to reach an equilibrium and pull away entirely after about 500 episodes. This may represent Alice and Bob determining an effective policy combining the key.
\begin{figure}
\centering
\includegraphics[width=\textwidth]{RL_anc.png}
\caption{Results observed using MADDPG. Bob (Brown) and Eve (Purple).}
\end{figure}
An example is shown in Figure 2. Here we see a slight pulling away after 150 episodes, only to be met by Eve's full recovery and then more pulling away. In our experiments, we found an equilibrium of secure communication after about 500 episodes.
\subsection{Brief Comparisons}
It's difficult to make a direct comparison between the GAN and MADDPG set-ups because the games have a technically different fundamental structure. Nevertheless, we can still define our goal as to secure some means of private communication between agents in the face of \textit{the best possible} adversary. Hence, as we noted above, Eve seemed particularly weak and unable to recover from large enough perturbations from accurate decryption in the GAN case. Furthermore, our goal of keeping the emergence of a protected communication protocol as "unsupervised" as possible is clearly best achieved by the RL algorithms because it did not require the "cutting of corners" described by the authors of the GAN paper.
Finally, one can at least note that the MADDPG algorithm converged at a speed with which the other algorithms could not. This fits with our theoretical considerations.
\section{Conclusion}
We showed that it is difficult to derive meaningful results when using the classic RL algorithms in the multi-agent setting theoretically and empirically in the lens of protected communications.
Nevertheless, interesting results are feasible with GANs though they might be weaker in nature than the results found using MADDPG given the weak ability of the adversary in the GAN context.
\subsection{Further Development}
Other interesting multi-agent reinforcement learning algorithms exist and would be worth testing\cite{gupta2017cooperative}. Furthermore, we redefined the precise structure of our game several times during development, varying what types of actions each agent can make in addition to the reward structure. If time had allowed, it would've been useful to quantify the effect of these changes. It's also interesting to consider the case of having a greater number of adversaries or "good" communicators.
We'd also like to analyze the convergent policy in the RL setting and determine if it's some clear kind of combination with the shared symmetric key.
Finally, it could be interesting to consider combinations of RL and neural network agents. Though, we would then lose the primary benefit of MADDPG, which is agents sharing a critic.
\subsection{Thanks}
Thanks to Prof. Parr for giving me enough time to jam this project into a short period of time. I was able to learn how to run deep reinforcement learning experiments in the cloud, understand a bit about cryptography and GANs, develop an understanding of Markov games, multi-agent reinforcement learning, and some interesting algorithms that have been developed to fill the holes that I mentioned above in the simple single-agent extension algorithms.
Thanks to Barrett for consulting on this project and being flexible with his schedule in addition to being happy to provide feedback.
\bibliographystyle{ieeetr}
\bibliography{cs590}
\nocite{*}
%
% ---- Bibliography ----
%
%\begin{thebibliography}{5}
%
%\bibitem {clar:eke}
%Clarke, F., Ekeland, I.:
%Nonlinear oscillations and
%boundary-value problems for Hamiltonian systems.
%Arch. Rat. Mech. Anal. 78, 315--333 (1982)
%\end{thebibliography}
\end{document}
|
lemma tendsto_complex_iff: "(f \<longlongrightarrow> x) F \<longleftrightarrow> (((\<lambda>x. Re (f x)) \<longlongrightarrow> Re x) F \<and> ((\<lambda>x. Im (f x)) \<longlongrightarrow> Im x) F)" |
C Numerical receipt Fortran 77, 1986-1992
C Modified to adopt 2-D complex model, by calculating beta and alpha from chi^2 directly
SUBROUTINE mrqcof_2Dfftfit_fitDM(prof_amp,prof_pha,tmpl_amp,
+tmpl_pha,sig,a,ia,alpha,beta,chisq,nchan,nbins,freq,D_0,mfit)
parameter (twopi=3.141592653589793*2)
INTEGER nchan,nbins,i,j,k,mfit
INTEGER ia(mfit)
REAL*8 prof_pha(nchan,nbins/2),prof_amp(nchan,nbins/2)
REAL*8 tmpl_amp(nchan,nbins/2),tmpl_pha(nchan,nbins/2)
REAL*8 chisq,a(mfit),alpha(mfit,mfit),beta(mfit)
REAL*8 sc1,sc2,sig(nchan),freq(nchan),D_0,tau_DM(nchan)
do i=1,nchan
tau_DM(i)=D_0*a(nchan+2)/freq(i)**2/nbins*twopi
end do
C Calculate nchan*nchan elements of alpha and nchan elements of beta
C from chi^2, and chi^2
C All summed to nbins/2 and then times by 2
sc1=0.
sc2=0.
do j=1,nchan
beta(j)=0.0
do k=1,nbins/2
sc1=sc1+(prof_amp(j,k)**2+(a(j)*tmpl_amp(j,k))**2)/sig(j)**2
sc2=sc2+2.0*a(j)/sig(j)**2*prof_amp(j,k)*tmpl_amp(j,k)
+ *cos(tmpl_pha(j,k)-prof_pha(j,k)+(tau_DM(j)+a(nchan+1))*k)
beta(j)=beta(j)+2.0*a(j)/(sig(j)**2)*tmpl_amp(j,k)**2
+ -2.0/sig(j)**2*prof_amp(j,k)*tmpl_amp(j,k)*
+ cos(tmpl_pha(j,k)-prof_pha(j,k)+(tau_DM(j)+a(nchan+1))*k)
end do
beta(j)=-beta(j)*0.5*2
do i=1,j
if(i.eq.j) then
alpha(j,i)=0.0
do k=1,nbins/2
alpha(j,i)=alpha(j,i)+2.0*(tmpl_amp(j,k)/sig(j))**2
end do
alpha(j,i)=alpha(j,i)*0.5*2
else
alpha(j,i)=0.0
end if
end do
end do
chisq=(sc1-sc2)*2
C Calculate the rest elements of alpha,beta
beta(nchan+1)=0.0
alpha(nchan+1,nchan+1)=0.0
if(mfit.eq.nchan+2) then
beta(nchan+2)=0.0
alpha(nchan+2,nchan+1)=0.0
alpha(nchan+2,nchan+2)=0.0
endif
do j=1,nchan
alpha(nchan+1,j)=0.0
if(mfit.eq.nchan+2) then
alpha(nchan+2,j)=0.0
end if
do k=1,nbins/2
alpha(nchan+1,nchan+1)=alpha(nchan+1,nchan+1)+
+ 2.0*(a(j)*tmpl_amp(j,k)*k/sig(j))**2
beta(nchan+1)=beta(nchan+1)+2.0*a(j)/(sig(j)**2)*k
+ *prof_amp(j,k)*tmpl_amp(j,k)*sin(tmpl_pha(j,k)
+ -prof_pha(j,k)+(tau_DM(j)+a(nchan+1))*k)
if(mfit.eq.nchan+2) then
beta(nchan+2)=beta(nchan+2)+2.0*a(j)/sig(j)**2*D_0*k
+ /freq(j)**2/nbins*twopi*prof_amp(j,k)*tmpl_amp(j,k)
+ *sin(tmpl_pha(j,k)-prof_pha(j,k)+(tau_DM(j)+a(nchan+1))*k)
alpha(nchan+2,nchan+2)=alpha(nchan+2,nchan+2)
+ +2.0*(a(j)*tmpl_amp(j,k)/sig(j))**2
+ *(D_0*k/(freq(j)**2)/nbins*twopi)**2
alpha(nchan+2,nchan+1)=alpha(nchan+2,nchan+1)
+ +2.0*(a(j)*tmpl_amp(j,k)/sig(j))**2
+ *D_0*(k/freq(j))**2/nbins*twopi
end if
end do
end do
beta(nchan+1)=-beta(nchan+1)*0.5*2
alpha(nchan+1,nchan+1)=alpha(nchan+1,nchan+1)*0.5*2
if(mfit.eq.nchan+2) then
beta(nchan+2)=-beta(nchan+2)*0.5*2
alpha(nchan+2,nchan+1)=alpha(nchan+2,nchan+1)*0.5*2
alpha(nchan+2,nchan+2)=alpha(nchan+2,nchan+2)*0.5*2
end if
C Fill in the symmetric side of alpha
do 18 j=2,mfit
do 17 k=1,j-1
alpha(k,j)=alpha(j,k)
17 continue
18 continue
return
END
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
lemma homotopy_eqv_homotopic_triviality: fixes S :: "'a::real_normed_vector set" and T :: "'b::real_normed_vector set" and U :: "'c::real_normed_vector set" assumes "S homotopy_eqv T" shows "(\<forall>f g. continuous_on U f \<and> f ` U \<subseteq> S \<and> continuous_on U g \<and> g ` U \<subseteq> S \<longrightarrow> homotopic_with_canon (\<lambda>x. True) U S f g) \<longleftrightarrow> (\<forall>f g. continuous_on U f \<and> f ` U \<subseteq> T \<and> continuous_on U g \<and> g ` U \<subseteq> T \<longrightarrow> homotopic_with_canon (\<lambda>x. True) U T f g)" (is "?lhs = ?rhs") |
Especially, during the last 10 years a lot of projects have been carried out at Groyne 42. The projects range from mapping of the comprehensive contamination of the area through examination of the contaminated area to development of models for the spreading of the toxic chemicals to the North Sea.
We have produced a chronologically list of all publications related to the toxic waste site at Groyne 42. Data from the NorthPestClean pilot experiments will be published on our website to make sure that everyone who might be interested has full access to the latest data.
In connection with the project, tasks have been put out to tender. Tender material is published on our website to make sure that everyone who might be interested in bidding has full access to the relevant information. |
module Clash.DSP.FFT.Twiddle (
twiddleFactors,
halveTwiddles
) where
import Clash.Prelude
import qualified Data.Complex as C
import qualified Prelude as P
import Clash.DSP.Complex
-- | Calculate FFT `twiddle` factors. You probably want to do this with template Haskell to ensure they are calculated at compile time.
twiddleFactors
:: Int -- ^ Twiddle factor vector length
-> [Complex Double] -- ^ Twiddle factors
twiddleFactors num = P.take num $ [fromComplex $ C.cis $ (-1) * P.pi * fromIntegral i / (fromIntegral num) | i <- [0..]]
-- | Take every second element of a vector of twiddle factors.
halveTwiddles
:: KnownNat n
=> Vec (2 * n) a -- ^ Twiddle factors
-> Vec n a -- ^ Halved output twiddle factors
halveTwiddles vec = transpose (unconcat (SNat @ 2) vec) !! 0
|
Our #CarerConversations toolkit is now available to help you get involved with Carers Week 11 - 17 June 2018.
Carers Week is the national celebration of unpaid carersβ contribution to our communities. Over 33,000 people care for a friend, relative or neighbour due to illness, disability or old age in the borough of Croydon alone.
Organisations, individuals, businesses and community groups can now download free resources, including posters, pledges, flyers and Facebook and Twitter graphics to help start #CarerConversations in Croydon.
You can also find useful tips and guidance on the national Carers Week website.
For more information about Carers Week at the Carers Support Centre and #CarerConversations, email our Communications Officer on [email protected]. |
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE BangPatterns,
ScopedTypeVariables,
RecordWildCards,
FlexibleContexts,
TypeFamilies #-}
import Data.IDX (IDXData, decodeIDXFile, idxIntContent )
{------------------------}
import Numeric.LinearAlgebra as NL (cmap, (#>), vjoin, Numeric, Vector, fromList )
{------------------------}
import Data.Vector.Unboxed as DTU ( toList )
import qualified Data.Vector.Storable as DT
import Data.List (sort)
import Prelude hiding (readFile)
import Neuro
( ActivationFunction, Network(..), loadNetwork )
kol_vo :: Int
kol_vo = 1000
main :: IO ()
main = do
res <- loadNetwork "smartNet5.nn"
Just idxTrain <- decodeIDXFile "test/t10k-images.idx3-ubyte" -- image
Just idxResult <- decodeIDXFile "test/t10k-labels.idx1-ubyte" -- result
--writeFile "resNeuro.txt" (concat $ take (28*kol_vo) $ drowImage idxTrain)
--writeFile "resLabel.txt" (show $ take kol_vo $ DTU.toList $ idxIntContent idxResult)
putStrLn "Π’ΠΎΡΠ½ΠΎΡΡΡ Π°Π»Π³ΠΎΡΠΈΡΠΌΠ° :"
print $ (\x -> (fromIntegral x) / fromIntegral kol_vo) $ length $ filter (\((_,x),y) -> x == y) $ flip zip (filterCorrect idxResult) $ printRes kol_vo res idxTrain $ DTU.toList $ idxIntContent idxResult
where filterCorrect idxResult = reverse $ take kol_vo $ DTU.toList $ idxIntContent idxResult
printRes :: Int -> Network Double -> IDXData -> t -> [(Double,Int)]
printRes 0 _ _ _ = []
printRes x res idxTrain idxResult = last (sort $ flip zip [0..] $ softmax $ DT.toList $ Main.output res tanh (last $ take x $ image idxTrain)) : printRes (x-1) res idxTrain idxResult
output :: (Floating (Vector a), Numeric a, DT.Storable a, Num (Vector a)) => Network a -> ActivationFunction a -> Vector a -> Vector a
output (Network{..}) act input = foldl f (vjoin [input, 1]) matrices
where f (!inp) m = cmap act $ m #> inp
softmax :: [Double] -> [Double]
softmax xs = let xs' = exp <$> xs
s = sum xs'
in map (/ s) xs'
drowImage :: IDXData -> [String]
drowImage = _0_255to0or1 . DTU.toList . idxIntContent
_0_255to0or1 :: [Int] -> [String]
_0_255to0or1 [] = []
_0_255to0or1 xs = (show (concat $ fmap show $ convert $ take 28 xs) ++ " \n") : _0_255to0or1 (drop 28 xs)
convert [] = []
convert (x:xs)
| x > 240 = 1 : convert xs
| otherwise = 0 : convert xs
image :: IDXData -> [Vector Double]
image = matrix2x2 . _0_1to0_255 . DTU.toList . idxIntContent
result :: IDXData -> [Vector Double]
result = unitar . DTU.toList . idxIntContent
unitar :: [Int] -> [NL.Vector Double]
unitar [] = []
unitar (0:xs) = NL.fromList [1,-1,-1,-1,-1,-1,-1,-1,-1,-1] : unitar xs
unitar (1:xs) = NL.fromList [-1,1,-1,-1,-1,-1,-1,-1,-1,-1] : unitar xs
unitar (2:xs) = NL.fromList [-1,-1,1,-1,-1,-1,-1,-1,-1,-1] : unitar xs
unitar (3:xs) = NL.fromList [-1,-1,-1,1,-1,-1,-1,-1,-1,-1] : unitar xs
unitar (4:xs) = NL.fromList [-1,-1,-1,-1,1,-1,-1,-1,-1,-1] : unitar xs
unitar (5:xs) = NL.fromList [-1,-1,-1,-1,-1,1,-1,-1,-1,-1] : unitar xs
unitar (6:xs) = NL.fromList [-1,-1,-1,-1,-1,-1,1,-1,-1,-1] : unitar xs
unitar (7:xs) = NL.fromList [-1,-1,-1,-1,-1,-1,-1,1,-1,-1] : unitar xs
unitar (8:xs) = NL.fromList [-1,-1,-1,-1,-1,-1,-1,-1,1,-1] : unitar xs
unitar (9:xs) = NL.fromList [-1,-1,-1,-1,-1,-1,-1,-1,-1,1] : unitar xs
_0_1to0_255 :: [Int] -> [Double]
_0_1to0_255 [] = []
_0_1to0_255 (x:xs) = (fromIntegral x / 255) : _0_1to0_255 xs
matrix2x2 :: [Double] -> [NL.Vector Double]
matrix2x2 [] = []
matrix2x2 xs = NL.fromList (Prelude.take 784 xs) : matrix2x2 (Prelude.drop 784 xs)
|
lemma Borsukian_eq_simply_connected: fixes S :: "complex set" shows "open S \<Longrightarrow> Borsukian S \<longleftrightarrow> (\<forall>C \<in> components S. simply_connected C)" |
function runtop
% See Article 8.6
a=.01; h=4; b=2; n=6; m=3; k=20;
psi=45; theta=-45; phi=0;
for j=1:2:720
psi=180+j; theta=-45+5*sin(.15*psi); phi=1.5*j;
topdraw(a,h,b,8,m,18,psi,theta,phi);
% topdraw(a,h,b,8,m,18,j,-45,1.5*j);
end
pause(1),% close
%================================================
function [x,y, z]=topdraw(a,h,b,n,m,k,psi,theta,phi)
% [x,y, z]=topdraw(a,h,b,n,m,k,psi,theta,phi)
% [X,Y,Z]=topsurf(n,m,k,a,h,b)
if nargin==0
a=.01; h=4; b=2; n=6; m=3; k=20;
psi=45; theta=-45; phi=0;
end
%s=sqrt(h^2+(a-b)^2); uax=cumsum([0,a,s,b]);
%u=cornrpts(uax/uax(4),nax+1);
%v=linspace(0,1,ncrc+1);
[dx,dy,dz]=topsurf(n,m,k,a,h,b);
x=dz; y=dx; z=dy;
m=eulerang(psi,theta,phi);
p=size(x); v=[x(:),y(:),z(:)]*m;
x=reshape(v(:,1),p); y=reshape(v(:,2),p);
z=reshape(v(:,3),p);
w=[-1 1 -1 1 -1 1]*sqrt(h^2+b^2);
%rotate3d on;
clf; surf(x,y,z), view([-45,30])
axis equal; axis(w); axis on
xlabel('x axis'), ylabel('y axis')
zlabel('z axis')
title('NUTATING TOP PRECESSION')
colormap([127/255 1 212/255]); drawnow, shg
%============================================
function m=eulerang(psi,theta,phi)
% m=eulerang(psi,theta,phi)
a=pi/180*[psi,theta,phi]; c=cos(a); s=sin(a);
m=[c(1)*c(2), s(1)*c(2), -s(2); -s(1)*c(3)+...
c(1)*s(2)*s(3), c(1)*c(3)+s(1)*s(2)*s(3),...
c(2)*s(3); s(1)*s(3)+c(1)*s(2)*c(3),...
-c(1)*s(3)+s(1)*s(2)*c(3), c(2)*c(3)];
%============================================
function [X,Y,Z]=topsurf(n,m,k,a,h,b)
% [X,Y,Z]=topsurf(n,m,k,a,h,b)
if nargin==0
n=8; m=4; k=20; a=.2; h=4; b=1;
end
tol=100*eps*(a+h+b);
a=a+(a==0)*tol; b=b+(b==0)*tol;
D=2*pi/n; u=cos(D/2); v=sin(D/2);
z=u+i*linspace(-v,v,m+1)'; z(m+1)=[];
z=z*exp(i*D*(0:n-1)); z=[z(:);u-i*v];
x=real(z); y=imag(z); N=length(x);
% plot(x,y,x,y,'.'), axis equal, shg, pause
qd=cumsum([0;a;sqrt(h^2+(a-b)^2);b]);
qd=qd/max(qd); q=cornrpts(qd,k);
K=length(q);
Z=interp1(qd,[0;0;h;h],q(:))*ones(1,N);
r=interp1(qd,[0;a;b;0],q); r=r(:);
X=r*x(:)'; Y=r*y(:)';
%============================================
function v=cornrpts(u,N)
% v=cornrpts(u,N)
% This function generates a set of approximately
% N points between min(u) and max(u) including
% all points in u plus additional points evenly
% spaced in each successive interval.
% u - vector of points
% N - approximate number of output points
% between min(u(:)) and max(u(:))
% v - vector of points in increasing order
u=sort(u(:))'; np=length(u); d=u(np)-u(1); v=u(1);
for j=1:np-1
dj=u(j+1)-u(j); nj=max(1,fix(N*dj/d));
v=[v,[u(j)+dj/nj*(1:nj)]];
end |
module Main
import Effects
import Effect.File
import Effect.State
import Effect.StdIO
import Control.IOExcept
data Count : Type where
TestFileIO : Type -> Type -> Type
TestFileIO st t = Eff t [FILE st, STDIO, Count ::: STATE Int]
readFileCount : Eff (FileOpResult (List String)) [FILE R, STDIO, Count ::: STATE Int]
readFileCount = readAcc []
where
readAcc : List String
-> Eff (FileOpResult (List String)) [FILE R, STDIO, Count ::: STATE Int]
readAcc acc = do
e <- eof
if (not e)
then do
(Result str) <- readLine
| (FError err) => pure (FError err)
Count :- put (!(Count :- get) + 1)
readAcc (str :: acc)
else do
let res = reverse acc
pure $ Result res
testFile : TestFileIO () ()
testFile = do
Success <- open "testFile" Read
| (FError err) => do
putStrLn "Error!"
pure ()
(Result fcontents) <- readFileCount
| (FError err) => do
close
putStrLn "Error!"
pure ()
putStrLn (show fcontents)
close
putStrLn (show !(Count :- get))
main : IO ()
main = run testFile
|
#define BOOST_TEST_MODULE nimu_ann_test_ann_static
#include <boost/test/unit_test.hpp>
#include <nimu/ann/ann_static.hpp>
BOOST_AUTO_TEST_SUITE(ann_static)
BOOST_AUTO_TEST_CASE(constructor_1)
{
BOOST_TEST(true);
}
BOOST_AUTO_TEST_SUITE_END()
|
A set $M$ is an algebra if and only if it is a subset of the power set of $\Omega$, contains the empty set, is closed under complements, and is closed under unions. |
lemma convex_hull_empty[simp]: "convex hull {} = {}" |
# Sympy and PhysicalQuantities
```python
%load_ext PhysicalQuantities.ipython
```
```python
from sympy import *
init_printing()
```
```python
a = 1 m * Matrix([ [1,2,3], [4,5,6]])
b = 1 cm * Matrix([ [1,2,3], [4,5,6]])
```
```python
a
```
$\left[\begin{matrix}1 & 2 & 3\\4 & 5 & 6\end{matrix}\right]$ $\text{m}$
```python
a+b
```
$\left[\begin{matrix}1.01 & 2.02 & 3.03\\4.04 & 5.05 & 6.06\end{matrix}\right]$ $\text{m}$
```python
x = Symbol('x')
```
```python
1 m * x
```
$x$ $\text{m}$
```python
a = 2 m * x
a
```
$2 x$ $\text{m}$
```python
a/3
```
$\frac{2 x}{3}$ $\text{m}$
```python
Integral(sqrt(1/x), x)
```
```python
```
|
(* Checking no anomaly on some unexpected intropattern *)
Ltac ih H := induction H as H.
Ltac ih' H H' := induction H as H'.
Goal True -> True.
Fail intro H; ih H.
intro H; ih' H ipattern:([]).
exact I.
Qed.
|
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
β’ β j k, 0 < k β§ k β€ βn β§ |βk * ΞΎ - βj| β€ 1 / (βn + 1)
[PROOFSTEP]
let f : β€ β β€ := fun m => βfract (ΞΎ * m) * (n + 1)β
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
β’ β j k, 0 < k β§ k β€ βn β§ |βk * ΞΎ - βj| β€ 1 / (βn + 1)
[PROOFSTEP]
have hn : 0 < (n : β) + 1 := by exact_mod_cast Nat.succ_pos _
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
β’ 0 < βn + 1
[PROOFSTEP]
exact_mod_cast Nat.succ_pos _
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
β’ β j k, 0 < k β§ k β€ βn β§ |βk * ΞΎ - βj| β€ 1 / (βn + 1)
[PROOFSTEP]
have hfu := fun m : β€ => mul_lt_of_lt_one_left hn <| fract_lt_one (ΞΎ * βm)
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
β’ β j k, 0 < k β§ k β€ βn β§ |βk * ΞΎ - βj| β€ 1 / (βn + 1)
[PROOFSTEP]
conv in |_| β€ _ => rw [mul_comm, le_div_iff hn, β abs_of_pos hn, β abs_mul]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
j k : β€
| |βk * ΞΎ - βj| β€ 1 / (βn + 1)
[PROOFSTEP]
rw [mul_comm, le_div_iff hn, β abs_of_pos hn, β abs_mul]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
j k : β€
| |βk * ΞΎ - βj| β€ 1 / (βn + 1)
[PROOFSTEP]
rw [mul_comm, le_div_iff hn, β abs_of_pos hn, β abs_mul]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
j k : β€
| |βk * ΞΎ - βj| β€ 1 / (βn + 1)
[PROOFSTEP]
rw [mul_comm, le_div_iff hn, β abs_of_pos hn, β abs_mul]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
let D := Icc (0 : β€) n
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
by_cases H : β m β D, f m = n
[GOAL]
case pos
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β m, m β D β§ f m = βn
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
obtain β¨m, hm, hfβ© := H
[GOAL]
case pos.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
have hf' : ((n : β€) : β) β€ fract (ΞΎ * m) * (n + 1) := hf βΈ floor_le (fract (ΞΎ * m) * (n + 1))
[GOAL]
case pos.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
have hmβ : 0 < m :=
by
have hfβ : f 0 = 0 := by
-- Porting note: was
-- simp only [floor_eq_zero_iff, algebraMap.coe_zero, mul_zero, fract_zero,
-- zero_mul, Set.left_mem_Ico, zero_lt_one]simp only [cast_zero, mul_zero, fract_zero, zero_mul,
floor_zero]
refine' Ne.lt_of_le (fun h => n_pos.ne _) (mem_Icc.mp hm).1
exact_mod_cast hfβ.symm.trans (h.symm βΈ hf : f 0 = n)
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
β’ 0 < m
[PROOFSTEP]
have hfβ : f 0 = 0 := by
-- Porting note: was
-- simp only [floor_eq_zero_iff, algebraMap.coe_zero, mul_zero, fract_zero,
-- zero_mul, Set.left_mem_Ico, zero_lt_one]simp only [cast_zero, mul_zero, fract_zero, zero_mul, floor_zero]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
β’ f 0 = 0
[PROOFSTEP]
simp only [cast_zero, mul_zero, fract_zero, zero_mul, floor_zero]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
hfβ : f 0 = 0
β’ 0 < m
[PROOFSTEP]
refine' Ne.lt_of_le (fun h => n_pos.ne _) (mem_Icc.mp hm).1
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
hfβ : f 0 = 0
h : 0 = m
β’ 0 = n
[PROOFSTEP]
exact_mod_cast hfβ.symm.trans (h.symm βΈ hf : f 0 = n)
[GOAL]
case pos.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
hmβ : 0 < m
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
refine' β¨βΞΎ * mβ + 1, m, hmβ, (mem_Icc.mp hm).2, _β©
[GOAL]
case pos.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
hmβ : 0 < m
β’ |(ΞΎ * βm - β(βΞΎ * βmβ + 1)) * (βn + 1)| β€ 1
[PROOFSTEP]
rw [cast_add, β sub_sub, sub_mul, cast_one, one_mul, abs_le]
[GOAL]
case pos.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
hmβ : 0 < m
β’ -1 β€ (ΞΎ * βm - ββΞΎ * βmβ) * (βn + 1) - (βn + 1) β§ (ΞΎ * βm - ββΞΎ * βmβ) * (βn + 1) - (βn + 1) β€ 1
[PROOFSTEP]
refine' β¨le_sub_iff_add_le.mpr _, sub_le_iff_le_add.mpr <| le_of_lt <| (hfu m).trans <| lt_one_add _β©
[GOAL]
case pos.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
m : β€
hm : m β D
hf : f m = βn
hf' : ββn β€ fract (ΞΎ * βm) * (βn + 1)
hmβ : 0 < m
β’ -1 + (βn + 1) β€ (ΞΎ * βm - ββΞΎ * βmβ) * (βn + 1)
[PROOFSTEP]
simpa only [neg_add_cancel_comm_assoc] using hf'
[GOAL]
case neg
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : Β¬β m, m β D β§ f m = βn
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
simp_rw [not_exists, not_and] at H
[GOAL]
case neg
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
have hD : (Ico (0 : β€) n).card < D.card := by rw [card_Icc, card_Ico]; exact lt_add_one n
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
β’ card (Ico 0 βn) < card D
[PROOFSTEP]
rw [card_Icc, card_Ico]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
β’ toNat (βn - 0) < toNat (βn + 1 - 0)
[PROOFSTEP]
exact lt_add_one n
[GOAL]
case neg
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
have hfu' : β m, f m β€ n := fun m => lt_add_one_iff.mp (floor_lt.mpr (by exact_mod_cast hfu m))
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
m : β€
β’ fract (ΞΎ * βm) * (βn + 1) < β(βn + 1)
[PROOFSTEP]
exact_mod_cast hfu m
[GOAL]
case neg
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
have hwd : β m : β€, m β D β f m β Ico (0 : β€) n := fun x hx =>
mem_Ico.mpr β¨floor_nonneg.mpr (mul_nonneg (fract_nonneg (ΞΎ * x)) hn.le), Ne.lt_of_le (H x hx) (hfu' x)β©
[GOAL]
case neg
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
have : β (x : β€) (_ : x β D) (y : β€) (_ : y β D), x < y β§ f x = f y :=
by
obtain β¨x, hx, y, hy, x_ne_y, hxyβ© := exists_ne_map_eq_of_card_lt_of_maps_to hD hwd
rcases lt_trichotomy x y with (h | h | h)
exacts [β¨x, hx, y, hy, h, hxyβ©, False.elim (x_ne_y h), β¨y, hy, x, hx, h, hxy.symmβ©]
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
β’ β x x_1 y x_2, x < y β§ f x = f y
[PROOFSTEP]
obtain β¨x, hx, y, hy, x_ne_y, hxyβ© := exists_ne_map_eq_of_card_lt_of_maps_to hD hwd
[GOAL]
case intro.intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_ne_y : x β y
hxy : f x = f y
β’ β x x_1 y x_2, x < y β§ f x = f y
[PROOFSTEP]
rcases lt_trichotomy x y with (h | h | h)
[GOAL]
case intro.intro.intro.intro.intro.inl
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_ne_y : x β y
hxy : f x = f y
h : x < y
β’ β x x_1 y x_2, x < y β§ f x = f y
case intro.intro.intro.intro.intro.inr.inl
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_ne_y : x β y
hxy : f x = f y
h : x = y
β’ β x x_1 y x_2, x < y β§ f x = f y
case intro.intro.intro.intro.intro.inr.inr
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_ne_y : x β y
hxy : f x = f y
h : y < x
β’ β x x_1 y x_2, x < y β§ f x = f y
[PROOFSTEP]
exacts [β¨x, hx, y, hy, h, hxyβ©, False.elim (x_ne_y h), β¨y, hy, x, hx, h, hxy.symmβ©]
[GOAL]
case neg
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
this : β x x_1 y x_2, x < y β§ f x = f y
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
obtain β¨x, hx, y, hy, x_lt_y, hxyβ© := this
[GOAL]
case neg.intro.intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_lt_y : x < y
hxy : f x = f y
β’ β j k, 0 < k β§ k β€ βn β§ |(ΞΎ * βk - βj) * (βn + 1)| β€ 1
[PROOFSTEP]
refine'
β¨βΞΎ * yβ - βΞΎ * xβ, y - x, sub_pos_of_lt x_lt_y,
sub_le_iff_le_add.mpr <| le_add_of_le_of_nonneg (mem_Icc.mp hy).2 (mem_Icc.mp hx).1, _β©
[GOAL]
case neg.intro.intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_lt_y : x < y
hxy : f x = f y
β’ |(ΞΎ * β(y - x) - β(βΞΎ * βyβ - βΞΎ * βxβ)) * (βn + 1)| β€ 1
[PROOFSTEP]
convert_to |fract (ΞΎ * y) * (n + 1) - fract (ΞΎ * x) * (n + 1)| β€ 1
[GOAL]
case h.e'_3
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_lt_y : x < y
hxy : f x = f y
β’ |(ΞΎ * β(y - x) - β(βΞΎ * βyβ - βΞΎ * βxβ)) * (βn + 1)| = |fract (ΞΎ * βy) * (βn + 1) - fract (ΞΎ * βx) * (βn + 1)|
[PROOFSTEP]
congr
[GOAL]
case h.e'_3.e_a
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_lt_y : x < y
hxy : f x = f y
β’ (ΞΎ * β(y - x) - β(βΞΎ * βyβ - βΞΎ * βxβ)) * (βn + 1) = fract (ΞΎ * βy) * (βn + 1) - fract (ΞΎ * βx) * (βn + 1)
[PROOFSTEP]
push_cast
[GOAL]
case h.e'_3.e_a
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_lt_y : x < y
hxy : f x = f y
β’ (ΞΎ * (βy - βx) - (ββΞΎ * βyβ - ββΞΎ * βxβ)) * (βn + 1) = fract (ΞΎ * βy) * (βn + 1) - fract (ΞΎ * βx) * (βn + 1)
[PROOFSTEP]
simp only [fract]
[GOAL]
case h.e'_3.e_a
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_lt_y : x < y
hxy : f x = f y
β’ (ΞΎ * (βy - βx) - (ββΞΎ * βyβ - ββΞΎ * βxβ)) * (βn + 1) =
(ΞΎ * βy - ββΞΎ * βyβ) * (βn + 1) - (ΞΎ * βx - ββΞΎ * βxβ) * (βn + 1)
[PROOFSTEP]
ring
[GOAL]
case neg.intro.intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
f : β€ β β€ := fun m => βfract (ΞΎ * βm) * (βn + 1)β
hn : 0 < βn + 1
hfu : β (m : β€), fract (ΞΎ * βm) * (βn + 1) < βn + 1
D : Finset β€ := Icc 0 βn
H : β (x : β€), x β Icc 0 βn β Β¬βfract (ΞΎ * βx) * (βn + 1)β = βn
hD : card (Ico 0 βn) < card D
hfu' : β (m : β€), f m β€ βn
hwd : β (m : β€), m β D β f m β Ico 0 βn
x : β€
hx : x β D
y : β€
hy : y β D
x_lt_y : x < y
hxy : f x = f y
β’ |fract (ΞΎ * βy) * (βn + 1) - fract (ΞΎ * βx) * (βn + 1)| β€ 1
[PROOFSTEP]
exact (abs_sub_lt_one_of_floor_eq_floor hxy.symm).le
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
β’ β k, 0 < k β§ k β€ n β§ |βk * ΞΎ - β(round (βk * ΞΎ))| β€ 1 / (βn + 1)
[PROOFSTEP]
obtain β¨j, k, hkβ, hkβ, hβ© := exists_int_int_abs_mul_sub_le ΞΎ n_pos
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
β’ β k, 0 < k β§ k β€ n β§ |βk * ΞΎ - β(round (βk * ΞΎ))| β€ 1 / (βn + 1)
[PROOFSTEP]
have hk := toNat_of_nonneg hkβ.le
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hk : β(toNat k) = k
β’ β k, 0 < k β§ k β€ n β§ |βk * ΞΎ - β(round (βk * ΞΎ))| β€ 1 / (βn + 1)
[PROOFSTEP]
rw [β hk] at hkβ hkβ h
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < β(toNat k)
hkβ : β(toNat k) β€ βn
h : |ββ(toNat k) * ΞΎ - βj| β€ 1 / (βn + 1)
hk : β(toNat k) = k
β’ β k, 0 < k β§ k β€ n β§ |βk * ΞΎ - β(round (βk * ΞΎ))| β€ 1 / (βn + 1)
[PROOFSTEP]
exact β¨k.toNat, coe_nat_pos.mp hkβ, Nat.cast_le.mp hkβ, (round_le (βk.toNat * ΞΎ) j).trans hβ©
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
β’ β q, |ΞΎ - βq| β€ 1 / ((βn + 1) * βq.den) β§ q.den β€ n
[PROOFSTEP]
obtain β¨j, k, hkβ, hkβ, hβ© := exists_int_int_abs_mul_sub_le ΞΎ n_pos
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
β’ β q, |ΞΎ - βq| β€ 1 / ((βn + 1) * βq.den) β§ q.den β€ n
[PROOFSTEP]
have hkβ' : (0 : β) < k := Int.cast_pos.mpr hkβ
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hkβ' : 0 < βk
β’ β q, |ΞΎ - βq| β€ 1 / ((βn + 1) * βq.den) β§ q.den β€ n
[PROOFSTEP]
have hden : ((j / k : β).den : β€) β€ k :=
by
convert le_of_dvd hkβ (Rat.den_dvd j k)
exact Rat.coe_int_div_eq_divInt
[GOAL]
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hkβ' : 0 < βk
β’ β(βj / βk).den β€ k
[PROOFSTEP]
convert le_of_dvd hkβ (Rat.den_dvd j k)
[GOAL]
case h.e'_3.h.e'_3.h.e'_1
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hkβ' : 0 < βk
β’ βj / βk = Rat.divInt j k
[PROOFSTEP]
exact Rat.coe_int_div_eq_divInt
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hkβ' : 0 < βk
hden : β(βj / βk).den β€ k
β’ β q, |ΞΎ - βq| β€ 1 / ((βn + 1) * βq.den) β§ q.den β€ n
[PROOFSTEP]
refine' β¨j / k, _, Nat.cast_le.mp (hden.trans hkβ)β©
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hkβ' : 0 < βk
hden : β(βj / βk).den β€ k
β’ |ΞΎ - β(βj / βk)| β€ 1 / ((βn + 1) * β(βj / βk).den)
[PROOFSTEP]
rw [β div_div, le_div_iff (Nat.cast_pos.mpr <| Rat.pos _ : (0 : β) < _)]
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hkβ' : 0 < βk
hden : β(βj / βk).den β€ k
β’ |ΞΎ - β(βj / βk)| * β(βj / βk).den β€ 1 / (βn + 1)
[PROOFSTEP]
refine' (mul_le_mul_of_nonneg_left (Int.cast_le.mpr hden : _ β€ (k : β)) (abs_nonneg _)).trans _
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
n : β
n_pos : 0 < n
j k : β€
hkβ : 0 < k
hkβ : k β€ βn
h : |βk * ΞΎ - βj| β€ 1 / (βn + 1)
hkβ' : 0 < βk
hden : β(βj / βk).den β€ k
β’ |ΞΎ - β(βj / βk)| * βk β€ 1 / (βn + 1)
[PROOFSTEP]
rwa [β abs_of_pos hkβ', Rat.cast_div, Rat.cast_coe_int, Rat.cast_coe_int, β abs_mul, sub_mul, div_mul_cancel _ hkβ'.ne',
mul_comm]
[GOAL]
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
β’ β q', |ΞΎ - βq'| < 1 / βq'.den ^ 2 β§ |ΞΎ - βq'| < |ΞΎ - βq|
[PROOFSTEP]
have h := abs_pos.mpr (sub_ne_zero.mpr <| Irrational.ne_rat hΞΎ q)
[GOAL]
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
β’ β q', |ΞΎ - βq'| < 1 / βq'.den ^ 2 β§ |ΞΎ - βq'| < |ΞΎ - βq|
[PROOFSTEP]
obtain β¨m, hmβ© := exists_nat_gt (1 / |ΞΎ - q|)
[GOAL]
case intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
β’ β q', |ΞΎ - βq'| < 1 / βq'.den ^ 2 β§ |ΞΎ - βq'| < |ΞΎ - βq|
[PROOFSTEP]
have m_pos : (0 : β) < m := (one_div_pos.mpr h).trans hm
[GOAL]
case intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
m_pos : 0 < βm
β’ β q', |ΞΎ - βq'| < 1 / βq'.den ^ 2 β§ |ΞΎ - βq'| < |ΞΎ - βq|
[PROOFSTEP]
obtain β¨q', hbd, hdenβ© := exists_rat_abs_sub_le_and_den_le ΞΎ (Nat.cast_pos.mp m_pos)
[GOAL]
case intro.intro.intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
m_pos : 0 < βm
q' : β
hbd : |ΞΎ - βq'| β€ 1 / ((βm + 1) * βq'.den)
hden : q'.den β€ m
β’ β q', |ΞΎ - βq'| < 1 / βq'.den ^ 2 β§ |ΞΎ - βq'| < |ΞΎ - βq|
[PROOFSTEP]
have den_pos : (0 : β) < q'.den := Nat.cast_pos.mpr q'.pos
[GOAL]
case intro.intro.intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
m_pos : 0 < βm
q' : β
hbd : |ΞΎ - βq'| β€ 1 / ((βm + 1) * βq'.den)
hden : q'.den β€ m
den_pos : 0 < βq'.den
β’ β q', |ΞΎ - βq'| < 1 / βq'.den ^ 2 β§ |ΞΎ - βq'| < |ΞΎ - βq|
[PROOFSTEP]
have md_pos := mul_pos (add_pos m_pos zero_lt_one) den_pos
[GOAL]
case intro.intro.intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
m_pos : 0 < βm
q' : β
hbd : |ΞΎ - βq'| β€ 1 / ((βm + 1) * βq'.den)
hden : q'.den β€ m
den_pos : 0 < βq'.den
md_pos : 0 < (βm + 1) * βq'.den
β’ β q', |ΞΎ - βq'| < 1 / βq'.den ^ 2 β§ |ΞΎ - βq'| < |ΞΎ - βq|
[PROOFSTEP]
refine'
β¨q', lt_of_le_of_lt hbd _,
lt_of_le_of_lt hbd <|
(one_div_lt md_pos h).mpr <|
hm.trans <|
lt_of_lt_of_le (lt_add_one _) <|
(le_mul_iff_one_le_right <| add_pos m_pos zero_lt_one).mpr <| by exact_mod_cast (q'.pos : 1 β€ q'.den)β©
[GOAL]
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
m_pos : 0 < βm
q' : β
hbd : |ΞΎ - βq'| β€ 1 / ((βm + 1) * βq'.den)
hden : q'.den β€ m
den_pos : 0 < βq'.den
md_pos : 0 < (βm + 1) * βq'.den
β’ 1 β€ βq'.den
[PROOFSTEP]
exact_mod_cast (q'.pos : 1 β€ q'.den)
[GOAL]
case intro.intro.intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
m_pos : 0 < βm
q' : β
hbd : |ΞΎ - βq'| β€ 1 / ((βm + 1) * βq'.den)
hden : q'.den β€ m
den_pos : 0 < βq'.den
md_pos : 0 < (βm + 1) * βq'.den
β’ 1 / ((βm + 1) * βq'.den) < 1 / βq'.den ^ 2
[PROOFSTEP]
rw [sq, one_div_lt_one_div md_pos (mul_pos den_pos den_pos), mul_lt_mul_right den_pos]
[GOAL]
case intro.intro.intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
q : β
h : 0 < |ΞΎ - βq|
m : β
hm : 1 / |ΞΎ - βq| < βm
m_pos : 0 < βm
q' : β
hbd : |ΞΎ - βq'| β€ 1 / ((βm + 1) * βq'.den)
hden : q'.den β€ m
den_pos : 0 < βq'.den
md_pos : 0 < (βm + 1) * βq'.den
β’ βq'.den < βm + 1
[PROOFSTEP]
exact lt_add_of_le_of_pos (Nat.cast_le.mpr hden) zero_lt_one
[GOAL]
ΞΎ : β
hΞΎ : Irrational ΞΎ
β’ Set.Infinite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
[PROOFSTEP]
refine' Or.resolve_left (Set.finite_or_infinite _) fun h => _
[GOAL]
ΞΎ : β
hΞΎ : Irrational ΞΎ
h : Set.Finite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
β’ False
[PROOFSTEP]
obtain β¨q, _, hqβ© :=
exists_min_image {q : β | |ΞΎ - q| < 1 / (q.den : β) ^ 2} (fun q => |ΞΎ - q|) h
β¨βΞΎβ, by simp [abs_of_nonneg, Int.fract_lt_one]β©
[GOAL]
ΞΎ : β
hΞΎ : Irrational ΞΎ
h : Set.Finite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
β’ ββΞΎβ β {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
[PROOFSTEP]
simp [abs_of_nonneg, Int.fract_lt_one]
[GOAL]
case intro.intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
h : Set.Finite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
q : β
leftβ : q β {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
hq : β (b : β), b β {q | |ΞΎ - βq| < 1 / βq.den ^ 2} β |ΞΎ - βq| β€ |ΞΎ - βb|
β’ False
[PROOFSTEP]
obtain β¨q', hmem, hbetterβ© := exists_rat_abs_sub_lt_and_lt_of_irrational hΞΎ q
[GOAL]
case intro.intro.intro.intro
ΞΎ : β
hΞΎ : Irrational ΞΎ
h : Set.Finite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
q : β
leftβ : q β {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
hq : β (b : β), b β {q | |ΞΎ - βq| < 1 / βq.den ^ 2} β |ΞΎ - βq| β€ |ΞΎ - βb|
q' : β
hmem : |ΞΎ - βq'| < 1 / βq'.den ^ 2
hbetter : |ΞΎ - βq'| < |ΞΎ - βq|
β’ False
[PROOFSTEP]
exact lt_irrefl _ (lt_of_le_of_lt (hq q' hmem) hbetter)
[GOAL]
ΞΎ q : β
h : |ΞΎ - q| < 1 / βq.den ^ 2
β’ q.den β€ ΞΎ.den β§ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
have hqβ : (0 : β) < q.den := Nat.cast_pos.mpr q.pos
[GOAL]
ΞΎ q : β
h : |ΞΎ - q| < 1 / βq.den ^ 2
hqβ : 0 < βq.den
β’ q.den β€ ΞΎ.den β§ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
replace h : |ΞΎ * q.den - q.num| < 1 / q.den
[GOAL]
case h
ΞΎ q : β
h : |ΞΎ - q| < 1 / βq.den ^ 2
hqβ : 0 < βq.den
β’ |ΞΎ * βq.den - βq.num| < 1 / βq.den
[PROOFSTEP]
rw [β mul_lt_mul_right hqβ] at h
[GOAL]
case h
ΞΎ q : β
h : |ΞΎ - q| * βq.den < 1 / βq.den ^ 2 * βq.den
hqβ : 0 < βq.den
β’ |ΞΎ * βq.den - βq.num| < 1 / βq.den
[PROOFSTEP]
conv_lhs at h => rw [β abs_of_pos hqβ, β abs_mul, sub_mul, mul_den_eq_num]
[GOAL]
ΞΎ q : β
h : |ΞΎ - q| * βq.den < 1 / βq.den ^ 2 * βq.den
hqβ : 0 < βq.den
| |ΞΎ - q| * βq.den
[PROOFSTEP]
rw [β abs_of_pos hqβ, β abs_mul, sub_mul, mul_den_eq_num]
[GOAL]
ΞΎ q : β
h : |ΞΎ - q| * βq.den < 1 / βq.den ^ 2 * βq.den
hqβ : 0 < βq.den
| |ΞΎ - q| * βq.den
[PROOFSTEP]
rw [β abs_of_pos hqβ, β abs_mul, sub_mul, mul_den_eq_num]
[GOAL]
ΞΎ q : β
h : |ΞΎ - q| * βq.den < 1 / βq.den ^ 2 * βq.den
hqβ : 0 < βq.den
| |ΞΎ - q| * βq.den
[PROOFSTEP]
rw [β abs_of_pos hqβ, β abs_mul, sub_mul, mul_den_eq_num]
[GOAL]
case h
ΞΎ q : β
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den ^ 2 * βq.den
hqβ : 0 < βq.den
β’ |ΞΎ * βq.den - βq.num| < 1 / βq.den
[PROOFSTEP]
rwa [sq, div_mul, mul_div_cancel_left _ hqβ.ne'] at h
[GOAL]
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
β’ q.den β€ ΞΎ.den β§ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
constructor
[GOAL]
case left
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
β’ q.den β€ ΞΎ.den
[PROOFSTEP]
rcases eq_or_ne ΞΎ q with (rfl | H)
[GOAL]
case left.inl
ΞΎ : β
hqβ : 0 < βΞΎ.den
h : |ΞΎ * βΞΎ.den - βΞΎ.num| < 1 / βΞΎ.den
β’ ΞΎ.den β€ ΞΎ.den
[PROOFSTEP]
exact le_rfl
[GOAL]
case left.inr
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
H : ΞΎ β q
β’ q.den β€ ΞΎ.den
[PROOFSTEP]
have hΞΎβ : (0 : β) < ΞΎ.den := Nat.cast_pos.mpr ΞΎ.pos
[GOAL]
case left.inr
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
H : ΞΎ β q
hΞΎβ : 0 < βΞΎ.den
β’ q.den β€ ΞΎ.den
[PROOFSTEP]
rw [β Rat.num_div_den ΞΎ, div_mul_eq_mul_div, div_sub' _ _ _ hΞΎβ.ne', abs_div, abs_of_pos hΞΎβ, div_lt_iff hΞΎβ,
div_mul_comm, mul_one] at h
[GOAL]
case left.inr
ΞΎ q : β
hqβ : 0 < βq.den
h : |βΞΎ.num * βq.den - βΞΎ.den * βq.num| < βΞΎ.den / βq.den
H : ΞΎ β q
hΞΎβ : 0 < βΞΎ.den
β’ q.den β€ ΞΎ.den
[PROOFSTEP]
refine' Nat.cast_le.mp ((one_lt_div hqβ).mp <| lt_of_le_of_lt _ h).le
[GOAL]
case left.inr
ΞΎ q : β
hqβ : 0 < βq.den
h : |βΞΎ.num * βq.den - βΞΎ.den * βq.num| < βΞΎ.den / βq.den
H : ΞΎ β q
hΞΎβ : 0 < βΞΎ.den
β’ 1 β€ |βΞΎ.num * βq.den - βΞΎ.den * βq.num|
[PROOFSTEP]
norm_cast
[GOAL]
case left.inr
ΞΎ q : β
hqβ : 0 < βq.den
h : |βΞΎ.num * βq.den - βΞΎ.den * βq.num| < βΞΎ.den / βq.den
H : ΞΎ β q
hΞΎβ : 0 < βΞΎ.den
β’ 1 β€ |ΞΎ.num * βq.den - βΞΎ.den * q.num|
[PROOFSTEP]
rw [mul_comm _ q.num]
[GOAL]
case left.inr
ΞΎ q : β
hqβ : 0 < βq.den
h : |βΞΎ.num * βq.den - βΞΎ.den * βq.num| < βΞΎ.den / βq.den
H : ΞΎ β q
hΞΎβ : 0 < βΞΎ.den
β’ 1 β€ |ΞΎ.num * βq.den - q.num * βΞΎ.den|
[PROOFSTEP]
exact Int.one_le_abs (sub_ne_zero_of_ne <| mt Rat.eq_iff_mul_eq_mul.mpr H)
[GOAL]
case right
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
β’ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
obtain β¨hβ, hββ© :=
abs_sub_lt_iff.mp (h.trans_le <| (one_div_le zero_lt_one hqβ).mp <| (@one_div_one β _).symm βΈ Nat.cast_le.mpr q.pos)
[GOAL]
case right.intro
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
hβ : ΞΎ * βq.den - βq.num < 1
hβ : βq.num - ΞΎ * βq.den < 1
β’ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
rw [sub_lt_iff_lt_add, add_comm] at hβ hβ
[GOAL]
case right.intro
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
hβ : ΞΎ * βq.den < βq.num + 1
hβ : βq.num < ΞΎ * βq.den + 1
β’ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
rw [β sub_lt_iff_lt_add] at hβ
[GOAL]
case right.intro
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
hβ : ΞΎ * βq.den < βq.num + 1
hβ : βq.num - 1 < ΞΎ * βq.den
β’ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
norm_cast at hβ hβ
[GOAL]
case right.intro
ΞΎ q : β
hqβ : 0 < βq.den
h : |ΞΎ * βq.den - βq.num| < 1 / βq.den
hβ : ΞΎ * βq.den < β(q.num + 1)
hβ : β(q.num - 1) < ΞΎ * βq.den
β’ βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
[PROOFSTEP]
exact β¨sub_le_iff_le_add.mpr (Int.ceil_le.mpr hβ.le), sub_le_iff_le_add.mp (Int.le_floor.mpr hβ.le)β©
[GOAL]
ΞΎ : β
β’ Set.Finite {q | |ΞΎ - q| < 1 / βq.den ^ 2}
[PROOFSTEP]
let f : β β β€ Γ β := fun q => (q.num, q.den)
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
β’ Set.Finite {q | |ΞΎ - q| < 1 / βq.den ^ 2}
[PROOFSTEP]
set s := {q : β | |ΞΎ - q| < 1 / (q.den : β) ^ 2}
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
β’ Set.Finite s
[PROOFSTEP]
have hinj : Function.Injective f := by
intro a b hab
simp only [Prod.mk.inj_iff] at hab
rw [β Rat.num_div_den a, β Rat.num_div_den b, hab.1, hab.2]
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
β’ Function.Injective f
[PROOFSTEP]
intro a b hab
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
a b : β
hab : f a = f b
β’ a = b
[PROOFSTEP]
simp only [Prod.mk.inj_iff] at hab
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
a b : β
hab : a.num = b.num β§ a.den = b.den
β’ a = b
[PROOFSTEP]
rw [β Rat.num_div_den a, β Rat.num_div_den b, hab.1, hab.2]
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
β’ Set.Finite s
[PROOFSTEP]
have H : f '' s β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * yβ - 1) (βΞΎ * yβ + 1) ΓΛ’ { y } :=
by
intro xy hxy
simp only [mem_image, mem_setOf] at hxy
obtain β¨q, hqβ, hqββ© := hxy
obtain β¨hd, hnβ© := den_le_and_le_num_le_of_sub_lt_one_div_den_sq hqβ
simp_rw [mem_iUnion]
refine' β¨q.den, Set.mem_Ioc.mpr β¨q.pos, hdβ©, _β©
simp only [prod_singleton, mem_image, mem_Icc, (congr_arg Prod.snd (Eq.symm hqβ)).trans rfl]
exact β¨q.num, hn, hqββ©
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
β’ f '' s β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y}
[PROOFSTEP]
intro xy hxy
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
xy : β€ Γ β
hxy : xy β f '' s
β’ xy β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y}
[PROOFSTEP]
simp only [mem_image, mem_setOf] at hxy
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
xy : β€ Γ β
hxy : β x, |ΞΎ - x| < 1 / βx.den ^ 2 β§ (x.num, x.den) = xy
β’ xy β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y}
[PROOFSTEP]
obtain β¨q, hqβ, hqββ© := hxy
[GOAL]
case intro.intro
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
xy : β€ Γ β
q : β
hqβ : |ΞΎ - q| < 1 / βq.den ^ 2
hqβ : (q.num, q.den) = xy
β’ xy β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y}
[PROOFSTEP]
obtain β¨hd, hnβ© := den_le_and_le_num_le_of_sub_lt_one_div_den_sq hqβ
[GOAL]
case intro.intro.intro
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
xy : β€ Γ β
q : β
hqβ : |ΞΎ - q| < 1 / βq.den ^ 2
hqβ : (q.num, q.den) = xy
hd : q.den β€ ΞΎ.den
hn : βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
β’ xy β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y}
[PROOFSTEP]
simp_rw [mem_iUnion]
[GOAL]
case intro.intro.intro
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
xy : β€ Γ β
q : β
hqβ : |ΞΎ - q| < 1 / βq.den ^ 2
hqβ : (q.num, q.den) = xy
hd : q.den β€ ΞΎ.den
hn : βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
β’ β i i_1, xy β Icc (βΞΎ * βiβ - 1) (βΞΎ * βiβ + 1) ΓΛ’ {i}
[PROOFSTEP]
refine' β¨q.den, Set.mem_Ioc.mpr β¨q.pos, hdβ©, _β©
[GOAL]
case intro.intro.intro
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
xy : β€ Γ β
q : β
hqβ : |ΞΎ - q| < 1 / βq.den ^ 2
hqβ : (q.num, q.den) = xy
hd : q.den β€ ΞΎ.den
hn : βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
β’ xy β Icc (βΞΎ * βq.denβ - 1) (βΞΎ * βq.denβ + 1) ΓΛ’ {q.den}
[PROOFSTEP]
simp only [prod_singleton, mem_image, mem_Icc, (congr_arg Prod.snd (Eq.symm hqβ)).trans rfl]
[GOAL]
case intro.intro.intro
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
xy : β€ Γ β
q : β
hqβ : |ΞΎ - q| < 1 / βq.den ^ 2
hqβ : (q.num, q.den) = xy
hd : q.den β€ ΞΎ.den
hn : βΞΎ * βq.denβ - 1 β€ q.num β§ q.num β€ βΞΎ * βq.denβ + 1
β’ β x, (βΞΎ * βq.denβ - 1 β€ x β§ x β€ βΞΎ * βq.denβ + 1) β§ (x, q.den) = xy
[PROOFSTEP]
exact β¨q.num, hn, hqββ©
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
H : f '' s β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y}
β’ Set.Finite s
[PROOFSTEP]
refine' Finite.of_finite_image (Finite.subset _ H) (injOn_of_injective hinj s)
[GOAL]
ΞΎ : β
f : β β β€ Γ β := fun q => (q.num, q.den)
s : Set β := {q | |ΞΎ - q| < 1 / βq.den ^ 2}
hinj : Function.Injective f
H : f '' s β β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y}
β’ Set.Finite (β (y : β) (_ : y β Ioc 0 ΞΎ.den), Icc (βΞΎ * βyβ - 1) (βΞΎ * βyβ + 1) ΓΛ’ {y})
[PROOFSTEP]
exact Finite.biUnion (finite_Ioc _ _) fun x _ => Finite.prod (finite_Icc _ _) (finite_singleton _)
[GOAL]
ΞΎ : β
β’ Set.Infinite {q | |ΞΎ - βq| < 1 / βq.den ^ 2} β Irrational ΞΎ
[PROOFSTEP]
refine'
β¨fun h => (irrational_iff_ne_rational ΞΎ).mpr fun a b H => Set.not_infinite.mpr _ h,
Real.infinite_rat_abs_sub_lt_one_div_den_sq_of_irrationalβ©
[GOAL]
ΞΎ : β
h : Set.Infinite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
a b : β€
H : ΞΎ = βa / βb
β’ Set.Finite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
[PROOFSTEP]
convert Rat.finite_rat_abs_sub_lt_one_div_den_sq ((a : β) / b) with q
[GOAL]
case h.e'_2.h.e'_2.h.a
ΞΎ : β
h : Set.Infinite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
a b : β€
H : ΞΎ = βa / βb
q : β
β’ |ΞΎ - βq| < 1 / βq.den ^ 2 β |βa / βb - q| < 1 / βq.den ^ 2
[PROOFSTEP]
rw [H, (by (push_cast ; rfl) : (1 : β) / (q.den : β) ^ 2 = (1 / (q.den : β) ^ 2 : β))]
[GOAL]
ΞΎ : β
h : Set.Infinite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
a b : β€
H : ΞΎ = βa / βb
q : β
β’ 1 / βq.den ^ 2 = β(1 / βq.den ^ 2)
[PROOFSTEP]
push_cast
[GOAL]
ΞΎ : β
h : Set.Infinite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
a b : β€
H : ΞΎ = βa / βb
q : β
β’ 1 / βq.den ^ 2 = 1 / βq.den ^ 2
[PROOFSTEP]
rfl
[GOAL]
case h.e'_2.h.e'_2.h.a
ΞΎ : β
h : Set.Infinite {q | |ΞΎ - βq| < 1 / βq.den ^ 2}
a b : β€
H : ΞΎ = βa / βb
q : β
β’ |βa / βb - βq| < β(1 / βq.den ^ 2) β |βa / βb - q| < 1 / βq.den ^ 2
[PROOFSTEP]
norm_cast
[GOAL]
n : β
β’ convergent 0 n = 0
[PROOFSTEP]
induction' n with n ih
[GOAL]
case zero
β’ convergent 0 Nat.zero = 0
[PROOFSTEP]
simp only [Nat.zero_eq, convergent_zero, floor_zero, cast_zero]
[GOAL]
case succ
n : β
ih : convergent 0 n = 0
β’ convergent 0 (Nat.succ n) = 0
[PROOFSTEP]
simp only [ih, convergent_succ, floor_zero, cast_zero, fract_zero, add_zero, inv_zero]
[GOAL]
ΞΎ : β€
n : β
β’ convergent (βΞΎ) n = βΞΎ
[PROOFSTEP]
cases n
[GOAL]
case zero
ΞΎ : β€
β’ convergent (βΞΎ) Nat.zero = βΞΎ
[PROOFSTEP]
simp only [Nat.zero_eq, convergent_zero, floor_intCast]
[GOAL]
case succ
ΞΎ : β€
nβ : β
β’ convergent (βΞΎ) (Nat.succ nβ) = βΞΎ
[PROOFSTEP]
simp only [convergent_succ, floor_intCast, fract_intCast, convergent_of_zero, add_zero, inv_zero]
[GOAL]
ΞΎ : β
n : β
β’ convergents (GeneralizedContinuedFraction.of ΞΎ) n = β(convergent ΞΎ n)
[PROOFSTEP]
induction' n with n ih generalizing ΞΎ
[GOAL]
case zero
ΞΎβ ΞΎ : β
β’ convergents (GeneralizedContinuedFraction.of ΞΎ) Nat.zero = β(convergent ΞΎ Nat.zero)
[PROOFSTEP]
simp only [Nat.zero_eq, zeroth_convergent_eq_h, of_h_eq_floor, convergent_zero, Rat.cast_coe_int]
[GOAL]
case succ
ΞΎβ : β
n : β
ih : β (ΞΎ : β), convergents (GeneralizedContinuedFraction.of ΞΎ) n = β(convergent ΞΎ n)
ΞΎ : β
β’ convergents (GeneralizedContinuedFraction.of ΞΎ) (Nat.succ n) = β(convergent ΞΎ (Nat.succ n))
[PROOFSTEP]
rw [convergents_succ, ih (fract ΞΎ)β»ΒΉ, convergent_succ, one_div]
[GOAL]
case succ
ΞΎβ : β
n : β
ih : β (ΞΎ : β), convergents (GeneralizedContinuedFraction.of ΞΎ) n = β(convergent ΞΎ n)
ΞΎ : β
β’ ββΞΎβ + (β(convergent (fract ΞΎ)β»ΒΉ n))β»ΒΉ = β(ββΞΎβ + (convergent (fract ΞΎ)β»ΒΉ n)β»ΒΉ)
[PROOFSTEP]
norm_cast
[GOAL]
v : β€
hv : 0 < v
β’ 0 < 2 * βv - 1
[PROOFSTEP]
norm_cast
[GOAL]
v : β€
hv : 0 < v
β’ 0 < 2 * v - 1
[PROOFSTEP]
linarith
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
β’ 0 < fract ΞΎ
[PROOFSTEP]
have hvβ : (0 : β) < v := cast_pos.mpr (zero_lt_two.trans_le hv)
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hvβ : 0 < βv
β’ 0 < fract ΞΎ
[PROOFSTEP]
obtain β¨hvβ, hvββ© := auxβ (zero_lt_two.trans_le hv)
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
β’ 0 < fract ΞΎ
[PROOFSTEP]
obtain β¨hcop, _, hβ© := h
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
β’ 0 < fract ΞΎ
[PROOFSTEP]
refine' fract_pos.mpr fun hf => _
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
β’ False
[PROOFSTEP]
rw [hf] at h
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
β’ False
[PROOFSTEP]
have H : (2 * v - 1 : β) < 1 :=
by
refine' (mul_lt_iff_lt_one_right hvβ).mp ((inv_lt_inv hvβ (mul_pos hvβ hvβ)).mp (lt_of_le_of_lt _ h))
have h' : (βΞΎβ : β) - u / v = (βΞΎβ * v - u) / v := by field_simp [hvβ.ne']
rw [h', abs_div, abs_of_pos hvβ, β one_div, div_le_div_right hvβ]
norm_cast
rw [β zero_add (1 : β€), add_one_le_iff, abs_pos, sub_ne_zero]
rintro rfl
cases isUnit_iff.mp (isCoprime_self.mp (IsCoprime.mul_left_iff.mp hcop).2) <;> linarith
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
β’ 2 * βv - 1 < 1
[PROOFSTEP]
refine' (mul_lt_iff_lt_one_right hvβ).mp ((inv_lt_inv hvβ (mul_pos hvβ hvβ)).mp (lt_of_le_of_lt _ h))
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
β’ (βv)β»ΒΉ β€ |ββΞΎβ - βu / βv|
[PROOFSTEP]
have h' : (βΞΎβ : β) - u / v = (βΞΎβ * v - u) / v := by field_simp [hvβ.ne']
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
β’ ββΞΎβ - βu / βv = (ββΞΎβ * βv - βu) / βv
[PROOFSTEP]
field_simp [hvβ.ne']
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
h' : ββΞΎβ - βu / βv = (ββΞΎβ * βv - βu) / βv
β’ (βv)β»ΒΉ β€ |ββΞΎβ - βu / βv|
[PROOFSTEP]
rw [h', abs_div, abs_of_pos hvβ, β one_div, div_le_div_right hvβ]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
h' : ββΞΎβ - βu / βv = (ββΞΎβ * βv - βu) / βv
β’ 1 β€ |ββΞΎβ * βv - βu|
[PROOFSTEP]
norm_cast
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
h' : ββΞΎβ - βu / βv = (ββΞΎβ * βv - βu) / βv
β’ 1 β€ |βΞΎβ * v - u|
[PROOFSTEP]
rw [β zero_add (1 : β€), add_one_le_iff, abs_pos, sub_ne_zero]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
h' : ββΞΎβ - βu / βv = (ββΞΎβ * βv - βu) / βv
β’ βΞΎβ * v β u
[PROOFSTEP]
rintro rfl
[GOAL]
ΞΎ : β
v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hf : ΞΎ = ββΞΎβ
hcop : IsCoprime (βΞΎβ * v) v
leftβ : v = 1 β -(1 / 2) < ΞΎ - β(βΞΎβ * v)
h : |ββΞΎβ - β(βΞΎβ * v) / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : ββΞΎβ - β(βΞΎβ * v) / βv = (ββΞΎβ * βv - β(βΞΎβ * v)) / βv
β’ False
[PROOFSTEP]
cases isUnit_iff.mp (isCoprime_self.mp (IsCoprime.mul_left_iff.mp hcop).2)
[GOAL]
case inl
ΞΎ : β
v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hf : ΞΎ = ββΞΎβ
hcop : IsCoprime (βΞΎβ * v) v
leftβ : v = 1 β -(1 / 2) < ΞΎ - β(βΞΎβ * v)
h : |ββΞΎβ - β(βΞΎβ * v) / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : ββΞΎβ - β(βΞΎβ * v) / βv = (ββΞΎβ * βv - β(βΞΎβ * v)) / βv
hβ : v = 1
β’ False
[PROOFSTEP]
linarith
[GOAL]
case inr
ΞΎ : β
v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hf : ΞΎ = ββΞΎβ
hcop : IsCoprime (βΞΎβ * v) v
leftβ : v = 1 β -(1 / 2) < ΞΎ - β(βΞΎβ * v)
h : |ββΞΎβ - β(βΞΎβ * v) / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : ββΞΎβ - β(βΞΎβ * v) / βv = (ββΞΎβ * βv - β(βΞΎβ * v)) / βv
hβ : v = -1
β’ False
[PROOFSTEP]
linarith
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
H : 2 * βv - 1 < 1
β’ False
[PROOFSTEP]
norm_cast at H
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hvβ hvβ : 0 < βv
hvβ : 0 < 2 * βv - 1
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ββΞΎβ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hf : ΞΎ = ββΞΎβ
H : 2 * v - 1 < 1
β’ False
[PROOFSTEP]
linarith only [hv, H]
-- An auxiliary lemma for the inductive step.
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
obtain β¨hcop, _, hβ© := h
[GOAL]
case intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
obtain β¨hvβ, hvβ'β© := auxβ (zero_lt_two.trans_le hv)
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
have hvβ : 0 < 2 * v - 1 := by linarith only [hv]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
β’ 0 < 2 * v - 1
[PROOFSTEP]
linarith only [hv]
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
rw [β one_div, lt_div_iff (mul_pos hvβ hvβ'), β abs_of_pos (mul_pos hvβ hvβ'), β abs_mul, sub_mul, β mul_assoc, β
mul_assoc, div_mul_cancel _ hvβ.ne', abs_sub_comm, abs_lt, lt_sub_iff_add_lt, sub_lt_iff_lt_add, mul_assoc] at h
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
have huβ : 0 β€ u - βΞΎβ * v := by
-- Porting note: this abused the definitional equality `-1 + 1 = 0`
-- refine' (zero_le_mul_right hvβ).mp ((lt_iff_add_one_le (-1 : β€) _).mp _)
refine' (zero_le_mul_right hvβ).mp ?_
rw [β sub_one_lt_iff, zero_sub]
replace h := h.1
rw [β lt_sub_iff_add_lt, β mul_assoc, β sub_mul] at h
exact_mod_cast
h.trans_le
((mul_le_mul_right <| hvβ').mpr <| (sub_le_sub_iff_left (u : β)).mpr ((mul_le_mul_right hvβ).mpr (floor_le ΞΎ)))
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
β’ 0 β€ u - βΞΎβ * v
[PROOFSTEP]
refine' (zero_le_mul_right hvβ).mp ?_
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
β’ 0 β€ (u - βΞΎβ * v) * (2 * v - 1)
[PROOFSTEP]
rw [β sub_one_lt_iff, zero_sub]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
β’ -1 < (u - βΞΎβ * v) * (2 * v - 1)
[PROOFSTEP]
replace h := h.1
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1)
β’ -1 < (u - βΞΎβ * v) * (2 * v - 1)
[PROOFSTEP]
rw [β lt_sub_iff_add_lt, β mul_assoc, β sub_mul] at h
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
h : -1 < (βu - ΞΎ * βv) * (2 * βv - 1)
β’ -1 < (u - βΞΎβ * v) * (2 * v - 1)
[PROOFSTEP]
exact_mod_cast
h.trans_le
((mul_le_mul_right <| hvβ').mpr <| (sub_le_sub_iff_left (u : β)).mpr ((mul_le_mul_right hvβ).mpr (floor_le ΞΎ)))
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
have huβ : u - βΞΎβ * v β€ v := by
refine' le_of_mul_le_mul_right (le_of_lt_add_one _) hvβ
replace h := h.2
rw [β sub_lt_iff_lt_add, β mul_assoc, β sub_mul, β add_lt_add_iff_right (v * (2 * v - 1) : β), add_comm (1 : β)] at h
have :=
(mul_lt_mul_right <| hvβ').mpr
((sub_lt_sub_iff_left (u : β)).mpr <| (mul_lt_mul_right hvβ).mpr <| sub_right_lt_of_lt_add <| lt_floor_add_one ΞΎ)
rw [sub_mul ΞΎ, one_mul, β sub_add, add_mul] at this
exact_mod_cast this.trans h
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
β’ u - βΞΎβ * v β€ v
[PROOFSTEP]
refine' le_of_mul_le_mul_right (le_of_lt_add_one _) hvβ
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
β’ (u - βΞΎβ * v) * (2 * v - 1) < v * (2 * v - 1) + 1
[PROOFSTEP]
replace h := h.2
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
h : βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
β’ (u - βΞΎβ * v) * (2 * v - 1) < v * (2 * v - 1) + 1
[PROOFSTEP]
rw [β sub_lt_iff_lt_add, β mul_assoc, β sub_mul, β add_lt_add_iff_right (v * (2 * v - 1) : β), add_comm (1 : β)] at h
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
h : (βu - ΞΎ * βv) * (2 * βv - 1) + βv * (2 * βv - 1) < βv * (2 * βv - 1) + 1
β’ (u - βΞΎβ * v) * (2 * v - 1) < v * (2 * v - 1) + 1
[PROOFSTEP]
have :=
(mul_lt_mul_right <| hvβ').mpr
((sub_lt_sub_iff_left (u : β)).mpr <| (mul_lt_mul_right hvβ).mpr <| sub_right_lt_of_lt_add <| lt_floor_add_one ΞΎ)
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
h : (βu - ΞΎ * βv) * (2 * βv - 1) + βv * (2 * βv - 1) < βv * (2 * βv - 1) + 1
this : (βu - ββΞΎβ * βv) * (2 * βv - 1) < (βu - (ΞΎ - 1) * βv) * (2 * βv - 1)
β’ (u - βΞΎβ * v) * (2 * v - 1) < v * (2 * v - 1) + 1
[PROOFSTEP]
rw [sub_mul ΞΎ, one_mul, β sub_add, add_mul] at this
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
h : (βu - ΞΎ * βv) * (2 * βv - 1) + βv * (2 * βv - 1) < βv * (2 * βv - 1) + 1
this : (βu - ββΞΎβ * βv) * (2 * βv - 1) < (βu - ΞΎ * βv) * (2 * βv - 1) + βv * (2 * βv - 1)
β’ (u - βΞΎβ * v) * (2 * v - 1) < v * (2 * v - 1) + 1
[PROOFSTEP]
exact_mod_cast this.trans h
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
have huv_cop : IsCoprime (u - βΞΎβ * v) v := by rwa [sub_eq_add_neg, β neg_mul, IsCoprime.add_mul_right_left_iff]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
β’ IsCoprime (u - βΞΎβ * v) v
[PROOFSTEP]
rwa [sub_eq_add_neg, β neg_mul, IsCoprime.add_mul_right_left_iff]
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
huv_cop : IsCoprime (u - βΞΎβ * v) v
β’ 0 < u - βΞΎβ * v β§ u - βΞΎβ * v < v
[PROOFSTEP]
refine' β¨lt_of_le_of_ne' huβ fun hf => _, lt_of_le_of_ne huβ fun hf => _β©
[GOAL]
case intro.intro.intro.refine'_1
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
huv_cop : IsCoprime (u - βΞΎβ * v) v
hf : u - βΞΎβ * v = 0
β’ False
[PROOFSTEP]
rw [hf] at huv_cop
[GOAL]
case intro.intro.intro.refine'_1
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
huv_cop : IsCoprime 0 v
hf : u - βΞΎβ * v = 0
β’ False
[PROOFSTEP]
simp only [isCoprime_zero_left, isCoprime_self, isUnit_iff] at huv_cop
[GOAL]
case intro.intro.intro.refine'_1
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
hf : u - βΞΎβ * v = 0
huv_cop : v = 1 β¨ v = -1
β’ False
[PROOFSTEP]
cases' huv_cop with huv_cop huv_cop
[GOAL]
case intro.intro.intro.refine'_1.inl
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
hf : u - βΞΎβ * v = 0
huv_cop : v = 1
β’ False
[PROOFSTEP]
linarith only [hv, huv_cop]
-- The key step: the relevant inequality persists in the inductive step.
[GOAL]
case intro.intro.intro.refine'_1.inr
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
hf : u - βΞΎβ * v = 0
huv_cop : v = -1
β’ False
[PROOFSTEP]
linarith only [hv, huv_cop]
-- The key step: the relevant inequality persists in the inductive step.
[GOAL]
case intro.intro.intro.refine'_2
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
huv_cop : IsCoprime (u - βΞΎβ * v) v
hf : u - βΞΎβ * v = v
β’ False
[PROOFSTEP]
rw [hf] at huv_cop
[GOAL]
case intro.intro.intro.refine'_2
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
huv_cop : IsCoprime v v
hf : u - βΞΎβ * v = v
β’ False
[PROOFSTEP]
simp only [isCoprime_zero_left, isCoprime_self, isUnit_iff] at huv_cop
[GOAL]
case intro.intro.intro.refine'_2
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
hf : u - βΞΎβ * v = v
huv_cop : v = 1 β¨ v = -1
β’ False
[PROOFSTEP]
cases' huv_cop with huv_cop huv_cop
[GOAL]
case intro.intro.intro.refine'_2.inl
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
hf : u - βΞΎβ * v = v
huv_cop : v = 1
β’ False
[PROOFSTEP]
linarith only [hv, huv_cop]
-- The key step: the relevant inequality persists in the inductive step.
[GOAL]
case intro.intro.intro.refine'_2.inr
ΞΎ : β
u v : β€
hv : 2 β€ v
hcop : IsCoprime u v
leftβ : v = 1 β -(1 / 2) < ΞΎ - βu
h : -1 + ΞΎ * (βv * (2 * βv - 1)) < βu * (2 * βv - 1) β§ βu * (2 * βv - 1) < 1 + ΞΎ * (βv * (2 * βv - 1))
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
hvβ : 0 < 2 * v - 1
huβ : 0 β€ u - βΞΎβ * v
huβ : u - βΞΎβ * v β€ v
hf : u - βΞΎβ * v = v
huv_cop : v = -1
β’ False
[PROOFSTEP]
linarith only [hv, huv_cop]
-- The key step: the relevant inequality persists in the inductive step.
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
β’ |(fract ΞΎ)β»ΒΉ - βv / (βu - ββΞΎβ * βv)| < ((βu - ββΞΎβ * βv) * (2 * (βu - ββΞΎβ * βv) - 1))β»ΒΉ
[PROOFSTEP]
obtain β¨huβ, huvβ© := auxβ hv h
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huβ : 0 < u - βΞΎβ * v
huv : u - βΞΎβ * v < v
β’ |(fract ΞΎ)β»ΒΉ - βv / (βu - ββΞΎβ * βv)| < ((βu - ββΞΎβ * βv) * (2 * (βu - ββΞΎβ * βv) - 1))β»ΒΉ
[PROOFSTEP]
have hΞΎβ := auxβ hv h
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huβ : 0 < u - βΞΎβ * v
huv : u - βΞΎβ * v < v
hΞΎβ : 0 < fract ΞΎ
β’ |(fract ΞΎ)β»ΒΉ - βv / (βu - ββΞΎβ * βv)| < ((βu - ββΞΎβ * βv) * (2 * (βu - ββΞΎβ * βv) - 1))β»ΒΉ
[PROOFSTEP]
set u' := u - βΞΎβ * v with hu'
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
β’ |(fract ΞΎ)β»ΒΉ - βv / (βu - ββΞΎβ * βv)| < ((βu - ββΞΎβ * βv) * (2 * (βu - ββΞΎβ * βv) - 1))β»ΒΉ
[PROOFSTEP]
have hu'β : (u' : β) = u - βΞΎβ * v := by exact_mod_cast hu'
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
β’ βu' = βu - ββΞΎβ * βv
[PROOFSTEP]
exact_mod_cast hu'
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu' = βu - ββΞΎβ * βv
β’ |(fract ΞΎ)β»ΒΉ - βv / (βu - ββΞΎβ * βv)| < ((βu - ββΞΎβ * βv) * (2 * (βu - ββΞΎβ * βv) - 1))β»ΒΉ
[PROOFSTEP]
rw [β hu'β]
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu' = βu - ββΞΎβ * βv
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
replace hu'β := (eq_sub_iff_add_eq.mp hu'β).symm
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
obtain β¨Hu, Hu'β© := auxβ huβ
[GOAL]
case intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
obtain β¨Hv, Hv'β© := auxβ (zero_lt_two.trans_le hv)
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
have Hβ := div_pos (div_pos Hv Hu) hΞΎβ
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
replace h := h.2.2
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
have h' : |fract ΞΎ - u' / v| < ((v : β) * (2 * v - 1))β»ΒΉ := by
rwa [hu'β, add_div, mul_div_cancel _ Hv.ne', β sub_sub, sub_right_comm] at h
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
β’ |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
[PROOFSTEP]
rwa [hu'β, add_div, mul_div_cancel _ Hv.ne', β sub_sub, sub_right_comm] at h
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
have H : (2 * u' - 1 : β) β€ (2 * v - 1) * fract ΞΎ :=
by
replace h := (abs_lt.mp h).1
have : (2 * (v : β) - 1) * (-((v : β) * (2 * v - 1))β»ΒΉ + u' / v) = 2 * u' - (1 + u') / v := by
field_simp [Hv.ne', Hv'.ne']; ring
rw [hu'β, add_div, mul_div_cancel _ Hv.ne', β sub_sub, sub_right_comm, self_sub_floor, lt_sub_iff_add_lt, β
mul_lt_mul_left Hv', this] at h
refine' LE.le.trans _ h.le
rw [sub_le_sub_iff_left, div_le_one Hv, add_comm]
exact_mod_cast huv
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
β’ 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
[PROOFSTEP]
replace h := (abs_lt.mp h).1
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
h : -(βv * (2 * βv - 1))β»ΒΉ < ΞΎ - βu / βv
β’ 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
[PROOFSTEP]
have : (2 * (v : β) - 1) * (-((v : β) * (2 * v - 1))β»ΒΉ + u' / v) = 2 * u' - (1 + u') / v := by
field_simp [Hv.ne', Hv'.ne']; ring
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
h : -(βv * (2 * βv - 1))β»ΒΉ < ΞΎ - βu / βv
β’ (2 * βv - 1) * (-(βv * (2 * βv - 1))β»ΒΉ + βu' / βv) = 2 * βu' - (1 + βu') / βv
[PROOFSTEP]
field_simp [Hv.ne', Hv'.ne']
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
h : -(βv * (2 * βv - 1))β»ΒΉ < ΞΎ - βu / βv
β’ (2 * βv - 1) * (-βv + (βu - ββΞΎβ * βv) * (βv * (2 * βv - 1))) * βv =
(2 * (βu - ββΞΎβ * βv) * βv - (1 + (βu - ββΞΎβ * βv))) * (βv * (2 * βv - 1) * βv)
[PROOFSTEP]
ring
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
h : -(βv * (2 * βv - 1))β»ΒΉ < ΞΎ - βu / βv
this : (2 * βv - 1) * (-(βv * (2 * βv - 1))β»ΒΉ + βu' / βv) = 2 * βu' - (1 + βu') / βv
β’ 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
[PROOFSTEP]
rw [hu'β, add_div, mul_div_cancel _ Hv.ne', β sub_sub, sub_right_comm, self_sub_floor, lt_sub_iff_add_lt, β
mul_lt_mul_left Hv', this] at h
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
h : 2 * βu' - (1 + βu') / βv < (2 * βv - 1) * fract ΞΎ
this : (2 * βv - 1) * (-(βv * (2 * βv - 1))β»ΒΉ + βu' / βv) = 2 * βu' - (1 + βu') / βv
β’ 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
[PROOFSTEP]
refine' LE.le.trans _ h.le
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
h : 2 * βu' - (1 + βu') / βv < (2 * βv - 1) * fract ΞΎ
this : (2 * βv - 1) * (-(βv * (2 * βv - 1))β»ΒΉ + βu' / βv) = 2 * βu' - (1 + βu') / βv
β’ 2 * βu' - 1 β€ 2 * βu' - (1 + βu') / βv
[PROOFSTEP]
rw [sub_le_sub_iff_left, div_le_one Hv, add_comm]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
h : 2 * βu' - (1 + βu') / βv < (2 * βv - 1) * fract ΞΎ
this : (2 * βv - 1) * (-(βv * (2 * βv - 1))β»ΒΉ + βu' / βv) = 2 * βu' - (1 + βu') / βv
β’ βu' + 1 β€ βv
[PROOFSTEP]
exact_mod_cast huv
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
have helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)| := by intros;
rw [abs_sub_comm]; congr 1; field_simp; ring
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
β’ β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
[PROOFSTEP]
intros
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
aβΒ³ bβ cβ : β
aβΒ² : aβΒ³ β 0
aβΒΉ : bβ β 0
aβ : cβ β 0
β’ |aβΒ³β»ΒΉ - bβ / cβ| = |(aβΒ³ - cβ / bβ) * (bβ / cβ / aβΒ³)|
[PROOFSTEP]
rw [abs_sub_comm]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
aβΒ³ bβ cβ : β
aβΒ² : aβΒ³ β 0
aβΒΉ : bβ β 0
aβ : cβ β 0
β’ |bβ / cβ - aβΒ³β»ΒΉ| = |(aβΒ³ - cβ / bβ) * (bβ / cβ / aβΒ³)|
[PROOFSTEP]
congr 1
[GOAL]
case e_a
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
aβΒ³ bβ cβ : β
aβΒ² : aβΒ³ β 0
aβΒΉ : bβ β 0
aβ : cβ β 0
β’ bβ / cβ - aβΒ³β»ΒΉ = (aβΒ³ - cβ / bβ) * (bβ / cβ / aβΒ³)
[PROOFSTEP]
field_simp
[GOAL]
case e_a
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
aβΒ³ bβ cβ : β
aβΒ² : aβΒ³ β 0
aβΒΉ : bβ β 0
aβ : cβ β 0
β’ bβ * aβΒ³ = aβΒ³ * bβ
[PROOFSTEP]
ring
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
have helpβ : β {a b c d : β}, a β 0 β b β 0 β c β 0 β d β 0 β (b * c)β»ΒΉ * (b / d / a) = (d * c * a)β»ΒΉ := by intros;
field_simp; ring
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
β’ β {a b c d : β}, a β 0 β b β 0 β c β 0 β d β 0 β (b * c)β»ΒΉ * (b / d / a) = (d * c * a)β»ΒΉ
[PROOFSTEP]
intros
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
aββ΄ bβ cβ dβ : β
aβΒ³ : aββ΄ β 0
aβΒ² : bβ β 0
aβΒΉ : cβ β 0
aβ : dβ β 0
β’ (bβ * cβ)β»ΒΉ * (bβ / dβ / aββ΄) = (dβ * cβ * aββ΄)β»ΒΉ
[PROOFSTEP]
field_simp
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
aββ΄ bβ cβ dβ : β
aβΒ³ : aββ΄ β 0
aβΒ² : bβ β 0
aβΒΉ : cβ β 0
aβ : dβ β 0
β’ bβ * (dβ * cβ * aββ΄) = bβ * cβ * (dβ * aββ΄)
[PROOFSTEP]
ring
[GOAL]
case intro.intro.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
helpβ : β {a b c d : β}, a β 0 β b β 0 β c β 0 β d β 0 β (b * c)β»ΒΉ * (b / d / a) = (d * c * a)β»ΒΉ
β’ |(fract ΞΎ)β»ΒΉ - βv / βu'| < (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
calc
|(fract ΞΎ)β»ΒΉ - v / u'| = |(fract ΞΎ - u' / v) * (v / u' / fract ΞΎ)| := helpβ hΞΎβ.ne' Hv.ne' Hu.ne'
_ = |fract ΞΎ - u' / v| * (v / u' / fract ΞΎ) := by rw [abs_mul, abs_of_pos Hβ, abs_sub_comm]
_ < ((v : β) * (2 * v - 1))β»ΒΉ * (v / u' / fract ΞΎ) := ((mul_lt_mul_right Hβ).mpr h')
_ = (u' * (2 * v - 1) * fract ΞΎ)β»ΒΉ := (helpβ hΞΎβ.ne' Hv.ne' Hv'.ne' Hu.ne')
_ β€ ((u' : β) * (2 * u' - 1))β»ΒΉ := by
rwa [inv_le_inv (mul_pos (mul_pos Hu Hv') hΞΎβ) <| mul_pos Hu Hu', mul_assoc, mul_le_mul_left Hu]
-- The conditions `ass ΞΎ u v` persist in the inductive step.
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
helpβ : β {a b c d : β}, a β 0 β b β 0 β c β 0 β d β 0 β (b * c)β»ΒΉ * (b / d / a) = (d * c * a)β»ΒΉ
β’ |(fract ΞΎ - βu' / βv) * (βv / βu' / fract ΞΎ)| = |fract ΞΎ - βu' / βv| * (βv / βu' / fract ΞΎ)
[PROOFSTEP]
rw [abs_mul, abs_of_pos Hβ, abs_sub_comm]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hΞΎβ : 0 < fract ΞΎ
u' : β€ := u - βΞΎβ * v
huβ : 0 < u'
huv : u' < v
hu' : u' = u - βΞΎβ * v
hu'β : βu = βu' + ββΞΎβ * βv
Hu : 0 < βu'
Hu' : 0 < 2 * βu' - 1
Hv : 0 < βv
Hv' : 0 < 2 * βv - 1
Hβ : 0 < βv / βu' / fract ΞΎ
h : |ΞΎ - βu / βv| < (βv * (2 * βv - 1))β»ΒΉ
h' : |fract ΞΎ - βu' / βv| < (βv * (2 * βv - 1))β»ΒΉ
H : 2 * βu' - 1 β€ (2 * βv - 1) * fract ΞΎ
helpβ : β {a b c : β}, a β 0 β b β 0 β c β 0 β |aβ»ΒΉ - b / c| = |(a - c / b) * (b / c / a)|
helpβ : β {a b c d : β}, a β 0 β b β 0 β c β 0 β d β 0 β (b * c)β»ΒΉ * (b / d / a) = (d * c * a)β»ΒΉ
β’ (βu' * (2 * βv - 1) * fract ΞΎ)β»ΒΉ β€ (βu' * (2 * βu' - 1))β»ΒΉ
[PROOFSTEP]
rwa [inv_le_inv (mul_pos (mul_pos Hu Hv') hΞΎβ) <| mul_pos Hu Hu', mul_assoc, mul_le_mul_left Hu]
-- The conditions `ass ΞΎ u v` persist in the inductive step.
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
β’ ContfracLegendre.Ass (fract ΞΎ)β»ΒΉ v (u - βΞΎβ * v)
[PROOFSTEP]
refine' β¨_, fun huv => _, by exact_mod_cast auxβ hv hβ©
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
β’ |(fract ΞΎ)β»ΒΉ - βv / β(u - βΞΎβ * v)| < (β(u - βΞΎβ * v) * (2 * β(u - βΞΎβ * v) - 1))β»ΒΉ
[PROOFSTEP]
exact_mod_cast auxβ hv h
[GOAL]
case refine'_1
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
β’ IsCoprime v (u - βΞΎβ * v)
[PROOFSTEP]
rw [sub_eq_add_neg, β neg_mul, isCoprime_comm, IsCoprime.add_mul_right_left_iff]
[GOAL]
case refine'_1
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
β’ IsCoprime u v
[PROOFSTEP]
exact h.1
[GOAL]
case refine'_2
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
β’ -(1 / 2) < (fract ΞΎ)β»ΒΉ - βv
[PROOFSTEP]
obtain β¨hvβ, hvβ'β© := auxβ (zero_lt_two.trans_le hv)
[GOAL]
case refine'_2.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
β’ -(1 / 2) < (fract ΞΎ)β»ΒΉ - βv
[PROOFSTEP]
have Hv : (v * (2 * v - 1) : β)β»ΒΉ + (v : β)β»ΒΉ = 2 / (2 * v - 1) :=
by
field_simp [hvβ.ne', hvβ'.ne']
ring
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
β’ (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
[PROOFSTEP]
field_simp [hvβ.ne', hvβ'.ne']
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
β’ (βv + βv * (2 * βv - 1)) * (2 * βv - 1) = 2 * (βv * (2 * βv - 1) * βv)
[PROOFSTEP]
ring
[GOAL]
case refine'_2.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
Hv : (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
β’ -(1 / 2) < (fract ΞΎ)β»ΒΉ - βv
[PROOFSTEP]
have Huv : (u / v : β) = βΞΎβ + (v : β)β»ΒΉ := by rw [sub_eq_iff_eq_add'.mp huv]; field_simp [hvβ.ne']
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
Hv : (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
β’ βu / βv = ββΞΎβ + (βv)β»ΒΉ
[PROOFSTEP]
rw [sub_eq_iff_eq_add'.mp huv]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
Hv : (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
β’ β(βΞΎβ * v + 1) / βv = ββΞΎβ + (βv)β»ΒΉ
[PROOFSTEP]
field_simp [hvβ.ne']
[GOAL]
case refine'_2.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
Hv : (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
Huv : βu / βv = ββΞΎβ + (βv)β»ΒΉ
β’ -(1 / 2) < (fract ΞΎ)β»ΒΉ - βv
[PROOFSTEP]
have h' := (abs_sub_lt_iff.mp h.2.2).1
[GOAL]
case refine'_2.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
Hv : (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
Huv : βu / βv = ββΞΎβ + (βv)β»ΒΉ
h' : ΞΎ - βu / βv < (βv * (2 * βv - 1))β»ΒΉ
β’ -(1 / 2) < (fract ΞΎ)β»ΒΉ - βv
[PROOFSTEP]
rw [Huv, β sub_sub, sub_lt_iff_lt_add, self_sub_floor, Hv] at h'
[GOAL]
case refine'_2.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
Hv : (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
Huv : βu / βv = ββΞΎβ + (βv)β»ΒΉ
h' : fract ΞΎ < 2 / (2 * βv - 1)
β’ -(1 / 2) < (fract ΞΎ)β»ΒΉ - βv
[PROOFSTEP]
rwa [lt_sub_iff_add_lt', (by ring : (v : β) + -(1 / 2) = (2 * v - 1) / 2),
lt_inv (div_pos hvβ' zero_lt_two) (auxβ hv h), inv_div]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
h : ContfracLegendre.Ass ΞΎ u v
huv : u - βΞΎβ * v = 1
hvβ : 0 < βv
hvβ' : 0 < 2 * βv - 1
Hv : (βv * (2 * βv - 1))β»ΒΉ + (βv)β»ΒΉ = 2 / (2 * βv - 1)
Huv : βu / βv = ββΞΎβ + (βv)β»ΒΉ
h' : fract ΞΎ < 2 / (2 * βv - 1)
β’ βv + -(1 / 2) = (2 * βv - 1) / 2
[PROOFSTEP]
ring
[GOAL]
ΞΎ : β
u vβ : β€
hv : 2 β€ vβ
h : ContfracLegendre.Ass ΞΎ u vβ
v : β
h' : ContfracLegendre.Ass ΞΎ u βv
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
clear h
[GOAL]
ΞΎ : β
u vβ : β€
hv : 2 β€ vβ
v : β
h' : ContfracLegendre.Ass ΞΎ u βv
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
have h := h'
[GOAL]
ΞΎ : β
u vβ : β€
hv : 2 β€ vβ
v : β
h' h : ContfracLegendre.Ass ΞΎ u βv
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
clear h'
[GOAL]
ΞΎ : β
u vβ : β€
hv : 2 β€ vβ
v : β
h : ContfracLegendre.Ass ΞΎ u βv
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
induction v using Nat.strong_induction_on generalizing ΞΎ u with
| h v ih => ?_
[GOAL]
ΞΎ : β
u vβ : β€
hv : 2 β€ vβ
v : β
h : ContfracLegendre.Ass ΞΎ u βv
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
induction v using Nat.strong_induction_on generalizing ΞΎ u with
| h v ih => ?_
[GOAL]
case h
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
rcases lt_trichotomy v 1 with (ht | rfl | ht)
[GOAL]
case h.inl
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : v < 1
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
replace h := h.2.2
[GOAL]
case h.inl
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
ht : v < 1
h : |ΞΎ - βu / ββv| < (ββv * (2 * ββv - 1))β»ΒΉ
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
simp only [Nat.lt_one_iff.mp ht, Nat.cast_zero, div_zero, tsub_zero, zero_mul, cast_zero, inv_zero] at h
[GOAL]
case h.inl
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
ht : v < 1
h : |ΞΎ| < 0
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
exact False.elim (lt_irrefl _ <| (abs_nonneg ΞΎ).trans_lt h)
[GOAL]
case h.inr.inl
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
h : ContfracLegendre.Ass ΞΎ u β1
β’ β n, βu / β1 = convergent ΞΎ n
[PROOFSTEP]
rw [Nat.cast_one, div_one]
[GOAL]
case h.inr.inl
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
h : ContfracLegendre.Ass ΞΎ u β1
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
obtain β¨_, hβ, hββ© := h
[GOAL]
case h.inr.inl.intro.intro
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : β1 = 1 β -(1 / 2) < ΞΎ - βu
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
cases' le_or_lt (u : β) ΞΎ with ht ht
[GOAL]
case h.inr.inl.intro.intro.inl
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : β1 = 1 β -(1 / 2) < ΞΎ - βu
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : βu β€ ΞΎ
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
use 0
[GOAL]
case h
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : β1 = 1 β -(1 / 2) < ΞΎ - βu
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : βu β€ ΞΎ
β’ βu = convergent ΞΎ 0
[PROOFSTEP]
rw [convergent_zero, Rat.coe_int_inj, eq_comm, floor_eq_iff]
[GOAL]
case h
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : β1 = 1 β -(1 / 2) < ΞΎ - βu
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : βu β€ ΞΎ
β’ βu β€ ΞΎ β§ ΞΎ < βu + 1
[PROOFSTEP]
convert And.intro ht (sub_lt_iff_lt_add'.mp (abs_lt.mp hβ).2)
[GOAL]
case h.e'_2.h.e'_4.h.e'_5
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : β1 = 1 β -(1 / 2) < ΞΎ - βu
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : βu β€ ΞΎ
β’ βu = βu / ββ1
[PROOFSTEP]
norm_num
[GOAL]
case h.e'_2.h.e'_4.h.e'_6
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : β1 = 1 β -(1 / 2) < ΞΎ - βu
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : βu β€ ΞΎ
β’ 1 = (ββ1 * (2 * ββ1 - 1))β»ΒΉ
[PROOFSTEP]
norm_num
[GOAL]
case h.inr.inl.intro.intro.inr
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : β1 = 1 β -(1 / 2) < ΞΎ - βu
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
replace hβ := lt_sub_iff_add_lt'.mp (hβ rfl)
[GOAL]
case h.inr.inl.intro.intro.inr
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
have hΞΎβ : βΞΎβ = u - 1 := by
rw [floor_eq_iff, cast_sub, cast_one, sub_add_cancel]
exact β¨(((sub_lt_sub_iff_left _).mpr one_half_lt_one).trans hβ).le, htβ©
[GOAL]
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
β’ βΞΎβ = u - 1
[PROOFSTEP]
rw [floor_eq_iff, cast_sub, cast_one, sub_add_cancel]
[GOAL]
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
β’ βu - 1 β€ ΞΎ β§ ΞΎ < βu
[PROOFSTEP]
exact β¨(((sub_lt_sub_iff_left _).mpr one_half_lt_one).trans hβ).le, htβ©
[GOAL]
case h.inr.inl.intro.intro.inr
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
cases' eq_or_ne ΞΎ βΞΎβ with HΞΎ HΞΎ
[GOAL]
case h.inr.inl.intro.intro.inr.inl
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ = ββΞΎβ
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
rw [HΞΎ, hΞΎβ, cast_sub, cast_one, β sub_eq_add_neg, sub_lt_sub_iff_left] at hβ
[GOAL]
case h.inr.inl.intro.intro.inr.inl
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : 1 < 1 / 2
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ = ββΞΎβ
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
exact False.elim (lt_irrefl _ <| hβ.trans one_half_lt_one)
[GOAL]
case h.inr.inl.intro.intro.inr.inr
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
have hΞΎβ : β(fract ΞΎ)β»ΒΉβ = 1 :=
by
rw [floor_eq_iff, cast_one, le_inv zero_lt_one (fract_pos.mpr HΞΎ), inv_one, one_add_one_eq_two,
inv_lt (fract_pos.mpr HΞΎ) zero_lt_two]
refine' β¨(fract_lt_one ΞΎ).le, _β©
rw [fract, hΞΎβ, cast_sub, cast_one, lt_sub_iff_add_lt', sub_add]
convert hβ using 1
-- Porting note: added (`convert` handled this in lean 3)
rw [sub_eq_add_neg]
norm_num
[GOAL]
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
β’ β(fract ΞΎ)β»ΒΉβ = 1
[PROOFSTEP]
rw [floor_eq_iff, cast_one, le_inv zero_lt_one (fract_pos.mpr HΞΎ), inv_one, one_add_one_eq_two,
inv_lt (fract_pos.mpr HΞΎ) zero_lt_two]
[GOAL]
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
β’ fract ΞΎ β€ 1 β§ 2β»ΒΉ < fract ΞΎ
[PROOFSTEP]
refine' β¨(fract_lt_one ΞΎ).le, _β©
[GOAL]
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
β’ 2β»ΒΉ < fract ΞΎ
[PROOFSTEP]
rw [fract, hΞΎβ, cast_sub, cast_one, lt_sub_iff_add_lt', sub_add]
[GOAL]
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
β’ βu - (1 - 2β»ΒΉ) < ΞΎ
[PROOFSTEP]
convert hβ using 1
-- Porting note: added (`convert` handled this in lean 3)
[GOAL]
case h.e'_3
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
β’ βu - (1 - 2β»ΒΉ) = βu + -(1 / 2)
[PROOFSTEP]
rw [sub_eq_add_neg]
[GOAL]
case h.e'_3
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
β’ βu + -(1 - 2β»ΒΉ) = βu + -(1 / 2)
[PROOFSTEP]
norm_num
[GOAL]
case h.inr.inl.intro.intro.inr.inr
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
hΞΎβ : β(fract ΞΎ)β»ΒΉβ = 1
β’ β n, βu = convergent ΞΎ n
[PROOFSTEP]
use 1
[GOAL]
case h
v : β€
hv : 2 β€ v
ΞΎ : β
u : β€
ih : β (m : β), m < 1 β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
leftβ : IsCoprime u β1
hβ : |ΞΎ - βu / ββ1| < (ββ1 * (2 * ββ1 - 1))β»ΒΉ
ht : ΞΎ < βu
hβ : βu + -(1 / 2) < ΞΎ
hΞΎβ : βΞΎβ = u - 1
HΞΎ : ΞΎ β ββΞΎβ
hΞΎβ : β(fract ΞΎ)β»ΒΉβ = 1
β’ βu = convergent ΞΎ 1
[PROOFSTEP]
simp [convergent, hΞΎβ, hΞΎβ, cast_sub, cast_one]
[GOAL]
case h.inr.inr
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
obtain β¨huvβ, huvββ© := auxβ (Nat.cast_le.mpr ht) h
[GOAL]
case h.inr.inr.intro
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
have Hv : (v : β) β 0 := (Nat.cast_pos.mpr (zero_lt_one.trans ht)).ne'
[GOAL]
case h.inr.inr.intro
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
have huvβ' : (u - βΞΎβ * v).toNat < v := by zify; rwa [toNat_of_nonneg huvβ.le]
[GOAL]
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
β’ toNat (u - βΞΎβ * βv) < v
[PROOFSTEP]
zify
[GOAL]
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
β’ β(toNat (u - βΞΎβ * βv)) < βv
[PROOFSTEP]
rwa [toNat_of_nonneg huvβ.le]
[GOAL]
case h.inr.inr.intro
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
huvβ' : toNat (u - βΞΎβ * βv) < v
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
have inv : ContfracLegendre.Ass (fract ΞΎ)β»ΒΉ v (u - βΞΎβ * βv).toNat :=
(toNat_of_nonneg huvβ.le).symm βΈ invariant (Nat.cast_le.mpr ht) h
[GOAL]
case h.inr.inr.intro
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
huvβ' : toNat (u - βΞΎβ * βv) < v
inv : ContfracLegendre.Ass (fract ΞΎ)β»ΒΉ βv β(toNat (u - βΞΎβ * βv))
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
obtain β¨n, hnβ© := ih (u - βΞΎβ * v).toNat huvβ' inv
[GOAL]
case h.inr.inr.intro.intro
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
huvβ' : toNat (u - βΞΎβ * βv) < v
inv : ContfracLegendre.Ass (fract ΞΎ)β»ΒΉ βv β(toNat (u - βΞΎβ * βv))
n : β
hn : ββv / β(toNat (u - βΞΎβ * βv)) = convergent (fract ΞΎ)β»ΒΉ n
β’ β n, βu / βv = convergent ΞΎ n
[PROOFSTEP]
use n + 1
[GOAL]
case h
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
huvβ' : toNat (u - βΞΎβ * βv) < v
inv : ContfracLegendre.Ass (fract ΞΎ)β»ΒΉ βv β(toNat (u - βΞΎβ * βv))
n : β
hn : ββv / β(toNat (u - βΞΎβ * βv)) = convergent (fract ΞΎ)β»ΒΉ n
β’ βu / βv = convergent ΞΎ (n + 1)
[PROOFSTEP]
rw [convergent_succ, β hn, (by exact_mod_cast toNat_of_nonneg huvβ.le : ((u - βΞΎβ * v).toNat : β) = u - βΞΎβ * v),
cast_ofNat, inv_div, sub_div, mul_div_cancel _ Hv, add_sub_cancel'_right]
[GOAL]
vβ : β€
hv : 2 β€ vβ
v : β
ih : β (m : β), m < v β β {ΞΎ : β} {u : β€}, ContfracLegendre.Ass ΞΎ u βm β β n, βu / βm = convergent ΞΎ n
ΞΎ : β
u : β€
h : ContfracLegendre.Ass ΞΎ u βv
ht : 1 < v
huvβ : 0 < u - βΞΎβ * βv
huvβ : u - βΞΎβ * βv < βv
Hv : βv β 0
huvβ' : toNat (u - βΞΎβ * βv) < v
inv : ContfracLegendre.Ass (fract ΞΎ)β»ΒΉ βv β(toNat (u - βΞΎβ * βv))
n : β
hn : ββv / β(toNat (u - βΞΎβ * βv)) = convergent (fract ΞΎ)β»ΒΉ n
β’ β(toNat (u - βΞΎβ * βv)) = βu - ββΞΎβ * βv
[PROOFSTEP]
exact_mod_cast toNat_of_nonneg huvβ.le
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
β’ β n, q = convergent ΞΎ n
[PROOFSTEP]
refine' q.num_div_den βΈ exists_rat_eq_convergent' β¨_, fun hd => _, _β©
[GOAL]
case refine'_1
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
β’ IsCoprime q.num βq.den
[PROOFSTEP]
exact coprime_iff_nat_coprime.mpr (natAbs_ofNat q.den βΈ q.reduced)
[GOAL]
case refine'_2
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hd : βq.den = 1
β’ -(1 / 2) < ΞΎ - βq.num
[PROOFSTEP]
rw [β q.den_eq_one_iff.mp (Nat.cast_eq_one.mp hd)] at h
[GOAL]
case refine'_2
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - ββq.num| < 1 / (2 * β(βq.num).den ^ 2)
hd : βq.den = 1
β’ -(1 / 2) < ΞΎ - βq.num
[PROOFSTEP]
simpa only [Rat.coe_int_den, Nat.cast_one, one_pow, mul_one] using (abs_lt.mp h).1
[GOAL]
case refine'_3
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
β’ |ΞΎ - βq.num / ββq.den| < (ββq.den * (2 * ββq.den - 1))β»ΒΉ
[PROOFSTEP]
obtain β¨hqβ, hqββ© := auxβ (Nat.cast_pos.mpr q.pos)
[GOAL]
case refine'_3.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < ββq.den
hqβ : 0 < 2 * ββq.den - 1
β’ |ΞΎ - βq.num / ββq.den| < (ββq.den * (2 * ββq.den - 1))β»ΒΉ
[PROOFSTEP]
replace hqβ := mul_pos hqβ hqβ
[GOAL]
case refine'_3.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < ββq.den
hqβ : 0 < ββq.den * (2 * ββq.den - 1)
β’ |ΞΎ - βq.num / ββq.den| < (ββq.den * (2 * ββq.den - 1))β»ΒΉ
[PROOFSTEP]
have hqβ : (0 : β) < 2 * (q.den * q.den) := mul_pos zero_lt_two (mul_pos hqβ hqβ)
[GOAL]
case refine'_3.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < ββq.den
hqβ : 0 < ββq.den * (2 * ββq.den - 1)
hqβ : 0 < 2 * (βq.den * βq.den)
β’ |ΞΎ - βq.num / ββq.den| < (ββq.den * (2 * ββq.den - 1))β»ΒΉ
[PROOFSTEP]
rw [cast_ofNat] at *
[GOAL]
case refine'_3.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < βq.den
hqβ : 0 < βq.den * (2 * βq.den - 1)
hqβ : 0 < 2 * (βq.den * βq.den)
β’ |ΞΎ - βq.num / βq.den| < (βq.den * (2 * βq.den - 1))β»ΒΉ
[PROOFSTEP]
rw [(by norm_cast : (q.num / q.den : β) = (q.num / q.den : β)), Rat.num_div_den]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < βq.den
hqβ : 0 < βq.den * (2 * βq.den - 1)
hqβ : 0 < 2 * (βq.den * βq.den)
β’ βq.num / βq.den = β(βq.num / βq.den)
[PROOFSTEP]
norm_cast
[GOAL]
case refine'_3.intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < βq.den
hqβ : 0 < βq.den * (2 * βq.den - 1)
hqβ : 0 < 2 * (βq.den * βq.den)
β’ |ΞΎ - βq| < (βq.den * (2 * βq.den - 1))β»ΒΉ
[PROOFSTEP]
exact h.trans (by rw [β one_div, sq, one_div_lt_one_div hqβ hqβ, β sub_pos]; ring_nf; exact hqβ)
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < βq.den
hqβ : 0 < βq.den * (2 * βq.den - 1)
hqβ : 0 < 2 * (βq.den * βq.den)
β’ 1 / (2 * βq.den ^ 2) < (βq.den * (2 * βq.den - 1))β»ΒΉ
[PROOFSTEP]
rw [β one_div, sq, one_div_lt_one_div hqβ hqβ, β sub_pos]
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < βq.den
hqβ : 0 < βq.den * (2 * βq.den - 1)
hqβ : 0 < 2 * (βq.den * βq.den)
β’ 0 < 2 * (βq.den * βq.den) - βq.den * (2 * βq.den - 1)
[PROOFSTEP]
ring_nf
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
hqβ : 0 < βq.den
hqβ : 0 < βq.den * (2 * βq.den - 1)
hqβ : 0 < 2 * (βq.den * βq.den)
β’ 0 < βq.den
[PROOFSTEP]
exact hqβ
[GOAL]
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
β’ β n, GeneralizedContinuedFraction.convergents (GeneralizedContinuedFraction.of ΞΎ) n = βq
[PROOFSTEP]
obtain β¨n, hnβ© := exists_rat_eq_convergent h
[GOAL]
case intro
ΞΎ : β
u v : β€
hv : 2 β€ v
hβ : ContfracLegendre.Ass ΞΎ u v
q : β
h : |ΞΎ - βq| < 1 / (2 * βq.den ^ 2)
n : β
hn : q = convergent ΞΎ n
β’ β n, GeneralizedContinuedFraction.convergents (GeneralizedContinuedFraction.of ΞΎ) n = βq
[PROOFSTEP]
exact β¨n, hn.symm βΈ continued_fraction_convergent_eq_convergent ΞΎ nβ©
|
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .jl
# format_name: light
# format_version: '1.3'
# jupytext_version: 1.0.4
# kernelspec:
# display_name: Julia 1.0.3
# language: julia
# name: julia-1.0
# ---
using Weave
const EXAMPLES_DIR = abspath(joinpath(@__DIR__,"..", "examples"))
const JMD_DIR = abspath(joinpath(@__DIR__,"src","examples","jmd"))
const HTML_DIR = abspath(joinpath(@__DIR__,"src","examples","html"))
# +
if isdir(JMD_DIR)
nothing
else
mkpath(JMD_DIR)
end
if isdir(HTML_DIR)
nothing
else
mkpath(HTML_DIR)
end
# -
# run(`find $EXAMPLES_DIR -maxdepth 1 -name "*.jl" -exec jupytext "{}" --to ipynb ";" `)
function listnotebooks()
[ i for i in readdir(EXAMPLES_DIR) if splitext(i)[end] == ".ipynb"]
end
nbs = listnotebooks()
function createhtml(nbs)
for nb in nbs
@info "Converting $nb to .html file"
try
run(`jupyter nbconvert --ExecutePreprocessor.timeout=None --ExecutePreprocessor.kernel_name=julia-1.0
--to html --execute $EXAMPLES_DIR/$nb --output $HTML_DIR/$(splitext(nb)[1]).html`)
catch
@warn "failed to convert $nb"
end
end
end
createhtml(nbs)
|
lemma closed_imp_fip: fixes S :: "'a::heine_borel set" assumes "closed S" and T: "T \<in> \<F>" "bounded T" and clof: "\<And>T. T \<in> \<F> \<Longrightarrow> closed T" and none: "\<And>\<F>'. \<lbrakk>finite \<F>'; \<F>' \<subseteq> \<F>\<rbrakk> \<Longrightarrow> S \<inter> \<Inter>\<F>' \<noteq> {}" shows "S \<inter> \<Inter>\<F> \<noteq> {}" |
(* ------------------------------------------------------- *)
(** #<hr> <center> <h1>#
The double time redundancy (DTR) transformation
#</h1>#
- Exporting the main lemmas of control block
Dmitry Burlyaev - Pascal Fradet - 2015
#</center> <hr># *)
(* ------------------------------------------------------- *)
Add LoadPath "..\..\Common\".
Add LoadPath "..\..\TMRProof\".
Add LoadPath "..\Transf\".
Require Import dtrTransform.
(*Control Block properties during odd clock cycles w/o errors*)
Require Export controlStep0.
(*
step0_tcbv_C
step0_tcbv
*)
(*Control Block properties during even clock cycles w/o errors*)
Require Export controlStep1.
(*
step1_tcbv_C
step1_tcbv
stepr1_tcbv
*)
(*Control Block properties during odd clock cycles with errors*)
Require Export controlStepg0.
(*
stepg0_tcbv
step0_tcbv_i
*)
(*Control Block properties during even clock cycles with errors*)
Require Export controlStepg1.
(*
stepg1_tcbv
step1_tcbv_i
stepr1_tcbv_i
*)
(*Control Block properties during the DTR recovery process*)
Require Export controlRec.
(*
stepr2_tcbv_C
stepr2_tcbv
stepr3_tcbv
stepr4_tcbv
stepr5_tcbv
*)
|
function MimSave(file_path, filename_base, image_data, compression, reporting)
% MimSave. Saves an image or a structure containing images, with compression support
%
% MimSave allows you to save a structure as a .mat file, where every
% PTKImage in the structure has its raw data saved as a separate
% .raw file, with compression if supported. Use MimLoad to reload
% the structure.
%
% Syntax
% ------
%
% MimSave(file_path, filename_base, image_data, compression, reporting)
%
% file_path specify the location to save the files.
% filename_base specify the file prefix. Suffixes will be
% added automatically. A single header file
% will be saved for the structure or image,
% and a separate raw image file will be
% created for each image in the structure
% image_data is a PTKImage (or PTKDicomImage) class containing the image
% to be saved, or a structure which could
% contain one or more PTKImages
% compression the compression to use when saving the
% raw data in PTKImage files
% reporting an object implementing CoreReportingInterface
% for reporting progress and warnings
%
%
% Licence
% -------
% Part of the TD MIM Toolkit. https://github.com/tomdoel
% Author: Tom Doel, Copyright Tom Doel 2014. www.tomdoel.com
% Distributed under the MIT licence. Please see website for details.
%
result = ConvertStructAndSaveRawImageData(image_data, file_path, filename_base, 0, compression, reporting);
filename = [fullfile(file_path, filename_base) '.mat'];
MimDiskUtilities.Save(filename, result);
end
function [new_structure, next_index] = ConvertStructAndSaveRawImageData(old_structure, file_path, filename_base, next_index, compression, reporting)
if isstruct(old_structure)
new_structure = struct;
field_names = fieldnames(old_structure);
for field = field_names'
field_name = field{1};
[new_structure.(field_name), next_index] = ConvertStructAndSaveRawImageData(old_structure.(field_name), file_path, filename_base, next_index, compression, reporting);
end
else
if isa(old_structure, 'PTKImage')
reporting.LogVerbose(['Saving raw image data for ' filename_base]);
if next_index == 0
file_suffix = '';
else
file_suffix = ['_' int2str(next_index)];
end
raw_image_file_name = [filename_base file_suffix '.raw'];
if (length(size(old_structure.RawImage)) ~= 3) || (~MimDiskUtilities.CompressionSupported(compression, class(old_structure.RawImage), reporting))
% Compression currently only supports 3D images
compression = [];
end
% Create a header file if requested. The header is the image object
% minus the raw image data, and contains the raw image filename
header = old_structure.CreateHeader(raw_image_file_name, compression);
% Save the pixel data with compression, if supported
CoreSaveRawImage(old_structure.RawImage, file_path, raw_image_file_name, compression, reporting);
next_index = next_index + 1;
new_structure = header;
else
new_structure = old_structure;
end
end
end
|
#define BOOST_TEST_MODULE tests
#include <boost/test/unit_test.hpp>
#include <iostream>
struct GlobalFixture {
GlobalFixture() { std::cout << "global setup\n"; }
~GlobalFixture() { std::cout << "global teardown\n"; }
};
BOOST_GLOBAL_FIXTURE( GlobalFixture ); |
Formal statement is: lemma Re_Reals_divide: "r \<in> \<real> \<Longrightarrow> Re (r / z) = Re r * Re z / (norm z)\<^sup>2" Informal statement is: If $r$ is a real number, then $\frac{\mathrm{Re}(r)}{z} = \frac{\mathrm{Re}(r) \cdot \mathrm{Re}(z)}{|z|^2}$. |
theorem ex1 (p q r : Prop) (h1 : p β¨ q) (h2 : p β q) : q :=
have : q := by -- Error here
skip
by skip -- Error here
skip
theorem ex2 (p q r : Prop) (h1 : p β¨ q) (h2 : p β q) : q :=
have : q := by {
skip
} -- Error here
by skip -- Error here
skip
theorem ex3 (p q r : Prop) (h1 : p β¨ q) (h2 : p β q) : q := by
cases h1
{ skip
skip } -- Error here
{ skip
skip } -- Error here
theorem ex4 (p q r : Prop) (h1 : p β¨ q) (h2 : p β q) : q := by
first | done | apply ex3 p q r h1 h2
theorem ex5 (p q r : Prop) (h1 : p β¨ q) (h2 : p β q) : q := by
cases h1
Β· skip -- Error here
skip
Β· skip -- Error here
skip
|
A number $x$ is a zeroth power if and only if $x = 1$. |
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich, Leonardo de Moura
-/
import Lean.Data.Name
import Lean.Data.Format
/--
A position range inside a string. This type is mostly in combination with syntax trees,
as there might not be a single underlying string in this case that could be used for a `Substring`.
-/
protected structure String.Range where
start : String.Pos
stop : String.Pos
deriving Inhabited, Repr, BEq, Hashable
def String.Range.contains (r : String.Range) (pos : String.Pos) (includeStop := false) : Bool :=
r.start <= pos && (if includeStop then pos <= r.stop else pos < r.stop)
def String.Range.includes (super sub : String.Range) : Bool :=
super.start <= sub.start && super.stop >= sub.stop
namespace Lean
def SourceInfo.updateTrailing (trailing : Substring) : SourceInfo β SourceInfo
| SourceInfo.original leading pos _ endPos => SourceInfo.original leading pos trailing endPos
| info => info
/-! # Syntax AST -/
inductive IsNode : Syntax β Prop where
| mk (info : SourceInfo) (kind : SyntaxNodeKind) (args : Array Syntax) : IsNode (Syntax.node info kind args)
def SyntaxNode : Type := {s : Syntax // IsNode s }
def unreachIsNodeMissing {Ξ²} (h : IsNode Syntax.missing) : Ξ² := False.elim (nomatch h)
def unreachIsNodeAtom {Ξ²} {info val} (h : IsNode (Syntax.atom info val)) : Ξ² := False.elim (nomatch h)
def unreachIsNodeIdent {Ξ² info rawVal val preresolved} (h : IsNode (Syntax.ident info rawVal val preresolved)) : Ξ² := False.elim (nomatch h)
def isLitKind (k : SyntaxNodeKind) : Bool :=
k == strLitKind || k == numLitKind || k == charLitKind || k == nameLitKind || k == scientificLitKind
namespace SyntaxNode
@[inline] def getKind (n : SyntaxNode) : SyntaxNodeKind :=
match n with
| β¨Syntax.node _ k _, _β© => k
| β¨Syntax.missing, hβ© => unreachIsNodeMissing h
| β¨Syntax.atom .., hβ© => unreachIsNodeAtom h
| β¨Syntax.ident .., hβ© => unreachIsNodeIdent h
@[inline] def withArgs {Ξ²} (n : SyntaxNode) (fn : Array Syntax β Ξ²) : Ξ² :=
match n with
| β¨Syntax.node _ _ args, _β© => fn args
| β¨Syntax.missing, hβ© => unreachIsNodeMissing h
| β¨Syntax.atom _ _, hβ© => unreachIsNodeAtom h
| β¨Syntax.ident _ _ _ _, hβ© => unreachIsNodeIdent h
@[inline] def getNumArgs (n : SyntaxNode) : Nat :=
withArgs n fun args => args.size
@[inline] def getArg (n : SyntaxNode) (i : Nat) : Syntax :=
withArgs n fun args => args.get! i
@[inline] def getArgs (n : SyntaxNode) : Array Syntax :=
withArgs n fun args => args
@[inline] def modifyArgs (n : SyntaxNode) (fn : Array Syntax β Array Syntax) : Syntax :=
match n with
| β¨Syntax.node i k args, _β© => Syntax.node i k (fn args)
| β¨Syntax.missing, hβ© => unreachIsNodeMissing h
| β¨Syntax.atom _ _, hβ© => unreachIsNodeAtom h
| β¨Syntax.ident _ _ _ _, hβ© => unreachIsNodeIdent h
end SyntaxNode
namespace Syntax
def getAtomVal : Syntax β String
| atom _ val => val
| _ => ""
def setAtomVal : Syntax β String β Syntax
| atom info _, v => (atom info v)
| stx, _ => stx
@[inline] def ifNode {Ξ²} (stx : Syntax) (hyes : SyntaxNode β Ξ²) (hno : Unit β Ξ²) : Ξ² :=
match stx with
| Syntax.node i k args => hyes β¨Syntax.node i k args, IsNode.mk i k argsβ©
| _ => hno ()
@[inline] def ifNodeKind {Ξ²} (stx : Syntax) (kind : SyntaxNodeKind) (hyes : SyntaxNode β Ξ²) (hno : Unit β Ξ²) : Ξ² :=
match stx with
| Syntax.node i k args => if k == kind then hyes β¨Syntax.node i k args, IsNode.mk i k argsβ© else hno ()
| _ => hno ()
def asNode : Syntax β SyntaxNode
| Syntax.node info kind args => β¨Syntax.node info kind args, IsNode.mk info kind argsβ©
| _ => β¨mkNullNode, IsNode.mk _ _ _β©
def getIdAt (stx : Syntax) (i : Nat) : Name :=
(stx.getArg i).getId
@[inline] def modifyArgs (stx : Syntax) (fn : Array Syntax β Array Syntax) : Syntax :=
match stx with
| node i k args => node i k (fn args)
| stx => stx
@[inline] def modifyArg (stx : Syntax) (i : Nat) (fn : Syntax β Syntax) : Syntax :=
match stx with
| node info k args => node info k (args.modify i fn)
| stx => stx
@[specialize] partial def replaceM {m : Type β Type} [Monad m] (fn : Syntax β m (Option Syntax)) : Syntax β m (Syntax)
| stx@(node info kind args) => do
match (β fn stx) with
| some stx => return stx
| none => return node info kind (β args.mapM (replaceM fn))
| stx => do
let o β fn stx
return o.getD stx
@[specialize] partial def rewriteBottomUpM {m : Type β Type} [Monad m] (fn : Syntax β m (Syntax)) : Syntax β m (Syntax)
| node info kind args => do
let args β args.mapM (rewriteBottomUpM fn)
fn (node info kind args)
| stx => fn stx
@[inline] def rewriteBottomUp (fn : Syntax β Syntax) (stx : Syntax) : Syntax :=
Id.run <| stx.rewriteBottomUpM fn
private def updateInfo : SourceInfo β String.Pos β String.Pos β SourceInfo
| SourceInfo.original lead pos trail endPos, leadStart, trailStop =>
SourceInfo.original { lead with startPos := leadStart } pos { trail with stopPos := trailStop } endPos
| info, _, _ => info
private def chooseNiceTrailStop (trail : Substring) : String.Pos :=
trail.startPos + trail.posOf '\n'
/-- Remark: the State `String.Pos` is the `SourceInfo.trailing.stopPos` of the previous token,
or the beginning of the String. -/
@[inline]
private def updateLeadingAux : Syntax β StateM String.Pos (Option Syntax)
| atom info@(SourceInfo.original _ _ trail _) val => do
let trailStop := chooseNiceTrailStop trail
let newInfo := updateInfo info (β get) trailStop
set trailStop
return some (atom newInfo val)
| ident info@(SourceInfo.original _ _ trail _) rawVal val pre => do
let trailStop := chooseNiceTrailStop trail
let newInfo := updateInfo info (β get) trailStop
set trailStop
return some (ident newInfo rawVal val pre)
| _ => pure none
/-- Set `SourceInfo.leading` according to the trailing stop of the preceding token.
The result is a round-tripping syntax tree IF, in the input syntax tree,
* all leading stops, atom contents, and trailing starts are correct
* trailing stops are between the trailing start and the next leading stop.
Remark: after parsing, all `SourceInfo.leading` fields are empty.
The `Syntax` argument is the output produced by the parser for `source`.
This function "fixes" the `source.leading` field.
Additionally, we try to choose "nicer" splits between leading and trailing stops
according to some heuristics so that e.g. comments are associated to the (intuitively)
correct token.
Note that the `SourceInfo.trailing` fields must be correct.
The implementation of this Function relies on this property. -/
def updateLeading : Syntax β Syntax :=
fun stx => (replaceM updateLeadingAux stx).run' 0
partial def updateTrailing (trailing : Substring) : Syntax β Syntax
| Syntax.atom info val => Syntax.atom (info.updateTrailing trailing) val
| Syntax.ident info rawVal val pre => Syntax.ident (info.updateTrailing trailing) rawVal val pre
| n@(Syntax.node info k args) =>
if args.size == 0 then n
else
let i := args.size - 1
let last := updateTrailing trailing args[i]!
let args := args.set! i last;
Syntax.node info k args
| s => s
partial def getTailWithPos : Syntax β Option Syntax
| stx@(atom info _) => info.getPos?.map fun _ => stx
| stx@(ident info ..) => info.getPos?.map fun _ => stx
| node SourceInfo.none _ args => args.findSomeRev? getTailWithPos
| stx@(node ..) => stx
| _ => none
open SourceInfo in
/-- Split an `ident` into its dot-separated components while preserving source info.
Macro scopes are first erased. For example, `` `foo.bla.boo._@._hyg.4 `` β¦ `` [`foo, `bla, `boo] ``.
If `nFields` is set, we take that many fields from the end and keep the remaining components
as one name. For example, `` `foo.bla.boo `` with `(nFields := 1)` β¦ `` [`foo.bla, `boo] ``. -/
def identComponents (stx : Syntax) (nFields? : Option Nat := none) : List Syntax :=
match stx with
| ident (SourceInfo.original lead pos trail _) rawStr val _ =>
let val := val.eraseMacroScopes
-- With original info, we assume that `rawStr` represents `val`.
let nameComps := nameComps val nFields?
let rawComps := splitNameLit rawStr
let rawComps :=
if let some nFields := nFields? then
let nPrefix := rawComps.length - nFields
let prefixSz := rawComps.take nPrefix |>.foldl (init := 0) fun acc (ss : Substring) => acc + ss.bsize + 1
let prefixSz := prefixSz - 1 -- The last component has no dot
rawStr.extract 0 β¨prefixSzβ© :: rawComps.drop nPrefix
else
rawComps
assert! nameComps.length == rawComps.length
nameComps.zip rawComps |>.map fun (id, ss) =>
let off := ss.startPos - rawStr.startPos
let lead := if off == 0 then lead else "".toSubstring
let trail := if ss.stopPos == rawStr.stopPos then trail else "".toSubstring
let info := original lead (pos + off) trail (pos + off + β¨ss.bsizeβ©)
ident info ss id []
| ident si _ val _ =>
let val := val.eraseMacroScopes
/- With non-original info:
- `rawStr` can take all kinds of forms so we only use `val`.
- there is no source extent to offset, so we pass it as-is. -/
nameComps val nFields? |>.map fun n => ident si n.toString.toSubstring n []
| _ => unreachable!
where
nameComps (n : Name) (nFields? : Option Nat) : List Name :=
if let some nFields := nFields? then
let nameComps := n.components
let nPrefix := nameComps.length - nFields
let namePrefix := nameComps.take nPrefix |>.foldl (init := Name.anonymous) fun acc n => acc ++ n
namePrefix :: nameComps.drop nPrefix
else
n.components
structure TopDown where
firstChoiceOnly : Bool
stx : Syntax
/--
`for _ in stx.topDown` iterates through each node and leaf in `stx` top-down, left-to-right.
If `firstChoiceOnly` is `true`, only visit the first argument of each choice node.
-/
def topDown (stx : Syntax) (firstChoiceOnly := false) : TopDown := β¨firstChoiceOnly, stxβ©
partial instance : ForIn m TopDown Syntax where
forIn := fun β¨firstChoiceOnly, stxβ© init f => do
let rec @[specialize] loop stx b [Inhabited (type_of% b)] := do
match (β f stx b) with
| ForInStep.yield b' =>
let mut b := b'
if let Syntax.node _ k args := stx then
if firstChoiceOnly && k == choiceKind then
return β loop args[0]! b
else
for arg in args do
match (β loop arg b) with
| ForInStep.yield b' => b := b'
| ForInStep.done b' => return ForInStep.done b'
return ForInStep.yield b
| ForInStep.done b => return ForInStep.done b
match (β @loop stx init β¨initβ©) with
| ForInStep.yield b => return b
| ForInStep.done b => return b
partial def reprint (stx : Syntax) : Option String := do
let mut s := ""
for stx in stx.topDown (firstChoiceOnly := true) do
match stx with
| atom info val => s := s ++ reprintLeaf info val
| ident info rawVal _ _ => s := s ++ reprintLeaf info rawVal.toString
| node _ kind args =>
if kind == choiceKind then
-- this visit the first arg twice, but that should hardly be a problem
-- given that choice nodes are quite rare and small
let s0 β reprint args[0]!
for arg in args[1:] do
let s' β reprint arg
guard (s0 == s')
| _ => pure ()
return s
where
reprintLeaf (info : SourceInfo) (val : String) : String :=
match info with
| SourceInfo.original lead _ trail _ => s!"{lead}{val}{trail}"
-- no source info => add gracious amounts of whitespace to definitely separate tokens
-- Note that the proper pretty printer does not use this function.
-- The parser as well always produces source info, so round-tripping is still
-- guaranteed.
| _ => s!" {val} "
def hasMissing (stx : Syntax) : Bool := Id.run do
for stx in stx.topDown do
if stx.isMissing then
return true
return false
def getRange? (stx : Syntax) (canonicalOnly := false) : Option String.Range :=
match stx.getPos? canonicalOnly, stx.getTailPos? canonicalOnly with
| some start, some stop => some { start, stop }
| _, _ => none
/--
Represents a cursor into a syntax tree that can be read, written, and advanced down/up/left/right.
Indices are allowed to be out-of-bound, in which case `cur` is `Syntax.missing`.
If the `Traverser` is used linearly, updates are linear in the `Syntax` object as well.
-/
structure Traverser where
cur : Syntax
parents : Array Syntax
idxs : Array Nat
namespace Traverser
def fromSyntax (stx : Syntax) : Traverser :=
β¨stx, #[], #[]β©
def setCur (t : Traverser) (stx : Syntax) : Traverser :=
{ t with cur := stx }
/-- Advance to the `idx`-th child of the current node. -/
def down (t : Traverser) (idx : Nat) : Traverser :=
if idx < t.cur.getNumArgs then
{ cur := t.cur.getArg idx, parents := t.parents.push <| t.cur.setArg idx default, idxs := t.idxs.push idx }
else
{ cur := Syntax.missing, parents := t.parents.push t.cur, idxs := t.idxs.push idx }
/-- Advance to the parent of the current node, if any. -/
def up (t : Traverser) : Traverser :=
if t.parents.size > 0 then
let cur := if t.idxs.back < t.parents.back.getNumArgs then t.parents.back.setArg t.idxs.back t.cur else t.parents.back
{ cur := cur, parents := t.parents.pop, idxs := t.idxs.pop }
else
t
/-- Advance to the left sibling of the current node, if any. -/
def left (t : Traverser) : Traverser :=
if t.parents.size > 0 then
t.up.down (t.idxs.back - 1)
else
t
/-- Advance to the right sibling of the current node, if any. -/
def right (t : Traverser) : Traverser :=
if t.parents.size > 0 then
t.up.down (t.idxs.back + 1)
else
t
end Traverser
/-- Monad class that gives read/write access to a `Traverser`. -/
class MonadTraverser (m : Type β Type) where
st : MonadState Traverser m
namespace MonadTraverser
variable {m : Type β Type} [Monad m] [t : MonadTraverser m]
def getCur : m Syntax := Traverser.cur <$> t.st.get
def setCur (stx : Syntax) : m Unit := @modify _ _ t.st (fun t => t.setCur stx)
def goDown (idx : Nat) : m Unit := @modify _ _ t.st (fun t => t.down idx)
def goUp : m Unit := @modify _ _ t.st (fun t => t.up)
def goLeft : m Unit := @modify _ _ t.st (fun t => t.left)
def goRight : m Unit := @modify _ _ t.st (fun t => t.right)
def getIdx : m Nat := do
let st β t.st.get
return st.idxs.back?.getD 0
end MonadTraverser
end Syntax
namespace SyntaxNode
@[inline] def getIdAt (n : SyntaxNode) (i : Nat) : Name :=
(n.getArg i).getId
end SyntaxNode
def mkListNode (args : Array Syntax) : Syntax :=
mkNullNode args
namespace Syntax
-- quotation node kinds are formed from a unique quotation name plus "quot"
def isQuot : Syntax β Bool
| Syntax.node _ (Name.str _ "quot") _ => true
| Syntax.node _ `Lean.Parser.Term.dynamicQuot _ => true
| _ => false
def getQuotContent (stx : Syntax) : Syntax :=
let stx := if stx.getNumArgs == 1 then stx[0] else stx
if stx.isOfKind `Lean.Parser.Term.dynamicQuot then
stx[3]
else
stx[1]
-- antiquotation node kinds are formed from the original node kind (if any) plus "antiquot"
def isAntiquot : Syntax β Bool
| .node _ (.str _ "antiquot") _ => true
| _ => false
def isAntiquots (stx : Syntax) : Bool :=
stx.isAntiquot || (stx.isOfKind choiceKind && stx.getNumArgs > 0 && stx.getArgs.all isAntiquot)
def getCanonicalAntiquot (stx : Syntax) : Syntax :=
if stx.isOfKind choiceKind then
stx[0]
else
stx
def mkAntiquotNode (kind : Name) (term : Syntax) (nesting := 0) (name : Option String := none) (isPseudoKind := false) : Syntax :=
let nesting := mkNullNode (mkArray nesting (mkAtom "$"))
let term :=
if term.isIdent then term
else if term.isOfKind `Lean.Parser.Term.hole then term[0]
else mkNode `antiquotNestedExpr #[mkAtom "(", term, mkAtom ")"]
let name := match name with
| some name => mkNode `antiquotName #[mkAtom ":", mkAtom name]
| none => mkNullNode
mkNode (kind ++ (if isPseudoKind then `pseudo else Name.anonymous) ++ `antiquot) #[mkAtom "$", nesting, term, name]
-- Antiquotations can be escaped as in `$$x`, which is useful for nesting macros. Also works for antiquotation splices.
def isEscapedAntiquot (stx : Syntax) : Bool :=
!stx[1].getArgs.isEmpty
-- Also works for antiquotation splices.
def unescapeAntiquot (stx : Syntax) : Syntax :=
if isAntiquot stx then
stx.setArg 1 <| mkNullNode stx[1].getArgs.pop
else
stx
-- Also works for token antiquotations.
def getAntiquotTerm (stx : Syntax) : Syntax :=
let e := if stx.isAntiquot then stx[2] else stx[3]
if e.isIdent then e
else if e.isAtom then mkNode `Lean.Parser.Term.hole #[e]
else
-- `e` is from `"(" >> termParser >> ")"`
e[1]
/-- Return kind of parser expected at this antiquotation, and whether it is a "pseudo" kind (see `mkAntiquot`). -/
def antiquotKind? : Syntax β Option (SyntaxNodeKind Γ Bool)
| .node _ (.str (.str k "pseudo") "antiquot") _ => (k, true)
| .node _ (.str k "antiquot") _ => (k, false)
| _ => none
def antiquotKinds (stx : Syntax) : List (SyntaxNodeKind Γ Bool) :=
if stx.isOfKind choiceKind then
stx.getArgs.filterMap antiquotKind? |>.toList
else
match antiquotKind? stx with
| some stx => [stx]
| none => []
-- An "antiquotation splice" is something like `$[...]?` or `$[...]*`.
def antiquotSpliceKind? : Syntax β Option SyntaxNodeKind
| .node _ (.str k "antiquot_scope") _ => some k
| _ => none
def isAntiquotSplice (stx : Syntax) : Bool :=
antiquotSpliceKind? stx |>.isSome
def getAntiquotSpliceContents (stx : Syntax) : Array Syntax :=
stx[3].getArgs
-- `$[..],*` or `$x,*` ~> `,*`
def getAntiquotSpliceSuffix (stx : Syntax) : Syntax :=
if stx.isAntiquotSplice then
stx[5]
else
stx[1]
def mkAntiquotSpliceNode (kind : SyntaxNodeKind) (contents : Array Syntax) (suffix : String) (nesting := 0) : Syntax :=
let nesting := mkNullNode (mkArray nesting (mkAtom "$"))
mkNode (kind ++ `antiquot_splice) #[mkAtom "$", nesting, mkAtom "[", mkNullNode contents, mkAtom "]", mkAtom suffix]
-- `$x,*` etc.
def antiquotSuffixSplice? : Syntax β Option SyntaxNodeKind
| .node _ (.str k "antiquot_suffix_splice") _ => some k
| _ => none
def isAntiquotSuffixSplice (stx : Syntax) : Bool :=
antiquotSuffixSplice? stx |>.isSome
-- `$x` in the example above
def getAntiquotSuffixSpliceInner (stx : Syntax) : Syntax :=
stx[0]
def mkAntiquotSuffixSpliceNode (kind : SyntaxNodeKind) (inner : Syntax) (suffix : String) : Syntax :=
mkNode (kind ++ `antiquot_suffix_splice) #[inner, mkAtom suffix]
def isTokenAntiquot (stx : Syntax) : Bool :=
stx.isOfKind `token_antiquot
def isAnyAntiquot (stx : Syntax) : Bool :=
stx.isAntiquot || stx.isAntiquotSplice || stx.isAntiquotSuffixSplice || stx.isTokenAntiquot
/-- List of `Syntax` nodes in which each succeeding element is the parent of
the current. The associated index is the index of the preceding element in the
list of children of the current element. -/
protected abbrev Stack := List (Syntax Γ Nat)
/-- Return stack of syntax nodes satisfying `visit`, starting with such a node that also fulfills `accept` (default "is leaf"), and ending with the root. -/
partial def findStack? (root : Syntax) (visit : Syntax β Bool) (accept : Syntax β Bool := fun stx => !stx.hasArgs) : Option Syntax.Stack :=
if visit root then go [] root else none
where
go (stack : Syntax.Stack) (stx : Syntax) : Option Syntax.Stack := Id.run do
if accept stx then
return (stx, 0) :: stack -- the first index is arbitrary as there is no preceding element
for i in [0:stx.getNumArgs] do
if visit stx[i] then
if let some stack := go ((stx, i) :: stack) stx[i] then
return stack
return none
/-- Compare the `SyntaxNodeKind`s in `pattern` to those of the `Syntax`
elements in `stack`. Return `false` if `stack` is shorter than `pattern`. -/
def Stack.matches (stack : Syntax.Stack) (pattern : List $ Option SyntaxNodeKind) : Bool :=
stack.length >= pattern.length &&
(stack
|>.zipWith (fun (s, _) p => p |>.map (s.isOfKind Β·) |>.getD true) pattern
|>.all id)
end Syntax
end Lean
|
theory Chisholm_C imports DDL (*Christoph BenzmΓΌller & Xavier Parent, 2018*)
begin (* Chisholm Example *)
consts go::\<sigma> tell::\<sigma> kill::\<sigma>
axiomatization where
D1: "\<lfloor>\<^bold>O\<^bold>\<langle>go\<^bold>\<rangle>\<rfloor>" (*It ought to be that Jones goes to assist his neighbors.*) and
D2: "\<lfloor>\<^bold>O\<^bold>\<langle>go \<^bold>\<rightarrow> tell\<^bold>\<rangle>\<rfloor>" (*It ought to be that if Jones goes, then he tells them he is coming.*) and
D3: "\<lfloor>\<^bold>\<not>go \<^bold>\<rightarrow> \<^bold>O\<^bold>\<langle>\<^bold>\<not>tell\<^bold>\<rangle>\<rfloor>" (*If Jones doesn't go, then he ought not tell them he is coming.*) and
D4: "\<lfloor>\<^bold>\<not>go\<rfloor>\<^sub>c\<^sub>w" (*Jones doesn't go. (This is encoded as a locally valid statement.)*)
(*Some Experiments*)
sledgehammer_params [max_facts=20] (*Sets default parameters for the theorem provers*)
nitpick_params [user_axioms,expect=genuine,show_all,format=2] (*... and for the model finder.*)
lemma True nitpick [satisfy] oops (*Consistency-check: Is there a model?*)
lemma False sledgehammer oops (*Inconsistency-check: Can Falsum be derived?*)
lemma "\<lfloor>\<^bold>O\<^bold>\<langle>\<^bold>\<not>tell\<^bold>\<rangle>\<rfloor>" sledgehammer nitpick oops (*Should James not tell?*)
lemma "\<lfloor>\<^bold>O\<^bold>\<langle>tell\<^bold>\<rangle>\<rfloor>" sledgehammer nitpick oops (*Should James tell?*)
lemma "\<lfloor>\<^bold>O\<^bold>\<langle>kill\<^bold>\<rangle>\<rfloor>" sledgehammer nitpick oops (*Should James kill?*)
end
(*
D2: "\<lfloor>\<^bold>O\<^bold>\<langle>tell\<^bold>|go\<^bold>\<rangle>\<rfloor>" and
D3: "\<lfloor>\<^bold>O\<^bold>\<langle>\<^bold>\<not>tell\<^bold>|\<^bold>\<not>go\<^bold>\<rangle>\<rfloor>" and
*) |
lemma norm_exp_eq_Re [simp]: "norm (exp z) = exp (Re z)" |
\ Ingredients Needed:
\ - IF ELSE THEN
\ - BEGIN UNTIL
\ - '(' ')'
: IF IMMEDIATE
' 0BRANCH ,
HERE @
0 ,
;
: THEN IMMEDIATE
DUP
HERE @ SWAP -
SWAP !
;
: ELSE IMMEDIATE
' BRANCH ,
HERE @
0 ,
SWAP
DUP
HERE @ SWAP -
SWAP !
;
: BEGIN IMMEDIATE
HERE @
;
: UNTIL IMMEDIATE
' 0BRANCH ,
HERE @ -
,
;
: LITERAL IMMEDIATE
' LIT ,
,
;
: '(' [ CHAR ( ] LITERAL ;
: ')' [ CHAR ) ] LITERAL ;
: ( IMMEDIATE
1
BEGIN
KEY
DUP '(' = IF
DROP
1+
ELSE
')' = IF
1-
THEN
THEN
DUP 0= UNTIL
DROP
;
( foo )
( this should compile fine )
( and nested ( ... ) should works too )
|
Janie Isidoro tells about her family and their love of making and building a family business with makers.
Matthew Carlin shares his inspiration for his writing.
Teresa Mitchell is our first artist to do an improv PeckaKucha. She agreed to have a friend select 20 images from her Instagram account. Then, she shares about her own art!
Ed Boling talks about renovating a 100-year-old house and how he connected to his neighbors. |
# My Commit
# Author: LordZombitten
print("Hello world! Greetings from SLC, UT!") |
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
//=============================================================================
#include <remus/worker/detail/MessageRouter.h>
#include <remus/server/PortNumbers.h>
#include <remus/common/SleepFor.h>
#include <remus/proto/Message.h>
#include <remus/proto/Response.h>
#include <remus/proto/zmqHelper.h>
#include <remus/worker/detail/JobQueue.h>
#include <remus/testing/Testing.h>
REMUS_THIRDPARTY_PRE_INCLUDE
#include <boost/uuid/uuid.hpp>
REMUS_THIRDPARTY_POST_INCLUDE
using namespace remus::worker::detail;
namespace {
//------------------------------------------------------------------------------
remus::worker::ServerConnection bindToTCPSocket(zmq::socket_t &socket)
{
//try a new port each time we are called this is to help speed up the test
int port_offset = 72;
zmq::socketInfo<zmq::proto::tcp> socketInfo("127.0.0.1",
remus::server::WORKER_PORT + port_offset);
socketInfo = zmq::bindToAddress(socket,socketInfo);
return remus::worker::ServerConnection(socketInfo);
}
//------------------------------------------------------------------------------
void test_server_terminate_routing_call(MessageRouter& mr,
remus::worker::ServerConnection serverConn,
zmq::socket_t& serverSocket,
JobQueue& jq)
{
mr.start( serverConn, *(serverConn.context()) );
REMUS_ASSERT( (mr.valid()) )
REMUS_ASSERT( (mr.isForwardingToServer()) )
//we need to fetch a heartbeat message from the router
//so that we get the socket identity to send to
zmq::SocketIdentity sid = zmq::address_recv(serverSocket);
remus::worker::Job terminateJob(remus::testing::UUIDGenerator(),
remus::proto::JobSubmission());
//now send it a terminate message over the server channel
remus::proto::Response response =
remus::proto::send_NonBlockingResponse(remus::TERMINATE_WORKER,
remus::worker::to_string(terminateJob),
&serverSocket,
sid);
REMUS_ASSERT(response.isValid())
//cheap block while we wait for the router thread to get the message
for(int i=0; i < 10 && jq.size() == 0; ++i)
{
remus::common::SleepForMillisec(250);
}
REMUS_ASSERT( (jq.size() > 0) )
remus::common::SleepForMillisec(250);
REMUS_ASSERT( (mr.valid()) )
REMUS_ASSERT( (!mr.isForwardingToServer()) )
REMUS_ASSERT( (jq.size() == 1) )
remus::worker::Job invalid_job = jq.take();
REMUS_ASSERT( (!invalid_job.valid()) )
REMUS_ASSERT( (invalid_job.validityReason() ==
remus::worker::Job::TERMINATE_WORKER) )
}
}
int UnitTestMessageRouterServerTermination(int, char *[])
{
zmq::socketInfo<zmq::proto::inproc> worker_channel(remus::testing::UniqueString());
zmq::socketInfo<zmq::proto::inproc> queue_channel(remus::testing::UniqueString());
//bind the serverSocket
boost::shared_ptr<zmq::context_t> context = remus::worker::make_ServerContext();
zmq::socket_t serverSocket(*context, ZMQ_ROUTER);
remus::worker::ServerConnection serverConn = bindToTCPSocket(serverSocket);
//set the context on the server connection to the one we just created
serverConn.context(context);
//we need to bind to the inproc sockets before constructing the MessageRouter
//this is a required implementation detail caused by zmq design, also we have
//to share the same zmq context with the inproc protocol
zmq::socket_t worker_socket(*context, ZMQ_PAIR);
zmq::bindToAddress(worker_socket, worker_channel);
JobQueue jq(*context,queue_channel); //bind the jobqueue to the worker channel
//It should be noted that once you send a terminate call to a JobQueue
//or MessageRouter it can't be started again
//verify that we can send a TERMINATE_WORKER call from the server properly
MessageRouter mr(worker_channel, queue_channel);
test_server_terminate_routing_call(mr, serverConn, serverSocket,jq);
return 0;
}
|
lemma norm_of_real [simp]: "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>" |
{-# OPTIONS --warning=error --safe --without-K --guardedness #-}
open import Everything.Safe
open import Numbers.Reals.Definition
open import Fields.Orders.Limits.Definition
open import Rings.Orders.Partial.Bounded
open import Rings.Orders.Total.Bounded
open import Rings.Orders.Total.BaseExpansion
open import Fields.Orders.Limits.Lemmas
open import Rings.Orders.Total.Examples
--open import Fields.CauchyCompletion.Archimedean
open import Sets.Cardinality.Infinite.Examples
open import ProjectEuler.Problem2
open import LectureNotes.NumbersAndSets.Examples1
open import LectureNotes.Groups.Lecture1
module Everything.Guardedness where
|
If $f$ is a function from a set $X$ to $\mathbb{R}^n$ such that $f$ is continuous for each $i \in \{1, \ldots, n\}$, then the function $x \mapsto \sum_{i=1}^n f_i(x)$ is continuous. |
using Distributions
function poisson_dgp(N, mean_traps)
Ξ± = rand(Normal(log(4), .1))
Ξ² = rand(Normal(-0.25, .1))
traps = rand(Poisson(mean_traps), N)
complaints = similar(traps)
for i in eachindex(traps)
complaints[i] = rand(Poisson(exp(Ξ± + Ξ² * traps[i])))
end
return (Ξ± = Ξ±, Ξ² = Ξ², traps = traps, complaints = complaints)
end
|
"""
Sequential Monte Carlo for approximately constrained Gaussians.
http://arxiv.org/abs/1410.8209
"""
import numpy as np
def sample(white_constraint,
nsample,
proposal_sigma=0.2,
temps=np.linspace(0, 50., 51)):
"""
Build up an approximately constrained Gaussian
based on relaxations of the constraint.
Parameters
----------
white_constraint : `selection.constraints.affine`
Affine constraint with identity covariance
nsample : int
How many samples to draw?
proposal_sigma : float
"""
n = white_constraint.dim
sample_z = np.random.standard_normal((n, nsample))
def constraint_function(z, con):
value = (np.dot(con.linear_part, z) - con.offset[:,None])
return value.max(0)
def constraint_logit(temp, z, con):
tmp_z = constraint_function(z, con)
tmp_v = np.exp(-temp * tmp_z)
return tmp_v / (1 + tmp_v)
def MH_sample(temp, z_cur, con):
step = np.random.standard_normal(z_cur.shape) * proposal_sigma
z_new = z_cur + step
W_new = constraint_logit(temp, z_new, con)
W_cur = constraint_logit(temp, z_cur, con)
W_new *= np.exp(-(z_new**2).sum(0)/2)
W_cur *= np.exp(-(z_cur**2).sum(0)/2)
coin_flip = np.less_equal(np.random.sample(z_cur.shape[1]), W_new / W_cur)
final_sample = coin_flip * z_new + (1 - coin_flip) * z_cur
return final_sample
weights = np.ones(nsample, np.float) / nsample
num = np.ones(nsample) / 2
for i in range(temps.shape[0]-1):
num, den = constraint_logit(temps[i+1], sample_z, white_constraint), num
weights *= np.exp(np.log(num) - np.log(den))
weights /= weights.sum()
ESS = 1. / (weights**2).sum()
if ESS < nsample / 2.:
idx_z = np.random.choice(np.arange(nsample), size=(nsample,), replace=True, p=weights)
sample_z = sample_z[:, idx_z]
weights = np.ones(nsample, np.float) / nsample
sample_z = MH_sample(temps[i+1], sample_z, white_constraint)
return sample_z
|
const SGKmer{K} = BioSequences.DNAMer{K}
Base.write(io::IO, k::BioSequences.DNAMer) = write(io, reinterpret(UInt64, k))
Base.read(io::IO, ::Type{T}) where {T <: BioSequences.DNAMer} = convert(T, Base.read(io, UInt64))
# Conversion
# ----------
kmer_index( kmer::BioSequences.DNAMer{K} ) where {K} = Int(reinterpret(UInt64, kmer)) + 1
kmer_index( seq::BioSequence ) = Int(kmer_index_trailing( seq )) + 1
# calculate kmer index directly
@inline function kmer_index_trailing( ::Type{T}, seq ) where T <: Unsigned
x = T(0)
for nt in seq
ntint = convert(UInt8, trailing_zeros(nt))
if ntint > 0x03 || isambiguous(nt)
return zero(T)
else
x = x << 2 | ntint
end
end
x
end
kmer_index_trailing( seq ) = kmer_index_trailing(UInt64, seq )
kmer(seq::SGSequence) = sgkmer(seq)
sgkmer(seq::String) = SGKmer(seq)
sgkmer(seq::SGSequence) = SGKmer(seq)
|
(*:maxLineLen=78:*)
section \<open> Classical Soundness and Completeness \label{sec:classical-propositional-calculus} \<close>
theory Classical_Logic_Completeness
imports Classical_Logic
begin
sledgehammer_params [smt_proofs = false]
text \<open> The following presents soundness completeness of basic
propositional logic for propositional semantics.
A concrete algebraic data type is given for propositional
formulae in \S\ref{subsec:classical-calculus-syntax}. Logic for these
formulae is defined inductively. The Tarski truth relation \<open>\<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p\<close>
is also defined inductively, and is presented in
\S\ref{subsec:propositional-semantics}.\<close>
text \<open> The most significant results here are the \<^emph>\<open>embedding theorems\<close>.
These theorems show that the propositional calculus
can be embedded in any logic extending @{class classical_logic}.
These theorems are proved in \S\ref{subsec:propositional-embedding}. \<close>
subsection \<open> Syntax \label{subsec:classical-calculus-syntax} \<close>
datatype 'a classical_propositional_formula =
Falsum ("\<^bold>\<bottom>")
| Proposition 'a ("\<^bold>\<langle> _ \<^bold>\<rangle>" [45])
| Implication
"'a classical_propositional_formula"
"'a classical_propositional_formula" (infixr "\<^bold>\<rightarrow>" 70)
subsection \<open> Propositional Calculus \<close>
named_theorems classical_propositional_calculus
"Rules for the Propositional Calculus"
inductive classical_propositional_calculus ::
"'a classical_propositional_formula \<Rightarrow> bool" ("\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p _" [60] 55)
where
axiom_k [classical_propositional_calculus]:
"\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<^bold>\<rightarrow> \<psi> \<^bold>\<rightarrow> \<phi>"
| axiom_s [classical_propositional_calculus]:
"\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p (\<phi> \<^bold>\<rightarrow> \<psi> \<^bold>\<rightarrow> \<chi>) \<^bold>\<rightarrow> (\<phi> \<^bold>\<rightarrow> \<psi>) \<^bold>\<rightarrow> \<phi> \<^bold>\<rightarrow> \<chi>"
| double_negation [classical_propositional_calculus]:
"\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p ((\<phi> \<^bold>\<rightarrow> \<^bold>\<bottom>) \<^bold>\<rightarrow> \<^bold>\<bottom>) \<^bold>\<rightarrow> \<phi>"
| modus_ponens [classical_propositional_calculus]:
"\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<^bold>\<rightarrow> \<psi> \<Longrightarrow> \<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<Longrightarrow> \<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<psi>"
instantiation classical_propositional_formula
:: (type) classical_logic
begin
definition [simp]: "\<bottom> = \<^bold>\<bottom>"
definition [simp]: "\<turnstile> \<phi> = \<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
definition [simp]: "\<phi> \<rightarrow> \<psi> = \<phi> \<^bold>\<rightarrow> \<psi>"
instance by standard (simp add: classical_propositional_calculus)+
end
subsection \<open> Propositional Semantics \label{subsec:propositional-semantics}\<close>
primrec classical_propositional_semantics ::
"'a set \<Rightarrow> 'a classical_propositional_formula \<Rightarrow> bool"
(infix "\<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p" 65)
where
"\<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p Proposition p = (p \<in> \<MM>)"
| "\<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<^bold>\<rightarrow> \<psi> = (\<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<longrightarrow> \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<psi>)"
| "\<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<^bold>\<bottom> = False"
theorem classical_propositional_calculus_soundness:
"\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<Longrightarrow> \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
by (induct rule: classical_propositional_calculus.induct, simp+)
subsection \<open> Soundness and Completeness Proofs \label{subsec:classical-logic-completeness}\<close>
definition strong_classical_propositional_deduction ::
"'a classical_propositional_formula set
\<Rightarrow> 'a classical_propositional_formula \<Rightarrow> bool"
(infix "\<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p" 65)
where
[simp]: "\<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<equiv> \<Gamma> \<tturnstile> \<phi>"
definition strong_classical_propositional_tarski_truth ::
"'a classical_propositional_formula set
\<Rightarrow> 'a classical_propositional_formula \<Rightarrow> bool"
(infix "\<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p" 65)
where
[simp]: "\<Gamma> \<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<equiv> \<forall> \<MM>.(\<forall> \<gamma> \<in> \<Gamma>. \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<gamma>) \<longrightarrow> \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
definition theory_propositions ::
"'a classical_propositional_formula set \<Rightarrow> 'a set" ("\<^bold>\<lbrace> _ \<^bold>\<rbrace>" [50])
where
[simp]: "\<^bold>\<lbrace> \<Gamma> \<^bold>\<rbrace> = {p . \<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p Proposition p}"
text \<open> Below we give the main lemma for completeness: the \<^emph>\<open>truth lemma\<close>.
This proof connects the maximally consistent sets developed in \S\ref{sec:implicational-maximally-consistent-sets}
and \S\ref{subsec:mcs} with the semantics given in
\S\ref{subsec:propositional-semantics}. \<close>
text \<open> All together, the technique we are using essentially follows
Blackburn et al.'s approach @{cite \<open>\S 4.2, pgs. 196-201\<close> blackburnSectionCanonicalModels2001}. \<close>
lemma truth_lemma:
assumes "MCS \<Gamma>"
shows "\<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<equiv> \<^bold>\<lbrace> \<Gamma> \<^bold>\<rbrace> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
proof (induct \<phi>)
case Falsum
then show ?case using assms by auto
next
case (Proposition x)
then show ?case by simp
next
case (Implication \<psi> \<chi>)
thus ?case
unfolding strong_classical_propositional_deduction_def
by (metis
assms
maximally_consistent_set_def
formula_maximally_consistent_set_def_implication
classical_propositional_semantics.simps(2)
implication_classical_propositional_formula_def
set_deduction_modus_ponens
set_deduction_reflection)
qed
text \<open> Here the truth lemma above is combined with @{thm formula_maximally_consistent_extension}
proven in \S\ref{subsec:propositional-semantics}. These theorems together
give rise to completeness for the propositional calculus. \<close>
theorem classical_propositional_calculus_strong_soundness_and_completeness:
"\<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> = \<Gamma> \<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
proof -
have soundness: "\<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<Longrightarrow> \<Gamma> \<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
proof -
assume "\<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
from this obtain \<Gamma>' where \<Gamma>': "set \<Gamma>' \<subseteq> \<Gamma>" "\<Gamma>' :\<turnstile> \<phi>"
by (simp add: set_deduction_def, blast)
{
fix \<MM>
assume "\<forall> \<gamma> \<in> \<Gamma>. \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<gamma>"
hence "\<forall> \<gamma> \<in> set \<Gamma>'. \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<gamma>" using \<Gamma>'(1) by auto
hence "\<forall> \<phi>. \<Gamma>' :\<turnstile> \<phi> \<longrightarrow> \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
proof (induct \<Gamma>')
case Nil
then show ?case
by (simp add:
classical_propositional_calculus_soundness
list_deduction_def)
next
case (Cons \<psi> \<Gamma>')
thus ?case using list_deduction_theorem by fastforce
qed
with \<Gamma>'(2) have "\<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>" by blast
}
thus "\<Gamma> \<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
using strong_classical_propositional_tarski_truth_def by blast
qed
have completeness: "\<Gamma> \<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<Longrightarrow> \<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
proof (erule contrapos_pp)
assume "\<not> \<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
hence "\<exists> \<MM>. (\<forall> \<gamma> \<in> \<Gamma>. \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<gamma>) \<and> \<not> \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
proof -
from \<open>\<not> \<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>\<close> obtain \<Omega> where \<Omega>: "\<Gamma> \<subseteq> \<Omega>" "\<phi>-MCS \<Omega>"
by (meson
formula_consistent_def
formula_maximally_consistent_extension
strong_classical_propositional_deduction_def)
hence "(\<phi> \<rightarrow> \<bottom>) \<in> \<Omega>"
using formula_maximally_consistent_set_def_negation by blast
hence "\<not> \<^bold>\<lbrace> \<Omega> \<^bold>\<rbrace> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
using \<Omega>
formula_consistent_def
formula_maximal_consistency
formula_maximally_consistent_set_def_def
truth_lemma
unfolding strong_classical_propositional_deduction_def
by blast
moreover have "\<forall> \<gamma> \<in> \<Gamma>. \<^bold>\<lbrace> \<Omega> \<^bold>\<rbrace> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<gamma>"
using
formula_maximal_consistency
truth_lemma
\<Omega>
set_deduction_reflection
unfolding strong_classical_propositional_deduction_def
by blast
ultimately show ?thesis by auto
qed
thus "\<not> \<Gamma> \<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
unfolding strong_classical_propositional_tarski_truth_def
by simp
qed
from soundness completeness show "\<Gamma> \<tturnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> = \<Gamma> \<TTurnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>"
by linarith
qed
theorem classical_propositional_calculus_soundness_and_completeness:
"\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> = (\<forall>\<MM>. \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi>)"
using classical_propositional_calculus_soundness [where \<phi>="\<phi>"]
classical_propositional_calculus_strong_soundness_and_completeness
[where \<phi>="\<phi>" and \<Gamma>="{}"]
strong_classical_propositional_deduction_def
[where \<phi>="\<phi>" and \<Gamma>="{}"]
strong_classical_propositional_tarski_truth_def
[where \<phi>="\<phi>" and \<Gamma>="{}"]
deduction_classical_propositional_formula_def [where \<phi>="\<phi>"]
set_deduction_base_theory [where \<phi>="\<phi>"]
by metis
instantiation classical_propositional_formula
:: (type) consistent_classical_logic
begin
instance by standard
(simp add: classical_propositional_calculus_soundness_and_completeness)
end
subsection \<open> Embedding Theorem For the Propositional Calculus \label{subsec:propositional-embedding} \<close>
primrec (in classical_logic)
classical_propositional_formula_embedding
:: "'a classical_propositional_formula \<Rightarrow> 'a" ("\<^bold>\<lparr> _ \<^bold>\<rparr>" [50]) where
"\<^bold>\<lparr> \<^bold>\<langle> p \<^bold>\<rangle> \<^bold>\<rparr> = p"
| "\<^bold>\<lparr> \<phi> \<^bold>\<rightarrow> \<psi> \<^bold>\<rparr> = \<^bold>\<lparr> \<phi> \<^bold>\<rparr> \<rightarrow> \<^bold>\<lparr> \<psi> \<^bold>\<rparr>"
| "\<^bold>\<lparr> \<^bold>\<bottom> \<^bold>\<rparr> = \<bottom>"
theorem (in classical_logic) propositional_calculus:
"\<turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<Longrightarrow> \<turnstile> \<^bold>\<lparr> \<phi> \<^bold>\<rparr>"
by (induct rule: classical_propositional_calculus.induct,
(simp add: axiom_k axiom_s double_negation modus_ponens)+)
theorem (in classical_logic) propositional_semantics:
"\<forall>\<MM>. \<MM> \<Turnstile>\<^sub>p\<^sub>r\<^sub>o\<^sub>p \<phi> \<Longrightarrow> \<turnstile> \<^bold>\<lparr> \<phi> \<^bold>\<rparr>"
by (simp add:
classical_propositional_calculus_soundness_and_completeness
propositional_calculus)
end
|
# -*- coding: utf-8 -*-
# Copyright (C) 2008-2012, Luis Pedro Coelho <[email protected]>
# vim: set ts=4 sts=4 sw=4 expandtab smartindent:
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from __future__ import division
import numpy as np
__all__ = [
'center',
'zscore',
]
def _nanmean(arr, axis=None):
nancounts = np.sum(~np.isnan(arr), axis=axis)
return np.nansum(arr,axis=axis)/nancounts
def _nanstd(arr, axis=None):
if axis == 1:
return _nanstd(arr.T, axis=0)
mu = _nanmean(arr,axis=axis)
return np.sqrt(_nanmean((arr-mu)**2, axis=axis))
def zscore(features, axis=0, can_have_nans=True, inplace=False):
"""
features = zscore(features, axis=0, can_have_nans=True, inplace=False)
Returns a copy of features which has been normalised to zscores
Parameters
----------
features : ndarray
2-D input array
axis : integer, optional
which axis to normalise (default: 0)
can_have_nans : boolean, optional
whether ``features`` is allowed to have NaNs (default: True)
inplace : boolean, optional
Whether to operate inline (i.e., potentially change the input array).
Default is False
Returns
-------
features : ndarray
zscored version of features
"""
if features.ndim != 2:
raise('milk.unsupervised.zscore: Can only handle 2-D arrays')
if not inplace:
features = features.copy()
if can_have_nans:
mu = _nanmean(features, axis)
sigma = _nanstd(features, axis)
else:
mu = features.mean(axis)
sigma = np.std(features, axis)
sigma[sigma == 0] = 1.
if axis == 0:
features -= mu
features /= sigma
elif axis == 1:
features -= mu[:,None]
features /= sigma[:,None]
return features
def center(features, axis=0, can_have_nans=True, inplace=False):
'''
centered, mean = center(features, axis=0, inplace=False)
Center data
Parameters
----------
features : ndarray
2-D input array
axis : integer, optional
which axis to normalise (default: 0)
can_have_nans : boolean, optional
whether ``features`` is allowed to have NaNs (default: True)
inplace : boolean, optional
Whether to operate inline (i.e., potentially change the input array).
Default is False
Returns
-------
features : ndarray
centered version of features
mean : ndarray
mean values
'''
if can_have_nans:
meanfunction = _nanmean
else:
meanfunction = np.mean
features = np.array(features, copy=(not inplace), dtype=float)
mean = meanfunction(features, axis=axis)
if axis == 0:
features -= mean
elif axis == 1:
features -= mean[:,None]
else:
raise ValueError('milk.unsupervised.center: axis β { 0, 1}')
return features, mean
|
library(plyr) # install.packages("plyr")
# INPUTS
data <- read.csv("../output.csv", sep=",")
tmp.go_projects = data[data$language == "go",]
tmp.c_projects = data[data$language == "c",]
options(scipen=999) # disable scientific notation
boxplot(tmp.c_projects$support, tmp.go_projects$support, log = "y", at = c(1,2), ylim=c(1,300), names = c("C", "Go"))
quantile(tmp.c_projects$support)
quantile(tmp.go_projects$support)
boxplot(tmp.c_projects$confidence, tmp.go_projects$confidence, at = c(1,2), names = c("C", "Go"))
quantile(tmp.c_projects$confidence)
quantile(tmp.go_projects$confidence)
rm(list = ls(pattern = "tmp.*"))
|
https://www.cs.cornell.edu/projects/kddcup/datasets.html
!tar xzvf hep-th-2003.tar.gz!ls -hal 2003/ | wc -l
# load libraries
```python
# https://github.com/alvinwan/tex2py
!pip install tex2py
```
Collecting tex2py
Collecting pytest (from tex2py)
Using cached https://files.pythonhosted.org/packages/ca/e1/2f229554e5c273962fae8b286395d5bbcc7bef276d2b40e1bad954993db2/pytest-5.1.3-py3-none-any.whl
Collecting coverage==3.7.1 (from tex2py)
Collecting TexSoup==0.1.4 (from tex2py)
Collecting coveralls==1.1 (from tex2py)
Using cached https://files.pythonhosted.org/packages/81/f9/da2ad9334f60e418cb229c58724330be2635b369676d3eec8f61e1f85faa/coveralls-1.1-py2.py3-none-any.whl
Collecting pytest-cov==2.5.1 (from tex2py)
Using cached https://files.pythonhosted.org/packages/30/7d/7f6a78ae44a1248ee28cc777586c18b28a1df903470e5d34a6e25712b8aa/pytest_cov-2.5.1-py2.py3-none-any.whl
Collecting pptree==2.0 (from tex2py)
Collecting atomicwrites>=1.0 (from pytest->tex2py)
Using cached https://files.pythonhosted.org/packages/52/90/6155aa926f43f2b2a22b01be7241be3bfd1ceaf7d0b3267213e8127d41f4/atomicwrites-1.3.0-py2.py3-none-any.whl
Collecting more-itertools>=4.0.0 (from pytest->tex2py)
Using cached https://files.pythonhosted.org/packages/45/dc/3241eef99eb45f1def35cf93af35d1cf9ef4c0991792583b8f33ea41b092/more_itertools-7.2.0-py3-none-any.whl
Collecting pluggy<1.0,>=0.12 (from pytest->tex2py)
Using cached https://files.pythonhosted.org/packages/92/c7/48439f7d5fd6bddb4c04b850bb862b42e3e2b98570040dfaf68aedd8114b/pluggy-0.13.0-py2.py3-none-any.whl
Collecting py>=1.5.0 (from pytest->tex2py)
Using cached https://files.pythonhosted.org/packages/76/bc/394ad449851729244a97857ee14d7cba61ddb268dce3db538ba2f2ba1f0f/py-1.8.0-py2.py3-none-any.whl
Collecting attrs>=17.4.0 (from pytest->tex2py)
Using cached https://files.pythonhosted.org/packages/23/96/d828354fa2dbdf216eaa7b7de0db692f12c234f7ef888cc14980ef40d1d2/attrs-19.1.0-py2.py3-none-any.whl
Collecting importlib-metadata>=0.12; python_version < "3.8" (from pytest->tex2py)
Using cached https://files.pythonhosted.org/packages/f6/d2/40b3fa882147719744e6aa50ac39cf7a22a913cbcba86a0371176c425a3b/importlib_metadata-0.23-py2.py3-none-any.whl
Requirement already satisfied: packaging in /opt/conda/lib/python3.6/site-packages (from pytest->tex2py) (18.0)
Requirement already satisfied: wcwidth in /opt/conda/lib/python3.6/site-packages (from pytest->tex2py) (0.1.7)
Requirement already satisfied: requests>=1.0.0 in /opt/conda/lib/python3.6/site-packages (from coveralls==1.1->tex2py) (2.20.0)
Collecting docopt>=0.6.1 (from coveralls==1.1->tex2py)
Collecting zipp>=0.5 (from importlib-metadata>=0.12; python_version < "3.8"->pytest->tex2py)
Using cached https://files.pythonhosted.org/packages/74/3d/1ee25a26411ba0401b43c6376d2316a71addcc72ef8690b101b4ea56d76a/zipp-0.6.0-py2.py3-none-any.whl
Requirement already satisfied: six in /opt/conda/lib/python3.6/site-packages (from packaging->pytest->tex2py) (1.11.0)
Requirement already satisfied: pyparsing>=2.0.2 in /opt/conda/lib/python3.6/site-packages (from packaging->pytest->tex2py) (2.2.2)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->tex2py) (1.23)
Requirement already satisfied: idna<2.8,>=2.5 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->tex2py) (2.7)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->tex2py) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->tex2py) (2018.11.29)
Installing collected packages: atomicwrites, more-itertools, zipp, importlib-metadata, pluggy, py, attrs, pytest, coverage, docopt, coveralls, pytest-cov, TexSoup, pptree, tex2py
Successfully installed TexSoup-0.1.4 atomicwrites-1.3.0 attrs-19.1.0 coverage-3.7.1 coveralls-1.1 docopt-0.6.2 importlib-metadata-0.23 more-itertools-7.2.0 pluggy-0.13.0 pptree-2.0 py-1.8.0 pytest-5.1.3 pytest-cov-2.5.1 tex2py-0.0.5 zipp-0.6.0
```python
# https://github.com/alvinwan/TexSoup
!pip install texsoup
```
Requirement already satisfied: texsoup in /opt/conda/lib/python3.6/site-packages (0.1.4)
Requirement already satisfied: pytest in /opt/conda/lib/python3.6/site-packages (from texsoup) (5.1.3)
Requirement already satisfied: pytest-cov==2.5.1 in /opt/conda/lib/python3.6/site-packages (from texsoup) (2.5.1)
Requirement already satisfied: coveralls==1.1 in /opt/conda/lib/python3.6/site-packages (from texsoup) (1.1)
Requirement already satisfied: coverage==3.7.1 in /opt/conda/lib/python3.6/site-packages (from texsoup) (3.7.1)
Requirement already satisfied: packaging in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (18.0)
Requirement already satisfied: attrs>=17.4.0 in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (19.1.0)
Requirement already satisfied: atomicwrites>=1.0 in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (1.3.0)
Requirement already satisfied: more-itertools>=4.0.0 in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (7.2.0)
Requirement already satisfied: pluggy<1.0,>=0.12 in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (0.13.0)
Requirement already satisfied: py>=1.5.0 in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (1.8.0)
Requirement already satisfied: importlib-metadata>=0.12; python_version < "3.8" in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (0.23)
Requirement already satisfied: wcwidth in /opt/conda/lib/python3.6/site-packages (from pytest->texsoup) (0.1.7)
Requirement already satisfied: requests>=1.0.0 in /opt/conda/lib/python3.6/site-packages (from coveralls==1.1->texsoup) (2.20.0)
Requirement already satisfied: docopt>=0.6.1 in /opt/conda/lib/python3.6/site-packages (from coveralls==1.1->texsoup) (0.6.2)
Requirement already satisfied: pyparsing>=2.0.2 in /opt/conda/lib/python3.6/site-packages (from packaging->pytest->texsoup) (2.2.2)
Requirement already satisfied: six in /opt/conda/lib/python3.6/site-packages (from packaging->pytest->texsoup) (1.11.0)
Requirement already satisfied: zipp>=0.5 in /opt/conda/lib/python3.6/site-packages (from importlib-metadata>=0.12; python_version < "3.8"->pytest->texsoup) (0.6.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->texsoup) (2018.11.29)
Requirement already satisfied: idna<2.8,>=2.5 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->texsoup) (2.7)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->texsoup) (1.23)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.6/site-packages (from requests>=1.0.0->coveralls==1.1->texsoup) (3.0.4)
```python
import re
import time
import glob
import matplotlib.pyplot as plt
```
# load data
```python
list_of_files = glob.glob('hep-th/2003/*')
```
```python
len(list_of_files)
```
1019
# find relevant tags in latex
```python
start_time=time.time()
reslts={}
number_of_eq=0
for this_file in list_of_files:
with open(this_file,'rb') as f:
data = f.read()
resp = re.findall('\\\\begin{(?:eqnarray|equation|multiline)}.*?end{(?:eqnarray|equation|multiline)}',str(data),re.DOTALL)
# print(this_file)
for eq in resp:
number_of_eq+=1
try:
reslts[this_file].append(eq)
except KeyError:
reslts[this_file]=[]
reslts[this_file].append(eq)
# print(' ',eq,'\n')
print(round(time.time()-start_time,2),'seconds')
```
7.63 seconds
```python
number_of_eq
```
29481
```python
len(reslts.keys())
```
929
```python
reslts[list(reslts.keys())[0]]
```
['\\begin{equation}}\\n\\\\newcommand{\\\\eeq}{\\\\end{equation}',
'\\begin{eqnarray}}\\n\\\\newcommand{\\\\eeqa}{\\\\end{eqnarray}']
```python
reslts[list(reslts.keys())[1]][0]
```
'\\begin{equation}\\\\label{planewave}\\n\\\\begin{split}\\nds^2 & = 2dx^+dx^--\\\\m^2\\\\vec{x}^2\\\\bigl(dx^+\\\\bigr)^2+d\\\\vec{x}^2\\\\,,\\\\\\\\\\nF_5 & = 4\\\\m dx^+\\\\wedge\\\\bigl(dx^1\\\\wedge dx^2\\\\wedge dx^3\\\\wedge dx^4+dx^5\\\\wedge dx^6\\\\wedge dx^7\\\\wedge dx^8\\\\bigr)\\\\,.\\n\\\\end{split}\\n\\\\end{equation}'
# visualize results
```python
number_of_eq_per_file=[]
for k,v in reslts.items():
number_of_eq_per_file.append(len(v))
```
```python
_=plt.hist(number_of_eq_per_file,bins=100)
_=plt.ylabel('number of expressions')
_=plt.xlabel('number of documents')
```
```python
_=plt.hist(number_of_eq_per_file,bins=100)
_=plt.yscale('log', nonposy='clip')
_=plt.ylabel('number of expressions')
_=plt.xlabel('number of documents')
```
# parse the Latex
options:
* http://plastex.sourceforge.net/plastex/sect0025.html
* tex2py
* texsoup
```python
# https://github.com/alvinwan/tex2py
from tex2py import tex2py
```
```python
list_of_files[1]
```
'hep-th/2003/0304232'
```python
with open(list_of_files[1]) as f: data = f.read()
toc = tex2py(data)
```
toc.valid_tags
```python
from TexSoup import TexSoup
soup = TexSoup(data)
```
```python
soup.equation
```
\begin{equation}\label{planewave}
\begin{split}
ds^2 & = 2dx^+dx^--\m^2\vec{x}^2\bigl(dx^+\bigr)^2+d\vec{x}^2\,,\\
F_5 & = 4\m dx^+\wedge\bigl(dx^1\wedge dx^2\wedge dx^3\wedge dx^4+dx^5\wedge dx^6\wedge dx^7\wedge dx^8\bigr)\,.
\end{split}
\end{equation}
```python
lst = list(soup.find_all('equation'))
```
```python
len(lst) # how many equations are in the document?
```
79
```python
lst[0] # show the first match
```
\begin{equation}\label{planewave}
\begin{split}
ds^2 & = 2dx^+dx^--\m^2\vec{x}^2\bigl(dx^+\bigr)^2+d\vec{x}^2\,,\\
F_5 & = 4\m dx^+\wedge\bigl(dx^1\wedge dx^2\wedge dx^3\wedge dx^4+dx^5\wedge dx^6\wedge dx^7\wedge dx^8\bigr)\,.
\end{split}
\end{equation}
```python
lst[0][0] # what is the string inside the "begin{equation}"?
```
'\\label{planewave}\n\\begin{split}\nds^2 & = 2dx^+dx^--\\m^2\\vec{x}^2\\bigl(dx^+\\bigr)^2+d\\vec{x}^2\\,,\\\\\nF_5 & = 4\\m dx^+\\wedge\\bigl(dx^1\\wedge dx^2\\wedge dx^3\\wedge dx^4+dx^5\\wedge dx^6\\wedge dx^7\\wedge dx^8\\bigr)\\,.\n'
```python
lst[1]
```
\begin{equation}
\o_n=\sqrt{n^2+\bigl(\m\a'p^+\bigr)^2}\,,\qquad n\in\Nop\,,
\end{equation}
```python
lst[1][0]
```
"\n\\o_n=\\sqrt{n^2+\\bigl(\\m\\a'p^+\\bigr)^2}\\,,\\qquad n\\in\\Nop\\,,\n"
```python
for this_eq in soup.find_all('equation'):
print(this_eq[0])
```
\label{planewave}
\begin{split}
ds^2 & = 2dx^+dx^--\m^2\vec{x}^2\bigl(dx^+\bigr)^2+d\vec{x}^2\,,\\
F_5 & = 4\m dx^+\wedge\bigl(dx^1\wedge dx^2\wedge dx^3\wedge dx^4+dx^5\wedge dx^6\wedge dx^7\wedge dx^8\bigr)\,.
\o_n=\sqrt{n^2+\bigl(\m\a'p^+\bigr)^2}\,,\qquad n\in\Nop\,,
\label{dict}
\frac{1}{\m}H = \D-J\,,\qquad \frac{1}{\bigl(\m\a'p^+\bigr)^2} = \frac{g^2_{\text{YM}}N}{J^2}\equiv \l'\,,\qquad
4\pi g_{\text{s}}\bigl(\m\a'p^+\bigr)^2 = \frac{J^2}{N}\equiv g_2
N\to\infty\quad\text{and}\quad J\to\infty\quad\text{with}\quad\frac{J^2}{N}\quad
\text{fixed}\,,\quad g_{\text{YM}}\quad\text{fixed}\,,
S_{\mbox{\scriptsize bos.}(r)}=\frac{e(\a_r)}{4\pi\a'}\int\,d\t\int_0^{2\pi|\a_r|}
\,d\s_r\bigl[\dot{x}_r^2-x^{\prime\,2}_r-\m^2x_r^2\bigr]\,,
\begin{split}
x_r^I(\s_r)& = x_{0(r)}^I+\sqrt{2}\sum_{n=1}^{\infty}
\bigl(x_{n(r)}^I\cos\frac{n\s_r}{|\a_r|}+x_{-n(r)}^I\sin\frac{n\s_r}{|\a_r|}\bigr)\,,\\
p_r^I(\s_r) & =\frac{1}{2\pi|\a_r|}\bigl[p_{0(r)}^I+\sqrt{2}\sum_{n=1}^{\infty}
\bigl(p_{n(r)}^I\cos\frac{n\s_r}{|\a_r|}+p_{-n(r)}^I\sin\frac{n\s_r}{|\a_r|}\bigr)\bigr]\,.
\label{xp}
x_{n(r)}^I=i\sqrt{\frac{\a'}{2\o_{n(r)}}}\bigl(a_{n(r)}^I-a_{n(r)}^{I\,\dag}\bigr)\,,\qquad
p_{n(r)}^I=\sqrt{\frac{\o_{n(r)}}{2\a'}}\bigl(a_{n(r)}^I+a_{n(r)}^{I\,\dag}\bigr)\,.
=i\d^{IJ}\d_{rs}\d(\s_r-\s_s)\qquad\lr\qquad [a_{n(r)}^I,a_{m(s)}^{J\,\dag}]=\d^{IJ}\d_{nm}\d_{rs}\,.
S_{\mbox{\scriptsize ferm.}(r)}=\frac{1}{8\pi}\int\,d\t\int_0^{2\pi|\a_r|}\,d\s_r
[i(\bar{\vt}_r\dot{\vt}_r+\vt_r\dot{\bar{\vt}}_r)
-\vt_r\vt'_r+\bar{\vt}_r\bar{\vt}'_r-2\m\bar{\vt}_r\Pi\vt_r]\,,
\begin{split}
\vt^a_r(\s_r) & =\vt^a_{0(r)}+\sqrt{2}\sum_{n=1}^{\infty}
\bigl(\vt^a_{n(r)}\cos\frac{n\s_r}{|\a_r|}+\vt^a_{-n(r)}\sin\frac{n\s_r}{|\a_r|}\bigr)\,,\\
\l^a_r(\s_r) & =\frac{1}{2\pi|\a_r|}\bigl[\l^a_{0(r)}+\sqrt{2}\sum_{n=1}^{\infty}
\bigl(\l^a_{n(r)}\cos\frac{n\s_r}{|\a_r|}+\l^a_{-n(r)}\sin\frac{n\s_r}{|\a_r|}\bigr)\bigr]\,.
\{\vt^a_r(\s_r),\l^b_s(\s_s)\}=\d^{ab}\d_{rs}\d(\s_r-\s_s)\qquad\lr\qquad\{\vt^a_{n(r)},\l^b_{m(s)}\}=\d^{ab}\d_{nm}\d_{rs}\,.
\vt_{n(r)}=\frac{c_{n(r)}}{\sqrt{|\a_r|}}\left[(1+\r_{n(r)}\Pi)b_{n(r)}
+e(\a_rn)(1-\r_{n(r)}\Pi)b_{-n(r)}^{\dag}\right]\,,\qquad n\in\Zop\,,
\r_{n(r)}=\r_{-n(r)}=\frac{\o_{n(r)}-|n|}{\m\a_r}\,,\qquad
c_{n(r)}=c_{-n(r)}=\frac{1}{\sqrt{1+\r_{n(r)}^2}}\,.
\{b^a_{n(r)},b^{b\,\dag}_{m(s)}\}=\d^{ab}\d_{nm}\d_{rs}\,.
\Pi =
\begin{pmatrix}
\d_{\a_1}^{\b_1}\d_{\a_2}^{\b_2} & 0 \\ 0 & -\d^{\da_1}_{\db_1}\d^{\da_2}_{\db_2}
\{b_{n(r)\,\a_1\a_2},b^{\b_1\b_2\,\dag}_{m(s)}\}=\d_{\a_1}^{\b_1}\d_{\a_2}^{\b_2}\d_{nm}\d_{rs}\,,\qquad
\{b_{n(r)\,\da_1\da_2},b^{\db_1\db_2\,\dag}_{m(s)}\}=\d_{\da_1}^{\db_1}\d_{\da_2}^{\db_2}\d_{nm}\d_{rs}\,.
H_{2(r)}=\frac{1}{\a_r}\sum_{n\in\Zop}\o_{n(r)}\bigl(a_{n(r)}^{I\,\dag}a_{n(r)}^I
+b^{\a_1\a_2\,\dag}_{n(r)}b_{n(r)\,\a_1\a_2}+b^{\da_1\da_2\,\dag}_{n(r)}b_{n(r)\,\da_1\da_2}\bigr)\,.
a_{n(r)}|v\ra_r=0\,,\qquad b_{n(r)}|v\ra_r=0\,,\quad n\in\Nop\,.
\label{comm}
\begin{split}
[H,P^I] &= -i\m^2J^{+I}\,,\qquad [H,Q^+]=-\m\Pi Q^+\,,\\
\{Q^-_{\da},\bar{Q}^-_{\db}\} &=
2\d_{\dot{a}\dot{b}}H-i\m\bigl(\g_{ij}\Pi\bigr)_{\dot{a}\dot{b}}J^{ij}+i\m\bigl(\g_{i'j'}\Pi\bigr)_{\dot{a}\dot{b}}J^{i'j'}\,.
\label{q-mode}
\begin{split}
Q^-_{(r)} & =\frac{e(\a_r)}{\sqrt{|\a_r|}}\g
\Bigl(\sqrt{\m}\left[a_{0(r)}(1+e(\a_r)\Pi)+a_{0(r)}^{\dag}(1-e(\a_r)\Pi)\right]\l_{0(r)}\\
&+\sum_{n\neq 0}\sqrt{|n|}\left[a_{n(r)}P_{n(r)}^{-1}b_{n(r)}^{\dag}
+e(\a_r)e(n)a_{n(r)}^{\dag}P_{n(r)}b_{-n(r)}\right]\Bigr)\,,
P_{n(r)}\equiv\frac{1-\r_{n(r)}\Pi}{\sqrt{1-\r_{n(r)}^2}}
=\frac{1+\Pi}{2}U_{|n|(r)}^{1/2}+\frac{1-\Pi}{2}U_{|n|(r)}^{-1/2}\,,\qquad
U_{n(r)}\equiv\frac{\o_{n(r)}-\m\a_r}{n}\,.
\label{hexp}
H=H_2+g_{\text{s}}H_3+\cdots\,,
= -i\m^2J^{+I}\quad\Longrightarrow\quad[H_3,P^I]=0\,,
\label{q+}
[H,Q^+]=-\m\Pi Q^+\quad\Longrightarrow\quad[H_3,Q^+]=0\,,
|V\ra\equiv|E_a\ra|E_b\ra\d\bigl(\sum_{r=1}^3\a_r\bigr)\,,
\label{bv}
|E_a\ra = \exp\left(\frac{1}{2}
\sum_{r,s=1}^3\sum_{m,n\in\Zop}a^{I\,\dag}_{m(r)}\bar{N}^{rs}_{mn}a^{I\,\dag}_{n(s)}
\right)|v\ra_{123}\,,
\label{eb2}
|E_b\ra=\exp\left(
\sum_{r,s=1}^3\sum_{m,n\ge0}
\bigl(b^{\a_1\a_2\,\dag}_{-m(r)}b^{\dag}_{n(s)\,\a_1\a_2}+b^{\da_1\da_2\,\dag}_{m(r)}b^{\dag}_{-n(s)\,\da_1\da_2}\bigr)
\bar{Q}^{rs}_{mn}\right)|v\ra_{123}\,,
\sqrt{2}\eta\,Q\equiv Q^-+i\bar{Q}^-\,,\qquad\text{and}\qquad
\sqrt{2}\bar{\eta}\,\wt{Q}=Q^--i\bar{Q}^-
\{Q_{\dot{a}},\wt{Q}_{\dot{b}}\}=0\,,\quad
\{Q_{\dot{a}},Q_{\dot{b}}\}=\{\wt{Q}_{\dot{a}},\wt{Q}_{\dot{b}}\}
=2\d_{\dot{a}\dot{b}}H-i\m\bigl(\g_{ij}\Pi\bigr)_{\dot{a}\dot{b}}J^{ij}+i\m\bigl(\g_{i'j'}\Pi\bigr)_{\dot{a}\dot{b}}J^{i'j'}\,.
K^I \equiv \sum_{r=1}^3\sum_{n\in\Zop}K_{n(r)}a_{n(r)}^{I\,\dag}\,,\qquad
\K^I \equiv \sum_{r=1}^3\sum_{n\in\Zop}\K_{n(r)}a_{n(r)}^{I\,\dag}\,,
K_{n(r)} \equiv (1-4\m\a K)^{1/2}\begin{cases} F_{0(r)}\,, & n=0 \\
F_{n(r)}\,, & n>0 \\
iU_{n(r)}F_{n(r)}\,, & n<0
\label{Y}
Y^{\a_1\a_2} = \sum_{r=1}^3\sum_{n\ge 0}\bar{G}_{n(r)}b_{n(r)}^{\dag\,\a_1\a_2}\,,\qquad
Z^{\da_1\da_2} = \sum_{r=1}^3\sum_{n\ge 0}\bar{G}_{n(r)}b_{-n(r)}^{\dag\,\da_1\da_2}\,,
\label{G}
\bar{G}_{(r)} =
\sqrt{-\frac{\a'}{\a}}(1-4\m\a K)^{1/2}\sqrt{|\a_r|}U_{(r)}^{1/2}C^{-1/2}F_{(r)}\,,
\label{qy}
\begin{split}
\eta\sqrt{\frac{-2\a}{\a'}}\sum_{r=1}^3\{Q_{(r)},Y+iZ\} & = i\g^IK^I\,,\\
\bar{\eta}\sqrt{\frac{-2\a}{\a'}}\sum_{r=1}^3\{\wt{Q}_{(r)},Y-iZ\} & = -i\g^I\wt{K}^I\,.
^I\equiv\sum_{r=1}^3\sum_{n\in\Zop}K^*_{n(r)}a_{n(r)}^{I\,\dag} = \K^I,\quad
Y^*\equiv\sum_{r=1}^3\sum_{n\ge 0}\bar{G}^*_{n(r)}b_{n(r)}^{\dag}=Y,\quad
Z^*\equiv\sum_{r=1}^3\sum_{n\ge 0}\bar{G}^*_{n(r)}b_{-n(r)}^{\dag} = Z,
\label{ansatz1}
|Q_{3\,\b_1\db_2}\ra =
\bigl(f^i_{\b_1\db_2}(Y,Z)\K^i+g^{i'}_{\b_1\db_2}(Y,Z)\K^{i'}\bigr)|V\ra\,,
\label{y2}
Y^2_{\a_1\b_1} \equiv Y_{\a_1\a_2}Y^{\a_2}_{\b_1}\,,\qquad Y^2_{\a_2\b_2} \equiv Y_{\a_1\a_2}Y^{\a_1}_{\b_2}\,,
\label{y3}
Y^3_{\a_1\b_2} \equiv Y^2_{\a_1\b_1}Y^{\b_1}_{\b_2}=-Y^2_{\b_2\a_2}Y^{\a_2}_{\a_1}\,,
Y^4_{\a_1\b_1} \equiv Y^2_{\a_1\g_1}{Y^2}^{\g_1}_{\b_1}=-\frac{1}{2}\e_{\a_1\b_1}Y^4\,,\qquad
Y^4_{\a_2\b_2} \equiv Y^2_{\a_2\g_2}{Y^2}^{\g_2}_{\b_2}=\frac{1}{2}\e_{\a_2\b_2}Y^4\,,
\label{y4}
Y^4 \equiv Y^2_{\a_1\b_1}{Y^2}^{\a_1\b_1}=-Y^2_{\a_2\b_2}{Y^2}^{\a_2\b_2}\,.
\bar{\eta}\sqrt{\frac{\a'}{-2\a}}|Q_{3\,\b_1\db_2}\ra =
\Bigl(s_{\dg_1\db_2}(Z)t_{\b_1\g_1}(Y)\K^{\dg_1\g_1}+is_{\b_1\g_2}(Y)t^*_{\db_2\dg_2}(Z)\K^{\dg_2\g_2}\Bigr)|V\ra\,,
-\eta\sqrt{\frac{\a'}{-2\a}}|Q_{3\,\db_1\b_2}\ra =
\Bigl(s^*_{\g_1\b_2}(Y)t^*_{\db_1\dg_1}(Z)\K^{\dg_1\g_1}+is^*_{\db_1\dg_2}(Z)t_{\b_2\g_2}(Y)\K^{\dg_2\g_2}\Bigr)|V\ra\,.
\K^{\dg_1\g_1} \equiv \K^i{\s^i}^{\dg_1\g_1}\,,\qquad
\K^{\dg_2\g_2} \equiv \K^{i'}{\s^{i'}}^{\dg_2\g_2}\,,
s(Y) \equiv Y+\frac{i}{3}Y^3\,,\qquad t(Y) \equiv \e+iY^2-\frac{1}{6}Y^4\,.
^{ij} \equiv \s^{ij}_{\a_1\b_1}{Y^2}^{\a_1\b_1}\,,\quad
{Z^2}^{ij} \equiv \s^{ij}_{\da_1\db_1}{Z^2}^{\da_1\db_1}\,,\quad
\bigl(Y^2Z^2\bigr)^{ij} \equiv {Y^2}^{k(i}{Z^2}^{j)k}
\label{nij}
|n\ra\equiv\a^{I\,\dag}_{n(3)}\a^{J\,\dag}_{-n(3)}|v\ra_3\,.
\label{de1}
\d E_n^{(2)}\la n|n\ra = g_2^2\sum_{1,2}
\frac{1}{2}\frac{\left|\la n|H_3|1,2\ra\right|^2}{E_n^{(0)}-E_{1,2}^{(0)}}
-\frac{g_2^2}{4}\la n|Q_{3\,\b_1\db_1}Q_3^{\b_1\db_1}|n\ra\,.
\label{tr}
x^+ \to -x^+\,,\qquad x^- \to - x^-\,,\qquad \m \to -\m\,,
\m \to -\m\,,\qquad \Pi \to -\Pi
\label{de2}
{\mc N}\d E_n^{(2)}=-g_2^2\int_{-1}^0\frac{d\b}{\b(\b+1)}
\sum_{\text{modes}}\left[
\frac{1}{2}\frac{\left|\la n|H_3|1,2\ra\right|^2}{E_n^{(0)}-E_{1,2}^{(0)}}
-\frac{1}{4}\la n|Q_{3\,\b_1\db_1}|1,2\ra\la 1,2|Q_3^{\b_1\db_1}|n\ra\right]\,.
\begin{split}
\la n|H_3|\a_{0(r)}^{\dag\,k}\a_{0(s)}^{\dag\,l}|v\ra_{12}& \sim
\m\l'\frac{\sin^2 n\pi\b}{2\pi^2}\left(\d^{rs}+\frac{\sqrt{\a_r\a_s}}{\a_3}\right)S^{ijkl}\,,\\
\la n|H_3|\a_{k(r)}^{\dag\,k}\a_{-k(r)}^{\dag\,l}|v\ra_{12} & \sim
\m\l'\b(\b+1)\frac{\a_3}{\a_r}\frac{\sin^2 n\pi\b}{2\pi^2}S^{ijkl}\,,
S^{ijkl}\equiv T^{ijkl}+\frac{1}{4}\d^{ij}T^{kl}\,,\quad
T^{ijkl}=\d^{ik}\d^{jl}+\d^{jk}\d^{il}-\frac{1}{2}\d^{ij}\d^{kl}\,,\quad
T^{kl} = -2\d^{kl}
\frac{\m g_2^2\l'}{4\pi^2}\frac{15}{64\pi^2n^2}\sum_{k,l}S^{ijkl}S^{ijkl}=
\frac{\m g_2^2\l'}{4\pi^2}\frac{15}{16\pi^2n^2}\Bigl[\frac{1}{2}\bigl(1+\frac{1}{2}\d^{ij}\bigr)+\frac{1}{4}\d^{ij}\Bigr]\,.
\label{9-1}
\frac{\m g_2^2\l'}{4\pi^2}\frac{15}{16\pi^2n^2}\,.
-\pi\a'\m^2\la n|K^M\K^N|E_a\ra
\sim\frac{\m\sqrt{\l'}}{2\pi}\b(\b+1)\sin^2n\pi\b\left(\d^{MI}\d^{NJ}+\d^{NI}\d^{MJ}\right)\,.
-{}_{123}\la v|b_{k(r)\,\a_1\a_2}b_{-k(s)\,\da_1\da_2}Y^{\g_1\g_2}Z^{\dg_1\dg_2}|E_b\ra
=\d_{\a_1}^{\g_1}\d_{\a_2}^{\g_2}\d_{\da_1}^{\dg_1}\d_{\da_2}^{\dg_2}
\bar{G}_{k(r)}\bar{G}_{k(s)}\,.
\frac{\m g_2^2\l'}{4\pi^2}\frac{3}{8\pi^2 n^2}
-\frac{\m g_2^2\l'}{4n\pi^3}\int_{-1}^0 d\b\,\sin^4n\pi\b\cot n\pi\b(\b+1)
=\frac{\m g_2^2\l'}{4\pi^2}\frac{15}{16\pi^2 n^2}\frac{1}{2}\,,
\eta|Q_{3\,\b_1\db_2}\ra \sim
-\sqrt{-\frac{\a'}{8\a_3^3}}\sqrt{-\b(\b+1)}\bigl(Y_{\b_1\g_2}\K^{\g_2}_{\db_1}-iZ_{\dg_1\b_2}\K^{\dg_1}_{\b_1}\bigr)|E_a\ra|E_b\ra\,,
\frac{1}{2}\frac{\m g_2^2\l'}{4\pi^2}\left(\frac{1}{12}+\frac{35}{32n^2\pi^2}\right)\,,
\frac{\m g_2^2\l'}{4\pi^2}\left(\frac{1}{12}+\frac{5}{32n^2\pi^2}\right)
\Bigl[\frac{1}{2}\bigl(1+\frac{1}{2}\d^{ij}\bigr)+\frac{1}{4}\d^{ij}\Bigr]\,,
\d E_n^{(2)}=\frac{\m g_2^2\l'}{4\pi^2}\left(\frac{1}{12}+\frac{35}{32n^2\pi^2}\right)\,.
_v \longrightarrow ({\bf 4},{\bf 1})\oplus ({\bf 1},{\bf 4})\,,\qquad
{\bf 8}_s \longrightarrow ({\bf 2},{\bf 2}) \oplus ({\bf 2'},{\bf 2'})\,,\qquad
{\bf 8}_c \longrightarrow ({\bf 2},{\bf 2'}) \oplus ({\bf 2'},{\bf 2})\,,
\s^i_{\a\da}=\bigl(i\t^1,i\t^2,i\t^3,-1\bigr)_{\a\da}
\s^i_{\a\da} = \e_{\a\b}\e_{\da\db}{\s^i}^{\db\b}
\equiv \e_{\a\b}{\s^i}^{\b}_{\da} \equiv \e_{\da\db}{\s^i}^{\db}_{\a}\,.
\s^i_{\a\da}{\s^j}^{\da\b}+\s^j_{\a\da}{\s^i}^{\da\b}
=2\d^{ij}\d_{\a}^{\b}\,,\qquad
{\s^i}^{\da\a}\s^j_{\a\db}+{\s^j}^{\da\a}\s^i_{\a\db}=
2\d^{ij}\d^{\da}_{\db}\,.
\Pi_{ab} =
\begin{pmatrix} \bigl(\s^1\s^2\s^3\s^4\bigr)_{\a_1}^{\b_1}\d_{\a_2}^{\b_2} & 0 \\
0 & \bigl(\s^1\s^2\s^3\s^4\bigr)^{\da_1}_{\db_1}\d^{\da_2}_{\db_2}
\label{1Y234}
\begin{split}
\sum_r[Q_{(r)\,\a_1\da_2},Y^2_{\b_1\g_1}] & =
-i\bigl(\e_{\a_1\b_1}Y_{\g_1\g_2}+\e_{\a_1\g_1}Y_{\b_1\g_2}\bigr)K^{\g_2}_{\da_2}\,,\\
\sum_r[Q_{(r)\,\a_1\da_2},Y^2_{\b_2\g_2}] & =
i\bigl(Y_{\a_1\b_2}K_{\g_2\da_2}+Y_{\a_1\g_2}K_{\b_2\da_2}\bigr)\,,\\
\sum_r\{Q_{(r)\,\a_1\da_2},Y^3_{\b_1\g_2}\} & =
3iY_{\a_1\g_2}Y_{\b_1\d_2}K^{\d_2}_{\da_2}\,,\\
\sum_r[Q_{(r)\,\a_1\da_2},Y^4] & =
4iY^3_{\a_1\a_2}K^{\a_2}_{\da_2}\,,
\label{2Y234}
\begin{split}
\sum_r[Q_{(r)\,\db_1\b_2},Y^2_{\a_1\g_1}] & =
-i\bigl(Y_{\g_1\b_2}K_{\a_1\db_1}+Y_{\a_1\b_2}K_{\g_1\db_1}\bigr)\,,\\
\sum_r[Q_{(r)\,\db_1\b_2},Y^2_{\a_2\g_2}] & =
-i\bigl(\e_{\a_2\b_2}Y_{\g_1\g_2}+\e_{\g_2\b_2}Y_{\g_1\a_2}\bigr)K^{\g_1}_{\db_1}\,,\\
\sum_r\{Q_{(r)\,\db_1\b_2},Y^3_{\a_1\g_2}\} & =
3iY_{\a_1\b_2}Y_{\g_1\g_2}K^{\g_1}_{\db_1}\,,\\
\sum_r[Q_{(r)\,\db_1\b_2},Y^4] & =
-4iY^3_{\a_1\b_2}K^{\a_1}_{\db_1}\,,
\label{1Z234}
\begin{split}
\sum_r[Q_{(r)\,\a_1\da_2},Z^2_{\db_1\dg_1}] & =
K_{\a_1\db_1}Z_{\dg_1\da_2}+K_{\a_1\dg_1}Z_{\db_1\da_2}\,,\\
\sum_r[Q_{(r)\,\a_1\da_2},Z^2_{\db_2\dg_2}] & =
-\bigl(\e_{\da_2\db_2}Z_{\dg_1\dg_2}+\e_{\da_2\dg_2}Z_{\dg_1\db_2}\bigr)K_{\a_1}^{\dg_1}\,,\\
\sum_r\{Q_{(r)\,\a_1\da_2},Z^3_{\db_1\dg_2}\} & =
-3Z_{\db_1\da_2}Z_{\dg_1\dg_2}K^{\dg_1}_{\a_1}\,,\\
\sum_r[Q_{(r)\,\a_1\da_2},Z^4] & =
4Z^3_{\da_1\da_2}K^{\da_1}_{\a_1}\,,
\label{2Z234}
\begin{split}
\sum_r[Q_{(r)\,\db_1\b_2},Z^2_{\da_1\dg_1}] & =
-\bigl(\e_{\db_1\da_1}Z_{\dg_1\dg_2}+\e_{\db_1\dg_1}Z_{\da_1\dg_2}\bigr)K_{\b_2}^{\dg_2}\,,\\
\sum_r[Q_{(r)\,\db_1\b_2},Z^2_{\da_2\dg_2}] & =
K_{\b_2\da_2}Z_{\db_1\dg_2}+K_{\b_2\dg_2}Z_{\db_1\da_2}\,,\\
\sum_r\{Q_{(r)\,\db_1\b_2},Z^3_{\da_1\dg_2}\} & =
3Z_{\db_1\dg_2}Z_{\da_1\dd_2}K^{\dd_2}_{\b_2}\,,\\
\sum_r[Q_{(r)\,\db_1\b_2},Z^4] & =
4Z^3_{\db_1\dg_2}K^{\dg_2}_{\b_2}\,.
-4\frac{\m\a}{\a'}\e_{\a_1\b_1}\e_{\da_2\db_2}
\Bigl(a_{3,0}Y^4+ia_{0,3}Z^4+(a_{3,4}+ia_{4,3})Y^4Z^4\Bigr)\,,\quad
\text{and}\quad a_{2,1}=ia_{1,2}\,.
2Y_{[\a_1\g_2}K^{\dg_1}_{\b_1]} = \e_{\a_1\b_1}Y^{\g_1}_{\g_2}K^{\dg_1}_{\g_1}\,,
\label{trick}
\begin{pmatrix} b_{n(r)} \\ b_{-n(r)}
\begin{split}
\sum_r[Q_{(r)\,\a_1\da_2},K_{\b_1\db_1}] & =
-4\frac{\a}{\a'}\e_{\b_1\a_1}\bigl(\p_{\t}+\p_{\s}\bigr)Z_{\db_1\da_2}\,,\\
\sum_r[Q_{(r)\,\da_1\a_2},K_{\b_1\db_1}] & =
-4i\frac{\a}{\a'}\e_{\db_1\da_1}\bigl(\p_{\t}+\p_{\s}\bigr)Y_{\b_1\a_2}\,,
\begin{split}
\sum_r[Q_{(r)\,\a_1\da_2},K_{\b_2\db_2}] & =
-4i\frac{\a}{\a'}\e_{\da_2\db_2}\bigl(\p_{\t}+\p_{\s}\bigr)Y_{\a_1\b_2}\,,\\
\sum_r[Q_{(r)\,\da_1\a_2},K_{\b_2\db_2}] & =
4\frac{\a}{\a'}\e_{\a_2\b_2}\bigl(\p_{\t}+\p_{\s}\bigr)Z_{\da_1\db_2}\,,
\label{dV}
\p_{\s}|V\ra = -\frac{i}{4}
\left[\frac{\a'}{\a}\bigl(K^IK^I-\K^I\K^I\bigr)-
4\bigl(Y_{\a_1\a_2}\p_{\t}Y^{\a_1\a_2}-Z_{\da_1\da_2}\p_{\t}Z^{\da_1\da_2}\bigr)\right]|V\ra\,.
\lim_{\s\to\pi\a_1}Y(\s)|V\ra = Y|V\ra\,,\qquad \lim_{\s\to\pi\a_1}Z(\s)|V\ra = Z|V\ra\,.
\lim_{\s\to\pi\a_1}Y(\s)|V\ra = f(\m)(1-4\m\a K)^{-1/2}Y|V\ra\,,
f(\m)\equiv-2\frac{\sqrt{-\a}}{\a_1}\lim_{e\to0}\e^{1/2}
\sum_{n=1}^{\infty}(-1)^nn\cos(n\e/\a_1)\bar{N}^1_n=(1-4\m\a K)^{1/2}.
```python
```
|
y = 17;
x = (y + 3) / 2); |
-- Previously this gave an 'unreachable case warning' and evaluated
-- to the first case! Should give foo : Nat -> Nat
foo : (x : Nat) -> case S x of
Z => Nat -> Nat
(S k) => Nat
|
From Categories Require Import Essentials.Notations.
From Categories Require Import Essentials.Types.
From Categories Require Import Essentials.Facts_Tactics.
From Categories Require Import Category.Main.
From Categories Require Import Ext_Cons.Prod_Cat.Prod_Cat Ext_Cons.Prod_Cat.Nat_Facts
Ext_Cons.Prod_Cat.Operations.
From Categories Require Import Functor.Main.
From Categories Require Import Functor.Representable.Hom_Func
Functor.Representable.Hom_Func_Prop.
From Categories Require Import NatTrans.Main.
From Categories Require Import Adjunction.Adjunction Adjunction.Duality.
From Categories Require Import Cat.Cat Cat.Exponential Cat.Exponential_Facts.
From Categories Require Import Yoneda.Yoneda.
From Categories Require Import Functor.Functor_Extender.
Local Open Scope functor_scope.
Section Hom_Adjunct_left_iso.
Context {C D : Category}
{F F' : C ββ» D}
(N : (F' β F)%natiso)
{G : D ββ» C}
(adj : F β£_hom G)
.
(** If F β F' and (F β£_hom G) then (F' β£_hom G) *)
Definition Hom_Adjunct_left_iso : F' β£_hom G :=
(adj β ((NatTrans_id_Iso (Hom_Func D))
β_h (Prod_Functor_NatIso
(N^op) (NatTrans_id_Iso (Functor_id D))))
)%isomorphism%natiso.
End Hom_Adjunct_left_iso.
Section Hom_Adjunct_right_iso.
Context {C D : Category}
{F : C ββ» D}
{G G' : D ββ» C}
(N : (G β G')%natiso)
(adj : F β£_hom G)
.
(** If G β G' and (F β£_hom G) then (F β£_hom G') *)
Definition Hom_Adjunct_right_iso : F β£_hom G' :=
Hom_Adjunct_Duality
(Hom_Adjunct_left_iso
((N^op)β»ΒΉ)%isomorphism%natiso (Hom_Adjunct_Duality adj)).
End Hom_Adjunct_right_iso.
Section Adjunct_left_iso.
Context {C D : Category}
(F F' : C ββ» D)
(N : (F' β F)%natiso)
(G : D ββ» C)
(adj : F β£ G)
.
(** If F β F' and (F β£ G) then (F' β£ G) *)
Definition Adjunct_left_iso : F' β£ G :=
Hom_Adj_to_Adj (Hom_Adjunct_left_iso N (Adj_to_Hom_Adj adj)).
End Adjunct_left_iso.
Section Adjunct_right_iso.
Context {C D : Category}
(F : C ββ» D)
(G G' : D ββ» C)
(N : (G β G')%natiso)
(adj : F β£ G)
.
(** If G β G' and (F β£ G) then (F β£ G') *)
Definition Adjunct_right_iso : F β£ G' :=
Hom_Adj_to_Adj (Hom_Adjunct_right_iso N (Adj_to_Hom_Adj adj)).
End Adjunct_right_iso.
Section Hom_Adjunct_left_unique.
Context {C D : Category}
{F F' : C ββ» D}
{G : D ββ» C}
(adj : F β£_hom G)
(adj' : F' β£_hom G)
.
(** If F β£_hom G and F' β£_hom G then F β F' *)
Definition Hom_Adjunct_left_unique : (F β F')%natiso.
Proof.
apply (@Opposite_NatIso _ _ (F^op) (F'^op)).
eapply (Embedding_mono (Yoneda_Emb (D^op))).
eapply Isomorphism_Compose;
[eapply Inverse_Isomorphism; apply Exp_Cat_morph_ex_compose_Iso |].
eapply Isomorphism_Compose; [|apply Exp_Cat_morph_ex_compose_Iso].
apply Exp_Cat_morph_ex_Iso.
eapply Isomorphism_Compose.
apply adj.
eapply Inverse_Isomorphism.
apply adj'.
Defined.
End Hom_Adjunct_left_unique.
Section Hom_Adjunct_right_unique.
Context {C D : Category}
{F : C ββ» D}
{G G' : D ββ» C}
(adj : F β£_hom G)
(adj' : F β£_hom G')
.
(** If F β£_hom G and F β£_hom G' then G β G' *)
Theorem Hom_Adjunct_right_unique : (G β G')%natiso.
Proof.
apply Hom_Adjunct_Duality in adj.
apply Hom_Adjunct_Duality in adj'.
apply (@Opposite_NatIso _ _ (G^op) (G'^op)).
apply (Hom_Adjunct_left_unique adj adj').
Defined.
End Hom_Adjunct_right_unique.
Section Adjunct_left_unique.
Context {C D : Category}
{F F' : C ββ» D}
{G : D ββ» C}
(adj : F β£ G)
(adj' : F' β£ G)
.
(** If F β£ G and F' β£ G then F β F' *)
Theorem Adjunct_left_unique : (F β F' )%natiso.
Proof.
apply Adj_to_Hom_Adj in adj.
apply Adj_to_Hom_Adj in adj'.
eapply Hom_Adjunct_left_unique; eassumption.
Defined.
End Adjunct_left_unique.
Section Adjunct_right_unique.
Context {C D : Category}
{F : C ββ» D}
{G G' : D ββ» C}
(adj : F β£ G)
(adj' : F β£ G')
.
(** If F β£ G and F β£ G' then G β G' *)
Theorem Adjunct_right_unique : (G β G')%natiso.
Proof.
apply Adj_to_Hom_Adj in adj.
apply Adj_to_Hom_Adj in adj'.
eapply Hom_Adjunct_right_unique; eassumption.
Defined.
End Adjunct_right_unique.
(** If F β£_ucu G then
Hom_{Func_Cat B D}(Fα΅α΅ β β, β) β Hom_{Func_Cat B C}(β, G β β) *)
Section Hom_Adjunct_Lifted.
Context {C D : Category}
{F : C ββ» D}
{G : D ββ» C}
(adj : F β£_ucu G)
(B : Category)
.
Local Notation NID := NatTrans_id (only parsing).
Local Notation FCAT := Func_Cat (only parsing).
Local Notation LEFT :=
(
(Hom_Func (Func_Cat B D))
β (Prod_Functor
((Right_Functor_Extender F B)^op)
(Functor_id (Func_Cat B D))
)
)
(only parsing).
Local Notation RIGHT :=
(
(Hom_Func (Func_Cat B C))
β (Prod_Functor
(Functor_id ((Func_Cat B C)^op)%category)
(Right_Functor_Extender G B)
)
)
(only parsing).
Local Obligation Tactic := idtac.
Program Definition Hom_Adjunct_Lifted_LR : (LEFT ββ» RIGHT)%nattrans :=
{|
Trans := fun c h =>
((((NatTrans_id G) β_h h)
β ((NatTrans_Functor_assoc (fst c) F G)
β ((ucu_adj_unit adj) β_h (NatTrans_id (fst c)))))
β (NatTrans_to_compose_id _))%nattrans
|}.
Next Obligation.
intros [c1 c2] [c1' c2'] [h1 h2].
extensionality w.
apply NatTrans_eq_simplify.
extensionality x.
cbn in *.
repeat rewrite F_id; simpl_ids.
repeat rewrite F_compose.
repeat rewrite assoc.
cbn_rewrite (@Trans_com _ _ _ _ (ucu_adj_unit adj) _ _ (Trans h1 x)).
trivial.
Qed.
Next Obligation.
symmetry.
apply Hom_Adjunct_Lifted_LR_obligation_1.
Qed.
Program Definition Hom_Adjunct_Lifted_RL : (RIGHT ββ» LEFT)%nattrans :=
{|
Trans := fun c h =>
((NatTrans_from_compose_id _)
β ((((ucu_adj_counit adj)
β_h (NatTrans_id (snd c)))
β (NatTrans_Functor_assoc_sym (snd c) G F))
β ((NatTrans_id F) β_h h)))%nattrans
|}.
Next Obligation.
intros [c1 c2] [c1' c2'] [h1 h2].
extensionality w.
apply NatTrans_eq_simplify.
extensionality x.
cbn in *.
repeat rewrite F_id; simpl_ids.
repeat rewrite F_compose.
repeat rewrite assoc_sym.
cbn_rewrite (@Trans_com _ _ _ _ (ucu_adj_counit adj) _ _ (Trans h2 x)).
trivial.
Qed.
Next Obligation.
symmetry.
apply Hom_Adjunct_Lifted_RL_obligation_1.
Qed.
Program Definition Hom_Adjunct_Lifted : (LEFT β RIGHT)%natiso :=
{|
iso_morphism := Hom_Adjunct_Lifted_LR;
inverse_morphism := Hom_Adjunct_Lifted_RL
|}.
Next Obligation.
Proof.
apply NatTrans_eq_simplify;
extensionality c; extensionality h.
destruct c as [c1 c2].
apply NatTrans_eq_simplify; extensionality y.
cbn in *.
repeat rewrite F_id.
simpl_ids.
rewrite F_compose.
rewrite assoc_sym.
cbn_rewrite (Trans_com (ucu_adj_counit adj) (Trans h y)).
rewrite assoc.
simpl_ids; trivial.
set (W := f_equal (fun w => Trans w (c1 _o y)) (ucu_adj_left_id adj));
cbn in W; simpl_ids in W; apply W.
Qed.
Next Obligation.
Proof.
apply NatTrans_eq_simplify;
extensionality c; extensionality h.
destruct c as [c1 c2].
apply NatTrans_eq_simplify; extensionality y.
cbn in *.
repeat rewrite F_id.
simpl_ids.
rewrite F_compose.
rewrite assoc.
cbn_rewrite <- (Trans_com (ucu_adj_unit adj) (Trans h y)).
rewrite assoc_sym.
simpl_ids; trivial.
set (W := f_equal (fun w => Trans w (c2 _o y)) (ucu_adj_right_id adj));
cbn in W;
repeat rewrite F_compose in W; repeat rewrite F_id in W; simpl_ids in W;
apply W.
Qed.
End Hom_Adjunct_Lifted.
|
(* Note: n is a parameter, not an index *)
Inductive MemoryBank: nat -> Set :=
| Bit: bool -> MemoryBank 1
| Combine: forall n, MemoryBank n -> MemoryBank n -> MemoryBank (S n).
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.