Datasets:
AI4M
/

text
stringlengths
0
3.34M
lemma continuous_on_empty [simp]: "continuous_on {} f"
### Notation # small letters => vectors # capital letters => matrices function build_A(k, u, η, D, y, params) N = params.Ny g = params.g k2 = k^2 ik = 1im*k # This removed the free-surface deformation in the basic state, # which is more like what is done in the Hydrostatic case h = 0*η .+ params.H U = diagm(0 => u) H = diagm(0 => h) dU = diagm(0 => D*u) dH = diagm(0 => D*h) F = diagm(0 => params.f₀ .+ 0*y) I = diagm(0 => ones(N+1)) # Form 1L-RSW Matrix # [u1, v1, h1] A = [ k*U 1im*(F-dU)[:, 2:N] g*k*I; -1im*F[2:N,:] k*U[2:N,2:N] -1im*g*D[2:N,:]; k*H -1im*D*H[:, 2:N] k*U]; return A end
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata ! This file was ported from Lean 3 source module algebraic_geometry.elliptic_curve.point ! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.AlgebraicGeometry.EllipticCurve.Weierstrass import Mathbin.FieldTheory.Galois import Mathbin.RingTheory.ClassGroup /-! # The group of nonsingular rational points on a Weierstrass curve over a field This file defines the type of nonsingular rational points on a Weierstrass curve over a field and (TODO) proves that it forms an abelian group under a geometric secant-and-tangent process. ## Mathematical background Let `W` be a Weierstrass curve over a field `F`. A rational point on `W` is simply a point $[A:B:C]$ defined over `F` in the projective plane satisfying the homogeneous cubic equation $B^2C + a_1ABC + a_3BC^2 = A^3 + a_2A^2C + a_4AC^2 + a_6C^3$. Any such point either lies in the affine chart $C \ne 0$ and satisfies the Weierstrass equation obtained by setting $X := A/C$ and $Y := B/C$, or is the unique point at infinity $0 := [0:1:0]$ when $C = 0$. With this new description, a nonsingular rational point on `W` is either $0$ or an affine point $(x, y)$ where the partial derivatives $W_X(X, Y)$ and $W_Y(X, Y)$ do not vanish simultaneously. For a field extension `K` of `F`, a `K`-rational point is simply a rational point on `W` base changed to `K`. The set of nonsingular rational points forms an abelian group under a secant-and-tangent process. * The identity rational point is `0`. * Given a nonsingular rational point `P`, its negation `-P` is defined to be the unique third point of intersection between `W` and the line through `0` and `P`. Explicitly, if `P` is $(x, y)$, then `-P` is $(x, -y - a_1x - a_3)$. * Given two points `P` and `Q`, their addition `P + Q` is defined to be the negation of the unique third point of intersection between `W` and the line `L` through `P` and `Q`. Explicitly, let `P` be $(x_1, y_1)$ and let `Q` be $(x_2, y_2)$. * If $x_1 = x_2$ and $y_1 = -y_2 - a_1x_2 - a_3$, then `L` is vertical and `P + Q` is `0`. * If $x_1 = x_2$ and $y_1 \ne -y_2 - a_1x_2 - a_3$, then `L` is the tangent of `W` at `P = Q`, and has slope $\ell := (3x_1^2 + 2a_2x_1 + a_4 - a_1y_1) / (2y_1 + a_1x_1 + a_3)$. * Otherwise $x_1 \ne x_2$, then `L` is the secant of `W` through `P` and `Q`, and has slope $\ell := (y_1 - y_2) / (x_1 - x_2)$. In the latter two cases, the $X$-coordinate of `P + Q` is then the unique third solution of the equation obtained by substituting the line $Y = \ell(X - x_1) + y_1$ into the Weierstrass equation, and can be written down explicitly as $x := \ell^2 + a_1\ell - a_2 - x_1 - x_2$ by inspecting the $X^2$ terms. The $Y$-coordinate of `P + Q`, after applying the final negation that maps $Y$ to $-Y - a_1X - a_3$, is precisely $y := -(\ell(x - x_1) + y_1) - a_1x - a_3$. The group law on this set is then uniquely determined by these constructions. ## Main definitions * `weierstrass_curve.point`: the type of nonsingular rational points on a Weierstrass curve `W`. * `weierstrass_curve.point.add`: the addition of two nonsingular rational points on `W`. ## Main statements * TODO: the addition of two nonsingular rational points on `W` forms a group. ## Notations * `W⟮K⟯`: the group of nonsingular rational points on a Weierstrass curve `W` base changed to `K`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, rational point, group law -/ /- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/ -- temporary import to enable point notation -- temporary import to enable point notation private unsafe def map_simp : tactic Unit := sorry #align map_simp map_simp /- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/ private unsafe def eval_simp : tactic Unit := sorry #align eval_simp eval_simp /- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/ private unsafe def C_simp : tactic Unit := sorry #align C_simp C_simp /- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/ private unsafe def derivative_simp : tactic Unit := sorry #align derivative_simp derivative_simp universe u v w namespace WeierstrassCurve open Polynomial open Polynomial PolynomialPolynomial section Basic /-! ### Polynomials associated to nonsingular rational points on a Weierstrass curve -/ variable {R : Type u} [CommRing R] (W : WeierstrassCurve R) (A : Type v) [CommRing A] [Algebra R A] (B : Type w) [CommRing B] [Algebra R B] [Algebra A B] [IsScalarTower R A B] (x₁ x₂ y₁ y₂ L : R) /-- The polynomial $-Y - a_1X - a_3$ associated to negation. -/ noncomputable def negPolynomial : R[X][Y] := -Y - C (C W.a₁ * X + C W.a₃) #align weierstrass_curve.neg_polynomial WeierstrassCurve.negPolynomial /-- The $Y$-coordinate of the negation of an affine point in `W`. This depends on `W`, and has argument order: $x_1$, $y_1$. -/ @[simp] def negY : R := -y₁ - W.a₁ * x₁ - W.a₃ #align weierstrass_curve.neg_Y WeierstrassCurve.negY theorem negY_negY : W.negY x₁ (W.negY x₁ y₁) = y₁ := by simp only [neg_Y] ring1 #align weierstrass_curve.neg_Y_neg_Y WeierstrassCurve.negY_negY /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.2137773769.map_simp -/ theorem baseChange_negY : (W.base_change A).negY (algebraMap R A x₁) (algebraMap R A y₁) = algebraMap R A (W.negY x₁ y₁) := by simp only [neg_Y] run_tac map_simp rfl #align weierstrass_curve.base_change_neg_Y WeierstrassCurve.baseChange_negY theorem baseChange_negY_of_baseChange (x₁ y₁ : A) : (W.base_change B).negY (algebraMap A B x₁) (algebraMap A B y₁) = algebraMap A B ((W.base_change A).negY x₁ y₁) := by rw [← base_change_neg_Y, base_change_base_change] #align weierstrass_curve.base_change_neg_Y_of_base_change WeierstrassCurve.baseChange_negY_of_baseChange /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ @[simp] theorem eval_negPolynomial : (W.negPolynomial.eval <| C y₁).eval x₁ = W.negY x₁ y₁ := by rw [neg_Y, sub_sub, neg_polynomial] run_tac eval_simp #align weierstrass_curve.eval_neg_polynomial WeierstrassCurve.eval_negPolynomial /-- The polynomial $L(X - x_1) + y_1$ associated to the line $Y = L(X - x_1) + y_1$, with a slope of $L$ that passes through an affine point $(x_1, y_1)$. This does not depend on `W`, and has argument order: $x_1$, $y_1$, $L$. -/ noncomputable def linePolynomial : R[X] := C L * (X - C x₁) + C y₁ #align weierstrass_curve.line_polynomial WeierstrassCurve.linePolynomial /-- The polynomial obtained by substituting the line $Y = L(X - x_1) + y_1$, with a slope of $L$ that passes through an affine point $(x_1, y_1)$, into the polynomial $W(X, Y)$ associated to `W`. If such a line intersects `W` at another point $(x_2, y_2)$, then the roots of this polynomial are precisely $x_1$, $x_2$, and the $X$-coordinate of the addition of $(x_1, y_1)$ and $(x_2, y_2)$. This depends on `W`, and has argument order: $x_1$, $y_1$, $L$. -/ noncomputable def addPolynomial : R[X] := W.Polynomial.eval <| linePolynomial x₁ y₁ L #align weierstrass_curve.add_polynomial WeierstrassCurve.addPolynomial /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.4157056569.C_simp -/ theorem addPolynomial_eq : W.addPolynomial x₁ y₁ L = -Cubic.toPoly ⟨1, -L ^ 2 - W.a₁ * L + W.a₂, 2 * x₁ * L ^ 2 + (W.a₁ * x₁ - 2 * y₁ - W.a₃) * L + (-W.a₁ * y₁ + W.a₄), -x₁ ^ 2 * L ^ 2 + (2 * x₁ * y₁ + W.a₃ * x₁) * L - (y₁ ^ 2 + W.a₃ * y₁ - W.a₆)⟩ := by rw [add_polynomial, line_polynomial, WeierstrassCurve.polynomial, Cubic.toPoly] run_tac eval_simp run_tac C_simp ring1 #align weierstrass_curve.add_polynomial_eq WeierstrassCurve.addPolynomial_eq /-- The $X$-coordinate of the addition of two affine points $(x_1, y_1)$ and $(x_2, y_2)$ in `W`, where the line through them is not vertical and has a slope of $L$. This depends on `W`, and has argument order: $x_1$, $x_2$, $L$. -/ @[simp] def addX : R := L ^ 2 + W.a₁ * L - W.a₂ - x₁ - x₂ #align weierstrass_curve.add_X WeierstrassCurve.addX /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.2137773769.map_simp -/ theorem baseChange_addX : (W.base_change A).addX (algebraMap R A x₁) (algebraMap R A x₂) (algebraMap R A L) = algebraMap R A (W.addX x₁ x₂ L) := by simp only [add_X] run_tac map_simp rfl #align weierstrass_curve.base_change_add_X WeierstrassCurve.baseChange_addX theorem baseChange_addX_of_baseChange (x₁ x₂ L : A) : (W.base_change B).addX (algebraMap A B x₁) (algebraMap A B x₂) (algebraMap A B L) = algebraMap A B ((W.base_change A).addX x₁ x₂ L) := by rw [← base_change_add_X, base_change_base_change] #align weierstrass_curve.base_change_add_X_of_base_change WeierstrassCurve.baseChange_addX_of_baseChange /-- The $Y$-coordinate, before applying the final negation, of the addition of two affine points $(x_1, y_1)$ and $(x_2, y_2)$, where the line through them is not vertical and has a slope of $L$. This depends on `W`, and has argument order: $x_1$, $x_2$, $y_1$, $L$. -/ @[simp] def addY' : R := L * (W.addX x₁ x₂ L - x₁) + y₁ #align weierstrass_curve.add_Y' WeierstrassCurve.addY' /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.2137773769.map_simp -/ theorem baseChange_addY' : (W.base_change A).addY' (algebraMap R A x₁) (algebraMap R A x₂) (algebraMap R A y₁) (algebraMap R A L) = algebraMap R A (W.addY' x₁ x₂ y₁ L) := by simp only [add_Y', base_change_add_X] run_tac map_simp #align weierstrass_curve.base_change_add_Y' WeierstrassCurve.baseChange_addY' theorem baseChange_addY'_of_baseChange (x₁ x₂ y₁ L : A) : (W.base_change B).addY' (algebraMap A B x₁) (algebraMap A B x₂) (algebraMap A B y₁) (algebraMap A B L) = algebraMap A B ((W.base_change A).addY' x₁ x₂ y₁ L) := by rw [← base_change_add_Y', base_change_base_change] #align weierstrass_curve.base_change_add_Y'_of_base_change WeierstrassCurve.baseChange_addY'_of_baseChange /-- The $Y$-coordinate of the addition of two affine points $(x_1, y_1)$ and $(x_2, y_2)$ in `W`, where the line through them is not vertical and has a slope of $L$. This depends on `W`, and has argument order: $x_1$, $x_2$, $y_1$, $L$. -/ @[simp] def addY : R := W.negY (W.addX x₁ x₂ L) (W.addY' x₁ x₂ y₁ L) #align weierstrass_curve.add_Y WeierstrassCurve.addY theorem baseChange_addY : (W.base_change A).addY (algebraMap R A x₁) (algebraMap R A x₂) (algebraMap R A y₁) (algebraMap R A L) = algebraMap R A (W.addY x₁ x₂ y₁ L) := by simp only [add_Y, base_change_add_Y', base_change_add_X, base_change_neg_Y] #align weierstrass_curve.base_change_add_Y WeierstrassCurve.baseChange_addY theorem baseChange_addY_of_baseChange (x₁ x₂ y₁ L : A) : (W.base_change B).addY (algebraMap A B x₁) (algebraMap A B x₂) (algebraMap A B y₁) (algebraMap A B L) = algebraMap A B ((W.base_change A).addY x₁ x₂ y₁ L) := by rw [← base_change_add_Y, base_change_base_change] #align weierstrass_curve.base_change_add_Y_of_base_change WeierstrassCurve.baseChange_addY_of_baseChange /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ theorem equation_add_iff : W.Equation (W.addX x₁ x₂ L) (W.addY' x₁ x₂ y₁ L) ↔ (W.addPolynomial x₁ y₁ L).eval (W.addX x₁ x₂ L) = 0 := by rw [equation, add_Y', add_polynomial, line_polynomial, WeierstrassCurve.polynomial] run_tac eval_simp #align weierstrass_curve.equation_add_iff WeierstrassCurve.equation_add_iff /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.162409969.derivative_simp -/ /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ theorem nonsingular_add_of_eval_derivative_ne_zero (hx' : W.Equation (W.addX x₁ x₂ L) (W.addY' x₁ x₂ y₁ L)) (hx : (derivative <| W.addPolynomial x₁ y₁ L).eval (W.addX x₁ x₂ L) ≠ 0) : W.Nonsingular (W.addX x₁ x₂ L) (W.addY' x₁ x₂ y₁ L) := by rw [nonsingular, and_iff_right hx', add_Y', polynomial_X, polynomial_Y] run_tac eval_simp contrapose! hx rw [add_polynomial, line_polynomial, WeierstrassCurve.polynomial] run_tac eval_simp run_tac derivative_simp simp only [zero_add, add_zero, sub_zero, MulZeroClass.zero_mul, mul_one] run_tac eval_simp linear_combination (norm := (norm_num1; ring1)) hx.left + L * hx.right #align weierstrass_curve.nonsingular_add_of_eval_derivative_ne_zero WeierstrassCurve.nonsingular_add_of_eval_derivative_ne_zero /-! ### The type of nonsingular rational points on a Weierstrass curve -/ /-- A nonsingular rational point on a Weierstrass curve `W` over `R`. This is either the point at infinity `weierstrass_curve.point.zero` or an affine point `weierstrass_curve.point.some` $(x, y)$ satisfying the equation $y^2 + a_1xy + a_3y = x^3 + a_2x^2 + a_4x + a_6$ of `W`. For an algebraic extension `S` of `R`, the type of nonsingular `S`-rational points on `W` is denoted `W⟮S⟯`. -/ inductive Point | zero | some {x y : R} (h : W.Nonsingular x y) #align weierstrass_curve.point WeierstrassCurve.Point -- mathport name: «expr ⟮ ⟯» scoped notation W "⟮" S "⟯" => (W.base_change S).Point namespace Point instance : Inhabited W.Point := ⟨zero⟩ instance : Zero W.Point := ⟨zero⟩ @[simp] theorem zero_def : (zero : W.Point) = 0 := rfl #align weierstrass_curve.point.zero_def WeierstrassCurve.Point.zero_def end Point variable {W x₁ y₁} theorem equation_neg_iff : W.Equation x₁ (W.negY x₁ y₁) ↔ W.Equation x₁ y₁ := by rw [equation_iff, equation_iff, neg_Y] congr 2 ring1 #align weierstrass_curve.equation_neg_iff WeierstrassCurve.equation_neg_iff theorem equation_neg_of (h : W.Equation x₁ <| W.negY x₁ y₁) : W.Equation x₁ y₁ := equation_neg_iff.mp h #align weierstrass_curve.equation_neg_of WeierstrassCurve.equation_neg_of /-- The negation of an affine point in `W` lies in `W`. -/ theorem equation_neg (h : W.Equation x₁ y₁) : W.Equation x₁ <| W.negY x₁ y₁ := equation_neg_iff.mpr h #align weierstrass_curve.equation_neg WeierstrassCurve.equation_neg theorem nonsingular_neg_iff : W.Nonsingular x₁ (W.negY x₁ y₁) ↔ W.Nonsingular x₁ y₁ := by rw [nonsingular_iff, equation_neg_iff, ← neg_Y, neg_Y_neg_Y, ← @ne_comm _ y₁, nonsingular_iff] exact and_congr_right' ((iff_congr not_and_distrib.symm not_and_distrib.symm).mpr <| not_congr <| and_congr_left fun h => by rw [← h]) #align weierstrass_curve.nonsingular_neg_iff WeierstrassCurve.nonsingular_neg_iff theorem nonsingular_neg_of (h : W.Nonsingular x₁ <| W.negY x₁ y₁) : W.Nonsingular x₁ y₁ := nonsingular_neg_iff.mp h #align weierstrass_curve.nonsingular_neg_of WeierstrassCurve.nonsingular_neg_of /-- The negation of a nonsingular affine point in `W` is nonsingular. -/ theorem nonsingular_neg (h : W.Nonsingular x₁ y₁) : W.Nonsingular x₁ <| W.negY x₁ y₁ := nonsingular_neg_iff.mpr h #align weierstrass_curve.nonsingular_neg WeierstrassCurve.nonsingular_neg namespace Point /-- The negation of a nonsingular rational point. Given a nonsingular rational point `P`, use `-P` instead of `neg P`. -/ def neg : W.Point → W.Point | 0 => 0 | some h => some <| nonsingular_neg h #align weierstrass_curve.point.neg WeierstrassCurve.Point.neg instance : Neg W.Point := ⟨neg⟩ @[simp] theorem neg_def (P : W.Point) : P.neg = -P := rfl #align weierstrass_curve.point.neg_def WeierstrassCurve.Point.neg_def @[simp] theorem neg_zero : (-0 : W.Point) = 0 := rfl #align weierstrass_curve.point.neg_zero WeierstrassCurve.Point.neg_zero @[simp] theorem neg_some (h : W.Nonsingular x₁ y₁) : -some h = some (nonsingular_neg h) := rfl #align weierstrass_curve.point.neg_some WeierstrassCurve.Point.neg_some instance : InvolutiveNeg W.Point := ⟨neg, by rintro (_ | _) · rfl · simp ring1⟩ end Point end Basic section Addition /-! ### Slopes of lines through nonsingular rational points on a Weierstrass curve -/ open Classical variable {F : Type u} [Field F] (W : WeierstrassCurve F) (K : Type v) [Field K] [Algebra F K] (x₁ x₂ y₁ y₂ : F) /-- The slope of the line through two affine points $(x_1, y_1)$ and $(x_2, y_2)$ in `W`. If $x_1 \ne x_2$, then this line is the secant of `W` through $(x_1, y_1)$ and $(x_2, y_2)$, and has slope $(y_1 - y_2) / (x_1 - x_2)$. Otherwise, if $y_1 \ne -y_1 - a_1x_1 - a_3$, then this line is the tangent of `W` at $(x_1, y_1) = (x_2, y_2)$, and has slope $(3x_1^2 + 2a_2x_1 + a_4 - a_1y_1) / (2y_1 + a_1x_1 + a_3)$. Otherwise, this line is vertical, and has undefined slope, in which case this function returns the value 0. This depends on `W`, and has argument order: $x_1$, $x_2$, $y_1$, $y_2$. -/ noncomputable def slope : F := if hx : x₁ = x₂ then if hy : y₁ = W.negY x₂ y₂ then 0 else (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) else (y₁ - y₂) / (x₁ - x₂) #align weierstrass_curve.slope WeierstrassCurve.slope variable {W x₁ x₂ y₁ y₂} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂) (h₁' : W.Equation x₁ y₁) (h₂' : W.Equation x₂ y₂) @[simp] theorem slope_of_Y_eq (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = 0 := by rw [slope, dif_pos hx, dif_pos hy] #align weierstrass_curve.slope_of_Y_eq WeierstrassCurve.slope_of_Y_eq @[simp] theorem slope_of_Y_ne (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) := by rw [slope, dif_pos hx, dif_neg hy] #align weierstrass_curve.slope_of_Y_ne WeierstrassCurve.slope_of_Y_ne @[simp] theorem slope_of_X_ne (hx : x₁ ≠ x₂) : W.slope x₁ x₂ y₁ y₂ = (y₁ - y₂) / (x₁ - x₂) := by rw [slope, dif_neg hx] #align weierstrass_curve.slope_of_X_ne WeierstrassCurve.slope_of_X_ne theorem slope_of_Y_ne_eq_eval (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = -(W.polynomialX.eval <| C y₁).eval x₁ / (W.polynomialY.eval <| C y₁).eval x₁ := by rw [slope_of_Y_ne hx hy, eval_polynomial_X, neg_sub] congr 1 rw [neg_Y, eval_polynomial_Y] ring1 #align weierstrass_curve.slope_of_Y_ne_eq_eval WeierstrassCurve.slope_of_Y_ne_eq_eval /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.2137773769.map_simp -/ /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.2137773769.map_simp -/ theorem baseChange_slope : (W.base_change K).slope (algebraMap F K x₁) (algebraMap F K x₂) (algebraMap F K y₁) (algebraMap F K y₂) = algebraMap F K (W.slope x₁ x₂ y₁ y₂) := by by_cases hx : x₁ = x₂ · by_cases hy : y₁ = W.neg_Y x₂ y₂ · rw [slope_of_Y_eq hx hy, slope_of_Y_eq <| congr_arg _ hx, map_zero] · rw [hy, base_change_neg_Y] · rw [slope_of_Y_ne hx hy, slope_of_Y_ne <| congr_arg _ hx] · run_tac map_simp simpa only [base_change_neg_Y] · rw [base_change_neg_Y] contrapose! hy exact NoZeroSMulDivisors.algebraMap_injective F K hy · rw [slope_of_X_ne hx, slope_of_X_ne] · run_tac map_simp · contrapose! hx exact NoZeroSMulDivisors.algebraMap_injective F K hx #align weierstrass_curve.base_change_slope WeierstrassCurve.baseChange_slope theorem baseChange_slope_of_baseChange {R : Type u} [CommRing R] (W : WeierstrassCurve R) (F : Type v) [Field F] [Algebra R F] (K : Type w) [Field K] [Algebra R K] [Algebra F K] [IsScalarTower R F K] (x₁ x₂ y₁ y₂ : F) : (W.base_change K).slope (algebraMap F K x₁) (algebraMap F K x₂) (algebraMap F K y₁) (algebraMap F K y₂) = algebraMap F K ((W.base_change F).slope x₁ x₂ y₁ y₂) := by rw [← base_change_slope, base_change_base_change] #align weierstrass_curve.base_change_slope_of_base_change WeierstrassCurve.baseChange_slope_of_baseChange include h₁' h₂' theorem Y_eq_of_X_eq (hx : x₁ = x₂) : y₁ = y₂ ∨ y₁ = W.negY x₂ y₂ := by rw [equation_iff] at h₁' h₂' rw [← sub_eq_zero, ← @sub_eq_zero _ _ y₁, ← mul_eq_zero, neg_Y] linear_combination (norm := (rw [hx]; ring1)) h₁' - h₂' #align weierstrass_curve.Y_eq_of_X_eq WeierstrassCurve.Y_eq_of_X_eq theorem Y_eq_of_Y_ne (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : y₁ = y₂ := Or.resolve_right (Y_eq_of_X_eq h₁' h₂' hx) hy #align weierstrass_curve.Y_eq_of_Y_ne WeierstrassCurve.Y_eq_of_Y_ne theorem addPolynomial_slope (hxy : x₁ = x₂ → y₁ ≠ W.negY x₂ y₂) : W.addPolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂) = -((X - C x₁) * (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by rw [add_polynomial_eq, neg_inj, Cubic.prod_X_sub_C_eq, Cubic.toPoly_injective] by_cases hx : x₁ = x₂ · rcases hx, Y_eq_of_Y_ne h₁' h₂' hx (hxy hx) with ⟨rfl, rfl⟩ rw [equation_iff] at h₁' h₂' rw [slope_of_Y_ne rfl <| hxy rfl] rw [neg_Y, ← sub_ne_zero] at hxy ext · rfl · simp only [add_X] ring1 · field_simp [hxy rfl] ring1 · linear_combination (norm := (field_simp [hxy rfl] ; ring1)) -h₁' · rw [equation_iff] at h₁' h₂' rw [slope_of_X_ne hx] rw [← sub_eq_zero] at hx ext · rfl · simp only [add_X] ring1 · apply mul_right_injective₀ hx linear_combination (norm := (field_simp [hx] ; ring1)) h₂' - h₁' · apply mul_right_injective₀ hx linear_combination (norm := (field_simp [hx] ; ring1)) x₂ * h₁' - x₁ * h₂' #align weierstrass_curve.add_polynomial_slope WeierstrassCurve.addPolynomial_slope /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.162409969.derivative_simp -/ theorem derivative_addPolynomial_slope (hxy : x₁ = x₂ → y₁ ≠ W.negY x₂ y₂) : derivative (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) = -((X - C x₁) * (X - C x₂) + (X - C x₁) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)) + (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by rw [add_polynomial_slope h₁' h₂' hxy] run_tac derivative_simp ring1 #align weierstrass_curve.derivative_add_polynomial_slope WeierstrassCurve.derivative_addPolynomial_slope /-! ### The addition law on nonsingular rational points on a Weierstrass curve -/ /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ /-- The addition of two affine points in `W` on a sloped line, before applying the final negation that maps $Y$ to $-Y - a_1X - a_3$, lies in `W`. -/ theorem equation_add' (hxy : x₁ = x₂ → y₁ ≠ W.negY x₂ y₂) : W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY' x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by rw [equation_add_iff, add_polynomial_slope h₁' h₂' hxy] run_tac eval_simp rw [neg_eq_zero, sub_self, MulZeroClass.mul_zero] #align weierstrass_curve.equation_add' WeierstrassCurve.equation_add' /-- The addition of two affine points in `W` on a sloped line lies in `W`. -/ theorem equation_add (hxy : x₁ = x₂ → y₁ ≠ W.negY x₂ y₂) : W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := equation_neg <| equation_add' h₁' h₂' hxy #align weierstrass_curve.equation_add WeierstrassCurve.equation_add omit h₁' h₂' include h₁ h₂ /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.3102772865.eval_simp -/ /-- The addition of two nonsingular affine points in `W` on a sloped line, before applying the final negation that maps $Y$ to $-Y - a_1X - a_3$, is nonsingular. -/ theorem nonsingular_add' (hxy : x₁ = x₂ → y₁ ≠ W.negY x₂ y₂) : W.Nonsingular (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY' x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by by_cases hx₁ : W.add_X x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₁ · rwa [add_Y', hx₁, sub_self, MulZeroClass.mul_zero, zero_add] · by_cases hx₂ : W.add_X x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₂ · by_cases hx : x₁ = x₂ · subst hx contradiction · rwa [add_Y', ← neg_sub, mul_neg, hx₂, slope_of_X_ne hx, div_mul_cancel _ <| sub_ne_zero_of_ne hx, neg_sub, sub_add_cancel] · apply W.nonsingular_add_of_eval_derivative_ne_zero _ _ _ _ (equation_add' h₁.1 h₂.1 hxy) rw [derivative_add_polynomial_slope h₁.left h₂.left hxy] run_tac eval_simp simpa only [neg_ne_zero, sub_self, MulZeroClass.mul_zero, add_zero] using mul_ne_zero (sub_ne_zero_of_ne hx₁) (sub_ne_zero_of_ne hx₂) #align weierstrass_curve.nonsingular_add' WeierstrassCurve.nonsingular_add' /-- The addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/ theorem nonsingular_add (hxy : x₁ = x₂ → y₁ ≠ W.negY x₂ y₂) : W.Nonsingular (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := nonsingular_neg <| nonsingular_add' h₁ h₂ hxy #align weierstrass_curve.nonsingular_add WeierstrassCurve.nonsingular_add omit h₁ h₂ namespace Point variable {h₁ h₂} /-- The addition of two nonsingular rational points. Given two nonsingular rational points `P` and `Q`, use `P + Q` instead of `add P Q`. -/ noncomputable def add : W.Point → W.Point → W.Point | 0, P => P | P, 0 => P | @some _ _ _ x₁ y₁ h₁, @some _ _ _ x₂ y₂ h₂ => if hx : x₁ = x₂ then if hy : y₁ = W.negY x₂ y₂ then 0 else some <| nonsingular_add h₁ h₂ fun _ => hy else some <| nonsingular_add h₁ h₂ fun h => (hx h).elim #align weierstrass_curve.point.add WeierstrassCurve.Point.add noncomputable instance : Add W.Point := ⟨add⟩ @[simp] theorem add_def (P Q : W.Point) : P.add Q = P + Q := rfl #align weierstrass_curve.point.add_def WeierstrassCurve.Point.add_def noncomputable instance : AddZeroClass W.Point := ⟨0, (· + ·), by rintro (_ | _) <;> rfl, by rintro (_ | _) <;> rfl⟩ @[simp] theorem some_add_some_of_Y_eq (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) : some h₁ + some h₂ = 0 := by rw [← add_def, add, dif_pos hx, dif_pos hy] #align weierstrass_curve.point.some_add_some_of_Y_eq WeierstrassCurve.Point.some_add_some_of_Y_eq @[simp] theorem some_add_self_of_Y_eq (hy : y₁ = W.negY x₁ y₁) : some h₁ + some h₁ = 0 := some_add_some_of_Y_eq rfl hy #align weierstrass_curve.point.some_add_self_of_Y_eq WeierstrassCurve.Point.some_add_self_of_Y_eq @[simp] theorem some_add_some_of_Y_ne (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun _ => hy) := by rw [← add_def, add, dif_pos hx, dif_neg hy] #align weierstrass_curve.point.some_add_some_of_Y_ne WeierstrassCurve.Point.some_add_some_of_Y_ne theorem some_add_some_of_Y_ne' (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : some h₁ + some h₂ = -some (nonsingular_add' h₁ h₂ fun _ => hy) := some_add_some_of_Y_ne hx hy #align weierstrass_curve.point.some_add_some_of_Y_ne' WeierstrassCurve.Point.some_add_some_of_Y_ne' @[simp] theorem some_add_self_of_Y_ne (hy : y₁ ≠ W.negY x₁ y₁) : some h₁ + some h₁ = some (nonsingular_add h₁ h₁ fun _ => hy) := some_add_some_of_Y_ne rfl hy #align weierstrass_curve.point.some_add_self_of_Y_ne WeierstrassCurve.Point.some_add_self_of_Y_ne theorem some_add_self_of_Y_ne' (hy : y₁ ≠ W.negY x₁ y₁) : some h₁ + some h₁ = -some (nonsingular_add' h₁ h₁ fun _ => hy) := some_add_some_of_Y_ne rfl hy #align weierstrass_curve.point.some_add_self_of_Y_ne' WeierstrassCurve.Point.some_add_self_of_Y_ne' @[simp] theorem some_add_some_of_X_ne (hx : x₁ ≠ x₂) : some h₁ + some h₂ = some (nonsingular_add h₁ h₂ fun h => (hx h).elim) := by rw [← add_def, add, dif_neg hx] #align weierstrass_curve.point.some_add_some_of_X_ne WeierstrassCurve.Point.some_add_some_of_X_ne theorem some_add_some_of_X_ne' (hx : x₁ ≠ x₂) : some h₁ + some h₂ = -some (nonsingular_add' h₁ h₂ fun h => (hx h).elim) := some_add_some_of_X_ne hx #align weierstrass_curve.point.some_add_some_of_X_ne' WeierstrassCurve.Point.some_add_some_of_X_ne' end Point end Addition section Group /-! ### The axioms for nonsingular rational points on a Weierstrass curve -/ variable {F : Type u} [Field F] {W : WeierstrassCurve F} namespace Point @[simp] theorem add_eq_zero (P Q : W.Point) : P + Q = 0 ↔ P = -Q := by rcases P, Q with ⟨_ | @⟨x₁, y₁, _⟩, _ | @⟨x₂, y₂, _⟩⟩ any_goals rfl · rw [zero_def, zero_add, ← neg_eq_iff_eq_neg, neg_zero, eq_comm] · simp only [neg_some] constructor · intro h by_cases hx : x₁ = x₂ · by_cases hy : y₁ = W.neg_Y x₂ y₂ · exact ⟨hx, hy⟩ · rw [some_add_some_of_Y_ne hx hy] at h contradiction · rw [some_add_some_of_X_ne hx] at h contradiction · exact fun ⟨hx, hy⟩ => some_add_some_of_Y_eq hx hy #align weierstrass_curve.point.add_eq_zero WeierstrassCurve.Point.add_eq_zero @[simp] theorem add_left_neg (P : W.Point) : -P + P = 0 := by rw [add_eq_zero] #align weierstrass_curve.point.add_left_neg WeierstrassCurve.Point.add_left_neg @[simp] theorem neg_add_eq_zero (P Q : W.Point) : -P + Q = 0 ↔ P = Q := by rw [add_eq_zero, neg_inj] #align weierstrass_curve.point.neg_add_eq_zero WeierstrassCurve.Point.neg_add_eq_zero end Point end Group section BaseChange /-! ### Nonsingular rational points on a base changed Weierstrass curve -/ variable {R : Type u} [CommRing R] (W : WeierstrassCurve R) (F : Type v) [Field F] [Algebra R F] (K : Type w) [Field K] [Algebra R K] [Algebra F K] [IsScalarTower R F K] namespace Point open WeierstrassCurve /- warning: weierstrass_curve.point.of_base_change_fun -> WeierstrassCurve.Point.ofBaseChangeFun is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} [_inst_1 : CommRing.{u1} R] (W : WeierstrassCurve.{u1} R) (F : Type.{u2}) [_inst_2 : Field.{u2} F] [_inst_3 : Algebra.{u1, u2} R F (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} F (DivisionRing.toRing.{u2} F (Field.toDivisionRing.{u2} F _inst_2)))] (K : Type.{u3}) [_inst_4 : Field.{u3} K] [_inst_5 : Algebra.{u1, u3} R K (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4)))] [_inst_6 : Algebra.{u2, u3} F K (Semifield.toCommSemiring.{u2} F (Field.toSemifield.{u2} F _inst_2)) (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4)))] [_inst_7 : IsScalarTower.{u1, u2, u3} R F K (SMulZeroClass.toHasSmul.{u1, u2} R F (AddZeroClass.toHasZero.{u2} F (AddMonoid.toAddZeroClass.{u2} F (AddCommMonoid.toAddMonoid.{u2} F (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} F (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} F (Semiring.toNonAssocSemiring.{u2} F (Ring.toSemiring.{u2} F (DivisionRing.toRing.{u2} F (Field.toDivisionRing.{u2} F _inst_2))))))))) (SMulWithZero.toSmulZeroClass.{u1, u2} R F (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (AddZeroClass.toHasZero.{u2} F (AddMonoid.toAddZeroClass.{u2} F (AddCommMonoid.toAddMonoid.{u2} F (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} F (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} F (Semiring.toNonAssocSemiring.{u2} F (Ring.toSemiring.{u2} F (DivisionRing.toRing.{u2} F (Field.toDivisionRing.{u2} F _inst_2))))))))) (MulActionWithZero.toSMulWithZero.{u1, u2} R F (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddZeroClass.toHasZero.{u2} F (AddMonoid.toAddZeroClass.{u2} F (AddCommMonoid.toAddMonoid.{u2} F (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} F (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} F (Semiring.toNonAssocSemiring.{u2} F (Ring.toSemiring.{u2} F (DivisionRing.toRing.{u2} F (Field.toDivisionRing.{u2} F _inst_2))))))))) (Module.toMulActionWithZero.{u1, u2} R F (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u2} F (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} F (Semiring.toNonAssocSemiring.{u2} F (Ring.toSemiring.{u2} F (DivisionRing.toRing.{u2} F (Field.toDivisionRing.{u2} F _inst_2)))))) (Algebra.toModule.{u1, u2} R F (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u2} F (DivisionRing.toRing.{u2} F (Field.toDivisionRing.{u2} F _inst_2))) _inst_3))))) (SMulZeroClass.toHasSmul.{u2, u3} F K (AddZeroClass.toHasZero.{u3} K (AddMonoid.toAddZeroClass.{u3} K (AddCommMonoid.toAddMonoid.{u3} K (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))))))))) (SMulWithZero.toSmulZeroClass.{u2, u3} F K (MulZeroClass.toHasZero.{u2} F (MulZeroOneClass.toMulZeroClass.{u2} F (MonoidWithZero.toMulZeroOneClass.{u2} F (Semiring.toMonoidWithZero.{u2} F (CommSemiring.toSemiring.{u2} F (Semifield.toCommSemiring.{u2} F (Field.toSemifield.{u2} F _inst_2))))))) (AddZeroClass.toHasZero.{u3} K (AddMonoid.toAddZeroClass.{u3} K (AddCommMonoid.toAddMonoid.{u3} K (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))))))))) (MulActionWithZero.toSMulWithZero.{u2, u3} F K (Semiring.toMonoidWithZero.{u2} F (CommSemiring.toSemiring.{u2} F (Semifield.toCommSemiring.{u2} F (Field.toSemifield.{u2} F _inst_2)))) (AddZeroClass.toHasZero.{u3} K (AddMonoid.toAddZeroClass.{u3} K (AddCommMonoid.toAddMonoid.{u3} K (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))))))))) (Module.toMulActionWithZero.{u2, u3} F K (CommSemiring.toSemiring.{u2} F (Semifield.toCommSemiring.{u2} F (Field.toSemifield.{u2} F _inst_2))) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4)))))) (Algebra.toModule.{u2, u3} F K (Semifield.toCommSemiring.{u2} F (Field.toSemifield.{u2} F _inst_2)) (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))) _inst_6))))) (SMulZeroClass.toHasSmul.{u1, u3} R K (AddZeroClass.toHasZero.{u3} K (AddMonoid.toAddZeroClass.{u3} K (AddCommMonoid.toAddMonoid.{u3} K (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))))))))) (SMulWithZero.toSmulZeroClass.{u1, u3} R K (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)))))) (AddZeroClass.toHasZero.{u3} K (AddMonoid.toAddZeroClass.{u3} K (AddCommMonoid.toAddMonoid.{u3} K (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))))))))) (MulActionWithZero.toSMulWithZero.{u1, u3} R K (Semiring.toMonoidWithZero.{u1} R (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1))) (AddZeroClass.toHasZero.{u3} K (AddMonoid.toAddZeroClass.{u3} K (AddCommMonoid.toAddMonoid.{u3} K (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))))))))) (Module.toMulActionWithZero.{u1, u3} R K (CommSemiring.toSemiring.{u1} R (CommRing.toCommSemiring.{u1} R _inst_1)) (NonUnitalNonAssocSemiring.toAddCommMonoid.{u3} K (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} K (Semiring.toNonAssocSemiring.{u3} K (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4)))))) (Algebra.toModule.{u1, u3} R K (CommRing.toCommSemiring.{u1} R _inst_1) (Ring.toSemiring.{u3} K (DivisionRing.toRing.{u3} K (Field.toDivisionRing.{u3} K _inst_4))) _inst_5)))))], (WeierstrassCurve.Point.{u2} F (EuclideanDomain.toCommRing.{u2} F (Field.toEuclideanDomain.{u2} F _inst_2)) (WeierstrassCurve.baseChange.{u1, u2} R _inst_1 W F (EuclideanDomain.toCommRing.{u2} F (Field.toEuclideanDomain.{u2} F _inst_2)) _inst_3)) -> (WeierstrassCurve.Point.{u3} K (EuclideanDomain.toCommRing.{u3} K (Field.toEuclideanDomain.{u3} K _inst_4)) (WeierstrassCurve.baseChange.{u1, u3} R _inst_1 W K (EuclideanDomain.toCommRing.{u3} K (Field.toEuclideanDomain.{u3} K _inst_4)) _inst_5)) but is expected to have type PUnit.{max (max (succ (succ u1)) (succ (succ u2))) (succ (succ u3))} Case conversion may be inaccurate. Consider using '#align weierstrass_curve.point.of_base_change_fun WeierstrassCurve.Point.ofBaseChangeFunₓ'. -/ /-- The function from `W⟮F⟯` to `W⟮K⟯` induced by a base change from `F` to `K`. -/ def ofBaseChangeFun : W⟮F⟯ → W⟮K⟯ | 0 => 0 | some h => some <| (nonsingular_iff_baseChange_of_baseChange W F K _ _).mp h #align weierstrass_curve.point.of_base_change_fun WeierstrassCurve.Point.ofBaseChangeFun /-- The group homomorphism from `W⟮F⟯` to `W⟮K⟯` induced by a base change from `F` to `K`. -/ @[simps] def ofBaseChange : W⟮F⟯ →+ W⟮K⟯ where toFun := ofBaseChangeFun W F K map_zero' := rfl map_add' := by rintro (_ | @⟨x₁, y₁, _⟩) (_ | @⟨x₂, y₂, _⟩) any_goals rfl by_cases hx : x₁ = x₂ · by_cases hy : y₁ = (W.base_change F).negY x₂ y₂ · simp only [some_add_some_of_Y_eq hx hy, of_base_change_fun] rw [some_add_some_of_Y_eq <| congr_arg _ hx] · rw [hy, base_change_neg_Y_of_base_change] · simp only [some_add_some_of_Y_ne hx hy, of_base_change_fun] rw [some_add_some_of_Y_ne <| congr_arg _ hx] · simp only [base_change_add_X_of_base_change, base_change_add_Y_of_base_change, base_change_slope_of_base_change] exact ⟨rfl, rfl⟩ · rw [base_change_neg_Y_of_base_change] contrapose! hy exact NoZeroSMulDivisors.algebraMap_injective F K hy · simp only [some_add_some_of_X_ne hx, of_base_change_fun] rw [some_add_some_of_X_ne] · simp only [base_change_add_X_of_base_change, base_change_add_Y_of_base_change, base_change_slope_of_base_change] exact ⟨rfl, rfl⟩ · contrapose! hx exact NoZeroSMulDivisors.algebraMap_injective F K hx #align weierstrass_curve.point.of_base_change WeierstrassCurve.Point.ofBaseChange theorem ofBaseChange_injective : Function.Injective <| ofBaseChange W F K := by rintro (_ | _) (_ | _) h · rfl any_goals contradiction simp only exact ⟨NoZeroSMulDivisors.algebraMap_injective F K (some.inj h).left, NoZeroSMulDivisors.algebraMap_injective F K (some.inj h).right⟩ #align weierstrass_curve.point.of_base_change_injective WeierstrassCurve.Point.ofBaseChange_injective end Point end BaseChange end WeierstrassCurve namespace EllipticCurve /-! ### Rational points on an elliptic curve -/ namespace Point variable {R : Type} [Nontrivial R] [CommRing R] (E : EllipticCurve R) /-- An affine point on an elliptic curve `E` over `R`. -/ def mk {x y : R} (h : E.Equation x y) : E.Point := WeierstrassCurve.Point.some <| E.Nonsingular h #align elliptic_curve.point.mk EllipticCurve.Point.mk end Point end EllipticCurve
subsection \<open>Montanari Weak Relations\<close> theory Montanari_Weak_Relations imports Weak_Transition_Systems Weak_Relations_modified Montanari_Weak_Transition_Systems begin context lts_tau begin definition contrasim :: \<open>('s \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> bool\<close> where \<open>contrasim R \<equiv> \<forall> p q p' A . (\<forall> a \<in> set(A). a \<noteq> \<tau>) \<and> R p q \<and> (p \<Rightarrow>$ A p') \<longrightarrow> (\<exists> q'. (q \<Rightarrow>$ A q') \<and> R q' p')\<close> definition ZR :: "(('s \<Rightarrow> ('s set) \<Rightarrow> bool)) \<Rightarrow> ('s \<Rightarrow> ('s set) \<Rightarrow> bool)" where \<open>ZR R p' Q' \<equiv> \<exists>p Q A. R p Q \<and> p \<Rightarrow>$A p' \<and> (\<forall>a \<in> set A. a \<noteq> \<tau>) \<and> Q' = (succs_seq_rec (rev A) Q)\<close> definition set_type :: "('s \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> ('s \<Rightarrow> ('s set) \<Rightarrow> bool)" where \<open>set_type R p Q \<equiv> \<exists>q. R p q \<and> Q = {q}\<close> lemma R_is_in_ZR : assumes \<open>R p Q\<close> shows \<open>ZR R p Q\<close> proof - have Q_cond: \<open>Q = succs_seq_rec (rev []) Q\<close> by simp have p_cond: \<open>p \<Rightarrow>$[] p\<close> using steps.simps weak_step_seq.simps(1) by blast thus \<open>ZR R p Q\<close> using Q_cond ZR_def \<open>R p Q\<close> by (metis bex_empty empty_set tau_tau) qed lemma ZR_C_guarantees_tau_succ : assumes \<open>contrasim C\<close> \<open>ZR (set_type C) p Q\<close> \<open>p \<Rightarrow>^\<tau> p'\<close> shows \<open>\<exists>q'. q' \<in> (succs \<tau> Q) \<and> ZR (set_type C) q' {p'}\<close> proof - obtain p0 Q0 A q0 where \<open>(set_type C) p0 Q0\<close> \<open>p0 \<Rightarrow>$A p\<close> \<open>\<forall>a \<in> set A. a \<noteq> \<tau>\<close> \<open>Q0 = {q0}\<close> and Q_def: \<open>Q = (succs_seq_rec (rev A) Q0)\<close> using ZR_def assms set_type_def by metis hence \<open>C p0 q0\<close> using set_type_def by auto have \<open>p0 \<Rightarrow>$(A@[\<tau>]) p'\<close> using \<open>p0 \<Rightarrow>$A p\<close> \<open>p \<Rightarrow>^\<tau> p'\<close> rev_seq_step_concat by auto hence word: \<open>p0 \<Rightarrow>$A p'\<close> by (metis \<open>\<forall>a\<in>set A. a \<noteq> \<tau>\<close> app_tau_taufree_list tau_def weak_step_over_tau) then obtain q' where \<open>q0 \<Rightarrow>$A q'\<close> \<open>C q' p'\<close> using assms contrasim_def[of \<open>C\<close>] \<open>C p0 q0\<close> \<open>\<forall>a \<in> set A. a \<noteq> \<tau>\<close> by blast hence \<open>(set_type C) q' {p'}\<close> using set_type_def by auto hence inZR: \<open>ZR (set_type C) q' {p'}\<close> using R_is_in_ZR by auto have \<open>q' \<in> succs \<tau> Q\<close> proof (cases \<open>A = []\<close>) case True hence \<open>q0 \<Rightarrow>^\<tau> q'\<close> using \<open>q0 \<Rightarrow>$A q'\<close> by auto hence \<open>q' \<in> succs \<tau> {q0}\<close> using succs_def by simp hence \<open>q' \<in> succs \<tau> Q0\<close> using \<open>Q0 = {q0}\<close> by simp thus \<open>q' \<in> succs \<tau> Q\<close> using Q_def by (simp add: True) next case False hence \<open>q' \<in> succs_seq_rec (rev A) Q0\<close> using \<open>Q0 = {q0}\<close> \<open>q0 \<Rightarrow>$ A q'\<close> by (simp add: word_reachable_implies_in_s) hence \<open>q' \<in> Q\<close> using Q_def by auto hence \<open>\<exists>q \<in> Q. q \<Rightarrow>^\<tau> q'\<close> using \<open>q' \<in> Q\<close> steps.refl by auto thus \<open>q' \<in> succs \<tau> Q\<close>using succs_def by simp qed thus \<open>\<exists>q'. q' \<in> succs \<tau> Q \<and> ZR (set_type C) q' {p'}\<close> using inZR by auto qed lemma ZR_C_guarantees_action_succ : assumes \<open>contrasim C\<close> \<open>ZR (set_type C) p Q\<close> \<open>p \<Rightarrow>a p'\<close> \<open>a \<noteq> \<tau>\<close> shows \<open>succs a Q \<noteq> {} \<and> ZR (set_type C) p' (succs a Q)\<close> proof - obtain p0 Q0 A q0 where \<open>(set_type C) p0 Q0\<close> \<open>p0 \<Rightarrow>$A p\<close> \<open>Q0 = {q0}\<close> \<open>\<forall>a \<in> set A. a \<noteq> \<tau> \<close> and Q_def: \<open>Q = (succs_seq_rec (rev A) Q0)\<close> using ZR_def assms set_type_def by metis then obtain CS where CS_def: \<open>contrasim CS \<and> CS p0 q0\<close> using assms set_type_def by (metis singleton_inject) have notau: \<open>\<forall>a \<in> set (A@[a]). a \<noteq> \<tau>\<close> using \<open>a \<noteq> \<tau>\<close> \<open>\<forall>a \<in> set A. a \<noteq> \<tau> \<close> by auto have word: \<open>p0 \<Rightarrow>$(A@[a]) p'\<close> using \<open>p0 \<Rightarrow>$A p\<close> \<open>p \<Rightarrow>a p'\<close> rev_seq_step_concat by (meson steps.step steps_concat) then obtain q' where \<open>q0 \<Rightarrow>$(A@[a]) q' \<and> CS q' p'\<close> using CS_def contrasim_def[of \<open>CS\<close>] notau by fastforce hence in_succs: \<open>q' \<in> (succs_seq_rec (rev (A@[a])) {q0})\<close> using word_reachable_implies_in_s by blast hence \<open>q' \<in> (succs_seq_rec (a#(rev A)) {q0})\<close> by (metis rev_eq_Cons_iff rev_rev_ident) hence \<open>q' \<in> succs a (succs_seq_rec (rev A) {q0})\<close> by auto hence notempty: \<open>q' \<in> succs a Q\<close> using Q_def \<open>Q0 = {q0}\<close> by auto have \<open>ZR (set_type C) p' (succs a Q)\<close> using in_succs word ZR_def[of \<open>(set_type C)\<close>] \<open>(set_type C) p0 Q0\<close> \<open>Q0 = {q0}\<close> Q_def simp_succs_seq_rev notau by meson with notempty show \<open>succs a Q \<noteq> {} \<and> ZR (set_type C) p' (succs a Q)\<close> by auto qed end end
/- Copyright (c) 2022 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Devon Tuma -/ import computational_monads.simulation_semantics.simulate.basic /-! # Distributions of Simulations This file contains more complicated lemmas for `eval_dist` applied to `simulate` and `simulate'`. -/ variables {α β γ : Type} {spec spec' spec'' : oracle_spec} {S S' : Type} namespace oracle_comp open oracle_spec open_locale nnreal ennreal variables (so : sim_oracle spec spec' S) (so' : sim_oracle spec spec'' S') (a : α) (i : spec.ι) (t : spec.domain i) (oa oa' : oracle_comp spec α) (ob ob' : α → oracle_comp spec β) (s : S) (f : α → β) section monad lemma eval_dist_simulate_map_bind (g : β → γ) : ⁅simulate so (g <$> (oa >>= ob)) s⁆ = ⁅simulate so oa s⁆.bind (λ x, ⁅simulate so (ob x.1) x.2⁆.map (prod.map g id)) := by simp only [simulate_map, simulate_bind, eval_dist_map, eval_dist_bind, pmf.map_bind] lemma eval_dist_simulate_map_bind' (g : β → γ) : ⁅simulate so (g <$> (oa >>= ob)) s⁆ = ⁅simulate so oa s⁆.bind (λ x, ⁅prod.map g id <$> simulate so (ob x.1) x.2⁆) := by simp only [simulate_map, simulate_bind, eval_dist_map, eval_dist_bind, pmf.map_bind] lemma eval_dist_simulate_map_bind_apply [decidable_eq γ] [decidable_eq S] (g : β → γ) (z : γ × S) : ⁅simulate so (g <$> (oa >>= ob)) s⁆ z = ∑' (x : α × S), ⁅simulate so oa s⁆ x * ∑' (y : β), ite (z.1 = g y) (⁅simulate so (ob x.1) x.2⁆ (y, z.2)) 0 := by simp only [eval_dist_simulate_map_bind', pmf.bind_apply, eval_dist_map_prod_map_id_right_apply] end monad /-- Lemma for inductively proving the support of a simulation is a specific function of the input. Often this is simpler than induction on the computation itself, especially the case of `bind` -/ lemma eval_dist_simulate_eq_induction {pr : Π (α : Type), oracle_comp spec α → S → (pmf (α × S))} (so : sim_oracle spec spec' S) (oa : oracle_comp spec α) (s : S) (h_ret : ∀ α a s, pr α (return a) s = pmf.pure (a, s)) (h_bind : ∀ α β (oa : oracle_comp spec α) (ob : α → oracle_comp spec β) s, pr β (oa >>= ob) s = (pr α oa s).bind (λ x, pr β (ob x.1) x.2)) (h_query : ∀ i t s, pr (spec.range i) (query i t) s = ⁅so i (t, s)⁆) : ⁅simulate so oa s⁆ = pr α oa s := begin induction oa using oracle_comp.induction_on with α a' α β oa ob hoa hob i t generalizing s, { simp only [h_ret, simulate_return, eval_dist_return] }, { simp only [h_bind, hoa, hob, simulate_bind, eval_dist_bind] }, { simp only [h_query, simulate_query] } end /-- Lemma for inductively proving that the distribution associated to a simulation is a specific function. Gives more explicit criteria than induction on the computation. In particular this automatically splits the cases for `return` and the `prod` in the `bind` sum. -/ lemma eval_dist_simulate_apply_eq_induction {pr : Π (α : Type), oracle_comp spec α → S → α × S → ℝ≥0∞} (so : sim_oracle spec spec' S) (oa : oracle_comp spec α) (s : S) (a : α) (s' : S) (h_ret : ∀ α a s, pr α (return a) s (a, s) = 1) (h_ret' : ∀ α a a' s s', a ≠ a' ∨ s ≠ s' → pr α (return a) s (a', s') = 0) (h_bind : ∀ α β (oa : oracle_comp spec α) (ob : α → oracle_comp spec β) s b s', pr β (oa >>= ob) s (b, s') = ∑' (a : α) (t : S), (pr α oa s (a, t)) * (pr β (ob a) t (b, s'))) (h_query : ∀ i t s u s', pr (spec.range i) (query i t) s (u, s') = ⁅so i (t, s)⁆ (u, s')) : ⁅simulate so oa s⁆ (a, s') = pr α oa s (a, s') := begin induction oa using oracle_comp.induction_on with α a' α β oa ob hoa hob i t generalizing s s', { rw [eval_dist_simulate_return, pmf.pure_apply], split_ifs with has, { simp only [prod.eq_iff_fst_eq_snd_eq] at has, refine has.1 ▸ has.2.symm ▸ (h_ret α a s).symm, }, { simp only [prod.eq_iff_fst_eq_snd_eq, not_and_distrib] at has, cases has with ha hs, { exact (h_ret' α a' a s s' $ or.inl $ ne.symm ha).symm }, { exact (h_ret' α a' a s s' $ or.inr $ ne.symm hs).symm } } }, { simp only [eval_dist_simulate_bind_apply_eq_tsum_tsum, h_bind, hoa, hob] }, { rw [eval_dist_simulate_query, h_query] }, end /-- If the main output of oracle queries is uniformly distributed (ignoring the oracle state), then the output distribution under `simulate'` is exactly the original distribution, since we define `eval_dist` to be uniform on oracle calls. -/ theorem eval_dist_simulate'_eq_eval_dist (h : ∀ i t s, ⁅so i (t, s)⁆.map prod.fst = pmf.uniform_of_fintype (spec.range i)) : ⁅simulate' so oa s⁆ = ⁅oa⁆ := begin induction oa using oracle_comp.induction_on with α a α β oa ob hoa hob i t generalizing s, { simp only [simulate'_return, eval_dist_map_return, eval_dist_return] }, { refine pmf.ext (λ b, _), rw [eval_dist_bind_apply_eq_tsum, eval_dist_simulate'_bind_apply], refine tsum_congr (λ a, _), rw [← hoa s, eval_dist_simulate'_apply, ← ennreal.tsum_mul_right], refine tsum_congr (λ t, _), rw ← hob }, { simp only [h, simulate'_query, eval_dist_map, eval_dist_query] } end /-- Given two simulation oracles `so` and `so'`, if the output distribution of oracle queries (ignoring the output state) is the same for any input and pair of initial oracle states, then the output distribution of simulating a computation is the same for both. -/ theorem eval_dist_simulate'_eq_eval_dist_simulate' {so : sim_oracle spec spec' S} {so' : sim_oracle spec spec'' S'} (h : ∀ i t s s', ⁅so i (t, s)⁆.map prod.fst = ⁅so' i (t, s')⁆.map prod.fst) (oa : oracle_comp spec α) (s : S) (s' : S') : ⁅simulate' so oa s⁆ = ⁅simulate' so' oa s'⁆ := begin induction oa using oracle_comp.induction_on with α a α β oa ob hoa hob i t generalizing s s', { simp only [simulate'_return, eval_dist_map_return] }, { refine pmf.ext (λ b, _), simp only [eval_dist_simulate'_bind_apply], refine tsum_congr (λ a, _), calc ∑' (t : S), ⁅simulate so oa s⁆ (a, t) * ⁅simulate' so (ob a) t⁆ b = ∑' (t : S), ⁅simulate so oa s⁆ (a, t) * ⁅simulate' so' (ob a) s'⁆ b : tsum_congr (λ t, congr_arg (λ x, _ * x) $ by rw hob a t s') ... = (∑' (t' : S'), ⁅simulate so' oa s'⁆ (a, t')) * ⁅simulate' so' (ob a) s'⁆ b : by simp_rw [ennreal.tsum_mul_right, ← eval_dist_simulate'_apply, hoa s s'] ... = ∑' (t' : S'), ⁅simulate so' oa s'⁆ (a, t') * ⁅simulate' so (ob a) s⁆ b : by rw [ennreal.tsum_mul_right, hob] ... = ∑' (t' : S'), ⁅simulate so' oa s'⁆ (a, t') * ⁅simulate' so' (ob a) t'⁆ b : tsum_congr (λ t, congr_arg (λ x, _ * x) $ by rw hob) }, { simpa only [simulate'_query, eval_dist_map] using h i t s s' }, end end oracle_comp
(* Author: Stefan Berghofer, TU Muenchen, 2003 Author: Asta Halkjær From, DTU Compute, 2019 Thanks to John Bruntse Larsen, Anders Schlichtkrull & Jørgen Villadsen See also the Natural Deduction Assistant: https://nadea.compute.dtu.dk/ *) section \<open>First-Order Logic According to Fitting\<close> theory FOL_Fitting imports "HOL-Library.Countable" begin section \<open>Miscellaneous Utilities\<close> text \<open>Some facts about (in)finite sets\<close> theorem set_inter_compl_diff [simp]: \<open>- A \<inter> B = B - A\<close> by blast section \<open>Terms and formulae\<close> text \<open> \label{sec:terms} The datatypes of terms and formulae in {\em de Bruijn notation} are defined as follows: \<close> datatype 'a "term" = Var nat | App 'a \<open>'a term list\<close> datatype ('a, 'b) form = FF | TT | Pred 'b \<open>'a term list\<close> | And \<open>('a, 'b) form\<close> \<open>('a, 'b) form\<close> | Or \<open>('a, 'b) form\<close> \<open>('a, 'b) form\<close> | Impl \<open>('a, 'b) form\<close> \<open>('a, 'b) form\<close> | Neg \<open>('a, 'b) form\<close> | Forall \<open>('a, 'b) form\<close> | Exists \<open>('a, 'b) form\<close> text \<open> We use \<open>'a\<close> and \<open>'b\<close> to denote the type of {\em function symbols} and {\em predicate symbols}, respectively. In applications \<open>App a ts\<close> and predicates \<open>Pred a ts\<close>, the length of \<open>ts\<close> is considered to be a part of the function or predicate name, so \<open>App a [t]\<close> and \<open>App a [t,u]\<close> refer to different functions. The size of a formula is used later for wellfounded induction. The default implementation provided by the datatype package is not quite what we need, so here is an alternative version: \<close> primrec size_form :: \<open>('a, 'b) form \<Rightarrow> nat\<close> where \<open>size_form FF = 0\<close> | \<open>size_form TT = 0\<close> | \<open>size_form (Pred _ _) = 0\<close> | \<open>size_form (And p q) = size_form p + size_form q + 1\<close> | \<open>size_form (Or p q) = size_form p + size_form q + 1\<close> | \<open>size_form (Impl p q) = size_form p + size_form q + 1\<close> | \<open>size_form (Neg p) = size_form p + 1\<close> | \<open>size_form (Forall p) = size_form p + 1\<close> | \<open>size_form (Exists p) = size_form p + 1\<close> subsection \<open>Closed terms and formulae\<close> text \<open> Many of the results proved in the following sections are restricted to closed terms and formulae. We call a term or formula {\em closed at level \<open>i\<close>}, if it only contains ``loose'' bound variables with indices smaller than \<open>i\<close>. \<close> primrec closedt :: \<open>nat \<Rightarrow> 'a term \<Rightarrow> bool\<close> and closedts :: \<open>nat \<Rightarrow> 'a term list \<Rightarrow> bool\<close> where \<open>closedt m (Var n) = (n < m)\<close> | \<open>closedt m (App a ts) = closedts m ts\<close> | \<open>closedts m [] = True\<close> | \<open>closedts m (t # ts) = (closedt m t \<and> closedts m ts)\<close> primrec closed :: \<open>nat \<Rightarrow> ('a, 'b) form \<Rightarrow> bool\<close> where \<open>closed m FF = True\<close> | \<open>closed m TT = True\<close> | \<open>closed m (Pred b ts) = closedts m ts\<close> | \<open>closed m (And p q) = (closed m p \<and> closed m q)\<close> | \<open>closed m (Or p q) = (closed m p \<and> closed m q)\<close> | \<open>closed m (Impl p q) = (closed m p \<and> closed m q)\<close> | \<open>closed m (Neg p) = closed m p\<close> | \<open>closed m (Forall p) = closed (Suc m) p\<close> | \<open>closed m (Exists p) = closed (Suc m) p\<close> theorem closedt_mono: assumes le: \<open>i \<le> j\<close> shows \<open>closedt i (t::'a term) \<Longrightarrow> closedt j t\<close> and \<open>closedts i (ts::'a term list) \<Longrightarrow> closedts j ts\<close> using le by (induct t and ts rule: closedt.induct closedts.induct) simp_all theorem closed_mono: assumes le: \<open>i \<le> j\<close> shows \<open>closed i p \<Longrightarrow> closed j p\<close> using le proof (induct p arbitrary: i j) case (Pred i l) then show ?case using closedt_mono by simp qed auto subsection \<open>Substitution\<close> text \<open> We now define substitution functions for terms and formulae. When performing substitutions under quantifiers, we need to {\em lift} the terms to be substituted for variables, in order for the ``loose'' bound variables to point to the right position. \<close> primrec substt :: \<open>'a term \<Rightarrow> 'a term \<Rightarrow> nat \<Rightarrow> 'a term\<close> ("_[_'/_]" [300, 0, 0] 300) and substts :: \<open>'a term list \<Rightarrow> 'a term \<Rightarrow> nat \<Rightarrow> 'a term list\<close> ("_[_'/_]" [300, 0, 0] 300) where \<open>(Var i)[s/k] = (if k < i then Var (i - 1) else if i = k then s else Var i)\<close> | \<open>(App a ts)[s/k] = App a (ts[s/k])\<close> | \<open>[][s/k] = []\<close> | \<open>(t # ts)[s/k] = t[s/k] # ts[s/k]\<close> primrec liftt :: \<open>'a term \<Rightarrow> 'a term\<close> and liftts :: \<open>'a term list \<Rightarrow> 'a term list\<close> where \<open>liftt (Var i) = Var (Suc i)\<close> | \<open>liftt (App a ts) = App a (liftts ts)\<close> | \<open>liftts [] = []\<close> | \<open>liftts (t # ts) = liftt t # liftts ts\<close> primrec subst :: \<open>('a, 'b) form \<Rightarrow> 'a term \<Rightarrow> nat \<Rightarrow> ('a, 'b) form\<close> ("_[_'/_]" [300, 0, 0] 300) where \<open>FF[s/k] = FF\<close> | \<open>TT[s/k] = TT\<close> | \<open>(Pred b ts)[s/k] = Pred b (ts[s/k])\<close> | \<open>(And p q)[s/k] = And (p[s/k]) (q[s/k])\<close> | \<open>(Or p q)[s/k] = Or (p[s/k]) (q[s/k])\<close> | \<open>(Impl p q)[s/k] = Impl (p[s/k]) (q[s/k])\<close> | \<open>(Neg p)[s/k] = Neg (p[s/k])\<close> | \<open>(Forall p)[s/k] = Forall (p[liftt s/Suc k])\<close> | \<open>(Exists p)[s/k] = Exists (p[liftt s/Suc k])\<close> theorem lift_closed [simp]: \<open>closedt 0 (t::'a term) \<Longrightarrow> closedt 0 (liftt t)\<close> \<open>closedts 0 (ts::'a term list) \<Longrightarrow> closedts 0 (liftts ts)\<close> by (induct t and ts rule: closedt.induct closedts.induct) simp_all theorem subst_closedt [simp]: assumes u: \<open>closedt 0 u\<close> shows \<open>closedt (Suc i) t \<Longrightarrow> closedt i (t[u/i])\<close> and \<open>closedts (Suc i) ts \<Longrightarrow> closedts i (ts[u/i])\<close> using u closedt_mono(1) by (induct t and ts rule: closedt.induct closedts.induct) auto theorem subst_closed [simp]: \<open>closedt 0 t \<Longrightarrow> closed (Suc i) p \<Longrightarrow> closed i (p[t/i])\<close> by (induct p arbitrary: i t) simp_all theorem subst_size_form [simp]: \<open>size_form (subst p t i) = size_form p\<close> by (induct p arbitrary: i t) simp_all subsection \<open>Parameters\<close> text \<open> The introduction rule \<open>ForallI\<close> for the universal quantifier, as well as the elimination rule \<open>ExistsE\<close> for the existential quantifier introduced in \secref{sec:proof-calculus} require the quantified variable to be replaced by a ``fresh'' parameter. Fitting's solution is to use a new nullary function symbol for this purpose. To express that a function symbol is ``fresh'', we introduce functions for collecting all function symbols occurring in a term or formula. \<close> primrec paramst :: \<open>'a term \<Rightarrow> 'a set\<close> and paramsts :: \<open>'a term list \<Rightarrow> 'a set\<close> where \<open>paramst (Var n) = {}\<close> | \<open>paramst (App a ts) = {a} \<union> paramsts ts\<close> | \<open>paramsts [] = {}\<close> | \<open>paramsts (t # ts) = (paramst t \<union> paramsts ts)\<close> primrec params :: \<open>('a, 'b) form \<Rightarrow> 'a set\<close> where \<open>params FF = {}\<close> | \<open>params TT = {}\<close> | \<open>params (Pred b ts) = paramsts ts\<close> | \<open>params (And p q) = params p \<union> params q\<close> | \<open>params (Or p q) = params p \<union> params q\<close> | \<open>params (Impl p q) = params p \<union> params q\<close> | \<open>params (Neg p) = params p\<close> | \<open>params (Forall p) = params p\<close> | \<open>params (Exists p) = params p\<close> text\<open> We also define parameter substitution functions on terms and formulae that apply a function \<open>f\<close> to all function symbols. \<close> primrec psubstt :: \<open>('a \<Rightarrow> 'c) \<Rightarrow> 'a term \<Rightarrow> 'c term\<close> and psubstts :: \<open>('a \<Rightarrow> 'c) \<Rightarrow> 'a term list \<Rightarrow> 'c term list\<close> where \<open>psubstt f (Var i) = Var i\<close> | \<open>psubstt f (App x ts) = App (f x) (psubstts f ts)\<close> | \<open>psubstts f [] = []\<close> | \<open>psubstts f (t # ts) = psubstt f t # psubstts f ts\<close> primrec psubst :: \<open>('a \<Rightarrow> 'c) \<Rightarrow> ('a, 'b) form \<Rightarrow> ('c, 'b) form\<close> where \<open>psubst f FF = FF\<close> | \<open>psubst f TT = TT\<close> | \<open>psubst f (Pred b ts) = Pred b (psubstts f ts)\<close> | \<open>psubst f (And p q) = And (psubst f p) (psubst f q)\<close> | \<open>psubst f (Or p q) = Or (psubst f p) (psubst f q)\<close> | \<open>psubst f (Impl p q) = Impl (psubst f p) (psubst f q)\<close> | \<open>psubst f (Neg p) = Neg (psubst f p)\<close> | \<open>psubst f (Forall p) = Forall (psubst f p)\<close> | \<open>psubst f (Exists p) = Exists (psubst f p)\<close> theorem psubstt_closed [simp]: \<open>closedt i (psubstt f t) = closedt i t\<close> \<open>closedts i (psubstts f ts) = closedts i ts\<close> by (induct t and ts rule: closedt.induct closedts.induct) simp_all theorem psubst_closed [simp]: \<open>closed i (psubst f p) = closed i p\<close> by (induct p arbitrary: i) simp_all theorem psubstt_subst [simp]: \<open>psubstt f (substt t u i) = substt (psubstt f t) (psubstt f u) i\<close> \<open>psubstts f (substts ts u i) = substts (psubstts f ts) (psubstt f u) i\<close> by (induct t and ts rule: psubstt.induct psubstts.induct) simp_all theorem psubstt_lift [simp]: \<open>psubstt f (liftt t) = liftt (psubstt f t)\<close> \<open>psubstts f (liftts ts) = liftts (psubstts f ts)\<close> by (induct t and ts rule: psubstt.induct psubstts.induct) simp_all theorem psubst_subst [simp]: \<open>psubst f (subst P t i) = subst (psubst f P) (psubstt f t) i\<close> by (induct P arbitrary: i t) simp_all theorem psubstt_upd [simp]: \<open>x \<notin> paramst (t::'a term) \<Longrightarrow> psubstt (f(x := y)) t = psubstt f t\<close> \<open>x \<notin> paramsts (ts::'a term list) \<Longrightarrow> psubstts (f(x := y)) ts = psubstts f ts\<close> by (induct t and ts rule: psubstt.induct psubstts.induct) (auto split: sum.split) theorem psubst_upd [simp]: \<open>x \<notin> params P \<Longrightarrow> psubst (f(x := y)) P = psubst f P\<close> by (induct P) (simp_all del: fun_upd_apply) theorem psubstt_id: fixes t :: \<open>'a term\<close> and ts :: \<open>'a term list\<close> shows \<open>psubstt id t = t\<close> and \<open>psubstts (\<lambda>x. x) ts = ts\<close> by (induct t and ts rule: psubstt.induct psubstts.induct) simp_all theorem psubst_id [simp]: \<open>psubst id = id\<close> proof fix p :: \<open>('a, 'b) form\<close> show \<open>psubst id p = id p\<close> by (induct p) (simp_all add: psubstt_id) qed theorem psubstt_image [simp]: \<open>paramst (psubstt f t) = f ` paramst t\<close> \<open>paramsts (psubstts f ts) = f ` paramsts ts\<close> by (induct t and ts rule: paramst.induct paramsts.induct) (simp_all add: image_Un) theorem psubst_image [simp]: \<open>params (psubst f p) = f ` params p\<close> by (induct p) (simp_all add: image_Un) section \<open>Semantics\<close> text \<open> \label{sec:semantics} In this section, we define evaluation functions for terms and formulae. Evaluation is performed relative to an environment mapping indices of variables to values. We also introduce a function, denoted by \<open>e\<langle>i:a\<rangle>\<close>, for inserting a value \<open>a\<close> at position \<open>i\<close> into the environment. All values of variables with indices less than \<open>i\<close> are left untouched by this operation, whereas the values of variables with indices greater or equal than \<open>i\<close> are shifted one position up. \<close> definition shift :: \<open>(nat \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a\<close> ("_\<langle>_:_\<rangle>" [90, 0, 0] 91) where \<open>e\<langle>i:a\<rangle> = (\<lambda>j. if j < i then e j else if j = i then a else e (j - 1))\<close> lemma shift_gt [simp]: \<open>j < i \<Longrightarrow> (e\<langle>i:T\<rangle>) j = e j\<close> by (simp add: shift_def) lemma shift_lt [simp]: \<open>i < j \<Longrightarrow> (e\<langle>i:T\<rangle>) j = e (j - 1)\<close> by (simp add: shift_def) lemma shift_commute [simp]: \<open>e\<langle>i:U\<rangle>\<langle>0:T\<rangle> = e\<langle>0:T\<rangle>\<langle>Suc i:U\<rangle>\<close> proof fix x show \<open>(e\<langle>i:U\<rangle>\<langle>0:T\<rangle>) x = (e\<langle>0:T\<rangle>\<langle>Suc i:U\<rangle>) x\<close> by (cases x) (simp_all add: shift_def) qed primrec evalt :: \<open>(nat \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'c list \<Rightarrow> 'c) \<Rightarrow> 'a term \<Rightarrow> 'c\<close> and evalts :: \<open>(nat \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'c list \<Rightarrow> 'c) \<Rightarrow> 'a term list \<Rightarrow> 'c list\<close> where \<open>evalt e f (Var n) = e n\<close> | \<open>evalt e f (App a ts) = f a (evalts e f ts)\<close> | \<open>evalts e f [] = []\<close> | \<open>evalts e f (t # ts) = evalt e f t # evalts e f ts\<close> primrec eval :: \<open>(nat \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'c list \<Rightarrow> 'c) \<Rightarrow> ('b \<Rightarrow> 'c list \<Rightarrow> bool) \<Rightarrow> ('a, 'b) form \<Rightarrow> bool\<close> where \<open>eval e f g FF = False\<close> | \<open>eval e f g TT = True\<close> | \<open>eval e f g (Pred a ts) = g a (evalts e f ts)\<close> | \<open>eval e f g (And p q) = ((eval e f g p) \<and> (eval e f g q))\<close> | \<open>eval e f g (Or p q) = ((eval e f g p) \<or> (eval e f g q))\<close> | \<open>eval e f g (Impl p q) = ((eval e f g p) \<longrightarrow> (eval e f g q))\<close> | \<open>eval e f g (Neg p) = (\<not> (eval e f g p))\<close> | \<open>eval e f g (Forall p) = (\<forall>z. eval (e\<langle>0:z\<rangle>) f g p)\<close> | \<open>eval e f g (Exists p) = (\<exists>z. eval (e\<langle>0:z\<rangle>) f g p)\<close> text \<open> We write \<open>e,f,g,ps \<Turnstile> p\<close> to mean that the formula \<open>p\<close> is a semantic consequence of the list of formulae \<open>ps\<close> with respect to an environment \<open>e\<close> and interpretations \<open>f\<close> and \<open>g\<close> for function and predicate symbols, respectively. \<close> definition model :: \<open>(nat \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'c list \<Rightarrow> 'c) \<Rightarrow> ('b \<Rightarrow> 'c list \<Rightarrow> bool) \<Rightarrow> ('a, 'b) form list \<Rightarrow> ('a, 'b) form \<Rightarrow> bool\<close> ("_,_,_,_ \<Turnstile> _" [50,50] 50) where \<open>(e,f,g,ps \<Turnstile> p) = (list_all (eval e f g) ps \<longrightarrow> eval e f g p)\<close> text \<open> The following substitution lemmas relate substitution and evaluation functions: \<close> theorem subst_lemma' [simp]: \<open>evalt e f (substt t u i) = evalt (e\<langle>i:evalt e f u\<rangle>) f t\<close> \<open>evalts e f (substts ts u i) = evalts (e\<langle>i:evalt e f u\<rangle>) f ts\<close> by (induct t and ts rule: substt.induct substts.induct) simp_all theorem lift_ theorem subst_lemma [simp]: \<open>eval e f g (subst a t i) = eval (e\<langle>i:evalt e f t\<rangle>) f g a\<close> by (induct a arbitrary: e i t) simp_all theorem upd_lemma' [simp]: \<open>n \<notin> paramst t \<Longrightarrow> evalt e (f(n := x)) t = evalt e f t\<close> \<open>n \<notin> paramsts ts \<Longrightarrow> evalts e (f(n := x)) ts = evalts e f ts\<close> by (induct t and ts rule: paramst.induct paramsts.induct) auto theorem upd_lemma [simp]: \<open>n \<notin> params p \<Longrightarrow> eval e (f(n := x)) g p = eval e f g p\<close> by (induct p arbitrary: e) simp_all theorem list_upd_lemma [simp]: \<open>list_all (\<lambda>p. n \<notin> params p) G \<Longrightarrow> list_all (eval e (f(n := x)) g) G = list_all (eval e f g) G\<close> by (induct G) simp_all theorem psubst_eval' [simp]: \<open>evalt e f (psubstt h t) = evalt e (\<lambda>p. f (h p)) t\<close> \<open>evalts e f (psubstts h ts) = evalts e (\<lambda>p. f (h p)) ts\<close> by (induct t and ts rule: psubstt.induct psubstts.induct) simp_all theorem psubst_eval: \<open>eval e f g (psubst h p) = eval e (\<lambda>p. f (h p)) g p\<close> by (induct p arbitrary: e) simp_all text \<open> In order to test the evaluation function defined above, we apply it to an example: \<close> theorem ex_all_commute_eval: \<open>eval e f g (Impl (Exists (Forall (Pred p [Var 1, Var 0]))) (Forall (Exists (Pred p [Var 0, Var 1]))))\<close> apply simp txt \<open> Simplification yields the following proof state: @{subgoals [display]} This is easily proved using intuitionistic logic: \<close> by iprover section \<open>Proof calculus\<close> text \<open> \label{sec:proof-calculus} We now introduce a natural deduction proof calculus for first order logic. The derivability judgement \<open>G \<turnstile> a\<close> is defined as an inductive predicate. \<close> inductive deriv :: \<open>('a, 'b) form list \<Rightarrow> ('a, 'b) form \<Rightarrow> bool\<close> ("_ \<turnstile> _" [50,50] 50) where Assum: \<open>a \<in> set G \<Longrightarrow> G \<turnstile> a\<close> | TTI: \<open>G \<turnstile> TT\<close> | FFE: \<open>G \<turnstile> FF \<Longrightarrow> G \<turnstile> a\<close> | NegI: \<open>a # G \<turnstile> FF \<Longrightarrow> G \<turnstile> Neg a\<close> | NegE: \<open>G \<turnstile> Neg a \<Longrightarrow> G \<turnstile> a \<Longrightarrow> G \<turnstile> FF\<close> | Class: \<open>Neg a # G \<turnstile> FF \<Longrightarrow> G \<turnstile> a\<close> | AndI: \<open>G \<turnstile> a \<Longrightarrow> G \<turnstile> b \<Longrightarrow> G \<turnstile> And a b\<close> | AndE1: \<open>G \<turnstile> And a b \<Longrightarrow> G \<turnstile> a\<close> | AndE2: \<open>G \<turnstile> And a b \<Longrightarrow> G \<turnstile> b\<close> | OrI1: \<open>G \<turnstile> a \<Longrightarrow> G \<turnstile> Or a b\<close> | OrI2: \<open>G \<turnstile> b \<Longrightarrow> G \<turnstile> Or a b\<close> | OrE: \<open>G \<turnstile> Or a b \<Longrightarrow> a # G \<turnstile> c \<Longrightarrow> b # G \<turnstile> c \<Longrightarrow> G \<turnstile> c\<close> | ImplI: \<open>a # G \<turnstile> b \<Longrightarrow> G \<turnstile> Impl a b\<close> | ImplE: \<open>G \<turnstile> Impl a b \<Longrightarrow> G \<turnstile> a \<Longrightarrow> G \<turnstile> b\<close> | ForallI: \<open>G \<turnstile> a[App n []/0] \<Longrightarrow> list_all (\<lambda>p. n \<notin> params p) G \<Longrightarrow> n \<notin> params a \<Longrightarrow> G \<turnstile> Forall a\<close> | ForallE: \<open>G \<turnstile> Forall a \<Longrightarrow> G \<turnstile> a[t/0]\<close> | ExistsI: \<open>G \<turnstile> a[t/0] \<Longrightarrow> G \<turnstile> Exists a\<close> | ExistsE: \<open>G \<turnstile> Exists a \<Longrightarrow> a[App n []/0] # G \<turnstile> b \<Longrightarrow> list_all (\<lambda>p. n \<notin> params p) G \<Longrightarrow> n \<notin> params a \<Longrightarrow> n \<notin> params b \<Longrightarrow> G \<turnstile> b\<close> text \<open> The following derived inference rules are sometimes useful in applications. \<close> theorem Class': \<open>Neg A # G \<turnstile> A \<Longrightarrow> G \<turnstile> A\<close> by (rule Class, rule NegE, rule Assum) (simp, iprover) theorem cut: \<open>G \<turnstile> A \<Longrightarrow> A # G \<turnstile> B \<Longrightarrow> G \<turnstile> B\<close> by (rule ImplE, rule ImplI) theorem ForallE': \<open>G \<turnstile> Forall a \<Longrightarrow> subst a t 0 # G \<turnstile> B \<Longrightarrow> G \<turnstile> B\<close> by (rule cut, rule ForallE) text \<open> As an example, we show that the excluded middle, a commutation property for existential and universal quantifiers, the drinker principle, as well as Peirce's law are derivable in the calculus given above. \<close> theorem tnd: \<open>[] \<turnstile> Or (Pred p []) (Neg (Pred p []))\<close> (is \<open>_ \<turnstile> ?or\<close>) proof - have \<open>[Neg ?or] \<turnstile> Neg ?or\<close> by (simp add: Assum) moreover { have \<open>[Pred p [], Neg ?or] \<turnstile> Neg ?or\<close> by (simp add: Assum) moreover have \<open>[Pred p [], Neg ?or] \<turnstile> Pred p []\<close> by (simp add: Assum) then have \<open>[Pred p [], Neg ?or] \<turnstile> ?or\<close> by (rule OrI1) ultimately have \<open>[Pred p [], Neg ?or] \<turnstile> FF\<close> by (rule NegE) then have \<open>[Neg ?or] \<turnstile> Neg (Pred p [])\<close> by (rule NegI) then have \<open>[Neg ?or] \<turnstile> ?or\<close> by (rule OrI2) } ultimately have \<open>[Neg ?or] \<turnstile> FF\<close> by (rule NegE) then show ?thesis by (rule Class) qed theorem ex_all_commute: \<open>([]::(nat, 'b) form list) \<turnstile> Impl (Exists (Forall (Pred p [Var 1, Var 0]))) (Forall (Exists (Pred p [Var 0, Var 1])))\<close> proof - let ?forall = \<open>Forall (Pred p [Var 1, Var 0]) :: (nat, 'b) form\<close> have \<open>[Exists ?forall] \<turnstile> Exists ?forall\<close> by (simp add: Assum) moreover { have \<open>[?forall[App 1 []/0], Exists ?forall] \<turnstile> Forall (Pred p [App 1 [], Var 0])\<close> by (simp add: Assum) moreover have \<open>[Pred p [App 1 [], Var 0][App 0 []/0], ?forall[App 1 []/0], Exists ?forall] \<turnstile> Pred p [Var 0, App 0 []][App 1 []/0]\<close> by (simp add: Assum) ultimately have \<open>[?forall[App 1 []/0], Exists ?forall] \<turnstile> (Pred p [Var 0, App 0 []])[App 1 []/0]\<close> by (rule ForallE') } then have \<open>[?forall[App 1 []/0], Exists ?forall] \<turnstile> Exists (Pred p [Var 0, App 0 []])\<close> by (rule ExistsI) moreover have \<open>list_all (\<lambda>p. 1 \<notin> params p) [Exists ?forall]\<close> by simp moreover have \<open>1 \<notin> params ?forall\<close> by simp moreover have \<open>1 \<notin> params (Exists (Pred p [Var 0, App (0 :: nat) []]))\<close> by simp ultimately have \<open>[Exists ?forall] \<turnstile> Exists (Pred p [Var 0, App 0 []])\<close> by (rule ExistsE) then have \<open>[Exists ?forall] \<turnstile> (Exists (Pred p [Var 0, Var 1]))[App 0 []/0]\<close> by simp moreover have \<open>list_all (\<lambda>p. 0 \<notin> params p) [Exists ?forall]\<close> by simp moreover have \<open>0 \<notin> params (Exists (Pred p [Var 0, Var 1]))\<close> by simp ultimately have \<open>[Exists ?forall] \<turnstile> Forall (Exists (Pred p [Var 0, Var 1]))\<close> by (rule ForallI) then show ?thesis by (rule ImplI) qed theorem drinker: \<open>([]::(nat, 'b) form list) \<turnstile> Exists (Impl (Pred P [Var 0]) (Forall (Pred P [Var 0])))\<close> proof - let ?impl = \<open>(Impl (Pred P [Var 0]) (Forall (Pred P [Var 0]))) :: (nat, 'b) form\<close> let ?G' = \<open>[Pred P [Var 0], Neg (Exists ?impl)]\<close> let ?G = \<open>Neg (Pred P [App 0 []]) # ?G'\<close> have \<open>?G \<turnstile> Neg (Exists ?impl)\<close> by (simp add: Assum) moreover have \<open>Pred P [App 0 []] # ?G \<turnstile> Neg (Pred P [App 0 []])\<close> and \<open>Pred P [App 0 []] # ?G \<turnstile> Pred P [App 0 []]\<close> by (simp_all add: Assum) then have \<open>Pred P [App 0 []] # ?G \<turnstile> FF\<close> by (rule NegE) then have \<open>Pred P [App 0 []] # ?G \<turnstile> Forall (Pred P [Var 0])\<close> by (rule FFE) then have \<open>?G \<turnstile> ?impl[App 0 []/0]\<close> using ImplI by simp then have \<open>?G \<turnstile> Exists ?impl\<close> by (rule ExistsI) ultimately have \<open>?G \<turnstile> FF\<close> by (rule NegE) then have \<open>?G' \<turnstile> Pred P [Var 0][App 0 []/0]\<close> using Class by simp moreover have \<open>list_all (\<lambda>p. (0 :: nat) \<notin> params p) ?G'\<close> by simp moreover have \<open>(0 :: nat) \<notin> params (Pred P [Var 0])\<close> by simp ultimately have \<open>?G' \<turnstile> Forall (Pred P [Var 0])\<close> by (rule ForallI) then have \<open>[Neg (Exists ?impl)] \<turnstile> ?impl[Var 0/0]\<close> using ImplI by simp then have \<open>[Neg (Exists ?impl)] \<turnstile> Exists ?impl\<close> by (rule ExistsI) then show ?thesis by (rule Class') qed theorem peirce: \<open>[] \<turnstile> Impl (Impl (Impl (Pred P []) (Pred Q [])) (Pred P [])) (Pred P [])\<close> (is \<open>[] \<turnstile> Impl ?PQP (Pred P [])\<close>) proof - let ?PQPP = \<open>Impl ?PQP (Pred P [])\<close> have \<open>[?PQP, Neg ?PQPP] \<turnstile> ?PQP\<close> by (simp add: Assum) moreover { have \<open>[Pred P [], ?PQP, Neg ?PQPP] \<turnstile> Neg ?PQPP\<close> by (simp add: Assum) moreover have \<open>[?PQP, Pred P [], ?PQP, Neg ?PQPP] \<turnstile> Pred P []\<close> by (simp add: Assum) then have \<open>[Pred P [], ?PQP, Neg ?PQPP] \<turnstile> ?PQPP\<close> by (rule ImplI) ultimately have \<open>[Pred P [], ?PQP, Neg ?PQPP] \<turnstile> FF\<close> by (rule NegE) } then have \<open>[Pred P [], ?PQP, Neg ?PQPP] \<turnstile> Pred Q []\<close> by (rule FFE) then have \<open>[?PQP, Neg ?PQPP] \<turnstile> Impl (Pred P []) (Pred Q [])\<close> by (rule ImplI) ultimately have \<open>[?PQP, Neg ?PQPP] \<turnstile> Pred P []\<close> by (rule ImplE) then have \<open>[Neg ?PQPP] \<turnstile> ?PQPP\<close> by (rule ImplI) then show \<open>[] \<turnstile> ?PQPP\<close> by (rule Class') qed section \<open>Correctness\<close> text \<open> The correctness of the proof calculus introduced in \secref{sec:proof-calculus} can now be proved by induction on the derivation of @{term \<open>G \<turnstile> p\<close>}, using the substitution rules proved in \secref{sec:semantics}. \<close> theorem correctness: \<open>G \<turnstile> p \<Longrightarrow> \<forall>e f g. e,f,g,G \<Turnstile> p\<close> proof (induct p rule: deriv.induct) case (Assum a G) then show ?case by (simp add: model_def list_all_iff) next case (ForallI G a n) show ?case proof (intro allI) fix f g and e :: \<open>nat \<Rightarrow> 'c\<close> have \<open>\<forall>z. e, (f(n := \<lambda>x. z)), g, G \<Turnstile> (a[App n []/0])\<close> using ForallI by blast then have \<open>\<forall>z. list_all (eval e f g) G \<longrightarrow> eval (e\<langle>0:z\<rangle>) f g a\<close> using ForallI unfolding model_def by simp then show \<open>e,f,g,G \<Turnstile> Forall a\<close> unfolding model_def by simp qed next case (ExistsE G a n b) show ?case proof (intro allI) fix f g and e :: \<open>nat \<Rightarrow> 'c\<close> obtain z where \<open>list_all (eval e f g) G \<longrightarrow> eval (e\<langle>0:z\<rangle>) f g a\<close> using ExistsE unfolding model_def by simp blast then have \<open>e, (f(n := \<lambda>x. z)), g, G \<Turnstile> b\<close> using ExistsE unfolding model_def by simp then show \<open>e,f,g,G \<Turnstile> b\<close> using ExistsE unfolding model_def by simp qed qed (simp_all add: model_def, blast+) section \<open>Completeness\<close> text \<open> The goal of this section is to prove completeness of the natural deduction calculus introduced in \secref{sec:proof-calculus}. Before we start with the actual proof, it is useful to note that the following two formulations of completeness are equivalent: \begin{enumerate} \item All valid formulae are derivable, i.e. \<open>ps \<Turnstile> p \<Longrightarrow> ps \<turnstile> p\<close> \item All consistent sets are satisfiable \end{enumerate} The latter property is called the {\em model existence theorem}. To see why 2 implies 1, observe that \<open>Neg p, ps \<notturnstile> FF\<close> implies that \<open>Neg p, ps\<close> is consistent, which, by the model existence theorem, implies that \<open>Neg p, ps\<close> has a model, which in turn implies that \<open>ps \<notTurnstile> p\<close>. By contraposition, it therefore follows from \<open>ps \<Turnstile> p\<close> that \<open>Neg p, ps \<turnstile> FF\<close>, which allows us to deduce \<open>ps \<turnstile> p\<close> using rule \<open>Class\<close>. In most textbooks on logic, a set \<open>S\<close> of formulae is called {\em consistent}, if no contradiction can be derived from \<open>S\<close> using a {\em specific proof calculus}, i.e.\ \<open>S \<notturnstile> FF\<close>. Rather than defining consistency relative to a {\em specific} calculus, Fitting uses the more general approach of describing properties that all consistent sets must have (see \secref{sec:consistent-sets}). The key idea behind the proof of the model existence theorem is to extend a consistent set to one that is {\em maximal} (see \secref{sec:extend}). In order to do this, we use the fact that the set of formulae is enumerable (see \secref{sec:enumeration}), which allows us to form a sequence $\phi_0$, $\phi_1$, $\phi_2$, $\ldots$ containing all formulae. We can then construct a sequence $S_i$ of consistent sets as follows: \[ \begin{array}{l} S_0 = S \\ S_{i+1} = \left\{\begin{array}{ll} S_i \cup \{\phi_i\} & \hbox{if } S_i \cup \{\phi_i\} \hbox{ consistent} \\ S_i & \hbox{otherwise} \end{array}\right. \end{array} \] To obtain a maximal consistent set, we form the union $\bigcup_i S_i$ of these sets. To ensure that this union is still consistent, additional closure (see \secref{sec:closure}) and finiteness (see \secref{sec:finiteness}) properties are needed. It can be shown that a maximal consistent set is a {\em Hintikka set} (see \secref{sec:hintikka}). Hintikka sets are satisfiable in {\em Herbrand} models, where closed terms coincide with their interpretation. \<close> subsection \<open>Consistent sets\<close> text \<open> \label{sec:consistent-sets} In this section, we describe an abstract criterion for consistent sets. A set of sets of formulae is called a {\em consistency property}, if the following holds: \<close> definition consistency :: \<open>('a, 'b) form set set \<Rightarrow> bool\<close> where \<open>consistency C = (\<forall>S. S \<in> C \<longrightarrow> (\<forall>p ts. \<not> (Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S)) \<and> FF \<notin> S \<and> Neg TT \<notin> S \<and> (\<forall>Z. Neg (Neg Z) \<in> S \<longrightarrow> S \<union> {Z} \<in> C) \<and> (\<forall>A B. And A B \<in> S \<longrightarrow> S \<union> {A, B} \<in> C) \<and> (\<forall>A B. Neg (Or A B) \<in> S \<longrightarrow> S \<union> {Neg A, Neg B} \<in> C) \<and> (\<forall>A B. Or A B \<in> S \<longrightarrow> S \<union> {A} \<in> C \<or> S \<union> {B} \<in> C) \<and> (\<forall>A B. Neg (And A B) \<in> S \<longrightarrow> S \<union> {Neg A} \<in> C \<or> S \<union> {Neg B} \<in> C) \<and> (\<forall>A B. Impl A B \<in> S \<longrightarrow> S \<union> {Neg A} \<in> C \<or> S \<union> {B} \<in> C) \<and> (\<forall>A B. Neg (Impl A B) \<in> S \<longrightarrow> S \<union> {A, Neg B} \<in> C) \<and> (\<forall>P t. closedt 0 t \<longrightarrow> Forall P \<in> S \<longrightarrow> S \<union> {P[t/0]} \<in> C) \<and> (\<forall>P t. closedt 0 t \<longrightarrow> Neg (Exists P) \<in> S \<longrightarrow> S \<union> {Neg (P[t/0])} \<in> C) \<and> (\<forall>P. Exists P \<in> S \<longrightarrow> (\<exists>x. S \<union> {P[App x []/0]} \<in> C)) \<and> (\<forall>P. Neg (Forall P) \<in> S \<longrightarrow> (\<exists>x. S \<union> {Neg (P[App x []/0])} \<in> C)))\<close> text \<open> In \secref{sec:finiteness}, we will show how to extend a consistency property to one that is of {\em finite character}. However, the above definition of a consistency property cannot be used for this, since there is a problem with the treatment of formulae of the form \<open>Exists P\<close> and \<open>Neg (Forall P)\<close>. Fitting therefore suggests to define an {\em alternative consistency property} as follows: \<close> definition alt_consistency :: \<open>('a, 'b) form set set \<Rightarrow> bool\<close> where \<open>alt_consistency C = (\<forall>S. S \<in> C \<longrightarrow> (\<forall>p ts. \<not> (Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S)) \<and> FF \<notin> S \<and> Neg TT \<notin> S \<and> (\<forall>Z. Neg (Neg Z) \<in> S \<longrightarrow> S \<union> {Z} \<in> C) \<and> (\<forall>A B. And A B \<in> S \<longrightarrow> S \<union> {A, B} \<in> C) \<and> (\<forall>A B. Neg (Or A B) \<in> S \<longrightarrow> S \<union> {Neg A, Neg B} \<in> C) \<and> (\<forall>A B. Or A B \<in> S \<longrightarrow> S \<union> {A} \<in> C \<or> S \<union> {B} \<in> C) \<and> (\<forall>A B. Neg (And A B) \<in> S \<longrightarrow> S \<union> {Neg A} \<in> C \<or> S \<union> {Neg B} \<in> C) \<and> (\<forall>A B. Impl A B \<in> S \<longrightarrow> S \<union> {Neg A} \<in> C \<or> S \<union> {B} \<in> C) \<and> (\<forall>A B. Neg (Impl A B) \<in> S \<longrightarrow> S \<union> {A, Neg B} \<in> C) \<and> (\<forall>P t. closedt 0 t \<longrightarrow> Forall P \<in> S \<longrightarrow> S \<union> {P[t/0]} \<in> C) \<and> (\<forall>P t. closedt 0 t \<longrightarrow> Neg (Exists P) \<in> S \<longrightarrow> S \<union> {Neg (P[t/0])} \<in> C) \<and> (\<forall>P x. (\<forall>a \<in> S. x \<notin> params a) \<longrightarrow> Exists P \<in> S \<longrightarrow> S \<union> {P[App x []/0]} \<in> C) \<and> (\<forall>P x. (\<forall>a \<in> S. x \<notin> params a) \<longrightarrow> Neg (Forall P) \<in> S \<longrightarrow> S \<union> {Neg (P[App x []/0])} \<in> C))\<close> text \<open> Note that in the clauses for \<open>Exists P\<close> and \<open>Neg (Forall P)\<close>, the first definition requires the existence of a parameter \<open>x\<close> with a certain property, whereas the second definition requires that all parameters \<open>x\<close> that are new for \<open>S\<close> have a certain property. A consistency property can easily be turned into an alternative consistency property by applying a suitable parameter substitution: \<close> definition mk_alt_consistency :: \<open>('a, 'b) form set set \<Rightarrow> ('a, 'b) form set set\<close> where \<open>mk_alt_consistency C = {S. \<exists>f. psubst f ` S \<in> C}\<close> theorem alt_consistency: assumes conc: \<open>consistency C\<close> shows \<open>alt_consistency (mk_alt_consistency C)\<close> (is \<open>alt_consistency ?C'\<close>) unfolding alt_consistency_def proof (intro allI impI conjI) fix f :: \<open>'a \<Rightarrow> 'a\<close> and S :: \<open>('a, 'b) form set\<close> assume \<open>S \<in> mk_alt_consistency C\<close> then obtain f where sc: \<open>psubst f ` S \<in> C\<close> (is \<open>?S' \<in> C\<close>) unfolding mk_alt_consistency_def by blast fix p ts show \<open>\<not> (Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S)\<close> proof assume *: \<open>Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S\<close> then have \<open>psubst f (Pred p ts) \<in> ?S'\<close> by blast then have \<open>Pred p (psubstts f ts) \<in> ?S'\<close> by simp then have \<open>Neg (Pred p (psubstts f ts)) \<notin> ?S'\<close> using conc sc by (simp add: consistency_def) then have \<open>Neg (Pred p ts) \<notin> S\<close> by force then show False using * by blast qed have \<open>FF \<notin> ?S'\<close> and \<open>Neg TT \<notin> ?S'\<close> using conc sc unfolding consistency_def by simp_all then show \<open>FF \<notin> S\<close> and \<open>Neg TT \<notin> S\<close> by (force, force) { fix Z assume \<open>Neg (Neg Z) \<in> S\<close> then have \<open>psubst f (Neg (Neg Z)) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {psubst f Z} \<in> C\<close> using conc sc by (simp add: consistency_def) then show \<open>S \<union> {Z} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix A B assume \<open>And A B \<in> S\<close> then have \<open>psubst f (And A B) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {psubst f A, psubst f B} \<in> C\<close> using conc sc by (simp add: consistency_def) then show \<open>S \<union> {A, B} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix A B assume \<open>Neg (Or A B) \<in> S\<close> then have \<open>psubst f (Neg (Or A B)) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {Neg (psubst f A), Neg (psubst f B)} \<in> C\<close> using conc sc by (simp add: consistency_def) then show \<open>S \<union> {Neg A, Neg B} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix A B assume \<open>Neg (Impl A B) \<in> S\<close> then have \<open>psubst f (Neg (Impl A B)) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {psubst f A, Neg (psubst f B)} \<in> C\<close> using conc sc by (simp add: consistency_def) then show \<open>S \<union> {A, Neg B} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix A B assume \<open>Or A B \<in> S\<close> then have \<open>psubst f (Or A B) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {psubst f A} \<in> C \<or> ?S' \<union> {psubst f B} \<in> C\<close> using conc sc by (simp add: consistency_def) then show \<open>S \<union> {A} \<in> ?C' \<or> S \<union> {B} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix A B assume \<open>Neg (And A B) \<in> S\<close> then have \<open>psubst f (Neg (And A B)) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {Neg (psubst f A)} \<in> C \<or> ?S' \<union> {Neg (psubst f B)} \<in> C\<close> using conc sc by (simp add: consistency_def) then show \<open>S \<union> {Neg A} \<in> ?C' \<or> S \<union> {Neg B} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix A B assume \<open>Impl A B \<in> S\<close> then have \<open>psubst f (Impl A B) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {Neg (psubst f A)} \<in> C \<or> ?S' \<union> {psubst f B} \<in> C\<close> using conc sc by (simp add: consistency_def) then show \<open>S \<union> {Neg A} \<in> ?C' \<or> S \<union> {B} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix P and t :: \<open>'a term\<close> assume \<open>closedt 0 t\<close> and \<open>Forall P \<in> S\<close> then have \<open>psubst f (Forall P) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {psubst f P[psubstt f t/0]} \<in> C\<close> using \<open>closedt 0 t\<close> conc sc by (simp add: consistency_def) then show \<open>S \<union> {P[t/0]} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix P and t :: \<open>'a term\<close> assume \<open>closedt 0 t\<close> and \<open>Neg (Exists P) \<in> S\<close> then have \<open>psubst f (Neg (Exists P)) \<in> ?S'\<close> by blast then have \<open>?S' \<union> {Neg (psubst f P[psubstt f t/0])} \<in> C\<close> using \<open>closedt 0 t\<close> conc sc by (simp add: consistency_def) then show \<open>S \<union> {Neg (P[t/0])} \<in> ?C'\<close> unfolding mk_alt_consistency_def by auto } { fix P :: \<open>('a, 'b) form\<close> and x f' assume \<open>\<forall>a \<in> S. x \<notin> params a\<close> and \<open>Exists P \<in> S\<close> moreover have \<open>psubst f (Exists P) \<in> ?S'\<close> using calculation by blast then have \<open>\<exists>y. ?S' \<union> {psubst f P[App y []/0]} \<in> C\<close> using conc sc by (simp add: consistency_def) then obtain y where \<open>?S' \<union> {psubst f P[App y []/0]} \<in> C\<close> by blast moreover have \<open>psubst (f(x := y)) ` S = ?S'\<close> using calculation by (simp cong add: image_cong) moreover have \<open>psubst (f(x := y)) ` S \<union> {psubst (f(x := y)) P[App ((f(x := y)) x) []/0]} \<in> C\<close> using calculation by auto ultimately have \<open>\<exists>f. psubst f ` S \<union> {psubst f P[App (f x) []/0]} \<in> C\<close> by blast then show \<open>S \<union> {P[App x []/0]} \<in> ?C'\<close> unfolding mk_alt_consistency_def by simp } { fix P :: \<open>('a, 'b) form\<close> and x assume \<open>\<forall>a \<in> S. x \<notin> params a\<close> and \<open>Neg (Forall P) \<in> S\<close> moreover have \<open>psubst f (Neg (Forall P)) \<in> ?S'\<close> using calculation by blast then have \<open>\<exists>y. ?S' \<union> {Neg (psubst f P[App y []/0])} \<in> C\<close> using conc sc by (simp add: consistency_def) then obtain y where \<open>?S' \<union> {Neg (psubst f P[App y []/0])} \<in> C\<close> by blast moreover have \<open>psubst (f(x := y)) ` S = ?S'\<close> using calculation by (simp cong add: image_cong) moreover have \<open>psubst (f(x := y)) ` S \<union> {Neg (psubst (f(x := y)) P[App ((f(x := y)) x) []/0])} \<in> C\<close> using calculation by auto ultimately have \<open>\<exists>f. psubst f ` S \<union> {Neg (psubst f P[App (f x) []/0])} \<in> C\<close> by blast then show \<open>S \<union> {Neg (P[App x []/0])} \<in> ?C'\<close> unfolding mk_alt_consistency_def by simp } qed theorem mk_alt_consistency_subset: \<open>C \<subseteq> mk_alt_consistency C\<close> unfolding mk_alt_consistency_def proof fix x assume \<open>x \<in> C\<close> then have \<open>psubst id ` x \<in> C\<close> by simp then have \<open>(\<exists>f. psubst f ` x \<in> C)\<close> by blast then show \<open>x \<in> {S. \<exists>f. psubst f ` S \<in> C}\<close> by simp qed subsection \<open>Closure under subsets\<close> text \<open> \label{sec:closure} We now show that a consistency property can be extended to one that is closed under subsets. \<close> definition close :: \<open>('a, 'b) form set set \<Rightarrow> ('a, 'b) form set set\<close> where \<open>close C = {S. \<exists>S' \<in> C. S \<subseteq> S'}\<close> definition subset_closed :: \<open>'a set set \<Rightarrow> bool\<close> where \<open>subset_closed C = (\<forall>S' \<in> C. \<forall>S. S \<subseteq> S' \<longrightarrow> S \<in> C)\<close> lemma subset_in_close: assumes \<open>S \<subseteq> S'\<close> shows \<open>S' \<union> x \<in> C \<longrightarrow> S \<union> x \<in> close C\<close> proof - have \<open>S' \<union> x \<in> close C \<longrightarrow> S \<union> x \<in> close C\<close> unfolding close_def using \<open>S \<subseteq> S'\<close> by blast then show ?thesis unfolding close_def by blast qed theorem close_consistency: assumes conc: \<open>consistency C\<close> shows \<open>consistency (close C)\<close> unfolding consistency_def proof (intro allI impI conjI) fix S assume \<open>S \<in> close C\<close> then obtain x where \<open>x \<in> C\<close> and \<open>S \<subseteq> x\<close> unfolding close_def by blast { fix p ts have \<open>\<not> (Pred p ts \<in> x \<and> Neg (Pred p ts) \<in> x)\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>\<not> (Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S)\<close> using \<open>S \<subseteq> x\<close> by blast } { have \<open>FF \<notin> x\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by blast then show \<open>FF \<notin> S\<close> using \<open>S \<subseteq> x\<close> by blast } { have \<open>Neg TT \<notin> x\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by blast then show \<open>Neg TT \<notin> S\<close> using \<open>S \<subseteq> x\<close> by blast } { fix Z assume \<open>Neg (Neg Z) \<in> S\<close> then have \<open>Neg (Neg Z) \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {Z} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>S \<union> {Z} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix A B assume \<open>And A B \<in> S\<close> then have \<open>And A B \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {A, B} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>S \<union> {A, B} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix A B assume \<open>Neg (Or A B) \<in> S\<close> then have \<open>Neg (Or A B) \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {Neg A, Neg B} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>S \<union> {Neg A, Neg B} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix A B assume \<open>Or A B \<in> S\<close> then have \<open>Or A B \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {A} \<in> C \<or> x \<union> {B} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>S \<union> {A} \<in> close C \<or> S \<union> {B} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix A B assume \<open>Neg (And A B) \<in> S\<close> then have \<open>Neg (And A B) \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {Neg A} \<in> C \<or> x \<union> {Neg B} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>S \<union> {Neg A} \<in> close C \<or> S \<union> {Neg B} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix A B assume \<open>Impl A B \<in> S\<close> then have \<open>Impl A B \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {Neg A} \<in> C \<or> x \<union> {B} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>S \<union> {Neg A} \<in> close C \<or> S \<union> {B} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix A B assume \<open>Neg (Impl A B) \<in> S\<close> then have \<open>Neg (Impl A B) \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {A, Neg B} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by blast then show \<open>S \<union> {A, Neg B} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix P and t :: \<open>'a term\<close> assume \<open>closedt 0 t\<close> and \<open>Forall P \<in> S\<close> then have \<open>Forall P \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {P[t/0]} \<in> C\<close> using \<open>closedt 0 t\<close> \<open>x \<in> C\<close> conc unfolding consistency_def by blast then show \<open>S \<union> {P[t/0]} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix P and t :: \<open>'a term\<close> assume \<open>closedt 0 t\<close> and \<open>Neg (Exists P) \<in> S\<close> then have \<open>Neg (Exists P) \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>x \<union> {Neg (P[t/0])} \<in> C\<close> using \<open>closedt 0 t\<close> \<open>x \<in> C\<close> conc unfolding consistency_def by blast then show \<open>S \<union> {Neg (P[t/0])} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix P assume \<open>Exists P \<in> S\<close> then have \<open>Exists P \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>\<exists>c. x \<union> {P[App c []/0]} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by blast then show \<open>\<exists>c. S \<union> {P[App c []/0]} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } { fix P assume \<open>Neg (Forall P) \<in> S\<close> then have \<open>Neg (Forall P) \<in> x\<close> using \<open>S \<subseteq> x\<close> by blast then have \<open>\<exists>c. x \<union> {Neg (P[App c []/0])} \<in> C\<close> using \<open>x \<in> C\<close> conc unfolding consistency_def by simp then show \<open>\<exists>c. S \<union> {Neg (P[App c []/0])} \<in> close C\<close> using \<open>S \<subseteq> x\<close> subset_in_close by blast } qed theorem close_closed: \<open>subset_closed (close C)\<close> unfolding close_def subset_closed_def by blast text \<open> If a consistency property \<open>C\<close> is closed under subsets, so is the corresponding alternative consistency property: \<close> theorem mk_alt_consistency_closed: assumes \<open>subset_closed C\<close> shows \<open>subset_closed (mk_alt_consistency C)\<close> unfolding subset_closed_def mk_alt_consistency_def proof (intro ballI allI impI) fix S S' :: \<open>('a, 'b) form set\<close> assume \<open>S \<subseteq> S'\<close> and \<open>S' \<in> {S. \<exists>f. psubst f ` S \<in> C}\<close> then obtain f where *: \<open>psubst f ` S' \<in> C\<close> by blast moreover have \<open>psubst f ` S \<subseteq> psubst f ` S'\<close> using \<open>S \<subseteq> S'\<close> by blast moreover have \<open>\<forall>S' \<in> C. \<forall>S \<subseteq> S'. S \<in> C\<close> using \<open>subset_closed C\<close> unfolding subset_closed_def by blast ultimately have \<open>psubst f ` S \<in> C\<close> by blast then show \<open>S \<in> {S. \<exists>f. psubst f ` S \<in> C}\<close> by blast qed subsection \<open>Finite character\<close> text \<open> \label{sec:finiteness} In this section, we show that an alternative consistency property can be extended to one of finite character. A set of sets \<open>C\<close> is said to be of finite character, provided that \<open>S\<close> is a member of \<open>C\<close> if and only if every subset of \<open>S\<close> is. \<close> definition finite_char :: \<open>'a set set \<Rightarrow> bool\<close> where \<open>finite_char C = (\<forall>S. S \<in> C = (\<forall>S'. finite S' \<longrightarrow> S' \<subseteq> S \<longrightarrow> S' \<in> C))\<close> definition mk_finite_char :: \<open>'a set set \<Rightarrow> 'a set set\<close> where \<open>mk_finite_char C = {S. \<forall>S'. S' \<subseteq> S \<longrightarrow> finite S' \<longrightarrow> S' \<in> C}\<close> theorem finite_alt_consistency: assumes altconc: \<open>alt_consistency C\<close> and \<open>subset_closed C\<close> shows \<open>alt_consistency (mk_finite_char C)\<close> unfolding alt_consistency_def proof (intro allI impI conjI) fix S assume \<open>S \<in> mk_finite_char C\<close> then have finc: \<open>\<forall>S' \<subseteq> S. finite S' \<longrightarrow> S' \<in> C\<close> unfolding mk_finite_char_def by blast have \<open>\<forall>S' \<in> C. \<forall>S \<subseteq> S'. S \<in> C\<close> using \<open>subset_closed C\<close> unfolding subset_closed_def by blast then have sc: \<open>\<forall>S' x. S' \<union> x \<in> C \<longrightarrow> (\<forall>S \<subseteq> S' \<union> x. S \<in> C)\<close> by blast { fix p ts show \<open>\<not> (Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S)\<close> proof assume \<open>Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S\<close> then have \<open>{Pred p ts, Neg (Pred p ts)} \<in> C\<close> using finc by simp then show False using altconc unfolding alt_consistency_def by fast qed } show \<open>FF \<notin> S\<close> proof assume \<open>FF \<in> S\<close> then have \<open>{FF} \<in> C\<close> using finc by simp then show False using altconc unfolding alt_consistency_def by fast qed show \<open>Neg TT \<notin> S\<close> proof assume \<open>Neg TT \<in> S\<close> then have \<open>{Neg TT} \<in> C\<close> using finc by simp then show False using altconc unfolding alt_consistency_def by fast qed { fix Z assume *: \<open>Neg (Neg Z) \<in> S\<close> show \<open>S \<union> {Z} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {Z} \<union> {Neg (Neg Z)}\<close> assume \<open>S' \<subseteq> S \<union> {Z}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {Z} \<in> C\<close> using altconc unfolding alt_consistency_def by simp then show \<open>S' \<in> C\<close> using sc by blast qed } { fix A B assume *: \<open>And A B \<in> S\<close> show \<open>S \<union> {A, B} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {A, B} \<union> {And A B}\<close> assume \<open>S' \<subseteq> S \<union> {A, B}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {A, B} \<in> C\<close> using altconc unfolding alt_consistency_def by simp then show \<open>S' \<in> C\<close> using sc by blast qed } { fix A B assume *: \<open>Neg (Or A B) \<in> S\<close> show \<open>S \<union> {Neg A, Neg B} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {Neg A, Neg B} \<union> {Neg (Or A B)}\<close> assume \<open>S' \<subseteq> S \<union> {Neg A, Neg B}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {Neg A, Neg B} \<in> C\<close> using altconc unfolding alt_consistency_def by simp then show \<open>S' \<in> C\<close> using sc by blast qed } { fix A B assume *: \<open>Neg (Impl A B) \<in> S\<close> show \<open>S \<union> {A, Neg B} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {A, Neg B} \<union> {Neg (Impl A B)}\<close> assume \<open>S' \<subseteq> S \<union> {A, Neg B}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {A, Neg B} \<in> C\<close> using altconc unfolding alt_consistency_def by simp then show \<open>S' \<in> C\<close> using sc by blast qed } { fix A B assume *: \<open>Or A B \<in> S\<close> show \<open>S \<union> {A} \<in> mk_finite_char C \<or> S \<union> {B} \<in> mk_finite_char C\<close> proof (rule ccontr) assume \<open>\<not> ?thesis\<close> then obtain Sa and Sb where \<open>Sa \<subseteq> S \<union> {A}\<close> and \<open>finite Sa\<close> and \<open>Sa \<notin> C\<close> and \<open>Sb \<subseteq> S \<union> {B}\<close> and \<open>finite Sb\<close> and \<open>Sb \<notin> C\<close> unfolding mk_finite_char_def by blast let ?S' = \<open>(Sa - {A}) \<union> (Sb - {B}) \<union> {Or A B}\<close> have \<open>?S' \<subseteq> S\<close> using \<open>Sa \<subseteq> S \<union> {A}\<close> \<open>Sb \<subseteq> S \<union> {B}\<close> * by blast moreover have \<open>finite ?S'\<close> using \<open>finite Sa\<close> \<open>finite Sb\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {A} \<in> C \<or> ?S' \<union> {B} \<in> C\<close> using altconc unfolding alt_consistency_def by simp then have \<open>Sa \<in> C \<or> Sb \<in> C\<close> using sc by blast then show False using \<open>Sa \<notin> C\<close> \<open>Sb \<notin> C\<close> by blast qed } { fix A B assume *: \<open>Neg (And A B) \<in> S\<close> show \<open>S \<union> {Neg A} \<in> mk_finite_char C \<or> S \<union> {Neg B} \<in> mk_finite_char C\<close> proof (rule ccontr) assume \<open>\<not> ?thesis\<close> then obtain Sa and Sb where \<open>Sa \<subseteq> S \<union> {Neg A}\<close> and \<open>finite Sa\<close> and \<open>Sa \<notin> C\<close> and \<open>Sb \<subseteq> S \<union> {Neg B}\<close> and \<open>finite Sb\<close> and \<open>Sb \<notin> C\<close> unfolding mk_finite_char_def by blast let ?S' = \<open>(Sa - {Neg A}) \<union> (Sb - {Neg B}) \<union> {Neg (And A B)}\<close> have \<open>?S' \<subseteq> S\<close> using \<open>Sa \<subseteq> S \<union> {Neg A}\<close> \<open>Sb \<subseteq> S \<union> {Neg B}\<close> * by blast moreover have \<open>finite ?S'\<close> using \<open>finite Sa\<close> \<open>finite Sb\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {Neg A} \<in> C \<or> ?S' \<union> {Neg B} \<in> C\<close> using altconc unfolding alt_consistency_def by simp then have \<open>Sa \<in> C \<or> Sb \<in> C\<close> using sc by blast then show False using \<open>Sa \<notin> C\<close> \<open>Sb \<notin> C\<close> by blast qed } { fix A B assume *: \<open>Impl A B \<in> S\<close> show \<open>S \<union> {Neg A} \<in> mk_finite_char C \<or> S \<union> {B} \<in> mk_finite_char C\<close> proof (rule ccontr) assume \<open>\<not> ?thesis\<close> then obtain Sa and Sb where \<open>Sa \<subseteq> S \<union> {Neg A}\<close> and \<open>finite Sa\<close> and \<open>Sa \<notin> C\<close> and \<open>Sb \<subseteq> S \<union> {B}\<close> and \<open>finite Sb\<close> and \<open>Sb \<notin> C\<close> unfolding mk_finite_char_def by blast let ?S' = \<open>(Sa - {Neg A}) \<union> (Sb - {B}) \<union> {Impl A B}\<close> have \<open>?S' \<subseteq> S\<close> using \<open>Sa \<subseteq> S \<union> {Neg A}\<close> \<open>Sb \<subseteq> S \<union> {B}\<close> * by blast moreover have \<open>finite ?S'\<close> using \<open>finite Sa\<close> \<open>finite Sb\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {Neg A} \<in> C \<or> ?S' \<union> {B} \<in> C\<close> using altconc unfolding alt_consistency_def by simp then have \<open>Sa \<in> C \<or> Sb \<in> C\<close> using sc by blast then show False using \<open>Sa \<notin> C\<close> \<open>Sb \<notin> C\<close> by blast qed } { fix P and t :: \<open>'a term\<close> assume *: \<open>Forall P \<in> S\<close> and \<open>closedt 0 t\<close> show \<open>S \<union> {P[t/0]} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {P[t/0]} \<union> {Forall P}\<close> assume \<open>S' \<subseteq> S \<union> {P[t/0]}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {P[t/0]} \<in> C\<close> using altconc \<open>closedt 0 t\<close> unfolding alt_consistency_def by simp then show \<open>S' \<in> C\<close> using sc by blast qed } { fix P and t :: \<open>'a term\<close> assume *: \<open>Neg (Exists P) \<in> S\<close> and \<open>closedt 0 t\<close> show \<open>S \<union> {Neg (P[t/0])} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {Neg (P[t/0])} \<union> {Neg (Exists P)}\<close> assume \<open>S' \<subseteq> S \<union> {Neg (P[t/0])}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast then have \<open>?S' \<union> {Neg (P[t/0])} \<in> C\<close> using altconc \<open>closedt 0 t\<close> unfolding alt_consistency_def by simp then show \<open>S' \<in> C\<close> using sc by blast qed } { fix P x assume *: \<open>Exists P \<in> S\<close> and \<open>\<forall>a \<in> S. x \<notin> params a\<close> show \<open>S \<union> {P[App x []/0]} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {P[App x []/0]} \<union> {Exists P}\<close> assume \<open>S' \<subseteq> S \<union> {P[App x []/0]}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast moreover have \<open>\<forall>a \<in> ?S'. x \<notin> params a\<close> using \<open>\<forall>a \<in> S. x \<notin> params a\<close> \<open>?S' \<subseteq> S\<close> by blast ultimately have \<open>?S' \<union> {P[App x []/0]} \<in> C\<close> using altconc \<open>\<forall>a \<in> S. x \<notin> params a\<close> unfolding alt_consistency_def by blast then show \<open>S' \<in> C\<close> using sc by blast qed } { fix P x assume *: \<open>Neg (Forall P) \<in> S\<close> and \<open>\<forall>a \<in> S. x \<notin> params a\<close> show \<open>S \<union> {Neg (P[App x []/0])} \<in> mk_finite_char C\<close> unfolding mk_finite_char_def proof (intro allI impI CollectI) fix S' let ?S' = \<open>S' - {Neg (P[App x []/0])} \<union> {Neg (Forall P)}\<close> assume \<open>S' \<subseteq> S \<union> {Neg (P[App x []/0])}\<close> and \<open>finite S'\<close> then have \<open>?S' \<subseteq> S\<close> using * by blast moreover have \<open>finite ?S'\<close> using \<open>finite S'\<close> by blast ultimately have \<open>?S' \<in> C\<close> using finc by blast moreover have \<open>\<forall>a \<in> ?S'. x \<notin> params a\<close> using \<open>\<forall>a \<in> S. x \<notin> params a\<close> \<open>?S' \<subseteq> S\<close> by blast ultimately have \<open>?S' \<union> {Neg (P[App x []/0])} \<in> C\<close> using altconc \<open>\<forall>a \<in> S. x \<notin> params a\<close> unfolding alt_consistency_def by simp then show \<open>S' \<in> C\<close> using sc by blast qed } qed theorem finite_char: \<open>finite_char (mk_finite_char C)\<close> unfolding finite_char_def mk_finite_char_def by blast theorem finite_char_closed: \<open>finite_char C \<Longrightarrow> subset_closed C\<close> unfolding finite_char_def subset_closed_def proof (intro ballI allI impI) fix S S' assume *: \<open>\<forall>S. (S \<in> C) = (\<forall>S'. finite S' \<longrightarrow> S' \<subseteq> S \<longrightarrow> S' \<in> C)\<close> and \<open>S' \<in> C\<close> and \<open>S \<subseteq> S'\<close> then have \<open>\<forall>S'. finite S' \<longrightarrow> S' \<subseteq> S \<longrightarrow> S' \<in> C\<close> by blast then show \<open>S \<in> C\<close> using * by blast qed theorem finite_char_subset: \<open>subset_closed C \<Longrightarrow> C \<subseteq> mk_finite_char C\<close> unfolding mk_finite_char_def subset_closed_def by blast subsection \<open>Enumerating datatypes\<close> text \<open> \label{sec:enumeration} As has already been mentioned earlier, the proof of the model existence theorem relies on the fact that the set of formulae is enumerable. Using the infrastructure for datatypes, the types @{type term} and @{type form} can automatically be shown to be a member of the @{class countable} type class: \<close> instance \<open>term\<close> :: (countable) countable by countable_datatype instance form :: (countable, countable) countable by countable_datatype subsection \<open>Extension to maximal consistent sets\<close> text \<open> \label{sec:extend} Given a set \<open>C\<close> of finite character, we show that the least upper bound of a chain of sets that are elements of \<open>C\<close> is again an element of \<open>C\<close>. \<close> definition is_chain :: \<open>(nat \<Rightarrow> 'a set) \<Rightarrow> bool\<close> where \<open>is_chain f = (\<forall>n. f n \<subseteq> f (Suc n))\<close> theorem is_chainD: \<open>is_chain f \<Longrightarrow> x \<in> f m \<Longrightarrow> x \<in> f (m + n)\<close> by (induct n) (auto simp: is_chain_def) theorem is_chainD': assumes \<open>is_chain f\<close> and \<open>x \<in> f m\<close> and \<open>m \<le> k\<close> shows \<open>x \<in> f k\<close> proof - have \<open>\<exists>n. k = m + n\<close> using \<open>m \<le> k\<close> by (simp add: le_iff_add) then obtain n where \<open>k = m + n\<close> by blast then show \<open>x \<in> f k\<close> using \<open>is_chain f\<close> \<open>x \<in> f m\<close> by (simp add: is_chainD) qed theorem chain_index: assumes ch: \<open>is_chain f\<close> and fin: \<open>finite F\<close> shows \<open>F \<subseteq> (\<Union>n. f n) \<Longrightarrow> \<exists>n. F \<subseteq> f n\<close> using fin proof (induct rule: finite_induct) case empty then show ?case by blast next case (insert x F) then have \<open>\<exists>n. F \<subseteq> f n\<close> and \<open>\<exists>m. x \<in> f m\<close> and \<open>F \<subseteq> (\<Union>x. f x)\<close> using ch by simp_all then obtain n and m where \<open>F \<subseteq> f n\<close> and \<open>x \<in> f m\<close> by blast have \<open>m \<le> max n m\<close> and \<open>n \<le> max n m\<close> by simp_all have \<open>x \<in> f (max n m)\<close> using is_chainD' ch \<open>x \<in> f m\<close> \<open>m \<le> max n m\<close> by fast moreover have \<open>F \<subseteq> f (max n m)\<close> using is_chainD' ch \<open>F \<subseteq> f n\<close> \<open>n \<le> max n m\<close> by fast moreover have \<open>x \<in> f (max n m) \<and> F \<subseteq> f (max n m)\<close> using calculation by blast ultimately show ?case by blast qed lemma chain_union_closed': assumes \<open>is_chain f\<close> and \<open>(\<forall>n. f n \<in> C)\<close> and \<open>\<forall>S' \<in> C. \<forall>S \<subseteq> S'. S \<in> C\<close> and \<open>finite S'\<close> and \<open>S' \<subseteq> (\<Union>n. f n)\<close> shows \<open>S' \<in> C\<close> proof - note \<open>finite S'\<close> and \<open>S' \<subseteq> (\<Union>n. f n)\<close> then obtain n where \<open>S' \<subseteq> f n\<close> using chain_index \<open>is_chain f\<close> by blast moreover have \<open>f n \<in> C\<close> using \<open>\<forall>n. f n \<in> C\<close> by blast ultimately show \<open>S' \<in> C\<close> using \<open>\<forall>S' \<in> C. \<forall>S \<subseteq> S'. S \<in> C\<close> by blast qed theorem chain_union_closed: assumes \<open>finite_char C\<close> and \<open>is_chain f\<close> and \<open>\<forall>n. f n \<in> C\<close> shows \<open>(\<Union>n. f n) \<in> C\<close> proof - have \<open>subset_closed C\<close> using finite_char_closed \<open>finite_char C\<close> by blast then have \<open>\<forall>S' \<in> C. \<forall>S \<subseteq> S'. S \<in> C\<close> using subset_closed_def by blast then have \<open>\<forall>S'. finite S' \<longrightarrow> S' \<subseteq> (\<Union>n. f n) \<longrightarrow> S' \<in> C\<close> using chain_union_closed' assms by blast moreover have \<open>((\<Union>n. f n) \<in> C) = (\<forall>S'. finite S' \<longrightarrow> S' \<subseteq> (\<Union>n. f n) \<longrightarrow> S' \<in> C)\<close> using \<open>finite_char C\<close> unfolding finite_char_def by blast ultimately show ?thesis by blast qed text \<open> We can now define a function \<open>Extend\<close> that extends a consistent set to a maximal consistent set. To this end, we first define an auxiliary function \<open>extend\<close> that produces the elements of an ascending chain of consistent sets. \<close> primrec (nonexhaustive) dest_Neg :: \<open>('a, 'b) form \<Rightarrow> ('a, 'b) form\<close> where \<open>dest_Neg (Neg p) = p\<close> primrec (nonexhaustive) dest_Forall :: \<open>('a, 'b) form \<Rightarrow> ('a, 'b) form\<close> where \<open>dest_Forall (Forall p) = p\<close> primrec (nonexhaustive) dest_Exists :: \<open>('a, 'b) form \<Rightarrow> ('a, 'b) form\<close> where \<open>dest_Exists (Exists p) = p\<close> primrec extend :: \<open>(nat, 'b) form set \<Rightarrow> (nat, 'b) form set set \<Rightarrow> (nat \<Rightarrow> (nat, 'b) form) \<Rightarrow> nat \<Rightarrow> (nat, 'b) form set\<close> where \<open>extend S C f 0 = S\<close> | \<open>extend S C f (Suc n) = (if extend S C f n \<union> {f n} \<in> C then (if (\<exists>p. f n = Exists p) then extend S C f n \<union> {f n} \<union> {subst (dest_Exists (f n)) (App (SOME k. k \<notin> (\<Union>p \<in> extend S C f n \<union> {f n}. params p)) []) 0} else if (\<exists>p. f n = Neg (Forall p)) then extend S C f n \<union> {f n} \<union> {Neg (subst (dest_Forall (dest_Neg (f n))) (App (SOME k. k \<notin> (\<Union>p \<in> extend S C f n \<union> {f n}. params p)) []) 0)} else extend S C f n \<union> {f n}) else extend S C f n)\<close> definition Extend :: \<open>(nat, 'b) form set \<Rightarrow> (nat, 'b) form set set \<Rightarrow> (nat \<Rightarrow> (nat, 'b) form) \<Rightarrow> (nat, 'b) form set\<close> where \<open>Extend S C f = (\<Union>n. extend S C f n)\<close> theorem is_chain_extend: \<open>is_chain (extend S C f)\<close> by (simp add: is_chain_def) blast theorem finite_paramst [simp]: \<open>finite (paramst (t :: 'a term))\<close> \<open>finite (paramsts (ts :: 'a term list))\<close> by (induct t and ts rule: paramst.induct paramsts.induct) (simp_all split: sum.split) theorem finite_params [simp]: \<open>finite (params p)\<close> by (induct p) simp_all theorem finite_params_extend [simp]: \<open>infinite (\<Inter>p \<in> S. - params p) \<Longrightarrow> infinite (\<Inter>p \<in> extend S C f n. - params p)\<close> by (induct n) simp_all lemma infinite_params_available: assumes \<open>infinite (- (\<Union>p \<in> S. params p))\<close> shows \<open>\<exists>x. x \<notin> (\<Union>p \<in> extend S C f n \<union> {f n}. params p)\<close> proof - let ?S' = \<open>extend S C f n \<union> {f n}\<close> have \<open>infinite (- (\<Union>x \<in> ?S'. params x))\<close> using assms by simp then obtain x where \<open>x \<in> - (\<Union>x \<in> ?S'. params x)\<close> using infinite_imp_nonempty by blast then have \<open>\<forall>a \<in> ?S'. x \<notin> params a\<close> by blast then show ?thesis by blast qed lemma extend_in_C_Exists: assumes \<open>alt_consistency C\<close> and \<open>infinite (- (\<Union>p \<in> S. params p))\<close> and \<open>extend S C f n \<union> {f n} \<in> C\<close> (is \<open>?S' \<in> C\<close>) and \<open>\<exists>p. f n = Exists p\<close> shows \<open>extend S C f (Suc n) \<in> C\<close> proof - obtain p where *: \<open>f n = Exists p\<close> using \<open>\<exists>p. f n = Exists p\<close> by blast have \<open>\<exists>x. x \<notin> (\<Union>p \<in> ?S'. params p)\<close> using \<open>infinite (- (\<Union>p \<in> S. params p))\<close> infinite_params_available by blast moreover have \<open>Exists p \<in> ?S'\<close> using * by simp then have \<open>\<forall>x. x \<notin> (\<Union>p \<in> ?S'. params p) \<longrightarrow> ?S' \<union> {p[App x []/0]} \<in> C\<close> using \<open>?S' \<in> C\<close> \<open>alt_consistency C\<close> unfolding alt_consistency_def by simp ultimately have \<open>(?S' \<union> {p[App (SOME k. k \<notin> (\<Union>p \<in> ?S'. params p)) []/0]}) \<in> C\<close> by (metis (mono_tags, lifting) someI2) then show ?thesis using assms * by simp qed lemma extend_in_C_Neg_Forall: assumes \<open>alt_consistency C\<close> and \<open>infinite (- (\<Union>p \<in> S. params p))\<close> and \<open>extend S C f n \<union> {f n} \<in> C\<close> (is \<open>?S' \<in> C\<close>) and \<open>\<forall>p. f n \<noteq> Exists p\<close> and \<open>\<exists>p. f n = Neg (Forall p)\<close> shows \<open>extend S C f (Suc n) \<in> C\<close> proof - obtain p where *: \<open>f n = Neg (Forall p)\<close> using \<open>\<exists>p. f n = Neg (Forall p)\<close> by blast have \<open>\<exists>x. x \<notin> (\<Union>p \<in> ?S'. params p)\<close> using \<open>infinite (- (\<Union>p \<in> S. params p))\<close> infinite_params_available by blast moreover have \<open>Neg (Forall p) \<in> ?S'\<close> using * by simp then have \<open>\<forall>x. x \<notin> (\<Union>p \<in> ?S'. params p) \<longrightarrow> ?S' \<union> {Neg (p[App x []/0])} \<in> C\<close> using \<open>?S' \<in> C\<close> \<open>alt_consistency C\<close> unfolding alt_consistency_def by simp ultimately have \<open>(?S' \<union> {Neg (p[App (SOME k. k \<notin> (\<Union>p \<in> ?S'. params p)) []/0])}) \<in> C\<close> by (metis (mono_tags, lifting) someI2) then show ?thesis using assms * by simp qed lemma extend_in_C_no_delta: assumes \<open>extend S C f n \<union> {f n} \<in> C\<close> and \<open>\<forall>p. f n \<noteq> Exists p\<close> and \<open>\<forall>p. f n \<noteq> Neg (Forall p)\<close> shows \<open>extend S C f (Suc n) \<in> C\<close> using assms by simp lemma extend_in_C_stop: assumes \<open>extend S C f n \<in> C\<close> and \<open>extend S C f n \<union> {f n} \<notin> C\<close> shows \<open>extend S C f (Suc n) \<in> C\<close> using assms by simp theorem extend_in_C: \<open>alt_consistency C \<Longrightarrow> S \<in> C \<Longrightarrow> infinite (- (\<Union>p \<in> S. params p)) \<Longrightarrow> extend S C f n \<in> C\<close> proof (induct n) case 0 then show ?case by simp next case (Suc n) then show ?case using extend_in_C_Exists extend_in_C_Neg_Forall extend_in_C_no_delta extend_in_C_stop by metis qed text \<open> The main theorem about \<open>Extend\<close> says that if \<open>C\<close> is an alternative consistency property that is of finite character, \<open>S\<close> is consistent and \<open>S\<close> uses only finitely many parameters, then \<open>Extend S C f\<close> is again consistent. \<close> theorem Extend_in_C: \<open>alt_consistency C \<Longrightarrow> finite_char C \<Longrightarrow> S \<in> C \<Longrightarrow> infinite (- (\<Union>p \<in> S. params p)) \<Longrightarrow> Extend S C f \<in> C\<close> unfolding Extend_def using chain_union_closed is_chain_extend extend_in_C by blast theorem Extend_subset: \<open>S \<subseteq> Extend S C f\<close> proof fix x assume \<open>x \<in> S\<close> then have \<open>x \<in> extend S C f 0\<close> by simp then have \<open>\<exists>n. x \<in> extend S C f n\<close> by blast then show \<open>x \<in> Extend S C f\<close> by (simp add: Extend_def) qed text \<open> The \<open>Extend\<close> function yields a maximal set: \<close> definition maximal :: \<open>'a set \<Rightarrow> 'a set set \<Rightarrow> bool\<close> where \<open>maximal S C = (\<forall>S' \<in> C. S \<subseteq> S' \<longrightarrow> S = S')\<close> theorem extend_maximal: assumes \<open>\<forall>y. \<exists>n. y = f n\<close> and \<open>finite_char C\<close> shows \<open>maximal (Extend S C f) C\<close> unfolding maximal_def Extend_def proof (intro ballI impI) fix S' assume \<open>S' \<in> C\<close> and \<open>(\<Union>x. extend S C f x) \<subseteq> S'\<close> moreover have \<open>S' \<subseteq> (\<Union>x. extend S C f x)\<close> proof (rule ccontr) assume \<open>\<not> S' \<subseteq> (\<Union>x. extend S C f x)\<close> then have \<open>\<exists>z. z \<in> S' \<and> z \<notin> (\<Union>x. extend S C f x)\<close> by blast then obtain z where \<open>z \<in> S'\<close> and *: \<open>z \<notin> (\<Union>x. extend S C f x)\<close> by blast then obtain n where \<open>z = f n\<close> using \<open>\<forall>y. \<exists>n. y = f n\<close> by blast from \<open>(\<Union>x. extend S C f x) \<subseteq> S'\<close> \<open>z = f n\<close> \<open>z \<in> S'\<close> have \<open>extend S C f n \<union> {f n} \<subseteq> S'\<close> by blast from \<open>finite_char C\<close> have \<open>subset_closed C\<close> using finite_char_closed by blast then have \<open>\<forall>S' \<in> C. \<forall>S \<subseteq> S'. S \<in> C\<close> unfolding subset_closed_def by simp then have \<open>\<forall>S \<subseteq> S'. S \<in> C\<close> using \<open>S' \<in> C\<close> by blast then have \<open>extend S C f n \<union> {f n} \<in> C\<close> using \<open>extend S C f n \<union> {f n} \<subseteq> S'\<close> by blast then have \<open>z \<in> extend S C f (Suc n)\<close> using \<open>z \<notin> (\<Union>x. extend S C f x)\<close> \<open>z = f n\<close> by simp then show False using * by blast qed ultimately show \<open>(\<Union>x. extend S C f x) = S'\<close> by simp qed subsection \<open>Hintikka sets and Herbrand models\<close> text \<open> \label{sec:hintikka} A Hintikka set is defined as follows: \<close> definition hintikka :: \<open>('a, 'b) form set \<Rightarrow> bool\<close> where \<open>hintikka H = ((\<forall>p ts. \<not> (Pred p ts \<in> H \<and> Neg (Pred p ts) \<in> H)) \<and> FF \<notin> H \<and> Neg TT \<notin> H \<and> (\<forall>Z. Neg (Neg Z) \<in> H \<longrightarrow> Z \<in> H) \<and> (\<forall>A B. And A B \<in> H \<longrightarrow> A \<in> H \<and> B \<in> H) \<and> (\<forall>A B. Neg (Or A B) \<in> H \<longrightarrow> Neg A \<in> H \<and> Neg B \<in> H) \<and> (\<forall>A B. Or A B \<in> H \<longrightarrow> A \<in> H \<or> B \<in> H) \<and> (\<forall>A B. Neg (And A B) \<in> H \<longrightarrow> Neg A \<in> H \<or> Neg B \<in> H) \<and> (\<forall>A B. Impl A B \<in> H \<longrightarrow> Neg A \<in> H \<or> B \<in> H) \<and> (\<forall>A B. Neg (Impl A B) \<in> H \<longrightarrow> A \<in> H \<and> Neg B \<in> H) \<and> (\<forall>P t. closedt 0 t \<longrightarrow> Forall P \<in> H \<longrightarrow> subst P t 0 \<in> H) \<and> (\<forall>P t. closedt 0 t \<longrightarrow> Neg (Exists P) \<in> H \<longrightarrow> Neg (subst P t 0) \<in> H) \<and> (\<forall>P. Exists P \<in> H \<longrightarrow> (\<exists>t. closedt 0 t \<and> subst P t 0 \<in> H)) \<and> (\<forall>P. Neg (Forall P) \<in> H \<longrightarrow> (\<exists>t. closedt 0 t \<and> Neg (subst P t 0) \<in> H)))\<close> text \<open> In Herbrand models, each {\em closed} term is interpreted by itself. We introduce a new datatype \<open>hterm\<close> (``Herbrand terms''), which is similar to the datatype \<open>term\<close> introduced in \secref{sec:terms}, but without variables. We also define functions for converting between closed terms and Herbrand terms. \<close> datatype 'a hterm = HApp 'a \<open>'a hterm list\<close> primrec term_of_hterm :: \<open>'a hterm \<Rightarrow> 'a term\<close> and terms_of_hterms :: \<open>'a hterm list \<Rightarrow> 'a term list\<close> where \<open>term_of_hterm (HApp a hts) = App a (terms_of_hterms hts)\<close> | \<open>terms_of_hterms [] = []\<close> | \<open>terms_of_hterms (ht # hts) = term_of_hterm ht # terms_of_hterms hts\<close> theorem herbrand_evalt [simp]: \<open>closedt 0 t \<Longrightarrow> term_of_hterm (evalt e HApp t) = t\<close> \<open>closedts 0 ts \<Longrightarrow> terms_of_hterms (evalts e HApp ts) = ts\<close> by (induct t and ts rule: closedt.induct closedts.induct) simp_all theorem herbrand_evalt' [simp]: \<open>evalt e HApp (term_of_hterm ht) = ht\<close> \<open>evalts e HApp (terms_of_hterms hts) = hts\<close> by (induct ht and hts rule: term_of_hterm.induct terms_of_hterms.induct) simp_all theorem closed_hterm [simp]: \<open>closedt 0 (term_of_hterm (ht::'a hterm))\<close> \<open>closedts 0 (terms_of_hterms (hts::'a hterm list))\<close> by (induct ht and hts rule: term_of_hterm.induct terms_of_hterms.induct) simp_all text \<open> We can prove that Hintikka sets are satisfiable in Herbrand models. Note that this theorem cannot be proved by a simple structural induction (as claimed in Fitting's book), since a parameter substitution has to be applied in the cases for quantifiers. However, since parameter substitution does not change the size of formulae, the theorem can be proved by well-founded induction on the size of the formula \<open>p\<close>. \<close> theorem hintikka_model: assumes hin: \<open>hintikka H\<close> shows \<open>(p \<in> H \<longrightarrow> closed 0 p \<longrightarrow> eval e HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) p) \<and> (Neg p \<in> H \<longrightarrow> closed 0 p \<longrightarrow> eval e HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) (Neg p))\<close> proof (induct p rule: wf_induct [where r=\<open>measure size_form\<close>]) show \<open>wf (measure size_form)\<close> by blast next let ?eval = \<open>eval e HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H)\<close> fix x assume wf: \<open>\<forall>y. (y, x) \<in> measure size_form \<longrightarrow> (y \<in> H \<longrightarrow> closed 0 y \<longrightarrow> ?eval y) \<and> (Neg y \<in> H \<longrightarrow> closed 0 y \<longrightarrow> ?eval (Neg y))\<close> show \<open>(x \<in> H \<longrightarrow> closed 0 x \<longrightarrow> ?eval x) \<and> (Neg x \<in> H \<longrightarrow> closed 0 x \<longrightarrow> ?eval (Neg x))\<close> proof (cases x) case FF show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> then show \<open>?eval x\<close> using FF hin by (simp add: hintikka_def) next assume \<open>Neg x \<in> H\<close> then show \<open>?eval (Neg x)\<close> using FF by simp qed next case TT show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> then show \<open>?eval x\<close> using TT by simp next assume \<open>Neg x \<in> H\<close> then show \<open>?eval (Neg x)\<close> using TT hin by (simp add: hintikka_def) qed next case (Pred p ts) show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> and \<open>closed 0 x\<close> then show \<open>?eval x\<close> using Pred by simp next assume \<open>Neg x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>Neg (Pred p ts) \<in> H\<close> using Pred by simp then have \<open>Pred p ts \<notin> H\<close> using hin unfolding hintikka_def by fast then show \<open>?eval (Neg x)\<close> using Pred \<open>closed 0 x\<close> by simp qed next case (Neg Z) then show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> and \<open>closed 0 x\<close> then show \<open>?eval x\<close> using Neg wf by simp next assume \<open>Neg x \<in> H\<close> then have \<open>Z \<in> H\<close> using Neg hin unfolding hintikka_def by blast moreover assume \<open>closed 0 x\<close> then have \<open>closed 0 Z\<close> using Neg by simp ultimately have \<open>?eval Z\<close> using Neg wf by simp then show \<open>?eval (Neg x)\<close> using Neg by simp qed next case (And A B) then show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>And A B \<in> H\<close> and \<open>closed 0 (And A B)\<close> using And by simp_all then have \<open>A \<in> H \<and> B \<in> H\<close> using And hin unfolding hintikka_def by blast then show \<open>?eval x\<close> using And wf \<open>closed 0 (And A B)\<close> by simp next assume \<open>Neg x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>Neg (And A B) \<in> H\<close> and \<open>closed 0 (And A B)\<close> using And by simp_all then have \<open>Neg A \<in> H \<or> Neg B \<in> H\<close> using hin unfolding hintikka_def by blast then show \<open>?eval (Neg x)\<close> using And wf \<open>closed 0 (And A B)\<close> by fastforce qed next case (Or A B) then show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>Or A B \<in> H\<close> and \<open>closed 0 (Or A B)\<close> using Or by simp_all then have \<open>A \<in> H \<or> B \<in> H\<close> using hin unfolding hintikka_def by blast then show \<open>?eval x\<close> using Or wf \<open>closed 0 (Or A B)\<close> by fastforce next assume \<open>Neg x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>Neg (Or A B) \<in> H\<close> and \<open>closed 0 (Or A B)\<close> using Or by simp_all then have \<open>Neg A \<in> H \<and> Neg B \<in> H\<close> using hin unfolding hintikka_def by blast then show \<open>?eval (Neg x)\<close> using Or wf \<open>closed 0 (Or A B)\<close> by simp qed next case (Impl A B) then show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>Impl A B \<in> H\<close> and \<open>closed 0 (Impl A B)\<close> using Impl by simp_all then have \<open>Neg A \<in> H \<or> B \<in> H\<close> using hin unfolding hintikka_def by blast then show \<open>?eval x\<close> using Impl wf \<open>closed 0 (Impl A B)\<close> by fastforce next assume \<open>Neg x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>Neg (Impl A B) \<in> H\<close> and \<open>closed 0 (Impl A B)\<close> using Impl by simp_all then have \<open>A \<in> H \<and> Neg B \<in> H\<close> using hin unfolding hintikka_def by blast then show \<open>?eval (Neg x)\<close> using Impl wf \<open>closed 0 (Impl A B)\<close> by simp qed next case (Forall P) then show ?thesis proof (intro conjI impI) assume \<open>x \<in> H\<close> and \<open>closed 0 x\<close> have \<open>\<forall>z. eval (e\<langle>0:z\<rangle>) HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) P\<close> proof (rule allI) fix z from \<open>x \<in> H\<close> and \<open>closed 0 x\<close> have \<open>Forall P \<in> H\<close> and \<open>closed 0 (Forall P)\<close> using Forall by simp_all then have *: \<open>\<forall>P t. closedt 0 t \<longrightarrow> Forall P \<in> H \<longrightarrow> P[t/0] \<in> H\<close> using hin unfolding hintikka_def by blast from \<open>closed 0 (Forall P)\<close> have \<open>closed (Suc 0) P\<close> by simp have \<open>(P[term_of_hterm z/0], Forall P) \<in> measure size_form \<longrightarrow> (P[term_of_hterm z/0] \<in> H \<longrightarrow> closed 0 (P[term_of_hterm z/0]) \<longrightarrow> ?eval (P[term_of_hterm z/0]))\<close> using Forall wf by blast then show \<open>eval (e\<langle>0:z\<rangle>) HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) P\<close> using * \<open>Forall P \<in> H\<close> \<open>closed (Suc 0) P\<close> by simp qed then show \<open>?eval x\<close> using Forall by simp next assume \<open>Neg x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>Neg (Forall P) \<in> H\<close> using Forall by simp then have \<open>\<exists>t. closedt 0 t \<and> Neg (P[t/0]) \<in> H\<close> using Forall hin unfolding hintikka_def by blast then obtain t where *: \<open>closedt 0 t \<and> Neg (P[t/0]) \<in> H\<close> by blast then have \<open>closed 0 (P[t/0])\<close> using Forall \<open>closed 0 x\<close> by simp have \<open>(subst P t 0, Forall P) \<in> measure size_form \<longrightarrow> (Neg (subst P t 0) \<in> H \<longrightarrow> closed 0 (subst P t 0) \<longrightarrow> ?eval (Neg (subst P t 0)))\<close> using Forall wf by blast then have \<open>?eval (Neg (P[t/0]))\<close> using Forall * \<open>closed 0 (P[t/0])\<close> by simp then have \<open>\<exists>z. \<not> eval (e\<langle>0:z\<rangle>) HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) P\<close> by auto then show \<open>?eval (Neg x)\<close> using Forall by simp qed next case (Exists P) then show ?thesis proof (intro conjI impI allI) assume \<open>x \<in> H\<close> and \<open>closed 0 x\<close> then have \<open>\<exists>t. closedt 0 t \<and> (P[t/0]) \<in> H\<close> using Exists hin unfolding hintikka_def by blast then obtain t where *: \<open>closedt 0 t \<and> (P[t/0]) \<in> H\<close> by blast then have \<open>closed 0 (P[t/0])\<close> using Exists \<open>closed 0 x\<close> by simp have \<open>(subst P t 0, Exists P) \<in> measure size_form \<longrightarrow> ((subst P t 0) \<in> H \<longrightarrow> closed 0 (subst P t 0) \<longrightarrow> ?eval (subst P t 0))\<close> using Exists wf by blast then have \<open>?eval (P[t/0])\<close> using Exists * \<open>closed 0 (P[t/0])\<close> by simp then have \<open>\<exists>z. eval (e\<langle>0:z\<rangle>) HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) P\<close> by auto then show \<open>?eval x\<close> using Exists by simp next assume \<open>Neg x \<in> H\<close> and \<open>closed 0 x\<close> have \<open>\<forall>z. \<not> eval (e\<langle>0:z\<rangle>) HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) P\<close> proof (rule allI) fix z from \<open>Neg x \<in> H\<close> and \<open>closed 0 x\<close> have \<open>Neg (Exists P) \<in> H\<close> and \<open>closed 0 (Neg (Exists P))\<close> using Exists by simp_all then have *: \<open>\<forall>P t. closedt 0 t \<longrightarrow> Neg (Exists P) \<in> H \<longrightarrow> Neg (P[t/0]) \<in> H\<close> using hin unfolding hintikka_def by blast from \<open>closed 0 (Neg (Exists P))\<close> have \<open>closed (Suc 0) P\<close> by simp have \<open>(P[term_of_hterm z/0], Exists P) \<in> measure size_form \<longrightarrow> (Neg (P[term_of_hterm z/0]) \<in> H \<longrightarrow> closed 0 (P[term_of_hterm z/0]) \<longrightarrow> ?eval (Neg (P[term_of_hterm z/0])))\<close> using Exists wf by blast then show \<open>\<not> eval (e\<langle>0:z\<rangle>) HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> H) P\<close> using * \<open>Neg (Exists P) \<in> H\<close> \<open>closed (Suc 0) P\<close> by simp qed then show \<open>?eval (Neg x)\<close> using Exists by simp qed qed qed text \<open> Using the maximality of @{term \<open>Extend S C f\<close>}, we can show that @{term \<open>Extend S C f\<close>} yields Hintikka sets: \<close> lemma Exists_in_extend: assumes \<open>extend S C f n \<union> {f n} \<in> C\<close> (is \<open>?S' \<in> C\<close>) and \<open>Exists P = f n\<close> shows \<open>P[(App (SOME k. k \<notin> (\<Union>p \<in> extend S C f n \<union> {f n}. params p)) [])/0] \<in> extend S C f (Suc n)\<close> (is \<open>subst P ?t 0 \<in> extend S C f (Suc n)\<close>) proof - have \<open>\<exists>p. f n = Exists p\<close> using \<open>Exists P = f n\<close> by metis then have \<open>extend S C f (Suc n) = (?S' \<union> {(dest_Exists (f n))[?t/0]})\<close> using \<open>?S' \<in> C\<close> by simp also have \<open>\<dots> = (?S' \<union> {(dest_Exists (Exists P))[?t/0]})\<close> using \<open>Exists P = f n\<close> by simp also have \<open>\<dots> = (?S' \<union> {P[?t/0]})\<close> by simp finally show ?thesis by blast qed lemma Neg_Forall_in_extend: assumes \<open>extend S C f n \<union> {f n} \<in> C\<close> (is \<open>?S' \<in> C\<close>) and \<open>Neg (Forall P) = f n\<close> shows \<open>Neg (P[(App (SOME k. k \<notin> (\<Union>p \<in> extend S C f n \<union> {f n}. params p)) [])/0]) \<in> extend S C f (Suc n)\<close> (is \<open>Neg (subst P ?t 0) \<in> extend S C f (Suc n)\<close>) proof - have \<open>f n \<noteq> Exists P\<close> using \<open>Neg (Forall P) = f n\<close> by auto have \<open>\<exists>p. f n = Neg (Forall p)\<close> using \<open>Neg (Forall P) = f n\<close> by metis then have \<open>extend S C f (Suc n) = (?S' \<union> {Neg (dest_Forall (dest_Neg (f n))[?t/0])})\<close> using \<open>?S' \<in> C\<close> \<open>f n \<noteq> Exists P\<close> by auto also have \<open>\<dots> = (?S' \<union> {Neg (dest_Forall (dest_Neg (Neg (Forall P)))[?t/0])})\<close> using \<open>Neg (Forall P) = f n\<close> by simp also have \<open>\<dots> = (?S' \<union> {Neg (P[?t/0])})\<close> by simp finally show ?thesis by blast qed theorem extend_hintikka: assumes fin_ch: \<open>finite_char C\<close> and infin_p: \<open>infinite (- (\<Union>p \<in> S. params p))\<close> and surj: \<open>\<forall>y. \<exists>n. y = f n\<close> and altc: \<open>alt_consistency C\<close> and \<open>S \<in> C\<close> shows \<open>hintikka (Extend S C f)\<close> (is \<open>hintikka ?H\<close>) unfolding hintikka_def proof (intro allI impI conjI) have \<open>maximal ?H C\<close> by (simp add: extend_maximal fin_ch surj) have \<open>?H \<in> C\<close> using Extend_in_C assms by blast have \<open>\<forall>S' \<in> C. ?H \<subseteq> S' \<longrightarrow> ?H = S'\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by blast { fix p ts show \<open>\<not> (Pred p ts \<in> ?H \<and> Neg (Pred p ts) \<in> ?H)\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by fast } show \<open>FF \<notin> ?H\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by blast show \<open>Neg TT \<notin> ?H\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by blast { fix Z assume \<open>Neg (Neg Z) \<in> ?H\<close> then have \<open>?H \<union> {Z} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by fast then show \<open>Z \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast } { fix A B assume \<open>And A B \<in> ?H\<close> then have \<open>?H \<union> {A, B} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by fast then show \<open>A \<in> ?H\<close> and \<open>B \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast+ } { fix A B assume \<open>Neg (Or A B) \<in> ?H\<close> then have \<open>?H \<union> {Neg A, Neg B} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by fast then show \<open>Neg A \<in> ?H\<close> and \<open>Neg B \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast+ } { fix A B assume \<open>Neg (Impl A B) \<in> ?H\<close> then have \<open>?H \<union> {A, Neg B} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by blast then show \<open>A \<in> ?H\<close> and \<open>Neg B \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast+ } { fix A B assume \<open>Or A B \<in> ?H\<close> then have \<open>?H \<union> {A} \<in> C \<or> ?H \<union> {B} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by fast then show \<open>A \<in> ?H \<or> B \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast } { fix A B assume \<open>Neg (And A B) \<in> ?H\<close> then have \<open>?H \<union> {Neg A} \<in> C \<or> ?H \<union> {Neg B} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by simp then show \<open>Neg A \<in> ?H \<or> Neg B \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast } { fix A B assume \<open>Impl A B \<in> ?H\<close> then have \<open>?H \<union> {Neg A} \<in> C \<or> ?H \<union> {B} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by simp then show \<open>Neg A \<in> ?H \<or> B \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast } { fix P and t :: \<open>nat term\<close> assume \<open>Forall P \<in> ?H\<close> and \<open>closedt 0 t\<close> then have \<open>?H \<union> {P[t/0]} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by blast then show \<open>P[t/0] \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast } { fix P and t :: \<open>nat term\<close> assume \<open>Neg (Exists P) \<in> ?H\<close> and \<open>closedt 0 t\<close> then have \<open>?H \<union> {Neg (P[t/0])} \<in> C\<close> using \<open>?H \<in> C\<close> altc unfolding alt_consistency_def by blast then show \<open>Neg (P[t/0]) \<in> ?H\<close> using \<open>maximal ?H C\<close> unfolding maximal_def by fast } { fix P assume \<open>Exists P \<in> ?H\<close> obtain n where *: \<open>Exists P = f n\<close> using surj by blast let ?t = \<open>App (SOME k. k \<notin> (\<Union>p \<in> extend S C f n \<union> {f n}. params p)) []\<close> have \<open>closedt 0 ?t\<close> by simp have \<open>Exists P \<in> (\<Union>n. extend S C f n)\<close> using \<open>Exists P \<in> ?H\<close> Extend_def by blast then have \<open>extend S C f n \<union> {f n} \<subseteq> (\<Union>n. extend S C f n)\<close> using * by (simp add: UN_upper) then have \<open>extend S C f n \<union> {f n} \<in> C\<close> using Extend_def \<open>Extend S C f \<in> C\<close> fin_ch finite_char_closed unfolding subset_closed_def by metis then have \<open>P[?t/0] \<in> extend S C f (Suc n)\<close> using * Exists_in_extend by blast then have \<open>P[?t/0] \<in> ?H\<close> using Extend_def by blast then show \<open>\<exists>t. closedt 0 t \<and> P[t/0] \<in> ?H\<close> using \<open>closedt 0 ?t\<close> by blast } { fix P assume \<open>Neg (Forall P) \<in> ?H\<close> obtain n where *: \<open>Neg (Forall P) = f n\<close> using surj by blast let ?t = \<open>App (SOME k. k \<notin> (\<Union>p \<in> extend S C f n \<union> {f n}. params p)) []\<close> have \<open>closedt 0 ?t\<close> by simp have \<open>Neg (Forall P) \<in> (\<Union>n. extend S C f n)\<close> using \<open>Neg (Forall P) \<in> ?H\<close> Extend_def by blast then have \<open>extend S C f n \<union> {f n} \<subseteq> (\<Union>n. extend S C f n)\<close> using * by (simp add: UN_upper) then have \<open>extend S C f n \<union> {f n} \<in> C\<close> using Extend_def \<open>Extend S C f \<in> C\<close> fin_ch finite_char_closed unfolding subset_closed_def by metis then have \<open>Neg (P[?t/0]) \<in> extend S C f (Suc n)\<close> using * Neg_Forall_in_extend by blast then have \<open>Neg (P[?t/0]) \<in> ?H\<close> using Extend_def by blast then show \<open>\<exists>t. closedt 0 t \<and> Neg (P[t/0]) \<in> ?H\<close> using \<open>closedt 0 ?t\<close> by blast } qed subsection \<open>Model existence theorem\<close> text \<open> \label{sec:model-existence} Since the result of extending \<open>S\<close> is a superset of \<open>S\<close>, it follows that each consistent set \<open>S\<close> has a Herbrand model: \<close> lemma hintikka_Extend_S: assumes \<open>consistency C\<close> and \<open>S \<in> C\<close> and \<open>infinite (- (\<Union>p \<in> S. params p))\<close> shows \<open>hintikka (Extend S (mk_finite_char (mk_alt_consistency (close C))) from_nat)\<close> (is \<open>hintikka (Extend S ?C' from_nat)\<close>) proof - have \<open>finite_char ?C'\<close> using finite_char by blast moreover have \<open>\<forall>y. y = from_nat (to_nat y)\<close> by simp then have \<open>\<forall>y. \<exists>n. y = from_nat n\<close> by blast moreover have \<open>alt_consistency ?C'\<close> using alt_consistency close_closed close_consistency \<open>consistency C\<close> finite_alt_consistency mk_alt_consistency_closed by blast moreover have \<open>S \<in> close C\<close> using close_subset \<open>S \<in> C\<close> by blast then have \<open>S \<in> mk_alt_consistency (close C)\<close> using mk_alt_consistency_subset by blast then have \<open>S \<in> ?C'\<close> using close_closed finite_char_subset mk_alt_consistency_closed by blast ultimately show ?thesis using extend_hintikka \<open>infinite (- (\<Union>p \<in> S. params p))\<close> by metis qed theorem model_existence: assumes \<open>consistency C\<close> and \<open>S \<in> C\<close> and \<open>infinite (- (\<Union>p \<in> S. params p))\<close> and \<open>p \<in> S\<close> and \<open>closed 0 p\<close> shows \<open>eval e HApp (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> Extend S (mk_finite_char (mk_alt_consistency (close C))) from_nat) p\<close> using assms hintikka_model hintikka_Extend_S Extend_subset by blast subsection \<open>Completeness for Natural Deduction\<close> text \<open> Thanks to the model existence theorem, we can now show the completeness of the natural deduction calculus introduced in \secref{sec:proof-calculus}. In order for the model existence theorem to be applicable, we have to prove that the set of sets that are consistent with respect to \<open>\<turnstile>\<close> is a consistency property: \<close> theorem deriv_consistency: assumes inf_param: \<open>infinite (UNIV :: 'a set)\<close> shows \<open>consistency {S::('a, 'b) form set. \<exists>G. S = set G \<and> \<not> G \<turnstile> FF}\<close> unfolding consistency_def proof (intro conjI allI impI notI) fix S :: \<open>('a, 'b) form set\<close> assume \<open>S \<in> {set G | G. \<not> G \<turnstile> FF}\<close> (is \<open>S \<in> ?C\<close>) then obtain G :: \<open>('a, 'b) form list\<close> where *: \<open>S = set G\<close> and \<open>\<not> G \<turnstile> FF\<close> by blast { fix p ts assume \<open>Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S\<close> then have \<open>G \<turnstile> Pred p ts\<close> and \<open>G \<turnstile> Neg (Pred p ts)\<close> using Assum * by blast+ then have \<open>G \<turnstile> FF\<close> using NegE by blast then show False using \<open>\<not> G \<turnstile> FF\<close> by blast } { assume \<open>FF \<in> S\<close> then have \<open>G \<turnstile> FF\<close> using Assum * by blast then show False using \<open>\<not> G \<turnstile> FF\<close> by blast } { assume \<open>Neg TT \<in> S\<close> then have \<open>G \<turnstile> Neg TT\<close> using Assum * by blast moreover have \<open>G \<turnstile> TT\<close> using TTI by blast ultimately have \<open>G \<turnstile> FF\<close> using NegE by blast then show False using \<open>\<not> G \<turnstile> FF\<close> by blast } { fix Z assume \<open>Neg (Neg Z) \<in> S\<close> then have \<open>G \<turnstile> Neg (Neg Z)\<close> using Assum * by blast { assume \<open>Z # G \<turnstile> FF\<close> then have \<open>G \<turnstile> Neg Z\<close> using NegI by blast then have \<open>G \<turnstile> FF\<close> using NegE \<open>G \<turnstile> Neg (Neg Z)\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then have \<open>\<not> Z # G \<turnstile> FF\<close> by blast moreover have \<open>S \<union> {Z} = set (Z # G)\<close> using * by simp ultimately show \<open>S \<union> {Z} \<in> ?C\<close> by blast } { fix A B assume \<open>And A B \<in> S\<close> then have \<open>G \<turnstile> And A B\<close> using Assum * by blast then have \<open>G \<turnstile> A\<close> and \<open>G \<turnstile> B\<close> using AndE1 AndE2 by blast+ { assume \<open>A # B # G \<turnstile> FF\<close> then have \<open>B # G \<turnstile> Neg A\<close> using NegI by blast then have \<open>G \<turnstile> Neg A\<close> using cut \<open>G \<turnstile> B\<close> by blast then have \<open>G \<turnstile> FF\<close> using NegE \<open>G \<turnstile> A\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then have \<open>\<not> A # B # G \<turnstile> FF\<close> by blast moreover have \<open>S \<union> {A, B} = set (A # B # G)\<close> using * by simp ultimately show \<open>S \<union> {A, B} \<in> ?C\<close> by blast } { fix A B assume \<open>Neg (Or A B) \<in> S\<close> then have \<open>G \<turnstile> Neg (Or A B)\<close> using Assum * by blast have \<open>A # Neg B # G \<turnstile> A\<close> by (simp add: Assum) then have \<open>A # Neg B # G \<turnstile> Or A B\<close> using OrI1 by blast moreover have \<open>A # Neg B # G \<turnstile> Neg (Or A B)\<close> using * \<open>Neg (Or A B) \<in> S\<close> by (simp add: Assum) ultimately have \<open>A # Neg B # G \<turnstile> FF\<close> using NegE \<open>A # Neg B # G \<turnstile> Neg (Or A B)\<close> by blast then have \<open>Neg B # G \<turnstile> Neg A\<close> using NegI by blast have \<open>B # G \<turnstile> B\<close> by (simp add: Assum) then have \<open>B # G \<turnstile> Or A B\<close> using OrI2 by blast moreover have \<open>B # G \<turnstile> Neg (Or A B)\<close> using * \<open>Neg (Or A B) \<in> S\<close> by (simp add: Assum) ultimately have \<open>B # G \<turnstile> FF\<close> using NegE \<open>B # G \<turnstile> Neg (Or A B)\<close> by blast then have \<open>G \<turnstile> Neg B\<close> using NegI by blast { assume \<open>Neg A # Neg B # G \<turnstile> FF\<close> then have \<open>Neg B # G \<turnstile> Neg (Neg A)\<close> using NegI by blast then have \<open>Neg B # G \<turnstile> FF\<close> using NegE \<open>Neg B # G \<turnstile> Neg A\<close> by blast then have \<open>G \<turnstile> FF\<close> using cut \<open>G \<turnstile> Neg B\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then have \<open>\<not> Neg A # Neg B # G \<turnstile> FF\<close> by blast moreover have \<open>S \<union> {Neg A, Neg B} = set (Neg A # Neg B # G)\<close> using * by simp ultimately show \<open>S \<union> {Neg A, Neg B} \<in> ?C\<close> by blast } { fix A B assume \<open>Neg (Impl A B) \<in> S\<close> have \<open>A # Neg A # Neg B # G \<turnstile> A\<close> by (simp add: Assum) moreover have \<open>A # Neg A # Neg B # G \<turnstile> Neg A\<close> by (simp add: Assum) ultimately have \<open>A # Neg A # Neg B # G \<turnstile> FF\<close> using NegE by blast then have \<open>A # Neg A # Neg B # G \<turnstile> B\<close> using FFE by blast then have \<open>Neg A # Neg B # G \<turnstile> Impl A B\<close> using ImplI by blast moreover have \<open>Neg A # Neg B # G \<turnstile> Neg (Impl A B)\<close> using * \<open>Neg (Impl A B) \<in> S\<close> by (simp add: Assum) ultimately have \<open>Neg A # Neg B # G \<turnstile> FF\<close> using NegE by blast then have \<open>Neg B # G \<turnstile> A\<close> using Class by blast have \<open>A # B # G \<turnstile> B\<close> by (simp add: Assum) then have \<open>B # G \<turnstile> Impl A B\<close> using ImplI by blast moreover have \<open>B # G \<turnstile> Neg (Impl A B)\<close> using * \<open>Neg (Impl A B) \<in> S\<close> by (simp add: Assum) ultimately have \<open>B # G \<turnstile> FF\<close> using NegE by blast then have \<open>G \<turnstile> Neg B\<close> using NegI by blast { assume \<open>A # Neg B # G \<turnstile> FF\<close> then have \<open>Neg B # G \<turnstile> Neg A\<close> using NegI by blast then have \<open>Neg B # G \<turnstile> FF\<close> using NegE \<open>Neg B # G \<turnstile> A\<close> by blast then have \<open>G \<turnstile> FF\<close> using cut \<open>G \<turnstile> Neg B\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then have \<open>\<not> A # Neg B # G \<turnstile> FF\<close> by blast moreover have \<open>{A, Neg B} \<union> S = set (A # Neg B # G)\<close> using * by simp ultimately show \<open>S \<union> {A, Neg B} \<in> ?C\<close> by blast } { fix A B assume \<open>Or A B \<in> S\<close> then have \<open>G \<turnstile> Or A B\<close> using * Assum by blast { assume \<open>(\<forall>G'. set G' = S \<union> {A} \<longrightarrow> G' \<turnstile> FF)\<close> and \<open>(\<forall>G'. set G' = S \<union> {B} \<longrightarrow> G' \<turnstile> FF)\<close> then have \<open>A # G \<turnstile> FF\<close> and \<open>B # G \<turnstile> FF\<close> using * by simp_all then have \<open>G \<turnstile> FF\<close> using OrE \<open>G \<turnstile> Or A B\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then show \<open>S \<union> {A} \<in> ?C \<or> S \<union> {B} \<in> ?C\<close> by blast } { fix A B assume \<open>Neg (And A B) \<in> S\<close> let ?x = \<open>Or (Neg A) (Neg B)\<close> have \<open>B # A # Neg ?x # G \<turnstile> A\<close> and \<open>B # A # Neg ?x # G \<turnstile> B\<close> by (simp_all add: Assum) then have \<open>B # A # Neg ?x # G \<turnstile> And A B\<close> using AndI by blast moreover have \<open>B # A # Neg ?x # G \<turnstile> Neg (And A B)\<close> using * \<open>Neg (And A B) \<in> S\<close> by (simp add: Assum) ultimately have \<open>B # A # Neg ?x # G \<turnstile> FF\<close> using NegE by blast then have \<open>A # Neg ?x # G \<turnstile> Neg B\<close> using NegI by blast then have \<open>A # Neg ?x # G \<turnstile> ?x\<close> using OrI2 by blast moreover have \<open>A # Neg ?x # G \<turnstile> Neg ?x\<close> by (simp add: Assum) ultimately have \<open>A # Neg ?x # G \<turnstile> FF\<close> using NegE by blast then have \<open>Neg ?x # G \<turnstile> Neg A\<close> using NegI by blast then have \<open>Neg ?x # G \<turnstile> ?x\<close> using OrI1 by blast then have \<open>G \<turnstile> Or (Neg A) (Neg B)\<close> using Class' by blast { assume \<open>(\<forall>G'. set G' = S \<union> {Neg A} \<longrightarrow> G' \<turnstile> FF)\<close> and \<open>(\<forall>G'. set G' = S \<union> {Neg B} \<longrightarrow> G' \<turnstile> FF)\<close> then have \<open>Neg A # G \<turnstile> FF\<close> and \<open>Neg B # G \<turnstile> FF\<close> using * by simp_all then have \<open>G \<turnstile> FF\<close> using OrE \<open>G \<turnstile> Or (Neg A) (Neg B)\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then show \<open>S \<union> {Neg A} \<in> ?C \<or> S \<union> {Neg B} \<in> ?C\<close> by blast } { fix A B assume \<open>Impl A B \<in> S\<close> let ?x = \<open>Or (Neg A) B\<close> have \<open>A # Neg ?x # G \<turnstile> A\<close> by (simp add: Assum) moreover have \<open>A # Neg ?x # G \<turnstile> Impl A B\<close> using * \<open>Impl A B \<in> S\<close> by (simp add: Assum) ultimately have \<open>A # Neg ?x # G \<turnstile> B\<close> using ImplE by blast then have \<open>A # Neg ?x # G \<turnstile> ?x\<close> using OrI2 by blast moreover have \<open>A # Neg ?x # G \<turnstile> Neg ?x\<close> by (simp add: Assum) ultimately have \<open>A # Neg ?x # G \<turnstile> FF\<close> using NegE by blast then have \<open>Neg ?x # G \<turnstile> Neg A\<close> using NegI by blast then have \<open>Neg ?x # G \<turnstile> ?x\<close> using OrI1 by blast then have \<open>G \<turnstile> Or (Neg A) B\<close> using Class' by blast { assume \<open>(\<forall>G'. set G' = S \<union> {Neg A} \<longrightarrow> G' \<turnstile> FF)\<close> and \<open>(\<forall>G'. set G' = S \<union> {B} \<longrightarrow> G' \<turnstile> FF)\<close> then have \<open>Neg A # G \<turnstile> FF\<close> and \<open>B # G \<turnstile> FF\<close> using * by simp_all then have \<open>G \<turnstile> FF\<close> using OrE \<open>G \<turnstile> Or (Neg A) B\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then show \<open>S \<union> {Neg A} \<in> ?C \<or> S \<union> {B} \<in> ?C\<close> by blast } { fix P and t :: \<open>'a term\<close> assume \<open>closedt 0 t\<close> and \<open>Forall P \<in> S\<close> then have \<open>G \<turnstile> Forall P\<close> using Assum * by blast then have \<open>G \<turnstile> P[t/0]\<close> using ForallE by blast { assume \<open>P[t/0] # G \<turnstile> FF\<close> then have \<open>G \<turnstile> FF\<close> using cut \<open>G \<turnstile> P[t/0]\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then have \<open>\<not> P[t/0] # G \<turnstile> FF\<close> by blast moreover have \<open>S \<union> {P[t/0]} = set (P[t/0] # G)\<close> using * by simp ultimately show \<open>S \<union> {P[t/0]} \<in> ?C\<close> by blast } { fix P and t :: \<open>'a term\<close> assume \<open>closedt 0 t\<close> and \<open>Neg (Exists P) \<in> S\<close> then have \<open>G \<turnstile> Neg (Exists P)\<close> using Assum * by blast then have \<open>P[t/0] \<in> set (P[t/0] # G)\<close> by (simp add: Assum) then have \<open>P[t/0] # G \<turnstile> P[t/0]\<close> using Assum by blast then have \<open>P[t/0] # G \<turnstile> Exists P\<close> using ExistsI by blast moreover have \<open>P[t/0] # G \<turnstile> Neg (Exists P)\<close> using * \<open>Neg (Exists P) \<in> S\<close> by (simp add: Assum) ultimately have \<open>P[t/0] # G \<turnstile> FF\<close> using NegE by blast then have \<open>G \<turnstile> Neg (P[t/0])\<close> using NegI by blast { assume \<open>Neg (P[t/0]) # G \<turnstile> FF\<close> then have \<open>G \<turnstile> FF\<close> using cut \<open>G \<turnstile> Neg (P[t/0])\<close> by blast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast } then have \<open>\<not> Neg (P[t/0]) # G \<turnstile> FF\<close> by blast moreover have \<open>S \<union> {Neg (P[t/0])} = set (Neg (P[t/0]) # G)\<close> using * by simp ultimately show \<open>S \<union> {Neg (P[t/0])} \<in> ?C\<close> by blast } { fix P assume \<open>Exists P \<in> S\<close> then have \<open>G \<turnstile> Exists P\<close> using * Assum by blast have \<open>finite ((\<Union>p \<in> set G. params p) \<union> params P)\<close> by simp then have \<open>infinite (- ((\<Union>p \<in> set G. params p) \<union> params P))\<close> using inf_param Diff_infinite_finite finite_compl by blast then have \<open>infinite (- ((\<Union>p \<in> set G. params p) \<union> params P))\<close> by (simp add: Compl_eq_Diff_UNIV) then obtain x where **: \<open>x \<in> - ((\<Union>p \<in> set G. params p) \<union> params P)\<close> using infinite_imp_nonempty by blast { assume \<open>P[App x []/0] # G \<turnstile> FF\<close> moreover have \<open>list_all (\<lambda>p. x \<notin> params p) G\<close> using ** by (simp add: list_all_iff) moreover have \<open>x \<notin> params P\<close> using ** by simp moreover have \<open>x \<notin> params FF\<close> by simp ultimately have \<open>G \<turnstile> FF\<close> using ExistsE \<open>G \<turnstile> Exists P\<close> by fast then have False using \<open>\<not> G \<turnstile> FF\<close> by blast} then have \<open>\<not> P[App x []/0] # G \<turnstile> FF\<close> by blast moreover have \<open>S \<union> {P[App x []/0]} = set (P[App x []/0] # G)\<close> using * by simp ultimately show \<open>\<exists>x. S \<union> {P[App x []/0]} \<in> ?C\<close> by blast } { fix P assume \<open>Neg (Forall P) \<in> S\<close> then have \<open>G \<turnstile> Neg (Forall P)\<close> using * Assum by blast have \<open>finite ((\<Union>p \<in> set G. params p) \<union> params P)\<close> by simp then have \<open>infinite (- ((\<Union>p \<in> set G. params p) \<union> params P))\<close> using inf_param Diff_infinite_finite finite_compl by blast then have \<open>infinite (- ((\<Union>p \<in> set G. params p) \<union> params P))\<close> by (simp add: Compl_eq_Diff_UNIV) then obtain x where **: \<open>x \<in> - ((\<Union>p \<in> set G. params p) \<union> params P)\<close> using infinite_imp_nonempty by blast let ?x = \<open>Neg (Exists (Neg P))\<close> have \<open>Neg (P[App x []/0]) # ?x # G \<turnstile> Neg P[App x []/0]\<close> by (simp add: Assum) then have \<open>Neg (P[App x []/0]) # ?x # G \<turnstile> Exists (Neg P)\<close> using ExistsI by blast moreover have \<open>Neg (P[App x []/0]) # ?x # G \<turnstile> ?x\<close> by (simp add: Assum) ultimately have \<open>Neg (P[App x []/0]) # ?x # G \<turnstile> FF\<close> using NegE by blast then have \<open>?x # G \<turnstile> P[App x []/0]\<close> using Class by blast moreover have \<open>list_all (\<lambda>p. x \<notin> params p) (?x # G)\<close> using ** by (simp add: list_all_iff) moreover have \<open>x \<notin> params P\<close> using ** by simp ultimately have \<open>?x # G \<turnstile> Forall P\<close> using ForallI by fast moreover have \<open>?x # G \<turnstile> Neg (Forall P)\<close> using * \<open>Neg (Forall P) \<in> S\<close> by (simp add: Assum) ultimately have \<open>?x # G \<turnstile> FF\<close> using NegE by blast then have \<open>G \<turnstile> Exists (Neg P)\<close> using Class by blast { assume \<open>Neg (P[App x []/0]) # G \<turnstile> FF\<close> moreover have \<open>list_all (\<lambda>p. x \<notin> params p) G\<close> using ** by (simp add: list_all_iff) moreover have \<open>x \<notin> params P\<close> using ** by simp moreover have \<open>x \<notin> params FF\<close> by simp ultimately have \<open>G \<turnstile> FF\<close> using ExistsE \<open>G \<turnstile> Exists (Neg P)\<close> by fastforce then have False using \<open>\<not> G \<turnstile> FF\<close> by blast} then have \<open>\<not> Neg (P[App x []/0]) # G \<turnstile> FF\<close> by blast moreover have \<open>S \<union> {Neg (P[App x []/0])} = set (Neg (P[App x []/0]) # G)\<close> using * by simp ultimately show \<open>\<exists>x. S \<union> {Neg (P[App x []/0])} \<in> ?C\<close> by blast } qed text \<open> Hence, by contradiction, we have completeness of natural deduction: \<close> theorem natded_complete: assumes \<open>closed 0 p\<close> and \<open>list_all (closed 0) ps\<close> and mod: \<open>\<forall>e f g. e,(f :: nat \<Rightarrow> nat hterm list \<Rightarrow> nat hterm), (g :: nat \<Rightarrow> nat hterm list \<Rightarrow> bool),ps \<Turnstile> p\<close> shows \<open>ps \<turnstile> p\<close> proof (rule Class, rule ccontr) fix e assume \<open>\<not> Neg p # ps \<turnstile> FF\<close> let ?S = \<open>set (Neg p # ps)\<close> let ?C = \<open>{set (G :: (nat, nat) form list) | G. \<not> G \<turnstile> FF}\<close> let ?f = HApp let ?g = \<open>(\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> Extend ?S (mk_finite_char (mk_alt_consistency (close ?C))) from_nat)\<close> from \<open>list_all (closed 0) ps\<close> have \<open>\<forall>p \<in> set ps. closed 0 p\<close> by (simp add: list_all_iff) { fix x assume \<open>x \<in> ?S\<close> moreover have \<open>consistency ?C\<close> using deriv_consistency by blast moreover have \<open>?S \<in> ?C\<close> using \<open>\<not> Neg p # ps \<turnstile> FF\<close> by blast moreover have \<open>infinite (- (\<Union>p \<in> ?S. params p))\<close> by (simp add: Compl_eq_Diff_UNIV) moreover note \<open>closed 0 p\<close> \<open>\<forall>p \<in> set ps. closed 0 p\<close> \<open>x \<in> ?S\<close> then have \<open>closed 0 x\<close> by auto ultimately have \<open>eval e ?f ?g x\<close> using model_existence by blast } then have \<open>list_all (eval e ?f ?g) (Neg p # ps)\<close> by (simp add: list_all_iff) moreover have \<open>eval e ?f ?g (Neg p)\<close> using calculation by simp moreover have \<open>list_all (eval e ?f ?g) ps\<close> using calculation by simp then have \<open>eval e ?f ?g p\<close> using mod unfolding model_def by blast ultimately show False by simp qed section \<open>L\"owenheim-Skolem theorem\<close> text \<open> Another application of the model existence theorem presented in \secref{sec:model-existence} is the L\"owenheim-Skolem theorem. It says that a set of formulae that is satisfiable in an {\em arbitrary model} is also satisfiable in a {\em Herbrand model}. The main idea behind the proof is to show that satisfiable sets are consistent, hence they must be satisfiable in a Herbrand model. \<close> theorem sat_consistency: \<open>consistency {S. infinite (- (\<Union>p \<in> S. params p)) \<and> (\<exists>f. \<forall>(p::('a, 'b)form) \<in> S. eval e f g p)}\<close> unfolding consistency_def proof (intro allI impI conjI) let ?C = \<open>{S. infinite (- (\<Union>p \<in> S. params p)) \<and> (\<exists>f. \<forall>p \<in> S. eval e f g p)}\<close> fix S :: \<open>('a, 'b) form set\<close> assume \<open>S \<in> ?C\<close> then have inf_params: \<open>infinite (- (\<Union>p \<in> S. params p))\<close> and \<open>\<exists>f. \<forall>p \<in> S. eval e f g p\<close> by blast+ then obtain f where *: \<open>\<forall>x \<in> S. eval e f g x\<close> by blast { fix p ts show \<open>\<not> (Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S)\<close> proof assume \<open>Pred p ts \<in> S \<and> Neg (Pred p ts) \<in> S\<close> then have \<open>eval e f g (Pred p ts) \<and> eval e f g (Neg (Pred p ts))\<close> using * by blast then show False by simp qed } show \<open>FF \<notin> S\<close> using * by fastforce show \<open>Neg TT \<notin> S\<close> using * by fastforce { fix Z assume \<open>Neg (Neg Z) \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Neg (Neg Z)}. eval e f g x\<close> using * by blast then have \<open>\<forall>x \<in> S \<union> {Z}. eval e f g x\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {Z}. params p))\<close> using inf_params by simp ultimately show \<open>S \<union> {Z} \<in> ?C\<close> by blast } { fix A B assume \<open>And A B \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {And A B}. eval e f g x\<close> using * by blast then have \<open>\<forall>x \<in> S \<union> {A, B}. eval e f g x\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {A, B}. params p))\<close> using inf_params by simp ultimately show \<open>S \<union> {A, B} \<in> ?C\<close> by blast } { fix A B assume \<open>Neg (Or A B) \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Neg (Or A B)}. eval e f g x\<close> using * by blast then have \<open>\<forall>x \<in> S \<union> {Neg A, Neg B}. eval e f g x\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {Neg A, Neg B}. params p))\<close> using inf_params by simp ultimately show \<open>S \<union> {Neg A, Neg B} \<in> ?C\<close> by blast } { fix A B assume \<open>Neg (Impl A B) \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Neg (Impl A B)}. eval e f g x\<close> using * by blast then have \<open>\<forall>x \<in> S \<union> {A, Neg B}. eval e f g x\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {A, Neg B}. params p))\<close> using inf_params by simp ultimately show \<open>S \<union> {A, Neg B} \<in> ?C\<close> by blast } { fix A B assume \<open>Or A B \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Or A B}. eval e f g x\<close> using * by blast then have \<open>(\<forall>x \<in> S \<union> {A}. eval e f g x) \<or> (\<forall>x \<in> S \<union> {B}. eval e f g x)\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {A}. params p))\<close> and \<open>infinite (- (\<Union>p \<in> S \<union> {B}. params p))\<close> using inf_params by simp_all ultimately show \<open>S \<union> {A} \<in> ?C \<or> S \<union> {B} \<in> ?C\<close> by blast } { fix A B assume \<open>Neg (And A B) \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Neg (And A B)}. eval e f g x\<close> using * by blast then have \<open>(\<forall>x \<in> S \<union> {Neg A}. eval e f g x) \<or> (\<forall>x \<in> S \<union> {Neg B}. eval e f g x)\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {Neg A}. params p))\<close> and \<open>infinite (- (\<Union>p \<in> S \<union> {Neg B}. params p))\<close> using inf_params by simp_all ultimately show \<open>S \<union> {Neg A} \<in> ?C \<or> S \<union> {Neg B} \<in> ?C\<close> by blast } { fix A B assume \<open>Impl A B \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Impl A B}. eval e f g x\<close> using * by blast then have \<open>(\<forall>x \<in> S \<union> {Neg A}. eval e f g x) \<or> (\<forall>x \<in> S \<union> {B}. eval e f g x)\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {Neg A}. params p))\<close> and \<open>infinite (- (\<Union>p \<in> S \<union> {B}. params p))\<close> using inf_params by simp_all ultimately show \<open>S \<union> {Neg A} \<in> ?C \<or> S \<union> {B} \<in> ?C\<close> by blast } { fix P and t :: \<open>'a term\<close> assume \<open>Forall P \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Forall P}. eval e f g x\<close> using * by blast then have \<open>\<forall>x \<in> S \<union> {P[t/0]}. eval e f g x\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {P[t/0]}. params p))\<close> using inf_params by simp ultimately show \<open>S \<union> {P[t/0]} \<in> ?C\<close> by blast } { fix P and t :: \<open>'a term\<close> assume \<open>Neg (Exists P) \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Neg (Exists P)}. eval e f g x\<close> using * by blast then have \<open>\<forall>x \<in> S \<union> {Neg (P[t/0])}. eval e f g x\<close> by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {Neg (P[t/0])}. params p))\<close> using inf_params by simp ultimately show \<open>S \<union> {Neg (P[t/0])} \<in> ?C\<close> by blast } { fix P assume \<open>Exists P \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Exists P}. eval e f g x\<close> using * by blast then have \<open>eval e f g (Exists P)\<close> by blast then obtain z where \<open>eval (e\<langle>0:z\<rangle>) f g P\<close> by auto moreover obtain x where **: \<open>x \<in> - (\<Union>p \<in> S. params p)\<close> using inf_params infinite_imp_nonempty by blast then have \<open>x \<notin> params P\<close> using \<open>Exists P \<in> S\<close> by auto ultimately have \<open>eval (e\<langle>0:(f(x := \<lambda>y. z)) x []\<rangle>) (f(x := \<lambda>y. z)) g P\<close> by simp moreover have \<open>\<forall>p \<in> S. eval e (f(x := \<lambda>y. z)) g p\<close> using * ** by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {P[App x []/0]}. params p))\<close> using inf_params by simp ultimately have \<open>S \<union> {P[App x []/0]} \<in> {S. infinite (- (\<Union>p \<in> S. params p)) \<and> (\<forall>p \<in> S. eval e (f(x := \<lambda>y. z)) g p)}\<close> by simp then show \<open>\<exists>x. S \<union> {P[App x []/0]} \<in> ?C\<close> by blast } { fix P assume \<open>Neg (Forall P) \<in> S\<close> then have \<open>\<forall>x \<in> S \<union> {Neg (Forall P)}. eval e f g x\<close> using * by blast then have \<open>eval e f g (Neg (Forall P))\<close> by blast then obtain z where \<open>\<not> eval (e\<langle>0:z\<rangle>) f g P\<close> by auto moreover obtain x where **: \<open>x \<in> - (\<Union>p \<in> S. params p)\<close> using inf_params infinite_imp_nonempty by blast then have \<open>x \<notin> params P\<close> using \<open>Neg (Forall P) \<in> S\<close> by auto ultimately have \<open>\<not> eval (e\<langle>0:(f(x := \<lambda>y. z)) x []\<rangle>) (f(x := \<lambda>y. z)) g P\<close> by simp moreover have \<open>\<forall>p \<in> S. eval e (f(x := \<lambda>y. z)) g p\<close> using * ** by simp moreover have \<open>infinite (- (\<Union>p \<in> S \<union> {P[App x []/0]}. params p))\<close> using inf_params by simp ultimately have \<open>S \<union> {Neg (P[App x []/0])} \<in> {S. infinite (- (\<Union>p \<in> S. params p)) \<and> (\<forall>p \<in> S. eval e (f(x := \<lambda>y. z)) g p)}\<close> by simp then show \<open>\<exists>x. S \<union> {Neg (P[App x []/0])} \<in> ?C\<close> by blast } qed theorem doublep_infinite_params: \<open>infinite (- (\<Union>p \<in> psubst (\<lambda>n::nat. 2 * n) ` S. params p))\<close> proof (rule infinite_super) show \<open>infinite (range (\<lambda>n::nat. 2 * n + 1))\<close> using inj_onI Suc_1 Suc_mult_cancel1 add_right_imp_eq finite_imageD infinite_UNIV_char_0 by (metis (no_types, lifting)) next have \<open>\<And>m n. Suc (2 * m) \<noteq> 2 * n\<close> by arith then show \<open>range (\<lambda>n. 2 * n + 1) \<subseteq> - (\<Union>p::(nat, 'a) form \<in> psubst (\<lambda>n . 2 * n) ` S. params p)\<close> by auto qed text \<open> When applying the model existence theorem, there is a technical complication. We must make sure that there are infinitely many unused parameters. In order to achieve this, we encode parameters as natural numbers and multiply each parameter occurring in the set \<open>S\<close> by \<open>2\<close>. \<close> theorem loewenheim_skolem: assumes evalS: \<open>\<forall>p \<in> S. eval e f g p\<close> shows \<open>\<forall>p \<in> S. closed 0 p \<longrightarrow> eval e' (\<lambda>n. HApp (2*n)) (\<lambda>a ts. Pred a (terms_of_hterms ts) \<in> Extend (psubst (\<lambda>n. 2 * n) ` S) (mk_finite_char (mk_alt_consistency (close {S. infinite (- (\<Union>p \<in> S. params p)) \<and> (\<exists>f. \<forall>p \<in> S. eval e f g p)}))) from_nat) p\<close> (is \<open>\<forall>_ \<in> _. _ _ _ \<longrightarrow> eval _ _ ?g _\<close>) using evalS proof (intro ballI impI) fix p let ?C = \<open>{S. infinite (- (\<Union>p \<in> S. params p)) \<and> (\<exists>f. \<forall>x \<in> S. eval e f g x)}\<close> assume \<open>p \<in> S\<close> and \<open>closed 0 p\<close> then have \<open>eval e f g p\<close> using evalS by blast then have \<open>\<forall>x \<in> S. eval e f g x\<close> using evalS by blast then have \<open>\<forall>p \<in> psubst (\<lambda>n. 2 * n) ` S. eval e (\<lambda>n. f (n div 2)) g p\<close> by (simp add: psubst_eval) then have \<open>psubst (\<lambda>n. 2 * n) ` S \<in> ?C\<close> using doublep_infinite_params by blast moreover have \<open>psubst (\<lambda>n. 2 * n) p \<in> psubst (\<lambda>n. 2 * n) ` S\<close> using \<open>p \<in> S\<close> by blast moreover have \<open>closed 0 (psubst (\<lambda>n. 2 * n) p)\<close> using \<open>closed 0 p\<close> by simp moreover have \<open>consistency ?C\<close> using sat_consistency by blast ultimately have \<open>eval e' HApp ?g (psubst (\<lambda>n. 2 * n) p)\<close> using model_existence by blast then show \<open>eval e' (\<lambda>n. HApp (2 * n)) ?g p\<close> using psubst_eval by blast qed section \<open>Completeness for open formulas\<close> abbreviation \<open>new_term c t \<equiv> c \<notin> paramst t\<close> abbreviation \<open>new_list c ts \<equiv> c \<notin> paramsts ts\<close> abbreviation \<open>new c p \<equiv> c \<notin> params p\<close> abbreviation \<open>news c z \<equiv> list_all (new c) z\<close> subsection \<open>Renaming\<close> lemma new_psubst_image': \<open>new_term c t \<Longrightarrow> d \<notin> image f (paramst t) \<Longrightarrow> new_term d (psubstt (f(c := d)) t)\<close> \<open>new_list c l \<Longrightarrow> d \<notin> image f (paramsts l) \<Longrightarrow> new_list d (psubstts (f(c := d)) l)\<close> by (induct t and l rule: paramst.induct paramsts.induct) auto lemma new_psubst_image: \<open>new c p \<Longrightarrow> d \<notin> image f (params p) \<Longrightarrow> new d (psubst (f(c := d)) p)\<close> using new_psubst_image' by (induct p) auto lemma news_psubst: \<open>news c z \<Longrightarrow> d \<notin> image f (\<Union>p \<in> set z. params p) \<Longrightarrow> news d (map (psubst (f(c := d))) z)\<close> using new_psubst_image by (induct z) auto lemma member_psubst: \<open>p \<in> set z \<Longrightarrow> psubst f p \<in> set (map (psubst f) z)\<close> by (induct z) auto lemma deriv_psubst: fixes f :: \<open>'a \<Rightarrow> 'a\<close> assumes inf_params: \<open>infinite (UNIV :: 'a set)\<close> shows \<open>z \<turnstile> p \<Longrightarrow> map (psubst f) z \<turnstile> psubst f p\<close> proof (induct z p arbitrary: f rule: deriv.induct) case (Assum a G) then show ?case using deriv.Assum member_psubst by blast next case (TTI G) then show ?case using deriv.TTI by auto next case (FFE G a) then show ?case using deriv.FFE by auto next case (NegI a G) then show ?case using deriv.NegI by auto next case (NegE G a) then show ?case using deriv.NegE by auto next case (Class a G) then show ?case using deriv.Class by auto next case (ImplE G a b) then have \<open>map (psubst f) G \<turnstile> Impl (psubst f a) (psubst f b)\<close> and \<open>map (psubst f) G \<turnstile> psubst f a\<close> by simp_all then show ?case using deriv.ImplE by blast next case (ImplI G a b) then show ?case using deriv.ImplI by auto next case (OrE G a b c) then have \<open>map (psubst f) G \<turnstile> Or (psubst f a) (psubst f b)\<close> and \<open>psubst f a # map (psubst f) G \<turnstile> psubst f c\<close> and \<open>psubst f b # map (psubst f) G \<turnstile> psubst f c\<close> by simp_all then show ?case using deriv.OrE by blast next case (OrI1 G a b) then show ?case using deriv.OrI1 by auto next case (OrI2 G a b) then show ?case using deriv.OrI2 by auto next case (AndE1 G a b) then show ?case using deriv.AndE1 by auto next case (AndE2 p q z) then show ?case using deriv.AndE2 by auto next case (AndI G a b) then show ?case using deriv.AndI by fastforce next case (ExistsE z p c q) let ?params = \<open>params p \<union> params q \<union> (\<Union>p \<in> set z. params p)\<close> have \<open>finite ?params\<close> by simp then obtain fresh where *: \<open>fresh \<notin> ?params \<union> {c} \<union> image f ?params\<close> using ex_new_if_finite inf_params by (metis finite.emptyI finite.insertI finite_UnI finite_imageI) let ?f = \<open>f(c := fresh)\<close> have \<open>news c (p # q # z)\<close> using ExistsE by simp then have \<open>new fresh (psubst ?f p)\<close> \<open>new fresh (psubst ?f q)\<close> \<open>news fresh (map (psubst ?f) z)\<close> using * new_psubst_image news_psubst by (fastforce simp add: image_Un)+ then have \<open>map (psubst ?f) z = map (psubst f) z\<close> using ExistsE by (metis (mono_tags, lifting) Ball_set map_eq_conv psubst_upd) have \<open>map (psubst ?f) z \<turnstile> psubst ?f (Exists p)\<close> using ExistsE by blast then have \<open>map (psubst ?f) z \<turnstile> Exists (psubst ?f p)\<close> by simp moreover have \<open>map (psubst ?f) (subst p (App c []) 0 # z) \<turnstile> psubst ?f q\<close> using ExistsE by blast then have \<open>subst (psubst ?f p) (App fresh []) 0 # map (psubst ?f) z \<turnstile> psubst ?f q\<close> by simp moreover have \<open>news fresh (map (psubst ?f) (p # q # z))\<close> using \<open>new fresh (psubst ?f p)\<close> \<open>new fresh (psubst ?f q)\<close> \<open>news fresh (map (psubst ?f) z)\<close> by simp then have \<open>new fresh (psubst ?f p)\<close> \<open>new fresh (psubst ?f q)\<close> \<open>news fresh (map (psubst ?f) z)\<close> by simp_all ultimately have \<open>map (psubst ?f) z \<turnstile> psubst ?f q\<close> using deriv.ExistsE by metis then show ?case using ExistsE \<open>map (psubst ?f) z = map (psubst f) z\<close> by simp next case (ExistsI z p t) then show ?case using deriv.ExistsI by auto next case (ForallE z p t) then show ?case using deriv.ForallE by auto next case (ForallI z p c) let ?params = \<open>params p \<union>(\<Union>p \<in> set z. params p)\<close> have \<open>finite ?params\<close> by simp then obtain fresh where *: \<open>fresh \<notin> ?params \<union> {c} \<union> image f ?params\<close> using ex_new_if_finite inf_params by (metis finite.emptyI finite.insertI finite_UnI finite_imageI) let ?f = \<open>f(c := fresh)\<close> have \<open>news c (p # z)\<close> using ForallI by simp then have \<open>new fresh (psubst ?f p)\<close> \<open>news fresh (map (psubst ?f) z)\<close> using * new_psubst_image news_psubst by (fastforce simp add: image_Un)+ then have \<open>map (psubst ?f) z = map (psubst f) z\<close> using ForallI by (metis (mono_tags, lifting) Ball_set map_eq_conv psubst_upd) have \<open>map (psubst ?f) z \<turnstile> psubst ?f (subst p (App c []) 0)\<close> using ForallI by blast then have \<open>map (psubst ?f) z \<turnstile> subst (psubst ?f p) (App fresh []) 0\<close> by simp moreover have \<open>news fresh (map (psubst ?f) (p # z))\<close> using \<open>new fresh (psubst ?f p)\<close> \<open>news fresh (map (psubst ?f) z)\<close> by simp then have \<open>new fresh (psubst ?f p)\<close> \<open>news fresh (map (psubst ?f) z)\<close> by simp_all ultimately have \<open>map (psubst ?f) z \<turnstile> Forall (psubst ?f p)\<close> using deriv.ForallI by metis then show ?case using ForallI \<open>map (psubst ?f) z = map (psubst f) z\<close> by simp qed subsection \<open>Substitution for constants\<close> primrec subc_term :: \<open>'a \<Rightarrow> 'a term \<Rightarrow> 'a term \<Rightarrow> 'a term\<close> and subc_list :: \<open>'a \<Rightarrow> 'a term \<Rightarrow> 'a term list \<Rightarrow> 'a term list\<close> where \<open>subc_term c s (Var n) = Var n\<close> | \<open>subc_term c s (App i l) = (if i = c then s else App i (subc_list c s l))\<close> | \<open>subc_list c s [] = []\<close> | \<open>subc_list c s (t # l) = subc_term c s t # subc_list c s l\<close> primrec subc :: \<open>'a \<Rightarrow> 'a term \<Rightarrow> ('a, 'b) form \<Rightarrow> ('a, 'b) form\<close> where \<open>subc c s FF = FF\<close> | \<open>subc c s TT = TT\<close> | \<open>subc c s (Pred i l) = Pred i (subc_list c s l)\<close> | \<open>subc c s (Neg p) = Neg (subc c s p)\<close> | \<open>subc c s (Impl p q) = Impl (subc c s p) (subc c s q)\<close> | \<open>subc c s (Or p q) = Or (subc c s p) (subc c s q)\<close> | \<open>subc c s (And p q) = And (subc c s p) (subc c s q)\<close> | \<open>subc c s (Exists p) = Exists (subc c (liftt s) p)\<close> | \<open>subc c s (Forall p) = Forall (subc c (liftt s) p)\<close> primrec subcs :: \<open>'a \<Rightarrow> 'a term \<Rightarrow> ('a, 'b) form list \<Rightarrow> ('a, 'b) form list\<close> where \<open>subcs c s [] = []\<close> | \<open>subcs c s (p # z) = subc c s p # subcs c s z\<close> lemma subst_0_lift: \<open>substt (liftt t) s 0 = t\<close> \<open>substts (liftts l) s 0 = l\<close> by (induct t and l rule: substt.induct substts.induct) simp_all lemma params_lift [simp]: fixes t :: \<open>'a term\<close> and ts :: \<open>'a term list\<close> shows \<open>paramst (liftt t) = paramst t\<close> \<open>paramsts (liftts ts) = paramsts ts\<close> by (induct t and ts rule: paramst.induct paramsts.induct) simp_all lemma subst_new' [simp]: \<open>new_term c s \<Longrightarrow> new_term c t \<Longrightarrow> new_term c (substt t s m)\<close> \<open>new_term c s \<Longrightarrow> new_list c l \<Longrightarrow> new_list c (substts l s m)\<close> by (induct t and l rule: substt.induct substts.induct) simp_all lemma subst_new [simp]: \<open>new_term c s \<Longrightarrow> new c p \<Longrightarrow> new c (subst p s m)\<close> by (induct p arbitrary: m s) simp_all lemma subst_new_all: assumes \<open>a \<notin> set cs\<close> \<open>list_all (\<lambda>c. new c p) cs\<close> shows \<open>list_all (\<lambda>c. new c (subst p (App a []) m)) cs\<close> using assms by (induct cs) auto lemma subc_new' [simp]: \<open>new_term c t \<Longrightarrow> subc_term c s t = t\<close> \<open>new_list c l \<Longrightarrow> subc_list c s l = l\<close> by (induct t and l rule: subc_term.induct subc_list.induct) auto lemma subc_new [simp]: \<open>new c p \<Longrightarrow> subc c s p = p\<close> by (induct p arbitrary: s) simp_all lemma subcs_news: \<open>news c z \<Longrightarrow> subcs c s z = z\<close> by (induct z) simp_all lemma subc_psubst' [simp]: \<open>(\<forall>x \<in> paramst t. x \<noteq> c \<longrightarrow> f x \<noteq> f c) \<Longrightarrow> psubstt f (subc_term c s t) = subc_term (f c) (psubstt f s) (psubstt f t)\<close> \<open>(\<forall>x \<in> paramsts l. x \<noteq> c \<longrightarrow> f x \<noteq> f c) \<Longrightarrow> psubstts f (subc_list c s l) = subc_list (f c) (psubstt f s) (psubstts f l)\<close> by (induct t and l rule: psubstt.induct psubstts.induct) simp_all lemma subc_psubst: \<open>(\<forall>x \<in> params p. x \<noteq> c \<longrightarrow> f x \<noteq> f c) \<Longrightarrow> psubst f (subc c s p) = subc (f c) (psubstt f s) (psubst f p)\<close> by (induct p arbitrary: s) simp_all lemma subcs_psubst: \<open>(\<forall>x \<in> (\<Union>p \<in> set z. params p). x \<noteq> c \<longrightarrow> f x \<noteq> f c) \<Longrightarrow> map (psubst f) (subcs c s z) = subcs (f c) (psubstt f s) (map (psubst f) z)\<close> by (induct z) (simp_all add: subc_psubst) lemma new_lift: \<open>new_term c t \<Longrightarrow> new_term c (liftt t)\<close> \<open>new_list c l \<Longrightarrow> new_list c (liftts l)\<close> by (induct t and l rule: liftt.induct liftts.induct) simp_all lemma new_subc' [simp]: \<open>new_term d s \<Longrightarrow> new_term d t \<Longrightarrow> new_term d (subc_term c s t)\<close> \<open>new_term d s \<Longrightarrow> new_list d l \<Longrightarrow> new_list d (subc_list c s l)\<close> by (induct t and l rule: substt.induct substts.induct) simp_all lemma news_subcs: \<open>new_term d s \<Longrightarrow> news d z \<Longrightarrow> news d (subcs c s z)\<close> by (induct z) simp_all lemma psubst_new_free': \<open>c \<noteq> n \<Longrightarrow> new_term n (psubstt (id(n := c)) t)\<close> \<open>c \<noteq> n \<Longrightarrow> new_list n (psubstts (id(n := c)) l)\<close> by (induct t and l rule: paramst.induct paramsts.induct) simp_all lemma psubst_new_free: \<open>c \<noteq> n \<Longrightarrow> new n (psubst (id(n := c)) p)\<close> using psubst_new_free' by (induct p) fastforce+ lemma map_psubst_new_free: \<open>c \<noteq> n \<Longrightarrow> news n (map (psubst (id(n := c))) z)\<close> using psubst_new_free by (induct z) fastforce+ lemma psubst_new_away' [simp]: \<open>new_term fresh t \<Longrightarrow> psubstt (id(fresh := c)) (psubstt (id(c := fresh)) t) = t\<close> \<open>new_list fresh l \<Longrightarrow> psubstts (id(fresh := c)) (psubstts (id(c := fresh)) l) = l\<close> by (induct t and l rule: psubstt.induct psubstts.induct) auto lemma psubst_new_away [simp]: \<open>new fresh p \<Longrightarrow> psubst (id(fresh := c)) (psubst (id(c := fresh)) p) = p\<close> by (induct p) simp_all lemma map_psubst_new_away: \<open>news fresh z \<Longrightarrow> map (psubst (id(fresh := c))) (map (psubst (id(c := fresh))) z) = z\<close> by (induct z) simp_all lemma psubst_new': \<open>new_term c t \<Longrightarrow> psubstt (id(c := x)) t = t\<close> \<open>new_list c l \<Longrightarrow> psubstts (id(c := x)) l = l\<close> by (induct t and l rule: psubstt.induct psubstts.induct) auto lemma psubst_new: \<open>new c p \<Longrightarrow> psubst (id(c := x)) p = p\<close> using psubst_new' by (induct p) fastforce+ lemma map_psubst_new: \<open>news c z \<Longrightarrow> map (psubst (id(c := x))) z = z\<close> using psubst_new by (induct z) auto lemma lift_subst [simp]: \<open>liftt (substt t u m) = substt (liftt t) (liftt u) (m + 1)\<close> \<open>liftts (substts l u m) = substts (liftts l) (liftt u) (m + 1)\<close> by (induct t and l rule: substt.induct substts.induct) simp_all lemma new_subc_same' [simp]: \<open>new_term c s \<Longrightarrow> new_term c (subc_term c s t)\<close> \<open>new_term c s \<Longrightarrow> new_list c (subc_list c s l)\<close> by (induct t and l rule: subc_term.induct subc_list.induct) simp_all lemma new_subc_same: \<open>new_term c s \<Longrightarrow> new c (subc c s p)\<close> by (induct p arbitrary: s) simp_all lemma lift_subc: \<open>liftt (subc_term c s t) = subc_term c (liftt s) (liftt t)\<close> \<open>liftts (subc_list c s l) = subc_list c (liftt s) (liftts l)\<close> by (induct t and l rule: liftt.induct liftts.induct) simp_all lemma new_subc_put': \<open>new_term c s \<Longrightarrow> subc_term c s (substt t u m) = subc_term c s (substt t (subc_term c s u) m)\<close> \<open>new_term c s \<Longrightarrow> subc_list c s (substts l u m) = subc_list c s (substts l (subc_term c s u) m)\<close> by (induct t and l rule: subc_term.induct subc_list.induct) simp_all lemma new_subc_put: \<open>new_term c s \<Longrightarrow> subc c s (subst p t m) = subc c s (subst p (subc_term c s t) m)\<close> proof (induct p arbitrary: s m t) case FF then show ?case by simp next case TT then show ?case by simp next case (Pred i l) then show ?case using new_subc_put' by fastforce next case (Neg p) then show ?case by (metis subc.simps(4) subst.simps(7)) next case (Impl p q) then show ?case by (metis subc.simps(5) subst.simps(6)) next case (Or p q) then show ?case by (metis subc.simps(6) subst.simps(5)) next case (And p q) then show ?case by (metis subc.simps(7) subst.simps(4)) next case (Exists p) have \<open>subc c s (subst (Exists p) (subc_term c s t) m) = Exists (subc c (liftt s) (subst p (subc_term c (liftt s) (liftt t)) (Suc m)))\<close> by (simp add: lift_subc) also have \<open>\<dots> = Exists (subc c (liftt s) (subst p (liftt t) (Suc m)))\<close> using Exists new_lift(1) by metis finally show ?case by simp next case (Forall p) have \<open>subc c s (subst (Forall p) (subc_term c s t) m) = Forall (subc c (liftt s) (subst p (subc_term c (liftt s) (liftt t)) (Suc m)))\<close> by (simp add: lift_subc) also have \<open>\<dots> = Forall (subc c (liftt s) (subst p (liftt t) (Suc m)))\<close> using Forall new_lift(1) by metis finally show ?case by simp qed lemma subc_subst_new': \<open>new_term c u \<Longrightarrow> subc_term c (substt s u m) (substt t u m) = substt (subc_term c s t) u m\<close> \<open>new_term c u \<Longrightarrow> subc_list c (substt s u m) (substts l u m) = substts (subc_list c s l) u m\<close> by (induct t and l rule: subc_term.induct subc_list.induct) simp_all lemma subc_subst_new: \<open>new_term c t \<Longrightarrow> subc c (substt s t m) (subst p t m) = subst (subc c s p) t m\<close> using subc_subst_new' by (induct p arbitrary: m t s) fastforce+ lemma subc_sub_0_new [simp]: \<open>new_term c t \<Longrightarrow> subc c s (subst p t 0) = subst (subc c (liftt s) p) t 0\<close> using subc_subst_new subst_0_lift(1) by metis lemma member_subc: \<open>p \<in> set z \<Longrightarrow> subc c s p \<in> set (subcs c s z)\<close> by (induct z) auto lemma deriv_subc: fixes p :: \<open>('a, 'b) form\<close> assumes inf_params: \<open>infinite (UNIV :: 'a set)\<close> shows \<open>z \<turnstile> p \<Longrightarrow> subcs c s z \<turnstile> subc c s p\<close> proof (induct z p arbitrary: c s rule: deriv.induct) case (Assum p z) then show ?case using member_subc deriv.Assum by fast next case TTI then show ?case using deriv.TTI by simp case FFE then show ?case using deriv.FFE by auto next case (NegI z p) then show ?case using deriv.NegI by auto next case (NegE z p) then show ?case using deriv.NegE by fastforce next case (Class p z) then show ?case using deriv.Class by auto next case (ImplE z p q) then show ?case using deriv.ImplE by fastforce next case (ImplI z q p) then show ?case using deriv.ImplI by fastforce next case (OrE z p q r) then show ?case using deriv.OrE by fastforce next case (OrI1 z p q) then show ?case using deriv.OrI1 by fastforce next case (OrI2 z q p) then show ?case using deriv.OrI2 by fastforce next case (AndE1 z p q) then show ?case using deriv.AndE1 by fastforce next case (AndE2 z p q) then show ?case using deriv.AndE2 by fastforce next case (AndI p z q) then show ?case using deriv.AndI by fastforce next case (ExistsE z p d q) then show ?case proof (cases \<open>c = d\<close>) case True then have \<open>z \<turnstile> q\<close> using ExistsE deriv.ExistsE by fast moreover have \<open>new c q\<close> and \<open>news c z\<close> using ExistsE True by simp_all ultimately show ?thesis using subc_new subcs_news by metis next case False let ?params = \<open>params p \<union> params q \<union> (\<Union>p \<in> set z. params p) \<union> paramst s \<union> {c} \<union> {d}\<close> have \<open>finite ?params\<close> by simp then obtain fresh where fresh: \<open>fresh \<notin> ?params\<close> using inf_params by (meson ex_new_if_finite infinite_UNIV_listI) let ?s = \<open>psubstt (id(d := fresh)) s\<close> let ?f = \<open>id(d := fresh, fresh := d)\<close> have f: \<open>\<forall>x \<in> ?params. x \<noteq> c \<longrightarrow> ?f x \<noteq> ?f c\<close> using fresh by simp have \<open>new_term d ?s\<close> using fresh psubst_new_free'(1) by fast then have \<open>psubstt ?f ?s = psubstt (id(fresh := d)) ?s\<close> by (metis fun_upd_twist psubstt_upd(1)) then have psubst_s: \<open>psubstt ?f ?s = s\<close> using fresh by simp have \<open>?f c = c\<close> and \<open>new_term (?f c) (App fresh [])\<close> using False fresh by auto have \<open>subcs c (psubstt ?f ?s) z \<turnstile> subc c (psubstt ?f ?s) (Exists p)\<close> using ExistsE by blast then have exi_p: \<open>subcs c s z \<turnstile> Exists (subc c (liftt (psubstt ?f ?s)) p)\<close> using psubst_s by simp have \<open>news d z\<close> using ExistsE by simp moreover have \<open>news fresh z\<close> using fresh by (induct z) simp_all ultimately have \<open>map (psubst ?f) z = z\<close> by (induct z) simp_all moreover have \<open>\<forall>x \<in> \<Union>p \<in> set z. params p. x \<noteq> c \<longrightarrow> ?f x \<noteq> ?f c\<close> by auto ultimately have psubst_z: \<open>map (psubst ?f) (subcs c ?s z) = subcs c s z\<close> using \<open>?f c = c\<close> psubst_s by (simp add: subcs_psubst) have \<open>psubst ?f (subc c ?s (subst p (App d []) 0)) = subc (?f c) (psubstt ?f ?s) (psubst ?f (subst p (App d []) 0))\<close> using fresh by (simp add: subc_psubst) also have \<open>\<dots> = subc c s (subst (psubst ?f p) (App fresh []) 0)\<close> using psubst_subst psubst_s \<open>?f c = c\<close> by simp also have \<open>\<dots> = subc c s (subst p (App fresh []) 0)\<close> using ExistsE fresh by simp finally have psubst_p: \<open>psubst ?f (subc c ?s (subst p (App d []) 0)) = subst (subc c (liftt s) p) (App fresh []) 0\<close> using subc_sub_0_new \<open>new_term (?f c) (App fresh [])\<close> \<open>?f c = c\<close> by metis have \<open>\<forall>x \<in> params q. x \<noteq> c \<longrightarrow> ?f x \<noteq> ?f c\<close> using f by blast then have psubst_q: \<open>psubst ?f (subc c ?s q) = subc c s q\<close> using ExistsE fresh \<open>?f c = c\<close> psubst_s f by (simp add: subc_psubst) have \<open>subcs c ?s (subst p (App d []) 0 # z) \<turnstile> subc c ?s q\<close> using ExistsE by blast then have \<open>subc c ?s (subst p (App d []) 0) # subcs c ?s z \<turnstile> subc c ?s q\<close> by simp then have \<open>psubst ?f (subc c ?s (subst p (App d []) 0)) # map (psubst ?f) (subcs c ?s z) \<turnstile> psubst ?f (subc c ?s q)\<close> using deriv_psubst inf_params by fastforce then have q: \<open>subst (subc c (liftt s) p) (App fresh []) 0 # subcs c s z \<turnstile> subc c s q\<close> using psubst_q psubst_z psubst_p by simp have \<open>new fresh (subc c (liftt s) p)\<close> using fresh new_subc new_lift by simp moreover have \<open>new fresh (subc c s q)\<close> using fresh new_subc by simp moreover have \<open>news fresh (subcs c s z)\<close> using fresh \<open>news fresh z\<close> by (simp add: news_subcs) ultimately show \<open>subcs c s z \<turnstile> subc c s q\<close> using deriv.ExistsE exi_p q psubst_s by metis qed next case (ExistsI z p t) let ?params = \<open>params p \<union> (\<Union>p \<in> set z. params p) \<union> paramst s \<union> paramst t \<union> {c}\<close> have \<open>finite ?params\<close> by simp then obtain fresh where fresh: \<open>fresh \<notin> ?params\<close> using inf_params by (meson ex_new_if_finite infinite_UNIV_listI) let ?f = \<open>id(c := fresh)\<close> let ?g = \<open>id(fresh := c)\<close> let ?s = \<open>psubstt ?f s\<close> have c: \<open>?g c = c\<close> using fresh by simp have s: \<open>psubstt ?g ?s = s\<close> using fresh by simp have p: \<open>psubst ?g (Exists p) = Exists p\<close> using fresh by simp have \<open>\<forall>x \<in> (\<Union>p \<in> set z. params p). x \<noteq> c \<longrightarrow> ?g x \<noteq> ?g c\<close> using fresh by auto moreover have \<open>map (psubst ?g) z = z\<close> using fresh by (induct z) simp_all ultimately have z: \<open>map (psubst ?g) (subcs c ?s z) = subcs c s z\<close> using s by (simp add: subcs_psubst) have \<open>new_term c ?s\<close> using fresh psubst_new_free' by fast then have \<open>subcs c ?s z \<turnstile> subc c ?s (subst p (subc_term c ?s t) 0)\<close> using ExistsI new_subc_put by metis moreover have \<open>new_term c (subc_term c ?s t)\<close> using \<open>new_term c ?s\<close> new_subc_same' by fast ultimately have \<open>subcs c ?s z \<turnstile> subst (subc c (liftt ?s) p) (subc_term c ?s t) 0\<close> using subc_sub_0_new by metis then have \<open>subcs c ?s z \<turnstile> subc c ?s (Exists p)\<close> using deriv.ExistsI by simp then have \<open>map (psubst ?g) (subcs c ?s z) \<turnstile> psubst ?g (subc c ?s (Exists p))\<close> using deriv_psubst inf_params by blast moreover have \<open>\<forall>x \<in> params (Exists p). x \<noteq> c \<longrightarrow> ?g x \<noteq> ?g c\<close> using fresh by auto ultimately show \<open>subcs c s z \<turnstile> subc c s (Exists p)\<close> using c s p z by (simp add: subc_psubst) next case (ForallE z p t) let ?params = \<open>params p \<union> (\<Union>p \<in> set z. params p) \<union> paramst s \<union> paramst t \<union> {c}\<close> have \<open>finite ?params\<close> by simp then obtain fresh where fresh: \<open>fresh \<notin> ?params\<close> using inf_params by (meson ex_new_if_finite infinite_UNIV_listI) let ?f = \<open>id(c := fresh)\<close> let ?g = \<open>id(fresh := c)\<close> let ?s = \<open>psubstt ?f s\<close> have c: \<open>?g c = c\<close> using fresh by simp have s: \<open>psubstt ?g ?s = s\<close> using fresh by simp have p: \<open>psubst ?g (subst p t 0) = subst p t 0\<close> using fresh psubst_new psubst_subst subst_new psubst_new'(1) by fastforce have \<open>\<forall>x \<in> (\<Union>p \<in> set z. params p). x \<noteq> c \<longrightarrow> ?g x \<noteq> ?g c\<close> using fresh by auto moreover have \<open>map (psubst ?g) z = z\<close> using fresh by (induct z) simp_all ultimately have z: \<open>map (psubst ?g) (subcs c ?s z) = subcs c s z\<close> using s by (simp add: subcs_psubst) have \<open>new_term c ?s\<close> using fresh psubst_new_free' by fastforce have \<open>subcs c ?s z \<turnstile> Forall (subc c (liftt ?s) p)\<close> using ForallE by simp then have \<open>subcs c ?s z \<turnstile> subst (subc c (liftt ?s) p) (subc_term c ?s t) 0\<close> using deriv.ForallE by blast moreover have \<open>new_term c (subc_term c ?s t)\<close> using \<open>new_term c ?s\<close> new_subc_same' by fast ultimately have \<open>subcs c ?s z \<turnstile> subc c ?s (subst p (subc_term c ?s t) 0)\<close> by simp then have \<open>subcs c ?s z \<turnstile> subc c ?s (subst p t 0)\<close> using new_subc_put \<open>new_term c ?s\<close> by metis then have \<open>map (psubst ?g) (subcs c ?s z) \<turnstile> psubst ?g (subc c ?s (subst p t 0))\<close> using deriv_psubst inf_params by blast moreover have \<open>\<forall>x \<in> params (subst p t 0). x \<noteq> c \<longrightarrow> ?g x \<noteq> ?g c\<close> using fresh p psubst_new_free by (metis fun_upd_apply id_apply) ultimately show \<open>subcs c s z \<turnstile> subc c s (subst p t 0)\<close> using c s p z by (simp add: subc_psubst) next case (ForallI z p d) then show ?case proof (cases \<open>c = d\<close>) case True then have \<open>z \<turnstile> Forall p\<close> using ForallI deriv.ForallI by fast moreover have \<open>new c p\<close> and \<open>news c z\<close> using ForallI True by simp_all ultimately show ?thesis by (simp add: subcs_news) next case False let ?params = \<open>params p \<union> (\<Union>p \<in> set z. params p) \<union> paramst s \<union> {c} \<union> {d}\<close> have \<open>finite ?params\<close> by simp then obtain fresh where fresh: \<open>fresh \<notin> ?params\<close> using inf_params by (meson ex_new_if_finite infinite_UNIV_listI) let ?s = \<open>psubstt (id(d := fresh)) s\<close> let ?f = \<open>id(d := fresh, fresh := d)\<close> have f: \<open>\<forall>x \<in> ?params. x \<noteq> c \<longrightarrow> ?f x \<noteq> ?f c\<close> using fresh by simp have \<open>new_term d ?s\<close> using fresh psubst_new_free' by fastforce then have \<open>psubstt ?f ?s = psubstt (id(fresh := d)) ?s\<close> by (metis fun_upd_twist psubstt_upd(1)) then have psubst_s: \<open>psubstt ?f ?s = s\<close> using fresh by simp have \<open>?f c = c\<close> and \<open>new_term c (App fresh [])\<close> using False fresh by auto have \<open>psubst ?f (subc c ?s (subst p (App d []) 0)) = subc (?f c) (psubstt ?f ?s) (psubst ?f (subst p (App d []) 0))\<close> by (simp add: subc_psubst) also have \<open>\<dots> = subc c s (subst (psubst ?f p) (App fresh []) 0)\<close> using \<open>?f c = c\<close> psubst_subst psubst_s by simp also have \<open>\<dots> = subc c s (subst p (App fresh []) 0)\<close> using ForallI fresh by simp finally have psubst_p: \<open>psubst ?f (subc c ?s (subst p (App d []) 0)) = subst (subc c (liftt s) p) (App fresh []) 0\<close> using subc_sub_0_new \<open>new_term c (App fresh [])\<close> by simp have \<open>news d z\<close> using ForallI by simp moreover have \<open>news fresh z\<close> using fresh by (induct z) simp_all ultimately have \<open>map (psubst ?f) z = z\<close> by (induct z) simp_all moreover have \<open>\<forall>x \<in> \<Union>p \<in> set z. params p. x \<noteq> c \<longrightarrow> ?f x \<noteq> ?f c\<close> by auto ultimately have psubst_z: \<open>map (psubst ?f) (subcs c ?s z) = subcs c s z\<close> using \<open>?f c = c\<close> psubst_s by (simp add: subcs_psubst) have \<open>subcs c ?s z \<turnstile> subc c ?s (subst p (App d []) 0)\<close> using ForallI by blast then have \<open>map (psubst ?f) (subcs c ?s z) \<turnstile> psubst ?f (subc c ?s (subst p (App d []) 0))\<close> using deriv_psubst inf_params by blast then have \<open>subcs c s z \<turnstile> psubst ?f (subc c ?s (subst p (App d []) 0))\<close> using psubst_z by simp then have sub_p: \<open>subcs c s z \<turnstile> subst (subc c (liftt s) p) (App fresh []) 0\<close> using psubst_p by simp have \<open>new_term fresh s\<close> using fresh by simp then have \<open>new_term fresh (liftt s)\<close> using new_lift by simp then have \<open>new fresh (subc c (liftt s) p)\<close> using fresh new_subc by simp moreover have \<open>news fresh (subcs c s z)\<close> using \<open>news fresh z\<close> \<open>new_term fresh s\<close> news_subcs by fast ultimately show \<open>subcs c s z \<turnstile> subc c s (Forall p)\<close> using deriv.ForallI sub_p by simp qed qed subsection \<open>Weakening assumptions\<close> lemma psubst_new_subset: assumes \<open>set z \<subseteq> set z'\<close> \<open>c \<notin> (\<Union>p \<in> set z. params p)\<close> shows \<open>set z \<subseteq> set (map (psubst (id(c := n))) z')\<close> using assms by force lemma subset_cons: \<open>set z \<subseteq> set z' \<Longrightarrow> set (p # z) \<subseteq> set (p # z')\<close> by auto lemma weaken_assumptions: fixes p :: \<open>('a, 'b) form\<close> assumes inf_params: \<open>infinite (UNIV :: 'a set)\<close> shows \<open>z \<turnstile> p \<Longrightarrow> set z \<subseteq> set z' \<Longrightarrow> z' \<turnstile> p\<close> proof (induct z p arbitrary: z' rule: deriv.induct) case (Assum p z) then show ?case using deriv.Assum by auto next case TTI then show ?case using deriv.TTI by auto next case FFE then show ?case using deriv.FFE by auto next case (NegI p z) then show ?case using deriv.NegI subset_cons by metis next case (NegE p z) then show ?case using deriv.NegE by metis next case (Class z p) then show ?case using deriv.Class subset_cons by metis next case (ImplE z p q) then show ?case using deriv.ImplE by blast next case (ImplI z q p) then show ?case using deriv.ImplI subset_cons by metis next case (OrE z p q z ) then show ?case using deriv.OrE subset_cons by metis next case (OrI1 z p q) then show ?case using deriv.OrI1 by blast next case (OrI2 z q p) then show ?case using deriv.OrI2 by blast next case (AndE1 z p q) then show ?case using deriv.AndE1 by blast next case (AndE2 z p q) then show ?case using deriv.AndE2 by blast next case (AndI z p q) then show ?case using deriv.AndI by blast next case (ExistsE z p c q) let ?params = \<open>params p \<union> params q \<union> (\<Union>p \<in> set z'. params p) \<union> {c}\<close> have \<open>finite ?params\<close> by simp then obtain fresh where fresh: \<open>fresh \<notin> ?params\<close> using inf_params by (meson ex_new_if_finite List.finite_set infinite_UNIV_listI) let ?z' = \<open>map (psubst (id(c := fresh))) z'\<close> have \<open>news c z\<close> using ExistsE by simp then have \<open>set z \<subseteq> set ?z'\<close> using ExistsE psubst_new_subset by (simp add: Ball_set) then have \<open>?z' \<turnstile> Exists p\<close> using ExistsE by blast moreover have \<open>set (subst p (App c []) 0 # z) \<subseteq> set (subst p (App c []) 0 # ?z')\<close> using \<open>set z \<subseteq> set ?z'\<close> by auto then have \<open>subst p (App c []) 0 # ?z' \<turnstile> q\<close> using ExistsE by blast moreover have \<open>news c ?z'\<close> using fresh by (simp add: map_psubst_new_free) then have \<open>new c p\<close> \<open>new c q\<close> \<open>news c ?z'\<close> using ExistsE by simp_all ultimately have \<open>?z' \<turnstile> q\<close> using ExistsE deriv.ExistsE by metis then have \<open>map (psubst (id(fresh := c))) ?z' \<turnstile> psubst (id(fresh := c)) q\<close> using deriv_psubst inf_params by blast moreover have \<open>map (psubst (id(fresh := c))) ?z' = z'\<close> using fresh map_psubst_new_away Ball_set by fastforce moreover have \<open>psubst (id(fresh := c)) q = q\<close> using fresh by simp ultimately show \<open>z' \<turnstile> q\<close> by simp next case (ExistsI z p t) then show ?case using deriv.ExistsI by blast next case (ForallE p z t) then show ?case using deriv.ForallE by blast next case (ForallI z p c) let ?params = \<open>params p \<union> (\<Union>p \<in> set z'. params p) \<union> {c}\<close> have \<open>finite ?params\<close> by simp then obtain fresh where fresh: \<open>fresh \<notin> ?params\<close> using inf_params by (meson ex_new_if_finite List.finite_set infinite_UNIV_listI) let ?z' = \<open>map (psubst (id(c := fresh))) z'\<close> have \<open>news c z\<close> using ForallI by simp then have \<open>set z \<subseteq> set ?z'\<close> using ForallI psubst_new_subset by (metis (no_types, lifting) Ball_set UN_iff) then have \<open>?z' \<turnstile> subst p (App c []) 0\<close> using ForallI by blast moreover have \<open>\<forall>p \<in> set ?z'. c \<notin> params p\<close> using fresh psubst_new_free by fastforce then have \<open>list_all (\<lambda>p. c \<notin> params p) (p # ?z')\<close> using ForallI by (simp add: list_all_iff) then have \<open>new c p\<close> \<open>news c ?z'\<close> by simp_all ultimately have \<open>?z' \<turnstile> Forall p\<close> using ForallI deriv.ForallI by fast then have \<open>map (psubst (id(fresh := c))) ?z' \<turnstile> psubst (id(fresh := c)) (Forall p)\<close> using deriv_psubst inf_params by blast moreover have \<open>map (psubst (id(fresh := c))) ?z' = z'\<close> using fresh map_psubst_new_away Ball_set by fastforce moreover have \<open>psubst (id(fresh := c)) (Forall p) = Forall p\<close> using fresh ForallI by simp ultimately show \<open>z' \<turnstile> Forall p\<close> by simp qed subsection \<open>Implications and assumptions\<close> primrec put_imps :: \<open>('a, 'b) form \<Rightarrow> ('a, 'b) form list \<Rightarrow> ('a, 'b) form\<close> where \<open>put_imps p [] = p\<close> | \<open>put_imps p (q # z) = Impl q (put_imps p z)\<close> lemma semantics_put_imps: \<open>(e,f,g,z \<Turnstile> p) = eval e f g (put_imps p z)\<close> unfolding model_def by (induct z) auto subsection \<open>Closure elimination\<close> lemma subc_sub_closed_var' [simp]: \<open>new_term c t \<Longrightarrow> closedt (Suc m) t \<Longrightarrow> subc_term c (Var m) (substt t (App c []) m) = t\<close> \<open>new_list c l \<Longrightarrow> closedts (Suc m) l \<Longrightarrow> subc_list c (Var m) (substts l (App c []) m) = l\<close> by (induct t and l rule: substt.induct substts.induct) auto lemma subc_sub_closed_var [simp]: \<open>new c p \<Longrightarrow> closed (Suc m) p \<Longrightarrow> subc c (Var m) (subst p (App c []) m) = p\<close> by (induct p arbitrary: m) simp_all primrec put_unis :: \<open>nat \<Rightarrow> ('a, 'b) form \<Rightarrow> ('a, 'b) form\<close> where \<open>put_unis 0 p = p\<close> | \<open>put_unis (Suc m) p = Forall (put_unis m p)\<close> lemma sub_put_unis [simp]: \<open>subst (put_unis k p) (App c []) i = put_unis k (subst p (App c []) (i + k))\<close> by (induct k arbitrary: i) simp_all lemma valid_put_unis: \<open>\<forall>(e :: nat \<Rightarrow> 'a) f g. eval e f g p \<Longrightarrow> eval (e :: nat \<Rightarrow> 'a) f g (put_unis m p)\<close> by (induct m arbitrary: e) simp_all lemma put_unis_collapse: \<open>put_unis m (put_unis n p) = put_unis (m + n) p\<close> by (induct m) simp_all fun consts_for_unis :: \<open>('a, 'b) form \<Rightarrow> 'a list \<Rightarrow> ('a, 'b) form\<close> where \<open>consts_for_unis (Forall p) (c#cs) = consts_for_unis (subst p (App c []) 0) cs\<close> | \<open>consts_for_unis p _ = p\<close> lemma consts_for_unis: \<open>[] \<turnstile> put_unis (length cs) p \<Longrightarrow> [] \<turnstile> consts_for_unis (put_unis (length cs) p) cs\<close> proof (induct cs arbitrary: p) case (Cons c cs) then have \<open>[] \<turnstile> Forall (put_unis (length cs) p)\<close> by simp then have \<open>[] \<turnstile> subst (put_unis (length cs) p) (App c []) 0\<close> using ForallE by blast then show ?case using Cons by simp qed simp primrec vars_for_consts :: \<open>('a, 'b) form \<Rightarrow> 'a list \<Rightarrow> ('a, 'b) form\<close> where \<open>vars_for_consts p [] = p\<close> | \<open>vars_for_consts p (c # cs) = subc c (Var (length cs)) (vars_for_consts p cs)\<close> lemma vars_for_consts: assumes \<open>infinite (- params p)\<close> shows \<open>[] \<turnstile> p \<Longrightarrow> [] \<turnstile> vars_for_consts p xs\<close> using assms deriv_subc by (induct xs arbitrary: p) fastforce+ lemma vars_for_consts_for_unis: \<open>closed (length cs) p \<Longrightarrow> list_all (\<lambda>c. new c p) cs \<Longrightarrow> distinct cs \<Longrightarrow> vars_for_consts (consts_for_unis (put_unis (length cs) p) cs) cs = p\<close> by (induct cs arbitrary: p) (simp_all add: subst_new_all) lemma fresh_constant: fixes p :: \<open>('a, 'b) form\<close> assumes \<open>infinite (UNIV :: 'a set)\<close> shows \<open>\<exists>c. c \<notin> set cs \<and> new c p\<close> proof - have \<open>finite (set cs \<union> params p)\<close> by simp then show ?thesis using assms ex_new_if_finite UnI1 UnI2 by metis qed lemma fresh_constants: fixes p :: \<open>('a, 'b) form\<close> assumes \<open>infinite (UNIV :: 'a set)\<close> shows \<open>\<exists>cs. length cs = m \<and> list_all (\<lambda>c. new c p) cs \<and> distinct cs\<close> proof (induct m) case (Suc m) then obtain cs where \<open>length cs = m \<and> list_all (\<lambda>c. new c p) cs \<and> distinct cs\<close> by blast moreover obtain c where \<open>c \<notin> set cs \<and> new c p\<close> using Suc assms fresh_constant by blast ultimately have \<open>length (c # cs) = Suc m \<and> list_all (\<lambda>c. new c p) (c # cs) \<and> distinct (c # cs)\<close> by simp then show ?case by blast qed simp lemma closed_max: assumes \<open>closed m p\<close> \<open>closed n q\<close> shows \<open>closed (max m n) p \<and> closed (max m n) q\<close> proof - have \<open>m \<le> max m n\<close> and \<open>n \<le> max m n\<close> by simp_all then show ?thesis using assms closed_mono by metis qed lemma ex_closed' [simp]: fixes t :: \<open>'a term\<close> and l :: \<open>'a term list\<close> shows \<open>\<exists>m. closedt m t\<close> \<open>\<exists>n. closedts n l\<close> proof (induct t and l rule: closedt.induct closedts.induct) case (Cons_term t l) then obtain m and n where \<open>closedt m t\<close> and \<open>closedts n l\<close> by blast moreover have \<open>m \<le> max m n\<close> and \<open>n \<le> max m n\<close> by simp_all ultimately have \<open>closedt (max m n) t\<close> and \<open>closedts (max m n) l\<close> using closedt_mono by blast+ then show ?case by auto qed auto lemma ex_closed [simp]: \<open>\<exists>m. closed m p\<close> proof (induct p) case FF then show ?case by simp next case TT then show ?case by simp next case (Neg p) then show ?case by simp next case (Impl p q) then show ?case using closed_max by fastforce next case (Or p q) then show ?case using closed_max by fastforce next case (And p q) then show ?case using closed_max by fastforce next case (Exists p) then obtain m where \<open>closed m p\<close> by blast then have \<open>closed (Suc m) p\<close> using closed_mono Suc_n_not_le_n nat_le_linear by blast then show ?case by auto next case (Forall p) then obtain m where \<open>closed m p\<close> by blast then have \<open>closed (Suc m) p\<close> using closed_mono Suc_n_not_le_n nat_le_linear by blast then show ?case by auto qed simp_all lemma ex_closure: \<open>\<exists>m. closed 0 (put_unis m p)\<close> by simp lemma remove_unis_sentence: assumes inf_params: \<open>infinite (- params p)\<close> and \<open>closed 0 (put_unis m p)\<close> \<open>[] \<turnstile> put_unis m p\<close> shows \<open>[] \<turnstile> p\<close> proof - obtain cs :: \<open>'a list\<close> where \<open>length cs = m\<close> and *: \<open>distinct cs\<close> and **: \<open>list_all (\<lambda>c. new c p) cs\<close> using assms finite_compl finite_params fresh_constants inf_params by metis then have \<open>[] \<turnstile> consts_for_unis (put_unis (length cs) p) cs\<close> using assms consts_for_unis by blast then have \<open>[] \<turnstile> vars_for_consts (consts_for_unis (put_unis (length cs) p) cs) cs\<close> using vars_for_consts inf_params by fastforce moreover have \<open>closed (length cs) p\<close> using assms \<open>length cs = m\<close> by simp ultimately show \<open>[] \<turnstile> p\<close> using vars_for_consts_for_unis * ** by metis qed subsection \<open>Completeness\<close> theorem completeness: fixes p :: \<open>(nat, nat) form\<close> assumes \<open>\<forall>(e :: nat \<Rightarrow> nat hterm) f g. e, f, g, z \<Turnstile> p\<close> shows \<open>z \<turnstile> p\<close> proof - let ?p = \<open>put_imps p (rev z)\<close> have *: \<open>\<forall>(e :: nat \<Rightarrow> nat hterm) f g. eval e f g ?p\<close> using assms semantics_put_imps unfolding model_def by fastforce obtain m where **: \<open>closed 0 (put_unis m ?p)\<close> using ex_closure by blast moreover have \<open>list_all (closed 0) []\<close> by simp moreover have \<open>\<forall>(e :: nat \<Rightarrow> nat hterm) f g. e, f, g, [] \<Turnstile> put_unis m ?p\<close> using * valid_put_unis unfolding model_def by blast ultimately have \<open>[] \<turnstile> put_unis m ?p\<close> using natded_complete by blast then have \<open>[] \<turnstile> ?p\<close> using ** remove_unis_sentence by fastforce then show \<open>z \<turnstile> p\<close> using remove_imps by fastforce qed abbreviation \<open>valid p \<equiv> \<forall>(e :: nat \<Rightarrow> nat hterm) f g. eval e f g p\<close> proposition fixes p :: \<open>(nat, nat) form\<close> shows \<open>valid p \<Longrightarrow> eval e f g p\<close> using completeness correctness unfolding model_def by (metis list.pred_inject(1)) proposition fixes p :: \<open>(nat, nat) form\<close> shows \<open>([] \<turnstile> p) = valid p\<close> using completeness correctness unfolding model_def by fastforce corollary \<open>\<forall>e (f::nat \<Rightarrow> nat hterm list \<Rightarrow> nat hterm) (g::nat \<Rightarrow> nat hterm list \<Rightarrow> bool). e,f,g,ps \<Turnstile> p \<Longrightarrow> ps \<turnstile> p\<close> by (rule completeness) end
implicit none integer ns double precision, allocatable :: source(:,:) double complex, allocatable :: charge(:) double complex, allocatable :: pot(:) double complex, allocatable :: potex(:) double precision eps double complex eye,zk integer i,j,k integer ntest,nd double precision thresh,ra,erra double precision hkrand data eye/(0.0d0,1.0d0)/ c cc initialize printing routine c cc call prini(6,13) write(*,*) write(*,*) write(*,*) "=================================" print *, "This code is an example fortran driver*" write(*,*) write(*,*) zk = 2.2d0 ns = 300 000 000 print *, "nsources =",ns allocate(source(3,ns)) allocate(charge(ns)) allocate(pot(ns)) eps = 0.5d-3 write(*,*) "==========================================" c c c example demonstrating use of c source to source, charges, pot + gradient c c cc generate sources uniformly in the unit cube c c do i=1,ns source(1,i) = hkrand(0)**2 source(2,i) = hkrand(0)**2 source(3,i) = hkrand(0)**2 charge(i) = hkrand(0) + eye*hkrand(0) pot(i) = 0 enddo call hfmm3d_s_c_p(eps,zk,ns,source,charge,pot) ntest = 10 allocate(potex(ntest)) do i=1,ntest potex(i) = 0 enddo thresh = 1.0d-16 nd = 1 call h3ddirectcp(nd,zk,source,charge,ns,source,ntest,potex, 1 thresh) ra = 0 erra = 0 do i=1,ntest ra = ra + abs(potex(i))**2 erra = erra + abs(pot(i)-potex(i))**2 enddo erra = sqrt(erra/ra) print *, "Relative error in pot=",erra stop end c---------------------------------------------------------- c cc c c
State Before: α : Type u_1 β : Type u_2 γ : Type u_3 δ : Type ?u.34299 a : α s✝ t : Multiset α f✝ g✝ : α → Multiset β s : Multiset α f : α → Multiset β g : β → Multiset γ ⊢ bind (bind 0 f) g = bind 0 fun a => bind (f a) g State After: no goals Tactic: simp State Before: α : Type u_1 β : Type u_2 γ : Type u_3 δ : Type ?u.34299 a : α s✝ t : Multiset α f✝ g✝ : α → Multiset β s : Multiset α f : α → Multiset β g : β → Multiset γ ⊢ ∀ ⦃a : α⦄ {s : Multiset α}, (bind (bind s f) g = bind s fun a => bind (f a) g) → bind (bind (a ::ₘ s) f) g = bind (a ::ₘ s) fun a => bind (f a) g State After: no goals Tactic: simp (config := { contextual := true })
/- Copyright (c) 2020 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa, Jujian Zhang ! This file was ported from Lean 3 source module number_theory.liouville.liouville_constant ! leanprover-community/mathlib commit 98cbfb459a053c5ca44aec69f0a5a932b84c0d67 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.NumberTheory.Liouville.Basic /-! # Liouville constants This file contains a construction of a family of Liouville numbers, indexed by a natural number $m$. The most important property is that they are examples of transcendental real numbers. This fact is recorded in `liouville.is_transcendental`. More precisely, for a real number $m$, Liouville's constant is $$ \sum_{i=0}^\infty\frac{1}{m^{i!}}. $$ The series converges only for $1 < m$. However, there is no restriction on $m$, since, if the series does not converge, then the sum of the series is defined to be zero. We prove that, for $m \in \mathbb{N}$ satisfying $2 \le m$, Liouville's constant associated to $m$ is a transcendental number. Classically, the Liouville number for $m = 2$ is the one called ``Liouville's constant''. ## Implementation notes The indexing $m$ is eventually a natural number satisfying $2 ≤ m$. However, we prove the first few lemmas for $m \in \mathbb{R}$. -/ noncomputable section open Nat BigOperators open Real Finset namespace Liouville /-- For a real number `m`, Liouville's constant is $$ \sum_{i=0}^\infty\frac{1}{m^{i!}}. $$ The series converges only for `1 < m`. However, there is no restriction on `m`, since, if the series does not converge, then the sum of the series is defined to be zero. -/ def liouvilleNumber (m : ℝ) : ℝ := ∑' i : ℕ, 1 / m ^ i ! #align liouville.liouville_number Liouville.liouvilleNumber /-- `liouville_number_initial_terms` is the sum of the first `k + 1` terms of Liouville's constant, i.e. $$ \sum_{i=0}^k\frac{1}{m^{i!}}. $$ -/ def liouvilleNumberInitialTerms (m : ℝ) (k : ℕ) : ℝ := ∑ i in range (k + 1), 1 / m ^ i ! #align liouville.liouville_number_initial_terms Liouville.liouvilleNumberInitialTerms /-- `liouville_number_tail` is the sum of the series of the terms in `liouville_number m` starting from `k+1`, i.e $$ \sum_{i=k+1}^\infty\frac{1}{m^{i!}}. $$ -/ def liouvilleNumberTail (m : ℝ) (k : ℕ) : ℝ := ∑' i, 1 / m ^ (i + (k + 1))! #align liouville.liouville_number_tail Liouville.liouvilleNumberTail theorem liouvilleNumberTail_pos {m : ℝ} (hm : 1 < m) (k : ℕ) : 0 < liouvilleNumberTail m k := calc -- replace `0` with the constantly zero series `∑ i : ℕ, 0` (0 : ℝ) = ∑' i : ℕ, 0 := tsum_zero.symm _ < liouvilleNumberTail m k :=-- to show that a series with non-negative terms has strictly positive sum it suffices -- to prove that -- 1. the terms of the zero series are indeed non-negative -- 2. the terms of our series are non-negative -- 3. one term of our series is strictly positive -- they all are, we use the first term tsum_lt_tsum_of_nonneg (fun _ => rfl.le) (fun i => one_div_nonneg.mpr (pow_nonneg (zero_le_one.trans hm.le) _)) (one_div_pos.mpr (pow_pos (zero_lt_one.trans hm) (0 + (k + 1))!)) <|-- 4. our series converges -- it does since it is the tail of a converging series, though -- this is not the argument here. summable_one_div_pow_of_le hm fun i => trans le_self_add (Nat.self_le_factorial _) #align liouville.liouville_number_tail_pos Liouville.liouvilleNumberTail_pos /-- Split the sum definining a Liouville number into the first `k` term and the rest. -/ theorem liouvilleNumber_eq_initial_terms_add_tail {m : ℝ} (hm : 1 < m) (k : ℕ) : liouvilleNumber m = liouvilleNumberInitialTerms m k + liouvilleNumberTail m k := (sum_add_tsum_nat_add _ (summable_one_div_pow_of_le hm fun i => i.self_le_factorial)).symm #align liouville.liouville_number_eq_initial_terms_add_tail Liouville.liouvilleNumber_eq_initial_terms_add_tail /-! We now prove two useful inequalities, before collecting everything together. -/ /-- Partial inequality, works with `m ∈ ℝ` satisfying `1 < m`. -/ theorem tsum_one_div_pow_factorial_lt (n : ℕ) {m : ℝ} (m1 : 1 < m) : (∑' i : ℕ, 1 / m ^ (i + (n + 1))!) < (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) := have m0 :-- two useful inequalities 0 < m := zero_lt_one.trans m1 have mi : |1 / m| < 1 := (le_of_eq (abs_of_pos (one_div_pos.mpr m0))).trans_lt ((div_lt_one m0).mpr m1) calc (∑' i, 1 / m ^ (i + (n + 1))!) < ∑' i, 1 / m ^ (i + (n + 1)!) :=-- to show the strict inequality between these series, we prove that: tsum_lt_tsum_of_nonneg (-- 1. the first series has non-negative terms fun b => one_div_nonneg.mpr (pow_nonneg m0.le _)) (-- 2. the second series dominates the first fun b => one_div_pow_le_one_div_pow_of_le m1.le (b.add_factorial_succ_le_factorial_add_succ n)) (-- 3. the term with index `i = 2` of the first series is strictly smaller than -- the corresponding term of the second series one_div_pow_strictAnti m1 (n.add_factorial_succ_lt_factorial_add_succ rfl.le)) (-- 4. the second series is summable, since its terms grow quickly summable_one_div_pow_of_le m1 fun j => Nat.le.intro rfl) _ = ∑' i, (1 / m) ^ i * (1 / m ^ (n + 1)!) :=-- split the sum in the exponent and massage by congr ext i rw [pow_add, ← div_div, div_eq_mul_one_div, one_div_pow] -- factor the constant `(1 / m ^ (n + 1)!)` out of the series _ = (∑' i, (1 / m) ^ i) * (1 / m ^ (n + 1)!) := tsum_mul_right _ = (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) :=-- the series if the geometric series mul_eq_mul_right_iff.mpr (Or.inl (tsum_geometric_of_abs_lt_1 mi)) #align liouville.tsum_one_div_pow_factorial_lt Liouville.tsum_one_div_pow_factorial_lt theorem aux_calc (n : ℕ) {m : ℝ} (hm : 2 ≤ m) : (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) ≤ 1 / (m ^ n !) ^ n := calc (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) ≤ 2 * (1 / m ^ (n + 1)!) :=-- the second factors coincide (and are non-negative), -- the first factors, satisfy the inequality `sub_one_div_inv_le_two` mul_le_mul_of_nonneg_right (sub_one_div_inv_le_two hm) (by positivity) _ = 2 / m ^ (n + 1)! := (mul_one_div 2 _) _ = 2 / m ^ (n ! * (n + 1)) := (congr_arg ((· / ·) 2) (congr_arg (pow m) (mul_comm _ _))) _ ≤ 1 / m ^ (n ! * n) := by -- [ NB: in this block, I do not follow the brace convention for subgoals -- I wait until -- I solve all extraneous goals at once with `exact pow_pos (zero_lt_two.trans_le hm) _`. ] -- Clear denominators and massage* apply (div_le_div_iff _ _).mpr conv_rhs => rw [one_mul, mul_add, pow_add, mul_one, pow_mul, mul_comm, ← pow_mul] -- the second factors coincide, so we prove the inequality of the first factors* refine' (mul_le_mul_right _).mpr _ -- solve all the inequalities `0 < m ^ ??` any_goals exact pow_pos (zero_lt_two.trans_le hm) _ -- `2 ≤ m ^ n!` is a consequence of monotonicity of exponentiation at `2 ≤ m`. exact trans (trans hm (pow_one _).symm.le) (pow_mono (one_le_two.trans hm) n.factorial_pos) _ = 1 / (m ^ n !) ^ n := congr_arg ((· / ·) 1) (pow_mul m n ! n) #align liouville.aux_calc Liouville.aux_calc /-! Starting from here, we specialize to the case in which `m` is a natural number. -/ /-- The sum of the `k` initial terms of the Liouville number to base `m` is a ratio of natural numbers where the denominator is `m ^ k!`. -/ theorem liouville_number_rat_initial_terms {m : ℕ} (hm : 0 < m) (k : ℕ) : ∃ p : ℕ, liouvilleNumberInitialTerms m k = p / m ^ k ! := by induction' k with k h · exact ⟨1, by rw [liouville_number_initial_terms, range_one, sum_singleton, Nat.cast_one]⟩ · rcases h with ⟨p_k, h_k⟩ use p_k * m ^ ((k + 1)! - k !) + 1 unfold liouville_number_initial_terms at h_k⊢ rw [sum_range_succ, h_k, div_add_div, div_eq_div_iff, add_mul] · norm_cast rw [add_mul, one_mul, Nat.factorial_succ, show k.succ * k ! - k ! = (k.succ - 1) * k ! by rw [tsub_mul, one_mul], Nat.succ_sub_one, add_mul, one_mul, pow_add] simp [mul_assoc] refine' mul_ne_zero_iff.mpr ⟨_, _⟩ all_goals exact pow_ne_zero _ (nat.cast_ne_zero.mpr hm.ne.symm) #align liouville.liouville_number_rat_initial_terms Liouville.liouville_number_rat_initial_terms theorem is_liouville {m : ℕ} (hm : 2 ≤ m) : Liouville (liouvilleNumber m) := by -- two useful inequalities have mZ1 : 1 < (m : ℤ) := by norm_cast exact one_lt_two.trans_le hm have m1 : 1 < (m : ℝ) := by norm_cast exact one_lt_two.trans_le hm intro n -- the first `n` terms sum to `p / m ^ k!` rcases liouville_number_rat_initial_terms (zero_lt_two.trans_le hm) n with ⟨p, hp⟩ refine' ⟨p, m ^ n !, one_lt_pow mZ1 n.factorial_ne_zero, _⟩ push_cast -- separate out the sum of the first `n` terms and the rest rw [liouville_number_eq_initial_terms_add_tail m1 n, ← hp, add_sub_cancel', abs_of_nonneg (liouville_number_tail_pos m1 _).le] exact ⟨((lt_add_iff_pos_right _).mpr (liouville_number_tail_pos m1 n)).Ne.symm, (tsum_one_div_pow_factorial_lt n m1).trans_le (aux_calc _ (nat.cast_two.symm.le.trans (nat.cast_le.mpr hm)))⟩ #align liouville.is_liouville Liouville.is_liouville /- Placing this lemma outside of the `open/closed liouville`-namespace would allow to remove `_root_.`, at the cost of some other small weirdness. -/ theorem is_transcendental {m : ℕ} (hm : 2 ≤ m) : Transcendental ℤ (liouvilleNumber m) := transcendental (is_liouville hm) #align liouville.is_transcendental Liouville.is_transcendental end Liouville
* SB10FD EXAMPLE PROGRAM TEXT * Copyright (c) 2002-2020 NICONET e.V. * * .. Parameters .. INTEGER NIN, NOUT PARAMETER ( NIN = 5, NOUT = 6 ) INTEGER NMAX, MMAX, PMAX, N2MAX PARAMETER ( NMAX = 10, MMAX = 10, PMAX = 10, N2MAX = 20 ) INTEGER LDA, LDB, LDC, LDD, LDAK, LDBK, LDCK, LDDK, $ LDAC, LDBC, LDCC, LDDC PARAMETER ( LDA = NMAX, LDB = NMAX, LDC = PMAX, LDD = PMAX, $ LDAK = NMAX, LDBK = NMAX, LDCK = MMAX, $ LDDK = MMAX, LDAC = 2*NMAX, LDBC = 2*NMAX, $ LDCC = PMAX, LDDC = PMAX ) INTEGER LIWORK PARAMETER ( LIWORK = MAX( 2*MAX( NMAX, MMAX, PMAX ), $ NMAX*NMAX ) ) INTEGER MPMX PARAMETER ( MPMX = MAX( MMAX, PMAX ) ) INTEGER LDWORK PARAMETER ( LDWORK = 2*MPMX*( 3*MPMX + 2*NMAX ) + $ MAX( ( NMAX + MPMX )*( NMAX + MPMX + 6 ), $ MPMX*( MPMX + MAX( NMAX, MPMX, 5 ) + 1 ), $ 2*NMAX*( NMAX + 2*MPMX ) + $ MAX( 4*MPMX*MPMX + MAX( 2*MPMX, 3*NMAX*NMAX + $ MAX( 2*NMAX*MPMX, 10*NMAX*NMAX+12*NMAX+5 ) ), $ MPMX*( 3*NMAX + 3*MPMX + $ MAX( 2*NMAX, 4*MPMX + $ MAX( NMAX, MPMX ) ) ) ) ) ) * .. Local Scalars .. INTEGER SDIM LOGICAL SELECT DOUBLE PRECISION GAMMA, TOL INTEGER I, INFO1, INFO2, INFO3, J, M, N, NCON, NMEAS, NP * .. Local Arrays .. LOGICAL BWORK(N2MAX) INTEGER IWORK(LIWORK) DOUBLE PRECISION A(LDA,NMAX), AK(LDAK,NMAX), AC(LDAC,N2MAX), $ B(LDB,MMAX), BK(LDBK,PMAX), BC(LDBC,MMAX), $ C(LDC,NMAX), CK(LDCK,NMAX), CC(LDCC,N2MAX), $ D(LDD,MMAX), DK(LDDK,PMAX), DC(LDDC,MMAX), $ DWORK(LDWORK), RCOND( 4 ) * .. External Subroutines .. EXTERNAL SB10FD, SB10LD * .. Intrinsic Functions .. INTRINSIC MAX * .. Executable Statements .. * WRITE ( NOUT, FMT = 99999 ) * Skip the heading in the data file and read the data. READ ( NIN, FMT = '()' ) READ ( NIN, FMT = * ) N, M, NP, NCON, NMEAS IF ( N.LT.0 .OR. N.GT.NMAX ) THEN WRITE ( NOUT, FMT = 99987 ) N ELSE IF ( M.LT.0 .OR. M.GT.MMAX ) THEN WRITE ( NOUT, FMT = 99986 ) M ELSE IF ( NP.LT.0 .OR. NP.GT.PMAX ) THEN WRITE ( NOUT, FMT = 99985 ) NP ELSE IF ( NCON.LT.0 .OR. NCON.GT.MMAX ) THEN WRITE ( NOUT, FMT = 99984 ) NCON ELSE IF ( NMEAS.LT.0 .OR. NMEAS.GT.PMAX ) THEN WRITE ( NOUT, FMT = 99983 ) NMEAS ELSE READ ( NIN, FMT = * ) ( ( A(I,J), J = 1,N ), I = 1,N ) READ ( NIN, FMT = * ) ( ( B(I,J), J = 1,M ), I = 1,N ) READ ( NIN, FMT = * ) ( ( C(I,J), J = 1,N ), I = 1,NP ) READ ( NIN, FMT = * ) ( ( D(I,J), J = 1,M ), I = 1,NP ) READ ( NIN, FMT = * ) GAMMA, TOL * Compute the suboptimal controller CALL SB10FD( N, M, NP, NCON, NMEAS, GAMMA, A, LDA, B, LDB, $ C, LDC, D, LDD, AK, LDAK, BK, LDBK, CK, LDCK, $ DK, LDDK, RCOND, TOL, IWORK, DWORK, LDWORK, $ BWORK, INFO1 ) * IF ( INFO1.EQ.0 ) THEN WRITE ( NOUT, FMT = 99996 ) DO 10 I = 1, N WRITE ( NOUT, FMT = 99989 ) ( AK(I,J), J = 1,N ) 10 CONTINUE WRITE ( NOUT, FMT = 99995 ) DO 20 I = 1, N WRITE ( NOUT, FMT = 99989 ) ( BK(I,J), J = 1,NMEAS ) 20 CONTINUE WRITE ( NOUT, FMT = 99994 ) DO 30 I = 1, NCON WRITE ( NOUT, FMT = 99989 ) ( CK(I,J), J = 1,N ) 30 CONTINUE WRITE ( NOUT, FMT = 99993 ) DO 40 I = 1, NCON WRITE ( NOUT, FMT = 99989 ) ( DK(I,J), J = 1,NMEAS ) 40 CONTINUE WRITE( NOUT, FMT = 99992 ) WRITE( NOUT, FMT = 99988 ) ( RCOND(I), I = 1, 4 ) * Compute the closed-loop matrices CALL SB10LD(N, M, NP, NCON, NMEAS, A, LDA, B, LDB, C, LDC, $ D, LDD, AK, LDAK, BK, LDBK, CK, LDCK, DK, LDDK, $ AC, LDAC, BC, LDBC, CC, LDCC, DC, LDDC, IWORK, $ DWORK, LDWORK, INFO2 ) * IF ( INFO2.EQ.0 ) THEN * Compute the closed-loop poles CALL DGEES( 'N','N', SELECT, 2*N, AC, LDAC, SDIM, $ DWORK(1), DWORK(2*N+1), DWORK, 2*N, $ DWORK(4*N+1), LDWORK-4*N, BWORK, INFO3) * IF( INFO3.EQ.0 ) THEN WRITE( NOUT, FMT = 99991 ) WRITE( NOUT, FMT = 99988 ) (DWORK(I), I =1, 2*N) WRITE( NOUT, FMT = 99990 ) WRITE( NOUT, FMT = 99988 ) (DWORK(2*N+I), I =1, 2*N) ELSE WRITE( NOUT, FMT = 99996 ) INFO3 END IF ELSE WRITE( NOUT, FMT = 99997 ) INFO2 END IF ELSE WRITE( NOUT, FMT = 99998 ) INFO1 END IF END IF STOP * 99999 FORMAT (' SB10FD EXAMPLE PROGRAM RESULTS',/1X) 99998 FORMAT (/' INFO on exit from SB10FD =',I2) 99997 FORMAT (/' INFO on exit from SB10LD =',I2) 99996 FORMAT (' The controller state matrix AK is'/) 99995 FORMAT (/' The controller input matrix BK is'/) 99994 FORMAT (/' The controller output matrix CK is'/) 99993 FORMAT (/' The controller matrix DK is'/) 99992 FORMAT (/' The estimated condition numbers are'/) 99991 FORMAT (/' The real parts of the closed-loop system poles are'/) 99990 FORMAT (/' The imaginary parts of the closed-loop system', $ ' poles are'/) 99989 FORMAT (10(1X,F8.4)) 99988 FORMAT ( 5(1X,D12.5)) 99987 FORMAT (/' N is out of range.',/' N = ',I5) 99986 FORMAT (/' M is out of range.',/' M = ',I5) 99985 FORMAT (/' N is out of range.',/' N = ',I5) 99984 FORMAT (/' NCON is out of range.',/' NCON = ',I5) 99983 FORMAT (/' NMEAS is out of range.',/' NMEAS = ',I5) END
\part{Reference documentation} \section{Overview} \label{sec:mskref} This part contains the reference documentation for how parameters need to be formatted as well as the output of the simulator. It does not explain how to access the simulator from Java code. One needs to refer to Section~\ref{sec:mskusejava}, and the ContactCenters API documentation for this. Section~\ref{sec:mskxml} describes how XML is used by the simulator. It provides a brief overview of XML as well as the main data structures specific to our paramater file format. We also give examples on how the HTML documentation for specific parameters of the simulator can be retrieved. The following subsections give the available performance measures, arrival processes, routing and dialing policies, which are not listed in the HTML documentation for parameters. % Types of performance measures, arrival processes, % dialer's, and router's policies are represented as strings in the XML % documents. % These strings are not constrained by the XML % schema representing parameter files, because plug-ins may % eventually provide additional strings. % As a result, the authorized values of these strings are not given in % the HTML documentation of the schemas. % The following sections therefore give the builtin % types of performance measures, % arrival processes, % dialer's, and router's policies. %Section~\ref{sec:mskccparams} details the elements and attributes used %to describe a call center to be simulated. %Section~\ref{sec:msksimparams} provides a detailed description of the %parameters used to perform experiments. %For each XML element described in these two sections, the %its name, %acceptable attributes, and allowed %nested contents are specified and defined. Required elements and %attributes are identified. If an element or attribute is not %explicitly marked as required, it is optional and a default value or %behavior is specified in the documentation. Section~\ref{sec:mskexp} explains in more details the two supported methods of experiment. In particular, it contains information on how sequential sampling and batch means work in the simulator. Section~\ref{sec:mskoutput} describes the output produced by the simulator. It describes the contents and format of any report produced by the simulator, and how performance measures are regrouped into matrices. Every supported type of performance measure is also presented in detail.
= = Appearances and goals = =
! { dg-do run } ! { dg-options "-fno-range-check" } ! { dg-add-options ieee } ! { dg-skip-if "NaN not supported" { spu-*-* } } ! ! PR fortran/34319 ! ! Check support of INF/NaN for I/O. ! program main implicit none real :: r complex :: z character(len=30) :: str str = "nan" read(str,*) r if (.not.isnan(r)) STOP 1 str = "(nan,4.0)" read(str,*) z if (.not.isnan(real(z)) .or. aimag(z) /= 4.0) STOP 2 str = "(7.0,nan)" read(str,*) z if (.not.isnan(aimag(z)) .or. real(z) /= 7.0) STOP 3 str = "inFinity" read(str,*) r if (r <= huge(r)) STOP 4 str = "(+inFinity,4.0)" read(str,*) z if ((real(z) <= huge(r)) .or. aimag(z) /= 4.0) STOP 5 str = "(7.0,-inFinity)" read(str,*) z if ((aimag(z) >= -huge(r)) .or. real(z) /= 7.0) STOP 6 str = "inf" read(str,*) r if (r <= huge(r)) STOP 7 str = "(+inf,4.0)" read(str,*) z if ((real(z) <= huge(r)) .or. aimag(z) /= 4.0) STOP 8 str = "(7.0,-inf)" read(str,*) z if ((aimag(z) >= -huge(r)) .or. real(z) /= 7.0) STOP 9 end program main
program generate_rand implicit none integer i real rand real*8 drand48 do i=1, 20 print *, rand(), drand48() enddo end
# # Don't complain; just work harder! Dan Stanford # # Our responsibility is to do what we can, learn what we can, improve the solutions, and pass them on. RF # # @author: [email protected] # # @prerequisite # install.packages('ggplot2') # library(ggplot2) # library(ggthemes) # mtcars > library(ggplot2) > library(ggthemes) # Import data df <- read.csv('BootcampWithR/Economist_Assignment_Data.csv', sep=',') print(head(df)) # Use ggplot() + geom_point() to create a scatter plot object called pl. You will need to specify x=CPI and y=HDI and color=Region as aesthetics > pl <- ggplot(df, aes(x = CPI, y = HDI, color = Region)) + geom_point(shape = 1, size = 4) # We want to further edit this trend line. Add the following arguments to geom_smooth (outside of aes): # # Smoothing method (function) to use, accepts either a character vector, e.g. "auto", "lm", "glm", "gam", "loess" or a function, e.g. MASS::rlm or mgcv::gam, stats::lm, or stats::loess. # method = 'lm' # # Formula to use in smoothing function, eg. y ~ x, y ~ poly(x, 2), y ~ log(x) # formula = y ~ log(x) # # Display confidence interval around smooth? (TRUE by default, see level to control.) # se = FALSE # # color = 'red' pl2 <- pl + geom_smooth(formula = y ~ log(x), color = "red", method = "lm", se = FALSE) # Add labels > p2 + geom_text(aes(label=Country)) > pointsToLabel <- c("Russia", "Venezuela", "Iraq", "Myanmar", "Sudan", "Afghanistan", "Congo", "Greece", "Argentina", "Brazil", "India", "Italy", "China", "South Africa", "Spane", "Botswana", "Cape Verde", "Bhutan", "Rwanda", "France", "United States", "Germany", "Britain", "Barbados", "Norway", "Japan", "New Zealand", "Singapore") > pl3 <- pl2 + geom_text(aes(label = Country), color = "gray20", data = subset(df, df$Country %in% pointsToLabel), check_overlap=TRUE) # Change theme > pl4 <- pl3 + theme_bw() # Add scale_x_continuous() > pl5 <- pl4 + scale_x_continuous(name = "Corruption Perception Index, 2011 (10 = least corrupt)", limits = c(.9, 10.5), breaks=1:10) # Add scale_y_continous() > pl6 <- pl5 + scale_y_continuous(name = "Human Development Index, 2011 (1=Best)", limits = c(0.2, 1.0)) # Add graphic title # To center: theme(plot.title = element_text(hjust = 0.5)) > pl7 <- pl6 + ggtitle(label = "Corruption and Human development") + theme_economist_white() + theme(plot.title = element_text(hjust = 0.5))
State Before: F : Type u₀ → Type u₁ → Type u₂ inst✝¹ : Bifunctor F inst✝ : LawfulBifunctor F α₀ α₁ : Type u₀ β₀ β₁ : Type u₁ f : α₀ → α₁ f' : β₀ → β₁ x : F α₀ β₀ ⊢ fst f (snd f' x) = bimap f f' x State After: no goals Tactic: simp [fst, bimap_bimap]
(* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. *) theory TeaclaveRequirements imports Main TeaclaveAccessControl begin locale TeaclaveRequirements=TeaclaveAccessControl begin theorem TEACLAVESRS1:"request_user_access_data mconf uid oid= (find_usrid(objattr_owners(read_objattr mconf oid)) (usr_attr uid)\<and> resrcattr_infotype(objattr_resrcattr(read_objattr mconf oid))=data)" proof (simp add:read_objattr_def request_user_access_data_def read_subjattr_def) show "user_access_data (usr_attr uid) (get_objattr (modelconf_obj mconf) oid) = (find_usrid(objattr_owners (get_objattr (modelconf_obj mconf) oid)) (usr_attr uid) \<and> resrcattr_infotype(objattr_resrcattr (get_objattr (modelconf_obj mconf) oid))=data)" proof assume "user_access_data (usr_attr uid) (get_objattr (modelconf_obj mconf) oid)" from this show "find_usrid(objattr_owners((get_objattr (modelconf_obj mconf) oid))) (usr_attr uid)\<and> resrcattr_infotype(objattr_resrcattr (get_objattr (modelconf_obj mconf) oid))=data" proof (rule contrapos_pp) assume "\<not> (find_usrid (objattr_owners(get_objattr (modelconf_obj mconf) oid)) (usr_attr uid) \<and> resrcattr_infotype(objattr_resrcattr(get_objattr (modelconf_obj mconf) oid))=data)" from this show "\<not> user_access_data (usr_attr uid) (get_objattr (modelconf_obj mconf) oid)" by (rule FDPACF1HLR13) qed next assume "find_usrid(objattr_owners (get_objattr (modelconf_obj mconf) oid)) (usr_attr uid) \<and> resrcattr_infotype(objattr_resrcattr (get_objattr (modelconf_obj mconf) oid))=data" from this show "user_access_data (usr_attr uid) (get_objattr (modelconf_obj mconf) oid)" by (rule FDPACF1HLR10) qed qed theorem TEACLAVESRS2:"request_task_access_data mconf sid oid\<Longrightarrow> ((rel_subset(subjattr_participants(read_subjattr mconf sid)) (objattr_owners(read_objattr mconf oid)))\<and> resrcattr_infotype(objattr_resrcattr(read_objattr mconf oid))=data)" proof (simp add:read_objattr_def request_task_access_data_def read_subjattr_def) assume 0:"task_access_data (get_subjattr (modelconf_subj mconf) sid) (get_objattr (modelconf_obj mconf) oid)" from this have 1:"rel_subset(subjattr_participants(get_subjattr (modelconf_subj mconf) sid)) (objattr_owners(get_objattr (modelconf_obj mconf) oid))\<and> resrcattr_infotype(objattr_resrcattr(get_objattr (modelconf_obj mconf) oid))=data" proof (rule contrapos_pp) assume "\<not> (rel_subset (subjattr_participants(get_subjattr (modelconf_subj mconf) sid)) (objattr_owners (get_objattr (modelconf_obj mconf) oid)) \<and> resrcattr_infotype (objattr_resrcattr(get_objattr (modelconf_obj mconf) oid)) = data)" from this show "\<not> task_access_data (get_subjattr (modelconf_subj mconf) sid) (get_objattr (modelconf_obj mconf) oid)" by (rule FDPACF1HLR14) qed from this show "rel_subset(subjattr_participants(get_subjattr (modelconf_subj mconf) sid)) (objattr_owners (get_objattr (modelconf_obj mconf) oid)) \<and> resrcattr_infotype(objattr_resrcattr (get_objattr (modelconf_obj mconf) oid))=data" by auto qed end print_locale! TeaclaveRequirements end
(* Title: HOL/Analysis/Infinite_Set_Sum.thy Author: Manuel Eberl, TU München A theory of sums over possible infinite sets. (Only works for absolute summability) *) section \<open>Sums over Infinite Sets\<close> theory Infinite_Set_Sum imports Set_Integral begin (* TODO Move *) lemma sets_eq_countable: assumes "countable A" "space M = A" "\<And>x. x \<in> A \<Longrightarrow> {x} \<in> sets M" shows "sets M = Pow A" proof (intro equalityI subsetI) fix X assume "X \<in> Pow A" hence "(\<Union>x\<in>X. {x}) \<in> sets M" by (intro sets.countable_UN' countable_subset[OF _ assms(1)]) (auto intro!: assms(3)) also have "(\<Union>x\<in>X. {x}) = X" by auto finally show "X \<in> sets M" . next fix X assume "X \<in> sets M" from sets.sets_into_space[OF this] and assms show "X \<in> Pow A" by simp qed lemma measure_eqI_countable': assumes spaces: "space M = A" "space N = A" assumes sets: "\<And>x. x \<in> A \<Longrightarrow> {x} \<in> sets M" "\<And>x. x \<in> A \<Longrightarrow> {x} \<in> sets N" assumes A: "countable A" assumes eq: "\<And>a. a \<in> A \<Longrightarrow> emeasure M {a} = emeasure N {a}" shows "M = N" proof (rule measure_eqI_countable) show "sets M = Pow A" by (intro sets_eq_countable assms) show "sets N = Pow A" by (intro sets_eq_countable assms) qed fact+ lemma count_space_PiM_finite: fixes B :: "'a \<Rightarrow> 'b set" assumes "finite A" "\<And>i. countable (B i)" shows "PiM A (\<lambda>i. count_space (B i)) = count_space (PiE A B)" proof (rule measure_eqI_countable') show "space (PiM A (\<lambda>i. count_space (B i))) = PiE A B" by (simp add: space_PiM) show "space (count_space (PiE A B)) = PiE A B" by simp next fix f assume f: "f \<in> PiE A B" hence "PiE A (\<lambda>x. {f x}) \<in> sets (Pi\<^sub>M A (\<lambda>i. count_space (B i)))" by (intro sets_PiM_I_finite assms) auto also from f have "PiE A (\<lambda>x. {f x}) = {f}" by (intro PiE_singleton) (auto simp: PiE_def) finally show "{f} \<in> sets (Pi\<^sub>M A (\<lambda>i. count_space (B i)))" . next interpret product_sigma_finite "(\<lambda>i. count_space (B i))" by (intro product_sigma_finite.intro sigma_finite_measure_count_space_countable assms) thm sigma_finite_measure_count_space fix f assume f: "f \<in> PiE A B" hence "{f} = PiE A (\<lambda>x. {f x})" by (intro PiE_singleton [symmetric]) (auto simp: PiE_def) also have "emeasure (Pi\<^sub>M A (\<lambda>i. count_space (B i))) \<dots> = (\<Prod>i\<in>A. emeasure (count_space (B i)) {f i})" using f assms by (subst emeasure_PiM) auto also have "\<dots> = (\<Prod>i\<in>A. 1)" by (intro prod.cong refl, subst emeasure_count_space_finite) (use f in auto) also have "\<dots> = emeasure (count_space (PiE A B)) {f}" using f by (subst emeasure_count_space_finite) auto finally show "emeasure (Pi\<^sub>M A (\<lambda>i. count_space (B i))) {f} = emeasure (count_space (Pi\<^sub>E A B)) {f}" . qed (simp_all add: countable_PiE assms) definition\<^marker>\<open>tag important\<close> abs_summable_on :: "('a \<Rightarrow> 'b :: {banach, second_countable_topology}) \<Rightarrow> 'a set \<Rightarrow> bool" (infix "abs'_summable'_on" 50) where "f abs_summable_on A \<longleftrightarrow> integrable (count_space A) f" definition\<^marker>\<open>tag important\<close> infsetsum :: "('a \<Rightarrow> 'b :: {banach, second_countable_topology}) \<Rightarrow> 'a set \<Rightarrow> 'b" where "infsetsum f A = lebesgue_integral (count_space A) f" syntax (ASCII) "_infsetsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" ("(3INFSETSUM _:_./ _)" [0, 51, 10] 10) syntax "_infsetsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" ("(2\<Sum>\<^sub>a_\<in>_./ _)" [0, 51, 10] 10) translations \<comment> \<open>Beware of argument permutation!\<close> "\<Sum>\<^sub>ai\<in>A. b" \<rightleftharpoons> "CONST infsetsum (\<lambda>i. b) A" syntax (ASCII) "_uinfsetsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" ("(3INFSETSUM _:_./ _)" [0, 51, 10] 10) syntax "_uinfsetsum" :: "pttrn \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" ("(2\<Sum>\<^sub>a_./ _)" [0, 10] 10) translations \<comment> \<open>Beware of argument permutation!\<close> "\<Sum>\<^sub>ai. b" \<rightleftharpoons> "CONST infsetsum (\<lambda>i. b) (CONST UNIV)" syntax (ASCII) "_qinfsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a::{banach, second_countable_topology}" ("(3INFSETSUM _ |/ _./ _)" [0, 0, 10] 10) syntax "_qinfsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a::{banach, second_countable_topology}" ("(2\<Sum>\<^sub>a_ | (_)./ _)" [0, 0, 10] 10) translations "\<Sum>\<^sub>ax|P. t" => "CONST infsetsum (\<lambda>x. t) {x. P}" print_translation \<open> let fun sum_tr' [Abs (x, Tx, t), Const (\<^const_syntax>\<open>Collect\<close>, _) $ Abs (y, Ty, P)] = if x <> y then raise Match else let val x' = Syntax_Trans.mark_bound_body (x, Tx); val t' = subst_bound (x', t); val P' = subst_bound (x', P); in Syntax.const \<^syntax_const>\<open>_qinfsetsum\<close> $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t' end | sum_tr' _ = raise Match; in [(\<^const_syntax>\<open>infsetsum\<close>, K sum_tr')] end \<close> lemma restrict_count_space_subset: "A \<subseteq> B \<Longrightarrow> restrict_space (count_space B) A = count_space A" by (subst restrict_count_space) (simp_all add: Int_absorb2) lemma abs_summable_on_restrict: fixes f :: "'a \<Rightarrow> 'b :: {banach, second_countable_topology}" assumes "A \<subseteq> B" shows "f abs_summable_on A \<longleftrightarrow> (\<lambda>x. indicator A x *\<^sub>R f x) abs_summable_on B" proof - have "count_space A = restrict_space (count_space B) A" by (rule restrict_count_space_subset [symmetric]) fact+ also have "integrable \<dots> f \<longleftrightarrow> set_integrable (count_space B) A f" by (simp add: integrable_restrict_space set_integrable_def) finally show ?thesis unfolding abs_summable_on_def set_integrable_def . qed lemma abs_summable_on_altdef: "f abs_summable_on A \<longleftrightarrow> set_integrable (count_space UNIV) A f" unfolding abs_summable_on_def set_integrable_def by (metis (no_types) inf_top.right_neutral integrable_restrict_space restrict_count_space sets_UNIV) lemma abs_summable_on_altdef': "A \<subseteq> B \<Longrightarrow> f abs_summable_on A \<longleftrightarrow> set_integrable (count_space B) A f" unfolding abs_summable_on_def set_integrable_def by (metis (no_types) Pow_iff abs_summable_on_def inf.orderE integrable_restrict_space restrict_count_space_subset sets_count_space space_count_space) lemma abs_summable_on_norm_iff [simp]: "(\<lambda>x. norm (f x)) abs_summable_on A \<longleftrightarrow> f abs_summable_on A" by (simp add: abs_summable_on_def integrable_norm_iff) lemma abs_summable_on_normI: "f abs_summable_on A \<Longrightarrow> (\<lambda>x. norm (f x)) abs_summable_on A" by simp lemma abs_summable_complex_of_real [simp]: "(\<lambda>n. complex_of_real (f n)) abs_summable_on A \<longleftrightarrow> f abs_summable_on A" by (simp add: abs_summable_on_def complex_of_real_integrable_eq) lemma abs_summable_on_comparison_test: assumes "g abs_summable_on A" assumes "\<And>x. x \<in> A \<Longrightarrow> norm (f x) \<le> norm (g x)" shows "f abs_summable_on A" using assms Bochner_Integration.integrable_bound[of "count_space A" g f] unfolding abs_summable_on_def by (auto simp: AE_count_space) lemma abs_summable_on_comparison_test': assumes "g abs_summable_on A" assumes "\<And>x. x \<in> A \<Longrightarrow> norm (f x) \<le> g x" shows "f abs_summable_on A" proof (rule abs_summable_on_comparison_test[OF assms(1), of f]) fix x assume "x \<in> A" with assms(2) have "norm (f x) \<le> g x" . also have "\<dots> \<le> norm (g x)" by simp finally show "norm (f x) \<le> norm (g x)" . qed lemma abs_summable_on_cong [cong]: "(\<And>x. x \<in> A \<Longrightarrow> f x = g x) \<Longrightarrow> A = B \<Longrightarrow> (f abs_summable_on A) \<longleftrightarrow> (g abs_summable_on B)" unfolding abs_summable_on_def by (intro integrable_cong) auto lemma abs_summable_on_cong_neutral: assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x = 0" assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x = 0" assumes "\<And>x. x \<in> A \<inter> B \<Longrightarrow> f x = g x" shows "f abs_summable_on A \<longleftrightarrow> g abs_summable_on B" unfolding abs_summable_on_altdef set_integrable_def using assms by (intro Bochner_Integration.integrable_cong refl) (auto simp: indicator_def split: if_splits) lemma abs_summable_on_restrict': fixes f :: "'a \<Rightarrow> 'b :: {banach, second_countable_topology}" assumes "A \<subseteq> B" shows "f abs_summable_on A \<longleftrightarrow> (\<lambda>x. if x \<in> A then f x else 0) abs_summable_on B" by (subst abs_summable_on_restrict[OF assms]) (intro abs_summable_on_cong, auto) lemma abs_summable_on_nat_iff: "f abs_summable_on (A :: nat set) \<longleftrightarrow> summable (\<lambda>n. if n \<in> A then norm (f n) else 0)" proof - have "f abs_summable_on A \<longleftrightarrow> summable (\<lambda>x. norm (if x \<in> A then f x else 0))" by (subst abs_summable_on_restrict'[of _ UNIV]) (simp_all add: abs_summable_on_def integrable_count_space_nat_iff) also have "(\<lambda>x. norm (if x \<in> A then f x else 0)) = (\<lambda>x. if x \<in> A then norm (f x) else 0)" by auto finally show ?thesis . qed lemma abs_summable_on_nat_iff': "f abs_summable_on (UNIV :: nat set) \<longleftrightarrow> summable (\<lambda>n. norm (f n))" by (subst abs_summable_on_nat_iff) auto lemma nat_abs_summable_on_comparison_test: fixes f :: "nat \<Rightarrow> 'a :: {banach, second_countable_topology}" assumes "g abs_summable_on I" assumes "\<And>n. \<lbrakk>n\<ge>N; n \<in> I\<rbrakk> \<Longrightarrow> norm (f n) \<le> g n" shows "f abs_summable_on I" using assms by (fastforce simp add: abs_summable_on_nat_iff intro: summable_comparison_test') lemma abs_summable_comparison_test_ev: assumes "g abs_summable_on I" assumes "eventually (\<lambda>x. x \<in> I \<longrightarrow> norm (f x) \<le> g x) sequentially" shows "f abs_summable_on I" by (metis (no_types, lifting) nat_abs_summable_on_comparison_test eventually_at_top_linorder assms) lemma abs_summable_on_Cauchy: "f abs_summable_on (UNIV :: nat set) \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m\<ge>N. \<forall>n. (\<Sum>x = m..<n. norm (f x)) < e)" by (simp add: abs_summable_on_nat_iff' summable_Cauchy sum_nonneg) lemma abs_summable_on_finite [simp]: "finite A \<Longrightarrow> f abs_summable_on A" unfolding abs_summable_on_def by (rule integrable_count_space) lemma abs_summable_on_empty [simp, intro]: "f abs_summable_on {}" by simp lemma abs_summable_on_subset: assumes "f abs_summable_on B" and "A \<subseteq> B" shows "f abs_summable_on A" unfolding abs_summable_on_altdef by (rule set_integrable_subset) (insert assms, auto simp: abs_summable_on_altdef) lemma abs_summable_on_union [intro]: assumes "f abs_summable_on A" and "f abs_summable_on B" shows "f abs_summable_on (A \<union> B)" using assms unfolding abs_summable_on_altdef by (intro set_integrable_Un) auto lemma abs_summable_on_insert_iff [simp]: "f abs_summable_on insert x A \<longleftrightarrow> f abs_summable_on A" proof safe assume "f abs_summable_on insert x A" thus "f abs_summable_on A" by (rule abs_summable_on_subset) auto next assume "f abs_summable_on A" from abs_summable_on_union[OF this, of "{x}"] show "f abs_summable_on insert x A" by simp qed lemma abs_summable_sum: assumes "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B" shows "(\<lambda>y. \<Sum>x\<in>A. f x y) abs_summable_on B" using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_sum) lemma abs_summable_Re: "f abs_summable_on A \<Longrightarrow> (\<lambda>x. Re (f x)) abs_summable_on A" by (simp add: abs_summable_on_def) lemma abs_summable_Im: "f abs_summable_on A \<Longrightarrow> (\<lambda>x. Im (f x)) abs_summable_on A" by (simp add: abs_summable_on_def) lemma abs_summable_on_finite_diff: assumes "f abs_summable_on A" "A \<subseteq> B" "finite (B - A)" shows "f abs_summable_on B" proof - have "f abs_summable_on (A \<union> (B - A))" by (intro abs_summable_on_union assms abs_summable_on_finite) also from assms have "A \<union> (B - A) = B" by blast finally show ?thesis . qed lemma abs_summable_on_reindex_bij_betw: assumes "bij_betw g A B" shows "(\<lambda>x. f (g x)) abs_summable_on A \<longleftrightarrow> f abs_summable_on B" proof - have *: "count_space B = distr (count_space A) (count_space B) g" by (rule distr_bij_count_space [symmetric]) fact show ?thesis unfolding abs_summable_on_def by (subst *, subst integrable_distr_eq[of _ _ "count_space B"]) (insert assms, auto simp: bij_betw_def) qed lemma abs_summable_on_reindex: assumes "(\<lambda>x. f (g x)) abs_summable_on A" shows "f abs_summable_on (g ` A)" proof - define g' where "g' = inv_into A g" from assms have "(\<lambda>x. f (g x)) abs_summable_on (g' ` g ` A)" by (rule abs_summable_on_subset) (auto simp: g'_def inv_into_into) also have "?this \<longleftrightarrow> (\<lambda>x. f (g (g' x))) abs_summable_on (g ` A)" unfolding g'_def by (intro abs_summable_on_reindex_bij_betw [symmetric] inj_on_imp_bij_betw inj_on_inv_into) auto also have "\<dots> \<longleftrightarrow> f abs_summable_on (g ` A)" by (intro abs_summable_on_cong refl) (auto simp: g'_def f_inv_into_f) finally show ?thesis . qed lemma abs_summable_on_reindex_iff: "inj_on g A \<Longrightarrow> (\<lambda>x. f (g x)) abs_summable_on A \<longleftrightarrow> f abs_summable_on (g ` A)" by (intro abs_summable_on_reindex_bij_betw inj_on_imp_bij_betw) lemma abs_summable_on_Sigma_project2: fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set" assumes "f abs_summable_on (Sigma A B)" "x \<in> A" shows "(\<lambda>y. f (x, y)) abs_summable_on (B x)" proof - from assms(2) have "f abs_summable_on (Sigma {x} B)" by (intro abs_summable_on_subset [OF assms(1)]) auto also have "?this \<longleftrightarrow> (\<lambda>z. f (x, snd z)) abs_summable_on (Sigma {x} B)" by (rule abs_summable_on_cong) auto finally have "(\<lambda>y. f (x, y)) abs_summable_on (snd ` Sigma {x} B)" by (rule abs_summable_on_reindex) also have "snd ` Sigma {x} B = B x" using assms by (auto simp: image_iff) finally show ?thesis . qed lemma abs_summable_on_Times_swap: "f abs_summable_on A \<times> B \<longleftrightarrow> (\<lambda>(x,y). f (y,x)) abs_summable_on B \<times> A" proof - have bij: "bij_betw (\<lambda>(x,y). (y,x)) (B \<times> A) (A \<times> B)" by (auto simp: bij_betw_def inj_on_def) show ?thesis by (subst abs_summable_on_reindex_bij_betw[OF bij, of f, symmetric]) (simp_all add: case_prod_unfold) qed lemma abs_summable_on_0 [simp, intro]: "(\<lambda>_. 0) abs_summable_on A" by (simp add: abs_summable_on_def) lemma abs_summable_on_uminus [intro]: "f abs_summable_on A \<Longrightarrow> (\<lambda>x. -f x) abs_summable_on A" unfolding abs_summable_on_def by (rule Bochner_Integration.integrable_minus) lemma abs_summable_on_add [intro]: assumes "f abs_summable_on A" and "g abs_summable_on A" shows "(\<lambda>x. f x + g x) abs_summable_on A" using assms unfolding abs_summable_on_def by (rule Bochner_Integration.integrable_add) lemma abs_summable_on_diff [intro]: assumes "f abs_summable_on A" and "g abs_summable_on A" shows "(\<lambda>x. f x - g x) abs_summable_on A" using assms unfolding abs_summable_on_def by (rule Bochner_Integration.integrable_diff) lemma abs_summable_on_scaleR_left [intro]: assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "(\<lambda>x. f x *\<^sub>R c) abs_summable_on A" using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_scaleR_left) lemma abs_summable_on_scaleR_right [intro]: assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "(\<lambda>x. c *\<^sub>R f x) abs_summable_on A" using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_scaleR_right) lemma abs_summable_on_cmult_right [intro]: fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}" assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "(\<lambda>x. c * f x) abs_summable_on A" using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_mult_right) lemma abs_summable_on_cmult_left [intro]: fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}" assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "(\<lambda>x. f x * c) abs_summable_on A" using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_mult_left) lemma abs_summable_on_prod_PiE: fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {real_normed_field,banach,second_countable_topology}" assumes finite: "finite A" and countable: "\<And>x. x \<in> A \<Longrightarrow> countable (B x)" assumes summable: "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B x" shows "(\<lambda>g. \<Prod>x\<in>A. f x (g x)) abs_summable_on PiE A B" proof - define B' where "B' = (\<lambda>x. if x \<in> A then B x else {})" from assms have [simp]: "countable (B' x)" for x by (auto simp: B'_def) then interpret product_sigma_finite "count_space \<circ> B'" unfolding o_def by (intro product_sigma_finite.intro sigma_finite_measure_count_space_countable) from assms have "integrable (PiM A (count_space \<circ> B')) (\<lambda>g. \<Prod>x\<in>A. f x (g x))" by (intro product_integrable_prod) (auto simp: abs_summable_on_def B'_def) also have "PiM A (count_space \<circ> B') = count_space (PiE A B')" unfolding o_def using finite by (intro count_space_PiM_finite) simp_all also have "PiE A B' = PiE A B" by (intro PiE_cong) (simp_all add: B'_def) finally show ?thesis by (simp add: abs_summable_on_def) qed lemma not_summable_infsetsum_eq: "\<not>f abs_summable_on A \<Longrightarrow> infsetsum f A = 0" by (simp add: abs_summable_on_def infsetsum_def not_integrable_integral_eq) lemma infsetsum_altdef: "infsetsum f A = set_lebesgue_integral (count_space UNIV) A f" unfolding set_lebesgue_integral_def by (subst integral_restrict_space [symmetric]) (auto simp: restrict_count_space_subset infsetsum_def) lemma infsetsum_altdef': "A \<subseteq> B \<Longrightarrow> infsetsum f A = set_lebesgue_integral (count_space B) A f" unfolding set_lebesgue_integral_def by (subst integral_restrict_space [symmetric]) (auto simp: restrict_count_space_subset infsetsum_def) lemma nn_integral_conv_infsetsum: assumes "f abs_summable_on A" "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0" shows "nn_integral (count_space A) f = ennreal (infsetsum f A)" using assms unfolding infsetsum_def abs_summable_on_def by (subst nn_integral_eq_integral) auto lemma infsetsum_conv_nn_integral: assumes "nn_integral (count_space A) f \<noteq> \<infinity>" "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0" shows "infsetsum f A = enn2real (nn_integral (count_space A) f)" unfolding infsetsum_def using assms by (subst integral_eq_nn_integral) auto lemma infsetsum_cong [cong]: "(\<And>x. x \<in> A \<Longrightarrow> f x = g x) \<Longrightarrow> A = B \<Longrightarrow> infsetsum f A = infsetsum g B" unfolding infsetsum_def by (intro Bochner_Integration.integral_cong) auto lemma infsetsum_0 [simp]: "infsetsum (\<lambda>_. 0) A = 0" by (simp add: infsetsum_def) lemma infsetsum_all_0: "(\<And>x. x \<in> A \<Longrightarrow> f x = 0) \<Longrightarrow> infsetsum f A = 0" by simp lemma infsetsum_nonneg: "(\<And>x. x \<in> A \<Longrightarrow> f x \<ge> (0::real)) \<Longrightarrow> infsetsum f A \<ge> 0" unfolding infsetsum_def by (rule Bochner_Integration.integral_nonneg) auto lemma sum_infsetsum: assumes "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B" shows "(\<Sum>x\<in>A. \<Sum>\<^sub>ay\<in>B. f x y) = (\<Sum>\<^sub>ay\<in>B. \<Sum>x\<in>A. f x y)" using assms by (simp add: infsetsum_def abs_summable_on_def Bochner_Integration.integral_sum) lemma Re_infsetsum: "f abs_summable_on A \<Longrightarrow> Re (infsetsum f A) = (\<Sum>\<^sub>ax\<in>A. Re (f x))" by (simp add: infsetsum_def abs_summable_on_def) lemma Im_infsetsum: "f abs_summable_on A \<Longrightarrow> Im (infsetsum f A) = (\<Sum>\<^sub>ax\<in>A. Im (f x))" by (simp add: infsetsum_def abs_summable_on_def) lemma infsetsum_of_real: shows "infsetsum (\<lambda>x. of_real (f x) :: 'a :: {real_normed_algebra_1,banach,second_countable_topology,real_inner}) A = of_real (infsetsum f A)" unfolding infsetsum_def by (rule integral_bounded_linear'[OF bounded_linear_of_real bounded_linear_inner_left[of 1]]) auto lemma infsetsum_finite [simp]: "finite A \<Longrightarrow> infsetsum f A = (\<Sum>x\<in>A. f x)" by (simp add: infsetsum_def lebesgue_integral_count_space_finite) lemma infsetsum_nat: assumes "f abs_summable_on A" shows "infsetsum f A = (\<Sum>n. if n \<in> A then f n else 0)" proof - from assms have "infsetsum f A = (\<Sum>n. indicator A n *\<^sub>R f n)" unfolding infsetsum_altdef abs_summable_on_altdef set_lebesgue_integral_def set_integrable_def by (subst integral_count_space_nat) auto also have "(\<lambda>n. indicator A n *\<^sub>R f n) = (\<lambda>n. if n \<in> A then f n else 0)" by auto finally show ?thesis . qed lemma infsetsum_nat': assumes "f abs_summable_on UNIV" shows "infsetsum f UNIV = (\<Sum>n. f n)" using assms by (subst infsetsum_nat) auto lemma sums_infsetsum_nat: assumes "f abs_summable_on A" shows "(\<lambda>n. if n \<in> A then f n else 0) sums infsetsum f A" proof - from assms have "summable (\<lambda>n. if n \<in> A then norm (f n) else 0)" by (simp add: abs_summable_on_nat_iff) also have "(\<lambda>n. if n \<in> A then norm (f n) else 0) = (\<lambda>n. norm (if n \<in> A then f n else 0))" by auto finally have "summable (\<lambda>n. if n \<in> A then f n else 0)" by (rule summable_norm_cancel) with assms show ?thesis by (auto simp: sums_iff infsetsum_nat) qed lemma sums_infsetsum_nat': assumes "f abs_summable_on UNIV" shows "f sums infsetsum f UNIV" using sums_infsetsum_nat [OF assms] by simp lemma infsetsum_Un_disjoint: assumes "f abs_summable_on A" "f abs_summable_on B" "A \<inter> B = {}" shows "infsetsum f (A \<union> B) = infsetsum f A + infsetsum f B" using assms unfolding infsetsum_altdef abs_summable_on_altdef by (subst set_integral_Un) auto lemma infsetsum_Diff: assumes "f abs_summable_on B" "A \<subseteq> B" shows "infsetsum f (B - A) = infsetsum f B - infsetsum f A" proof - have "infsetsum f ((B - A) \<union> A) = infsetsum f (B - A) + infsetsum f A" using assms(2) by (intro infsetsum_Un_disjoint abs_summable_on_subset[OF assms(1)]) auto also from assms(2) have "(B - A) \<union> A = B" by auto ultimately show ?thesis by (simp add: algebra_simps) qed lemma infsetsum_Un_Int: assumes "f abs_summable_on (A \<union> B)" shows "infsetsum f (A \<union> B) = infsetsum f A + infsetsum f B - infsetsum f (A \<inter> B)" proof - have "A \<union> B = A \<union> (B - A \<inter> B)" by auto also have "infsetsum f \<dots> = infsetsum f A + infsetsum f (B - A \<inter> B)" by (intro infsetsum_Un_disjoint abs_summable_on_subset[OF assms]) auto also have "infsetsum f (B - A \<inter> B) = infsetsum f B - infsetsum f (A \<inter> B)" by (intro infsetsum_Diff abs_summable_on_subset[OF assms]) auto finally show ?thesis by (simp add: algebra_simps) qed lemma infsetsum_reindex_bij_betw: assumes "bij_betw g A B" shows "infsetsum (\<lambda>x. f (g x)) A = infsetsum f B" proof - have *: "count_space B = distr (count_space A) (count_space B) g" by (rule distr_bij_count_space [symmetric]) fact show ?thesis unfolding infsetsum_def by (subst *, subst integral_distr[of _ _ "count_space B"]) (insert assms, auto simp: bij_betw_def) qed theorem infsetsum_reindex: assumes "inj_on g A" shows "infsetsum f (g ` A) = infsetsum (\<lambda>x. f (g x)) A" by (intro infsetsum_reindex_bij_betw [symmetric] inj_on_imp_bij_betw assms) lemma infsetsum_cong_neutral: assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x = 0" assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x = 0" assumes "\<And>x. x \<in> A \<inter> B \<Longrightarrow> f x = g x" shows "infsetsum f A = infsetsum g B" unfolding infsetsum_altdef set_lebesgue_integral_def using assms by (intro Bochner_Integration.integral_cong refl) (auto simp: indicator_def split: if_splits) lemma infsetsum_mono_neutral: fixes f g :: "'a \<Rightarrow> real" assumes "f abs_summable_on A" and "g abs_summable_on B" assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x" assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x \<le> 0" assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x \<ge> 0" shows "infsetsum f A \<le> infsetsum g B" using assms unfolding infsetsum_altdef set_lebesgue_integral_def abs_summable_on_altdef set_integrable_def by (intro Bochner_Integration.integral_mono) (auto simp: indicator_def) lemma infsetsum_mono_neutral_left: fixes f g :: "'a \<Rightarrow> real" assumes "f abs_summable_on A" and "g abs_summable_on B" assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x" assumes "A \<subseteq> B" assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x \<ge> 0" shows "infsetsum f A \<le> infsetsum g B" using \<open>A \<subseteq> B\<close> by (intro infsetsum_mono_neutral assms) auto lemma infsetsum_mono_neutral_right: fixes f g :: "'a \<Rightarrow> real" assumes "f abs_summable_on A" and "g abs_summable_on B" assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x" assumes "B \<subseteq> A" assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x \<le> 0" shows "infsetsum f A \<le> infsetsum g B" using \<open>B \<subseteq> A\<close> by (intro infsetsum_mono_neutral assms) auto lemma infsetsum_mono: fixes f g :: "'a \<Rightarrow> real" assumes "f abs_summable_on A" and "g abs_summable_on A" assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x" shows "infsetsum f A \<le> infsetsum g A" by (intro infsetsum_mono_neutral assms) auto lemma norm_infsetsum_bound: "norm (infsetsum f A) \<le> infsetsum (\<lambda>x. norm (f x)) A" unfolding abs_summable_on_def infsetsum_def by (rule Bochner_Integration.integral_norm_bound) theorem infsetsum_Sigma: fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set" assumes [simp]: "countable A" and "\<And>i. countable (B i)" assumes summable: "f abs_summable_on (Sigma A B)" shows "infsetsum f (Sigma A B) = infsetsum (\<lambda>x. infsetsum (\<lambda>y. f (x, y)) (B x)) A" proof - define B' where "B' = (\<Union>i\<in>A. B i)" have [simp]: "countable B'" unfolding B'_def by (intro countable_UN assms) interpret pair_sigma_finite "count_space A" "count_space B'" by (intro pair_sigma_finite.intro sigma_finite_measure_count_space_countable) fact+ have "integrable (count_space (A \<times> B')) (\<lambda>z. indicator (Sigma A B) z *\<^sub>R f z)" using summable by (metis (mono_tags, lifting) abs_summable_on_altdef abs_summable_on_def integrable_cong integrable_mult_indicator set_integrable_def sets_UNIV) also have "?this \<longleftrightarrow> integrable (count_space A \<Otimes>\<^sub>M count_space B') (\<lambda>(x, y). indicator (B x) y *\<^sub>R f (x, y))" by (intro Bochner_Integration.integrable_cong) (auto simp: pair_measure_countable indicator_def split: if_splits) finally have integrable: \<dots> . have "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f (x, y)) (B x)) A = (\<integral>x. infsetsum (\<lambda>y. f (x, y)) (B x) \<partial>count_space A)" unfolding infsetsum_def by simp also have "\<dots> = (\<integral>x. \<integral>y. indicator (B x) y *\<^sub>R f (x, y) \<partial>count_space B' \<partial>count_space A)" proof (rule Bochner_Integration.integral_cong [OF refl]) show "\<And>x. x \<in> space (count_space A) \<Longrightarrow> (\<Sum>\<^sub>ay\<in>B x. f (x, y)) = LINT y|count_space B'. indicat_real (B x) y *\<^sub>R f (x, y)" using infsetsum_altdef'[of _ B'] unfolding set_lebesgue_integral_def B'_def by auto qed also have "\<dots> = (\<integral>(x,y). indicator (B x) y *\<^sub>R f (x, y) \<partial>(count_space A \<Otimes>\<^sub>M count_space B'))" by (subst integral_fst [OF integrable]) auto also have "\<dots> = (\<integral>z. indicator (Sigma A B) z *\<^sub>R f z \<partial>count_space (A \<times> B'))" by (intro Bochner_Integration.integral_cong) (auto simp: pair_measure_countable indicator_def split: if_splits) also have "\<dots> = infsetsum f (Sigma A B)" unfolding set_lebesgue_integral_def [symmetric] by (rule infsetsum_altdef' [symmetric]) (auto simp: B'_def) finally show ?thesis .. qed lemma infsetsum_Sigma': fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set" assumes [simp]: "countable A" and "\<And>i. countable (B i)" assumes summable: "(\<lambda>(x,y). f x y) abs_summable_on (Sigma A B)" shows "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) (B x)) A = infsetsum (\<lambda>(x,y). f x y) (Sigma A B)" using assms by (subst infsetsum_Sigma) auto lemma infsetsum_Times: fixes A :: "'a set" and B :: "'b set" assumes [simp]: "countable A" and "countable B" assumes summable: "f abs_summable_on (A \<times> B)" shows "infsetsum f (A \<times> B) = infsetsum (\<lambda>x. infsetsum (\<lambda>y. f (x, y)) B) A" using assms by (subst infsetsum_Sigma) auto lemma infsetsum_Times': fixes A :: "'a set" and B :: "'b set" fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {banach, second_countable_topology}" assumes [simp]: "countable A" and [simp]: "countable B" assumes summable: "(\<lambda>(x,y). f x y) abs_summable_on (A \<times> B)" shows "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) B) A = infsetsum (\<lambda>(x,y). f x y) (A \<times> B)" using assms by (subst infsetsum_Times) auto lemma infsetsum_swap: fixes A :: "'a set" and B :: "'b set" fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {banach, second_countable_topology}" assumes [simp]: "countable A" and [simp]: "countable B" assumes summable: "(\<lambda>(x,y). f x y) abs_summable_on A \<times> B" shows "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) B) A = infsetsum (\<lambda>y. infsetsum (\<lambda>x. f x y) A) B" proof - from summable have summable': "(\<lambda>(x,y). f y x) abs_summable_on B \<times> A" by (subst abs_summable_on_Times_swap) auto have bij: "bij_betw (\<lambda>(x, y). (y, x)) (B \<times> A) (A \<times> B)" by (auto simp: bij_betw_def inj_on_def) have "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) B) A = infsetsum (\<lambda>(x,y). f x y) (A \<times> B)" using summable by (subst infsetsum_Times) auto also have "\<dots> = infsetsum (\<lambda>(x,y). f y x) (B \<times> A)" by (subst infsetsum_reindex_bij_betw[OF bij, of "\<lambda>(x,y). f x y", symmetric]) (simp_all add: case_prod_unfold) also have "\<dots> = infsetsum (\<lambda>y. infsetsum (\<lambda>x. f x y) A) B" using summable' by (subst infsetsum_Times) auto finally show ?thesis . qed theorem abs_summable_on_Sigma_iff: assumes [simp]: "countable A" and "\<And>x. x \<in> A \<Longrightarrow> countable (B x)" shows "f abs_summable_on Sigma A B \<longleftrightarrow> (\<forall>x\<in>A. (\<lambda>y. f (x, y)) abs_summable_on B x) \<and> ((\<lambda>x. infsetsum (\<lambda>y. norm (f (x, y))) (B x)) abs_summable_on A)" proof safe define B' where "B' = (\<Union>x\<in>A. B x)" have [simp]: "countable B'" unfolding B'_def using assms by auto interpret pair_sigma_finite "count_space A" "count_space B'" by (intro pair_sigma_finite.intro sigma_finite_measure_count_space_countable) fact+ { assume *: "f abs_summable_on Sigma A B" thus "(\<lambda>y. f (x, y)) abs_summable_on B x" if "x \<in> A" for x using that by (rule abs_summable_on_Sigma_project2) have "set_integrable (count_space (A \<times> B')) (Sigma A B) (\<lambda>z. norm (f z))" using abs_summable_on_normI[OF *] by (subst abs_summable_on_altdef' [symmetric]) (auto simp: B'_def) also have "count_space (A \<times> B') = count_space A \<Otimes>\<^sub>M count_space B'" by (simp add: pair_measure_countable) finally have "integrable (count_space A) (\<lambda>x. lebesgue_integral (count_space B') (\<lambda>y. indicator (Sigma A B) (x, y) *\<^sub>R norm (f (x, y))))" unfolding set_integrable_def by (rule integrable_fst') also have "?this \<longleftrightarrow> integrable (count_space A) (\<lambda>x. lebesgue_integral (count_space B') (\<lambda>y. indicator (B x) y *\<^sub>R norm (f (x, y))))" by (intro integrable_cong refl) (simp_all add: indicator_def) also have "\<dots> \<longleftrightarrow> integrable (count_space A) (\<lambda>x. infsetsum (\<lambda>y. norm (f (x, y))) (B x))" unfolding set_lebesgue_integral_def [symmetric] by (intro integrable_cong refl infsetsum_altdef' [symmetric]) (auto simp: B'_def) also have "\<dots> \<longleftrightarrow> (\<lambda>x. infsetsum (\<lambda>y. norm (f (x, y))) (B x)) abs_summable_on A" by (simp add: abs_summable_on_def) finally show \<dots> . } { assume *: "\<forall>x\<in>A. (\<lambda>y. f (x, y)) abs_summable_on B x" assume "(\<lambda>x. \<Sum>\<^sub>ay\<in>B x. norm (f (x, y))) abs_summable_on A" also have "?this \<longleftrightarrow> (\<lambda>x. \<integral>y\<in>B x. norm (f (x, y)) \<partial>count_space B') abs_summable_on A" by (intro abs_summable_on_cong refl infsetsum_altdef') (auto simp: B'_def) also have "\<dots> \<longleftrightarrow> (\<lambda>x. \<integral>y. indicator (Sigma A B) (x, y) *\<^sub>R norm (f (x, y)) \<partial>count_space B') abs_summable_on A" (is "_ \<longleftrightarrow> ?h abs_summable_on _") unfolding set_lebesgue_integral_def by (intro abs_summable_on_cong) (auto simp: indicator_def) also have "\<dots> \<longleftrightarrow> integrable (count_space A) ?h" by (simp add: abs_summable_on_def) finally have **: \<dots> . have "integrable (count_space A \<Otimes>\<^sub>M count_space B') (\<lambda>z. indicator (Sigma A B) z *\<^sub>R f z)" proof (rule Fubini_integrable, goal_cases) case 3 { fix x assume x: "x \<in> A" with * have "(\<lambda>y. f (x, y)) abs_summable_on B x" by blast also have "?this \<longleftrightarrow> integrable (count_space B') (\<lambda>y. indicator (B x) y *\<^sub>R f (x, y))" unfolding set_integrable_def [symmetric] using x by (intro abs_summable_on_altdef') (auto simp: B'_def) also have "(\<lambda>y. indicator (B x) y *\<^sub>R f (x, y)) = (\<lambda>y. indicator (Sigma A B) (x, y) *\<^sub>R f (x, y))" using x by (auto simp: indicator_def) finally have "integrable (count_space B') (\<lambda>y. indicator (Sigma A B) (x, y) *\<^sub>R f (x, y))" . } thus ?case by (auto simp: AE_count_space) qed (insert **, auto simp: pair_measure_countable) moreover have "count_space A \<Otimes>\<^sub>M count_space B' = count_space (A \<times> B')" by (simp add: pair_measure_countable) moreover have "set_integrable (count_space (A \<times> B')) (Sigma A B) f \<longleftrightarrow> f abs_summable_on Sigma A B" by (rule abs_summable_on_altdef' [symmetric]) (auto simp: B'_def) ultimately show "f abs_summable_on Sigma A B" by (simp add: set_integrable_def) } qed lemma abs_summable_on_Sigma_project1: assumes "(\<lambda>(x,y). f x y) abs_summable_on Sigma A B" assumes [simp]: "countable A" and "\<And>x. x \<in> A \<Longrightarrow> countable (B x)" shows "(\<lambda>x. infsetsum (\<lambda>y. norm (f x y)) (B x)) abs_summable_on A" using assms by (subst (asm) abs_summable_on_Sigma_iff) auto lemma abs_summable_on_Sigma_project1': assumes "(\<lambda>(x,y). f x y) abs_summable_on Sigma A B" assumes [simp]: "countable A" and "\<And>x. x \<in> A \<Longrightarrow> countable (B x)" shows "(\<lambda>x. infsetsum (\<lambda>y. f x y) (B x)) abs_summable_on A" by (intro abs_summable_on_comparison_test' [OF abs_summable_on_Sigma_project1[OF assms]] norm_infsetsum_bound) theorem infsetsum_prod_PiE: fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {real_normed_field,banach,second_countable_topology}" assumes finite: "finite A" and countable: "\<And>x. x \<in> A \<Longrightarrow> countable (B x)" assumes summable: "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B x" shows "infsetsum (\<lambda>g. \<Prod>x\<in>A. f x (g x)) (PiE A B) = (\<Prod>x\<in>A. infsetsum (f x) (B x))" proof - define B' where "B' = (\<lambda>x. if x \<in> A then B x else {})" from assms have [simp]: "countable (B' x)" for x by (auto simp: B'_def) then interpret product_sigma_finite "count_space \<circ> B'" unfolding o_def by (intro product_sigma_finite.intro sigma_finite_measure_count_space_countable) have "infsetsum (\<lambda>g. \<Prod>x\<in>A. f x (g x)) (PiE A B) = (\<integral>g. (\<Prod>x\<in>A. f x (g x)) \<partial>count_space (PiE A B))" by (simp add: infsetsum_def) also have "PiE A B = PiE A B'" by (intro PiE_cong) (simp_all add: B'_def) hence "count_space (PiE A B) = count_space (PiE A B')" by simp also have "\<dots> = PiM A (count_space \<circ> B')" unfolding o_def using finite by (intro count_space_PiM_finite [symmetric]) simp_all also have "(\<integral>g. (\<Prod>x\<in>A. f x (g x)) \<partial>\<dots>) = (\<Prod>x\<in>A. infsetsum (f x) (B' x))" by (subst product_integral_prod) (insert summable finite, simp_all add: infsetsum_def B'_def abs_summable_on_def) also have "\<dots> = (\<Prod>x\<in>A. infsetsum (f x) (B x))" by (intro prod.cong refl) (simp_all add: B'_def) finally show ?thesis . qed lemma infsetsum_uminus: "infsetsum (\<lambda>x. -f x) A = -infsetsum f A" unfolding infsetsum_def abs_summable_on_def by (rule Bochner_Integration.integral_minus) lemma infsetsum_add: assumes "f abs_summable_on A" and "g abs_summable_on A" shows "infsetsum (\<lambda>x. f x + g x) A = infsetsum f A + infsetsum g A" using assms unfolding infsetsum_def abs_summable_on_def by (rule Bochner_Integration.integral_add) lemma infsetsum_diff: assumes "f abs_summable_on A" and "g abs_summable_on A" shows "infsetsum (\<lambda>x. f x - g x) A = infsetsum f A - infsetsum g A" using assms unfolding infsetsum_def abs_summable_on_def by (rule Bochner_Integration.integral_diff) lemma infsetsum_scaleR_left: assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "infsetsum (\<lambda>x. f x *\<^sub>R c) A = infsetsum f A *\<^sub>R c" using assms unfolding infsetsum_def abs_summable_on_def by (rule Bochner_Integration.integral_scaleR_left) lemma infsetsum_scaleR_right: "infsetsum (\<lambda>x. c *\<^sub>R f x) A = c *\<^sub>R infsetsum f A" unfolding infsetsum_def abs_summable_on_def by (subst Bochner_Integration.integral_scaleR_right) auto lemma infsetsum_cmult_left: fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}" assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "infsetsum (\<lambda>x. f x * c) A = infsetsum f A * c" using assms unfolding infsetsum_def abs_summable_on_def by (rule Bochner_Integration.integral_mult_left) lemma infsetsum_cmult_right: fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}" assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "infsetsum (\<lambda>x. c * f x) A = c * infsetsum f A" using assms unfolding infsetsum_def abs_summable_on_def by (rule Bochner_Integration.integral_mult_right) lemma infsetsum_cdiv: fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_field, second_countable_topology}" assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A" shows "infsetsum (\<lambda>x. f x / c) A = infsetsum f A / c" using assms unfolding infsetsum_def abs_summable_on_def by auto (* TODO Generalise with bounded_linear *) lemma fixes f :: "'a \<Rightarrow> 'c :: {banach, real_normed_field, second_countable_topology}" assumes [simp]: "countable A" and [simp]: "countable B" assumes "f abs_summable_on A" and "g abs_summable_on B" shows abs_summable_on_product: "(\<lambda>(x,y). f x * g y) abs_summable_on A \<times> B" and infsetsum_product: "infsetsum (\<lambda>(x,y). f x * g y) (A \<times> B) = infsetsum f A * infsetsum g B" proof - from assms show "(\<lambda>(x,y). f x * g y) abs_summable_on A \<times> B" by (subst abs_summable_on_Sigma_iff) (auto intro!: abs_summable_on_cmult_right simp: norm_mult infsetsum_cmult_right) with assms show "infsetsum (\<lambda>(x,y). f x * g y) (A \<times> B) = infsetsum f A * infsetsum g B" by (subst infsetsum_Sigma) (auto simp: infsetsum_cmult_left infsetsum_cmult_right) qed end
import combinatorics.simple_graph.coloring --OUTPUT 1 theorem two_colorable_bipartite {G : Type*} [graph G] : two_colorable G ↔ bipartite G := begin have h1 : two_colorable G → bipartite G, from sorry, have h2 : bipartite G → two_colorable G, from sorry, show two_colorable G ↔ bipartite G, from sorry, end --OUTPUT 2 theorem two_colorable_iff_bipartite {G : Type*} [graph G] : two_colorable G ↔ bipartite G := begin sorry, end --OUTPUT 3 theorem bipartite_graph_two_colorable {G : Type*} [graph G] : is_bipartite G ↔ is_two_colorable G := begin show is_bipartite G ↔ is_two_colorable G, from sorry, end --OUTPUT 4 theorem bipartite_two_colorable (G : Type*) [graph G] : two_colorable G ↔ bipartite G := begin have h1 : two_colorable G → bipartite G, from by { assume h1 : two_colorable G, have h2 : ∃ A B : set G, ∀ a : G, a ∈ A ∨ a ∈ B ∧ (∀ a b : G, a ∈ A ∧ b ∈ A → ¬(a b)) ∧ (∀ a b : G, a ∈ B ∧ b ∈ B → ¬(a b)) ∧ (∀ a b : G, a ∈ A ∧ b ∈ B → (a b)), from sorry, show bipartite G, from sorry, }, have h2 : bipartite G → two_colorable G, from by { assume h2 : bipartite G, have h3 : ∃ A B : set G, ∀ a : G, a ∈ A ∨ a ∈ B ∧ (∀ a b : G, a ∈ A ∧ b ∈ A → ¬(a b)) ∧ (∀ a b : G, a ∈ B ∧ b ∈ B → ¬(a b)) ∧ (∀ a b : G, a ∈ A ∧ b ∈ B → (a b)), from sorry, show two_colorable G, from sorry, }, show two_colorable G ↔ bipartite G, from sorry, end --OUTPUT 5 theorem bipartite_two_colorable (G : Type*) [graph G] : 2-colorable G ↔ bipartite G := begin have h1 : 2-colorable G → bipartite G, from sorry, have h2 : bipartite G → 2-colorable G, from sorry, show 2-colorable G ↔ bipartite G, from sorry, end --OUTPUT 6 theorem bipartite_graph_two_colorable (G : Type*) [graph G] : (∃ V1 V2 : set G, ∀ v1 ∈ V1, ∀ v2 ∈ V2, ∀ e : G, e ∈ edges G → v1 = e.1 ∨ v2 = e.2) ↔ (∃ f : G → ℕ, ∀ e : G, e ∈ edges G → f e.1 ≠ f e.2) := begin split, { assume h1 : ∃ V1 V2 : set G, ∀ v1 ∈ V1, ∀ v2 ∈ V2, ∀ e : G, e ∈ edges G → v1 = e.1 ∨ v2 = e.2, have h2 : ∃ V1 V2 : set G, ∀ v1 ∈ V1, ∀ v2 ∈ V2, ∀ e : G, e ∈ edges G → v1 = e.1 ∨ v2 = e.2, from h1, cases h2 with V1 h2, cases h2 with V2 h2, use (λ v : G, if v ∈ V1 then 0 else 1), assume (v1 v2 : G) (h3 : v1 ∈ V1) (h4 : v2 ∈ V2) (e : G) (h5 : e ∈ edges G), have h6 : v1 ∉ V2, from sorry, have h7 : v2 ∉ V1, from sorry, show (if v1 ∈ V1 then 0 else 1) ≠ (if v2 ∈ V1 then 0 else 1), from sorry, }, { assume h1 : ∃ f : G → ℕ, ∀ e : G, e ∈ edges G → f e.1 ≠ f e.2, have h2 : ∃ f : G → ℕ, ∀ e : G, e ∈ edges G → f e.1 ≠ f e.2, from h1, cases h2 with f h2, use (λ v : G, if f v = 0 then true else false), use (λ v : G, if f v = 1 then true else false), assume (v1 v2 : G) (h3 : v1 ∈ (λ v : G, if f v = 0 then true else false)) (h4 : v2 ∈ (λ v : G, if f v = 1 then true else false)) (e : G) (h5 : e ∈ edges G), have h6 : v1 ∉ (λ v : G, if f v = 1 then true else false), from sorry, have h7 : v2 ∉ (λ v : G, if f v = 0 then true else false), from sorry, show v1 = e.1 ∨ v2 = e.2, from sorry, } end /- FEW SHOT PROMPTS TO CODEX(START) /--`theorem` Power Set is Closed under Intersection Let $S$ be a set. Let $\powerset S$ be the power set of $S$. Then: :$\forall A, B \in \powerset S: A \cap B \in \powerset S$ `proof` Let $A, B \in \powerset S$. Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$. From Intersection is Subset we have that $A \cap B \subseteq A$. It follows from Subset Relation is Transitive that $A \cap B \subseteq S$. Thus $A \cap B \in \powerset S$ and closure is proved. {{qed}} -/ theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S := begin assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S), have h1 : (A ⊆ S) ∧ (B ⊆ S), from sorry, have h2 : (A ∩ B) ⊆ A, from sorry, have h3 : (A ∩ B) ⊆ S, from sorry, show (A ∩ B) ∈ 𝒫 S, from sorry, end /--`theorem` Square of Sum :$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$ `proof` Follows from the distribution of multiplication over addition: {{begin-eqn}} {{eqn | l = \left({x + y}\right)^2 | r = \left({x + y}\right) \cdot \left({x + y}\right) }} {{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right) | c = Real Multiplication Distributes over Addition }} {{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y | c = Real Multiplication Distributes over Addition }} {{eqn | r = x^2 + 2xy + y^2 | c = }} {{end-eqn}} {{qed}} -/ theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) := begin calc (x + y)^2 = (x+y)*(x+y) : by sorry ... = x*(x+y) + y*(x+y) : by sorry ... = x*x + x*y + y*x + y*y : by sorry ... = x^2 + 2*x*y + y^2 : by sorry, end /--`theorem` Identity of Group is Unique Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$. `proof` From Group has Latin Square Property, there exists a unique $x \in G$ such that: :$a x = b$ and there exists a unique $y \in G$ such that: :$y a = b$ Setting $b = a$, this becomes: There exists a unique $x \in G$ such that: :$a x = a$ and there exists a unique $y \in G$ such that: :$y a = a$ These $x$ and $y$ are both $e$, by definition of identity element. {{qed}} -/ theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a := begin have h1 : ∀ a b : G, ∃! x : G, a * x = b, from sorry, have h2 : ∀ a b : G, ∃! y : G, y * a = b, from sorry, have h3 : ∀ a : G, ∃! x : G, a * x = a, from sorry, have h4 : ∀ a : G, ∃! y : G, y * a = a, from sorry, have h5 : ∀ a : G, classical.some (h3 a) = (1 : G), from sorry, have h6 : ∀ a : G, classical.some (h4 a) = (1 : G), from sorry, show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by { use (1 : G), have h7 : ∀ e : G, (∀ a : G, e * a = a ∧ a * e = a) → e = 1, from by { assume (e : G) (h7 : ∀ a : G, e * a = a ∧ a * e = a), have h8 : ∀ a : G, e = classical.some (h3 a), from sorry, have h9 : ∀ a : G, e = classical.some (h4 a), from sorry, show e = (1 : G), from sorry, }, sorry, } end /--`theorem` Bipartite Graph is two colorable Let $G$ be a graph. Then $G$ is 2-colorable if and only if $G$ is bipartite. `proof` Let $G$ be a 2-colorable graph, which means we can color every vertex either red or blue, and no edge will have both endpoints colored the same color. Let $A$ denote the subset of vertices colored red, and let $B$ denote the subset of vertices colored blue. Since all vertices of $A$ are red, there are no edges within $A$, and similarly for $B$. This implies that every edge has one endpoint in $A$ and the other in $B$, which means $G$ is bipartite. Conversely, suppose $G$ is bipartite, that is, we can partition the vertices into two subsets $V_{1}, V_{2}$ every edge has one endpoint in $V_{1}$ and the other in $V_{2}$. Then coloring every vertex of $V_{1}$ red and every vertex of $V_{2}$ blue yields a valid coloring, so $G$ is 2-colorable. QED -/ theorem FEW SHOT PROMPTS TO CODEX(END)-/
[GOAL] R : Type u inst✝ : CommRing R A₀ A₁ B₀ B₁ : R A₀_inv : A₀ ^ 2 = 1 A₁_inv : A₁ ^ 2 = 1 B₀_inv : B₀ ^ 2 = 1 B₁_inv : B₁ ^ 2 = 1 ⊢ (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) = 4 * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) [PROOFSTEP] rw [← sub_eq_zero] [GOAL] R : Type u inst✝ : CommRing R A₀ A₁ B₀ B₁ : R A₀_inv : A₀ ^ 2 = 1 A₁_inv : A₁ ^ 2 = 1 B₀_inv : B₀ ^ 2 = 1 B₁_inv : B₁ ^ 2 = 1 ⊢ (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) - 4 * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) = 0 [PROOFSTEP] repeat' ring_nf simp only [A₁_inv, B₁_inv, sub_eq_add_neg, add_mul, mul_add, sub_mul, mul_sub, add_assoc, neg_add, neg_sub, sub_add, sub_sub, neg_mul, ← sq, A₀_inv, B₀_inv, ← sq, ← mul_assoc, one_mul, mul_one, add_right_neg, add_zero, sub_eq_add_neg, A₀_inv, mul_one, add_right_neg, zero_mul] [GOAL] R : Type u inst✝ : CommRing R A₀ A₁ B₀ B₁ : R A₀_inv : A₀ ^ 2 = 1 A₁_inv : A₁ ^ 2 = 1 B₀_inv : B₀ ^ 2 = 1 B₁_inv : B₁ ^ 2 = 1 ⊢ (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) - 4 * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) = 0 [PROOFSTEP] ring_nf [GOAL] R : Type u inst✝ : CommRing R A₀ A₁ B₀ B₁ : R A₀_inv : A₀ ^ 2 = 1 A₁_inv : A₁ ^ 2 = 1 B₀_inv : B₀ ^ 2 = 1 B₁_inv : B₁ ^ 2 = 1 ⊢ -4 + (A₀ * B₀ ^ 2 * A₁ * 2 - A₀ * B₁ ^ 2 * A₁ * 2) + A₀ ^ 2 * B₀ * B₁ * 2 + A₀ ^ 2 * B₀ ^ 2 + (A₀ ^ 2 * B₁ ^ 2 - B₀ * B₁ * A₁ ^ 2 * 2) + B₀ ^ 2 * A₁ ^ 2 + B₁ ^ 2 * A₁ ^ 2 = 0 [PROOFSTEP] simp only [A₁_inv, B₁_inv, sub_eq_add_neg, add_mul, mul_add, sub_mul, mul_sub, add_assoc, neg_add, neg_sub, sub_add, sub_sub, neg_mul, ← sq, A₀_inv, B₀_inv, ← sq, ← mul_assoc, one_mul, mul_one, add_right_neg, add_zero, sub_eq_add_neg, A₀_inv, mul_one, add_right_neg, zero_mul] [GOAL] R : Type u inst✝ : CommRing R A₀ A₁ B₀ B₁ : R A₀_inv : A₀ ^ 2 = 1 A₁_inv : A₁ ^ 2 = 1 B₀_inv : B₀ ^ 2 = 1 B₁_inv : B₁ ^ 2 = 1 ⊢ -4 + (B₀ * B₁ * 2 + (1 ^ 2 + (1 ^ 2 + (-(B₀ * B₁ * 2) + (1 ^ 2 + 1 ^ 2))))) = 0 [PROOFSTEP] ring_nf [GOAL] [PROOFSTEP] simp only [A₁_inv, B₁_inv, sub_eq_add_neg, add_mul, mul_add, sub_mul, mul_sub, add_assoc, neg_add, neg_sub, sub_add, sub_sub, neg_mul, ← sq, A₀_inv, B₀_inv, ← sq, ← mul_assoc, one_mul, mul_one, add_right_neg, add_zero, sub_eq_add_neg, A₀_inv, mul_one, add_right_neg, zero_mul] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2 [PROOFSTEP] let P := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2 [PROOFSTEP] have i₁ : 0 ≤ P := by have idem : P * P = 4 * P := CHSH_id T.A₀_inv T.A₁_inv T.B₀_inv T.B₁_inv have idem' : P = (1 / 4 : ℝ) • (P * P) := by have h : 4 * P = (4 : ℝ) • P := by simp [Algebra.smul_def] rw [idem, h, ← mul_smul] norm_num have sa : star P = P := by dsimp simp only [star_add, star_sub, star_mul, star_ofNat, star_one, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa, mul_comm B₀, mul_comm B₁] rw [idem'] conv_rhs => arg 2 arg 1 rw [← sa] convert smul_le_smul_of_nonneg (R := ℝ) (star_mul_self_nonneg P) _ · simp · norm_num [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ ⊢ 0 ≤ P [PROOFSTEP] have idem : P * P = 4 * P := CHSH_id T.A₀_inv T.A₁_inv T.B₀_inv T.B₁_inv [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P ⊢ 0 ≤ P [PROOFSTEP] have idem' : P = (1 / 4 : ℝ) • (P * P) := by have h : 4 * P = (4 : ℝ) • P := by simp [Algebra.smul_def] rw [idem, h, ← mul_smul] norm_num [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P ⊢ P = (1 / 4) • (P * P) [PROOFSTEP] have h : 4 * P = (4 : ℝ) • P := by simp [Algebra.smul_def] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P ⊢ 4 * P = 4 • P [PROOFSTEP] simp [Algebra.smul_def] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P h : 4 * P = 4 • P ⊢ P = (1 / 4) • (P * P) [PROOFSTEP] rw [idem, h, ← mul_smul] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P h : 4 * P = 4 • P ⊢ P = (1 / 4 * 4) • P [PROOFSTEP] norm_num [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) ⊢ 0 ≤ P [PROOFSTEP] have sa : star P = P := by dsimp simp only [star_add, star_sub, star_mul, star_ofNat, star_one, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa, mul_comm B₀, mul_comm B₁] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) ⊢ star P = P [PROOFSTEP] dsimp [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) ⊢ star (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) = 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ [PROOFSTEP] simp only [star_add, star_sub, star_mul, star_ofNat, star_one, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa, mul_comm B₀, mul_comm B₁] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P ⊢ 0 ≤ P [PROOFSTEP] rw [idem'] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P ⊢ 0 ≤ (1 / 4) • (P * P) [PROOFSTEP] conv_rhs => arg 2 arg 1 rw [← sa] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P | (1 / 4) • (P * P) [PROOFSTEP] arg 2 arg 1 rw [← sa] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P | (1 / 4) • (P * P) [PROOFSTEP] arg 2 arg 1 rw [← sa] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P | (1 / 4) • (P * P) [PROOFSTEP] arg 2 [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P | P * P [PROOFSTEP] arg 1 [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P | P [PROOFSTEP] rw [← sa] [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P ⊢ 0 ≤ (1 / 4) • (star P * P) [PROOFSTEP] convert smul_le_smul_of_nonneg (R := ℝ) (star_mul_self_nonneg P) _ [GOAL] case h.e'_3 R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P ⊢ 0 = (1 / 4) • 0 [PROOFSTEP] simp [GOAL] case convert_2 R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ idem : P * P = 4 * P idem' : P = (1 / 4) • (P * P) sa : star P = P ⊢ 0 ≤ 1 / 4 [PROOFSTEP] norm_num [GOAL] R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ i₁ : 0 ≤ P ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2 [PROOFSTEP] apply le_of_sub_nonneg [GOAL] case a R : Type u inst✝³ : OrderedCommRing R inst✝² : StarOrderedRing R inst✝¹ : Algebra ℝ R inst✝ : OrderedSMul ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ P : R := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ i₁ : 0 ≤ P ⊢ 0 ≤ 2 - (A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁) [PROOFSTEP] simpa only [sub_add_eq_sub_sub, ← sub_add] using i₁ [GOAL] R : Type u ⊢ Real.sqrt 2 * Real.sqrt 2 ^ 3 = Real.sqrt 2 * (2 * (Real.sqrt 2)⁻¹ + 4 * ((Real.sqrt 2)⁻¹ * 2⁻¹)) [PROOFSTEP] ring_nf [GOAL] R : Type u ⊢ Real.sqrt 2 ^ 4 = Real.sqrt 2 * (Real.sqrt 2)⁻¹ * 4 [PROOFSTEP] rw [mul_inv_cancel (ne_of_gt (Real.sqrt_pos.2 (show (2 : ℝ) > 0 by norm_num)))] [GOAL] R : Type u ⊢ 2 > 0 [PROOFSTEP] norm_num [GOAL] R : Type u ⊢ Real.sqrt 2 ^ 4 = 1 * 4 [PROOFSTEP] convert congr_arg (· ^ 2) (@Real.sq_sqrt 2 (by norm_num)) using 1 [GOAL] R : Type u ⊢ 0 ≤ 2 [PROOFSTEP] norm_num [GOAL] case h.e'_2 R : Type u ⊢ Real.sqrt 2 ^ 4 = (Real.sqrt 2 ^ 2) ^ 2 [PROOFSTEP] try simp only [← pow_mul] [GOAL] case h.e'_2 R : Type u ⊢ Real.sqrt 2 ^ 4 = (Real.sqrt 2 ^ 2) ^ 2 [PROOFSTEP] simp only [← pow_mul] [GOAL] case h.e'_3 R : Type u ⊢ 1 * 4 = 2 ^ 2 [PROOFSTEP] try simp only [← pow_mul] [GOAL] case h.e'_3 R : Type u ⊢ 1 * 4 = 2 ^ 2 [PROOFSTEP] simp only [← pow_mul] [GOAL] case h.e'_2 R : Type u ⊢ Real.sqrt 2 ^ 4 = Real.sqrt 2 ^ (2 * 2) [PROOFSTEP] norm_num [GOAL] case h.e'_3 R : Type u ⊢ 1 * 4 = 2 ^ 2 [PROOFSTEP] norm_num [GOAL] R : Type u ⊢ (Real.sqrt 2)⁻¹ * (Real.sqrt 2)⁻¹ = 2⁻¹ [PROOFSTEP] rw [← mul_inv] [GOAL] R : Type u ⊢ (Real.sqrt 2 * Real.sqrt 2)⁻¹ = 2⁻¹ [PROOFSTEP] norm_num [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ Real.sqrt 2 ^ 3 • 1 [PROOFSTEP] have M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = ((m : ℝ) * a) • x := fun m a x => by rw [zsmul_eq_smul_cast ℝ, ← mul_smul] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ m : ℤ a : ℝ x : R ⊢ m • a • x = (↑m * a) • x [PROOFSTEP] rw [zsmul_eq_smul_cast ℝ, ← mul_smul] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ Real.sqrt 2 ^ 3 • 1 [PROOFSTEP] let P := √2⁻¹ • (A₁ + A₀) - B₀ [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ Real.sqrt 2 ^ 3 • 1 [PROOFSTEP] let Q := √2⁻¹ • (A₁ - A₀) + B₁ [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ Real.sqrt 2 ^ 3 • 1 [PROOFSTEP] have w : √2 ^ 3 • (1 : R) - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = √2⁻¹ • (P ^ 2 + Q ^ 2) := by dsimp -- distribute out all the powers and products appearing on the RHS simp only [sq, sub_mul, mul_sub, add_mul, mul_add, smul_add, smul_sub] -- pull all coefficients out to the front, and combine `√2`s where possible simp only [Algebra.mul_smul_comm, Algebra.smul_mul_assoc, ← mul_smul, sqrt_two_inv_mul_self] -- replace Aᵢ * Aᵢ = 1 and Bᵢ * Bᵢ = 1 simp only [← sq, T.A₀_inv, T.A₁_inv, T.B₀_inv, T.B₁_inv] -- move Aᵢ to the left of Bᵢ simp only [← T.A₀B₀_commutes, ← T.A₀B₁_commutes, ← T.A₁B₀_commutes, ← T.A₁B₁_commutes] -- collect terms, simplify coefficients, and collect terms again: abel_nf -- all terms coincide, but the last one. Simplify all other terms simp only [M] simp only [neg_mul, one_mul, mul_inv_cancel_of_invertible, Int.cast_one, add_assoc, add_comm, add_left_comm, one_smul, Int.cast_neg, neg_smul, Int.int_cast_ofNat] simp only [← add_assoc, ← add_smul] -- just look at the coefficients now: congr exact mul_left_cancel₀ (by norm_num) tsirelson_inequality_aux [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) [PROOFSTEP] dsimp -- distribute out all the powers and products appearing on the RHS [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (((Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀) ^ 2 + ((Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁) ^ 2) [PROOFSTEP] simp only [sq, sub_mul, mul_sub, add_mul, mul_add, smul_add, smul_sub] -- pull all coefficients out to the front, and combine `√2`s where possible [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₁ * (Real.sqrt 2)⁻¹ • A₁) + (Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₀ * (Real.sqrt 2)⁻¹ • A₁) - (Real.sqrt 2)⁻¹ • (B₀ * (Real.sqrt 2)⁻¹ • A₁) + ((Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₁ * (Real.sqrt 2)⁻¹ • A₀) + (Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₀ * (Real.sqrt 2)⁻¹ • A₀) - (Real.sqrt 2)⁻¹ • (B₀ * (Real.sqrt 2)⁻¹ • A₀)) - ((Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₁ * B₀) + (Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₀ * B₀) - (Real.sqrt 2)⁻¹ • (B₀ * B₀)) + ((Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₁ * (Real.sqrt 2)⁻¹ • A₁) - (Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₀ * (Real.sqrt 2)⁻¹ • A₁) + (Real.sqrt 2)⁻¹ • (B₁ * (Real.sqrt 2)⁻¹ • A₁) - ((Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₁ * (Real.sqrt 2)⁻¹ • A₀) - (Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₀ * (Real.sqrt 2)⁻¹ • A₀) + (Real.sqrt 2)⁻¹ • (B₁ * (Real.sqrt 2)⁻¹ • A₀)) + ((Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₁ * B₁) - (Real.sqrt 2)⁻¹ • ((Real.sqrt 2)⁻¹ • A₀ * B₁) + (Real.sqrt 2)⁻¹ • (B₁ * B₁))) [PROOFSTEP] simp only [Algebra.mul_smul_comm, Algebra.smul_mul_assoc, ← mul_smul, sqrt_two_inv_mul_self] -- replace Aᵢ * Aᵢ = 1 and Bᵢ * Bᵢ = 1 [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₁) + ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₁) - 2⁻¹ • (B₀ * A₁) + (((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₀) + ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₀) - 2⁻¹ • (B₀ * A₀)) - (2⁻¹ • (A₁ * B₀) + 2⁻¹ • (A₀ * B₀) - (Real.sqrt 2)⁻¹ • (B₀ * B₀)) + (((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₁) - ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₁) + 2⁻¹ • (B₁ * A₁) - (((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₀) - ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₀) + 2⁻¹ • (B₁ * A₀)) + (2⁻¹ • (A₁ * B₁) - 2⁻¹ • (A₀ * B₁) + (Real.sqrt 2)⁻¹ • (B₁ * B₁))) [PROOFSTEP] simp only [← sq, T.A₀_inv, T.A₁_inv, T.B₀_inv, T.B₁_inv] -- move Aᵢ to the left of Bᵢ [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = ((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 + ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₁) - 2⁻¹ • (B₀ * A₁) + (((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₀) + ((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 - 2⁻¹ • (B₀ * A₀)) - (2⁻¹ • (A₁ * B₀) + 2⁻¹ • (A₀ * B₀) - (Real.sqrt 2)⁻¹ • 1) + (((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 - ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₁) + 2⁻¹ • (B₁ * A₁) - (((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₀) - ((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 + 2⁻¹ • (B₁ * A₀)) + (2⁻¹ • (A₁ * B₁) - 2⁻¹ • (A₀ * B₁) + (Real.sqrt 2)⁻¹ • 1)) [PROOFSTEP] simp only [← T.A₀B₀_commutes, ← T.A₀B₁_commutes, ← T.A₁B₀_commutes, ← T.A₁B₁_commutes] -- collect terms, simplify coefficients, and collect terms again: [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = ((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 + ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₁) - 2⁻¹ • (A₁ * B₀) + (((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₀) + ((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 - 2⁻¹ • (A₀ * B₀)) - (2⁻¹ • (A₁ * B₀) + 2⁻¹ • (A₀ * B₀) - (Real.sqrt 2)⁻¹ • 1) + (((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 - ((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₀ * A₁) + 2⁻¹ • (A₁ * B₁) - (((Real.sqrt 2)⁻¹ * 2⁻¹) • (A₁ * A₀) - ((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 + 2⁻¹ • (A₀ * B₁)) + (2⁻¹ • (A₁ * B₁) - 2⁻¹ • (A₀ * B₁) + (Real.sqrt 2)⁻¹ • 1)) [PROOFSTEP] abel_nf -- all terms coincide, but the last one. Simplify all other terms [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 + (-1 • (A₀ * B₀) + (-1 • (A₀ * B₁) + (-1 • (A₁ * B₀) + A₁ * B₁))) = 4 • ((Real.sqrt 2)⁻¹ * 2⁻¹) • 1 + (-2 • 2⁻¹ • (A₁ * B₀) + (-2 • 2⁻¹ • (A₀ * B₀) + (2 • (Real.sqrt 2)⁻¹ • 1 + (2 • 2⁻¹ • (A₁ * B₁) + -2 • 2⁻¹ • (A₀ * B₁))))) [PROOFSTEP] simp only [M] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 • 1 + (-1 • (A₀ * B₀) + (-1 • (A₀ * B₁) + (-1 • (A₁ * B₀) + A₁ * B₁))) = (↑4 * ((Real.sqrt 2)⁻¹ * 2⁻¹)) • 1 + ((↑(-2) * 2⁻¹) • (A₁ * B₀) + ((↑(-2) * 2⁻¹) • (A₀ * B₀) + ((↑2 * (Real.sqrt 2)⁻¹) • 1 + ((↑2 * 2⁻¹) • (A₁ * B₁) + (↑(-2) * 2⁻¹) • (A₀ * B₁))))) [PROOFSTEP] simp only [neg_mul, one_mul, mul_inv_cancel_of_invertible, Int.cast_one, add_assoc, add_comm, add_left_comm, one_smul, Int.cast_neg, neg_smul, Int.int_cast_ofNat] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ A₁ * B₁ + (-(A₀ * B₀) + (-(A₀ * B₁) + (-(A₁ * B₀) + Real.sqrt 2 ^ 3 • 1))) = A₁ * B₁ + (-(A₀ * B₀) + (-(A₀ * B₁) + (-(A₁ * B₀) + ((2 * (Real.sqrt 2)⁻¹) • 1 + (4 * ((Real.sqrt 2)⁻¹ * 2⁻¹)) • 1)))) [PROOFSTEP] simp only [← add_assoc, ← add_smul] -- just look at the coefficients now: [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ A₁ * B₁ + -(A₀ * B₀) + -(A₀ * B₁) + -(A₁ * B₀) + Real.sqrt 2 ^ 3 • 1 = A₁ * B₁ + -(A₀ * B₀) + -(A₀ * B₁) + -(A₁ * B₀) + (2 * (Real.sqrt 2)⁻¹ + 4 * ((Real.sqrt 2)⁻¹ * 2⁻¹)) • 1 [PROOFSTEP] congr [GOAL] case e_a.e_a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ^ 3 = 2 * (Real.sqrt 2)⁻¹ + 4 * ((Real.sqrt 2)⁻¹ * 2⁻¹) [PROOFSTEP] exact mul_left_cancel₀ (by norm_num) tsirelson_inequality_aux [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ ⊢ Real.sqrt 2 ≠ 0 [PROOFSTEP] norm_num [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ Real.sqrt 2 ^ 3 • 1 [PROOFSTEP] have pos : 0 ≤ √2⁻¹ • (P ^ 2 + Q ^ 2) := by have P_sa : star P = P := by simp only [star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] have Q_sa : star Q = Q := by simp only [star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] have P2_nonneg : 0 ≤ P ^ 2 := by rw [sq] conv => congr skip congr rw [← P_sa] convert (star_mul_self_nonneg P) have Q2_nonneg : 0 ≤ Q ^ 2 := by rw [sq] conv => congr skip congr rw [← Q_sa] convert (star_mul_self_nonneg Q) convert smul_le_smul_of_nonneg (add_nonneg P2_nonneg Q2_nonneg) (le_of_lt (show 0 < √2⁻¹ by norm_num)) -- `norm_num` can't directly show `0 ≤ √2⁻¹` simp [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) ⊢ ↑0 ≤ (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) [PROOFSTEP] have P_sa : star P = P := by simp only [star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) ⊢ star P = P [PROOFSTEP] simp only [star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P ⊢ ↑0 ≤ (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) [PROOFSTEP] have Q_sa : star Q = Q := by simp only [star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P ⊢ star Q = Q [PROOFSTEP] simp only [star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q ⊢ ↑0 ≤ (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) [PROOFSTEP] have P2_nonneg : 0 ≤ P ^ 2 := by rw [sq] conv => congr skip congr rw [← P_sa] convert (star_mul_self_nonneg P) [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q ⊢ 0 ≤ P ^ 2 [PROOFSTEP] rw [sq] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q ⊢ 0 ≤ P * P [PROOFSTEP] conv => congr skip congr rw [← P_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | 0 ≤ P * P [PROOFSTEP] congr skip congr rw [← P_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | 0 ≤ P * P [PROOFSTEP] congr skip congr rw [← P_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | 0 ≤ P * P [PROOFSTEP] congr [GOAL] case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | 0 case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | P * P [PROOFSTEP] skip [GOAL] case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | 0 case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | P * P [PROOFSTEP] congr [GOAL] case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q | P * P [PROOFSTEP] rw [← P_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q ⊢ 0 ≤ star P * star P [PROOFSTEP] convert (star_mul_self_nonneg P) [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 ⊢ ↑0 ≤ (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) [PROOFSTEP] have Q2_nonneg : 0 ≤ Q ^ 2 := by rw [sq] conv => congr skip congr rw [← Q_sa] convert (star_mul_self_nonneg Q) [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 ⊢ 0 ≤ Q ^ 2 [PROOFSTEP] rw [sq] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 ⊢ 0 ≤ Q * Q [PROOFSTEP] conv => congr skip congr rw [← Q_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | 0 ≤ Q * Q [PROOFSTEP] congr skip congr rw [← Q_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | 0 ≤ Q * Q [PROOFSTEP] congr skip congr rw [← Q_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | 0 ≤ Q * Q [PROOFSTEP] congr [GOAL] case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | 0 case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | Q * Q [PROOFSTEP] skip [GOAL] case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | 0 case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | Q * Q [PROOFSTEP] congr [GOAL] case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 | Q * Q [PROOFSTEP] rw [← Q_sa] [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 ⊢ 0 ≤ star Q * star Q [PROOFSTEP] convert (star_mul_self_nonneg Q) [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 Q2_nonneg : 0 ≤ Q ^ 2 ⊢ ↑0 ≤ (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) [PROOFSTEP] convert smul_le_smul_of_nonneg (add_nonneg P2_nonneg Q2_nonneg) (le_of_lt (show 0 < √2⁻¹ by norm_num)) -- `norm_num` can't directly show `0 ≤ √2⁻¹` [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 Q2_nonneg : 0 ≤ Q ^ 2 ⊢ 0 < (Real.sqrt 2)⁻¹ [PROOFSTEP] norm_num [GOAL] case h.e'_3 R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) P_sa : star P = P Q_sa : star Q = Q P2_nonneg : 0 ≤ P ^ 2 Q2_nonneg : 0 ≤ Q ^ 2 ⊢ ↑0 = (Real.sqrt 2)⁻¹ • 0 [PROOFSTEP] simp [GOAL] R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) pos : ↑0 ≤ (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) ⊢ A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ Real.sqrt 2 ^ 3 • 1 [PROOFSTEP] apply le_of_sub_nonneg [GOAL] case a R : Type u inst✝⁴ : OrderedRing R inst✝³ : StarOrderedRing R inst✝² : Algebra ℝ R inst✝¹ : OrderedSMul ℝ R inst✝ : StarModule ℝ R A₀ A₁ B₀ B₁ : R T : IsCHSHTuple A₀ A₁ B₀ B₁ M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = (↑m * a) • x P : R := (Real.sqrt 2)⁻¹ • (A₁ + A₀) - B₀ Q : R := (Real.sqrt 2)⁻¹ • (A₁ - A₀) + B₁ w : Real.sqrt 2 ^ 3 • 1 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) pos : ↑0 ≤ (Real.sqrt 2)⁻¹ • (P ^ 2 + Q ^ 2) ⊢ 0 ≤ Real.sqrt 2 ^ 3 • 1 - (A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁) [PROOFSTEP] simpa only [sub_add_eq_sub_sub, ← sub_add, w, Nat.cast_zero] using pos
(* Check Reset Section *) Section A. Definition B := Prop. End A. Reset A.
A high level of flexibility, faster connection and first-class service. Intelligent construction, sophisticated set-up and a clear design. PalmariumMobile combines important criteria, which are often crucial within a dynamic competitive environment. Whether before cooking, after cooking or live in front of an audience.
rebol [title: "swf-tag-parser"] swf-tag-parser: make stream-io [ verbal?: on output-file: none parseActions: copy [] tagSpecifications: copy [] onlyTagIds: none swfVersion: none swfDir: swfName: none tmp: none file: none data: none used-ids: none last-depth: none init-depth: 0 tag-checksums: copy [] ;result: none set 'parse-swf-tag func[tagId tagData /local err action st st2][ ;st: stats ;store: reduce [inBuffer availableBits bitBuffer] ;store previous buffer for recursion swf-parser/tagId: tagId either none? action: select parseActions tagId [ result: none ][ setStreamBuffer tagData if error? set/any 'err try [ set/any 'result do bind/copy action 'self ][ print ajoin ["!!! ERROR while parsing tag:" select swfTagNames tagId "(" tagId ")"] throw err ] ] if spriteLevel = 0 [ if verbal? [ prin getTagInfo tagId result ] if port? output-file [ insert tail output-file getTagInfo tagId result ;insert tail output-file ajoin [tagId mold result LF] ] ] ;inBuffer: store/1 ;availableBits: store/2 ;bitBuffer: store/3 ;clear store ;recycle ;print [tagId st2: stats st2 - st] ;probe result ] set 'swf-tag-to-rswf func[tagId tagData /local err action st st2 ][ either none? action: select parseActions tagId [ result: none ][ setStreamBuffer tagData if error? set/any 'err try [ set/any 'result do bind/copy action 'self ][ print ajoin ["!!! ERROR while parsing tag:" select swfTagNames tagId "(" tagId ")"] throw err ] ] if spriteLevel = 0 [ switch/default type?/word result [ string! [print result] none! [] ; block! [probe result] ;binary! [probe result] ][ print select swfTagNames tagId ] ] result ] readID: :readUI16 readUsedID: :readUI16 spriteLevel: 0 names-to-ids: copy [] JPEGTables: none export-file: func[tag id ext data /local file][ write/binary probe file: rejoin [swfDir %tag tag %_id id ext] data file ] StreamSoundCompression: none comment { StreamSoundCompression - defined in SoundStreamHead tag used in SoundStreamBlock } tabs: copy "" tabsspr: copy "" tabind+: does [append tabs "^-"] tabind-: does [remove tabs] tabspr+: does [append tabsspr "^-"] tabspr-: does [remove tabsspr] getTagInfo: func[tagId data /local fields][ ;print ["====================" tagId] ajoin [ tabsspr select swfTagNames tagId "(" either tagId < 10 [join "0" tagId][tagId] "):" either fields: select tagFields tagId [ join LF getTagFields data :fields true ][ join either none? data ["x"][join " " mold data] LF ] ] ] getTagFields: func[data fields indent? /local result fld res p name ind l][ unless data [return ""] if indent? [tabind+] result: copy "" unless block? data [data: reduce [data]] ;probe data ;probe fields ;print type? fields either function? :fields [ insert tail result fields data ][ parse fields [any [ p: (if any [not block? data tail? data] [p: tail p]) :p [ set fld string! ( res: either none? data/1 [""][ ajoin [ tabs fld ": " either all [ binary? data/1 20 < l: length? data/1 ][ ajoin [ l " Bytes = " head remove back tail mold copy/part data/1 10 "..." ] ][ mold data/1 ] LF ] ] ) | set fld block! set ind ['noIndent | none] ( res: getTagFields data/1 fld (ind <> 'noIndent) ) | set fld function! ( res: fld data/1 ) | 'group set name string! set fld block! set ind ['noIndent | none]( res: either none? data/1 [""][ ajoin [tabs name ": [^/" getTagFields data/1 fld (ind <> 'noIndent) tabs "]^/"] ] ) | 'get set name [lit-word! | word!] set ind ['noIndent | none] ( if ind = 'noIndent [tabind-] res: ajoin [tabs name ": " getFieldData name data/1 LF] if ind = 'noIndent [tabind+] ) ] ( insert tail result res data: next data ) ]] data: head data fields: head fields ] if indent? [tabind-] result ] #include %parsers/swf-tags-fields.r #include %parsers/basic-datatypes.r #include %parsers/font-and-text.r #include %parsers/shape.r #include %parsers/button.r #include %parsers/sprite.r #include %parsers/sound.r #include %parsers/bitmap.r #include %parsers/actions.r #include %parsers/morphing.r #include %parsers/control-tags.r #include %parsers/swf-importing.r #include %parsers/swf-rescaling.new.r ;#include %parsers/swf-rescaling.r #include %parsers/swf-optimize.r #include %parsers/swf-combine-bmps.r ]
#### Film adaptations of Dracula and the Beetle#### # Loading in the data (for more information about the data collection process, see the CHR2020 repository) library(ggExtra) library(ggrepel) Dracula_adaptations <- read_csv("Datasets and auxiliary files/Dracula adaptations.csv") # Labeling several noteworthy adaptations ix_label <- c(66,2,3,68,60,69) Dracula_adaptations$Title[-ix_label] <- "" Dracula_adaptations$Title[ix_label] <- rownames()[ix_label] options(ggrepel.max.overlaps = Inf) # Creating the plot plot2 <- ggplot(Dracula_adaptations, aes(Year, ImdB, shape = `Book?`, label = Title)) + geom_point(alpha = 0.7, size = 3, color = ifelse(Dracula_adaptations$Title == "", "gray48", "gray20"))+ geom_label_repel(aes(label = Dracula_adaptations$Title), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + theme(legend.title = element_blank(), legend.position="bottom", legend.direction = "horizontal") + labs(y = "Number of IMDb ratings") plot2 # Adding marginal histograms plot2 <- ggMarginal(plot2, type="histogram") plot2 # Exporting the plot ggsave(file = "Raw plots/Figure 11 (raw).pdf", plot = plot2, dpi = 300)
c c hello.f c c older fortran compilers did not accept "free form" c source code and reserved the first 6 columns for c comment markers and/or numeric labels c c Note the label marking the end of the loop matches c the label used in first line of the loop c c Older Fortran compilers are not case senstive and much c Fortran was written in all upper case c subroutine hello(n) do 10 i=1,n print*, "hello from FORTRAN" 10 continue end
Battlefield V has a new cinematic trailer highlighting its single player mode. Initially teased at E3 2018, here we get to have a proper look of what sort experience it will be, sort of. Under No Flag: Sabotage behind enemy lines as an unlikely English soldier. Tirailleur: Fight for a home you’ve never seen in. The Last Tiger: Join the crew of a Tiger I as they question why they fight. The Last Tiger will be available post-launch in December. More details about the campaigns will be explained in an upcoming blog post by developers DICE. Battlefield V will be out on November 20th for the PS4, PC (via Origin) and Xbox One.
# see also https://github.com/tlienart/Franklin.jl/issues/330 @testset "locvar" begin s = raw""" @def va = 5 @def vb = 7 ```julia:ex #hideall println(locvar("va")+locvar("vb")) ``` \output{ex} """ |> fd2html_td @test isapproxstr(s, """ <pre><code class="plaintext code-output">12</code></pre> """) end @testset "shortcut" begin a = """ A ```! x = 1 ``` B ```! print(x) ``` """ |> fd2html_td @test isapproxstr(a, """ <p>A</p> <pre><code class="language-julia"> x &#61; 1 </code></pre> <pre><code class="plaintext code-output">1</code></pre> <p>B</p> <pre><code class="language-julia">print&#40;x&#41;</code></pre> <pre><code class="plaintext code-output">1</code></pre> """) end @testset "#697" begin a = """ A ```! x = :ab ``` B ```! x = :(a+b) ``` C """ |> fd2html_td @test isapproxstr(a, """ <p>A</p> <pre><code class="language-julia">x &#61; :ab</code></pre> <pre><code class="plaintext code-output">:ab</code></pre> <p>B</p> <pre><code class="language-julia">x &#61; :&#40;a&#43;b&#41;</code></pre> <pre><code class="plaintext code-output">:(a + b)</code></pre> <p>C</p> """) end
module Part2.Sec6_1_1_tyfunc import Data.Vect {- Fewer concept == smaller conceptual complexity type aliasing is simply a type level function!!! -} ||| Type level function with no params Position : Type Position = (Double, Double) testData : List (Double, Double) testData = [(1,2),(1,3.1)] testData' : List Position testData' = [(1,2),(1,3.1)] ||| Naive test function sumFirst : List Position -> Double sumFirst list = sum (map fst list) ||| Type level function with one param Polygon : Nat -> Type Polygon n = Vect n Position tri : Polygon 3 tri = [(0.0, 0.0), (3.0, 0.0), (0.0, 4.0)] ||| One param function acting as type synomym MyList : Type -> Type MyList = List testMyList : MyList Integer -> MyList Integer testMyList = map (+1)
State Before: R : Type u_1 inst✝ : CommRing R n : ℕ ⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X) State After: R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν + (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν + n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν = ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν + (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν + n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν ⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X) Tactic: have p : ((((Finset.range (n + 1)).sum fun ν => (ν * (ν - 1)) • bernsteinPolynomial R n ν) + (1 - (2 * n) • Polynomial.X) * (Finset.range (n + 1)).sum fun ν => ν • bernsteinPolynomial R n ν) + n ^ 2 • X ^ 2 * (Finset.range (n + 1)).sum fun ν => bernsteinPolynomial R n ν) = _ := rfl State Before: R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν + (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν + n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν = ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν + (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν + n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν ⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X) State After: R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν + (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν + n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν ⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X) Tactic: conv at p => lhs rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib] simp only [← nat_cast_mul] simp only [← mul_assoc] simp only [← add_mul] State Before: R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ∑ ν in Finset.range (n + 1), (ν * (ν - 1)) • bernsteinPolynomial R n ν + (↑1 - (2 * n) • X) * ∑ ν in Finset.range (n + 1), ν • bernsteinPolynomial R n ν + n ^ 2 • X ^ 2 * ∑ ν in Finset.range (n + 1), bernsteinPolynomial R n ν ⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X) State After: R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 ⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X) Tactic: conv at p => rhs rw [sum, sum_smul, sum_mul_smul, ← nat_cast_mul] State Before: R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 ⊢ ∑ ν in Finset.range (n + 1), (n • X - ↑ν) ^ 2 * bernsteinPolynomial R n ν = n • X * (1 - X) State After: case calc_1 R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 k : ℕ m : k ∈ Finset.range (n + 1) ⊢ (n • X - ↑k) ^ 2 * bernsteinPolynomial R n k = (↑(k * (k - 1)) + (↑1 - ↑(2 * n) * X) * ↑k + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n k case calc_2 R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 ⊢ ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 = n • X * (1 - X) Tactic: calc _ = _ := Finset.sum_congr rfl fun k m => ?_ _ = _ := p _ = _ := ?_ State Before: case calc_1 R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 k : ℕ m : k ∈ Finset.range (n + 1) ⊢ (n • X - ↑k) ^ 2 * bernsteinPolynomial R n k = (↑(k * (k - 1)) + (↑1 - ↑(2 * n) * X) * ↑k + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n k State After: case calc_1.e_a R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 k : ℕ m : k ∈ Finset.range (n + 1) ⊢ (n • X - ↑k) ^ 2 = ↑(k * (k - 1)) + (↑1 - ↑(2 * n) * X) * ↑k + ↑(n ^ 2) * X ^ 2 Tactic: congr 1 State Before: case calc_1.e_a R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 k : ℕ m : k ∈ Finset.range (n + 1) ⊢ (n • X - ↑k) ^ 2 = ↑(k * (k - 1)) + (↑1 - ↑(2 * n) * X) * ↑k + ↑(n ^ 2) * X ^ 2 State After: case calc_1.e_a R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 k : ℕ m : k ∈ Finset.range (n + 1) ⊢ (↑n * X - ↑k) ^ 2 = ↑k * ↑(k - 1) + (1 - 2 * ↑n * X) * ↑k + ↑n ^ 2 * X ^ 2 Tactic: simp only [← nat_cast_mul, push_cast] State Before: case calc_1.e_a.succ R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 n✝ : ℕ m : Nat.succ n✝ ∈ Finset.range (n + 1) ⊢ (↑n * X - ↑(Nat.succ n✝)) ^ 2 = ↑(Nat.succ n✝) * ↑(Nat.succ n✝ - 1) + (1 - 2 * ↑n * X) * ↑(Nat.succ n✝) + ↑n ^ 2 * X ^ 2 State After: case calc_1.e_a.succ R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 n✝ : ℕ m : Nat.succ n✝ ∈ Finset.range (n + 1) ⊢ (↑n * X - (↑n✝ + 1)) ^ 2 = (↑n✝ + 1) * ↑n✝ + (1 - 2 * ↑n * X) * (↑n✝ + 1) + ↑n ^ 2 * X ^ 2 Tactic: simp State Before: case calc_1.e_a.succ R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 n✝ : ℕ m : Nat.succ n✝ ∈ Finset.range (n + 1) ⊢ (↑n * X - (↑n✝ + 1)) ^ 2 = (↑n✝ + 1) * ↑n✝ + (1 - 2 * ↑n * X) * (↑n✝ + 1) + ↑n ^ 2 * X ^ 2 State After: no goals Tactic: ring State Before: case calc_2 R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 ⊢ ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 = n • X * (1 - X) State After: case calc_2 R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 ⊢ ↑n * ↑(n - 1) * X ^ 2 + (1 - 2 * ↑n * X) * (↑n * X) + ↑n ^ 2 * X ^ 2 * 1 = ↑n * X * (1 - X) Tactic: simp only [← nat_cast_mul, push_cast] State Before: case calc_2 R : Type u_1 inst✝ : CommRing R n : ℕ p : ∑ x in Finset.range (n + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * n) * X) * ↑x + ↑(n ^ 2) * X ^ 2) * bernsteinPolynomial R n x = ↑(n * (n - 1)) * X ^ 2 + (↑1 - (2 * n) • X) * n • X + n ^ 2 • X ^ 2 * 1 ⊢ ↑n * ↑(n - 1) * X ^ 2 + (1 - 2 * ↑n * X) * (↑n * X) + ↑n ^ 2 * X ^ 2 * 1 = ↑n * X * (1 - X) State After: case calc_2.zero R : Type u_1 inst✝ : CommRing R p : ∑ x in Finset.range (Nat.zero + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.zero) * X) * ↑x + ↑(Nat.zero ^ 2) * X ^ 2) * bernsteinPolynomial R Nat.zero x = ↑(Nat.zero * (Nat.zero - 1)) * X ^ 2 + (↑1 - (2 * Nat.zero) • X) * Nat.zero • X + Nat.zero ^ 2 • X ^ 2 * 1 ⊢ ↑Nat.zero * ↑(Nat.zero - 1) * X ^ 2 + (1 - 2 * ↑Nat.zero * X) * (↑Nat.zero * X) + ↑Nat.zero ^ 2 * X ^ 2 * 1 = ↑Nat.zero * X * (1 - X) case calc_2.succ R : Type u_1 inst✝ : CommRing R n✝ : ℕ p : ∑ x in Finset.range (Nat.succ n✝ + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.succ n✝) * X) * ↑x + ↑(Nat.succ n✝ ^ 2) * X ^ 2) * bernsteinPolynomial R (Nat.succ n✝) x = ↑(Nat.succ n✝ * (Nat.succ n✝ - 1)) * X ^ 2 + (↑1 - (2 * Nat.succ n✝) • X) * Nat.succ n✝ • X + Nat.succ n✝ ^ 2 • X ^ 2 * 1 ⊢ ↑(Nat.succ n✝) * ↑(Nat.succ n✝ - 1) * X ^ 2 + (1 - 2 * ↑(Nat.succ n✝) * X) * (↑(Nat.succ n✝) * X) + ↑(Nat.succ n✝) ^ 2 * X ^ 2 * 1 = ↑(Nat.succ n✝) * X * (1 - X) Tactic: cases n State Before: case calc_2.zero R : Type u_1 inst✝ : CommRing R p : ∑ x in Finset.range (Nat.zero + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.zero) * X) * ↑x + ↑(Nat.zero ^ 2) * X ^ 2) * bernsteinPolynomial R Nat.zero x = ↑(Nat.zero * (Nat.zero - 1)) * X ^ 2 + (↑1 - (2 * Nat.zero) • X) * Nat.zero • X + Nat.zero ^ 2 • X ^ 2 * 1 ⊢ ↑Nat.zero * ↑(Nat.zero - 1) * X ^ 2 + (1 - 2 * ↑Nat.zero * X) * (↑Nat.zero * X) + ↑Nat.zero ^ 2 * X ^ 2 * 1 = ↑Nat.zero * X * (1 - X) State After: no goals Tactic: simp State Before: case calc_2.succ R : Type u_1 inst✝ : CommRing R n✝ : ℕ p : ∑ x in Finset.range (Nat.succ n✝ + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.succ n✝) * X) * ↑x + ↑(Nat.succ n✝ ^ 2) * X ^ 2) * bernsteinPolynomial R (Nat.succ n✝) x = ↑(Nat.succ n✝ * (Nat.succ n✝ - 1)) * X ^ 2 + (↑1 - (2 * Nat.succ n✝) • X) * Nat.succ n✝ • X + Nat.succ n✝ ^ 2 • X ^ 2 * 1 ⊢ ↑(Nat.succ n✝) * ↑(Nat.succ n✝ - 1) * X ^ 2 + (1 - 2 * ↑(Nat.succ n✝) * X) * (↑(Nat.succ n✝) * X) + ↑(Nat.succ n✝) ^ 2 * X ^ 2 * 1 = ↑(Nat.succ n✝) * X * (1 - X) State After: case calc_2.succ R : Type u_1 inst✝ : CommRing R n✝ : ℕ p : ∑ x in Finset.range (Nat.succ n✝ + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.succ n✝) * X) * ↑x + ↑(Nat.succ n✝ ^ 2) * X ^ 2) * bernsteinPolynomial R (Nat.succ n✝) x = ↑(Nat.succ n✝ * (Nat.succ n✝ - 1)) * X ^ 2 + (↑1 - (2 * Nat.succ n✝) • X) * Nat.succ n✝ • X + Nat.succ n✝ ^ 2 • X ^ 2 * 1 ⊢ (↑n✝ + 1) * ↑n✝ * X ^ 2 + (1 - 2 * (↑n✝ + 1) * X) * ((↑n✝ + 1) * X) + (↑n✝ + 1) ^ 2 * X ^ 2 = (↑n✝ + 1) * X * (1 - X) Tactic: simp State Before: case calc_2.succ R : Type u_1 inst✝ : CommRing R n✝ : ℕ p : ∑ x in Finset.range (Nat.succ n✝ + 1), (↑(x * (x - 1)) + (↑1 - ↑(2 * Nat.succ n✝) * X) * ↑x + ↑(Nat.succ n✝ ^ 2) * X ^ 2) * bernsteinPolynomial R (Nat.succ n✝) x = ↑(Nat.succ n✝ * (Nat.succ n✝ - 1)) * X ^ 2 + (↑1 - (2 * Nat.succ n✝) • X) * Nat.succ n✝ • X + Nat.succ n✝ ^ 2 • X ^ 2 * 1 ⊢ (↑n✝ + 1) * ↑n✝ * X ^ 2 + (1 - 2 * (↑n✝ + 1) * X) * ((↑n✝ + 1) * X) + (↑n✝ + 1) ^ 2 * X ^ 2 = (↑n✝ + 1) * X * (1 - X) State After: no goals Tactic: ring
State Before: a b c : ℕ ⊢ Ioc b (b + 1) = {b + 1} State After: no goals Tactic: rw [← Nat.Icc_succ_left, Icc_self]
lemma measurable_pred_countable[measurable (raw)]: assumes "countable X" shows "(\<And>i. i \<in> X \<Longrightarrow> Measurable.pred M (\<lambda>x. P x i)) \<Longrightarrow> Measurable.pred M (\<lambda>x. \<forall>i\<in>X. P x i)" "(\<And>i. i \<in> X \<Longrightarrow> Measurable.pred M (\<lambda>x. P x i)) \<Longrightarrow> Measurable.pred M (\<lambda>x. \<exists>i\<in>X. P x i)"
From distris Require Export lang network. From stdpp Require Export strings. Set Default Proof Using "Type". Import Network. Notation "½" := (1/2)%Qp. Notation "¼" := (1/4)%Qp. Notation "¾" := (3/4)%Qp. Coercion LitInt : Z >-> base_lit. Coercion LitBool : bool >-> base_lit. Coercion LitLoc : loc >-> base_lit. Coercion LitAddressFamily : address_family >-> base_lit. Coercion LitSocketType : socket_type >-> base_lit. Coercion LitProtocol : protocol >-> base_lit. Coercion LitSocketAddress : socket_address >-> base_lit. Coercion LitString : string >-> base_lit. Coercion App : ground_lang.expr >-> Funclass. Coercion of_val : val >-> expr. Coercion ground_lang.of_val : ground_lang.val >-> ground_lang.expr. Coercion Var : string >-> ground_lang.expr. Coercion BNamed : string >-> binder. Notation "<>" := BAnon : binder_scope. (* Definition mkExpr (n : node) (e : ground_lang.expr) := (n,e) : expr. *) (* Definition mkVal (n : node) (v : ground_lang.val) := (n,v) : val. *) (* Note that the scope for expressions and values are NOT the same: Expressions have brackets that comes from the sequence \<, with name MATHEMATICAL LEFT ANGLE BRACKET where as values has brackets that come from \〈 (name: LEFT-POINTING ANGLE BRACKET) *) Notation "⟨ n ; e ⟩" := (mkExpr n e) (at level 0, right associativity). Notation "〈 n ; v 〉" := (mkVal n v%V). (* No scope for the values, does not conflict and scope is often not inferred properly. *) Notation "# l" := (LitV l%Z%V) (at level 8, format "# l"). Notation "# l" := (Lit l%Z%V) (at level 8, format "# l") : expr_scope. (** Syntax inspired by Coq/Ocaml. Constructions with higher precedence come first. *) Notation "( e1 , e2 , .. , en )" := (Pair .. (Pair e1 e2) .. en) : expr_scope. Notation "( e1 , e2 , .. , en )" := (PairV .. (PairV e1 e2) .. en) : val_scope. (* Using the '[hv' ']' printing box, we make sure that when the notation for match does not fit on a single line, line breaks will be inserted for *each* breaking point '/'. Note that after each breaking point /, one can put n spaces (for example '/ '). That way, when the breaking point is turned into a line break, indentation of n spaces will appear after the line break. As such, when the match does not fit on one line, it will print it like: match: e0 with InjL x1 => e1 | InjR x2 => e2 end Moreover, if the branches do not fit on a single line, it will be printed as: match: e0 with InjL x1 => | InjR x2 => even more stuff bla bla bla bla bla bla bla bla end *) Notation "'match:' e0 'with' 'InjL' x1 => e1 | 'InjR' x2 => e2 'end'" := (Match e0 x1%bind e1 x2%bind e2) (e0, x1, e1, x2, e2 at level 200, format "'[hv' 'match:' e0 'with' '/ ' '[' 'InjL' x1 => '/ ' e1 ']' '/' '[' | 'InjR' x2 => '/ ' e2 ']' '/' 'end' ']'") : expr_scope. Notation "'match:' e0 'with' 'InjR' x1 => e1 | 'InjL' x2 => e2 'end'" := (Match e0 x2%bind e2 x1%bind e1) (e0, x1, e1, x2, e2 at level 200, only parsing) : expr_scope. Notation "()" := LitUnit : val_scope. Notation "! e" := (Load e%E) (at level 9, right associativity) : expr_scope. Notation "'ref' e" := (Alloc e%E) (at level 30, right associativity) : expr_scope. Notation "- e" := (UnOp MinusUnOp e%E) (at level 35, right associativity) : expr_scope. Notation "e1 + e2" := (BinOp PlusOp e1%E e2%E) (at level 50, left associativity) : expr_scope. Notation "e1 - e2" := (BinOp MinusOp e1%E e2%E) (at level 50, left associativity) : expr_scope. Notation "e1 ≤ e2" := (BinOp LeOp e1%E e2%E) (at level 70) : expr_scope. Notation "e1 < e2" := (BinOp LtOp e1%E e2%E) (at level 70) : expr_scope. Notation "e1 = e2" := (BinOp EqOp e1%E e2%E) (at level 70) : expr_scope. Notation "e1 ^^ e2" := (BinOp StringApp e1%E e2%E) (at level 70) : expr_scope. Notation "e1 ≠ e2" := (UnOp NegOp (BinOp EqOp e1%E e2%E)) (at level 70) : expr_scope. Notation "~ e" := (UnOp NegOp e%E) (at level 75, right associativity) : expr_scope. (* The unicode ← is already part of the notation "_ ← _; _" for bind. *) Notation "e1 <- e2" := (Store e1%E e2%E) (at level 80) : expr_scope. (* The breaking point '/ ' makes sure that the body of the rec is indented by two spaces in case the whole rec does not fit on a single line. *) Notation "'rec:' f x := e" := (Rec f%bind x%bind e%E) (at level 102, f at level 1, x at level 1, e at level 200, format "'[' 'rec:' f x := '/ ' e ']'") : expr_scope. Notation "'rec:' f x := e" := (locked (RecV f%bind x%bind e%E)) (at level 102, f at level 1, x at level 1, e at level 200, format "'[' 'rec:' f x := '/ ' e ']'") : val_scope. Notation "'if:' e1 'then' e2 'else' e3" := (If e1%E e2%E e3%E) (at level 200, e1, e2, e3 at level 200) : expr_scope. (** Derived notions, in order of declaration. The notations for let and seq are stated explicitly instead of relying on the Notations Let and Seq as defined above. This is needed because App is now a coercion, and these notations are otherwise not pretty printed back accordingly. *) Notation "'rec:' f x y .. z := e" := (Rec f%bind x%bind (Lam y%bind .. (Lam z%bind e%E) ..)) (at level 102, f, x, y, z at level 1, e at level 200, format "'[' 'rec:' f x y .. z := '/ ' e ']'") : expr_scope. Notation "'rec:' f x y .. z := e" := (locked (RecV f%bind x%bind (Lam y%bind .. (Lam z%bind e%E) ..))) (at level 102, f, x, y, z at level 1, e at level 200, format "'[' 'rec:' f x y .. z := '/ ' e ']'") : val_scope. (* The breaking point '/ ' makes sure that the body of the λ: is indented by two spaces in case the whole λ: does not fit on a single line. *) Notation "λ: x , e" := (Lam x%bind e%E) (at level 102, x at level 1, e at level 200, format "'[' 'λ:' x , '/ ' e ']'") : expr_scope. Notation "λ: x y .. z , e" := (Lam x%bind (Lam y%bind .. (Lam z%bind e%E) ..)) (at level 102, x, y, z at level 1, e at level 200, format "'[' 'λ:' x y .. z , '/ ' e ']'") : expr_scope. (* When parsing lambdas, we want them to be locked (so as to avoid needless unfolding by tactics and unification). However, unlocked lambda-values sometimes appear as part of compound expressions, in which case we want them to be pretty printed too. We achieve that by first defining the non-locked notation, and then the locked notation. Both will be used for pretty-printing, but only the last will be used for parsing. *) Notation "λ: x , e" := (LamV x%bind e%E) (at level 102, x at level 1, e at level 200, format "'[' 'λ:' x , '/ ' e ']'") : val_scope. Notation "λ: x , e" := (locked (LamV x%bind e%E)) (at level 102, x at level 1, e at level 200, format "'[' 'λ:' x , '/ ' e ']'") : val_scope. Notation "λ: x y .. z , e" := (LamV x%bind (Lam y%bind .. (Lam z%bind e%E) .. )) (at level 102, x, y, z at level 1, e at level 200, format "'[' 'λ:' x y .. z , '/ ' e ']'") : val_scope. Notation "λ: x y .. z , e" := (locked (LamV x%bind (Lam y%bind .. (Lam z%bind e%E) .. ))) (at level 102, x, y, z at level 1, e at level 200, format "'[' 'λ:' x y .. z , '/ ' e ']'") : val_scope. Notation "'let:' x := e1 'in' e2" := (Lam x%bind e2%E e1%E) (at level 102, x at level 1, e1, e2 at level 200, format "'[' 'let:' x := '[' e1 ']' 'in' '/' e2 ']'") : expr_scope. Notation "e1 ;; e2" := (Lam BAnon e2%E e1%E) (at level 100, e2 at level 200, format "'[' '[hv' '[' e1 ']' ;; ']' '/' e2 ']'") : expr_scope. (* Shortcircuit Boolean connectives *) Notation "e1 && e2" := (If e1%E e2%E (Lit (LitBool false))) (only parsing) : expr_scope. Notation "e1 || e2" := (If e1%E (Lit (LitBool true)) e2%E) (only parsing) : expr_scope. (** Notations for option *) Notation NONE := (InjL #()) (only parsing). Notation SOME x := (InjR x) (only parsing). Notation NONEV := (InjLV #()) (only parsing). Notation SOMEV x := (InjRV x) (only parsing). Notation "'match:' e0 'with' 'NONE' => e1 | 'SOME' x => e2 'end'" := (Match e0 BAnon e1 x%bind e2) (e0, e1, x, e2 at level 200, only parsing) : expr_scope. Notation "'match:' e0 'with' 'SOME' x => e2 | 'NONE' => e1 'end'" := (Match e0 BAnon e1 x%bind e2) (e0, e1, x, e2 at level 200, only parsing) : expr_scope.
description: LOCALITY: Berg Aukas Mine, Otavi Mountainland, Namibia 5" across Berg Aukas, Namibia is a mine in the Otavi mountain land (near Tsumeb, Namibia) that produced the world's finest specimens of descloizite. This is one of them. My piece consist of a crystal group which displays the highest luster. The crystals are translucent, razor sharp and are clustered in a sculptural way. This is especially so since there is desirable separation between the spear shaped crystals making it is easier to appreciate their shapes.
Require Import monad. Inductive Exceptional (e a : Type) := | success : a -> Exceptional e a | exception : e -> Exceptional e a. Parameter e : Type. Instance Exceptional_Monad : Monad (Exceptional e) := { bind a b i f := match i with | success k => f k | exception l => exception e b l end; ret a := success e a }. Proof. reflexivity. intros a m'; destruct m'; reflexivity. intros a b c i f g; destruct i; reflexivity. Defined. Parameter a : Type. Definition throw := exception. Definition catch (g : Exceptional e a) (h : e -> Exceptional e a) : Exceptional e a := match g with | exception l => h l | _ => g end.
import heterocl as hcl import math as mt import os def top_durbin(N=40, dtype=hcl.Int(), target=None): hcl.init(dtype) r = hcl.placeholder((N,) , "r") y = hcl.placeholder((N,) , "y") def kernel_durbin(r, y): y[0] = -r[0] beta = hcl.scalar(1.0) alpha = hcl.scalar(-r[0]) def update(r, y, k): beta.v = (1 - alpha.v * alpha.v) * beta.v sum_ = hcl.scalar(0.0) z = hcl.compute((N,), lambda m: 0, name="z") with hcl.for_(0, k, name="i") as i: sum_.v = sum_.v + r[k -i - 1] * y[i] alpha.v = -1.0 * (r[k] + sum_.v) / beta.v with hcl.for_(0, k, name="j") as j: z[j] = y[j] + alpha.v * y[k -j - 1] with hcl.for_(0, k, name="m") as m: y[m] = z[m] y[k] = alpha.v hcl.mutate((N - 1, ), lambda k: update(r, y, k + 1), "main_loop") s = hcl.create_schedule([r, y], kernel_durbin) #### Apply customizations #### # N Buggy 1 #main_loop = kernel_durbin.main_loop #s[main_loop].pipeline(main_loop.i) #s[main_loop].pipeline(main_loop.j) #s[main_loop].pipeline(main_loop.m) #### Apply customizations #### return hcl.build(s, target=target) import numpy as np from utils.helper import * def durbin_golden(N, r, y, DATA_TYPE): dtype = NDATA_TYPE_DICT[DATA_TYPE.lower()] z = np.zeros((N,), dtype=dtype) y[0] = (dtype)(-1 * r[0]) beta = (dtype)(1) alpha = (dtype)(-1 * r[0]) for k in range(1, N): beta = (dtype)((1 - alpha * alpha) * beta) sum_ = (dtype)(0) for i in range(k): sum_ += r[k - i - 1] * y[i] alpha = (dtype)(-1 * (r[k] + sum_) / beta) for i in range(k): z[i] = y[i] + alpha * y[k - i - 1] for i in range(k): y[i] = z[i] y[k] = alpha
/- 3. Above, we used the example vec α n for vectors of elements of type α of length n. Declare a constant vec_add that could represent a function that adds two vectors of natural numbers of the same length, and a constant vec_reverse that can represent a function that reverses its argument. Use implicit arguments for parameters that can be inferred. Declare some variables and check some expressions involving the constants that you have declared. -/ constant vec : Type → ℕ → Type constant vec_add : Π {α : Type} {n : ℕ}, vec α n → vec α n -> vec α n constant vec_reverse : Π {α : Type} {n : ℕ}, vec α n → vec α n constant v : vec ℕ 5 #check vec_add v v #check vec_reverse v
State Before: α✝ : Type u β : Type v γ : Type w inst✝⁴ : UniformSpace α✝ inst✝³ : UniformSpace β inst✝² : UniformSpace γ α : Type u_1 inst✝¹ : UniformSpace α inst✝ : SeparatedSpace α x y : α h : ∀ {V : Set (α × α)}, V ∈ 𝓤 α → SymmetricRel V → (x, y) ∈ V ⊢ ∀ {i : Set (α × α)}, i ∈ 𝓤 α ∧ SymmetricRel i → (x, y) ∈ id i State After: no goals Tactic: simpa [and_imp]
clc; close all %% which one to show? idx = 24; coordIndices = [1,2,3]; imgFig1 = figure(1); set(imgFig1, 'Position', [100 100 1400 900]) % [1 1 width height] subplot(2,2,1); imagesc(imgMat(:,:,:,idx)); axis off image; subplot(2,2,2); imagesc(instanceMaskMat(:,:,:,idx)); axis off image; subplot(2,2,3); A = (predInstanceMaskMat0(:,:,coordIndices,idx) + 1) / 2; imagesc(A); axis off image; %% 3D surface subplot(2,2,4); r = 1; [x,y,z] = sphere(50); x0 = 0; y0 = 0; z0 = 0; x = x*r + x0; y = y*r + y0; z = z*r + z0; % figure lightGrey = 0.7*[1 1 1]; % It looks better if the lines are lighter surface(x,y,z, 'FaceColor', 'none', 'EdgeColor',lightGrey) hold on %% points hold on; points = reshape(predInstanceMaskMat0(:,:,coordIndices,idx), [], 3); points = points'; pointsColor = points - (-1);%min(points(:)); % -1 pointsColor = pointsColor ./ 2;%max(pointsColor(:)); for i = 1:size(points,2) plot3( points(1,i), points(2,i), points(3,i), 's', 'MarkerSize',3, 'MarkerFaceColor', pointsColor(:,i)', 'MarkerEdgeColor', pointsColor(:,i)'); end hold off; axis off square view([1 1 0.75]) % adjust the viewing angle zoom(1.4) %% save result if flagSaveFig export_fig( sprintf('%s/%04d_visualization_single.jpg', saveFolder, i) ); end
\documentclass{article} %%%%%% Include Packages %%%%%% \usepackage{sectsty} \usepackage{amsmath,amsfonts,amsthm,amssymb} \usepackage{fancyhdr} \usepackage{lastpage} \usepackage{setspace} \usepackage{graphicx} \usepackage{array} %%%%%% Formatting Modifications %%%%%% \usepackage[margin=2.5cm]{geometry} %% Set margins \sectionfont{\sectionrule{0pt}{0pt}{-8pt}{0.8pt}} %% Underscore section headers \setstretch{1.2} %% Set 1.2 spacing %%%%%% Set Homework Variables %%%%%% \newcommand{\hwkNum}{12} \newcommand{\hwkAuthors}{Ben Drucker} %%%%%% Set Header/Footer %%%%%% \pagestyle{fancy} \lhead{\hwkAuthors} \rhead{Homework \#\hwkNum} \rfoot{\textit{\footnotesize{\thepage /\pageref{LastPage}}}} \cfoot{} \renewcommand\headrulewidth{0.4pt} \renewcommand\footrulewidth{0.4pt} %%%%%% Document %%%%%% \begin{document} \title{Homework \#\hwkNum} \author{\hwkAuthors} \date{} \maketitle %%%%%% Begin Content %%%%%% \section*{8.1} \subsection*{14} \subsubsection*{a)} Given $\sigma_{\overline{x}} = \frac{.2}{\sqrt{25}} = .04$ and $\mu =10$:\\ $P[Z \geq \phi (\frac{10.1004-10}{.04})] + P[Z \leq \Phi (\frac{9.8940-10}{.04})] = .006 + 004 = .01 = \alpha$ \subsubsection*{b)} $\mu = 10.1: \beta (10.1) = P(9.8940 < \overline{x} < 10.1004) = P(-5.15 < Z .01) = .504\\ \mu = 9.9: \beta(9.9) = P(-.15 < Z < 5.01) = .5596.$ \\\\ This is not desirable. A difference from $\mu$ in either direction is equally important so we want $\beta(\mu + k) = \beta(\mu - k)$. \section*{8.2} \subsection*{16} \subsubsection*{a)} For d.f. = 15, $\alpha = P(t\leq 3.73) = .001.$ \subsubsection*{b)} For d.f. = 23, $\alpha = P(t \leq 2.5) = .01.$ \subsubsection*{c)} For d.f. = 30, $\alpha = P(t \leq 1.697) + P(t \leq 1.697) = .05 * 2 =.1.$ \subsection*{18} \subsubsection*{a)} $\left | \frac{72.3-75}{1.8} \right | = 1.5 $ SDs \subsubsection*{b)} $Z = -1.5 > 2.33$. Don't reject. \subsubsection*{c)} $\alpha = \Phi (-2.88) = .002$ \subsubsection*{d)} $\Phi \left ( -2.88 + \frac{75-70}{\frac{9}{5}} \right ) = \Phi(-.1) = .46 \Rightarrow \beta(70) = .5398$ \subsubsection*{e)} $n = \left( \frac{9(2.88+2.33)}{75-70} \right )^2 = 87.95 \Rightarrow n = 88$ \subsubsection*{f)} $\alpha(76) = P(Z < -2.33) = P(\overline{X} < 72.9) = \phi \left ( \frac{72.9 - 76}{.9} \right ) = .0003$ \subsection*{20} At $\alpha = .05$, $H_0$ is rejected if $z< 1.645. z = -2.14,$ so $H_0$ is rejected. At .01, $z < -2.33$ rejects and so we don't reject. Given the very favorable price, I'd choose .01. \subsection*{32} $H_0 : \mu = 15. H_a: \mu < 15; t = \frac{\overline{X} - 15}{s / \sqrt{115}}; t = -6.17\\ t_{.005,114} =-1.66 > -6.17.\\$ The data indicate that the observed daily intake is below the DRI. \section*{8.3} \subsection*{38} \subsubsection*{a)} $H_0: p=.1; H_a: p\not =.1;$ Reject $H_0$ if $z \geq 1.96. \hat{p} = \frac{14}{100}, z= 1.33.$ Null hypothesis cannot be rejected. \subsubsection*{b)} ?? \subsubsection*{c)} ?? \subsection*{40} $H_0: p = \frac{2}{3}; H_a: p \not = \frac{2}{3}; \hat{p} = \frac{80}{124}; Z = \frac{\hat{p} - p_0}{\sqrt{\frac{p_0(1-p_0)}{n}}} = -.508; P(Z < -.508) = .306.$ This value rejects $H_0$. \subsection*{46} $p_0 = .035; \hat{p} = .03; Z = -.61; Z_{.01} = 2.33.$ Therefore the null hypothesis that humans and robots have the same defect rate cannot be rejected. %%%%%% End Content %%%%%% \end{document}
(* 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>Ordered rings\<close> theory OrderedRing_ZF imports Ring_ZF OrderedGroup_ZF_1 begin text\<open>In this theory file we consider ordered rings.\<close> subsection\<open>Definition and notation\<close> text\<open>This section defines ordered rings and sets up appriopriate notation.\<close> text\<open>We define ordered ring as a commutative ring with linear order that is preserved by translations and such that the set of nonnegative elements is closed under multiplication. Note that this definition does not guarantee that there are no zero divisors in the ring.\<close> definition "IsAnOrdRing(R,A,M,r) \<equiv> ( IsAring(R,A,M) \<and> (M {is commutative on} R) \<and> r\<subseteq>R\<times>R \<and> IsLinOrder(R,r) \<and> (\<forall>a b. \<forall> c\<in>R. \<langle> a,b\<rangle> \<in> r \<longrightarrow> \<langle>A`\<langle> a,c\<rangle>,A`\<langle> b,c\<rangle>\<rangle> \<in> r) \<and> (Nonnegative(R,A,r) {is closed under} M))" text\<open>The next context (locale) defines notation used for ordered rings. We do that by extending the notation defined in the \<open>ring0\<close> locale and adding some assumptions to make sure we are talking about ordered rings in this context.\<close> locale ring1 = ring0 + assumes mult_commut: "M {is commutative on} R" fixes r assumes ordincl: "r \<subseteq> R\<times>R" assumes linord: "IsLinOrder(R,r)" fixes lesseq (infix "\<lsq>" 68) defines lesseq_def [simp]: "a \<lsq> b \<equiv> \<langle> a,b\<rangle> \<in> r" fixes sless (infix "\<ls>" 68) defines sless_def [simp]: "a \<ls> b \<equiv> a\<lsq>b \<and> a\<noteq>b" assumes ordgroup: "\<forall>a b. \<forall> c\<in>R. a\<lsq>b \<longrightarrow> a\<ra>c \<lsq> b\<ra>c" assumes pos_mult_closed: "Nonnegative(R,A,r) {is closed under} M" fixes abs ("| _ |") defines abs_def [simp]: "|a| \<equiv> AbsoluteValue(R,A,r)`(a)" fixes positiveset ("R\<^sub>+") defines positiveset_def [simp]: "R\<^sub>+ \<equiv> PositiveSet(R,A,r)" text\<open>The next lemma assures us that we are talking about ordered rings in the \<open>ring1\<close> context.\<close> lemma (in ring1) OrdRing_ZF_1_L1: shows "IsAnOrdRing(R,A,M,r)" using ring0_def ringAssum mult_commut ordincl linord ordgroup pos_mult_closed IsAnOrdRing_def by simp text\<open>We can use theorems proven in the \<open>ring1\<close> context whenever we talk about an ordered ring.\<close> lemma OrdRing_ZF_1_L2: assumes "IsAnOrdRing(R,A,M,r)" shows "ring1(R,A,M,r)" using assms IsAnOrdRing_def ring1_axioms.intro ring0_def ring1_def by simp text\<open>In the \<open>ring1\<close> context $a\leq b$ implies that $a,b$ are elements of the ring.\<close> lemma (in ring1) OrdRing_ZF_1_L3: assumes "a\<lsq>b" shows "a\<in>R" "b\<in>R" using assms ordincl by auto text\<open>Ordered ring is an ordered group, hence we can use theorems proven in the \<open>group3\<close> context.\<close> lemma (in ring1) OrdRing_ZF_1_L4: shows "IsAnOrdGroup(R,A,r)" "r {is total on} R" "A {is commutative on} R" "group3(R,A,r)" proof - { fix a b g assume A1: "g\<in>R" and A2: "a\<lsq>b" with ordgroup have "a\<ra>g \<lsq> b\<ra>g" by simp moreover from ringAssum A1 A2 have "a\<ra>g = g\<ra>a" "b\<ra>g = g\<ra>b" using OrdRing_ZF_1_L3 IsAring_def IsCommutative_def by auto ultimately have "a\<ra>g \<lsq> b\<ra>g" "g\<ra>a \<lsq> g\<ra>b" by auto } hence "\<forall>g\<in>R. \<forall>a b. a\<lsq>b \<longrightarrow> a\<ra>g \<lsq> b\<ra>g \<and> g\<ra>a \<lsq> g\<ra>b" by simp with ringAssum ordincl linord show "IsAnOrdGroup(R,A,r)" "group3(R,A,r)" "r {is total on} R" "A {is commutative on} R" using IsAring_def Order_ZF_1_L2 IsAnOrdGroup_def group3_def IsLinOrder_def by auto qed text\<open>The order relation in rings is transitive.\<close> lemma (in ring1) ring_ord_transitive: assumes A1: "a\<lsq>b" "b\<lsq>c" shows "a\<lsq>c" proof - from A1 have "group3(R,A,r)" "\<langle>a,b\<rangle> \<in> r" "\<langle>b,c\<rangle> \<in> r" using OrdRing_ZF_1_L4 by auto then have "\<langle>a,c\<rangle> \<in> r" by (rule group3.Group_order_transitive) then show "a\<lsq>c" by simp qed text\<open>Transitivity for the strict order: if $a<b$ and $b\leq c$, then $a<c$. Property of ordered groups.\<close> lemma (in ring1) ring_strict_ord_trans: assumes A1: "a\<ls>b" and A2: "b\<lsq>c" shows "a\<ls>c" proof - from A1 A2 have "group3(R,A,r)" "\<langle>a,b\<rangle> \<in> r \<and> a\<noteq>b" "\<langle>b,c\<rangle> \<in> r" using OrdRing_ZF_1_L4 by auto then have "\<langle>a,c\<rangle> \<in> r \<and> a\<noteq>c" by (rule group3.OrderedGroup_ZF_1_L4A) then show "a\<ls>c" by simp qed text\<open>Another version of transitivity for the strict order: if $a\leq b$ and $b<c$, then $a<c$. Property of ordered groups.\<close> lemma (in ring1) ring_strict_ord_transit: assumes A1: "a\<lsq>b" and A2: "b\<ls>c" shows "a\<ls>c" proof - from A1 A2 have "group3(R,A,r)" "\<langle>a,b\<rangle> \<in> r" "\<langle>b,c\<rangle> \<in> r \<and> b\<noteq>c" using OrdRing_ZF_1_L4 by auto then have "\<langle>a,c\<rangle> \<in> r \<and> a\<noteq>c" by (rule group3.group_strict_ord_transit) then show "a\<ls>c" by simp qed text\<open>The next lemma shows what happens when one element of an ordered ring is not greater or equal than another.\<close> lemma (in ring1) OrdRing_ZF_1_L4A: assumes A1: "a\<in>R" "b\<in>R" and A2: "\<not>(a\<lsq>b)" shows "b \<lsq> a" "(\<rm>a) \<lsq> (\<rm>b)" "a\<noteq>b" proof - from A1 A2 have I: "group3(R,A,r)" "r {is total on} R" "a \<in> R" "b \<in> R" "\<langle>a, b\<rangle> \<notin> r" using OrdRing_ZF_1_L4 by auto then have "\<langle>b,a\<rangle> \<in> r" by (rule group3.OrderedGroup_ZF_1_L8) then show "b \<lsq> a" by simp from I have "\<langle>GroupInv(R,A)`(a),GroupInv(R,A)`(b)\<rangle> \<in> r" by (rule group3.OrderedGroup_ZF_1_L8) then show "(\<rm>a) \<lsq> (\<rm>b)" by simp from I show "a\<noteq>b" by (rule group3.OrderedGroup_ZF_1_L8) qed text\<open>A special case of \<open>OrdRing_ZF_1_L4A\<close> when one of the constants is $0$. This is useful for many proofs by cases.\<close> corollary (in ring1) ord_ring_split2: assumes A1: "a\<in>R" shows "a\<lsq>\<zero> \<or> (\<zero>\<lsq>a \<and> a\<noteq>\<zero>)" proof - { from A1 have I: "a\<in>R" "\<zero>\<in>R" using Ring_ZF_1_L2 by auto moreover assume A2: "\<not>(a\<lsq>\<zero>)" ultimately have "\<zero>\<lsq>a" by (rule OrdRing_ZF_1_L4A) moreover from I A2 have "a\<noteq>\<zero>" by (rule OrdRing_ZF_1_L4A) ultimately have "\<zero>\<lsq>a \<and> a\<noteq>\<zero>" by simp} then show ?thesis by auto qed text\<open>Taking minus on both sides reverses an inequality.\<close> lemma (in ring1) OrdRing_ZF_1_L4B: assumes "a\<lsq>b" shows "(\<rm>b) \<lsq> (\<rm>a)" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L5 by simp text\<open>The next lemma just expands the condition that requires the set of nonnegative elements to be closed with respect to multiplication. These are properties of totally ordered groups.\<close> lemma (in ring1) OrdRing_ZF_1_L5: assumes "\<zero>\<lsq>a" "\<zero>\<lsq>b" shows "\<zero> \<lsq> a\<cdot>b" using pos_mult_closed assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L2 IsOpClosed_def by simp text\<open>Double nonnegative is nonnegative.\<close> lemma (in ring1) OrdRing_ZF_1_L5A: assumes A1: "\<zero>\<lsq>a" shows "\<zero>\<lsq>\<two>\<cdot>a" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L5G OrdRing_ZF_1_L3 Ring_ZF_1_L3 by simp text\<open>A sufficient (somewhat redundant) condition for a structure to be an ordered ring. It says that a commutative ring that is a totally ordered group with respect to the additive operation such that set of nonnegative elements is closed under multiplication, is an ordered ring.\<close> lemma OrdRing_ZF_1_L6: assumes "IsAring(R,A,M)" "M {is commutative on} R" "Nonnegative(R,A,r) {is closed under} M" "IsAnOrdGroup(R,A,r)" "r {is total on} R" shows "IsAnOrdRing(R,A,M,r)" using assms IsAnOrdGroup_def Order_ZF_1_L3 IsAnOrdRing_def by simp text\<open> $a\leq b$ iff $a-b\leq 0$. This is a fact from \<open>OrderedGroup.thy\<close>, where it is stated in multiplicative notation.\<close> lemma (in ring1) OrdRing_ZF_1_L7: assumes "a\<in>R" "b\<in>R" shows "a\<lsq>b \<longleftrightarrow> a\<rs>b \<lsq> \<zero>" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L9 by simp text\<open>Negative times positive is negative.\<close> lemma (in ring1) OrdRing_ZF_1_L8: assumes A1: "a\<lsq>\<zero>" and A2: "\<zero>\<lsq>b" shows "a\<cdot>b \<lsq> \<zero>" proof - from A1 A2 have T1: "a\<in>R" "b\<in>R" "a\<cdot>b \<in> R" using OrdRing_ZF_1_L3 Ring_ZF_1_L4 by auto from A1 A2 have "\<zero>\<lsq>(\<rm>a)\<cdot>b" using OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L5A OrdRing_ZF_1_L5 by simp with T1 show "a\<cdot>b \<lsq> \<zero>" using Ring_ZF_1_L7 OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L5AA by simp qed text\<open>We can multiply both sides of an inequality by a nonnegative ring element. This property is sometimes (not here) used to define ordered rings.\<close> lemma (in ring1) OrdRing_ZF_1_L9: assumes A1: "a\<lsq>b" and A2: "\<zero>\<lsq>c" shows "a\<cdot>c \<lsq> b\<cdot>c" "c\<cdot>a \<lsq> c\<cdot>b" proof - from A1 A2 have T1: "a\<in>R" "b\<in>R" "c\<in>R" "a\<cdot>c \<in> R" "b\<cdot>c \<in> R" using OrdRing_ZF_1_L3 Ring_ZF_1_L4 by auto with A1 A2 have "(a\<rs>b)\<cdot>c \<lsq> \<zero>" using OrdRing_ZF_1_L7 OrdRing_ZF_1_L8 by simp with T1 show "a\<cdot>c \<lsq> b\<cdot>c" using Ring_ZF_1_L8 OrdRing_ZF_1_L7 by simp with mult_commut T1 show "c\<cdot>a \<lsq> c\<cdot>b" using IsCommutative_def by simp qed text\<open>A special case of \<open>OrdRing_ZF_1_L9\<close>: we can multiply an inequality by a positive ring element.\<close> lemma (in ring1) OrdRing_ZF_1_L9A: assumes A1: "a\<lsq>b" and A2: "c\<in>R\<^sub>+" shows "a\<cdot>c \<lsq> b\<cdot>c" "c\<cdot>a \<lsq> c\<cdot>b" proof - from A2 have "\<zero> \<lsq> c" using PositiveSet_def by simp with A1 show "a\<cdot>c \<lsq> b\<cdot>c" "c\<cdot>a \<lsq> c\<cdot>b" using OrdRing_ZF_1_L9 by auto qed text\<open>A square is nonnegative.\<close> lemma (in ring1) OrdRing_ZF_1_L10: assumes A1: "a\<in>R" shows "\<zero>\<lsq>(a\<^sup>2)" proof - { assume "\<zero>\<lsq>a" then have "\<zero>\<lsq>(a\<^sup>2)" using OrdRing_ZF_1_L5 by simp} moreover { assume "\<not>(\<zero>\<lsq>a)" with A1 have "\<zero>\<lsq>((\<rm>a)\<^sup>2)" using OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L8A OrdRing_ZF_1_L5 by simp with A1 have "\<zero>\<lsq>(a\<^sup>2)" using Ring_ZF_1_L14 by simp } ultimately show ?thesis by blast qed text\<open>$1$ is nonnegative.\<close> corollary (in ring1) ordring_one_is_nonneg: shows "\<zero> \<lsq> \<one>" proof - have "\<zero> \<lsq> (\<one>\<^sup>2)" using Ring_ZF_1_L2 OrdRing_ZF_1_L10 by simp then show "\<zero> \<lsq> \<one>" using Ring_ZF_1_L2 Ring_ZF_1_L3 by simp qed text\<open>In nontrivial rings one is positive.\<close> lemma (in ring1) ordring_one_is_pos: assumes "\<zero>\<noteq>\<one>" shows "\<one> \<in> R\<^sub>+" using assms Ring_ZF_1_L2 ordring_one_is_nonneg PositiveSet_def by auto text\<open>Nonnegative is not negative. Property of ordered groups.\<close> lemma (in ring1) OrdRing_ZF_1_L11: assumes "\<zero>\<lsq>a" shows "\<not>(a\<lsq>\<zero> \<and> a\<noteq>\<zero>)" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L5AB by simp text\<open>A negative element cannot be a square.\<close> lemma (in ring1) OrdRing_ZF_1_L12: assumes A1: "a\<lsq>\<zero>" "a\<noteq>\<zero>" shows "\<not>(\<exists>b\<in>R. a = (b\<^sup>2))" proof - { assume "\<exists>b\<in>R. a = (b\<^sup>2)" with A1 have False using OrdRing_ZF_1_L10 OrdRing_ZF_1_L11 by auto } then show ?thesis by auto qed text\<open>If $a\leq b$, then $0\leq b-a$.\<close> lemma (in ring1) OrdRing_ZF_1_L13: assumes "a\<lsq>b" shows "\<zero> \<lsq> b\<rs>a" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L9D by simp text\<open>If $a<b$, then $0 < b-a$.\<close> lemma (in ring1) OrdRing_ZF_1_L14: assumes "a\<lsq>b" "a\<noteq>b" shows "\<zero> \<lsq> b\<rs>a" "\<zero> \<noteq> b\<rs>a" "b\<rs>a \<in> R\<^sub>+" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L9E by auto text\<open>If the difference is nonnegative, then $a\leq b$.\<close> lemma (in ring1) OrdRing_ZF_1_L15: assumes "a\<in>R" "b\<in>R" and "\<zero> \<lsq> b\<rs>a" shows "a\<lsq>b" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L9F by simp text\<open>A nonnegative number is does not decrease when multiplied by a number greater or equal $1$.\<close> lemma (in ring1) OrdRing_ZF_1_L16: assumes A1: "\<zero>\<lsq>a" and A2: "\<one>\<lsq>b" shows "a\<lsq>a\<cdot>b" proof - from A1 A2 have T: "a\<in>R" "b\<in>R" "a\<cdot>b \<in> R" using OrdRing_ZF_1_L3 Ring_ZF_1_L4 by auto from A1 A2 have "\<zero> \<lsq> a\<cdot>(b\<rs>\<one>)" using OrdRing_ZF_1_L13 OrdRing_ZF_1_L5 by simp with T show "a\<lsq>a\<cdot>b" using Ring_ZF_1_L8 Ring_ZF_1_L2 Ring_ZF_1_L3 OrdRing_ZF_1_L15 by simp qed text\<open>We can multiply the right hand side of an inequality between nonnegative ring elements by an element greater or equal $1$.\<close> lemma (in ring1) OrdRing_ZF_1_L17: assumes A1: "\<zero>\<lsq>a" and A2: "a\<lsq>b" and A3: "\<one>\<lsq>c" shows "a\<lsq>b\<cdot>c" proof - from A1 A2 have "\<zero>\<lsq>b" by (rule ring_ord_transitive) with A3 have "b\<lsq>b\<cdot>c" using OrdRing_ZF_1_L16 by simp with A2 show "a\<lsq>b\<cdot>c" by (rule ring_ord_transitive) qed text\<open>Strict order is preserved by translations.\<close> lemma (in ring1) ring_strict_ord_trans_inv: assumes "a\<ls>b" and "c\<in>R" shows "a\<ra>c \<ls> b\<ra>c" "c\<ra>a \<ls> c\<ra>b" using assms OrdRing_ZF_1_L4 group3.group_strict_ord_transl_inv by auto text\<open>We can put an element on the other side of a strict inequality, changing its sign.\<close> lemma (in ring1) OrdRing_ZF_1_L18: assumes "a\<in>R" "b\<in>R" and "a\<rs>b \<ls> c" shows "a \<ls> c\<ra>b" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L12B by simp text\<open>We can add the sides of two inequalities, the first of them strict, and we get a strict inequality. Property of ordered groups.\<close> lemma (in ring1) OrdRing_ZF_1_L19: assumes "a\<ls>b" and "c\<lsq>d" shows "a\<ra>c \<ls> b\<ra>d" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L12C by simp text\<open>We can add the sides of two inequalities, the second of them strict and we get a strict inequality. Property of ordered groups.\<close> lemma (in ring1) OrdRing_ZF_1_L20: assumes "a\<lsq>b" and "c\<ls>d" shows "a\<ra>c \<ls> b\<ra>d" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L12D by simp subsection\<open>Absolute value for ordered rings\<close> text\<open>Absolute value is defined for ordered groups as a function that is the identity on the nonnegative set and the negative of the element (the inverse in the multiplicative notation) on the rest. In this section we consider properties of absolute value related to multiplication in ordered rings.\<close> text\<open>Absolute value of a product is the product of absolute values: the case when both elements of the ring are nonnegative.\<close> lemma (in ring1) OrdRing_ZF_2_L1: assumes "\<zero>\<lsq>a" "\<zero>\<lsq>b" shows "|a\<cdot>b| = |a|\<cdot>|b|" using assms OrdRing_ZF_1_L5 OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L2 group3.OrderedGroup_ZF_3_L2 by simp text\<open>The absolue value of an element and its negative are the same.\<close> lemma (in ring1) OrdRing_ZF_2_L2: assumes "a\<in>R" shows "|\<rm>a| = |a|" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_3_L7A by simp text\<open>The next lemma states that $|a\cdot (-b)| = |(-a)\cdot b| = |(-a)\cdot (-b)| = |a\cdot b|$.\<close> lemma (in ring1) OrdRing_ZF_2_L3: assumes "a\<in>R" "b\<in>R" shows "|(\<rm>a)\<cdot>b| = |a\<cdot>b|" "|a\<cdot>(\<rm>b)| = |a\<cdot>b|" "|(\<rm>a)\<cdot>(\<rm>b)| = |a\<cdot>b|" using assms Ring_ZF_1_L4 Ring_ZF_1_L7 Ring_ZF_1_L7A OrdRing_ZF_2_L2 by auto text\<open>This lemma allows to prove theorems for the case of positive and negative elements of the ring separately.\<close> lemma (in ring1) OrdRing_ZF_2_L4: assumes "a\<in>R" and "\<not>(\<zero>\<lsq>a)" shows "\<zero> \<lsq> (\<rm>a)" "\<zero>\<noteq>a" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L8A by auto text\<open>Absolute value of a product is the product of absolute values.\<close> lemma (in ring1) OrdRing_ZF_2_L5: assumes A1: "a\<in>R" "b\<in>R" shows "|a\<cdot>b| = |a|\<cdot>|b|" proof - { assume A2: "\<zero>\<lsq>a" have "|a\<cdot>b| = |a|\<cdot>|b|" proof - { assume "\<zero>\<lsq>b" with A2 have "|a\<cdot>b| = |a|\<cdot>|b|" using OrdRing_ZF_2_L1 by simp } moreover { assume "\<not>(\<zero>\<lsq>b)" with A1 A2 have "|a\<cdot>(\<rm>b)| = |a|\<cdot>|\<rm>b|" using OrdRing_ZF_2_L4 OrdRing_ZF_2_L1 by simp with A1 have "|a\<cdot>b| = |a|\<cdot>|b|" using OrdRing_ZF_2_L2 OrdRing_ZF_2_L3 by simp } ultimately show ?thesis by blast qed } moreover { assume "\<not>(\<zero>\<lsq>a)" with A1 have A3: "\<zero> \<lsq> (\<rm>a)" using OrdRing_ZF_2_L4 by simp have "|a\<cdot>b| = |a|\<cdot>|b|" proof - { assume "\<zero>\<lsq>b" with A3 have "|(\<rm>a)\<cdot>b| = |\<rm>a|\<cdot>|b|" using OrdRing_ZF_2_L1 by simp with A1 have "|a\<cdot>b| = |a|\<cdot>|b|" using OrdRing_ZF_2_L2 OrdRing_ZF_2_L3 by simp } moreover { assume "\<not>(\<zero>\<lsq>b)" with A1 A3 have "|(\<rm>a)\<cdot>(\<rm>b)| = |\<rm>a|\<cdot>|\<rm>b|" using OrdRing_ZF_2_L4 OrdRing_ZF_2_L1 by simp with A1 have "|a\<cdot>b| = |a|\<cdot>|b|" using OrdRing_ZF_2_L2 OrdRing_ZF_2_L3 by simp } ultimately show ?thesis by blast qed } ultimately show ?thesis by blast qed text\<open>Triangle inequality. Property of linearly ordered abelian groups.\<close> lemma (in ring1) ord_ring_triangle_ineq: assumes "a\<in>R" "b\<in>R" shows "|a\<ra>b| \<lsq> |a|\<ra>|b|" using assms OrdRing_ZF_1_L4 group3.OrdGroup_triangle_ineq by simp text\<open>If $a\leq c$ and $b\leq c$, then $a+b\leq 2\cdot c$.\<close> lemma (in ring1) OrdRing_ZF_2_L6: assumes "a\<lsq>c" "b\<lsq>c" shows "a\<ra>b \<lsq> \<two>\<cdot>c" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L5B OrdRing_ZF_1_L3 Ring_ZF_1_L3 by simp subsection\<open>Positivity in ordered rings\<close> text\<open>This section is about properties of the set of positive elements \<open>R\<^sub>+\<close>.\<close> text\<open>The set of positive elements is closed under ring addition. This is a property of ordered groups, we just reference a theorem from \<open>OrderedGroup_ZF\<close> theory in the proof.\<close> lemma (in ring1) OrdRing_ZF_3_L1: shows "R\<^sub>+ {is closed under} A" using OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L13 by simp text\<open>Every element of a ring can be either in the postitive set, equal to zero or its opposite (the additive inverse) is in the positive set. This is a property of ordered groups, we just reference a theorem from \<open>OrderedGroup_ZF\<close> theory.\<close> lemma (in ring1) OrdRing_ZF_3_L2: assumes "a\<in>R" shows "Exactly_1_of_3_holds (a=\<zero>, a\<in>R\<^sub>+, (\<rm>a) \<in> R\<^sub>+)" using assms OrdRing_ZF_1_L4 group3.OrdGroup_decomp by simp text\<open>If a ring element $a\neq 0$, and it is not positive, then $-a$ is positive.\<close> lemma (in ring1) OrdRing_ZF_3_L2A: assumes "a\<in>R" "a\<noteq>\<zero>" "a \<notin> R\<^sub>+" shows "(\<rm>a) \<in> R\<^sub>+" using assms OrdRing_ZF_1_L4 group3.OrdGroup_cases by simp text\<open>\<open>R\<^sub>+\<close> is closed under multiplication iff the ring has no zero divisors.\<close> lemma (in ring1) OrdRing_ZF_3_L3: shows "(R\<^sub>+ {is closed under} M)\<longleftrightarrow> HasNoZeroDivs(R,A,M)" proof assume A1: "HasNoZeroDivs(R,A,M)" { fix a b assume "a\<in>R\<^sub>+" "b\<in>R\<^sub>+" then have "\<zero>\<lsq>a" "a\<noteq>\<zero>" "\<zero>\<lsq>b" "b\<noteq>\<zero>" using PositiveSet_def by auto with A1 have "a\<cdot>b \<in> R\<^sub>+" using OrdRing_ZF_1_L5 Ring_ZF_1_L2 OrdRing_ZF_1_L3 Ring_ZF_1_L12 OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L2A by simp } then show "R\<^sub>+ {is closed under} M" using IsOpClosed_def by simp next assume A2: "R\<^sub>+ {is closed under} M" { fix a b assume A3: "a\<in>R" "b\<in>R" and "a\<noteq>\<zero>" "b\<noteq>\<zero>" with A2 have "|a\<cdot>b| \<in> R\<^sub>+" using OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_3_L12 IsOpClosed_def OrdRing_ZF_2_L5 by simp with A3 have "a\<cdot>b \<noteq> \<zero>" using PositiveSet_def Ring_ZF_1_L4 OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_3_L2A by auto } then show "HasNoZeroDivs(R,A,M)" using HasNoZeroDivs_def by auto qed text\<open>Another (in addition to \<open>OrdRing_ZF_1_L6\<close> sufficient condition that defines order in an ordered ring starting from the positive set.\<close> theorem (in ring0) ring_ord_by_positive_set: assumes A1: "M {is commutative on} R" and A2: "P\<subseteq>R" "P {is closed under} A" "\<zero> \<notin> P" and A3: "\<forall>a\<in>R. a\<noteq>\<zero> \<longrightarrow> (a\<in>P) Xor ((\<rm>a) \<in> P)" and A4: "P {is closed under} M" and A5: "r = OrderFromPosSet(R,A,P)" shows "IsAnOrdGroup(R,A,r)" "IsAnOrdRing(R,A,M,r)" "r {is total on} R" "PositiveSet(R,A,r) = P" "Nonnegative(R,A,r) = P \<union> {\<zero>}" "HasNoZeroDivs(R,A,M)" proof - from A2 A3 A5 show I: "IsAnOrdGroup(R,A,r)" "r {is total on} R" and II: "PositiveSet(R,A,r) = P" and III: "Nonnegative(R,A,r) = P \<union> {\<zero>}" using Ring_ZF_1_L1 group0.Group_ord_by_positive_set by auto from A2 A4 III have "Nonnegative(R,A,r) {is closed under} M" using Ring_ZF_1_L16 by simp with ringAssum A1 I show "IsAnOrdRing(R,A,M,r)" using OrdRing_ZF_1_L6 by simp with A4 II show "HasNoZeroDivs(R,A,M)" using OrdRing_ZF_1_L2 ring1.OrdRing_ZF_3_L3 by auto qed text\<open>Nontrivial ordered rings are infinite. More precisely we assume that the neutral element of the additive operation is not equal to the multiplicative neutral element and show that the the set of positive elements of the ring is not a finite subset of the ring and the ring is not a finite subset of itself.\<close> theorem (in ring1) ord_ring_infinite: assumes "\<zero>\<noteq>\<one>" shows "R\<^sub>+ \<notin> Fin(R)" "R \<notin> Fin(R)" using assms Ring_ZF_1_L17 OrdRing_ZF_1_L4 group3.Linord_group_infinite by auto text\<open>If every element of a nontrivial ordered ring can be dominated by an element from $B$, then we $B$ is not bounded and not finite.\<close> lemma (in ring1) OrdRing_ZF_3_L4: assumes "\<zero>\<noteq>\<one>" and "\<forall>a\<in>R. \<exists>b\<in>B. a\<lsq>b" shows "\<not>IsBoundedAbove(B,r)" "B \<notin> Fin(R)" using assms Ring_ZF_1_L17 OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_2_L2A by auto text\<open>If $m$ is greater or equal the multiplicative unit, then the set $\{m\cdot n: n\in R\}$ is infinite (unless the ring is trivial).\<close> lemma (in ring1) OrdRing_ZF_3_L5: assumes A1: "\<zero>\<noteq>\<one>" and A2: "\<one>\<lsq>m" shows "{m\<cdot>x. x\<in>R\<^sub>+} \<notin> Fin(R)" "{m\<cdot>x. x\<in>R} \<notin> Fin(R)" "{(\<rm>m)\<cdot>x. x\<in>R} \<notin> Fin(R)" proof - from A2 have T: "m\<in>R" using OrdRing_ZF_1_L3 by simp from A2 have "\<zero>\<lsq>\<one>" "\<one>\<lsq>m" using ordring_one_is_nonneg by auto then have I: "\<zero>\<lsq>m" by (rule ring_ord_transitive) let ?B = "{m\<cdot>x. x\<in>R\<^sub>+}" { fix a assume A3: "a\<in>R" then have "a\<lsq>\<zero> \<or> (\<zero>\<lsq>a \<and> a\<noteq>\<zero>)" using ord_ring_split2 by simp moreover { assume A4: "a\<lsq>\<zero>" from A1 have "m\<cdot>\<one> \<in> ?B" using ordring_one_is_pos by auto with T have "m\<in>?B" using Ring_ZF_1_L3 by simp moreover from A4 I have "a\<lsq>m" by (rule ring_ord_transitive) ultimately have "\<exists>b\<in>?B. a\<lsq>b" by blast } moreover { assume A4: "\<zero>\<lsq>a \<and> a\<noteq>\<zero>" with A3 have "m\<cdot>a \<in> ?B" using PositiveSet_def by auto moreover from A2 A4 have "\<one>\<cdot>a \<lsq> m\<cdot>a" using OrdRing_ZF_1_L9 by simp with A3 have "a \<lsq> m\<cdot>a" using Ring_ZF_1_L3 by simp ultimately have "\<exists>b\<in>?B. a\<lsq>b" by auto } ultimately have "\<exists>b\<in>?B. a\<lsq>b" by auto } then have "\<forall>a\<in>R. \<exists>b\<in>?B. a\<lsq>b" by simp with A1 show "?B \<notin> Fin(R)" using OrdRing_ZF_3_L4 by simp moreover have "?B \<subseteq> {m\<cdot>x. x\<in>R}" using PositiveSet_def by auto ultimately show "{m\<cdot>x. x\<in>R} \<notin> Fin(R)" using Fin_subset by auto with T show "{(\<rm>m)\<cdot>x. x\<in>R} \<notin> Fin(R)" using Ring_ZF_1_L18 by simp qed text\<open>If $m$ is less or equal than the negative of multiplicative unit, then the set $\{m\cdot n: n\in R\}$ is infinite (unless the ring is trivial).\<close> lemma (in ring1) OrdRing_ZF_3_L6: assumes A1: "\<zero>\<noteq>\<one>" and A2: "m \<lsq> \<rm>\<one>" shows "{m\<cdot>x. x\<in>R} \<notin> Fin(R)" proof - from A2 have "(\<rm>(\<rm>\<one>)) \<lsq> \<rm>m" using OrdRing_ZF_1_L4B by simp with A1 have "{(\<rm>m)\<cdot>x. x\<in>R} \<notin> Fin(R)" using Ring_ZF_1_L2 Ring_ZF_1_L3 OrdRing_ZF_3_L5 by simp with A2 show "{m\<cdot>x. x\<in>R} \<notin> Fin(R)" using OrdRing_ZF_1_L3 Ring_ZF_1_L18 by simp qed text\<open>All elements greater or equal than an element of \<open>R\<^sub>+\<close> belong to \<open>R\<^sub>+\<close>. Property of ordered groups.\<close> lemma (in ring1) OrdRing_ZF_3_L7: assumes A1: "a \<in> R\<^sub>+" and A2: "a\<lsq>b" shows "b \<in> R\<^sub>+" proof - from A1 A2 have "group3(R,A,r)" "a \<in> PositiveSet(R,A,r)" "\<langle>a,b\<rangle> \<in> r" using OrdRing_ZF_1_L4 by auto then have "b \<in> PositiveSet(R,A,r)" by (rule group3.OrderedGroup_ZF_1_L19) then show "b \<in> R\<^sub>+" by simp qed text\<open>A special case of \<open>OrdRing_ZF_3_L7\<close>: a ring element greater or equal than $1$ is positive.\<close> corollary (in ring1) OrdRing_ZF_3_L8: assumes A1: "\<zero>\<noteq>\<one>" and A2: "\<one>\<lsq>a" shows "a \<in> R\<^sub>+" proof - from A1 A2 have "\<one> \<in> R\<^sub>+" "\<one>\<lsq>a" using ordring_one_is_pos by auto then show "a \<in> R\<^sub>+" by (rule OrdRing_ZF_3_L7) qed text\<open>Adding a positive element to $a$ strictly increases $a$. Property of ordered groups.\<close> lemma (in ring1) OrdRing_ZF_3_L9: assumes A1: "a\<in>R" "b\<in>R\<^sub>+" shows "a \<lsq> a\<ra>b" "a \<noteq> a\<ra>b" using assms OrdRing_ZF_1_L4 group3.OrderedGroup_ZF_1_L22 by auto text\<open>A special case of \<open> OrdRing_ZF_3_L9\<close>: in nontrivial rings adding one to $a$ increases $a$.\<close> corollary (in ring1) OrdRing_ZF_3_L10: assumes A1: "\<zero>\<noteq>\<one>" and A2: "a\<in>R" shows "a \<lsq> a\<ra>\<one>" "a \<noteq> a\<ra>\<one>" using assms ordring_one_is_pos OrdRing_ZF_3_L9 by auto text\<open>If $a$ is not greater than $b$, then it is strictly less than $b+1$.\<close> lemma (in ring1) OrdRing_ZF_3_L11: assumes A1: "\<zero>\<noteq>\<one>" and A2: "a\<lsq>b" shows "a\<ls> b\<ra>\<one>" proof - from A1 A2 have I: "b \<ls> b\<ra>\<one>" using OrdRing_ZF_1_L3 OrdRing_ZF_3_L10 by auto with A2 show "a\<ls> b\<ra>\<one>" by (rule ring_strict_ord_transit) qed text\<open>For any ring element $a$ the greater of $a$ and $1$ is a positive element that is greater or equal than $m$. If we add $1$ to it we get a positive element that is strictly greater than $m$. This holds in nontrivial rings.\<close> lemma (in ring1) OrdRing_ZF_3_L12: assumes A1: "\<zero>\<noteq>\<one>" and A2: "a\<in>R" shows "a \<lsq> GreaterOf(r,\<one>,a)" "GreaterOf(r,\<one>,a) \<in> R\<^sub>+" "GreaterOf(r,\<one>,a) \<ra> \<one> \<in> R\<^sub>+" "a \<lsq> GreaterOf(r,\<one>,a) \<ra> \<one>" "a \<noteq> GreaterOf(r,\<one>,a) \<ra> \<one>" proof - from linord have "r {is total on} R" using IsLinOrder_def by simp moreover from A2 have "\<one> \<in> R" "a\<in>R" using Ring_ZF_1_L2 by auto ultimately have "\<one> \<lsq> GreaterOf(r,\<one>,a)" and I: "a \<lsq> GreaterOf(r,\<one>,a)" using Order_ZF_3_L2 by auto with A1 show "a \<lsq> GreaterOf(r,\<one>,a)" and "GreaterOf(r,\<one>,a) \<in> R\<^sub>+" using OrdRing_ZF_3_L8 by auto with A1 show "GreaterOf(r,\<one>,a) \<ra> \<one> \<in> R\<^sub>+" using ordring_one_is_pos OrdRing_ZF_3_L1 IsOpClosed_def by simp from A1 I show "a \<lsq> GreaterOf(r,\<one>,a) \<ra> \<one>" "a \<noteq> GreaterOf(r,\<one>,a) \<ra> \<one>" using OrdRing_ZF_3_L11 by auto qed text\<open>We can multiply strict inequality by a positive element.\<close> lemma (in ring1) OrdRing_ZF_3_L13: assumes A1: "HasNoZeroDivs(R,A,M)" and A2: "a\<ls>b" and A3: "c\<in>R\<^sub>+" shows "a\<cdot>c \<ls> b\<cdot>c" "c\<cdot>a \<ls> c\<cdot>b" proof - from A2 A3 have T: "a\<in>R" "b\<in>R" "c\<in>R" "c\<noteq>\<zero>" using OrdRing_ZF_1_L3 PositiveSet_def by auto from A2 A3 have "a\<cdot>c \<lsq> b\<cdot>c" using OrdRing_ZF_1_L9A by simp moreover from A1 A2 T have "a\<cdot>c \<noteq> b\<cdot>c" using Ring_ZF_1_L12A by auto ultimately show "a\<cdot>c \<ls> b\<cdot>c" by simp moreover from mult_commut T have "a\<cdot>c = c\<cdot>a" and "b\<cdot>c = c\<cdot>b" using IsCommutative_def by auto ultimately show "c\<cdot>a \<ls> c\<cdot>b" by simp qed text\<open>A sufficient condition for an element to be in the set of positive ring elements.\<close> lemma (in ring1) OrdRing_ZF_3_L14: assumes "\<zero>\<lsq>a" and "a\<noteq>\<zero>" shows "a \<in> R\<^sub>+" using assms OrdRing_ZF_1_L3 PositiveSet_def by auto text\<open>If a ring has no zero divisors, the square of a nonzero element is positive.\<close> lemma (in ring1) OrdRing_ZF_3_L15: assumes "HasNoZeroDivs(R,A,M)" and "a\<in>R" "a\<noteq>\<zero>" shows "\<zero> \<lsq> a\<^sup>2" "a\<^sup>2 \<noteq> \<zero>" "a\<^sup>2 \<in> R\<^sub>+" using assms OrdRing_ZF_1_L10 Ring_ZF_1_L12 OrdRing_ZF_3_L14 by auto text\<open>In rings with no zero divisors we can (strictly) increase a positive element by multiplying it by an element that is greater than $1$.\<close> lemma (in ring1) OrdRing_ZF_3_L16: assumes "HasNoZeroDivs(R,A,M)" and "a \<in> R\<^sub>+" and "\<one>\<lsq>b" "\<one>\<noteq>b" shows "a\<lsq>a\<cdot>b" "a \<noteq> a\<cdot>b" using assms PositiveSet_def OrdRing_ZF_1_L16 OrdRing_ZF_1_L3 Ring_ZF_1_L12C by auto text\<open>If the right hand side of an inequality is positive we can multiply it by a number that is greater than one.\<close> lemma (in ring1) OrdRing_ZF_3_L17: assumes A1: "HasNoZeroDivs(R,A,M)" and A2: "b\<in>R\<^sub>+" and A3: "a\<lsq>b" and A4: "\<one>\<ls>c" shows "a\<ls>b\<cdot>c" proof - from A1 A2 A4 have "b \<ls> b\<cdot>c" using OrdRing_ZF_3_L16 by auto with A3 show "a\<ls>b\<cdot>c" by (rule ring_strict_ord_transit) qed text\<open>We can multiply a right hand side of an inequality between positive numbers by a number that is greater than one.\<close> lemma (in ring1) OrdRing_ZF_3_L18: assumes A1: "HasNoZeroDivs(R,A,M)" and A2: "a \<in> R\<^sub>+" and A3: "a\<lsq>b" and A4: "\<one>\<ls>c" shows "a\<ls>b\<cdot>c" proof - from A2 A3 have "b \<in> R\<^sub>+" using OrdRing_ZF_3_L7 by blast with A1 A3 A4 show "a\<ls>b\<cdot>c" using OrdRing_ZF_3_L17 by simp qed text\<open>In ordered rings with no zero divisors if at least one of $a,b$ is not zero, then $0 < a^2+b^2$, in particular $a^2+b^2\neq 0$.\<close> lemma (in ring1) OrdRing_ZF_3_L19: assumes A1: "HasNoZeroDivs(R,A,M)" and A2: "a\<in>R" "b\<in>R" and A3: "a \<noteq> \<zero> \<or> b \<noteq> \<zero>" shows "\<zero> \<ls> a\<^sup>2 \<ra> b\<^sup>2" proof - { assume "a \<noteq> \<zero>" with A1 A2 have "\<zero> \<lsq> a\<^sup>2" "a\<^sup>2 \<noteq> \<zero>" using OrdRing_ZF_3_L15 by auto then have "\<zero> \<ls> a\<^sup>2" by auto moreover from A2 have "\<zero> \<lsq> b\<^sup>2" using OrdRing_ZF_1_L10 by simp ultimately have "\<zero> \<ra> \<zero> \<ls> a\<^sup>2 \<ra> b\<^sup>2" using OrdRing_ZF_1_L19 by simp then have "\<zero> \<ls> a\<^sup>2 \<ra> b\<^sup>2" using Ring_ZF_1_L2 Ring_ZF_1_L3 by simp } moreover { assume A4: "a = \<zero>" then have "a\<^sup>2 \<ra> b\<^sup>2 = \<zero> \<ra> b\<^sup>2" using Ring_ZF_1_L2 Ring_ZF_1_L6 by simp also from A2 have "\<dots> = b\<^sup>2" using Ring_ZF_1_L4 Ring_ZF_1_L3 by simp finally have "a\<^sup>2 \<ra> b\<^sup>2 = b\<^sup>2" by simp moreover from A3 A4 have "b \<noteq> \<zero>" by simp with A1 A2 have "\<zero> \<lsq> b\<^sup>2" and "b\<^sup>2 \<noteq> \<zero>" using OrdRing_ZF_3_L15 by auto hence "\<zero> \<ls> b\<^sup>2" by auto ultimately have "\<zero> \<ls> a\<^sup>2 \<ra> b\<^sup>2" by simp } ultimately show "\<zero> \<ls> a\<^sup>2 \<ra> b\<^sup>2" by auto qed end
When you arrive at your Walt Disney World resort, you can leave your carry-on bags with Bell Services; we do this all the time! We often arrive from the cold, wintry North, so we leave our winter coats, long pants (hats, gloves, etc.) along with our carry-on items at Bell Services. They'll be happy to give you claim ticket, with the number of items left with them, and you are free to roam the parks without the extra baggage. Upon your return, simply head to Bell Services, hand them your claim ticket and they'll be happy to help bring your belongings to your room. Have a wonderful trip! Be sure to send any additional questions as you think of them! We love to help!
The polynomial $1$ is equal to the constant polynomial $1$.
Dating back to the late 1700‘s, this may be the oldest western stagecoach stop still in existence in the USA. Today it offers five guest rooms, all named after the notable figures to have stayed at the tavern (which has gone by several different names during its history, including the Old Stone Tavern). Located at the heart of bourbon whisky country, both Louisville and Lexington are within reasonable driving distance of the hotel. Among the famous guests who have stayed here were the young Abraham Lincoln, Andrew Jackson, William Henry Harrison, Daniel Boone, General George S. Patton, Washington Irving, and exiled French King Louis Phillipe in 1797. Jesse James is also reputed to have partaken of too much liquor while here. Unsurprisingly, the Old Talbott Tavern is also reputed to be haunted.
State Before: α : Type u_1 inst✝¹ : OrderedSemiring α inst✝ : Nontrivial α x : ↑(Ico 0 1) ⊢ ↑x = 0 ↔ x = 0 State After: α : Type u_1 inst✝¹ : OrderedSemiring α inst✝ : Nontrivial α x : ↑(Ico 0 1) ⊢ x = 0 ↔ ↑x = 0 Tactic: symm State Before: α : Type u_1 inst✝¹ : OrderedSemiring α inst✝ : Nontrivial α x : ↑(Ico 0 1) ⊢ x = 0 ↔ ↑x = 0 State After: no goals Tactic: exact Subtype.ext_iff
lemma contour_integral_trivial [simp]: "contour_integral (linepath a a) f = 0"
/- Copyright (c) 2020 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker, Bryan Gin-ge Chen -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.nat.prime import Mathlib.data.int.basic import Mathlib.PostPort namespace Mathlib /-! # Lemmas about nat.prime using `int`s -/ namespace int theorem not_prime_of_int_mul {a : ℤ} {b : ℤ} {c : ℕ} (ha : 1 < nat_abs a) (hb : 1 < nat_abs b) (hc : a * b = ↑c) : ¬nat.prime c := nat.not_prime_mul' (nat_abs_mul_nat_abs_eq hc) ha hb end Mathlib
Section Soundness. Load "PTS_spec". Notation typ2 := (typ the_PTS) (only parsing). Notation wf_type2 := (wf_type the_PTS) (only parsing). Section SoundnessDef. Variable R : red_rule. Definition rule_sound := forall (e : env) (x y : term), R e x y -> forall T : term, typ the_PTS e x T -> typ the_PTS e y T. End SoundnessDef. Section Sound_context. Variable the_rule : Basic_rule. Let R := Rule the_rule. Let Rlifts : R_lift R := R_lifts the_rule. Hint Resolve Rlifts: pts. Hypothesis incl_R_le_type : forall (e : env) (x y : term), ctxt R e x y -> le_type e y x. Theorem red_incl_le_type : forall (e : env) (x y : term), red R e x y -> le_type e y x. simple induction 1; intros; auto with pts. apply le_type_trans with y0; auto with pts. Qed. Theorem red_in_env : forall (e : env) (u v t T : term), typ the_PTS (Ax u :: e) t T -> forall s : sort, typ the_PTS e v (Srt s) -> red R e u v -> typ the_PTS (Ax v :: e) t T. intros. apply subtype_in_env with (1 := H). constructor. constructor. red in |- *. auto with pts. apply red_incl_le_type. trivial with pts. apply wf_var with s; trivial with pts. Qed. Theorem ctxt_sound : rule_sound R -> rule_sound (ctxt R). red in |- *. simple induction 2; auto with pts; intros. Inversion_typ H3. apply typ_conv_wf with (Prod M U); auto with pts. apply type_conv with (Prod M' U) s; auto with pts. Inversion_typ H5. apply type_abs with s3; auto with pts. apply type_prod with s1 s2; auto with pts. apply red_in_env with M s1; auto with pts. apply red_in_env with M s1; auto with pts. apply incl_R_le_type. auto with pts. apply type_correctness with (Abs M N); auto with pts. Inversion_typ H3. apply typ_conv_wf with (Prod N U); auto with pts. apply type_abs with s; auto with pts. apply type_correctness with (Abs N M); auto with pts. Inversion_typ H3. apply typ_conv_wf with (subst M2 Ur); auto with pts. apply type_app with V; auto with pts. apply type_correctness with (App M1 M2); auto with pts. Inversion_typ H3. apply typ_conv_wf with (subst M2 Ur); auto with pts. cut (wf_type the_PTS e0 (Prod V Ur)); intros. inversion_clear H7. Inversion_typ H8. apply type_conv with (subst N2 Ur) s2; auto with pts. apply type_app with V; auto with pts. apply red_incl_le_type. unfold subst in |- *. apply red_subst_l with e0; auto with pts. replace (Srt s2) with (subst M2 (Srt s2)); auto with pts. apply substitution with V; auto with pts. apply type_correctness with M1; auto with pts. apply type_correctness with (App M1 M2); auto with pts. Inversion_typ H3. apply typ_conv_wf with (Srt s3); auto with pts. apply type_prod with s1 s2; auto with pts. apply red_in_env with M1 s1; auto with pts. apply type_correctness with (Prod M1 M2); auto with pts. Inversion_typ H3. apply typ_conv_wf with (Srt s3); auto with pts. apply type_prod with s1 s2; auto with pts. apply type_correctness with (Prod M1 M2); auto with pts. Qed. End Sound_context. Theorem incl_sound : forall P Q : red_rule, (forall (e : env) (x y : term), P e x y -> Q e x y) -> rule_sound Q -> rule_sound P. unfold rule_sound in |- *. intros. apply H0 with x; auto with pts. Qed. Theorem union_sound : forall P Q : red_rule, rule_sound P -> rule_sound Q -> rule_sound (reunion P Q). red in |- *. simple induction 3; intros. apply H with x; auto with pts. apply H0 with x; auto with pts. Qed. Theorem clos_trans_sound : forall P : red_rule, rule_sound P -> rule_sound (fun e : env => clos_trans term (P e)). red in |- *. simple induction 2; intros; auto with pts. apply H with x0; auto with pts. Qed. Theorem clos_refl_trans_sound : forall P : red_rule, rule_sound P -> rule_sound (R_rt P). red in |- *. simple induction 2; intros; auto with pts. apply H with x0; auto with pts. Qed. End Soundness.
C02AJJ Example Program Results Roots of quadratic equation z = 2.0000E+00 z = -5.0000E+00
\section{Interpretation of QM} \subsection{Supporting definitions} To provide our interpretation of quantum mechanics we need to develop a number of supporting definitions. As the reader familiar with process algebraic systems can readily verify, these definitions make \emph{essential} use of the reflective operations and as such identify this calculus as uniquely suited to this particular task. Among these operations we find a notion of \emph{multiplication} of names that interacts well with a notion of \emph{tensor product} of processes. Even more intriguingly, we find a notion of a \emph{dual} to a process in the form of maps from processes to names. While notions of composite names have been investigated in the process algebraic literature, it is the fact that names reflect process structure that enables the collection of duals to enjoy an algebraic structure dual to the collection of processes (i.e. there are operations available to duals that reflect the operations on processes). Moreover, it is this structure that enables an effective definition of inner product. \subsubsection{Multiplication} \begin{mathpar} \quotep{Q} \cdot \quotep{R} := \quotep{Q|R} \and \\ \quotep{Q} \cdot P := P\{ \quotep{Q|R} / \quotep{R} : \quotep{R} \in \freenames{P} \} \end{mathpar} \paragraph{Discussion} The first equation needs little explanation; the second says that each free name of the process is replaced with the multiplication of that name by the scalar. Multiplication of a scalar (name) by a state (process) results in a process all the names of which have been `moved over' by parallel composition with the process the scalar quotes. There is a subtlety that the bound names have to be manipulated so that multiplied names aren't accidentally captured. There are many ways to achieve this. \begin{remark}\label{rem:multiplication_identities} The reader is invited to verify that for all $x,y,z \in \QProc$ and $P \in \Proc$ \begin{mathpar} x \cdot \quotep{0} \equiv x \and x \cdot y \equiv y \cdot x \and x \cdot (y \cdot z) \equiv (x \cdot y) \cdot z \and \\ \quotep{0} \cdot P \equiv P \and \\ x \cdot (y \cdot P) \equiv (x \cdot y) \cdot P \and \\ x \cdot (P|Q) \equiv (x \cdot P) | (x \cdot Q) \and \\ \end{mathpar} \end{remark} \subsubsection{Tensor product} We define a tensor product on processes by structural induction. \paragraph{Tensor of sums} First note that all summations, including $\pzero$ and sequence, can be written $\Sigma_{i} x_{i}.A_{i} + \Sigma_{j} x_{j}.C_{j}$, where we have grouped input-guarded processes together and output-guarded processes together. Thus, we can define the tensor product of two summations, $N_{1}\otimes N_{2}$, where \begin{mathpar} N_{1} := \Sigma_{i} x_{i}.A_{i} + \Sigma_{j} x_{j}.C_{j} \and N_{2} := \Sigma_{i'} y_{i'}.B_{i'} + \Sigma_{j'} y_{j'}.D_{j'} \end{mathpar} as follows. \begin{mathpar} \Sigma_{i} x_{i}.A_{i} + \Sigma_{j} x_{j}.C_{j} \otimes \Sigma_{i'} y_{i'}.B_{i'} + \Sigma_{j'} y_{j'}.D_{j'} \and \\ := \; \Sigma_{i} \Sigma_{i'} \quotep{\stackrel{\vee}{x_{i}}| \stackrel{\vee}{y_{i'}}}.(A_{i}\otimes B_{i'}) \; | \; \Sigma_{i'} \Sigma_{i} \quotep{\stackrel{\vee}{y_{i'}}|\stackrel{\vee}{x_{i}}}.(B_{i'}\otimes A_{i}) \and \;\; | \;\; \Sigma_{j} \Sigma_{j'} \quotep{\stackrel{\vee}{x_{j}}|\stackrel{\vee}{y_{j'}}}.(A_{j}\otimes B_{j'}) \; | \; \Sigma_{j'} \Sigma_{j} \quotep{\stackrel{\vee}{y_{j'}}|\stackrel{\vee}{x_{j}}}.(B_{j'}\otimes A_{j}) \end{mathpar} \begin{remark} Do we need to $x^{L}$ and $y^{R}$ for this construction as well? \end{remark} \paragraph{Tensor of parallel compositions} Next, we distribute tensor over par. \begin{mathpar} P_{1}|P_{2} \otimes Q_{1}|Q_{2} := (P_{1} \otimes Q_{1}) | (P_{1} \otimes Q_{2}) | (P_{2} \otimes Q_{1}) | (P_{2} \otimes Q_{2}) \end{mathpar} \paragraph{Tensor with dropped names} We treat tensor of a process with a dropped name as parallel composition. \begin{mathpar} P \otimes \dropn{x} := P | \dropn{x} \end{mathpar} \paragraph{Tensor of agents} Finally, we need to define tensor on agents. Note that the definition of tensor on summations only tensors inputs with inputs and outputs with outputs. Thus, we only have to define the operation on ``homogeneous'' pairings. \begin{mathpar} (\vec{x})P \otimes (\vec{y})Q \and \\ := (x_{0}^{L}|y_{0}^{R},\ldots,x_{0}^{L}|y_{n}^{R},\ldots,x_{m}^{L}|y_{0}^{R},\ldots,x_{m}^{L}|y_{n}^R)(P\{ \vec{x}^{L}/\vec{x}\} \otimes Q \{ \vec{y}^{R}/\vec{y}\}) \and \\ \clift{\vec{P}} \otimes \clift{\vec{Q}} \and \\ := \clift{P_{0}\otimes Q_{0},\ldots,P_{0}\otimes Q_{n},\ldots,P_{m}\otimes Q_{0},\ldots,P_{m}\otimes Q_{n}} \end{mathpar} \begin{remark} Observe that arities of tensored abstractions matches arities of tensored concretions if the original arities matched. Note also that the length of the arities corresponds to the increase in dimension we see in ordinary vector space tensor product. \end{remark} \begin{remark} Operationally, this definition distributes the tensor down to components ``linked'' by summation. Tensor over summation is intriguing in that it mixes names. Moreover, as a consequence of the way it mixes names we have the identities for all $x \in \QProc$ and $P,Q \in \Proc$ \begin{mathpar} (x \cdot P) \otimes Q \equiv x \cdot (P \otimes Q) \equiv P \otimes (x \cdot Q) \and \\ P \otimes \pzero \equiv P \end{mathpar} that the reader is invited to verify. \end{remark} \subsubsection{Annihilation} \begin{mathpar} P^{\perp} := \{ Q : \forall R. P|Q \red^{*} R \Rightarrow R \red^{*} \pzero \} \and \\ \annihilate{P} := \Sigma_{Q \in P^{\perp}} \quotep{Q}?(y).(\dropn{y}|Q) | \Sigma_{Q \in P^{\perp}} \quotep{Q}\clift{\Box} \end{mathpar} \paragraph{Discussion} The reader will note that $P^{\perp}$ is a \emph{set} of processes, while $\annihilate{P}$ is a \emph{context}. We call the set $P^{\perp}$ the \emph{annihilators} of $P$. The parallel composition of a process in the annihilators of $P$ with $P$ will result in a process, the state space of which has all paths eventually leading to $\pzero$. Execution may endure loops; but under reasonable conditions of fairness (naturally guaranteed under most notions of bisimulation) such a composite process cannot get stuck in such a loop and will, eventually pop out and terminate. The context $\annihilate{P}$ is ready and willing to ``take the $P$ out of'' the process to which it is applied. It will effectively transmit the code of the process to which it is applied to one of the annihilators and run the process against it. \begin{remark} Note that ${\annihilate{P}}^*$ is the abstraction corresponding to context $\annihilate{P}$. We will set $\dualize{P} := {\annihilate{P}}^*$. \end{remark} \subsubsection{Evaluation} We fix $M$ a domain of fully abstract interpretation with an equality coincident with bisimulation. We take $\meaningof{\cdot} : \Proc \to M$ to be the map interpreting processes and $\nmeaningof{\cdot} : \M \to Proc$ to be the map running the other way. Then we define \begin{mathpar} \int P := \nmeaningof{\meaningof{P}} \end{mathpar} \paragraph{Discussion} There are many fully abstract interpretations of Milner's $\pi$-calculus. Any of them can be used as a basis for interpreting the reflective calculus here. Equipped with such a domain it is largely a matter of grinding through to check that the Yoneda construction for the normalization-by-evaluation program can be extended to this setting. \begin{remark} The reader is invited to verify that $\int (\annihilate{P}[P]) = 0$, and equivalently $(\nu\; x)\int \dualize{P}\langle x \rangle | x\clift{P} = 0$. \end{remark} \subsection{Quantum mechanics} \subsubsection{What is the quantum mechanical notion of continuation?}\label{sec:quantum_continuation} Imagine the following experimental set-up. Alice, our intrepid quantum investigator, prepares a state by performing some operation on some initial state. Then she performs some measurement to obtain an observation. Using the information of the observation, she selects a new initial state, operation and measurement and repeats the steps above. She iterates this procedure until she obtains some desired observation. What is the expression of this procedure in the language of quantum mechanics? \begin{figure}[htp]\label{fig:iterated_experiment} % \fbox{ \begin{lstlisting}[mathescape] $\mathcal{E} ::=$ let S = $U \state{L}$ in (* prepare state*) let m = $\innerprod{M}{S}^2$ in (* take measurement *) match m with (* use m to decide next experiment *) v$_0$ -> $\mathcal{E}$ | $\ldots$ | v$_N$ -> $\mathcal{E}$ | v$_{Exit}$ -> m (* return observation *) \end{lstlisting} % } \caption{Iterated experiment schematic} \end{figure} Figure \ref{fig:iterated_experiment} gives a schematic description of such an iterated experimental procedure. The question is how do we write down this iterated procedure without stepping outside the language of quantum mechanics? Note that accounts of famous composite quantum experiments, like the Stern-Gerlach experiment leave the language of quantum mechanics to describe the iterated experiment. We ask this question for many reasons, but one of them is to help set up the exegesis of our interpretation. In our framework \emph{everything} is a computation, both the quantum operations and processes (classical or quantum) that invoke those operations. There is no need to step out of the conceptual (and more pragmatically, the computational) framework to describe these kinds of experiments. More to the point, the framework we are proposing is -- like the hybrid functional language employed in the schema -- \emph{compositional}: experiments, computations are built out of experiments and computations. This is of enormous pragmatic value if we are to build and reason about systems of significant scale. \begin{remark} It is also worth noting in this connection that this schema is the core of a wide range of recursive functions. Further, this connection to calculations of fixpoints makes it a close neighbor of search techniques like natural selection and the scientific method. This is a theme to which we will return, for quantum information seems very \emph{unlife-like} in it's uncloneable, undeleteable nature. \end{remark} Returning the matter of the computational interpretation, our interpretation will take the form of a map, written $\meaningof{-}(-)$, from expressions in Dirac notation to expressions in our target reflective calculus. The map takes an \emph{ancillary} argument, a channel along which to communicate results to subsequent computations. This is how we communicate, for example, the results of taking a measurement to a subsequent step in an experiment. \subsubsection{Interpretation} Table \ref{tbl:core_qm_op_defns} gives the core operational correspondences. It is meant as an intuitive guide. \begin{table}[htp]\label{tbl:core_qm_op_defns} \center{ \fbox{ \begin{tabular}{c|c} quantum mechanics & process calculus \\ \hline scalar & $x := \quotep{P}$ \\ state vector & $\state{P} := P$ \\ dual & $\state{P}^{*} := \event{\annihilate{P}} := \quotep{\annihilate{P}}[-]$ \\ matrix & $ \Sigma_{\alpha} \state{P_{\alpha}}x_{\alpha}\event{Q_{\alpha}}$ \\ vector addition & $\state{P} + \state{Q} := \state{P | Q}$ \\ tensor product & $\state{P} \otimes \state{Q} := \state{P \otimes Q}$ \\ inner product & $\innerprod{P}{Q} := \quotep{\int \annihilate{P}[Q]}$ \\ \end{tabular} } } \caption{QM - operational definitions} \end{table} \paragraph{Discussion} The process algebraic view of a state is called, ironically, a process, and that is what we map vectors to in our interpretation. It has long been noted in the process algebraic community that names play a role somewhat similar to scalars in a vector space. What is unique about the reflective calculus, and makes it suitable for an interpretation of this form is that with the structure of names reflecting the structure of processes we can both make this similarity in a precision instrument; and find a notion of \emph{dual} to a state. If we posit names as scalars, then in perfect analogy with vector spaces a dual is a map from processes to names. We actually have two candidates for this interpretation: nominal contexts, $\quotep{M}$, and their corresponding abstraction, $\quotep{M}^{*}$. The goal of supporting a notion of continuation selects the latter of the two for our interpretation. Taking these as the basis of the interpretation together with the algebraic identities required by the Dirac notation more or less fixes the definitions of the rest of the operations. Among the interesting particularities, the definition of inner product finds near perfect mirroring of the Feyman interpretation. \begin{mathpar} \inferrule* [lab=states] {} {\meaningof{\state{P}}(c) = c?(l,r).r\clift{P}} \and \inferrule* [lab=events] {} {\meaningof{\event{P}}(c) = (x)c?(l,r).l\clift{\dualize{P}\langle x \rangle} } \and \inferrule* [lab=vector addition] {} {\meaningof{\state{P} + \state{Q}}(c) = \meaningof{\state{P | Q}}(c)} \and \inferrule* [lab=tensor product] {} {\meaningof{\state{P} \otimes \state{Q}}(c) = \meaningof{\state{P\otimes Q}}(c)} \and \inferrule* [lab=inner product] {} {\meaningof{\innerprod{P}{Q}}(c) = (\nu\; x)c\clift{\int \dualize{P}\langle x \rangle | x\clift{Q}}} \and \inferrule* [lab=matrix] {} {\meaningof{\fprmatrix{P}{x}{Q}}(c) = \\\\ (u)(\nu \; lr) c!(l,r).(l?(e). (\nu\; y)\meaningof{\innerprod{\dropn{e}}{Q}}(x) | x?(z).x?(a).c\clift{(\dualize{P}\sigma(z,a))\langle u \rangle}|y!(x) \\\\ + r?(e). (\nu\; x)\meaningof{\innerprod{P}{\dropn{e}}}(x) | x?(z).x?(a).c\clift{Q\sigma(z,a)}|x!(x_{\alpha}))} \and \inferrule* [lab=matrix application] {} {\meaningof{(\fprmatrix{P}{x}{Q})(\state{S})}(c) = (\nu\; c'u)\meaningof{\fprmatrix{P}{x}{Q}}(c')\langle u \rangle | \meaningof{\state{S}}(c') | c'?(a).c!(a) \\\\ \meaningof{(\fprmatrix{P}{x}{Q})(\event{S})}(c) = (\nu\; c'u)\meaningof{\fprmatrix{P}{x}{Q}}(c')\langle u \rangle | \meaningof{\event{S}}(c') | c'?(a).c!(a)} \end{mathpar} where \begin{mathpar} P\sigma(z,a) := P\{ z\cdot a\cdot r/r : r \in \freenames{P} \} \end{mathpar} \begin{remark} The reader is invited to verify that \begin{mathpar} \meaningof{\innerprod{P}{Q}}(c) \and \\ \wbbisim \and \\ %\and (\nu\; x)(\nu c'lr)\meaningof{\event{P}}(c')\langle x \rangle \;|\; \meaningof{\state{Q}}(c') %\and |\; c'!(l,r).l?(p).r?(q).c\clift{\int \dropn{p} | x!(q)} \end{mathpar} This provides a (more) compositional definition of inner product. It also illustrates an important point of the computational interpretation. We have a notion of equivalence providing a crucial proof method: bisimulation. \end{remark} \begin{remark} Assuming $\int (\annihilate{P}[P]) = 0$, the reader is invited to verify that $(\fprmatrix{P}{x}{P})(\state{P}) = x \cdot \state{P}$. \end{remark} % \begin{remark} % The reader is invited to verify that $\innerprod{P}{Q}$ could % equally well have been written $\quotep{\int \stackrel{\vee}{x}}$ % where $x = \event{\annihilate{P}}(Q)$. % One of the motivations for this remark is that there is another way % to factor these operations. We could package up evaluation in the dual: % \begin{mathpar} % \state{P}^{*} := \event{\int \annihilate{P}} := \quotep{\int \annihilate{P}}[-] % \end{mathpar} % and then have inner product defined by % \begin{mathpar} % \innerprod{M}{Q} := \event{M}(Q) % \end{mathpar} % where we use $M$ to label the dual to emphasize that it is a context. % Hopefully, experience with the calculations will provide guidance on % the best factoring. % \end{remark} \begin{remark}\label{rem:abstract_scalars} Assuming $\int (\annihilate{P}[P]) = 0$, the reader is invited to verify that $\forall P,Q. (\prmatrix{0}{Q})(\state{0}) = \state{0}$ and dually $(\prmatrix{P}{0})(\event{0}) = \event{0}$. \end{remark} \subsubsection{Interpreting continuations} As promised, we can combine these interpretations with standard semantics for conditionals and continuations to provide an interpretation of the iterated experiment. \begin{lstlisting}[mathescape] $\ldb$ let S = $U \state{L}$ in let m = $\innerprod{M}{S}^2$ in match m with v$_0$ -> $\mathcal{E}$ | $\ldots$ | v$_N$ -> $\mathcal{E}$ | v$_{Exit}$ -> m $\rdb(c)$ $=$ $(\nu\; c')\meaningof{\innerprod{M}{U\state{L}}}(c')$ $| c'?(m).m!(m) | \Sigma_{i=0}^{N}v_{i}?(m).\meaningof{\mathcal{E}} + v_{Exit}?(m).c!(m)$ \end{lstlisting} \paragraph{A quick tally} Already the interpretation is beginning to show signs of promise. First of all, it is no more notationally cumbersome than the notation used in QM calculations. Beyond syntax, we have a new proof principle in hand and the ability to reason about more complex experimental situations than is directly calculable in ordinary quantum mechanics. \subsubsection{Adjointness} We need to give a definition of $(\cdot)^{\dagger}$ for matrices. The obvious candidate definition is \begin{mathpar} \meaningof{(\fprmatrix{P}{x}{Q})^{\dagger}}(c) = (\nu\; u)\meaningof{\fprmatrix{\dualize{Q}\langle u \rangle}{\overline{x}}{\dualize{P}\langle u \rangle}}(c) \end{mathpar} % But, $(Q_{\alpha}^{\underline{\perp}})^{*}$ requires a name along % which to communicate the process to achieve the context application. \begin{remark} i'm a little worried that i don't (yet) have proper support for complex conjugacy. But, the observation above may give us a clue. According to Abramsky, it must be the case that the scalars are iso to the homset of the identity for the tensor -- which the observation above (\ref{rem:abstract_scalars}) characterizes. For now, we will simply bookmark the notion with $\overline{x}$. \end{remark} \subsubsection{Basis for a basis} If processes label states and ``addition'' of states (a.k.a. vector addition) is interpreted as parallel composition, what corresponds to notions of linear independence and basis? Here, we recall that Yoshida has developed a set of \emph{combinators} for an asynchronous verison of Milner's $\pi$-calculus \cite{DBLP:conf/concur/Yoshida98}. These are a finite set of processes such any process can be expressed as parallel composition of these combinators together with liberal uses of the new operator and replication. We can simply give a translation of these into the present calculus and have reasonable expectation that the property carries over. That is, that the resultant set allows to express all processes via parallel composition. Note, however, that there is no new operator or replication in this calculus. As a result, we expect that the corresponding set is actually infinite. That is, we expect that the space is actually infinite dimensional. \begin{remark} The reader familiar with the lambda calculus may reasonably object: certainly, the collection $S$, $K$ and $I$ is a finite set of combinators \cite{Barendregt84}. Shouldn't we expect to see a finite set of combinators for an effectively equivalent system? i am very sympathetic to this critique and feel it warrants full attention. On the other hand, i also have in mind the following analogy. The natural numbers, as a monoid under addition, has exactly $1$ generator, while the natural numbers, as a monoid under multiplication, has countably many generators (the primes). We observe that the application of the lambda calculus is much less resource sensitive than the parallel composition of the $\pi$-calculus. Could it be the case that we have an analogy of the form \begin{mathpar} m + n : MN :: m*n : M|N \end{mathpar} giving a similar blow up in the set of ``primes''? This is such a wonderful thought that, even if it's not true, i think it's worth writing down. \end{remark}
[STATEMENT] lemma drop_bit_word_beyond [simp]: \<open>drop_bit n w = 0\<close> if \<open>LENGTH('a) \<le> n\<close> for w :: \<open>'a::len word\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. drop_bit n w = 0 [PROOF STEP] using that [PROOF STATE] proof (prove) using this: LENGTH('a) \<le> n goal (1 subgoal): 1. drop_bit n w = 0 [PROOF STEP] by (transfer fixing: n) (simp add: drop_bit_take_bit)
CINPUT C SUBROUTINE INPUT SUBROUTINE INPUT C REAL MFSTOP LOGICAL PREVER COMMON /SNTCP/G,AJ,PRPC,ICASE,PREVER,MFSTOP,JUMP,LOPIN,ISCASE, 1KN,GAMF,IP,SCRIT,PTRN,ISECT,KSTG,WTOL,RHOTOL,PRTOL,TRLOOP,LSTG, 2LBRC,IBRC,ICHOKE,ISORR,CHOKE,PT0PS1(6,8),PTRS2(6,8),TRDIAG,SC,RC, 3DELPR,PASS,IPC,LOPC,ISS C COMMON /SINPUT/ 1PTPS,PTIN,TTIN,WAIR,FAIR,DELC,DELL,DELA,AACS,VCTD,STG,SECT,EXPN, 2EXPP,EXPRE,RG,RPM,PAF,SLI,STGCH,ENDJOB,XNAME(20),TITLE(20), 3PCNH(6),GAM(6,8),SR(6,8),ST(6,8),SWG(6,8),ALPHAS(6,8),ALPHA1(6,8), 4ETARS(6,8),ETAS(6,8),CFS(6,8),ANDO(6,8),BETA1(6,8),BETA2(6,8),ETAR 5R(6,8),ETAR(6,8),CFR(6,8),TFR(6,8),ANDOR(6,8),OMEGAS(6,8),AS0(6,8) 6,ASMP0(6,8),ACMN0(6,8),A1(6,8),A2(6,8),A3(6,8),A4(6,8),A5(6,8),A6( 76,8),OMEGAR(6,8),BSIA(6,8),BSMPIA(6,8),BCMNIA(6,8),B1(6,8),B2(6,8) 8,B3(6,8),B4(6,8),B5(6,8),B6(6,8), * SESTHI(8),RERTHI(8) 9,fairx(5,8),wairx(5,8),rg1(8),rg1a(8),rg2(8),rg2a(8) COMMON /SADDIN/ PS1P(8),PS2P(8) COMMON/SADIN2/PTINH(6),TTINH(6),ALF0H(6) C COMMON/GETPR/TRY1,TRY2,PTRY1,PTRY2,PFIND,DHFIND,PFIND1, 1DHFND1 DIMENSION X(6,8,37),Y(6,37) DIMENSION RVU1(6),RVU2(6),TWG(6),pwg(6) COMMON /TDIL/TWGK(6,8),pwgk(6,8) C EQUIVALENCE (X(1,1,1),GAM(1,1)),(Y(1,1),GAMG(1)) C common/cfi/icf COMMON/DESOPT/RVU1K(6,8),RVU2K(6,8),WG,EPR COMMON/RPMCOM/RPMK(8) COMMON GAMG(6),DR(6),DT(6),RWG(6),SDIA(6),SDEA(6),SREC(6),SETA(6), 1SCF(6),SPA(6),RDIA(6),RDEA(6),RREC(6),RETA(6),RCF(6),RTF(6),RPA(6) 2,STPLC(6),SINR(6),SINMP(6),SINMN(6),SCPS(6),SCPC(6),SCPQ(6),SCNS(6 3),SCNC(6),SCNQ(6),RTPLC(6),RINR(6),RINMP(6),RINMN(6),RCPS(6),RCPC( 46),RCPQ(6),RCNS(6),RCNC(6),RCNQ(6) C COMMON/PLOTT/ENDPLT,IPCAS,IPSCAS(20),xnname(20),iplot(3) dimension tangms(6,8),tangmr(6,8),tangm1(6,8),tangm2(6,8),tang0(6) common/slope/tangms,tangmr,tangm1,tangm2,tang0,iar,icyl C NAMELIST/DATAIN/ PTPS,PTIN,TTIN,WAIR,FAIR,DELC,DELL,DELA,AACS,VCTD 1,STG,SECT,STAGE,EXPN,EXPP,EXPRE,RG,RPM,PAF,SLI,ENDSTG,ENDJOB,PCNH, 2GAMG,DR,DT,RWG,SDIA,SDEA,SREC,SETA,SCF,SPA,RDIA,RDEA,RREC,RETA,RCF 3,RTF,RPA,STPLC,SINR,SINMP,SIMMN,SCPS,SCPC,SCPQ,SCNS,SCNC,SCNQ,RTPL 4C,RINR,RINMP,RINMN,RCPS,RCPC,RCPQ,RCNS,RCNC,RCNQ,SESTH,RERTH, 5WTOL,RHOTOL,PRTOL,TRLOOP,TRDIAG,STGCH,SEPS,REPS 6,PTINH,TTINH,ALF0H,iar,icyl,icf,iplot, 1PFIND,DHFIND,WG,RVU1,RVU2,EPR,TWG,pwg,endplt C DATA BLANKS/66666.66/ C C C READ THE HEADING CARDS EVERY TIME ENTRY IS MADE READ(15,6669,END=9999) (XNAME(I),I=1,20) READ(15,6669) (TITLE(I),I=1,20) J=0 endstg=0.0 30 DO 25 L=1,37 DO 25 I=1,6 25 Y(I,L)=BLANKS DO 31 I=1,6 RVU1(I)=0.0 twg(i)=blanks pwg(i)=blanks 31 RVU2(I)=0.0 SEPS=BLANKS REPS= BLANKS SESTH=BLANKS RERTH=BLANKS READ(15,DATAIN) K=STAGE+.0001 ISECT=SECT+.0001 DO 80 L=1,37 DO 80 I=1,6 IF (Y(I,L).NE.BLANKS) GO TO 71 Y(I,L)=0.0 GO TO 80 71 X(I,K,L)=Y(I,L) 80 CONTINUE DO 220 I=1,6 if (twg(i).ne.blanks) TWGK(I,K)=TWG(I) twg(i)=twgk(i,k) if (pwg(i).ne.blanks) pwgk(i,k)=pwg(i) pwg(i)=pwgk(i,k) RVU1K(I,K)=RVU1(I) 220 RVU2K(I,K)=RVU2(I) IF(SEPS.EQ.BLANKS) GO TO 84 PS1P(K)= SEPS GO TO 84 84 IF(REPS.EQ.BLANKS) GO TO 88 PS2P(K)= REPS GO TO 88 88 CONTINUE IF(SESTH.EQ.BLANKS) GO TO 95 SESTHI(K)=SESTH GO TO 96 95 SESTH=0. 96 IF(RERTH.EQ.BLANKS) GO TO 105 RERTHI(K)=RERTH GO TO 110 105 RERTH=0. 110 RPMK(K)=RPM C IF (K-1)120,120,130 C replaced by ....... C IF (K.LE.1) THEN IF ((K-1).LE.0) THEN C120 WRITE(16,6670)XNAME,TITLE,TTIN,PTIN,WAIR,FAIR,PTPS,DELC,DELL, WRITE(16,6670)XNAME,TITLE,TTIN,PTIN,WAIR,FAIR,PTPS,DELC,DELL, 1 dela,STG,SECT,EXPN,EXPP,RG,PAF,SLI,AACS,RPM,VCTD,EXPRE, * WG,ENDSTG,ENDJOB,DHFIND,PFIND,iar,epr, 1 PCNH J=J+1 ENDIF C130 WRITE(16,6671) K,GAMG,DR,DT,RWG,TWG,pwg, WRITE(16,6671) K,GAMG,DR,DT,RWG,TWG,pwg, * SESTH,RERTH,RPM,SDIA,SDEA,SREC,SETA,SCF, SPA,RVU1, 1 RDIA,RDEA,RREC,RETA,RCF,RTF,RPA,RVU2 C IF (OMEGAS(1,K))160,160,150 C replaced by ....... C IF (OMEGAS(1,K).LE.0) THEN C GO TO 160 C ELSE C150 WRITE(16,6672)STPLC,SINR,SINMP,SINMN,SCPS,SCPC,SCPQ,SCNS,SCNC, C 1 SCNQ,RTPLC,RINR,RINMP,RINMN,RCPS,RCPC,RCPQ,RCNS,RCNC,RCNQ C ENDIF C160 J = J+1 IF (OMEGAS(1,K).GT.0) THEN WRITE(16,6672)STPLC,SINR,SINMP,SINMN,SCPS,SCPC,SCPQ,SCNS,SCNC, 1 SCNQ,RTPLC,RINR,RINMP,RINMN,RCPS,RCPC,RCPQ,RCNS,RCNC,RCNQ ENDIF J=J+1 AM= J-2*(J/2) C IF(AM)200,210,200 C replaced by ....... IF(AM.NE.0) WRITE(16,6673) C200 WRITE(16,6673) C210 IF (ENDSTG-1.)30,170,170 C replaced by ....... 210 IF (ENDSTG.LT.1.) GO TO 30 C170 RETURN RETURN 6669 FORMAT(20A4) 6670 FORMAT (1H1,6X,20A4/6X,20A4/2X, 17H*DATAIN/2X,7H TTIN=,F10.3,1X,7H PTIN=, &F10.3,1X,6H WAIR=,F10.3,1X,5HFAIR=,F10.3/ 22X,7H PTPS=,F10.3,1X,7H DELC=,F10.3,1X,6H DELL=,F10.3,1X,5HDELA= 3,F10.3/2X,7H STG=,F10.3,1X,7H SECT=,F10.3,1X,6H EXPN=,F10.3,1X, 45HEXPP=,F10.3/2X,7H RG=,F10.3,1X,7H PAF=,F10.3,1X,6H SLI=, 5F10.3,1X,5HAACS=,F10.3/2X,7H RPM=,F10.3,1X,7H VCTD=,F10.3, &1X,6HEXPRE=,F10.3,3X,3HWG=,F10.3 */2X,7HENDSTG=,F10.3,1X,7HENDJOB=,F10.3,7HDHFIND=,F10.3, *6HPFIND=,F10.3/5x,4hIAR=,i10,4x,4hEPR=,f10.3 */25X,21HINLET RADIAL PROFILES/2X,5HPCNH=,6(F8.3,2X)/1H1) 6671 FORMAT(28X,15HSTANDARD OPTION/3X, &6HSTAGE=,I3,21X,14HAXIAL STATIONS/ 110X,6HSTA. 0,4X,6HSTA. 1,4X,6HSTA.1A,4X,6HSTA. 2,3X,7HSTA. 2A/ 33X,6H GAMG=,6(F8.3,2X)/3X,6H DR=,6(F8.3,2X)/ &3X,6H DT=,6(F8.3,2X)/ 33X,6H RWG=,6(F8.3,2X)/5X,4HTWG=,6(F8.1,2X)/5x,4hPWG=,6(f8.2,2x)/ 33X,6HSESTH=,F8.3,3X,6HRERTH=,F8.3,3X,4HRPM=, 3F8.1//22X,27HSTATOR RADIAL DISTRIBUTIONS/3X,6H SDIA=,6(F8.3,2X) &/3X,6H SDEA=,6(F8.3,2X)/3X,6H SREC=,6(F8.3,2X)/3x, &6H SETA=,6(F8.3,2X)/3X,6H SCF=,6(F8.3,2X)/3X,6H SPA=,6(F8.3,2X) */4X,5HRVU1=,6(F8.1,2X)//23X,26HROTOR RADIAL DISTRIBUTIONS/ 83X,6H RDIA=,6(F8.3,2X)/3X,6H RDEA=,6(F8.3,2X)/ &3X,6H RREC=,6(F8.3,2X)/3X,6H RETA=,6(F8.3,2X)/3X,6H RCF=, &6(F8.3,2X)/3X,6H RTF=,6(F8.3,2X)/ 13X,6H RPA=,6(F8.3,2X)/4X,5HRVU2=,6(F8.1,2X)) 6672 FORMAT(/25X,23HLOSS COEFFICIENT OPTION/22X,27HSTATOR RADIAL DISTRI 1BUTIONS/ 23X,6HSTPLC=,6(F8.3,2X)/ &3X,6H SINR=,6(F8.3,2X)/3X,6HSINMP=,6(F8.3,2X)/ 33X,6HSINMN=,6(F8.3,2X)/ &3X,6H SCPS=,6(F8.3,2X)/3X,6H SCPC=,6(F8.3,2X)/ 43X,6H SCPQ=,6(F8.3,2X)/ &3X,6H SCNS=,6(F8.3,2X)/3X,6H SCNC=,6(F8.3,2X)/ 53X,6H SCNQ=,6(F8.3,2X)/023X,26HROTOR RADIAL DISTRIBUTIONS/ 63X,6HRTPLC=,6(F8.3,2X)/ &3X,6H RINR=,6(F8.3,2X)/3X,6HRINMP=,6(F8.3,2X)/ 73X,6HRINMN=,6(F8.3,2X)/ &3X,6H RCPS=,6(F8.3,2X)/3X,6H RCPC=,6(F8.3,2X)/ 83X,6H RCPQ=,6(F8.3,2X)/ &3X,6H RCNS=,6(F8.3,2X)/3X,6H RCNC=,6(F8.3,2X)/ 93X,6H RCNQ=,6(F8.3,2X)) 6673 FORMAT (1H1) cerm c 9999 call exit c exit subroutine is an extension to standard fortran c not available on all compilers. It has been replace c with the following coding 9999 stop END
lemma Chain3: assumes At0: "At x0 y0 z0 0" and AtSuc: "\<And>x y z n. At x y z n \<Longrightarrow> \<exists>x' y' z'. At x' y' z' (Suc n) \<and> Follows x' y' z' x y z" obtains f g h where "f 0 = x0" "g 0 = y0" "h 0 = z0" "\<And>n. At (f n) (g n) (h n) n" "\<And>n. Follows (f(Suc n)) (g(Suc n)) (h(Suc n)) (f n) (g n) (h n)"
If $f$ is a positive additive function on a ring of sets, then $f$ is increasing.
(* $Id$ *) theory HEAP0SanityProofs imports HEAP0Sanity HEAP0Proofs begin (*------------------------------------------------------------------------*) section \<open> Proof of some properties of interest \<close> (*------------------------------------------------------------------------*) (*------------------------------------------------------------------------*) subsection \<open> Invariant \<close> (*------------------------------------------------------------------------*) (* The invariant holds and fails at expected examples *) lemma l_F0_inv_example: "F0_ex_inv F0_ex" unfolding F0_ex_inv_defs by auto lemma l_F0_inv_counter_example: "\<not> F0_ex_inv UNIV" unfolding F0_ex_inv_defs by auto (*------------------------------------------------------------------------*) subsection \<open> Operations \<close> (*------------------------------------------------------------------------*) (*------------------------------------------------------------------------*) (* NEW0(n) shrinks f *) lemma new0_post_shrinks_f: "PO_new0_post_shrinks_f" unfolding PO_new0_post_shrinks_f_def new0_post_defs unfolding nat1_def inv_VDMNat1_def apply simp apply safe by (metis DiffE less_add_same_cancel1 mem_Collect_eq order_refl subset_iff) (*by (smt Diff_subset mem_Collect_eq inv_VDMNat1_def set_diff_eq set_mp subset_iff_psubset_eq)*) context level0_new begin lemma new0_postcondition_shrinks_f: "PO_new0_postcondition_shrinks_f" by (smt PO_new0_post_shrinks_f_def PO_new0_postcondition_shrinks_f_def new0_post_shrinks_f new0_postcondition_def) end (*------------------------------------------------------------------------*) (* NEW0(n) shrinks f by n, excactly *) thm card_Diff_subset[of "locs_of r n" f] lemma new0_post_shrinks_f_exactly: "PO_new0_post_shrinks_f_exactly" unfolding PO_new0_post_shrinks_f_exactly_def new0_post_def is_block_def apply safe by (simp add: card_Diff_subset b_locs_of_finite b_locs_of_as_set_interval) (*------------------------------------------------------------------------*) (* DISPOSE0 extends f*) context level0_dispose begin (* It's interesting what the difference is here: same goal, different proof script *) lemma dispose0_postcondition_extends_f: "PO_dispose0_postcondition_extends_f" unfolding PO_dispose0_postcondition_extends_f_def dispose0_postcondition_def dispose0_post_def by (metis Un_commute b_locs_of_non_empty dispose0_pre_def inf_sup_absorb inf_sup_ord(3) l0_dispose0_precondition_def l0_input_notempty_def less_le) lemma "dispose0_postcondition f' \<Longrightarrow> f0 \<subset> f'" unfolding dispose0_postcondition_def dispose0_post_def by (metis b_locs_of_non_empty dispose0_pre_def l0_dispose0_precondition_def inf_absorb2 inf_commute inf_sup_ord(4) l0_input_notempty_def le_iff_sup less_le sup.left_idem) (*NOTE: we need the precondition *) (*------------------------------------------------------------------------*) (* DISPOSE0 extends f by n exactly*) thm card_Un_disjoint[of f0 "locs_of d0 s0"] (* finite f0 \<Longrightarrow> finite (locs_of d0 s0) \<Longrightarrow> f0 \<inter> locs_of d0 s0 = {} \<Longrightarrow> card (f0 \<union> locs_of d0 s0) = card f0 + card (locs_of d0 s0) *) lemma dispose0_postcondition_extends_f_exactly: "PO_dispose0_postcondition_extends_f_exactly" unfolding PO_dispose0_postcondition_extends_f_exactly_def dispose0_postcondition_def dispose0_post_def F0_inv_def by (metis Int_commute add_0_iff card_Un_Int card.empty dispose0_pre_def finite_Un l0_dispose0_precondition_def l0_input_notempty_def l_locs_of_card) lemma "dispose0_postcondition f' \<Longrightarrow> card f' = card f0 + s0" unfolding dispose0_postcondition_def dispose0_post_def F0_inv_def using PO_dispose0_feasibility_def PO_dispose0_postcondition_extends_f_exactly_def dispose0_post_def dispose0_postcondition_def dispose0_postcondition_extends_f_exactly locale0_dispose_FSB by presburger (*NOTE: we need the precondition *) end (*------------------------------------------------------------------------*) (* DISPOSE0 NEW0(n) n = Id *) lemma "PO_new0_dispose_0_identity" unfolding PO_new0_dispose_0_identity_def new0_post_def dispose0_post_def F0_inv_def apply (safe) apply (metis is_block_def set_mp) apply (metis finite_Diff) by (metis b_locs_of_finite is_block_def) lemma new0_dispose_0_identity: "PO_new0_dispose_0_identity" by (metis PO_new0_dispose_0_identity_def Un_Diff_cancel dispose0_post_def is_block_def new0_post_def sup_absorb1 sup_commute) end
import Architectural.ArchWithContracts variables {Φ Var : Type} [fintype Var] [decidable_eq Var] [AssertionLang Φ Var] def isCorrectDecompositionImpl {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is : Implementations A.to_Architecture) : Prop := (∀ (S' : Component Var) (h : S' ∈ A.subs), (Is S' h).satisfiesContract (A.contracts.find_val S').iget) → (@CompositeImplementation Var _ _ _ _ S {..A} Is).satisfiesContract A.parent def isCorrectDecompositionEnv {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is : Implementations A.to_Architecture) (E : Env Var) : Prop := ∀ (S'' : Component Var) (h'': S'' ∈ A.subs) , (E.satisfiesContract A.parent ∧ (∀ (S' : Component Var) {S' ∈ A.subs.erase S''}, (Is S' (list.mem_of_mem_erase H)).satisfiesContract (A.contracts.find_val S').iget) → (CompositeEnvironment A.to_Architecture S'' Is E).satisfiesContract (A.contracts.find_val S'').iget) def isCorrectDecomposition {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is : Implementations A.to_Architecture) (E : Env Var) := isCorrectDecompositionImpl A Is ∧ isCorrectDecompositionEnv A Is E namespace Claim def correctDecompositionImpl {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is :Implementations A.to_Architecture) (σ : Trace Var) : Prop := (∀ (S' : Component Var) {S' ∈ A.subs}, ∀ σ',(σ' ∈ (Is S' H) ∧ (σ' ∈ (@AssertionLang.sem Φ Var _ _ _ (A.contracts.find_val S').iget.A))) → (σ' ∈ (@AssertionLang.sem Φ Var _ _ _ (A.contracts.find_val S').iget.G))) → ( (σ ∈ (@CompositeImplementation Var _ _ _ _ S ↑A Is) ∧ (σ ∈ (@AssertionLang.sem Φ Var _ _ _ A.parent.A))) → (σ ∈ (@AssertionLang.sem Φ Var _ _ _ A.parent.G))) -- example {C : Contract Φ Var} {σ : Trace Var} : -- (σ ∈ (@AssertionLang.sem Φ Var _ _ _ C.A)) → (σ ∈ (@AssertionLang.sem Φ Var _ _ _ C.G)) -- ↔ (σ ∈ (@AssertionLang.sem Φ Var _ _ _ C.nf)) := -- begin -- split, -- intro H, -- rw AssertionLang.disj_def, -- rw AssertionLang.compl_def, -- simp, -- rw ← imp_iff_not_or, exact H, -- intro H, -- rw AssertionLang.disj_def at H, -- rw AssertionLang.compl_def at H, -- simp at H, -- rw ← imp_iff_not_or at H, exact H, -- end def correctDecompositionImpl' {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is :Implementations A.to_Architecture) (σ : Trace Var) : Prop := (∀ (S' : Component Var) {S' ∈ A.subs}, ∀ σ',(σ' ∈ (Is S' H) ∧ (σ' ∈ (@AssertionLang.sem Φ Var _ _ _ (A.contracts.find_val S').iget.A))) → (σ' ∈ (@AssertionLang.sem Φ Var _ _ _ (A.contracts.find_val S').iget.G))) → ( (σ ∈ (@CompositeImplementation Var _ _ _ _ S ↑A Is) ∧ (σ ∈ (@AssertionLang.sem Φ Var _ _ _ A.parent.A))) → (σ ∈ (@AssertionLang.sem Φ Var _ _ _ A.parent.G))) def correctDecompositionEnv {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is :Implementations A.to_Architecture) (E : Env Var) (σ : Trace Var) : Prop := ∀ (S'' : Component Var) {S'' ∈ A.subs}, E.satisfiesContract A.parent → (∀ (S' : Component Var) {S' ∈ A.subs.erase S''}, (Is S' (list.mem_of_mem_erase H)).satisfiesContract (A.contracts.find_val S').iget) → (σ ∈ (CompositeEnvironment A.to_Architecture S'' Is E)) → σ ∈ (@AssertionLang.sem Φ Var _ _ _ ((A.contracts.find_val S'').iget).A) def correctDecomposition {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is : Implementations A.to_Architecture) (E : Env Var) : Claim (Trace Var) := { X := set.univ, P := λ σ, correctDecompositionImpl A Is σ ∧ correctDecompositionEnv A Is E σ } end Claim -- def correctDecompositionImplProperty -- (A : ArchWithContracts S) -- (Is : Implementations A) : Property (Trace Var) := λ σ, -- (∀ (S' : Component Var) {S' ∈ A.subs}, -- (∀ σ', σ' ∈ (Is S' H) ∧ σ' ∈ $\llparenthesis$(A.contracts.get S').A$\rrparenthesis$ -- → (σ' ∈ $\llparenthesis$(A.contracts.get S').G$\rrparenthesis$)) -- → ((σ ∈ CompositeImplementation A Is ∧ σ ∈ $\llparenthesis$S.C.A$\rrparenthesis$) -- → σ ∈ $\llparenthesis$S.C.G$\rrparenthesis$) -- def correctDecompositionEnvProperty -- {S : ComponentWithContract Φ Var} -- (A : ArchWithContracts S) -- (Is :Implementations A) -- (E : Env Var) : Property (Trace Var) :=λ σ, -- ∀ (S'' : Component Var), -- E.satisfiesContract S.C → -- (∀ (S' : Component Var) {S' ∈ A.subs}, -- (Is S' H).satisfies (A.contracts.get S')) → -- (σ ∈ CompositeEnvironment A S'' Is E) → -- σ ∈ {{((A.contracts.get S'')).A}} theorem claim_imp_correctDecomp {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is : Implementations A.to_Architecture) (E : Env Var) : ⟦Claim.correctDecomposition A Is E⟧ → isCorrectDecomposition A Is E := begin intro clm, rw meaning at clm, split, { intro h, intro s, replace clm := clm s, rw [Claim.correctDecomposition] at clm, simp at clm, replace clm := clm.1, intro h', cases h' with h₂ h₃, rw Claim.correctDecompositionImpl at clm, apply clm, intros S' S'' hMem, replace h := h S'', rw Impl.satisfiesContract at h, rw CompositeImplementation at h₂, simp at h₂, intro h'', apply h,split, exact h₂, exact h₃, }, { rintros S'' h₄ ⟨h₅, h₆⟩ s, replace clm := clm s, rw [Claim.correctDecomposition] at clm, simp at clm, replace clm := clm.2 S'' h₅ h₆, exact clm, rw Claim.correctDecompositionEnv at clm, assumption, } end theorem decompCorrectImpClaim {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is : Implementations A.to_Architecture) (E : Env Var) : isCorrectDecomposition A Is E → ⟦Claim.correctDecomposition A Is E⟧ := begin intro h, rw Claim.correctDecomposition, rw meaning, simp, rw forall_and_distrib, split, { intro s, rw Claim.correctDecompositionImpl, revert s,simp, replace h := h.1, rw isCorrectDecompositionImpl at h, intros σ' h₂ h₃, rw CompositeImplementation at h₃, intros h₄, rw Impl.satisfiesContract at h, simp at h, apply h, intros S' h', replace h₂ := h₂ S' h', intros σ h₅, cases h₅ with L R, replace h₂ := h₂ σ L R, simp, apply h₂,split, rw CompositeImplementation, apply h₃, assumption, }, { intros σ, intros _, intros S'' mem, replace h := h.2, rw isCorrectDecompositionEnv at h, simp at h, replace h := h S'' mem, intros s smem, rw Env.satisfiesContract at h, simp at h, apply h, intros h₂, apply s, exact smem, } end theorem decompositionCorrectAsClaim {S : Component Var} (A : ArchitectureWithContracts Φ S) (Is : Implementations A.to_Architecture) (E : Env Var) : isCorrectDecomposition A Is E ↔ ⟦Claim.correctDecomposition A Is E⟧ := iff.intro (decompCorrectImpClaim A Is E) (claim_imp_correctDecomp A Is E)
lemma monom_eq_0_iff [simp]: "monom a n = 0 \<longleftrightarrow> a = 0"
[STATEMENT] lemma interval_lebesgue_integrable_mult_left [intro, simp]: fixes M a b c and f :: "real \<Rightarrow> 'a::{banach, real_normed_field, second_countable_topology}" shows "(c \<noteq> 0 \<Longrightarrow> interval_lebesgue_integrable M a b f) \<Longrightarrow> interval_lebesgue_integrable M a b (\<lambda>x. f x * c)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (c \<noteq> (0::'a) \<Longrightarrow> interval_lebesgue_integrable M a b f) \<Longrightarrow> interval_lebesgue_integrable M a b (\<lambda>x. f x * c) [PROOF STEP] by (simp add: interval_lebesgue_integrable_def)
function obj = downloadLatestGithubVersion(obj) % Biafra Ahanonu % Started: 2021.03.25 [22:11:25] (branched from ciatah.m) % Blank function end
State Before: t : Type u → Type u → Type u inst✝⁵ : Bitraversable t β✝ : Type u F G : Type u → Type u inst✝⁴ : Applicative F inst✝³ : Applicative G inst✝² : IsLawfulBitraversable t inst✝¹ : LawfulApplicative F inst✝ : LawfulApplicative G α₀ α₁ α₂ β : Type u f : α₀ → F α₁ f' : α₁ → G α₂ x : t α₀ β ⊢ Comp.mk (tfst f' <$> tfst f x) = tfst (Comp.mk ∘ map f' ∘ f) x State After: t : Type u → Type u → Type u inst✝⁵ : Bitraversable t β✝ : Type u F G : Type u → Type u inst✝⁴ : Applicative F inst✝³ : Applicative G inst✝² : IsLawfulBitraversable t inst✝¹ : LawfulApplicative F inst✝ : LawfulApplicative G α₀ α₁ α₂ β : Type u f : α₀ → F α₁ f' : α₁ → G α₂ x : t α₀ β ⊢ bitraverse (Comp.mk ∘ map f' ∘ f) (Comp.mk ∘ map pure ∘ pure) x = tfst (Comp.mk ∘ map f' ∘ f) x Tactic: rw [← comp_bitraverse] State Before: t : Type u → Type u → Type u inst✝⁵ : Bitraversable t β✝ : Type u F G : Type u → Type u inst✝⁴ : Applicative F inst✝³ : Applicative G inst✝² : IsLawfulBitraversable t inst✝¹ : LawfulApplicative F inst✝ : LawfulApplicative G α₀ α₁ α₂ β : Type u f : α₀ → F α₁ f' : α₁ → G α₂ x : t α₀ β ⊢ bitraverse (Comp.mk ∘ map f' ∘ f) (Comp.mk ∘ map pure ∘ pure) x = tfst (Comp.mk ∘ map f' ∘ f) x State After: no goals Tactic: simp only [Function.comp, tfst, map_pure, Pure.pure]
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_HADDOCK show-extensions #-} module NQS.Internal.Types ( -- * Numeric types ℂ , ℝ -- , Estimate(..) -- , NormalError(..) -- , EnergyMeasurement(..) , RealOf -- , SRMeasurement(..) {- , withRbm , withRbmPure , withMRbm , withMRbmPure -} -- * Vectors and matrices , DenseVector , DenseMatrix , MDenseVector , MDenseMatrix , slice , withForeignPtrPrim , newVectorAligned , newDenseVector , newDenseMatrix , unsafeRow , unsafeColumn , unsafeWriteVector , Mutable(..) , Variant(..) , Orientation(..) , Transpose(..) , MatUpLo(..) , Sing(..) , CheckValid(..) , isValidVector , isValidMatrix , badVectorInfo , HasBuffer(..) , HasStride(..) , HasDim(..) , orientationOf , ToNative(..) , DenseWorkspace(..) , MCConfig(..) , defaultMCConfig , CGConfig(..) , SRConfig(..) , HasMc(..) , HasCg(..) , HasSteps(..) , HasRuns(..) , HasRate(..) , HasRestarts(..) , HasRegulariser(..) , HasMaxIter(..) , HasMagnetisation(..) , mapVectorM , mapMatrixM , zipWithVectorM , zipWithMatrixM -- , asTuple -- , fromTuple , FreezeThaw(..) , HasMean(..) , HasVar(..) -- , HasEnergy(..) -- , HasForce(..) -- , HasDerivatives(..) ) where import Foreign.Storable import Foreign.ForeignPtr import Control.DeepSeq import Control.Exception (assert) import Control.Monad ((>=>), unless) import Control.Monad.Primitive import Control.Monad.ST.Strict import Data.Complex import Debug.Trace import GHC.Generics (Generic) import GHC.ForeignPtr (mallocPlainForeignPtrAlignedBytes) import Data.Semigroup ((<>)) import Lens.Micro import Lens.Micro.TH import System.IO.Unsafe import Data.Coerce import Data.Bits import Foreign.Marshal.Alloc import Foreign.Ptr import Foreign.ForeignPtr import Foreign.ForeignPtr.Unsafe import qualified Data.Vector.Storable as V import qualified Data.Vector.Storable.Mutable as MV import Data.Vector.Storable (Vector, MVector(..)) import qualified Data.Vector.Generic as GV import qualified Data.Vector as Boxed import Data.Aeson import qualified Data.Aeson.Types as Aeson import Data.Singletons import qualified Numerical.HBLAS.MatrixTypes as HBLAS import Numerical.HBLAS.MatrixTypes ( Variant(..) , Orientation(..) , Transpose(..) , MatUpLo(..) ) import Numerical.HBLAS.BLAS.FFI ( CBLAS_UPLOT(..) ) import Data.Kind import Data.Proxy deriving instance Generic Variant deriving instance NFData Variant deriving instance Generic Orientation deriving instance NFData Orientation class ToNative a b where encode :: a -> b data family Mutable (v :: * -> *) :: * -> * -> * -- | After some prototyping, I've concluded (possibly incorrectly) that a -- single-precision 'Float' is enough for our purposes. -- -- [This answer](https://stackoverflow.com/a/40538415) also mentions that 32-bit -- floats should be enought for most neural network applications. type ℝ = Float type ℂ = Complex ℝ data instance Sing (orient :: Orientation) where SRow :: Sing 'Row SColumn :: Sing 'Column instance SingI 'Row where sing = SRow instance SingI 'Column where sing = SColumn instance SingKind Orientation where type Demote Orientation = Orientation fromSing SRow = Row fromSing SColumn = Column toSing x = case x of Row -> SomeSing SRow Column -> SomeSing SColumn data DenseVector (variant :: Variant) (a :: *) = DenseVector { _denseVectorDim :: {-# UNPACK #-}!Int , _denseVectorStride :: {-# UNPACK #-}!Int , _denseVectorBuffer :: {-# UNPACK #-}!(Vector a) } deriving (Show, Generic, NFData) data DenseMatrix (orientation :: Orientation) (a :: *) = DenseMatrix { _denseMatrixRows :: {-# UNPACK #-}!Int , _denseMatrixCols :: {-# UNPACK #-}!Int , _denseMatrixStride :: {-# UNPACK #-}!Int , _denseMatrixBuffer :: {-# UNPACK #-}!(Vector a) } deriving (Show, Generic, NFData) data instance Mutable (DenseVector variant) s a = MDenseVector { _mDenseVectorDim :: {-# UNPACK #-}!Int , _mDenseVectorStride :: {-# UNPACK #-}!Int , _mDenseVectorBuffer :: {-# UNPACK #-}!(MVector s a) } deriving (Generic, NFData) type MDenseVector variant = Mutable (DenseVector variant) data instance Mutable (DenseMatrix orientation) s a = MDenseMatrix { _mDenseMatrixRows :: {-# UNPACK #-}!Int , _mDenseMatrixCols :: {-# UNPACK #-}!Int , _mDenseMatrixStride :: {-# UNPACK #-}!Int , _mDenseMatrixBuffer :: {-# UNPACK #-}!(MVector s a) } deriving (Generic, NFData) type MDenseMatrix orientation = Mutable (DenseMatrix orientation) makeFields ''DenseVector makeFields ''DenseMatrix unsafeIndexVector :: Storable a => DenseVector 'Direct a -> Int -> a {-# INLINE unsafeIndexVector #-} unsafeIndexVector !(DenseVector _ stride buff) !i = V.unsafeIndex buff (i * stride) unsafeIndexMatrix :: forall a orient. (Storable a, SingI orient) => DenseMatrix orient a -> (Int, Int) -> a {-# INLINE unsafeIndexMatrix #-} unsafeIndexMatrix !(DenseMatrix _ _ stride buff) !(r, c) = V.unsafeIndex buff i where i = case (sing :: Sing orient) of SRow -> r * stride + c SColumn -> r + c * stride unsafeReadVector :: (Storable a, PrimMonad m) => MDenseVector 'Direct (PrimState m) a -> Int -> m a {-# INLINE unsafeReadVector #-} unsafeReadVector !(MDenseVector _ stride buff) !i = MV.unsafeRead buff (i * stride) unsafeReadMatrix :: forall a m orient. (Storable a, PrimMonad m, SingI orient) => MDenseMatrix orient (PrimState m) a -> (Int, Int) -> m a {-# INLINE unsafeReadMatrix #-} unsafeReadMatrix !(MDenseMatrix _ _ stride buff) !(r, c) = MV.unsafeRead buff i where i = case (sing :: Sing orient) of SRow -> r * stride + c SColumn -> r + c * stride unsafeWriteVector :: (Storable a, PrimMonad m) => MDenseVector 'Direct (PrimState m) a -> Int -> a -> m () {-# INLINE unsafeWriteVector #-} unsafeWriteVector !(MDenseVector _ stride buff) !i !x = MV.unsafeWrite buff (i * stride) x unsafeWriteMatrix :: forall a m orient. (Storable a, PrimMonad m, SingI orient) => MDenseMatrix orient (PrimState m) a -> (Int, Int) -> a -> m () {-# INLINE unsafeWriteMatrix #-} unsafeWriteMatrix !(MDenseMatrix _ _ stride buff) !(r, c) !x = MV.unsafeWrite buff i x where i = case (sing :: Sing orient) of SRow -> r * stride + c SColumn -> r + c * stride -- | Returns a row of a matrix. unsafeRow :: forall orient s a . (Storable a, SingI orient) => Int -> MDenseMatrix orient s a -> MDenseVector 'Direct s a {-# INLINE unsafeRow #-} unsafeRow !i !(MDenseMatrix rows cols stride buff) = assert False $ assert (i < rows) $ case (sing :: Sing orient) of SRow -> MDenseVector cols 1 (MV.slice (i * stride) cols buff) SColumn -> MDenseVector cols stride (MV.slice i (cols * stride) buff) -- | Returns a column of a matrix. unsafeColumn :: forall orient s a . (Storable a, SingI orient) => Int -> MDenseMatrix orient s a -> MDenseVector 'Direct s a {-# INLINE unsafeColumn #-} unsafeColumn !i !(MDenseMatrix rows cols stride buff) = assert (i < cols) $ case (sing :: Sing orient) of SRow -> if rows == 1 then MDenseVector 1 1 (MV.slice i 1 buff) else MDenseVector rows stride (MV.slice i ((rows - 1)* stride + 1) buff) SColumn -> MDenseVector rows 1 (MV.slice (i * stride) rows buff) data DenseWorkspace s a = DenseWorkspace { _denseWorkspaceForce :: !(MDenseVector 'Direct s a) -- ^ Force , _denseWorkspaceDerivatives :: !(MDenseMatrix 'Row s a) -- ^ Derivatives , _denseWorkspaceDelta :: !(MDenseVector 'Direct s a) -- ^ Old delta } deriving (Generic, NFData) -- | Configuration for Monte-Carlo sampling. data MCConfig = MCConfig { _mCConfigSteps :: {-# UNPACK #-}!(Int, Int, Int) -- ^ A range of steps for a single run. It is very similar to Python's -- [range](). @(low, high, step)@ corresponds to [low, low + step, low + -- 2 * step, ..., high). -- -- /Note:/ only positive @step@s are supported. , _mCConfigThreads :: {-# UNPACK #-}!(Int, Int, Int) , _mCConfigRuns :: {-# UNPACK #-}!Int -- ^ Number of Monte-Carlo runs to perform. -- -- /Note:/ for optimal work scheduling, make that the total number of -- threads is divisible by the number of runs. , _mCConfigFlips :: {-# UNPACK #-}!Int -- ^ Number of spin-flips to do at each step. , _mCConfigRestarts :: {-# UNPACK #-}!Int -- ^ Allowed number of restarts. -- -- A restart happens when the function computing local energy notices -- that a particular spin-flip results in a spin configuration with -- significantly higher probability. Monte-Carlo sampler is then reset -- and this new spin configuration is used as the initial one. , _mCConfigMagnetisation :: !(Maybe Int) -- ^ Specifies the magnetisation over which to sample. } makeFields ''MCConfig defaultMCConfig :: MCConfig defaultMCConfig = MCConfig (1000, 11000, 1) (4, 1, 1) 4 2 5 Nothing -- | Configuration for the Conjugate Gradient solver. data CGConfig a = CGConfig { _cGConfigMaxIter :: {-# UNPACK #-}!Int -- ^ Maximum number of iterations. , _cGConfigTol :: !a -- ^ Tolerance. } makeFields ''CGConfig -- | Configuration for the Stochastic Reconfiguration algorithm. data SRConfig a = SRConfig { _sRConfigMaxIter :: !Int -- ^ Maximum number of iterations to perform. , _sRConfigRegulariser :: !(Maybe (Int -> ℂ)) -- ^ Regulariser for the S matrix. If it is @'Just' f@, -- then @λ = f i@ where @i@ is the currect iteration is used to -- regularise the matrix S according to @S <- S + λ1@. , _sRConfigRate :: !(Int -> ℂ) -- ^ Learning rate as a function of the iteration. , _sRConfigCg :: !(CGConfig ℝ) -- ^ Configuration for the Monte-Carlo sampling. , _sRConfigMc :: !MCConfig -- ^ Configuration for the Conjugate Gradient solver. } -- | Returns a slice of the vector. slice :: forall a s . Storable a => Int -- ^ Start index -> Int -- ^ Length -> MDenseVector 'Direct s a -- ^ Source vector -> MDenseVector 'Direct s a -- ^ Slice slice !i !n !(MDenseVector size stride buff) = MDenseVector n stride (MV.slice (stride * i) (stride * n) buff) makeFields ''SRConfig type family RealOf a :: * type instance RealOf Float = Float type instance RealOf Double = Double type instance RealOf (Complex a) = a mallocVectorAligned :: forall a. Storable a => Int -> Int -> IO (ForeignPtr a) mallocVectorAligned n alignment = mallocPlainForeignPtrAlignedBytes (n * sizeOf (undefined :: a)) alignment newVectorAligned :: (Storable a, PrimMonad m) => Int -> Int -> m (MVector (PrimState m) a) newVectorAligned n alignment = unsafePrimToPrim $! MVector n <$> mallocVectorAligned n alignment newDenseVector :: (Storable a, PrimMonad m) => Int -> m (MDenseVector 'Direct (PrimState m) a) newDenseVector n = MDenseVector n 1 <$> newVectorAligned n 64 -- | Default alignment used when allocating new vectors and matrices. defaultAlignment :: Int defaultAlignment = 64 roundUpTo :: Int -> Int -> Int {-# INLINE roundUpTo #-} roundUpTo !alignment !n = assert (isValidAlignment alignment && n >= 0) $ (n + alignment - 1) .&. complement (alignment - 1) where isValidAlignment !x = x > 0 && (x .&. (x - 1) == 0) newDenseMatrix :: forall orient a m. (Storable a, SingI orient, PrimMonad m) => Int -> Int -> m (MDenseMatrix orient (PrimState m) a) newDenseMatrix rows cols = case (sing :: Sing orient) of SRow -> let ldim = assert (defaultAlignment `mod` sizeOf (undefined :: a) == 0) $ roundUpTo (defaultAlignment `div` sizeOf (undefined :: a)) cols in MDenseMatrix rows cols ldim <$> newVectorAligned (rows * ldim) defaultAlignment SColumn -> let ldim = roundUpTo defaultAlignment rows in MDenseMatrix rows cols ldim <$> newVectorAligned (ldim * cols) defaultAlignment class HasOrientation s a | s -> a where orientationOf :: s -> a instance SingI orient => HasOrientation (DenseMatrix orient a) Orientation where orientationOf _ = fromSing (sing :: Sing orient) instance SingI orient => HasOrientation (Mutable (DenseMatrix orient) s a) Orientation where orientationOf _ = fromSing (sing :: Sing orient) isValidMatrix :: Orientation -- ^ Row- vs. column-major layout -> Int -- ^ Number of rows -> Int -- ^ Number of columns -> Int -- ^ Stride -> Int -- ^ Buffer size -> Bool isValidMatrix orient rows cols i size = i >= 0 && (rows == 0 && cols == 0 || rows > 0 && cols > 0 && validAccesses orient) where validAccesses Row = (rows - 1) * i < size && cols <= i validAccesses Column = (cols - 1) * i < size && rows <= i -- | Constructs a nice message describing the problem in the BLAS vector. badMatrixInfo :: String -- ^ Function name -> String -- ^ Argument name -> Int -- ^ Number of rows -> Int -- ^ Number of columns -> Int -- ^ Stride -> Int -- ^ Size of the underlying buffer -> String -- ^ Error message badMatrixInfo funcName argName rows cols i size | rows < 0 = preamble <> " has a negative number of rows: " <> show rows <> "." | cols < 0 = preamble <> " has a negative number of columns: " <> show cols <> "." | i < 0 = preamble <> " has a negative stride: " <> show i <> "." | otherwise = preamble <> " has invalid range of accesses: #rows = " <> show rows <> ", #cols = " <> show cols <> ", stride = " <> show i <> ", bufferSize = " <> show size <> "." where preamble = funcName <> ": " <> argName -- | Returns whether strides and dimensions are consistent. isValidVector :: Int -- ^ Logical dimension -> Int -- ^ Stride -> Int -- ^ Buffer size -> Bool isValidVector n i size = i >= 0 && (n == 0 || n > 0 && (n - 1) * i < size) -- | Constructs a nice message describing the problem in the BLAS vector. badVectorInfo :: String -- ^ Function name -> String -- ^ Argument name -> Int -- ^ Logical vector dimension -> Int -- ^ Vector stride -> Int -- ^ Size of the underlying buffer -> String -- ^ Error message badVectorInfo funcName argName n i size | n < 0 = preamble <> " has a negative logical dimension: " <> show n <> "." | i < 0 = preamble <> " has a negative stride: " <> show i <> "." | otherwise = preamble <> " has invalid range of accesses: dim = " <> show n <> ", stride = " <> show i <> ", bufferSize = " <> show size <> "." where preamble = funcName <> ": " <> argName class CheckValid a where assertValid :: String -> String -> a -> b -> b instance Storable a => CheckValid (DenseVector variant a) where assertValid funcName argName !(DenseVector dim stride (V.length -> size)) | isValidVector dim stride size = id | otherwise = error $! badVectorInfo funcName argName dim stride size instance Storable a => CheckValid (Mutable (DenseVector variant) s a) where assertValid funcName argName !(MDenseVector dim stride (MV.length -> size)) | isValidVector dim stride size = id | otherwise = error $! badVectorInfo funcName argName dim stride size instance (Storable a, SingI orient) => CheckValid (DenseMatrix orient a) where assertValid funcName argName !m@(DenseMatrix rows cols stride (V.length -> size)) | isValidMatrix (orientationOf m) rows cols stride size = id | otherwise = error $! badMatrixInfo funcName argName rows cols stride size instance (Storable a, SingI orient) => CheckValid (Mutable (DenseMatrix orient) s a) where assertValid funcName argName !m@(MDenseMatrix rows cols stride (MV.length -> size)) | isValidMatrix (orientationOf m) rows cols stride size = id | otherwise = error $! badMatrixInfo funcName argName rows cols stride size instance Storable a => HasBuffer (MDenseVector variant s a) (MVector s a) where buffer inj (MDenseVector dim stride buf) = MDenseVector dim stride <$> inj buf instance Storable a => HasBuffer (MDenseMatrix orientation s a) (MVector s a) where buffer inj (MDenseMatrix rows cols stride buf) = MDenseMatrix rows cols stride <$> inj buf instance Storable a => HasStride (MDenseVector variant s a) Int where stride inj (MDenseVector dim stride buf) = (\x -> MDenseVector dim x buf) <$> inj stride instance Storable a => HasStride (MDenseMatrix orientation s a) Int where stride inj (MDenseMatrix rows cols stride buf) = (\x -> MDenseMatrix rows cols x buf) <$> inj stride instance Storable a => HasDim (MDenseVector variant s a) Int where dim inj (MDenseVector dim stride buf) = (\x -> MDenseVector x stride buf) <$> inj dim instance Storable a => HasDim (MDenseMatrix orientation s a) (Int, Int) where dim inj (MDenseMatrix rows cols stride buf) = (\(x, y) -> MDenseMatrix x y stride buf) <$> inj (rows, cols) instance Storable a => HasDim (DenseMatrix orientation a) (Int, Int) where dim inj (DenseMatrix rows cols stride buf) = (\(x, y) -> DenseMatrix x y stride buf) <$> inj (rows, cols) class FreezeThaw (v :: * -> *) a where unsafeFreeze :: PrimMonad m => (Mutable v) (PrimState m) a -> m (v a) unsafeThaw :: PrimMonad m => v a -> m ((Mutable v) (PrimState m) a) instance Storable a => FreezeThaw (DenseVector variant) a where unsafeFreeze (MDenseVector dim stride mv) = DenseVector dim stride <$> V.unsafeFreeze mv unsafeThaw (DenseVector dim stride mv) = MDenseVector dim stride <$> V.unsafeThaw mv instance Storable a => FreezeThaw (DenseMatrix orientation) a where unsafeFreeze (MDenseMatrix rows cols stride mv) = DenseMatrix rows cols stride <$> V.unsafeFreeze mv unsafeThaw (DenseMatrix rows cols stride v) = MDenseMatrix rows cols stride <$> V.unsafeThaw v touchForeignPtrPrim :: PrimMonad m => ForeignPtr a -> m () {-# NOINLINE touchForeignPtrPrim #-} touchForeignPtrPrim fp = unsafeIOToPrim $! touchForeignPtr fp withForeignPtrPrim :: PrimMonad m => ForeignPtr a -> (Ptr a -> m b) -> m b {-# INLINE withForeignPtrPrim #-} withForeignPtrPrim p func = do r <- func (unsafeForeignPtrToPtr p) touchForeignPtrPrim p return r mapVectorM :: (PrimMonad m, Storable a, Storable b) => (a -> m b) -> MDenseVector 'Direct (PrimState m) a -> MDenseVector 'Direct (PrimState m) b -> m () mapVectorM f x y = assertValid "NQS.Rbm.zipWithVectorM" "x" x $ assertValid "NQS.Rbm.zipWithVectorM" "x" y $ assert (x ^. dim == y ^. dim) $ go 0 where n = x ^. dim go !i | i == n = return () | otherwise = do xi <- unsafeReadVector x i yi <- f xi unsafeWriteVector y i yi go (i + 1) zipWithVectorM :: (PrimMonad m, Storable a, Storable b, Storable c) => (a -> b -> m c) -> MDenseVector 'Direct (PrimState m) a -> MDenseVector 'Direct (PrimState m) b -> MDenseVector 'Direct (PrimState m) c -> m () zipWithVectorM f x y z = assertValid "NQS.Rbm.zipWithVectorM" "x" x $ assertValid "NQS.Rbm.zipWithVectorM" "x" y $ assertValid "NQS.Rbm.zipWithVectorM" "x" z $ assert (y ^. dim == n && z ^. dim == n) $ go 0 where n = x ^. dim go !i | i == n = return () | otherwise = do xi <- unsafeReadVector x i yi <- unsafeReadVector y i zi <- f xi yi unsafeWriteVector z i zi go (i + 1) mapMatrixM :: forall m a b orientX orientY. (PrimMonad m, Storable a, Storable b, SingI orientX, SingI orientY) => (a -> m b) -> MDenseMatrix orientX (PrimState m) a -> MDenseMatrix orientY (PrimState m) b -> m () mapMatrixM f x y = assertValid "NQS.Rbm.zipWithMatrixM" "x" x $ assertValid "NQS.Rbm.zipWithMatrixM" "y" y $ assert (x ^. dim == y ^. dim) $ case (sing :: Sing orientY) of SRow -> stepperRow 0 0 SColumn -> stepperColumn 0 0 where !(n, m) = x ^. dim stepperRow !i !j | j < m && i < n = go i j >> stepperRow i (j + 1) | i < n = stepperRow (i + 1) 0 | otherwise = return () stepperColumn !i !j | i < n && j < m = go i j >> stepperColumn (i + 1) j | j < m = stepperColumn 0 (j + 1) | otherwise = return () go !i !j = do xij <- unsafeReadMatrix x (i, j) yij <- f xij unsafeWriteMatrix y (i, j) yij zipWithMatrixM :: forall m a b c orientX orientY orientZ. (PrimMonad m, Storable a, Storable b, Storable c, SingI orientX, SingI orientY, SingI orientZ) => (a -> b -> m c) -> MDenseMatrix orientX (PrimState m) a -> MDenseMatrix orientY (PrimState m) b -> MDenseMatrix orientZ (PrimState m) c -> m () zipWithMatrixM f x y z = assertValid "NQS.Rbm.zipWithMatrixM" "x" x $ assertValid "NQS.Rbm.zipWithMatrixM" "y" y $ assertValid "NQS.Rbm.zipWithMatrixM" "z" z $ assert (y ^. dim == (n, m) && z ^. dim == (n, m)) $ case (sing :: Sing orientZ) of SRow -> stepperRow 0 0 SColumn -> stepperColumn 0 0 where !(n, m) = x ^. dim stepperRow !i !j | j < m && i < n = go i j >> stepperRow i (j + 1) | i < n = stepperRow (i + 1) 0 | otherwise = return () stepperColumn !i !j | i < n && j < m = go i j >> stepperColumn (i + 1) j | j < m = stepperColumn 0 (j + 1) | otherwise = return () go !i !j = do xij <- unsafeReadMatrix x (i, j) yij <- unsafeReadMatrix y (i, j) zij <- f xij yij unsafeWriteMatrix z (i, j) zij {- withRbm :: PrimMonad m => Rbm a -> (Ptr (RbmCore a) -> m b) -> m b withRbm (Rbm p) func = withForeignPtrPrim p func withRbmPure :: Rbm a -> (Ptr (RbmCore a) -> b) -> b withRbmPure (Rbm p) func = unsafePerformIO $! withForeignPtrPrim p (return . func) withMRbm :: PrimMonad m => MRbm (PrimState m) a -> (Ptr (RbmCore a) -> m b) -> m b withMRbm (MRbm p) func = withForeignPtrPrim p func withMRbmPure :: MRbm s a -> (Ptr (RbmCore a) -> b) -> b withMRbmPure (MRbm p) func = unsafePerformIO $! withForeignPtr p (return . func) -} data Estimate e a = Estimate { estPoint :: !a , estError :: !(e a) } deriving (Generic, NFData) newtype NormalError a = NormalError a deriving (Eq, Ord, Read, Show, Generic, NFData) data EnergyMeasurement a = EnergyMeasurement { _energyMeasurementMean :: !a , _energyMeasurementVar :: !a } deriving (Generic) makeFields ''EnergyMeasurement -- | Simple for loop. Counts from /start/ to /end/-1. for :: Monad m => Int -> Int -> (Int -> m ()) -> m () for !start !end f = assert (start <= end) $ loop start where loop !i | i == end = return () | otherwise = f i >> loop (i + 1) {-# INLINE for #-} for' :: Monad m => a -> Int -> (a -> Int -> m a) -> m a for' !x0 !n f = assert (n >= 0) $ loop x0 0 where loop !x !i | i == n = return x | otherwise = f x i >>= \x' -> loop x' (i + 1) {-# INLINE for' #-} generateVectorM :: forall a m . (Monad m, Storable a) => Int -> (Int -> m a) -> m (DenseVector 'Direct a) {-# NOINLINE generateVectorM #-} generateVectorM !n f | n < 0 = error $! "generateVectorM: Invalid dimension: " <> show n | n == 0 = return $! DenseVector 0 0 V.empty | otherwise = go (runST $ newDenseVector n >>= unsafeFreeze) where go :: DenseVector 'Direct a -> m (DenseVector 'Direct a) go !v' = for' v' n $ \v i -> f i >>= \x -> return (set v i x) set !v !i !x = runST $ do !v' <- unsafeThaw v unsafeWriteVector v' i x unsafeFreeze v' generateMatrixM :: forall orient m a. (Monad m, Storable a, SingI orient) => Int -> Int -> (Int -> Int -> m a) -> m (DenseMatrix orient a) {-# NOINLINE generateMatrixM #-} generateMatrixM !rows !cols f | rows < 0 || cols < 0 = error $! "generateMatrixM: Invalid dimensions: " <> show (rows, cols) | rows == 0 || cols == 0 = return $! DenseMatrix 0 0 0 V.empty | otherwise = go (runST $ newDenseMatrix rows cols >>= unsafeFreeze) where go :: DenseMatrix orient a -> m (DenseMatrix orient a) go !m'' = case (sing :: Sing orient) of SRow -> for' m'' rows $ \m' i -> for' m' cols $ \m j -> f i j >>= \x -> return (set m i j x) SColumn -> for' m'' cols $ \m' j -> for' m' rows $ \m i -> f i j >>= \x -> return (set m i j x) set !m !i !j !x = runST $ do !m' <- unsafeThaw m unsafeWriteMatrix m' (i, j) x unsafeFreeze m' instance (Storable a, FromJSON a) => FromJSON (DenseVector 'Direct a) where parseJSON = withArray "vector elements (i.e. Array)" $ \v -> do generateVectorM (GV.length v) $ \i -> parseJSON (v `GV.unsafeIndex` i) instance ToJSON a => ToJSON (Complex a) where toJSON (x :+ y) = toJSON [x, y] toEncoding (x :+ y) = toEncoding [x, y] instance FromJSON a => FromJSON (Complex a) where parseJSON = withArray "Complex" $ \v -> (:+) <$> parseJSON (v GV.! 0) <*> parseJSON (v GV.! 1) instance (Storable a, FromJSON a, SingI orient) => FromJSON (DenseMatrix orient a) where parseJSON = withArray "Matrix rows" $ \matrix -> do (n, m) <- checkDimensions matrix generateMatrixM n m $ \i j -> flip (withArray "a matrix row") (matrix `GV.unsafeIndex` i) $ \row -> parseJSON (row `GV.unsafeIndex` j) where checkDimensions x@(GV.length -> n) | n == 0 = return (0, 0) | otherwise = do !m <- withArray "first row (i.e. Array)" (return . GV.length) (GV.unsafeHead x) for 0 n $ \i -> flip (withArray "a matrix row (i.e. Array)") (x `GV.unsafeIndex` i) $ \row -> unless (GV.length row == m) $ fail $! "Matrix row #" <> show i <> " has wrong dimension." return (n, m) vectorAsVector :: Storable a => DenseVector 'Direct a -> Boxed.Vector a vectorAsVector !(DenseVector n stride buff) = Boxed.generate n (\i -> buff `V.unsafeIndex` (i * stride)) -- | Returns a row of a matrix. unsafeRowAsVector :: forall orient a . (Storable a, SingI orient) => Int -> DenseMatrix orient a -> Boxed.Vector a unsafeRowAsVector !i !(DenseMatrix rows cols stride buff) = assert (i < rows) $ case (sing :: Sing orient) of SRow -> GV.generate cols (\j -> buff `V.unsafeIndex` (i * stride + j)) SColumn -> GV.generate cols (\j -> buff `V.unsafeIndex` (i + j * stride)) instance (Storable a, ToJSON a) => ToJSON (DenseVector 'Direct a) where toEncoding = toEncoding . vectorAsVector instance (Storable a, ToJSON a, SingI orient) => ToJSON (DenseMatrix orient a) where toEncoding x = toEncoding $ Boxed.generate (x ^. dim . _1) (\i -> unsafeRowAsVector i x)
//////////////////////////////////////////////////////////////////////////////////////////////////// // iterator.hpp // Proto callables for std functions found in \<iterator\> // // Copyright 2012 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PROTO_V5_FUNCTIONAL_STD_ITERATOR_HPP_INCLUDED #define BOOST_PROTO_V5_FUNCTIONAL_STD_ITERATOR_HPP_INCLUDED #include <iterator> #include <boost/proto/v5/proto_fwd.hpp> namespace boost { namespace proto { inline namespace v5 { namespace functional { namespace std { // A PolymorphicFunctionObject wrapping std::advance struct advance { template<typename InputIterator, typename Distance> void operator()(InputIterator &x, Distance n) const noexcept(noexcept(std::advance(x, n))) { ::std::advance(x, n); } }; // A PolymorphicFunctionObject wrapping std::distance struct distance { template<typename InputIterator> auto operator()(InputIterator first, InputIterator last) const BOOST_PROTO_AUTO_RETURN( ::std::distance(first, last) ) }; // A PolymorphicFunctionObject wrapping std::next struct next { template<typename ForwardIterator> ForwardIterator operator()( ForwardIterator x , typename ::std::iterator_traits<ForwardIterator>::difference_type n = 1 ) const noexcept(noexcept(ForwardIterator(std::next(x, n)))) { return ::std::next(x, n); } }; // A PolymorphicFunctionObject wrapping std::prior struct prior { template<typename BidirectionalIterator> BidirectionalIterator operator()( BidirectionalIterator x , typename ::std::iterator_traits<BidirectionalIterator>::difference_type n = 1 ) const noexcept(noexcept(BidirectionalIterator(std::advance(x, -n)))) { return ::std::advance(x, -n); } }; } } } } } #endif
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel -/ import analysis.calculus.mean_value import analysis.special_functions.pow_deriv import analysis.special_functions.sqrt /-! # Collection of convex functions In this file we prove that the following functions are convex: * `strict_convex_on_exp` : The exponential function is strictly convex. * `even.convex_on_pow`, `even.strict_convex_on_pow` : For an even `n : ℕ`, `λ x, x ^ n` is convex and strictly convex when `2 ≤ n`. * `convex_on_pow`, `strict_convex_on_pow` : For `n : ℕ`, `λ x, x ^ n` is convex on $[0, +∞)$ and strictly convex when `2 ≤ n`. * `convex_on_zpow`, `strict_convex_on_zpow` : For `m : ℤ`, `λ x, x ^ m` is convex on $[0, +∞)$ and strictly convex when `m ≠ 0, 1`. * `convex_on_rpow`, `strict_convex_on_rpow` : For `p : ℝ`, `λ x, x ^ p` is convex on $[0, +∞)$ when `1 ≤ p` and strictly convex when `1 < p`. * `strict_concave_on_log_Ioi`, `strict_concave_on_log_Iio`: `real.log` is strictly concave on $(0, +∞)$ and $(-∞, 0)$ respectively. ## TODO For `p : ℝ`, prove that `λ x, x ^ p` is concave when `0 ≤ p ≤ 1` and strictly concave when `0 < p < 1`. -/ open real set open_locale big_operators /-- `exp` is strictly convex on the whole real line. -/ lemma strict_convex_on_exp : strict_convex_on ℝ univ exp := strict_convex_on_univ_of_deriv2_pos differentiable_exp (λ x, (iter_deriv_exp 2).symm ▸ exp_pos x) /-- `exp` is convex on the whole real line. -/ lemma convex_on_exp : convex_on ℝ univ exp := strict_convex_on_exp.convex_on /-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even -/ lemma even.convex_on_pow {n : ℕ} (hn : even n) : convex_on ℝ set.univ (λ x : ℝ, x^n) := begin apply convex_on_univ_of_deriv2_nonneg (differentiable_pow n), { simp only [deriv_pow', differentiable.mul, differentiable_const, differentiable_pow] }, { intro x, obtain ⟨k, hk⟩ := (hn.tsub $ even_bit0 _).exists_two_nsmul _, rw [iter_deriv_pow, finset.prod_range_cast_nat_sub, hk, nsmul_eq_mul, pow_mul'], exact mul_nonneg (nat.cast_nonneg _) (pow_two_nonneg _) } end /-- `x^n`, `n : ℕ` is strictly convex on the whole real line whenever `n ≠ 0` is even. -/ lemma even.strict_convex_on_pow {n : ℕ} (hn : even n) (h : n ≠ 0) : strict_convex_on ℝ set.univ (λ x : ℝ, x^n) := begin apply strict_mono.strict_convex_on_univ_of_deriv (differentiable_pow n), rw deriv_pow', replace h := nat.pos_of_ne_zero h, exact strict_mono.const_mul (odd.strict_mono_pow $ nat.even.sub_odd h hn $ nat.odd_iff.2 rfl) (nat.cast_pos.2 h), end /-- `x^n`, `n : ℕ` is convex on `[0, +∞)` for all `n` -/ lemma convex_on_pow (n : ℕ) : convex_on ℝ (Ici 0) (λ x : ℝ, x^n) := begin apply convex_on_of_deriv2_nonneg (convex_Ici _) (continuous_pow n).continuous_on (differentiable_on_pow n), { simp only [deriv_pow'], exact (@differentiable_on_pow ℝ _ _ _).const_mul (n : ℝ) }, { intros x hx, rw [iter_deriv_pow, finset.prod_range_cast_nat_sub], exact mul_nonneg (nat.cast_nonneg _) (pow_nonneg (interior_subset hx) _) } end /-- `x^n`, `n : ℕ` is strictly convex on `[0, +∞)` for all `n` greater than `2`. -/ lemma strict_convex_on_pow {n : ℕ} (hn : 2 ≤ n) : strict_convex_on ℝ (Ici 0) (λ x : ℝ, x^n) := begin apply strict_mono_on.strict_convex_on_of_deriv (convex_Ici _) (continuous_on_pow _) (differentiable_on_pow n), rw [deriv_pow', interior_Ici], exact λ x (hx : 0 < x) y hy hxy, mul_lt_mul_of_pos_left (pow_lt_pow_of_lt_left hxy hx.le $ nat.sub_pos_of_lt hn) (nat.cast_pos.2 $ zero_lt_two.trans_le hn), end lemma finset.prod_nonneg_of_card_nonpos_even {α β : Type*} [linear_ordered_comm_ring β] {f : α → β} [decidable_pred (λ x, f x ≤ 0)] {s : finset α} (h0 : even (s.filter (λ x, f x ≤ 0)).card) : 0 ≤ ∏ x in s, f x := calc 0 ≤ (∏ x in s, ((if f x ≤ 0 then (-1:β) else 1) * f x)) : finset.prod_nonneg (λ x _, by { split_ifs with hx hx, by simp [hx], simp at hx ⊢, exact le_of_lt hx }) ... = _ : by rw [finset.prod_mul_distrib, finset.prod_ite, finset.prod_const_one, mul_one, finset.prod_const, neg_one_pow_eq_pow_mod_two, nat.even_iff.1 h0, pow_zero, one_mul] lemma int_prod_range_nonneg (m : ℤ) (n : ℕ) (hn : even n) : 0 ≤ ∏ k in finset.range n, (m - k) := begin rcases hn with ⟨n, rfl⟩, induction n with n ihn, { simp }, rw ← two_mul at ihn, rw [← two_mul, nat.succ_eq_add_one, mul_add, mul_one, bit0, ← add_assoc, finset.prod_range_succ, finset.prod_range_succ, mul_assoc], refine mul_nonneg ihn _, generalize : (1 + 1) * n = k, cases le_or_lt m k with hmk hmk, { have : m ≤ k + 1, from hmk.trans (lt_add_one ↑k).le, exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) (sub_nonpos_of_le this) }, { exact mul_nonneg (sub_nonneg_of_le hmk.le) (sub_nonneg_of_le hmk) } end lemma int_prod_range_pos {m : ℤ} {n : ℕ} (hn : even n) (hm : m ∉ Ico (0 : ℤ) n) : 0 < ∏ k in finset.range n, (m - k) := begin refine (int_prod_range_nonneg m n hn).lt_of_ne (λ h, hm _), rw [eq_comm, finset.prod_eq_zero_iff] at h, obtain ⟨a, ha, h⟩ := h, rw sub_eq_zero.1 h, exact ⟨int.coe_zero_le _, int.coe_nat_lt.2 $ finset.mem_range.1 ha⟩, end /-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` -/ lemma convex_on_zpow (m : ℤ) : convex_on ℝ (Ioi 0) (λ x : ℝ, x^m) := begin have : ∀ n : ℤ, differentiable_on ℝ (λ x, x ^ n) (Ioi (0 : ℝ)), from λ n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _), apply convex_on_of_deriv2_nonneg (convex_Ioi 0); try { simp only [interior_Ioi, deriv_zpow'] }, { exact (this _).continuous_on }, { exact this _ }, { exact (this _).const_mul _ }, { intros x hx, rw iter_deriv_zpow, refine mul_nonneg _ (zpow_nonneg (le_of_lt hx) _), exact_mod_cast int_prod_range_nonneg _ _ (even_bit0 1) } end /-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` except `0` and `1`. -/ lemma strict_convex_on_zpow {m : ℤ} (hm₀ : m ≠ 0) (hm₁ : m ≠ 1) : strict_convex_on ℝ (Ioi 0) (λ x : ℝ, x^m) := begin have : ∀ n : ℤ, differentiable_on ℝ (λ x, x ^ n) (Ioi (0 : ℝ)), from λ n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _), apply strict_convex_on_of_deriv2_pos (convex_Ioi 0), { exact (this _).continuous_on }, all_goals { rw interior_Ioi }, { exact this _ }, intros x hx, rw iter_deriv_zpow, refine mul_pos _ (zpow_pos_of_pos hx _), exact_mod_cast int_prod_range_pos (even_bit0 1) (λ hm, _), norm_cast at hm, rw ← finset.coe_Ico at hm, fin_cases hm; cc, end lemma convex_on_rpow {p : ℝ} (hp : 1 ≤ p) : convex_on ℝ (Ici 0) (λ x : ℝ, x^p) := begin have A : deriv (λ (x : ℝ), x ^ p) = λ x, p * x^(p-1), by { ext x, simp [hp] }, apply convex_on_of_deriv2_nonneg (convex_Ici 0), { exact continuous_on_id.rpow_const (λ x _, or.inr (zero_le_one.trans hp)) }, { exact (differentiable_rpow_const hp).differentiable_on }, { rw A, assume x hx, replace hx : x ≠ 0, by { simp at hx, exact ne_of_gt hx }, simp [differentiable_at.differentiable_within_at, hx] }, { assume x hx, replace hx : 0 < x, by simpa using hx, suffices : 0 ≤ p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A], apply mul_nonneg (le_trans zero_le_one hp), exact mul_nonneg (sub_nonneg_of_le hp) (rpow_nonneg_of_nonneg hx.le _) } end lemma strict_convex_on_rpow {p : ℝ} (hp : 1 < p) : strict_convex_on ℝ (Ici 0) (λ x : ℝ, x^p) := begin have A : deriv (λ (x : ℝ), x ^ p) = λ x, p * x^(p-1), by { ext x, simp [hp.le] }, apply strict_convex_on_of_deriv2_pos (convex_Ici 0), { exact continuous_on_id.rpow_const (λ x _, or.inr (zero_le_one.trans hp.le)) }, { exact (differentiable_rpow_const hp.le).differentiable_on }, rw interior_Ici, rintro x (hx : 0 < x), suffices : 0 < p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A], exact mul_pos (zero_lt_one.trans hp) (mul_pos (sub_pos_of_lt hp) (rpow_pos_of_pos hx _)), end lemma strict_concave_on_log_Ioi : strict_concave_on ℝ (Ioi 0) log := begin have h₁ : Ioi 0 ⊆ ({0} : set ℝ)ᶜ, { exact λ x (hx : 0 < x) (hx' : x = 0), hx.ne' hx' }, refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 0) is_open_Ioi (differentiable_on_log.mono h₁) (λ x (hx : 0 < x), _), rw [function.iterate_succ, function.iterate_one], change (deriv (deriv log)) x < 0, rw [deriv_log', deriv_inv], exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne'), end lemma strict_concave_on_log_Iio : strict_concave_on ℝ (Iio 0) log := begin have h₁ : Iio 0 ⊆ ({0} : set ℝ)ᶜ, { exact λ x (hx : x < 0) (hx' : x = 0), hx.ne hx' }, refine strict_concave_on_open_of_deriv2_neg (convex_Iio 0) is_open_Iio (differentiable_on_log.mono h₁) (λ x (hx : x < 0), _), rw [function.iterate_succ, function.iterate_one], change (deriv (deriv log)) x < 0, rw [deriv_log', deriv_inv], exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne), end section sqrt_mul_log lemma has_deriv_at_sqrt_mul_log {x : ℝ} (hx : x ≠ 0) : has_deriv_at (λ x, sqrt x * log x) ((2 + log x) / (2 * sqrt x)) x := begin convert (has_deriv_at_sqrt hx).mul (has_deriv_at_log hx), rw [add_div, div_mul_right (sqrt x) two_ne_zero, ←div_eq_mul_inv, sqrt_div_self', add_comm, div_eq_mul_one_div, mul_comm], end lemma deriv_sqrt_mul_log (x : ℝ) : deriv (λ x, sqrt x * log x) x = (2 + log x) / (2 * sqrt x) := begin cases lt_or_le 0 x with hx hx, { exact (has_deriv_at_sqrt_mul_log hx.ne').deriv }, { rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero], refine has_deriv_within_at.deriv_eq_zero _ (unique_diff_on_Iic 0 x hx), refine (has_deriv_within_at_const x _ 0).congr_of_mem (λ x hx, _) hx, rw [sqrt_eq_zero_of_nonpos hx, zero_mul] }, end lemma deriv_sqrt_mul_log' : deriv (λ x, sqrt x * log x) = λ x, (2 + log x) / (2 * sqrt x) := funext deriv_sqrt_mul_log lemma deriv2_sqrt_mul_log (x : ℝ) : deriv^[2] (λ x, sqrt x * log x) x = -log x / (4 * sqrt x ^ 3) := begin simp only [nat.iterate, deriv_sqrt_mul_log'], cases le_or_lt x 0 with hx hx, { rw [sqrt_eq_zero_of_nonpos hx, zero_pow zero_lt_three, mul_zero, div_zero], refine has_deriv_within_at.deriv_eq_zero _ (unique_diff_on_Iic 0 x hx), refine (has_deriv_within_at_const _ _ 0).congr_of_mem (λ x hx, _) hx, rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero] }, { have h₀ : sqrt x ≠ 0, from sqrt_ne_zero'.2 hx, convert (((has_deriv_at_log hx.ne').const_add 2).div ((has_deriv_at_sqrt hx.ne').const_mul 2) $ mul_ne_zero two_ne_zero h₀).deriv using 1, nth_rewrite 2 [← mul_self_sqrt hx.le], field_simp, ring }, end lemma strict_concave_on_sqrt_mul_log_Ioi : strict_concave_on ℝ (set.Ioi 1) (λ x, sqrt x * log x) := begin refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 1) is_open_Ioi (λ x hx, _) (λ x hx, _), { have h₀ : x ≠ 0, from (one_pos.trans hx.out).ne', exact (has_deriv_at_sqrt_mul_log h₀).differentiable_at.differentiable_within_at }, { rw [deriv2_sqrt_mul_log x], exact div_neg_of_neg_of_pos (neg_neg_of_pos (log_pos hx)) (mul_pos four_pos (pow_pos (sqrt_pos.mpr (zero_lt_one.trans hx)) 3)) }, end end sqrt_mul_log open_locale real lemma strict_concave_on_sin_Icc : strict_concave_on ℝ (Icc 0 π) sin := begin apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_sin differentiable_sin.differentiable_on (λ x hx, _), rw interior_Icc at hx, simp [sin_pos_of_mem_Ioo hx], end lemma strict_concave_on_cos_Icc : strict_concave_on ℝ (Icc (-(π/2)) (π/2)) cos := begin apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_cos differentiable_cos.differentiable_on (λ x hx, _), rw interior_Icc at hx, simp [cos_pos_of_mem_Ioo hx], end
[STATEMENT] lemma Propagate_Black_aux: "\<turnstile> Propagate_Black_aux \<lbrace>\<acute>Proper \<and> Roots\<subseteq>Blacks \<acute>M \<and> \<acute>obc\<subseteq>Blacks \<acute>M \<and> \<acute>bc\<subseteq>Blacks \<acute>M \<and> ( \<acute>obc < Blacks \<acute>M \<or> \<acute>Safe)\<rbrace>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<turnstile> Propagate_Black_aux \<lbrace>\<acute>Proper \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> \<acute>Safe)\<rbrace> [PROOF STEP] apply (unfold Propagate_Black_aux_def PBInv_def collector_defs) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<turnstile> \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M\<rbrace> \<acute>ind := 0;; \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> \<acute>ind = 0\<rbrace> WHILE \<acute>ind < length \<acute>E INV \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> DO \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> IF \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black THEN \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<acute>M := \<acute>M[snd (\<acute>E ! \<acute>ind) := Black];; \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind + 1. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind + 1. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<acute>ind := \<acute>ind + 1 FI OD \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply annhoare [PROOF STATE] proof (prove) goal (8 subgoals): 1. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M\<rbrace> \<subseteq> \<lbrace>\<acute>(ind_update (\<lambda>_. 0)) \<in> pre (\<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> \<acute>ind = 0\<rbrace> WHILE \<acute>ind < length \<acute>E INV \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> DO \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> IF \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black THEN \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<acute>M := \<acute>M[snd (\<acute>E ! \<acute>ind) := Black];; \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind + 1. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind + 1. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<acute>ind := \<acute>ind + 1 FI OD)\<rbrace> 2. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> \<acute>ind = 0\<rbrace> \<subseteq> \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> pre (\<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> IF \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black THEN \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<acute>M := \<acute>M[snd (\<acute>E ! \<acute>ind) := Black];; \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind + 1. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind + 1. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<acute>ind := \<acute>ind + 1 FI) 4. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> pre (\<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<acute>M := \<acute>M[snd (\<acute>E ! \<acute>ind) := Black];; \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind + 1. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind + 1. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<acute>ind := \<acute>ind + 1) 5. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>\<acute>(M_update (\<lambda>_. \<acute>M[snd (\<acute>E ! \<acute>ind) := Black])) \<in> pre (\<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind + 1. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind + 1. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<acute>ind := \<acute>ind + 1)\<rbrace> 6. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind + 1. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind + 1. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>\<acute>(ind_update (\<lambda>_. \<acute>ind + 1)) \<in> \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace>\<rbrace> 7. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 8. \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. \<not> BtoW (\<acute>E ! i, \<acute>M) \<or> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>(Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M) \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply(simp_all add:Graph6 Graph7 Graph8 Graph12) [PROOF STATE] proof (prove) goal (7 subgoals): 1. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> \<acute>ind = 0\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> Proper_Edges (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black], \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>obc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>bc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> (\<acute>obc \<subset> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black])))) \<and> \<acute>ind < length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 7. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply force [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> Proper_Edges (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black], \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>obc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>bc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> (\<acute>obc \<subset> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black])))) \<and> \<acute>ind < length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply force [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> Proper_Edges (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black], \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>obc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>bc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> (\<acute>obc \<subset> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black])))) \<and> \<acute>ind < length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply force \<comment> \<open>4 subgoals left\<close> [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E \<and> \<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> Proper_Edges (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black], \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>obc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> \<acute>bc \<subseteq> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<and> (\<acute>obc \<subset> Blacks (\<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black]) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M[snd (\<acute>E ! \<acute>ind) := Black])))) \<and> \<acute>ind < length \<acute>E\<rbrace> 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply clarify [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); obc x \<subset> Blacks (M x) \<or> (\<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))); ind x < length (E x); M x ! fst (E x ! ind x) = Black\<rbrakk> \<Longrightarrow> Proper_Roots ((M x)[snd (E x ! ind x) := Black]) \<and> Proper_Edges ((M x)[snd (E x ! ind x) := Black], E x) \<and> Blacks M_init = Roots \<and> length M_init = length (M x) \<and> Roots \<subseteq> Blacks ((M x)[snd (E x ! ind x) := Black]) \<and> obc x \<subseteq> Blacks ((M x)[snd (E x ! ind x) := Black]) \<and> bc x \<subseteq> Blacks ((M x)[snd (E x ! ind x) := Black]) \<and> (obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black])))) \<and> ind x < length (E x) 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply(simp add:Proper_Edges_def Proper_Roots_def Graph6 Graph7 Graph8 Graph12) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); obc x \<subset> Blacks (M x) \<or> (\<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))); ind x < length (E x); M x ! fst (E x ! ind x) = Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (erule disjE) [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; obc x \<subset> Blacks (M x)\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply(rule disjI1) [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; obc x \<subset> Blacks (M x)\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply(erule Graph13) [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black\<rbrakk> \<Longrightarrow> snd (E x ! ind x) < length (M x) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply force [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (case_tac "M x ! snd (E x ! ind x)=Black") [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) = Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (simp add: Graph10 BtoW_def) [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks (M x) \<or> (\<forall>i<Suc (ind x). M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black)) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (rule disjI2) [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black\<rbrakk> \<Longrightarrow> \<forall>i<Suc (ind x). M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply clarify [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; i < Suc (ind x); M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (erule less_SucE) [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i < ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 2. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 3. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (erule_tac x=i in allE , erule (1) notE impE) [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i < ind x; M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black)\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 2. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 3. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply simp [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>x. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black)\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 2. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 3. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply clarify [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; ind x \<le> r; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 2. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 3. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (drule_tac y = r in le_imp_less_or_eq) [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x < r \<or> ind x = r\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 2. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 3. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (erule disjE) [PROOF STATE] proof (prove) goal (7 subgoals): 1. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x < r\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 2. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x = r\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 3. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 4. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 7. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply (subgoal_tac "Suc (ind x)\<le>r") [PROOF STATE] proof (prove) goal (8 subgoals): 1. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x < r; Suc (ind x) \<le> r\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 2. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x < r\<rbrakk> \<Longrightarrow> Suc (ind x) \<le> r 3. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x = r\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 4. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 5. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 7. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 8. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply fast [PROOF STATE] proof (prove) goal (7 subgoals): 1. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x < r\<rbrakk> \<Longrightarrow> Suc (ind x) \<le> r 2. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x = r\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 3. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 4. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 7. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply arith [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>x r. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! R) = Black; M x ! T \<noteq> Black; R < ind x; \<not> z x; snd (E x ! R) = T; r < length (E x); M x ! fst (E x ! r) = Black; M x ! snd (E x ! r) \<noteq> Black; ind x = r\<rbrakk> \<Longrightarrow> \<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black 2. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 3. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 6. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply fast [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>x i. \<lbrakk>\<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. M x ! fst (E x ! i) = Black \<and> M x ! snd (E x ! i) \<noteq> Black \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black); M x ! snd (E x ! ind x) = Black; Roots \<noteq> {}; Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; M x ! fst (E x ! i) = Black; M x ! snd (E x ! i) \<noteq> Black; i = ind x\<rbrakk> \<Longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> M x ! fst (E x ! r) = Black \<and> M x ! snd (E x ! r) \<noteq> Black) 2. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 5. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply fast [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) \<or> (\<forall>i<Suc (ind x). BtoW (E x ! i, (M x)[snd (E x ! ind x) := Black]) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>Suc (ind x). r < length (E x) \<and> BtoW (E x ! r, (M x)[snd (E x ! ind x) := Black]))) 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply(rule disjI1) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> obc x \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply(erule subset_psubset_trans) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x)); M x ! snd (E x ! ind x) \<noteq> Black\<rbrakk> \<Longrightarrow> Blacks (M x) \<subset> Blacks ((M x)[snd (E x ! ind x) := Black]) 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply(erule Graph11) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x. \<lbrakk>Roots \<noteq> {} \<and> Roots \<subseteq> \<lbrace>\<acute>(<) (length (M x))\<rbrace>; \<forall>i<length (E x). fst (E x ! i) < length (M x) \<and> snd (E x ! i) < length (M x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); ind x < length (E x); M x ! fst (E x ! ind x) = Black; \<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))\<rbrakk> \<Longrightarrow> snd (E x ! ind x) < length (M x) 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 4. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply fast \<comment> \<open>3 subgoals left\<close> [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<Suc \<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>Suc \<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> Suc \<acute>ind \<le> length \<acute>E\<rbrace> 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 3. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply force [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind < length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>M ! fst (\<acute>E ! \<acute>ind) = Black\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> 2. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply force \<comment> \<open>last\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> (\<forall>i<\<acute>ind. BtoW (\<acute>E ! i, \<acute>M) \<longrightarrow> \<not> \<acute>z \<and> i = R \<and> snd (\<acute>E ! R) = T \<and> (\<exists>r\<ge>\<acute>ind. r < length \<acute>E \<and> BtoW (\<acute>E ! r, \<acute>M)))) \<and> \<acute>ind \<le> length \<acute>E\<rbrace> \<inter> - \<lbrace>\<acute>ind < length \<acute>E\<rbrace> \<subseteq> \<lbrace>Proper_Roots \<acute>M \<and> Proper_Edges (\<acute>M, \<acute>E) \<and> Blacks M_init = Roots \<and> length M_init = length \<acute>M \<and> Roots \<subseteq> Blacks \<acute>M \<and> \<acute>obc \<subseteq> Blacks \<acute>M \<and> \<acute>bc \<subseteq> Blacks \<acute>M \<and> (\<acute>obc \<subset> Blacks \<acute>M \<or> Reach \<acute>E \<subseteq> Blacks \<acute>M)\<rbrace> [PROOF STEP] apply clarify [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x xa. \<lbrakk>\<not> ind x < length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); obc x \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); obc x \<subset> Blacks (M x) \<or> (\<forall>i<ind x. BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>ind x. r < length (E x) \<and> BtoW (E x ! r, M x))); ind x \<le> length (E x); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> False [PROOF STEP] apply simp [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> False [PROOF STEP] apply(subgoal_tac "ind x = length (E x)") [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x)\<rbrakk> \<Longrightarrow> False 2. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply (simp) [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x)\<rbrakk> \<Longrightarrow> False 2. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply(drule Graph1) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x)\<rbrakk> \<Longrightarrow> Proper_Edges (M x, ?E263 x xa) 2. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x)\<rbrakk> \<Longrightarrow> \<forall>i<length (?E263 x xa). \<not> BtoW (?E263 x xa ! i, M x) 3. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x); Reach (?E263 x xa) \<subseteq> Blacks (M x)\<rbrakk> \<Longrightarrow> False 4. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply simp [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x)\<rbrakk> \<Longrightarrow> \<forall>i<length (E x). \<not> BtoW (E x ! i, M x) 2. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x); Reach (E x) \<subseteq> Blacks (M x)\<rbrakk> \<Longrightarrow> False 3. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply clarify [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<And>x xa i. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x); i < length (E x); BtoW (E x ! i, M x)\<rbrakk> \<Longrightarrow> False 2. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x); Reach (E x) \<subseteq> Blacks (M x)\<rbrakk> \<Longrightarrow> False 3. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply(erule allE, erule impE, assumption) [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<And>x xa i. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x); i < length (E x); BtoW (E x ! i, M x); BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x))\<rbrakk> \<Longrightarrow> False 2. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x); Reach (E x) \<subseteq> Blacks (M x)\<rbrakk> \<Longrightarrow> False 3. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply force [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<And>x xa. \<lbrakk>Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x); ind x = length (E x); Reach (E x) \<subseteq> Blacks (M x)\<rbrakk> \<Longrightarrow> False 2. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply force [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x xa. \<lbrakk>ind x = length (E x); Proper_Roots (M x); Proper_Edges (M x, E x); Blacks M_init = Roots; length M_init = length (M x); Roots \<subseteq> Blacks (M x); bc x \<subseteq> Blacks (M x); \<forall>i<length (E x). BtoW (E x ! i, M x) \<longrightarrow> \<not> z x \<and> i = R \<and> snd (E x ! R) = T \<and> (\<exists>r\<ge>length (E x). r < length (E x) \<and> BtoW (E x ! r, M x)); xa \<in> Reach (E x); xa \<notin> Blacks (M x); obc x = Blacks (M x)\<rbrakk> \<Longrightarrow> ind x = length (E x) [PROOF STEP] apply arith [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
//================================================================================================== /*! @file Defines the meta::scalar_of meta-function @copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) **/ //================================================================================================== #ifndef BOOST_SIMD_DETAIL_DISPATCH_META_SCALAR_OF_HPP_INCLUDED #define BOOST_SIMD_DETAIL_DISPATCH_META_SCALAR_OF_HPP_INCLUDED #include <boost/simd/detail/dispatch/detail/scalar_of.hpp> namespace boost { namespace dispatch { /*! @ingroup group-introspection @brief Compute the basic value type of an arbitrary type Retrieves the most embedded fundamental type of any given type, carrying over cv-qualifiers. @tparam T Type to analyze **/ template<typename T> struct scalar_of : ext::scalar_of<T> {}; template<typename T> struct scalar_of<T&> : ext::scalar_of<T> {}; template<typename T> struct scalar_of<T const> : ext::scalar_of<T> {}; template<typename T> struct scalar_of<T const&> : ext::scalar_of<T> {}; template<typename T> struct scalar_of<T&&> : ext::scalar_of<T> {}; /// Eager shortcut for scalar_of template<typename T> using scalar_of_t = typename scalar_of<T>::type; } } #endif
_ : Set _ : Set → Set
postulate T C D : Set instance I : {{_ : C}} → D d : {{_ : D}} → T t : T t = d
// (C) Copyright Matt Borland 2021. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_MATH_CCMATH #define BOOST_MATH_CCMATH #include <boost/math/ccmath/sqrt.hpp> #include <boost/math/ccmath/isinf.hpp> #include <boost/math/ccmath/isnan.hpp> #include <boost/math/ccmath/abs.hpp> #include <boost/math/ccmath/fabs.hpp> #include <boost/math/ccmath/isfinite.hpp> #include <boost/math/ccmath/isnormal.hpp> #include <boost/math/ccmath/fpclassify.hpp> #endif // BOOST_MATH_CCMATH
[GOAL] m k : ℕ ⊢ shiftl m (k + 1) = m * 2 ^ (k + 1) [PROOFSTEP] show bit0 (shiftl m k) = m * (2 ^ k * 2) [GOAL] m k : ℕ ⊢ bit0 (shiftl m k) = m * (2 ^ k * 2) [PROOFSTEP] rw [bit0_val, shiftl_eq_mul_pow m k, mul_comm 2, mul_assoc] [GOAL] m : ℕ ⊢ shiftl' true m 0 + 1 = (m + 1) * 2 ^ 0 [PROOFSTEP] simp [shiftl, shiftl', pow_zero, Nat.one_mul] [GOAL] m k : ℕ ⊢ shiftl' true m (k + 1) + 1 = (m + 1) * 2 ^ (k + 1) [PROOFSTEP] change bit1 (shiftl' true m k) + 1 = (m + 1) * (2 ^ k * 2) [GOAL] m k : ℕ ⊢ bit1 (shiftl' true m k) + 1 = (m + 1) * (2 ^ k * 2) [PROOFSTEP] rw [bit1_val] [GOAL] m k : ℕ ⊢ 2 * shiftl' true m k + 1 + 1 = (m + 1) * (2 ^ k * 2) [PROOFSTEP] change 2 * (shiftl' true m k + 1) = _ [GOAL] m k : ℕ ⊢ 2 * (shiftl' true m k + 1) = (m + 1) * (2 ^ k * 2) [PROOFSTEP] rw [shiftl'_tt_eq_mul_pow m k, mul_left_comm, mul_comm 2] [GOAL] m k : ℕ ⊢ div2 (m / 2 ^ k) = m / 2 ^ (k + 1) [PROOFSTEP] rw [div2_val, Nat.div_div_eq_div_mul, Nat.pow_succ] [GOAL] b : Bool m : ℕ h : m ≠ 0 n : ℕ ⊢ shiftl' b m n ≠ 0 [PROOFSTEP] induction n [GOAL] case zero b : Bool m : ℕ h : m ≠ 0 ⊢ shiftl' b m zero ≠ 0 [PROOFSTEP] simp [bit_ne_zero, shiftl', *] [GOAL] case succ b : Bool m : ℕ h : m ≠ 0 n✝ : ℕ n_ih✝ : shiftl' b m n✝ ≠ 0 ⊢ shiftl' b m (succ n✝) ≠ 0 [PROOFSTEP] simp [bit_ne_zero, shiftl', *] [GOAL] ⊢ size 0 = 0 [PROOFSTEP] simp [size] [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 ⊢ size (bit b n) = succ (size n) [PROOFSTEP] rw [size] [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 ⊢ binaryRec 0 (fun x x => succ) (bit b n) = succ (binaryRec 0 (fun x x => succ) n) [PROOFSTEP] conv => lhs rw [binaryRec] simp [h] [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 | binaryRec 0 (fun x x => succ) (bit b n) = succ (binaryRec 0 (fun x x => succ) n) [PROOFSTEP] lhs rw [binaryRec] simp [h] [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 | binaryRec 0 (fun x x => succ) (bit b n) = succ (binaryRec 0 (fun x x => succ) n) [PROOFSTEP] lhs rw [binaryRec] simp [h] [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 | binaryRec 0 (fun x x => succ) (bit b n) = succ (binaryRec 0 (fun x x => succ) n) [PROOFSTEP] lhs [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 | binaryRec 0 (fun x x => succ) (bit b n) [PROOFSTEP] rw [binaryRec] [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 | if n0 : bit b n = 0 then Eq.mpr (_ : ℕ = ℕ) 0 else let n' := div2 (bit b n); let_fun _x := (_ : bit (bodd (bit b n)) (div2 (bit b n)) = bit b n); Eq.mpr (_ : ℕ = ℕ) (succ (binaryRec 0 (fun x x => succ) n')) [PROOFSTEP] simp [h] [GOAL] b : Bool n : ℕ h : bit b n ≠ 0 ⊢ succ (binaryRec 0 (fun x x => succ) (div2 (bit b n))) = succ (binaryRec 0 (fun x x => succ) n) [PROOFSTEP] rw [div2_bit] [GOAL] ⊢ size (bit1 0) = 1 [PROOFSTEP] rw [size_bit1, size_zero] [GOAL] b : Bool m n : ℕ h : shiftl' b m n ≠ 0 ⊢ size (shiftl' b m n) = size m + n [PROOFSTEP] induction' n with n IH [GOAL] case zero b : Bool m n : ℕ h✝ : shiftl' b m n ≠ 0 h : shiftl' b m zero ≠ 0 ⊢ size (shiftl' b m zero) = size m + zero [PROOFSTEP] simp [shiftl'] at h ⊢ [GOAL] case succ b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : shiftl' b m (succ n) ≠ 0 ⊢ size (shiftl' b m (succ n)) = size m + succ n [PROOFSTEP] simp [shiftl'] at h ⊢ [GOAL] case succ b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : ¬bit b (shiftl' b m n) = 0 ⊢ size (bit b (shiftl' b m n)) = size m + succ n [PROOFSTEP] rw [size_bit h, Nat.add_succ] [GOAL] case succ b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : ¬bit b (shiftl' b m n) = 0 ⊢ succ (size (shiftl' b m n)) = succ (size m + n) [PROOFSTEP] by_cases s0 : shiftl' b m n = 0 <;> [skip; rw [IH s0]] [GOAL] case succ b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : ¬bit b (shiftl' b m n) = 0 ⊢ succ (size (shiftl' b m n)) = succ (size m + n) [PROOFSTEP] by_cases s0 : shiftl' b m n = 0 [GOAL] case pos b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : ¬bit b (shiftl' b m n) = 0 s0 : shiftl' b m n = 0 ⊢ succ (size (shiftl' b m n)) = succ (size m + n) [PROOFSTEP] skip [GOAL] case neg b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : ¬bit b (shiftl' b m n) = 0 s0 : ¬shiftl' b m n = 0 ⊢ succ (size (shiftl' b m n)) = succ (size m + n) [PROOFSTEP] rw [IH s0] [GOAL] case pos b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : ¬bit b (shiftl' b m n) = 0 s0 : shiftl' b m n = 0 ⊢ succ (size (shiftl' b m n)) = succ (size m + n) [PROOFSTEP] rw [s0] at h ⊢ [GOAL] case pos b : Bool m n✝ : ℕ h✝ : shiftl' b m n✝ ≠ 0 n : ℕ IH : shiftl' b m n ≠ 0 → size (shiftl' b m n) = size m + n h : ¬bit b 0 = 0 s0 : shiftl' b m n = 0 ⊢ succ (size 0) = succ (size m + n) [PROOFSTEP] cases b [GOAL] case pos.false m n✝ n : ℕ h✝ : shiftl' false m n✝ ≠ 0 IH : shiftl' false m n ≠ 0 → size (shiftl' false m n) = size m + n h : ¬bit false 0 = 0 s0 : shiftl' false m n = 0 ⊢ succ (size 0) = succ (size m + n) [PROOFSTEP] exact absurd rfl h [GOAL] case pos.true m n✝ n : ℕ h✝ : shiftl' true m n✝ ≠ 0 IH : shiftl' true m n ≠ 0 → size (shiftl' true m n) = size m + n h : ¬bit true 0 = 0 s0 : shiftl' true m n = 0 ⊢ succ (size 0) = succ (size m + n) [PROOFSTEP] have : shiftl' true m n + 1 = 1 := congr_arg (· + 1) s0 [GOAL] case pos.true m n✝ n : ℕ h✝ : shiftl' true m n✝ ≠ 0 IH : shiftl' true m n ≠ 0 → size (shiftl' true m n) = size m + n h : ¬bit true 0 = 0 s0 : shiftl' true m n = 0 this : shiftl' true m n + 1 = 1 ⊢ succ (size 0) = succ (size m + n) [PROOFSTEP] rw [shiftl'_tt_eq_mul_pow] at this [GOAL] case pos.true m n✝ n : ℕ h✝ : shiftl' true m n✝ ≠ 0 IH : shiftl' true m n ≠ 0 → size (shiftl' true m n) = size m + n h : ¬bit true 0 = 0 s0 : shiftl' true m n = 0 this : (m + 1) * 2 ^ n = 1 ⊢ succ (size 0) = succ (size m + n) [PROOFSTEP] obtain rfl := succ.inj (eq_one_of_dvd_one ⟨_, this.symm⟩) [GOAL] case pos.true n✝ n : ℕ h✝ : ¬bit true 0 = 0 h : shiftl' true 0 n✝ ≠ 0 IH : shiftl' true 0 n ≠ 0 → size (shiftl' true 0 n) = size 0 + n s0 : shiftl' true 0 n = 0 this : (0 + 1) * 2 ^ n = 1 ⊢ succ (size 0) = succ (size 0 + n) [PROOFSTEP] simp only [zero_add, one_mul] at this [GOAL] case pos.true n✝ n : ℕ h✝ : ¬bit true 0 = 0 h : shiftl' true 0 n✝ ≠ 0 IH : shiftl' true 0 n ≠ 0 → size (shiftl' true 0 n) = size 0 + n s0 : shiftl' true 0 n = 0 this : 2 ^ n = 1 ⊢ succ (size 0) = succ (size 0 + n) [PROOFSTEP] obtain rfl : n = 0 := Nat.eq_zero_of_le_zero (le_of_not_gt fun hn => ne_of_gt (pow_lt_pow_of_lt_right (by decide) hn) this) [GOAL] n✝ n : ℕ h✝ : ¬bit true 0 = 0 h : shiftl' true 0 n✝ ≠ 0 IH : shiftl' true 0 n ≠ 0 → size (shiftl' true 0 n) = size 0 + n s0 : shiftl' true 0 n = 0 this : 2 ^ n = 1 hn : n > 0 ⊢ 1 < 2 [PROOFSTEP] decide [GOAL] case pos.true n : ℕ h✝ : ¬bit true 0 = 0 h : shiftl' true 0 n ≠ 0 IH : shiftl' true 0 0 ≠ 0 → size (shiftl' true 0 0) = size 0 + 0 s0 : shiftl' true 0 0 = 0 this : 2 ^ 0 = 1 ⊢ succ (size 0) = succ (size 0 + 0) [PROOFSTEP] rfl [GOAL] n : ℕ ⊢ n < 2 ^ size n [PROOFSTEP] rw [← one_shiftl] [GOAL] n : ℕ ⊢ n < shiftl 1 (size n) [PROOFSTEP] have : ∀ {n}, n = 0 → n < shiftl 1 (size n) := by simp [GOAL] n : ℕ ⊢ ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) [PROOFSTEP] simp [GOAL] n : ℕ this : ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) ⊢ n < shiftl 1 (size n) [PROOFSTEP] apply binaryRec _ _ n [GOAL] n : ℕ this : ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) ⊢ 0 < shiftl 1 (size 0) [PROOFSTEP] apply this rfl [GOAL] n : ℕ this : ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) ⊢ ∀ (b : Bool) (n : ℕ), n < shiftl 1 (size n) → bit b n < shiftl 1 (size (bit b n)) [PROOFSTEP] intro b n IH [GOAL] n✝ : ℕ this : ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) b : Bool n : ℕ IH : n < shiftl 1 (size n) ⊢ bit b n < shiftl 1 (size (bit b n)) [PROOFSTEP] by_cases h : bit b n = 0 [GOAL] case pos n✝ : ℕ this : ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) b : Bool n : ℕ IH : n < shiftl 1 (size n) h : bit b n = 0 ⊢ bit b n < shiftl 1 (size (bit b n)) [PROOFSTEP] apply this h [GOAL] case neg n✝ : ℕ this : ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) b : Bool n : ℕ IH : n < shiftl 1 (size n) h : ¬bit b n = 0 ⊢ bit b n < shiftl 1 (size (bit b n)) [PROOFSTEP] rw [size_bit h, shiftl_succ] [GOAL] case neg n✝ : ℕ this : ∀ {n : ℕ}, n = 0 → n < shiftl 1 (size n) b : Bool n : ℕ IH : n < shiftl 1 (size n) h : ¬bit b n = 0 ⊢ bit b n < bit0 (shiftl 1 (size n)) [PROOFSTEP] exact bit_lt_bit0 _ IH [GOAL] m n : ℕ h : size m ≤ n ⊢ 2 > 0 [PROOFSTEP] decide [GOAL] m n : ℕ ⊢ m < 2 ^ n → size m ≤ n [PROOFSTEP] rw [← one_shiftl] [GOAL] m n : ℕ ⊢ m < shiftl 1 n → size m ≤ n [PROOFSTEP] revert n [GOAL] m : ℕ ⊢ ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n [PROOFSTEP] apply binaryRec _ _ m [GOAL] m : ℕ ⊢ ∀ {n : ℕ}, 0 < shiftl 1 n → size 0 ≤ n [PROOFSTEP] intro n [GOAL] m n : ℕ ⊢ 0 < shiftl 1 n → size 0 ≤ n [PROOFSTEP] simp [GOAL] m : ℕ ⊢ ∀ (b : Bool) (n : ℕ), (∀ {n_1 : ℕ}, n < shiftl 1 n_1 → size n ≤ n_1) → ∀ {n_1 : ℕ}, bit b n < shiftl 1 n_1 → size (bit b n) ≤ n_1 [PROOFSTEP] intro b m IH n h [GOAL] m✝ : ℕ b : Bool m : ℕ IH : ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n n : ℕ h : bit b m < shiftl 1 n ⊢ size (bit b m) ≤ n [PROOFSTEP] by_cases e : bit b m = 0 [GOAL] case pos m✝ : ℕ b : Bool m : ℕ IH : ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n n : ℕ h : bit b m < shiftl 1 n e : bit b m = 0 ⊢ size (bit b m) ≤ n [PROOFSTEP] simp [e] [GOAL] case neg m✝ : ℕ b : Bool m : ℕ IH : ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n n : ℕ h : bit b m < shiftl 1 n e : ¬bit b m = 0 ⊢ size (bit b m) ≤ n [PROOFSTEP] rw [size_bit e] [GOAL] case neg m✝ : ℕ b : Bool m : ℕ IH : ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n n : ℕ h : bit b m < shiftl 1 n e : ¬bit b m = 0 ⊢ succ (size m) ≤ n [PROOFSTEP] cases' n with n [GOAL] case neg.zero m✝ : ℕ b : Bool m : ℕ IH : ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n e : ¬bit b m = 0 h : bit b m < shiftl 1 zero ⊢ succ (size m) ≤ zero [PROOFSTEP] exact e.elim (Nat.eq_zero_of_le_zero (le_of_lt_succ h)) [GOAL] case neg.succ m✝ : ℕ b : Bool m : ℕ IH : ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n e : ¬bit b m = 0 n : ℕ h : bit b m < shiftl 1 (succ n) ⊢ succ (size m) ≤ succ n [PROOFSTEP] apply succ_le_succ (IH _) [GOAL] m✝ : ℕ b : Bool m : ℕ IH : ∀ {n : ℕ}, m < shiftl 1 n → size m ≤ n e : ¬bit b m = 0 n : ℕ h : bit b m < shiftl 1 (succ n) ⊢ m < shiftl 1 n [PROOFSTEP] apply lt_imp_lt_of_le_imp_le (fun h' => bit0_le_bit _ h') h [GOAL] m n : ℕ ⊢ m < size n ↔ 2 ^ m ≤ n [PROOFSTEP] rw [← not_lt, Decidable.iff_not_comm, not_lt, size_le] [GOAL] n : ℕ ⊢ 0 < size n ↔ 0 < n [PROOFSTEP] rw [lt_size] [GOAL] n : ℕ ⊢ 2 ^ 0 ≤ n ↔ 0 < n [PROOFSTEP] rfl [GOAL] n : ℕ ⊢ size n = 0 ↔ n = 0 [PROOFSTEP] have := @size_pos n [GOAL] n : ℕ this : 0 < size n ↔ 0 < n ⊢ size n = 0 ↔ n = 0 [PROOFSTEP] simp [pos_iff_ne_zero] at this [GOAL] n : ℕ this : ¬size n = 0 ↔ ¬n = 0 ⊢ size n = 0 ↔ n = 0 [PROOFSTEP] exact Decidable.not_iff_not.1 this [GOAL] n : ℕ ⊢ 1 < 2 [PROOFSTEP] decide [GOAL] n : ℕ ⊢ List.length (bits n) = size n [PROOFSTEP] induction' n using Nat.binaryRec' with b n h ih [GOAL] case z ⊢ List.length (bits 0) = size 0 [PROOFSTEP] simp [GOAL] case f b : Bool n : ℕ h : n = 0 → b = true ih : List.length (bits n) = size n ⊢ List.length (bits (bit b n)) = size (bit b n) [PROOFSTEP] rw [size_bit, bits_append_bit _ _ h] [GOAL] case f b : Bool n : ℕ h : n = 0 → b = true ih : List.length (bits n) = size n ⊢ List.length (b :: bits n) = succ (size n) [PROOFSTEP] simp [ih] [GOAL] case f b : Bool n : ℕ h : n = 0 → b = true ih : List.length (bits n) = size n ⊢ bit b n ≠ 0 [PROOFSTEP] simpa [bit_eq_zero_iff]
[STATEMENT] lemma sol_fres: "((y \<cdot> x) \<leftarrow> x = y) = (\<exists>z. y = z \<leftarrow> x)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (y \<cdot> x \<leftarrow> x = y) = (\<exists>z. y = z \<leftarrow> x) [PROOF STEP] by (metis fres_canc1 fres_canc2 fres_sol order.eq_iff fres_galois)
module Numeric.Digamma (digamma) where import Numeric.SpecFunctions (digamma)
% EEGLAB Toolbox to process EEG data % Version - see eeg_getversion() % % eeglab() - Matlab graphic user interface environment for % electrophysiological data analysis incorporating the ICA/EEG toolbox % (Makeig et al.) developed at CNL / The Salk Institute, 1997-2001. % Released 11/2002- as EEGLAB (Delorme, Makeig, et al.) at the Swartz Center % for Computational Neuroscience, Institute for Neural Computation, % University of California San Diego (http://sccn.ucsd.edu/). % User feedback welcome: email [email protected] % % Authors: Arnaud Delorme, Scott Makeig, with substantial contributions % from Colin Humphries, Sigurd Enghoff, Tzyy-Ping Jung, plus contributions % from Tony Bell, Te-Won Lee, Luca Finelli and other contributors. % % Description: % EEGLAB is Matlab software for processing continuous or event-related % EEG or other physiological data. It is designed for use by both novice and % expert Matlab users. In normal use, the EEGLAB graphic interface calls % graphic functions via pop-up function windows. The EEGLAB history mechanism % can save the resulting Matlab calls to disk for later incorporation into % Matlab scripts. A single data structure ('EEG') containing all dataset % parameters may be accessed and modified directly from the Matlab commandline. % EEGLAB now recognizes "plugins," sets of EEGLAB functions linked to the EEGLAB % main menu through an "eegplugin_[name].m" function (Ex. >> help eeplugin_besa.m). %
-- | Module for operating on vectors and matrices. It includes some functions -- for using bra-ket notation. module DiracLists where import Data.Complex import Data.List (transpose) -- This can be used to hide the standard operators. -- import Prelude hiding ((+)) -- import qualified Prelude -- | Function 'ket' provides basic functionality for producing vectors from the -- canonical basis. Vectors and matrices are represented as lists and are stored -- in column-order (as in Mathematica). Operations on vectors and matrices have -- to be defined using new operators. ket :: Int -> Int -> [Complex Double] ket d i = (take i zeros) ++ [1] ++ (take (d-1-i) zeros) where zeros = replicate (d-1) 0 -- | The 'norm' function calculates the Euclidean norm of a vector. norm :: [Complex Double] -> Double norm a = sqrt $ realPart $ sum [ x^2 | x<-a ] -- | The 'proj' function builds d-dimensional operator |i><j|. proj :: Int -> Int -> Int -> [Complex Double] proj d i j = outerWith (*) (ket d i) (ket d j) -- | The 'outer' defines the form of outer product resulting in paris of elements. outer :: [a] -> [b] -> [(a,b)] outer a b = [ (x,y) | x<-a, y<-b ] -- | General form of the outer product resulting in paris of elements. outerWith :: (a -> b -> c) -> [a] -> [b] -> [c] outerWith f a b = [ f x y | x<-a, y<-b ] -- | Kronecker product is defined in terms of the outer product. kron :: Num a => [a] -> [a] -> [a] kron a b = outerWith (*) a b -- | Function 'overlap' for calculating the inner product of two vectors. In -- Dirac notation this is represented as <v|w>. overlap :: Num a => [a] -> [a] -> a overlap vec1 vec2 = sum $ zipWith (*) vec1 vec2 -- | The scalar product is defined to be consistent with the other operators. It -- is identical with the 'overlap' function and it suppose to resemble the -- braket. (<>) :: [Complex Double] -> [Complex Double] -> Complex Double (<>) = overlap -- | Definition of the vector addition for two complex vectors. The standard '+' -- operator does not work, and it is not a good idead to hide it. (+>) :: [Complex Double] -> [Complex Double] -> [Complex Double] (+>) = zipWith (+) -- | The multiplication of a vector by a scalar. (.*) :: Complex Double -> [Complex Double] -> [Complex Double] (.*) c v = [ c*x | x<-v ] -- | Matrix-vector multiplication. (#>) :: [[Complex Double]] -> [Complex Double] -> [Complex Double] (#>) m v = [ overlap w v | w<-tm ] where tm = transpose m
import Smt theorem forallExists : ∀ x : Nat, ∃ y : Int, x ≤ y := by smt intro x apply Exists.intro case w => exact Int.ofNat x case h => induction x with | zero => decide | succ x _ => simp only [LE.le, Int.le, HSub.hSub, Sub.sub, Int.sub, Neg.neg, Int.neg, Int.negOfNat, HAdd.hAdd, Add.add, Int.add] simp only [Int.subNatNat, Nat.sub_self, Int.NonNeg.mk]
## ## A cow operation, artist unknown ## """ function surgery() A cow operation, artist unknown # Example ```jldoctest julia> cowsay("Removing the last bit of net wrap now", cow=Cowsay.surgery) _______________________________________ < Removing the last bit of net wrap now > --------------------------------------- \\ \\ / \\ \\/ (__) /\\ (oo) O O _\\/_ // * ( ) // \\ (\\\\ // \\( \\\\ ) ( \\\\ ) /\\ ___[\\______/^^^^^^^\\__/) o-)__ |\\__[=======______//________)__\\ \\|_______________//____________| ||| || //|| ||| ||| || @.|| ||| || \\/ .\\/ || . . '.'.` COW-OPERATION ``` """ function surgery(;eyes="oo", tongue=" ", thoughts="\\") the_cow = """ $thoughts \\ / $thoughts \\/ (__) /\\ ($eyes) O O _\\/_ // * ( ) // \\ (\\\\ // \\( \\\\ ) ( \\\\ ) /\\ ___[\\______/^^^^^^^\\__/) o-)__ |\\__[=======______//________)__\\ \\|_______________//____________| ||| || //|| ||| ||| || @.|| ||| || \\/ .\\/ || . . '.'.` COW-OPERATION """ return the_cow end
// -*- coding: utf-8 -*- #include <iostream> #include <fstream> #include <Eigen/Dense> #include <Eigen/LU> #include <chrono> int main() { std::cout << "" << std::endl; std::cout << " # C++ Eigen benchmark" << std::endl; int n; std::ifstream fr("input"); fr >> n; std::cout << "n " << n << std::endl; std::srand((unsigned int)time(NULL)); Eigen::MatrixXd A = Eigen::MatrixXd::Random(n, n); Eigen::MatrixXd B = Eigen::MatrixXd::Random(n, n); std::chrono::system_clock::time_point start, end; double time; // multiplication start = std::chrono::system_clock::now(); Eigen::MatrixXd C = A*B; end = std::chrono::system_clock::now(); time = static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()/1000.0); std::cout << "multiplication time " << time << std::endl; // inverse start = std::chrono::system_clock::now(); Eigen::MatrixXd D = A.inverse(); end = std::chrono::system_clock::now(); time = static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()/1000.0); std::cout << "inverse time " << time << std::endl; // LU inverse start = std::chrono::system_clock::now(); Eigen::MatrixXd E = A.partialPivLu().inverse(); end = std::chrono::system_clock::now(); time = static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()/1000.0); std::cout << "LU inverse time " << time << std::endl; // LU decomposition start = std::chrono::system_clock::now(); Eigen::MatrixXd F = A.partialPivLu().matrixLU(); end = std::chrono::system_clock::now(); time = static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()/1000.0); std::cout << "LU decomposition time " << time << std::endl; // rank-revealing QR start = std::chrono::system_clock::now(); Eigen::MatrixXd G = A.colPivHouseholderQr().matrixQR(); end = std::chrono::system_clock::now(); time = static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()/1000.0); std::cout << "rank-revealing QR time " << time << std::endl; }
function k = taylororder %TAYLORORDER Order of Taylor evaluations % % k = taylororder % %In the current initialization of the Taylor package, Taylor coefficients %up to order k will be calculated. Result is -1 if Taylor package is not %yet initialized. % % written 05/21/09 S.M. Rump % modified 08/26/12 S.M. Rump global variables removed % INTLAB_TAYLOR_ORDER = getappdata(0,'INTLAB_TAYLOR_ORDER'); if isempty(INTLAB_TAYLOR_ORDER) % Taylor package not yet initialized k = -1; else k = INTLAB_TAYLOR_ORDER; end
------------------------------------------------------------------------ -- Some results/examples related to CCS, implemented using the -- coinductive definition of bisimilarity ------------------------------------------------------------------------ -- Unless anything else is stated the results (or statements, in the -- case of exercises) below are taken from "Enhancements of the -- bisimulation proof method" by Pous and Sangiorgi. {-# OPTIONS --sized-types #-} open import Prelude module Bisimilarity.CCS.Examples {ℓ} {Name : Type ℓ} where open import Equality.Propositional open import Prelude.Size open import Bisimilarity.CCS import Bisimilarity.Equational-reasoning-instances open import Equational-reasoning open import Labelled-transition-system.CCS Name open import Bisimilarity CCS ------------------------------------------------------------------------ -- A result mentioned in "Enhancements of the bisimulation proof -- method" mutual -- For a more general result, see 6-2-14 below. !∙⊕∙∼!∙∣!∙ : ∀ {i a b} → [ i ] ! (a ∙ ⊕ b ∙) ∼ ! a ∙ ∣ ! b ∙ !∙⊕∙∼!∙∣!∙ {i} {a} {b} = ⟨ lr , rl ⟩ where lemma = ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ ∣-right-identity ⟩ ! (a ∙ ⊕ b ∙) ∼⟨ !∙⊕∙∼′!∙∣!∙ {i = i} ⟩■ ! a ∙ ∣ ! b ∙ left-lemma = ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ lemma ⟩ ! a ∙ ∣ ! b ∙ ∼⟨ symmetric ∣-right-identity ∣-cong reflexive ⟩■ (! a ∙ ∣ ∅) ∣ ! b ∙ right-lemma = ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ lemma ⟩ ! a ∙ ∣ ! b ∙ ∼⟨ reflexive ∣-cong symmetric ∣-right-identity ⟩■ ! a ∙ ∣ (! b ∙ ∣ ∅) τ-lemma = (! (a ∙ ⊕ b ∙) ∣ ∅) ∣ ∅ ∼⟨ ∣-right-identity ⟩ ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ lemma ⟩ ! a ∙ ∣ ! b ∙ ∼⟨ symmetric (∣-right-identity ∣-cong ∣-right-identity) ⟩■ (! a ∙ ∣ ∅) ∣ (! b ∙ ∣ ∅) lr : ∀ {P μ} → ! (a ∙ ⊕ b ∙) [ μ ]⟶ P → ∃ λ Q → ! a ∙ ∣ ! b ∙ [ μ ]⟶ Q × [ i ] P ∼′ Q lr {P} tr = case 6-1-3-2 tr of λ where (inj₁ (.∅ , sum-left action , P∼![a⊕b]∣∅)) → P ∼⟨ P∼![a⊕b]∣∅ ⟩ ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ left-lemma ⟩■ (! a ∙ ∣ ∅) ∣ ! b ∙ [ name a ]⟵⟨ par-left (replication (par-right action)) ⟩ ! a ∙ ∣ ! b ∙ (inj₁ (.∅ , sum-right action , P∼![a⊕b]∣∅)) → P ∼⟨ P∼![a⊕b]∣∅ ⟩ ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ right-lemma ⟩■ ! a ∙ ∣ (! b ∙ ∣ ∅) [ name b ]⟵⟨ par-right (replication (par-right action)) ⟩ ! a ∙ ∣ ! b ∙ (inj₂ (refl , P′ , P″ , c , a⊕b⟶P′ , a⊕b⟶P″ , P∼![a⊕b]∣P′∣P″)) → let b≡co-a , P′≡∅ , P″≡∅ = Σ-map id [ id , id ] (·⊕·-co a⊕b⟶P′ a⊕b⟶P″) in P ∼⟨ P∼![a⊕b]∣P′∣P″ ⟩ (! (a ∙ ⊕ b ∙) ∣ P′) ∣ P″ ∼⟨ (reflexive ∣-cong ≡⇒∼ P′≡∅) ∣-cong ≡⇒∼ P″≡∅ ⟩ (! (a ∙ ⊕ b ∙) ∣ ∅) ∣ ∅ ∼⟨ τ-lemma ⟩■ (! a ∙ ∣ ∅) ∣ (! b ∙ ∣ ∅) [ τ ]⟵⟨ par-τ′ b≡co-a (replication (par-right action)) (replication (par-right action)) ⟩ ! a ∙ ∣ ! b ∙ rl : ∀ {Q μ} → ! a ∙ ∣ ! b ∙ [ μ ]⟶ Q → ∃ λ P → ! (a ∙ ⊕ b ∙) [ μ ]⟶ P × [ i ] P ∼′ Q rl (par-left {P′ = P′} tr) = case 6-1-3-2 tr of λ where (inj₁ (.∅ , action , P′∼!a∣∅)) → ! (a ∙ ⊕ b ∙) [ name a ]⟶⟨ replication (par-right (sum-left action)) ⟩ʳˡ ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ left-lemma ⟩ (! a ∙ ∣ ∅) ∣ ! b ∙ ∼⟨ symmetric P′∼!a∣∅ ∣-cong reflexive ⟩■ P′ ∣ ! b ∙ (inj₂ (refl , .∅ , P″ , .a , action , a⟶P″ , P′∼!a∣∅∣P″)) → ⊥-elim (names-are-not-inverted a⟶P″) rl (par-right {Q′ = Q′} tr) = case 6-1-3-2 tr of λ where (inj₁ (.∅ , action , Q′∼!b∣∅)) → ! (a ∙ ⊕ b ∙) [ name b ]⟶⟨ replication (par-right (sum-right action)) ⟩ʳˡ ! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ right-lemma ⟩ ! a ∙ ∣ (! b ∙ ∣ ∅) ∼⟨ reflexive ∣-cong symmetric Q′∼!b∣∅ ⟩■ ! a ∙ ∣ Q′ (inj₂ (refl , .∅ , Q″ , .b , action , b⟶Q″ , Q′∼!b∣∅∣Q″)) → ⊥-elim (names-are-not-inverted b⟶Q″) rl (par-τ {P′ = P′} {Q′ = Q′} tr₁ tr₂) = case 6-1-3-2 tr₁ ,′ 6-1-3-2 tr₂ of λ where (inj₁ (.∅ , action , P′∼!a∣∅) , inj₁ (.∅ , action , Q′∼!co-a∣∅)) → ! (a ∙ ⊕ co a ∙) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left action))) (sum-right action)) ⟩ʳˡ (! (a ∙ ⊕ co a ∙) ∣ ∅) ∣ ∅ ∼⟨ τ-lemma ⟩ (! a ∙ ∣ ∅) ∣ (! co a ∙ ∣ ∅) ∼⟨ symmetric (P′∼!a∣∅ ∣-cong Q′∼!co-a∣∅) ⟩■ P′ ∣ Q′ (inj₁ _ , inj₂ (() , _)) (inj₂ (() , _) , _) !∙⊕∙∼′!∙∣!∙ : ∀ {a b i} → [ i ] ! (a ∙ ⊕ b ∙) ∼′ ! a ∙ ∣ ! b ∙ force !∙⊕∙∼′!∙∣!∙ = !∙⊕∙∼!∙∣!∙ ------------------------------------------------------------------------ -- Exercise 6.2.4 mutual -- For a more general result, see 6-2-17-4 below. 6-2-4 : ∀ {a i} → [ i ] ! ! a ∙ ∼ ! a ∙ 6-2-4 {a} {i} = ⟨ lr , rl ⟩ where impossible : ∀ {μ P q} {Q : Type q} → ! ! a ∙ [ μ ]⟶ P → μ ≡ τ → Q impossible {μ} !!a⟶P μ≡τ = ⊥-elim $ name≢τ (name a ≡⟨ !-only (!-only ·-only) !!a⟶P ⟩ μ ≡⟨ μ≡τ ⟩∎ τ ∎) lemma : ∀ {P} → P ∼ ! a ∙ ∣ ∅ → _ lemma {P} P∼!a∣∅ = ! ! a ∙ ∣ P ∼⟨ reflexive ∣-cong P∼!a∣∅ ⟩ ! ! a ∙ ∣ (! a ∙ ∣ ∅) ∼⟨ reflexive ∣-cong ∣-right-identity ⟩ ! ! a ∙ ∣ ! a ∙ ∼⟨ 6-1-2 ⟩ ! ! a ∙ ∼⟨ 6-2-4′ {i = i} ⟩ ! a ∙ ∼⟨ symmetric ∣-right-identity ⟩■ ! a ∙ ∣ ∅ lr : ∀ {P μ} → ! ! a ∙ [ μ ]⟶ P → ∃ λ P′ → ! a ∙ [ μ ]⟶ P′ × [ i ] P ∼′ P′ lr {P = P} !!a⟶P = case 6-1-3-2 !!a⟶P of λ where (inj₂ (μ≡τ , _)) → impossible !!a⟶P μ≡τ (inj₁ (P′ , !a⟶P′ , P∼!!a∣P′)) → case 6-1-3-2 !a⟶P′ of λ where (inj₂ (μ≡τ , _)) → impossible !!a⟶P μ≡τ (inj₁ (.∅ , action , P′∼!a∣∅)) → P ∼⟨ P∼!!a∣P′ ⟩ ! ! a ∙ ∣ P′ ∼⟨ lemma P′∼!a∣∅ ⟩■ ! a ∙ ∣ ∅ [ name a ]⟵⟨ replication (par-right action) ⟩ ! a ∙ rl : ∀ {P μ} → ! a ∙ [ μ ]⟶ P → ∃ λ P′ → ! ! a ∙ [ μ ]⟶ P′ × [ i ] P′ ∼′ P rl {P = P} !a⟶P = case 6-1-3-2 !a⟶P of λ where (inj₂ (refl , .∅ , Q″ , .a , action , a⟶Q″ , _)) → ⊥-elim (names-are-not-inverted a⟶Q″) (inj₁ (.∅ , action , P∼!a∣∅)) → ! ! a ∙ [ name a ]⟶⟨ replication (par-right !a⟶P) ⟩ʳˡ ! ! a ∙ ∣ P ∼⟨ lemma P∼!a∣∅ ⟩ ! a ∙ ∣ ∅ ∼⟨ symmetric P∼!a∣∅ ⟩■ P 6-2-4′ : ∀ {a i} → [ i ] ! ! a ∙ ∼′ ! a ∙ force 6-2-4′ = 6-2-4 ------------------------------------------------------------------------ -- A result mentioned in "Enhancements of the bisimulation proof -- method" ∙∣∙∼∙∙ : ∀ {a} → a ∙ ∣ a ∙ ∼ name a ∙ (a ∙) ∙∣∙∼∙∙ {a} = ⟨ lr , rl ⟩ where lr : ∀ {P μ} → a ∙ ∣ a ∙ [ μ ]⟶ P → ∃ λ P′ → name a ∙ (a ∙) [ μ ]⟶ P′ × P ∼′ P′ lr (par-left action) = ∅ ∣ a ∙ ∼⟨ ∣-left-identity ⟩■ a ∙ [ name a ]⟵⟨ action ⟩ name a ∙ (a ∙) lr (par-right action) = a ∙ ∣ ∅ ∼⟨ ∣-right-identity ⟩■ a ∙ [ name a ]⟵⟨ action ⟩ name a ∙ (a ∙) lr (par-τ action tr) = ⊥-elim (names-are-not-inverted tr) rl : ∀ {P μ} → name a ∙ (a ∙) [ μ ]⟶ P → ∃ λ P′ → a ∙ ∣ a ∙ [ μ ]⟶ P′ × P′ ∼′ P rl action = a ∙ ∣ a ∙ [ name a ]⟶⟨ par-right action ⟩ʳˡ a ∙ ∣ ∅ ∼⟨ ∣-right-identity ⟩■ a ∙ ------------------------------------------------------------------------ -- Lemma 6.2.14 mutual -- A more general variant of !∙⊕∙∼!∙∣!∙. For an even more general -- variant, see 6-2-17-2 below. 6-2-14 : ∀ {i a b P Q} → [ i ] ! (name a ∙ P ⊕ name b ∙ Q) ∼ ! name a ∙ P ∣ ! name b ∙ Q 6-2-14 {i} {a} {b} {P} {Q} = ⟨ lr , rl ⟩ where left-lemma = ! (name a ∙ P ⊕ name b ∙ Q) ∣ P ∼⟨ 6-2-14′ {i = i} ∣-cong′ reflexive ⟩ (! name a ∙ P ∣ ! name b ∙ Q) ∣ P ∼⟨ swap-rightmost ⟩■ (! name a ∙ P ∣ P) ∣ ! name b ∙ Q right-lemma = ! (name a ∙ P ⊕ name b ∙ Q) ∣ Q ∼⟨ 6-2-14′ {i = i} ∣-cong′ reflexive ⟩ (! name a ∙ P ∣ ! name b ∙ Q) ∣ Q ∼⟨ symmetric ∣-assoc ⟩■ ! name a ∙ P ∣ (! name b ∙ Q ∣ Q) τ-lemma = (! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q ∼⟨ left-lemma ∣-cong′ reflexive ⟩ ((! name a ∙ P ∣ P) ∣ ! name b ∙ Q) ∣ Q ∼⟨ symmetric ∣-assoc ⟩■ (! name a ∙ P ∣ P) ∣ (! name b ∙ Q ∣ Q) lr : ∀ {R μ} → ! (name a ∙ P ⊕ name b ∙ Q) [ μ ]⟶ R → ∃ λ S → ! name a ∙ P ∣ ! name b ∙ Q [ μ ]⟶ S × [ i ] R ∼′ S lr {R} tr = case 6-1-3-2 tr of λ where (inj₁ (.P , sum-left action , R∼![aP⊕bQ]∣P)) → R ∼⟨ R∼![aP⊕bQ]∣P ⟩ ! (name a ∙ P ⊕ name b ∙ Q) ∣ P ∼⟨ left-lemma ⟩■ (! name a ∙ P ∣ P) ∣ ! name b ∙ Q [ name a ]⟵⟨ par-left (replication (par-right action)) ⟩ ! name a ∙ P ∣ ! name b ∙ Q (inj₁ (.Q , sum-right action , R∼![aP⊕bQ]∣Q)) → R ∼⟨ R∼![aP⊕bQ]∣Q ⟩ ! (name a ∙ P ⊕ name b ∙ Q) ∣ Q ∼⟨ right-lemma ⟩■ ! name a ∙ P ∣ (! name b ∙ Q ∣ Q) [ name b ]⟵⟨ par-right (replication (par-right action)) ⟩ ! name a ∙ P ∣ ! name b ∙ Q (inj₂ ( refl , R′ , R″ , c , aP⊕bQ⟶R′ , aP⊕bQ⟶R″ , R∼![aP⊕bQ]∣R′∣R″ )) → let b≡co-a , R′≡,R″≡ = ·⊕·-co aP⊕bQ⟶R′ aP⊕bQ⟶R″ lemma : _ → [ _ ] _ ∼ _ lemma = λ where (inj₁ (R′≡P , R″≡Q)) → (! (name a ∙ P ⊕ name b ∙ Q) ∣ R′) ∣ R″ ∼⟨ (reflexive ∣-cong ≡⇒∼ R′≡P) ∣-cong ≡⇒∼ R″≡Q ⟩■ (! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q (inj₂ (R′≡Q , R″≡P)) → (! (name a ∙ P ⊕ name b ∙ Q) ∣ R′) ∣ R″ ∼⟨ (reflexive ∣-cong ≡⇒∼ R′≡Q) ∣-cong ≡⇒∼ R″≡P ⟩ (! (name a ∙ P ⊕ name b ∙ Q) ∣ Q) ∣ P ∼⟨ swap-rightmost ⟩■ (! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q in R ∼⟨ R∼![aP⊕bQ]∣R′∣R″ ⟩ (! (name a ∙ P ⊕ name b ∙ Q) ∣ R′) ∣ R″ ∼⟨ lemma R′≡,R″≡ ⟩ (! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q ∼⟨ τ-lemma ⟩■ (! name a ∙ P ∣ P) ∣ (! name b ∙ Q ∣ Q) [ τ ]⟵⟨ par-τ′ b≡co-a (replication (par-right action)) (replication (par-right action)) ⟩ ! name a ∙ P ∣ ! name b ∙ Q rl : ∀ {S μ} → ! name a ∙ P ∣ ! name b ∙ Q [ μ ]⟶ S → ∃ λ R → ! (name a ∙ P ⊕ name b ∙ Q) [ μ ]⟶ R × [ i ] R ∼′ S rl (par-left {P′ = S} tr) = case 6-1-3-2 tr of λ where (inj₁ (.P , action , S∼!aP∣P)) → ! (name a ∙ P ⊕ name b ∙ Q) [ name a ]⟶⟨ replication (par-right (sum-left action)) ⟩ʳˡ ! (name a ∙ P ⊕ name b ∙ Q) ∣ P ∼⟨ left-lemma ⟩ (! name a ∙ P ∣ P) ∣ ! name b ∙ Q ∼⟨ symmetric S∼!aP∣P ∣-cong reflexive ⟩■ S ∣ ! name b ∙ Q (inj₂ (refl , .P , S′ , .a , action , aP⟶S′ , S∼!aP∣P∣S′)) → ⊥-elim (names-are-not-inverted aP⟶S′) rl (par-right {Q′ = S} tr) = case 6-1-3-2 tr of λ where (inj₁ (.Q , action , S∼!bQ∣Q)) → ! (name a ∙ P ⊕ name b ∙ Q) [ name b ]⟶⟨ replication (par-right (sum-right action)) ⟩ʳˡ ! (name a ∙ P ⊕ name b ∙ Q) ∣ Q ∼⟨ right-lemma ⟩ ! name a ∙ P ∣ (! name b ∙ Q ∣ Q) ∼⟨ reflexive ∣-cong symmetric S∼!bQ∣Q ⟩■ ! name a ∙ P ∣ S (inj₂ (refl , .Q , S′ , .b , action , bQ⟶S′ , S∼!bQ∣Q∣S′)) → ⊥-elim (names-are-not-inverted bQ⟶S′) rl (par-τ {P′ = S} {Q′ = S′} tr₁ tr₂) = case 6-1-3-2 tr₁ ,′ 6-1-3-2 tr₂ of λ where (inj₁ (.P , action , S∼!aP∣P) , inj₁ (.Q , action , S′∼!co-aQ∣Q)) → ! (name a ∙ P ⊕ name (co a) ∙ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left action))) (sum-right action)) ⟩ʳˡ (! (name a ∙ P ⊕ name (co a) ∙ Q) ∣ P) ∣ Q ∼⟨ τ-lemma ⟩ (! name a ∙ P ∣ P) ∣ (! name (co a) ∙ Q ∣ Q) ∼⟨ symmetric (S∼!aP∣P ∣-cong S′∼!co-aQ∣Q) ⟩■ S ∣ S′ (inj₁ _ , inj₂ (() , _)) (inj₂ (() , _) , _) 6-2-14′ : ∀ {i a b P Q} → [ i ] ! (name a ∙ P ⊕ name b ∙ Q) ∼′ ! name a ∙ P ∣ ! name b ∙ Q force 6-2-14′ = 6-2-14 ------------------------------------------------------------------------ -- Lemma 6.2.17 -- Some results mentioned in the proof of 6.2.17 (1) in -- "Enhancements of the bisimulation proof method". 6-2-17-1-lemma₁ : ∀ {P Q} → (! P ∣ ! Q) ∣ (P ∣ Q) ∼ ! P ∣ ! Q 6-2-17-1-lemma₁ {P} {Q} = (! P ∣ ! Q) ∣ (P ∣ Q) ∼⟨ swap-in-the-middle ⟩ (! P ∣ P) ∣ (! Q ∣ Q) ∼⟨ 6-1-2 ∣-cong 6-1-2 ⟩■ ! P ∣ ! Q abstract 6-2-17-1-lemma₂ : ∀ {P Q R μ} → ! (P ∣ Q) [ μ ]⟶ R → ∃ λ S → R ∼ ! (P ∣ Q) ∣ S × ∃ λ T → ! P ∣ ! Q [ μ ]⟶ T × (! P ∣ ! Q) ∣ S ∼′ T 6-2-17-1-lemma₂ {P} {Q} {R} tr = case 6-1-3-2 tr of λ where (inj₁ (R′ , P∣Q⟶R′ , R∼![P∣Q]∣R′)) → let R″ , !P∣!Q⟶R″ , !P∣!Q∣R′∼R″ = left-to-right ((! P ∣ ! Q) ∣ (P ∣ Q) ∼⟨ 6-2-17-1-lemma₁ ⟩■ ! P ∣ ! Q) ((! P ∣ ! Q) ∣ (P ∣ Q) ⟶⟨ par-right P∣Q⟶R′ ⟩ (! P ∣ ! Q) ∣ R′) in _ , R∼![P∣Q]∣R′ , _ , !P∣!Q⟶R″ , !P∣!Q∣R′∼R″ (inj₂ (refl , R′ , R″ , a , P∣Q⟶R′ , P∣Q⟶R″ , R∼![P∣Q]∣R′∣R″)) → let T , !P∣!Q⟶T , !P∣!Q∣[R′∣R″]∼T = left-to-right ((! P ∣ ! Q) ∣ ((P ∣ Q) ∣ (P ∣ Q)) ∼⟨ ∣-assoc ⟩ ((! P ∣ ! Q) ∣ (P ∣ Q)) ∣ (P ∣ Q) ∼⟨ 6-2-17-1-lemma₁ ∣-cong reflexive ⟩ (! P ∣ ! Q) ∣ (P ∣ Q) ∼⟨ 6-2-17-1-lemma₁ ⟩■ ! P ∣ ! Q) ((! P ∣ ! Q) ∣ ((P ∣ Q) ∣ (P ∣ Q)) ⟶⟨ par-right (par-τ P∣Q⟶R′ P∣Q⟶R″) ⟩ (! P ∣ ! Q) ∣ (R′ ∣ R″)) in _ , (R ∼⟨ R∼![P∣Q]∣R′∣R″ ⟩ (! (P ∣ Q) ∣ R′) ∣ R″ ∼⟨ symmetric ∣-assoc ⟩■ ! (P ∣ Q) ∣ (R′ ∣ R″)) , _ , !P∣!Q⟶T , !P∣!Q∣[R′∣R″]∼T mutual 6-2-17-1 : ∀ {i P Q} → [ i ] ! (P ∣ Q) ∼ ! P ∣ ! Q 6-2-17-1 {i} {P} {Q} = ⟨ lr , rl ⟩ where lr : ∀ {R μ} → ! (P ∣ Q) [ μ ]⟶ R → ∃ λ S → ! P ∣ ! Q [ μ ]⟶ S × [ i ] R ∼′ S lr {R} tr = let S , R∼![P∣Q]∣S , T , !P∣!Q⟶T , !P∣!Q∣S∼T = 6-2-17-1-lemma₂ tr in R ∼⟨ R∼![P∣Q]∣S ⟩ ! (P ∣ Q) ∣ S ∼⟨ 6-2-17-1′ ∣-cong′ reflexive ⟩ (! P ∣ ! Q) ∣ S ∼⟨ !P∣!Q∣S∼T ⟩■ T ⟵⟨ !P∣!Q⟶T ⟩ ! P ∣ ! Q lemma = λ {R S : Proc ∞} → ! (P ∣ Q) ∣ (R ∣ S) ∼⟨ 6-2-17-1′ {i = i} ∣-cong′ reflexive ⟩ (! P ∣ ! Q) ∣ (R ∣ S) ∼⟨ swap-in-the-middle ⟩■ (! P ∣ R) ∣ (! Q ∣ S) left-lemma = λ {R : Proc ∞} → ! (P ∣ Q) ∣ (R ∣ Q) ∼⟨ lemma ⟩ (! P ∣ R) ∣ (! Q ∣ Q) ∼⟨ reflexive ∣-cong 6-1-2 ⟩■ (! P ∣ R) ∣ ! Q right-lemma = λ {R : Proc ∞} → ! (P ∣ Q) ∣ (P ∣ R) ∼⟨ lemma ⟩ (! P ∣ P) ∣ (! Q ∣ R) ∼⟨ 6-1-2 ∣-cong reflexive ⟩■ ! P ∣ (! Q ∣ R) rl : ∀ {S μ} → ! P ∣ ! Q [ μ ]⟶ S → ∃ λ R → ! (P ∣ Q) [ μ ]⟶ R × [ i ] R ∼′ S rl (par-left {P′ = S} !P⟶S) = case 6-1-3-2 !P⟶S return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _) of λ where (inj₁ (P′ , P⟶P′ , S∼!P∣P′)) → ! (P ∣ Q) ⟶⟨ replication (par-right (par-left P⟶P′)) ⟩ʳˡ ! (P ∣ Q) ∣ (P′ ∣ Q) ∼⟨ left-lemma ⟩ (! P ∣ P′) ∣ ! Q ∼⟨ symmetric S∼!P∣P′ ∣-cong reflexive ⟩■ S ∣ ! Q (inj₂ (refl , P′ , P″ , a , P⟶P′ , P⟶P″ , S∼!P∣P′∣P″)) → ! (P ∣ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (par-left P⟶P′))) (par-left P⟶P″)) ⟩ʳˡ (! (P ∣ Q) ∣ (P′ ∣ Q)) ∣ (P″ ∣ Q) ∼⟨ left-lemma ∣-cong′ reflexive ⟩ ((! P ∣ P′) ∣ ! Q) ∣ (P″ ∣ Q) ∼⟨ swap-in-the-middle ⟩ ((! P ∣ P′) ∣ P″) ∣ (! Q ∣ Q) ∼⟨ reflexive ∣-cong 6-1-2 ⟩ ((! P ∣ P′) ∣ P″) ∣ ! Q ∼⟨ symmetric S∼!P∣P′∣P″ ∣-cong reflexive ⟩■ S ∣ ! Q rl (par-right {Q′ = S} !Q⟶S) = case 6-1-3-2 !Q⟶S return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _) of λ where (inj₁ (Q′ , Q⟶Q′ , S∼!Q∣Q′)) → ! (P ∣ Q) ⟶⟨ replication (par-right (par-right Q⟶Q′)) ⟩ʳˡ ! (P ∣ Q) ∣ (P ∣ Q′) ∼⟨ right-lemma ⟩ ! P ∣ (! Q ∣ Q′) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′ ⟩■ ! P ∣ S (inj₂ (refl , Q′ , Q″ , a , Q⟶Q′ , Q⟶Q″ , S∼!Q∣Q′∣Q″)) → ! (P ∣ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (par-right Q⟶Q′))) (par-right Q⟶Q″)) ⟩ʳˡ (! (P ∣ Q) ∣ (P ∣ Q′)) ∣ (P ∣ Q″) ∼⟨ right-lemma ∣-cong′ reflexive ⟩ (! P ∣ (! Q ∣ Q′)) ∣ (P ∣ Q″) ∼⟨ swap-in-the-middle ⟩ (! P ∣ P) ∣ ((! Q ∣ Q′) ∣ Q″) ∼⟨ 6-1-2 ∣-cong reflexive ⟩ ! P ∣ ((! Q ∣ Q′) ∣ Q″) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′∣Q″ ⟩■ ! P ∣ S rl (par-τ {P′ = S} {Q′ = S′} !P⟶S !Q⟶S′) = case 6-1-3-2 !P⟶S ,′ 6-1-3-2 !Q⟶S′ of λ where (inj₁ (P′ , P⟶P′ , S∼!P∣P′) , inj₁ (Q′ , Q⟶Q′ , S′∼!Q∣Q′)) → ! (P ∣ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (par-left P⟶P′))) (par-right Q⟶Q′)) ⟩ʳˡ (! (P ∣ Q) ∣ (P′ ∣ Q)) ∣ (P ∣ Q′) ∼⟨ left-lemma ∣-cong′ reflexive ⟩ ((! P ∣ P′) ∣ ! Q) ∣ (P ∣ Q′) ∼⟨ swap-in-the-middle ⟩ ((! P ∣ P′) ∣ P) ∣ (! Q ∣ Q′) ∼⟨ swap-rightmost ∣-cong reflexive ⟩ ((! P ∣ P) ∣ P′) ∣ (! Q ∣ Q′) ∼⟨ (6-1-2 ∣-cong reflexive) ∣-cong reflexive ⟩ (! P ∣ P′) ∣ (! Q ∣ Q′) ∼⟨ symmetric (S∼!P∣P′ ∣-cong S′∼!Q∣Q′) ⟩■ S ∣ S′ (inj₁ _ , inj₂ (() , _)) (inj₂ (() , _) , _) 6-2-17-1′ : ∀ {i P Q} → [ i ] ! (P ∣ Q) ∼′ ! P ∣ ! Q force 6-2-17-1′ = 6-2-17-1 mutual 6-2-17-2 : ∀ {i P Q} → [ i ] ! (P ⊕ Q) ∼ ! P ∣ ! Q 6-2-17-2 {i} {P} {Q} = ⟨ lr , rl ⟩ where left-lemma = λ {R : Proc ∞} → ! (P ⊕ Q) ∣ R ∼⟨ 6-2-17-2′ {i = i} ∣-cong′ reflexive ⟩ (! P ∣ ! Q) ∣ R ∼⟨ swap-rightmost ⟩■ (! P ∣ R) ∣ ! Q right-lemma = λ {R : Proc ∞} → ! (P ⊕ Q) ∣ R ∼⟨ 6-2-17-2′ {i = i} ∣-cong′ reflexive ⟩ (! P ∣ ! Q) ∣ R ∼⟨ symmetric ∣-assoc ⟩■ ! P ∣ (! Q ∣ R) τ-lemma₁ = λ {P′ P″ : Proc ∞} → (! (P ⊕ Q) ∣ P′) ∣ P″ ∼⟨ left-lemma ∣-cong′ reflexive ⟩ ((! P ∣ P′) ∣ ! Q) ∣ P″ ∼⟨ swap-rightmost ⟩■ ((! P ∣ P′) ∣ P″) ∣ ! Q τ-lemma₂ = λ {P′ Q′ : Proc ∞} → (! (P ⊕ Q) ∣ P′) ∣ Q′ ∼⟨ left-lemma ∣-cong′ reflexive ⟩ ((! P ∣ P′) ∣ ! Q) ∣ Q′ ∼⟨ symmetric ∣-assoc ⟩■ (! P ∣ P′) ∣ (! Q ∣ Q′) τ-lemma₃ = λ {Q′ Q″ : Proc ∞} → (! (P ⊕ Q) ∣ Q′) ∣ Q″ ∼⟨ right-lemma ∣-cong′ reflexive ⟩ (! P ∣ (! Q ∣ Q′)) ∣ Q″ ∼⟨ symmetric ∣-assoc ⟩■ ! P ∣ ((! Q ∣ Q′) ∣ Q″) lr : ∀ {R μ} → ! (P ⊕ Q) [ μ ]⟶ R → ∃ λ S → ! P ∣ ! Q [ μ ]⟶ S × [ i ] R ∼′ S lr {R} tr = case 6-1-3-2 tr return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _) of λ where (inj₁ (P′ , sum-left P⟶P′ , R∼![P⊕Q]∣P′)) → R ∼⟨ R∼![P⊕Q]∣P′ ⟩ ! (P ⊕ Q) ∣ P′ ∼⟨ left-lemma ⟩■ (! P ∣ P′) ∣ ! Q ⟵⟨ par-left (replication (par-right P⟶P′)) ⟩ ! P ∣ ! Q (inj₁ (Q′ , sum-right Q⟶Q′ , R∼![P⊕Q]∣Q′)) → R ∼⟨ R∼![P⊕Q]∣Q′ ⟩ ! (P ⊕ Q) ∣ Q′ ∼⟨ right-lemma ⟩■ ! P ∣ (! Q ∣ Q′) ⟵⟨ par-right (replication (par-right Q⟶Q′)) ⟩ ! P ∣ ! Q (inj₂ ( refl , P′ , P″ , c , sum-left P⟶P′ , sum-left P⟶P″ , R∼![P⊕Q]∣P′∣P″ )) → R ∼⟨ R∼![P⊕Q]∣P′∣P″ ⟩ (! (P ⊕ Q) ∣ P′) ∣ P″ ∼⟨ τ-lemma₁ ⟩■ ((! P ∣ P′) ∣ P″) ∣ ! Q [ τ ]⟵⟨ par-left (replication (par-τ (replication (par-right P⟶P′)) P⟶P″)) ⟩ ! P ∣ ! Q (inj₂ ( refl , P′ , Q′ , c , sum-left P⟶P′ , sum-right Q⟶Q′ , R∼![P⊕Q]∣P′∣Q′ )) → R ∼⟨ R∼![P⊕Q]∣P′∣Q′ ⟩ (! (P ⊕ Q) ∣ P′) ∣ Q′ ∼⟨ τ-lemma₂ ⟩■ (! P ∣ P′) ∣ (! Q ∣ Q′) [ τ ]⟵⟨ par-τ (replication (par-right P⟶P′)) (replication (par-right Q⟶Q′)) ⟩ ! P ∣ ! Q (inj₂ ( refl , Q′ , P′ , c , sum-right Q⟶Q′ , sum-left P⟶P′ , R∼![P⊕Q]∣Q′∣P′ )) → R ∼⟨ R∼![P⊕Q]∣Q′∣P′ ⟩ (! (P ⊕ Q) ∣ Q′) ∣ P′ ∼⟨ right-lemma ∣-cong′ reflexive ⟩ (! P ∣ (! Q ∣ Q′)) ∣ P′ ∼⟨ swap-rightmost ⟩■ (! P ∣ P′) ∣ (! Q ∣ Q′) [ τ ]⟵⟨ par-τ′ (sym $ co-involutive c) (replication (par-right P⟶P′)) (replication (par-right Q⟶Q′)) ⟩ ! P ∣ ! Q (inj₂ ( refl , Q′ , Q″ , c , sum-right Q⟶Q′ , sum-right Q⟶Q″ , R∼![P⊕Q]∣Q′∣Q″ )) → R ∼⟨ R∼![P⊕Q]∣Q′∣Q″ ⟩ (! (P ⊕ Q) ∣ Q′) ∣ Q″ ∼⟨ τ-lemma₃ ⟩■ ! P ∣ ((! Q ∣ Q′) ∣ Q″) [ τ ]⟵⟨ par-right (replication (par-τ (replication (par-right Q⟶Q′)) Q⟶Q″)) ⟩ ! P ∣ ! Q rl : ∀ {S μ} → ! P ∣ ! Q [ μ ]⟶ S → ∃ λ R → ! (P ⊕ Q) [ μ ]⟶ R × [ i ] R ∼′ S rl (par-left {P′ = S} !P⟶S) = case 6-1-3-2 !P⟶S return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _) of λ where (inj₁ (P′ , P⟶P′ , S∼!P∣P′)) → ! (P ⊕ Q) ⟶⟨ replication (par-right (sum-left P⟶P′)) ⟩ʳˡ ! (P ⊕ Q) ∣ P′ ∼⟨ left-lemma ⟩ (! P ∣ P′) ∣ ! Q ∼⟨ symmetric S∼!P∣P′ ∣-cong reflexive ⟩■ S ∣ ! Q (inj₂ (refl , P′ , P″ , a , P⟶P′ , P⟶P″ , S∼!P∣P′∣P″)) → ! (P ⊕ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left P⟶P′))) (sum-left P⟶P″)) ⟩ʳˡ (! (P ⊕ Q) ∣ P′) ∣ P″ ∼⟨ τ-lemma₁ ⟩ ((! P ∣ P′) ∣ P″) ∣ ! Q ∼⟨ symmetric S∼!P∣P′∣P″ ∣-cong reflexive ⟩■ S ∣ ! Q rl (par-right {Q′ = S} !Q⟶S) = case 6-1-3-2 !Q⟶S return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _) of λ where (inj₁ (Q′ , Q⟶Q′ , S∼!Q∣Q′)) → ! (P ⊕ Q) ⟶⟨ replication (par-right (sum-right Q⟶Q′)) ⟩ʳˡ ! (P ⊕ Q) ∣ Q′ ∼⟨ right-lemma ⟩ ! P ∣ (! Q ∣ Q′) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′ ⟩■ ! P ∣ S (inj₂ (refl , Q′ , Q″ , a , Q⟶Q′ , Q⟶Q″ , S∼!Q∣Q′∣Q″)) → ! (P ⊕ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-right Q⟶Q′))) (sum-right Q⟶Q″)) ⟩ʳˡ (! (P ⊕ Q) ∣ Q′) ∣ Q″ ∼⟨ τ-lemma₃ ⟩ ! P ∣ ((! Q ∣ Q′) ∣ Q″) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′∣Q″ ⟩■ ! P ∣ S rl (par-τ {P′ = S} {Q′ = S′} !P⟶S !Q⟶S′) = case 6-1-3-2 !P⟶S ,′ 6-1-3-2 !Q⟶S′ of λ where (inj₁ (P′ , P⟶P′ , S∼!P∣P′) , inj₁ (Q′ , Q⟶Q′ , S′∼!Q∣Q′)) → ! (P ⊕ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left P⟶P′))) (sum-right Q⟶Q′)) ⟩ʳˡ (! (P ⊕ Q) ∣ P′) ∣ Q′ ∼⟨ τ-lemma₂ ⟩ (! P ∣ P′) ∣ (! Q ∣ Q′) ∼⟨ symmetric (S∼!P∣P′ ∣-cong S′∼!Q∣Q′) ⟩■ S ∣ S′ (inj₁ _ , inj₂ (() , _)) (inj₂ (() , _) , _) 6-2-17-2′ : ∀ {i P Q} → [ i ] ! (P ⊕ Q) ∼′ ! P ∣ ! Q force 6-2-17-2′ = 6-2-17-2 6-2-17-3 : ∀ {P} → ! P ∣ ! P ∼ ! P 6-2-17-3 {P} = ! P ∣ ! P ∼⟨ symmetric 6-2-17-2 ⟩ ! (P ⊕ P) ∼⟨ !-cong ⊕-idempotent ⟩■ ! P -- A result mentioned in the proof of 6.2.17 (4) in "Enhancements of -- the bisimulation proof method". 6-2-17-4-lemma : ∀ {P Q μ} → ! P [ μ ]⟶ Q → Q ∼ ! P ∣ Q 6-2-17-4-lemma {P} {Q} !P⟶Q = case 6-1-3-2 !P⟶Q of λ where (inj₁ (P′ , P⟶P′ , Q∼!P∣P′)) → Q ∼⟨ Q∼!P∣P′ ⟩ ! P ∣ P′ ∼⟨ symmetric 6-2-17-3 ∣-cong reflexive ⟩ (! P ∣ ! P) ∣ P′ ∼⟨ symmetric ∣-assoc ⟩ ! P ∣ (! P ∣ P′) ∼⟨ reflexive ∣-cong symmetric Q∼!P∣P′ ⟩■ ! P ∣ Q (inj₂ (_ , P′ , P″ , _ , P⟶P′ , P⟶P″ , Q∼!P∣P′∣P″)) → Q ∼⟨ Q∼!P∣P′∣P″ ⟩ (! P ∣ P′) ∣ P″ ∼⟨ symmetric ∣-assoc ⟩ ! P ∣ (P′ ∣ P″) ∼⟨ symmetric 6-2-17-3 ∣-cong reflexive ⟩ (! P ∣ ! P) ∣ (P′ ∣ P″) ∼⟨ symmetric ∣-assoc ⟩ ! P ∣ (! P ∣ (P′ ∣ P″)) ∼⟨ reflexive ∣-cong ∣-assoc ⟩ ! P ∣ ((! P ∣ P′) ∣ P″) ∼⟨ reflexive ∣-cong symmetric Q∼!P∣P′∣P″ ⟩■ ! P ∣ Q mutual 6-2-17-4 : ∀ {P i} → [ i ] ! ! P ∼ ! P 6-2-17-4 {P} {i} = ⟨ lr , rl ⟩ where lemma = λ {Q μ} (!P⟶Q : ! P [ μ ]⟶ Q) → ! ! P ∣ Q ∼⟨ 6-2-17-4′ {i = i} ∣-cong′ reflexive ⟩ ! P ∣ Q ∼⟨ symmetric (6-2-17-4-lemma !P⟶Q) ⟩■ Q lr : ∀ {Q μ} → ! ! P [ μ ]⟶ Q → ∃ λ Q′ → ! P [ μ ]⟶ Q′ × [ i ] Q ∼′ Q′ lr {Q} !!P⟶Q = case 6-1-3-2 !!P⟶Q of λ where (inj₁ (Q′ , !P⟶Q′ , Q∼!!P∣Q′)) → _ , !P⟶Q′ , (Q ∼⟨ Q∼!!P∣Q′ ⟩ ! ! P ∣ Q′ ∼⟨ lemma !P⟶Q′ ⟩■ Q′) (inj₂ (refl , Q′ , Q″ , a , !P⟶Q′ , !P⟶Q″ , Q∼!!P∣Q′∣Q″)) → case 6-1-3-2 !P⟶Q″ of λ where (inj₂ (() , _)) (inj₁ (Q‴ , P⟶Q‴ , Q″∼!P∣Q‴)) → let !P⟶Q′∣Q″ = ! P [ τ ]⟶⟨ replication (par-τ !P⟶Q′ P⟶Q‴) ⟩ Q′ ∣ Q‴ in Q ∼⟨ Q∼!!P∣Q′∣Q″ ⟩ (! ! P ∣ Q′) ∣ Q″ ∼⟨ reflexive ∣-cong Q″∼!P∣Q‴ ⟩ (! ! P ∣ Q′) ∣ (! P ∣ Q‴) ∼⟨ swap-in-the-middle ⟩ (! ! P ∣ ! P) ∣ (Q′ ∣ Q‴) ∼⟨ 6-1-2 ∣-cong reflexive ⟩ ! ! P ∣ (Q′ ∣ Q‴) ∼⟨ lemma !P⟶Q′∣Q″ ⟩■ Q′ ∣ Q‴ [ τ ]⟵⟨ !P⟶Q′∣Q″ ⟩ ! P rl : ∀ {Q μ} → ! P [ μ ]⟶ Q → ∃ λ Q′ → ! ! P [ μ ]⟶ Q′ × [ i ] Q′ ∼′ Q rl {Q} !P⟶Q = ! ! P ⟶⟨ replication (par-right !P⟶Q) ⟩ʳˡ ! ! P ∣ Q ∼⟨ lemma !P⟶Q ⟩■ Q 6-2-17-4′ : ∀ {P i} → [ i ] ! ! P ∼′ ! P force 6-2-17-4′ = 6-2-17-4 ------------------------------------------------------------------------ -- An example from "Coinduction All the Way Up" by Pous module _ (a b : Name-with-kind) where A B C D : ∀ {i} → Proc i A = name a ∙ name b ∙ D B = name a ∙ name b ∙ C C = name (co a) · λ { .force → A ∣ C } D = name (co a) · λ { .force → B ∣ D } mutual A∼B : ∀ {i} → [ i ] A ∼ B A∼B = refl ∙-cong (refl ∙-cong symmetric C∼D) C∼D : ∀ {i} → [ i ] C ∼ D C∼D = refl ·-cong λ { .force → A∼B ∣-cong C∼D } ------------------------------------------------------------------------ -- Another example (not taken from Pous and Sangiorgi) Restricted : Name → Proc ∞ Restricted a = ⟨ν a ⟩ (name (a , true) · λ { .force → ∅ }) Restricted∼∅ : ∀ {a} → Restricted a ∼ ∅ Restricted∼∅ = ⟨ (λ { (restriction x≢x action) → ⊥-elim (x≢x refl) }) , (λ ()) ⟩
State Before: C : Type u₁ inst✝² : Category C D : Type u₂ inst✝¹ : Category D E : Type u₃ inst✝ : Category E F✝ G✝ : C ⥤ D α : F✝ ≅ G✝ F G : C ⥤ D e : F ≅ G X : C ⊢ inv (e.inv.app X) = e.hom.app X State After: no goals Tactic: aesop_cat
lemma degree_of_nat [simp]: "degree (of_nat n) = 0"
lemma of_real_neg_numeral [simp]: "of_real (- numeral w) = - numeral w"
-- | Now we plot! module QuickHullDraw where import Control.Arrow import Data.List import qualified Data.Vector as V import qualified Data.Vector.Unboxed as UV import Graphics.Rendering.Plot import Numeric.LinearAlgebra (Vector (..)) import QuickHull import System.Environment import System.Random main :: IO () main = do [d] <- getArgs let vectors = V.fromList . map UV.fromList . chop 2 . take ((* 2) $ read d :: Int) . randomRs (0 :: Double, 100) $ mkStdGen 0 (rxL, rxH) = (0, 100) (ryL, ryH) = (0, 100) (vx, vy) = convertPoints vectors hull' = qhull2D vectors (hx, hy) = convertPoints . V.fromList $ hull' writeFigure PNG ("QHullTest" ++ d ++ "Points" ++ ".png") (600, 600) (testFig vx vy hx hy (rxL, rxH) (ryL, ryH)) convertPoints :: V.Vector (UV.Vector Double) -> (Vector Double, Vector Double) convertPoints = (V.convert *** V.convert) . V.unzip . V.map (UV.unsafeHead &&& UV.unsafeLast) testFig :: Series -> Series -> Series -> Series -> (Double, Double) -> (Double, Double) -> Figure () testFig xs ys hx hy (rxL, rxH) (ryL, ryH) = do withTextDefaults $ setFontFamily "OpenSymbol" withTitle $ setText "2D Convex Hull with QuickHull!" setPlots 1 1 withPlot (1, 1) $ do setDataset [(xs, point ys (Asterisk, red)), (hx, point hy (Box, purple))] addAxis XAxis (Side Lower) $ withAxisLabel $ setText "x-axis" addAxis YAxis (Side Lower) $ withAxisLabel $ setText "y-axis" addAxis XAxis (Value 0) $ return () setRange XAxis Lower Linear (rxL - 5) (rxH + 5) setRange YAxis Lower Linear (ryL - 5) (ryH + 5) chop :: Int -> [a] -> [[a]] chop n = unfoldr (\v -> if null v then Nothing else Just $ splitAt n v)
Continuing Education's office at the Kansas City Art Institute is located on the 2nd-floor of the historic Jannes Library. Temporary 15 minute and reserved Continuing Education parking is available behind the library, at the top of the hill for students wishing to enroll in office. Office hours are Monday through Friday, 8:30 a.m. to 5 p.m. *Please see your registration receipt for first course procedures and additional details on classroom location.
/** * * @file example_dgelqf.c * * PLASMA testing routines * PLASMA is a software package provided by Univ. of Tennessee, * Univ. of California Berkeley and Univ. of Colorado Denver * * @brief Example using LQ factorization * * @version 2.6.0 * @author Bilel Hadri * @date 2010-11-15 * @generated d Tue Jan 7 11:45:20 2014 * **/ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <plasma.h> #include <cblas.h> #include <lapacke.h> #include <core_blas.h> #ifndef max #define max(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef min #define min(a, b) ((a) < (b) ? (a) : (b)) #endif int check_orthogonality(int, int, int, double*); int check_factorization(int, int, double*, double*, int, double*); int IONE=1; int ISEED[4] = {0,0,0,1}; /* initial seed for dlarnv() */ int main () { int cores = 2; int M = 10; int N = 15; int LDA = 10; int K = min(M, N); int info; int info_ortho, info_factorization; int i,j; int LDAxN = LDA*N; double *A1 = (double *)malloc(LDA*N*sizeof(double)); double *A2 = (double *)malloc(LDA*N*sizeof(double)); double *Q = (double *)malloc(LDA*N*sizeof(double)); PLASMA_desc *T; /* Check if unable to allocate memory */ if ((!A1)||(!A2)||(!Q)){ printf("Out of Memory \n "); return EXIT_SUCCESS; } /* Plasma Initialization */ PLASMA_Init(cores); printf("-- PLASMA is initialized to run on %d cores. \n",cores); /* Allocate T */ PLASMA_Alloc_Workspace_dgelqf(M, N, &T); /* Initialize A1 and A2 */ LAPACKE_dlarnv_work(IONE, ISEED, LDAxN, A1); for (i = 0; i < M; i++) for (j = 0; j < N; j++) A2[LDA*j+i] = A1[LDA*j+i] ; /* Factorization QR of the matrix A2 */ info = PLASMA_dgelqf(M, N, A2, LDA, T); /* Building the economy-size Q */ memset((void*)Q, 0, LDA*N*sizeof(double)); for (i = 0; i < K; i++) Q[LDA*i+i] = 1.0; PLASMA_dorglq(M, N, K, A2, LDA, T, Q, LDA); /* Check the orthogonality, factorization and the solution */ info_ortho = check_orthogonality(M, N, LDA, Q); info_factorization = check_factorization(M, N, A1, A2, LDA, Q); if ((info_ortho != 0)|(info_factorization != 0)|(info != 0)) printf("-- Error in DGELQF example ! \n"); else printf("-- Run of DGELQF example successful ! \n"); free(A1); free(A2); free(Q); free(T); PLASMA_Finalize(); return EXIT_SUCCESS; } /*------------------------------------------------------------------- * Check the orthogonality of Q */ int check_orthogonality(int M, int N, int LDQ, double *Q) { double alpha, beta; double normQ; int info_ortho; int i; int minMN = min(M, N); double eps; double *work = (double *)malloc(minMN*sizeof(double)); eps = LAPACKE_dlamch_work('e'); alpha = 1.0; beta = -1.0; /* Build the idendity matrix USE DLASET?*/ double *Id = (double *) malloc(minMN*minMN*sizeof(double)); memset((void*)Id, 0, minMN*minMN*sizeof(double)); for (i = 0; i < minMN; i++) Id[i*minMN+i] = (double)1.0; /* Perform Id - Q'Q */ if (M >= N) cblas_dsyrk(CblasColMajor, CblasUpper, CblasTrans, N, M, alpha, Q, LDQ, beta, Id, N); else cblas_dsyrk(CblasColMajor, CblasUpper, CblasNoTrans, M, N, alpha, Q, LDQ, beta, Id, M); normQ = LAPACKE_dlansy_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), 'u', minMN, Id, minMN, work); printf("============\n"); printf("Checking the orthogonality of Q \n"); printf("||Id-Q'*Q||_oo / (N*eps) = %e \n",normQ/(minMN*eps)); if ( isnan(normQ / (minMN * eps)) || (normQ / (minMN * eps) > 10.0) ) { printf("-- Orthogonality is suspicious ! \n"); info_ortho=1; } else { printf("-- Orthogonality is CORRECT ! \n"); info_ortho=0; } free(work); free(Id); return info_ortho; } /*------------------------------------------------------------ * Check the factorization QR */ int check_factorization(int M, int N, double *A1, double *A2, int LDA, double *Q) { double Anorm, Rnorm; double alpha, beta; int info_factorization; int i,j; double eps; eps = LAPACKE_dlamch_work('e'); double *Ql = (double *)malloc(M*N*sizeof(double)); double *Residual = (double *)malloc(M*N*sizeof(double)); double *work = (double *)malloc(max(M,N)*sizeof(double)); alpha=1.0; beta=0.0; if (M >= N) { /* Extract the R */ double *R = (double *)malloc(N*N*sizeof(double)); memset((void*)R, 0, N*N*sizeof(double)); LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'u', M, N, A2, LDA, R, N); /* Perform Ql=Q*R */ memset((void*)Ql, 0, M*N*sizeof(double)); cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, N, (alpha), Q, LDA, R, N, (beta), Ql, M); free(R); } else { /* Extract the L */ double *L = (double *)malloc(M*M*sizeof(double)); memset((void*)L, 0, M*M*sizeof(double)); LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'l', M, N, A2, LDA, L, M); /* Perform Ql=LQ */ memset((void*)Ql, 0, M*N*sizeof(double)); cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, M, (alpha), L, M, Q, LDA, (beta), Ql, M); free(L); } /* Compute the Residual */ for (i = 0; i < M; i++) for (j = 0 ; j < N; j++) Residual[j*M+i] = A1[j*LDA+i]-Ql[j*M+i]; Rnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), M, N, Residual, M, work); Anorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), M, N, A2, LDA, work); if (M >= N) { printf("============\n"); printf("Checking the QR Factorization \n"); printf("-- ||A-QR||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); } else { printf("============\n"); printf("Checking the LQ Factorization \n"); printf("-- ||A-LQ||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); } if (isnan(Rnorm / (Anorm * N *eps)) || (Rnorm / (Anorm * N * eps) > 10.0) ) { printf("-- Factorization is suspicious ! \n"); info_factorization = 1; } else { printf("-- Factorization is CORRECT ! \n"); info_factorization = 0; } free(work); free(Ql); free(Residual); return info_factorization; }
Total 10 @,@ 247
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Stephen Morgan, Scott Morrison import ..braided_monoidal_category import categories.functor_categories.isomorphisms import categories.functor_categories.whiskering import tidy.its open categories open categories.functor open categories.products open categories.natural_transformation open categories.monoidal_category open categories.functor_categories namespace categories.braided_monoidal_category @[reducible] definition {u v} squared_Braiding {C : Type u} [𝒞 : monoidal_category.{u v} C] (commutor : Commutor C) : NaturalTransformation 𝒞.tensor 𝒞.tensor := begin exact (commutor.morphism ⊟ (whisker_on_left (SwitchProductCategory C C) commutor.morphism) ⊟ (FunctorComposition_associator _ _ _).inverse ⊟ (whisker_on_right (SwitchSymmetry _ _).morphism 𝒞.tensor) ⊟ (FunctorComposition_left_unitor 𝒞.tensor).morphism) end lemma {u v} symmetry_in_terms_of_natural_transformations {C : Type u} [𝒞 : monoidal_category.{u v} C] (β : Symmetry C) : squared_Braiding (β.braiding) = IdentityNaturalTransformation 𝒞.tensor := by obviously lemma {u v} symmetric_in_terms_of_components {C : Type u} [𝒞 : monoidal_category.{u v} C] (β : Braiding C) (e : squared_Braiding (β.braiding) = IdentityNaturalTransformation 𝒞.tensor) : Symmetry C := { β with symmetry := λ X Y : C, begin its congr_fun (congr_arg NaturalTransformation.components e) (X, Y), -- obviously -- FIXME sorry end } end categories.braided_monoidal_category
I love it when a plan comes together. Or, more specifically, when a half-baked idea actually works. One of my go-to slow cooker dishes is Pepperoncini Beef, which is pretty much a 2- to 3-pound beef chuck roast stuffed with a few cloves of slivered garlic, topped with a 16-ounce jar of pepperoncini and simmered on low for eight hours. We make roast beef and pepperoncini sandwiches on sub bread; topped with cheese and baked in the toaster oven for about three minutes, these are more than mere sandwiches. Problem: 2 to 3 pounds of roast beef leaves us with WAY more leftovers than we can possibly stand to eat in one week, and it doesn’t freeze well. Yesterday, while filling the grocery list with ingredients for another slow cooker recipe, I found the solution. Household fave Cowboy Stew, from the Year of Slow Cooking blog, calls for a pound of browned hamburger meat. In the end, what’s the difference between a pound of ground beef and a similar amount of shredded roast beef once you mix it all up together and cook it for eight hours? It was delicious, plus it saved me nearly $5 and the guilt of tossing out perfectly edible food. Kitchen WIN!
{-# LANGUAGE CPP #-} -- | Binary lists are lists whose number of elements is a power of two. -- This data structure is efficient for some computations like: -- -- * Splitting a list in half. -- -- * Appending two lists of the same length. -- -- * Extracting an element from the list. -- -- All the functions exported are total except for 'fromListWithDefault'. -- It is impossible for the user of this library to create a binary list -- whose length is /not/ a power of two. -- -- Since many names in this module clash with the names of some "Prelude" -- functions, you probably want to import this module this way: -- -- > import Data.BinaryList (BinList,Exponent) -- > import qualified Data.BinaryList as BL -- -- Remember that binary lists are an instance of the 'Foldable' and 'Traversable' -- classes. If you are missing a function here, look for functions using those -- instances. -- -- Note that some functions like 'replicate', 'generate', or 'take', don't use -- the length of the list as argument, but the exponent of its length expressed -- as a power of two. Throughout this document, this is referred -- as the /length exponent/. For example, if the list has length 16, its length exponent -- is 4 since 2^4 = 16. Therefore @replicate 4 0@ will create a list with 16 zeroes. -- Keep this in mind when using this library. Note as well that this implies that -- there is no need to check that the length argument is or is not a power of two. -- module Data.BinaryList ( -- * Type BinList , Exponent -- * Construction , singleton , append , replicate , replicateA , replicateAR , generate , generateM -- * Queries , lengthExponent #if !MIN_VERSION_base(4,8,0) , length #endif , lookup , head , last -- * Deconstruction , split , take , takeEnd -- * Transformation , replace , reverse -- * Tuples , joinPairs , disjoinPairs -- * Zipping and Unzipping , zip , unzip , zipWith -- * Lists -- ** From list , fromList , fromListWithDefault , fromListSplit -- ** To list , toListFilter , toListSegment -- * Others , traverseSegment -- * Example: Radix-2 FFT -- $fft ) where import Prelude hiding ( map, head, last , reverse, replicate , take, lookup , zip, unzip, zipWith , foldr1, length, foldr ) #if MIN_VERSION_base(4,8,0) import Prelude (length, foldr, foldr1) #endif import Data.Foldable (fold,toList) import Foreign.Storable (sizeOf) import Data.List (find) import Data.BinaryList.Internal import Control.Applicative.Backwards import Control.Arrow ((***)) import Control.Monad.Trans.State ( StateT (..) , evalStateT ,evalState , runState , get ,modify ) import Control.Monad.Trans.Class (lift) import Data.Functor.Identity (Identity (..)) import Control.Applicative.PhantomState import Data.Word (Word8) -- GHC-7.8 compatibility #if !MIN_VERSION_base(4,8,0) import qualified Prelude import Data.Foldable (Foldable (..)) import Data.Traversable (Traversable (..)) import Control.Applicative (Applicative (..), (<$>)) import Data.Monoid (mappend) -- | /O(1)/. Number of elements in the list. length :: BinList a -> Int length = (2^) . lengthExponent #endif -- | An exponent. type Exponent = Word8 -- | /O(1)/. Build a list with a single element. singleton :: a -> BinList a singleton = ListEnd -- | /O(1)/. Given a binary list @l@ with length @2^k@: -- -- > lengthExponent l = k -- lengthExponent :: BinList a -> Exponent lengthExponent (ListNode n _ _) = n lengthExponent (ListEnd _) = 0 {-# RULES "Data.BinaryList: length equality" forall xs ys . length xs == length ys = lengthExponent xs == lengthExponent ys #-} -- | /O(log n)/. Lookup an element in the list by its index (starting from 0). -- If the index is out of range, 'Nothing' is returned. lookup :: BinList a -> Int -> Maybe a lookup (ListNode n l r) i = let m = 2^(n-1) -- Number of elements in a single branch in if i < m then lookup l i -- Lookup in the left branch else lookup r $ i - m -- Lookup in the right branch lookup (ListEnd x) 0 = Just x lookup _ _ = Nothing -- | /O(log n)/. Replace a single element in the list. If the index is -- out of range, returns the original list. replace :: Int -- ^ Index to look for -> a -- ^ Element to insert -> BinList a -> BinList a replace i0 y = go i0 where go i (ListNode n l r) = let m = 2^(n-1) in if i < m then ListNode n (go i l) r else ListNode n l (go (i-m) r) go 0 (ListEnd _) = ListEnd y go _ e = e -- | /O(1)/. Append two binary lists. This is only possible -- if both lists have the same length. If this condition -- is not hold, 'Nothing' is returned. append :: BinList a -> BinList a -> Maybe (BinList a) append xs ys = let i = lengthExponent xs in if i == lengthExponent ys then Just $ ListNode (i+1) xs ys else Nothing -- | /O(1)/. Split a binary list into two sublists of half the length, -- unless the list only contains one element. In that case, it -- just returns that element. split :: BinList a -> Either a (BinList a,BinList a) split (ListNode _ l r) = Right (l,r) split (ListEnd x) = Left x -- | /O(log n)/. Calling @take n xs@ returns the first @min (2^n) (length xs)@ elements of @xs@. take :: Exponent -> BinList a -> BinList a take k xs@(ListNode n l _) = if k >= n then xs else take k l take _ xs = xs -- | /O(log n)/. Calling @takeEnd n xs@ returns the last @min (2^n) (length xs)@ elements of @xs@. takeEnd :: Exponent -> BinList a -> BinList a takeEnd k xs@(ListNode n _ r) = if k >= n then xs else takeEnd k r takeEnd _ xs = xs -- | Calling @replicateA n f@ builds a binary list collecting the results of -- executing @2^n@ times the applicative action @f@. replicateA :: Applicative f => Exponent -> f a -> f (BinList a) replicateA n f = go n where go 0 = ListEnd <$> f go i = let b = go (i-1) in ListNode <$> pure i <*> b <*> b -- | The same as 'replicateA', but the actions are executed in reversed order. replicateAR :: Applicative f => Exponent -> f a -> f (BinList a) replicateAR n = forwards . replicateA n . Backwards {-# RULES "Data.BinaryList: map reverse/replicateA" forall i f . map reverse (replicateA i f) = replicateAR i f #-} {-# RULES "Data.BinaryList: map reverse/replicateAR" forall i f . map reverse (replicateAR i f) = replicateA i f #-} -- | /O(log n)/. Calling @replicate n x@ builds a binary list with -- @2^n@ occurences of @x@. replicate :: Exponent -> a -> BinList a replicate n = runIdentity . replicateA n . Identity {-# RULES "Data.BinaryList: map/replicate" forall f n x . map f (replicate n x) = replicate n (f x) #-} -- | /O(n)/. Build a binary list with the given length exponent (see 'lengthExponent') -- by applying a function to each index. generate :: Exponent -> (Int -> a) -> BinList a generate l f = evalState (replicateA l $ fmap f get <* modify (+1)) 0 -- | Like 'generate', but the generator function returns a value in a 'Monad'. -- Therefore, the result is as well contained in a 'Monad'. generateM :: (Applicative m, Monad m) => Exponent -> (Int -> m a) -> m (BinList a) generateM l f = evalStateT (replicateA l $ (get >>= lift . f) <* modify (+1)) 0 -- | /O(log n)/. Get the first element of a binary list. head :: BinList a -> a head (ListNode _ l _) = head l head (ListEnd x) = x -- | /O(log n)/. Get the last element of a binary list. last :: BinList a -> a last (ListNode _ _ r) = last r last (ListEnd x) = x -- | /O(n)/. Reverse a binary list. reverse :: BinList a -> BinList a {-# INLINE[2] reverse #-} reverse (ListNode n l r) = ListNode n (reverse r) (reverse l) reverse xs = xs {-# RULES "Data.BinaryList: reverse/reverse" forall xs. reverse (reverse xs) = xs #-} ------------------------------ -- Transformations with tuples -- | /O(n)/. Transform a list of pairs into a flat list. The -- resulting list will have twice more elements than the -- original. joinPairs :: BinList (a,a) -> BinList a {-# INLINE[1] joinPairs #-} joinPairs (ListEnd (x,y)) = ListNode 1 (ListEnd x) (ListEnd y) joinPairs (ListNode n l r) = ListNode (n+1) (joinPairs l) (joinPairs r) -- | /O(n)/. Opposite transformation of 'joinPairs'. It halves -- the number of elements of the input. As a result, when -- applied to a binary list with a single element, it returns -- 'Nothing'. disjoinPairs :: BinList a -> Maybe (BinList (a,a)) {-# INLINE [1] disjoinPairs #-} disjoinPairs (ListEnd _) = Nothing disjoinPairs xs = Just $ disjoinPairsNodes xs disjoinPairsNodes :: BinList a -> BinList (a,a) disjoinPairsNodes (ListNode _ (ListEnd x) (ListEnd y)) = ListEnd (x,y) disjoinPairsNodes (ListNode n l r) = ListNode (n-1) (disjoinPairsNodes l) (disjoinPairsNodes r) disjoinPairsNodes _ = error "disjoinPairsNodes: bug. Please, report this with an example input." {-# RULES "Data.BinaryList: disjoinPairs/joinPairs" forall xs . disjoinPairs (joinPairs xs) = Just xs #-} {-# RULES "Data.BinaryList: disjoinPairs/map/joinPairs" forall f xs . disjoinPairs (map f (joinPairs xs)) = Just (map (f *** f) xs) #-} -- | Expression @pairBuilder f xs@ is equivalent to @joinPairs (map f xs)@, but does -- not build any intermediate structure. Used for rewriting rules. pairBuilder :: (a -> (b,b)) -> BinList a -> BinList b {-# INLINE[0] pairBuilder #-} pairBuilder f = go where go (ListEnd x) = let (a,b) = f x in ListNode 1 (ListEnd a) (ListEnd b) go (ListNode n l r) = ListNode (n+1) (go l) (go r) {-# RULES "Data.BinaryList: joinPairs/map" forall f xs . joinPairs (map f xs) = pairBuilder f xs #-} -- | Expression @zipAndJoing f g xs ys@ is equivalent to @pairBuilder f (zipWith g xs ys)@, -- but does not build any intermediate structure. Used for rewriting rules. zipAndJoin :: (c -> (d,d)) -> (a -> b -> c) -> BinList a -> BinList b -> BinList d zipAndJoin f g = go where -- Recursion go xs@(ListNode n l r) ys@(ListNode n' l' r') -- If both lists have the same length, recurse assuming it -- to avoid comparisons. | n == n' = ListNode (n+1) (goEquals l l') (goEquals r r') -- If the first list is larger, the second fits entirely in -- the left branch of the first. | n > n' = go l ys -- If the second list is larger, the first fits entirely in -- the left branch of the second. | otherwise = go xs l' go xs ys = let (x,y) = f $ g (head xs) (head ys) in ListNode 1 (ListEnd x) (ListEnd y) -- Recursion assuming both lists have the same length goEquals (ListNode n l r) (ListNode _ l' r') = ListNode (n+1) (goEquals l l') (goEquals r r') goEquals (ListEnd x) (ListEnd y) = let (x',y') = f $ g x y in ListNode 1 (ListEnd x') (ListEnd y') goEquals _ _ = undefined -- This can't happen! {-# RULES "Data.BinaryList: pairBuilder/zipWith" forall f g xs ys . pairBuilder f (zipWith g xs ys) = zipAndJoin f g xs ys #-} ------------------------ -- Zipping and Unzipping -- | /O(n)/. Zip two binary lists using an operator. zipWith :: (a -> b -> c) -> BinList a -> BinList b -> BinList c {-# INLINE[1] zipWith #-} zipWith f = go where -- Recursion go xs@(ListNode n l r) ys@(ListNode n' l' r') -- If both lists have the same length, recurse assuming it -- to avoid comparisons. | n == n' = ListNode n (goEquals l l') (goEquals r r') -- If the first list is larger, the second fits entirely in -- the left branch of the first. | n > n' = go l ys -- If the second list is larger, the first fits entirely in -- the left branch of the second. | otherwise = go xs l' go xs ys = ListEnd $ f (head xs) (head ys) -- Recursion assuming both lists have the same length goEquals (ListNode n l r) (ListNode _ l' r') = ListNode n (goEquals l l') (goEquals r r') goEquals (ListEnd x) (ListEnd y) = ListEnd (f x y) goEquals _ _ = undefined -- this can't happen -- | /O(n)/. Zip two binary lists in pairs. zip :: BinList a -> BinList b -> BinList (a,b) {-# INLINE zip #-} zip = zipWith (,) -- | /O(n)/. Unzip a binary list of pairs. unzip :: BinList (a,b) -> (BinList a, BinList b) {-# INLINE[1] unzip #-} unzip (ListEnd (x,y)) = (ListEnd x, ListEnd y) unzip (ListNode n l r) = let (la,lb) = unzip l (ra,rb) = unzip r in (ListNode n la ra, ListNode n lb rb) -- | Expression @unzipMap f xs@ is equivalent to @unzip (map f xs)@, but -- does not create any intermediate structure. unzipMap :: ((a,b) -> (c,d)) -> BinList (a,b) -> (BinList c,BinList d) unzipMap f = go where go (ListEnd p) = ListEnd *** ListEnd $ f p go (ListNode n l r) = let (lc,ld) = go l (rc,rd) = go r in (ListNode n lc rc, ListNode n ld rd) {-# RULES "Data.BinaryList: unzip/map" forall f xs . unzip (map f xs) = unzipMap f xs #-} ----------------------------- -- Transforming from/to lists -- | /O(log n)/. Calculate the exponent of a positive integer number expressed -- as a power of two. exponentInBasisTwo :: Int -> Maybe Exponent exponentInBasisTwo 1 = Just 0 exponentInBasisTwo n = if even n then fmap (+1) $ exponentInBasisTwo $ div n 2 else Nothing -- | /O(n)/. Build a binary list from a linked list. If the input list -- has length different from a power of two, it returns 'Nothing'. fromList :: [a] -> Maybe (BinList a) fromList xs = fmap builder . exponentInBasisTwo $ Prelude.length xs where builder l = evalState (replicateA l $ StateT $ \(h:t) -> pure (h,t)) xs -- | /O(1)/. This is the last exponent that has power of two defined in the type 'Int'. -- -- /Note: This value is system dependent, since the type 'Int' varies in size/ -- /from system to system./ -- lastExponentOfTwo :: Exponent lastExponentOfTwo = fromIntegral $ 8 * sizeOf (undefined :: Int) - 2 -- | /O(1)/. Calculate the next power of two exponent, if there is any. It is possible -- to not find a next one since the type 'Int' is finite. If the input is -- already a power of two, its exponent is returned. nextExponentOfTwo :: Int -> Maybe Exponent nextExponentOfTwo n = find (\i -> n <= 2^i) [0 .. lastExponentOfTwo] -- | /O(n)/. Build a binary list from a linked list. If the input list -- has length different from a power of two, fill to the next -- power of two with a default element. -- -- /Warning: this function crashes if the input list length is larger than any/ -- /power of two in the type 'Int'. However, this is very unlikely./ fromListWithDefault :: a -> [a] -> BinList a fromListWithDefault e xs = let l = Prelude.length xs in case nextExponentOfTwo l of Just n -> evalState (replicateA n $ StateT $ \ys -> pure $ case ys of (h:t) -> (h,t ) _ -> (e,[]) ) xs _ -> error "[binary-list] fromListWithDefault: input list is too big." -- | /O(n)/. Build a binary list from a linked list. It returns a binary list -- with length @2 ^ n@ (where @n@ is the supplied 'Int' argument), and -- the list of elements of the original list that were not used. If the -- input list is shorter than @2 ^ n@, a default element will be used to -- complete the binary list. This method for building binary lists is faster -- than both 'fromList' and 'fromListWithDefault'. fromListSplit :: a -- ^ Default element -> Exponent -- ^ Length exponent -> [a] -- ^ Input list -> (BinList a, [a]) fromListSplit e n = runState $ replicateA n $ StateT $ \xs -> pure $ case xs of (h:t) -> (h,t ) _ -> (e,[]) -- | /O(n)/. Create a list from the elements of a binary list matching a given -- condition. toListFilter :: (a -> Bool) -> BinList a -> [a] {-# INLINE toListFilter #-} toListFilter c = foldr (\x -> if c x then (x:) else id) [] -- | /O(n)/. Create a list extracting a sublist of elements from a binary list. toListSegment :: Int -> Int -> BinList a -> [a] {-# INLINE toListSegment #-} toListSegment s e xs = runPhantomState (traverseSegment (changeState . (:)) s e xs) [] -- | Apply an applicative action to every element in a segment of a binary list, from left to right. traverseSegment :: Applicative f => (a -> f ()) -> Int -> Int -> BinList a -> f () {-# INLINE traverseSegment #-} traverseSegment f s e xs | s > e = pure () | e < 0 = pure () | s >= length xs = pure () | otherwise = traverseSegmentFromTo f (max 0 s) e xs traverseSegmentFromTo :: Applicative f => (a -> f ()) -> Int -> Int -> BinList a -> f () {-# INLINE traverseSegmentFromTo #-} traverseSegmentFromTo f = go where go s e (ListNode n l r) = let k = 2^(n-1) in if s >= k -- Sublist is contained in right portion then go (s - k) (e - k) r else if e < k -- Sublist is contained in left portion then go s e l -- Sublist is divided in both portions else traverseSegmentFrom f s l *> traverseSegmentTo f (e - k) r go _ _ (ListEnd x) = f x traverseSegmentFrom :: Applicative f => (a -> f ()) -> Int -> BinList a -> f () {-# INLINE traverseSegmentFrom #-} traverseSegmentFrom f = go where go s (ListNode n l r) = let k = 2^(n-1) in if s >= k -- Sublist is contained in right portion then go (s - k) r -- Sublist is divided in both portions, but right -- portion is taken entirely else go s l *> traverseFull f r go _ (ListEnd x) = f x traverseSegmentTo :: Applicative f => (a -> f ()) -> Int -> BinList a -> f () {-# INLINE traverseSegmentTo #-} traverseSegmentTo f = go where go e (ListNode n l r) = let k = 2^(n-1) in if e < k -- Sublist is contained in left portion then go e l -- Sublist is divided in both portions, but left -- portion is taken entirely else traverseFull f l *> go (e - k) r go _ (ListEnd x) = f x traverseFull :: Applicative f => (a -> f ()) -> BinList a -> f () {-# INLINE traverseFull #-} traverseFull f = go where go (ListEnd x) = f x go (ListNode _ l r) = go l *> go r ------------------------------------------------ ------------------------------------------------ ----------------------------- -- Show and Functor instances instance Show a => Show (BinList a) where show = show . toList {- Internal map Although we encourage the use of 'fmap', we define fmap as a custom 'map' function and inline 'fmap' to make them equivalent, so writing 'fmap' is actually writing 'map'. We do this to use 'map' in rewriting rules. -} map :: (a -> b) -> BinList a -> BinList b {-# INLINE[1] map #-} map f = go where go (ListEnd x) = ListEnd (f x) go (ListNode n l r) = ListNode n (go l) (go r) instance Functor BinList where {-# INLINE fmap #-} fmap = map instance Foldable BinList where -- Folding foldr1 f = go where go (ListEnd x) = x go (ListNode _ l r) = f (go l) (go r) -- fold = foldr1 mappend foldl1 = foldr1 foldMap f = fold . fmap f #if MIN_VERSION_base(4,8,0) length = (2^) . lengthExponent #endif instance Traversable BinList where sequenceA (ListEnd f) = ListEnd <$> f sequenceA (ListNode n l r) = ListNode <$> pure n <*> sequenceA l <*> sequenceA r ----------------------------- -- Example: Radix-2 FFT {- $fft This is an example demonstrating the use of binary lists to calculate the Discrete Fourier Transform of complex vectors with the Radix-2 Fast Fourier Transform algorithm. > import Data.BinaryList (BinList) > import qualified Data.BinaryList as BL > > import Data.Complex > import Data.Maybe (fromJust) > > i :: Complex Double > i = 0 :+ 1 > > fft :: BinList (Complex Double) -> BinList (Complex Double) > fft xs = > case BL.disjoinPairs xs of > Nothing -> xs > Just ps -> > let (evens,odds) = BL.unzip ps > n = BL.lengthExponent xs - 1 > q = negate $ pi * i / fromIntegral (2^n) > twiddles = BL.generate n $ \k -> exp $ q * fromIntegral k > oddsfft = BL.zipWith (*) twiddles $ fft odds > evensfft = fft evens > in fromJust $ > BL.append (BL.zipWith (+) evensfft oddsfft) > (BL.zipWith (-) evensfft oddsfft) -}
The officers at the Philadelphia Mint , including Chief Coiner Franklin Peale , were mostly the friends and relations of Director Patterson . The outsider in their midst was Chief Engraver James B. Longacre , successor to Gobrecht ( who had died in 1844 ) . A former copper @-@ plate engraver , Longacre had been appointed through the political influence of South Carolina Senator John C. Calhoun .
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying ! This file was ported from Lean 3 source module probability.martingale.borel_cantelli ! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Probability.Martingale.Convergence import Mathbin.Probability.Martingale.OptionalStopping import Mathbin.Probability.Martingale.Centering /-! # Generalized Borel-Cantelli lemma This file proves Lévy's generalized Borel-Cantelli lemma which is a generalization of the Borel-Cantelli lemmas. With this generalization, one can easily deduce the Borel-Cantelli lemmas by choosing appropriate filtrations. This file also contains the one sided martingale bound which is required to prove the generalized Borel-Cantelli. ## Main results - `measure_theory.submartingale.bdd_above_iff_exists_tendsto`: the one sided martingale bound: given a submartingale `f` with uniformly bounded differences, the set for which `f` converges is almost everywhere equal to the set for which it is bounded. - `measure_theory.ae_mem_limsup_at_top_iff`: Lévy's generalized Borel-Cantelli: given a filtration `ℱ` and a sequence of sets `s` such that `s n ∈ ℱ n` for all `n`, `limsup at_top s` is almost everywhere equal to the set for which `∑ ℙ[s (n + 1)∣ℱ n] = ∞`. -/ open Filter open NNReal ENNReal MeasureTheory ProbabilityTheory BigOperators Topology namespace MeasureTheory variable {Ω : Type _} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0} {f : ℕ → Ω → ℝ} {ω : Ω} /-! ### One sided martingale bound -/ -- TODO: `least_ge` should be defined taking values in `with_top ℕ` once the `stopped_process` -- refactor is complete /-- `least_ge f r n` is the stopping time corresponding to the first time `f ≥ r`. -/ noncomputable def leastGe (f : ℕ → Ω → ℝ) (r : ℝ) (n : ℕ) := hitting f (Set.Ici r) 0 n #align measure_theory.least_ge MeasureTheory.leastGe theorem Adapted.isStoppingTime_leastGe (r : ℝ) (n : ℕ) (hf : Adapted ℱ f) : IsStoppingTime ℱ (leastGe f r n) := hitting_isStoppingTime hf measurableSet_Ici #align measure_theory.adapted.is_stopping_time_least_ge MeasureTheory.Adapted.isStoppingTime_leastGe theorem leastGe_le {i : ℕ} {r : ℝ} (ω : Ω) : leastGe f r i ω ≤ i := hitting_le ω #align measure_theory.least_ge_le MeasureTheory.leastGe_le -- The following four lemmas shows `least_ge` behaves like a stopped process. Ideally we should -- define `least_ge` as a stopping time and take its stopped process. However, we can't do that -- with our current definition since a stopping time takes only finite indicies. An upcomming -- refactor should hopefully make it possible to have stopping times taking infinity as a value theorem leastGe_mono {n m : ℕ} (hnm : n ≤ m) (r : ℝ) (ω : Ω) : leastGe f r n ω ≤ leastGe f r m ω := hitting_mono hnm #align measure_theory.least_ge_mono MeasureTheory.leastGe_mono theorem leastGe_eq_min (π : Ω → ℕ) (r : ℝ) (ω : Ω) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : leastGe f r (π ω) ω = min (π ω) (leastGe f r n ω) := by classical refine' le_antisymm (le_min (least_ge_le _) (least_ge_mono (hπn ω) r ω)) _ by_cases hle : π ω ≤ least_ge f r n ω · rw [min_eq_left hle, least_ge] by_cases h : ∃ j ∈ Set.Icc 0 (π ω), f j ω ∈ Set.Ici r · refine' hle.trans (Eq.le _) rw [least_ge, ← hitting_eq_hitting_of_exists (hπn ω) h] · simp only [hitting, if_neg h] · rw [min_eq_right (not_le.1 hle).le, least_ge, least_ge, ← hitting_eq_hitting_of_exists (hπn ω) _] rw [not_le, least_ge, hitting_lt_iff _ (hπn ω)] at hle exact let ⟨j, hj₁, hj₂⟩ := hle ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ #align measure_theory.least_ge_eq_min MeasureTheory.leastGe_eq_min theorem stoppedValue_stoppedValue_leastGe (f : ℕ → Ω → ℝ) (π : Ω → ℕ) (r : ℝ) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : stoppedValue (fun i => stoppedValue f (leastGe f r i)) π = stoppedValue (stoppedProcess f (leastGe f r n)) π := by ext1 ω simp_rw [stopped_process, stopped_value] rw [least_ge_eq_min _ _ _ hπn] #align measure_theory.stopped_value_stopped_value_least_ge MeasureTheory.stoppedValue_stoppedValue_leastGe theorem Submartingale.stoppedValueLeastGe [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (r : ℝ) : Submartingale (fun i => stoppedValue f (leastGe f r i)) ℱ μ := by rw [submartingale_iff_expected_stopped_value_mono] · intro σ π hσ hπ hσ_le_π hπ_bdd obtain ⟨n, hπ_le_n⟩ := hπ_bdd simp_rw [stopped_value_stopped_value_least_ge f σ r fun i => (hσ_le_π i).trans (hπ_le_n i)] simp_rw [stopped_value_stopped_value_least_ge f π r hπ_le_n] refine' hf.expected_stopped_value_mono _ _ _ fun ω => (min_le_left _ _).trans (hπ_le_n ω) · exact hσ.min (hf.adapted.is_stopping_time_least_ge _ _) · exact hπ.min (hf.adapted.is_stopping_time_least_ge _ _) · exact fun ω => min_le_min (hσ_le_π ω) le_rfl · exact fun i => strongly_measurable_stopped_value_of_le hf.adapted.prog_measurable_of_discrete (hf.adapted.is_stopping_time_least_ge _ _) least_ge_le · exact fun i => integrable_stopped_value _ (hf.adapted.is_stopping_time_least_ge _ _) hf.integrable least_ge_le #align measure_theory.submartingale.stopped_value_least_ge MeasureTheory.Submartingale.stoppedValueLeastGe variable {r : ℝ} {R : ℝ≥0} theorem norm_stoppedValue_leastGe_le (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : ∀ᵐ ω ∂μ, stoppedValue f (leastGe f r i) ω ≤ r + R := by filter_upwards [hbdd]with ω hbddω change f (least_ge f r i ω) ω ≤ r + R by_cases heq : least_ge f r i ω = 0 · rw [HEq, hf0, Pi.zero_apply] exact add_nonneg hr R.coe_nonneg · obtain ⟨k, hk⟩ := Nat.exists_eq_succ_of_ne_zero HEq rw [hk, add_comm, ← sub_le_iff_le_add] have := not_mem_of_lt_hitting (hk.symm ▸ k.lt_succ_self : k < least_ge f r i ω) (zero_le _) simp only [Set.mem_union, Set.mem_Iic, Set.mem_Ici, not_or, not_le] at this exact (sub_lt_sub_left this _).le.trans ((le_abs_self _).trans (hbddω _)) #align measure_theory.norm_stopped_value_least_ge_le MeasureTheory.norm_stoppedValue_leastGe_le theorem Submartingale.stoppedValue_leastGe_snorm_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : snorm (stoppedValue f (leastGe f r i)) 1 μ ≤ 2 * μ Set.univ * ENNReal.ofReal (r + R) := by refine' snorm_one_le_of_le' ((hf.stopped_value_least_ge r).Integrable _) _ (norm_stopped_value_least_ge_le hr hf0 hbdd i) rw [← integral_univ] refine' le_trans _ ((hf.stopped_value_least_ge r).set_integral_le (zero_le _) MeasurableSet.univ) simp_rw [stopped_value, least_ge, hitting_of_le le_rfl, hf0, integral_zero'] #align measure_theory.submartingale.stopped_value_least_ge_snorm_le MeasureTheory.Submartingale.stoppedValue_leastGe_snorm_le theorem Submartingale.stoppedValue_leastGe_snorm_le' [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : snorm (stoppedValue f (leastGe f r i)) 1 μ ≤ ENNReal.toNNReal (2 * μ Set.univ * ENNReal.ofReal (r + R)) := by refine' (hf.stopped_value_least_ge_snorm_le hr hf0 hbdd i).trans _ simp [ENNReal.coe_toNNReal (measure_ne_top μ _), ENNReal.coe_toNNReal] #align measure_theory.submartingale.stopped_value_least_ge_snorm_le' MeasureTheory.Submartingale.stoppedValue_leastGe_snorm_le' /-- This lemma is superceded by `submartingale.bdd_above_iff_exists_tendsto`. -/ theorem Submartingale.exists_tendsto_of_abs_bddAbove_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) → ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by have ht : ∀ᵐ ω ∂μ, ∀ i : ℕ, ∃ c, tendsto (fun n => stopped_value f (least_ge f i n) ω) at_top (𝓝 c) := by rw [ae_all_iff] exact fun i => submartingale.exists_ae_tendsto_of_bdd (hf.stopped_value_least_ge i) (hf.stopped_value_least_ge_snorm_le' i.cast_nonneg hf0 hbdd) filter_upwards [ht]with ω hω hωb rw [BddAbove] at hωb obtain ⟨i, hi⟩ := exists_nat_gt hωb.some have hib : ∀ n, f n ω < i := by intro n exact lt_of_le_of_lt ((mem_upperBounds.1 hωb.some_mem) _ ⟨n, rfl⟩) hi have heq : ∀ n, stopped_value f (least_ge f i n) ω = f n ω := by intro n rw [least_ge, hitting, stopped_value] simp only rw [if_neg] simp only [Set.mem_Icc, Set.mem_union, Set.mem_Ici] push_neg exact fun j _ => hib j simp only [← HEq, hω i] #align measure_theory.submartingale.exists_tendsto_of_abs_bdd_above_aux MeasureTheory.Submartingale.exists_tendsto_of_abs_bddAbove_aux theorem Submartingale.bddAbove_iff_exists_tendsto_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by filter_upwards [hf.exists_tendsto_of_abs_bdd_above_aux hf0 hbdd]with ω hω using⟨hω, fun ⟨c, hc⟩ => hc.bddAbove_range⟩ #align measure_theory.submartingale.bdd_above_iff_exists_tendsto_aux MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto_aux /-- One sided martingale bound: If `f` is a submartingale which has uniformly bounded differences, then for almost every `ω`, `f n ω` is bounded above (in `n`) if and only if it converges. -/ theorem Submartingale.bddAbove_iff_exists_tendsto [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by set g : ℕ → Ω → ℝ := fun n ω => f n ω - f 0 ω with hgdef have hg : submartingale g ℱ μ := hf.sub_martingale (martingale_const_fun _ _ (hf.adapted 0) (hf.integrable 0)) have hg0 : g 0 = 0 := by ext ω simp only [hgdef, sub_self, Pi.zero_apply] have hgbdd : ∀ᵐ ω ∂μ, ∀ i : ℕ, |g (i + 1) ω - g i ω| ≤ ↑R := by simpa only [sub_sub_sub_cancel_right] filter_upwards [hg.bdd_above_iff_exists_tendsto_aux hg0 hgbdd]with ω hω convert hω using 1 <;> rw [eq_iff_iff] · simp only [hgdef] refine' ⟨fun h => _, fun h => _⟩ <;> obtain ⟨b, hb⟩ := h <;> refine' ⟨b + |f 0 ω|, fun y hy => _⟩ <;> obtain ⟨n, rfl⟩ := hy · simp_rw [sub_eq_add_neg] exact add_le_add (hb ⟨n, rfl⟩) (neg_le_abs_self _) · exact sub_le_iff_le_add.1 (le_trans (sub_le_sub_left (le_abs_self _) _) (hb ⟨n, rfl⟩)) · simp only [hgdef] refine' ⟨fun h => _, fun h => _⟩ <;> obtain ⟨c, hc⟩ := h · exact ⟨c - f 0 ω, hc.sub_const _⟩ · refine' ⟨c + f 0 ω, _⟩ have := hc.add_const (f 0 ω) simpa only [sub_add_cancel] #align measure_theory.submartingale.bdd_above_iff_exists_tendsto MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto /-! ### Lévy's generalization of the Borel-Cantelli lemma Lévy's generalization of the Borel-Cantelli lemma states that: given a natural number indexed filtration $(\mathcal{F}_n)$, and a sequence of sets $(s_n)$ such that for all $n$, $s_n \in \mathcal{F}_n$, $limsup_n s_n$ is almost everywhere equal to the set for which $\sum_n \mathbb{P}[s_n \mid \mathcal{F}_n] = \infty$. The proof strategy follows by constructing a martingale satisfying the one sided martingale bound. In particular, we define $$ f_n := \sum_{k < n} \mathbf{1}_{s_{n + 1}} - \mathbb{P}[s_{n + 1} \mid \mathcal{F}_n]. $$ Then, as a martingale is both a sub and a super-martingale, the set for which it is unbounded from above must agree with the set for which it is unbounded from below almost everywhere. Thus, it can only converge to $\pm \infty$ with probability 0. Thus, by considering $$ \limsup_n s_n = \{\sum_n \mathbf{1}_{s_n} = \infty\} $$ almost everywhere, the result follows. -/ theorem Martingale.bddAbove_range_iff_bddBelow_range [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ BddBelow (Set.range fun n => f n ω) := by have hbdd' : ∀ᵐ ω ∂μ, ∀ i, |(-f) (i + 1) ω - (-f) i ω| ≤ R := by filter_upwards [hbdd]with ω hω i erw [← abs_neg, neg_sub, sub_neg_eq_add, neg_add_eq_sub] exact hω i have hup := hf.submartingale.bdd_above_iff_exists_tendsto hbdd have hdown := hf.neg.submartingale.bdd_above_iff_exists_tendsto hbdd' filter_upwards [hup, hdown]with ω hω₁ hω₂ have : (∃ c, tendsto (fun n => f n ω) at_top (𝓝 c)) ↔ ∃ c, tendsto (fun n => (-f) n ω) at_top (𝓝 c) := by constructor <;> rintro ⟨c, hc⟩ · exact ⟨-c, hc.neg⟩ · refine' ⟨-c, _⟩ convert hc.neg simp only [neg_neg, Pi.neg_apply] rw [hω₁, this, ← hω₂] constructor <;> rintro ⟨c, hc⟩ <;> refine' ⟨-c, fun ω hω => _⟩ · rw [mem_upperBounds] at hc refine' neg_le.2 (hc _ _) simpa only [Pi.neg_apply, Set.mem_range, neg_inj] · rw [mem_lowerBounds] at hc simp_rw [Set.mem_range, Pi.neg_apply, neg_eq_iff_eq_neg] at hω refine' le_neg.1 (hc _ _) simpa only [Set.mem_range] #align measure_theory.martingale.bdd_above_range_iff_bdd_below_range MeasureTheory.Martingale.bddAbove_range_iff_bddBelow_range theorem Martingale.ae_not_tendsto_atTop_atTop [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atTop := by filter_upwards [hf.bdd_above_range_iff_bdd_below_range hbdd]with ω hω htop using unbounded_of_tendsto_at_top htop (hω.2 <| bddBelow_range_of_tendsto_atTop_atTop htop) #align measure_theory.martingale.ae_not_tendsto_at_top_at_top MeasureTheory.Martingale.ae_not_tendsto_atTop_atTop theorem Martingale.ae_not_tendsto_atTop_atBot [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atBot := by filter_upwards [hf.bdd_above_range_iff_bdd_below_range hbdd]with ω hω htop using unbounded_of_tendsto_at_bot htop (hω.1 <| bddAbove_range_of_tendsto_atTop_atBot htop) #align measure_theory.martingale.ae_not_tendsto_at_top_at_bot MeasureTheory.Martingale.ae_not_tendsto_atTop_atBot namespace BorelCantelli /-- Auxiliary definition required to prove Lévy's generalization of the Borel-Cantelli lemmas for which we will take the martingale part. -/ noncomputable def process (s : ℕ → Set Ω) (n : ℕ) : Ω → ℝ := ∑ k in Finset.range n, (s (k + 1)).indicator 1 #align measure_theory.borel_cantelli.process MeasureTheory.BorelCantelli.process variable {s : ℕ → Set Ω} theorem process_zero : process s 0 = 0 := by rw [process, Finset.range_zero, Finset.sum_empty] #align measure_theory.borel_cantelli.process_zero MeasureTheory.BorelCantelli.process_zero theorem adapted_process (hs : ∀ n, measurable_set[ℱ n] (s n)) : Adapted ℱ (process s) := fun n => Finset.stronglyMeasurable_sum' _ fun k hk => stronglyMeasurable_one.indicator <| ℱ.mono (Finset.mem_range.1 hk) _ <| hs _ #align measure_theory.borel_cantelli.adapted_process MeasureTheory.BorelCantelli.adapted_process theorem martingalePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω) (n : ℕ) : martingalePart (process s) ℱ μ n = ∑ k in Finset.range n, (s (k + 1)).indicator 1 - μ[(s (k + 1)).indicator 1|ℱ k] := by simp only [martingale_part_eq_sum, process_zero, zero_add] refine' Finset.sum_congr rfl fun k hk => _ simp only [process, Finset.sum_range_succ_sub_sum] #align measure_theory.borel_cantelli.martingale_part_process_ae_eq MeasureTheory.BorelCantelli.martingalePart_process_ae_eq theorem predictablePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω) (n : ℕ) : predictablePart (process s) ℱ μ n = ∑ k in Finset.range n, μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k] := by have := martingale_part_process_ae_eq ℱ μ s n simp_rw [martingale_part, process, Finset.sum_sub_distrib] at this exact sub_right_injective this #align measure_theory.borel_cantelli.predictable_part_process_ae_eq MeasureTheory.BorelCantelli.predictablePart_process_ae_eq theorem process_difference_le (s : ℕ → Set Ω) (ω : Ω) (n : ℕ) : |process s (n + 1) ω - process s n ω| ≤ (1 : ℝ≥0) := by rw [Nonneg.coe_one, process, process, Finset.sum_apply, Finset.sum_apply, Finset.sum_range_succ_sub_sum, ← Real.norm_eq_abs, norm_indicator_eq_indicator_norm] refine' Set.indicator_le' (fun _ _ => _) (fun _ _ => zero_le_one) _ rw [Pi.one_apply, norm_one] #align measure_theory.borel_cantelli.process_difference_le MeasureTheory.BorelCantelli.process_difference_le theorem integrableProcess (μ : Measure Ω) [IsFiniteMeasure μ] (hs : ∀ n, measurable_set[ℱ n] (s n)) (n : ℕ) : Integrable (process s n) μ := integrableFinsetSum' _ fun k hk => IntegrableOn.integrableIndicator (integrableConst 1) <| ℱ.le _ _ <| hs _ #align measure_theory.borel_cantelli.integrable_process MeasureTheory.BorelCantelli.integrableProcess end BorelCantelli open BorelCantelli /-- An a.e. monotone adapted process `f` with uniformly bounded differences converges to `+∞` if and only if its predictable part also converges to `+∞`. -/ theorem tendsto_sum_indicator_atTop_iff [IsFiniteMeasure μ] (hfmono : ∀ᵐ ω ∂μ, ∀ n, f n ω ≤ f (n + 1) ω) (hf : Adapted ℱ f) (hint : ∀ n, Integrable (f n) μ) (hbdd : ∀ᵐ ω ∂μ, ∀ n, |f (n + 1) ω - f n ω| ≤ R) : ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop atTop ↔ Tendsto (fun n => predictablePart f ℱ μ n ω) atTop atTop := by have h₁ := (martingale_martingale_part hf hint).ae_not_tendsto_atTop_atTop (martingale_part_bdd_difference ℱ hbdd) have h₂ := (martingale_martingale_part hf hint).ae_not_tendsto_atTop_atBot (martingale_part_bdd_difference ℱ hbdd) have h₃ : ∀ᵐ ω ∂μ, ∀ n, 0 ≤ (μ[f (n + 1) - f n|ℱ n]) ω := by refine' ae_all_iff.2 fun n => condexp_nonneg _ filter_upwards [ae_all_iff.1 hfmono n]with ω hω using sub_nonneg.2 hω filter_upwards [h₁, h₂, h₃, hfmono]with ω hω₁ hω₂ hω₃ hω₄ constructor <;> intro ht · refine' tendsto_at_top_at_top_of_monotone' _ _ · intro n m hnm simp only [predictable_part, Finset.sum_apply] refine' Finset.sum_mono_set_of_nonneg hω₃ (Finset.range_mono hnm) rintro ⟨b, hbdd⟩ rw [← tendsto_neg_at_bot_iff] at ht simp only [martingale_part, sub_eq_add_neg] at hω₁ exact hω₁ (tendsto_at_top_add_right_of_le _ (-b) (tendsto_neg_at_bot_iff.1 ht) fun n => neg_le_neg (hbdd ⟨n, rfl⟩)) · refine' tendsto_at_top_at_top_of_monotone' (monotone_nat_of_le_succ hω₄) _ rintro ⟨b, hbdd⟩ exact hω₂ ((tendsto_at_bot_add_left_of_ge _ b fun n => hbdd ⟨n, rfl⟩) <| tendsto_neg_at_bot_iff.2 ht) #align measure_theory.tendsto_sum_indicator_at_top_iff MeasureTheory.tendsto_sum_indicator_atTop_iff open BorelCantelli theorem tendsto_sum_indicator_atTop_iff' [IsFiniteMeasure μ] {s : ℕ → Set Ω} (hs : ∀ n, measurable_set[ℱ n] (s n)) : ∀ᵐ ω ∂μ, Tendsto (fun n => ∑ k in Finset.range n, (s (k + 1)).indicator (1 : Ω → ℝ) ω) atTop atTop ↔ Tendsto (fun n => ∑ k in Finset.range n, (μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k]) ω) atTop atTop := by have := tendsto_sum_indicator_at_top_iff (eventually_of_forall fun ω n => _) (adapted_process hs) (integrable_process μ hs) (eventually_of_forall <| process_difference_le s) swap · rw [process, process, ← sub_nonneg, Finset.sum_apply, Finset.sum_apply, Finset.sum_range_succ_sub_sum] exact Set.indicator_nonneg (fun _ _ => zero_le_one) _ simp_rw [process, predictable_part_process_ae_eq] at this simpa using this #align measure_theory.tendsto_sum_indicator_at_top_iff' MeasureTheory.tendsto_sum_indicator_atTop_iff' /-- **Lévy's generalization of the Borel-Cantelli lemma**: given a sequence of sets `s` and a filtration `ℱ` such that for all `n`, `s n` is `ℱ n`-measurable, `at_top.limsup s` is almost everywhere equal to the set for which `∑ k, ℙ(s (k + 1) | ℱ k) = ∞`. -/ theorem ae_mem_limsup_atTop_iff (μ : Measure Ω) [IsFiniteMeasure μ] {s : ℕ → Set Ω} (hs : ∀ n, measurable_set[ℱ n] (s n)) : ∀ᵐ ω ∂μ, ω ∈ limsup s atTop ↔ Tendsto (fun n => ∑ k in Finset.range n, (μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k]) ω) atTop atTop := (limsup_eq_tendsto_sum_indicator_atTop ℝ s).symm ▸ tendsto_sum_indicator_atTop_iff' hs #align measure_theory.ae_mem_limsup_at_top_iff MeasureTheory.ae_mem_limsup_atTop_iff end MeasureTheory
Not unlike Car rental you sometimes need a slightly larger vehicle with more capacity, often on Moving Day Moving Trucks (BoxVan) UHaul (2 Locations) Stonegate Self Storage Davis Carpet Sales Budget (2 Locations) Budget Rent a Car South Davis Storage Harrison Self Storage All Star Rents Pickup Trucks Home Depot Dump Trucks All Star Rents Cargo Vans All Star Rents ? How Big of a Truck do I need? Common sizes of trucks: Pickup 1/2 Ton 1 Ton 6 Trailer 10 14 24 Flatbed
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{csquotes} \usepackage[backend=bibtex]{biblatex} \usepackage{amsmath} \usepackage{hyperref} \usepackage{graphicx} \addbibresource{sources.bib} \title{Codon Usage Differences Among Homo Sapiens Populations} \author{Martin Indra, Petr Tománek} \date{June 2019} \begin{document} \begin{titlepage} \maketitle \end{titlepage} \begin{abstract} This work focuses on statistical differences in codon usage among 26 human populations tracked by 1000 Genomes Project. \end{abstract} \clearpage \section{Introduction} The number of available whole-genome sequences of H. Sapiens DNA is steadily growing which brings possibility to do advanced statistical analyses on the data. In this article we examine codon usage differences among human individuals from different populations in the following steps: \begin{enumerate} \item We downloaded whole-genome sequences of 426 individuals from 26 different populations. \item For each individual, we extracted protein coding sequences and counted number of occurrences of each of 64 possible DNA triplets. Id est we computed codon usage for each individual. \item We compare the resulting data with preexisting sources. \item We analyze the resulting data with several statistical methods. \end{enumerate} \section{Source Code and Data} Source code and data behind this report can be obtained in git repository hosted on \href{https://github.com/Indy2222/mbg-codon-usage}{github.com/Indy2222/mbg-codon-usage}. Version of the source codes and data used is tagged as \href{https://github.com/Indy2222/mbg-codon-usage/releases/tag/v1.0}{``v1.0''}. \section{Coding Sequences} We calculated codon usage for 423 individuals from 26 different populations on data provided by 1000 Genomes Project\cite{1000genomes}. We used only high-coverage data from phase 3 of the project aligned to GRCh38\cite{Schneider072116} reference genome. The data were downloaded from FTP server of National Center for Biotechnology Information (NCBI). To calculate codon usage, we extracted coding sequences identified by Release 22 of the Consensus Coding Sequence Project (CCDS)\cite{pruitt2009consensus}. We extracted only sequences meeting all of the following criteria: \begin{itemize} \item Location of the sequence is known. \item Status of the sequence is ``Public''. \item The sequence is located on positive strand. \item Length of the sequence is a multiple of 3. \end{itemize} We extract coding sequences from CRAM files containing aligned DNA reads. The final CDS is constructed from individual exons which are constructed from individual reads. We filled missing symbols with ``-''. Figure \ref{fig:cram} illustrates exon creation from incomplete sequence. \begin{figure}[h] \centering \includegraphics[scale=0.3]{figures/exon_reading.png} \caption{Construction of exon from reads} \label{fig:cram} \end{figure} We further filtered coding sequences for each individual separately based on the following rules: \begin{itemize} \item The sequence starts with start codon ``ATG''. \item The sequence ends with one of stop codons ``TAG'', ``TAA'' and ``TGA''. \end{itemize} When counting codon occurrences we accounted only for triplets with symbols ``A'', ``C'', ``T'', ``G'' on all three positions, id est we skipped incomplete codons. \section{Overall Codon Usage} We used formula \ref{eq:total-codon-usage} to calculate overall codon usage of all individuals. \begin{equation} \label{eq:total-codon-usage} f_{t} = 1000 \cdot \frac{\sum_{i = 1}^N u_{i, t}}{\sum_{i = 1}^N \sum_{j = 1}^{64} u_{i, j}} \end{equation} Where $f_{t}$ is frequency of codon $t$ per one thousand codons, $N = 423$ is number of sampled individuals and $u_{i, j}$ is number of occurrences of codon $j$ in all coding sequences of individual $i$. The overall codon usage of our data sample is given by table \ref{table:overall-codon-usage}. \begin{table}[h] \centering \begin{tabular}{|lr|lr|lr|lr|} \hline AAA & 25.5 & AAT & 17.5 & AAC & 19.0 & AAG & 31.9 \\ ATA & 7.7 & ATT & 16.0 & ATC & 20.0 & ATG & 21.6 \\ ACA & 15.6 & ACT & 13.5 & ACC & 18.3 & ACG & 6.1 \\ AGA & 12.3 & AGT & 13.0 & AGC & 20.0 & AGG & 12.0 \\ TAA & 0.8 & TAT & 11.9 & TAC & 14.4 & TAG & 0.6 \\ TTA & 7.9 & TTT & 17.0 & TTC & 19.0 & TTG & 13.0 \\ TCA & 12.9 & TCT & 15.7 & TCC & 17.7 & TCG & 4.5 \\ TGA & 1.3 & TGT & 10.5 & TGC & 11.9 & TGG & 12.1 \\ CAA & 12.9 & CAT & 11.1 & CAC & 15.0 & CAG & 34.7 \\ CTA & 7.2 & CTT & 13.3 & CTC & 18.5 & CTG & 38.1 \\ CCA & 17.8 & CCT & 18.0 & CCC & 20.0 & CCG & 7.0 \\ CGA & 6.4 & CGT & 4.5 & CGC & 10.0 & CGG & 11.6 \\ GAA & 30.8 & GAT & 22.9 & GAC & 25.2 & GAG & 40.2 \\ GTA & 7.3 & GTT & 11.2 & GTC & 13.9 & GTG & 27.2 \\ GCA & 16.4 & GCT & 18.5 & GCC & 27.2 & GCG & 7.2 \\ GGA & 16.7 & GGT & 10.7 & GGC & 21.4 & GGG & 16.0 \\ \hline \end{tabular} \caption{Overall codon usage given as per-thousand occurrences} \label{table:overall-codon-usage} \end{table} We compared codon usage of our data with data from codon usage database at \href{https://www.kazusa.or.jp/codon/cgi-bin/showcodon.cgi?species=9606}{kazusa.or.jp} \cite{nakamura2000codon} and found very small mean absolute deviation of $0.45$. \section{Individual Codon Usage} We used formula \ref{eq:individual-codon-usage} to calculate codon usage of each individual. \begin{equation} \label{eq:individual-codon-usage} f_{i, t} = 1000 \cdot \frac{u_{i, t}}{\sum_{j = 1}^{64} u_{i, j}} \end{equation} Where $f_{i, t}$ is per-thousand frequency of codon $t$ for individual $i$ and $u_{i, j}$ is number of occurrences of codon $j$ in all coding sequences of individual $i$. \begin{figure}[h] \centering \includegraphics[scale=0.5]{figures/pca.png} \caption{PCA of codon usage, individuals from different populations are depicted in different color} \label{fig:pca} \end{figure} The 426 individuals are split into 26 populations reported in table \ref{table:pupulations}. We utilized Principal Component Analysis (PCA)\cite{pearson1901liii} dimensionality reduction technique on the 64-dimensional data to obtain 2D visualization reported in figure \ref{fig:pca}. The first two principal components explain 36\% and 14\% of variability respectively. We further used Kruskal–Wallis H test\cite{kruskal1952use} on 61 codons, excluding stop codons ``TAG'', ``TAA'' and ``TGA'', in identification of codons which have different usage distribution among populations with statistical significance. We did Bonferroni correction\cite{dunn1958estimation} to compensate for multiple comparison test. We report codons with unequal distributions among populations in table \ref{table:diff-codons}, the table excludes codons with p-value larger than $\alpha = \frac{0.05}{61}$. \begin{table}[h] \centering \begin{tabular}{|l|l|l|l|} \hline \bf{Codon} & \bf{p-value} & \bf{Codon} & \bf{p-value} \\ \hline TGG & $1.8 \cdot 10^{-13}$ & TAT & $1.6 \cdot 10^{-05}$ \\ GAC & $2.1 \cdot 10^{-10}$ & CTG & $2.5 \cdot 10^{-05}$ \\ AAG & $7.8 \cdot 10^{-08}$ & CGA & $2.6 \cdot 10^{-05}$ \\ AGA & $1.4 \cdot 10^{-07}$ & CGT & $9.1 \cdot 10^{-05}$ \\ ATA & $1.8 \cdot 10^{-07}$ & GAA & $2.0 \cdot 10^{-04}$ \\ AGG & $8.5 \cdot 10^{-07}$ & GTT & $2.1 \cdot 10^{-04}$ \\ GTA & $9.0 \cdot 10^{-07}$ & GGG & $2.8 \cdot 10^{-04}$ \\ CAG & $2.2 \cdot 10^{-06}$ & GGA & $2.8 \cdot 10^{-04}$ \\ ACA & $2.2 \cdot 10^{-06}$ & TTT & $5.2 \cdot 10^{-04}$ \\ GAG & $1.3 \cdot 10^{-05}$ & GAT & $6.0 \cdot 10^{-04}$ \\ GTG & $1.4 \cdot 10^{-05}$ & & \\ \hline \end{tabular} \caption{Codons with different distribution among different populations} \label{table:diff-codons} \end{table} \begin{table}[p] \centering \begin{tabular}{|l|l|} \hline \bf{Code} & \bf{Populating Description} \\ \hline CHB & Han Chinese in Beijing, China \\ JPT & Japanese in Tokyo, Japan \\ CHS & Southern Han Chinese \\ CDX & Chinese Dai in Xishuangbanna, China \\ KHV & Kinh in Ho Chi Minh City, Vietnam \\ CEU & Utah Residents (CEPH) with Northern and Western European Ancestry \\ TSI & Toscani in Italia \\ FIN & Finnish in Finland \\ GBR & British in England and Scotland \\ IBS & Iberian Population in Spain \\ YRI & Yoruba in Ibadan, Nigeria \\ LWK & Luhya in Webuye, Kenya \\ GWD & Gambian in Western Divisions in the Gambia \\ MSL & Mende in Sierra Leone \\ ESN & Esan in Nigeria \\ ASW & Americans of African Ancestry in SW USA \\ ACB & African Caribbeans in Barbados \\ MXL & Mexican Ancestry from Los Angeles USA \\ PUR & Puerto Ricans from Puerto Rico \\ CLM & Colombians from Medellin, Colombia \\ PEL & Peruvians from Lima, Peru \\ GIH & Gujarati Indian from Houston, Texas \\ PJL & Punjabi from Lahore, Pakistan \\ BEB & Bengali from Bangladesh \\ STU & Sri Lankan Tamil from the UK \\ ITU & Indian Telugu from the UK \\ \hline \end{tabular} \caption{1000 Genome Project populations\cite{1000genomes}} \label{table:pupulations} \end{table} \section{Conclusion} Our calculated codon usage largely agrees with previously reported statistics. We identified 21 codons with different statistical distribution among different populations with large statistical significance. However our reporting must be taken with caution because our selection of coding sequences may have introduced a systematic error. \clearpage \printbibliography \end{document}
sd_section("UI Layout", "Functions for laying out the user interface for your application.", c( "absolutePanel", "bootstrapPage", "column", "conditionalPanel", "fillPage", "fillRow", "fixedPage", "fluidPage", "headerPanel", "helpText", "icon", "mainPanel", "navbarPage", "navlistPanel", "pageWithSidebar", "sidebarLayout", "sidebarPanel", "tabPanel", "tabsetPanel", "titlePanel", "inputPanel", "flowLayout", "splitLayout", "verticalLayout", "wellPanel", "withMathJax" ) ) sd_section("UI Inputs", "Functions for creating user interface elements that prompt the user for input values or interaction.", c( "actionButton", "checkboxGroupInput", "checkboxInput", "dateInput", "dateRangeInput", "fileInput", "numericInput", "radioButtons", "selectInput", "sliderInput", "submitButton", "textInput", "textAreaInput", "passwordInput", "modalButton", "updateActionButton", "updateCheckboxGroupInput", "updateCheckboxInput", "updateDateInput", "updateDateRangeInput", "updateNumericInput", "updateRadioButtons", "updateSelectInput", "updateSliderInput", "updateTabsetPanel", "updateTextInput", "updateTextAreaInput", "updateQueryString", "getQueryString" ) ) sd_section("UI Outputs", "Functions for creating user interface elements that, in conjunction with rendering functions, display different kinds of output from your application.", c( "htmlOutput", "plotOutput", "outputOptions", "tableOutput", "textOutput", "verbatimTextOutput", "downloadButton", "Progress", "withProgress", "modalDialog", "urlModal", "showModal", "showNotification" ) ) sd_section("Interface builder functions", "A sub-library for writing HTML using R functions. These functions form the foundation on which the higher level user interface functions are built, and can also be used in your Shiny UI to provide custom HTML, CSS, and JavaScript.", c( "builder", "HTML", "include", "singleton", "tag", "validateCssUnit", "withTags", "htmlTemplate", "bootstrapLib", "suppressDependencies", "insertUI", "removeUI" ) ) sd_section("Rendering functions", "Functions that you use in your application's server side code, assigning them to outputs that appear in your user interface.", c( "renderPlot", "renderText", "renderPrint", "renderDataTable", "renderImage", "renderTable", "renderUI", "downloadHandler", "reactivePlot", "reactivePrint", "reactiveTable", "reactiveText", "reactiveUI" ) ) sd_section("Reactive programming", "A sub-library that provides reactive programming facilities for R.", c( "reactive", "observe", "observeEvent", "reactiveValues", "reactiveValuesToList", "is.reactivevalues", "isolate", "invalidateLater", "debounce", "showReactLog", "makeReactiveBinding", "reactiveFileReader", "reactivePoll", "reactiveTimer", "domains", "freezeReactiveValue" ) ) sd_section("Boilerplate", "Functions that are required boilerplate in ui.R and server.R.", c( "shinyUI", "shinyServer" ) ) sd_section("Running", "Functions that are used to run or stop Shiny applications.", c( "runApp", "runGadget", "runExample", "runGadget", "runUrl", "stopApp", "viewer" ) ) sd_section("Bookmarking state", "Functions that are used for bookmarking and restoring state.", c( "bookmarkButton", "enableBookmarking", "setBookmarkExclude", "showBookmarkUrlModal", "onBookmark" ) ) sd_section("Extending Shiny", "Functions that are intended to be called by third-party packages that extend Shiny.", c( "createWebDependency", "addResourcePath", "registerInputHandler", "removeInputHandler", "markRenderFunction" ) ) sd_section("Utility functions", "Miscellaneous utilities that may be useful to advanced users or when extending Shiny.", c( "req", "validate", "session", "shinyOptions", "safeError", "onFlush", "restoreInput", "applyInputHandlers", "exprToFunction", "installExprFunction", "parseQueryString", "plotPNG", "exportTestValues", "snapshotExclude", "markOutputAttrs", "repeatable", "shinyDeprecated", "serverInfo", "shiny-options" ) ) sd_section("Plot interaction", "Functions related to interactive plots", c( "brushedPoints", "brushOpts", "clickOpts", "dblclickOpts", "hoverOpts", "nearPoints" ) ) sd_section("Modules", "Functions for modularizing Shiny apps", c( "NS", "callModule" ) ) sd_section("Embedding", "Functions that are intended for third-party packages that embed Shiny applications.", c( "shinyApp", "maskReactiveContext" ) )
(* Copyright (c) 2009-2012, 2015, Adam Chlipala * * This work is licensed under a * Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 * Unported License. * The license text is available at: * http://creativecommons.org/licenses/by-nc-nd/3.0/ *) (* begin hide *) Require Import List. Require Import DepList Cpdt.CpdtTactics. Require Extraction. Set Implicit Arguments. Set Asymmetric Patterns. (* end hide *) (** printing $ %({}*% #(<a/>*# *) (** printing ^ %*{})% #*<a/>)# *) (** %\chapter{Universes and Axioms}% *) (** Many traditional theorems can be proved in Coq without special knowledge of CIC, the logic behind the prover. A development just seems to be using a particular ASCII notation for standard formulas based on %\index{set theory}%set theory. Nonetheless, as we saw in Chapter 4, CIC differs from set theory in starting from fewer orthogonal primitives. It is possible to define the usual logical connectives as derived notions. The foundation of it all is a dependently typed functional programming language, based on dependent function types and inductive type families. By using the facilities of this language directly, we can accomplish some things much more easily than in mainstream math. %\index{Gallina}%Gallina, which adds features to the more theoretical CIC%~\cite{CIC}%, is the logic implemented in Coq. It has a relatively simple foundation that can be defined rigorously in a page or two of formal proof rules. Still, there are some important subtleties that have practical ramifications. This chapter focuses on those subtleties, avoiding formal metatheory in favor of example code. *) (** * The [Type] Hierarchy *) (** %\index{type hierarchy}%Every object in Gallina has a type. *) Check 0. (** %\vspace{-.15in}% [[ 0 : nat ]] It is natural enough that zero be considered as a natural number. *) Check nat. (** %\vspace{-.15in}% [[ nat : Set ]] From a set theory perspective, it is unsurprising to consider the natural numbers as a "set." *) Check Set. (** %\vspace{-.15in}% [[ Set : Type ]] The type [Set] may be considered as the set of all sets, a concept that set theory handles in terms of%\index{class (in set theory)}% _classes_. In Coq, this more general notion is [Type]. *) Check Type. (** %\vspace{-.15in}% [[ Type : Type ]] Strangely enough, [Type] appears to be its own type. It is known that polymorphic languages with this property are inconsistent, via %\index{Girard's paradox}%Girard's paradox%~\cite{GirardsParadox}%. That is, using such a language to encode proofs is unwise, because it is possible to "prove" any proposition. What is really going on here? Let us repeat some of our queries after toggling a flag related to Coq's printing behavior.%\index{Vernacular commands!Set Printing Universes}% *) Set Printing Universes. Check nat. (** %\vspace{-.15in}% [[ nat : Set ]] *) Check Set. (** %\vspace{-.15in}% [[ Set : Type $ (0)+1 ^ ]] *) Check Type. (** %\vspace{-.15in}% [[ Type $ Top.3 ^ : Type $ (Top.3)+1 ^ ]] Occurrences of [Type] are annotated with some additional information, inside comments. These annotations have to do with the secret behind [Type]: it really stands for an infinite hierarchy of types. The type of [Set] is [Type(0)], the type of [Type(0)] is [Type(1)], the type of [Type(1)] is [Type(2)], and so on. This is how we avoid the "[Type : Type]" paradox. As a convenience, the universe hierarchy drives Coq's one variety of subtyping. Any term whose type is [Type] at level [i] is automatically also described by [Type] at level [j] when [j > i]. In the outputs of our first [Check] query, we see that the type level of [Set]'s type is [(0)+1]. Here [0] stands for the level of [Set], and we increment it to arrive at the level that _classifies_ [Set]. In the third query's output, we see that the occurrence of [Type] that we check is assigned a fresh%\index{universe variable}% _universe variable_ [Top.3]. The output type increments [Top.3] to move up a level in the universe hierarchy. As we write code that uses definitions whose types mention universe variables, unification may refine the values of those variables. Luckily, the user rarely has to worry about the details. Another crucial concept in CIC is%\index{predicativity}% _predicativity_. Consider these queries. *) Check forall T : nat, fin T. (** %\vspace{-.15in}% [[ forall T : nat, fin T : Set ]] *) Check forall T : Set, T. (** %\vspace{-.15in}% [[ forall T : Set, T : Type $ max(0, (0)+1) ^ ]] *) Check forall T : Type, T. (** %\vspace{-.15in}% [[ forall T : Type $ Top.9 ^ , T : Type $ max(Top.9, (Top.9)+1) ^ ]] These outputs demonstrate the rule for determining which universe a [forall] type lives in. In particular, for a type [forall x : T1, T2], we take the maximum of the universes of [T1] and [T2]. In the first example query, both [T1] ([nat]) and [T2] ([fin T]) are in [Set], so the [forall] type is in [Set], too. In the second query, [T1] is [Set], which is at level [(0)+1]; and [T2] is [T], which is at level [0]. Thus, the [forall] exists at the maximum of these two levels. The third example illustrates the same outcome, where we replace [Set] with an occurrence of [Type] that is assigned universe variable [Top.9]. This universe variable appears in the places where [0] appeared in the previous query. The behind-the-scenes manipulation of universe variables gives us predicativity. Consider this simple definition of a polymorphic identity function, where the first argument [T] will automatically be marked as implicit, since it can be inferred from the type of the second argument [x]. *) Definition id (T : Set) (x : T) : T := x. Check id 0. (** %\vspace{-.15in}% [[ id 0 : nat Check id Set. ]] << Error: Illegal application (Type Error): ... The 1st term has type "Type (* (Top.15)+1 *)" which should be coercible to "Set". >> The parameter [T] of [id] must be instantiated with a [Set]. The type [nat] is a [Set], but [Set] is not. We can try fixing the problem by generalizing our definition of [id]. *) Reset id. Definition id (T : Type) (x : T) : T := x. Check id 0. (** %\vspace{-.15in}% [[ id 0 : nat ]] *) Check id Set. (** %\vspace{-.15in}% [[ id Set : Type $ Top.17 ^ ]] *) Check id Type. (** %\vspace{-.15in}% [[ id Type $ Top.18 ^ : Type $ Top.19 ^ ]] *) (** So far so good. As we apply [id] to different [T] values, the inferred index for [T]'s [Type] occurrence automatically moves higher up the type hierarchy. [[ Check id id. ]] << Error: Universe inconsistency (cannot enforce Top.16 < Top.16). >> %\index{universe inconsistency}%This error message reminds us that the universe variable for [T] still exists, even though it is usually hidden. To apply [id] to itself, that variable would need to be less than itself in the type hierarchy. Universe inconsistency error messages announce cases like this one where a term could only type-check by violating an implied constraint over universe variables. Such errors demonstrate that [Type] is _predicative_, where this word has a CIC meaning closely related to its usual mathematical meaning. A predicative system enforces the constraint that, when an object is defined using some sort of quantifier, none of the quantifiers may ever be instantiated with the object itself. %\index{impredicativity}%Impredicativity is associated with popular paradoxes in set theory, involving inconsistent constructions like "the set of all sets that do not contain themselves" (%\index{Russell's paradox}%Russell's paradox). Similar paradoxes would result from uncontrolled impredicativity in Coq. *) (** ** Inductive Definitions *) (** Predicativity restrictions also apply to inductive definitions. As an example, let us consider a type of expression trees that allows injection of any native Coq value. The idea is that an [exp T] stands for an encoded expression of type [T]. [[ Inductive exp : Set -> Set := | Const : forall T : Set, T -> exp T | Pair : forall T1 T2, exp T1 -> exp T2 -> exp (T1 * T2) | Eq : forall T, exp T -> exp T -> exp bool. ]] << Error: Large non-propositional inductive types must be in Type. >> This definition is%\index{large inductive types}% _large_ in the sense that at least one of its constructors takes an argument whose type has type [Type]. Coq would be inconsistent if we allowed definitions like this one in their full generality. Instead, we must change [exp] to live in [Type]. We will go even further and move [exp]'s index to [Type] as well. *) Inductive exp : Type -> Type := | Const : forall T, T -> exp T | Pair : forall T1 T2, exp T1 -> exp T2 -> exp (T1 * T2) | Eq : forall T, exp T -> exp T -> exp bool. (** Note that before we had to include an annotation [: Set] for the variable [T] in [Const]'s type, but we need no annotation now. When the type of a variable is not known, and when that variable is used in a context where only types are allowed, Coq infers that the variable is of type [Type], the right behavior here, though it was wrong for the [Set] version of [exp]. Our new definition is accepted. We can build some sample expressions. *) Check Const 0. (** %\vspace{-.15in}% [[ Const 0 : exp nat ]] *) Check Pair (Const 0) (Const tt). (** %\vspace{-.15in}% [[ Pair (Const 0) (Const tt) : exp (nat * unit) ]] *) Check Eq (Const Set) (Const Type). (** %\vspace{-.15in}% [[ Eq (Const Set) (Const Type $ Top.59 ^ ) : exp bool ]] We can check many expressions, including fancy expressions that include types. However, it is not hard to hit a type-checking wall. [[ Check Const (Const O). ]] << Error: Universe inconsistency (cannot enforce Top.42 < Top.42). >> We are unable to instantiate the parameter [T] of [Const] with an [exp] type. To see why, it is helpful to print the annotated version of [exp]'s inductive definition. *) (** [[ Print exp. ]] %\vspace{-.15in}%[[ Inductive exp : Type $ Top.8 ^ -> Type $ max(0, (Top.11)+1, (Top.14)+1, (Top.15)+1, (Top.19)+1) ^ := Const : forall T : Type $ Top.11 ^ , T -> exp T | Pair : forall (T1 : Type $ Top.14 ^ ) (T2 : Type $ Top.15 ^ ), exp T1 -> exp T2 -> exp (T1 * T2) | Eq : forall T : Type $ Top.19 ^ , exp T -> exp T -> exp bool ]] We see that the index type of [exp] has been assigned to universe level [Top.8]. In addition, each of the four occurrences of [Type] in the types of the constructors gets its own universe variable. Each of these variables appears explicitly in the type of [exp]. In particular, any type [exp T] lives at a universe level found by incrementing by one the maximum of the four argument variables. Therefore, [exp] _must_ live at a higher universe level than any type which may be passed to one of its constructors. This consequence led to the universe inconsistency. Strangely, the universe variable [Top.8] only appears in one place. Is there no restriction imposed on which types are valid arguments to [exp]? In fact, there is a restriction, but it only appears in a global set of universe constraints that are maintained "off to the side," not appearing explicitly in types. We can print the current database.%\index{Vernacular commands!Print Universes}% *) Print Universes. (** %\vspace{-.15in}% [[ Top.19 < Top.9 <= Top.8 Top.15 < Top.9 <= Top.8 <= Coq.Init.Datatypes.38 Top.14 < Top.9 <= Top.8 <= Coq.Init.Datatypes.37 Top.11 < Top.9 <= Top.8 ]] The command outputs many more constraints, but we have collected only those that mention [Top] variables. We see one constraint for each universe variable associated with a constructor argument from [exp]'s definition. Universe variable [Top.19] is the type argument to [Eq]. The constraint for [Top.19] effectively says that [Top.19] must be less than [Top.8], the universe of [exp]'s indices; an intermediate variable [Top.9] appears as an artifact of the way the constraint was generated. The next constraint, for [Top.15], is more complicated. This is the universe of the second argument to the [Pair] constructor. Not only must [Top.15] be less than [Top.8], but it also comes out that [Top.8] must be less than [Coq.Init.Datatypes.38]. What is this new universe variable? It is from the definition of the [prod] inductive family, to which types of the form [A * B] are desugared. *) (* begin hide *) (* begin thide *) Inductive prod := pair. Reset prod. (* end thide *) (* end hide *) (** %\vspace{-.3in}%[[ Print prod. ]] %\vspace{-.15in}%[[ Inductive prod (A : Type $ Coq.Init.Datatypes.37 ^ ) (B : Type $ Coq.Init.Datatypes.38 ^ ) : Type $ max(Coq.Init.Datatypes.37, Coq.Init.Datatypes.38) ^ := pair : A -> B -> A * B ]] We see that the constraint is enforcing that indices to [exp] must not live in a higher universe level than [B]-indices to [prod]. The next constraint above establishes a symmetric condition for [A]. Thus it is apparent that Coq maintains a tortuous set of universe variable inequalities behind the scenes. It may look like some functions are polymorphic in the universe levels of their arguments, but what is really happening is imperative updating of a system of constraints, such that all uses of a function are consistent with a global set of universe levels. When the constraint system may not be evolved soundly, we get a universe inconsistency error. %\medskip% The annotated definition of [prod] reveals something interesting. A type [prod A B] lives at a universe that is the maximum of the universes of [A] and [B]. From our earlier experiments, we might expect that [prod]'s universe would in fact need to be _one higher_ than the maximum. The critical difference is that, in the definition of [prod], [A] and [B] are defined as _parameters_; that is, they appear named to the left of the main colon, rather than appearing (possibly unnamed) to the right. Parameters are not as flexible as normal inductive type arguments. The range types of all of the constructors of a parameterized type must share the same parameters. Nonetheless, when it is possible to define a polymorphic type in this way, we gain the ability to use the new type family in more ways, without triggering universe inconsistencies. For instance, nested pairs of types are perfectly legal. *) Check (nat, (Type, Set)). (** %\vspace{-.15in}% [[ (nat, (Type $ Top.44 ^ , Set)) : Set * (Type $ Top.45 ^ * Type $ Top.46 ^ ) ]] The same cannot be done with a counterpart to [prod] that does not use parameters. *) Inductive prod' : Type -> Type -> Type := | pair' : forall A B : Type, A -> B -> prod' A B. (** %\vspace{-.15in}%[[ Check (pair' nat (pair' Type Set)). ]] << Error: Universe inconsistency (cannot enforce Top.51 < Top.51). >> The key benefit parameters bring us is the ability to avoid quantifying over types in the types of constructors. Such quantification induces less-than constraints, while parameters only introduce less-than-or-equal-to constraints. Coq includes one more (potentially confusing) feature related to parameters. While Gallina does not support real %\index{universe polymorphism}%universe polymorphism, there is a convenience facility that mimics universe polymorphism in some cases. We can illustrate what this means with a simple example. *) Inductive foo (A : Type) : Type := | Foo : A -> foo A. (* begin hide *) Unset Printing Universes. (* end hide *) Check foo nat. (** %\vspace{-.15in}% [[ foo nat : Set ]] *) Check foo Set. (** %\vspace{-.15in}% [[ foo Set : Type ]] *) Check foo True. (** %\vspace{-.15in}% [[ foo True : Prop ]] The basic pattern here is that Coq is willing to automatically build a "copied-and-pasted" version of an inductive definition, where some occurrences of [Type] have been replaced by [Set] or [Prop]. In each context, the type-checker tries to find the valid replacements that are lowest in the type hierarchy. Automatic cloning of definitions can be much more convenient than manual cloning. We have already taken advantage of the fact that we may re-use the same families of tuple and list types to form values in [Set] and [Type]. Imitation polymorphism can be confusing in some contexts. For instance, it is what is responsible for this weird behavior. *) Inductive bar : Type := Bar : bar. Check bar. (** %\vspace{-.15in}% [[ bar : Prop ]] The type that Coq comes up with may be used in strictly more contexts than the type one might have expected. *) (** ** Deciphering Baffling Messages About Inability to Unify *) (** One of the most confusing sorts of Coq error messages arises from an interplay between universes, syntax notations, and %\index{implicit arguments}%implicit arguments. Consider the following innocuous lemma, which is symmetry of equality for the special case of types. *) Theorem symmetry : forall A B : Type, A = B -> B = A. intros ? ? H; rewrite H; reflexivity. Qed. (** Let us attempt an admittedly silly proof of the following theorem. *) Theorem illustrative_but_silly_detour : unit = unit. (** %\vspace{-.25in}%[[ apply symmetry. ]] << Error: Impossible to unify "?35 = ?34" with "unit = unit". >> Coq tells us that we cannot, in fact, apply our lemma [symmetry] here, but the error message seems defective. In particular, one might think that [apply] should unify [?35] and [?34] with [unit] to ensure that the unification goes through. In fact, the issue is in a part of the unification problem that is _not_ shown to us in this error message! The following command is the secret to getting better error messages in such cases:%\index{Vernacular commands!Set Printing All}% *) Set Printing All. (** %\vspace{-.15in}%[[ apply symmetry. ]] << Error: Impossible to unify "@eq Type ?46 ?45" with "@eq Set unit unit". >> Now we can see the problem: it is the first, _implicit_ argument to the underlying equality function [eq] that disagrees across the two terms. The universe [Set] may be both an element and a subtype of [Type], but the two are not definitionally equal. *) Abort. (** A variety of changes to the theorem statement would lead to use of [Type] as the implicit argument of [eq]. Here is one such change. *) Theorem illustrative_but_silly_detour : (unit : Type) = unit. apply symmetry; reflexivity. Qed. (** There are many related issues that can come up with error messages, where one or both of notations and implicit arguments hide important details. The [Set Printing All] command turns off all such features and exposes underlying CIC terms. For completeness, we mention one other class of confusing error message about inability to unify two terms that look obviously unifiable. Each unification variable has a scope; a unification variable instantiation may not mention variables that were not already defined within that scope, at the point in proof search where the unification variable was introduced. Consider this illustrative example: *) Unset Printing All. Theorem ex_symmetry : (exists x, x = 0) -> (exists x, 0 = x). eexists. (** %\vspace{-.15in}%[[ H : exists x : nat, x = 0 ============================ 0 = ?98 ]] *) destruct H. (** %\vspace{-.15in}%[[ x : nat H : x = 0 ============================ 0 = ?99 ]] *) (** %\vspace{-.2in}%[[ symmetry; exact H. ]] << Error: In environment x : nat H : x = 0 The term "H" has type "x = 0" while it is expected to have type "?99 = 0". >> The problem here is that variable [x] was introduced by [destruct] _after_ we introduced [?99] with [eexists], so the instantiation of [?99] may not mention [x]. A simple reordering of the proof solves the problem. *) Restart. destruct 1 as [x]; apply ex_intro with x; symmetry; assumption. Qed. (** This restriction for unification variables may seem counterintuitive, but it follows from the fact that CIC contains no concept of unification variable. Rather, to construct the final proof term, at the point in a proof where the unification variable is introduced, we replace it with the instantiation we eventually find for it. It is simply syntactically illegal to refer there to variables that are not in scope. Without such a restriction, we could trivially "prove" such non-theorems as [exists n : nat, forall m : nat, n = m] by [econstructor; intro; reflexivity]. *) (** * The [Prop] Universe *) (** In Chapter 4, we saw parallel versions of useful datatypes for "programs" and "proofs." The convention was that programs live in [Set], and proofs live in [Prop]. We gave little explanation for why it is useful to maintain this distinction. There is certainly documentation value from separating programs from proofs; in practice, different concerns apply to building the two types of objects. It turns out, however, that these concerns motivate formal differences between the two universes in Coq. Recall the types [sig] and [ex], which are the program and proof versions of existential quantification. Their definitions differ only in one place, where [sig] uses [Type] and [ex] uses [Prop]. *) Print sig. (** %\vspace{-.15in}% [[ Inductive sig (A : Type) (P : A -> Prop) : Type := exist : forall x : A, P x -> sig P ]] *) Print ex. (** %\vspace{-.15in}% [[ Inductive ex (A : Type) (P : A -> Prop) : Prop := ex_intro : forall x : A, P x -> ex P ]] It is natural to want a function to extract the first components of data structures like these. Doing so is easy enough for [sig]. *) Definition projS A (P : A -> Prop) (x : sig P) : A := match x with | exist v _ => v end. (* begin hide *) (* begin thide *) Definition projE := O. (* end thide *) (* end hide *) (** We run into trouble with a version that has been changed to work with [ex]. [[ Definition projE A (P : A -> Prop) (x : ex P) : A := match x with | ex_intro v _ => v end. ]] << Error: Incorrect elimination of "x" in the inductive type "ex": the return type has sort "Type" while it should be "Prop". Elimination of an inductive object of sort Prop is not allowed on a predicate in sort Type because proofs can be eliminated only to build proofs. >> In formal Coq parlance, %\index{elimination}%"elimination" means "pattern-matching." The typing rules of Gallina forbid us from pattern-matching on a discriminee whose type belongs to [Prop], whenever the result type of the [match] has a type besides [Prop]. This is a sort of "information flow" policy, where the type system ensures that the details of proofs can never have any effect on parts of a development that are not also marked as proofs. This restriction matches informal practice. We think of programs and proofs as clearly separated, and, outside of constructive logic, the idea of computing with proofs is ill-formed. The distinction also has practical importance in Coq, where it affects the behavior of extraction. Recall that %\index{program extraction}%extraction is Coq's facility for translating Coq developments into programs in general-purpose programming languages like OCaml. Extraction _erases_ proofs and leaves programs intact. A simple example with [sig] and [ex] demonstrates the distinction. *) Definition sym_sig (x : sig (fun n => n = 0)) : sig (fun n => 0 = n) := match x with | exist n pf => exist _ n (sym_eq pf) end. Extraction sym_sig. (** << (** val sym_sig : nat -> nat **) let sym_sig x = x >> Since extraction erases proofs, the second components of [sig] values are elided, making [sig] a simple identity type family. The [sym_sig] operation is thus an identity function. *) Definition sym_ex (x : ex (fun n => n = 0)) : ex (fun n => 0 = n) := match x with | ex_intro n pf => ex_intro _ n (sym_eq pf) end. Extraction sym_ex. (** << (** val sym_ex : __ **) let sym_ex = __ >> In this example, the [ex] type itself is in [Prop], so whole [ex] packages are erased. Coq extracts every proposition as the (Coq-specific) type <<__>>, whose single constructor is <<__>>. Not only are proofs replaced by [__], but proof arguments to functions are also removed completely, as we see here. Extraction is very helpful as an optimization over programs that contain proofs. In languages like Haskell, advanced features make it possible to program with proofs, as a way of convincing the type checker to accept particular definitions. Unfortunately, when proofs are encoded as values in GADTs%~\cite{GADT}%, these proofs exist at runtime and consume resources. In contrast, with Coq, as long as all proofs are kept within [Prop], extraction is guaranteed to erase them. Many fans of the %\index{Curry-Howard correspondence}%Curry-Howard correspondence support the idea of _extracting programs from proofs_. In reality, few users of Coq and related tools do any such thing. Instead, extraction is better thought of as an optimization that reduces the runtime costs of expressive typing. %\medskip% We have seen two of the differences between proofs and programs: proofs are subject to an elimination restriction and are elided by extraction. The remaining difference is that [Prop] is%\index{impredicativity}% _impredicative_, as this example shows. *) Check forall P Q : Prop, P \/ Q -> Q \/ P. (** %\vspace{-.15in}% [[ forall P Q : Prop, P \/ Q -> Q \/ P : Prop ]] We see that it is possible to define a [Prop] that quantifies over other [Prop]s. This is fortunate, as we start wanting that ability even for such basic purposes as stating propositional tautologies. In the next section of this chapter, we will see some reasons why unrestricted impredicativity is undesirable. The impredicativity of [Prop] interacts crucially with the elimination restriction to avoid those pitfalls. Impredicativity also allows us to implement a version of our earlier [exp] type that does not suffer from the weakness that we found. *) Inductive expP : Type -> Prop := | ConstP : forall T, T -> expP T | PairP : forall T1 T2, expP T1 -> expP T2 -> expP (T1 * T2) | EqP : forall T, expP T -> expP T -> expP bool. Check ConstP 0. (** %\vspace{-.15in}% [[ ConstP 0 : expP nat ]] *) Check PairP (ConstP 0) (ConstP tt). (** %\vspace{-.15in}% [[ PairP (ConstP 0) (ConstP tt) : expP (nat * unit) ]] *) Check EqP (ConstP Set) (ConstP Type). (** %\vspace{-.15in}% [[ EqP (ConstP Set) (ConstP Type) : expP bool ]] *) Check ConstP (ConstP O). (** %\vspace{-.15in}% [[ ConstP (ConstP 0) : expP (expP nat) ]] In this case, our victory is really a shallow one. As we have marked [expP] as a family of proofs, we cannot deconstruct our expressions in the usual programmatic ways, which makes them almost useless for the usual purposes. Impredicative quantification is much more useful in defining inductive families that we really think of as judgments. For instance, this code defines a notion of equality that is strictly more permissive than the base equality [=]. *) Inductive eqPlus : forall T, T -> T -> Prop := | Base : forall T (x : T), eqPlus x x | Func : forall dom ran (f1 f2 : dom -> ran), (forall x : dom, eqPlus (f1 x) (f2 x)) -> eqPlus f1 f2. Check (Base 0). (** %\vspace{-.15in}% [[ Base 0 : eqPlus 0 0 ]] *) Check (Func (fun n => n) (fun n => 0 + n) (fun n => Base n)). (** %\vspace{-.15in}% [[ Func (fun n : nat => n) (fun n : nat => 0 + n) (fun n : nat => Base n) : eqPlus (fun n : nat => n) (fun n : nat => 0 + n) ]] *) Check (Base (Base 1)). (** %\vspace{-.15in}% [[ Base (Base 1) : eqPlus (Base 1) (Base 1) ]] *) (** Stating equality facts about proofs may seem baroque, but we have already seen its utility in the chapter on reasoning about equality proofs. *) (** * Axioms *) (** While the specific logic Gallina is hardcoded into Coq's implementation, it is possible to add certain logical rules in a controlled way. In other words, Coq may be used to reason about many different refinements of Gallina where strictly more theorems are provable. We achieve this by asserting%\index{axioms}% _axioms_ without proof. We will motivate the idea by touring through some standard axioms, as enumerated in Coq's online FAQ. I will add additional commentary as appropriate. *) (** ** The Basics *) (** One simple example of a useful axiom is the %\index{law of the excluded middle}%law of the excluded middle. *) Require Import Classical_Prop. Print classic. (** %\vspace{-.15in}% [[ *** [ classic : forall P : Prop, P \/ ~ P ] ]] In the implementation of module [Classical_Prop], this axiom was defined with the command%\index{Vernacular commands!Axiom}% *) Axiom classic : forall P : Prop, P \/ ~ P. (** An [Axiom] may be declared with any type, in any of the universes. There is a synonym %\index{Vernacular commands!Parameter}%[Parameter] for [Axiom], and that synonym is often clearer for assertions not of type [Prop]. For instance, we can assert the existence of objects with certain properties. *) Parameter num : nat. Axiom positive : num > 0. Reset num. (** This kind of "axiomatic presentation" of a theory is very common outside of higher-order logic. However, in Coq, it is almost always preferable to stick to defining your objects, functions, and predicates via inductive definitions and functional programming. In general, there is a significant burden associated with any use of axioms. It is easy to assert a set of axioms that together is%\index{inconsistent axioms}% _inconsistent_. That is, a set of axioms may imply [False], which allows any theorem to be proved, which defeats the purpose of a proof assistant. For example, we could assert the following axiom, which is consistent by itself but inconsistent when combined with [classic]. *) Axiom not_classic : ~ forall P : Prop, P \/ ~ P. Theorem uhoh : False. generalize classic not_classic; tauto. Qed. Theorem uhoh_again : 1 + 1 = 3. destruct uhoh. Qed. Reset not_classic. (** On the subject of the law of the excluded middle itself, this axiom is usually quite harmless, and many practical Coq developments assume it. It has been proved metatheoretically to be consistent with CIC. Here, "proved metatheoretically" means that someone proved on paper that excluded middle holds in a _model_ of CIC in set theory%~\cite{SetsInTypes}%. All of the other axioms that we will survey in this section hold in the same model, so they are all consistent together. Recall that Coq implements%\index{constructive logic}% _constructive_ logic by default, where the law of the excluded middle is not provable. Proofs in constructive logic can be thought of as programs. A [forall] quantifier denotes a dependent function type, and a disjunction denotes a variant type. In such a setting, excluded middle could be interpreted as a decision procedure for arbitrary propositions, which computability theory tells us cannot exist. Thus, constructive logic with excluded middle can no longer be associated with our usual notion of programming. Given all this, why is it all right to assert excluded middle as an axiom? The intuitive justification is that the elimination restriction for [Prop] prevents us from treating proofs as programs. An excluded middle axiom that quantified over [Set] instead of [Prop] _would_ be problematic. If a development used that axiom, we would not be able to extract the code to OCaml (soundly) without implementing a genuine universal decision procedure. In contrast, values whose types belong to [Prop] are always erased by extraction, so we sidestep the axiom's algorithmic consequences. Because the proper use of axioms is so precarious, there are helpful commands for determining which axioms a theorem relies on.%\index{Vernacular commands!Print Assumptions}% *) Theorem t1 : forall P : Prop, P -> ~ ~ P. tauto. Qed. Print Assumptions t1. (** << Closed under the global context >> *) Theorem t2 : forall P : Prop, ~ ~ P -> P. (** %\vspace{-.25in}%[[ tauto. ]] << Error: tauto failed. >> *) intro P; destruct (classic P); tauto. Qed. Print Assumptions t2. (** %\vspace{-.15in}% [[ Axioms: classic : forall P : Prop, P \/ ~ P ]] It is possible to avoid this dependence in some specific cases, where excluded middle _is_ provable, for decidable families of propositions. *) Theorem nat_eq_dec : forall n m : nat, n = m \/ n <> m. induction n; destruct m; intuition; generalize (IHn m); intuition. Qed. Theorem t2' : forall n m : nat, ~ ~ (n = m) -> n = m. intros n m; destruct (nat_eq_dec n m); tauto. Qed. Print Assumptions t2'. (** << Closed under the global context >> %\bigskip% Mainstream mathematical practice assumes excluded middle, so it can be useful to have it available in Coq developments, though it is also nice to know that a theorem is proved in a simpler formal system than classical logic. There is a similar story for%\index{proof irrelevance}% _proof irrelevance_, which simplifies proof issues that would not even arise in mainstream math. *) Require Import ProofIrrelevance. Print proof_irrelevance. (** %\vspace{-.15in}% [[ *** [ proof_irrelevance : forall (P : Prop) (p1 p2 : P), p1 = p2 ] ]] This axiom asserts that any two proofs of the same proposition are equal. Recall this example function from Chapter 6. *) (* begin hide *) Lemma zgtz : 0 > 0 -> False. crush. Qed. (* end hide *) Definition pred_strong1 (n : nat) : n > 0 -> nat := match n with | O => fun pf : 0 > 0 => match zgtz pf with end | S n' => fun _ => n' end. (** We might want to prove that different proofs of [n > 0] do not lead to different results from our richly typed predecessor function. *) Theorem pred_strong1_irrel : forall n (pf1 pf2 : n > 0), pred_strong1 pf1 = pred_strong1 pf2. destruct n; crush. Qed. (** The proof script is simple, but it involved peeking into the definition of [pred_strong1]. For more complicated function definitions, it can be considerably more work to prove that they do not discriminate on details of proof arguments. This can seem like a shame, since the [Prop] elimination restriction makes it impossible to write any function that does otherwise. Unfortunately, this fact is only true metatheoretically, unless we assert an axiom like [proof_irrelevance]. With that axiom, we can prove our theorem without consulting the definition of [pred_strong1]. *) Theorem pred_strong1_irrel' : forall n (pf1 pf2 : n > 0), pred_strong1 pf1 = pred_strong1 pf2. intros; f_equal; apply proof_irrelevance. Qed. (** %\bigskip% In the chapter on equality, we already discussed some axioms that are related to proof irrelevance. In particular, Coq's standard library includes this axiom: *) Require Import Eqdep. Import Eq_rect_eq. Print eq_rect_eq. (** %\vspace{-.15in}% [[ *** [ eq_rect_eq : forall (U : Type) (p : U) (Q : U -> Type) (x : Q p) (h : p = p), x = eq_rect p Q x p h ] ]] This axiom says that it is permissible to simplify pattern matches over proofs of equalities like [e = e]. The axiom is logically equivalent to some simpler corollaries. In the theorem names, "UIP" stands for %\index{unicity of identity proofs}%"unicity of identity proofs", where "identity" is a synonym for "equality." *) Corollary UIP_refl : forall A (x : A) (pf : x = x), pf = eq_refl x. intros; replace pf with (eq_rect x (eq x) (eq_refl x) x pf); [ symmetry; apply eq_rect_eq | exact (match pf as pf' return match pf' in _ = y return x = y with | eq_refl => eq_refl x end = pf' with | eq_refl => eq_refl _ end) ]. Qed. Corollary UIP : forall A (x y : A) (pf1 pf2 : x = y), pf1 = pf2. intros; generalize pf1 pf2; subst; intros; match goal with | [ |- ?pf1 = ?pf2 ] => rewrite (UIP_refl pf1); rewrite (UIP_refl pf2); reflexivity end. Qed. (* begin hide *) (* begin thide *) Require Eqdep_dec. (* end thide *) (* end hide *) (** These corollaries are special cases of proof irrelevance. In developments that only need proof irrelevance for equality, there is no need to assert full irrelevance. Another facet of proof irrelevance is that, like excluded middle, it is often provable for specific propositions. For instance, [UIP] is provable whenever the type [A] has a decidable equality operation. The module [Eqdep_dec] of the standard library contains a proof. A similar phenomenon applies to other notable cases, including less-than proofs. Thus, it is often possible to use proof irrelevance without asserting axioms. %\bigskip% There are two more basic axioms that are often assumed, to avoid complications that do not arise in set theory. *) Require Import FunctionalExtensionality. Print functional_extensionality_dep. (** %\vspace{-.15in}% [[ *** [ functional_extensionality_dep : forall (A : Type) (B : A -> Type) (f g : forall x : A, B x), (forall x : A, f x = g x) -> f = g ] ]] This axiom says that two functions are equal if they map equal inputs to equal outputs. Such facts are not provable in general in CIC, but it is consistent to assume that they are. A simple corollary shows that the same property applies to predicates. *) Corollary predicate_extensionality : forall (A : Type) (B : A -> Prop) (f g : forall x : A, B x), (forall x : A, f x = g x) -> f = g. intros; apply functional_extensionality_dep; assumption. Qed. (** In some cases, one might prefer to assert this corollary as the axiom, to restrict the consequences to proofs and not programs. *) (** ** Axioms of Choice *) (** Some Coq axioms are also points of contention in mainstream math. The most prominent example is the %\index{axiom of choice}%axiom of choice. In fact, there are multiple versions that we might consider, and, considered in isolation, none of these versions means quite what it means in classical set theory. First, it is possible to implement a choice operator _without_ axioms in some potentially surprising cases. *) Require Import ConstructiveEpsilon. Check constructive_definite_description. (** %\vspace{-.15in}% [[ constructive_definite_description : forall (A : Set) (f : A -> nat) (g : nat -> A), (forall x : A, g (f x) = x) -> forall P : A -> Prop, (forall x : A, {P x} + { ~ P x}) -> (exists! x : A, P x) -> {x : A | P x} ]] *) Print Assumptions constructive_definite_description. (** << Closed under the global context >> This function transforms a decidable predicate [P] into a function that produces an element satisfying [P] from a proof that such an element exists. The functions [f] and [g], in conjunction with an associated injectivity property, are used to express the idea that the set [A] is countable. Under these conditions, a simple brute force algorithm gets the job done: we just enumerate all elements of [A], stopping when we find one satisfying [P]. The existence proof, specified in terms of _unique_ existence [exists!], guarantees termination. The definition of this operator in Coq uses some interesting techniques, as seen in the implementation of the [ConstructiveEpsilon] module. Countable choice is provable in set theory without appealing to the general axiom of choice. To support the more general principle in Coq, we must also add an axiom. Here is a functional version of the axiom of unique choice. *) Require Import ClassicalUniqueChoice. Check dependent_unique_choice. (** %\vspace{-.15in}% [[ dependent_unique_choice : forall (A : Type) (B : A -> Type) (R : forall x : A, B x -> Prop), (forall x : A, exists! y : B x, R x y) -> exists f : forall x : A, B x, forall x : A, R x (f x) ]] This axiom lets us convert a relational specification [R] into a function implementing that specification. We need only prove that [R] is truly a function. An alternate, stronger formulation applies to cases where [R] maps each input to one or more outputs. We also simplify the statement of the theorem by considering only non-dependent function types. *) (* begin hide *) (* begin thide *) Require RelationalChoice. (* end thide *) (* end hide *) Require Import ClassicalChoice. Check choice. (** %\vspace{-.15in}% [[ choice : forall (A B : Type) (R : A -> B -> Prop), (forall x : A, exists y : B, R x y) -> exists f : A -> B, forall x : A, R x (f x) ]] This principle is proved as a theorem, based on the unique choice axiom and an additional axiom of relational choice from the [RelationalChoice] module. In set theory, the axiom of choice is a fundamental philosophical commitment one makes about the universe of sets. In Coq, the choice axioms say something weaker. For instance, consider the simple restatement of the [choice] axiom where we replace existential quantification by its Curry-Howard analogue, subset types. *) Definition choice_Set (A B : Type) (R : A -> B -> Prop) (H : forall x : A, {y : B | R x y}) : {f : A -> B | forall x : A, R x (f x)} := exist (fun f => forall x : A, R x (f x)) (fun x => proj1_sig (H x)) (fun x => proj2_sig (H x)). (** %\smallskip{}%Via the Curry-Howard correspondence, this "axiom" can be taken to have the same meaning as the original. It is implemented trivially as a transformation not much deeper than uncurrying. Thus, we see that the utility of the axioms that we mentioned earlier comes in their usage to build programs from proofs. Normal set theory has no explicit proofs, so the meaning of the usual axiom of choice is subtly different. In Gallina, the axioms implement a controlled relaxation of the restrictions on information flow from proofs to programs. However, when we combine an axiom of choice with the law of the excluded middle, the idea of "choice" becomes more interesting. Excluded middle gives us a highly non-computational way of constructing proofs, but it does not change the computational nature of programs. Thus, the axiom of choice is still giving us a way of translating between two different sorts of "programs," but the input programs (which are proofs) may be written in a rich language that goes beyond normal computability. This combination truly is more than repackaging a function with a different type. %\bigskip% The Coq tools support a command-line flag %\index{impredicative Set}%<<-impredicative-set>>, which modifies Gallina in a more fundamental way by making [Set] impredicative. A term like [forall T : Set, T] has type [Set], and inductive definitions in [Set] may have constructors that quantify over arguments of any types. To maintain consistency, an elimination restriction must be imposed, similarly to the restriction for [Prop]. The restriction only applies to large inductive types, where some constructor quantifies over a type of type [Type]. In such cases, a value in this inductive type may only be pattern-matched over to yield a result type whose type is [Set] or [Prop]. This rule contrasts with the rule for [Prop], where the restriction applies even to non-large inductive types, and where the result type may only have type [Prop]. In old versions of Coq, [Set] was impredicative by default. Later versions make [Set] predicative to avoid inconsistency with some classical axioms. In particular, one should watch out when using impredicative [Set] with axioms of choice. In combination with excluded middle or predicate extensionality, inconsistency can result. Impredicative [Set] can be useful for modeling inherently impredicative mathematical concepts, but almost all Coq developments get by fine without it. *) (** ** Axioms and Computation *) (** One additional axiom-related wrinkle arises from an aspect of Gallina that is very different from set theory: a notion of _computational equivalence_ is central to the definition of the formal system. Axioms tend not to play well with computation. Consider this example. We start by implementing a function that uses a type equality proof to perform a safe type-cast. *) Definition cast (x y : Set) (pf : x = y) (v : x) : y := match pf with | eq_refl => v end. (** Computation over programs that use [cast] can proceed smoothly. *) Eval compute in (cast (eq_refl (nat -> nat)) (fun n => S n)) 12. (** %\vspace{-.15in}%[[ = 13 : nat ]] *) (** Things do not go as smoothly when we use [cast] with proofs that rely on axioms. *) Theorem t3 : (forall n : nat, fin (S n)) = (forall n : nat, fin (n + 1)). change ((forall n : nat, (fun n => fin (S n)) n) = (forall n : nat, (fun n => fin (n + 1)) n)); rewrite (functional_extensionality (fun n => fin (n + 1)) (fun n => fin (S n))); crush. Qed. Eval compute in (cast t3 (fun _ => First)) 12. (** %\vspace{-.15in}%[[ = match t3 in (_ = P) return P with | eq_refl => fun n : nat => First end 12 : fin (12 + 1) ]] Computation gets stuck in a pattern-match on the proof [t3]. The structure of [t3] is not known, so the match cannot proceed. It turns out a more basic problem leads to this particular situation. We ended the proof of [t3] with [Qed], so the definition of [t3] is not available to computation. That mistake is easily fixed. *) Reset t3. Theorem t3 : (forall n : nat, fin (S n)) = (forall n : nat, fin (n + 1)). change ((forall n : nat, (fun n => fin (S n)) n) = (forall n : nat, (fun n => fin (n + 1)) n)); rewrite (functional_extensionality (fun n => fin (n + 1)) (fun n => fin (S n))); crush. Defined. Eval compute in (cast t3 (fun _ => First)) 12. (** %\vspace{-.15in}%[[ = match match match functional_extensionality .... ]] We elide most of the details. A very unwieldy tree of nested matches on equality proofs appears. This time evaluation really _is_ stuck on a use of an axiom. If we are careful in using tactics to prove an equality, we can still compute with casts over the proof. *) Lemma plus1 : forall n, S n = n + 1. induction n; simpl; intuition. Defined. Theorem t4 : forall n, fin (S n) = fin (n + 1). intro; f_equal; apply plus1. Defined. Eval compute in cast (t4 13) First. (** %\vspace{-.15in}% [[ = First : fin (13 + 1) ]] This simple computational reduction hides the use of a recursive function to produce a suitable [eq_refl] proof term. The recursion originates in our use of [induction] in [t4]'s proof. *) (** ** Methods for Avoiding Axioms *) (** The last section demonstrated one reason to avoid axioms: they interfere with computational behavior of terms. A further reason is to reduce the philosophical commitment of a theorem. The more axioms one assumes, the harder it becomes to convince oneself that the formal system corresponds appropriately to one's intuitions. A refinement of this last point, in applications like %\index{proof-carrying code}%proof-carrying code%~\cite{PCC}% in computer security, has to do with minimizing the size of a%\index{trusted code base}% _trusted code base_. To convince ourselves that a theorem is true, we must convince ourselves of the correctness of the program that checks the theorem. Axioms effectively become new source code for the checking program, increasing the effort required to perform a correctness audit. An earlier section gave one example of avoiding an axiom. We proved that [pred_strong1] is agnostic to details of the proofs passed to it as arguments, by unfolding the definition of the function. A "simpler" proof keeps the function definition opaque and instead applies a proof irrelevance axiom. By accepting a more complex proof, we reduce our philosophical commitment and trusted base. (By the way, the less-than relation that the proofs in question here prove turns out to admit proof irrelevance as a theorem provable within normal Gallina!) One dark secret of the [dep_destruct] tactic that we have used several times is reliance on an axiom. Consider this simple case analysis principle for [fin] values: *) Theorem fin_cases : forall n (f : fin (S n)), f = First \/ exists f', f = Next f'. intros; dep_destruct f; eauto. Qed. (* begin hide *) Require Import JMeq. (* begin thide *) Definition jme := (JMeq, JMeq_eq). (* end thide *) (* end hide *) Print Assumptions fin_cases. (** %\vspace{-.15in}%[[ Axioms: JMeq_eq : forall (A : Type) (x y : A), JMeq x y -> x = y ]] The proof depends on the [JMeq_eq] axiom that we met in the chapter on equality proofs. However, a smarter tactic could have avoided an axiom dependence. Here is an alternate proof via a slightly strange looking lemma. *) (* begin thide *) Lemma fin_cases_again' : forall n (f : fin n), match n return fin n -> Prop with | O => fun _ => False | S n' => fun f => f = First \/ exists f', f = Next f' end f. destruct f; eauto. Qed. (** We apply a variant of the %\index{convoy pattern}%convoy pattern, which we are used to seeing in function implementations. Here, the pattern helps us state a lemma in a form where the argument to [fin] is a variable. Recall that, thanks to basic typing rules for pattern-matching, [destruct] will only work effectively on types whose non-parameter arguments are variables. The %\index{tactics!exact}%[exact] tactic, which takes as argument a literal proof term, now gives us an easy way of proving the original theorem. *) Theorem fin_cases_again : forall n (f : fin (S n)), f = First \/ exists f', f = Next f'. intros; exact (fin_cases_again' f). Qed. (* end thide *) Print Assumptions fin_cases_again. (** %\vspace{-.15in}% << Closed under the global context >> *) (* begin thide *) (** As the Curry-Howard correspondence might lead us to expect, the same pattern may be applied in programming as in proving. Axioms are relevant in programming, too, because, while Coq includes useful extensions like [Program] that make dependently typed programming more straightforward, in general these extensions generate code that relies on axioms about equality. We can use clever pattern matching to write our code axiom-free. As an example, consider a [Set] version of [fin_cases]. We use [Set] types instead of [Prop] types, so that return values have computational content and may be used to guide the behavior of algorithms. Beside that, we are essentially writing the same "proof" in a more explicit way. *) Definition finOut n (f : fin n) : match n return fin n -> Type with | O => fun _ => Empty_set | _ => fun f => {f' : _ | f = Next f'} + {f = First} end f := match f with | First _ => inright _ (eq_refl _) | Next _ f' => inleft _ (exist _ f' (eq_refl _)) end. (* end thide *) (** As another example, consider the following type of formulas in first-order logic. The intent of the type definition will not be important in what follows, but we give a quick intuition for the curious reader. Our formulas may include [forall] quantification over arbitrary [Type]s, and we index formulas by environments telling which variables are in scope and what their types are; such an environment is a [list Type]. A constructor [Inject] lets us include any Coq [Prop] as a formula, and [VarEq] and [Lift] can be used for variable references, in what is essentially the de Bruijn index convention. (Again, the detail in this paragraph is not important to understand the discussion that follows!) *) Inductive formula : list Type -> Type := | Inject : forall Ts, Prop -> formula Ts | VarEq : forall T Ts, T -> formula (T :: Ts) | Lift : forall T Ts, formula Ts -> formula (T :: Ts) | Forall : forall T Ts, formula (T :: Ts) -> formula Ts | And : forall Ts, formula Ts -> formula Ts -> formula Ts. (** This example is based on my own experiences implementing variants of a program logic called XCAP%~\cite{XCAP}%, which also includes an inductive predicate for characterizing which formulas are provable. Here I include a pared-down version of such a predicate, with only two constructors, which is sufficient to illustrate certain tricky issues. *) Inductive proof : formula nil -> Prop := | PInject : forall (P : Prop), P -> proof (Inject nil P) | PAnd : forall p q, proof p -> proof q -> proof (And p q). (** Let us prove a lemma showing that a "[P /\ Q -> P]" rule is derivable within the rules of [proof]. *) Theorem proj1 : forall p q, proof (And p q) -> proof p. destruct 1. (** %\vspace{-.15in}%[[ p : formula nil q : formula nil P : Prop H : P ============================ proof p ]] *) (** We are reminded that [induction] and [destruct] do not work effectively on types with non-variable arguments. The first subgoal, shown above, is clearly unprovable. (Consider the case where [p = Inject nil False].) An application of the %\index{tactics!dependent destruction}%[dependent destruction] tactic (the basis for [dep_destruct]) solves the problem handily. We use a shorthand with the %\index{tactics!intros}%[intros] tactic that lets us use question marks for variable names that do not matter. *) Restart. Require Import Program. intros ? ? H; dependent destruction H; auto. Qed. Print Assumptions proj1. (** %\vspace{-.15in}%[[ Axioms: eq_rect_eq : forall (U : Type) (p : U) (Q : U -> Type) (x : Q p) (h : p = p), x = eq_rect p Q x p h ]] Unfortunately, that built-in tactic appeals to an axiom. It is still possible to avoid axioms by giving the proof via another odd-looking lemma. Here is a first attempt that fails at remaining axiom-free, using a common equality-based trick for supporting induction on non-variable arguments to type families. The trick works fine without axioms for datatypes more traditional than [formula], but we run into trouble with our current type. *) Lemma proj1_again' : forall r, proof r -> forall p q, r = And p q -> proof p. destruct 1; crush. (** %\vspace{-.15in}%[[ H0 : Inject [] P = And p q ============================ proof p ]] The first goal looks reasonable. Hypothesis [H0] is clearly contradictory, as [discriminate] can show. *) try discriminate. (* Note: Coq 8.6 is now solving this subgoal automatically! * This line left here to keep everything working in * 8.4 and 8.5. *) (** %\vspace{-.15in}%[[ H : proof p H1 : And p q = And p0 q0 ============================ proof p0 ]] It looks like we are almost done. Hypothesis [H1] gives [p = p0] by injectivity of constructors, and then [H] finishes the case. *) injection H1; intros. (* begin hide *) (* begin thide *) Definition existT' := existT. (* end thide *) (* end hide *) (** Unfortunately, the "equality" that we expected between [p] and [p0] comes in a strange form: [[ H3 : existT (fun Ts : list Type => formula Ts) []%list p = existT (fun Ts : list Type => formula Ts) []%list p0 ============================ proof p0 ]] It may take a bit of tinkering, but, reviewing Chapter 3's discussion of writing injection principles manually, it makes sense that an [existT] type is the most direct way to express the output of [injection] on a dependently typed constructor. The constructor [And] is dependently typed, since it takes a parameter [Ts] upon which the types of [p] and [q] depend. Let us not dwell further here on why this goal appears; the reader may like to attempt the (impossible) exercise of building a better injection lemma for [And], without using axioms. How exactly does an axiom come into the picture here? Let us ask [crush] to finish the proof. *) crush. Qed. Print Assumptions proj1_again'. (** %\vspace{-.15in}%[[ Axioms: eq_rect_eq : forall (U : Type) (p : U) (Q : U -> Type) (x : Q p) (h : p = p), x = eq_rect p Q x p h ]] It turns out that this familiar axiom about equality (or some other axiom) is required to deduce [p = p0] from the hypothesis [H3] above. The soundness of that proof step is neither provable nor disprovable in Gallina. Hope is not lost, however. We can produce an even stranger looking lemma, which gives us the theorem without axioms. As always when we want to do case analysis on a term with a tricky dependent type, the key is to refactor the theorem statement so that every term we [match] on has _variables_ as its type indices; so instead of talking about proofs of [And p q], we talk about proofs of an arbitrary [r], but we only conclude anything interesting when [r] is an [And]. *) Lemma proj1_again'' : forall r, proof r -> match r with | And Ps p _ => match Ps return formula Ps -> Prop with | nil => fun p => proof p | _ => fun _ => True end p | _ => True end. destruct 1; auto. Qed. Theorem proj1_again : forall p q, proof (And p q) -> proof p. intros ? ? H; exact (proj1_again'' H). Qed. Print Assumptions proj1_again. (** << Closed under the global context >> This example illustrates again how some of the same design patterns we learned for dependently typed programming can be used fruitfully in theorem statements. %\medskip% To close the chapter, we consider one final way to avoid dependence on axioms. Often this task is equivalent to writing definitions such that they _compute_. That is, we want Coq's normal reduction to be able to run certain programs to completion. Here is a simple example where such computation can get stuck. In proving properties of such functions, we would need to apply axioms like %\index{axiom K}%K manually to make progress. Imagine we are working with %\index{deep embedding}%deeply embedded syntax of some programming language, where each term is considered to be in the scope of a number of free variables that hold normal Coq values. To enforce proper typing, we will need to model a Coq typing environment somehow. One natural choice is as a list of types, where variable number [i] will be treated as a reference to the [i]th element of the list. *) Section withTypes. Variable types : list Set. (** To give the semantics of terms, we will need to represent value environments, which assign each variable a term of the proper type. *) Variable values : hlist (fun x : Set => x) types. (** Now imagine that we are writing some procedure that operates on a distinguished variable of type [nat]. A hypothesis formalizes this assumption, using the standard library function [nth_error] for looking up list elements by position. *) Variable natIndex : nat. Variable natIndex_ok : nth_error types natIndex = Some nat. (** It is not hard to use this hypothesis to write a function for extracting the [nat] value in position [natIndex] of [values], starting with two helpful lemmas, each of which we finish with [Defined] to mark the lemma as transparent, so that its definition may be expanded during evaluation. *) Lemma nth_error_nil : forall A n x, nth_error (@nil A) n = Some x -> False. destruct n; simpl; unfold error; congruence. Defined. Implicit Arguments nth_error_nil [A n x]. Lemma Some_inj : forall A (x y : A), Some x = Some y -> x = y. congruence. Defined. Fixpoint getNat (types' : list Set) (values' : hlist (fun x : Set => x) types') (natIndex : nat) : (nth_error types' natIndex = Some nat) -> nat := match values' with | HNil => fun pf => match nth_error_nil pf with end | HCons t ts x values'' => match natIndex return nth_error (t :: ts) natIndex = Some nat -> nat with | O => fun pf => match Some_inj pf in _ = T return T with | eq_refl => x end | S natIndex' => getNat values'' natIndex' end end. End withTypes. (** The problem becomes apparent when we experiment with running [getNat] on a concrete [types] list. *) Definition myTypes := unit :: nat :: bool :: nil. Definition myValues : hlist (fun x : Set => x) myTypes := tt ::: 3 ::: false ::: HNil. Definition myNatIndex := 1. Theorem myNatIndex_ok : nth_error myTypes myNatIndex = Some nat. reflexivity. Defined. Eval compute in getNat myValues myNatIndex myNatIndex_ok. (** %\vspace{-.15in}%[[ = 3 ]] We have not hit the problem yet, since we proceeded with a concrete equality proof for [myNatIndex_ok]. However, consider a case where we want to reason about the behavior of [getNat] _independently_ of a specific proof. *) Theorem getNat_is_reasonable : forall pf, getNat myValues myNatIndex pf = 3. intro; compute. (** << 1 subgoal >> %\vspace{-.3in}%[[ pf : nth_error myTypes myNatIndex = Some nat ============================ match match pf in (_ = y) return (nat = match y with | Some H => H | None => nat end) with | eq_refl => eq_refl end in (_ = T) return T with | eq_refl => 3 end = 3 ]] Since the details of the equality proof [pf] are not known, computation can proceed no further. A rewrite with axiom K would allow us to make progress, but we can rethink the definitions a bit to avoid depending on axioms. *) Abort. (** Here is a definition of a function that turns out to be useful, though no doubt its purpose will be mysterious for now. A call [update ls n x] overwrites the [n]th position of the list [ls] with the value [x], padding the end of the list with extra [x] values as needed to ensure sufficient length. *) Fixpoint copies A (x : A) (n : nat) : list A := match n with | O => nil | S n' => x :: copies x n' end. Fixpoint update A (ls : list A) (n : nat) (x : A) : list A := match ls with | nil => copies x n ++ x :: nil | y :: ls' => match n with | O => x :: ls' | S n' => y :: update ls' n' x end end. (** Now let us revisit the definition of [getNat]. *) Section withTypes'. Variable types : list Set. Variable natIndex : nat. (** Here is the trick: instead of asserting properties about the list [types], we build a "new" list that is _guaranteed by construction_ to have those properties. *) Definition types' := update types natIndex nat. Variable values : hlist (fun x : Set => x) types'. (** Now a bit of dependent pattern matching helps us rewrite [getNat] in a way that avoids any use of equality proofs. *) Fixpoint skipCopies (n : nat) : hlist (fun x : Set => x) (copies nat n ++ nat :: nil) -> nat := match n with | O => fun vs => hhd vs | S n' => fun vs => skipCopies n' (htl vs) end. Fixpoint getNat' (types'' : list Set) (natIndex : nat) : hlist (fun x : Set => x) (update types'' natIndex nat) -> nat := match types'' with | nil => skipCopies natIndex | t :: types0 => match natIndex return hlist (fun x : Set => x) (update (t :: types0) natIndex nat) -> nat with | O => fun vs => hhd vs | S natIndex' => fun vs => getNat' types0 natIndex' (htl vs) end end. End withTypes'. (** Now the surprise comes in how easy it is to _use_ [getNat']. While typing works by modification of a types list, we can choose parameters so that the modification has no effect. *) Theorem getNat_is_reasonable : getNat' myTypes myNatIndex myValues = 3. reflexivity. Qed. (** The same parameters as before work without alteration, and we avoid use of axioms. *)
################################################################################ """ mindGraphics(modelHMM::Dict{S, Tuple{Array{T, 1}, Array{Array{U, 1}, 1}}}, shArgs::Dict; labels = nothing) where S <: String where T <: Int64 where U <: Float64 # Description Control graphic module of *MindReader*. Verifies arguments, builds heatmap, write to file and renders image. # Arguments `modelHMM` model to render by graphics module. `shArgs` shell arguments. if available `labels` are available, concatenate to rendering. """ function mindGraphics(modelHMM::Dict{S, Tuple{Array{T, 1}, Array{Array{U, 1}, 1}}}, shArgs::Dict; labels = nothing) where S <: String where T <: Int64 where U <: Float64 # check arguments | assign κ = [:svg, :csv] for (ζ, ξ) ∈ zip([Symbol("out", ι) for ι ∈ κ], κ) τ = shChecker(shArgs, string(ζ), string(ξ)) @eval $ζ = $τ end @info "Plotting..." # create array to plot toHeat, keyString = collectState(modelHMM) if !isnothing(labels) # concatenate annotations toHeat = [toHeat; labels' .+ 1] end # write writedlm( string(shArgs["outdir"], outcsv), toHeat, "," ) @info "Rendering..." renderGraphics( string(shArgs["outdir"], outsvg), toHeat ) end ################################################################################ "wrapper for model heatmap plotting" function renderGraphics(filename::S, toHeat::Array{T, 2}) where S <: String where T <: Number # TODO: add channel labels by passing vector to heatmap function # plot layout plotFig = Figure() heatplot = plotFig[1, 1] = Axis(plotFig, title = "States Heatmap") # axis labels heatplot.xlabel = "Recording Time" heatplot.ylabel = "Channels" # heatplot.yticks = 1:22 # heatmap plot & color range hm = heatmap!(heatplot, toHeat') hm.colorrange = (0, 5) # color bar cbar = plotFig[2, 1] = Colorbar(plotFig, hm, label = "HMM states") cbar.vertical = false cbar.height = 10 cbar.width = Relative(2 / 3) cbar.ticks = 1:1:5 # save rendering save( filename, plotFig ) end ################################################################################ "iterate over known electrodes and collect states from Hidden Markov model" function collectState(modelHMM::Dict{S, Tuple{Array{T, 1}, Array{Array{U, 1}, 1}}}) where S <: String where T <: Int64 where U <: Float64 keyString = modelHMM[convert.(String, keys(modelHMM))[1]][1] toHeat = zeros(length(modelHMM), length(keyString)) ψ = size(toHeat, 1) for ε ∈ elecID if haskey(modelHMM, ε) toHeat[ψ, :] = modelHMM[ε][1] ψ -= 1 else @debug ε end end return toHeat, keyString end ################################################################################ "check whether shell argument was explicitly declared and assigned" function shChecker(shArgs::Dict, κ::S, ζ::S) where S <: String if shArgs[κ] != nothing return shArgs[κ] else return replace(shArgs["file"], "edf" => ζ) end end ################################################################################
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import topology.subset_properties import topology.connected import topology.algebra.monoid import topology.continuous_function.basic import tactic.tfae import tactic.fin_cases /-! # Locally constant functions This file sets up the theory of locally constant function from a topological space to a type. ## Main definitions and constructions * `is_locally_constant f` : a map `f : X → Y` where `X` is a topological space is locally constant if every set in `Y` has an open preimage. * `locally_constant X Y` : the type of locally constant maps from `X` to `Y` * `locally_constant.map` : push-forward of locally constant maps * `locally_constant.comap` : pull-back of locally constant maps -/ variables {X Y Z α : Type*} [topological_space X] open set filter open_locale topological_space /-- A function between topological spaces is locally constant if the preimage of any set is open. -/ def is_locally_constant (f : X → Y) : Prop := ∀ s : set Y, is_open (f ⁻¹' s) namespace is_locally_constant protected lemma tfae (f : X → Y) : tfae [is_locally_constant f, ∀ x, ∀ᶠ x' in 𝓝 x, f x' = f x, ∀ x, is_open {x' | f x' = f x}, ∀ y, is_open (f ⁻¹' {y}), ∀ x, ∃ (U : set X) (hU : is_open U) (hx : x ∈ U), ∀ x' ∈ U, f x' = f x] := begin tfae_have : 1 → 4, from λ h y, h {y}, tfae_have : 4 → 3, from λ h x, h (f x), tfae_have : 3 → 2, from λ h x, is_open.mem_nhds (h x) rfl, tfae_have : 2 → 5, { intros h x, rcases mem_nhds_iff.1 (h x) with ⟨U, eq, hU, hx⟩, exact ⟨U, hU, hx, eq⟩ }, tfae_have : 5 → 1, { intros h s, refine is_open_iff_forall_mem_open.2 (λ x hx, _), rcases h x with ⟨U, hU, hxU, eq⟩, exact ⟨U, λ x' hx', mem_preimage.2 $ (eq x' hx').symm ▸ hx, hU, hxU⟩ }, tfae_finish end @[nontriviality] lemma of_discrete [discrete_topology X] (f : X → Y) : is_locally_constant f := λ s, is_open_discrete _ lemma is_open_fiber {f : X → Y} (hf : is_locally_constant f) (y : Y) : is_open {x | f x = y} := hf {y} lemma is_closed_fiber {f : X → Y} (hf : is_locally_constant f) (y : Y) : is_closed {x | f x = y} := ⟨hf {y}ᶜ⟩ lemma is_clopen_fiber {f : X → Y} (hf : is_locally_constant f) (y : Y) : is_clopen {x | f x = y} := ⟨is_open_fiber hf _, is_closed_fiber hf _⟩ lemma iff_exists_open (f : X → Y) : is_locally_constant f ↔ ∀ x, ∃ (U : set X) (hU : is_open U) (hx : x ∈ U), ∀ x' ∈ U, f x' = f x := (is_locally_constant.tfae f).out 0 4 lemma iff_eventually_eq (f : X → Y) : is_locally_constant f ↔ ∀ x, ∀ᶠ y in 𝓝 x, f y = f x := (is_locally_constant.tfae f).out 0 1 lemma exists_open {f : X → Y} (hf : is_locally_constant f) (x : X) : ∃ (U : set X) (hU : is_open U) (hx : x ∈ U), ∀ x' ∈ U, f x' = f x := (iff_exists_open f).1 hf x protected lemma eventually_eq {f : X → Y} (hf : is_locally_constant f) (x : X) : ∀ᶠ y in 𝓝 x, f y = f x := (iff_eventually_eq f).1 hf x protected lemma continuous [topological_space Y] {f : X → Y} (hf : is_locally_constant f) : continuous f := ⟨λ U hU, hf _⟩ lemma iff_continuous {_ : topological_space Y} [discrete_topology Y] (f : X → Y) : is_locally_constant f ↔ continuous f := ⟨is_locally_constant.continuous, λ h s, h.is_open_preimage s (is_open_discrete _)⟩ lemma iff_continuous_bot (f : X → Y) : is_locally_constant f ↔ @continuous X Y _ ⊥ f := iff_continuous f lemma of_constant (f : X → Y) (h : ∀ x y, f x = f y) : is_locally_constant f := (iff_eventually_eq f).2 $ λ x, eventually_of_forall $ λ x', h _ _ lemma const (y : Y) : is_locally_constant (function.const X y) := of_constant _ $ λ _ _, rfl lemma comp {f : X → Y} (hf : is_locally_constant f) (g : Y → Z) : is_locally_constant (g ∘ f) := λ s, by { rw set.preimage_comp, exact hf _ } lemma prod_mk {Y'} {f : X → Y} {f' : X → Y'} (hf : is_locally_constant f) (hf' : is_locally_constant f') : is_locally_constant (λ x, (f x, f' x)) := (iff_eventually_eq _).2 $ λ x, (hf.eventually_eq x).mp $ (hf'.eventually_eq x).mono $ λ x' hf' hf, prod.ext hf hf' lemma comp₂ {Y₁ Y₂ Z : Type*} {f : X → Y₁} {g : X → Y₂} (hf : is_locally_constant f) (hg : is_locally_constant g) (h : Y₁ → Y₂ → Z) : is_locally_constant (λ x, h (f x) (g x)) := (hf.prod_mk hg).comp (λ x : Y₁ × Y₂, h x.1 x.2) lemma comp_continuous [topological_space Y] {g : Y → Z} {f : X → Y} (hg : is_locally_constant g) (hf : continuous f) : is_locally_constant (g ∘ f) := λ s, by { rw set.preimage_comp, exact hf.is_open_preimage _ (hg _) } /-- A locally constant function is constant on any preconnected set. -/ lemma apply_eq_of_is_preconnected {f : X → Y} (hf : is_locally_constant f) {s : set X} (hs : is_preconnected s) {x y : X} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := begin let U := f ⁻¹' {f y}, suffices : x ∉ Uᶜ, from not_not.1 this, intro hxV, specialize hs U Uᶜ (hf {f y}) (hf {f y}ᶜ) _ ⟨y, ⟨hy, rfl⟩⟩ ⟨x, ⟨hx, hxV⟩⟩, { simp only [union_compl_self, subset_univ] }, { simpa only [inter_empty, not_nonempty_empty, inter_compl_self] using hs } end lemma iff_is_const [preconnected_space X] {f : X → Y} : is_locally_constant f ↔ ∀ x y, f x = f y := ⟨λ h x y, h.apply_eq_of_is_preconnected is_preconnected_univ trivial trivial, of_constant _⟩ lemma range_finite [compact_space X] {f : X → Y} (hf : is_locally_constant f) : (set.range f).finite := begin letI : topological_space Y := ⊥, haveI : discrete_topology Y := ⟨rfl⟩, rw @iff_continuous X Y ‹_› ‹_› at hf, exact finite_of_is_compact_of_discrete _ (is_compact_range hf) end @[to_additive] lemma one [has_one Y] : is_locally_constant (1 : X → Y) := const 1 @[to_additive] lemma inv [has_inv Y] ⦃f : X → Y⦄ (hf : is_locally_constant f) : is_locally_constant f⁻¹ := hf.comp (λ x, x⁻¹) @[to_additive] lemma mul [has_mul Y] ⦃f g : X → Y⦄ (hf : is_locally_constant f) (hg : is_locally_constant g) : is_locally_constant (f * g) := hf.comp₂ hg (*) @[to_additive] lemma div [has_div Y] ⦃f g : X → Y⦄ (hf : is_locally_constant f) (hg : is_locally_constant g) : is_locally_constant (f / g) := hf.comp₂ hg (/) /-- If a composition of a function `f` followed by an injection `g` is locally constant, then the locally constant property descends to `f`. -/ lemma desc {α β : Type*} (f : X → α) (g : α → β) (h : is_locally_constant (g ∘ f)) (inj : function.injective g) : is_locally_constant f := begin rw (is_locally_constant.tfae f).out 0 3, intros a, have : f ⁻¹' {a} = (g ∘ f) ⁻¹' { g a }, { ext x, simp only [mem_singleton_iff, function.comp_app, mem_preimage], exact ⟨λ h, by rw h, λ h, inj h⟩ }, rw this, apply h, end end is_locally_constant /-- A (bundled) locally constant function from a topological space `X` to a type `Y`. -/ structure locally_constant (X Y : Type*) [topological_space X] := (to_fun : X → Y) (is_locally_constant : is_locally_constant to_fun) namespace locally_constant instance [inhabited Y] : inhabited (locally_constant X Y) := ⟨⟨_, is_locally_constant.const (default Y)⟩⟩ instance : has_coe_to_fun (locally_constant X Y) (λ _, X → Y) := ⟨locally_constant.to_fun⟩ initialize_simps_projections locally_constant (to_fun → apply) @[simp] lemma to_fun_eq_coe (f : locally_constant X Y) : f.to_fun = f := rfl @[simp] lemma coe_mk (f : X → Y) (h) : ⇑(⟨f, h⟩ : locally_constant X Y) = f := rfl theorem congr_fun {f g : locally_constant X Y} (h : f = g) (x : X) : f x = g x := congr_arg (λ h : locally_constant X Y, h x) h theorem congr_arg (f : locally_constant X Y) {x y : X} (h : x = y) : f x = f y := congr_arg (λ x : X, f x) h theorem coe_injective : @function.injective (locally_constant X Y) (X → Y) coe_fn | ⟨f, hf⟩ ⟨g, hg⟩ h := have f = g, from h, by subst f @[simp, norm_cast] theorem coe_inj {f g : locally_constant X Y} : (f : X → Y) = g ↔ f = g := coe_injective.eq_iff @[ext] theorem ext ⦃f g : locally_constant X Y⦄ (h : ∀ x, f x = g x) : f = g := coe_injective (funext h) theorem ext_iff {f g : locally_constant X Y} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, ext h⟩ section codomain_topological_space variables [topological_space Y] (f : locally_constant X Y) protected lemma continuous : continuous f := f.is_locally_constant.continuous /-- We can turn a locally-constant function into a bundled `continuous_map`. -/ def to_continuous_map : C(X, Y) := ⟨f, f.continuous⟩ /-- As a shorthand, `locally_constant.to_continuous_map` is available as a coercion -/ instance : has_coe (locally_constant X Y) C(X, Y) := ⟨to_continuous_map⟩ @[simp] lemma to_continuous_map_eq_coe : f.to_continuous_map = f := rfl @[simp] lemma coe_continuous_map : ((f : C(X, Y)) : X → Y) = (f : X → Y) := rfl lemma to_continuous_map_injective : function.injective (to_continuous_map : locally_constant X Y → C(X, Y)) := λ _ _ h, ext (continuous_map.congr_fun h) end codomain_topological_space /-- The constant locally constant function on `X` with value `y : Y`. -/ def const (X : Type*) {Y : Type*} [topological_space X] (y : Y) : locally_constant X Y := ⟨function.const X y, is_locally_constant.const _⟩ @[simp] lemma coe_const (y : Y) : (const X y : X → Y) = function.const X y := rfl /-- The locally constant function to `fin 2` associated to a clopen set. -/ def of_clopen {X : Type*} [topological_space X] {U : set X} [∀ x, decidable (x ∈ U)] (hU : is_clopen U) : locally_constant X (fin 2) := { to_fun := λ x, if x ∈ U then 0 else 1, is_locally_constant := begin rw (is_locally_constant.tfae (λ x, if x ∈ U then (0 : fin 2) else 1)).out 0 3, intros e, fin_cases e, { convert hU.1 using 1, ext, simp only [nat.one_ne_zero, mem_singleton_iff, fin.one_eq_zero_iff, mem_preimage, ite_eq_left_iff], tauto }, { rw ← is_closed_compl_iff, convert hU.2, ext, simp } end } @[simp] lemma of_clopen_fiber_zero {X : Type*} [topological_space X] {U : set X} [∀ x, decidable (x ∈ U)] (hU : is_clopen U) : of_clopen hU ⁻¹' ({0} : set (fin 2)) = U := begin ext, simp only [of_clopen, nat.one_ne_zero, mem_singleton_iff, fin.one_eq_zero_iff, coe_mk, mem_preimage, ite_eq_left_iff], tauto, end @[simp] lemma of_clopen_fiber_one {X : Type*} [topological_space X] {U : set X} [∀ x, decidable (x ∈ U)] (hU : is_clopen U) : of_clopen hU ⁻¹' ({1} : set (fin 2)) = Uᶜ := begin ext, simp only [of_clopen, nat.one_ne_zero, mem_singleton_iff, coe_mk, fin.zero_eq_one_iff, mem_preimage, ite_eq_right_iff, mem_compl_eq], tauto, end lemma locally_constant_eq_of_fiber_zero_eq {X : Type*} [topological_space X] (f g : locally_constant X (fin 2)) (h : f ⁻¹' ({0} : set (fin 2)) = g ⁻¹' {0}) : f = g := begin simp only [set.ext_iff, mem_singleton_iff, mem_preimage] at h, ext1 x, have := h x, set a := f x, set b := g x, fin_cases a; fin_cases b; finish end lemma range_finite [compact_space X] (f : locally_constant X Y) : (set.range f).finite := f.is_locally_constant.range_finite lemma apply_eq_of_is_preconnected (f : locally_constant X Y) {s : set X} (hs : is_preconnected s) {x y : X} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := f.is_locally_constant.apply_eq_of_is_preconnected hs hx hy lemma apply_eq_of_preconnected_space [preconnected_space X] (f : locally_constant X Y) (x y : X) : f x = f y := f.is_locally_constant.apply_eq_of_is_preconnected is_preconnected_univ trivial trivial lemma eq_const [preconnected_space X] (f : locally_constant X Y) (x : X) : f = const X (f x) := ext $ λ y, apply_eq_of_preconnected_space f _ _ lemma exists_eq_const [preconnected_space X] [nonempty Y] (f : locally_constant X Y) : ∃ y, f = const X y := begin rcases classical.em (nonempty X) with ⟨⟨x⟩⟩|hX, { exact ⟨f x, f.eq_const x⟩ }, { exact ⟨classical.arbitrary Y, ext $ λ x, (hX ⟨x⟩).elim⟩ } end /-- Push forward of locally constant maps under any map, by post-composition. -/ def map (f : Y → Z) : locally_constant X Y → locally_constant X Z := λ g, ⟨f ∘ g, λ s, by { rw set.preimage_comp, apply g.is_locally_constant }⟩ @[simp] lemma map_apply (f : Y → Z) (g : locally_constant X Y) : ⇑(map f g) = f ∘ g := rfl @[simp] lemma map_id : @map X Y Y _ id = id := by { ext, refl } @[simp] lemma map_comp {Y₁ Y₂ Y₃ : Type*} (g : Y₂ → Y₃) (f : Y₁ → Y₂) : @map X _ _ _ g ∘ map f = map (g ∘ f) := by { ext, refl } /-- Given a locally constant function to `α → β`, construct a family of locally constant functions with values in β indexed by α. -/ def flip {X α β : Type*} [topological_space X] (f : locally_constant X (α → β)) (a : α) : locally_constant X β := f.map (λ f, f a) /-- If α is finite, this constructs a locally constant function to `α → β` given a family of locally constant functions with values in β indexed by α. -/ def unflip {X α β : Type*} [fintype α] [topological_space X] (f : α → locally_constant X β) : locally_constant X (α → β) := { to_fun := λ x a, f a x, is_locally_constant := begin rw (is_locally_constant.tfae (λ x a, f a x)).out 0 3, intros g, have : (λ (x : X) (a : α), f a x) ⁻¹' {g} = ⋂ (a : α), (f a) ⁻¹' {g a}, by tidy, rw this, apply is_open_Inter, intros a, apply (f a).is_locally_constant, end } @[simp] lemma unflip_flip {X α β : Type*} [fintype α] [topological_space X] (f : locally_constant X (α → β)) : unflip f.flip = f := by { ext, refl } @[simp] lemma flip_unflip {X α β : Type*} [fintype α] [topological_space X] (f : α → locally_constant X β) : (unflip f).flip = f := by { ext, refl } section comap open_locale classical variables [topological_space Y] /-- Pull back of locally constant maps under any map, by pre-composition. This definition only makes sense if `f` is continuous, in which case it sends locally constant functions to their precomposition with `f`. See also `locally_constant.coe_comap`. -/ noncomputable def comap (f : X → Y) : locally_constant Y Z → locally_constant X Z := if hf : continuous f then λ g, ⟨g ∘ f, g.is_locally_constant.comp_continuous hf⟩ else begin by_cases H : nonempty X, { introsI g, exact const X (g $ f $ classical.arbitrary X) }, { intro g, refine ⟨λ x, (H ⟨x⟩).elim, _⟩, intro s, rw is_open_iff_nhds, intro x, exact (H ⟨x⟩).elim } end @[simp] lemma coe_comap (f : X → Y) (g : locally_constant Y Z) (hf : continuous f) : ⇑(comap f g) = g ∘ f := by { rw [comap, dif_pos hf], refl } @[simp] lemma comap_id : @comap X X Z _ _ id = id := by { ext, simp only [continuous_id, id.def, function.comp.right_id, coe_comap] } lemma comap_comp [topological_space Z] (f : X → Y) (g : Y → Z) (hf : continuous f) (hg : continuous g) : @comap _ _ α _ _ f ∘ comap g = comap (g ∘ f) := by { ext, simp only [hf, hg, hg.comp hf, coe_comap] } lemma comap_const (f : X → Y) (y : Y) (h : ∀ x, f x = y) : (comap f : locally_constant Y Z → locally_constant X Z) = λ g, ⟨λ x, g y, is_locally_constant.const _⟩ := begin ext, rw coe_comap, { simp only [h, coe_mk, function.comp_app] }, { rw show f = λ x, y, by ext; apply h, exact continuous_const } end end comap section desc /-- If a locally constant function factors through an injection, then it factors through a locally constant function. -/ def desc {X α β : Type*} [topological_space X] {g : α → β} (f : X → α) (h : locally_constant X β) (cond : g ∘ f = h) (inj : function.injective g) : locally_constant X α := { to_fun := f, is_locally_constant := is_locally_constant.desc _ g (by { rw cond, exact h.2 }) inj } @[simp] lemma coe_desc {X α β : Type*} [topological_space X] (f : X → α) (g : α → β) (h : locally_constant X β) (cond : g ∘ f = h) (inj : function.injective g) : ⇑(desc f h cond inj) = f := rfl end desc end locally_constant
#include <gsl/gsl_math.h> #include <gsl/gsl_cblas.h> #include "cblas.h" void cblas_zgeru (const enum CBLAS_ORDER order, const int M, const int N, const void *alpha, const void *X, const int incX, const void *Y, const int incY, void *A, const int lda) { #define BASE double #include "source_geru.h" #undef BASE }
#include "benchmark.h" #include <ozo/connection_info.h> #include <ozo/query_builder.h> #include <ozo/request.h> #include <boost/asio/io_service.hpp> #include <boost/asio/spawn.hpp> #include <iostream> int main(int argc, char *argv[]) { using namespace ozo::literals; using namespace ozo::benchmark; namespace asio = boost::asio; if (argc < 2) { std::cout << "Usage: " << argv[0] << " <conninfo>" << std::endl; return 1; } rows_count_limit_benchmark benchmark(10000000); asio::io_context io(1); ozo::connection_info<> connection_info(argv[1]); const auto query = ("SELECT typname, typnamespace, typowner, typlen, typbyval, typcategory, "_SQL + "typispreferred, typisdefined, typdelim, typrelid, typelem, typarray "_SQL + "FROM pg_type WHERE typtypmod = "_SQL + -1 + " AND typisdefined = "_SQL + true).build(); for (int i = 0; i < 8; ++i) { asio::spawn(io, [&] (auto yield) { try { auto connection = ozo::get_connection(connection_info[io], yield); benchmark.start(); while (true) { ozo::result result; ozo::request(connection, query, std::ref(result), yield); if (!benchmark.step(result.size())) { break; } } } catch (const std::exception& e) { std::cout << e.what() << '\n'; } }); } io.run(); return 0; }
State Before: p : ℝ≥0∞ 𝕜 : Type ?u.285404 𝕜' : Type ?u.285407 ι : Type u_2 α : ι → Type ?u.285415 β✝ : ι → Type ?u.285420 inst✝² : Fintype ι inst✝¹ : Fact (1 ≤ p) β : ι → Type u_1 inst✝ : (i : ι) → SeminormedAddCommGroup (β i) x : PiLp 2 β ⊢ ‖x‖ ^ 2 = ∑ i : ι, ‖x i‖ ^ 2 State After: p : ℝ≥0∞ 𝕜 : Type ?u.285404 𝕜' : Type ?u.285407 ι : Type u_2 α : ι → Type ?u.285415 β✝ : ι → Type ?u.285420 inst✝² : Fintype ι inst✝¹ : Fact (1 ≤ p) β : ι → Type u_1 inst✝ : (i : ι) → SeminormedAddCommGroup (β i) x : PiLp 2 β ⊢ ‖x‖₊ ^ 2 = ∑ i : ι, ‖x i‖₊ ^ 2 Tactic: suffices ‖x‖₊ ^ 2 = ∑ i : ι, ‖x i‖₊ ^ 2 by simpa only [NNReal.coe_sum] using congr_arg ((↑) : ℝ≥0 → ℝ) this State Before: p : ℝ≥0∞ 𝕜 : Type ?u.285404 𝕜' : Type ?u.285407 ι : Type u_2 α : ι → Type ?u.285415 β✝ : ι → Type ?u.285420 inst✝² : Fintype ι inst✝¹ : Fact (1 ≤ p) β : ι → Type u_1 inst✝ : (i : ι) → SeminormedAddCommGroup (β i) x : PiLp 2 β ⊢ ‖x‖₊ ^ 2 = ∑ i : ι, ‖x i‖₊ ^ 2 State After: no goals Tactic: rw [nnnorm_eq_of_L2, NNReal.sq_sqrt] State Before: p : ℝ≥0∞ 𝕜 : Type ?u.285404 𝕜' : Type ?u.285407 ι : Type u_2 α : ι → Type ?u.285415 β✝ : ι → Type ?u.285420 inst✝² : Fintype ι inst✝¹ : Fact (1 ≤ p) β : ι → Type u_1 inst✝ : (i : ι) → SeminormedAddCommGroup (β i) x : PiLp 2 β this : ‖x‖₊ ^ 2 = ∑ i : ι, ‖x i‖₊ ^ 2 ⊢ ‖x‖ ^ 2 = ∑ i : ι, ‖x i‖ ^ 2 State After: no goals Tactic: simpa only [NNReal.coe_sum] using congr_arg ((↑) : ℝ≥0 → ℝ) this
/- 5. Use the Pigeonhole Principle to prove the following statements involv- ing a positive integer n: (a) In any set of 6 integers, there must be two whose difference is divisible by 5. (b) In any set of n + 1 integers, there must be two whose difference is divisible by n. (c) Given any n integers a₁, a₂,..., aₙ, there is a non-empty subset of these whose sum is divisible by n. (Hint: Consider the integers 0,a₁ , a₁ + a₂ ,..., a₁ +...+aₙ and use (b).) (d) Given any set S consisting of ten distinct integers between 1 and 50, there are two different 5-element subsets of S with the same sum. (e) Given any set T consisting of nine distinct integers between 1 and 50, there are two disjoint subsets of T with the same sum. (f) In any set of 101 integers chosen from the set {1, 2, . . . , 200}, there must be two integers such that one divides the other. -/ import tactic import combinatorics.pigeonhole import algebra.big_operators.fin import data.int.succ_pred import data.int.parity import data.nat.factorization.basic open function lemma parta (S : finset ℤ) (hS : S.card = 6) : ∃ a b ∈ S, a ≠ b ∧ (5 : ℤ) ∣ a - b := begin let f : ℤ → ℤ := λ z, z % 5, let T : finset ℤ := finset.Ico 0 5, have hfT : ∀ z : ℤ, z ∈ S → (f z) ∈ T, { intros z hz, simp only [f, finset.mem_Ico], split, apply int.mod_nonneg, norm_num, apply int.mod_lt, norm_num, }, have hST : T.card * 1 < S.card, { simp only [hS, int.card_Ico, tsub_zero, mul_one], norm_num, }, have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hfT hST, dsimp at this, rcases this with ⟨y, Hy, H⟩, rw finset.one_lt_card at H, rcases H with ⟨a, ha, b, hb, H⟩, simp only [finset.mem_filter] at ha hb, use [a, ha.1, b, hb.1, H], apply int.modeq.dvd, change f b = f a, rw [hb.2, ha.2], end lemma partb (n : ℕ) (hn : 0 < n) (S : finset ℤ) (hS : S.card = n + 1) : ∃ a b ∈ S, a ≠ b ∧ (n : ℤ) ∣ a - b := begin let f : ℤ → ℤ := λ z, z % n, let T : finset ℤ := finset.Ico 0 n, have hfT : ∀ z : ℤ, z ∈ S → (f z) ∈ T, { intros z hz, simp only [f, finset.mem_Ico], split, apply int.mod_nonneg, linarith, convert int.mod_lt _ _, simp only [nat.abs_cast], linarith, }, have hST : T.card * 1 < S.card, { simp only [hS, int.card_Ico, tsub_zero, int.to_nat_coe_nat, mul_one, lt_add_iff_pos_right, nat.lt_one_iff], }, have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hfT hST, dsimp at this, rcases this with ⟨y, Hy, H⟩, rw finset.one_lt_card at H, rcases H with ⟨a, ha, b, hb, H⟩, simp at ha hb, use [a, ha.1, b, hb.1, H], apply int.modeq.dvd, change f b = f a, rw [hb.2, ha.2], end -- A stronger of part b which should be easier to use -- (the point is that f might not be injective on s) lemma partb' {ι : Type*} {s : finset ι} (f : ι → ℤ) (hs : s.nonempty) {n : ℕ} (hn : 0 < n) (hs' : n < s.card): ∃ a b ∈ s, a ≠ b ∧ (n : ℤ) ∣ f a - f b := begin let f' : ι → ℤ := λ z, (f z) % n, let T : finset ℤ := finset.Ico 0 n, have hfT : ∀ z : ι, z ∈ s → (f' z) ∈ T, { intros z hz, simp only [f', finset.mem_Ico], have hn' : (n : ℤ) ≠ 0, { norm_cast, exact hn.ne', }, split, { exact int.mod_nonneg _ hn', }, { convert int.mod_lt _ hn', simp only [nat.abs_cast], }, }, have hST : T.card * 1 < s.card, { simp [hs'], }, obtain ⟨y, hyT, hcard⟩ := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hfT hST, rw finset.one_lt_card_iff at hcard, rcases hcard with ⟨a, b, ha, hb, hab⟩, rw finset.mem_filter at ha hb, refine ⟨a, ha.1, b, hb.1, hab, _⟩, dsimp at ha hb, apply int.modeq.dvd, change f' b = f' a, rw [hb.2, ha.2], end open_locale big_operators lemma finset.sum_Ico {M : Type*} [add_comm_group M] {a b : ℕ} (h : a ≤ b) (f : ℕ → M) : ∑ i in finset.Ico a b, f i = ∑ j in finset.range b, f j - ∑ j in finset.range a, f j := begin rw eq_sub_iff_add_eq, rw ← finset.sum_union, { apply finset.sum_congr _ (λ x _, rfl), rw [finset.range_eq_Ico, finset.union_comm, finset.Ico_union_Ico_eq_Ico (nat.zero_le a) h], }, { rintros x (hx : x ∈ _ ∩ _), rw [finset.mem_inter, finset.mem_Ico, finset.mem_range] at hx, rcases hx with ⟨⟨h1, _⟩, h2⟩, exact false.elim (h1.not_lt h2), }, end lemma partc (n : ℕ) (hn : 0 < n) (f : ℕ → ℤ) : ∃ S : finset ℕ, S ⊆ finset.range n ∧ S.nonempty ∧ (n : ℤ) ∣ ∑ i in S, f i := begin -- {ι : Type*} {s : finset ι} (f : ι → ℤ) (hs : s.nonempty) {n : ℕ} (hn : 0 < n) -- (hs' : n < s.card): ∃ a b ∈ s, a ≠ b ∧ (n : ℤ) ∣ f a - f b := sorry rcases partb' (λ t, ∑ i in finset.range t, f i) (@finset.nonempty_range_succ n) hn (by simp) with ⟨a, ha, b, hb, hab, hn⟩, rw finset.mem_range_succ_iff at ha hb, rw ne_iff_lt_or_gt at hab, rcases hab with hab | (hab : b < a), { use finset.Ico a b, refine ⟨_, _, _⟩, { rw [finset.range_eq_Ico, finset.Ico_subset_Ico_iff hab], exact ⟨zero_le a, hb⟩, }, { rwa finset.nonempty_Ico, }, { rwa [finset.sum_Ico hab.le, ← dvd_neg, neg_sub], }, }, { -- b < a case use finset.Ico b a, refine ⟨_, _, _⟩, { rw [finset.range_eq_Ico, finset.Ico_subset_Ico_iff hab], exact ⟨zero_le b, ha⟩, }, { rwa finset.nonempty_Ico, }, { rwa finset.sum_Ico hab.le, }, }, end -- should be in mathlib maybe? (thanks Eric Rodriguez) def sum_le_max (S : finset ℤ) (x : ℤ) (hS' : ∀ s ∈ S, s ≤ x) : ∑ i in S, i ≤ ∑ i in finset.Ioc (x - finset.card S) x, i := begin induction h : finset.card S with k ih generalizing S x, { obtain rfl := finset.card_eq_zero.mp h, simp}, have hSn : 0 < S.card := h.symm ▸ k.succ_pos, replace hSn : S.nonempty := finset.card_pos.mp hSn, specialize ih (S.erase (S.max' hSn)) (x - 1) (λ s hs, _) _, { rw [←int.pred, ←int.pred_eq_pred, order.le_pred_iff], obtain ⟨hs₁, hs₂⟩ := finset.mem_erase.1 hs, exact (S.lt_max'_of_mem_erase_max' hSn hs).trans_le (hS' _ $ S.max'_mem hSn) }, { simpa [h] using finset.card_erase_of_mem (S.max'_mem hSn) }, have : x - 1 - k = x - k.succ, { rw [sub_sub, sub_right_inj], simp only [add_comm, nat.cast_succ]}, rw this at ih, have hSm : S.max' hSn ≤ x := hS' _ (S.max'_mem hSn), replace ih := add_le_add ih hSm, suffices : finset.Ioc (x - k.succ) (x - 1) = (finset.Ioc (x - k.succ) x).erase x, { rwa [finset.sum_erase_add _ _ $ S.max'_mem hSn, this, finset.sum_erase_add] at ih, simp only [finset.right_mem_Ioc, sub_lt_self_iff], exact nat.cast_pos.mpr (k.succ_pos) }, ext, simp only [nat.cast_succ, finset.mem_Ioc, finset.Ioc_erase_right, finset.mem_Ioo, and.congr_right_iff], rintro -, rw [←int.pred, ←int.pred_eq_pred, order.le_pred_iff] end -- should also be in mathlib maybe? def min_le_sum (S : finset ℤ) (x : ℤ) (hS' : ∀ s ∈ S, x ≤ s) : ∑ i in finset.Ico x (x + finset.card S), i ≤ ∑ i in S, i := begin have := sum_le_max (finset.image (λ i, -i) S) (-x) _, swap, { intros s hs, rw finset.mem_image at hs, rcases hs with ⟨t, ht, rfl⟩, exact neg_le_neg (hS' t ht), }, rw ← neg_le_neg_iff, have Scard : (finset.image has_neg.neg S).card = S.card, { rw finset.card_image_iff, intros x hx y hy, exact neg_inj.1, }, convert this, { rw finset.sum_image, symmetry, apply finset.sum_neg_distrib, intros x hx y hy h, rwa neg_inj at h, }, { rw ← finset.sum_neg_distrib, apply finset.sum_bij (λ (a : ℤ) ha, -a), { intros a ha, simp only [finset.mem_Ioc, neg_le_neg_iff], rw finset.mem_Ico at ha, rw Scard, cases ha, split; linarith, }, { simp only [eq_self_iff_true, implies_true_iff], }, { simp only [neg_inj, imp_self, implies_true_iff, forall_const], }, { rw Scard, intros b hb, refine ⟨-b, _, _⟩, { simp only [finset.mem_Ico, finset.mem_Ioc] at hb ⊢, cases hb, split; linarith, }, { simp only [neg_neg], }, }, }, end lemma partd (S : finset ℤ) (hS : ∀ s ∈ S, (1 : ℤ) ≤ s ∧ s ≤ 50) (hScard : S.card = 10) : ∃ A B : finset ℤ, A.card = 5 ∧ B.card = 5 ∧ A ≠ B ∧ A ≤ S ∧ B ≤ S ∧ ∑ i in A, i = ∑ j in B, j := begin -- consider possibilities for subset of S with card 5 let P := finset.powerset_len 5 S, -- consider possibilities for sum let F := finset.Icc (15 : ℤ) 240, have hFP : F.card * 1 < P.card, { simp only [finset.card_powerset_len 5 S, hScard, int.card_Icc, mul_one], have h : (10 : ℕ).choose 5 = 252, {refl}, simp only [h], norm_num, }, let g : finset ℤ → ℤ := λ x, ∑ i in x, i, have hg : ∀ p : finset ℤ, p ∈ P → (g p) ∈ F, { intros p hp, simp only [g, finset.mem_Icc], rw finset.mem_powerset_len at hp, split, { convert min_le_sum p 1 (λ s hs, (hS s (hp.1 hs)).1), rw hp.2, refl, }, { convert sum_le_max p 50 (λ s hs, (hS s (hp.1 hs)).2), rw hp.2, refl, }, }, have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hg hFP, dsimp at this, rcases this with ⟨y, hy1, hy2⟩, rw finset.one_lt_card at hy2, rcases hy2 with ⟨A, hA, B, hB, hAB⟩, rw finset.mem_filter at hA hB, refine ⟨A, B, _⟩, rw [finset.mem_powerset_len] at hA hB, simp [hAB, hA.1, hB.1], change g A = g B, rw [hA.2, hB.2], end lemma parte (T : finset ℤ) (hT : ∀ t ∈ T, (1 : ℤ) ≤ t ∧ t ≤ 50) (hTcard : T.card = 9) : ∃ A B : finset ℤ, A ≤ T ∧ B ≤ T ∧ disjoint A B ∧ ∑ i in A, i = ∑ j in B, j := begin -- as long as we can find two non-empty sets A, B of the same sum, we can find two disjoint set by A\B and B\A suffices h : ∃ C D : finset ℤ, C ≤ T ∧ D ≤ T ∧ C ≠ D ∧ ∑ i in C, i = ∑ j in D, j, { -- let A = C - (C ∩ D), B = D - (C ∩ D), rcases h with ⟨C, D, hC, hD, hCD, h⟩, let A : finset ℤ := C \ D, let B : finset ℤ := D \ C, refine ⟨A, B, _⟩, have hAC : A ≤ C, apply finset.sdiff_subset, have hBD : B ≤ D, apply finset.sdiff_subset, have hA : A ≤ T := le_trans hAC hC, have hB : B ≤ T := le_trans hBD hD, refine ⟨hA, hB, disjoint_sdiff_sdiff, _⟩, let X := C ∩ D, suffices : ∑ (i : ℤ) in A, i + ∑ (x : ℤ) in X, x = ∑ (j : ℤ) in B, j + ∑ (x : ℤ) in X, x, exact (add_left_inj (∑ (x : ℤ) in X, x)).mp this, convert h, { suffices : C = A ∪ X, { rw [this, ← finset.sum_union], exact finset.disjoint_sdiff_inter C D, }, ext x, simp only [finset.mem_union, finset.mem_sdiff, finset.mem_inter, ← and_or_distrib_left], tauto, }, { suffices : D = B ∪ X, { rw [this, ← finset.sum_union], change disjoint B (C ∩ D), rw finset.inter_comm C D, exact finset.disjoint_sdiff_inter D C, }, { ext x, simp only [finset.mem_union, finset.mem_sdiff, finset.mem_inter, ← and_or_distrib_left], tauto, }, }, }, { -- consider powerset of T let P := finset.powerset T, let F := finset.Icc (0:ℤ) 414, have hPF : F.card * 1 < P.card, { simp [nat.card_Icc, finset.card_powerset, hTcard], norm_num, }, -- find a map from P to F by summing elements in P let g : finset ℤ → ℤ := λ x, ∑ i in x, i, have hg : ∀ p : finset ℤ, p ∈ P → (g p) ∈ F, { intros p hp, simp [g], rw finset.mem_powerset at hp, split, { apply finset.sum_nonneg, intros i hi, exact le_trans zero_le_one (hT i (hp hi)).1, }, { transitivity (∑ i in T, i), { apply finset.sum_le_sum_of_subset_of_nonneg hp, intros i hi _, exact le_trans zero_le_one (hT i hi).1, }, { convert sum_le_max T 50 _, { rw hTcard, refl, }, { intros i hi, exact (hT i hi).2, }, } }, }, have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hg hPF, dsimp at this, rcases this with ⟨y, hy1, hy2⟩, rw finset.one_lt_card at hy2, rcases hy2 with ⟨C, hC, D, hD, hCD⟩, rw [finset.mem_filter, finset.mem_powerset] at hC hD, refine ⟨C, D, hC.1, hD.1, hCD, _⟩, change g C = g D, rw [hC.2, hD.2], }, end lemma nat.ord_compl_eq_dvd (a b : ℕ) (h : ord_compl[2] a = ord_compl[2] b) (ha : 0 < a) (hab : a < b) : a ∣ b := begin -- if a = 2^k1 * p, b = 2^k2 * p set k1 : ℕ := a.factorization 2, set k2 : ℕ := b.factorization 2, rw dvd_iff_exists_eq_mul_left, -- c = 2^ (k2 - k1) use (2 ^ (k2 - k1)), have h02 : 0 < 2 := by norm_num, -- because of natural division is involved, we need divisibility have had := nat.ord_proj_dvd a 2, have hbd := nat.ord_proj_dvd b 2, have haf := pow_pos h02 k1, have hbf := pow_pos h02 k2, have hab : k1 ≤ k2, { by_contra hc, push_neg at hc, have hc' : 2 ^ k2 < 2 ^ k1, { rw pow_lt_pow_iff, exact hc, norm_num, }, have hak : 0 < a / 2 ^ k1, { apply nat.div_pos, apply nat.ord_proj_le, exact ne_of_gt ha, exact haf, }, suffices : b < a, { linarith, }, { have hc'' : 2 ^ k2 * (b / 2 ^ k2) < 2 ^ k1 * (a / 2 ^ k1), { rw ← h, apply mul_lt_mul_of_pos_right hc' hak, }, rw [mul_comm (2 ^ k2) (b / 2 ^ k2), nat.div_mul_cancel] at hc'', swap, exact hbd, rw [mul_comm (2 ^ k1) (a / 2 ^ k1), nat.div_mul_cancel] at hc'', exact hc'', exact had, }, }, have := nat.pow_div hab h02, rw ← this, -- again we need divisibility to proceed have hkd := pow_dvd_pow 2 hab, rw [mul_comm, ← nat.mul_div_assoc _ hkd, mul_comm a (2^k2), nat.mul_div_assoc], swap, exact had, rw [h, mul_comm, nat.div_mul_cancel hbd], end lemma partf (T : finset ℕ) (hT : ∀ t ∈ T, (1 : ℤ) ≤ t ∧ t ≤ 200) (hTcard : T.card = 101) : ∃ a b : ℕ, a ∈ T ∧ b ∈ T ∧ a ≠ b ∧ a ∣ b := begin -- claim : every t can be written as 2^k * q for which q is odd, using ord_compl[2] t let Q : finset ℕ := (finset.Icc 1 200).filter odd, have hQcard : Q.card = 100, { -- Show that it equals (finset.Iio 100).map \<\la n, 2 * n + 1, proof_of_injectivity_here\> have hQ : Q = (finset.Iio 100).map ⟨λ n, 2 * n + 1 , begin intros a b hab, simpa [add_left_inj, mul_eq_mul_left_iff, bit0_eq_zero, nat.one_ne_zero, or_false] using hab, end ⟩, { dsimp [Q], rw le_antisymm_iff, split, { intros x hx, simp only [finset.mem_map, finset.mem_Iio, function.embedding.coe_fn_mk, exists_prop, nat.one_le_cast, finset.mem_filter, finset.mem_Icc, nat.odd_iff_not_even] at hx ⊢, refine ⟨((x-1)/2), _, _⟩, { rcases hx with ⟨⟨h1, h2⟩, h3⟩, zify at h2 ⊢, rw int.div_lt_iff_lt_mul, linarith, norm_num, }, { rcases hx with ⟨⟨h1, h2⟩, h3⟩, rw ← nat.odd_iff_not_even at h3, unfold odd at h3, cases h3 with k h3, rw h3, simp only [nat.add_succ_sub_one, add_zero, nat.mul_div_right, nat.succ_pos'], }, }, { intros x hx, simp only [finset.mem_map, finset.mem_Iio, function.embedding.coe_fn_mk, exists_prop, nat.one_le_cast, finset.mem_filter, finset.mem_Icc, nat.odd_iff_not_even] at hx ⊢, rcases hx with ⟨a, ⟨h1, h2⟩⟩, refine ⟨⟨_, _⟩, _⟩, { rw ← h2, linarith, }, { rw ← h2, linarith, }, { intro h, rw [nat.even_iff, ← h2, nat.mul_comm, nat.mul_add_mod a 2 1] at h, simpa [nat.one_mod, nat.one_ne_zero] using h, }, }, }, rw hQ, simp only [nat.card_Iio, finset.card_map], }, have hTO : Q.card * 1 < T.card, { rw [hQcard, hTcard], norm_num, }, -- find a map from T to Q, by considering corresponding 'q' let f : ℕ → ℕ := λ z, ord_compl[2] z, have hf : ∀ t ∈ T, (f t) ∈ Q, { intros t ht, simp only [f, finset.mem_filter, finset.mem_Icc, nat.odd_iff_not_even], have ht0 : t ≠ 0, { specialize hT t ht, cases hT with hT1 hT2, linarith, }, refine ⟨⟨_,_⟩,_⟩, { rw nat.one_le_div_iff, {apply nat.ord_proj_le 2 ht0, }, {exact nat.ord_proj_pos t 2, }, }, { apply nat.div_le_of_le_mul, have h1 := nat.ord_proj_pos t 2, rw ← nat.succ_le_iff at h1, exact le_mul_of_one_le_of_le h1 (hT t ht).2, }, { simp only [even_iff_two_dvd, nat.not_dvd_ord_compl nat.prime_two ht0, not_false_iff], }, }, have := finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to hf hTO, dsimp at this, rcases this with ⟨y, hy1, hy2⟩, rw finset.one_lt_card at hy2, rcases hy2 with ⟨a, ha, b, hb, hab⟩, by_cases a < b, { refine ⟨a, b, _⟩, simp only [hab, ne.def, not_false_iff, true_and], rw finset.mem_filter at ha hb, simp only [ha.1, hb.1, true_and], have ha0 : 0 < a, { specialize hT a ha.1, cases hT with h1 h2, linarith, }, suffices : f a = f b, { apply nat.ord_compl_eq_dvd, exact this, exact ha0, exact h, }, { rw [ha.2, hb.2], }, }, { have h : b < a, { omega, }, refine ⟨b, a, _⟩, simp only [ne.symm hab, ne.def, not_false_iff, true_and], rw finset.mem_filter at ha hb, simp only [ha.1, hb.1, true_and], have hb0 : 0 < b, { specialize hT b hb.1, cases hT with h1 h2, linarith, }, suffices : f b = f a, { apply nat.ord_compl_eq_dvd, exact this, exact hb0, exact h, }, { rw [ha.2, hb.2], }, }, end
(* * 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 dc_20081211 imports "../CTranslation" begin install_C_file "dc_20081211.c" declare [[show_types]] context dc_20081211_global_addresses begin thm \<Gamma>_def end context setHardwareASID_modifies begin thm \<Gamma>_def thm setHardwareASID_modifies end context dc_20081211 begin term "\<Gamma>" thm setHardwareASID_modifies thm test_body_def thm test_modifies lemma test_modifies: "\<forall>s. \<Gamma> \<turnstile>\<^bsub>/UNIV\<^esub> {s} Call test_'proc {t. t may_only_modify_globals s in [x]}" (* fails: apply(vcg spec=modifies) perhaps because there already is a test_modifies already in scope *) oops end end