text
stringlengths 0
3.34M
|
---|
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-type-defaults #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fplugin Data.Singletons.TypeNats.Presburger #-}
module Algebra.Algorithms.Groebner.ZeroDimSpec where
import Algebra.Algorithms.Groebner
import Algebra.Algorithms.ZeroDim
import Algebra.Internal
import Algebra.Prelude.Core hiding ((%))
import Algebra.Ring.Ideal
import Algebra.Ring.Polynomial
import Algebra.Ring.Polynomial.Quotient
import Control.Monad
import Control.Monad.Random
import Data.Complex
import Data.Convertible (convert)
import qualified Data.Foldable as F
import qualified Data.Matrix as M
import Data.Maybe
import qualified Data.Sized as SV
import Data.Type.Natural.Lemma.Order
import qualified Data.Vector as V
import Numeric.Field.Fraction (Fraction, (%))
import Numeric.Natural
import Test.QuickCheck hiding (promote)
import qualified Test.QuickCheck as QC
import Test.Tasty
import Test.Tasty.ExpectedFailure
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck
import Utils
import qualified Prelude as P
default (Fraction Integer, Natural)
asGenListOf :: Gen [a] -> a -> Gen [a]
asGenListOf = const
test_solveLinear :: TestTree
test_solveLinear =
testGroup
"solveLinear"
[ testCase "solves data set correctly" $
forM_ linSet $ \set ->
solveLinear (M.fromLists $ inputMat set) (V.fromList $ inputVec set)
@?= Just (V.fromList $ answer set)
, testProperty "solves any solvable cases" $
forAll (resize 10 arbitrary) $ \(MatrixCase ms) ->
let mat = M.fromLists ms :: M.Matrix (Fraction Integer)
in rank mat == M.ncols mat
==> forAll (vector (length $ head ms))
$ \v ->
let ans = M.getCol 1 $ mat P.* M.colVector (V.fromList v)
in solveLinear mat ans == Just (V.fromList v)
, ignoreTestBecause "Needs effective inputs for this" $
testCase "cannot solve unsolvable cases" $
pure ()
]
test_univPoly :: TestTree
test_univPoly =
testGroup
"univPoly"
[ testProperty "produces monic generators of the elimination ideal" $
withMaxSuccess 25 $
QC.mapSize (const 4) $
checkForTypeNat [2 .. 4] chk_univPoly
]
test_radical :: TestTree
test_radical =
testGroup
"radical"
[ ignoreTestBecause "We can verify correctness by comparing with singular, but it's not quite smart way..." $
testCase "really computes radical" $ pure ()
]
test_fglm :: TestTree
test_fglm =
testGroup
"fglm"
[ testProperty "computes monomial basis" $
withMaxSuccess 25 $
mapSize (const 3) $
checkForTypeNat [2 .. 4] $ \sdim ->
case zeroOrSucc sdim of
IsZero -> error "impossible"
IsSucc k ->
withWitness (lneqSucc k) $
withWitness (lneqZero k) $
withKnownNat k $
forAll (zeroDimOf sdim) $ \(ZeroDimIdeal ideal) ->
let base =
reifyQuotient (mapIdeal (changeOrder Lex) ideal) $ \ii ->
map quotRepr $ fromJust $ standardMonomials' ii
in stdReduced (snd $ fglm ideal) == stdReduced base
, testProperty "computes lex base" $
checkForTypeNat [2 .. 4] $ \sdim ->
case zeroOrSucc sdim of
IsZero -> error "impossible"
IsSucc k -> withKnownNat k $
withWitness (lneqSucc k) $
withWitness (lneqZero k) $
forAll (zeroDimOf sdim) $ \(ZeroDimIdeal ideal) ->
stdReduced (fst $ fglm ideal)
== stdReduced (calcGroebnerBasisWith Lex ideal)
, testProperty "returns lex base in descending order" $
checkForTypeNat [2 .. 4] $ \sdim ->
case zeroOrSucc sdim of
IsZero -> error "impossible"
IsSucc k -> withKnownNat k $
case (lneqSucc k, lneqZero k) of
(Witness, Witness) ->
forAll (zeroDimOf sdim) $ \(ZeroDimIdeal ideal) ->
isDescending (map leadingMonomial $ fst $ fglm ideal)
]
test_solve' :: TestTree
test_solve' =
testGroup
"solve'"
[ testProperty "solves equation with admissible error" $
withMaxSuccess 50 $
mapSize (const 4) $ do
checkForTypeNat [2 .. 4] $ chkIsApproximateZero 1e-5 (pure . solve' 1e-5)
, testGroup "solves regression cases correctly" $
map (approxZeroTestCase 1e-5 (pure . solve' 1e-5)) companionRegressions
]
test_solveViaCompanion :: TestTree
test_solveViaCompanion =
testGroup
"solveViaCompanion"
[ testProperty "solves equation with admissible error" $
withMaxSuccess 50 $
mapSize (const 4) $
checkForTypeNat [2 .. 4] $
chkIsApproximateZero
1e-5
(pure . solveViaCompanion 1e-5)
, testGroup "solves regression cases correctly" $
map (approxZeroTestCase 1e-5 (pure . solveViaCompanion 1e-5)) companionRegressions
]
test_solveM :: TestTree
test_solveM =
testGroup
"solveM"
[ testProperty "solves equation with admissible error" $
withMaxSuccess 50 $
mapSize (const 4) $
checkForTypeNat [2 .. 4] $ chkIsApproximateZero 1e-9 solveM
, testGroup "solves regressions correctly" $
map (approxZeroTestCase 1e-9 solveM) companionRegressions
]
isDescending :: Ord a => [a] -> Bool
isDescending xs = and $ zipWith (>=) xs (drop 1 xs)
chkIsApproximateZero ::
(KnownNat n) =>
Double ->
( forall m.
(0 < m, KnownNat m) =>
Ideal (Polynomial (Fraction Integer) m) ->
IO [Sized m (Complex Double)]
) ->
SNat n ->
Property
chkIsApproximateZero err solver sn =
case zeroOrSucc sn of
IsSucc _ ->
withKnownNat sn $
forAll (zeroDimOf sn) $ ioProperty . checkSolverApproxZero err solver
IsZero -> error "chkIsApproximateZero must be called with non-zero typenats!"
companionRegressions ::
[SolverTestCase]
companionRegressions =
[ SolverTestCase @3 $
let [x, y, z] = vars
in ZeroDimIdeal $
toIdeal
[ 2 * x ^ 2 + (0.5 :: Fraction Integer) .*. x * y
, - (0.5 :: Fraction Integer) .*. y ^ 2 + y * z
, z ^ 2 - z
]
, SolverTestCase @3 $
let [x, y, z] = vars
in ZeroDimIdeal $
toIdeal
[2 * x + 1, 2 * y ^ 2, - z ^ 2 - 1]
, SolverTestCase @2 $
let [x, y] = vars
in ZeroDimIdeal $
toIdeal
[x ^ 2 - y, -2 * y ^ 2]
]
approxZeroTestCase ::
Double ->
( forall n.
(0 < n, KnownNat n) =>
Ideal (Polynomial (Fraction Integer) n) ->
IO [Sized n (Complex Double)]
) ->
SolverTestCase ->
TestTree
approxZeroTestCase err calc (SolverTestCase f@(ZeroDimIdeal i)) =
testCase (show $ getIdeal f) $ do
isZeroDimensional (F.toList i) @? "Not zero-dimensional!"
checkSolverApproxZero err calc f
@? "Solved correctly"
checkSolverApproxZero ::
(0 < n, KnownNat n) =>
Double ->
(Ideal (Polynomial (Fraction Integer) n) -> IO [Sized n (Complex Double)]) ->
ZeroDimIdeal n ->
IO Bool
checkSolverApproxZero err solver (ZeroDimIdeal ideal) = do
anss <- solver ideal
let mul r d = convert r * d
pure $
all
( \as ->
all ((< err) . magnitude . substWith mul as) $
generators ideal
)
anss
data SolverTestCase where
SolverTestCase ::
(0 < n, KnownNat n) =>
ZeroDimIdeal n ->
SolverTestCase
chk_univPoly :: KnownNat n => SNat n -> Property
chk_univPoly sdim =
forAll (zeroDimOf sdim) $ \(ZeroDimIdeal ideal) ->
let ods = enumOrdinal sdim
in conjoin $
flip map ods $ \nth ->
let gen = univPoly nth ideal
in forAll (unaryPoly sdim nth) $ \f ->
(f `modPolynomial` [gen] == 0) == (f `isIdealMember` ideal)
rank :: (Ord r, Fractional r) => M.Matrix r -> Int
rank mat =
let Just (u, _, _, _, _, _) = M.luDecomp' mat
in V.foldr (\a acc -> if a /= 0 then acc + 1 else acc) (0 :: Int) $ M.getDiag u
data TestSet = TestSet
{ inputMat :: [[Fraction Integer]]
, inputVec :: [Fraction Integer]
, answer :: [Fraction Integer]
}
deriving (Show, Eq, Ord)
linSet :: [TestSet]
linSet =
[ TestSet
[ [1, 0, 0, 0, 0]
, [0, (-2), (-2), (-2), (-2)]
, [0, 0, 3 % 2, 0, (-1) % 2]
, [0, 0, 0, 0, (-5) % 2]
, [0, 1, 1, 1, 1]
, [0, 0, (-2), 1, (-1)]
]
[0, (-2), 19 % 5, 14 % 5, 1, 0]
[0, (-81) % 25, 54 % 25, 16 % 5, (-28) % 25]
]
|
import tactic.default .tactic .basic
universes u v w
namespace two_three
variables (α : Type u) (β : Type v) {γ : Type w}
open tree nat
variables {α β}
inductive liftp (p : α → Prop) : tree α β → Prop
| leaf {k v} : p k → liftp (tree.leaf k v)
| node2 {x} {t₀ t₁} : p x → liftp t₀ → liftp t₁ → liftp (tree.node2 t₀ x t₁)
| node3 {x y} {t₀ t₁ t₂} : p x → p y → liftp t₀ → liftp t₁ → liftp t₂ → liftp (tree.node3 t₀ x t₁ y t₂)
-- | node4 {x y z} {t₀ t₁ t₂ t₃} :
-- p x → p y → p z →
-- liftp t₀ → liftp t₁ →
-- liftp t₂ → liftp t₃ →
-- liftp (tree.node4 t₀ x t₁ y t₂ z t₃)
lemma liftp_true {t : tree α β} : liftp (λ _, true) t :=
begin
induction t; repeat { trivial <|> assumption <|> constructor },
end
lemma liftp_map {p q : α → Prop} {t : tree α β} (f : ∀ x, p x → q x) (h : liftp p t) :
liftp q t :=
begin
induction h; constructor; solve_by_elim
end
lemma liftp_and {p q : α → Prop} {t : tree α β} (h : liftp p t) (h' : liftp q t) :
liftp (λ x, p x ∧ q x) t :=
begin
induction h; cases h'; constructor;
solve_by_elim [and.intro]
end
lemma exists_of_liftp {p : α → Prop} {t : tree α β} (h : liftp p t) :
∃ x, p x :=
begin
cases h; split; assumption
end
section defs
variables [has_le α] [has_lt α]
open tree nat
variables [@decidable_rel α (<)]
def insert' (x : α) (v' : β) :
tree α β →
(tree α β → γ) →
(tree α β → α → tree α β → γ) → γ
| (tree.leaf y v) ret_one inc_two :=
match cmp x y with
| ordering.lt := inc_two (tree.leaf x v') y (tree.leaf y v)
| ordering.eq := ret_one (tree.leaf y v')
| ordering.gt := inc_two (tree.leaf y v) x (tree.leaf x v')
end
| (tree.node2 t₀ y t₁) ret_one inc_two :=
if x < y then
insert' t₀
(λ t', ret_one $ tree.node2 t' y t₁)
(λ ta k tb, ret_one $ tree.node3 ta k tb y t₁)
else
insert' t₁
(λ t', ret_one $ tree.node2 t₀ y t')
(λ ta k tb, ret_one $ tree.node3 t₀ y ta k tb)
| (tree.node3 t₀ y t₁ z t₂) ret_one inc_two :=
if x < y
then insert' t₀
(λ t', ret_one $ tree.node3 t' y t₁ z t₂)
(λ ta k tb, inc_two (tree.node2 ta k tb) y (tree.node2 t₁ z t₂))
else if x < z
then insert' t₁
(λ t', ret_one $ tree.node3 t₀ y t' z t₂)
(λ ta k tb, inc_two (tree.node2 t₀ y ta) k (tree.node2 tb z t₂))
else insert' t₂
(λ t', ret_one $ tree.node3 t₀ y t₁ z t')
(λ ta k tb, inc_two (tree.node2 t₀ y t₁) z (tree.node2 ta k tb))
def insert (x : α) (v' : β) (t : tree α β) : tree α β :=
insert' x v' t id tree.node2
-- inductive shrunk (α : Type u) : ℕ
section add_
variables (ret shr : tree α β → γ)
def add_left : tree α β → α → tree α β → γ
| t₀ x t@(tree.leaf _ _) := ret t₀
| t₀ x (tree.node2 t₁ y t₂) := shr (tree.node3 t₀ x t₁ y t₂)
| t₀ x (tree.node3 t₁ y t₂ z t₃) := ret (tree.node2 (tree.node2 t₀ x t₁) y (tree.node2 t₂ z t₃))
def add_right : tree α β → α → tree α β → γ
| t@(tree.leaf _ _) x t₀ := ret t
| (tree.node2 t₀ x t₁) y t₂ := shr (tree.node3 t₀ x t₁ y t₂)
| (tree.node3 t₀ x t₁ y t₂) z t₃ := ret (tree.node2 (tree.node2 t₀ x t₁) y (tree.node2 t₂ z t₃))
variables (t₀ : tree α β) (x : α) (t₁ : tree α β) (y : α) (t₂ : tree α β)
def add_left_left : Π (t₀ : tree α β) (x : α) (t₁ : tree α β) (y : α) (t₂ : tree α β), γ
| t₀ x (tree.leaf k v) z t₂ := ret t₀
| t₀ x (tree.node2 t₁ y t₂) z t₃ := ret (tree.node2 (tree.node3 t₀ x t₁ y t₂) z t₃)
| t₀ w (tree.node3 t₁ x t₂ y t₃) z t₄ := ret (tree.node3 (tree.node2 t₀ w t₁) x (tree.node2 t₂ y t₃) z t₄)
def add_middle : Π (t₀ : tree α β) (x : α) (t₁ : tree α β) (y : α) (t₂ : tree α β), γ
| t@(tree.leaf k v) y t₁ z t₂ := ret t
| (tree.node2 t₀ x t₁) y t₂ z t₃ := ret (tree.node2 (tree.node3 t₀ x t₁ y t₂) z t₃)
| (tree.node3 t₀ w t₁ x t₂) y t₃ z t₄ := ret (tree.node3 (tree.node2 t₀ w t₁) x (tree.node2 t₂ y t₃) z t₄)
def add_right_right : Π (t₀ : tree α β) (x : α) (t₁ : tree α β) (y : α) (t₂ : tree α β), γ
| t₀ x (tree.leaf k v) z t₂ := ret t₀
| t₀ x (tree.node2 t₁ y t₂) z t₃ := ret (tree.node2 t₀ x (tree.node3 t₁ y t₂ z t₃))
| t₀ w (tree.node3 t₁ x t₂ y t₃) z t₄ := ret (tree.node3 t₀ w (tree.node2 t₁ x t₂) y (tree.node2 t₃ z t₄))
end add_
def delete' [decidable_eq α] (x : α) :
tree α β →
(option α → tree α β → γ) →
(option α → tree α β → γ) →
(unit → γ) → γ
| (tree.leaf y v) ret shr del :=
if x = y then del () else ret (some y) (tree.leaf y v)
| (tree.node2 t₀ y t₁) ret shr del :=
if x < y
then delete' t₀ (λ a t', ret a $ tree.node2 t' y t₁)
(λ a t', add_left (ret a) (shr a) t' y t₁)
(λ _, shr (some y) t₁)
else delete' t₁ (λ y' t', ret none $ tree.node2 t₀ (y'.get_or_else y) t')
(λ y' t', add_right (ret none) (shr none) t₀ (y'.get_or_else y) t')
(λ _, shr none t₀)
| (tree.node3 t₀ y t₁ z t₂) ret shr del :=
if x < y
then delete' t₀ (λ a t', ret a $ tree.node3 t' y t₁ z t₂)
(λ a t', add_left_left (ret a) t' y t₁ z t₂)
(λ _, ret (some y) $ tree.node2 t₁ z t₂)
else if x < z
then delete' t₁ (λ a t', ret none $ tree.node3 t₀ (a.get_or_else y) t' z t₂)
(λ a t', add_middle (ret none) t₀ y t' z t₂)
(λ _, ret none $ tree.node2 t₀ z t₂)
else delete' t₂ (λ a t', ret none $ tree.node3 t₀ y t₁ (a.get_or_else z) t')
(λ a t', add_right_right (ret none) t₀ y t₁ z t')
(λ _, ret none $ tree.node2 t₀ y t₁)
def delete [decidable_eq α] (x : α) (t : tree α β) : option (tree α β) :=
delete' x t (λ _, some) (λ _, some) (λ _, none)
end defs
local attribute [simp] add_left add_right add_left_left add_middle add_right_right first last
variables [linear_order α]
-- #check @above_of_above_of_forall_le_of_le
lemma first_le_last_of_sorted {t : tree α β} (h : sorted' t) :
first t ≤ last t :=
begin
induction h; subst_vars; dsimp [first, last],
{ refl },
repeat { solve_by_elim [le_of_lt] <|> transitivity },
end
lemma eq_of_below {x : option α} {y : α} (h : below x y) : x.get_or_else y = y :=
by cases h; refl
lemma above_of_above_of_le {x y : α} {k}
(h : x ≤ y) (h' : above y k) : above x k :=
by cases h'; constructor; solve_by_elim [lt_of_le_of_lt]
@[interactive]
meta def interactive.saturate : tactic unit := do
tactic.interactive.casesm (some ()) [``(above _ (some _)), ``(below (some _) _), ``(below' (some _) _)],
tactic.find_all_hyps ``(sorted' _) $ λ h, do
{ n ← tactic.get_unused_name `h,
tactic.mk_app ``first_le_last_of_sorted [h] >>= tactic.note n none,
tactic.skip },
tactic.find_all_hyps ``(below _ _) $ λ h, do
{ n ← tactic.get_unused_name `h,
tactic.mk_app ``eq_of_below [h] >>= tactic.note n none,
tactic.skip },
tactic.find_all_hyps ``(¬ _ < _) $ λ h, do
{ -- n ← tactic.get_unused_name `h,
tactic.mk_app ``le_of_not_gt [h] >>= tactic.note h.local_pp_name none,
tactic.clear h,
tactic.skip }
@[interactive]
meta def interactive.above : tactic unit := do
-- tactic.interactive.saturate,
tactic.find_hyp ``(above _ _) $ λ h, do
tactic.refine ``(above_of_above_of_le _ %%h),
tactic.interactive.chain_trans
section sorted_insert
variables (lb ub : option α)
(P : γ → Prop)
(ret : tree α β → γ)
-- (ret' : tree α β → tree α β)
(mk : tree α β → α → tree α β → γ)
(h₀ : ∀ t,
below lb (first t) →
above (last t) ub →
sorted' t → P (ret t))
(h₂ : ∀ t₀ x t₁,
below lb (first t₀) →
above (last t₀) (some x) →
below (some x) (first t₁) →
above (last t₁) ub →
sorted' t₀ → sorted' t₁ → P (mk t₀ x t₁))
include h₀ h₂
lemma sorted_insert_aux' {k : α} {v : β} {t}
(h : sorted' t)
(h' : below lb (min k (first t)))
(h'' : above k ub)
(h''' : above (last t) ub) :
P (insert' k v t ret mk) :=
begin
-- generalize_hyp hlb : none = k₀ at h,
induction h generalizing lb ub ret mk,
case two_three.sorted'.leaf : k' v' lb ub ret mk h₀ h₂ h' h''
{ dsimp [insert'],
trichotomy k =? k'; dsimp [insert']; apply h₀ <|> apply h₂,
all_goals
{ try { have h := le_of_lt h },
simp [first, h, min_eq_left, min_eq_right, min_self] at h', },
repeat { assumption <|> constructor <|> refl } },
case two_three.sorted'.node2 : x t₀ t₁ h h' h_a h_a_1
h_ih₀ h_ih₁ lb ub ret mk h₀ h₂
{ dsimp [insert'],
split_ifs; [apply @h_ih₀ lb (some x), apply @h_ih₁ (some x) ub]; clear h_ih₀ h_ih₁,
all_goals
{ try { intros, apply h₀ <|> apply h₂ },
clear h₀ h₂, },
all_goals
{ casesm* [above _ (some _), below (some _) _],
dsimp [first, last] at * { fail_if_unchanged := ff },
repeat { assumption <|> constructor } },
all_goals
{ find_all_hyps foo := ¬ (_ < _) then { replace foo := le_of_not_gt foo },
find_all_hyps ht := sorted' _ then { have hh := first_le_last_of_sorted ht } },
{ rw min_eq_right at h'_1, assumption, chain_trans, },
{ have h : first t₀ ≤ k, chain_trans,
have hh' := min_eq_right h, cc, },
{ subst x,
rw min_eq_right h_1, constructor } },
case two_three.sorted'.node3 : x y t₀ t₁ t₂ h_a h_a_1 h_a_2 h_a_3 h_a_4 h_a_5 h_a_6
h_ih₀ h_ih₁ h_ih₂ lb ub ret mk h₀ h₂ h' h'' h'''
{ dsimp [insert'],
split_ifs; [apply @h_ih₀ lb (some x), apply @h_ih₁ (some x) (some y), apply @h_ih₂ (some y) ub];
clear h_ih₀ h_ih₁ h_ih₂,
all_goals
{ try { intros, apply h₀ <|> apply h₂ },
clear h₀ h₂, },
all_goals
{ casesm* [above _ (some _), below (some _) _],
subst_vars,
dsimp [first, last] at * { fail_if_unchanged := ff },
repeat { assumption <|> constructor } },
all_goals
{ find_all_hyps foo := ¬ (_ < _) then { replace foo := le_of_not_gt foo },
find_all_hyps ht := sorted' _ then { have hh := first_le_last_of_sorted ht },
have h₀ : first t₀ ≤ k; [chain_trans, skip],
try { have h₁ : first t₁ ≤ k; [chain_trans, skip] },
try { have h₂ : first t₂ ≤ k; [chain_trans, skip] } },
{ have hh' := min_eq_right h₀, cc, },
{ have hh' := min_eq_right h₀, cc, },
{ rw min_eq_right h₁, constructor, },
{ have hh' := min_eq_right h₀, cc, },
{ have hh' := min_eq_right h₀, cc, },
{ rw min_eq_right h₂, constructor, } },
end
end sorted_insert
lemma sorted_insert {k : α} {v : β} {t : tree α β}
(h : sorted' t) :
sorted' (insert k v t) :=
sorted_insert_aux' none none _ _ _
(λ t _ _ h, h)
(λ t₀ x t₁ h₀ h₁ h₂ h₃ ht₀ ht₁, sorted'.node2 (by cases h₁; assumption) (by cases h₂; refl) ht₀ ht₁)
h (by constructor) (by constructor) (by constructor)
section with_height_insert
variables (n : ℕ) (P : γ → Prop)
(ret : tree α β → γ)
(mk : tree α β → α → tree α β → γ)
(h₀ : ∀ t, with_height n t → P (ret t))
(h₂ : ∀ t₀ x t₁,
with_height n t₀ → with_height n t₁ → P (mk t₀ x t₁))
include h₀ h₂
lemma with_height_insert_aux {k : α} {v : β} {t}
(h : with_height n t) :
P (insert' k v t ret mk) :=
begin
induction h generalizing ret mk,
case two_three.with_height.leaf : k' v'
{ dsimp [insert'],
trichotomy k =? k',
all_goals
{ dsimp [insert'], subst_vars, apply h₂ <|> apply h₀, repeat { constructor }, }, },
case two_three.with_height.node2 : h_n h_x h_t₀ h_t₁ h_a h_a_1 h_ih₀ h_ih₁
{ dsimp [insert'], split_ifs,
repeat { intro <|> apply h_ih₀ <|> apply h_ih₁ <|>
apply h₀ <|> apply h₂ <|> assumption <|> constructor }, },
case two_three.with_height.node3 : h_n h_x h_y h_t₀ h_t₁ h_t₂ h_a h_a_1 h_a_2 h_ih₀ h_ih₁ h_ih₂
{ dsimp [insert'], split_ifs,
repeat { intro <|> apply h_ih₀ <|> apply h_ih₁ <|> apply h_ih₂ <|>
apply h₀ <|> apply h₂ <|> assumption <|> constructor }, },
end
end with_height_insert
lemma with_height_insert {k : α} {v : β} {n t}
(h : with_height n t) :
with_height n (insert k v t) ∨
with_height (succ n) (insert k v t) :=
begin
apply with_height_insert_aux _ (λ t' : tree α β, with_height n t' ∨ with_height (succ n) t') _ _ _ _ h,
{ introv h', left, apply h' },
{ introv h₀ h₁, right, constructor; assumption }
end
section with_height_add_left
variables (n : ℕ) (P : γ → Prop)
(ret shr : tree α β → γ)
variables
(h₀ : ∀ t, with_height (succ (succ n)) t → P (ret t))
(h₁ : ∀ t, with_height (succ n) t → P (shr t))
include h₀ h₁
lemma with_height_add_left {k : α} {t₀ t₁}
(h : with_height n t₀)
(h' : with_height (succ n) t₁) :
P (add_left ret shr t₀ k t₁) :=
begin
cases h'; dsimp [add_left],
{ apply h₁, repeat { assumption <|> constructor}, },
{ apply h₀, repeat { assumption <|> constructor}, },
end
lemma with_height_add_right {k : α} {t₀ t₁}
(h : with_height (succ n) t₀)
(h' : with_height n t₁) :
P (add_right ret shr t₀ k t₁) :=
begin
cases h; dsimp [add_right],
{ apply h₁, repeat { assumption <|> constructor}, },
{ apply h₀, repeat { assumption <|> constructor}, },
end
omit h₁
lemma with_height_add_left_left {k k' : α} {t₀ t₁ t₂}
(hh₀ : with_height n t₀)
(hh₁ : with_height (succ n) t₁)
(hh₂ : with_height (succ n) t₂) :
P (add_left_left ret t₀ k t₁ k' t₂) :=
begin
cases hh₁; clear hh₁; dsimp; apply h₀,
repeat { assumption <|> constructor },
end
lemma with_height_add_middle {k k' : α} {t₀ t₁ t₂}
(hh₀ : with_height (succ n) t₀)
(hh₁ : with_height n t₁)
(hh₂ : with_height (succ n) t₂) :
P (add_middle ret t₀ k t₁ k' t₂) :=
begin
cases hh₀; clear hh₀; dsimp; apply h₀,
repeat { assumption <|> constructor },
end
lemma with_height_add_right_right {k k' : α} {t₀ t₁ t₂}
(hh₀ : with_height (succ n) t₀)
(hh₁ : with_height (succ n) t₁)
(hh₂ : with_height n t₂) :
P (add_right_right ret t₀ k t₁ k' t₂) :=
begin
cases hh₁; clear hh₁; dsimp; apply h₀,
repeat { assumption <|> constructor },
end
end with_height_add_left
section with_height_delete
variables (n : ℕ) (P : γ → Prop)
(ret shr : option α → tree α β → γ)
(del : unit → γ)
(h₀ : ∀ a t, with_height n t → P (ret a t))
(h₁ : ∀ a t n', succ n' = n → with_height n' t → P (shr a t))
(h₂ : ∀ u, n = 0 → P (del u))
include h₀ h₁ h₂
lemma with_height_delete_aux {k : α} {t}
(h : with_height n t) :
P (delete' k t ret shr del) :=
begin
induction h generalizing ret shr del,
case two_three.with_height.leaf : k' v'
{ dsimp [delete'],
split_ifs,
all_goals
{ subst_vars, apply h₂ <|> apply h₀ <|> apply h₁, repeat { constructor }, }, },
case two_three.with_height.node2 : n h_x h_t₀ h_t₁ h_a h_a_1 h_ih₀ h_ih₁
{ dsimp [delete'], split_ifs,
repeat { intro <|> apply h_ih₀ <|> apply h_ih₁ <|>
apply h₀ <|> apply h₁ <|> apply with_height_add_left <|>
apply with_height_add_right <|> assumption <|> constructor, try { subst_vars } } },
case two_three.with_height.node3 : h_n h_x h_y h_t₀ h_t₁ h_t₂ h_a h_a_1 h_a_2 h_ih₀ h_ih₁ h_ih₂
{ dsimp [delete'], split_ifs,
repeat { intro <|> apply h_ih₀ <|> apply h_ih₁ <|> apply h_ih₂ },
all_goals
{ repeat { intro <|> apply h₀ <|> apply h₁ <|> apply h₂ <|>
apply with_height_add_left <|>
apply with_height_add_right <|>
apply with_height_add_left_left <|>
apply with_height_add_middle <|>
apply with_height_add_right_right, },
repeat
{ subst_vars,
assumption <|> constructor } }, },
end
end with_height_delete
lemma with_height_delete {n} {k : α} {t : tree α β}
(h : with_height n t) :
option.elim (delete k t) false (with_height n) ∨ option.elim (delete k t) (n = 0) (with_height n.pred) :=
with_height_delete_aux n (λ x : option (tree α β), option.elim x false (with_height n) ∨ option.elim x (n = 0) (with_height n.pred))
(λ _, some) (λ _, some) _
(by { dsimp, tauto })
(by { dsimp, intros, subst n, tauto })
(by { dsimp, tauto })
h
section sorted_add_left
variables (P : γ → Prop)
(lb ub : option α)
(ret shr : tree α β → γ)
variables
(h₀ : ∀ t, below lb (first t) → above (last t) ub → sorted' t → P (ret t))
(h₁ : ∀ t, below lb (first t) → above (last t) ub → sorted' t → P (shr t))
include h₀ h₁
lemma sorted_add_left {k : α} {t₀ t₁}
(hhₐ : below lb (first t₀))
(hh₀ : sorted' t₀)
(hh₁ : last t₀ < k)
(hh₂ : k = first t₁)
(hh₃ : sorted' t₁)
(hh₄ : above (last t₁) ub) :
P (add_left ret shr t₀ k t₁) :=
begin
cases hh₃; clear hh₃; dsimp [add_left],
all_goals
{ apply h₁ <|> apply h₀, clear h₀ h₁,
repeat { assumption <|> constructor } },
dsimp at *, subst_vars,
cases hh₄; constructor,
chain_trans
end
lemma sorted_add_right {k : α} {t₀ t₁}
(hhₐ : below lb (first t₀))
(hh₀ : sorted' t₀)
(hh₁ : last t₀ < k)
(hh₂ : k = first t₁)
(hh₃ : sorted' t₁)
(hh₄ : above (last t₁) ub) :
P (add_right ret shr t₀ k t₁) :=
begin
cases hh₀; clear hh₀; dsimp [add_left],
all_goals
{ apply h₁ <|> apply h₀, clear h₀ h₁,
repeat { assumption <|> constructor } },
dsimp at *, subst_vars,
cases hh₄; constructor,
have := first_le_last_of_sorted hh₃,
chain_trans
end
omit h₁
lemma sorted_add_left_left {k k' : α} {t₀ t₁ t₂}
(hhₐ : below lb (first t₀))
(hh₀ : sorted' t₀)
(hh₁ : last t₀ < k)
(hh₂ : k = first t₁)
(hh₃ : sorted' t₁)
(hh₄ : last t₁ < k')
(hh₅ : k' = first t₂)
(hh₆ : sorted' t₂)
(hh₇ : above (last t₂) ub) :
P (add_left_left ret t₀ k t₁ k' t₂) :=
begin
cases hh₃; clear hh₃; dsimp at *,
all_goals
{ saturate,
subst_vars, apply h₀,
repeat { assumption <|> constructor <|> above }, },
end
lemma sorted_add_middle {k k' : α} {t₀ t₁ t₂}
(hhₐ : below lb (first t₀))
(hh₀ : sorted' t₀)
(hh₁ : last t₀ < k)
(hh₂ : k = first t₁)
(hh₃ : sorted' t₁)
(hh₄ : last t₁ < k')
(hh₅ : k' = first t₂)
(hh₆ : sorted' t₂)
(hh₇ : above (last t₂) ub) :
P (add_middle ret t₀ k t₁ k' t₂) :=
begin
cases hh₀; clear hh₀; dsimp; apply h₀; clear h₀,
repeat { assumption <|> constructor <|> above },
end
lemma sorted_add_right_right {k k' : α} {t₀ t₁ t₂}
(hhₐ : below lb (first t₀))
(hh₀ : sorted' t₀)
(hh₁ : last t₀ < k)
(hh₂ : k = first t₁)
(hh₃ : sorted' t₁)
(hh₄ : last t₁ < k')
(hh₅ : k' = first t₂)
(hh₆ : sorted' t₂)
(hh₇ : above (last t₂) ub) :
P (add_right_right ret t₀ k t₁ k' t₂) :=
begin
cases hh₃; clear hh₃; dsimp at *; apply h₀; clear h₀,
repeat { assumption <|> constructor <|> above },
end
end sorted_add_left
section sorted_delete
variables
(lb ub : option α)
(P : γ → Prop)
(ret shr : option α → tree α β → γ)
(del : unit → γ)
-- (h₀ : ∀ a t, sorted' t → P (ret a t))
-- (h₁ : ∀ a t, sorted' t → P (shr a t))
-- (h₀ : ∀ a t, below lb (first t) → below a (first t) → above (last t) ub → sorted' t → P (ret a t))
-- (h₁ : ∀ a t, below lb (first t) → below a (first t) → above (last t) ub → sorted' t → P (shr a t))
(h₀ : ∀ a t, below lb (first t) → above (last t) ub → sorted' t → P (ret a t))
(h₁ : ∀ a t, below lb (first t) → above (last t) ub → sorted' t → P (shr a t))
(h₂ : ∀ u, P (del u))
include h₀ h₁ h₂
lemma sorted_delete_aux {k : α} {t}
(hh₀ : below lb (first t))
(hh₁ : sorted' t)
(hh₂ : above (last t) ub) :
P (delete' k t ret shr del) :=
begin
induction hh₁ generalizing lb ub ret shr del,
case two_three.sorted'.leaf : k' v'
{ dsimp [delete'],
split_ifs,
all_goals
{ subst_vars, apply h₂ <|> apply h₀ <|> apply h₁,
repeat { assumption <|> constructor <|> dsimp at * }, }, },
case two_three.sorted'.node2 : n h_x h_t₀ h_t₁ hh₀ hh₁ hh₂ h_ih₀ h_ih₁
{ dsimp [delete'],
find_all_hyps hh := sorted' _ then { have h := first_le_last_of_sorted hh },
split_ifs,
all_goals {
try {
repeat
{ repeat { intro h, try { have := first_le_last_of_sorted h } },
apply h_ih₀ lb (some n) <|> apply h_ih₁ (some n) ub <|>
casesm [above _ (some _)] <|>
apply h₀ <|> apply h₁ <|> apply h₂ <|>
apply sorted_add_left <|>
apply sorted_add_right <|>
apply sorted_add_left_left <|>
apply sorted_add_middle <|>
apply sorted_add_right_right <|>
assumption <|> constructor,
try { subst_vars } },
done }
},
{ apply h_ih₀ lb (some n); clear h_ih₀ h_ih₁,
{ intros, casesm* [above _ (some _)],
apply h₀,
repeat { assumption <|> constructor } },
{ intros, apply sorted_add_left,
intros, apply h₀,
repeat { assumption <|> constructor },
all_goals
{ casesm* [above _ (some _)],
repeat { intro <|> apply h₀ <|> apply h₁ <|> apply h₂ <|>
apply with_height_add_left <|>
apply with_height_add_right <|>
apply with_height_add_left_left <|>
apply with_height_add_middle <|>
apply with_height_add_right_right, } },
repeat
{ subst_vars,
intro <|> assumption <|> constructor } },
admit,
admit,
admit,
},
admit
},
admit,
-- case two_three.sorted'.node3 : h_n h_x h_y h_t₀ h_t₁ h_t₂ h_a h_a_1 h_a_2 h_ih₀ h_ih₁ h_ih₂
-- { dsimp [delete'], split_ifs,
-- repeat { intro <|> apply h_ih₀ <|> apply h_ih₁ <|> apply h_ih₂ },
-- all_goals
-- { repeat { intro <|> apply h₀ <|> apply h₁ <|> apply h₂ <|>
-- apply with_height_add_left <|>
-- apply with_height_add_right <|>
-- apply with_height_add_left_left <|>
-- apply with_height_add_middle <|>
-- apply with_height_add_right_right, },
-- repeat
-- { subst_vars,
-- assumption <|> constructor } }, },
end
end sorted_delete
end two_three
|
\subsection{External Interface Requirements}
\subsubsection{User interfaces}
In the design document there will be the specific application UI created after the process (UX) of defining how users interact with SafeStreets.
The following mocks describe only the generic application screen design:
\begin{figure}[H]
\centering
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=\textwidth]{Images/rasd-mocks/login.png}
\caption{Login form}
\end{minipage}
\hfill
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=\textwidth]{Images/rasd-mocks/registration.png}
\caption{Registration form}
\end{minipage}
\end{figure}
\newpage
\begin{figure}[H]
\centering
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=\textwidth]{Images/rasd-mocks/report.png}
\caption{User send violation report}
\end{minipage}
\hfill
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=\textwidth]{Images/rasd-mocks/violationsMap.png}
\caption{Map showing violations}
\end{minipage}
\end{figure}
\begin{figure}[H]
\centering
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=\textwidth]{Images/rasd-mocks/interventions.png}
\caption{Suggestion for possible interventions}
\end{minipage}
\hfill
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=\textwidth]{Images/rasd-mocks/vehicle.png}
\caption{Violations by vehicle}
\end{minipage}
\end{figure}
\newpage
\subsubsection{Hardware interfaces}
There are no hardware interfaces.
\subsubsection{Software interfaces}
The system functionalities are provided with the usage of some external web services:
\paragraph{Google Maps}
Google Maps library is used in the page that shows the map.
Furthermore, Google Maps APIs are used to transform addresses in coordinates and vice versa.
\paragraph{Vehicle model identification}
Using an external web service, SafeStreets is able to retrieve information about the vehicles from the license plate number.
This data will be show in statistics about violations by vehicles.
\paragraph{IndicePA}
The \textit{CUU (Codice Univoco Ufficio)} verification is made by an external web service provided by \textit{IndicePA}. The code is required during the authorities registration to ensure their identity.
The external API are exposed only for authorities application and the implementation details will be shown in the design document (DD).
\subsubsection{Communication interfaces}
Any communication functionality takes place via internet with HTTPS to allow protection and privacy.
This protocol will be used for both access to the web-application and REST communication.
\newpage
\subsection{Design constraints}
\subsubsection{Standards compliance}
Part of the information collected by SafeStreets (e.g. license plate) are sensitive. For this reason the project is subject to the \textit{General Data Protection Regulation (GDPR)}.
One of the technique used by the system to protect these important information is the creation of different type of users.
For example normal account can only send information and see general information.
While authorities have a different account that is able to access to the collected and generated data in details.
\subsubsection{Hardware limitations}
The application is based on retrieving data from the pictures sent by the user.
Obviously the camera of the devices is a crucial aspect to consider during the design process. For this reason a minimum resolution of the sensor is required to install the application.
The identification of this value will be done during design phase and will be written in the design document (DD).
An other constraint is generated by the precision of the GPS sensor of the device, since the impact is smaller than the image resolution, the requirement is not so strict.
\subsubsection{Any other constraint}
SafeStreets works with violations and traffic tickets so it has to deal with laws and regulations; for this aspect see the specific domain assumption.
Furthermore we have to consider the possible improper use of the platform. To prevent it, SafeStreets does specific controls on images and it is able to detect manipulations or repeated pictures of the same violations.
The implementation of this part will be done with some external algorithm and will be detailed in the design document (DD).
\newpage
\subsection{Functional requirements}
\subsubsection{Definition of use case diagram}
The use case diagrams provide a vision of the uses that can be done with the platform.
They show the relationship between the actors and the use that every actor made with the software to reach the goals.
\subsubsection{Scenario 1}
Paul wants to sign up to SafeStreets platform. He has to insert his personal data (name, surname, place, mail and so forth). Then he will receive a confirm mail and can use the platform.
\subsubsection{Scenario 2}
Bob is coming back to his car when he notice that someone double parked and he can’t go out from the parking.
He logs in into the SafeStreets and he takes a picture of the car. Then he has to insert the information about the violation: type of violation and route where the violation happened. Once Bob has added the data he can send the report.
\subsubsection{Scenario 3}
Luke is walking on the sidewalk when he see that a man is parking on a park reserved for disable.
Luke logs in into the SafeStreets and he takes a picture of the car. Then he has to insert the information about the violation: type of violation and route where the violation happened. Once Luke has added the data he can send the report.
\subsubsection{Scenario 4}
Mark has submitted a report to the platform, and he wants to check if it has been accepted or declined.
He logs in into the app, he goes to his reserved area and next to his report there is the status of message sent.
\subsubsection{Scenario 5}
An accidents in via Anzani occurs, the municipality system records the information about it.
SafeStreets is able to retrieve a portion of these data and cross it with violations information, in order to generate statistics.
\subsubsection{Scenario 6}
The local authority wants to check which are the streets with more violations. They log in into the platform and access to their personal area where they can check the streets status.
\subsubsection{Scenario 7}
The local authority wants to check which are the vehicles with more violations. They log in into the platform and access to their personal area where they can check the cars that have the most reports assigned.
\subsubsection{Scenario 8}
The system receives pictures from the users and have to check if they are reliable. It runs an algorithm that can detect if the photo is real or it has been manipulated. In the first case, the report will be stored and be used by authorities. In the second case the report will be discarded.
\subsection{Description of use case scenarios}
\subsubsection{Description scenario 1}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & Visitors \\
\hline
GOALS & Sign up \\
\hline
INPUT CONDITION & Personal data (name, surname, mail, telephone number, place where he lives, car license plate etc.) \\
\hline
EVENTS FLOW & The user from the home page clicks on sign up. He inserts all of his information and if it is all correct he will recive an email of confirm. \\
\hline
OUTPUT CONDITION & The user can now log in and use all the function that the user can do on the platform. \\
\hline
EXCEPTIONS & Data incorrect, user already exists, mail already exists. All of this exceptions will be notified instantly to the user. \\
\hline
\end{tabular}
\end{center}
\subsubsection{Description scenario 2}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & User \\
\hline
GOALS & Report a violation \\
\hline
INPUT CONDITION & Type of violation (double row park), name of the street, \\
\hline
EVENTS FLOW & The user take a picture of the car that has done the violation. He insert the type of violation and the route where it happened. The system use an algorithm to read the car license plate and then store all the informations once it is established that the photo isn't fake. \\
\hline
OUTPUT CONDITION & The violation has been stored with all the data, it will be generated a traffic ticket, and the local authority can decide to highlight who has made the violation or the street. \\
\hline
EXCEPTIONS & Data incorrect or fake photo. The report will be discarded and no traffic ticket will be generated. \\
\hline
\end{tabular}
\end{center}
\newpage
\subsubsection{Description scenario 3}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & User \\
\hline
GOALS & Report a violation \\
\hline
INPUT CONDITION & Type of violation (wrong park), name of the street, \\
\hline
EVENTS FLOW & The user take a picture of the car that has done the violation. He insert the type of violation and the route where it happened. The system use an algorithm to read the car license plate and then store all the informations once it is established that the photo isn't fake. \\
\hline
OUTPUT CONDITION & The violation has been stored with all the data, it will be generated a traffic ticket, and the local authority can decide to highlight who has made the violation or the street. \\
\hline
EXCEPTIONS & Data incorrect or fake photo. The report will be discarded and no traffic ticket will be generated. \\
\hline
\end{tabular}
\end{center}
\subsubsection{Description scenario 4}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & User \\
\hline
GOALS & Check report status \\
\hline
INPUT CONDITION & User credentials \\
\hline
EVENTS FLOW & The user log in into the platform. He accesses to his personal area and he can check the status of his report \\
\hline
OUTPUT CONDITION & Report status \\
\hline
EXCEPTIONS & The user hasn't made any report. The system show a messagge that the list of the reports is empty. \\
\hline
\end{tabular}
\end{center}
\subsubsection{Description scenario 5}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & Authority, SafeStreets \\
\hline
GOALS & Generate statistics \\
\hline
INPUT CONDITION & The authority inserts data about an accident. \\
\hline
EVENTS FLOW & The authority add the data about an accident in their system. SafeStreets retrieve these data generate statistic for the authority. \\
\hline
OUTPUT CONDITION & Accident and violation statistics\\
\hline
EXCEPTIONS & There are no exceptions \\
\hline
\end{tabular}
\end{center}
\subsubsection{Description scenario 6}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & Authority \\
\hline
GOALS & Check streets status \\
\hline
INPUT CONDITION & Local authority credentials \\
\hline
EVENTS FLOW & The authority log in into the platform. He accesses to his personal area and he can check the streets status \\
\hline
OUTPUT CONDITION & Different colors for the streets based on their status and possibly changes to the color of some streets \\
\hline
EXCEPTIONS & none \\
\hline
\end{tabular}
\end{center}
\subsubsection{Description scenario 7}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & Authority \\
\hline
GOALS & Check cars status \\
\hline
INPUT CONDITION & Local authority credentials \\
\hline
EVENTS FLOW & The authority log in into the platform. He accesses to his personal area and he can check the cars status based on reports \\
\hline
OUTPUT CONDITION & Different colors for the cars based on how many reports they recived and possibly changes to the color of some cars \\
\hline
EXCEPTIONS & none \\
\hline
\end{tabular}
\end{center}
\subsubsection{Description scenario 8}
\begin{center}
\begin{tabular}{ | l | p{6cm} | }
\hline
ACTORS & SafeStreets \\
\hline
GOALS & Check the reliability of the photo \\
\hline
INPUT CONDITION & Photo that has been taken by a user. \\
\hline
EVENTS FLOW & The system recives from the user a photo of a possibile violation. It runs an algorithm that can establish if it is real or fake. \\
\hline
OUTPUT CONDITION & The photo is real of fake. \\
\hline
EXCEPTIONS & none \\
\hline
\end{tabular}
\end{center}
\newpage
\subsection{Activity diagram}
\subsubsection{Scenario 1}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=12cm,height=17cm]{Images/ActivityRASD/Scenario1.png}
\caption{Scenario 1}
\end{minipage}
\end{figure}
\newpage
\subsubsection{Scenario 3}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=12cm,height=17cm]{Images/ActivityRASD/Scenario3.png}
\caption{Scenario 3}
\end{minipage}
\end{figure}
\newpage
\subsubsection{Scenario 4}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=12cm,height=17cm]{Images/ActivityRASD/Scenario4.png}
\caption{Scenario 4}
\end{minipage}
\end{figure}
\newpage
\subsubsection{Scenario 7}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=12cm,height=16.5cm]{Images/ActivityRASD/Scenario7.png}
\caption{Scenario 7}
\end{minipage}
\end{figure}
\newpage
\subsubsection{Scenario 8}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=14cm,height=17cm]{Images/ActivityRASD/Scenario8.png}
\caption{Scenario 8}
\end{minipage}
\end{figure}
\newpage
\subsection{Sequence diagram}
\subsubsection{Scenario 2}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=18cm,height=15cm]{Images/SequenceRASD/Scenario2.png}
\caption{Scenario 2}
\end{minipage}
\end{figure}
\newpage
\subsubsection{Scenario 5}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=15cm,height=10cm]{Images/SequenceRASD/Scenario5.png}
\caption{Scenario 5}
\end{minipage}
\end{figure}
\newpage
\subsubsection{Scenario 6}
\begin{figure}[H]
\begin{minipage}[b]{0.40\textwidth}
\includegraphics[width=15cm,height=10cm]{Images/SequenceRASD/Scenario6.png}
\caption{Scenario 6}
\end{minipage}
\end{figure}
\subsection{Software system attributes}
\subsubsection{Reliability}
The system has to ensure reliability, for this reason we have decided to keep a backup server, updated everyday.
Consistency is guaranteed by the algorithm we have already described.
Furthermore SafeStreets guarantees reliability in terms of plate recognition because the results are compared with the information coming from users.
\subsubsection{Availability}
The platform has to be available every day, especially in the rush hours because are the ones where there traffic is higher.
SafeStreets must have an availability of 99\% (3.65 days/year downtime).
\subsubsection{Security}
The data have to be encrypted, to grant the privacy (e.g. user's position, car license plate and so forth).
For this reason is used HTTPS protocol to transmit data from user to SafeStreets.
Every account must have a strong password with the combination of upper-case, lower-case letters and numbers.
\paragraph{Chain of custody}
\hfill
The system have to guarantee the chain of custody, thus SafeStreets needs to ensure that the data received from the users are genuine.
In order to implement this feature the system checks the authenticity of the pictures recived before creating and storing new reports.
In this way we have the certainty that the data stored are reliable and all the other portions of the system can work without deal with this aspect (for them it is trasparent).
\subsubsection{Maintainability}
The system is developed to be compatible with other platform, like the system of the local authority.
There could be maintenance interventions, when it's possible there will be in the hours with the less use of the platform (e.g. midnight).
There will be released updates, both for web-application and system.
\subsubsection{Portability}
The entire system is portable, every user (citizen or local authority) can access to their profile, see data, statistics and make reports of violation from their mobile, their tablet or PCs.
\subsection{Mapping on requirements}
\begin{center}
\begin{tabular}{ | l | p{2cm} | p{2cm}| p{2cm}|}
\hline
RawID & GoalID & ReqID & Use Case ID \\
\hline
1&G1&RE.1&Scenario 2/3\\
\hline
2&G2.1&RE.2&\\
\hline
3&G2&RE.3&\\
\hline
4&G3.1&RE.4&Scenario 6\\
\hline
5&G3&RE.5&\\
\hline
6&G4&RE.6&\\
\hline
7&G5&RE.7&Scenario 8\\
\hline
8&G2&RE.8&\\
\hline
\end{tabular}
\end{center}
|
%================ch3======================================
\chapter{Genomic Data Analysis Methods}\label{ch:ch5}
\section{Steps of Genomic Data Analysis}
Regardless of the analysis type, the data analysis has a common pattern. I will discuss this general pattern and how it applies to genomics problems. The data analysis steps typically include data collection, quality check and cleaning, processing, modeling, visualization and reporting. Although, one expects to go through these steps in a linear fashion, it is normal to go back and repeat the steps with different parameters or tools. In practice, data analysis requires going through the same steps over and over again in order to be able to do a combination of the following:
\begin{itemize}
\item answering other related questions,
\item dealing with data quality issues that are later realized, and,) including new data sets to the analysis.
\end{itemize}
We will now go through a brief explanation of the steps within the context of genomic data analysis\cite{seq2018}.
\subsection{Data collection}
Data collection refers to any source, experiment or survey that provides data for the data analysis question you have. In genomics, data collection is done by high-throughput assays. One can also use publicly available data sets and specialized databases. How much data and what type of data you should collect depends on the question you are trying to answer and the technical and biological variability of the system you are studying.
\subsection{Data quality check and cleaning}
In general, data analysis almost always deals with imperfect data. It is common to have missing values or measurements that are noisy. Data quality check and cleaning aims to identify any data quality issue and clean it from the dataset.
High-throughput genomics data is produced by technologies that could embed technical biases into the data. If we were to give an example from sequencing, the sequenced reads do not have the same quality of bases called. Towards the ends of the reads, you could have bases that might be called incorrectly. Identifying those low quality bases and removing them will improve read mapping step.
\subsection{Data processing}
This step refers to processing the data to a format that is suitable for exploratory analysis and modeling. Often times, the data will not come in ready to analyze format. You may need to convert it to other formats by transforming data points (such as log transforming, normalizing etc), or subset the data set with some arbitrary or pre-defined condition. In terms of genomics, processing includes multiple steps. Following the sequencing analysis example above, processing will include aligning reads to the genome and quantification over genes or regions of interest. This is simply counting how many reads are covering your regions of interest. This quantity can give you ideas about how much a gene is expressed if your experimental protocol was RNA sequencing. This can be followed by some normalization to aid the next step.
\subsection{Exploratory data analysis and modeling}
This phase usually takes in the processed or semi-processed data and applies machine-learning or statistical methods to explore the data. Typically, one needs to see relationship between variables measured, relationship between samples based on the variables measured. At this point, we might be looking to see if the samples group as expected by the experimental design, are there outliers or any other anomalies ? After this step you might want to do additional clean up or re-processing to deal with anomalies.
Another related step is modeling. This generally refers to modeling your variable of interest based on other variables you measured. In the context of genomics, it could be that you are trying to predict disease status of the patients from expression of genes you measured from their tissue samples. Then your variable of interest is the disease status and . This is generally called predictive modeling and could be solved with regression based or any other machine-learning methods. This kind of approach is generally called “predictive modeling
Statistical modeling would also be a part of this modeling step, this can cover predictive modeling as well where we use statistical methods such as linear regression. Other analyses such as hypothesis testing, where we have an expectation and we are trying to confirm that expectation is also related to statistical modeling. A good example of this in genomics is the differential gene expression analysis. This can be formulated as comparing two data sets, in this case expression values from condition A and condition B, with the expectation that condition A and condition B has similar expression values\cite{edwards2013beginner}.
\subsection{Visualization and reporting}
Visualization is necessary for all the previous steps more or less. But in the final phase, we need final figures, tables and text that describes the outcome of your analysis. This will be your report. In genomics, we use common data visualization methods as well as specific visualization methods developed or popularized by genomic data analysis.
|
lemma locally_path_connected_UNIV: "locally path_connected (UNIV::'a :: real_normed_vector set)" |
a=array(c(1,5,8,7))
a
a1=array(1:15,dim=c(3,4,3))
a1
v1<-c(1,5,7,45,78,98)
v2<-c(10,12,15,18,16,11)
(a2<-array(c(v1,v2),dim=c(3,3,4),
dimnames=list(c("R1","R2","R3"),
c("C1","C2","C3"),
c("M1","M2","M3","M4"))))
#access element
a1
a1[c(1,3),1:2,2]
a1[,,3]
a1[1:2,,]
a1[c(1,3),1:2,c(1,3)]
#create 2 vector of diff length\
v3<-c(10,20,40)
v4<-c(4,-5,6,7,10,12,10,-2,1)
(a3<-array(c(v3,v4),dim=c(3,3,2))) |
digest("The quick brown fox jumps over the lazy dog","crc32", serialize=F)
|
Require Export Fiat.Common.Coq__8_4__8_5__Compat.
Require Import Coq.Strings.String Coq.ZArith.ZArith Coq.Lists.List
Coq.Logic.FunctionalExtensionality Coq.Sets.Ensembles
Fiat.Computation
Fiat.Computation.Refinements.Iterate_Decide_Comp
Fiat.ADT
Fiat.ADTRefinement
Fiat.ADTNotation
Fiat.QueryStructure.Specification.Representation.QueryStructureSchema
Fiat.ADTRefinement.BuildADTRefinements
Fiat.QueryStructure.Specification.Representation.QueryStructure
Fiat.Common.Ensembles.IndexedEnsembles
Fiat.Common.IterateBoundedIndex
Fiat.QueryStructure.Specification.Operations.Query
Fiat.QueryStructure.Specification.Operations.Insert
Fiat.QueryStructure.Implementation.Constraints.ConstraintChecksRefinements.
(* Facts about implements insert operations. *)
Section InsertRefinements.
Hint Resolve crossConstr.
Hint Unfold SatisfiesCrossRelationConstraints
SatisfiesTupleConstraints
SatisfiesAttributeConstraints.
Arguments GetUnConstrRelation : simpl never.
Arguments UpdateUnConstrRelation : simpl never.
Arguments replace_BoundedIndex : simpl never.
Arguments BuildQueryStructureConstraints : simpl never.
Arguments BuildQueryStructureConstraints' : simpl never.
Program
Definition Insert_Valid
(qsSchema : QueryStructureSchema)
(qs : QueryStructure qsSchema)
(Ridx : _)
(tup : _ )
(schConstr : forall tup',
GetRelation qs Ridx tup' ->
SatisfiesTupleConstraints Ridx (indexedElement tup) (indexedElement tup'))
(schConstr' : forall tup',
GetRelation qs Ridx tup' ->
SatisfiesTupleConstraints Ridx (indexedElement tup') (indexedElement tup))
(schConstr_self :
@SatisfiesAttributeConstraints qsSchema Ridx (indexedElement tup))
(qsConstr : forall Ridx',
SatisfiesCrossRelationConstraints Ridx Ridx' (indexedElement tup) (GetRelation qs Ridx'))
(qsConstr' : forall Ridx',
Ridx' <> Ridx ->
forall tup',
GetRelation qs Ridx' tup'
-> SatisfiesCrossRelationConstraints
Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetRelation qs Ridx)))
: QueryStructure qsSchema :=
{| rawRels :=
UpdateRelation (rawRels qs) Ridx {| rawRel := EnsembleInsert tup (GetRelation qs Ridx)|}
|}.
Next Obligation.
unfold GetRelation.
unfold SatisfiesAttributeConstraints, QSGetNRelSchema, GetNRelSchema,
GetRelation in *.
set ((ilist2.ith2 (rawRels qs) Ridx)) as X in *; destruct X; simpl in *.
destruct (attrConstraints
(Vector.nth (Vector.map schemaRaw (QSschemaSchemas qsSchema)) Ridx));
eauto;
unfold EnsembleInsert in *; simpl in *; intuition; subst; eauto.
Defined.
Next Obligation.
unfold GetRelation.
unfold SatisfiesTupleConstraints, QSGetNRelSchema, GetNRelSchema,
GetRelation in *.
set ((ilist2.ith2 (rawRels qs) Ridx )) as X in *; destruct X; simpl in *.
destruct (tupleConstraints
(Vector.nth (Vector.map schemaRaw (QSschemaSchemas qsSchema)) Ridx));
eauto.
unfold EnsembleInsert in *; simpl in *; intuition; subst; eauto.
congruence.
Qed.
Next Obligation.
caseEq (BuildQueryStructureConstraints qsSchema idx idx'); eauto.
unfold SatisfiesCrossRelationConstraints, UpdateRelation in *;
destruct (fin_eq_dec Ridx idx'); subst.
- rewrite ilist2.ith_replace2_Index_eq; simpl.
rewrite ilist2.ith_replace2_Index_neq in H1; eauto using string_dec.
generalize (qsConstr' idx H0 _ H1); rewrite H; eauto.
- rewrite ilist2.ith_replace2_Index_neq; eauto using string_dec.
destruct (fin_eq_dec Ridx idx); subst.
+ rewrite ilist2.ith_replace2_Index_eq in H1; simpl in *; eauto.
unfold EnsembleInsert in H1; destruct H1; subst; eauto.
* generalize (qsConstr idx'); rewrite H; eauto.
* pose proof (crossConstr qs idx idx') as X; rewrite H in X; eauto.
+ rewrite ilist2.ith_replace2_Index_neq in H1; eauto using string_dec.
pose proof (crossConstr qs idx idx') as X; rewrite H in X; eauto.
Qed.
Lemma QSInsertSpec_refine' :
forall qsSchema (qs : QueryStructure qsSchema) Ridx tup default,
refine
(Pick (QSInsertSpec qs Ridx tup))
(schConstr_self <-
{b |
decides b
(SatisfiesAttributeConstraints Ridx (indexedElement tup))};
schConstr <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup) (indexedElement tup'))};
schConstr' <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') (indexedElement tup))};
qsConstr <- {b | decides b
(forall Ridx', SatisfiesCrossRelationConstraints Ridx Ridx' (indexedElement tup) (GetRelation qs Ridx'))};
qsConstr' <- {b | decides
b
(forall Ridx',
Ridx' <> Ridx ->
forall tup',
(GetRelation qs Ridx') tup'
-> SatisfiesCrossRelationConstraints
Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetRelation qs Ridx)))};
match schConstr_self, schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true, true =>
{qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert tup (GetRelation qs Ridx) t)
}
| _, _ , _, _, _ => default
end).
Proof.
intros qsSchema qs Ridx tup default v Comp_v;
computes_to_inv;
destruct v0;
[ destruct v1;
[ destruct v2;
[ destruct v3;
[ destruct v4;
[ repeat (computes_to_inv; destruct_ex; split_and); simpl in *;
computes_to_econstructor; unfold QSInsertSpec; eauto |
]
| ]
| ]
| ]
| ];
cbv delta [decides] beta in *; simpl in *;
repeat (computes_to_inv; destruct_ex); eauto;
computes_to_econstructor; unfold QSInsertSpec; intros;
solve [exfalso; intuition].
Qed.
Lemma QSInsertSpec_refine :
forall qsSchema (qs : QueryStructure qsSchema) Ridx tup default,
refine
(Pick (QSInsertSpec qs Ridx tup))
(schConstr_self <- {b | decides b
(SatisfiesAttributeConstraints Ridx (indexedElement tup))};
schConstr <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup) (indexedElement tup'))};
schConstr' <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') (indexedElement tup))};
qsConstr <- (@Iterate_Decide_Comp _
(fun Ridx' =>
SatisfiesCrossRelationConstraints
Ridx Ridx' (indexedElement tup)
(GetRelation qs Ridx')));
qsConstr' <- (@Iterate_Decide_Comp _
(fun Ridx' =>
Ridx' <> Ridx
-> forall tup',
(GetRelation qs Ridx') tup'
-> SatisfiesCrossRelationConstraints
Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetRelation qs Ridx))));
match schConstr_self, schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true, true =>
{qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert tup (GetRelation qs Ridx) t)
}
| _, _, _, _, _ => default
end).
Proof.
intros.
rewrite QSInsertSpec_refine'; f_equiv.
unfold pointwise_relation; intros.
repeat (f_equiv; unfold pointwise_relation; intros).
setoid_rewrite Iterate_Decide_Comp_BoundedIndex; f_equiv; eauto.
setoid_rewrite Iterate_Decide_Comp_BoundedIndex; f_equiv; eauto.
Qed.
Lemma freshIdx_UnConstrFreshIdx_Equiv
: forall qsSchema (qs : QueryStructure qsSchema) Ridx,
refine {x : nat | freshIdx qs Ridx x}
{idx : nat | UnConstrFreshIdx (GetRelation qs Ridx) idx}.
Proof.
unfold freshIdx, UnConstrFreshIdx, refine; intros.
computes_to_inv.
computes_to_econstructor; intros.
apply H in H0.
unfold RawTupleIndex; intro; subst.
destruct tup; omega.
Qed.
Lemma refine_SuccessfulInsert :
forall qsSchema (qs : QueryStructure qsSchema) Ridx tup b,
computes_to {idx | UnConstrFreshIdx (GetRelation qs Ridx) idx} b
-> refine
(b <- {result : bool |
decides result
(forall t : IndexedElement,
GetRelation qs Ridx t <->
EnsembleInsert {| elementIndex := b; indexedElement := tup |}
(GetRelation qs Ridx) t)};
ret (qs, b)) (ret (qs, false)).
Proof.
intros; computes_to_inv.
unfold UnConstrFreshIdx in *.
refine pick val false; simpl.
- simplify with monad laws; reflexivity.
- intro.
unfold EnsembleInsert in H0.
assert (GetRelation qs Ridx {| elementIndex := b; indexedElement := tup |}).
eapply H0; intuition.
apply H in H1; simpl in *; intuition.
Qed.
Corollary refine_SuccessfulInsert_Bind ResultT:
forall qsSchema (qs : QueryStructure qsSchema) Ridx tup b (k : _ -> Comp ResultT),
computes_to {idx | UnConstrFreshIdx (GetRelation qs Ridx) idx} b
->
refine
(x2 <- {x : bool |
SuccessfulInsertSpec qs Ridx qs
{| elementIndex := b; indexedElement := tup |} x};
k (qs, x2)) (k (qs, false)).
Proof.
unfold SuccessfulInsertSpec; intros.
rewrite <- refineEquiv_bind_unit with (f := k).
rewrite <- refine_SuccessfulInsert by eauto.
rewrite refineEquiv_bind_bind.
setoid_rewrite refineEquiv_bind_unit; f_equiv.
Qed.
Lemma QSInsertSpec_refine_opt :
forall qsSchema (qs : QueryStructure qsSchema) Ridx tup,
refine
(QSInsert qs Ridx tup)
match (attrConstraints (GetNRelSchema (qschemaSchemas qsSchema) Ridx)),
(tupleConstraints (GetNRelSchema (qschemaSchemas qsSchema) Ridx)) with
Some aConstr, Some tConstr =>
idx <- {idx | UnConstrFreshIdx (GetRelation qs Ridx) idx} ;
(schConstr_self <- {b | decides b (aConstr tup) };
schConstr <- {b | decides b
(forall tup',
GetRelation qs Ridx tup'
-> tConstr tup (indexedElement tup'))};
schConstr' <- {b | decides b
(forall tup',
GetRelation qs Ridx tup'
-> tConstr (indexedElement tup') tup)};
qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
If (fin_eq_dec Ridx Ridx') Then
None
Else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetRelation qs Ridx))))
| None => None
end));
match schConstr_self, schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true, true =>
qs' <- {qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert {| elementIndex := idx;
indexedElement := tup |} (GetRelation qs Ridx) t)};
ret (qs', true)
| _, _, _, _, _ => ret (qs, false)
end)
| Some aConstr, None =>
idx <- {idx | UnConstrFreshIdx (GetRelation qs Ridx) idx} ;
(schConstr_self <- {b | decides b (aConstr tup) };
qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
If (fin_eq_dec Ridx Ridx') Then
None
Else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetRelation qs Ridx))))
| None => None
end));
match schConstr_self, qsConstr, qsConstr' with
| true, true, true =>
qs' <- {qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert {| elementIndex := idx;
indexedElement := tup |} (GetRelation qs Ridx) t)};
ret (qs', true)
| _, _, _ => ret (qs, false)
end)
| None, Some tConstr =>
idx <- {idx | UnConstrFreshIdx (GetRelation qs Ridx) idx} ;
(schConstr <- {b | decides b
(forall tup',
GetRelation qs Ridx tup'
-> tConstr tup (indexedElement tup'))};
schConstr' <- {b | decides b
(forall tup',
GetRelation qs Ridx tup'
-> tConstr (indexedElement tup') tup)};
qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
If (fin_eq_dec Ridx Ridx') Then
None
Else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetRelation qs Ridx))))
| None => None
end));
match schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true =>
qs' <- {qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert {| elementIndex := idx;
indexedElement := tup |} (GetRelation qs Ridx) t)};
ret (qs', true)
| _, _, _, _ => ret (qs, false)
end)
| None, None =>
idx <- {idx | UnConstrFreshIdx (GetRelation qs Ridx) idx} ;
(qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
If (fin_eq_dec Ridx Ridx') Then
None
Else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetRelation qs Ridx))))
| None => None
end));
match qsConstr, qsConstr' with
| true, true =>
qs' <- {qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert {| elementIndex := idx;
indexedElement := tup |} (GetRelation qs Ridx) t)};
ret (qs', true)
| _, _ => ret (qs, false)
end)
end.
Proof.
unfold QSInsert.
intros; simpl.
unfold If_Then_Else.
setoid_rewrite QSInsertSpec_refine with (default := ret qs).
simplify with monad laws.
setoid_rewrite refine_SatisfiesAttributeConstraints_self; simpl.
match goal with
|- context [attrConstraints ?R] => destruct (attrConstraints R)
end.
setoid_rewrite refine_SatisfiesTupleConstraints_Constr; simpl.
setoid_rewrite refine_SatisfiesTupleConstraints_Constr'; simpl.
match goal with
|- context [tupleConstraints ?R] => destruct (tupleConstraints R)
end.
setoid_rewrite refine_SatisfiesCrossConstraints_Constr; simpl.
rewrite freshIdx_UnConstrFreshIdx_Equiv.
repeat (eapply refine_under_bind; intros).
eapply refine_under_bind_both.
unfold SatisfiesCrossRelationConstraints; simpl.
setoid_rewrite refine_Iterate_Decide_Comp_equiv.
eapply refine_Iterate_Decide_Comp.
- simpl; intros; simpl in *.
destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
+ congruence.
+ destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
- simpl; intros.
intro; apply H4.
simpl in *; destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
+ destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
- intros.
repeat setoid_rewrite refine_If_Then_Else_Bind.
unfold If_Then_Else.
repeat find_if_inside; unfold SuccessfulInsertSpec;
try (simplify with monad laws; eapply refine_SuccessfulInsert; eauto).
+ apply refine_under_bind; intros.
refine pick val true; simpl.
simplify with monad laws; reflexivity.
intros; computes_to_inv; intuition;
eapply H7; eauto.
- simpl; simplify with monad laws.
setoid_rewrite refine_SatisfiesCrossConstraints_Constr; simpl.
rewrite freshIdx_UnConstrFreshIdx_Equiv.
repeat (eapply refine_under_bind; intros).
eapply refine_under_bind_both.
unfold SatisfiesCrossRelationConstraints; simpl.
setoid_rewrite refine_Iterate_Decide_Comp_equiv.
eapply refine_Iterate_Decide_Comp.
+ simpl; intros; simpl in *.
destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
* congruence.
* destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
+ simpl; intros.
intro; apply H2.
simpl in *; destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
* destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
+ intros.
repeat setoid_rewrite refine_If_Then_Else_Bind.
unfold If_Then_Else.
repeat find_if_inside; unfold SuccessfulInsertSpec;
try (simplify with monad laws; eapply refine_SuccessfulInsert; eauto).
* apply refine_under_bind; intros.
refine pick val true; simpl.
simplify with monad laws; reflexivity.
intros; computes_to_inv; intuition;
eapply H5; eauto.
- simplify with monad laws.
setoid_rewrite refine_SatisfiesTupleConstraints_Constr; simpl.
setoid_rewrite refine_SatisfiesTupleConstraints_Constr'; simpl.
match goal with
|- context [tupleConstraints ?R] => destruct (tupleConstraints R)
end.
setoid_rewrite refine_SatisfiesCrossConstraints_Constr; simpl.
rewrite freshIdx_UnConstrFreshIdx_Equiv.
repeat (eapply refine_under_bind; intros).
eapply refine_under_bind_both.
unfold SatisfiesCrossRelationConstraints; simpl.
setoid_rewrite refine_Iterate_Decide_Comp_equiv.
eapply refine_Iterate_Decide_Comp.
+ simpl; intros; simpl in *.
destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
* congruence.
* destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
+ simpl; intros.
intro; apply H3.
simpl in *; destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
* destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
+ intros.
repeat setoid_rewrite refine_If_Then_Else_Bind.
unfold If_Then_Else.
repeat find_if_inside; unfold SuccessfulInsertSpec;
try (simplify with monad laws; eapply refine_SuccessfulInsert; eauto).
* apply refine_under_bind; intros.
refine pick val true; simpl.
simplify with monad laws; reflexivity.
intros; computes_to_inv; intuition;
eapply H6; eauto.
+ simpl; simplify with monad laws.
setoid_rewrite refine_SatisfiesCrossConstraints_Constr; simpl.
rewrite freshIdx_UnConstrFreshIdx_Equiv.
repeat (eapply refine_under_bind; intros).
eapply refine_under_bind_both.
unfold SatisfiesCrossRelationConstraints; simpl.
setoid_rewrite refine_Iterate_Decide_Comp_equiv.
eapply refine_Iterate_Decide_Comp.
* simpl; intros; simpl in *.
destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
congruence.
destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
* simpl; intros.
intro; apply H1.
simpl in *; destruct (fin_eq_dec Ridx idx); simpl in *; substs; eauto.
destruct (BuildQueryStructureConstraints qsSchema idx Ridx); eauto.
* intros.
repeat setoid_rewrite refine_If_Then_Else_Bind.
unfold If_Then_Else.
repeat find_if_inside; unfold SuccessfulInsertSpec;
try (simplify with monad laws; eapply refine_SuccessfulInsert; eauto).
apply refine_under_bind; intros.
refine pick val true; simpl.
simplify with monad laws; reflexivity.
intros; computes_to_inv; intuition;
eapply H4; eauto.
Qed.
Lemma QSInsertSpec_UnConstr_refine' :
forall qsSchema
(qs : _ )
(Ridx : _)
(tup : _ )
(or : _ )
(NIntup : ~ GetUnConstrRelation qs Ridx tup),
@DropQSConstraints_AbsR qsSchema or qs ->
refine
(or' <- (qs' <- Pick (QSInsertSpec or Ridx tup);
b <- Pick (SuccessfulInsertSpec or Ridx qs' tup);
ret (qs', b));
nr' <- {nr' | DropQSConstraints_AbsR (fst or') nr'};
ret (nr', snd or'))
(schConstr_self <- {b | decides b (SatisfiesAttributeConstraints Ridx (indexedElement tup))};
schConstr <-
{b | decides b
(forall tup',
GetUnConstrRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup) (indexedElement tup'))};
schConstr' <-
{b |
decides
b
(forall tup',
GetUnConstrRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') (indexedElement tup))};
qsConstr <- (@Iterate_Decide_Comp _
(fun Ridx' =>
SatisfiesCrossRelationConstraints
Ridx Ridx' (indexedElement tup)
(GetUnConstrRelation qs Ridx')));
qsConstr' <- (@Iterate_Decide_Comp _
(fun Ridx' =>
Ridx' <> Ridx
-> forall tup',
(GetUnConstrRelation qs Ridx') tup'
-> SatisfiesCrossRelationConstraints
Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetUnConstrRelation qs Ridx))));
match schConstr_self, schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true, true =>
ret (UpdateUnConstrRelation qs Ridx (EnsembleInsert tup (GetUnConstrRelation qs Ridx)), true)
| _, _, _, _, _ => ret (qs, false)
end).
Proof.
intros.
setoid_rewrite refineEquiv_pick_eq'.
unfold DropQSConstraints_AbsR in *; intros; subst.
rewrite QSInsertSpec_refine with (default := ret or).
unfold refine; intros; subst.
computes_to_inv.
repeat rewrite GetRelDropConstraints in *.
(* These assert are gross. Need to eliminate them. *)
assert ((fun Ridx' =>
SatisfiesCrossRelationConstraints Ridx Ridx' (indexedElement tup)
(GetUnConstrRelation (DropQSConstraints or) Ridx')) =
(fun Ridx' =>
SatisfiesCrossRelationConstraints Ridx Ridx' (indexedElement tup)
(GetRelation or Ridx'))) as rewriteSat
by (apply functional_extensionality; intros; rewrite GetRelDropConstraints;
reflexivity); rewrite rewriteSat in H'''; clear rewriteSat.
assert ((fun Ridx' =>
Ridx' <> Ridx ->
forall tup',
GetUnConstrRelation (DropQSConstraints or) Ridx' tup' ->
SatisfiesCrossRelationConstraints Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetRelation or Ridx))) =
(fun Ridx' =>
Ridx' <> Ridx ->
forall tup',
GetRelation or Ridx' tup' ->
SatisfiesCrossRelationConstraints Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetRelation or Ridx))))
as rewriteSat
by (apply functional_extensionality; intros; rewrite GetRelDropConstraints;
reflexivity).
rewrite GetRelDropConstraints in H', H'', H''''.
setoid_rewrite rewriteSat in H''''; clear rewriteSat.
(* Resume not-terribleness *)
generalize (Iterate_Decide_Comp_BoundedIndex _ _ H''') as H3';
generalize (Iterate_Decide_Comp_BoundedIndex _ _ H'''') as H4'; intros.
revert H''' H''''.
computes_to_inv.
intros.
eapply BindComputes with (a := match v0 as x', v1 as x0', v2 as x1', v3 as x2', v4 as x3'
return decides x' _ ->
decides x0' _ ->
decides x1' _ ->
decides x2' _ ->
decides x3' _ -> _
with
| true, true, true, true, true =>
fun H H0 H1 H2 H3 => (@Insert_Valid _ or Ridx tup H0 H1 H H2 H3, true)
| _, _, _, _, _ => fun _ _ _ _ _ => (or, false)
end H H' H'' H3' H4').
eapply BindComputes with (a :=
match v0 as x', v1 as x0', v2 as x1', v3 as x2', v4 as x3'
return decides x' _ ->
decides x0' _ ->
decides x1' _ ->
decides x2' _ ->
decides x3' _ -> _
with
| true, true, true, true, true =>
fun H H0 H1 H2 H3 => @Insert_Valid _ or Ridx tup H0 H1 H H2 H3
| _, _, _, _, _ => fun _ _ _ _ _ => or
end H H' H'' H3' H4').
repeat (computes_to_econstructor; eauto).
repeat find_if_inside; try computes_to_econstructor; simpl in *.
unfold GetRelation, Insert_Valid, UpdateUnConstrRelation,
UpdateRelation, EnsembleInsert ; simpl; split; intros; eauto.
rewrite ilist2.ith_replace2_Index_neq; eauto using string_dec; simpl.
rewrite ilist2.ith_replace2_Index_eq; unfold EnsembleInsert, GetRelation;
simpl; intuition.
computes_to_econstructor.
eapply PickComputes with (a := match v0 as x', v1 as x0', v2 as x1', v3 as x2', v4 as x3'
return decides x' _ ->
decides x0' _ ->
decides x1' _ ->
decides x2' _ ->
decides x3' _ -> _
with
| true, true, true, true, true =>
fun H H0 H1 H2 H3 => true
| _, _, _, _, _ => fun _ _ _ _ _ => false
end H H' H'' H3' H4').
repeat find_if_inside; simpl;
try (solve [unfold not; let H := fresh in intros H; eapply NIntup; eapply H;
unfold EnsembleInsert; eauto]).
intros; rewrite <- GetRelDropConstraints.
unfold Insert_Valid, GetUnConstrRelation, DropQSConstraints,
UpdateRelation; simpl.
rewrite <- ilist2.ith_imap2, ilist2.ith_replace2_Index_eq; simpl; tauto.
simpl in *.
unfold not; intros; apply NIntup.
rewrite GetRelDropConstraints; eapply H0;
unfold DropQSConstraints, Insert_Valid, EnsembleInsert; simpl; eauto.
unfold not; intros; apply NIntup;
rewrite GetRelDropConstraints; eapply H0;
unfold DropQSConstraints, Insert_Valid, EnsembleInsert; simpl; eauto.
unfold not; intros; apply NIntup;
rewrite GetRelDropConstraints; eapply H0;
unfold DropQSConstraints, Insert_Valid, EnsembleInsert; simpl; eauto.
unfold not; intros; apply NIntup;
rewrite GetRelDropConstraints; eapply H0;
unfold DropQSConstraints, Insert_Valid, EnsembleInsert; simpl; eauto.
unfold not; intros; apply NIntup;
rewrite GetRelDropConstraints; eapply H0;
unfold DropQSConstraints, Insert_Valid, EnsembleInsert; simpl; eauto.
simpl in *.
repeat find_if_inside; simpl; eauto.
repeat find_if_inside; simpl; eauto.
repeat computes_to_econstructor.
unfold Insert_Valid, GetUnConstrRelation, DropQSConstraints,
UpdateRelation; simpl; eauto.
computes_to_inv; subst.
unfold Insert_Valid, GetUnConstrRelation, DropQSConstraints,
UpdateUnConstrRelation; simpl; eauto.
rewrite ilist2.imap_replace2_Index, <- ilist2.ith_imap2.
simpl; computes_to_econstructor.
Qed.
Lemma freshIdx2UnConstr {qsSchema} qs Ridx
: refine {bound | forall tup,
@GetUnConstrRelation (QueryStructureSchemaRaw qsSchema) qs Ridx tup ->
RawTupleIndex tup <> bound}
{bound | UnConstrFreshIdx (GetUnConstrRelation qs Ridx) bound}.
Proof.
unfold UnConstrFreshIdx; intros v Comp_v; computes_to_econstructor.
computes_to_inv; intros.
unfold RawTupleIndex in *; apply Comp_v in H; omega.
Qed.
Lemma QSInsertSpec_UnConstr_refine :
forall qsSchema qs Ridx tup or
refined_schConstr_self refined_schConstr refined_schConstr'
refined_qsConstr refined_qsConstr',
refine {b | decides b (SatisfiesAttributeConstraints Ridx tup)}
refined_schConstr_self
-> refine {b | decides b
(forall tup' : @IndexedElement
(@RawTuple
(@GetNRelSchemaHeading
(numRawQSschemaSchemas
(QueryStructureSchemaRaw
qsSchema))
(qschemaSchemas
(QueryStructureSchemaRaw
qsSchema))
_)),
GetUnConstrRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx tup (indexedElement tup'))}
refined_schConstr
-> refine
{b |
decides
b
(forall tup',
GetUnConstrRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') tup)}
refined_schConstr'
-> refine
(@Iterate_Decide_Comp _
(fun Ridx' =>
SatisfiesCrossRelationConstraints
Ridx Ridx' tup
(GetUnConstrRelation qs Ridx')))
refined_qsConstr
-> (forall idx,
refine
(@Iterate_Decide_Comp _
(fun Ridx' =>
Ridx' <> Ridx
-> forall tup',
(GetUnConstrRelation qs Ridx') tup'
-> SatisfiesCrossRelationConstraints
Ridx' Ridx (indexedElement tup')
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx))))
(refined_qsConstr' idx))
-> @DropQSConstraints_AbsR qsSchema or qs ->
refine
(or' <- (idx <- Pick (freshIdx or Ridx);
qs' <- Pick (QSInsertSpec or Ridx
{| elementIndex := idx;
indexedElement := tup |});
b <- Pick (SuccessfulInsertSpec or Ridx qs'
{| elementIndex := idx;
indexedElement := tup |});
ret (qs', b));
nr' <- {nr' | DropQSConstraints_AbsR (fst or') nr'};
ret (nr', snd or'))
(idx <- {idx | UnConstrFreshIdx (GetUnConstrRelation qs Ridx) idx};
(schConstr_self <- refined_schConstr_self;
schConstr <- refined_schConstr;
schConstr' <- refined_schConstr';
qsConstr <- refined_qsConstr ;
qsConstr' <- (refined_qsConstr' idx);
match schConstr_self, schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true, true =>
ret (UpdateUnConstrRelation qs Ridx
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx)), true)
| _, _, _, _, _ => ret (qs, false)
end)).
Proof.
intros.
simplify with monad laws.
unfold freshIdx.
rewrite <- GetRelDropConstraints.
unfold DropQSConstraints_AbsR in *; subst.
rewrite freshIdx2UnConstr.
apply refine_bind_pick; intros.
setoid_rewrite <- H; setoid_rewrite <- H0; setoid_rewrite <- H1;
setoid_rewrite <- H2; setoid_rewrite <- (H3 a).
setoid_rewrite <- (QSInsertSpec_UnConstr_refine' _ {| elementIndex := a; indexedElement := tup |}).
repeat setoid_rewrite refineEquiv_bind_bind.
setoid_rewrite refineEquiv_bind_unit; simpl.
unfold DropQSConstraints_AbsR in *; subst.
f_equiv; intros.
unfold UnConstrFreshIdx, not in *; intros.
apply H4 in H5; simpl in *; omega.
reflexivity.
Qed.
Local Transparent QSInsert.
Definition UpdateUnConstrRelationInsertC {qsSchema} (qs : UnConstrQueryStructure qsSchema) Ridx tup :=
ret (UpdateUnConstrRelation qs Ridx
(EnsembleInsert tup (GetUnConstrRelation qs Ridx))).
Lemma QSInsertSpec_refine_subgoals ResultT :
forall qsSchema (qs : QueryStructure qsSchema) qs' Ridx
tup default success refined_schConstr_self
refined_schConstr refined_schConstr'
refined_qsConstr refined_qsConstr'
(k : _ -> Comp ResultT),
DropQSConstraints_AbsR qs qs'
-> refine {b | decides b
(SatisfiesAttributeConstraints Ridx tup)}
refined_schConstr_self
-> refine {b |
decides
b
(forall tup',
GetUnConstrRelation qs' Ridx tup'
-> SatisfiesTupleConstraints Ridx tup (indexedElement tup'))}
refined_schConstr
-> (forall b',
decides b'
(forall tup',
GetUnConstrRelation qs' Ridx tup'
-> SatisfiesTupleConstraints Ridx tup (indexedElement tup'))
-> refine
{b |
decides
b
(forall tup',
GetUnConstrRelation qs' Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') tup)}
(refined_schConstr' b'))
-> refine
(@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetUnConstrRelation qs' Ridx'))
| None => None
end))
refined_qsConstr
-> (forall idx,
UnConstrFreshIdx (GetUnConstrRelation qs' Ridx) idx
-> refine
(@Iterate_Decide_Comp_opt _
(fun Ridx' =>
if (fin_eq_dec Ridx Ridx') then
None
else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetUnConstrRelation qs' Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs' Ridx))))
| None => None
end))
(refined_qsConstr' idx))
-> (forall idx qs' qs'',
DropQSConstraints_AbsR qs' qs''
-> UnConstrFreshIdx (GetRelation qs Ridx) idx
-> (forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
-> (forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetRelation qs Ridx) t))
-> refine (k (qs', true))
(success qs''))
-> refine (k (qs, false)) default
-> refine
(qs' <- QSInsert qs Ridx tup; k qs')
(idx <- {idx | UnConstrFreshIdx (GetUnConstrRelation qs' Ridx) idx} ;
schConstr_self <- refined_schConstr_self;
schConstr <- refined_schConstr;
schConstr' <- refined_schConstr' schConstr;
qsConstr <- refined_qsConstr;
qsConstr' <- refined_qsConstr' idx;
match schConstr_self, schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true, true =>
qs'' <- UpdateUnConstrRelationInsertC qs' Ridx {| elementIndex := idx;
indexedElement := tup |};
success qs''
| _, _, _, _, _ => default
end).
Proof.
intros.
unfold QSInsert.
simplify with monad laws.
setoid_rewrite QSInsertSpec_refine with (default := ret qs).
rewrite freshIdx_UnConstrFreshIdx_Equiv.
simplify with monad laws.
rewrite <- H, (GetRelDropConstraints qs).
apply refine_under_bind_both; [reflexivity | intros].
rewrite <- !GetRelDropConstraints; rewrite !H.
repeat (apply refine_under_bind_both;
[repeat rewrite <- (GetRelDropConstraints qs); eauto
| intros]).
computes_to_inv; eauto.
rewrite refine_SatisfiesCrossConstraints_Constr; etransitivity; try eassumption.
simpl; f_equiv; apply functional_extensionality; intros;
rewrite <- H, GetRelDropConstraints; reflexivity.
rewrite <- H, GetRelDropConstraints, refine_SatisfiesCrossConstraints'_Constr.
etransitivity; try eapply H4.
simpl; f_equiv; apply functional_extensionality; intros.
rewrite <- H; rewrite !(GetRelDropConstraints qs); eauto.
rewrite <- H, GetRelDropConstraints; computes_to_inv; eauto.
repeat find_if_inside; try simplify with monad laws;
try solve [rewrite refine_SuccessfulInsert_Bind; eauto].
apply Iterate_Decide_Comp_BoundedIndex in H11.
apply Iterate_Decide_Comp_BoundedIndex in H12.
computes_to_inv; simpl in *.
assert (forall tup' : IndexedElement,
GetRelation qs Ridx tup' ->
SatisfiesTupleConstraints (qsSchema := qsSchema) Ridx
(indexedElement {| elementIndex := a; indexedElement := tup |})
(indexedElement tup')) as H9'
by (intros; apply H9; rewrite <- H, GetRelDropConstraints; eassumption).
assert (forall Ridx' : Fin.t (numRawQSschemaSchemas qsSchema),
Ridx' <> Ridx ->
forall tup' : IndexedElement,
GetRelation qs Ridx' tup' ->
SatisfiesCrossRelationConstraints Ridx' Ridx (indexedElement tup')
(EnsembleInsert {| elementIndex := a; indexedElement := tup |}
(GetRelation qs Ridx)))
as H12' by (intros; rewrite <- GetRelDropConstraints, H; eauto).
assert (forall tup' : IndexedElement,
GetRelation qs Ridx tup' ->
SatisfiesTupleConstraints (qsSchema := qsSchema) Ridx (indexedElement tup')
(indexedElement {| elementIndex := a; indexedElement := tup |})) as H10'
by (intros; apply H10; rewrite <- H, GetRelDropConstraints; eassumption).
refine pick val (Insert_Valid qs {| elementIndex := a;
indexedElement := tup |} H9' H10' H8 H11 H12').
simplify with monad laws.
refine pick val true.
unfold UpdateUnConstrRelationInsertC.
simplify with monad laws.
setoid_rewrite refineEquiv_bind_unit.
eapply H5.
rewrite <- H.
rewrite GetRelDropConstraints.
unfold DropQSConstraints_AbsR, DropQSConstraints, Insert_Valid; simpl.
unfold UpdateRelation.
rewrite ilist2.imap_replace2_Index; reflexivity.
eauto.
intros; unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_neq; simpl; eauto.
intros; unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_eq; simpl; reflexivity.
unfold SuccessfulInsertSpec; simpl.
unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_eq; simpl; reflexivity.
split; intros.
unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_neq; simpl; eauto.
rewrite <- H; rewrite GetRelDropConstraints.
unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_eq; simpl; reflexivity.
Qed.
Lemma QSInsertSpec_refine_short_circuit' :
forall qsSchema (qs : QueryStructure qsSchema) Ridx tup default,
refine
(Pick (QSInsertSpec qs Ridx tup))
(schConstr_self <-
{b |
decides b
(SatisfiesAttributeConstraints Ridx (indexedElement tup))};
If schConstr_self Then
schConstr <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup) (indexedElement tup'))};
If schConstr Then
schConstr' <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') (indexedElement tup))};
If schConstr' Then
qsConstr <- {b | decides b
(forall Ridx', SatisfiesCrossRelationConstraints Ridx Ridx' (indexedElement tup) (GetRelation qs Ridx'))};
If qsConstr Then
qsConstr' <- {b | decides
b
(forall Ridx',
Ridx' <> Ridx ->
forall tup',
(GetRelation qs Ridx') tup'
-> SatisfiesCrossRelationConstraints
Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetRelation qs Ridx)))};
If qsConstr' Then
{qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert tup (GetRelation qs Ridx) t)
}
Else default
Else default
Else default
Else default
Else default).
Proof.
intros qsSchema qs Ridx tup default v Comp_v;
computes_to_inv.
destruct v0;
[ simpl in *; computes_to_inv; destruct v0;
[ simpl in *; computes_to_inv; destruct v0;
[simpl in *; computes_to_inv; destruct v0;
[ simpl in *; computes_to_inv; destruct v0;
[ repeat (computes_to_inv; destruct_ex; split_and); simpl in *;
computes_to_econstructor; unfold QSInsertSpec; eauto |
]
| ]
| ]
| ]
| ];
cbv delta [decides] beta in *; simpl in *;
repeat (computes_to_inv; destruct_ex); eauto.
intuition.
unfold QSInsertSpec; intros; intuition.
unfold QSInsertSpec; intros; intuition.
unfold QSInsertSpec; intros; intuition.
unfold QSInsertSpec; intros; intuition.
unfold QSInsertSpec; intros; intuition.
computes_to_econstructor; unfold QSInsertSpec; intros;
intros.
solve [exfalso; intuition].
Qed.
Lemma QSInsertSpec_refine_short_circuit :
forall qsSchema (qs : QueryStructure qsSchema) Ridx tup default,
refine
(Pick (QSInsertSpec qs Ridx tup))
(schConstr_self <- {b | decides b
(SatisfiesAttributeConstraints Ridx (indexedElement tup))};
If schConstr_self Then
schConstr <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup) (indexedElement tup'))};
If schConstr Then
schConstr' <-
{b |
decides
b
(forall tup',
GetRelation qs Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') (indexedElement tup))};
If schConstr' Then
qsConstr <- (@Iterate_Decide_Comp _
(fun Ridx' =>
SatisfiesCrossRelationConstraints
Ridx Ridx' (indexedElement tup)
(GetRelation qs Ridx')));
If qsConstr Then
qsConstr' <- (@Iterate_Decide_Comp _
(fun Ridx' =>
Ridx' <> Ridx
-> forall tup',
(GetRelation qs Ridx') tup'
-> SatisfiesCrossRelationConstraints
Ridx' Ridx (indexedElement tup')
(EnsembleInsert tup (GetRelation qs Ridx))));
If qsConstr' Then
{qs' |
(forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
/\ forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert tup (GetRelation qs Ridx) t)
} Else default
Else default
Else default
Else default
Else default).
Proof.
intros.
rewrite QSInsertSpec_refine_short_circuit'; f_equiv.
unfold pointwise_relation; intros.
apply refine_If_Then_Else; f_equiv; unfold pointwise_relation; intros.
apply refine_If_Then_Else; f_equiv; unfold pointwise_relation; intros.
apply refine_If_Then_Else; f_equiv; unfold pointwise_relation; intros.
setoid_rewrite Iterate_Decide_Comp_BoundedIndex; f_equiv; eauto.
apply refine_If_Then_Else; f_equiv; unfold pointwise_relation; intros.
setoid_rewrite Iterate_Decide_Comp_BoundedIndex; f_equiv; eauto.
Qed.
Lemma QSInsertSpec_refine_subgoals_short_circuit ResultT :
forall qsSchema (qs : QueryStructure qsSchema) qs' Ridx
tup default success refined_schConstr_self
refined_schConstr refined_schConstr'
refined_qsConstr refined_qsConstr'
(k : _ -> Comp ResultT),
DropQSConstraints_AbsR qs qs'
-> refine {b | decides b
(SatisfiesAttributeConstraints Ridx tup)}
refined_schConstr_self
-> refine {b |
decides
b
(forall tup',
GetUnConstrRelation qs' Ridx tup'
-> SatisfiesTupleConstraints Ridx tup (indexedElement tup'))}
refined_schConstr
-> (forall b',
decides b'
(forall tup',
GetUnConstrRelation qs' Ridx tup'
-> SatisfiesTupleConstraints Ridx tup (indexedElement tup'))
-> refine
{b |
decides
b
(forall tup',
GetUnConstrRelation qs' Ridx tup'
-> SatisfiesTupleConstraints Ridx (indexedElement tup') tup)}
(refined_schConstr' b'))
-> refine
(@Iterate_Decide_Comp.Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetUnConstrRelation qs' Ridx'))
| None => None
end))
refined_qsConstr
-> (forall idx,
UnConstrFreshIdx (GetUnConstrRelation qs' Ridx) idx
-> refine
(@Iterate_Decide_Comp.Iterate_Decide_Comp_opt _
(fun Ridx' =>
if (fin_eq_dec Ridx Ridx') then
None
else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetUnConstrRelation qs' Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs' Ridx))))
| None => None
end))
(refined_qsConstr' idx))
-> (forall idx qs' qs'',
DropQSConstraints_AbsR qs' qs''
-> UnConstrFreshIdx (GetRelation qs Ridx) idx
-> (forall Ridx',
Ridx <> Ridx' ->
GetRelation qs Ridx' =
GetRelation qs' Ridx')
-> (forall t,
GetRelation qs' Ridx t <->
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetRelation qs Ridx) t))
-> refine (k (qs', true))
(success qs''))
-> refine (k (qs, false)) default
-> refine
(qs' <- QSInsert qs Ridx tup; k qs')
(idx <- {idx | UnConstrFreshIdx (GetUnConstrRelation qs' Ridx) idx} ;
schConstr_self <- refined_schConstr_self;
If schConstr_self Then
schConstr <- refined_schConstr;
If schConstr Then
schConstr' <- refined_schConstr' schConstr;
If schConstr' Then
qsConstr <- refined_qsConstr;
If qsConstr Then
qsConstr' <- refined_qsConstr' idx;
If qsConstr' Then
qs'' <- UpdateUnConstrRelationInsertC qs' Ridx {| elementIndex := idx;
indexedElement := tup |};
success qs''
Else default
Else default
Else default
Else default
Else default
).
Proof.
intros; unfold QSInsert.
simplify with monad laws.
setoid_rewrite QSInsertSpec_refine_short_circuit with (default := ret qs).
rewrite freshIdx_UnConstrFreshIdx_Equiv.
simplify with monad laws.
rewrite <- !H, (GetRelDropConstraints qs).
apply refine_under_bind_both; [reflexivity | intros].
apply refine_under_bind_both; [eassumption | intros].
rewrite refine_If_Then_Else_Bind.
eapply refine_if; intros; subst; simpl; try simplify with monad laws.
apply refine_under_bind_both; [eauto | intros].
rewrite <- H1; simpl.
rewrite <- (GetRelDropConstraints qs), H; reflexivity.
rewrite refine_If_Then_Else_Bind.
eapply refine_if; intros; subst; simpl; try simplify with monad laws.
apply refine_under_bind_both; [eauto | intros].
rewrite <- H2; simpl.
rewrite <- (GetRelDropConstraints qs), H; reflexivity.
computes_to_inv; simpl in *; eauto.
rewrite <- !GetRelDropConstraints in H9; rewrite !H in H9.
eauto.
rewrite refine_If_Then_Else_Bind.
eapply refine_if; intros; subst; simpl; try simplify with monad laws.
apply refine_under_bind_both; [eauto | intros].
rewrite <- H3; simpl.
etransitivity.
apply refine_SatisfiesCrossConstraints_Constr.
f_equiv.
apply functional_extensionality; intro.
destruct (BuildQueryStructureConstraints qsSchema Ridx x).
rewrite <- (GetRelDropConstraints qs), H; reflexivity.
reflexivity.
rewrite refine_If_Then_Else_Bind.
eapply refine_if; intros; subst; simpl; try simplify with monad laws.
apply refine_under_bind_both; [eauto | intros].
rewrite <- H4; simpl.
etransitivity.
apply refine_SatisfiesCrossConstraints'_Constr.
f_equiv.
apply functional_extensionality; intro.
simpl.
find_if_inside; eauto.
destruct (BuildQueryStructureConstraints qsSchema x Ridx).
rewrite <- (GetRelDropConstraints qs), H.
rewrite <- (GetRelDropConstraints qs), H.
reflexivity.
reflexivity.
computes_to_inv; simpl in *; subst.
rewrite <- H, (GetRelDropConstraints qs); eauto.
rewrite refine_If_Then_Else_Bind.
eapply refine_if.
simpl in *; intros; subst; simpl; computes_to_inv; simpl in *.
assert (forall tup' : IndexedElement,
GetRelation qs Ridx tup' ->
SatisfiesTupleConstraints (qsSchema := qsSchema) Ridx
(indexedElement {| elementIndex := a; indexedElement := tup |})
(indexedElement tup')) as H9'
by (intros; apply H9; try rewrite <- H, GetRelDropConstraints; eassumption).
assert (forall Ridx' : Fin.t (numRawQSschemaSchemas qsSchema),
Ridx' <> Ridx ->
forall tup' : IndexedElement,
GetRelation qs Ridx' tup' ->
SatisfiesCrossRelationConstraints Ridx' Ridx (indexedElement tup')
(EnsembleInsert {| elementIndex := a; indexedElement := tup |}
(GetRelation qs Ridx)))
as H12' by
(apply Iterate_Decide_Comp_BoundedIndex in H12;
computes_to_inv; subst; simpl in *; apply H12).
assert (forall tup' : IndexedElement,
GetRelation qs Ridx tup' ->
SatisfiesTupleConstraints (qsSchema := qsSchema) Ridx (indexedElement tup')
(indexedElement {| elementIndex := a; indexedElement := tup |})) as H10'
by (intros; apply H10; try rewrite <- H, GetRelDropConstraints; eassumption).
assert (forall Ridx' : Fin.t (numRawQSschemaSchemas qsSchema),
SatisfiesCrossRelationConstraints (qsSchema := qsSchema) Ridx Ridx' (indexedElement {| elementIndex := a; indexedElement := tup |})
(GetRelation qs Ridx'))
as H11'.
(apply Iterate_Decide_Comp_BoundedIndex in H11;
computes_to_inv; subst; simpl in *; apply H11).
refine pick val (Insert_Valid qs {| elementIndex := a;
indexedElement := tup |} H9' H10' H8 H11' H12').
simplify with monad laws.
refine pick val true.
unfold UpdateUnConstrRelationInsertC.
simplify with monad laws.
setoid_rewrite refineEquiv_bind_unit.
eapply H5.
rewrite H.
unfold DropQSConstraints_AbsR, DropQSConstraints, Insert_Valid; simpl.
unfold UpdateRelation.
rewrite ilist2.imap_replace2_Index; try reflexivity.
simpl.
unfold UpdateUnConstrRelation; simpl.
rewrite <- H.
rewrite GetRelDropConstraints; reflexivity.
apply H7.
intros.
intros; unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
simpl.
rewrite ilist2.ith_replace2_Index_neq; simpl; eauto.
intros; unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_eq; simpl; reflexivity.
unfold SuccessfulInsertSpec; simpl.
unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_eq; simpl; reflexivity.
split; intros.
unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
rewrite ilist2.ith_replace2_Index_neq; simpl; eauto.
rewrite <- GetRelDropConstraints.
unfold Insert_Valid, GetRelation, UpdateRelation; simpl.
unfold DropQSConstraints, GetUnConstrRelation; simpl.
rewrite ilist2.imap_replace2_Index; simpl.
rewrite ilist2.ith_replace2_Index_eq; simpl; reflexivity.
intros; subst; computes_to_inv; simpl.
simplify with monad laws.
refine pick val _; try simplify with monad laws; eauto.
unfold SuccessfulInsertSpec.
computes_to_inv; simpl in *; subst.
intro.
pose proof (proj2 (H13 _) (or_introl (eq_refl _))).
apply H7 in H14; simpl in H14; omega.
refine pick val _; try simplify with monad laws; eauto.
unfold SuccessfulInsertSpec.
computes_to_inv; simpl in *; subst.
intro.
pose proof (proj2 (H12 _) (or_introl (eq_refl _))).
apply H7 in H13; simpl in H13; omega.
refine pick val _; try simplify with monad laws; eauto.
unfold SuccessfulInsertSpec.
computes_to_inv; simpl in *; subst.
intro.
pose proof (proj2 (H11 _) (or_introl (eq_refl _))).
apply H7 in H12; simpl in H12; omega.
refine pick val _; try simplify with monad laws; eauto.
unfold SuccessfulInsertSpec.
computes_to_inv; simpl in *; subst.
intro.
pose proof (proj2 (H10 _) (or_introl (eq_refl _))).
apply H7 in H11; simpl in H11; omega.
refine pick val _; try simplify with monad laws; eauto.
unfold SuccessfulInsertSpec.
computes_to_inv; simpl in *; subst.
intro.
pose proof (proj2 (H9 _) (or_introl (eq_refl _))).
apply H7 in H10; simpl in H10; omega.
Qed.
Lemma QSInsertSpec_UnConstr_refine_opt :
forall qsSchema
qs
or
(Ridx : Fin.t _) tup,
@DropQSConstraints_AbsR qsSchema or qs ->
refine
(or' <- (idx <- Pick (freshIdx or Ridx);
qs' <- Pick (QSInsertSpec or Ridx
{| elementIndex := idx;
indexedElement := tup |});
b <- Pick (SuccessfulInsertSpec or Ridx qs'
{| elementIndex := idx;
indexedElement := tup |});
ret (qs', b));
nr' <- {nr' | DropQSConstraints_AbsR (fst or') nr'};
ret (nr', snd or'))
match (attrConstraints (GetNRelSchema (qschemaSchemas qsSchema) Ridx)),
(tupleConstraints (GetNRelSchema (qschemaSchemas qsSchema) Ridx)) with
Some aConstr, Some tConstr =>
idx <- {idx | UnConstrFreshIdx (GetUnConstrRelation qs Ridx) idx} ;
(schConstr_self <- {b | decides b (aConstr tup) };
schConstr <- {b | decides b
(forall tup',
GetUnConstrRelation qs Ridx tup'
-> tConstr tup (indexedElement tup'))};
schConstr' <- {b | decides b
(forall tup',
GetUnConstrRelation qs Ridx tup'
-> tConstr (indexedElement tup') tup)};
qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetUnConstrRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
if (fin_eq_dec Ridx Ridx') then
None
else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetUnConstrRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx))))
| None => None
end));
match schConstr_self, schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true, true =>
ret (UpdateUnConstrRelation qs Ridx
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx)), true)
| _, _, _, _, _ => ret (qs, false)
end)
| Some aConstr, None =>
idx <- {idx | UnConstrFreshIdx (GetUnConstrRelation qs Ridx) idx} ;
(schConstr_self <- {b | decides b (aConstr tup) };
qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetUnConstrRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
if (fin_eq_dec Ridx Ridx') then
None
else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetUnConstrRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx))))
| None => None
end));
match schConstr_self, qsConstr, qsConstr' with
| true, true, true =>
ret (UpdateUnConstrRelation qs Ridx
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx)), true)
| _, _, _ => ret (qs, false)
end)
| None, Some tConstr =>
idx <- {idx | UnConstrFreshIdx (GetUnConstrRelation qs Ridx) idx} ;
(schConstr <- {b | decides b
(forall tup',
GetUnConstrRelation qs Ridx tup'
-> tConstr tup (indexedElement tup'))};
schConstr' <- {b | decides b
(forall tup',
GetUnConstrRelation qs Ridx tup'
-> tConstr (indexedElement tup') tup)};
qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetUnConstrRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
if (fin_eq_dec Ridx Ridx') then
None
else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetUnConstrRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx))))
| None => None
end));
match schConstr, schConstr', qsConstr, qsConstr' with
| true, true, true, true =>
ret (UpdateUnConstrRelation qs Ridx
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx)), true)
| _, _, _, _ => ret (qs, false)
end)
| None, None =>
idx <- {idx | UnConstrFreshIdx (GetUnConstrRelation qs Ridx) idx} ;
(qsConstr <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
match (BuildQueryStructureConstraints qsSchema Ridx Ridx') with
| Some CrossConstr =>
Some (CrossConstr tup (GetUnConstrRelation qs Ridx'))
| None => None
end));
qsConstr' <- (@Iterate_Decide_Comp_opt _
(fun Ridx' =>
if (fin_eq_dec Ridx Ridx') then
None
else
match (BuildQueryStructureConstraints qsSchema Ridx' Ridx) with
| Some CrossConstr =>
Some (
forall tup',
(GetUnConstrRelation qs Ridx') tup'
-> CrossConstr (indexedElement tup') (
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx))))
| None => None
end));
match qsConstr, qsConstr' with
| true, true =>
ret (UpdateUnConstrRelation qs Ridx
(EnsembleInsert
{| elementIndex := idx;
indexedElement := tup |}
(GetUnConstrRelation qs Ridx)), true)
| _, _ => ret (qs, false)
end)
end.
unfold QSInsert.
intros; rewrite QSInsertSpec_UnConstr_refine;
eauto using
refine_SatisfiesAttributeConstraints_self,
refine_SatisfiesTupleConstraints,
refine_SatisfiesTupleConstraints',
refine_SatisfiesCrossConstraints;
[
| intros; eapply refine_SatisfiesCrossConstraints'].
destruct (attrConstraints (GetNRelSchema (qschemaSchemas qsSchema) Ridx));
destruct (tupleConstraints (GetNRelSchema (qschemaSchemas qsSchema) Ridx)).
- reflexivity.
- f_equiv; unfold pointwise_relation; intros.
repeat setoid_rewrite refineEquiv_bind_bind.
repeat setoid_rewrite refineEquiv_bind_unit; f_equiv.
- f_equiv; unfold pointwise_relation; intros.
repeat setoid_rewrite refineEquiv_bind_bind.
repeat setoid_rewrite refineEquiv_bind_unit; f_equiv.
- f_equiv; unfold pointwise_relation; intros.
repeat setoid_rewrite refineEquiv_bind_bind.
repeat setoid_rewrite refineEquiv_bind_unit; f_equiv.
Qed.
End InsertRefinements.
(* We should put all these simplification hints into a distinct file
so we're not unfolding things all willy-nilly. *)
Arguments Iterate_Decide_Comp _ _ / _.
Arguments SatisfiesCrossRelationConstraints _ _ _ _ _ / .
Arguments BuildQueryStructureConstraints _ _ _ / .
Arguments BuildQueryStructureConstraints_cons / .
Arguments GetNRelSchemaHeading _ _ _ / .
Arguments id _ _ / .
Create HintDb refine_keyconstraints discriminated.
(*Hint Rewrite refine_Any_DecideableSB_True : refine_keyconstraints.*)
Arguments ith_Bounded _ _ _ _ _ _ / .
Arguments SatisfiesTupleConstraints _ _ _ _ / .
Arguments GetUnConstrRelation : simpl never.
Arguments UpdateUnConstrRelation : simpl never.
Arguments replace_BoundedIndex : simpl never.
Opaque UpdateUnConstrRelationInsertC.
|
lemma lebesgue_on_UNIV_eq: "lebesgue_on UNIV = lebesgue" |
!
! Copyright 2016 ARTED developers
!
! Licensed 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.
!
!This file is "main.f90"
!This file contains main program and four subroutines.
!PROGRAM main
!SUBROUTINE err_finalize(err_message)
!--------10--------20--------30--------40--------50--------60--------70--------80--------90--------100-------110-------120--------130
Program main
use Global_Variables
use timelog
use opt_variables
use environment
implicit none
integer :: iter,ik,ib,ia,i,ixyz
character(3) :: Rion_update
character(10) :: functional_t
!$ integer :: omp_get_max_threads
call MPI_init(ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,Nprocs,ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,Myrank,ierr)
call timelog_initialize
call load_environments
if(Myrank == 0) then
write(*,'(2A)')'ARTED ver. = ',ARTED_ver
call print_optimize_message
end if
NEW_COMM_WORLD=MPI_COMM_WORLD
NUMBER_THREADS=1
!$ NUMBER_THREADS=omp_get_max_threads()
!$ if(iter*0 == 0) then
!$ if(myrank == 0)write(*,*)'parallel = Hybrid'
!$ else
if(myrank == 0)write(*,*)'parallel = Flat MPI'
!$ end if
if(myrank == 0)write(*,*)'NUMBER_THREADS = ',NUMBER_THREADS
etime1=MPI_WTIME()
Time_start=MPI_WTIME() !reentrance
call MPI_BCAST(Time_start,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
Rion_update='on'
call Read_data
if (entrance_option == 'reentrance' ) go to 2
allocate(rho_in(1:NL,1:Nscf+1),rho_out(1:NL,1:Nscf+1))
rho_in(1:NL,1:Nscf+1)=0.d0; rho_out(1:NL,1:Nscf+1)=0.d0
allocate(Eall_GS(0:Nscf),esp_var_ave(1:Nscf),esp_var_max(1:Nscf),dns_diff(1:Nscf))
call fd_coef
call init
call init_wf
call Gram_Schmidt
rho=0.d0; Vh=0.d0
! call psi_rho_omp !sym
! initialize for optimization.
call opt_vars_initialize_p1
call psi_rho_GS !sym
rho_in(1:NL,1)=rho(1:NL)
call input_pseudopotential_YS !shinohara
! call input_pseudopotential_KY !shinohara
! call MPI_FINALIZE(ierr) !!debug shinohara
! stop !!debug shinohara
call prep_ps_periodic('initial ')
! initialize for optimization.
call opt_vars_initialize_p2
call Hartree
! yabana
functional_t = functional
if(functional_t == 'TBmBJ') functional = 'PZ'
call Exc_Cor('GS')
if(functional_t == 'TBmBJ') functional = 'TBmBJ'
! yabana
Vloc(1:NL)=Vh(1:NL)+Vpsl(1:NL)+Vexc(1:NL)
! call Total_Energy(Rion_update,'GS')
call Total_Energy_omp(Rion_update,'GS') ! debug
call Ion_Force_omp(Rion_update,'GS')
if (MD_option /= 'Y') Rion_update = 'off'
Eall_GS(0)=Eall
if(Myrank == 0) write(*,*) 'This is the end of preparation for ground state calculation'
if(Myrank == 0) write(*,*) '-----------------------------------------------------------'
call timelog_reset
do iter=1,Nscf
if (Myrank == 0) write(*,*) 'iter = ',iter
if( kbTev < 0d0 )then ! sato
if (FSset_option == 'Y') then
if (iter/NFSset_every*NFSset_every == iter .and. iter >= NFSset_start) then
do ik=1,NK
esp_vb_min(ik)=minval(esp(1:NBocc(ik),ik))
esp_vb_max(ik)=maxval(esp(1:NBocc(ik),ik))
esp_cb_min(ik)=minval(esp(NBocc(ik)+1:NB,ik))
esp_cb_max(ik)=maxval(esp(NBocc(ik)+1:NB,ik))
end do
if (minval(esp_cb_min(:))-maxval(esp_vb_max(:))<0.d0) then
call Occupation_Redistribution
else
if (Myrank == 0) then
write(*,*) '======================================='
write(*,*) 'occupation redistribution is not needed'
write(*,*) '======================================='
end if
end if
end if
end if
else if( iter /= 1 )then ! sato
call Fermi_Dirac_distribution
if((Myrank == 0).and.(iter == Nscf))then
open(126,file='occ.out')
do ik=1,NK
do ib=1,NB
write(126,'(2I7,e26.16E3)')ik,ib,occ(ib,ik)
end do
end do
close(126)
end if
end if
call Gram_Schmidt
call diag_omp
call Gram_Schmidt
call CG_omp(Ncg)
call Gram_Schmidt
! call psi_rho_omp !sym
call psi_rho_GS
call Density_Update(iter)
call Hartree
! yabana
functional_t = functional
if(functional_t == 'TBmBJ' .and. iter < 20) functional = 'PZ'
call Exc_Cor('GS')
if(functional_t == 'TBmBJ' .and. iter < 20) functional = 'TBmBJ'
! yabana
Vloc(1:NL)=Vh(1:NL)+Vpsl(1:NL)+Vexc(1:NL)
call Total_Energy_omp(Rion_update,'GS')
call Ion_Force_omp(Rion_update,'GS')
call sp_energy_omp
call current_GS_omp_KB
Eall_GS(iter)=Eall
esp_var_ave(iter)=sum(esp_var(:,:))/(NK*Nelec/2)
esp_var_max(iter)=maxval(esp_var(:,:))
dns_diff(iter)=sqrt(sum((rho_out(:,iter)-rho_in(:,iter))**2))*Hxyz
if (Myrank == 0) then
write(*,*) 'Total Energy = ',Eall_GS(iter),Eall_GS(iter)-Eall_GS(iter-1)
write(*,'(a28,3e15.6)') 'jav(1),jav(2),jav(3)= ',jav(1),jav(2),jav(3)
write(*,'(4(i3,f12.6,2x))') (ib,esp(ib,1),ib=1,NB)
do ia=1,NI
write(*,'(1x,i7,3f15.6)') ia,force(1,ia),force(2,ia),force(3,ia)
end do
write(*,*) 'var_ave,var_max=',esp_var_ave(iter),esp_var_max(iter)
write(*,*) 'dns. difference =',dns_diff(iter)
if (iter/20*20 == iter) then
etime2=MPI_WTIME()
write(*,*) '====='
write(*,*) 'elapse time=',etime2-etime1,'sec=',(etime2-etime1)/60,'min'
end if
write(*,*) '-----------------------------------------------'
end if
end do
etime2 = MPI_WTIME()
if(Myrank == 0) then
call timelog_set(LOG_DYNAMICS, etime2 - etime1)
call timelog_show_hour('Ground State time :', LOG_DYNAMICS)
call timelog_show_min ('CG time :', LOG_CG)
call timelog_show_min ('Gram Schmidt time :', LOG_GRAM_SCHMIDT)
call timelog_show_min ('diag time :', LOG_DIAG)
call timelog_show_min ('sp_energy time :', LOG_SP_ENERGY)
call timelog_show_min ('hpsi time :', LOG_HPSI)
call timelog_show_min (' - stencil time :', LOG_HPSI_STENCIL)
call timelog_show_min (' - pseudo pt. time :', LOG_HPSI_PSEUDO)
call timelog_show_min ('psi_rho time :', LOG_PSI_RHO)
call timelog_show_min ('Hartree time :', LOG_HARTREE)
call timelog_show_min ('Exc_Cor time :', LOG_EXC_COR)
call timelog_show_min ('current time :', LOG_CURRENT)
call timelog_show_min ('Total_Energy time :', LOG_TOTAL_ENERGY)
call timelog_show_min ('Ion_Force time :', LOG_ION_FORCE)
end if
if(Myrank == 0) write(*,*) 'This is the end of GS calculation'
zu_GS0(:,:,:)=zu_GS(:,:,:)
zu(:,:,:)=zu_GS(:,1:NBoccmax,:)
Rion_eq=Rion
dRion(:,:,-1)=0.d0; dRion(:,:,0)=0.d0
! call psi_rho_omp !sym
call psi_rho_GS
call Hartree
! yabana
call Exc_Cor('GS')
! yabana
Vloc(1:NL)=Vh(1:NL)+Vpsl(1:NL)+Vexc(1:NL)
Vloc_GS(:)=Vloc(:)
call Total_Energy_omp(Rion_update,'GS')
Eall0=Eall
if(Myrank == 0) write(*,*) 'Eall =',Eall
etime2=MPI_WTIME()
if (Myrank == 0) then
write(*,*) '-----------------------------------------------'
write(*,*) 'static time=',etime2-etime1,'sec=', (etime2-etime1)/60,'min'
write(*,*) '-----------------------------------------------'
end if
etime1=etime2
if (Myrank == 0) then
write(*,*) '-----------------------------------------------'
write(*,*) '----some information for Band map--------------'
do ik=1,NK
esp_vb_min(ik)=minval(esp(1:NBocc(ik),ik))
esp_vb_max(ik)=maxval(esp(1:NBocc(ik),ik))
esp_cb_min(ik)=minval(esp(NBocc(ik)+1:NB,ik))
esp_cb_max(ik)=maxval(esp(NBocc(ik)+1:NB,ik))
end do
write(*,*) 'Bottom of VB',minval(esp_vb_min(:))
write(*,*) 'Top of VB',maxval(esp_vb_max(:))
write(*,*) 'Bottom of CB',minval(esp_cb_min(:))
write(*,*) 'Top of CB',maxval(esp_cb_max(:))
write(*,*) 'The Bandgap',minval(esp_cb_min(:))-maxval(esp_vb_max(:))
write(*,*) 'BG between same k-point',minval(esp_cb_min(:)-esp_vb_max(:))
write(*,*) 'Physicaly upper bound of CB for DOS',minval(esp_cb_max(:))
write(*,*) 'Physicaly upper bound of CB for eps(omega)',minval(esp_cb_max(:)-esp_vb_min(:))
write(*,*) '-----------------------------------------------'
write(*,*) '-----------------------------------------------'
end if
#ifndef ARTED_DEBUG
call write_GS_data
#endif
deallocate(rho_in,rho_out)
deallocate(Eall_GS,esp_var_ave,esp_var_max,dns_diff)
!====GS calculation============================
if(Myrank == 0) write(*,*) 'This is the end of preparation for Real time calculation'
!====RT calculation============================
call init_Ac
! yabana
! kAc0=kAc
! yabana
rho_gs(:)=rho(:)
!reentrance
2 if (entrance_option == 'reentrance') then
position_option='append'
else
position_option='rewind'
entrance_iter=-1
end if
if (Myrank == 0) then
open(7,file=file_epst,position = position_option)
open(8,file=file_dns,position = position_option)
open(9,file=file_force_dR,position = position_option)
if (AD_RHO /= 'No') then
open(404,file=file_ovlp,position = position_option)
open(408,file=file_nex,position = position_option)
end if
endif
call timelog_reset
call timelog_enable_verbose
#ifdef ARTED_USE_PAPI
call papi_begin
#endif
etime1=MPI_WTIME()
do iter=entrance_iter+1,Nt
do ixyz=1,3
kAc(:,ixyz)=kAc0(:,ixyz)+Ac_tot(iter,ixyz)
enddo
call dt_evolve_omp_KB(iter)
call current_omp_KB
javt(iter,:)=jav(:)
if (MD_option == 'Y') then
call Ion_Force_omp(Rion_update,'RT')
if (iter/10*10 == iter) then
call Total_Energy_omp(Rion_update,'RT')
end if
else
if (iter/10*10 == iter) then
call Total_Energy_omp(Rion_update,'RT')
call Ion_Force_omp(Rion_update,'RT')
end if
end if
call timelog_begin(LOG_OTHER)
if (Longi_Trans == 'Lo') then
Ac_ind(iter+1,:)=2*Ac_ind(iter,:)-Ac_ind(iter-1,:)-4*Pi*javt(iter,:)*dt**2
if (Sym /= 1) then
Ac_ind(iter+1,1)=0.d0
Ac_ind(iter+1,2)=0.d0
end if
Ac_tot(iter+1,:)=Ac_ext(iter+1,:)+Ac_ind(iter+1,:)
else if (Longi_Trans == 'Tr') then
Ac_tot(iter+1,:)=Ac_ext(iter+1,:)
end if
E_ext(iter,:)=-(Ac_ext(iter+1,:)-Ac_ext(iter-1,:))/(2*dt)
E_ind(iter,:)=-(Ac_ind(iter+1,:)-Ac_ind(iter-1,:))/(2*dt)
E_tot(iter,:)=-(Ac_tot(iter+1,:)-Ac_tot(iter-1,:))/(2*dt)
Eelemag=aLxyz*sum(E_tot(iter,:)**2)/(8.d0*Pi)
Eall=Eall+Eelemag
do ia=1,NI
force_ion(:,ia)=Zps(Kion(ia))*E_tot(iter,:)
enddo
force=force+force_ion
!pseudo potential update
if (MD_option == 'Y') then
Tion=0.d0
do ia=1,NI
dRion(:,ia,iter+1)=2*dRion(:,ia,iter)-dRion(:,ia,iter-1)+force(:,ia)*dt**2/(umass*Mass(Kion(ia)))
Rion(:,ia)=Rion_eq(:,ia)+dRion(:,ia,iter+1)
Tion=Tion+0.5d0*umass*Mass(Kion(ia))*sum((dRion(:,ia,iter+1)-dRion(:,ia,iter-1))**2)/(2*dt)**2
enddo
call prep_ps_periodic('not_initial')
else
dRion(:,:,iter+1)=0.d0
Tion=0.d0
endif
Eall=Eall+Tion
!write section
if (iter/10*10 == iter.and.Myrank == 0) then
write(*,'(1x,f10.4,8f12.6,f22.14)') iter*dt,&
&E_ext(iter,1),E_tot(iter,1),&
&E_ext(iter,2),E_tot(iter,2),&
&E_ext(iter,3),E_tot(iter,3),&
&Eall,Eall-Eall0,Tion
write(7,'(1x,100e16.6E3)') iter*dt,&
&E_ext(iter,1),E_tot(iter,1),&
&E_ext(iter,2),E_tot(iter,2),&
&E_ext(iter,3),E_tot(iter,3),&
&Eall,Eall-Eall0,Tion
write(9,'(1x,100e16.6E3)') iter*dt,((force(ixyz,ia),ixyz=1,3),ia=1,NI),((dRion(ixyz,ia,iter),ixyz=1,3),ia=1,NI)
endif
#ifndef ARTED_DEBUG
!Dynamical Density
if (iter/100*100 == iter.and.Myrank == 0) then
write(8,'(1x,i10)') iter
do i=1,NL
write(8,'(1x,2e16.6E3)') rho(i),(rho(i)-rho_gs(i))
enddo
endif
#endif
!j_Ac writing
if(Myrank == 0)then
if (iter/1000*1000 == iter .or. iter == Nt) then
open(407,file=file_j_ac)
do i=0,Nt
write(407,'(100e26.16E3)') i*dt,javt(i,1),javt(i,2),javt(i,3),&
&Ac_ext(i,1),Ac_ext(i,2),Ac_ext(i,3),Ac_tot(i,1),Ac_tot(i,2),Ac_tot(i,3)
end do
write(407,'(100e26.16E3)') (Nt+1)*dt,javt(Nt,1),javt(Nt,2),javt(Nt,3),&
&Ac_ext(Nt+1,1),Ac_ext(Nt+1,2),Ac_ext(Nt+1,3),Ac_tot(Nt+1,1),Ac_tot(Nt+1,2),Ac_tot(Nt+1,3)
close(407)
end if
end if
!Adiabatic evolution
if (AD_RHO /= 'No' .and. iter/100*100 == iter) then
call k_shift_wf(Rion_update,2)
if (Myrank == 0) then
do ia=1,NI
write(*,'(1x,i7,3f15.6)') ia,force(1,ia),force(2,ia),force(3,ia)
end do
write(404,'(1x,i10)') iter
do ik=1,NK
write(404,'(1x,i5,500e16.6)')ik,(ovlp_occ(ib,ik)*NKxyz,ib=1,NB)
enddo
write(408,'(1x,3e16.6E3)') iter*dt,sum(ovlp_occ(NBoccmax+1:NB,:)),sum(occ)-sum(ovlp_occ(1:NBoccmax,:))
write(*,*) 'number of excited electron',sum(ovlp_occ(NBoccmax+1:NB,:)),sum(occ)-sum(ovlp_occ(1:NBoccmax,:))
write(*,*) 'var_tot,var_max=',sum(esp_var(:,:))/(NK*Nelec/2),maxval(esp_var(:,:))
end if
end if
!Timer
if (iter/1000*1000 == iter.and.Myrank == 0) then
etime2=MPI_WTIME()
call timelog_set(LOG_DYNAMICS, etime2 - etime1)
call timelog_show_hour('dynamics time :', LOG_DYNAMICS)
call timelog_show_min ('dt_evolve time :', LOG_DT_EVOLVE)
call timelog_show_min ('Hartree time :', LOG_HARTREE)
call timelog_show_min ('current time :', LOG_CURRENT)
end if
!Timer for shutdown
if (iter/10*10 == iter) then
Time_now=MPI_WTIME()
call MPI_BCAST(Time_now,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
if (Myrank == 0 .and. iter/100*100 == iter) then
write(*,*) 'Total time =',(Time_now-Time_start)
end if
if ((Time_now - Time_start)>Time_shutdown) then
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
write(*,*) Myrank,'iter =',iter
iter_now=iter
call prep_Reentrance_write
go to 1
end if
end if
call timelog_end(LOG_OTHER)
enddo !end of RT iteraction========================
etime2=MPI_WTIME()
#ifdef ARTED_USE_PAPI
call papi_end
#endif
call timelog_disable_verbose
if(Myrank == 0) then
call timelog_set(LOG_DYNAMICS, etime2 - etime1)
#ifdef ARTED_USE_PAPI
call papi_result(timelog_get(LOG_DYNAMICS))
#endif
call timelog_show_hour('dynamics time :', LOG_DYNAMICS)
call timelog_show_min ('dt_evolve time :', LOG_DT_EVOLVE)
call timelog_show_min ('hpsi time :', LOG_HPSI)
call timelog_show_min (' - init time :', LOG_HPSI_INIT)
call timelog_show_min (' - stencil time :', LOG_HPSI_STENCIL)
call timelog_show_min (' - pseudo pt. time :', LOG_HPSI_PSEUDO)
call timelog_show_min (' - update time :', LOG_HPSI_UPDATE)
print *, ' - stencil GFLOPS :', get_stencil_gflops(timelog_get(LOG_HPSI_STENCIL))
#ifdef ARTED_PROFILE_THREADS
call write_threads_performance
#endif
call timelog_show_min ('psi_rho time :', LOG_PSI_RHO)
call timelog_show_min ('Hartree time :', LOG_HARTREE)
call timelog_show_min ('Exc_Cor time :', LOG_EXC_COR)
call timelog_show_min ('current time :', LOG_CURRENT)
call timelog_show_min ('Total_Energy time :', LOG_TOTAL_ENERGY)
call timelog_show_min ('Ion_Force time :', LOG_ION_FORCE)
call timelog_show_min ('Other time :', LOG_OTHER)
end if
if(Myrank == 0) then
close(7)
close(8)
close(9)
if (AD_RHO /= 'No') then
close(404)
close(408)
end if
endif
if(Myrank == 0) write(*,*) 'This is the end of RT calculation'
#ifdef ARTED_DEBUG
call err_finalize('force shutdown.')
#endif
!====RT calculation===========================
!====Analyzing calculation====================
!Adiabatic evolution
call k_shift_wf_last(Rion_update,10)
call Fourier_tr
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
if (Myrank == 0) write(*,*) 'This is the end of all calculation'
Time_now=MPI_WTIME()
if (Myrank == 0 ) write(*,*) 'Total time =',(Time_now-Time_start)
1 if(Myrank == 0) write(*,*) 'This calculation is shutdown successfully!'
call MPI_FINALIZE(ierr)
End Program Main
!--------10--------20--------30--------40--------50--------60--------70--------80--------90--------100-------110-------120--------130
Subroutine Read_data
use Global_Variables
use opt_variables, only: symmetric_load_balancing, is_symmetric_mode
use environment
implicit none
integer :: ia,i,j
if (Myrank == 0) then
write(*,*) 'Nprocs=',Nprocs
write(*,*) 'Myrank=0: ',Myrank
read(*,*) entrance_option
write(*,*) 'entrance_option=',entrance_option
read(*,*) Time_shutdown
write(*,*) 'Time_shutdown=',Time_shutdown,'sec'
end if
call MPI_BCAST(entrance_option,10,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Time_shutdown,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
if(entrance_option == 'reentrance') then
call prep_Reentrance_Read
return
else if(entrance_option == 'new') then
else
call err_finalize('entrance_option /= new or reentrance')
end if
if(Myrank == 0)then
read(*,*) entrance_iter
read(*,*) SYSname
read(*,*) directory
!yabana
read(*,*) functional, cval
!yabana
read(*,*) ps_format !shinohara
read(*,*) PSmask_option !shinohara
read(*,*) alpha_mask, gamma_mask, eta_mask !shinohara
read(*,*) aL,ax,ay,az
read(*,*) Sym,crystal_structure ! sym
read(*,*) Nd,NLx,NLy,NLz,NKx,NKy,NKz
read(*,*) NEwald, aEwald
read(*,*) KbTev ! sato
write(*,*) 'entrance_iter=',entrance_iter
write(*,*) SYSname
write(*,*) directory
!yabana
write(*,*) 'functional=',functional
if(functional == 'TBmBJ') write(*,*) 'cvalue=',cval
!yabana
write(*,*) 'ps_format =',ps_format !shinohara
write(*,*) 'PSmask_option =',PSmask_option !shinohara
write(*,*) 'alpha_mask, gamma_mask, eta_mask =',alpha_mask, gamma_mask, eta_mask !shinohara
file_GS=trim(directory)//trim(SYSname)//'_GS.out'
file_RT=trim(directory)//trim(SYSname)//'_RT.out'
file_epst=trim(directory)//trim(SYSname)//'_t.out'
file_epse=trim(directory)//trim(SYSname)//'_e.out'
file_force_dR=trim(directory)//trim(SYSname)//'_force_dR.out'
file_j_ac=trim(directory)//trim(SYSname)//'_j_ac.out'
file_DoS=trim(directory)//trim(SYSname)//'_DoS.out'
file_band=trim(directory)//trim(SYSname)//'_band.out'
file_dns=trim(directory)//trim(SYSname)//'_dns.out'
file_ovlp=trim(directory)//trim(SYSname)//'_ovlp.out'
file_nex=trim(directory)//trim(SYSname)//'_nex.out'
write(*,*) 'aL,ax,ay,az=',aL,ax,ay,az
write(*,*) 'Sym=',Sym,'crystal structure=',crystal_structure !sym
write(*,*) 'Nd,NLx,NLy,NLz,NKx,NKy,NKz=',Nd,NLx,NLy,NLz,NKx,NKy,NKz
write(*,*) 'NEwald, aEwald =',NEwald, aEwald
write(*,*) 'KbTev=',KbTev ! sato
end if
call MPI_BCAST(SYSname,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(directory,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
!yabana
call MPI_BCAST(functional,10,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(cval,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
!yabana
call MPI_BCAST(ps_format,10,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)!shinohara
call MPI_BCAST(PSmask_option,1,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)!shinohara
call MPI_BCAST(alpha_mask,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr) !shinohara
call MPI_BCAST(gamma_mask,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr) !shinohara
call MPI_BCAST(eta_mask,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr) !shinohara
call MPI_BCAST(file_GS,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_RT,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_epst,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_epse,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_force_dR,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_j_ac,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_DoS,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_band,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_dns,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_ovlp,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(file_nex,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(aL,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(ax,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(ay,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(az,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Sym,1,MPI_Integer,0,MPI_COMM_WORLD,ierr) !sym
call MPI_BCAST(crystal_structure,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Nd,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NLx,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NLy,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NLz,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NKx,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NKy,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NKz,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NEwald,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(aEwald,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(KbTev,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr) ! sato
!sym ---
select case(crystal_structure)
case("diamond")
if(functional == "PZ")then
if(Sym == 8)then
if((mod(NLx,4)+mod(NLy,4)+mod(NLz,4)) /= 0)call err_finalize('Bad grid point')
if(NLx /= NLy)call err_finalize('Bad grid point')
if(NKx /= NKy) call err_finalize('NKx /= NKy')
else if(Sym ==4 )then
if(NLx /= NLy)call err_finalize('Bad grid point')
if(NKx /= NKy) call err_finalize('NKx /= NKy')
else if(Sym /= 1)then
call err_finalize('Bad crystal structure')
end if
else if(functional == "TBmBJ")then
if(Sym == 4)then
if(NLx /= NLy)call err_finalize('Bad grid point')
if(NKx /= NKy) call err_finalize('NKx /= NKy')
else if(Sym /= 1)then
call err_finalize('Bad crystal structure')
end if
else
if(Sym /= 1)call err_finalize('Bad crystal structure')
end if
case default
if(Sym /= 1)call err_finalize('Bad symmetry')
end select
!sym ---
if(mod(NKx,2)+mod(NKy,2)+mod(NKz,2) /= 0) call err_finalize('NKx,NKy,NKz /= even')
if(mod(NLx,2)+mod(NLy,2)+mod(NLz,2) /= 0) call err_finalize('NLx,NLy,NLz /= even')
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
aLx=ax*aL; aLy=ay*aL; aLz=az*aL
aLxyz=aLx*aLy*aLz
bLx=2*Pi/aLx; bLy=2*Pi/aLy; bLz=2*Pi/aLz
Hx=aLx/NLx; Hy=aLy/NLy; Hz=aLz/NLz
Hxyz=Hx*Hy*Hz
NL=NLx*NLy*NLz
NG=NL
NKxyz=NKx*NKy*NKz
select case(Sym)
case(1)
NK=NKx*NKy*NKz
case(4)
NK=(NKx/2)*(NKy/2)*NKz
case(8)
NK=NKz*(NKx/2)*((NKx/2)+1)/2
end select
NK_ave=NK/Nprocs; NK_remainder=NK-NK_ave*Nprocs
NG_ave=NG/Nprocs; NG_remainder=NG-NG_ave*Nprocs
if(is_symmetric_mode() == 1 .and. ENABLE_LOAD_BALANCER == 1) then
call symmetric_load_balancing(NK,NK_ave,NK_s,NK_e,NK_remainder,Myrank,Nprocs)
else
if (NK/Nprocs*Nprocs == NK) then
NK_s=NK_ave*Myrank+1
NK_e=NK_ave*(Myrank+1)
else
if (Myrank < (Nprocs-1) - NK_remainder + 1) then
NK_s=NK_ave*Myrank+1
NK_e=NK_ave*(Myrank+1)
else
NK_s=NK-(NK_ave+1)*((Nprocs-1)-Myrank)-NK_ave
NK_e=NK-(NK_ave+1)*((Nprocs-1)-Myrank)
end if
end if
if(Myrank == Nprocs-1 .and. NK_e /= NK) call err_finalize('prep. NK_e error')
end if
if (NG/Nprocs*Nprocs == NG) then
NG_s=NG_ave*Myrank+1
NG_e=NG_ave*(Myrank+1)
else
if (Myrank < (Nprocs-1) - NG_remainder + 1) then
NG_s=NG_ave*Myrank+1
NG_e=NG_ave*(Myrank+1)
else
NG_s=NG-(NG_ave+1)*((Nprocs-1)-Myrank)-NG_ave
NG_e=NG-(NG_ave+1)*((Nprocs-1)-Myrank)
end if
end if
if(Myrank == Nprocs-1 .and. NG_e /= NG) call err_finalize('prep. NG_e error')
allocate(lap(-Nd:Nd),nab(-Nd:Nd))
allocate(lapx(-Nd:Nd),lapy(-Nd:Nd),lapz(-Nd:Nd))
allocate(nabx(-Nd:Nd),naby(-Nd:Nd),nabz(-Nd:Nd))
allocate(Lx(NL),Ly(NL),Lz(NL),Gx(NG),Gy(NG),Gz(NG))
allocate(Lxyz(0:NLx-1,0:NLy-1,0:NLz-1))
allocate(ifdx(-Nd:Nd,1:NL),ifdy(-Nd:Nd,1:NL),ifdz(-Nd:Nd,1:NL))
allocate(kAc(NK,3),kAc0(NK,3))
allocate(Vh(NL),Vexc(NL),Eexc(NL),rho(NL),Vpsl(NL),Vloc(NL),Vloc_GS(NL),Vloc_t(NL))
!yabana
allocate(tmass(NL),tjr(NL,3),tjr2(NL),tmass_t(NL),tjr_t(NL,3),tjr2_t(NL))
!yabana
allocate(rhoe_G(NG_s:NG_e),rhoion_G(NG_s:NG_e))
allocate(rho_gs(NL))
allocate(tpsi(NL),htpsi(NL),ttpsi(NL))
allocate(tpsi_omp(NL,0:NUMBER_THREADS-1),htpsi_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(ttpsi_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(xk_omp(NL,0:NUMBER_THREADS-1),hxk_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(gk_omp(NL,0:NUMBER_THREADS-1),pk_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(pko_omp(NL,0:NUMBER_THREADS-1),txk_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(tau_s_l_omp(NL,0:NUMBER_THREADS-1),j_s_l_omp(NL,3,0:NUMBER_THREADS-1)) ! sato
allocate(work(-Nd:NLx+Nd-1,-Nd:NLy+Nd-1,-Nd:NLz+Nd-1))
allocate(zwork(-Nd:NLx+Nd-1,-Nd:NLy+Nd-1,-Nd:NLz+Nd-1))
allocate(nxyz(-NLx/2:NLx/2-1,-NLy/2:NLy/2-1,-NLz/2:NLz/2-1)) !Hartree
allocate(rho_3D(0:NLx-1,0:NLy-1,0:NLz-1),Vh_3D(0:NLx-1,0:NLy-1,0:NLz-1))!Hartree
allocate(rhoe_G_temp(1:NG),rhoe_G_3D(-NLx/2:NLx/2-1,-NLy/2:NLy/2-1,-NLz/2:NLz/2-1))!Hartree
allocate(f1(0:NLx-1,0:NLy-1,-NLz/2:NLz/2-1),f2(0:NLx-1,-NLy/2:NLy/2-1,-NLz/2:NLz/2-1))!Hartree
allocate(f3(-NLx/2:NLx/2-1,-NLy/2:NLy/2-1,0:NLz-1),f4(-NLx/2:NLx/2-1,0:NLy-1,0:NLz-1))!Hartree
allocate(eGx(-NLx/2:NLx/2-1,0:NLx-1),eGy(-NLy/2:NLy/2-1,0:NLy-1),eGz(-NLz/2:NLz/2-1,0:NLz-1))!Hartree
allocate(eGxc(-NLx/2:NLx/2-1,0:NLx-1),eGyc(-NLy/2:NLy/2-1,0:NLy-1),eGzc(-NLz/2:NLz/2-1,0:NLz-1))!Hartree
allocate(itable_sym(Sym,NL)) ! sym
allocate(rho_l(NL),rho_tmp1(NL),rho_tmp2(NL)) !sym
if (Myrank == 0) then
read(*,*) NB,Nelec
write(*,*) 'NB,Nelec=',NB,Nelec
endif
if( kbTev < 0d0 )then ! sato
NBoccmax=Nelec/2
else
NBoccmax=NB
end if
call MPI_BCAST(Nelec,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr) ! sato
call MPI_BCAST(NB,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NBoccmax,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
NKB=(NK_e-NK_s+1)*NBoccmax ! sato
allocate(occ(NB,NK),wk(NK),esp(NB,NK))
allocate(ovlp_occ_l(NB,NK),ovlp_occ(NB,NK))
allocate(zu_GS(NL,NB,NK_s:NK_e),zu_GS0(NL,NB,NK_s:NK_e))
allocate(zu(NL,NBoccmax,NK_s:NK_e))
allocate(ik_table(NKB),ib_table(NKB)) ! sato
allocate(esp_var(NB,NK))
allocate(NBocc(NK)) !redistribution
NBocc(:)=NBoccmax
allocate(esp_vb_min(NK),esp_vb_max(NK)) !redistribution
allocate(esp_cb_min(NK),esp_cb_max(NK)) !redistribution
if (Myrank == 0) then
read(*,*) FSset_option
read(*,*) Ncg
read(*,*) Nmemory_MB,alpha_MB
read(*,*) NFSset_start,NFSset_every
read(*,*) Nscf
read(*,*) ext_field
read(*,*) Longi_Trans
read(*,*) MD_option
read(*,*) AD_RHO
read(*,*) Nt,dt
write(*,*) 'FSset_option =',FSset_option
write(*,*) 'Ncg=',Ncg
write(*,*) 'Nmemory_MB,alpha_MB =',Nmemory_MB,alpha_MB
write(*,*) 'NFSset_start,NFSset_every =',NFSset_start,NFSset_every
write(*,*) 'Nscf=',Nscf
write(*,*) 'ext_field =',ext_field
write(*,*) 'Longi_Trans =',Longi_Trans
write(*,*) 'MD_option =', MD_option
write(*,*) 'AD_RHO =', AD_RHO
write(*,*) 'Nt,dt=',Nt,dt
endif
call MPI_BCAST(FSset_option,1,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Ncg,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Nmemory_MB,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(alpha_MB,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NFSset_start,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NFSset_every,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Nscf,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(ext_field,2,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Longi_Trans,2,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(MD_option,1,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(AD_RHO,2,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Nt,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(dt,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(entrance_option,12,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
! call MPI_BCAST(Time_shutdown,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(entrance_iter,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
if(ext_field /= 'LF' .and. ext_field /= 'LR' ) call err_finalize('incorrect option for ext_field')
if(Longi_Trans /= 'Lo' .and. Longi_Trans /= 'Tr' ) call err_finalize('incorrect option for Longi_Trans')
if(AD_RHO /= 'TD' .and. AD_RHO /= 'GS' .and. AD_RHO /= 'No' ) call err_finalize('incorrect option for Longi_Trans')
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
allocate(javt(0:Nt,3))
allocate(Ac_ext(-1:Nt+1,3),Ac_ind(-1:Nt+1,3),Ac_tot(-1:Nt+1,3))
allocate(E_ext(0:Nt,3),E_ind(0:Nt,3),E_tot(0:Nt,3))
if (Myrank == 0) then
read(*,*) dAc
read(*,*) Nomega,domega
read(*,*) AE_shape
read(*,*) IWcm2_1,tpulsefs_1,omegaev_1,phi_CEP_1
read(*,*) Epdir_1(1),Epdir_1(2),Epdir_1(3)
read(*,*) IWcm2_2,tpulsefs_2,omegaev_2,phi_CEP_2
read(*,*) Epdir_2(1),Epdir_2(2),Epdir_2(3)
read(*,*) T1_T2fs
read(*,*) NI,NE
write(*,*) 'dAc=',dAc
write(*,*) 'Nomega,etep=',Nomega,domega
write(*,*) 'AE_shape=',AE_shape
write(*,*) 'IWcm2_1, tpulsefs_1, omegaev_1, phi_CEP_1 =',IWcm2_1,tpulsefs_1,omegaev_1,phi_CEP_1
write(*,*) 'Epdir_1(1), Epdir_1(2), Epdir_1(3) =', Epdir_1(1),Epdir_1(2),Epdir_1(3)
write(*,*) 'IWcm2_2, tpulsefs_2, omegaev_2, phi_CEP_2 =',IWcm2_2,tpulsefs_2,omegaev_2,phi_CEP_2
write(*,*) 'Epdir_2(1), Epdir_2(2), Epdir_2(3) =', Epdir_2(1),Epdir_2(2),Epdir_2(3)
write(*,*) 'T1_T2fs =', T1_T2fs
write(*,*) ''
write(*,*) '===========ion configuration================'
write(*,*) 'NI,NE=',NI,NE
endif
call MPI_BCAST(dAc,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Nomega,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(domega,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(AE_shape,8,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(IWcm2_1,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(tpulsefs_1,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(omegaev_1,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(phi_CEP_1,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Epdir_1,3,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(IWcm2_2,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(tpulsefs_2,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(omegaev_2,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(phi_CEP_2,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Epdir_2,3,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(T1_T2fs,1,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NI,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(NE,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
if(AE_shape /= 'Asin2cos' .and. AE_shape /= 'Esin2sin' &
&.and. AE_shape /= 'input' .and. AE_shape /= 'Asin2_cw' ) call err_finalize('incorrect option for AE_shape')
allocate(Zatom(NE),Kion(NI),Rps(NE),NRps(NE))
allocate(Rion(3,NI),Rion_eq(3,NI),dRion(3,NI,-1:Nt+1))
allocate(Zps(NE),NRloc(NE),Rloc(NE),Mass(NE),force(3,NI))
allocate(dVloc_G(NG_s:NG_e,NE),force_ion(3,NI))
allocate(Mps(NI),Lref(NE),Mlps(NE))
allocate(anorm(0:Lmax,NE),inorm(0:Lmax,NE))
allocate(rad(Nrmax,NE),vloctbl(Nrmax,NE),dvloctbl(Nrmax,NE))
allocate(radnl(Nrmax,NE))
allocate(udVtbl(Nrmax,0:Lmax,NE),dudVtbl(Nrmax,0:Lmax,NE))
allocate(Floc(3,NI),Fnl(3,NI),Fion(3,NI))
if (Myrank == 0) then
read(*,*) (Zatom(j),j=1,NE)
read(*,*) (Lref(j),j=1,NE)
do ia=1,NI
read(*,*) i,(Rion(j,ia),j=1,3),Kion(ia)
enddo
write(*,*) 'Zatom=',(Zatom(j),j=1,NE)
write(*,*) 'Lref=',(Lref(j),j=1,NE)
write(*,*) 'i,Kion(ia)','(Rion(j,a),j=1,3)'
do ia=1,NI
write(*,*) ia,Kion(ia)
write(*,'(3f12.8)') (Rion(j,ia),j=1,3)
end do
endif
call MPI_BCAST(Zatom,NE,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Kion,NI,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Lref,NE,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
call MPI_BCAST(Rion,3*NI,MPI_REAL8,0,MPI_COMM_WORLD,ierr)
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
Rion(1,:)=Rion(1,:)*aLx
Rion(2,:)=Rion(2,:)*aLy
Rion(3,:)=Rion(3,:)*aLz
return
End Subroutine Read_data
!--------10--------20--------30--------40--------50--------60--------70--------80--------90--------100-------110-------120--------130
subroutine prep_Reentrance_Read
use Global_Variables
use timelog, only: timelog_reentrance_read
use opt_variables, only: opt_vars_initialize_p1, opt_vars_initialize_p2
implicit none
real(8) :: time_in,time_out
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
time_in=MPI_WTIME()
if(Myrank == 0) then
read(*,*) directory
end if
call MPI_BCAST(directory,50,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
write(cMyrank,'(I5.5)')Myrank
file_reentrance=trim(directory)//'tmp_re.'//trim(cMyrank)
open(500,file=file_reentrance,form='unformatted')
read(500) iter_now,entrance_iter
! need to exclude from reading data:
! Time_shutdown, Time_start, Time_now,iter_now,entrance_iter,entrance_option
!======== read section ===========================
!== read data ===!
!ARTED version
! character(50),parameter :: ARTED_ver='ARTED_sc.2014.08.10.0'
! constants
! real(8),parameter :: Pi=3.141592653589793d0
! complex(8),parameter :: zI=(0.d0,1.d0)
! real(8),parameter :: a_B=0.529177d0,Ry=13.6058d0
! real(8),parameter :: umass=1822.9d0
!yabana
!! DFT parameters
! real(8),parameter :: gammaU=-0.1423d0,beta1U=1.0529d0
! real(8),parameter :: beta2U=0.3334d0,AU=0.0311d0,BU=-0.048d0
! real(8),parameter :: CU=0.002d0,DU=-0.0116d0
!yabana
! grid
read(500) NLx,NLy,NLz,Nd,NL,NG,NKx,NKy,NKz,NK,Sym,nGzero
read(500) NKxyz
read(500) aL,ax,ay,az,aLx,aLy,aLz,aLxyz
read(500) bLx,bLy,bLz,Hx,Hy,Hz,Hxyz
! pseudopotential
! integer,parameter :: Nrmax=3000,Lmax=4
read(500) ps_type
read(500) ps_format !shinohara
read(500) PSmask_option != 'n' !shinohara
read(500) alpha_mask, gamma_mask, eta_mask!shinohara
read(500) Nps,Nlma
! material
read(500) NI,NE,NB,NBoccmax
read(500) Ne_tot
! physical quantities
read(500) Eall,Eall0,jav(3),Tion
read(500) Ekin,Eloc,Enl,Eh,Exc,Eion,Eelemag
!yabana
read(500) Nelec !FS set
! Bloch momentum,laser pulse, electric field
! real(8) :: f0,Wcm2,pulseT,wave_length,omega,pulse_time,pdir(3),phi_CEP=0.00*2*pi
read(500) AE_shape
read(500) f0_1,IWcm2_1,tpulsefs_1,omegaev_1,omega_1,tpulse_1,Epdir_1(3),phi_CEP_1 ! sato
read(500) f0_2,IWcm2_2,tpulsefs_2,omegaev_2,omega_2,tpulse_2,Epdir_2(3),phi_CEP_2 ! sato
read(500) T1_T2fs,T1_T2
! control parameters
read(500) NEwald !Ewald summation
read(500) aEwald
read(500) Ncg !# of conjugate gradient (cg)
read(500) dt,dAc,domega
read(500) Nscf,Nt,Nomega
read(500) Nmemory_MB !Modified-Broyden (MB) method
read(500) alpha_MB
read(500) NFSset_start,NFSset_every !Fermi Surface (FS) set
! file names, flags, etc
read(500) SYSname,directory
read(500) file_GS,file_RT
read(500) file_epst,file_epse
read(500) file_force_dR,file_j_ac
read(500) file_DoS,file_band
read(500) file_dns,file_ovlp,file_nex
read(500) ext_field
read(500) Longi_Trans
read(500) FSset_option,MD_option
read(500) AD_RHO !ovlp_option
!yabana
read(500) functional
read(500) cval ! cvalue for TBmBJ. If cval<=0, calculated in the program
!yabana
! MPI
! include 'mpif.h'
! read(500) Myrank,Nprocs,ierr
! read(500) NEW_COMM_WORLD,NEWPROCS,NEWRANK ! sato
read(500) NK_ave,NG_ave,NK_s,NK_e,NG_s,NG_e
read(500) NK_remainder,NG_remainder
read(500) etime1,etime2
! Timer
! read(500) Time_shutdown
! read(500) Time_start,Time_now
! read(500) iter_now,entrance_iter
! read(500) entrance_option !initial or reentrance
read(500) position_option
! omp
! integer :: NUMBER_THREADS
read(500) NKB
! sym
read(500) crystal_structure !sym
! Finite temperature
read(500) KbTev
! For reentrance
read(500) cMyrank,file_reentrance
! allocatable
allocate(Lx(NL),Ly(NL),Lz(NL),Gx(NG),Gy(NG),Gz(NG))
allocate(ifdx(-Nd:Nd,1:NL),ifdy(-Nd:Nd,1:NL),ifdz(-Nd:Nd,1:NL))
allocate(lap(-Nd:Nd),nab(-Nd:Nd))
allocate(lapx(-Nd:Nd),lapy(-Nd:Nd),lapz(-Nd:Nd))
allocate(nabx(-Nd:Nd),naby(-Nd:Nd),nabz(-Nd:Nd))
allocate(Lxyz(0:NLx-1,0:NLy-1,0:NLz-1))
read(500) Lx(:),Ly(:),Lz(:),Lxyz(:,:,:)
read(500) ifdx(:,:),ifdy(:,:),ifdz(:,:)
read(500) Gx(:),Gy(:),Gz(:)
read(500) lap(:),nab(:)
read(500) lapx(:),lapy(:),lapz(:)
read(500) nabx(:),naby(:),nabz(:)
allocate(Mps(NI),Jxyz(Nps,NI),Jxx(Nps,NI),Jyy(Nps,NI),Jzz(Nps,NI))
allocate(Mlps(NE),Lref(NE),Zps(NE),NRloc(NE))
allocate(NRps(NE),inorm(0:Lmax,NE),iuV(Nlma),a_tbl(Nlma))
allocate(rad(Nrmax,NE),Rps(NE),vloctbl(Nrmax,NE),udVtbl(Nrmax,0:Lmax,NE))
allocate(radnl(Nrmax,NE))
allocate(Rloc(NE),uV(Nps,Nlma),duV(Nps,Nlma,3),anorm(0:Lmax,NE))
allocate(dvloctbl(Nrmax,NE),dudVtbl(Nrmax,0:Lmax,NE))
read(500) Mps(:),Jxyz(:,:),Jxx(:,:),Jyy(:,:),Jzz(:,:)
read(500) Mlps(:),Lref(:),Zps(:),NRloc(:)
read(500) NRps(:),inorm(:,:),iuV(:),a_tbl(:)
read(500) rad(:,:),Rps(:),vloctbl(:,:),udVtbl(:,:,:)
read(500) radnl(:,:)
read(500) Rloc(:),uV(:,:),duV(:,:,:),anorm(:,:)
read(500) dvloctbl(:,:),dudVtbl(:,:,:)
allocate(Zatom(NE),Kion(NI))
allocate(Rion(3,NI),Mass(NE),Rion_eq(3,NI),dRion(3,NI,-1:Nt+1))
allocate(occ(NB,NK),wk(NK))
read(500) Zatom(:),Kion(:)
read(500) Rion(:,:),Mass(:),Rion_eq(:,:),dRion(:,:,:)
read(500) occ(:,:),wk(:)
allocate(javt(0:Nt,3))
allocate(Vpsl(NL),Vh(NL),Vexc(NL),Eexc(NL),Vloc(NL),Vloc_GS(NL),Vloc_t(NL))
allocate(tmass(NL),tjr(NL,3),tjr2(NL),tmass_t(NL),tjr_t(NL,3),tjr2_t(NL))
allocate(dVloc_G(NG_s:NG_e,NE))
allocate(rho(NL),rho_gs(NL))
allocate(rhoe_G(NG_s:NG_e),rhoion_G(NG_s:NG_e))
allocate(force(3,NI),esp(NB,NK),force_ion(3,NI))
allocate(Floc(3,NI),Fnl(3,NI),Fion(3,NI))
allocate(ovlp_occ_l(NB,NK),ovlp_occ(NB,NK))
read(500) javt(:,:)
read(500) Vpsl(:),Vh(:),Vexc(:),Eexc(:),Vloc(:),Vloc_GS(:),Vloc_t(:)
read(500) tmass(:),tjr(:,:),tjr2(:),tmass_t(:),tjr_t(:,:),tjr2_t(:)
read(500) dVloc_G(:,:)
read(500) rho(:),rho_gs(:)
! real(8),allocatable :: rho_in(:,:),rho_out(:,:) !MB method
read(500) rhoe_G(:),rhoion_G(:)
read(500) force(:,:),esp(:,:),force_ion(:,:)
read(500) Floc(:,:),Fnl(:,:),Fion(:,:)
read(500) ovlp_occ_l(:,:),ovlp_occ(:,:)
allocate(NBocc(NK)) !redistribution
allocate(esp_vb_min(NK),esp_vb_max(NK)) !redistribution
allocate(esp_cb_min(NK),esp_cb_max(NK)) !redistribution
! allocate(Eall_GS(0:Nscf),esp_var_ave(1:Nscf),esp_var_max(1:Nscf),dns_diff(1:Nscf))
read(500) NBocc(:) !FS set
read(500) esp_vb_min(:),esp_vb_max(:) !FS set
read(500) esp_cb_min(:),esp_cb_max(:) !FS set
! read(500) Eall_GS(:),esp_var_ave(:),esp_var_max(:),dns_diff(:)
allocate(zu_GS(NL,NB,NK_s:NK_e),zu_GS0(NL,NB,NK_s:NK_e))
allocate(zu(NL,NBoccmax,NK_s:NK_e))
allocate(tpsi(NL),htpsi(NL),zwork(-Nd:NLx+Nd-1,-Nd:NLy+Nd-1,-Nd:NLz+Nd-1),ttpsi(NL))
allocate(work(-Nd:NLx+Nd-1,-Nd:NLy+Nd-1,-Nd:NLz+Nd-1))
allocate(esp_var(NB,NK))
! wave functions, work array
read(500) zu(:,:,:),zu_GS(:,:,:),zu_GS0(:,:,:)
! read(500) tpsi(:),htpsi(:),zwork(:,:,:),ttpsi(:)
! read(500) work(:,:,:)
read(500) esp_var(:,:)
allocate(nxyz(-NLx/2:NLx/2-1,-NLy/2:NLy/2-1,-NLz/2:NLz/2-1)) !Hartree
allocate(rho_3D(0:NLx-1,0:NLy-1,0:NLz-1),Vh_3D(0:NLx-1,0:NLy-1,0:NLz-1))!Hartree
allocate(rhoe_G_temp(1:NG),rhoe_G_3D(-NLx/2:NLx/2-1,-NLy/2:NLy/2-1,-NLz/2:NLz/2-1))!Hartree
allocate(f1(0:NLx-1,0:NLy-1,-NLz/2:NLz/2-1),f2(0:NLx-1,-NLy/2:NLy/2-1,-NLz/2:NLz/2-1))!Hartree
allocate(f3(-NLx/2:NLx/2-1,-NLy/2:NLy/2-1,0:NLz-1),f4(-NLx/2:NLx/2-1,0:NLy-1,0:NLz-1))!Hartree
allocate(eGx(-NLx/2:NLx/2-1,0:NLx-1),eGy(-NLy/2:NLy/2-1,0:NLy-1),eGz(-NLz/2:NLz/2-1,0:NLz-1))!Hartree
allocate(eGxc(-NLx/2:NLx/2-1,0:NLx-1),eGyc(-NLy/2:NLy/2-1,0:NLy-1),eGzc(-NLz/2:NLz/2-1,0:NLz-1))!Hartree
! variables for 4-times loop in Fourier transportation
read(500) nxyz(:,:,:)
read(500) rho_3D(:,:,:),Vh_3D(:,:,:)
read(500) rhoe_G_temp(:),rhoe_G_3D(:,:,:)
read(500) f1(:,:,:),f2(:,:,:),f3(:,:,:),f4(:,:,:)
read(500) eGx(:,:),eGy(:,:),eGz(:,:),eGxc(:,:),eGyc(:,:),eGzc(:,:)
allocate(E_ext(0:Nt,3),E_ind(0:Nt,3),E_tot(0:Nt,3))
allocate(kAc(NK,3),kAc0(NK,3))
allocate(Ac_ext(-1:Nt+1,3),Ac_ind(-1:Nt+1,3),Ac_tot(-1:Nt+1,3))
read(500) E_ext(:,:),E_ind(:,:),E_tot(:,:)
read(500) kAc(:,:),kAc0(:,:) !k+A(t)/c (kAc)
read(500) Ac_ext(:,:),Ac_ind(:,:),Ac_tot(:,:) !A(t)/c (Ac)
allocate(ekr(Nps,NI)) ! sato
allocate(ekr_omp(Nps,NI,NK_s:NK_e))
allocate(tpsi_omp(NL,0:NUMBER_THREADS-1),htpsi_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(ttpsi_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(xk_omp(NL,0:NUMBER_THREADS-1),hxk_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(gk_omp(NL,0:NUMBER_THREADS-1),pk_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(pko_omp(NL,0:NUMBER_THREADS-1),txk_omp(NL,0:NUMBER_THREADS-1)) ! sato
allocate(ik_table(NKB),ib_table(NKB)) ! sato
! sato
read(500) ekr(:,:)
! omp
! integer :: NUMBER_THREADS
read(500) ekr_omp(:,:,:)
read(500) tpsi_omp(:,:),ttpsi_omp(:,:),htpsi_omp(:,:)
read(500) xk_omp(:,:),hxk_omp(:,:),gk_omp(:,:),pk_omp(:,:),pko_omp(:,:),txk_omp(:,:)
read(500) ik_table(:),ib_table(:)
allocate(tau_s_l_omp(NL,0:NUMBER_THREADS-1),j_s_l_omp(NL,3,0:NUMBER_THREADS-1)) ! sato
read(500) tau_s_l_omp(:,:),j_s_l_omp(:,:,:)
allocate(itable_sym(Sym,NL)) ! sym
allocate(rho_l(NL),rho_tmp1(NL),rho_tmp2(NL)) !sym
read(500) itable_sym(:,:) ! sym
read(500) rho_l(:),rho_tmp1(:),rho_tmp2(:) !sym
call timelog_reentrance_read(500)
call opt_vars_initialize_p1
call opt_vars_initialize_p2
!== read data ===!
close(500)
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
time_out=MPI_WTIME()
if(myrank == 0)write(*,*)'Reentrance time read =',time_out-time_in,' sec'
return
end subroutine prep_Reentrance_Read
!--------10--------20--------30--------40--------50--------60--------70--------80--------90--------100-------110-------120--------130
subroutine prep_Reentrance_write
use Global_Variables
use timelog, only: timelog_reentrance_write
implicit none
real(8) :: time_in,time_out
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
time_in=MPI_WTIME()
if (Myrank == 0) then
open(501,file=trim(directory)//trim(SYSname)//'_re.dat')
write(501,*) "'reentrance'"! entrance_option
write(501,*) Time_shutdown
write(501,*) "'"//trim(directory)//"'"
close(501)
end if
write(cMyrank,'(I5.5)')Myrank
file_reentrance=trim(directory)//'tmp_re.'//trim(cMyrank)
open(500,file=file_reentrance,form='unformatted')
write(500) iter_now,iter_now !iter_now=entrance_iter
!======== write section ===========================
!== write data ===!
! grid
write(500) NLx,NLy,NLz,Nd,NL,NG,NKx,NKy,NKz,NK,Sym,nGzero
write(500) NKxyz
write(500) aL,ax,ay,az,aLx,aLy,aLz,aLxyz
write(500) bLx,bLy,bLz,Hx,Hy,Hz,Hxyz
! pseudopotential
! integer,parameter :: Nrmax=3000,Lmax=4
write(500) ps_type
write(500) ps_format !shinohara
write(500) PSmask_option != 'n' !shinohara
write(500) alpha_mask, gamma_mask, eta_mask!shinohara
write(500) Nps,Nlma
! material
write(500) NI,NE,NB,NBoccmax
write(500) Ne_tot
! physical quantities
write(500) Eall,Eall0,jav(3),Tion
write(500) Ekin,Eloc,Enl,Eh,Exc,Eion,Eelemag
!yabana
write(500) Nelec !FS set
! Bloch momentum,laser pulse, electric field
! real(8) :: f0,Wcm2,pulseT,wave_length,omega,pulse_time,pdir(3),phi_CEP=0.00*2*pi
write(500) AE_shape
write(500) f0_1,IWcm2_1,tpulsefs_1,omegaev_1,omega_1,tpulse_1,Epdir_1(3),phi_CEP_1 ! sato
write(500) f0_2,IWcm2_2,tpulsefs_2,omegaev_2,omega_2,tpulse_2,Epdir_2(3),phi_CEP_2 ! sato
write(500) T1_T2fs,T1_T2
! control parameters
write(500) NEwald !Ewald summation
write(500) aEwald
write(500) Ncg
write(500) dt,dAc,domega
write(500) Nscf,Nt,Nomega
write(500) Nmemory_MB !Modified-Broyden (MB) method
write(500) alpha_MB
write(500) NFSset_start,NFSset_every !Fermi Surface (FS) set
! file names, flags, etc
write(500) SYSname,directory
write(500) file_GS,file_RT
write(500) file_epst,file_epse
write(500) file_force_dR,file_j_ac
write(500) file_DoS,file_band
write(500) file_dns,file_ovlp,file_nex
write(500) ext_field
write(500) Longi_Trans
write(500) FSset_option,MD_option
write(500) AD_RHO !ovlp_option
!yabana
write(500) functional
write(500) cval ! cvalue for TBmBJ. If cval<=0, calculated in the program
!yabana
! MPI
! include 'mpif.h'
! write(500) Myrank,Nprocs,ierr
! write(500) NEW_COMM_WORLD,NEWPROCS,NEWRANK ! sato
write(500) NK_ave,NG_ave,NK_s,NK_e,NG_s,NG_e
write(500) NK_remainder,NG_remainder
write(500) etime1,etime2
! Timer
! write(500) Time_shutdown
! write(500) Time_start,Time_now
! write(500) iter_now,entrance_iter
! write(500) entrance_option !initial or reentrance
write(500) position_option
! omp
! integer :: NUMBER_THWRITES
write(500) NKB
! sym
write(500) crystal_structure !sym
! Finite temperature
write(500) KbTev
! For reentrance
write(500) cMyrank,file_reentrance
! allocatable
write(500) Lx(:),Ly(:),Lz(:),Lxyz(:,:,:)
write(500) ifdx(:,:),ifdy(:,:),ifdz(:,:)
write(500) Gx(:),Gy(:),Gz(:)
write(500) lap(:),nab(:)
write(500) lapx(:),lapy(:),lapz(:)
write(500) nabx(:),naby(:),nabz(:)
write(500) Mps(:),Jxyz(:,:),Jxx(:,:),Jyy(:,:),Jzz(:,:)
write(500) Mlps(:),Lref(:),Zps(:),NRloc(:)
write(500) NRps(:),inorm(:,:),iuV(:),a_tbl(:)
write(500) rad(:,:),Rps(:),vloctbl(:,:),udVtbl(:,:,:)
write(500) radnl(:,:)
write(500) Rloc(:),uV(:,:),duV(:,:,:),anorm(:,:)
write(500) dvloctbl(:,:),dudVtbl(:,:,:)
write(500) Zatom(:),Kion(:)
write(500) Rion(:,:),Mass(:),Rion_eq(:,:),dRion(:,:,:)
write(500) occ(:,:),wk(:)
write(500) javt(:,:)
write(500) Vpsl(:),Vh(:),Vexc(:),Eexc(:),Vloc(:),Vloc_GS(:),Vloc_t(:)
write(500) tmass(:),tjr(:,:),tjr2(:),tmass_t(:),tjr_t(:,:),tjr2_t(:)
write(500) dVloc_G(:,:)
write(500) rho(:),rho_gs(:)
! real(8),allocatable :: rho_in(:,:),rho_out(:,:) !MB method
write(500) rhoe_G(:),rhoion_G(:)
write(500) force(:,:),esp(:,:),force_ion(:,:)
write(500) Floc(:,:),Fnl(:,:),Fion(:,:)
write(500) ovlp_occ_l(:,:),ovlp_occ(:,:)
write(500) NBocc(:) !FS set
write(500) esp_vb_min(:),esp_vb_max(:) !FS set
write(500) esp_cb_min(:),esp_cb_max(:) !FS set
! write(500) Eall_GS(:),esp_var_ave(:),esp_var_max(:),dns_diff(:)
! wave functions, work array
write(500) zu(:,:,:),zu_GS(:,:,:),zu_GS0(:,:,:)
! write(500) tpsi(:),htpsi(:),zwork(:,:,:),ttpsi(:)
! write(500) work(:,:,:)
write(500) esp_var(:,:)
! variables for 4-times loop in Fourier transportation
write(500) nxyz(:,:,:)
write(500) rho_3D(:,:,:),Vh_3D(:,:,:)
write(500) rhoe_G_temp(:),rhoe_G_3D(:,:,:)
write(500) f1(:,:,:),f2(:,:,:),f3(:,:,:),f4(:,:,:)
write(500) eGx(:,:),eGy(:,:),eGz(:,:),eGxc(:,:),eGyc(:,:),eGzc(:,:)
write(500) E_ext(:,:),E_ind(:,:),E_tot(:,:)
write(500) kAc(:,:),kAc0(:,:) !k+A(t)/c (kAc)
write(500) Ac_ext(:,:),Ac_ind(:,:),Ac_tot(:,:) !A(t)/c (Ac)
! sato
write(500) ekr(:,:)
! omp
! integer :: NUMBER_THWRITES
write(500) ekr_omp(:,:,:)
write(500) tpsi_omp(:,:),ttpsi_omp(:,:),htpsi_omp(:,:)
write(500) xk_omp(:,:),hxk_omp(:,:),gk_omp(:,:),pk_omp(:,:),pko_omp(:,:),txk_omp(:,:)
write(500) ik_table(:),ib_table(:)
write(500) tau_s_l_omp(:,:),j_s_l_omp(:,:,:)
write(500) itable_sym(:,:) ! sym
write(500) rho_l(:),rho_tmp1(:),rho_tmp2(:) !sym
call timelog_reentrance_write(500)
!== write data ===!
close(500)
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
time_out=MPI_WTIME()
if(myrank == 0)write(*,*)'Reentrance time write =',time_out-time_in,' sec'
return
end subroutine prep_Reentrance_write
!--------10--------20--------30--------40--------50--------60--------70--------80--------90--------100-------110-------120--------130
Subroutine err_finalize(err_message)
use Global_Variables
implicit none
character(*),intent(in) :: err_message
if (Myrank == 0) then
write(*,*) err_message
endif
call MPI_FINALIZE(ierr)
stop
End Subroutine Err_finalize
|
Require Import Coq.Arith.Arith.
Require Export Coq.Vectors.Vector.
Require Import Coq.Program.Equality. (* for dependent induction *)
Require Import Coq.Setoids.Setoid.
Require Import Coq.Logic.ProofIrrelevance.
(* CoLoR: `opam install coq-color` *)
Require Export CoLoR.Util.Vector.VecUtil.
Open Scope vector_scope.
(* Re-define :: List notation for vectors. Probably not such a good idea *)
Notation "h :: t" := (cons h t) (at level 60, right associativity)
: vector_scope.
Import VectorNotations.
Section VPermutation.
Variable A:Type.
Inductive VPermutation: forall n, vector A n -> vector A n -> Prop :=
| vperm_nil: VPermutation 0 [] []
| vperm_skip {n} x l l' : VPermutation n l l' -> VPermutation (S n) (x::l) (x::l')
| vperm_swap {n} x y l : VPermutation (S (S n)) (y::x::l) (x::y::l)
| vperm_trans {n} l l' l'' :
VPermutation n l l' -> VPermutation n l' l'' -> VPermutation n l l''.
Local Hint Constructors VPermutation : vperm_hints.
(** Some facts about [VPermutation] *)
Theorem VPermutation_nil : forall (l : vector A 0), VPermutation 0 [] l -> l = [].
Proof.
intros l HF.
dependent destruction l.
reflexivity.
Qed.
(** VPermutation over vectors is a equivalence relation *)
Theorem VPermutation_refl : forall {n} (l: vector A n), VPermutation n l l.
Proof.
induction l; constructor. exact IHl.
Qed.
Theorem VPermutation_sym : forall {n} (l l' : vector A n),
VPermutation n l l' -> VPermutation n l' l.
Proof.
intros n l l' Hperm.
induction Hperm; auto with vperm_hints.
apply vperm_trans with (l'0:=l'); auto.
Qed.
Theorem VPermutation_trans : forall {n} (l l' l'' : vector A n),
VPermutation n l l' -> VPermutation n l' l'' -> VPermutation n l l''.
Proof.
intros n l l' l''.
apply vperm_trans.
Qed.
End VPermutation.
Hint Resolve VPermutation_refl vperm_nil vperm_skip : vperm_hints.
(* These hints do not reduce the size of the problem to solve and they
must be used with care to avoid combinatoric explosions *)
Local Hint Resolve vperm_swap vperm_trans : vperm_hints.
Local Hint Resolve VPermutation_sym VPermutation_trans : vperm_hints.
(* This provides reflexivity, symmetry and transitivity and rewriting
on morphims to come *)
Instance VPermutation_Equivalence A n : Equivalence (@VPermutation A n) | 10 :=
{
Equivalence_Reflexive := @VPermutation_refl A n ;
Equivalence_Symmetric := @VPermutation_sym A n ;
Equivalence_Transitive := @VPermutation_trans A n
}.
Require Import Coq.Sorting.Permutation.
Require Import Helix.Util.VecUtil.
Section VPermutation_properties.
Variable A:Type.
Lemma ListVecPermutation {n} {l1 l2} {v1 v2}:
l1 = list_of_vec v1 ->
l2 = list_of_vec v2 ->
Permutation l1 l2 <->
VPermutation A n v1 v2.
Proof.
intros H1 H2.
split.
-
intros P; revert n v1 v2 H1 H2.
dependent induction P; intros n v1 v2 H1 H2.
+ dependent destruction v1; inversion H1; subst.
dependent destruction v2; inversion H2; subst.
apply vperm_nil.
+ dependent destruction v1; inversion H1; subst.
dependent destruction v2; inversion H2; subst.
apply vperm_skip.
now apply IHP.
+ do 2 (dependent destruction v1; inversion H1; subst).
do 2 (dependent destruction v2; inversion H2; subst).
apply list_of_vec_eq in H5; subst.
apply vperm_swap.
+ assert (n = length l').
{ pose proof (Permutation_length P1) as len.
subst.
now rewrite list_of_vec_length in len.
}
subst.
apply vperm_trans with (l' := vec_of_list l').
* apply IHP1; auto.
now rewrite list_of_vec_vec_of_list.
* apply IHP2; auto.
now rewrite list_of_vec_vec_of_list.
-
subst l1 l2.
intros P.
dependent induction P.
+
subst; auto.
+
simpl.
apply perm_skip.
apply IHP.
+
simpl.
apply perm_swap.
+
apply perm_trans with (l':=list_of_vec l'); auto.
Qed.
End VPermutation_properties.
Lemma Vsig_of_forall_cons
{A : Type}
{n : nat}
(P : A->Prop)
(x : A)
(l : vector A n)
(P1h : P x)
(P1x : @Vforall A P n l):
(@Vsig_of_forall A P (S n) (@cons A x n l) (@conj (P x) (@Vforall A P n l) P1h P1x)) =
(Vcons (@exist A P x P1h) (Vsig_of_forall P1x)).
Proof.
simpl.
f_equal.
apply subset_eq_compat.
reflexivity.
f_equal.
apply proof_irrelevance.
Qed.
Lemma VPermutation_Vsig_of_forall
{n: nat}
{A: Type}
(P: A->Prop)
(v1 v2 : vector A n)
(P1 : Vforall P v1)
(P2 : Vforall P v2):
VPermutation A n v1 v2
-> VPermutation {x : A | P x} n (Vsig_of_forall P1) (Vsig_of_forall P2).
Proof.
intros V.
revert P1 P2.
dependent induction V; intros P1 P2.
-
apply vperm_nil.
-
destruct P1 as [P1h P1x].
destruct P2 as [P2h P2x].
rewrite 2!Vsig_of_forall_cons.
replace P1h with P2h by apply proof_irrelevance.
apply vperm_skip.
apply IHV.
-
destruct P1 as [P1y [P1x P1l]].
destruct P2 as [P1x' [P1y' P1l']].
repeat rewrite Vsig_of_forall_cons.
replace P1y' with P1y by apply proof_irrelevance.
replace P1x' with P1x by apply proof_irrelevance.
replace P1l' with P1l by apply proof_irrelevance.
apply vperm_swap.
-
assert(Vforall P l').
{
apply Vforall_intro.
intros x H.
apply list_of_vec_in in H.
eapply ListVecPermutation in V1; auto.
apply Permutation_in with (l':=(list_of_vec l)) in H.
+
apply Vforall_lforall in P1.
apply ListUtil.lforall_in with (l:=(list_of_vec l)); auto.
+
symmetry.
auto.
}
(* Looks like a coq bug here. It should find H automatically *)
unshelve eauto with vperm_hints.
apply H.
Qed.
|
calc_T_k(reactor, R_0, B_0) = K_T(reactor) * B_0 * R_0
|
> module PNat.Properties
> import Syntax.PreorderReasoning
> import PNat.PNat
> import PNat.Operations
> import Nat.Positive
> import Unique.Predicates
> import Subset.Properties
> import Nat.LTProperties
> import Pairs.Operations
> %default total
> %access export
> ||| PNat is an implementation of DecEq
> implementation DecEq PNat where
> decEq (Element m pm) (Element n pn) with (decEq m n)
> | (Yes prf) = Yes (subsetEqLemma1 (Element m pm) (Element n pn) prf PositiveUnique)
> | (No contra) = No (\ prf => contra (getWitnessPreservesEq prf))
> ||| PNat is an implementation of Show
> implementation Show PNat where
> show = show . toNat
> |||
> predToNatLemma : (x : PNat) -> S (pred x) = toNat x
> predToNatLemma (Element _ (MkPositive {n})) = Refl
> |||
> toNatfromNatLemma : (m : Nat) -> (zLTm : Z `LT` m) -> toNat (fromNat m zLTm) = m
> {-
> toNatfromNatLemma Z zLTz = absurd zLTz
> toNatfromNatLemma (S m) _ = Refl
> ---}
> --{-
> toNatfromNatLemma m zLTm = Refl
> ---}
> |||
> toNatLTLemma : (x : PNat) -> Z `LT` toNat x
> toNatLTLemma x = s2 where
> s1 : Z `LT` (S (pred x))
> s1 = ltZS (pred x)
> s2 : Z `LT` (toNat x)
> s2 = replace (predToNatLemma x) s1
> |||
> toNatEqLemma : {x, y : PNat} -> (toNat x) = (toNat y) -> x = y
> toNatEqLemma {x} {y} p = subsetEqLemma1 x y p PositiveUnique
> |||
> -- toNatMultLemma : {x, y : PNat} -> toNat (x * y) = (toNat x) * (toNat y)
> toNatMultLemma : {x, y : PNat} -> toNat (x * y) = (toNat x) * (toNat y)
> toNatMultLemma {x = (Element m pm)} {y = (Element n pn)} = Refl
> |||
> multOneRightNeutral : (x : PNat) -> x * (Element 1 MkPositive) = x
> multOneRightNeutral (Element m pm) =
> ( (Element m pm) * (Element 1 MkPositive) )
> ={ Refl }=
> ( Element (m * 1) (multPreservesPositivity pm MkPositive) )
> ={ toNatEqLemma (multOneRightNeutral m) }=
> ( Element m pm )
> QED
> |||
> multCommutative : (x : PNat) -> (y : PNat) -> x * y = y * x
> multCommutative (Element m pm) (Element n pn) =
> let pmn = multPreservesPositivity pm pn in
> let pnm = multPreservesPositivity pn pm in
> ( Element (m * n) pmn )
> ={ toNatEqLemma (multCommutative m n) }=
> ( Element (n * m) pnm )
> QED
> |||
> multAssociative : (x : PNat) -> (y : PNat) -> (z : PNat) ->
> x * (y * z) = (x * y) * z
> multAssociative (Element m pm) (Element n pn) (Element o po) =
> let pno = multPreservesPositivity pn po in
> let pmno = multPreservesPositivity pm pno in
> let pmn = multPreservesPositivity pm pn in
> let pmno' = multPreservesPositivity pmn po in
> ( (Element m pm) * ((Element n pn) * (Element o po)) )
> ={ Refl }=
> ( (Element m pm) * (Element (n * o) pno) )
> ={ Refl }=
> ( Element (m * (n * o)) pmno )
> ={ toNatEqLemma (multAssociative m n o) }=
> ( Element ((m * n) * o) pmno' )
> ={ Refl }=
> ( (Element (m * n) pmn) * (Element o po) )
> ={ Refl }=
> ( ((Element m pm) * (Element n pn)) * (Element o po) )
> QED
> {-
> ---}
|
/*
* This file is open source software, licensed to you under the terms
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. 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.
*/
/*
* Copyright (C) 2020 ScyllaDB
*/
#define BOOST_TEST_MODULE parquet
#include <parquet4seastar/rle_encoding.hh>
#include <boost/test/included/unit_test.hpp>
#include <cstdint>
#include <cstring>
#include <random>
#include <vector>
#include <array>
using parquet4seastar::BitReader;
using parquet4seastar::RleDecoder;
BOOST_AUTO_TEST_CASE(BitReader_happy) {
constexpr int bit_width = 3;
std::array<uint8_t, 6> packed = {
0b10001000, 0b01000110, // {0, 1, 2, 3, 4} packed with bit width 3
0b10000000, 0b00000001, // 128 encoded as LEB128
0b11111111, 0b00000001, // -128 encoded as zigzag
};
std::array<int, 2> unpacked_1;
const std::array<int, 2> expected_1 = {0, 1};
std::array<int, 3> unpacked_2;
const std::array<int, 3> expected_2 = {2, 3, 4};
uint32_t unpacked_3;
const uint32_t expected_3 = 128;
int32_t unpacked_4;
const int32_t expected_4 = -128;
bool ok;
int values_read;
BitReader reader(packed.data(), packed.size());
values_read = reader.GetBatch(bit_width, unpacked_1.data(), expected_1.size());
BOOST_CHECK_EQUAL(values_read, expected_1.size());
BOOST_CHECK_EQUAL_COLLECTIONS(unpacked_1.begin(), unpacked_1.end(), expected_1.begin(), expected_1.end());
values_read = reader.GetBatch(bit_width, unpacked_2.data(), expected_2.size());
BOOST_CHECK_EQUAL(values_read, expected_2.size());
BOOST_CHECK_EQUAL_COLLECTIONS(unpacked_2.begin(), unpacked_2.end(), expected_2.begin(), expected_2.end());
ok = reader.GetVlqInt(&unpacked_3);
BOOST_CHECK(ok);
BOOST_CHECK_EQUAL(unpacked_3, expected_3);
ok = reader.GetZigZagVlqInt(&unpacked_4);
BOOST_CHECK(ok);
BOOST_CHECK_EQUAL(unpacked_4, expected_4);
values_read = reader.GetBatch(bit_width, unpacked_2.data(), 999999);
BOOST_CHECK_EQUAL(values_read, 0);
}
BOOST_AUTO_TEST_CASE(BitReader_ULEB128_corrupted) {
std::array<uint8_t, 1> packed = {
0b10000000,// Incomplete ULEB128
};
uint32_t unpacked;
BitReader reader(packed.data(), packed.size());
bool ok = reader.GetVlqInt(&unpacked);
BOOST_CHECK(!ok);
}
BOOST_AUTO_TEST_CASE(BitReader_ULEB128_overflow) {
std::array<uint8_t, 7> packed = {
0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b00000000
};
uint32_t unpacked;
BitReader reader(packed.data(), packed.size());
bool ok = reader.GetVlqInt(&unpacked);
BOOST_CHECK(!ok);
}
BOOST_AUTO_TEST_CASE(BitReader_zigzag_corrupted) {
std::array<uint8_t, 1> packed = {
0b10000000, // Incomplete zigzag
};
int32_t unpacked;
BitReader reader(packed.data(), packed.size());
bool ok = reader.GetZigZagVlqInt(&unpacked);
BOOST_CHECK(!ok);
}
BOOST_AUTO_TEST_CASE(BitReader_zigzag_overflow) {
std::array<uint8_t, 7> packed = {
0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b00000000
};
int32_t unpacked;
BitReader reader(packed.data(), packed.size());
bool ok = reader.GetZigZagVlqInt(&unpacked);
BOOST_CHECK(!ok);
}
// Refer to doc/parquet/Encodings.md (section about RLE)
// for a description of the encoding being tested here.
BOOST_AUTO_TEST_CASE(RleDecoder_happy) {
constexpr int bit_width = 3;
std::array<uint8_t, 6> packed = {
0b00000011, 0b10001000, 0b11000110, 0b11111010, // bit-packed-run {0, 1, 2, 3, 4, 5, 6, 7}
0b00001000, 0b00000101 // rle-run {5, 5, 5, 5}
};
std::array<int, 6> unpacked_1;
const std::array<int, 6> expected_1 = {0, 1, 2, 3, 4, 5};
std::array<int, 4> unpacked_2;
const std::array<int, 4> expected_2 = {6, 7, 5, 5};
std::array<int, 2> unpacked_3;
const std::array<int, 2> expected_3 = {5, 5};
int values_read;
RleDecoder reader(packed.data(), packed.size(), bit_width);
values_read = reader.GetBatch(unpacked_1.data(), expected_1.size());
BOOST_CHECK_EQUAL(values_read, expected_1.size());
BOOST_CHECK_EQUAL_COLLECTIONS(unpacked_1.begin(), unpacked_1.end(), expected_1.begin(), expected_1.end());
values_read = reader.GetBatch(unpacked_2.data(), expected_2.size());
BOOST_CHECK_EQUAL(values_read, expected_2.size());
BOOST_CHECK_EQUAL_COLLECTIONS(unpacked_2.begin(), unpacked_2.end(), expected_2.begin(), expected_2.end());
values_read = reader.GetBatch(unpacked_3.data(), 9999999);
BOOST_CHECK_EQUAL(values_read, expected_3.size());
BOOST_CHECK_EQUAL_COLLECTIONS(unpacked_3.begin(), unpacked_3.end(), expected_3.begin(), expected_3.end());
values_read = reader.GetBatch(unpacked_2.data(), 9999999);
BOOST_CHECK_EQUAL(values_read, 0);
}
BOOST_AUTO_TEST_CASE(RleDecoder_bit_packed_ULEB128) {
constexpr int bit_width = 16;
std::array<uint8_t, 1026> packed = {
0b10000001, 0b00000001// bit-packed-run with 8 * 64 values
};
std::array<int, 512> expected;
std::array<int, 512> unpacked;
for (size_t i = 0; i < expected.size(); ++i) {
uint16_t value = i;
memcpy(&packed[2 + i*2], &value, 2);
expected[i] = i;
}
int values_read;
RleDecoder reader(packed.data(), packed.size(), bit_width);
values_read = reader.GetBatch(unpacked.data(), 9999999);
BOOST_CHECK_EQUAL(values_read, expected.size());
BOOST_CHECK_EQUAL_COLLECTIONS(unpacked.begin(), unpacked.end(), expected.begin(), expected.end());
}
BOOST_AUTO_TEST_CASE(RleDecoder_rle_ULEB128) {
constexpr int bit_width = 8;
std::array<uint8_t, 3> packed = {
0b10000000, 0b00000001, 0b00000101 // rle-run with 64 copies of 5
};
std::array<int, 64> expected;
std::array<int, 64> unpacked;
for (size_t i = 0; i < expected.size(); ++i) {
expected[i] = 5;
}
int values_read;
RleDecoder reader(packed.data(), packed.size(), bit_width);
values_read = reader.GetBatch(unpacked.data(), 9999999);
BOOST_CHECK_EQUAL(values_read, expected.size());
BOOST_CHECK_EQUAL_COLLECTIONS(unpacked.begin(), unpacked.end(), expected.begin(), expected.end());
}
BOOST_AUTO_TEST_CASE(RleDecoder_bit_packed_too_short) {
constexpr int bit_width = 3;
std::array<uint8_t, 3> packed = {
0b00000011, 0b10001000, 0b11000110 // bit-packed-run {0, 1, 2, 3, 4, EOF
};
std::array<int, 8> unpacked;
RleDecoder reader(packed.data(), packed.size(), bit_width);
int values_read = reader.GetBatch(unpacked.data(), unpacked.size());
BOOST_CHECK_EQUAL(values_read, 0);
}
BOOST_AUTO_TEST_CASE(RleDecoder_rle_too_short) {
constexpr int bit_width = 3;
std::array<uint8_t, 1> packed = {
0b00001000 // rle-run without value
};
std::array<int, 4> unpacked;
RleDecoder reader(packed.data(), packed.size(), bit_width);
int values_read = reader.GetBatch(unpacked.data(), unpacked.size());
BOOST_CHECK_EQUAL(values_read, 0);
}
BOOST_AUTO_TEST_CASE(RleDecoder_bit_packed_ULEB128_too_short) {
constexpr int bit_width = 3;
std::array<uint8_t, 1> packed = {
0b10000001 // bit-packed-run of incomplete ULEB128 length
};
std::array<int, 512> unpacked;
RleDecoder reader(packed.data(), packed.size(), bit_width);
int values_read = reader.GetBatch(unpacked.data(), unpacked.size());
BOOST_CHECK_EQUAL(values_read, 0);
}
BOOST_AUTO_TEST_CASE(RleDecoder_rle_ULEB128_too_short) {
constexpr int bit_width = 3;
std::array<uint8_t, 1> packed = {
0b10000000 // rle-run of incomplete ULEB128 length
};
std::array<int, 512> unpacked;
RleDecoder reader(packed.data(), packed.size(), bit_width);
int values_read = reader.GetBatch(unpacked.data(), unpacked.size());
BOOST_CHECK_EQUAL(values_read, 0);
}
|
import matplotlib
matplotlib.use('TkAgg')
import pymc3 as pm
import pandas as pd
import matplotlib
import numpy as np
import pickle as pkl
import datetime
from BaseModel import BaseModel
import isoweek
from matplotlib import rc
from shared_utils import *
from pymc3.stats import quantiles
from matplotlib import pyplot as plt
from config import * # <-- to select the right model
# from pandas import register_matplotlib_converters
# register_matplotlib_converters() # the fk python
def temporal_contribution(model_i=15, combinations=combinations, save_plot=False):
use_ia, use_report_delay, use_demographics, trend_order, periodic_order = combinations[model_i]
plt.style.use('ggplot')
with open('../data/counties/counties.pkl', "rb") as f:
county_info = pkl.load(f)
C1 = "#D55E00"
C2 = "#E69F00"
C3 = C2 # "#808080"
if use_report_delay:
fig = plt.figure(figsize=(25, 10))
grid = plt.GridSpec(4, 1, top=0.93, bottom=0.12,
left=0.11, right=0.97, hspace=0.28, wspace=0.30)
else:
fig = plt.figure(figsize=(16, 10))
grid = plt.GridSpec(3, 1, top=0.93, bottom=0.12,
left=0.11, right=0.97, hspace=0.28, wspace=0.30)
disease = "covid19"
prediction_region = "germany"
data = load_daily_data(disease, prediction_region, county_info)
first_day = pd.Timestamp('2020-04-01')
last_day = data.index.max()
_, target_train, _, _ = split_data(
data,
train_start=first_day,
test_start=last_day - pd.Timedelta(days=1),
post_test=last_day + pd.Timedelta(days=1)
)
tspan = (target_train.index[0], target_train.index[-1])
model = BaseModel(tspan,
county_info,
["../data/ia_effect_samples/{}_{}.pkl".format(disease,
i) for i in range(100)],
include_ia=use_ia,
include_report_delay=use_report_delay,
include_demographics=True,
trend_poly_order=4,
periodic_poly_order=4)
features = model.evaluate_features(
target_train.index, target_train.columns)
trend_features = features["temporal_trend"].swaplevel(0, 1).loc["09162"]
periodic_features = features["temporal_seasonal"].swaplevel(0, 1).loc["09162"]
#t_all = t_all_b if disease == "borreliosis" else t_all_cr
trace = load_final_trace()
trend_params = pm.trace_to_dataframe(trace, varnames=["W_t_t"])
periodic_params = pm.trace_to_dataframe(trace, varnames=["W_t_s"])
TT = trend_params.values.dot(trend_features.values.T)
TP = periodic_params.values.dot(periodic_features.values.T)
TTP = TT + TP
# add report delay if used
#if use_report_delay:
# delay_features = features["temporal_report_delay"].swaplevel(0,1).loc["09162"]
# delay_params = pm.trace_to_dataframe(trace,varnames=["W_t_d"])
# TD =delay_params.values.dot(delay_features.values.T)
# TTP += TD
# TD_quantiles = quantiles(TD, (25, 75))
TT_quantiles = quantiles(TT, (25, 75))
TP_quantiles = quantiles(TP, (25, 75))
TTP_quantiles = quantiles(TTP, (2.5,25, 75,97.5))
dates = [pd.Timestamp(day) for day in target_train.index.values]
days = [ (day - min(dates)).days for day in dates]
# Temporal trend+periodic effect
if use_report_delay:
ax_tp = fig.add_subplot(grid[0, 0])
else:
ax_tp = fig.add_subplot(grid[0, 0])
ax_tp.fill_between(days, np.exp(TTP_quantiles[25]), np.exp(
TTP_quantiles[75]), alpha=0.5, zorder=1, facecolor=C1)
ax_tp.plot(days, np.exp(TTP.mean(axis=0)),
"-", color=C1, lw=2, zorder=5)
ax_tp.plot(days, np.exp(
TTP_quantiles[25]), "-", color=C2, lw=2, zorder=3)
ax_tp.plot(days, np.exp(
TTP_quantiles[75]), "-", color=C2, lw=2, zorder=3)
ax_tp.plot(days, np.exp(
TTP_quantiles[2.5]), "--", color=C2, lw=2, zorder=3)
ax_tp.plot(days, np.exp(
TTP_quantiles[97.5]), "--", color=C2, lw=2, zorder=3)
#ax_tp.plot(days, np.exp(TTP[:25, :].T),
# "--", color=C3, lw=1, alpha=0.5, zorder=2)
ax_tp.tick_params(axis="x", rotation=45)
# Temporal trend effect
ax_t = fig.add_subplot(grid[1, 0], sharex=ax_tp)
#ax_t.fill_between(days, np.exp(TT_quantiles[25]), np.exp(
# TT_quantiles[75]), alpha=0.5, zorder=1, facecolor=C1)
ax_t.plot(days, np.exp(TT.mean(axis=0)),
"-", color=C1, lw=2, zorder=5)
#ax_t.plot(days, np.exp(
# TT_quantiles[25]), "-", color=C2, lw=2, zorder=3)
#ax_t.plot(days, np.exp(
# TT_quantiles[75]), "-", color=C2, lw=2, zorder=3)
#ax_t.plot(days, np.exp(TT[:25, :].T),
# "--", color=C3, lw=1, alpha=0.5, zorder=2)
ax_t.tick_params(axis="x", rotation=45)
ax_t.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
# Temporal periodic effect
ax_p = fig.add_subplot(grid[2, 0], sharex=ax_tp)
#ax_p.fill_between(days, np.exp(TP_quantiles[25]), np.exp(
# TP_quantiles[75]), alpha=0.5, zorder=1, facecolor=C1)
ax_p.plot(days, np.exp(TP.mean(axis=0)),
"-", color=C1, lw=2, zorder=5)
ax_p.set_ylim([-0.0001,0.001])
#ax_p.plot(days, np.exp(
# TP_quantiles[25]), "-", color=C2, lw=2, zorder=3)
#ax_p.plot(days, np.exp(
# TP_quantiles[75]), "-", color=C2, lw=2, zorder=3)
#ax_p.plot(days, np.exp(TP[:25, :].T),
# "--", color=C3, lw=1, alpha=0.5, zorder=2)
ax_p.tick_params(axis="x", rotation=45)
ax_p.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
ticks = ['2020-03-02','2020-03-12','2020-03-22','2020-04-01','2020-04-11','2020-04-21','2020-05-1','2020-05-11','2020-05-21']
labels = ['02.03.2020','12.03.2020','22.03.2020','01.04.2020','11.04.2020','21.04.2020','01.05.2020','11.05.2020','21.05.2020']
#if use_report_delay:
# ax_td = fig.add_subplot(grid[2, 0], sharex=ax_p)
#
# ax_td.fill_between(days, np.exp(TD_quantiles[25]), np.exp(
# TD_quantiles[75]), alpha=0.5, zorder=1, facecolor=C1)
# ax_td.plot(days, np.exp(TD.mean(axis=0)),
# "-", color=C1, lw=2, zorder=5)
# ax_td.plot(days, np.exp(
# TD_quantiles[25]), "-", color=C2, lw=2, zorder=3)
# ax_td.plot(days, np.exp(
# TD_quantiles[75]), "-", color=C2, lw=2, zorder=3)
# ax_td.plot(days, np.exp(TD[:25, :].T),
# "--", color=C3, lw=1, alpha=0.5, zorder=2)
# ax_td.tick_params(axis="x", rotation=45)
#ax_tp.set_title("campylob." if disease ==
# "campylobacter" else disease, fontsize=22)
ax_p.set_xlabel("time [days]", fontsize=22)
ax_p.set_ylabel("periodic\ncontribution", fontsize=22)
ax_t.set_ylabel("trend\ncontribution", fontsize=22)
ax_tp.set_ylabel("combined\ncontribution", fontsize=22)
#if use_report_delay:
# ax_td.set_ylabel("r.delay\ncontribution", fontsize=22)
ax_t.set_xlim(days[0], days[-1])
ax_t.tick_params(labelbottom=False, labelleft=True, labelsize=18, length=6)
ax_p.tick_params(labelbottom=True, labelleft=True, labelsize=18, length=6)
ax_tp.tick_params(labelbottom=False, labelleft=True, labelsize=18, length=6)
#ax_p.set_xticks(ticks)#,labels)
if save_plot:
fig.savefig("../figures/temporal_contribution_{}.pdf".format(model_i))
#return fig
if __name__ == "__main__":
_ = temporal_contribution(15, combinations,save_plot=True)
|
The time has now come for us to seriously think about where we would like the Front Page Davis Wiki to go. This page will be the hub for Future Plans for the Davis Wiki, and the wiki:wikispot:Front Page Wiki Spot and http://localwiki.org Local Wiki projects in general.
Issues
Software
Wiki Community/Future/Spammers and Newbies
Wiki Community/Future/Software Features
Wiki Community/Future/Gnome Features
Community
Wiki Community/Future/Outreach
Wiki Community/Future/Fundraising
Content and Culture
Wiki Community/Future/Builders and Commenters
Related Pages
In the past, long range planning is scattered on a lot of other pages. A selection below:
Wiki Community/Longview
Wiki Community/Proposals
Cut that comment bar out
Wiki Community/Room to grow
Wiki Community/Building Community
wiki:wikispot:Feature Requests
wiki:wikispot:FAQ Wikispot FAQ
Davis Wiki fundraiser
Wiki Community/Outreach
Mature Davisite Wiki Recruitment Drive
|
{-# OPTIONS --cubical --prop #-}
module Issue2487-2 where
import Issue2487.Infective
|
include("SolveBalances_Flow.jl")
include("DataFile_Flow.jl")
using PyPlot
TSTART = 0
TSTOP = 24
Ts = 0.01
data_dictionary = DataFile_Flow(TSTART,TSTOP,Ts)
(T,X) = SolveBalances_Flow(TSTART,TSTOP,Ts,data_dictionary)
|
From iris.bi Require Import bi.
From iris.proofmode Require Export classes.
Set Default Proof Using "Type".
Import bi.
Section bi_modalities.
Context {PROP : bi}.
Lemma modality_persistently_mixin :
modality_mixin (@bi_persistently PROP) MIEnvId MIEnvClear.
Proof.
split; simpl; eauto using equiv_entails_sym, persistently_intro,
persistently_mono, persistently_sep_2 with typeclass_instances.
Qed.
Definition modality_persistently :=
Modality _ modality_persistently_mixin.
Lemma modality_affinely_mixin :
modality_mixin (@bi_affinely PROP) MIEnvId (MIEnvForall Affine).
Proof.
split; simpl; eauto using equiv_entails_sym, affinely_intro, affinely_mono,
affinely_sep_2 with typeclass_instances.
Qed.
Definition modality_affinely :=
Modality _ modality_affinely_mixin.
Lemma modality_intuitionistically_mixin :
modality_mixin (@bi_intuitionistically PROP) MIEnvId MIEnvIsEmpty.
Proof.
split; simpl; eauto using equiv_entails_sym, intuitionistically_emp,
affinely_mono, persistently_mono, intuitionistically_idemp,
intuitionistically_sep_2 with typeclass_instances.
Qed.
Definition modality_intuitionistically :=
Modality _ modality_intuitionistically_mixin.
Lemma modality_embed_mixin `{BiEmbed PROP PROP'} :
modality_mixin (@embed PROP PROP' _)
(MIEnvTransform IntoEmbed) (MIEnvTransform IntoEmbed).
Proof.
split; simpl; split_and?;
eauto using equiv_entails_sym, embed_emp_2, embed_sep, embed_and.
- intros P Q. rewrite /IntoEmbed=> ->. by rewrite embed_intuitionistically_2.
- by intros P Q ->.
Qed.
Definition modality_embed `{BiEmbed PROP PROP'} :=
Modality _ modality_embed_mixin.
End bi_modalities.
Section sbi_modalities.
Context {PROP : sbi}.
Lemma modality_plainly_mixin `{BiPlainly PROP} :
modality_mixin (@plainly PROP _) (MIEnvForall Plain) MIEnvClear.
Proof.
split; simpl; split_and?; eauto using equiv_entails_sym, plainly_intro,
plainly_mono, plainly_and, plainly_sep_2 with typeclass_instances.
Qed.
Definition modality_plainly `{BiPlainly PROP} :=
Modality _ modality_plainly_mixin.
Lemma modality_laterN_mixin n :
modality_mixin (@sbi_laterN PROP n)
(MIEnvTransform (MaybeIntoLaterN false n)) (MIEnvTransform (MaybeIntoLaterN false n)).
Proof.
split; simpl; split_and?; eauto using equiv_entails_sym, laterN_intro,
laterN_mono, laterN_and, laterN_sep with typeclass_instances.
rewrite /MaybeIntoLaterN=> P Q ->. by rewrite laterN_intuitionistically_2.
Qed.
Definition modality_laterN n :=
Modality _ (modality_laterN_mixin n).
End sbi_modalities.
|
#### Healthy Neighborhoods Project: Using Ecological Data to Improve Community Health
### Neville Subproject: Using Random Forestes, Factor Analysis, and Logistic regression to Screen Variables for Imapcts on Public Health
## National Health and Nutrition Examination Survey: The R Project for Statistical Computing Script by DrewC!
# Detecting Prediabetes in those under 65
#### Section A: Prepare Code
### Step 1: Import Libraries and Import Dataset
## Import Hadley Wickham Libraries
library(tidyverse) # All of the libraries above in one line of code
## Import Data
setwd("C:/Users/drewc/GitHub/Data_Club") # Set wd to project repository
df_check = read.csv("_data/health_check_stage.csv") # Import dataset from _data folder
## Verify
dim(df_check)
model_linear <- lm(MSPB~ Case_Mix_Index + Mean_Physician_Income + Percent_For_Profit, data = df_check)
summary(model_linear)
model_linear <- lm(MSPB~ Mean_Physician_Income + Percent_For_Profit, data = df_check)
summary(model_linear)
|
Welcome to the Profile Reviews section. This is a list of members who have requested others to review their profile. Have you ever wondered what people think of your profile? Now is your chance to find out. Submit your profile to be reviewed by members, read reviews of other member's profiles, post comments on reviews. Click here for a list of profile reviews with no responses yet. Click here to get your profile reviewed.
Would YOU like to have your profile reviewed on Connecting Singles?
Have you been searching for the ONE and wondering if she or he has browsed on by without stopping to get acquainted. First impressions are important in online dating. Maybe there's a difference between the person you are trying to present in your profile and the one others see when they're viewing it.
Submit your profile to see how you come across to others and what you can do to correct that image if necessary to attract the attention you are seeking.
Use this feature to request reviews by site members, read and learn from the reviews of other profiles, or leave constructive comments on the reviews of others. |
lemma pderiv_diff: "pderiv ((p :: _ :: idom poly) - q) = pderiv p - pderiv q" |
#redirect A Plus Image
|
addprocs(1)
using BaseBenchmarks
using BenchmarkTools
using Base.Test
BaseBenchmarks.loadall!()
@test begin
run(BaseBenchmarks.SUITE, verbose = true, samples = 1,
evals = 2, gctrial = false, gcsample = false);
true
end
|
(*===========================================================================
Specification logic -- step-indexed and with hidden frames
This is a step-indexed version of the specification logic defined in Chapter
3 of Krishnaswami's thesis, which is adapted from Birkedal et al.
A specification S is a predicate on nat and SPred, where it holds for a pair
(k,P) if it denotes a "desirable" machine execution for up to k steps
starting from any machine configuration that has a sub-state satisfying P.
The meaning of "desirable" depends on S; it might, for example, mean "safe
under certain assumptions". Note the wording "up to" and "sub-state" above:
they suggest that formally, S must be closed under decreasing k and starring
on assertions to P.
The utility of this is to get a higher-order frame rule in the specification
logic, which is very valuable for a low-level language that does not have
structured control flow and therefore does not have the structure required
to define a Hoare triple. When frames cannot be fixed by the symmetry of
pre- and postconditions, they must float freely around the specification
logic, which is exactly what the higher-order frame rule allows -- see
[spec_frame].
===========================================================================*)
Require Import ssreflect ssrbool ssrfun ssrnat eqtype tuple seq fintype.
Require Import bitsrep procstate procstatemonad SPred septac.
Require Import instr eval monad monadinst reader step cursor.
Require Import common_tactics.
(* Importing this file really only makes sense if you also import ilogic, so we
force that. *)
Require Export ilogic later.
Transparent ILPre_Ops.
Set Implicit Arguments.
Unset Strict Implicit.
Import Prenex Implicits.
Require Import Setoid RelationClasses Morphisms.
(* The ssreflect inequalities on nat are just getting in the way here. They
don't work with non-Equivalence setoids. *)
Local Open Scope coq_nat_scope.
(* The natural numbers in descending order. *)
(*
Instance ge_Pre: PreOrder ge.
Proof. repeat constructor. hnf. eauto with arith. Qed.
*)
(* SPred, ordered by extension with **. *)
Definition extSP (P Q: SPred) := exists R, (P ** R) -|- Q.
Instance extSP_Pre: PreOrder extSP.
Proof.
split.
- exists empSP. apply empSPR.
- move=> P1 P2 P3 [R1 H1] [R2 H2]. exists (R1 ** R2).
by rewrite <-H1, sepSPA in H2.
Qed.
Instance extSP_impl_m :
Proper (extSP --> extSP ++> Basics.impl) extSP.
Proof.
rewrite /extSP. intros P P' [RP HP] Q Q' [RQ HQ] [R H].
eexists. rewrite -HQ -H -HP. split; by ssimpl.
Qed.
Instance extSP_iff_m :
Proper (lequiv ==> lequiv ==> iff) extSP.
Proof.
rewrite /extSP. intros P P' HP Q Q' HQ.
setoid_rewrite HP. setoid_rewrite HQ. done.
Qed.
Instance extSP_sepSP_m :
Proper (extSP ++> extSP ++> extSP) sepSP.
Proof.
rewrite /extSP. intros P P' [RP HP] Q Q' [RQ HQ].
eexists. rewrite -HP -HQ. split; by ssimpl.
Qed.
Instance subrelation_equivSP_extSP: subrelation lequiv extSP.
Proof. rewrite /extSP => P P' HP. exists empSP. rewrite HP. apply empSPR. Qed.
Instance subrelation_equivSP_inverse_extSP: subrelation lequiv (inverse extSP).
Proof. rewrite /extSP => P P' HP. exists empSP. rewrite HP. apply empSPR. Qed.
Hint Extern 0 (extSP ?P ?P) => reflexivity.
(*
Definition of "spec" and properties of it as a logic
*)
Section ILSpecSect.
Local Existing Instance ILPre_Ops.
Local Existing Instance ILPre_ILogic.
Local Existing Instance ILLaterPreOps.
Local Existing Instance ILLaterPre.
Definition spec := ILPreFrm ge (ILPreFrm extSP Prop).
Global Instance ILSpecOps: ILLOperators spec | 2 := _.
Global Instance ILOps: ILogicOps spec | 2 := _.
Global Instance ILSpec: ILLater spec | 2 := _.
End ILSpecSect.
Local Obligation Tactic := try solve [Tactics.program_simpl|auto].
(* This uses 'refine' instead of Program Definition to work around a Coq 8.4
bug. *)
Definition mkspec (f: nat -> SPred -> Prop)
(Hnat: forall k P, f (S k) P -> f k P)
(HSPred: forall k P P', extSP P P' -> f k P -> f k P') : spec.
refine (mkILPreFrm (fun k => mkILPreFrm (f k) _) _).
Proof.
have Hnat' : forall k' k P, k' >= k -> f k' P -> f k P.
- move => k' k P. elim; by auto.
move=> k' k Hk P /= Hf.
eapply Hnat'; eassumption.
Grab Existential Variables.
Proof.
move=> P P' HP /= Hf. eapply HSPred; eassumption.
Defined.
Implicit Arguments mkspec [].
Definition spec_fun (S: spec) := fun k P => S k P.
Coercion spec_fun: spec >-> Funclass.
Add Parametric Morphism (S: spec) : S with signature
ge ++> extSP ++> Basics.impl
as spec_impl_m.
Proof.
rewrite /spec_fun. move => k k' Hk P P' HP.
rewrite -[Basics.impl _ _]/(@lentails _ ILogicOps_Prop _ _).
by rewrite ->HP, ->Hk.
Qed.
Add Parametric Morphism (S: spec) : S with signature
eq ==> lequiv ==> iff
as spec_iff_m.
Proof.
move=> k P P' HP. split => HS.
- by rewrite ->HP in HS.
- by rewrite <-HP in HS.
Qed.
(* The default definition of spec equivalence is sometimes inconvenient.
Here is an alternative one. *)
Lemma spec_equiv (S S': spec):
(forall k P, S k P <-> S' k P) -> S -|- S'.
Proof. move=> H; split => k P /=; apply H. Qed.
Lemma spec_downwards_closed (S: spec) P k k':
k <= k' -> S k' P -> S k P.
Proof.
move=> Hk. have Hk' : k' >= k by auto. by rewrite ->Hk'.
Qed.
(*
Properties of spec_at
*)
Program Definition spec_at (S: spec) (R: SPred) :=
mkspec (fun k P => S k (R ** P)) _ _.
Next Obligation.
move=> S R k P P'. eauto using spec_downwards_closed.
Qed.
Next Obligation.
move=> S R k P P' HP. by rewrite ->HP.
Qed.
Infix "@" := spec_at (at level 44, left associativity).
Lemma spec_frame (S : spec) (R : SPred) :
S |-- S @ R.
Proof.
move => k P H. rewrite /spec_at /=.
assert (extSP P (P ** R)) as HPR by (exists R; reflexivity).
rewrite ->sepSPC in HPR. by rewrite <-HPR.
Qed.
(* For variations of this instance with lentails instead of extSP, look at
[spec_at_covar_m] and [spec_at_contra_m]. *)
Instance spec_at_entails_m:
Proper (lentails ++> extSP ++> lentails) spec_at.
Proof.
move=> S S' HS R R' HR k P. rewrite /spec_at /= /spec_fun /=.
by rewrite <- HR, -> HS.
Qed.
Instance spec_at_equiv_m:
Proper (lequiv ++> lequiv ++> lequiv) spec_at.
Proof.
move => S S' HS R R' HR.
split; cancel2; by (rewrite HS || rewrite HR).
Qed.
Lemma spec_at_emp S: S @ empSP -|- S.
Proof.
split; last exact: spec_frame.
move=> k P. rewrite /spec_at /spec_fun /=. by rewrite empSPL.
Qed.
Lemma spec_at_at S R R': S @ R @ R' -|- S @ (R ** R').
Proof.
apply spec_equiv => k P. rewrite /spec_at /spec_fun /=.
split; by [rewrite -sepSPA | rewrite sepSPA].
Qed.
Lemma spec_at_forall {T} F R: (Forall x:T, F x) @ R -|- Forall x:T, (F x @ R).
Proof. split; rewrite /= /spec_fun /=; auto. Qed.
Lemma spec_at_exists {T} F R: (Exists x:T, F x) @ R -|- Exists x:T, (F x @ R).
Proof. split; rewrite /= /spec_fun /= => k P [x Hx]; eauto. Qed.
Lemma spec_at_true R: ltrue @ R -|- ltrue.
Proof. split; rewrite /= /spec_fun /=; auto. Qed.
Lemma spec_at_false R: lfalse @ R -|- lfalse.
Proof. split; rewrite /= /spec_fun /=; auto. Qed.
Lemma spec_at_and S S' R: (S //\\ S') @ R -|- (S @ R) //\\ (S' @ R).
Proof. split; rewrite /spec_at /= /spec_fun /= => k P H; auto. Qed.
Lemma spec_at_or S S' R: (S \\// S') @ R -|- (S @ R) \\// (S' @ R).
Proof. split; rewrite /spec_at /= /spec_fun /= => k P H; auto. Qed.
Lemma spec_at_propimpl p S R: (p ->> S) @ R -|- p ->> (S @ R).
Proof. split; rewrite /= /spec_fun /=; auto. Qed.
Lemma spec_at_propand p S R: (p /\\ S) @ R -|- p /\\ (S @ R).
Proof. split; rewrite /= /spec_fun /=; auto. Qed.
Lemma spec_at_impl S S' R: (S -->> S') @ R -|- (S @ R) -->> (S' @ R).
Proof.
split.
- apply: limplAdj. rewrite <-spec_at_and.
cancel2. exact: landAdj.
- rewrite /spec_at /= /spec_fun /= => k P H.
(* This proof follows the corresponding one (Lemma 25) in Krishnaswami's
PhD thesis. *)
intros k' Hk' P' [Pext HPext] HS.
move/(_ k' Hk' (P ** Pext)): H => H.
rewrite ->sepSPA in HPext.
(* The rewriting by using explicit subrelation instances here is a bit
awkward. *)
rewrite <-(subrelation_equivSP_extSP HPext).
apply H; first by exists Pext.
rewrite ->(subrelation_equivSP_inverse_extSP HPext). done.
Qed.
Hint Rewrite
spec_at_at
spec_at_true
spec_at_false
spec_at_and
spec_at_or
spec_at_impl
@spec_at_forall
@spec_at_exists
spec_at_propimpl
spec_at_propand
: push_at.
(* This lemma is what [spec_at_at] really should be in order to be consistent
with the others in the hint database, but this variant is not suitable for
autorewrite. *)
Lemma spec_at_swap S R1 R2:
S @ R1 @ R2 -|- S @ R2 @ R1.
Proof. autorewrite with push_at. by rewrite sepSPC. Qed.
(*
"Rule of consequence" for spec_at
*)
Class AtCovar S := at_covar: forall P Q, P |-- Q -> S @ P |-- S @ Q.
Class AtContra S := at_contra: forall P Q, P |-- Q -> S @ Q |-- S @ P.
Instance: Proper (lequiv ==> iff) AtCovar.
Proof. move=> S S' HS. rewrite /AtCovar. by setoid_rewrite HS. Qed.
Instance: Proper (lequiv ==> iff) AtContra.
Proof. move=> S S' HS. rewrite /AtContra. by setoid_rewrite HS. Qed.
Instance AtCovar_forall A S {HS: forall a:A, AtCovar (S a)} :
AtCovar (Forall a, S a).
Proof.
move=> P Q HPQ. autorewrite with push_at. cancel1 => a.
by rewrite ->(HS _ _ _ HPQ).
Qed.
Instance AtContra_forall A S {HS: forall a:A, AtContra (S a)} :
AtContra (Forall a, S a).
Proof.
move=> P Q HPQ. autorewrite with push_at. cancel1 => a.
by rewrite ->(HS _ _ _ HPQ).
Qed.
Instance AtCovar_and S1 S2 {H1: AtCovar S1} {H2: AtCovar S2} :
AtCovar (S1 //\\ S2).
Proof. rewrite land_is_forall. by apply AtCovar_forall => [[]]. Qed.
Instance AtContra_and S1 S2 {H1: AtContra S1} {H2: AtContra S2} :
AtContra (S1 //\\ S2).
Proof. rewrite land_is_forall. by apply AtContra_forall => [[]]. Qed.
Instance AtCovar_true : AtCovar ltrue.
Proof. rewrite ltrue_is_forall. by apply AtCovar_forall => [[]]. Qed.
Instance AtContra_true : AtContra ltrue.
Proof. rewrite ltrue_is_forall. by apply AtContra_forall => [[]]. Qed.
Instance AtCovar_exists A S {HS: forall a:A, AtCovar (S a)} :
AtCovar (Exists a, S a).
Proof.
move=> P Q HPQ. autorewrite with push_at. cancel1 => a.
by rewrite ->(HS _ _ _ HPQ).
Qed.
Instance AtContra_exists A S {HS: forall a:A, AtContra (S a)} :
AtContra (Exists a, S a).
Proof.
move=> P Q HPQ. autorewrite with push_at. cancel1 => a.
by rewrite ->(HS _ _ _ HPQ).
Qed.
Instance AtCovar_or S1 S2 {H1: AtCovar S1} {H2: AtCovar S2} :
AtCovar (S1 \\// S2).
Proof. rewrite lor_is_exists. by apply AtCovar_exists => [[]]. Qed.
Instance AtContra_or S1 S2 {H1: AtContra S1} {H2: AtContra S2} :
AtContra (S1 \\// S2).
Proof. rewrite lor_is_exists. by apply AtContra_exists => [[]]. Qed.
Instance AtCovar_false : AtCovar lfalse.
Proof. rewrite lfalse_is_exists. by apply AtCovar_exists => [[]]. Qed.
Instance AtContra_false : AtContra lfalse.
Proof. rewrite lfalse_is_exists. by apply AtContra_exists => [[]]. Qed.
Instance AtCovar_impl S1 S2 {H1: AtContra S1} {H2: AtCovar S2} :
AtCovar (S1 -->> S2).
Proof.
move=> P Q HPQ. autorewrite with push_at.
by rewrite ->(H1 _ _ HPQ), <-(H2 _ _ HPQ).
Qed.
Instance AtContra_impl S1 S2 {H1: AtCovar S1} {H2: AtContra S2} :
AtContra (S1 -->> S2).
Proof.
move=> P Q HPQ. autorewrite with push_at.
by rewrite ->(H1 _ _ HPQ), <-(H2 _ _ HPQ).
Qed.
Instance AtCovar_at S R {HS: AtCovar S} : AtCovar (S @ R).
Proof.
move=> P Q HPQ. rewrite [_ @ P]spec_at_swap [_ @ Q]spec_at_swap.
by rewrite <-(HS _ _ HPQ).
Qed.
Instance AtContra_at S R {HS: AtContra S} : AtContra (S @ R).
Proof.
move=> P Q HPQ. rewrite [_ @ Q]spec_at_swap [_ @ P]spec_at_swap.
by rewrite <-(HS _ _ HPQ).
Qed.
Instance spec_at_covar_m S {HS: AtCovar S} :
Proper (lentails ++> lentails) (spec_at S).
Proof. move=> P Q HPQ. by apply HS. Qed.
Instance spec_at_contra_m S {HS: AtContra S} :
Proper (lentails --> lentails) (spec_at S).
Proof. move=> P Q HPQ. by apply HS. Qed.
Instance at_contra_entails_m (S: spec) `{HContra: AtContra S}:
Proper (ge ++> lentails --> lentails) S.
Proof.
move => k k' Hk P P' HP H. rewrite <-Hk.
specialize (HContra P' P HP k empSP).
simpl in HContra. rewrite ->!empSPR in HContra. by auto.
Qed.
Instance at_covar_entails_m (S: spec) `{HCovar: AtCovar S}:
Proper (ge ++> lentails ++> lentails) S.
Proof.
move => k k' Hk P P' HP H. rewrite <-Hk.
specialize (HCovar P P' HP k empSP).
simpl in HCovar. rewrite ->!empSPR in HCovar. by auto.
Qed.
(*
Rules for pulling existentials from the second argument of spec_at. These
rules together form a spec-level analogue of the "existential rule" for
Hoare triples.
Whether an existential quantifier can be pulled out of the R in [S @ R]
depends on S. Rewrite by <-at_ex to pull it out from a positive position in
the goal. Rewrite by ->at_ex' to pull it out from a negative position in the
goal.
*)
Class AtEx S := at_ex: forall A f, Forall x:A, S @ f x |-- S @ lexists f.
(* The reverse direction of at_ex. This not only follows from AtContra but is
actually equivalent to it. The proof is in revision 22259 (spec.v#22). *)
Lemma at_ex' S {HS: AtContra S} :
forall A f, S @ lexists f |-- Forall x:A, S @ f x.
Proof.
move=> A f. apply: lforallR => x. apply HS. ssplit. reflexivity.
Qed.
Instance: Proper (lequiv ==> iff) AtEx.
Proof. move=> S S' HS. rewrite /AtEx. by setoid_rewrite HS. Qed.
Lemma spec_at_and_or S R1 R2 {HS: AtEx S}:
S @ R1 //\\ S @ R2 |-- S @ (R1 \\// R2).
Proof.
rewrite ->land_is_forall, lor_is_exists.
transitivity (Forall b, S @ (if b then R1 else R2)).
- apply: lforallR => [[|]].
- by apply lforallL with true.
- by apply lforallL with false.
apply: at_ex.
Qed.
Lemma spec_at_or_and S R1 R2 {HNeg: AtContra S}:
S @ (R1 \\// R2) |-- S @ R1 //\\ S @ R2.
Proof.
rewrite ->land_is_forall, lor_is_exists.
transitivity (Forall b, S @ (if b then R1 else R2)); last first.
- apply: lforallR => [[|]].
- by apply lforallL with true.
- by apply lforallL with false.
apply: at_ex'.
Qed.
Instance AtEx_forall A S {HS: forall a:A, AtEx (S a)} :
AtEx (Forall a, S a).
Proof.
move=> T f.
rewrite -> spec_at_forall. apply: lforallR => a.
rewrite <- at_ex; cancel1 => x.
rewrite spec_at_forall; by apply lforallL with a.
Qed.
Instance AtEx_and S1 S2 {H1: AtEx S1} {H2: AtEx S2} : AtEx (S1 //\\ S2).
Proof. rewrite land_is_forall. by apply AtEx_forall => [[]]. Qed.
Instance AtEx_true : AtEx ltrue.
Proof. rewrite ltrue_is_forall. by apply AtEx_forall => [[]]. Qed.
Instance AtEx_impl S1 S2 {H1: AtContra S1} {H2: AtEx S2} : AtEx (S1 -->> S2).
Proof.
move=> A f. setoid_rewrite spec_at_impl.
rewrite ->at_ex', <-at_ex => //. (*TODO: why does at_ex' leave a subgoal? *)
apply: limplAdj. apply: lforallR => x. apply: landAdj.
apply lforallL with x. apply: limplAdj. rewrite landC. apply: landAdj.
apply lforallL with x. apply: limplAdj. rewrite landC. apply: landAdj.
reflexivity.
Qed.
Instance AtEx_at S R {HS: AtEx S} : AtEx (S @ R).
Proof.
move=> A f. rewrite spec_at_at.
assert (R ** lexists f -|- Exists x, R ** f x) as Hpull.
- split; sbazooka.
rewrite Hpull. rewrite <-at_ex. cancel1 => x. by rewrite spec_at_at.
Qed.
(* The payoff for all this: a tactic for pulling quantifiers *)
Module Export PullQuant.
Implicit Type S: spec.
Definition PullQuant {A} S (f: A -> spec) := lforall f |-- S.
Lemma pq_rhs S {A} S' (f: A -> spec) {HPQ: PullQuant S' f}:
(forall a:A, S |-- f a) ->
S |-- S'.
Proof. move=> H. red in HPQ. rewrite <-HPQ. by apply: lforallR. Qed.
Lemma PullQuant_forall A (f: A -> spec): PullQuant (lforall f) f.
Proof. red. reflexivity. Qed.
(* Hint Resolve worked here in Coq 8.3 but not since 8.4. *)
Hint Extern 0 (PullQuant (lforall _) _) =>
apply PullQuant_forall : pullquant.
Lemma PullQuant_propimpl p S:
PullQuant (p ->> S) (fun H: p => S).
Proof. red. reflexivity. Qed.
(* Hint Resolve worked here in Coq 8.3 but not since 8.4. *)
Hint Extern 0 (PullQuant (?p ->> ?S) _) =>
apply (@PullQuant_propimpl p S) : pullquant.
Lemma pq_at_rec S R A f:
PullQuant S f ->
PullQuant (S @ R) (fun a:A => f a @ R).
Proof.
rewrite /PullQuant => Hf. rewrite <-Hf. by rewrite spec_at_forall.
Qed.
(* If we didn't find anything to pull from the frame itself, recurse under it. *)
(* Unfortunately, Hint Resolve doesn't work here. For some obscure reason,
there has to be an underscore for the last argument. *)
Hint Extern 1 (PullQuant (?S @ ?R) _) =>
eapply (@pq_at_rec S R _ _) : pullquant.
Lemma pq_impl S S' A f:
PullQuant S f ->
PullQuant (S' -->> S) (fun a:A => S' -->> f a).
Proof.
rewrite /PullQuant => Hf. rewrite <-Hf. apply: limplAdj.
apply: lforallR => a. apply: landAdj. eapply lforallL. reflexivity.
Qed.
Hint Extern 1 (PullQuant (?S' -->> ?S) _) =>
eapply (@pq_impl S S' _ _) : pullquant.
Import Existentials.
Lemma pq_at S t:
match find t with
| Some (mkf _ f) =>
AtEx S -> PullQuant (S @ eval t) (fun a => S @ f a)
| None => True
end.
Proof.
move: (@find_correct t). case: (find t) => [[A f]|]; last done.
move=> Heval HS. red. rewrite ->Heval. by rewrite <-at_ex.
Qed.
Hint Extern 0 (PullQuant (?S @ ?R) _) =>
let t := quote_term R in
apply (@pq_at S t); [apply _] : pullquant.
(* It's a slight breach of abstraction to [cbv [eval]] here, but it's easier
than dealing with it in the hints that use reflection. *)
(* For some reason, auto sometimes hangs when there are entailments among the
hypotheses. As a workaround, we clear those first. Another workaround is
to use [typeclasses eauto], but that sometimes fails. *)
Ltac specintro :=
eapply pq_rhs; [
repeat match goal with H: _ |-- _ |- _ => clear H end;
solve [auto with pullquant]
|];
instantiate;
cbv [eval].
Ltac specintros :=
specintro; let x := fresh "x" in move=> x; try specintros; move: x.
End PullQuant.
(*
The spec_reads connective, [S <@ R].
It is like spec_at but requires S to not only preserve the validity of R but
keep the memory in R's footprint unchanged.
*)
Definition spec_reads S R := Forall s : PState, (eq_pred s |-- R) ->> S @ eq_pred s.
Infix "<@" := spec_reads (at level 44, left associativity).
Instance spec_reads_entails:
Proper (lentails ++> lentails --> lentails) spec_reads.
Proof.
move=> S S' HS R R' HR. red in HR. rewrite /spec_reads. cancel1 => s.
by rewrite ->HS, ->HR.
Qed.
Instance spec_reads_equiv:
Proper (lequiv ==> lequiv ==> lequiv) spec_reads.
Proof.
move=> S S' HS R R' HR. rewrite /spec_reads. setoid_rewrite HS.
by setoid_rewrite HR.
Qed.
Lemma spec_reads_alt S R:
S <@ R -|- Forall s, (eq_pred s |-- R ** ltrue) ->> S @ eq_pred s.
Proof.
rewrite /spec_reads. split.
- specintros => s Hs. rewrite <-lentails_eq in Hs.
case: Hs => sR [sframe [Hs [HsR _]]].
apply lforallL with sR. apply lpropimplL.
- by apply-> lentails_eq.
etransitivity; [apply (spec_frame (eq_pred sframe))|]. autorewrite with push_at.
rewrite stateSplitsAs_eq; [|eapply Hs]. done.
- cancel1 => s. apply: lpropimplR => Hs. apply lpropimplL => //.
rewrite ->Hs. by ssimpl.
Qed.
(* This definition can be more convenient in metatheory. *)
Lemma spec_reads_alt_meta S R : S <@ R -|- Forall s, R s ->> S @ eq_pred s.
Proof. rewrite /spec_reads. by setoid_rewrite <-lentails_eq. Qed.
Lemma spec_reads_ex S T f: Forall x:T, S <@ f x -|- S <@ lexists f.
Proof.
setoid_rewrite spec_reads_alt_meta. split.
- specintros => s [x Hx]. apply lforallL with x. apply lforallL with s.
by apply lpropimplL.
- specintros => x s Hf.
apply lforallL with s. apply: lpropimplL => //. econstructor. eassumption.
Qed.
Lemma spec_reads_frame S R:
S |-- S <@ R.
Proof. rewrite /spec_reads. specintros => s Hs. apply spec_frame. Qed.
Lemma spec_reads_entails_at S {HEx: AtEx S} R:
S <@ R |-- S @ R.
Proof.
rewrite spec_reads_alt_meta. rewrite ->(ILFun_exists_eq R).
specintros => s Hs. apply lforallL with s. by apply: lpropimplL.
Qed.
Local Transparent ILFun_Ops SABIOps.
Lemma emp_unit : empSP -|- eq_pred sa_unit.
split; simpl; move => x H.
+ destruct H as [H _]; assumption.
+ exists H; tauto.
Qed.
Lemma spec_at_entails_reads S {HContra: AtContra S} R:
S @ R |-- S <@ R.
Proof. rewrite /spec_reads. specintros => s Hs. by rewrite <-Hs. Qed.
Lemma spec_reads_eq_at S s:
S <@ eq_pred s -|- S @ eq_pred s.
Proof.
rewrite /spec_reads. split.
- apply lforallL with s. exact: lpropimplL.
- specintros => s' Hs'. rewrite <-lentails_eq in Hs'.
simpl in Hs'; rewrite -> Hs'; reflexivity.
Qed.
Lemma spec_reads_emp S:
S <@ empSP -|- S.
Proof.
rewrite emp_unit spec_reads_eq_at -emp_unit. by rewrite spec_at_emp.
Qed.
Corollary spec_reads_byteIs S p b:
S <@ byteIs p b -|- S @ byteIs p b.
Proof. apply spec_reads_eq_at. Qed.
Corollary spec_reads_flagIs S (p:Flag) b:
S <@ (p~=b) -|- S @ (p~=b).
Proof. apply spec_reads_eq_at. Qed.
Corollary spec_reads_regIs S (p:AnyReg) b:
S <@ (p~=b) -|- S @ (p~=b).
Proof. apply spec_reads_eq_at. Qed.
Lemma spec_reads_merge S R1 R2:
S <@ R1 <@ R2 |-- S <@ (R1 ** R2).
Proof.
setoid_rewrite spec_reads_alt_meta.
specintros => s [s1 [s2 [Hs [Hs1 Hs2]]]].
apply lforallL with s2. apply lpropimplL; first done.
rewrite spec_reads_alt_meta.
assert ((Forall s', R1 s' ->> S @ eq_pred s') |-- S @ eq_pred s1) as Htmp.
- apply lforallL with s1. by apply lpropimplL.
rewrite ->Htmp => {Htmp}. autorewrite with push_at.
rewrite stateSplitsAs_eq; [|eapply Hs]. done.
Qed.
Lemma spec_reads_split S {HS: AtEx S} R1 R2:
S <@ (R1 ** R2) |-- S <@ R1 <@ R2.
Proof.
rewrite /spec_reads.
specintros => s2 Hs2 s1 Hs1. autorewrite with push_at.
rewrite (ILFun_exists_eq (eq_pred s1 ** eq_pred s2)).
specintros => s Hs. rewrite ->lentails_eq in Hs. apply lforallL with s.
apply lpropimplL => //. by rewrite <-Hs1, <-Hs2.
Qed.
Lemma spec_reads_swap' S R1 R2:
S <@ R1 <@ R2 |-- S <@ R2 <@ R1.
Proof.
rewrite /spec_reads.
specintros => s1 Hs1 s2 Hs2. rewrite spec_at_swap.
apply lforallL with s2. apply lpropimplL => //. rewrite spec_at_forall.
apply lforallL with s1. rewrite spec_at_propimpl. exact: lpropimplL.
Qed.
Lemma spec_reads_swap S R1 R2:
S <@ R1 <@ R2 -|- S <@ R2 <@ R1.
Proof. split; apply spec_reads_swap'. Qed.
Lemma spec_reads_forall A S R:
(Forall a:A, S a) <@ R -|- Forall a:A, (S a <@ R).
Proof.
rewrite /spec_reads. split.
- specintros => a s' Hs'. apply lforallL with s'. apply: lpropimplL => //.
autorewrite with push_at. by apply lforallL with a.
- specintros => s' Hs' a.
apply lforallL with a. apply lforallL with s'. exact: lpropimplL.
Qed.
Lemma spec_reads_true R: ltrue <@ R -|- ltrue.
Proof.
rewrite ltrue_is_forall. rewrite spec_reads_forall.
split; specintro => [[]].
Qed.
Lemma spec_reads_and S1 S2 R:
(S1 //\\ S2) <@ R -|- (S1 <@ R) //\\ (S2 <@ R).
Proof.
rewrite !land_is_forall. rewrite spec_reads_forall.
split; by cancel1 => [[]].
Qed.
Lemma spec_reads_exists A S R:
Exists a:A, (S a <@ R) |-- (Exists a:A, S a) <@ R.
Proof.
rewrite /spec_reads. apply: lexistsL => a. specintros => s' Hs'.
autorewrite with push_at. apply lexistsR with a. apply lforallL with s'.
exact: lpropimplL.
Qed.
Lemma spec_reads_or S1 S2 R:
(S1 <@ R) \\// (S2 <@ R) |-- (S1 \\// S2) <@ R.
Proof.
rewrite !lor_is_exists. rewrite <-spec_reads_exists. by cancel1 => [[]].
Qed.
Lemma spec_reads_impl S1 S2 R:
(S1 -->> S2) <@ R |-- S1 <@ R -->> S2 <@ R.
Proof.
rewrite /spec_reads. apply: limplAdj. specintros => s Hs.
apply: landAdj. apply lforallL with s. apply lpropimplL => //.
apply: limplAdj. rewrite landC. apply: landAdj.
apply lforallL with s. apply lpropimplL => //. apply: limplAdj.
autorewrite with push_at. rewrite landC. apply: landAdj. reflexivity.
Qed.
Lemma spec_at_reads S R1 R:
S <@ R1 @ R -|- S @ R <@ R1.
Proof.
rewrite /spec_reads. split.
- specintros => s Hs. autorewrite with push_at.
apply lforallL with s. autorewrite with push_at.
apply lpropimplL => //. by rewrite sepSPC.
- autorewrite with push_at. specintro => s.
autorewrite with push_at. specintro => Hs.
apply lforallL with s. apply: lpropimplL => //.
autorewrite with push_at. by rewrite sepSPC.
Qed.
Hint Rewrite spec_at_reads : push_at.
Instance AtEx_reads S R {HS: AtEx S}: AtEx (S <@ R) := _.
Instance AtCovar_reads S R {HS: AtCovar S}: AtCovar (S <@ R) := _.
Instance AtContra_reads S R {HS: AtContra S}: AtContra (S <@ R) := _.
Module Export PullQuant_reads.
Import Existentials.
Lemma pq_reads S t:
match find t with
| Some (mkf _ f) =>
PullQuant (S <@ eval t) (fun a => S <@ f a)
| None => True
end.
Proof.
move: (@find_correct t). case: (find t) => [[A f]|]; last done.
move=> Heval. red. rewrite ->Heval. by apply_and spec_reads_ex.
Qed.
Hint Extern 0 (PullQuant (?S <@ ?R) _) =>
let t := quote_term R in
apply (@pq_reads S t) : pullquant.
Lemma pq_reads_rec S R A f:
PullQuant S f ->
PullQuant (S <@ R) (fun a:A => f a <@ R).
Proof.
rewrite /PullQuant => Hf. rewrite <-Hf. by rewrite spec_reads_forall.
Qed.
(* If we didn't find anything to pull from the frame itself, recurse under it. *)
(* Unfortunately, Hint Resolve doesn't work here. For some obscure reason,
there has to be an underscore for the last argument. *)
Hint Extern 1 (PullQuant (?S <@ ?R) _) =>
eapply (@pq_reads_rec S R _ _) : pullquant.
End PullQuant_reads.
Lemma spec_at_later S R:
(|> S) @ R -|- |> (S @ R).
Proof.
split => k P; reflexivity.
Qed.
Hint Rewrite spec_at_later : push_at.
Local Transparent ILLaterPreOps.
Lemma spec_reads_later S R: (|> S) <@ R -|- |> (S <@ R).
split => k P /=; rewrite /spec_fun /=; eauto.
Qed.
Hint Rewrite <-
spec_at_later
spec_reads_later
: push_later.
Hint Rewrite @spec_later_exists_inhabited
using repeat constructor : push_later.
Lemma spec_lob_context C S: (C //\\ |> S |-- S) -> C |-- S.
Proof.
etransitivity.
- apply landR; first apply ltrueR. reflexivity.
apply: landAdj. apply: spec_lob. rewrite spec_later_impl.
apply: limplAdj. apply: limplL; last by rewrite landC.
apply spec_later_weaken.
Qed.
Instance AtEx_later S {HS: AtEx S} : AtEx (|> S).
Proof.
move=> A f. rewrite spec_at_later.
red in HS. rewrite <-HS. rewrite spec_later_forall. cancel1 => x.
by rewrite spec_at_later.
Qed.
Instance AtCovar_later S {HS: AtCovar S} : AtCovar (|> S).
Proof.
move=> P Q HPQ. autorewrite with push_at. by rewrite ->(HS _ _ HPQ).
Qed.
Instance AtContra_later S {HS: AtContra S} : AtContra (|> S).
Proof.
move=> P Q HPQ. autorewrite with push_at. by rewrite ->(HS _ _ HPQ).
Qed.
|
module Issue840a where
------------------------------------------------------------------------
-- Prelude
record ⊤ : Set where
data ⊥ : Set where
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
data Bool : Set where
true false : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
postulate String : Set
{-# BUILTIN STRING String #-}
primitive primStringEquality : String → String → Bool
infixr 4 _,_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
------------------------------------------------------------------------
-- Other stuff
mutual
infixl 5 _,_∶_
data Signature : Set₁ where
∅ : Signature
_,_∶_ : (Sig : Signature)
(ℓ : String)
(A : Record Sig → Set) →
Signature
record Record (Sig : Signature) : Set where
constructor rec
field fun : Record-fun Sig
Record-fun : Signature → Set
Record-fun ∅ = ⊤
Record-fun (Sig , ℓ ∶ A) = Σ (Record Sig) A
_∈_ : String → Signature → Set
ℓ ∈ ∅ = ⊥
ℓ ∈ (Sig , ℓ′ ∶ A) with primStringEquality ℓ ℓ′
... | true = ⊤
... | false = ℓ ∈ Sig
Restrict : (Sig : Signature) (ℓ : String) → ℓ ∈ Sig → Signature
Restrict ∅ ℓ ()
Restrict (Sig , ℓ′ ∶ A) ℓ ℓ∈ with primStringEquality ℓ ℓ′
... | true = Sig
... | false = Restrict Sig ℓ ℓ∈
Proj : (Sig : Signature) (ℓ : String) {ℓ∈ : ℓ ∈ Sig} →
Record (Restrict Sig ℓ ℓ∈) → Set
Proj ∅ ℓ {}
Proj (Sig , ℓ′ ∶ A) ℓ {ℓ∈} with primStringEquality ℓ ℓ′
... | true = A
... | false = Proj Sig ℓ {ℓ∈}
_∣_ : {Sig : Signature} → Record Sig →
(ℓ : String) {ℓ∈ : ℓ ∈ Sig} → Record (Restrict Sig ℓ ℓ∈)
_∣_ {Sig = ∅} r ℓ {}
_∣_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with primStringEquality ℓ ℓ′
... | true = Σ.proj₁ r
... | false = _∣_ (Σ.proj₁ r) ℓ {ℓ∈}
infixl 5 _·_
_·_ : {Sig : Signature} (r : Record Sig)
(ℓ : String) {ℓ∈ : ℓ ∈ Sig} →
Proj Sig ℓ {ℓ∈} (r ∣ ℓ)
_·_ {Sig = ∅} r ℓ {}
_·_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with primStringEquality ℓ ℓ′
... | true = Σ.proj₂ r
... | false = _·_ (Σ.proj₁ r) ℓ {ℓ∈}
R : Set → Signature
R A = ∅ , "f" ∶ (λ _ → A → A)
, "x" ∶ (λ _ → A)
, "lemma" ∶ (λ r → ∀ y → (r · "f") y ≡ y)
record GS (A B : Set) : Set where
field
get : A → B
set : A → B → A
get-set : ∀ a b → get (set a b) ≡ b
set-get : ∀ a → set a (get a) ≡ a
f : {A : Set} →
GS (Record (R A))
(Record (∅ , "f" ∶ (λ _ → A → A)
, "lemma" ∶ (λ r → ∀ x → (r · "f") x ≡ x)))
f = record
{ set = λ r f-lemma → rec (rec (rec (rec _
, f-lemma · "f")
, r · "x")
, f-lemma · "lemma")
; get-set = λ { (rec (rec (rec (_ , _) , _) , _))
(rec (rec (_ , _) , _)) → refl }
; set-get = λ { (rec (rec (rec (rec _ , _) , _) , _)) → refl }
}
|
# distances between points with nearest neighbor approx
# x = c(1,2,3,4,5,6,7,8,9)
# y = c(1,2,3,4,5,6,7,8,9)
#
# a = x + 2
# b = y * 2
#
# all = c(a,b,x,y)
# plot(a,b,pch = 20, ylim = c(min(all), max(all)), xlim = c(min(all), max(all)), asp = 1)
# points(x,y,pch = 20, col = 'red')
#
#
# X = cbind(x,y)
# A = cbind(a,b)
nearest_xy = function(A,X,to = 1, plot = F) {
Z = as.matrix(dist(rbind(X,A)))
aseq = ((length(x)+1):length(c(x,a))); xseq = (1:(length(x)))
Z = Z [ aseq , xseq ]
# so now have distances between every point in each xy dataset. now pick which set to choose the nearest neighbor
# if the A dataset is the one to match to...
if (to == 1) {
v = apply(Z, 1, 'min')
j = 1
m = c()
for (i in aseq) {
jkl = Z[paste0(i),]
lkj = which(jkl %in% v[paste0(i)])[1]
m[j] = lkj
j = j + 1
}
T = cbind(A,X[m,])
}
# if the X dataset is the one to match to...
else if (to == 2) {
v = apply(Z, 2, 'min')
j = 1
m = c()
for (i in xseq) {
jkl = Z[,paste0(i)]
lkj = which(jkl %in% v[paste0(i)])[1]
m[j] = lkj
j = j + 1
}
T = cbind(X,A[m,])
}
else {stop('pick a variable to match to.')}
if (plot == T) {
par(bg = 'grey90')
plot(T[,1], T[,2], type = 'n', ylim = c(min(all), max(all)), xlim = c(min(all), max(all)), asp = 1)
points(X[,1], X[,2], col = 'black', pch = 20)
points(A[,1], A[,2], col = 'blue3', pch = 20)
points(T[,3], T[,4], col = 'red3', pch = 1, cex = 1.5)
segments(T[,1], T[,2],T[,3], T[,4], col = 'red3', lty = 3)
}
}
|
Importantly , the concentration of individual proteins ranges from a few molecules per cell to hundreds of thousands . In fact , about a third of all proteins is not produced in most cells or only induced under certain circumstances . For instance , of the 20 @,@ 000 or so proteins encoded by the human genome only 6 @,@ 000 are detected in <unk> cells .
|
/*
* Copyright 2014 Marc Normandin
*
* Licensed 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.
*/
/*
* pso.h
*
* Created on: Jun 30, 2013
* Author: marc
*/
#ifndef PSO_H_
#define PSO_H_
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdlib>
#include <gsl/gsl_rng.h>
#include <limits>
#include <fstream>
#include <cassert>
#include "rng.h"
#include "dim.h"
#include "particle.h"
template<class FitnessFunction>
class PSO
{
public:
// This routine is used by the PSO unit test
PSO(const unsigned int numParticles, const std::vector<Dim>& dim,
const gslseed_t seed, FitnessFunction& fitnessFunction, const unsigned int maxIterations)
: mNumParticles(numParticles), mGBest(dim), mDim(dim), mRng(seed), mFitnessFunction(fitnessFunction),
mMaxIterations(maxIterations)
{
mParticles.reserve(mNumParticles);
}
unsigned int getNumParticles() const
{
return mNumParticles;
}
const Particle& iterate()
{
createRandomParticles();
unsigned int numIterations = 0;
std::vector<double> particleFitnesses(mParticles.size());
do
{
// Evaluate the fitness/objective function
mFitnessFunction(mParticles, &particleFitnesses);
//For each particle
for (unsigned int i = 0; i < mParticles.size(); i++)
{
// Calculate fitness value
const prob_t fitness = particleFitnesses[i]; //
// If the fitness value is better than the best fitness value (pBest) in history
// set current value as the new pBest
mParticles[i].updateFitness( fitness );
}
// Choose the particle with the best fitness value of all the particles as the gBest
std::vector<Particle>::const_iterator best = std::max_element(mParticles.begin(), mParticles.end());
mGBest = Particle( best->getBestPosition(), best->getBestFitness() );
// Update the inertia weight
const double inertiaWeight = computeInertiaWeight(numIterations, mMaxIterations);
// For each particle
for (unsigned int i = 0; i < mParticles.size(); i++)
{
mParticles[i].updatePosition( mGBest, mDim, mCognitiveWeight, mSocialWeight, mRng, inertiaWeight );
}
numIterations++;
}
while(numIterations < mMaxIterations);
return mGBest;
}
protected:
PSO(const PSO&);
void operator=(const PSO&);
void createRandomParticles() {
mParticles.clear(); // Remove previous particles in the container
// For each particle
for (unsigned int i = 0; i < mNumParticles; i++)
{
std::vector<dim_t> pos;
// For each dimension
for (unsigned int d = 0; d < mDim.size(); d++)
{
dim_t posd = mRng.uniform( mDim[d].min(), mDim[d].max() );
pos.push_back(posd);
}
// Add the particle to the collection
mParticles.push_back( Particle(pos) );
}
}
// Compute inertia. This is based on equation 4.1 from:
// http://www.hindawi.com/journals/ddns/2010/462145/
double computeInertiaWeight(const unsigned int iteration, const unsigned int maxInterations) const
{
// Note. We add +1 because our iterations go from 0 to max-1.
double inertiaWeight = (mOmega1 - mOmega2) * ( (maxInterations - (iteration+1.0)) / (1.0 * (iteration+1.0) ) ) + mOmega2;
return inertiaWeight;
}
private:
unsigned int mNumParticles;
std::vector<Particle> mParticles; // Particle positions
Particle mGBest;
std::vector<Dim> mDim;
// These values control how random the particle velocities are
static const double mCognitiveWeight;
static const double mSocialWeight;
// These values control the rate of convergence
static const double mOmega1;
static const double mOmega2;
RandomNumberGenerator mRng;
FitnessFunction& mFitnessFunction;
unsigned int mMaxIterations;
};
#endif /* PSO_H_ */
|
# -*- coding: utf-8 -*-
import turtle
import numpy
import time
import random
from collections import defaultdict
import abc
# UI object
turtle.colormode(255)
#turtle.delay(0) # if want to see the drawing procedure slower, comment this line
myPen = turtle.Turtle()
myPen.speed(0)
myPen.color((0, 0, 0)) #grid color = black
myPen.hideturtle()
# Global Constant
MIN_NUM = 1
MAX_NUM = 9
INT_LIST = [1, 2, 3, 4, 5, 6, 7, 8, 9]
TRANS_PROB = 0.3
# UI Constants
topLeft_x = -150
topLeft_y = 150
cellSize = 36
# Create Grid
class visualizeRandomWalk:
def __init__(self, GRID_SIZE=9, seed=5):
self.GRID_SIZE = GRID_SIZE
self.__grid = numpy.zeros((self.GRID_SIZE, self.GRID_SIZE), dtype=int)
random.seed(seed)
numpy.random.seed(seed) #set up random seed
self.__cages = defaultdict(lambda: [0, []])
def populateGrid(self):
for cell in range(self.GRID_SIZE * self.GRID_SIZE):
row = cell // self.GRID_SIZE
col = cell % self.GRID_SIZE
# print(cell)
if self.__grid[row, col] == 0:
values = INT_LIST
random.shuffle(values)
for num in values:
if self.validNum(row, col, num):
self.__grid[row, col] = num
if self.fullGrid():
return True
elif self.populateGrid():
return True
break
self.__grid[row, col] = 0
def validNum(self, row, col, n):
if n not in self.getRow(row):
if n not in self.getCol(col):
if n not in self.getNonet((row, col)):
return True
return False
def fullGrid(self):
for i in range(self.GRID_SIZE):
row = self.getRow(i)
col = self.getCol(i)
if (0 in row) or (0 in col):
return False
return True
def getNonet(self, coordinate):
row = coordinate[0] // 3
col = coordinate[1] // 3
return self.__grid[3 * row:3 * row + 3, 3 * col:3 * col + 3]
def getRow(self, idx):
return self.__grid[idx, :]
def getCol(self, idx):
return self.__grid[:, idx]
# Generate Cages
def genCages(self, method='rw', maxCageSize=5):
if method == 'rw':
cageInd = 0
self.currentCell = []
self.nextCell = []
self.notAssigned = []
maxCageSize = maxCageSize
for row in range(len(self.__grid[0])):
for column in range(len(self.__grid[0])):
self.notAssigned.append([row, column]) # initialize with all poosition of rows and columns cells
random.shuffle(self.notAssigned) # [[,],[,],[,]] shuffle the sequence of cells
self.cageSize = defaultdict(list)
self.__cagesRw = defaultdict(list) # {'cageID': [[x1,y1],[x2, y2]]}
self.cageValues = defaultdict(list) # {'cageID': [[val_1], [val_2]...] , }
self.cageSums = defaultdict(list) # {'cageID': [val] , }
while self.notAssigned: # cell: [x1,y1]
flag = True
self.currentCell = self.notAssigned[0]
self.__cagesRw[cageInd].append(self.currentCell)
self.cageValues[cageInd].append(self.__grid[self.currentCell[0]][self.currentCell[1]])
self.cageSums[cageInd] = [self.__grid[self.currentCell[0]][self.currentCell[1]]]
self.cageSize[cageInd] = len(self.cageValues[cageInd])
walkDirectionList = [[0, 1], [0, -1], [1, 0], [-1, 0]] # right, left, up, down
while walkDirectionList != []:
direction = random.choice(walkDirectionList)
self.nextCell = [self.currentCell[0] + direction[0], self.currentCell[1] + direction[1]]
# if not acceptable, delete that direction and redo walk
while self.nextCell[0] < 0 or self.nextCell[0] > 8 or self.nextCell[1] < 0 or self.nextCell[
1] > 8 \
or self.nextCell not in self.notAssigned or [
self.__grid[self.nextCell[0]][self.nextCell[1]]] in \
self.cageValues[cageInd]:
walkDirectionList.remove(direction)
# if no available direction, go to next notAssigned cell
if walkDirectionList == []:
flag = False
break
direction = random.choice(walkDirectionList)
self.nextCell = [self.currentCell[0] + direction[0], self.currentCell[1] + direction[1]]
# if no available direction go to next not assigned cell, other wise append the next cell from walk
if flag == False or self.cageSize[cageInd] == maxCageSize:
cageInd += 1
self.notAssigned.remove(self.currentCell)
break #back to while notAssigned loop, start from a new cell
# append cells to cages, cell value to cage_value, cell value add into cageSums
self.__cagesRw[cageInd].append(self.nextCell)
self.cageValues[cageInd].append([self.__grid[self.nextCell[0]][self.nextCell[1]]])
self.cageSize[cageInd] = len(self.cageValues[cageInd])
if self.cageSums[cageInd] == []:
self.cageSums[cageInd] = [self.__grid[self.nextCell[0]][self.nextCell[1]]]
else:
self.cageSums[cageInd] = [
self.cageSums[cageInd][0] + self.__grid[self.nextCell[0]][self.nextCell[1]]]
# remove current cell from not assigned list
self.notAssigned.remove(self.currentCell)
# next cell becomes current cell, reset walk_direction_list
self.currentCell = self.nextCell
walkDirectionList = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for cageID in self.__cagesRw.keys():
self.__cages[cageID] = (self.cageSums[cageID][0], self.__cagesRw[cageID])
return print('Killer sudoku has been generated')
elif method == 'oc':
randValue = numpy.random.uniform(0, 1, 100)
# cages = defaultdict(lambda: [0, []])
cageID = 0
for row in range(self.GRID_SIZE):
for col in range(self.GRID_SIZE):
# First cell
if row == 0 and col == 0:
self.__cages[cageID][1].append((row, col))
self.__cages[cageID][0] += self.__grid[row, col]
# Identify adjacent cages and their sizes
if col > 0:
leftCage = self.getCageID(self.__cages, (row, col - 1))
leftCageSize = self.getSize(self.__cages, leftCage)
leftCageValues = [self.__grid[cell[0], cell[1]] for cell in self.__cages[leftCage][1]]
if row > 0:
aboveCage = self.getCageID(self.__cages, (row - 1, col))
aboveCageSize = self.getSize(self.__cages, aboveCage)
aboveCageValues = [self.__grid[cell[0], cell[1]] for cell in self.__cages[aboveCage][1]]
# Only consider cells to the left of first row
if row == 0 and col > 0:
rand = random.choice(randValue)
if leftCageSize < maxCageSize and rand >= TRANS_PROB:
self.__cages[cageID][1].append((row, col))
self.__cages[cageID][0] += self.__grid[row, col]
else:
cageID += 1
self.__cages[cageID][1].append((row, col))
self.__cages[cageID][0] += self.__grid[row, col]
# Only consider cells above (no cells to the left)
if row > 0 and col == 0:
rand = random.choice(randValue)
if aboveCageSize < maxCageSize and rand >= TRANS_PROB and self.__grid[row, col] not in aboveCageValues:
self.__cages[aboveCage][1].append((row, col))
self.__cages[aboveCage][0] += self.__grid[row, col]
else:
cageID += 1
self.__cages[cageID][1].append((row, col))
self.__cages[cageID][0] += self.__grid[row, col]
# Consider cells to the left and above
if row > 0 and col > 0:
rand = random.choice(randValue)
if rand >= TRANS_PROB * 2 and aboveCageSize < maxCageSize and self.__grid[row][col] not in aboveCageValues:
self.__cages[aboveCage][1].append((row, col))
self.__cages[aboveCage][0] += self.__grid[row, col]
elif rand >= TRANS_PROB and leftCageSize < maxCageSize and self.__grid[row][col] not in leftCageValues:
self.__cages[leftCage][1].append((row, col))
self.__cages[leftCage][0] += self.__grid[row, col]
else:
cageID += 1
self.__cages[cageID][1].append((row, col))
self.__cages[cageID][0] += self.__grid[row, col]
for cage in list(self.__cages.keys()):
self.__cages[cage] = tuple(self.__cages[cage])
return print('Killer sudoku has been generated')
else:
raise AttributeError('The input method not found')
def getGrid(self):
return self.__grid
def getCages(self):
return self.__cages
def getCageID(self, dic, pos):
for key, value in dic.items():
cellList = value[1]
for cell in cellList:
if cell == pos:
return key
# Function to get size of the cage
def getSize(self, dic, cageID):
size = len(dic[cageID][1])
return size
# UI methods
def render(self):
for row in range(0, 10):
myPen.pensize(1)
myPen.penup() # Puts pen up for defaut turtle
myPen.goto(topLeft_x, topLeft_y - row * cellSize) # draw row from the topleft to the bottom
myPen.pendown() #begin to draw
myPen.goto(topLeft_x + 9 * cellSize, topLeft_y - row * cellSize) #draw the line till 9 cellsize long,
#myPen.penup()
for col in range(0, 10):
myPen.pensize(1)
myPen.penup()
myPen.goto(topLeft_x + col * cellSize, topLeft_y)
myPen.pendown()
myPen.goto(topLeft_x + col * cellSize, topLeft_y - 9 * cellSize)
#myPen.penup()
for cageRowLine in range(0, 10):
if (cageRowLine % 3) == 0:
myPen.pensize(3)
myPen.penup()
myPen.goto(topLeft_x, topLeft_y - cageRowLine * cellSize) #draw horizontal lines
myPen.pendown()
myPen.goto(topLeft_x + 9 * cellSize, topLeft_y - cageRowLine * cellSize)
#myPen.penup()
for cageColLine in range(0, 10):
if (cageColLine % 3) == 0:
myPen.pensize(3)
myPen.penup()
myPen.goto(topLeft_x + cageColLine * cellSize, topLeft_y) #drawing vertical lines
myPen.pendown()
myPen.goto(topLeft_x + cageColLine * cellSize, topLeft_y - 9 * cellSize)
#myPen.penup()
for row in range(self.GRID_SIZE):
for col in range(self.GRID_SIZE):
if self.__grid[row, col] != 0:
self.text(self.__grid[row, col], topLeft_x + col * cellSize + 13,
topLeft_y - row * cellSize - cellSize + 4.5, 18)
for cage in list(self.__cages.keys()):
color = self.getRandomColor()
for cell in self.__cages[cage][1]:
cellRow = cell[0]
cellCol = cell[1]
self.fillCellColor(cellRow, cellCol, color)
self.text(self.__grid[cellRow, cellCol], topLeft_x + cellCol * cellSize + 13,
topLeft_y - cellRow * cellSize - cellSize + 4.5, 18)
for cage in list(self.__cages.keys()): #draw sum in the cage
self.text(self.__cages[cage][0], #number - sum
topLeft_x + self.__cages[cage][1][0][1] * cellSize + 3, # place on x-axis to try,
topLeft_y - self.__cages[cage][1][0][0] * cellSize - cellSize + 23, #locate the bottom of number on this line, need to move down
7) # size to try
turtle.getscreen()._root.mainloop()
def getRandomColor(self): #higher the first #, the lighter the color
R = random.randrange(100, 256, 4)
G = random.randrange(80, 256, 4)
B = random.randrange(100, 256, 4)
return (R, G, B)
def text(self, message, x, y, size): #draw the sum on the top-left corner
FONT = ('Arial', size, 'normal')
myPen.penup()
myPen.goto(x, y)
myPen.write(message, align="left", font=FONT)
def fillCellColor(self, row, col, color):
myPen.penup()
myPen.goto(topLeft_x + col * cellSize, topLeft_y - row * cellSize)
myPen.pensize(0.5)
myPen.pendown()
myPen.fillcolor(color)
myPen.begin_fill()
for side in range(4):
myPen.forward(cellSize)
myPen.right(90)
myPen.end_fill()
myPen.penup()
'''
KS1 = KillerSudoku(Grid, 5)
KS1.populateGrid()
KS1.genCages(method='oc', maxCageSize=5)
print(KS1.getCages())
print(KS1.getGrid())
KS1.render()
'''
'''
KS1 = killerSudoku(GRID_SIZE=9,seed=5)
KS1.populateGrid()
KS1.genCages(method='oc', maxCageSize=5)
print(KS1.getCages())
print(len(KS1.getCages()))
t = KS1.getCages()
print(random.choice(t[len(KS1.getCages())-1][1]))
'''
|
[GOAL]
G : Type u_1
inst✝ : Group G
V : Set G
⊢ index ∅ V = 0
[PROOFSTEP]
simp only [index, Nat.sInf_eq_zero]
[GOAL]
G : Type u_1
inst✝ : Group G
V : Set G
⊢ 0 ∈ Finset.card '' {t | ∅ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V} ∨
Finset.card '' {t | ∅ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V} = ∅
[PROOFSTEP]
left
[GOAL]
case h
G : Type u_1
inst✝ : Group G
V : Set G
⊢ 0 ∈ Finset.card '' {t | ∅ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
use∅
[GOAL]
case h
G : Type u_1
inst✝ : Group G
V : Set G
⊢ ∅ ∈ {t | ∅ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V} ∧ Finset.card ∅ = 0
[PROOFSTEP]
simp only [Finset.card_empty, empty_subset, mem_setOf_eq, eq_self_iff_true, and_self_iff]
[GOAL]
G : Type u_1
inst✝¹ : Group G
inst✝ : TopologicalSpace G
K₀ : PositiveCompacts G
U : Set G
⊢ prehaar (↑K₀) U ⊥ = 0
[PROOFSTEP]
rw [prehaar, Compacts.coe_bot, index_empty, Nat.cast_zero, zero_div]
[GOAL]
G : Type u_1
inst✝¹ : Group G
inst✝ : TopologicalSpace G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
⊢ 0 ≤ prehaar (↑K₀) U K
[PROOFSTEP]
apply div_nonneg
[GOAL]
case ha
G : Type u_1
inst✝¹ : Group G
inst✝ : TopologicalSpace G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
⊢ 0 ≤ ↑(index (↑K) U)
[PROOFSTEP]
norm_cast
[GOAL]
case hb
G : Type u_1
inst✝¹ : Group G
inst✝ : TopologicalSpace G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
⊢ 0 ≤ ↑(index (↑K₀) U)
[PROOFSTEP]
norm_cast
[GOAL]
case ha
G : Type u_1
inst✝¹ : Group G
inst✝ : TopologicalSpace G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
⊢ 0 ≤ index (↑K) U
[PROOFSTEP]
apply zero_le
[GOAL]
case hb
G : Type u_1
inst✝¹ : Group G
inst✝ : TopologicalSpace G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
⊢ 0 ≤ index (↑K₀) U
[PROOFSTEP]
apply zero_le
[GOAL]
G : Type u_1
inst✝¹ : Group G
inst✝ : TopologicalSpace G
K₀ : Set G
f : Compacts G → ℝ
⊢ f ∈ haarProduct K₀ ↔ ∀ (K : Compacts G), f K ∈ Icc 0 ↑(index (↑K) K₀)
[PROOFSTEP]
simp only [haarProduct, Set.pi, forall_prop_of_true, mem_univ, mem_setOf_eq]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K V : Set G
hK : IsCompact K
hV : Set.Nonempty (interior V)
⊢ ∃ n, n ∈ Finset.card '' {t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩
[GOAL]
case intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K V : Set G
hK : IsCompact K
hV : Set.Nonempty (interior V)
t : Finset G
ht : K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
⊢ ∃ n, n ∈ Finset.card '' {t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
exact ⟨t.card, t, ht, rfl⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K V : Set G
hK : IsCompact K
hV : Set.Nonempty (interior V)
⊢ ∃ t, K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V ∧ Finset.card t = index K V
[PROOFSTEP]
have := Nat.sInf_mem (index_defined hK hV)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K V : Set G
hK : IsCompact K
hV : Set.Nonempty (interior V)
this :
sInf (Finset.card '' {t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}) ∈
Finset.card '' {t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
⊢ ∃ t, K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V ∧ Finset.card t = index K V
[PROOFSTEP]
rwa [mem_image] at this
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
⊢ index (↑K) V ≤ index ↑K ↑K₀ * index (↑K₀) V
[PROOFSTEP]
obtain ⟨s, h1s, h2s⟩ := index_elim K.isCompact K₀.interior_nonempty
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
⊢ index (↑K) V ≤ index ↑K ↑K₀ * index (↑K₀) V
[PROOFSTEP]
obtain ⟨t, h1t, h2t⟩ := index_elim K₀.isCompact hV
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ index (↑K) V ≤ index ↑K ↑K₀ * index (↑K₀) V
[PROOFSTEP]
rw [← h2s, ← h2t, mul_comm]
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ index (↑K) V ≤ Finset.card t * Finset.card s
[PROOFSTEP]
refine' le_trans _ Finset.card_mul_le
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ index (↑K) V ≤ Finset.card (t * s)
[PROOFSTEP]
apply Nat.sInf_le
[GOAL]
case intro.intro.intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ Finset.card (t * s) ∈ Finset.card '' {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
refine' ⟨_, _, rfl⟩
[GOAL]
case intro.intro.intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ t * s ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
rw [mem_setOf_eq]
[GOAL]
case intro.intro.intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ ↑K ⊆ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
refine' Subset.trans h1s _
[GOAL]
case intro.intro.intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
apply iUnion₂_subset
[GOAL]
case intro.intro.intro.intro.hm.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
⊢ ∀ (i : G), i ∈ s → (fun h => i * h) ⁻¹' ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
intro g₁ hg₁
[GOAL]
case intro.intro.intro.intro.hm.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
g₁ : G
hg₁ : g₁ ∈ s
⊢ (fun h => g₁ * h) ⁻¹' ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
rw [preimage_subset_iff]
[GOAL]
case intro.intro.intro.intro.hm.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
g₁ : G
hg₁ : g₁ ∈ s
⊢ ∀ (a : G), g₁ * a ∈ ↑K₀ → a ∈ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
intro g₂ hg₂
[GOAL]
case intro.intro.intro.intro.hm.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
g₁ : G
hg₁ : g₁ ∈ s
g₂ : G
hg₂ : g₁ * g₂ ∈ ↑K₀
⊢ g₂ ∈ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
have := h1t hg₂
[GOAL]
case intro.intro.intro.intro.hm.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
g₁ : G
hg₁ : g₁ ∈ s
g₂ : G
hg₂ : g₁ * g₂ ∈ ↑K₀
this : g₁ * g₂ ∈ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
⊢ g₂ ∈ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩
[GOAL]
case intro.intro.intro.intro.hm.h.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
g₁ : G
hg₁ : g₁ ∈ s
g₂ : G
hg₂ : g₁ * g₂ ∈ ↑K₀
g₃ : G
hg₃ : g₃ ∈ t
h2V : g₁ * g₂ ∈ (fun h => (fun h => g₃ * h) ⁻¹' V) hg₃
⊢ g₂ ∈ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
rw [mem_preimage, ← mul_assoc] at h2V
[GOAL]
case intro.intro.intro.intro.hm.h.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : ↑K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' ↑K₀
h2s : Finset.card s = index ↑K ↑K₀
t : Finset G
h1t : ↑K₀ ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index (↑K₀) V
g₁ : G
hg₁ : g₁ ∈ s
g₂ : G
hg₂ : g₁ * g₂ ∈ ↑K₀
g₃ : G
hg₃ : g₃ ∈ t
h2V : g₃ * g₁ * g₂ ∈ V
⊢ g₂ ∈ ⋃ (g : G) (_ : g ∈ t * s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
exact mem_biUnion (Finset.mul_mem_mul hg₃ hg₁) h2V
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
⊢ 0 < index (↑K) V
[PROOFSTEP]
unfold index
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
⊢ 0 < sInf (Finset.card '' {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V})
[PROOFSTEP]
rw [Nat.sInf_def, Nat.find_pos, mem_image]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
⊢ ¬∃ x, x ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V} ∧ Finset.card x = 0
[PROOFSTEP]
rintro ⟨t, h1t, h2t⟩
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
t : Finset G
h1t : t ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
h2t : Finset.card t = 0
⊢ False
[PROOFSTEP]
rw [Finset.card_eq_zero] at h2t
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
t : Finset G
h1t : t ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
h2t : t = ∅
⊢ False
[PROOFSTEP]
subst h2t
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
h1t : ∅ ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
⊢ False
[PROOFSTEP]
obtain ⟨g, hg⟩ := K.interior_nonempty
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
h1t : ∅ ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
g : G
hg : g ∈ interior ↑K
⊢ False
[PROOFSTEP]
show g ∈ (∅ : Set G)
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
h1t : ∅ ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
g : G
hg : g ∈ interior ↑K
⊢ g ∈ ∅
[PROOFSTEP]
convert h1t (interior_subset hg)
[GOAL]
case h.e'_5
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
h1t : ∅ ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
g : G
hg : g ∈ interior ↑K
⊢ ∅ = ⋃ (g : G) (_ : g ∈ ∅), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
symm
[GOAL]
case h.e'_5
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
h1t : ∅ ∈ {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
g : G
hg : g ∈ interior ↑K
⊢ ⋃ (g : G) (_ : g ∈ ∅), (fun h => g * h) ⁻¹' V = ∅
[PROOFSTEP]
simp only [Finset.not_mem_empty, iUnion_of_empty, iUnion_empty]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : PositiveCompacts G
V : Set G
hV : Set.Nonempty (interior V)
⊢ ∃ n, n ∈ Finset.card '' {t | ↑K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
exact index_defined K.isCompact hV
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K K' V : Set G
hK' : IsCompact K'
h : K ⊆ K'
hV : Set.Nonempty (interior V)
⊢ index K V ≤ index K' V
[PROOFSTEP]
rcases index_elim hK' hV with ⟨s, h1s, h2s⟩
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K K' V : Set G
hK' : IsCompact K'
h : K ⊆ K'
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K' ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K' V
⊢ index K V ≤ index K' V
[PROOFSTEP]
apply Nat.sInf_le
[GOAL]
case intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K K' V : Set G
hK' : IsCompact K'
h : K ⊆ K'
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K' ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K' V
⊢ index K' V ∈ Finset.card '' {t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
rw [mem_image]
[GOAL]
case intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K K' V : Set G
hK' : IsCompact K'
h : K ⊆ K'
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K' ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K' V
⊢ ∃ x, x ∈ {t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V} ∧ Finset.card x = index K' V
[PROOFSTEP]
refine' ⟨s, Subset.trans h h1s, h2s⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
⊢ index (K₁.carrier ∪ K₂.carrier) V ≤ index K₁.carrier V + index K₂.carrier V
[PROOFSTEP]
rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
⊢ index (K₁.carrier ∪ K₂.carrier) V ≤ index K₁.carrier V + index K₂.carrier V
[PROOFSTEP]
rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ index (K₁.carrier ∪ K₂.carrier) V ≤ index K₁.carrier V + index K₂.carrier V
[PROOFSTEP]
rw [← h2s, ← h2t]
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ index (K₁.carrier ∪ K₂.carrier) V ≤ Finset.card s + Finset.card t
[PROOFSTEP]
refine' le_trans _ (Finset.card_union_le _ _)
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ index (K₁.carrier ∪ K₂.carrier) V ≤ Finset.card (s ∪ t)
[PROOFSTEP]
apply Nat.sInf_le
[GOAL]
case intro.intro.intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ Finset.card (s ∪ t) ∈ Finset.card '' {t | K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
refine' ⟨_, _, rfl⟩
[GOAL]
case intro.intro.intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ s ∪ t ∈ {t | K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
rw [mem_setOf_eq]
[GOAL]
case intro.intro.intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s ∪ t), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
apply union_subset
[GOAL]
case intro.intro.intro.intro.hm.sr
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s ∪ t), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
refine' Subset.trans (by assumption) _
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ K₁.carrier ⊆ ?m.46641
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.intro.intro.hm.tr
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s ∪ t), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
refine' Subset.trans (by assumption) _
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ K₂.carrier ⊆ ?m.46676
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.intro.intro.hm.sr
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V ⊆ ⋃ (g : G) (_ : g ∈ s ∪ t), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
apply biUnion_subset_biUnion_left
[GOAL]
case intro.intro.intro.intro.hm.tr
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V ⊆ ⋃ (g : G) (_ : g ∈ s ∪ t), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
apply biUnion_subset_biUnion_left
[GOAL]
case intro.intro.intro.intro.hm.sr.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ (fun x => x ∈ s.val) ⊆ fun x => x ∈ (s ∪ t).val
[PROOFSTEP]
intro g hg
[GOAL]
case intro.intro.intro.intro.hm.tr.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
⊢ (fun x => x ∈ t.val) ⊆ fun x => x ∈ (s ∪ t).val
[PROOFSTEP]
intro g hg
[GOAL]
case intro.intro.intro.intro.hm.sr.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
g : G
hg : g ∈ fun x => x ∈ s.val
⊢ g ∈ fun x => x ∈ (s ∪ t).val
[PROOFSTEP]
simp only [mem_def] at hg
[GOAL]
case intro.intro.intro.intro.hm.tr.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
g : G
hg : g ∈ fun x => x ∈ t.val
⊢ g ∈ fun x => x ∈ (s ∪ t).val
[PROOFSTEP]
simp only [mem_def] at hg
[GOAL]
case intro.intro.intro.intro.hm.sr.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
g : G
hg : g ∈ s.val
⊢ g ∈ fun x => x ∈ (s ∪ t).val
[PROOFSTEP]
simp only [mem_def, Multiset.mem_union, Finset.union_val, hg, or_true_iff, true_or_iff]
[GOAL]
case intro.intro.intro.intro.hm.tr.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
s : Finset G
h1s : K₁.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K₁.carrier V
t : Finset G
h1t : K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V
h2t : Finset.card t = index K₂.carrier V
g : G
hg : g ∈ t.val
⊢ g ∈ fun x => x ∈ (s ∪ t).val
[PROOFSTEP]
simp only [mem_def, Multiset.mem_union, Finset.union_val, hg, or_true_iff, true_or_iff]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
⊢ index (K₁.carrier ∪ K₂.carrier) V = index K₁.carrier V + index K₂.carrier V
[PROOFSTEP]
apply le_antisymm (index_union_le K₁ K₂ hV)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
⊢ index K₁.carrier V + index K₂.carrier V ≤ index (K₁.carrier ∪ K₂.carrier) V
[PROOFSTEP]
rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
⊢ index K₁.carrier V + index K₂.carrier V ≤ index (K₁.carrier ∪ K₂.carrier) V
[PROOFSTEP]
rw [← h2s]
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
⊢ index K₁.carrier V + index K₂.carrier V ≤ Finset.card s
[PROOFSTEP]
have :
∀ K : Set G,
(K ⊆ ⋃ g ∈ s, (fun h => g * h) ⁻¹' V) →
index K V ≤ (s.filter fun g => ((fun h : G => g * h) ⁻¹' V ∩ K).Nonempty).card :=
by
intro K hK; apply Nat.sInf_le; refine' ⟨_, _, rfl⟩; rw [mem_setOf_eq]
intro g hg; rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩
simp only [mem_preimage] at h2g₀
simp only [mem_iUnion]; use g₀; constructor; swap
· simp only [Finset.mem_filter, h1g₀, true_and_iff]; use g
simp only [hg, h2g₀, mem_inter_iff, mem_preimage, and_self_iff]
exact h2g₀
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
⊢ ∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
[PROOFSTEP]
intro K hK
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
⊢ index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
[PROOFSTEP]
apply Nat.sInf_le
[GOAL]
case hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
⊢ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s) ∈
Finset.card '' {t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
refine' ⟨_, _, rfl⟩
[GOAL]
case hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
⊢ Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s ∈
{t | K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
rw [mem_setOf_eq]
[GOAL]
case hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
⊢ K ⊆ ⋃ (g : G) (_ : g ∈ Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
intro g hg
[GOAL]
case hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
⊢ g ∈ ⋃ (g : G) (_ : g ∈ Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩
[GOAL]
case hm.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g ∈ (fun h => (fun h => g₀ * h) ⁻¹' V) h1g₀
⊢ g ∈ ⋃ (g : G) (_ : g ∈ Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
simp only [mem_preimage] at h2g₀
[GOAL]
case hm.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ g ∈ ⋃ (g : G) (_ : g ∈ Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s), (fun h => g * h) ⁻¹' V
[PROOFSTEP]
simp only [mem_iUnion]
[GOAL]
case hm.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ ∃ i i_1, g ∈ (fun h => i * h) ⁻¹' V
[PROOFSTEP]
use g₀
[GOAL]
case h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ ∃ i, g ∈ (fun h => g₀ * h) ⁻¹' V
[PROOFSTEP]
constructor
[GOAL]
case h.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ g ∈ (fun h => g₀ * h) ⁻¹' V
case h.w
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ g₀ ∈ Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s
[PROOFSTEP]
swap
[GOAL]
case h.w
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ g₀ ∈ Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s
[PROOFSTEP]
simp only [Finset.mem_filter, h1g₀, true_and_iff]
[GOAL]
case h.w
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ Set.Nonempty ((fun h => g₀ * h) ⁻¹' V ∩ K)
[PROOFSTEP]
use g
[GOAL]
case h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ g ∈ (fun h => g₀ * h) ⁻¹' V ∩ K
[PROOFSTEP]
simp only [hg, h2g₀, mem_inter_iff, mem_preimage, and_self_iff]
[GOAL]
case h.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
K : Set G
hK : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
g : G
hg : g ∈ K
g₀ : G
h1g₀ : g₀ ∈ s
h2g₀ : g₀ * g ∈ V
⊢ g ∈ (fun h => g₀ * h) ⁻¹' V
[PROOFSTEP]
exact h2g₀
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
⊢ index K₁.carrier V + index K₂.carrier V ≤ Finset.card s
[PROOFSTEP]
refine'
le_trans
(add_le_add (this K₁.1 <| Subset.trans (subset_union_left _ _) h1s)
(this K₂.1 <| Subset.trans (subset_union_right _ _) h1s))
_
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
⊢ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K₁.carrier)) s) +
Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K₂.carrier)) s) ≤
Finset.card s
[PROOFSTEP]
rw [← Finset.card_union_eq, Finset.filter_union_right]
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
⊢ Finset.card
(Finset.filter
(fun x =>
Set.Nonempty ((fun h => x * h) ⁻¹' V ∩ K₁.carrier) ∨ Set.Nonempty ((fun h => x * h) ⁻¹' V ∩ K₂.carrier))
s) ≤
Finset.card s
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
⊢ Disjoint (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K₁.carrier)) s)
(Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K₂.carrier)) s)
[PROOFSTEP]
exact s.card_filter_le _
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
⊢ Disjoint (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K₁.carrier)) s)
(Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K₂.carrier)) s)
[PROOFSTEP]
apply Finset.disjoint_filter.mpr
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
⊢ ∀ (x : G),
x ∈ s → Set.Nonempty ((fun h => x * h) ⁻¹' V ∩ K₁.carrier) → ¬Set.Nonempty ((fun h => x * h) ⁻¹' V ∩ K₂.carrier)
[PROOFSTEP]
rintro g₁ _ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩
[GOAL]
case intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h1g₂ : g₂ ∈ (fun h => g₁ * h) ⁻¹' V
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h1g₃ : g₃ ∈ (fun h => g₁ * h) ⁻¹' V
h2g₃ : g₃ ∈ K₂.carrier
⊢ False
[PROOFSTEP]
simp only [mem_preimage] at h1g₃ h1g₂
[GOAL]
case intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ False
[PROOFSTEP]
refine' h.le_bot (_ : g₁⁻¹ ∈ _)
[GOAL]
case intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ g₁⁻¹ ∈ K₁.carrier * V⁻¹ ⊓ K₂.carrier * V⁻¹
[PROOFSTEP]
constructor
[GOAL]
case intro.intro.intro.intro.intro.intro.left
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ g₁⁻¹ ∈ K₁.carrier * V⁻¹
[PROOFSTEP]
simp only [Set.mem_inv, Set.mem_mul, exists_exists_and_eq_and, exists_and_left]
[GOAL]
case intro.intro.intro.intro.intro.intro.right
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ g₁⁻¹ ∈ K₂.carrier * V⁻¹
[PROOFSTEP]
simp only [Set.mem_inv, Set.mem_mul, exists_exists_and_eq_and, exists_and_left]
[GOAL]
case intro.intro.intro.intro.intro.intro.left
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ ∃ x, x ∈ K₁.carrier ∧ ∃ x_1, x_1⁻¹ ∈ V ∧ x * x_1 = g₁⁻¹
[PROOFSTEP]
refine' ⟨_, h2g₂, (g₁ * g₂)⁻¹, _, _⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.left.refine'_1
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ (g₁ * g₂)⁻¹⁻¹ ∈ V
case intro.intro.intro.intro.intro.intro.left.refine'_2
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ g₂ * (g₁ * g₂)⁻¹ = g₁⁻¹
[PROOFSTEP]
simp only [inv_inv, h1g₂]
[GOAL]
case intro.intro.intro.intro.intro.intro.left.refine'_2
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ g₂ * (g₁ * g₂)⁻¹ = g₁⁻¹
[PROOFSTEP]
simp only [mul_inv_rev, mul_inv_cancel_left]
[GOAL]
case intro.intro.intro.intro.intro.intro.right
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ ∃ x, x ∈ K₂.carrier ∧ ∃ x_1, x_1⁻¹ ∈ V ∧ x * x_1 = g₁⁻¹
[PROOFSTEP]
refine' ⟨_, h2g₃, (g₁ * g₃)⁻¹, _, _⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.right.refine'_1
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ (g₁ * g₃)⁻¹⁻¹ ∈ V
case intro.intro.intro.intro.intro.intro.right.refine'_2
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ g₃ * (g₁ * g₃)⁻¹ = g₁⁻¹
[PROOFSTEP]
simp only [inv_inv, h1g₃]
[GOAL]
case intro.intro.intro.intro.intro.intro.right.refine'_2
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₁ K₂ : Compacts G
V : Set G
hV : Set.Nonempty (interior V)
h : Disjoint (K₁.carrier * V⁻¹) (K₂.carrier * V⁻¹)
s : Finset G
h1s : K₁.carrier ∪ K₂.carrier ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index (K₁.carrier ∪ K₂.carrier) V
this :
∀ (K : Set G),
K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V →
index K V ≤ Finset.card (Finset.filter (fun g => Set.Nonempty ((fun h => g * h) ⁻¹' V ∩ K)) s)
g₁ : G
a✝ : g₁ ∈ s
g₂ : G
h2g₂ : g₂ ∈ K₁.carrier
g₃ : G
h2g₃ : g₃ ∈ K₂.carrier
h1g₃ : g₁ * g₃ ∈ V
h1g₂ : g₁ * g₂ ∈ V
⊢ g₃ * (g₁ * g₃)⁻¹ = g₁⁻¹
[PROOFSTEP]
simp only [mul_inv_rev, mul_inv_cancel_left]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
⊢ index ((fun h => g * h) '' K) V ≤ index K V
[PROOFSTEP]
rcases index_elim hK hV with ⟨s, h1s, h2s⟩
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
⊢ index ((fun h => g * h) '' K) V ≤ index K V
[PROOFSTEP]
rw [← h2s]
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
⊢ index ((fun h => g * h) '' K) V ≤ Finset.card s
[PROOFSTEP]
apply Nat.sInf_le
[GOAL]
case intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
⊢ Finset.card s ∈ Finset.card '' {t | (fun h => g * h) '' K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
rw [mem_image]
[GOAL]
case intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
⊢ ∃ x, x ∈ {t | (fun h => g * h) '' K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V} ∧ Finset.card x = Finset.card s
[PROOFSTEP]
refine' ⟨s.map (Equiv.mulRight g⁻¹).toEmbedding, _, Finset.card_map _⟩
[GOAL]
case intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
⊢ Finset.map (Equiv.toEmbedding (Equiv.mulRight g⁻¹)) s ∈
{t | (fun h => g * h) '' K ⊆ ⋃ (g : G) (_ : g ∈ t), (fun h => g * h) ⁻¹' V}
[PROOFSTEP]
simp only [mem_setOf_eq]
[GOAL]
case intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
⊢ (fun h => g * h) '' K ⊆
⋃ (g_1 : G) (_ : g_1 ∈ Finset.map (Equiv.toEmbedding (Equiv.mulRight g⁻¹)) s), (fun h => g_1 * h) ⁻¹' V
[PROOFSTEP]
refine' Subset.trans (image_subset _ h1s) _
[GOAL]
case intro.intro.hm
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
⊢ (fun h => g * h) '' ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V ⊆
⋃ (g_1 : G) (_ : g_1 ∈ Finset.map (Equiv.toEmbedding (Equiv.mulRight g⁻¹)) s), (fun h => g_1 * h) ⁻¹' V
[PROOFSTEP]
rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩
[GOAL]
case intro.intro.hm.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
g₁ g₂ : G
hg₂ : g₂ ∈ s
hg₁ : g₁ ∈ (fun h => (fun h => g₂ * h) ⁻¹' V) hg₂
⊢ (fun h => g * h) g₁ ∈
⋃ (g_1 : G) (_ : g_1 ∈ Finset.map (Equiv.toEmbedding (Equiv.mulRight g⁻¹)) s), (fun h => g_1 * h) ⁻¹' V
[PROOFSTEP]
simp only [mem_preimage] at hg₁
[GOAL]
case intro.intro.hm.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
g₁ g₂ : G
hg₂ : g₂ ∈ s
hg₁ : g₂ * g₁ ∈ V
⊢ (fun h => g * h) g₁ ∈
⋃ (g_1 : G) (_ : g_1 ∈ Finset.map (Equiv.toEmbedding (Equiv.mulRight g⁻¹)) s), (fun h => g_1 * h) ⁻¹' V
[PROOFSTEP]
simp only [exists_prop, mem_iUnion, Finset.mem_map, Equiv.coe_mulRight, exists_exists_and_eq_and, mem_preimage,
Equiv.toEmbedding_apply]
[GOAL]
case intro.intro.hm.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
g₁ g₂ : G
hg₂ : g₂ ∈ s
hg₁ : g₂ * g₁ ∈ V
⊢ ∃ a, a ∈ s ∧ a * g⁻¹ * (g * g₁) ∈ V
[PROOFSTEP]
refine' ⟨_, hg₂, _⟩
[GOAL]
case intro.intro.hm.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
V : Set G
hV : Set.Nonempty (interior V)
g : G
s : Finset G
h1s : K ⊆ ⋃ (g : G) (_ : g ∈ s), (fun h => g * h) ⁻¹' V
h2s : Finset.card s = index K V
g₁ g₂ : G
hg₂ : g₂ ∈ s
hg₁ : g₂ * g₁ ∈ V
⊢ g₂ * g⁻¹ * (g * g₁) ∈ V
[PROOFSTEP]
simp only [mul_assoc, hg₁, inv_mul_cancel_left]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
g : G
V : Set G
hV : Set.Nonempty (interior V)
⊢ index ((fun h => g * h) '' K) V = index K V
[PROOFSTEP]
refine' le_antisymm (mul_left_index_le hK hV g) _
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
g : G
V : Set G
hV : Set.Nonempty (interior V)
⊢ index K V ≤ index ((fun h => g * h) '' K) V
[PROOFSTEP]
convert mul_left_index_le (hK.image <| continuous_mul_left g) hV g⁻¹
[GOAL]
case h.e'_3.h.e'_3
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
g : G
V : Set G
hV : Set.Nonempty (interior V)
⊢ K = (fun h => g⁻¹ * h) '' ((fun b => g * b) '' K)
[PROOFSTEP]
rw [image_image]
[GOAL]
case h.e'_3.h.e'_3
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
g : G
V : Set G
hV : Set.Nonempty (interior V)
⊢ K = (fun x => g⁻¹ * (g * x)) '' K
[PROOFSTEP]
symm
[GOAL]
case h.e'_3.h.e'_3
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
g : G
V : Set G
hV : Set.Nonempty (interior V)
⊢ (fun x => g⁻¹ * (g * x)) '' K = K
[PROOFSTEP]
convert image_id' _ with h
[GOAL]
case h.e'_2.h.e'_3.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K : Set G
hK : IsCompact K
g : G
V : Set G
hV : Set.Nonempty (interior V)
h : G
⊢ g⁻¹ * (g * h) = h
[PROOFSTEP]
apply inv_mul_cancel_left
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
hU : Set.Nonempty (interior U)
⊢ prehaar (↑K₀) U K ≤ ↑(index ↑K ↑K₀)
[PROOFSTEP]
unfold prehaar
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
hU : Set.Nonempty (interior U)
⊢ ↑(index (↑K) U) / ↑(index (↑K₀) U) ≤ ↑(index ↑K ↑K₀)
[PROOFSTEP]
rw [div_le_iff]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
hU : Set.Nonempty (interior U)
⊢ ↑(index (↑K) U) ≤ ↑(index ↑K ↑K₀) * ↑(index (↑K₀) U)
[PROOFSTEP]
norm_cast
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
hU : Set.Nonempty (interior U)
⊢ 0 < ↑(index (↑K₀) U)
[PROOFSTEP]
norm_cast
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
hU : Set.Nonempty (interior U)
⊢ index (↑K) U ≤ index ↑K ↑K₀ * index (↑K₀) U
[PROOFSTEP]
apply le_index_mul K₀ K hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K : Compacts G
hU : Set.Nonempty (interior U)
⊢ 0 < index (↑K₀) U
[PROOFSTEP]
exact index_pos K₀ hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
h1K : IsCompact K
h2K : Set.Nonempty (interior K)
⊢ 0 < prehaar (↑K₀) U { carrier := K, isCompact' := h1K }
[PROOFSTEP]
apply div_pos
[GOAL]
case ha
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
h1K : IsCompact K
h2K : Set.Nonempty (interior K)
⊢ 0 < ↑(index (↑{ carrier := K, isCompact' := h1K }) U)
[PROOFSTEP]
norm_cast
[GOAL]
case hb
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
h1K : IsCompact K
h2K : Set.Nonempty (interior K)
⊢ 0 < ↑(index (↑K₀) U)
[PROOFSTEP]
norm_cast
[GOAL]
case ha
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
h1K : IsCompact K
h2K : Set.Nonempty (interior K)
⊢ 0 < index (↑{ carrier := K, isCompact' := h1K }) U
case hb
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
h1K : IsCompact K
h2K : Set.Nonempty (interior K)
⊢ 0 < index (↑K₀) U
[PROOFSTEP]
apply index_pos ⟨⟨K, h1K⟩, h2K⟩ hU
[GOAL]
case hb
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
h1K : IsCompact K
h2K : Set.Nonempty (interior K)
⊢ 0 < index (↑K₀) U
[PROOFSTEP]
exact index_pos K₀ hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ K₂.carrier
⊢ prehaar (↑K₀) U K₁ ≤ prehaar (↑K₀) U K₂
[PROOFSTEP]
simp only [prehaar]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ K₂.carrier
⊢ ↑(index (↑K₁) U) / ↑(index (↑K₀) U) ≤ ↑(index (↑K₂) U) / ↑(index (↑K₀) U)
[PROOFSTEP]
rw [div_le_div_right]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ K₂.carrier
⊢ ↑(index (↑K₁) U) ≤ ↑(index (↑K₂) U)
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ K₂.carrier
⊢ 0 < ↑(index (↑K₀) U)
[PROOFSTEP]
exact_mod_cast index_mono K₂.2 h hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ K₂.carrier
⊢ 0 < ↑(index (↑K₀) U)
[PROOFSTEP]
exact_mod_cast index_pos K₀ hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
⊢ 0 < ↑(index (↑K₀.toCompacts) U)
[PROOFSTEP]
exact_mod_cast index_pos K₀ hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
⊢ prehaar (↑K₀) U (K₁ ⊔ K₂) ≤ prehaar (↑K₀) U K₁ + prehaar (↑K₀) U K₂
[PROOFSTEP]
simp only [prehaar]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
⊢ ↑(index (↑(K₁ ⊔ K₂)) U) / ↑(index (↑K₀) U) ≤ ↑(index (↑K₁) U) / ↑(index (↑K₀) U) + ↑(index (↑K₂) U) / ↑(index (↑K₀) U)
[PROOFSTEP]
rw [div_add_div_same, div_le_div_right]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
⊢ ↑(index (↑(K₁ ⊔ K₂)) U) ≤ ↑(index (↑K₁) U) + ↑(index (↑K₂) U)
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
⊢ 0 < ↑(index (↑K₀) U)
[PROOFSTEP]
exact_mod_cast index_union_le K₁ K₂ hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
⊢ 0 < ↑(index (↑K₀) U)
[PROOFSTEP]
exact_mod_cast index_pos K₀ hU
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
h : Disjoint (K₁.carrier * U⁻¹) (K₂.carrier * U⁻¹)
⊢ prehaar (↑K₀) U (K₁ ⊔ K₂) = prehaar (↑K₀) U K₁ + prehaar (↑K₀) U K₂
[PROOFSTEP]
simp only [prehaar]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
h : Disjoint (K₁.carrier * U⁻¹) (K₂.carrier * U⁻¹)
⊢ ↑(index (↑(K₁ ⊔ K₂)) U) / ↑(index (↑K₀) U) = ↑(index (↑K₁) U) / ↑(index (↑K₀) U) + ↑(index (↑K₂) U) / ↑(index (↑K₀) U)
[PROOFSTEP]
rw [div_add_div_same]
-- Porting note: Here was `congr`, but `to_additive` failed to generate a theorem.
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
h : Disjoint (K₁.carrier * U⁻¹) (K₂.carrier * U⁻¹)
⊢ ↑(index (↑(K₁ ⊔ K₂)) U) / ↑(index (↑K₀) U) = (↑(index (↑K₁) U) + ↑(index (↑K₂) U)) / ↑(index (↑K₀) U)
[PROOFSTEP]
refine congr_arg (fun x : ℝ => x / index K₀ U) ?_
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
K₁ K₂ : Compacts G
hU : Set.Nonempty (interior U)
h : Disjoint (K₁.carrier * U⁻¹) (K₂.carrier * U⁻¹)
⊢ ↑(index (↑(K₁ ⊔ K₂)) U) = ↑(index (↑K₁) U) + ↑(index (↑K₂) U)
[PROOFSTEP]
exact_mod_cast index_union_eq K₁ K₂ hU h
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
g : G
K : Compacts G
⊢ prehaar (↑K₀) U (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) = prehaar (↑K₀) U K
[PROOFSTEP]
simp only [prehaar, Compacts.coe_map, is_left_invariant_index K.isCompact _ hU]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
⊢ prehaar (↑K₀) U ∈ haarProduct ↑K₀
[PROOFSTEP]
rintro ⟨K, hK⟩ _
[GOAL]
case mk
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
hK : IsCompact K
a✝ : { carrier := K, isCompact' := hK } ∈ univ
⊢ prehaar (↑K₀) U { carrier := K, isCompact' := hK } ∈
(fun K => Icc 0 ↑(index ↑K ↑K₀)) { carrier := K, isCompact' := hK }
[PROOFSTEP]
rw [mem_Icc]
[GOAL]
case mk
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
U : Set G
hU : Set.Nonempty (interior U)
K : Set G
hK : IsCompact K
a✝ : { carrier := K, isCompact' := hK } ∈ univ
⊢ 0 ≤ prehaar (↑K₀) U { carrier := K, isCompact' := hK } ∧
prehaar (↑K₀) U { carrier := K, isCompact' := hK } ≤ ↑(index ↑{ carrier := K, isCompact' := hK } ↑K₀)
[PROOFSTEP]
exact ⟨prehaar_nonneg K₀ _, prehaar_le_index K₀ _ hU⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
⊢ Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (V : OpenNhdsOf 1), clPrehaar (↑K₀) V)
[PROOFSTEP]
have : IsCompact (haarProduct (K₀ : Set G)) := by apply isCompact_univ_pi; intro K; apply isCompact_Icc
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
⊢ IsCompact (haarProduct ↑K₀)
[PROOFSTEP]
apply isCompact_univ_pi
[GOAL]
case h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
⊢ ∀ (i : Compacts G), IsCompact (Icc 0 ↑(index ↑i ↑K₀))
[PROOFSTEP]
intro K
[GOAL]
case h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
⊢ IsCompact (Icc 0 ↑(index ↑K ↑K₀))
[PROOFSTEP]
apply isCompact_Icc
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
⊢ Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (V : OpenNhdsOf 1), clPrehaar (↑K₀) V)
[PROOFSTEP]
refine' this.inter_iInter_nonempty (clPrehaar K₀) (fun s => isClosed_closure) fun t => _
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
⊢ Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (i : OpenNhdsOf 1) (_ : i ∈ t), clPrehaar (↑K₀) i)
[PROOFSTEP]
let V₀ := ⋂ V ∈ t, (V : OpenNhdsOf (1 : G)).carrier
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
⊢ Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (i : OpenNhdsOf 1) (_ : i ∈ t), clPrehaar (↑K₀) i)
[PROOFSTEP]
have h1V₀ : IsOpen V₀ := by apply isOpen_biInter; apply Finset.finite_toSet; rintro ⟨⟨V, hV₁⟩, hV₂⟩ _; exact hV₁
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
⊢ IsOpen V₀
[PROOFSTEP]
apply isOpen_biInter
[GOAL]
case hs
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
⊢ Set.Finite fun i => i ∈ t.val
case h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
⊢ ∀ (i : OpenNhdsOf 1), (i ∈ fun i => i ∈ t.val) → IsOpen i.carrier
[PROOFSTEP]
apply Finset.finite_toSet
[GOAL]
case h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
⊢ ∀ (i : OpenNhdsOf 1), (i ∈ fun i => i ∈ t.val) → IsOpen i.carrier
[PROOFSTEP]
rintro ⟨⟨V, hV₁⟩, hV₂⟩ _
[GOAL]
case h.mk.mk
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
V : Set G
hV₁ : IsOpen V
hV₂ : 1 ∈ { carrier := V, is_open' := hV₁ }.carrier
a✝ : { toOpens := { carrier := V, is_open' := hV₁ }, mem' := hV₂ } ∈ fun i => i ∈ t.val
⊢ IsOpen { toOpens := { carrier := V, is_open' := hV₁ }, mem' := hV₂ }.toOpens.carrier
[PROOFSTEP]
exact hV₁
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
⊢ Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (i : OpenNhdsOf 1) (_ : i ∈ t), clPrehaar (↑K₀) i)
[PROOFSTEP]
have h2V₀ : (1 : G) ∈ V₀ := by simp only [mem_iInter]; rintro ⟨⟨V, hV₁⟩, hV₂⟩ _; exact hV₂
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
⊢ 1 ∈ V₀
[PROOFSTEP]
simp only [mem_iInter]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
⊢ ∀ (i : OpenNhdsOf 1), i ∈ t → 1 ∈ i.carrier
[PROOFSTEP]
rintro ⟨⟨V, hV₁⟩, hV₂⟩ _
[GOAL]
case mk.mk
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
V : Set G
hV₁ : IsOpen V
hV₂ : 1 ∈ { carrier := V, is_open' := hV₁ }.carrier
i✝ : { toOpens := { carrier := V, is_open' := hV₁ }, mem' := hV₂ } ∈ t
⊢ 1 ∈ { toOpens := { carrier := V, is_open' := hV₁ }, mem' := hV₂ }.toOpens.carrier
[PROOFSTEP]
exact hV₂
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
⊢ Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (i : OpenNhdsOf 1) (_ : i ∈ t), clPrehaar (↑K₀) i)
[PROOFSTEP]
refine' ⟨prehaar K₀ V₀, _⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
⊢ prehaar (↑K₀) V₀ ∈ haarProduct ↑K₀ ∩ ⋂ (i : OpenNhdsOf 1) (_ : i ∈ t), clPrehaar (↑K₀) i
[PROOFSTEP]
constructor
[GOAL]
case left
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
⊢ prehaar (↑K₀) V₀ ∈ haarProduct ↑K₀
[PROOFSTEP]
apply prehaar_mem_haarProduct K₀
[GOAL]
case left
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
⊢ Set.Nonempty (interior V₀)
[PROOFSTEP]
use 1
[GOAL]
case h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
⊢ 1 ∈ interior V₀
[PROOFSTEP]
rwa [h1V₀.interior_eq]
[GOAL]
case right
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
⊢ prehaar (↑K₀) V₀ ∈ ⋂ (i : OpenNhdsOf 1) (_ : i ∈ t), clPrehaar (↑K₀) i
[PROOFSTEP]
simp only [mem_iInter]
[GOAL]
case right
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
⊢ ∀ (i : OpenNhdsOf 1), i ∈ t → prehaar (↑K₀) (⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier) ∈ clPrehaar (↑K₀) i
[PROOFSTEP]
rintro ⟨V, hV⟩ h2V
[GOAL]
case right.mk
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
V : Opens G
hV : 1 ∈ V.carrier
h2V : { toOpens := V, mem' := hV } ∈ t
⊢ prehaar (↑K₀) (⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier) ∈ clPrehaar ↑K₀ { toOpens := V, mem' := hV }
[PROOFSTEP]
apply subset_closure
[GOAL]
case right.mk.a
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
V : Opens G
hV : 1 ∈ V.carrier
h2V : { toOpens := V, mem' := hV } ∈ t
⊢ prehaar (↑K₀) (⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier) ∈
prehaar ↑K₀ '' {U | U ⊆ ↑{ toOpens := V, mem' := hV }.toOpens ∧ IsOpen U ∧ 1 ∈ U}
[PROOFSTEP]
apply mem_image_of_mem
[GOAL]
case right.mk.a.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
V : Opens G
hV : 1 ∈ V.carrier
h2V : { toOpens := V, mem' := hV } ∈ t
⊢ ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier ∈ {U | U ⊆ ↑{ toOpens := V, mem' := hV }.toOpens ∧ IsOpen U ∧ 1 ∈ U}
[PROOFSTEP]
rw [mem_setOf_eq]
[GOAL]
case right.mk.a.h
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
this : IsCompact (haarProduct ↑K₀)
t : Finset (OpenNhdsOf 1)
V₀ : Set G := ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
h1V₀ : IsOpen V₀
h2V₀ : 1 ∈ V₀
V : Opens G
hV : 1 ∈ V.carrier
h2V : { toOpens := V, mem' := hV } ∈ t
⊢ ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier ⊆ ↑{ toOpens := V, mem' := hV }.toOpens ∧
IsOpen (⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier) ∧ 1 ∈ ⋂ (V : OpenNhdsOf 1) (_ : V ∈ t), V.carrier
[PROOFSTEP]
exact ⟨Subset.trans (iInter_subset _ ⟨V, hV⟩) (iInter_subset _ h2V), h1V₀, h2V₀⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
V : OpenNhdsOf 1
⊢ chaar K₀ ∈ clPrehaar (↑K₀) V
[PROOFSTEP]
have := (Classical.choose_spec (nonempty_iInter_clPrehaar K₀)).2
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
V : OpenNhdsOf 1
this :
Classical.choose (_ : Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (V : OpenNhdsOf 1), clPrehaar (↑K₀) V)) ∈
⋂ (V : OpenNhdsOf 1), clPrehaar (↑K₀) V
⊢ chaar K₀ ∈ clPrehaar (↑K₀) V
[PROOFSTEP]
rw [mem_iInter] at this
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
V : OpenNhdsOf 1
this :
∀ (i : OpenNhdsOf 1),
Classical.choose (_ : Set.Nonempty (haarProduct ↑K₀ ∩ ⋂ (V : OpenNhdsOf 1), clPrehaar (↑K₀) V)) ∈ clPrehaar (↑K₀) i
⊢ chaar K₀ ∈ clPrehaar (↑K₀) V
[PROOFSTEP]
exact this V
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
⊢ 0 ≤ chaar K₀ K
[PROOFSTEP]
have := chaar_mem_haarProduct K₀ K (mem_univ _)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
this : chaar K₀ K ∈ (fun K => Icc 0 ↑(index ↑K ↑K₀)) K
⊢ 0 ≤ chaar K₀ K
[PROOFSTEP]
rw [mem_Icc] at this
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K : Compacts G
this : 0 ≤ chaar K₀ K ∧ chaar K₀ K ≤ ↑(index ↑K ↑K₀)
⊢ 0 ≤ chaar K₀ K
[PROOFSTEP]
exact this.1
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
⊢ chaar K₀ ⊥ = 0
[PROOFSTEP]
let eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
⊢ chaar K₀ ⊥ = 0
[PROOFSTEP]
have : Continuous eval := continuous_apply ⊥
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
⊢ chaar K₀ ⊥ = 0
[PROOFSTEP]
show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
⊢ chaar K₀ ∈ eval ⁻¹' {0}
[PROOFSTEP]
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
⊢ clPrehaar ↑K₀ ⊤ ⊆ eval ⁻¹' {0}
[PROOFSTEP]
unfold clPrehaar
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
⊢ closure (prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U}) ⊆ eval ⁻¹' {0}
[PROOFSTEP]
rw [IsClosed.closure_subset_iff]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
⊢ prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U} ⊆ eval ⁻¹' {0}
[PROOFSTEP]
rintro _ ⟨U, _, rfl⟩
[GOAL]
case intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
U : Set G
left✝ : U ∈ {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U}
⊢ prehaar (↑K₀) U ∈ eval ⁻¹' {0}
[PROOFSTEP]
apply prehaar_empty
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
⊢ IsClosed (eval ⁻¹' {0})
[PROOFSTEP]
apply continuous_iff_isClosed.mp this
[GOAL]
case a
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
this : Continuous eval
⊢ IsClosed {0}
[PROOFSTEP]
exact isClosed_singleton
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
⊢ chaar K₀ K₀.toCompacts = 1
[PROOFSTEP]
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
⊢ chaar K₀ K₀.toCompacts = 1
[PROOFSTEP]
have : Continuous eval := continuous_apply _
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
⊢ chaar K₀ K₀.toCompacts = 1
[PROOFSTEP]
show chaar K₀ ∈ eval ⁻¹' {(1 : ℝ)}
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
⊢ chaar K₀ ∈ eval ⁻¹' {1}
[PROOFSTEP]
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
⊢ clPrehaar ↑K₀ ⊤ ⊆ eval ⁻¹' {1}
[PROOFSTEP]
unfold clPrehaar
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
⊢ closure (prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U}) ⊆ eval ⁻¹' {1}
[PROOFSTEP]
rw [IsClosed.closure_subset_iff]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
⊢ prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U} ⊆ eval ⁻¹' {1}
[PROOFSTEP]
rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U ∈ eval ⁻¹' {1}
[PROOFSTEP]
apply prehaar_self
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty (interior U)
[PROOFSTEP]
rw [h2U.interior_eq]
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty U
[PROOFSTEP]
exact ⟨1, h3U⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
⊢ IsClosed (eval ⁻¹' {1})
[PROOFSTEP]
apply continuous_iff_isClosed.mp this
[GOAL]
case a
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
this : Continuous eval
⊢ IsClosed {1}
[PROOFSTEP]
exact isClosed_singleton
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
⊢ chaar K₀ K₁ ≤ chaar K₀ K₂
[PROOFSTEP]
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
⊢ chaar K₀ K₁ ≤ chaar K₀ K₂
[PROOFSTEP]
have : Continuous eval := (continuous_apply K₂).sub (continuous_apply K₁)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ chaar K₀ K₁ ≤ chaar K₀ K₂
[PROOFSTEP]
rw [← sub_nonneg]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ 0 ≤ chaar K₀ K₂ - chaar K₀ K₁
[PROOFSTEP]
show chaar K₀ ∈ eval ⁻¹' Ici (0 : ℝ)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ chaar K₀ ∈ eval ⁻¹' Ici 0
[PROOFSTEP]
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ clPrehaar ↑K₀ ⊤ ⊆ eval ⁻¹' Ici 0
[PROOFSTEP]
unfold clPrehaar
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ closure (prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U}) ⊆ eval ⁻¹' Ici 0
[PROOFSTEP]
rw [IsClosed.closure_subset_iff]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U} ⊆ eval ⁻¹' Ici 0
[PROOFSTEP]
rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U ∈ eval ⁻¹' Ici 0
[PROOFSTEP]
simp only [mem_preimage, mem_Ici, sub_nonneg]
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U K₁ ≤ prehaar (↑K₀) U K₂
[PROOFSTEP]
apply prehaar_mono _ h
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty (interior U)
[PROOFSTEP]
rw [h2U.interior_eq]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty U
[PROOFSTEP]
exact ⟨1, h3U⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ IsClosed (eval ⁻¹' Ici 0)
[PROOFSTEP]
apply continuous_iff_isClosed.mp this
[GOAL]
case a
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
this : Continuous eval
⊢ IsClosed (Ici 0)
[PROOFSTEP]
exact isClosed_Ici
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
⊢ chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
⊢ chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
have : Continuous eval := by exact ((continuous_apply K₁).add (continuous_apply K₂)).sub (continuous_apply (K₁ ⊔ K₂))
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
⊢ Continuous eval
[PROOFSTEP]
exact ((continuous_apply K₁).add (continuous_apply K₂)).sub (continuous_apply (K₁ ⊔ K₂))
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
rw [← sub_nonneg]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ 0 ≤ chaar K₀ K₁ + chaar K₀ K₂ - chaar K₀ (K₁ ⊔ K₂)
[PROOFSTEP]
show chaar K₀ ∈ eval ⁻¹' Ici (0 : ℝ)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ chaar K₀ ∈ eval ⁻¹' Ici 0
[PROOFSTEP]
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ clPrehaar ↑K₀ ⊤ ⊆ eval ⁻¹' Ici 0
[PROOFSTEP]
unfold clPrehaar
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ closure (prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U}) ⊆ eval ⁻¹' Ici 0
[PROOFSTEP]
rw [IsClosed.closure_subset_iff]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U} ⊆ eval ⁻¹' Ici 0
[PROOFSTEP]
rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U ∈ eval ⁻¹' Ici 0
[PROOFSTEP]
simp only [mem_preimage, mem_Ici, sub_nonneg]
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U (K₁ ⊔ K₂) ≤ prehaar (↑K₀) U K₁ + prehaar (↑K₀) U K₂
[PROOFSTEP]
apply prehaar_sup_le
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty (interior U)
[PROOFSTEP]
rw [h2U.interior_eq]
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty U
[PROOFSTEP]
exact ⟨1, h3U⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ IsClosed (eval ⁻¹' Ici 0)
[PROOFSTEP]
apply continuous_iff_isClosed.mp this
[GOAL]
case a
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ IsClosed (Ici 0)
[PROOFSTEP]
exact isClosed_Ici
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
rcases isCompact_isCompact_separated K₁.2 K₂.2 h with ⟨U₁, U₂, h1U₁, h1U₂, h2U₁, h2U₂, hU⟩
[GOAL]
case intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
rcases compact_open_separated_mul_right K₁.2 h1U₁ h2U₁ with ⟨L₁, h1L₁, h2L₁⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
h2L₁ : K₁.carrier * L₁ ⊆ U₁
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
rcases mem_nhds_iff.mp h1L₁ with ⟨V₁, h1V₁, h2V₁, h3V₁⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
h2L₁ : K₁.carrier * L₁ ⊆ U₁
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
replace h2L₁ := Subset.trans (mul_subset_mul_left h1V₁) h2L₁
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
rcases compact_open_separated_mul_right K₂.2 h1U₂ h2U₂ with ⟨L₂, h1L₂, h2L₂⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
h2L₂ : K₂.carrier * L₂ ⊆ U₂
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
rcases mem_nhds_iff.mp h1L₂ with ⟨V₂, h1V₂, h2V₂, h3V₂⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
h2L₂ : K₂.carrier * L₂ ⊆ U₂
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
replace h2L₂ := Subset.trans (mul_subset_mul_left h1V₂) h2L₂
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
have : Continuous eval := ((continuous_apply K₁).add (continuous_apply K₂)).sub (continuous_apply (K₁ ⊔ K₂))
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂
[PROOFSTEP]
rw [eq_comm, ← sub_eq_zero]
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ chaar K₀ K₁ + chaar K₀ K₂ - chaar K₀ (K₁ ⊔ K₂) = 0
[PROOFSTEP]
show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
⊢ chaar K₀ ∈ eval ⁻¹' {0}
[PROOFSTEP]
let V := V₁ ∩ V₂
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
⊢ chaar K₀ ∈ eval ⁻¹' {0}
[PROOFSTEP]
apply
mem_of_subset_of_mem _
(chaar_mem_clPrehaar K₀
⟨⟨V⁻¹, (h2V₁.inter h2V₂).preimage continuous_inv⟩, by
simp only [mem_inv, inv_one, h3V₁, h3V₂, mem_inter_iff, true_and_iff]⟩)
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
⊢ 1 ∈ { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) }.carrier
[PROOFSTEP]
simp only [mem_inv, inv_one, h3V₁, h3V₂, mem_inter_iff, true_and_iff]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
⊢ clPrehaar ↑K₀
{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) } ⊆
eval ⁻¹' {0}
[PROOFSTEP]
unfold clPrehaar
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
⊢ closure
(prehaar ↑K₀ ''
{U |
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens ∧
IsOpen U ∧ 1 ∈ U}) ⊆
eval ⁻¹' {0}
[PROOFSTEP]
rw [IsClosed.closure_subset_iff]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
⊢ prehaar ↑K₀ ''
{U |
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens ∧
IsOpen U ∧ 1 ∈ U} ⊆
eval ⁻¹' {0}
[PROOFSTEP]
rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U ∈ eval ⁻¹' {0}
[PROOFSTEP]
simp only [mem_preimage, sub_eq_zero, mem_singleton_iff]
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U K₁ + prehaar (↑K₀) U K₂ = prehaar (↑K₀) U (K₁ ⊔ K₂)
[PROOFSTEP]
rw [eq_comm]
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U (K₁ ⊔ K₂) = prehaar (↑K₀) U K₁ + prehaar (↑K₀) U K₂
[PROOFSTEP]
apply prehaar_sup_eq
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty (interior U)
[PROOFSTEP]
rw [h2U.interior_eq]
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty U
[PROOFSTEP]
exact ⟨1, h3U⟩
[GOAL]
case intro.intro.intro.intro.h
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Disjoint (K₁.carrier * U⁻¹) (K₂.carrier * U⁻¹)
[PROOFSTEP]
refine' disjoint_of_subset _ _ hU
[GOAL]
case intro.intro.intro.intro.h.refine'_1
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ K₁.carrier * U⁻¹ ⊆ U₁
[PROOFSTEP]
refine' Subset.trans (mul_subset_mul Subset.rfl _) h2L₁
[GOAL]
case intro.intro.intro.intro.h.refine'_1
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ U⁻¹ ⊆ V₁
[PROOFSTEP]
exact Subset.trans (inv_subset.mpr h1U) (inter_subset_left _ _)
[GOAL]
case intro.intro.intro.intro.h.refine'_2
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ K₂.carrier * U⁻¹ ⊆ U₂
[PROOFSTEP]
refine' Subset.trans (mul_subset_mul Subset.rfl _) h2L₂
[GOAL]
case intro.intro.intro.intro.h.refine'_2
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
U : Set G
h1U :
U ⊆
↑{ toOpens := { carrier := V⁻¹, is_open' := (_ : IsOpen ((fun a => a⁻¹) ⁻¹' (V₁ ∩ V₂))) },
mem' := (_ : 1 ∈ (V₁ ∩ V₂)⁻¹) }.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ U⁻¹ ⊆ V₂
[PROOFSTEP]
exact Subset.trans (inv_subset.mpr h1U) (inter_subset_right _ _)
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
⊢ IsClosed (eval ⁻¹' {0})
[PROOFSTEP]
apply continuous_iff_isClosed.mp this
[GOAL]
case a
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint K₁.carrier K₂.carrier
U₁ U₂ : Set G
h1U₁ : IsOpen U₁
h1U₂ : IsOpen U₂
h2U₁ : K₁.carrier ⊆ U₁
h2U₂ : K₂.carrier ⊆ U₂
hU : Disjoint U₁ U₂
L₁ : Set G
h1L₁ : L₁ ∈ 𝓝 1
V₁ : Set G
h1V₁ : V₁ ⊆ L₁
h2V₁ : IsOpen V₁
h3V₁ : 1 ∈ V₁
h2L₁ : K₁.carrier * V₁ ⊆ U₁
L₂ : Set G
h1L₂ : L₂ ∈ 𝓝 1
V₂ : Set G
h1V₂ : V₂ ⊆ L₂
h2V₂ : IsOpen V₂
h3V₂ : 1 ∈ V₂
h2L₂ : K₂.carrier * V₂ ⊆ U₂
eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
this : Continuous eval
V : Set G := V₁ ∩ V₂
⊢ IsClosed {0}
[PROOFSTEP]
exact isClosed_singleton
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
⊢ chaar K₀ (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) = chaar K₀ K
[PROOFSTEP]
let eval : (Compacts G → ℝ) → ℝ := fun f => f (K.map _ <| continuous_mul_left g) - f K
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
⊢ chaar K₀ (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) = chaar K₀ K
[PROOFSTEP]
have : Continuous eval := (continuous_apply (K.map _ _)).sub (continuous_apply K)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ chaar K₀ (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) = chaar K₀ K
[PROOFSTEP]
rw [← sub_eq_zero]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ chaar K₀ (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - chaar K₀ K = 0
[PROOFSTEP]
show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ chaar K₀ ∈ eval ⁻¹' {0}
[PROOFSTEP]
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ clPrehaar ↑K₀ ⊤ ⊆ eval ⁻¹' {0}
[PROOFSTEP]
unfold clPrehaar
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ closure (prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U}) ⊆ eval ⁻¹' {0}
[PROOFSTEP]
rw [IsClosed.closure_subset_iff]
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ prehaar ↑K₀ '' {U | U ⊆ ↑⊤.toOpens ∧ IsOpen U ∧ 1 ∈ U} ⊆ eval ⁻¹' {0}
[PROOFSTEP]
rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U ∈ eval ⁻¹' {0}
[PROOFSTEP]
simp only [mem_singleton_iff, mem_preimage, sub_eq_zero]
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ prehaar (↑K₀) U (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) = prehaar (↑K₀) U K
[PROOFSTEP]
apply is_left_invariant_prehaar
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty (interior U)
[PROOFSTEP]
rw [h2U.interior_eq]
[GOAL]
case intro.intro.intro.intro.hU
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
U : Set G
left✝ : U ⊆ ↑⊤.toOpens
h2U : IsOpen U
h3U : 1 ∈ U
⊢ Set.Nonempty U
[PROOFSTEP]
exact ⟨1, h3U⟩
[GOAL]
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ IsClosed (eval ⁻¹' {0})
[PROOFSTEP]
apply continuous_iff_isClosed.mp this
[GOAL]
case a
G : Type u_1
inst✝² : Group G
inst✝¹ : TopologicalSpace G
inst✝ : TopologicalGroup G
K₀ : PositiveCompacts G
g : G
K : Compacts G
eval : (Compacts G → ℝ) → ℝ := fun f => f (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) - f K
this : Continuous eval
⊢ IsClosed {0}
[PROOFSTEP]
exact isClosed_singleton
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : ↑K₁ ⊆ ↑K₂
⊢ (fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) K₁ ≤
(fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) K₂
[PROOFSTEP]
simp only [← NNReal.coe_le_coe, NNReal.toReal, chaar_mono, h]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint ↑K₁ ↑K₂
⊢ (fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) (K₁ ⊔ K₂) =
(fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) K₁ +
(fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) K₂
[PROOFSTEP]
simp only [chaar_sup_eq h]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
h : Disjoint ↑K₁ ↑K₂
⊢ { val := chaar K₀ K₁ + chaar K₀ K₂, property := (_ : (fun r => 0 ≤ r) (chaar K₀ K₁ + chaar K₀ K₂)) } =
{ val := chaar K₀ K₁, property := (_ : 0 ≤ chaar K₀ K₁) } +
{ val := chaar K₀ K₂, property := (_ : 0 ≤ chaar K₀ K₂) }
[PROOFSTEP]
rfl
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
⊢ (fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) (K₁ ⊔ K₂) ≤
(fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) K₁ +
(fun K => { val := chaar K₀ K, property := (_ : 0 ≤ chaar K₀ K) }) K₂
[PROOFSTEP]
simp only [← NNReal.coe_le_coe, NNReal.coe_add]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
K₁ K₂ : Compacts G
⊢ ↑{ val := chaar K₀ (K₁ ⊔ K₂), property := (_ : 0 ≤ chaar K₀ (K₁ ⊔ K₂)) } ≤
↑{ val := chaar K₀ K₁, property := (_ : 0 ≤ chaar K₀ K₁) } +
↑{ val := chaar K₀ K₂, property := (_ : 0 ≤ chaar K₀ K₂) }
[PROOFSTEP]
simp only [NNReal.toReal, chaar_sup_le]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
⊢ (fun s => ↑(Content.toFun (haarContent K₀) s)) K₀.toCompacts = 1
[PROOFSTEP]
simp_rw [← ENNReal.coe_one, haarContent_apply, ENNReal.coe_eq_coe, chaar_self]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
⊢ { val := 1, property := (_ : (fun r => 0 ≤ r) 1) } = 1
[PROOFSTEP]
rfl
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
g : G
K : Compacts G
⊢ (fun s => ↑(Content.toFun (haarContent K₀) s)) (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) =
(fun s => ↑(Content.toFun (haarContent K₀) s)) K
[PROOFSTEP]
simpa only [ENNReal.coe_eq_coe, ← NNReal.coe_eq, haarContent_apply] using is_left_invariant_chaar g K
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
⊢ 0 < ↑(Content.outerMeasure (haarContent K₀)) ↑K₀
[PROOFSTEP]
refine' zero_lt_one.trans_le _
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
⊢ 1 ≤ ↑(Content.outerMeasure (haarContent K₀)) ↑K₀
[PROOFSTEP]
rw [Content.outerMeasure_eq_iInf]
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
⊢ 1 ≤
⨅ (U : Set G) (hU : IsOpen U) (_ : ↑K₀ ⊆ U), Content.innerContent (haarContent K₀) { carrier := U, is_open' := hU }
[PROOFSTEP]
refine' le_iInf₂ fun U hU => le_iInf fun hK₀ => le_trans _ <| le_iSup₂ K₀.toCompacts hK₀
[GOAL]
G : Type u_1
inst✝³ : Group G
inst✝² : TopologicalSpace G
inst✝¹ : TopologicalGroup G
inst✝ : T2Space G
K₀ : PositiveCompacts G
U : Set G
hU : IsOpen U
hK₀ : ↑K₀ ⊆ U
⊢ 1 ≤ (fun s => ↑(Content.toFun (haarContent K₀) s)) K₀.toCompacts
[PROOFSTEP]
exact haarContent_self.ge
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
s : Set G
hs : MeasurableSet s
⊢ ↑↑(haarMeasure K₀) s = ↑(Content.outerMeasure (haarContent K₀)) s / ↑(Content.outerMeasure (haarContent K₀)) ↑K₀
[PROOFSTEP]
change ((haarContent K₀).outerMeasure K₀)⁻¹ * (haarContent K₀).measure s = _
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
s : Set G
hs : MeasurableSet s
⊢ (↑(Content.outerMeasure (haarContent K₀)) ↑K₀)⁻¹ * ↑↑(Content.measure (haarContent K₀)) s =
↑(Content.outerMeasure (haarContent K₀)) s / ↑(Content.outerMeasure (haarContent K₀)) ↑K₀
[PROOFSTEP]
simp only [hs, div_eq_mul_inv, mul_comm, Content.measure_apply]
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ IsMulLeftInvariant (haarMeasure K₀)
[PROOFSTEP]
rw [← forall_measure_preimage_mul_iff]
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ ∀ (g : G) (A : Set G), MeasurableSet A → ↑↑(haarMeasure K₀) ((fun h => g * h) ⁻¹' A) = ↑↑(haarMeasure K₀) A
[PROOFSTEP]
intro g A hA
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
g : G
A : Set G
hA : MeasurableSet A
⊢ ↑↑(haarMeasure K₀) ((fun h => g * h) ⁻¹' A) = ↑↑(haarMeasure K₀) A
[PROOFSTEP]
rw [haarMeasure_apply hA, haarMeasure_apply (measurable_const_mul g hA)]
-- Porting note: Here was `congr 1`, but `to_additive` failed to generate a theorem.
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
g : G
A : Set G
hA : MeasurableSet A
⊢ ↑(Content.outerMeasure (haarContent K₀)) ((fun x => g * x) ⁻¹' A) / ↑(Content.outerMeasure (haarContent K₀)) ↑K₀ =
↑(Content.outerMeasure (haarContent K₀)) A / ↑(Content.outerMeasure (haarContent K₀)) ↑K₀
[PROOFSTEP]
refine congr_arg (fun x : ℝ≥0∞ => x / (haarContent K₀).outerMeasure K₀) ?_
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
g : G
A : Set G
hA : MeasurableSet A
⊢ ↑(Content.outerMeasure (haarContent K₀)) ((fun x => g * x) ⁻¹' A) = ↑(Content.outerMeasure (haarContent K₀)) A
[PROOFSTEP]
apply Content.is_mul_left_invariant_outerMeasure
[GOAL]
case h
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
g : G
A : Set G
hA : MeasurableSet A
⊢ ∀ (g : G) {K : Compacts G},
(fun s => ↑(Content.toFun (haarContent K₀) s)) (Compacts.map (fun b => g * b) (_ : Continuous fun b => g * b) K) =
(fun s => ↑(Content.toFun (haarContent K₀) s)) K
[PROOFSTEP]
apply is_left_invariant_haarContent
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ ↑↑(haarMeasure K₀) ↑K₀ = 1
[PROOFSTEP]
haveI : LocallyCompactSpace G := K₀.locallyCompactSpace_of_group
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ ↑↑(haarMeasure K₀) ↑K₀ = 1
[PROOFSTEP]
rw [haarMeasure_apply K₀.isCompact.measurableSet, ENNReal.div_self]
[GOAL]
case h0
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ ↑(Content.outerMeasure (haarContent K₀)) ↑K₀ ≠ 0
[PROOFSTEP]
rw [← pos_iff_ne_zero]
[GOAL]
case h0
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ 0 < ↑(Content.outerMeasure (haarContent K₀)) ↑K₀
[PROOFSTEP]
exact haarContent_outerMeasure_self_pos
[GOAL]
case hI
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ ↑(Content.outerMeasure (haarContent K₀)) ↑K₀ ≠ ⊤
[PROOFSTEP]
exact (Content.outerMeasure_lt_top_of_isCompact _ K₀.isCompact).ne
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ Regular (haarMeasure K₀)
[PROOFSTEP]
haveI : LocallyCompactSpace G := K₀.locallyCompactSpace_of_group
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ Regular (haarMeasure K₀)
[PROOFSTEP]
apply Regular.smul
[GOAL]
case hx
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ (↑(Content.outerMeasure (haarContent K₀)) ↑K₀)⁻¹ ≠ ⊤
[PROOFSTEP]
rw [ENNReal.inv_ne_top]
[GOAL]
case hx
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ ↑(Content.outerMeasure (haarContent K₀)) ↑K₀ ≠ 0
[PROOFSTEP]
exact haarContent_outerMeasure_self_pos.ne'
[GOAL]
G : Type u_1
inst✝⁶ : Group G
inst✝⁵ : TopologicalSpace G
inst✝⁴ : T2Space G
inst✝³ : TopologicalGroup G
inst✝² : MeasurableSpace G
inst✝¹ : BorelSpace G
inst✝ : SecondCountableTopology G
K₀ : PositiveCompacts G
⊢ SigmaFinite (haarMeasure K₀)
[PROOFSTEP]
haveI : LocallyCompactSpace G := K₀.locallyCompactSpace_of_group
[GOAL]
G : Type u_1
inst✝⁶ : Group G
inst✝⁵ : TopologicalSpace G
inst✝⁴ : T2Space G
inst✝³ : TopologicalGroup G
inst✝² : MeasurableSpace G
inst✝¹ : BorelSpace G
inst✝ : SecondCountableTopology G
K₀ : PositiveCompacts G
this : LocallyCompactSpace G
⊢ SigmaFinite (haarMeasure K₀)
[PROOFSTEP]
infer_instance
[GOAL]
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ IsHaarMeasure (haarMeasure K₀)
[PROOFSTEP]
apply isHaarMeasure_of_isCompact_nonempty_interior (haarMeasure K₀) K₀ K₀.isCompact K₀.interior_nonempty
[GOAL]
case h
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ ↑↑(haarMeasure K₀) ↑K₀ ≠ 0
[PROOFSTEP]
simp only [haarMeasure_self]
[GOAL]
case h
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ 1 ≠ 0
[PROOFSTEP]
exact one_ne_zero
[GOAL]
case h'
G : Type u_1
inst✝⁵ : Group G
inst✝⁴ : TopologicalSpace G
inst✝³ : T2Space G
inst✝² : TopologicalGroup G
inst✝¹ : MeasurableSpace G
inst✝ : BorelSpace G
K₀ : PositiveCompacts G
⊢ ↑↑(haarMeasure K₀) ↑K₀ ≠ ⊤
[PROOFSTEP]
simp only [haarMeasure_self]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : SigmaFinite μ
inst✝ : IsMulLeftInvariant μ
K₀ : PositiveCompacts G
⊢ (↑↑μ ↑K₀ / ↑↑(haarMeasure K₀) ↑K₀) • haarMeasure K₀ = ↑↑μ ↑K₀ • haarMeasure K₀
[PROOFSTEP]
rw [haarMeasure_self, div_one]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : SigmaFinite μ
inst✝ : IsMulLeftInvariant μ
K : Set G
hK : IsCompact K
h2K : Set.Nonempty (interior K)
hμK : ↑↑μ K ≠ ⊤
⊢ Regular μ
[PROOFSTEP]
rw [haarMeasure_unique μ ⟨⟨K, hK⟩, h2K⟩]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : SigmaFinite μ
inst✝ : IsMulLeftInvariant μ
K : Set G
hK : IsCompact K
h2K : Set.Nonempty (interior K)
hμK : ↑↑μ K ≠ ⊤
⊢ Regular
(↑↑μ ↑{ toCompacts := { carrier := K, isCompact' := hK }, interior_nonempty' := h2K } •
haarMeasure { toCompacts := { carrier := K, isCompact' := hK }, interior_nonempty' := h2K })
[PROOFSTEP]
exact Regular.smul hμK
[GOAL]
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
⊢ ∃ c, c ≠ 0 ∧ c ≠ ⊤ ∧ μ = c • ν
[PROOFSTEP]
have K : PositiveCompacts G := Classical.arbitrary _
[GOAL]
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
⊢ ∃ c, c ≠ 0 ∧ c ≠ ⊤ ∧ μ = c • ν
[PROOFSTEP]
have νpos : 0 < ν K := measure_pos_of_nonempty_interior _ K.interior_nonempty
[GOAL]
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
νpos : 0 < ↑↑ν ↑K
⊢ ∃ c, c ≠ 0 ∧ c ≠ ⊤ ∧ μ = c • ν
[PROOFSTEP]
have νne : ν K ≠ ∞ := K.isCompact.measure_lt_top.ne
[GOAL]
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
νpos : 0 < ↑↑ν ↑K
νne : ↑↑ν ↑K ≠ ⊤
⊢ ∃ c, c ≠ 0 ∧ c ≠ ⊤ ∧ μ = c • ν
[PROOFSTEP]
refine' ⟨μ K / ν K, _, _, _⟩
[GOAL]
case refine'_1
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
νpos : 0 < ↑↑ν ↑K
νne : ↑↑ν ↑K ≠ ⊤
⊢ ↑↑μ ↑K / ↑↑ν ↑K ≠ 0
[PROOFSTEP]
simp only [νne, (μ.measure_pos_of_nonempty_interior K.interior_nonempty).ne', Ne.def, ENNReal.div_eq_zero_iff,
not_false_iff, or_self_iff]
[GOAL]
case refine'_2
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
νpos : 0 < ↑↑ν ↑K
νne : ↑↑ν ↑K ≠ ⊤
⊢ ↑↑μ ↑K / ↑↑ν ↑K ≠ ⊤
[PROOFSTEP]
simp only [div_eq_mul_inv, νpos.ne', (K.isCompact.measure_lt_top (μ := μ)).ne, or_self_iff, ENNReal.inv_eq_top,
ENNReal.mul_eq_top, Ne.def, not_false_iff, and_false_iff, false_and_iff]
[GOAL]
case refine'_3
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
νpos : 0 < ↑↑ν ↑K
νne : ↑↑ν ↑K ≠ ⊤
⊢ μ = (↑↑μ ↑K / ↑↑ν ↑K) • ν
[PROOFSTEP]
calc
μ = μ K • haarMeasure K := haarMeasure_unique μ K
_ = (μ K / ν K) • ν K • haarMeasure K := by
rw [smul_smul, div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel νpos.ne' νne, mul_one]
_ = (μ K / ν K) • ν := by rw [← haarMeasure_unique ν K]
[GOAL]
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
νpos : 0 < ↑↑ν ↑K
νne : ↑↑ν ↑K ≠ ⊤
⊢ ↑↑μ ↑K • haarMeasure K = (↑↑μ ↑K / ↑↑ν ↑K) • ↑↑ν ↑K • haarMeasure K
[PROOFSTEP]
rw [smul_smul, div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel νpos.ne' νne, mul_one]
[GOAL]
G : Type u_1
inst✝⁹ : Group G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : T2Space G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
inst✝² : LocallyCompactSpace G
μ ν : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : IsHaarMeasure ν
K : PositiveCompacts G
νpos : 0 < ↑↑ν ↑K
νne : ↑↑ν ↑K ≠ ⊤
⊢ (↑↑μ ↑K / ↑↑ν ↑K) • ↑↑ν ↑K • haarMeasure K = (↑↑μ ↑K / ↑↑ν ↑K) • ν
[PROOFSTEP]
rw [← haarMeasure_unique ν K]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
inst✝¹ : LocallyCompactSpace G
μ : Measure G
inst✝ : IsHaarMeasure μ
⊢ Regular μ
[PROOFSTEP]
have K : PositiveCompacts G := Classical.arbitrary _
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
inst✝¹ : LocallyCompactSpace G
μ : Measure G
inst✝ : IsHaarMeasure μ
K : PositiveCompacts G
⊢ Regular μ
[PROOFSTEP]
obtain ⟨c, _, ctop, hμ⟩ : ∃ c : ℝ≥0∞, c ≠ 0 ∧ c ≠ ∞ ∧ μ = c • haarMeasure K := isHaarMeasure_eq_smul_isHaarMeasure μ _
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
inst✝¹ : LocallyCompactSpace G
μ : Measure G
inst✝ : IsHaarMeasure μ
K : PositiveCompacts G
c : ℝ≥0∞
left✝ : c ≠ 0
ctop : c ≠ ⊤
hμ : μ = c • haarMeasure K
⊢ Regular μ
[PROOFSTEP]
rw [hμ]
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
inst✝¹ : LocallyCompactSpace G
μ : Measure G
inst✝ : IsHaarMeasure μ
K : PositiveCompacts G
c : ℝ≥0∞
left✝ : c ≠ 0
ctop : c ≠ ⊤
hμ : μ = c • haarMeasure K
⊢ Regular (c • haarMeasure K)
[PROOFSTEP]
exact Regular.smul ctop
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
⊢ E / E ∈ 𝓝 1
[PROOFSTEP]
obtain ⟨L, hL, hLE, hLpos, hLtop⟩ : ∃ L : Set G, MeasurableSet L ∧ L ⊆ E ∧ 0 < μ L ∧ μ L < ∞ :=
exists_subset_measure_lt_top hE hEpos
[GOAL]
case intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
⊢ E / E ∈ 𝓝 1
[PROOFSTEP]
obtain ⟨K, hKL, hK, hKpos⟩ : ∃ (K : Set G), K ⊆ L ∧ IsCompact K ∧ 0 < μ K :=
MeasurableSet.exists_lt_isCompact_of_ne_top hL (ne_of_lt hLtop) hLpos
[GOAL]
case intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
⊢ E / E ∈ 𝓝 1
[PROOFSTEP]
have hKtop : μ K ≠ ∞ := by
apply ne_top_of_le_ne_top (ne_of_lt hLtop)
apply measure_mono hKL
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
⊢ ↑↑μ K ≠ ⊤
[PROOFSTEP]
apply ne_top_of_le_ne_top (ne_of_lt hLtop)
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
⊢ ↑↑μ K ≤ ↑↑μ L
[PROOFSTEP]
apply measure_mono hKL
[GOAL]
case intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
⊢ E / E ∈ 𝓝 1
[PROOFSTEP]
obtain ⟨U, hUK, hU, hμUK⟩ : ∃ (U : Set G), U ⊇ K ∧ IsOpen U ∧ μ U < μ K + μ K :=
Set.exists_isOpen_lt_add K hKtop hKpos.ne'
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
⊢ E / E ∈ 𝓝 1
[PROOFSTEP]
obtain ⟨V, hV1, hVKU⟩ : ∃ V ∈ 𝓝 (1 : G), V * K ⊆ U := compact_open_separated_mul_left hK hU hUK
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
⊢ E / E ∈ 𝓝 1
[PROOFSTEP]
have hv : ∀ v : G, v ∈ V → ¬Disjoint ({ v } * K) K :=
by
intro v hv hKv
have hKvsub : { v } * K ∪ K ⊆ U := by
apply Set.union_subset _ hUK
apply _root_.subset_trans _ hVKU
apply Set.mul_subset_mul _ (Set.Subset.refl K)
simp only [Set.singleton_subset_iff, hv]
replace hKvsub := @measure_mono _ _ μ _ _ hKvsub
have hcontr := lt_of_le_of_lt hKvsub hμUK
rw [measure_union hKv (IsCompact.measurableSet hK)] at hcontr
have hKtranslate : μ ({ v } * K) = μ K := by simp only [singleton_mul, image_mul_left, measure_preimage_mul]
rw [hKtranslate, lt_self_iff_false] at hcontr
assumption
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
⊢ ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
[PROOFSTEP]
intro v hv hKv
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
⊢ False
[PROOFSTEP]
have hKvsub : { v } * K ∪ K ⊆ U := by
apply Set.union_subset _ hUK
apply _root_.subset_trans _ hVKU
apply Set.mul_subset_mul _ (Set.Subset.refl K)
simp only [Set.singleton_subset_iff, hv]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
⊢ {v} * K ∪ K ⊆ U
[PROOFSTEP]
apply Set.union_subset _ hUK
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
⊢ {v} * K ⊆ U
[PROOFSTEP]
apply _root_.subset_trans _ hVKU
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
⊢ {v} * K ⊆ V * K
[PROOFSTEP]
apply Set.mul_subset_mul _ (Set.Subset.refl K)
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
⊢ {v} ⊆ V
[PROOFSTEP]
simp only [Set.singleton_subset_iff, hv]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
hKvsub : {v} * K ∪ K ⊆ U
⊢ False
[PROOFSTEP]
replace hKvsub := @measure_mono _ _ μ _ _ hKvsub
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
hKvsub : ↑↑μ ({v} * K ∪ K) ≤ ↑↑μ U
⊢ False
[PROOFSTEP]
have hcontr := lt_of_le_of_lt hKvsub hμUK
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
hKvsub : ↑↑μ ({v} * K ∪ K) ≤ ↑↑μ U
hcontr : ↑↑μ ({v} * K ∪ K) < ↑↑μ K + ↑↑μ K
⊢ False
[PROOFSTEP]
rw [measure_union hKv (IsCompact.measurableSet hK)] at hcontr
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
hKvsub : ↑↑μ ({v} * K ∪ K) ≤ ↑↑μ U
hcontr : ↑↑μ ({v} * K) + ↑↑μ K < ↑↑μ K + ↑↑μ K
⊢ False
[PROOFSTEP]
have hKtranslate : μ ({ v } * K) = μ K := by simp only [singleton_mul, image_mul_left, measure_preimage_mul]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
hKvsub : ↑↑μ ({v} * K ∪ K) ≤ ↑↑μ U
hcontr : ↑↑μ ({v} * K) + ↑↑μ K < ↑↑μ K + ↑↑μ K
⊢ ↑↑μ ({v} * K) = ↑↑μ K
[PROOFSTEP]
simp only [singleton_mul, image_mul_left, measure_preimage_mul]
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
hKvsub : ↑↑μ ({v} * K ∪ K) ≤ ↑↑μ U
hcontr : ↑↑μ ({v} * K) + ↑↑μ K < ↑↑μ K + ↑↑μ K
hKtranslate : ↑↑μ ({v} * K) = ↑↑μ K
⊢ False
[PROOFSTEP]
rw [hKtranslate, lt_self_iff_false] at hcontr
[GOAL]
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
v : G
hv : v ∈ V
hKv : Disjoint ({v} * K) K
hKvsub : ↑↑μ ({v} * K ∪ K) ≤ ↑↑μ U
hcontr : False
hKtranslate : ↑↑μ ({v} * K) = ↑↑μ K
⊢ False
[PROOFSTEP]
assumption
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
hv : ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
⊢ E / E ∈ 𝓝 1
[PROOFSTEP]
suffices V ⊆ E / E from Filter.mem_of_superset hV1 this
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
hv : ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
⊢ V ⊆ E / E
[PROOFSTEP]
intro v hvV
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
hv : ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
v : G
hvV : v ∈ V
⊢ v ∈ E / E
[PROOFSTEP]
obtain ⟨x, hxK, hxvK⟩ : ∃ x : G, x ∈ { v } * K ∧ x ∈ K := Set.not_disjoint_iff.1 (hv v hvV)
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
hv : ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
v : G
hvV : v ∈ V
x : G
hxK : x ∈ {v} * K
hxvK : x ∈ K
⊢ v ∈ E / E
[PROOFSTEP]
refine' ⟨x, v⁻¹ * x, hLE (hKL hxvK), _, _⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.refine'_1
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
hv : ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
v : G
hvV : v ∈ V
x : G
hxK : x ∈ {v} * K
hxvK : x ∈ K
⊢ v⁻¹ * x ∈ E
[PROOFSTEP]
apply hKL.trans hLE
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.refine'_1.a
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
hv : ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
v : G
hvV : v ∈ V
x : G
hxK : x ∈ {v} * K
hxvK : x ∈ K
⊢ v⁻¹ * x ∈ K
[PROOFSTEP]
simpa only [singleton_mul, image_mul_left, mem_preimage] using hxK
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.intro.refine'_2
G : Type u_1
inst✝⁸ : Group G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : T2Space G
inst✝⁵ : TopologicalGroup G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
E : Set G
hE : MeasurableSet E
hEpos : 0 < ↑↑μ E
L : Set G
hL : MeasurableSet L
hLE : L ⊆ E
hLpos : 0 < ↑↑μ L
hLtop : ↑↑μ L < ⊤
K : Set G
hKL : K ⊆ L
hK : IsCompact K
hKpos : 0 < ↑↑μ K
hKtop : ↑↑μ K ≠ ⊤
U : Set G
hUK : U ⊇ K
hU : IsOpen U
hμUK : ↑↑μ U < ↑↑μ K + ↑↑μ K
V : Set G
hV1 : V ∈ 𝓝 1
hVKU : V * K ⊆ U
hv : ∀ (v : G), v ∈ V → ¬Disjoint ({v} * K) K
v : G
hvV : v ∈ V
x : G
hxK : x ∈ {v} * K
hxvK : x ∈ K
⊢ (fun x x_1 => x / x_1) x (v⁻¹ * x) = v
[PROOFSTEP]
simp only [div_eq_iff_eq_mul, ← mul_assoc, mul_right_inv, one_mul]
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
⊢ IsInvInvariant μ
[PROOFSTEP]
constructor
[GOAL]
case inv_eq_self
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
⊢ Measure.inv μ = μ
[PROOFSTEP]
haveI : IsHaarMeasure (Measure.map Inv.inv μ) := (MulEquiv.inv G).isHaarMeasure_map μ continuous_inv continuous_inv
[GOAL]
case inv_eq_self
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this : IsHaarMeasure (map inv μ)
⊢ Measure.inv μ = μ
[PROOFSTEP]
obtain ⟨c, _, _, hc⟩ : ∃ c : ℝ≥0∞, c ≠ 0 ∧ c ≠ ∞ ∧ Measure.map Inv.inv μ = c • μ :=
isHaarMeasure_eq_smul_isHaarMeasure _ _
[GOAL]
case inv_eq_self.intro.intro.intro
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
⊢ Measure.inv μ = μ
[PROOFSTEP]
have : map Inv.inv (map Inv.inv μ) = c ^ 2 • μ := by simp only [hc, smul_smul, pow_two, Measure.map_smul]
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
⊢ map inv (map inv μ) = c ^ 2 • μ
[PROOFSTEP]
simp only [hc, smul_smul, pow_two, Measure.map_smul]
[GOAL]
case inv_eq_self.intro.intro.intro
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
⊢ Measure.inv μ = μ
[PROOFSTEP]
have μeq : μ = c ^ 2 • μ :=
by
rw [map_map continuous_inv.measurable continuous_inv.measurable] at this
simpa only [inv_involutive, Involutive.comp_self, map_id]
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
⊢ μ = c ^ 2 • μ
[PROOFSTEP]
rw [map_map continuous_inv.measurable continuous_inv.measurable] at this
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map ((fun a => a⁻¹) ∘ fun a => a⁻¹) μ = c ^ 2 • μ
⊢ μ = c ^ 2 • μ
[PROOFSTEP]
simpa only [inv_involutive, Involutive.comp_self, map_id]
[GOAL]
case inv_eq_self.intro.intro.intro
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
⊢ Measure.inv μ = μ
[PROOFSTEP]
have K : PositiveCompacts G := Classical.arbitrary _
[GOAL]
case inv_eq_self.intro.intro.intro
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
⊢ Measure.inv μ = μ
[PROOFSTEP]
have : c ^ 2 * μ K = 1 ^ 2 * μ K := by
conv_rhs => rw [μeq]
simp
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
⊢ c ^ 2 * ↑↑μ ↑K = 1 ^ 2 * ↑↑μ ↑K
[PROOFSTEP]
conv_rhs => rw [μeq]
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
| 1 ^ 2 * ↑↑μ ↑K
[PROOFSTEP]
rw [μeq]
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
| 1 ^ 2 * ↑↑μ ↑K
[PROOFSTEP]
rw [μeq]
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
| 1 ^ 2 * ↑↑μ ↑K
[PROOFSTEP]
rw [μeq]
[GOAL]
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
⊢ c ^ 2 * ↑↑μ ↑K = 1 ^ 2 * ↑↑(c ^ 2 • μ) ↑K
[PROOFSTEP]
simp
[GOAL]
case inv_eq_self.intro.intro.intro
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝¹ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this✝ : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
this : c ^ 2 * ↑↑μ ↑K = 1 ^ 2 * ↑↑μ ↑K
⊢ Measure.inv μ = μ
[PROOFSTEP]
have : c ^ 2 = 1 ^ 2 :=
(ENNReal.mul_eq_mul_right (measure_pos_of_nonempty_interior _ K.interior_nonempty).ne'
K.isCompact.measure_lt_top.ne).1
this
[GOAL]
case inv_eq_self.intro.intro.intro
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝² : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this✝¹ : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
this✝ : c ^ 2 * ↑↑μ ↑K = 1 ^ 2 * ↑↑μ ↑K
this : c ^ 2 = 1 ^ 2
⊢ Measure.inv μ = μ
[PROOFSTEP]
have : c = 1 := (ENNReal.pow_strictMono two_ne_zero).injective this
[GOAL]
case inv_eq_self.intro.intro.intro
G : Type u_1
inst✝⁸ : CommGroup G
inst✝⁷ : TopologicalSpace G
inst✝⁶ : TopologicalGroup G
inst✝⁵ : T2Space G
inst✝⁴ : MeasurableSpace G
inst✝³ : BorelSpace G
inst✝² : SecondCountableTopology G
μ : Measure G
inst✝¹ : IsHaarMeasure μ
inst✝ : LocallyCompactSpace G
this✝³ : IsHaarMeasure (map inv μ)
c : ℝ≥0∞
left✝¹ : c ≠ 0
left✝ : c ≠ ⊤
hc : map inv μ = c • μ
this✝² : map inv (map inv μ) = c ^ 2 • μ
μeq : μ = c ^ 2 • μ
K : PositiveCompacts G
this✝¹ : c ^ 2 * ↑↑μ ↑K = 1 ^ 2 * ↑↑μ ↑K
this✝ : c ^ 2 = 1 ^ 2
this : c = 1
⊢ Measure.inv μ = μ
[PROOFSTEP]
rw [Measure.inv, hc, this, one_smul]
[GOAL]
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
⊢ map (fun g => g ^ n) μ = μ
[PROOFSTEP]
let f := @zpowGroupHom G _ n
[GOAL]
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
⊢ map (fun g => g ^ n) μ = μ
[PROOFSTEP]
have hf : Continuous f := continuous_zpow n
[GOAL]
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
⊢ map (fun g => g ^ n) μ = μ
[PROOFSTEP]
haveI : (μ.map f).IsHaarMeasure := isHaarMeasure_map μ f hf (RootableBy.surjective_pow G ℤ hn) (by simp)
[GOAL]
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
⊢ Filter.Tendsto (↑f) (Filter.cocompact G) (Filter.cocompact G)
[PROOFSTEP]
simp
[GOAL]
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this : IsHaarMeasure (map (↑f) μ)
⊢ map (fun g => g ^ n) μ = μ
[PROOFSTEP]
obtain ⟨C, -, -, hC⟩ := isHaarMeasure_eq_smul_isHaarMeasure (μ.map f) μ
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this : IsHaarMeasure (map (↑f) μ)
C : ℝ≥0∞
hC : map (↑f) μ = C • μ
⊢ map (fun g => g ^ n) μ = μ
[PROOFSTEP]
suffices C = 1 by rwa [this, one_smul] at hC
[GOAL]
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this✝ : IsHaarMeasure (map (↑f) μ)
C : ℝ≥0∞
hC : map (↑f) μ = C • μ
this : C = 1
⊢ map (fun g => g ^ n) μ = μ
[PROOFSTEP]
rwa [this, one_smul] at hC
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this : IsHaarMeasure (map (↑f) μ)
C : ℝ≥0∞
hC : map (↑f) μ = C • μ
⊢ C = 1
[PROOFSTEP]
have h_univ : (μ.map f) univ = μ univ := by
rw [map_apply_of_aemeasurable hf.measurable.aemeasurable MeasurableSet.univ, preimage_univ]
[GOAL]
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this : IsHaarMeasure (map (↑f) μ)
C : ℝ≥0∞
hC : map (↑f) μ = C • μ
⊢ ↑↑(map (↑f) μ) univ = ↑↑μ univ
[PROOFSTEP]
rw [map_apply_of_aemeasurable hf.measurable.aemeasurable MeasurableSet.univ, preimage_univ]
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this : IsHaarMeasure (map (↑f) μ)
C : ℝ≥0∞
hC : map (↑f) μ = C • μ
h_univ : ↑↑(map (↑f) μ) univ = ↑↑μ univ
⊢ C = 1
[PROOFSTEP]
have hμ₀ : μ univ ≠ 0 := IsOpenPosMeasure.open_pos univ isOpen_univ univ_nonempty
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this : IsHaarMeasure (map (↑f) μ)
C : ℝ≥0∞
hC : map (↑f) μ = C • μ
h_univ : ↑↑(map (↑f) μ) univ = ↑↑μ univ
hμ₀ : ↑↑μ univ ≠ 0
⊢ C = 1
[PROOFSTEP]
have hμ₁ : μ univ ≠ ∞ := CompactSpace.isFiniteMeasure.measure_univ_lt_top.ne
[GOAL]
case intro.intro.intro
G : Type u_1
inst✝⁹ : CommGroup G
inst✝⁸ : TopologicalSpace G
inst✝⁷ : TopologicalGroup G
inst✝⁶ : T2Space G
inst✝⁵ : MeasurableSpace G
inst✝⁴ : BorelSpace G
inst✝³ : SecondCountableTopology G
μ : Measure G
inst✝² : IsHaarMeasure μ
inst✝¹ : CompactSpace G
inst✝ : RootableBy G ℤ
n : ℤ
hn : n ≠ 0
f : G →* G := zpowGroupHom n
hf : Continuous ↑f
this : IsHaarMeasure (map (↑f) μ)
C : ℝ≥0∞
hC : map (↑f) μ = C • μ
h_univ : ↑↑(map (↑f) μ) univ = ↑↑μ univ
hμ₀ : ↑↑μ univ ≠ 0
hμ₁ : ↑↑μ univ ≠ ⊤
⊢ C = 1
[PROOFSTEP]
rwa [hC, smul_apply, Algebra.id.smul_eq_mul, mul_comm, ← ENNReal.eq_div_iff hμ₀ hμ₁, ENNReal.div_self hμ₀ hμ₁] at h_univ
|
theory int_mul_comm
imports Main
"$HIPSTER_HOME/IsaHipster"
begin
datatype Sign = Pos | Neg
datatype Nat = Zero | Succ "Nat"
datatype Z = P "Nat" | N "Nat"
fun toInteger :: "Sign => Nat => Z" where
"toInteger (Pos) y = P y"
| "toInteger (Neg) (Zero) = P Zero"
| "toInteger (Neg) (Succ m) = N m"
fun sign2 :: "Z => Sign" where
"sign2 (P y) = Pos"
| "sign2 (N z) = Neg"
fun plus :: "Nat => Nat => Nat" where
"plus (Zero) y = y"
| "plus (Succ n) y = Succ (plus n y)"
fun opposite :: "Sign => Sign" where
"opposite (Pos) = Neg"
| "opposite (Neg) = Pos"
fun timesSign :: "Sign => Sign => Sign" where
"timesSign (Pos) y = y"
| "timesSign (Neg) y = opposite y"
fun mult :: "Nat => Nat => Nat" where
"mult (Zero) y = Zero"
| "mult (Succ n) y = plus y (mult n y)"
fun absVal :: "Z => Nat" where
"absVal (P n) = n"
| "absVal (N m) = Succ m"
fun times :: "Z => Z => Z" where
"times x y =
toInteger
(timesSign (sign2 x) (sign2 y)) (mult (absVal x) (absVal y))"
(*hipster toInteger
sign2
plus
opposite
timesSign
mult
absVal
times *)
theorem x0 :
"!! (x :: Z) (y :: Z) . (times x y) = (times y x)"
by (tactic \<open>Subgoal.FOCUS_PARAMS (K (Tactic_Data.hard_tac @{context})) @{context} 1\<close>)
end
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category.Core
module Categories.Object.Product.Limit {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Data.Nat.Base using (ℕ)
open import Data.Fin.Base using (Fin)
open import Data.Fin.Patterns
open import Categories.Category.Lift
open import Categories.Category.Finite.Fin
open import Categories.Category.Finite.Fin.Construction.Discrete
open import Categories.Object.Product C
open import Categories.Diagram.Limit
open import Categories.Functor.Core
import Categories.Category.Construction.Cones as Co
import Categories.Morphism.Reasoning as MR
private
module C = Category C
open C
open MR C
open HomReasoning
module _ {o′ ℓ′ e′} {F : Functor (liftC o′ ℓ′ e′ (Discrete 2)) C} where
private
module F = Functor F
open F
limit⇒product : Limit F → Product (F₀ (lift 0F)) (F₀ (lift 1F))
limit⇒product L = record
{ A×B = apex
; π₁ = proj (lift 0F)
; π₂ = proj (lift 1F)
; ⟨_,_⟩ = λ f g → rep record
{ apex = record
{ ψ = λ { (lift 0F) → f
; (lift 1F) → g }
; commute = λ { {lift 0F} {lift 0F} (lift 0F) → elimˡ identity
; {lift 1F} {lift 1F} (lift 0F) → elimˡ identity }
}
}
; project₁ = commute
; project₂ = commute
; unique = λ {_} {h} eq eq′ → terminal.!-unique record
{ arr = h
; commute = λ { {lift 0F} → eq
; {lift 1F} → eq′ }
}
}
where open Limit L
module _ o′ ℓ′ e′ A B where
open Equiv
product⇒limit-F : Functor (liftC o′ ℓ′ e′ (Discrete 2)) C
product⇒limit-F = record
{ F₀ = λ { (lift 0F) → A
; (lift 1F) → B }
; F₁ = λ { {lift 0F} {lift 0F} _ → C.id
; {lift 1F} {lift 1F} _ → C.id }
; identity = λ { {lift 0F} → refl
; {lift 1F} → refl }
; homomorphism = λ { {lift 0F} {lift 0F} {lift 0F} → sym identity²
; {lift 1F} {lift 1F} {lift 1F} → sym identity² }
; F-resp-≈ = λ { {lift 0F} {lift 0F} _ → refl
; {lift 1F} {lift 1F} _ → refl }
}
module _ o′ ℓ′ e′ {A B} (p : Product A B) where
open Product p
private
F = product⇒limit-F o′ ℓ′ e′ A B
open Functor F
product⇒limit : Limit F
product⇒limit = record
{ terminal = record
{ ⊤ = record
{ N = A×B
; apex = record
{ ψ = λ { (lift 0F) → π₁
; (lift 1F) → π₂ }
; commute = λ { {lift 0F} {lift 0F} (lift 0F) → identityˡ
; {lift 1F} {lift 1F} (lift 0F) → identityˡ }
}
}
; ! = λ {K} →
let open Co.Cone F K
in record
{ arr = ⟨ ψ (lift 0F) , ψ (lift 1F) ⟩
; commute = λ { {lift 0F} → project₁
; {lift 1F} → project₂ }
}
; !-unique = λ {K} f →
let module K = Co.Cone F K
module f = Co.Cone⇒ F f
in begin
⟨ K.ψ (lift 0F) , K.ψ (lift 1F) ⟩ ≈˘⟨ ⟨⟩-cong₂ f.commute f.commute ⟩
⟨ π₁ ∘ f.arr , π₂ ∘ f.arr ⟩ ≈⟨ g-η ⟩
f.arr ∎
}
}
|
Require Import Reals Coquelicot.Coquelicot Coquelicot.Series.
Require Import ProofIrrelevance EquivDec.
Require Import Sums utils.Utils Morphisms.
Require Import Lia Lra.
Require Import Coq.Logic.FunctionalExtensionality.
From mathcomp Require Import ssreflect ssrfun seq.
Require Import ExtLib.Structures.Monad ExtLib.Structures.MonadLaws.
Require Import ExtLib.Structures.Functor.
Import MonadNotation FunctorNotation.
Set Bullet Behavior "Strict Subproofs".
Require List.
Require Import Permutation.
(*
****************************************************************************************
This file defines the pmf monad (also called the finitary Giry monad) which is a monad
of finitely supported probability measures on a set. The construction is very general,
and we don't need to work in that generality. Our main application is to use this monad
to define and reason about Markov Decision Processes.
We also add results on conditional probability and conditional expectation, everything
tailored to the discrete case.
****************************************************************************************
*)
(* Helper lemmas. Move to RealAdd. *)
Fixpoint list_fst_sum {A : Type} (l : list (nonnegreal*A)): R :=
match l with
| nil => 0
| (n,_) :: ns => n + list_fst_sum ns
end.
Definition list_fst_sum' {A : Type} (l : list (nonnegreal*A)) : R :=
list_sum (map (fun x => nonneg (fst x)) l).
Lemma list_fst_sum_compat {A : Type} (l : list (nonnegreal*A)) : list_fst_sum l = list_fst_sum' l.
Proof.
induction l.
* unfold list_fst_sum' ; simpl ; reflexivity.
* unfold list_fst_sum'. destruct a. simpl.
rewrite IHl. f_equal.
Qed.
Lemma list_sum_is_nonneg {A : Type} (l : list(nonnegreal*A)) : 0 <= list_fst_sum l.
Proof.
induction l.
simpl ; lra.
simpl. destruct a as [n].
assert (0 <= n) by apply (cond_nonneg n).
apply (Rplus_le_le_0_compat _ _ H).
lra.
Qed.
Lemma prod_nonnegreal : forall (a b : nonnegreal), 0 <= a*b.
Proof.
intros (a,ha) (b,hb).
exact (Rmult_le_pos _ _ ha hb).
Qed.
Lemma div_nonnegreal : forall (a b : nonnegreal), 0 <> b -> 0 <= a/b.
Proof.
intros (a,ha) (b,hb) Hb.
apply (Rdiv_le_0_compat).
apply ha. simpl in *. case hb.
trivial. intros H. firstorder.
Qed.
Lemma mknonnegreal_assoc (r1 r2 r3 : nonnegreal) :
mknonnegreal _ (prod_nonnegreal (mknonnegreal _ (prod_nonnegreal r1 r2) ) r3) = mknonnegreal _ (prod_nonnegreal r1 (mknonnegreal _ (prod_nonnegreal r2 r3))).
Proof.
apply nonneg_ext; simpl.
lra.
Qed.
Lemma Rone_mult_nonnegreal (r : nonnegreal) (hr : 0 <= R1*r) : mknonnegreal (R1*r) hr = r.
Proof.
destruct r as [r hr'].
simpl. assert (r = R1 * r) by lra.
simpl in hr. revert hr.
rewrite <- H. intros.
f_equal. apply proof_irrelevance.
Qed.
Lemma list_fst_sum_cat {A : Type} (l1 l2 : list (nonnegreal * A)) :
list_fst_sum (l1 ++ l2) = (list_fst_sum l1) + (list_fst_sum l2).
Proof.
induction l1.
* simpl ; nra.
* simpl ; destruct a; nra.
Qed.
Definition nonneg_list_sum {A : Type} (l : list (nonnegreal * A)) : nonnegreal
:= {|
nonneg := list_fst_sum l;
cond_nonneg := (list_sum_is_nonneg l)
|}.
Section Pmf.
(* Defines the record of discrete probability measures on a type. *)
Record Pmf (A : Type) := mkPmf {
outcomes :> list (nonnegreal * A);
sum1 : list_fst_sum outcomes = R1
}.
Global Arguments outcomes {_}.
Global Arguments sum1 {_}.
Global Arguments mkPmf {_}.
Lemma Pmf_ext {A} (p q : Pmf A) : outcomes p = outcomes q -> p = q.
Proof.
destruct p as [op sp].
destruct q as [oq sq].
rewrite /outcomes => ?. (* what's happening here? *)
subst. f_equal. apply proof_irrelevance.
Qed.
Lemma sum1_compat {B} (p : Pmf B) :
list_sum (map (fun y : nonnegreal * B => nonneg (fst y)) (p.(outcomes))) = R1.
Proof.
rewrite <- p.(sum1).
rewrite list_fst_sum_compat.
unfold list_fst_sum'. reflexivity.
Qed.
Lemma pure_sum1 {A} (a : A) : list_fst_sum [::(mknonnegreal R1 (Rlt_le _ _ Rlt_0_1),a)] = R1.
Proof.
simpl. lra.
Qed.
Definition Pmf_pure : forall {A : Type}, A -> Pmf A := fun {A} (a:A) => {|
outcomes := [::(mknonnegreal R1 (Rlt_le _ _ Rlt_0_1),a)];
sum1 := pure_sum1 _
|}.
Global Instance Proper_pure {A : Type}: Proper (eq ==> eq) (@Pmf_pure A).
Proof.
unfold Proper,respectful; intros.
now subst.
Qed.
Fixpoint dist_bind_outcomes
{A B : Type} (f : A -> Pmf B) (p : list (nonnegreal*A)) : list(nonnegreal*B) :=
match p with
| nil => nil
| (n,a) :: ps =>
map (fun (py:nonnegreal*B) => (mknonnegreal _ (prod_nonnegreal n py.1),py.2)) (f a).(outcomes) ++ (dist_bind_outcomes f ps)
end.
Lemma dist_bind_outcomes_cat {A B : Type} (f : A -> Pmf B) (l1 l2 : list(nonnegreal*A)) :
dist_bind_outcomes f (l1 ++ l2) = (dist_bind_outcomes f l1) ++ (dist_bind_outcomes f l2).
Proof.
induction l1.
* simpl; easy.
* destruct a as [an aa]. simpl.
rewrite <- catA. rewrite IHl1.
reflexivity.
Qed.
Lemma list_fst_sum_const_mult {A B : Type} (f : A -> Pmf B) (n : nonnegreal) (a : A):
list_fst_sum [seq (mknonnegreal _ (prod_nonnegreal n py.1), py.2) | py <- f a]
= n*list_fst_sum [seq py | py <- f a].
Proof.
destruct (f a) as [fa Hfa]. simpl. revert Hfa.
generalize R1 as t. induction fa.
* simpl; intros.
auto with real.
*
simpl in *. destruct a0. intros t Htn0.
rewrite (IHfa (t - n0)).
specialize (IHfa (t-n0)). simpl. auto with real.
rewrite <- Htn0. lra.
Qed.
Lemma list_fst_sum_const_div {A : Type} (l : list (nonnegreal*A)) {n : nonnegreal} (hn : 0 <> nonneg n) :
list_fst_sum [seq (mknonnegreal _ (div_nonnegreal py.1 _ hn), py.2) | py <- l]
= list_fst_sum [seq py | py <- l]/n.
Proof.
generalize R1 as t. induction l.
* simpl. intros H. lra.
* simpl in *. destruct a. intros t. simpl.
rewrite (IHl (t - n)).
specialize (IHl (t-n)). simpl.
lra.
Qed.
Lemma dist_bind_sum1 {A B : Type} (f : A -> Pmf B) (p : Pmf A) :
list_fst_sum (dist_bind_outcomes f p.(outcomes)) = R1.
Proof.
destruct p as [p Hp]. simpl.
revert Hp. generalize R1 as t.
induction p.
* simpl; intuition.
* simpl in *. destruct a as [n a]. intros t0 Hnt0.
rewrite list_fst_sum_cat. rewrite (IHp (t0-n)).
rewrite list_fst_sum_const_mult. destruct (f a) as [fp Hfp]. simpl.
rewrite map_id Hfp. lra.
lra.
Qed.
Lemma dist_bind_sum1_compat {A B : Type} (f : A -> Pmf B) (p : Pmf A) :
list_fst_sum' (dist_bind_outcomes f p.(outcomes)) = R1.
Proof.
rewrite <-list_fst_sum_compat. apply dist_bind_sum1.
Qed.
Definition Pmf_bind {A B : Type} (p : Pmf A) (f : A -> Pmf B) : Pmf B :={|
outcomes := dist_bind_outcomes f p.(outcomes);
sum1 := dist_bind_sum1 f p
|}.
Global Instance Proper_bind {A B : Type}:
Proper (eq ==> (pointwise_relation A eq) ==> eq) (@Pmf_bind A B).
Proof.
unfold Proper, respectful, pointwise_relation.
intros p q Hpq f g Hfg; subst.
apply Pmf_ext.
destruct q as [q Hq].
unfold Pmf_bind; simpl.
clear Hq.
induction q; simpl; trivial.
destruct a.
f_equal; trivial.
now rewrite Hfg.
Qed.
Global Instance Monad_Pmf : Monad Pmf := {|
ret := @Pmf_pure;
bind := @Pmf_bind;
|}.
(*We can use the nice bind and return syntax, since Pmf is now part of the Monad typeclass.*)
Open Scope monad_scope.
Lemma Pmf_ret_of_bind {A : Type} (p : Pmf A) : p >>= (fun a => ret a) = p.
Proof.
apply Pmf_ext ; simpl.
induction p.(outcomes).
simpl. reflexivity.
simpl. destruct a. rewrite IHl.
f_equal. f_equal.
destruct n. apply nonneg_ext.
apply Rmult_1_r.
Qed.
Lemma Pmf_bind_of_ret {A B : Type} (a : A) (f : A -> Pmf B) : (ret a) >>= f = f a.
Proof.
apply Pmf_ext.
simpl. rewrite cats0.
rewrite <- map_id. apply eq_map.
intros (n,b). simpl.
now rewrite Rone_mult_nonnegreal.
Qed.
Lemma Pmf_bind_of_bind {A B C : Type} (p : Pmf A) (f : A -> Pmf B) (g : B -> Pmf C) :
(p >>= f) >>= g = p >>= (fun a => (f a) >>= g).
Proof.
apply Pmf_ext.
destruct p as [pout Hp].
revert Hp. simpl. generalize R1 as t.
induction pout.
* simpl ; easy.
* simpl. destruct a as [an aa].
intros t Ht. rewrite dist_bind_outcomes_cat. simpl.
rewrite <- (IHpout (t-an)).
destruct (f aa) as [faa Hfaa]. f_equal.
revert Hfaa. simpl. generalize R1 as u.
induction faa.
- simpl. reflexivity.
- destruct a as [an1 aa1].
simpl. intros u Hu. rewrite map_cat.
rewrite (IHfaa (u-an1)); clear IHfaa. f_equal. rewrite <- map_comp.
unfold comp. simpl.
apply List.map_ext; intros.
f_equal.
apply nonneg_ext. apply Rmult_assoc.
lra.
-
lra.
Qed.
(* Global Instance Pmf_MonadLaws : MonadLaws Monad_Pmf := {| *)
(* bind_of_return := @Pmf_bind_of_ret; *)
(* bind_associativity := @Pmf_bind_of_bind; *)
(* | }.*)
Definition dist_bind_outcomes_alt
{A B : Type} (f : A -> list (nonnegreal * B)) (p : list (nonnegreal*A)) : list(nonnegreal*B) :=
flatten (map (fun '(n,a) =>
map (fun (py:nonnegreal*B) => (mknonnegreal _ (prod_nonnegreal n py.1),py.2)) (f a)) p).
Definition dist_bind_outcomes_alt2
{A B : Type} (f : A -> list (nonnegreal * B)) (p : list (nonnegreal*A)) : list(nonnegreal*B) :=
List.concat (List.map (fun na =>
List.map (fun (py:nonnegreal*B) => (mknonnegreal _ (prod_nonnegreal (fst na) py.1),py.2)) (f (snd na))) p).
Lemma dist_bind_outcomes_alt2_eq {A B : Type} (f : A -> list (nonnegreal * B)) (p : list (nonnegreal*A)) :
dist_bind_outcomes_alt f p = dist_bind_outcomes_alt2 f p.
Proof.
induction p; simpl; trivial.
unfold dist_bind_outcomes_alt, dist_bind_outcomes_alt2 in *.
destruct a; simpl.
rewrite IHp.
firstorder.
Qed.
Instance dist_bind_outcomes_alt_eq_ext_proper {A B : Type} :
Proper (pointwise_relation A eq ==> eq ==> eq) (@dist_bind_outcomes_alt A B).
Proof.
intros ??????; subst.
unfold dist_bind_outcomes_alt.
f_equal.
eapply eq_map.
intros ?.
destruct x0; simpl.
rewrite H.
eapply eq_map.
intros ?.
reflexivity.
Qed.
Lemma dist_bind_outcomes_alt_eq {A B : Type}
(f : A -> Pmf B)
(p : list (nonnegreal*A)) :
dist_bind_outcomes f p = dist_bind_outcomes_alt (fun x => (f x).(outcomes)) p.
Proof.
unfold dist_bind_outcomes_alt.
induction p; simpl; trivial.
destruct a.
simpl.
now f_equal.
Qed.
Lemma dist_bind_outcomes_alt_comm {A B C : Type} (p:seq (nonnegreal * A)) (q:seq (nonnegreal * B)) (f : A -> B -> Pmf C) :
Permutation (dist_bind_outcomes_alt2 (fun a : A => dist_bind_outcomes_alt2 (fun x : B => f a x) q) p)
(dist_bind_outcomes_alt2 (fun a : B => dist_bind_outcomes_alt2 (fun x : A => (f^~ a) x) p) q).
Proof.
unfold dist_bind_outcomes_alt2.
erewrite List.map_ext.
2: {
intros.
rewrite List.concat_map.
rewrite List.map_map.
reflexivity.
}
symmetry.
erewrite List.map_ext.
2: {
intros.
rewrite List.concat_map.
rewrite List.map_map.
reflexivity.
}
symmetry.
repeat rewrite concat_map_concat'.
rewrite concat_map_swap_perm.
apply Permutation_concat.
apply Permutation_concat.
match goal with
| [|- Permutation ?x ?y ] => cut (x = y); [intros eqqq; rewrite eqqq; reflexivity | ]
end.
repeat (apply List.map_ext; intros).
repeat rewrite List.map_map.
repeat (apply List.map_ext; intros).
simpl.
f_equal.
apply nonneg_ext.
lra.
Qed.
Lemma Pmf_bind_comm {A B C : Type} (p : Pmf A) (q : Pmf B) (f : A -> B -> Pmf C) :
Permutation (Pmf_bind p (fun a => Pmf_bind q (f a))) (Pmf_bind q (fun b => Pmf_bind p (fun a => f a b))).
Proof.
unfold Pmf_bind; simpl.
destruct p as [p p1]; destruct q as [q q1].
repeat rewrite dist_bind_outcomes_alt_eq; simpl.
erewrite dist_bind_outcomes_alt_eq_ext_proper
; try (intros ?; rewrite dist_bind_outcomes_alt_eq; apply dist_bind_outcomes_alt2_eq)
; try reflexivity.
erewrite (dist_bind_outcomes_alt_eq_ext_proper (fun x : B => dist_bind_outcomes (f^~ x) p))
; try (intros ?; rewrite dist_bind_outcomes_alt_eq; apply dist_bind_outcomes_alt2_eq)
; try reflexivity.
repeat rewrite dist_bind_outcomes_alt2_eq; simpl.
apply dist_bind_outcomes_alt_comm.
Qed.
(* The functorial action of Pmf. *)
Definition Pmf_map {A B : Type}(f : A -> B) (p : Pmf A) : Pmf B := p >>= (ret \o f).
Global Instance Pmf_Functor : Functor Pmf := {| fmap := @Pmf_map |}.
Lemma Pmf_map_id {A : Type} (p : Pmf A) : id <$> p = p.
Proof.
simpl. unfold Pmf_map.
now rewrite Pmf_ret_of_bind.
Qed.
Lemma Pmf_map_ret {A B : Type} (a : A) (f : A -> B) : f <$> (ret a) = ret (f a).
Proof.
simpl.
unfold Pmf_map.
rewrite Pmf_bind_of_ret.
now unfold comp.
Qed.
Lemma Pmf_map_bind {A B : Type} (p : Pmf A) (f : A -> B) : p >>= (ret \o f) = f <$> p.
Proof.
reflexivity.
Qed.
Lemma Pmf_map_comp {A B C : Type}(p : Pmf A) (f : A -> B)(g : B -> C) :
g <$> (f <$> p) = (g \o f) <$> p.
Proof.
simpl.
unfold Pmf_map, comp.
rewrite Pmf_bind_of_bind.
now setoid_rewrite Pmf_bind_of_ret.
Qed.
Definition Pmf_prod {A B : Type} (p : Pmf A) (q : Pmf B) : Pmf (A*B) :=
a <- p;;
b <- q;;
ret (a,b).
End Pmf.
Definition prob {A : Type} (l : seq(nonnegreal*A)) : nonnegreal :=
mknonnegreal (list_fst_sum l) (list_sum_is_nonneg _).
(* Make all notations part of a single scope. *)
Notation "𝕡[ x ]" := (nonneg (prob x)) (at level 75, right associativity).
Section expected_value.
Open Scope fun_scope.
Arguments outcomes {_}.
Definition expt_value {A : Type} (p : Pmf A) (f : A -> R): R :=
list_sum (map (fun x => (f x.2) * nonneg x.1) p.(outcomes)).
Global Instance expt_value_Proper {A : Type}:
Proper (eq ==> pointwise_relation A eq ==> eq) (@expt_value A).
intros p q Hpq f g Hfg.
rewrite Hpq.
apply list_sum_map_ext.
intros a. now f_equal.
Qed.
Lemma expt_value_zero {A : Type} (p : Pmf A) :
expt_value p (fun a => 0) = 0.
Proof.
unfold expt_value.
induction p.(outcomes).
- simpl;lra.
- simpl. rewrite IHl. lra.
Qed.
Lemma expt_value_const_mul {A : Type} (p : Pmf A) (f : A -> R) (c : R):
expt_value p (fun a => c * (f a)) = c * expt_value p (fun a => f a).
Proof.
unfold expt_value.
induction p.(outcomes).
simpl ; lra.
simpl. rewrite IHl. lra.
Qed.
Lemma expt_value_const_mul' {A : Type} (p : Pmf A) (f : A -> R) (c : R):
expt_value p (fun a => (f a)*c) = c * expt_value p (fun a => f a).
Proof.
unfold expt_value.
induction p.(outcomes).
simpl ; lra.
simpl. rewrite IHl. lra.
Qed.
Lemma expt_value_add {A : Type} (p : Pmf A) (f1 f2 : A -> R) :
expt_value p (fun x => f1 x + f2 x) = (expt_value p f1) + (expt_value p f2).
Proof.
unfold expt_value.
induction p.(outcomes).
* simpl ; lra.
* simpl. rewrite IHl. lra.
Qed.
Lemma expt_value_sub {A : Type} (p : Pmf A) (f1 f2 : A -> R) :
expt_value p (fun x => f1 x - f2 x) = (expt_value p f1) - (expt_value p f2).
Proof.
unfold expt_value.
induction p.(outcomes).
* simpl ; lra.
* simpl. rewrite IHl. lra.
Qed.
Lemma expt_value_le {A : Type} (p : Pmf A) (f1 f2 : A -> R) :
(forall a : A, f1 a <= f2 a) -> expt_value p f1 <= expt_value p f2.
Proof.
intros Hf1f2. unfold expt_value.
induction p.(outcomes).
* simpl ; lra.
* simpl. enough (f1 a.2 * a.1 <= f2 a.2 * a.1).
apply (Rplus_le_compat _ _ _ _ H IHl).
apply Rmult_le_compat_r. apply cond_nonneg.
exact (Hf1f2 a.2).
Qed.
Lemma expt_value_sum_f_R0 {A : Type} (p : Pmf A) (f : nat -> A -> R) (N : nat) :
expt_value p (fun a => sum_f_R0 (fun n => f n a) N) = sum_f_R0 (fun n => expt_value p (f n)) N.
Proof.
unfold expt_value.
induction p.(outcomes).
* simpl. now rewrite sum_eq_R0.
* simpl. rewrite IHl. rewrite sum_plus. f_equal.
destruct a. simpl. rewrite <- scal_sum. apply Rmult_comm.
Qed.
Lemma sum_f_R0_Rabs_Series_aux_1 {A : Type} (p : Pmf A) (f : nat -> A -> R) (N : nat):
sum_f_R0 (fun n => expt_value p (fun a => f n a)) N <= Rabs (sum_f_R0 (fun n => expt_value p (fun a => f n a)) N).
Proof.
apply Rle_abs.
Qed.
Lemma sum_f_R0_Rabs_Series_aux_2 {A : Type} (p : Pmf A) (f : nat -> A -> R) (N : nat):
Rabs (sum_f_R0 (fun n => expt_value p (fun a => f n a)) N) <= sum_f_R0 (fun n => Rabs (expt_value p (fun a => f n a))) N.
Proof.
apply Rabs_triang_gen.
Qed.
Lemma expt_value_Rabs_Rle {A : Type} (p : Pmf A) (f : A -> R):
Rabs (expt_value p f) <= expt_value p (fun a => Rabs (f a)).
Proof.
unfold expt_value.
induction p.(outcomes).
* simpl. rewrite Rabs_R0 ; lra.
* simpl. refine (Rle_trans _ _ _ _ _).
apply Rabs_triang. rewrite Rabs_mult.
rewrite (Rabs_pos_eq a.1). apply Rplus_le_compat.
apply Rmult_le_compat_r. apply cond_nonneg. now right.
apply IHl. apply cond_nonneg.
Qed.
Lemma ex_series_le_Reals
: forall (a : nat -> R) (b : nat -> R),
(forall n : nat, Rabs (a n) <= b n) -> ex_series b -> ex_series a.
Proof.
intros a b Hab Hexb.
apply (@ex_series_le _ _ a b).
now apply Hab. assumption.
Qed.
Lemma expt_value_ex_series {A : Type} (p : Pmf A) (f : nat -> A -> R) :
ex_series (fun n => expt_value p (fun a => Rabs (f n a))) ->
ex_series (fun n => expt_value p (f n)).
Proof.
intros Hex.
refine (@ex_series_le_Reals _ _ _ _).
intros n. apply expt_value_Rabs_Rle.
assumption.
Qed.
Lemma expt_val_bdd_aux {A : Type} (g : nat -> A -> R) (p : Pmf A):
(forall (a : A), is_lim_seq (fun n => g n a) 0) -> is_lim_seq (fun n => expt_value p (fun x => g n x)) 0.
Proof.
intros H.
unfold expt_value. rewrite is_lim_seq_Reals.
unfold Un_cv.
induction p.(outcomes).
* simpl. intros eps0 H0. exists 0%nat. rewrite R_dist_eq. intros n Hn. apply H0.
* simpl in *. intros eps0 H0.
enough (H0': eps0/4 > 0).
specialize (IHl (eps0/4)%R H0'). destruct IHl as [N0 HN0].
specialize (H a.2).
revert H. rewrite is_lim_seq_Reals.
intros H. unfold Un_cv in H.
set (Ha := cond_nonneg a.1). case Ha.
intro Ha1. clear Ha.
enough (H1': eps0/(4 * a.1) > 0).
specialize (H (eps0/(4 * a.1))%R H1').
destruct H as [N1 HN1].
exists (N0 + N1)%nat. intros n Hn.
specialize (HN0 n).
specialize (HN1 n).
assert (Hn0 : (n >= N0)%nat) by lia.
assert (Hn1 : (n >= N1)%nat) by lia.
specialize (HN1 Hn1). specialize (HN0 Hn0).
clear Hn0 ; clear Hn1.
revert HN0. revert HN1.
unfold R_dist. rewrite Rminus_0_r ; rewrite Rminus_0_r ; rewrite Rminus_0_r.
intros HN0 HN1. refine (Rle_lt_trans _ _ _ _ _).
apply Rabs_triang. rewrite Rabs_mult. rewrite (Rabs_pos_eq a.1).
eapply Rlt_trans.
assert ((eps0 / (4 * a.1))*a.1 + (eps0 / 4) = eps0/2). field ; lra.
assert (Rabs (g n a.2) * a.1 + Rabs (list_sum [seq g n x.2 * nonneg (x.1) | x <- l]) < eps0/2).
rewrite <-H.
refine (Rplus_lt_compat _ _ _ _ _ _).
now apply Rmult_lt_compat_r. assumption.
apply H1. lra.
now left. apply Rlt_gt. apply RIneq.Rdiv_lt_0_compat. assumption.
lra.
intros Ha1. rewrite <-Ha1. setoid_rewrite Rmult_0_r.
setoid_rewrite Rplus_0_l. exists N0. intros n Hn.
eapply Rlt_trans. specialize (HN0 n Hn). apply HN0.
lra. lra.
Qed.
Lemma expt_value_Series {A : Type} (p : Pmf A) (f : nat -> A -> R) :
(forall a:A, ex_series (fun n => f n a)) ->
expt_value p (fun a => Series (fun n => f n a)) = Series (fun n => expt_value p (f n)).
Proof.
intros Hex.
symmetry.
apply is_series_unique.
rewrite is_series_Reals.
unfold infinite_sum.
intros eps Heps.
setoid_rewrite <- expt_value_sum_f_R0.
unfold R_dist. unfold Series. setoid_rewrite <-expt_value_sub.
assert (Ha : forall a:A, is_series (fun n => f n a) (Series (fun n => f n a)) ).
intros a. eapply (Series_correct _). apply (Hex a).
assert (Hinf : forall a:A, infinite_sum (fun n => f n a) (Series (fun n => f n a)) ).
intros a. rewrite <- is_series_Reals. apply Ha. clear Ha.
unfold infinite_sum in Hinf. unfold Series in Hinf. unfold R_dist in Hinf.
(* Change the name of the hypothesis from H to something else. *)
assert (H : forall x, Rabs x = R_dist x 0). intros x. unfold R_dist. f_equal ; lra.
setoid_rewrite H.
setoid_rewrite H in Hinf.
set (He := @expt_val_bdd_aux A).
setoid_rewrite is_lim_seq_Reals in He.
unfold Un_cv in He. apply He. apply Hinf. assumption.
Qed.
Lemma expt_value_pure {A : Type} (a : A) (f : A -> R) :
expt_value (Pmf_pure a) f = f a.
Proof.
unfold expt_value ; unfold Pmf_pure ; simpl.
lra.
Qed.
Lemma expt_value_Series_aux_2 {A : Type} (p : Pmf A) (f : nat -> A -> R) (N : nat):
expt_value p (fun a => sum_f_R0 (fun n => f n a) N) <= expt_value p (fun a => sum_f_R0 (fun n => Rabs (f n a)) N).
Proof.
apply expt_value_le.
intros a. induction N.
* simpl. apply Rle_abs.
* simpl. apply Rplus_le_compat ; try assumption.
apply Rle_abs.
Qed.
Lemma expt_value_bind_aux {A B : Type} (p : Pmf A) (g : A -> Pmf B) (f : B -> R) (n : nonnegreal) :
forall a : A, list_sum [seq (f x.2) * nonneg(x.1) * n | x <- (g a).(outcomes)] = list_sum [seq (f x.2) * nonneg(x.1) | x <- (g a).(outcomes)] * n.
Proof.
intros a.
induction (g a).(outcomes).
* simpl ; lra.
* rewrite map_cons. simpl. rewrite IHl. lra.
Qed.
Lemma expt_value_bind {A B : Type} (p : Pmf A) (g : A -> Pmf B) (f : B -> R) :
expt_value (Pmf_bind p g) f = expt_value p (fun a => expt_value (g a) f).
Proof.
unfold Pmf_bind.
unfold expt_value. simpl.
induction (p.(outcomes)).
* simpl ; reflexivity.
* destruct a. simpl. rewrite <-IHl. rewrite map_cat.
rewrite list_sum_cat. f_equal.
rewrite <-map_comp. rewrite <- (expt_value_bind_aux p).
f_equal. apply List.map_ext.
intros a0. simpl. lra.
Qed.
Lemma expt_value_bind' {A B : Type} (p : Pmf A) (g : A -> Pmf B) (f : A -> B -> R) :
forall init:A, expt_value (Pmf_bind p g) (f init) = expt_value p (fun a => expt_value (g a) (f init)).
Proof.
intros init.
unfold Pmf_bind.
unfold expt_value. simpl.
induction (p.(outcomes)).
* simpl ; reflexivity.
* destruct a. simpl. rewrite <-IHl. rewrite map_cat.
rewrite list_sum_cat. f_equal.
rewrite <-map_comp. rewrite <- (expt_value_bind_aux p).
f_equal. apply List.map_ext.
intros a0. simpl. lra.
Qed.
Lemma expt_value_bind_ret {A B : Type} (a : A) (g : A -> Pmf B) (f : B -> R) :
expt_value (Pmf_bind (Pmf_pure a) g) f = expt_value (g a) f.
Proof.
rewrite expt_value_bind.
rewrite expt_value_pure.
reflexivity.
Qed.
Lemma expt_value_expt_value {A : Type} (p q : Pmf A) (f : A -> R) :
expt_value p (fun a => expt_value q f) = (expt_value q f)*(expt_value p (fun a => 1)).
Proof.
unfold expt_value.
induction p.(outcomes).
simpl ; lra.
simpl. rewrite IHl. lra.
Qed.
Lemma expt_value_expt_value_pure {A : Type} (a : A) (p : Pmf A) (f : A -> R):
expt_value p (fun a => expt_value (Pmf_pure a) f) = (expt_value p f).
Proof.
f_equal. apply functional_extensionality. intros x.
now rewrite expt_value_pure.
Qed.
Lemma expt_value_Rle {A : Type} {D : R} {f : A -> R} (hf : forall a:A, Rabs (f a) <= D) (p : Pmf A) :
Rabs(expt_value p f) <= D.
Proof.
eapply Rle_trans.
apply expt_value_Rabs_Rle.
unfold expt_value. rewrite <- Rmult_1_r.
change (D*1) with (D*R1). rewrite <- (sum1_compat p).
induction p.(outcomes).
* simpl ; lra.
* simpl in *. rewrite Rmult_plus_distr_l.
assert ( Rabs (f a.2) * a.1 <= D * a.1). apply Rmult_le_compat_r. apply cond_nonneg.
refine (Rle_trans _ _ _ _ _).
apply Rle_abs. rewrite Rabs_Rabsolu.
apply hf.
refine (Rle_trans _ _ _ _ _).
apply Rplus_le_compat.
apply Rmult_le_compat_r.
apply cond_nonneg. apply hf. apply IHl.
now right.
Qed.
Lemma expt_value_bdd {A : Type} {D : R} {f : A -> R} (hf : forall a:A, (f a) <= D) (p : Pmf A) :
(expt_value p f) <= D.
Proof.
unfold expt_value. rewrite <- Rmult_1_r.
change (D*1) with (D*R1). rewrite <- (sum1_compat p).
induction p.(outcomes).
* simpl ; lra.
* simpl in *. rewrite Rmult_plus_distr_l.
assert ( f a.2 * a.1 <= D * a.1). apply Rmult_le_compat_r. apply cond_nonneg.
apply hf.
now apply Rplus_le_compat.
Qed.
Lemma expt_value_lbdd {A : Type} {D : R} {f : A -> R} (hf : forall a:A, D <= (f a)) (p : Pmf A) :
D <= (expt_value p f).
Proof.
unfold expt_value.
replace D with (D * R1) by lra.
rewrite <- (sum1_compat p).
induction p.(outcomes).
* simpl; lra.
* simpl in *. rewrite Rmult_plus_distr_l.
assert ( D * a.1 <= f a.2 * a.1). apply Rmult_le_compat_r. apply cond_nonneg.
apply hf.
now apply Rplus_le_compat.
Qed.
Lemma expt_value_const {A : Type} (c : R) (p : Pmf A) : expt_value p (fun _ => c) = c.
Proof.
destruct p as [lp Hp].
unfold expt_value.
simpl.
rewrite list_sum_const_mul.
rewrite list_fst_sum_compat in Hp.
unfold list_fst_sum' in Hp.
rewrite Hp.
lra.
Qed.
Lemma expt_value_sum_comm {A B : Type}
(f : A -> B -> R) (p : Pmf B) (la : list A):
expt_value p (fun b => list_sum (map (fun a => f a b) la)) =
list_sum (List.map (fun a => expt_value p (fun b => f a b)) la).
Proof.
destruct p as [lp Hlp].
unfold expt_value.
simpl. clear Hlp.
revert lp.
induction lp.
+ simpl. symmetry.
apply list_sum_map_zero.
+ simpl. rewrite IHlp.
rewrite list_sum_map_add.
f_equal. rewrite Rmult_comm.
rewrite <-list_sum_const_mul.
f_equal. apply List.map_ext; intros.
lra.
Qed.
Lemma expt_value_minus {A : Type} (f : A -> R) (p : Pmf A):
expt_value p (fun x => - (f x)) = - expt_value p f.
Proof.
apply Rplus_opp_r_uniq.
rewrite <-expt_value_add.
setoid_rewrite Rplus_opp_r.
apply expt_value_const.
Qed.
Lemma expt_value_prod_pmf {A B : Type} (f : A -> B -> R) (p : Pmf A) (q : Pmf B):
expt_value (Pmf_prod p q) (fun '(a,b) => f a b) = expt_value p (fun a => expt_value q (fun b => f a b)).
Proof.
unfold Pmf_prod; simpl.
rewrite expt_value_bind.
setoid_rewrite expt_value_bind.
now setoid_rewrite expt_value_pure.
Qed.
End expected_value.
Section variance.
Definition variance {A : Type} (p : Pmf A) (f : A -> R) :=
expt_value p (fun a => Rsqr((f a) - expt_value p f)).
Lemma variance_eq {A : Type} (p : Pmf A) (f : A -> R):
variance p f = expt_value p (fun a => (f a)²) - (expt_value p f)².
Proof.
unfold variance.
setoid_rewrite Rsqr_plus.
setoid_rewrite <-Rsqr_neg.
setoid_rewrite Ropp_mult_distr_r_reverse.
do 2 rewrite expt_value_add.
rewrite Rplus_assoc. unfold Rminus. f_equal.
rewrite expt_value_const.
rewrite expt_value_minus.
setoid_rewrite Rmult_assoc.
rewrite expt_value_const_mul.
rewrite expt_value_const_mul'.
rewrite <-Rmult_assoc.
replace (expt_value p [eta f]) with (expt_value p f) by reflexivity.
unfold Rsqr.
ring.
Qed.
Lemma variance_le_expt_value_sqr {A : Type} (p : Pmf A) (f : A -> R):
variance p f <= expt_value p (fun a => (f a)²).
Proof.
rewrite variance_eq.
rewrite Rle_minus_l.
rewrite <-(Rplus_0_r) at 1.
apply Rplus_le_compat_l.
apply Rle_0_sqr.
Qed.
Definition total_variance {A : Type} (lp : list (Pmf A)) (lf : list (A -> R)): R :=
list_sum (map (fun '(f,p) => variance p f) (zip lf lp)).
Lemma list_sum_sqr_pos {A : Type} (f : A -> R) (l : list A):
0 <= list_sum (map (fun x => (f x)²) l).
Proof.
apply list_sum_pos_pos'.
rewrite List.Forall_forall; intros.
rewrite List.in_map_iff in H *; intros.
destruct H as [a [Ha HIna]].
unfold comp in Ha; subst.
apply Rle_0_sqr.
Qed.
Lemma total_variance_eq_sum {A : Type} (lp : list (Pmf A)) (lf : list (A -> R)) :
total_variance lp lf = list_sum (map (fun '(f,p) => expt_value p (comp Rsqr f)) (zip lf lp))
- list_sum (map (fun '(f,p) => (expt_value p f)²) (zip lf lp)).
Proof.
rewrite <-list_sum_map_sub.
unfold total_variance.
apply list_sum_map_ext; intros.
destruct x. apply variance_eq.
Qed.
Lemma total_variance_le_expt_sqr {A : Type} (lp : list (Pmf A)) (lf : list (A -> R)) :
total_variance lp lf <= list_sum (map (fun '(f,p) => expt_value p (comp Rsqr f)) (zip lf lp)).
Proof.
rewrite total_variance_eq_sum.
rewrite Rle_minus_l.
rewrite <-(Rplus_0_r) at 1.
apply Rplus_le_compat_l.
apply list_sum_pos_pos'.
rewrite List.Forall_forall; intros.
rewrite List.in_map_iff in H *; intros.
destruct H as [a [Ha HIna]].
unfold comp in Ha; subst.
destruct a; apply Rle_0_sqr.
Qed.
End variance.
|
[STATEMENT]
lemma admissible_leI:
assumes f: "mcont luba orda Sup (\<le>) (\<lambda>x. f x)"
and g: "mcont luba orda Sup (\<le>) (\<lambda>x. g x)"
shows "ccpo.admissible luba orda (\<lambda>x. f x \<le> g x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ccpo.admissible luba orda (\<lambda>x. f x \<le> g x)
[PROOF STEP]
proof(rule ccpo.admissibleI)
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
fix A
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
assume chain: "Complete_Partial_Order.chain orda A"
and le: "\<forall>x\<in>A. f x \<le> g x"
and False: "A \<noteq> {}"
[PROOF STATE]
proof (state)
this:
Complete_Partial_Order.chain orda A
\<forall>x\<in>A. f x \<le> g x
A \<noteq> {}
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
have "f (luba A) = \<Squnion>(f ` A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. f (luba A) = \<Squnion> (f ` A)
[PROOF STEP]
by(simp add: mcont_contD[OF f] chain False)
[PROOF STATE]
proof (state)
this:
f (luba A) = \<Squnion> (f ` A)
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
f (luba A) = \<Squnion> (f ` A)
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
have "\<dots> \<le> \<Squnion>(g ` A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Squnion> (f ` A) \<le> \<Squnion> (g ` A)
[PROOF STEP]
proof(rule ccpo_Sup_least)
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. Complete_Partial_Order.chain (\<le>) (f ` A)
2. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
from chain
[PROOF STATE]
proof (chain)
picking this:
Complete_Partial_Order.chain orda A
[PROOF STEP]
show "Complete_Partial_Order.chain (\<le>) (f ` A)"
[PROOF STATE]
proof (prove)
using this:
Complete_Partial_Order.chain orda A
goal (1 subgoal):
1. Complete_Partial_Order.chain (\<le>) (f ` A)
[PROOF STEP]
by(rule chain_imageI)(rule mcont_monoD[OF f])
[PROOF STATE]
proof (state)
this:
Complete_Partial_Order.chain (\<le>) (f ` A)
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
fix x
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
assume "x \<in> f ` A"
[PROOF STATE]
proof (state)
this:
x \<in> f ` A
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x \<in> f ` A
[PROOF STEP]
obtain y where "y \<in> A" "x = f y"
[PROOF STATE]
proof (prove)
using this:
x \<in> f ` A
goal (1 subgoal):
1. (\<And>y. \<lbrakk>y \<in> A; x = f y\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
y \<in> A
x = f y
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
note this(2)
[PROOF STATE]
proof (state)
this:
x = f y
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
x = f y
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
have "f y \<le> g y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. f y \<le> g y
[PROOF STEP]
using le \<open>y \<in> A\<close>
[PROOF STATE]
proof (prove)
using this:
\<forall>x\<in>A. f x \<le> g x
y \<in> A
goal (1 subgoal):
1. f y \<le> g y
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
f y \<le> g y
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
f y \<le> g y
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
have "Complete_Partial_Order.chain (\<le>) (g ` A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. Complete_Partial_Order.chain (\<le>) (g ` A)
[PROOF STEP]
using chain
[PROOF STATE]
proof (prove)
using this:
Complete_Partial_Order.chain orda A
goal (1 subgoal):
1. Complete_Partial_Order.chain (\<le>) (g ` A)
[PROOF STEP]
by(rule chain_imageI)(rule mcont_monoD[OF g])
[PROOF STATE]
proof (state)
this:
Complete_Partial_Order.chain (\<le>) (g ` A)
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
hence "g y \<le> \<Squnion>(g ` A)"
[PROOF STATE]
proof (prove)
using this:
Complete_Partial_Order.chain (\<le>) (g ` A)
goal (1 subgoal):
1. g y \<le> \<Squnion> (g ` A)
[PROOF STEP]
by(rule ccpo_Sup_upper)(simp add: \<open>y \<in> A\<close>)
[PROOF STATE]
proof (state)
this:
g y \<le> \<Squnion> (g ` A)
goal (1 subgoal):
1. \<And>x. x \<in> f ` A \<Longrightarrow> x \<le> \<Squnion> (g ` A)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
x \<le> \<Squnion> (g ` A)
[PROOF STEP]
show "x \<le> \<dots>"
[PROOF STATE]
proof (prove)
using this:
x \<le> \<Squnion> (g ` A)
goal (1 subgoal):
1. x \<le> \<Squnion> (g ` A)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
x \<le> \<Squnion> (g ` A)
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Squnion> (f ` A) \<le> \<Squnion> (g ` A)
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
\<Squnion> (f ` A) \<le> \<Squnion> (g ` A)
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
have "\<dots> = g (luba A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Squnion> (g ` A) = g (luba A)
[PROOF STEP]
by(simp add: mcont_contD[OF g] chain False)
[PROOF STATE]
proof (state)
this:
\<Squnion> (g ` A) = g (luba A)
goal (1 subgoal):
1. \<And>A. \<lbrakk>Complete_Partial_Order.chain orda A; A \<noteq> {}; \<forall>x\<in>A. f x \<le> g x\<rbrakk> \<Longrightarrow> f (luba A) \<le> g (luba A)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
f (luba A) \<le> g (luba A)
[PROOF STEP]
show "f (luba A) \<le> g (luba A)"
[PROOF STATE]
proof (prove)
using this:
f (luba A) \<le> g (luba A)
goal (1 subgoal):
1. f (luba A) \<le> g (luba A)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
f (luba A) \<le> g (luba A)
goal:
No subgoals!
[PROOF STEP]
qed |
(**
<<
This file contains parition function of quicksort as an exampl
that tries to use [fold_left_right_tup] from [FoldLib].
[1] Bird, Richard. Introduction to Functional Programming using
Haskell (2nd ed.). Prentice Hall. Harlow, England.
1998.
>>
*)
Require Import Recdef.
Require Import homo.MyLib.
(** ** Partitioning
*)
(** *** [partition_lt]
We use [partition] from the List library of Coq to
defined [partition_lt].
*)
Functional Scheme partition_ind := Induction for partition Sort Prop.
Definition f_part (p: nat) := fun x => Nat.ltb x p.
Definition partition_lt (p: nat) (l: list nat) := partition (f_part p) l.
Functional Scheme partition_lt_ind := Induction for partition_lt Sort Prop.
(** *** [partition_wont_expand]
*)
Lemma partition_wont_expand:
forall l p m_lt m_ge,
(m_lt, m_ge) = partition_lt p l ->
length m_lt <= length l /\ length m_ge <= length l.
Proof.
intros l p.
functional induction (partition (f_part p) l); intros * P.
- injection P; intros; subst; auto.
- unfold partition_lt in P.
simpl in P.
rewrite e0 in P.
rewrite e1 in P.
injection P; intros; subst.
simpl.
symmetry in e0.
apply IHp0 in e0.
intuition.
- unfold partition_lt in P.
simpl in P.
rewrite e0 in P.
rewrite e1 in P.
injection P; intros; subst.
simpl.
symmetry in e0.
apply IHp0 in e0.
intuition.
Qed.
(** *** [partition_lt_idempotent]
*)
Lemma partition_lt_idempotent:
forall l p m_lt m_ge,
(m_lt, m_ge) = partition_lt p l ->
(m_lt, []) = partition_lt p m_lt.
Proof.
intros l p.
functional induction (partition (f_part p) l); intros * P.
- injection P; intros;
now subst m_lt m_ge.
- unfold partition_lt in P.
simpl in P.
rewrite e0 in P.
rewrite e1 in P.
symmetry in e0.
apply IHp0 in e0.
injection P; intros;
subst m_lt m_ge.
simpl.
rewrite <- e0.
rewrite e1.
reflexivity.
-
simpl in P.
unfold partition_lt in P.
rewrite e0 in P.
rewrite e1 in P.
injection P; intros;
subst m_lt m_ge.
symmetry in e0.
apply IHp0 in e0.
apply e0.
Qed.
(** *** [partition__lt]
*)
Lemma partition__lt:
forall l p m_lt m_ge k,
(m_lt, m_ge) = partition_lt p l ->
In k m_lt ->
k < p.
Proof.
induction l as [| y ys] ; intros * P IN.
- inversion P; subst.
apply in_nil in IN; inversion IN.
- unfold partition_lt in P.
simpl in P.
name_term tpl (partition (f_part p) ys) Py.
destruct tpl as [lo hi].
rewrite <- Py in P.
unfold f_part in P.
remember (Nat.ltb y p) as r.
destruct r.
+
injection P; intros T1 T2.
inversion T1; clear T1.
subst.
symmetry in Heqr.
apply Nat.ltb_lt in Heqr.
destruct IN.
* now subst k.
* apply IHys with (m_lt:=lo) (m_ge:=hi); auto.
+ injection P; intros;
subst lo.
apply IHys with (m_lt:=m_lt) (m_ge:=hi); auto.
Qed.
Lemma partition__le:
forall l p m_lt m_ge k,
(m_lt, m_ge) = partition_lt p l ->
In k m_ge ->
p <= k.
Proof.
induction l as [| y ys] ; intros * P IN.
- inversion P; subst.
apply in_nil in IN; inversion IN.
- unfold partition_lt in P.
simpl in P.
name_term tpl (partition (f_part p) ys) Py.
destruct tpl as [lo hi].
rewrite <- Py in P.
unfold f_part in P.
remember (Nat.ltb y p) as r.
destruct r.
+ injection P; intros T1 T2.
subst hi; apply IHys with (k:=k) in Py; auto.
+ symmetry in Heqr.
apply Nat.ltb_ge in Heqr.
injection P; intros T1 T2.
subst.
destruct IN.
* now subst k.
* apply IHys with (m_lt:=lo) (m_ge:=hi); auto.
Qed.
Require Import Sorting.Sorted Sorting.Permutation.
Definition join_parted (p:nat) (m_lt m_ge: list nat) :=
m_lt ++ [p] ++ m_ge.
Lemma partition_join_parted_permute:
forall m p m_lt m_ge,
(m_lt, m_ge) = partition_lt p m ->
Permutation (p::m) (m_lt++[p]++m_ge).
Proof.
intros * P.
apply Permutation_cons_app.
revert P.
revert m_ge m_lt p.
induction m as [| x xs]; intros * P.
- simpl in P.
injection P; intros;
subst.
apply perm_nil.
- simpl in P.
unfold partition_lt in P.
name_term tpl (partition (f_part p) xs) Tpl.
rewrite <- Tpl in P.
unfold f_part in P.
destruct tpl as [lo hi].
remember (Nat.ltb x p) as r.
destruct r; injection P; intros;
subst m_lt m_ge.
+ apply IHxs in Tpl.
simpl.
apply perm_skip.
apply Tpl.
+ apply Permutation_cons_app.
apply IHxs in Tpl; auto.
Qed.
Definition partition_one (l: list nat) (p: nat) :=
(fix f (l: list nat) (z: list nat * list nat) :=
match l with
| [] => z
| x::xs => match z with
| (lo, hi) => if Nat.ltb x p
then f xs (lo ++ [x], hi)
else f xs (lo, hi ++ [x])
end
end)
l ([],[]).
Lemma f_fact_7:
forall {S1 S2 A B C D E F: Type}
(f: S1 -> S2 -> A -> B -> C -> D -> E -> F)
(bb:bool) s1 s2 f1 f2 f4 f5 pp1 pp2,
f s1 s2 f1 f2
(if bb then pp1 else pp2)
f4 f5
=
if bb then
f s1 s2 f1 f2 pp1 f4 f5
else
f s1 s2 f1 f2 pp2 f4 f5
.
Proof.
intros.
now destruct bb.
Qed.
(** ** Quicksort
*)
(** *** [qsort]
*)
Function qsort (m: list nat) {measure length m}:=
match m with
| [] => []
| x::xs => let (m_lt, m_ge) := partition_lt x xs in
(qsort m_lt) ++ [x] ++ (qsort m_ge)
end.
Proof.
-
intros * M * P.
symmetry in P.
apply partition_wont_expand in P.
simpl.
intuition.
- intros * M * P.
symmetry in P.
apply partition_wont_expand in P.
simpl.
intuition.
Qed.
|
SARAJEVO, Bosnia-Herzegovina (AP) — The U.S. Embassy and Bosnian journalists have expressed outrage after unknown assailants attacked and seriously hurt a reporter of an independent Bosnian Serb television station.
BNTV reporter Vladimir Kovacevic has been hospitalized following the attack by two assailants late Sunday outside his home in Banja Luka, the main town in the Serb-run part of Bosnia.
Kovacevic posted a photo on Twitter showing his bloodied and bandaged head. He has said that the men attacked him with metal bars as he was coming home after reporting from an anti-government rally.
BNTV has faced criticism from the Bosnian Serb authorities for its independent editorial policies.
The U.S. Embassy tweeted Monday that the attacks on journalists are "unacceptable." The Bosnian journalists' association says the attack is aimed at intimidating independent media. |
(* Title: HOL/Proofs/Lambda/ListBeta.thy
Author: Tobias Nipkow
Copyright 1998 TU Muenchen
*)
section \<open>Lifting beta-reduction to lists\<close>
theory ListBeta imports ListApplication ListOrder begin
text \<open>
Lifting beta-reduction to lists of terms, reducing exactly one element.
\<close>
abbreviation
list_beta :: "dB list => dB list => bool" (infixl "=>" 50) where
"rs => ss == step1 beta rs ss"
lemma head_Var_reduction:
"Var n \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> v \<Longrightarrow> \<exists>ss. rs => ss \<and> v = Var n \<degree>\<degree> ss"
apply (induct u == "Var n \<degree>\<degree> rs" v arbitrary: rs set: beta)
apply simp
apply (rule_tac xs = rs in rev_exhaust)
apply simp
apply (atomize, force intro: append_step1I)
apply (rule_tac xs = rs in rev_exhaust)
apply simp
apply (auto 0 3 intro: disjI2 [THEN append_step1I])
done
lemma apps_betasE [elim!]:
assumes major: "r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> s"
and cases: "!!r'. [| r \<rightarrow>\<^sub>\<beta> r'; s = r' \<degree>\<degree> rs |] ==> R"
"!!rs'. [| rs => rs'; s = r \<degree>\<degree> rs' |] ==> R"
"!!t u us. [| r = Abs t; rs = u # us; s = t[u/0] \<degree>\<degree> us |] ==> R"
shows R
proof -
from major have
"(\<exists>r'. r \<rightarrow>\<^sub>\<beta> r' \<and> s = r' \<degree>\<degree> rs) \<or>
(\<exists>rs'. rs => rs' \<and> s = r \<degree>\<degree> rs') \<or>
(\<exists>t u us. r = Abs t \<and> rs = u # us \<and> s = t[u/0] \<degree>\<degree> us)"
apply (induct u == "r \<degree>\<degree> rs" s arbitrary: r rs set: beta)
apply (case_tac r)
apply simp
apply (simp add: App_eq_foldl_conv)
apply (split if_split_asm)
apply simp
apply blast
apply simp
apply (simp add: App_eq_foldl_conv)
apply (split if_split_asm)
apply simp
apply simp
apply (drule App_eq_foldl_conv [THEN iffD1])
apply (split if_split_asm)
apply simp
apply blast
apply (force intro!: disjI1 [THEN append_step1I])
apply (drule App_eq_foldl_conv [THEN iffD1])
apply (split if_split_asm)
apply simp
apply blast
apply (clarify, auto 0 3 intro!: exI intro: append_step1I)
done
with cases show ?thesis by blast
qed
lemma apps_preserves_beta [simp]:
"r \<rightarrow>\<^sub>\<beta> s ==> r \<degree>\<degree> ss \<rightarrow>\<^sub>\<beta> s \<degree>\<degree> ss"
by (induct ss rule: rev_induct) auto
lemma apps_preserves_beta2 [simp]:
"r \<rightarrow>\<^sub>\<beta>\<^sup>* s ==> r \<degree>\<degree> ss \<rightarrow>\<^sub>\<beta>\<^sup>* s \<degree>\<degree> ss"
apply (induct set: rtranclp)
apply blast
apply (blast intro: apps_preserves_beta rtranclp.rtrancl_into_rtrancl)
done
lemma apps_preserves_betas [simp]:
"rs => ss \<Longrightarrow> r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> r \<degree>\<degree> ss"
apply (induct rs arbitrary: ss rule: rev_induct)
apply simp
apply simp
apply (rule_tac xs = ss in rev_exhaust)
apply simp
apply simp
apply (drule Snoc_step1_SnocD)
apply blast
done
end
|
(** * 6.822 Formal Reasoning About Programs, Spring 2018 - Pset 9 *)
Require Import Frap Pset9Sig.
Set Implicit Arguments.
Theorem logical_rel_fundamental:
forall abst1 abst2 (value_rel_abs: exp -> exp -> Prop),
(forall v1 v2, value_rel_abs v1 v2 -> value v1 /\ value v2) ->
abst1 <> AbsT ->
abst2 <> AbsT ->
forall e G t,
hasty None G e t ->
logical_rel abst1 abst2 value_rel_abs G e e t.
Proof.
Admitted.
Theorem counter_impls_equiv:
forall x e,
hasty None ($0 $+ (x, counter_type)) e Nat ->
exists n : nat,
eval (subst counter_impl1 x e) n /\ eval (subst counter_impl2 x e) n.
Proof.
Admitted.
|
{-# OPTIONS --without-K --exact-split --rewriting #-}
open import Coequalizers.Definition
open import lib.Basics
open import lib.types.Paths
open import Graphs.Definition
module Coequalizers.EdgeCoproduct where
module CoeqCoprodEquiv {i j k : ULevel} (V : Type i) (E₁ : Type j) (E₂ : Type k) ⦃ gph : Graph (E₁ ⊔ E₂) V ⦄ where
instance
gph1 : Graph E₁ V
gph1 = record { π₀ = (Graph.π₀ gph) ∘ inl ; π₁ = (Graph.π₁ gph) ∘ inl }
instance
gph2 : Graph E₂ (V / E₁)
gph2 = record { π₀ = c[_] ∘ (Graph.π₀ gph) ∘ inr ; π₁ = c[_] ∘ (Graph.π₁ gph) ∘ inr }
edge-coproduct-expand : (V / (E₁ ⊔ E₂)) ≃ ((V / E₁) / E₂)
edge-coproduct-expand = equiv f g f-g g-f
where
f : V / (E₁ ⊔ E₂) → (V / E₁) / E₂
f = Coeq-rec (c[_] ∘ c[_]) λ { (inl x) → ap c[_] (quot x) ; (inr x) → quot x}
g : (V / E₁) / E₂ → V / (E₁ ⊔ E₂)
g = Coeq-rec (Coeq-rec c[_] (λ e → quot (inl e))) (λ e → quot (inr e))
f-g : (x : (V / E₁) / E₂) → (f (g x) == x)
f-g = Coeq-elim (λ x' → f (g x') == x') (Coeq-elim (λ x' → f (g (c[ x' ])) == c[ x' ]) (λ v → idp) (λ e → ↓-='-in (lemma1 e))) λ e → ↓-app=idf-in $
idp ∙' quot e
=⟨ ∙'-unit-l _ ⟩
quot e
=⟨ ! (Coeq-rec-β= _ _ _) ⟩
ap f (quot (inr e))
=⟨ ap (ap f) (! (Coeq-rec-β= _ _ _)) ⟩
ap f (ap g (quot e))
=⟨ ! (ap-∘ f g (quot e)) ⟩
ap (f ∘ g) (quot e)
=⟨ ! (∙-unit-r _) ⟩
ap (f ∘ g) (quot e) ∙ idp
=∎
where
lemma1 : (e : E₁) → idp ∙' ap (λ z → c[ z ]) (quot e) ==
ap (λ z → f (g c[ z ])) (quot e) ∙ idp
lemma1 e =
idp ∙' ap c[_] (quot e)
=⟨ ∙'-unit-l _ ⟩
ap c[_] (quot e)
=⟨ ! (Coeq-rec-β= _ _ _) ⟩
ap f (quot (inl e))
=⟨ ap (ap f) (! (Coeq-rec-β= _ _ _)) ⟩
ap f (ap (Coeq-rec c[_] (λ e → quot (inl e))) (quot e))
=⟨ idp ⟩
ap f (ap (g ∘ c[_]) (quot e))
=⟨ ! (ap-∘ f (g ∘ c[_]) (quot e)) ⟩
ap (f ∘ g ∘ c[_]) (quot e)
=⟨ ! (∙-unit-r _) ⟩
ap (f ∘ g ∘ c[_]) (quot e) ∙ idp
=∎
g-f : (x : V / (E₁ ⊔ E₂)) → (g (f x) == x)
g-f = Coeq-elim (λ x → g (f x) == x) (λ v → idp) (λ { (inl e) → ↓-app=idf-in (! (lemma1 e)) ; (inr e) → ↓-app=idf-in (! (lemma2 e))})
where
lemma1 : (e : E₁) → ap (λ z → g (f z)) (quot (inl e)) ∙ idp == idp ∙' quot (inl e)
lemma1 e =
ap (g ∘ f) (quot (inl e)) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap (g ∘ f) (quot (inl e))
=⟨ ap-∘ g f (quot (inl e)) ⟩
ap g (ap f (quot (inl e)))
=⟨ ap (ap g) (Coeq-rec-β= _ _ _) ⟩
ap g (ap c[_] (quot e))
=⟨ ! (ap-∘ g c[_] (quot e)) ⟩
ap (g ∘ c[_]) (quot e)
=⟨ idp ⟩
ap (Coeq-rec c[_] (λ e' → quot (inl e'))) (quot e)
=⟨ Coeq-rec-β= _ _ _ ⟩
quot (inl e)
=⟨ ! (∙'-unit-l _) ⟩
idp ∙' quot (inl e)
=∎
lemma2 : (e : E₂) → ap (λ z → g (f z)) (quot (inr e)) ∙ idp == idp ∙' quot (inr e)
lemma2 e =
ap (g ∘ f) (quot (inr e)) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap (g ∘ f) (quot (inr e))
=⟨ ap-∘ g f (quot (inr e)) ⟩
ap g (ap f (quot (inr e)))
=⟨ ap (ap g) (Coeq-rec-β= _ _ _) ⟩
ap g (quot e)
=⟨ Coeq-rec-β= _ _ _ ⟩
quot (inr e)
=⟨ ! (∙'-unit-l _) ⟩
idp ∙' quot (inr e)
=∎
|
[STATEMENT]
lemma mem_correct_default:
"mem_correct
(\<lambda> k. do {m \<leftarrow> State_Monad.get; State_Monad.return (m k)})
(\<lambda> k v. do {m \<leftarrow> State_Monad.get; State_Monad.set (m(k\<mapsto>v))})
(\<lambda> _. True)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. mem_correct (\<lambda>k. State_Monad.get \<bind> (\<lambda>m. State_Monad.return (m k))) (\<lambda>k v. State_Monad.get \<bind> (\<lambda>m. State_Monad.set (m(k \<mapsto> v)))) (\<lambda>_. True)
[PROOF STEP]
by standard
(auto simp: map_le_def state_mem_defs.map_of_def State_Monad.bind_def State_Monad.get_def State_Monad.return_def State_Monad.set_def lift_p_def) |
For a 1913 revival at the same theatre the young actors Gerald Ames and A. E. Matthews succeeded the creators as Jack and Algy . John <unk> as Jack and Margaret Scudamore as Lady Bracknell headed the cast in a 1923 production at the Haymarket Theatre . Many revivals in the first decades of the 20th century treated " the present " as the current year . It was not until the 1920s that the case for 1890s costumes was established ; as a critic in The Manchester Guardian put it , " Thirty years on , one begins to feel that Wilde should be done in the costume of his period — that his wit today needs the backing of the atmosphere that gave it life and truth . … Wilde 's glittering and complex verbal felicities go ill with the shingle and the short skirt . "
|
#############################################################################
####
##
#A anusp.gi ANUPQ package Eamonn O'Brien
#A Alice Niemeyer
##
#Y Copyright 1993-2001, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany
#Y Copyright 1993-2001, School of Mathematical Sciences, ANU, Australia
##
#############################################################################
##
#F ANUPQSPerror( <param> ) . . . . . . . . . . . . report illegal parameter
##
InstallGlobalFunction( ANUPQSPerror, function( param )
Error(
"Valid Options:\n",
" \"ClassBound\", <bound>\n",
" \"PcgsAutomorphisms\"\n",
" \"Exponent\", <exponent>\n",
" \"Metabelian\"\n",
" \"OutputLevel\", <level>\n",
" \"SetupFile\", <file>\n",
"Illegal Parameter: \"", param, "\"" );
end );
#############################################################################
##
#F ANUPQSPextractArgs( <args> ) . . . . . . . . . . . . parse argument list
##
InstallGlobalFunction( ANUPQSPextractArgs, function( args )
local CR, i, act, G, match;
# allow to give only a prefix
match := function( g, w )
return 1 < Length(g) and
Length(g) <= Length(w) and
w{[1..Length(g)]} = g;
end;
# extract arguments
G := args[2];
CR := rec( group := G );
i := 3;
while i <= Length(args) do
act := args[i];
# "ClassBound", <class>
if match( act, "ClassBound" ) then
i := i + 1;
CR.ClassBound := args[i];
if CR.ClassBound <= PClassPGroup(G) then
Error( "\"ClassBound\" must be at least ", PClassPGroup(G)+1 );
fi;
# "PcgsAutomorphisms"
elif match( act, "PcgsAutomorphisms" ) then
CR.PcgsAutomorphisms := true;
#this may be available later
# "SpaceEfficient"
#elif match( act, "SpaceEfficient" ) then
# CR.SpaceEfficient := true;
# "Exponent", <exp>
elif match( act, "Exponent" ) then
i := i + 1;
CR.Exponent := args[i];
# "Metabelian"
elif match( act, "Metabelian" ) then
CR.Metabelian := true;
# "Verbose"
elif match( act, "Verbose" ) then
CR.Verbose := true;
# "SetupFile", <file>
elif match( act, "SetupFile" ) then
i := i + 1;
CR.SetupFile := args[i];
# "TmpDir", <dir>
elif match( act, "TmpDir" ) then
i := i + 1;
CR.TmpDir := args[i];
# "Output", <level>
elif match( act, "OutputLevel" ) then
i := i + 1;
CR.OutputLevel := args[i];
CR.Verbose := true;
# signal an error
else
ANUPQSPerror(act);
fi;
i := i + 1;
od;
return CR;
end );
#############################################################################
##
#F PqFpGroupPcGroup( <G> ) . . . . . . corresponding fp group of a pc group
##
InstallGlobalFunction( PqFpGroupPcGroup,
G -> Image( IsomorphismFpGroup( G ) )
);
#############################################################################
##
#M FpGroupPcGroup( <G> ) . . . . . . . corresponding fp group of a pc group
##
InstallMethod( FpGroupPcGroup, "pc group", [IsPcGroup], 0, PqFpGroupPcGroup );
#############################################################################
##
#F PQ_EPIMORPHISM_STANDARD_PRESENTATION( <args> ) . (epi. onto) SP for group
##
InstallGlobalFunction( PQ_EPIMORPHISM_STANDARD_PRESENTATION,
function( args )
local datarec, rank, Q, Qclass, automorphisms, generators, x,
images, i, r, j, aut, result, desc, k;
datarec := ANUPQ_ARG_CHK("StandardPresentation", args);
if datarec.calltype = "interactive" and IsBound(datarec.SPepi) then
# Note: the `pq' binary seg-faults if called twice to
# calculate the standard presentation of a group
return datarec.SPepi;
fi;
if VALUE_PQ_OPTION("pQuotient") = fail and
VALUE_PQ_OPTION("Prime", datarec) <> fail then
# Ensure a saved value of `Prime' has precedence
# over a saved value of `pQuotient'.
Unbind(datarec.pQuotient);
fi;
if VALUE_PQ_OPTION("pQuotient", datarec) <> fail then
PQ_AUT_GROUP( datarec.pQuotient );
datarec.Prime := PrimePGroup( datarec.pQuotient );
elif VALUE_PQ_OPTION("Prime", datarec) <> fail then
rank := Number( List( AbelianInvariants(datarec.group),
x -> Gcd(x, datarec.Prime) ),
y -> y = datarec.Prime );
# construct free group with <rank> generators
Q := FreeGroup( IsSyllableWordsFamily, rank, "q" );
# construct power-relation
Q := Q / List( GeneratorsOfGroup(Q), x -> x^datarec.Prime );
# construct pc group
Q := PcGroupFpGroup(Q);
# construct automorphism
automorphisms := [];
generators := GeneratorsOfGroup(Q);
for x in GeneratorsOfGroup( GL(rank, datarec.Prime) ) do
images := [];
for i in [ 1 .. rank ] do
r := One(Q);
for j in [ 1 .. rank ] do
r := r * generators[j]^Int(x[i][j]);
od;
images[i] := r;
od;
aut := GroupHomomorphismByImages( Q, Q, generators, images );
SetIsBijective( aut, true );
Add( automorphisms, aut );
od;
SetAutomorphismGroup( Q, GroupByGenerators( automorphisms ) );
datarec.pQuotient := Q;
fi;
#PushOptions(rec(nonuser := true));
Qclass := PClassPGroup( datarec.pQuotient );
if VALUE_PQ_OPTION("ClassBound", 63) <= Qclass then
Error( "option `ClassBound' must be greater than `pQuotient' class (",
Qclass, ")\n" );
fi;
PQ_PC_PRESENTATION(datarec, "SP" : ClassBound := Qclass);
PQ_SP_STANDARD_PRESENTATION(datarec);
PQ_SP_ISOMORPHISM(datarec);
if datarec.calltype = "non-interactive" then
PQ_COMPLETE_NONINTERACTIVE_FUNC_CALL(datarec);
if IsBound( datarec.setupfile ) then
#PopOptions();
return true;
fi;
fi;
# try to read output
result := ANUPQReadOutput( ANUPQData.SPimages );
if not IsBound(result.ANUPQmagic) then
Error("something wrong with `pq' binary. Please check installation\n");
fi;
desc := rec();
result.ANUPQgroups[Length(result.ANUPQgroups)](desc);
# if result.ANUPQautos <> fail and
# Length( result.ANUPQautos ) = Length( result.ANUPQgroups ) then
# result.ANUPQautos[ Length(result.ANUPQgroups) ]( desc.group );
# fi;
# revise images to correspond to images of user-supplied generators
datarec.SP := desc.group;
x := Length( desc.map );
k := Length( GeneratorsOfGroup( datarec.group ) );
# images of user supplied generators are last k entries in .pqImages
datarec.SPepi := GroupHomomorphismByImagesNC(
datarec.group,
datarec.SP,
GeneratorsOfGroup(datarec.group),
desc.map{[x - k + 1..x]} );
#PopOptions();
return datarec.SPepi;
end );
#############################################################################
##
#F EpimorphismPqStandardPresentation( <arg> ) . . . epi. onto SP for p-group
##
InstallGlobalFunction( EpimorphismPqStandardPresentation, function( arg )
return PQ_EPIMORPHISM_STANDARD_PRESENTATION( arg );
end );
#############################################################################
##
#F PqStandardPresentation( <arg> : <options> ) . . . . . . . SP for p-group
##
InstallGlobalFunction( PqStandardPresentation, function( arg )
local SPepi;
SPepi := PQ_EPIMORPHISM_STANDARD_PRESENTATION( arg );
if SPepi = true then
return true; # the SetupFile case
fi;
return Range( SPepi );
end );
#############################################################################
##
#M EpimorphismStandardPresentation( <F> ) . . . . . epi. onto SP for p-group
#M EpimorphismStandardPresentation( [<i>] )
##
InstallMethod( EpimorphismStandardPresentation,
"fp group", [IsFpGroup], 0,
EpimorphismPqStandardPresentation );
InstallMethod( EpimorphismStandardPresentation,
"pc group", [IsPcGroup], 0,
EpimorphismPqStandardPresentation );
InstallMethod( EpimorphismStandardPresentation,
"positive integer", [IsPosInt], 0,
EpimorphismPqStandardPresentation );
InstallOtherMethod( EpimorphismStandardPresentation,
"", [], 0,
EpimorphismPqStandardPresentation );
#############################################################################
##
#M StandardPresentation( <F> ) . . . . . . . . . . . . . . . SP for p-group
#M StandardPresentation( [<i>] )
##
InstallMethod( StandardPresentation,
"fp group", [IsFpGroup], 0,
PqStandardPresentation );
InstallMethod( StandardPresentation,
"pc group", [IsPcGroup], 0,
PqStandardPresentation );
InstallMethod( StandardPresentation,
"positive integer", [IsPosInt], 0,
PqStandardPresentation );
InstallOtherMethod( StandardPresentation,
"", [], 0,
PqStandardPresentation );
#############################################################################
##
#F IsPqIsomorphicPGroup( <G>, <H> ) . . . . . . . . . . . isomorphism test
##
InstallGlobalFunction( IsPqIsomorphicPGroup, function( G, H )
local p, class, SG, SH, Ggens, Hgens;
# <G> and <H> must both be pc groups and p-groups
if not IsPcGroup(G) then
Error( "<G> must be a pc group" );
fi;
if not IsPcGroup(H) then
Error( "<H> must be a pc group" );
fi;
if Size(G) <> Size(H) then
return false;
fi;
p := SmallestRootInt(Size(G));
if not IsPrimeInt(p) then
Error( "<G> must be a p-group" );
fi;
# check the Frattini factor
if RankPGroup(G) <> RankPGroup(H) then
return false;
fi;
# check the exponent-p length and the sizes of the groups in the
# p-central series of both groups
if List(PCentralSeries(G,p), Size) <> List(PCentralSeries(H,p), Size) then
return false;
fi;
# if the groups are elementary abelian they are isomorphic
class := PClassPGroup(G);
if class = 1 then
return true;
fi;
# compute a standard presentation for both
SG := PqStandardPresentation(PqFpGroupPcGroup(G)
: Prime := p, ClassBound := class);
SH := PqStandardPresentation(PqFpGroupPcGroup(H)
: Prime := p, ClassBound := class);
# the groups are equal if the presentation are equal
Ggens := GeneratorsOfGroup( FreeGroupOfFpGroup( SG ) );
Hgens := GeneratorsOfGroup( FreeGroupOfFpGroup( SH ) );
return RelatorsOfFpGroup(SG)
= List( RelatorsOfFpGroup(SH),
x -> MappedWord( x, Hgens, Ggens ) );
end );
#############################################################################
##
#M IsIsomorphicPGroup( <F>, <G> )
##
InstallMethod( IsIsomorphicPGroup, "pc group, pc group",
[IsPcGroup, IsPcGroup], 0,
IsPqIsomorphicPGroup );
#E anusp.gi . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
|
#include <stdlib.h>
#include <gsl/block/gsl_block.h>
#define BASE_DOUBLE
#include <gsl/templates_on.h>
#include <gsl/block/init_source.c>
#include <gsl/templates_off.h>
#undef BASE_DOUBLE |
/-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
! This file was ported from Lean 3 source module probability.kernel.composition
! leanprover-community/mathlib commit 97d1aa955750bd57a7eeef91de310e633881670b
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Probability.Kernel.Basic
/-!
# Product and composition of kernels
We define
* the composition-product `κ ⊗ₖ η` of two s-finite kernels `κ : kernel α β` and
`η : kernel (α × β) γ`, a kernel from `α` to `β × γ`.
* the map and comap of a kernel along a measurable function.
* the composition `η ∘ₖ κ` of s-finite kernels `κ : kernel α β` and `η : kernel β γ`,
a kernel from `α` to `γ`.
* the product `prod κ η` of s-finite kernels `κ : kernel α β` and `η : kernel α γ`,
a kernel from `α` to `β × γ`.
A note on names:
The composition-product `kernel α β → kernel (α × β) γ → kernel α (β × γ)` is named composition in
[kallenberg2021] and product on the wikipedia article on transition kernels.
Most papers studying categories of kernels call composition the map we call composition. We adopt
that convention because it fits better with the use of the name `comp` elsewhere in mathlib.
## Main definitions
Kernels built from other kernels:
* `comp_prod (κ : kernel α β) (η : kernel (α × β) γ) : kernel α (β × γ)`: composition-product of 2
s-finite kernels. We define a notation `κ ⊗ₖ η = comp_prod κ η`.
`∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`
* `map (κ : kernel α β) (f : β → γ) (hf : measurable f) : kernel α γ`
`∫⁻ c, g c ∂(map κ f hf a) = ∫⁻ b, g (f b) ∂(κ a)`
* `comap (κ : kernel α β) (f : γ → α) (hf : measurable f) : kernel γ β`
`∫⁻ b, g b ∂(comap κ f hf c) = ∫⁻ b, g b ∂(κ (f c))`
* `comp (η : kernel β γ) (κ : kernel α β) : kernel α γ`: composition of 2 s-finite kernels.
We define a notation `η ∘ₖ κ = comp η κ`.
`∫⁻ c, g c ∂((η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, g c ∂(η b) ∂(κ a)`
* `prod (κ : kernel α β) (η : kernel α γ) : kernel α (β × γ)`: product of 2 s-finite kernels.
`∫⁻ bc, f bc ∂(prod κ η a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η a) ∂(κ a)`
## Main statements
* `lintegral_comp_prod`, `lintegral_map`, `lintegral_comap`, `lintegral_comp`, `lintegral_prod`:
Lebesgue integral of a function against a composition-product/map/comap/composition/product of
kernels.
* Instances of the form `<class>.<operation>` where class is one of `is_markov_kernel`,
`is_finite_kernel`, `is_s_finite_kernel` and operation is one of `comp_prod`, `map`, `comap`,
`comp`, `prod`. These instances state that the three classes are stable by the various operations.
## Notations
* `κ ⊗ₖ η = probability_theory.kernel.comp_prod κ η`
* `η ∘ₖ κ = probability_theory.kernel.comp η κ`
-/
open MeasureTheory
open ENNReal
namespace ProbabilityTheory
namespace Kernel
variable {α β ι : Type _} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
include mα mβ
section CompositionProduct
/-!
### Composition-Product of kernels
We define a kernel composition-product
`comp_prod : kernel α β → kernel (α × β) γ → kernel α (β × γ)`.
-/
variable {γ : Type _} {mγ : MeasurableSpace γ} {s : Set (β × γ)}
include mγ
/-- Auxiliary function for the definition of the composition-product of two kernels.
For all `a : α`, `comp_prod_fun κ η a` is a countably additive function with value zero on the empty
set, and the composition-product of kernels is defined in `kernel.comp_prod` through
`measure.of_measurable`. -/
noncomputable def compProdFun (κ : kernel α β) (η : kernel (α × β) γ) (a : α) (s : Set (β × γ)) :
ℝ≥0∞ :=
∫⁻ b, η (a, b) { c | (b, c) ∈ s } ∂κ a
#align probability_theory.kernel.comp_prod_fun ProbabilityTheory.kernel.compProdFun
theorem compProdFun_empty (κ : kernel α β) (η : kernel (α × β) γ) (a : α) :
compProdFun κ η a ∅ = 0 := by
simp only [comp_prod_fun, Set.mem_empty_iff_false, Set.setOf_false, measure_empty,
lintegral_const, MulZeroClass.zero_mul]
#align probability_theory.kernel.comp_prod_fun_empty ProbabilityTheory.kernel.compProdFun_empty
theorem compProdFun_unionᵢ (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α)
(f : ℕ → Set (β × γ)) (hf_meas : ∀ i, MeasurableSet (f i))
(hf_disj : Pairwise (Disjoint on f)) :
compProdFun κ η a (⋃ i, f i) = ∑' i, compProdFun κ η a (f i) :=
by
have h_Union :
(fun b => η (a, b) { c : γ | (b, c) ∈ ⋃ i, f i }) = fun b =>
η (a, b) (⋃ i, { c : γ | (b, c) ∈ f i }) :=
by
ext1 b
congr with c
simp only [Set.mem_unionᵢ, Set.supᵢ_eq_unionᵢ, Set.mem_setOf_eq]
rfl
rw [comp_prod_fun, h_Union]
have h_tsum :
(fun b => η (a, b) (⋃ i, { c : γ | (b, c) ∈ f i })) = fun b =>
∑' i, η (a, b) { c : γ | (b, c) ∈ f i } :=
by
ext1 b
rw [measure_Union]
· intro i j hij s hsi hsj c hcs
have hbci : {(b, c)} ⊆ f i := by
rw [Set.singleton_subset_iff]
exact hsi hcs
have hbcj : {(b, c)} ⊆ f j := by
rw [Set.singleton_subset_iff]
exact hsj hcs
simpa only [Set.bot_eq_empty, Set.le_eq_subset, Set.singleton_subset_iff,
Set.mem_empty_iff_false] using hf_disj hij hbci hbcj
· exact fun i => (@measurable_prod_mk_left β γ _ _ b) _ (hf_meas i)
rw [h_tsum, lintegral_tsum]
· rfl
· intro i
have hm : MeasurableSet { p : (α × β) × γ | (p.1.2, p.2) ∈ f i } :=
measurable_fst.snd.prod_mk measurable_snd (hf_meas i)
exact ((measurable_prod_mk_mem η hm).comp measurable_prod_mk_left).AeMeasurable
#align probability_theory.kernel.comp_prod_fun_Union ProbabilityTheory.kernel.compProdFun_unionᵢ
theorem compProdFun_tsum_right (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α)
(hs : MeasurableSet s) : compProdFun κ η a s = ∑' n, compProdFun κ (seq η n) a s :=
by
simp_rw [comp_prod_fun, (measure_sum_seq η _).symm]
have :
(∫⁻ b, measure.sum (fun n => seq η n (a, b)) { c : γ | (b, c) ∈ s } ∂κ a) =
∫⁻ b, ∑' n, seq η n (a, b) { c : γ | (b, c) ∈ s } ∂κ a :=
by
congr
ext1 b
rw [measure.sum_apply]
exact measurable_prod_mk_left hs
rw [this, lintegral_tsum fun n : ℕ => _]
exact
((measurable_prod_mk_mem (seq η n) ((measurable_fst.snd.prod_mk measurable_snd) hs)).comp
measurable_prod_mk_left).AeMeasurable
#align probability_theory.kernel.comp_prod_fun_tsum_right ProbabilityTheory.kernel.compProdFun_tsum_right
theorem compProdFun_tsum_left (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel κ] (a : α)
(s : Set (β × γ)) : compProdFun κ η a s = ∑' n, compProdFun (seq κ n) η a s := by
simp_rw [comp_prod_fun, (measure_sum_seq κ _).symm, lintegral_sum_measure]
#align probability_theory.kernel.comp_prod_fun_tsum_left ProbabilityTheory.kernel.compProdFun_tsum_left
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (n m) -/
theorem compProdFun_eq_tsum (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) :
compProdFun κ η a s = ∑' (n) (m), compProdFun (seq κ n) (seq η m) a s := by
simp_rw [comp_prod_fun_tsum_left κ η a s, comp_prod_fun_tsum_right _ η a hs]
#align probability_theory.kernel.comp_prod_fun_eq_tsum ProbabilityTheory.kernel.compProdFun_eq_tsum
/-- Auxiliary lemma for `measurable_comp_prod_fun`. -/
theorem measurable_compProdFun_of_finite (κ : kernel α β) [IsFiniteKernel κ] (η : kernel (α × β) γ)
[IsFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s :=
by
simp only [comp_prod_fun]
have h_meas : Measurable (Function.uncurry fun a b => η (a, b) { c : γ | (b, c) ∈ s }) :=
by
have :
(Function.uncurry fun a b => η (a, b) { c : γ | (b, c) ∈ s }) = fun p =>
η p { c : γ | (p.2, c) ∈ s } :=
by
ext1 p
have hp_eq_mk : p = (p.fst, p.snd) := prod.mk.eta.symm
rw [hp_eq_mk, Function.uncurry_apply_pair]
rw [this]
exact measurable_prod_mk_mem η (measurable_fst.snd.prod_mk measurable_snd hs)
exact measurable_lintegral κ h_meas
#align probability_theory.kernel.measurable_comp_prod_fun_of_finite ProbabilityTheory.kernel.measurable_compProdFun_of_finite
theorem measurable_compProdFun (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s :=
by
simp_rw [comp_prod_fun_tsum_right κ η _ hs]
refine' Measurable.eNNReal_tsum fun n => _
simp only [comp_prod_fun]
have h_meas : Measurable (Function.uncurry fun a b => seq η n (a, b) { c : γ | (b, c) ∈ s }) :=
by
have :
(Function.uncurry fun a b => seq η n (a, b) { c : γ | (b, c) ∈ s }) = fun p =>
seq η n p { c : γ | (p.2, c) ∈ s } :=
by
ext1 p
have hp_eq_mk : p = (p.fst, p.snd) := prod.mk.eta.symm
rw [hp_eq_mk, Function.uncurry_apply_pair]
rw [this]
exact measurable_prod_mk_mem (seq η n) (measurable_fst.snd.prod_mk measurable_snd hs)
exact measurable_lintegral κ h_meas
#align probability_theory.kernel.measurable_comp_prod_fun ProbabilityTheory.kernel.measurable_compProdFun
/-- Composition-Product of kernels. It verifies
`∫⁻ bc, f bc ∂(comp_prod κ η a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`
(see `lintegral_comp_prod`). -/
noncomputable def compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] : kernel α (β × γ)
where
val a :=
Measure.ofMeasurable (fun s hs => compProdFun κ η a s) (compProdFun_empty κ η a)
(compProdFun_unionᵢ κ η a)
property := by
refine' measure.measurable_of_measurable_coe _ fun s hs => _
have :
(fun a =>
measure.of_measurable (fun s hs => comp_prod_fun κ η a s) (comp_prod_fun_empty κ η a)
(comp_prod_fun_Union κ η a) s) =
fun a => comp_prod_fun κ η a s :=
by
ext1 a
rwa [measure.of_measurable_apply]
rw [this]
exact measurable_comp_prod_fun κ η hs
#align probability_theory.kernel.comp_prod ProbabilityTheory.kernel.compProd
-- mathport name: kernel.comp_prod
scoped[ProbabilityTheory] infixl:100 " ⊗ₖ " => ProbabilityTheory.kernel.compProd
theorem compProd_apply_eq_compProdFun (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = compProdFun κ η a s :=
by
rw [comp_prod]
change
measure.of_measurable (fun s hs => comp_prod_fun κ η a s) (comp_prod_fun_empty κ η a)
(comp_prod_fun_Union κ η a) s =
∫⁻ b, η (a, b) { c | (b, c) ∈ s } ∂κ a
rw [measure.of_measurable_apply _ hs]
rfl
#align probability_theory.kernel.comp_prod_apply_eq_comp_prod_fun ProbabilityTheory.kernel.compProd_apply_eq_compProdFun
theorem compProd_apply (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) :
(κ ⊗ₖ η) a s = ∫⁻ b, η (a, b) { c | (b, c) ∈ s } ∂κ a :=
compProd_apply_eq_compProdFun κ η a hs
#align probability_theory.kernel.comp_prod_apply ProbabilityTheory.kernel.compProd_apply
/-- Lebesgue integral against the composition-product of two kernels. -/
theorem lintegral_comp_prod' (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) {f : β → γ → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) :
(∫⁻ bc, f bc.1 bc.2 ∂(κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f b c ∂η (a, b) ∂κ a :=
by
let F : ℕ → simple_func (β × γ) ℝ≥0∞ := simple_func.eapprox (Function.uncurry f)
have h : ∀ a, (⨆ n, F n a) = Function.uncurry f a :=
simple_func.supr_eapprox_apply (Function.uncurry f) hf
simp only [Prod.forall, Function.uncurry_apply_pair] at h
simp_rw [← h, Prod.mk.eta]
have h_mono : Monotone F := fun i j hij b =>
simple_func.monotone_eapprox (Function.uncurry f) hij _
rw [lintegral_supr (fun n => (F n).Measurable) h_mono]
have : ∀ b, (∫⁻ c, ⨆ n, F n (b, c) ∂η (a, b)) = ⨆ n, ∫⁻ c, F n (b, c) ∂η (a, b) :=
by
intro a
rw [lintegral_supr]
· exact fun n => (F n).Measurable.comp measurable_prod_mk_left
· exact fun i j hij b => h_mono hij _
simp_rw [this]
have h_some_meas_integral :
∀ f' : simple_func (β × γ) ℝ≥0∞, Measurable fun b => ∫⁻ c, f' (b, c) ∂η (a, b) :=
by
intro f'
have :
(fun b => ∫⁻ c, f' (b, c) ∂η (a, b)) =
(fun ab => ∫⁻ c, f' (ab.2, c) ∂η ab) ∘ fun b => (a, b) :=
by
ext1 ab
rfl
rw [this]
refine' Measurable.comp _ measurable_prod_mk_left
exact
measurable_lintegral η
((simple_func.measurable _).comp (measurable_fst.snd.prod_mk measurable_snd))
rw [lintegral_supr]
rotate_left
· exact fun n => h_some_meas_integral (F n)
· exact fun i j hij b => lintegral_mono fun c => h_mono hij _
congr
ext1 n
refine' simple_func.induction _ _ (F n)
· intro c s hs
simp only [simple_func.const_zero, simple_func.coe_piecewise, simple_func.coe_const,
simple_func.coe_zero, Set.piecewise_eq_indicator, lintegral_indicator_const hs]
rw [comp_prod_apply κ η _ hs, ← lintegral_const_mul c _]
swap
·
exact
(measurable_prod_mk_mem η ((measurable_fst.snd.prod_mk measurable_snd) hs)).comp
measurable_prod_mk_left
congr
ext1 b
rw [lintegral_indicator_const_comp measurable_prod_mk_left hs]
rfl
· intro f f' h_disj hf_eq hf'_eq
simp_rw [simple_func.coe_add, Pi.add_apply]
change
(∫⁻ x, (f : β × γ → ℝ≥0∞) x + f' x ∂(κ ⊗ₖ η) a) =
∫⁻ b, ∫⁻ c : γ, f (b, c) + f' (b, c) ∂η (a, b) ∂κ a
rw [lintegral_add_left (simple_func.measurable _), hf_eq, hf'_eq, ← lintegral_add_left]
swap
· exact h_some_meas_integral f
congr with b
rw [← lintegral_add_left ((simple_func.measurable _).comp measurable_prod_mk_left)]
#align probability_theory.kernel.lintegral_comp_prod' ProbabilityTheory.kernel.lintegral_comp_prod'
/-- Lebesgue integral against the composition-product of two kernels. -/
theorem lintegral_compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) :
(∫⁻ bc, f bc ∂(κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂η (a, b) ∂κ a :=
by
let g := Function.curry f
change (∫⁻ bc, f bc ∂(κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, g b c ∂η (a, b) ∂κ a
rw [← lintegral_comp_prod']
· simp_rw [g, Function.curry_apply, Prod.mk.eta]
· simp_rw [g, Function.uncurry_curry]
exact hf
#align probability_theory.kernel.lintegral_comp_prod ProbabilityTheory.kernel.lintegral_compProd
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (n m) -/
theorem compProd_eq_tsum_compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) :
(κ ⊗ₖ η) a s = ∑' (n : ℕ) (m : ℕ), (seq κ n ⊗ₖ seq η m) a s :=
by
simp_rw [comp_prod_apply_eq_comp_prod_fun _ _ _ hs]
exact comp_prod_fun_eq_tsum κ η a hs
#align probability_theory.kernel.comp_prod_eq_tsum_comp_prod ProbabilityTheory.kernel.compProd_eq_tsum_compProd
theorem compProd_eq_sum_compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] : κ ⊗ₖ η = kernel.sum fun n => kernel.sum fun m => seq κ n ⊗ₖ seq η m :=
by
ext (a s hs) : 2
simp_rw [kernel.sum_apply' _ a hs]
rw [comp_prod_eq_tsum_comp_prod κ η a hs]
#align probability_theory.kernel.comp_prod_eq_sum_comp_prod ProbabilityTheory.kernel.compProd_eq_sum_compProd
theorem compProd_eq_sum_compProd_left (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] : κ ⊗ₖ η = kernel.sum fun n => seq κ n ⊗ₖ η :=
by
rw [comp_prod_eq_sum_comp_prod]
congr with (n a s hs)
simp_rw [kernel.sum_apply' _ _ hs, comp_prod_apply_eq_comp_prod_fun _ _ _ hs,
comp_prod_fun_tsum_right _ η a hs]
#align probability_theory.kernel.comp_prod_eq_sum_comp_prod_left ProbabilityTheory.kernel.compProd_eq_sum_compProd_left
theorem compProd_eq_sum_compProd_right (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] : κ ⊗ₖ η = kernel.sum fun n => κ ⊗ₖ seq η n :=
by
rw [comp_prod_eq_sum_comp_prod]
simp_rw [comp_prod_eq_sum_comp_prod_left κ _]
rw [kernel.sum_comm]
#align probability_theory.kernel.comp_prod_eq_sum_comp_prod_right ProbabilityTheory.kernel.compProd_eq_sum_compProd_right
instance IsMarkovKernel.compProd (κ : kernel α β) [IsMarkovKernel κ] (η : kernel (α × β) γ)
[IsMarkovKernel η] : IsMarkovKernel (κ ⊗ₖ η) :=
⟨fun a =>
⟨by
rw [comp_prod_apply κ η a MeasurableSet.univ]
simp only [Set.mem_univ, Set.setOf_true, measure_univ, lintegral_one]⟩⟩
#align probability_theory.kernel.is_markov_kernel.comp_prod ProbabilityTheory.kernel.IsMarkovKernel.compProd
theorem compProd_apply_univ_le (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsFiniteKernel η] (a : α) : (κ ⊗ₖ η) a Set.univ ≤ κ a Set.univ * IsFiniteKernel.bound η :=
by
rw [comp_prod_apply κ η a MeasurableSet.univ]
simp only [Set.mem_univ, Set.setOf_true]
let Cη := is_finite_kernel.bound η
calc
(∫⁻ b, η (a, b) Set.univ ∂κ a) ≤ ∫⁻ b, Cη ∂κ a :=
lintegral_mono fun b => measure_le_bound η (a, b) Set.univ
_ = Cη * κ a Set.univ := (lintegral_const Cη)
_ = κ a Set.univ * Cη := mul_comm _ _
#align probability_theory.kernel.comp_prod_apply_univ_le ProbabilityTheory.kernel.compProd_apply_univ_le
instance IsFiniteKernel.compProd (κ : kernel α β) [IsFiniteKernel κ] (η : kernel (α × β) γ)
[IsFiniteKernel η] : IsFiniteKernel (κ ⊗ₖ η) :=
⟨⟨IsFiniteKernel.bound κ * IsFiniteKernel.bound η,
ENNReal.mul_lt_top (IsFiniteKernel.bound_ne_top κ) (IsFiniteKernel.bound_ne_top η), fun a =>
calc
(κ ⊗ₖ η) a Set.univ ≤ κ a Set.univ * IsFiniteKernel.bound η := compProd_apply_univ_le κ η a
_ ≤ IsFiniteKernel.bound κ * IsFiniteKernel.bound η :=
mul_le_mul (measure_le_bound κ a Set.univ) le_rfl (zero_le _) (zero_le _)
⟩⟩
#align probability_theory.kernel.is_finite_kernel.comp_prod ProbabilityTheory.kernel.IsFiniteKernel.compProd
instance IsSFiniteKernel.compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] : IsSFiniteKernel (κ ⊗ₖ η) :=
by
rw [comp_prod_eq_sum_comp_prod]
exact kernel.is_s_finite_kernel_sum fun n => kernel.is_s_finite_kernel_sum inferInstance
#align probability_theory.kernel.is_s_finite_kernel.comp_prod ProbabilityTheory.kernel.IsSFiniteKernel.compProd
end CompositionProduct
section MapComap
/-! ### map, comap -/
variable {γ : Type _} {mγ : MeasurableSpace γ} {f : β → γ} {g : γ → α}
include mγ
/-- The pushforward of a kernel along a measurable function.
We include measurability in the assumptions instead of using junk values
to make sure that typeclass inference can infer that the `map` of a Markov kernel
is again a Markov kernel. -/
noncomputable def map (κ : kernel α β) (f : β → γ) (hf : Measurable f) : kernel α γ
where
val a := (κ a).map f
property := (Measure.measurable_map _ hf).comp (kernel.measurable κ)
#align probability_theory.kernel.map ProbabilityTheory.kernel.map
theorem map_apply (κ : kernel α β) (hf : Measurable f) (a : α) : map κ f hf a = (κ a).map f :=
rfl
#align probability_theory.kernel.map_apply ProbabilityTheory.kernel.map_apply
theorem map_apply' (κ : kernel α β) (hf : Measurable f) (a : α) {s : Set γ} (hs : MeasurableSet s) :
map κ f hf a s = κ a (f ⁻¹' s) := by rw [map_apply, measure.map_apply hf hs]
#align probability_theory.kernel.map_apply' ProbabilityTheory.kernel.map_apply'
theorem lintegral_map (κ : kernel α β) (hf : Measurable f) (a : α) {g' : γ → ℝ≥0∞}
(hg : Measurable g') : (∫⁻ b, g' b ∂map κ f hf a) = ∫⁻ a, g' (f a) ∂κ a := by
rw [map_apply _ hf, lintegral_map hg hf]
#align probability_theory.kernel.lintegral_map ProbabilityTheory.kernel.lintegral_map
theorem sum_map_seq (κ : kernel α β) [IsSFiniteKernel κ] (hf : Measurable f) :
(kernel.sum fun n => map (seq κ n) f hf) = map κ f hf :=
by
ext (a s hs) : 2
rw [kernel.sum_apply, map_apply' κ hf a hs, measure.sum_apply _ hs, ← measure_sum_seq κ,
measure.sum_apply _ (hf hs)]
simp_rw [map_apply' _ hf _ hs]
#align probability_theory.kernel.sum_map_seq ProbabilityTheory.kernel.sum_map_seq
instance IsMarkovKernel.map (κ : kernel α β) [IsMarkovKernel κ] (hf : Measurable f) :
IsMarkovKernel (map κ f hf) :=
⟨fun a => ⟨by rw [map_apply' κ hf a MeasurableSet.univ, Set.preimage_univ, measure_univ]⟩⟩
#align probability_theory.kernel.is_markov_kernel.map ProbabilityTheory.kernel.IsMarkovKernel.map
instance IsFiniteKernel.map (κ : kernel α β) [IsFiniteKernel κ] (hf : Measurable f) :
IsFiniteKernel (map κ f hf) :=
by
refine' ⟨⟨is_finite_kernel.bound κ, is_finite_kernel.bound_lt_top κ, fun a => _⟩⟩
rw [map_apply' κ hf a MeasurableSet.univ]
exact measure_le_bound κ a _
#align probability_theory.kernel.is_finite_kernel.map ProbabilityTheory.kernel.IsFiniteKernel.map
instance IsSFiniteKernel.map (κ : kernel α β) [IsSFiniteKernel κ] (hf : Measurable f) :
IsSFiniteKernel (map κ f hf) :=
⟨⟨fun n => map (seq κ n) f hf, inferInstance, (sum_map_seq κ hf).symm⟩⟩
#align probability_theory.kernel.is_s_finite_kernel.map ProbabilityTheory.kernel.IsSFiniteKernel.map
/-- Pullback of a kernel, such that for each set s `comap κ g hg c s = κ (g c) s`.
We include measurability in the assumptions instead of using junk values
to make sure that typeclass inference can infer that the `comap` of a Markov kernel
is again a Markov kernel. -/
def comap (κ : kernel α β) (g : γ → α) (hg : Measurable g) : kernel γ β
where
val a := κ (g a)
property := (kernel.measurable κ).comp hg
#align probability_theory.kernel.comap ProbabilityTheory.kernel.comap
theorem comap_apply (κ : kernel α β) (hg : Measurable g) (c : γ) : comap κ g hg c = κ (g c) :=
rfl
#align probability_theory.kernel.comap_apply ProbabilityTheory.kernel.comap_apply
theorem comap_apply' (κ : kernel α β) (hg : Measurable g) (c : γ) (s : Set β) :
comap κ g hg c s = κ (g c) s :=
rfl
#align probability_theory.kernel.comap_apply' ProbabilityTheory.kernel.comap_apply'
theorem lintegral_comap (κ : kernel α β) (hg : Measurable g) (c : γ) (g' : β → ℝ≥0∞) :
(∫⁻ b, g' b ∂comap κ g hg c) = ∫⁻ b, g' b ∂κ (g c) :=
rfl
#align probability_theory.kernel.lintegral_comap ProbabilityTheory.kernel.lintegral_comap
theorem sum_comap_seq (κ : kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) :
(kernel.sum fun n => comap (seq κ n) g hg) = comap κ g hg :=
by
ext (a s hs) : 2
rw [kernel.sum_apply, comap_apply' κ hg a s, measure.sum_apply _ hs, ← measure_sum_seq κ,
measure.sum_apply _ hs]
simp_rw [comap_apply' _ hg _ s]
#align probability_theory.kernel.sum_comap_seq ProbabilityTheory.kernel.sum_comap_seq
instance IsMarkovKernel.comap (κ : kernel α β) [IsMarkovKernel κ] (hg : Measurable g) :
IsMarkovKernel (comap κ g hg) :=
⟨fun a => ⟨by rw [comap_apply' κ hg a Set.univ, measure_univ]⟩⟩
#align probability_theory.kernel.is_markov_kernel.comap ProbabilityTheory.kernel.IsMarkovKernel.comap
instance IsFiniteKernel.comap (κ : kernel α β) [IsFiniteKernel κ] (hg : Measurable g) :
IsFiniteKernel (comap κ g hg) :=
by
refine' ⟨⟨is_finite_kernel.bound κ, is_finite_kernel.bound_lt_top κ, fun a => _⟩⟩
rw [comap_apply' κ hg a Set.univ]
exact measure_le_bound κ _ _
#align probability_theory.kernel.is_finite_kernel.comap ProbabilityTheory.kernel.IsFiniteKernel.comap
instance IsSFiniteKernel.comap (κ : kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) :
IsSFiniteKernel (comap κ g hg) :=
⟨⟨fun n => comap (seq κ n) g hg, inferInstance, (sum_comap_seq κ hg).symm⟩⟩
#align probability_theory.kernel.is_s_finite_kernel.comap ProbabilityTheory.kernel.IsSFiniteKernel.comap
end MapComap
open ProbabilityTheory
section FstSnd
/-- Define a `kernel (γ × α) β` from a `kernel α β` by taking the comap of the projection. -/
def prodMkLeft (κ : kernel α β) (γ : Type _) [MeasurableSpace γ] : kernel (γ × α) β :=
comap κ Prod.snd measurable_snd
#align probability_theory.kernel.prod_mk_left ProbabilityTheory.kernel.prodMkLeft
variable {γ : Type _} {mγ : MeasurableSpace γ} {f : β → γ} {g : γ → α}
include mγ
theorem prodMkLeft_apply (κ : kernel α β) (ca : γ × α) : prodMkLeft κ γ ca = κ ca.snd :=
rfl
#align probability_theory.kernel.prod_mk_left_apply ProbabilityTheory.kernel.prodMkLeft_apply
theorem prodMkLeft_apply' (κ : kernel α β) (ca : γ × α) (s : Set β) :
prodMkLeft κ γ ca s = κ ca.snd s :=
rfl
#align probability_theory.kernel.prod_mk_left_apply' ProbabilityTheory.kernel.prodMkLeft_apply'
theorem lintegral_prodMkLeft (κ : kernel α β) (ca : γ × α) (g : β → ℝ≥0∞) :
(∫⁻ b, g b ∂prodMkLeft κ γ ca) = ∫⁻ b, g b ∂κ ca.snd :=
rfl
#align probability_theory.kernel.lintegral_prod_mk_left ProbabilityTheory.kernel.lintegral_prodMkLeft
instance IsMarkovKernel.prodMkLeft (κ : kernel α β) [IsMarkovKernel κ] :
IsMarkovKernel (prodMkLeft κ γ) := by
rw [prod_mk_left]
infer_instance
#align probability_theory.kernel.is_markov_kernel.prod_mk_left ProbabilityTheory.kernel.IsMarkovKernel.prodMkLeft
instance IsFiniteKernel.prodMkLeft (κ : kernel α β) [IsFiniteKernel κ] :
IsFiniteKernel (prodMkLeft κ γ) := by
rw [prod_mk_left]
infer_instance
#align probability_theory.kernel.is_finite_kernel.prod_mk_left ProbabilityTheory.kernel.IsFiniteKernel.prodMkLeft
instance IsSFiniteKernel.prodMkLeft (κ : kernel α β) [IsSFiniteKernel κ] :
IsSFiniteKernel (prodMkLeft κ γ) := by
rw [prod_mk_left]
infer_instance
#align probability_theory.kernel.is_s_finite_kernel.prod_mk_left ProbabilityTheory.kernel.IsSFiniteKernel.prodMkLeft
/-- Define a `kernel (β × α) γ` from a `kernel (α × β) γ` by taking the comap of `prod.swap`. -/
def swapLeft (κ : kernel (α × β) γ) : kernel (β × α) γ :=
comap κ Prod.swap measurable_swap
#align probability_theory.kernel.swap_left ProbabilityTheory.kernel.swapLeft
theorem swapLeft_apply (κ : kernel (α × β) γ) (a : β × α) : swapLeft κ a = κ a.symm :=
rfl
#align probability_theory.kernel.swap_left_apply ProbabilityTheory.kernel.swapLeft_apply
theorem swapLeft_apply' (κ : kernel (α × β) γ) (a : β × α) (s : Set γ) :
swapLeft κ a s = κ a.symm s :=
rfl
#align probability_theory.kernel.swap_left_apply' ProbabilityTheory.kernel.swapLeft_apply'
theorem lintegral_swapLeft (κ : kernel (α × β) γ) (a : β × α) (g : γ → ℝ≥0∞) :
(∫⁻ c, g c ∂swapLeft κ a) = ∫⁻ c, g c ∂κ a.symm := by
rw [swap_left, lintegral_comap _ measurable_swap a]
#align probability_theory.kernel.lintegral_swap_left ProbabilityTheory.kernel.lintegral_swapLeft
instance IsMarkovKernel.swapLeft (κ : kernel (α × β) γ) [IsMarkovKernel κ] :
IsMarkovKernel (swapLeft κ) := by
rw [swap_left]
infer_instance
#align probability_theory.kernel.is_markov_kernel.swap_left ProbabilityTheory.kernel.IsMarkovKernel.swapLeft
instance IsFiniteKernel.swapLeft (κ : kernel (α × β) γ) [IsFiniteKernel κ] :
IsFiniteKernel (swapLeft κ) := by
rw [swap_left]
infer_instance
#align probability_theory.kernel.is_finite_kernel.swap_left ProbabilityTheory.kernel.IsFiniteKernel.swapLeft
instance IsSFiniteKernel.swapLeft (κ : kernel (α × β) γ) [IsSFiniteKernel κ] :
IsSFiniteKernel (swapLeft κ) := by
rw [swap_left]
infer_instance
#align probability_theory.kernel.is_s_finite_kernel.swap_left ProbabilityTheory.kernel.IsSFiniteKernel.swapLeft
/-- Define a `kernel α (γ × β)` from a `kernel α (β × γ)` by taking the map of `prod.swap`. -/
noncomputable def swapRight (κ : kernel α (β × γ)) : kernel α (γ × β) :=
map κ Prod.swap measurable_swap
#align probability_theory.kernel.swap_right ProbabilityTheory.kernel.swapRight
theorem swapRight_apply (κ : kernel α (β × γ)) (a : α) : swapRight κ a = (κ a).map Prod.swap :=
rfl
#align probability_theory.kernel.swap_right_apply ProbabilityTheory.kernel.swapRight_apply
theorem swapRight_apply' (κ : kernel α (β × γ)) (a : α) {s : Set (γ × β)} (hs : MeasurableSet s) :
swapRight κ a s = κ a { p | p.symm ∈ s } :=
by
rw [swap_right_apply, measure.map_apply measurable_swap hs]
rfl
#align probability_theory.kernel.swap_right_apply' ProbabilityTheory.kernel.swapRight_apply'
theorem lintegral_swapRight (κ : kernel α (β × γ)) (a : α) {g : γ × β → ℝ≥0∞} (hg : Measurable g) :
(∫⁻ c, g c ∂swapRight κ a) = ∫⁻ bc : β × γ, g bc.symm ∂κ a := by
rw [swap_right, lintegral_map _ measurable_swap a hg]
#align probability_theory.kernel.lintegral_swap_right ProbabilityTheory.kernel.lintegral_swapRight
instance IsMarkovKernel.swapRight (κ : kernel α (β × γ)) [IsMarkovKernel κ] :
IsMarkovKernel (swapRight κ) := by
rw [swap_right]
infer_instance
#align probability_theory.kernel.is_markov_kernel.swap_right ProbabilityTheory.kernel.IsMarkovKernel.swapRight
instance IsFiniteKernel.swapRight (κ : kernel α (β × γ)) [IsFiniteKernel κ] :
IsFiniteKernel (swapRight κ) := by
rw [swap_right]
infer_instance
#align probability_theory.kernel.is_finite_kernel.swap_right ProbabilityTheory.kernel.IsFiniteKernel.swapRight
instance IsSFiniteKernel.swapRight (κ : kernel α (β × γ)) [IsSFiniteKernel κ] :
IsSFiniteKernel (swapRight κ) := by
rw [swap_right]
infer_instance
#align probability_theory.kernel.is_s_finite_kernel.swap_right ProbabilityTheory.kernel.IsSFiniteKernel.swapRight
/-- Define a `kernel α β` from a `kernel α (β × γ)` by taking the map of the first projection. -/
noncomputable def fst (κ : kernel α (β × γ)) : kernel α β :=
map κ Prod.fst measurable_fst
#align probability_theory.kernel.fst ProbabilityTheory.kernel.fst
theorem fst_apply (κ : kernel α (β × γ)) (a : α) : fst κ a = (κ a).map Prod.fst :=
rfl
#align probability_theory.kernel.fst_apply ProbabilityTheory.kernel.fst_apply
theorem fst_apply' (κ : kernel α (β × γ)) (a : α) {s : Set β} (hs : MeasurableSet s) :
fst κ a s = κ a { p | p.1 ∈ s } :=
by
rw [fst_apply, measure.map_apply measurable_fst hs]
rfl
#align probability_theory.kernel.fst_apply' ProbabilityTheory.kernel.fst_apply'
theorem lintegral_fst (κ : kernel α (β × γ)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) :
(∫⁻ c, g c ∂fst κ a) = ∫⁻ bc : β × γ, g bc.fst ∂κ a := by
rw [fst, lintegral_map _ measurable_fst a hg]
#align probability_theory.kernel.lintegral_fst ProbabilityTheory.kernel.lintegral_fst
instance IsMarkovKernel.fst (κ : kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (fst κ) :=
by
rw [fst]
infer_instance
#align probability_theory.kernel.is_markov_kernel.fst ProbabilityTheory.kernel.IsMarkovKernel.fst
instance IsFiniteKernel.fst (κ : kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (fst κ) :=
by
rw [fst]
infer_instance
#align probability_theory.kernel.is_finite_kernel.fst ProbabilityTheory.kernel.IsFiniteKernel.fst
instance IsSFiniteKernel.fst (κ : kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (fst κ) :=
by
rw [fst]
infer_instance
#align probability_theory.kernel.is_s_finite_kernel.fst ProbabilityTheory.kernel.IsSFiniteKernel.fst
/-- Define a `kernel α γ` from a `kernel α (β × γ)` by taking the map of the second projection. -/
noncomputable def snd (κ : kernel α (β × γ)) : kernel α γ :=
map κ Prod.snd measurable_snd
#align probability_theory.kernel.snd ProbabilityTheory.kernel.snd
theorem snd_apply (κ : kernel α (β × γ)) (a : α) : snd κ a = (κ a).map Prod.snd :=
rfl
#align probability_theory.kernel.snd_apply ProbabilityTheory.kernel.snd_apply
theorem snd_apply' (κ : kernel α (β × γ)) (a : α) {s : Set γ} (hs : MeasurableSet s) :
snd κ a s = κ a { p | p.2 ∈ s } :=
by
rw [snd_apply, measure.map_apply measurable_snd hs]
rfl
#align probability_theory.kernel.snd_apply' ProbabilityTheory.kernel.snd_apply'
theorem lintegral_snd (κ : kernel α (β × γ)) (a : α) {g : γ → ℝ≥0∞} (hg : Measurable g) :
(∫⁻ c, g c ∂snd κ a) = ∫⁻ bc : β × γ, g bc.snd ∂κ a := by
rw [snd, lintegral_map _ measurable_snd a hg]
#align probability_theory.kernel.lintegral_snd ProbabilityTheory.kernel.lintegral_snd
instance IsMarkovKernel.snd (κ : kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (snd κ) :=
by
rw [snd]
infer_instance
#align probability_theory.kernel.is_markov_kernel.snd ProbabilityTheory.kernel.IsMarkovKernel.snd
instance IsFiniteKernel.snd (κ : kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (snd κ) :=
by
rw [snd]
infer_instance
#align probability_theory.kernel.is_finite_kernel.snd ProbabilityTheory.kernel.IsFiniteKernel.snd
instance IsSFiniteKernel.snd (κ : kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (snd κ) :=
by
rw [snd]
infer_instance
#align probability_theory.kernel.is_s_finite_kernel.snd ProbabilityTheory.kernel.IsSFiniteKernel.snd
end FstSnd
section Comp
/-! ### Composition of two kernels -/
variable {γ : Type _} {mγ : MeasurableSpace γ} {f : β → γ} {g : γ → α}
include mγ
/-- Composition of two s-finite kernels. -/
noncomputable def comp (η : kernel β γ) [IsSFiniteKernel η] (κ : kernel α β) [IsSFiniteKernel κ] :
kernel α γ :=
snd (κ ⊗ₖ prodMkLeft η α)
#align probability_theory.kernel.comp ProbabilityTheory.kernel.comp
-- mathport name: kernel.comp
scoped[ProbabilityTheory] infixl:100 " ∘ₖ " => ProbabilityTheory.kernel.comp
theorem comp_apply (η : kernel β γ) [IsSFiniteKernel η] (κ : kernel α β) [IsSFiniteKernel κ] (a : α)
{s : Set γ} (hs : MeasurableSet s) : (η ∘ₖ κ) a s = ∫⁻ b, η b s ∂κ a :=
by
rw [comp, snd_apply' _ _ hs, comp_prod_apply]
swap; · exact measurable_snd hs
simp only [Set.mem_setOf_eq, Set.setOf_mem_eq, prod_mk_left_apply' _ _ s]
#align probability_theory.kernel.comp_apply ProbabilityTheory.kernel.comp_apply
theorem lintegral_comp (η : kernel β γ) [IsSFiniteKernel η] (κ : kernel α β) [IsSFiniteKernel κ]
(a : α) {g : γ → ℝ≥0∞} (hg : Measurable g) :
(∫⁻ c, g c ∂(η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, g c ∂η b ∂κ a :=
by
rw [comp, lintegral_snd _ _ hg]
change
(∫⁻ bc, (fun a b => g b) bc.fst bc.snd ∂(κ ⊗ₖ prod_mk_left η α) a) = ∫⁻ b, ∫⁻ c, g c ∂η b ∂κ a
exact lintegral_comp_prod _ _ _ (hg.comp measurable_snd)
#align probability_theory.kernel.lintegral_comp ProbabilityTheory.kernel.lintegral_comp
instance IsMarkovKernel.comp (η : kernel β γ) [IsMarkovKernel η] (κ : kernel α β)
[IsMarkovKernel κ] : IsMarkovKernel (η ∘ₖ κ) :=
by
rw [comp]
infer_instance
#align probability_theory.kernel.is_markov_kernel.comp ProbabilityTheory.kernel.IsMarkovKernel.comp
instance IsFiniteKernel.comp (η : kernel β γ) [IsFiniteKernel η] (κ : kernel α β)
[IsFiniteKernel κ] : IsFiniteKernel (η ∘ₖ κ) :=
by
rw [comp]
infer_instance
#align probability_theory.kernel.is_finite_kernel.comp ProbabilityTheory.kernel.IsFiniteKernel.comp
instance IsSFiniteKernel.comp (η : kernel β γ) [IsSFiniteKernel η] (κ : kernel α β)
[IsSFiniteKernel κ] : IsSFiniteKernel (η ∘ₖ κ) :=
by
rw [comp]
infer_instance
#align probability_theory.kernel.is_s_finite_kernel.comp ProbabilityTheory.kernel.IsSFiniteKernel.comp
/-- Composition of kernels is associative. -/
theorem comp_assoc {δ : Type _} {mδ : MeasurableSpace δ} (ξ : kernel γ δ) [IsSFiniteKernel ξ]
(η : kernel β γ) [IsSFiniteKernel η] (κ : kernel α β) [IsSFiniteKernel κ] :
ξ ∘ₖ η ∘ₖ κ = ξ ∘ₖ (η ∘ₖ κ) :=
by
refine' ext_fun fun a f hf => _
simp_rw [lintegral_comp _ _ _ hf, lintegral_comp _ _ _ (measurable_lintegral' ξ hf)]
#align probability_theory.kernel.comp_assoc ProbabilityTheory.kernel.comp_assoc
theorem deterministic_comp_eq_map (hf : Measurable f) (κ : kernel α β) [IsSFiniteKernel κ] :
deterministic hf ∘ₖ κ = map κ f hf :=
by
ext (a s hs) : 2
simp_rw [map_apply' _ _ _ hs, comp_apply _ _ _ hs, deterministic_apply' hf _ hs,
lintegral_indicator_const_comp hf hs, one_mul]
#align probability_theory.kernel.deterministic_comp_eq_map ProbabilityTheory.kernel.deterministic_comp_eq_map
theorem comp_deterministic_eq_comap (κ : kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) :
κ ∘ₖ deterministic hg = comap κ g hg :=
by
ext (a s hs) : 2
simp_rw [comap_apply' _ _ _ s, comp_apply _ _ _ hs, deterministic_apply hg a,
lintegral_dirac' _ (kernel.measurable_coe κ hs)]
#align probability_theory.kernel.comp_deterministic_eq_comap ProbabilityTheory.kernel.comp_deterministic_eq_comap
end Comp
section Prod
/-! ### Product of two kernels -/
variable {γ : Type _} {mγ : MeasurableSpace γ}
include mγ
/-- Product of two s-finite kernels. -/
noncomputable def prod (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel α γ) [IsSFiniteKernel η] :
kernel α (β × γ) :=
κ ⊗ₖ swapLeft (prodMkLeft η β)
#align probability_theory.kernel.prod ProbabilityTheory.kernel.prod
theorem prod_apply (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel α γ) [IsSFiniteKernel η] (a : α)
{s : Set (β × γ)} (hs : MeasurableSet s) :
(prod κ η) a s = ∫⁻ b : β, (η a) { c : γ | (b, c) ∈ s } ∂κ a := by
simp_rw [Prod, comp_prod_apply _ _ _ hs, swap_left_apply _ _, prod_mk_left_apply,
Prod.swap_prod_mk]
#align probability_theory.kernel.prod_apply ProbabilityTheory.kernel.prod_apply
theorem lintegral_prod (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel α γ) [IsSFiniteKernel η]
(a : α) {g : β × γ → ℝ≥0∞} (hg : Measurable g) :
(∫⁻ c, g c ∂(prod κ η) a) = ∫⁻ b, ∫⁻ c, g (b, c) ∂η a ∂κ a := by
simp_rw [Prod, lintegral_comp_prod _ _ _ hg, swap_left_apply, prod_mk_left_apply,
Prod.swap_prod_mk]
#align probability_theory.kernel.lintegral_prod ProbabilityTheory.kernel.lintegral_prod
instance IsMarkovKernel.prod (κ : kernel α β) [IsMarkovKernel κ] (η : kernel α γ)
[IsMarkovKernel η] : IsMarkovKernel (prod κ η) :=
by
rw [Prod]
infer_instance
#align probability_theory.kernel.is_markov_kernel.prod ProbabilityTheory.kernel.IsMarkovKernel.prod
instance IsFiniteKernel.prod (κ : kernel α β) [IsFiniteKernel κ] (η : kernel α γ)
[IsFiniteKernel η] : IsFiniteKernel (prod κ η) :=
by
rw [Prod]
infer_instance
#align probability_theory.kernel.is_finite_kernel.prod ProbabilityTheory.kernel.IsFiniteKernel.prod
instance IsSFiniteKernel.prod (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel α γ)
[IsSFiniteKernel η] : IsSFiniteKernel (prod κ η) :=
by
rw [Prod]
infer_instance
#align probability_theory.kernel.is_s_finite_kernel.prod ProbabilityTheory.kernel.IsSFiniteKernel.prod
end Prod
end Kernel
end ProbabilityTheory
|
#ifndef H_GPM_STRIPPED_DOWN
#define H_GPM_STRIPPED_DOWN
#include <gsl/gsl_vector.h>
#include <gsl/gsl_histogram.h>
#include "../csm_all.h"
void ght_find_theta_range(LDP laser_ref, LDP laser_sens,
const double*x0, double max_linear_correction,
double max_angular_correction_deg, int interval, gsl_histogram*hist, int*num_correspondences);
void ght_one_shot(LDP laser_ref, LDP laser_sens,
const double*x0, double max_linear_correction,
double max_angular_correction_deg, int interval, double*x, int*num_correspondences) ;
#endif
|
module Control.Monad.Reader
import Control.Monad.Identity
import Control.Monad.Trans
||| A computation which runs in a static context and produces an output
public export
interface Monad m => MonadReader stateType (m : Type -> Type) | m where
||| Get the context
ask : m stateType
||| `local f c` runs the computation `c` in an environment modified by `f`.
local : MonadReader stateType m => (stateType -> stateType) -> m a -> m a
||| The transformer on which the Reader monad is based
public export
record ReaderT (stateType : Type) (m : Type -> Type) (a : Type) where
constructor MkReaderT
runReaderT' : stateType -> m a
public export
implementation Functor f => Functor (ReaderT stateType f) where
map f (MkReaderT g) = MkReaderT (\st => map f (g st))
public export
implementation Applicative f => Applicative (ReaderT stateType f) where
pure x = MkReaderT (\st => pure x)
(MkReaderT f) <*> (MkReaderT a) =
MkReaderT (\st =>
let f' = f st in
let a' = a st in
f' <*> a')
public export
implementation Monad m => Monad (ReaderT stateType m) where
(MkReaderT f) >>= k =
MkReaderT (\st => do v <- f st
let MkReaderT kv = k v
kv st)
public export
implementation MonadTrans (ReaderT stateType) where
lift x = MkReaderT (\_ => x)
public export
implementation Monad m => MonadReader stateType (ReaderT stateType m) where
ask = MkReaderT (\st => pure st)
local f (MkReaderT action) = MkReaderT (action . f)
public export
implementation HasIO m => HasIO (ReaderT stateType m) where
liftIO f = MkReaderT (\_ => liftIO f)
public export
implementation (Monad f, Alternative f) => Alternative (ReaderT stateType f) where
empty = lift empty
(MkReaderT f) <|> (MkReaderT g) = MkReaderT (\st => f st <|> g st)
||| Evaluate a function in the context held by this computation
public export
asks : MonadReader stateType m => (stateType -> a) -> m a
asks f = ask >>= pure . f
||| Unwrap and apply a ReaderT monad computation
public export
%inline
runReaderT : stateType -> ReaderT stateType m a -> m a
runReaderT s action = runReaderT' action s
||| The Reader monad. The ReaderT transformer applied to the Identity monad.
public export
Reader : (stateType : Type) -> (a : Type) -> Type
Reader s a = ReaderT s Identity a
||| Unwrap and apply a Reader monad computation
public export
runReader : stateType -> Reader stateType a -> a
runReader s = runIdentity . runReaderT s
|
%The spherical K-means algorithm
%(C) 2007-2011 Nguyen Xuan Vinh
%Contact: vinh.nguyenx at gmail.com or vinh.nguyen at monash.edu
%Reference:
% [1] Xuan Vinh Nguyen: Gene Clustering on the Unit Hypersphere with the
% Spherical K-Means Algorithm: Coping with Extremely Large Number of Local Optima. BIOCOMP 2008: 226-233
%Usage: Normalize the data set to have mean zero and unit norm
function b=normalize_norm_mean(a)
[n dim]=size(a);
for i=1:n
a(i,:)=(a(i,:)-mean(a(i,:)))/norm(a(i,:)-mean(a(i,:)),2);
end
b=a; |
<!-- dom:TITLE: PHY321: Classical Mechanics 1 -->
# PHY321: Classical Mechanics 1
<!-- dom:AUTHOR: Solution Homework 8, due Monday March 29 -->
<!-- Author: -->
**Solution Homework 8, due Monday March 29**
Date: **Mar 30, 2021**
### Introduction to homework 8
This week's sets of classical pen and paper and computational
exercises are tailored to the topic of two-body problems and central
forces. It follows what was discussed during the lectures during week
12 (March 15-19) and week 12 (March 22-26).
The relevant reading background is
1. Sections 8.1-8.7 of Taylor.
2. Lecture notes on two-body problems, central forces and gravity.
### Exercise 1 (10pt), Conservation of Energy
The equations of motion in the center-of-mass frame in two dimensions with $x=r\cos{(\phi)}$ and $y=r\sin{(\phi)}$ and
$r\in [0,\infty)$, $\phi\in [0,2\pi]$ and $r=\sqrt{x^2+y^2}$ are given by
$$
\mu \ddot{r}=-\frac{dV(r)}{dr}+\mu r\dot{\phi}^2,
$$
and
$$
\dot{\phi}=\frac{L}{\mu r^2}.
$$
Here $V(r)$ is any central force which depends only on the relative coordinate.
* 1a (5pt) Show that you can rewrite the radial equation in terms of an effective potential $V_{\mathrm{eff}}(r)=V(r)+L^2/(2\mu r^2)$.
Here we use that
$$
\dot{\phi}=\frac{L}{\mu r^2}.
$$
and rewrite the above equation of motion as
$$
\mu \ddot{r}=-\frac{dV(r)}{dr}+\frac{L^2}{\mu r^3}.
$$
If we now define an effective potential
$$
V_{\mathrm{eff}}=V(r)+\frac{L^2}{2\mu r^2},
$$
we can rewrite our equation of motion in terms of
$$
\mu \ddot{r}=-\frac{dV_{\mathrm{eff}}(r)}{dr}=-\frac{dV(r)}{dr}+\frac{L^2}{\mu r^3}.
$$
The addition due to the angular momentum comes from the kinetic energy
when we rewrote it in terms of polar coordinates. It introduces a
so-called centrifugal barrier due to the angular momentum. This
centrifugal barrier pushes the object farther away from the origin.
Alternatively,
<!-- Equation labels as ordinary links -->
<div id="_auto1"></div>
$$
\begin{equation}
-\frac{dV_{\text{eff}}(r)}{dr} = \mu \ddot{r} =-\frac{dV(r)}{dr}+\mu\dot{\phi}^2r
\label{_auto1} \tag{1}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto2"></div>
$$
\begin{equation}
-\frac{dV_{\text{eff}}(r)}{dr} = -\frac{dV(r)}{dr}+\mu\left( \frac{L}{\mu r^2}\right) ^2r
\label{_auto2} \tag{2}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto3"></div>
$$
\begin{equation}
= -\frac{dV(r)}{dr}+\mu\frac{L^2}{\mu}r^{-3}
\label{_auto3} \tag{3}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto4"></div>
$$
\begin{equation}
= -\frac{d\left( V(r)+\frac{1}{2} \frac{L^2}{\mu r^2}\right) }{dr}.
\label{_auto4} \tag{4}
\end{equation}
$$
Integrating we obtain
<!-- Equation labels as ordinary links -->
<div id="_auto5"></div>
$$
\begin{equation}
V_{\text{eff}}(r) = V(r) + \frac{L^2}{2\mu r^2} + C
\label{_auto5} \tag{5}
\end{equation}
$$
Imposing the extra condition that $V_{\text{eff}}(r\rightarrow \infty) = V(r\rightarrow \infty)$,
<!-- Equation labels as ordinary links -->
<div id="_auto6"></div>
$$
\begin{equation}
V_{\text{eff}}(r) = V(r) + \frac{L^2}{2\mu r^2}
\label{_auto6} \tag{6}
\end{equation}
$$
* 1b (5pt) Write out the final differential equation for the radial degrees of freedom when we specify that $V(r)=-\alpha/r$. Plot the effective potential. You can choose values for $\alpha$ and $L$ and discuss (see Taylor section 8.4 and example 8.2) the physics of the system for two energies, one larger than zero and one smaller than zero. This is similar to what you did in the first midterm, except that the potential is different.
We insert now the explicit potential form $V(r)=-\alpha/r$. This gives us the following equation of motion
$$
\mu \ddot{r}=-\frac{dV_{\mathrm{eff}}(r)}{dr}=-\frac{d(-\alpha/r)}{dr}+\frac{L^2}{\mu r^3}=-\frac{\alpha}{r^2}+\frac{L^2}{\mu r^3}.
$$
The following code plots this effective potential for a simple choice of parameters, with a standard gravitational potential $-\alpha/r$. Here we have chosen $L=m=\alpha=1$.
```python
%matplotlib inline
# Common imports
import numpy as np
from math import *
import matplotlib.pyplot as plt
Deltax = 0.01
#set up arrays
xinitial = 0.3
xfinal = 5.0
alpha = 0.2 # spring constant
m = 1.0 # mass, you can change these
AngMom = 1.0 # The angular momentum
n = ceil((xfinal-xinitial)/Deltax)
x = np.zeros(n)
for i in range(n):
x[i] = xinitial+i*Deltax
V = np.zeros(n)
V = -alpha/x**2+0.5*AngMom*AngMom/(m*x*x)
# Plot potential
fig, ax = plt.subplots()
ax.set_xlabel('r[m]')
ax.set_ylabel('V[J]')
ax.plot(x, V)
fig.tight_layout()
plt.show()
```
If we select a potential energy below zero (and not necessarily one
which corresponds to the minimum point), the object will oscillate
between two values of $r$, a value $r_{\mathrm{min}}$ and a value
$r_{\mathrm{max}}$. We can assume that for example the kinetic energy
is zero at these two points. The object will thus oscillate back and
forth between these two points. As we will see in connection with the
solution of the equations of motion, this case corresponds to
elliptical orbits. If we select $r$ equal to the minimum of the
potential and use initial conditions for the velocity that correspond
to circular motion, the object will have a constant value of $r$ given
by the value at the minimum and the orbit is a circle.
If we select a potential energy larger than zero, then, since the
kinetic energy is always larger or equal to zero, the object will move
away from the origin. See also the discussion in Taylor, sections 8.4-8.6.
### Exercise 2 (40pt), Harmonic oscillator again
Consider a particle of mass $m$ in a $2$-dimensional harmonic oscillator with potential
$$
V(r)=\frac{1}{2}kr^2=\frac{1}{2}k(x^2+y^2).
$$
We assume the orbit has a final non-zero angular momentum $L$. The
effective potential looks like that of a harmonic oscillator for large
$r$, but for small $r$, the centrifugal potential repels the particle
from the origin. The combination of the two potentials has a minimum
for at some radius $r_{\rm min}$.
* 2a (10pt) Set up the effective potential and plot it. Find $r_{\rm min}$ and $\dot{\phi}$. Show that the latter is given by $\dot{\phi}=\sqrt{k/m}$. At $r_{\rm min}$ the particle does not accelerate and $r$ stays constant and the motion is circular. With fixed $k$ and $m$, which parameter can we adjust to change the value of $r$ at $r_{\rm min}$?
We consider the effective potential. The radius of a circular orbit is at the minimum of the potential (where the effective force is zero).
The potential is plotted here with the parameters $k=m=1.0$ and $L=1.0$.
```python
# Common imports
import numpy as np
from math import *
import matplotlib.pyplot as plt
Deltax = 0.01
#set up arrays
xinitial = 0.5
xfinal = 3.0
k = 1.0 # spring constant
m = 1.0 # mass, you can change these
AngMom = 1.0 # The angular momentum
n = ceil((xfinal-xinitial)/Deltax)
x = np.zeros(n)
for i in range(n):
x[i] = xinitial+i*Deltax
V = np.zeros(n)
V = 0.5*k*x*x+0.5*AngMom*AngMom/(m*x*x)
# Plot potential
fig, ax = plt.subplots()
ax.set_xlabel('r[m]')
ax.set_ylabel('V[J]')
ax.plot(x, V)
fig.tight_layout()
plt.show()
```
We have an effective potential
$$
\begin{eqnarray*}
V_{\rm eff}&=&\frac{1}{2}kr^2+\frac{L^2}{2mr^2}
\end{eqnarray*}
$$
The effective potential looks like that of a harmonic oscillator for
large $r$, but for small $r$, the centrifugal potential repels the
particle from the origin. The combination of the two potentials has a
minimum for at some radius $r_{\rm min}$.
$$
\begin{eqnarray*}
0&=&kr_{\rm min}-\frac{L^2}{mr_{\rm min}^3},\\
r_{\rm min}&=&\left(\frac{L^2}{mk}\right)^{1/4},\\
\dot{\theta}&=&\frac{L}{mr_{\rm min}^2}=\sqrt{k/m}.
\end{eqnarray*}
$$
For particles at $r_{\rm min}$ with $\dot{r}=0$, the particle does not
accelerate and $r$ stays constant, i.e. a circular orbit. The radius
of the circular orbit can be adjusted by changing the angular momentum
$L$.
For the above parameters this minimum is at $r_{\rm min}=1$.
* 2b (10pt) Now consider small vibrations about $r_{\rm min}$. The effective spring constant is the curvature of the effective potential. Use the curvature at $r_{\rm min}$ to find the effective spring constant (hint, look at exercise 4 in homework 6) $k_{\mathrm{eff}}$. Show also that $\omega=\sqrt{k_{\mathrm{eff}}/m}=2\dot{\phi}$
$$
\begin{eqnarray*}
k_{\rm eff}&=&\left.\frac{d^2}{dr^2}V_{\rm eff}(r)\right|_{r=r_{\rm min}}=k+\frac{3L^2}{mr_{\rm min}^4}\\
&=&4k,\\
\omega&=&\sqrt{k_{\rm eff}/m}=2\sqrt{k/m}=2\dot{\theta}.
\end{eqnarray*}
$$
Because the radius oscillates with twice the angular frequency,
the orbit has two places where $r$ reaches a minimum in one
cycle. This differs from the inverse-square force where there is one
minimum in an orbit. One can show that the orbit for the harmonic
oscillator is also elliptical, but in this case the center of the
potential is at the center of the ellipse, not at one of the foci.
* 2c (10pt) The solution to the equations of motion in Cartesian coordinates is simple. The $x$ and $y$ equations of motion separate, and we have $\ddot{x}=-kx/m$ and $\ddot{y}=-ky/m$. The harmonic oscillator is indeed a system where the degrees of freedom separate and we can find analytical solutions. Define a natural frequency $\omega_0=\sqrt{k/m}$ and show that (where $A$, $B$, $C$ and $D$ are arbitrary constants defined by the initial conditions)
$$
\begin{eqnarray*}
x&=&A\cos\omega_0 t+B\sin\omega_0 t,\\
y&=&C\cos\omega_0 t+D\sin\omega_0 t.
\end{eqnarray*}
$$
The solution is also simple to write down exactly in Cartesian coordinates. The $x$ and $y$ equations of motion separate,
$$
\begin{eqnarray*}
\ddot{x}&=&-kx,\\
\ddot{y}&=&-ky.
\end{eqnarray*}
$$
We know from our studies of the harmonic oscillator that the general solution can be expressed as
$$
\begin{eqnarray*}
x&=&A\cos\omega_0 t+B\sin\omega_0 t,\\
y&=&C\cos\omega_0 t+D\sin\omega_0 t.
\end{eqnarray*}
$$
* 2d (10pt) With the solutions for $x$ and $y$, and $r^2=x^2+y^2$ and the definitions $\alpha=\frac{A^2+B^2+C^2+D^2}{2}$, $\beta=\frac{A^2-B^2+C^2-D^2}{2}$ and $\gamma=AB+CD$, show that
$$
r^2=\alpha+(\beta^2+\gamma^2)^{1/2}\cos(2\omega_0 t-\delta),
$$
with
$$
\delta=\arctan(\gamma/\beta).
$$
We start with $r^2 & = x^2+y^2$ and square the above analytical solutions and after some **exciting algebraic manipulations** we arrive at
<!-- Equation labels as ordinary links -->
<div id="_auto7"></div>
$$
\begin{equation}
r^2 = x^2+y^2
\label{_auto7} \tag{7}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto8"></div>
$$
\begin{equation}
= \left( A\cos\omega_0 t+B\sin\omega_0 t\right) ^2 + \left( C\cos\omega_0 t+D\sin\omega_0 t\right) ^2
\label{_auto8} \tag{8}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto9"></div>
$$
\begin{equation}
= A^2\cos^2\omega_0 t+B^2\sin^2\omega_0 t + 2AB\sin\omega_0 t \cos\omega_0 t + C^2\cos^2\omega_0 t+D^2\sin^2\omega_0 t + 2CD\sin\omega_0 t \cos\omega_0 t
\label{_auto9} \tag{9}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto10"></div>
$$
\begin{equation}
= (A^2+C^2)\cos^2\omega_0 t + (B^2+D^2)\sin^2\omega_0 t + 2(AC + BD)\sin\omega_0 t \cos\omega_0 t
\label{_auto10} \tag{10}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto11"></div>
$$
\begin{equation}
= (B^2+D^2) + (A^2+C^2-B^2-D^2)\cos^2\omega_0 t + 2(AC + BD)2\sin2\omega_0 t
\label{_auto11} \tag{11}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto12"></div>
$$
\begin{equation}
= (B^2+D^2) + (A^2+C^2-B^2-D^2)\frac{1+\cos{2\omega_0 t}}{2} + 2(AC + BD)\frac{1}{2}\sin2\omega_0 t
\label{_auto12} \tag{12}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto13"></div>
$$
\begin{equation}
= \frac{2B^2+2D^2+A^2+C^2-B^2-D^2}{2} + (A^2+C^2-B^2-D^2)\frac{\cos{2\omega_0 t}}{2} + (AC + BD)\sin2\omega_0 t
\label{_auto13} \tag{13}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto14"></div>
$$
\begin{equation}
= \frac{B^2+D^2+A^2+C^2}{2} + \frac{A^2+C^2-B^2-D^2}{2}\cos{2\omega_0 t} + (AC + BD)\sin2\omega_0 t
\label{_auto14} \tag{14}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto15"></div>
$$
\begin{equation}
= \alpha + \beta\cos{2\omega_0 t} + \gamma\sin2\omega_0 t
\label{_auto15} \tag{15}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto16"></div>
$$
\begin{equation}
= \alpha + \sqrt{\beta^2+\gamma^2}\left( \frac{\beta}{\sqrt{\beta^2+\gamma^2}}\cos{2\omega_0 t} + \frac{\gamma}{\sqrt{\beta^2+\gamma^2}}\sin2\omega_0 t\right)
\label{_auto16} \tag{16}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto17"></div>
$$
\begin{equation}
= \alpha + \sqrt{\beta^2+\gamma^2}\left( \cos{\delta}\cos{2\omega_0 t} + \sin{\delta}\sin2\omega_0 t\right)
\label{_auto17} \tag{17}
\end{equation}
$$
<!-- Equation labels as ordinary links -->
<div id="_auto18"></div>
$$
\begin{equation}
= \alpha + \sqrt{\beta^2+\gamma^2}\cos{\left( 2\omega_0 t - \delta\right) },
\label{_auto18} \tag{18}
\end{equation}
$$
which is what we wanted to show.
### Exercise 3 (40pt), Numerical Solution of the Harmonic Oscillator
Using the code we developed in homeworks 5 and/or 6 for the Earth-Sun system, we can solve the above harmonic oscillator problem in two dimensions using our code from this homework. We need however to change the acceleration from the gravitational force to the one given by the harmonic oscillator potential.
* 3a (20pt) Use for example the code in the exercise set to set up the acceleration and use the initial conditions fixed by for example $r_{\rm min}$ from exercise 2. Which value should the initial velocity take if you place yourself at $r_{\rm min}$ and you require a circular motion? Hint: see the first midterm, part 2. There you used the centripetal acceleration.
Instead of solving the equations in the cartesian frame we will now rewrite the above code in terms of the radial degrees of freedom only. Our differential equation is now
$$
\mu \ddot{r}=-\frac{dV(r)}{dr}+\mu\dot{\phi}^2,
$$
and
$$
\dot{\phi}=\frac{L}{\mu r^2}.
$$
* 3b (20pt) We will use $r_{\rm min}$ to fix a value of $L$, as seen in exercise 2. This fixes also $\dot{\phi}$. Write a code which now implements the radial equation for $r$ using the same $r_{\rm min}$ as you did in 3a. Compare the results with those from 3a with the same initial conditions. Do they agree? Use only one set of initial conditions.
The code here finds the solution for $x$ and $y$ using the code we
developed in homework 5 and 6 and the midterm. Note that this code is
tailored to run in Cartesian coordinates. There is thus no angular
momentum dependent term.
Here we have chosen initial conditions that
correspond to the minimum of the effective potential
$r_{\mathrm{min}}$. We have chosen $x_0=r_{\mathrm{min}}$ and
$y_0=0$. Similarly, we use the centripetal acceleration to determine
the initial velocity so that we have a circular motion (see back to the
last question of the midterm). This means that we set the centripetal
acceleration $v^2/r$ equal to the force from the harmonic oscillator $-k\boldsymbol{r}$. Taking the
magnitude of $\boldsymbol{r}$ we have then
$v^2/r=k/mr$, which gives $v=\pm\omega_0r$.
Since the code here solves the equations of motion in cartesian
coordinates and the harmonic oscillator potential leads to forces in
the $x$- and $y$-directions that are decoupled, we have to select the initial velocities and positions so that we don't get that for example $y(t)=0$.
We set $x_0$ to be different from zero and $v_{y0}$ to be different from zero.
```python
# Common imports
import numpy as np
import pandas as pd
from math import *
import matplotlib.pyplot as plt
import os
# Where to save the figures and data files
PROJECT_ROOT_DIR = "Results"
FIGURE_ID = "Results/FigureFiles"
DATA_ID = "DataFiles/"
if not os.path.exists(PROJECT_ROOT_DIR):
os.mkdir(PROJECT_ROOT_DIR)
if not os.path.exists(FIGURE_ID):
os.makedirs(FIGURE_ID)
if not os.path.exists(DATA_ID):
os.makedirs(DATA_ID)
def image_path(fig_id):
return os.path.join(FIGURE_ID, fig_id)
def data_path(dat_id):
return os.path.join(DATA_ID, dat_id)
def save_fig(fig_id):
plt.savefig(image_path(fig_id) + ".png", format='png')
DeltaT = 0.001
#set up arrays
tfinal = 10.0
n = ceil(tfinal/DeltaT)
# set up arrays
t = np.zeros(n)
v = np.zeros((n,2))
r = np.zeros((n,2))
radius = np.zeros(n)
# Constants of the model
k = 1.0 # spring constant
m = 1.0 # mass, you can change these
omega02 = k/m # Frequency
AngMom = 1.0 # The angular momentum
# Potential minimum
rmin = (AngMom*AngMom/k/m)**0.25
# Initial conditions as compact 2-dimensional arrays, x0=rmin and y0 = 0
# r^2 = x^2+y^2. r0 = rmin = sqrt(x0^2+y0^2)
x0 = rmin; y0= 0.0
r0 = np.array([x0,y0])
vy0 = sqrt(omega02)*rmin; vx0 = 0.0
v0 = np.array([vx0,vy0])
r[0] = r0
v[0] = v0
# Start integrating using the Velocity-Verlet method
for i in range(n-1):
# Set up the acceleration
a = -r[i]*omega02
# update velocity, time and position using the Velocity-Verlet method
r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a
anew = -r[i+1]*omega02
v[i+1] = v[i] + 0.5*DeltaT*(a+anew)
t[i+1] = t[i] + DeltaT
# Plot position as function of time
radius = np.sqrt(r[:,0]**2+r[:,1]**2)
fig, ax = plt.subplots(3,1)
ax[0].set_xlabel('time')
ax[0].set_ylabel('radius squared')
ax[0].plot(t,r[:,0]**2+r[:,1]**2)
ax[1].set_xlabel('time')
ax[1].set_ylabel('x position')
ax[1].plot(t,r[:,0])
ax[2].set_xlabel('time')
ax[2].set_ylabel('y position')
ax[2].plot(r[:,0],r[:,1])
fig.tight_layout()
save_fig("2DimHOVV")
plt.show()
```
We see that the radius (to within a given error), we obtain a constant radius.
The following code shows first how we can solve this problem using the radial degrees of freedom only.
Here we need to add the explicit centrifugal barrier. Note that the variable $r$ depends only on time. There is no $x$ and $y$ directions
since we have transformed the equations to polar coordinates.
```python
DeltaT = 0.00001
#set up arrays
tfinal = 5.0
n = ceil(tfinal/DeltaT)
# set up arrays for t, v and r
t = np.zeros(n)
v = np.zeros(n)
r = np.zeros(n)
E = np.zeros(n)
# Constants of the model
AngMom = 1.0 # The angular momentum
m = 1.0
k = 1.0
omega02 = k/m
alpha = 5
c1 = AngMom*AngMom/(m*m)
c2 = AngMom*AngMom/m
rmin = 1.0# (AngMom*AngMom/k/m)**0.25
# Initial conditions
r0 = rmin
v0 = 0.0
r[0] = r0
v[0] = v0
E[0] = 0.5*m*v0*v0-0.5*alpha/(r0**2)+0.5*c2/(r0*r0)
# Start integrating using the Velocity-Verlet method
for i in range(n-1):
# Set up acceleration
a = -alpha/(r[i]**3)+c1/(r[i]**3)
# update velocity, time and position using the Velocity-Verlet method
r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a
anew = -alpha/(r[i+1]**3)+c1/(r[i+1]**3)
v[i+1] = v[i] + 0.5*DeltaT*(a+anew)
t[i+1] = t[i] + DeltaT
E[i+1] = 0.5*m*v[i+1]*v[i+1]-0.5*alpha/(r[i+1]**2)+0.5*c2/(r[i+1]*r[i+1])
# Plot position as function of time
#fig, ax = plt.subplots(2,1)
#ax[0].set_xlabel('time')
#ax[0].set_ylabel('radius')
#ax[0].plot(t,r)
#plt.set_xlabel('time')
#plt.set_ylabel('Energy')
plt.plot(t,E)
save_fig("RadialHOVV")
plt.show()
```
### Exercise 4, equations for an ellipse (10pt)
Consider an ellipse defined by the sum of the distances from the two foci being $2D$, which expressed in a Cartesian coordinates with the middle of the ellipse being at the origin becomes
$$
\sqrt{(x-a)^2+y^2}+\sqrt{(x+a)^2+y^2}=2D.
$$
Here the two foci are at $(a,0)$ and $(-a,0)$. Show that this form is can be written as
$$
\frac{x^2}{D^2}+\frac{y^2}{D^2-a^2}=1.
$$
We start by squaring the two sides and, again, after some **exciting algebraic manipulations** we arrive at
$$
\sqrt{(x-a)^2+y^2}+\sqrt{(x+a)^2+y^2} =2D
\\ (x-a)^2 + y^2 + (x+a)^2 + y^2 + 2\sqrt{(x-a)^2 + y^2}\sqrt{(x+a)^2+y^2} = 4D^2
\\ 2y^2 + 2x^2 + 2a^2 + 2\sqrt{(x-a)^2(x+a)^2 + y^4 + y^2[(x-a)^2+(x+a)^2]} = 4D^2
\\ y^2 + x^2 + a^2 + \sqrt{(x^2-a^2)^2 + y^4 + y^2(2x^2+2a^2)} = 2D^2
\\ \sqrt{(x^2-a^2)^2 + y^4 + y^2(2x^2+2a^2)} = 2D^2 -( y^2 + x^2 + a^2 )
\\ (x^2-a^2)^2 + y^4 + y^2(2x^2+2a^2) = 4D^4 + y^4 + x^4 + a^4 - 4D^2( y^2 + x^2 + a^2 ) + 2(y^2x^2+y^2a^2+x^2a^2)
\\ x^4-2x^2a^2+a^4 + y^4 + 2y^2x^2+2y^2a^2 = 4D^4 + y^4 + x^4 + a^4 - 4D^2y^2 -4D^2 x^2 -4D^2 a^2 + 2y^2x^2+2y^2a^2+2x^2a^2
\\ 4D^4 - 4D^2y^2 -4D^2 x^2 -4D^2 a^2 +4x^2a^2 = 0
\\ D^4 - D^2y^2 -D^2 x^2 -D^2 a^2 +x^2a^2 = 0
\\ D^2(D^2-a^2) - x^2(D^2-a^2) = D^2y^2
\\ D^2 - x^2 = \frac{D^2y^2}{D^2-a^2}
\\ 1 - \frac{x^2}{D^2} = \frac{y^2}{D^2-a^2}
\\ \frac{x^2}{D^2} + \frac{y^2}{D^2-a^2} = 1,
$$
where the last line is indeed the equation for an ellipse.
|
[STATEMENT]
lemma totalize_Constrains_iff [simp]: "(totalize F \<in> A Co B) = (F \<in> A Co B)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (totalize F \<in> A Co B) = (F \<in> A Co B)
[PROOF STEP]
by (simp add: Constrains_def) |
! { dg-do run }
program foo
real, parameter :: x(3) = 2.0 * [real :: 1, 2, 3 ]
if (any(x /= [2., 4., 6.])) STOP 1
end program foo
|
Formal statement is: lemma numeral_power_int_eq_of_real_cancel_iff [simp]: "power_int (numeral x) n = (of_real y :: 'a :: {real_div_algebra, division_ring}) \<longleftrightarrow> power_int (numeral x) n = y" Informal statement is: If $x$ is a numeral and $y$ is a real number, then $x^n = y$ if and only if $x^n = y$. |
#include <stdlib.h>
#include <stdio.h>
//#define VERY_VERBOSE
#define MSG(x) { printf(x); fflush(stdout); }
#define MSGF(x) { printf x ; fflush(stdout); }
#include "buffer.h"
static void test_buffer()
{
}
#include "array.h"
static void test_array()
{
int k;
const int * p;
const int * q;
OLIO_ARRAY_STACK(st, int, 64);
olio_array * hp;
OLIO_ARRAY_ALLOC(hp, int, 0);
printf("[testing array...]\n"); fflush(stdout);
MSGF(("st %u\n", st->base.allocated));
MSGF(("hp %u\n", hp->base.allocated));
#define ARRAY_COUNT 1000
MSG("appending to arrays...\n");
for (k = 0; k < ARRAY_COUNT; k++) {
olio_array_append(st, &k, 1);
olio_array_append(hp, &k, 1);
}
MSG("prepending to arrays...\n");
for (k = 0; k < ARRAY_COUNT; k++) {
olio_array_prepend(st, &k, 1);
olio_array_prepend(hp, &k, 1);
}
MSG("inserting to arrays...\n");
for (k = 0; k <= ARRAY_COUNT * 2; k++) {
olio_array_insert(st, k * 2, &k, 1);
olio_array_insert(hp, k * 2, &k, 1);
}
MSG("checking array contents...\n");
p = olio_array_contents(st);
q = olio_array_contents(hp);
for (k = 0; k < ARRAY_COUNT; k++) {
if (p[k * 2 + 1] != ARRAY_COUNT - 1 - k ||
p[k * 2 + 1 + ARRAY_COUNT * 2] != k)
MSG("ERROR: odd numbered stack item not as expected\n");
if (p[k * 2] != k ||
p[k * 2 + ARRAY_COUNT * 2] != k + ARRAY_COUNT)
MSG("ERROR: even numbered stack item not as expected\n");
if (q[k * 2 + 1] != ARRAY_COUNT - 1 - k ||
q[k * 2 + 1 + ARRAY_COUNT * 2] != k)
MSG("ERROR: odd numbered heap item not as expected\n");
if (q[k * 2] != k ||
q[k * 2 + ARRAY_COUNT * 2] != k + ARRAY_COUNT)
MSG("ERROR: even numbered heap item not as expected\n");
}
if (p[ARRAY_COUNT * 4] != ARRAY_COUNT * 2)
MSG("ERROR: last item in stack array not as expected\n");
if (q[ARRAY_COUNT * 4] != ARRAY_COUNT * 2)
MSG("ERROR: last item in heap array not as expected\n");
#ifdef VERY_VERBOSE
for (k = 0; k < olio_array_length(st) ||
k < olio_array_length(hp); k++) {
MSGF(("%i: st % 4i hp % 4i\n", k,
(k < olio_array_length(st)) ? p[k] : -1,
(k < olio_array_length(hp)) ? q[k] : -1));
}
#endif
MSGF(("st %p = %p\n", st->base.data, st->stack));
MSGF(("hp %p = %p\n", hp->base.data, hp->stack));
MSG("freeing arrays...\n");
olio_array_free(st);
olio_array_free(hp);
}
#include "string.h"
static void test_string()
{
}
#include "graph.h"
static void test_graph()
{
int rc;
olio_graph g;
printf("[testing graph...]\n"); fflush(stdout);
printf("graph initialization...\n"); fflush(stdout);
olio_graph_init(&g, 10);
printf("graph setting edges...\n"); fflush(stdout);
olio_graph_set_edge(&g, 0, 1, 10);
olio_graph_set_edge(&g, 1, 2, 10);
printf("graph testing cyclic...\n"); fflush(stdout);
rc = olio_graph_acyclic(&g);
if (rc == 0) {
printf("ERROR: graph NOT acyclic\n"); fflush(stdout);
}
printf("graph setting edges...\n"); fflush(stdout);
olio_graph_set_edge(&g, 2, 0, 10);
MSG("graph testing cyclic...\n");
rc = olio_graph_acyclic(&g);
if (rc != 0) MSG("ERROR: graph NOT cyclic\n");
MSG("freeing graph...\n");
olio_graph_free(&g);
}
#include "skiplist.h"
static void test_skiplist()
{
uint32_t test_data[] = {0xf, 0x436, 0x53547, 0x65, 0x54, 0x5654, 0x8756, 0x8767};
olio_skiplist sk;
int i;
printf("sizeof(entry) = %li\n", sizeof(olio_skiplist_entry));
printf("sizeof(block) = %li\n", sizeof(olio_skiplist_block));
printf("sizeof(skiplist) = %li\n", sizeof(olio_skiplist));
olio_skiplist_init(&sk);
printf("adding...\n");
for (i = 0; i < sizeof(test_data) / sizeof(uint32_t); i++) {
int rv = olio_skiplist_add(&sk, test_data[i], (void*) test_data[i]);
printf("k: 0x%x, rv: %i\n", test_data[i], rv);
}
printf("searching...\n");
for (i = 0; i < sizeof(test_data) / sizeof(uint32_t); i++) {
void * d = olio_skiplist_find(&sk, test_data[i]);
printf("k: 0x%x, data: %p\n", test_data[i], d);
}
olio_skiplist_display(&sk);
printf("freeing...\n");
olio_skiplist_free(&sk);
olio_skiplist_display(&sk);
olio_skiplist_init(&sk);
printf("adding...\n");
for (i = 0; i < sizeof(test_data) / sizeof(uint32_t); i++) {
int rv = olio_skiplist_add(&sk, test_data[i], (void*) test_data[i]);
printf("k: 0x%x, rv: %i\n", test_data[i], rv);
}
printf("deleting...\n");
for (i = 0; i < sizeof(test_data) / sizeof(uint32_t); i++) {
void * d;
int rv = olio_skiplist_remove(&sk, test_data[i], &d);
printf("k: 0x%x, rv: %i, data: %p\n", test_data[i], rv, d);
olio_skiplist_display(&sk);
}
printf("freeing...\n");
olio_skiplist_free(&sk);
olio_skiplist_display(&sk);
}
#include "error.h"
static void test_error()
{
}
#ifdef HAVE_GSL
#include <gsl/gsl_rng.h>
#include "random.h"
gsl_rng * gsl;
olio_random olio;
static void test_random()
{
uint32_t seed;
uint32_t a, b;
long i;
printf("[testing random...]\n"); fflush(stdout);
gsl = gsl_rng_alloc(gsl_rng_mt19937);
//for (seed = 0; seed < 1000; seed++)
{
seed = 0;
gsl_rng_set(gsl, 0);
olio_random_set_seed(&olio, 4357);
for (i = 0; i < 10000; i++) {
a = gsl_rng_uniform_int(gsl, 0xffffffff);
b = olio_random_integer(&olio);
if (a != b) {
printf("mismatch\n");
}
}
}
gsl_rng_free(gsl);
}
#else
static void test_random() {}
#endif
#include "phash.h"
#include "hash.h"
static void test_hashes()
{
unsigned long i;
const char * s[] = {
"alpha", "beta", "gamma", "delta", "epsilon",
"lamda", "mu", "nu", "omicron", "pi", "phi", "psi",
"tau", "theta", "zeta", NULL
};
olio_phash_build m;
int rc;
printf("[testing hashes...]\n"); fflush(stdout);
rc = olio_phash_init(&m, NULL);
if (rc == -1) {
printf("error, aborting\n");
exit(1);
}
for (i = 0; s[i] != NULL; i++) {
rc = olio_phash_add_entry(&m, s[i], strlen(s[i]), i * 1000);
if (rc == -1) {
printf("error, aborting\n");
exit(1);
}
}
rc = olio_phash_generate(&m, 1000, 1);
if (rc < 0) {
printf("error, aborting\n");
exit(1);
}
if (rc > 0) {
printf("failed to generate with attempt/extra limits\n");
exit(1);
}
printf("phash generated:\n");
printf("A hash: %08x\nB hash: %08x\nG size: %u\n",
m.phash->a_hash_seed, m.phash->b_hash_seed,
m.phash->g_table_size);
printf("{ ");
for (i = 0; i < m.phash->g_table_size; i++) {
int16_t * gv = (int16_t *) m.phash->data;
printf("%i, ", gv[i]);
}
printf("}\n");
for (i = 0; s[i] != NULL; i++) {
int32_t v = olio_phash_value(m.phash,
s[i], strlen(s[i]));
printf(" %s -> %li\n",
s[i], v);
}
olio_phash_free(&m);
}
#include "varint.h"
static void test_varint_sub(uint32_t x, uint8_t bytes_expected)
{
uint32_t a;
uint8_t storage[5];
uint8_t bytes_set, bytes_get;
uint8_t i;
bytes_set = olio_varint_set(x, storage);
a = olio_varint_get(storage, &bytes_get);
if (a != x || bytes_set != bytes_get || bytes_set != bytes_expected)
{
printf("x = %lu\n(%u) 0x", x, bytes_set);
for (i = 0; i < bytes_set; i++)
printf("%02x", storage[i]);
printf("\na = %lu\n(%u)\n\n", a, bytes_get);
}
}
static void test_varint()
{
printf("[testing varint...]\n"); fflush(stdout);
test_varint_sub(0, 1);
test_varint_sub(1,1);
test_varint_sub(127, 1);
test_varint_sub(200, 2);
test_varint_sub(32000, 3);
test_varint_sub(32000000, 3);
test_varint_sub(100000000, 4);
test_varint_sub(400000000, 5);
test_varint_sub(0, 1);
test_varint_sub(1, 1);
}
int main(int argv, char ** argc)
{
test_buffer();
test_array();
test_string();
test_graph();
test_skiplist();
test_error();
test_random();
test_hashes();
test_varint();
}
|
[STATEMENT]
lemma concat_replicate_trivial[simp]:
"concat (replicate i []) = []"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. concat (replicate i []) = []
[PROOF STEP]
by (induct i) (auto simp add: map_replicate_const) |
# Variational Bayesian Probabilistic Matrix Factorization
#
# Reference
# ----------
# Lim, Yew Jin, and Yee Whye Teh. "Variational Bayesian approach to movie rating prediction."
# Proceedings of KDD cup and workshop. Vol. 7. 2007.
#
mutable struct VBPMFModel
M::Array
I::Int64
J::Int64
n::Int64
L::Int64
U::Array
V::Array
τ²::Float64
σ²::Array
ρ²::Array
end
function fit(model::VBPMFModel)
M = model.M = model.M[sortperm(model.M[:, 1]), :]
n = model.n
I = model.I
J = model.J
K = size(M)[1]
Ψ = zeros(n, n, J)
model.σ² = ones(n)
model.ρ² = ones(n)
model.U = rand(I, n)
model.V = rand(J, n)
#1.nitialize Sj and tj for j = 1,...,J:
S, t = initialize_S_t(model, n, J)
for l = 1:model.L
#2. Update Q(ui) for i = 1,...,I:
model.U, S, t, τ²_tmp, σ²_tmp = update_U(model, Ψ, S, t, I)
#3. Update Q(vj) for j = 1,...,J:
model.V, Ψ, ρ²_tmp = update_V(model, Ψ, S, t, J)
#update Learning the Variances
model.σ², model.ρ², model.τ² = update_learning_variances(model, I, J, K, σ²_tmp, ρ²_tmp, τ²_tmp)
end
end
function initialize_S_t(model::VBPMFModel, n, J)
S = zeros(n, n, J)
for j = 1:J
S[:, :, j] = one(zeros(n, n))
end
t = zeros(J, n)
return(S, t)
end
function update_U(model::VBPMFModel, Ψ, S, t, I)
n = model.n
M = model.M
U = model.U
V = model.V
τ² = model.τ²
σ² = model.σ²
τ²_tmp = 0
σ²_tmp = zeros(n)
σ²_matrix = one(zeros(n, n)) .* (1 ./ σ²)
for i = 1:I
#(a) Compute Φi and ui:
N_i = M[M[:, 1] .== i - 1, :] #user's rate item
N_i[:, 1:2] .+= 1 #index start 1
Φ = inv(σ²_matrix + sum((Ψ[:, :, N_i[:, 2]] .+ mean(V[N_i[:, 2], :], dims = 1)' * mean(V[N_i[:, 2], :], dims = 1)) / τ², dims = 3)[:, :, 1])
u = Φ * sum((N_i[:, 3]' * V[N_i[:, 2], :]) / τ², dims = 1)'
U[i, :] = u
σ²_tmp = σ²_tmp + diag(Φ)
#(b) Update Sj and tj for j ∈ N(i), and discard Φi:
idx = 1
for j = N_i[:, 2]
S[:, :, j] = S[:, :, j] + (Φ + U[i, :] * U[i, :]') / τ²
t[j, :] = t[j, :] + ((N_i[idx, 3] * U[i, :]') / τ²)'
τ²_tmp = τ²_tmp + (N_i[idx, 3] ^ 2) - (2 * N_i[idx, 3] * (U[i, :]' * V[j, :])) + tr((Φ + U[i, :] * U[i, :]') * (Ψ[:, :, j] + V[j, :] * V[j, :]'))
idx = idx + 1
end
end
σ²_tmp = σ²_tmp + (mean(U, dims =1) .^ 2)'
return(U, S, t, τ²_tmp, σ²_tmp)
end
function update_V(model::VBPMFModel, Ψ, S, t, J)
V = zeros(J, model.n)
ρ²_tmp = 0
#3. Update Q(vj) for j = 1,...,J:
for j = 1:J
Ψ[:, :, j] = inv(S[:, :, j])
V[j, :] = (Ψ[:, :, j] * t[j, :])'
ρ²_tmp = ρ²_tmp .+ diag(Ψ[:, :, j])
end
ρ²_tmp = ρ²_tmp + (mean(V, dims =1) .^ 2)'
return(V, Ψ, ρ²_tmp)
end
function update_learning_variances(model::VBPMFModel, I, J, K, σ²_tmp, ρ²_tmp, τ²_tmp)
σ² = (1/(I - 1)) * σ²_tmp
ρ² = (1/(J- 1)) * ρ²_tmp
τ² = (1/(K - 1)) * τ²_tmp
return(σ², ρ² , τ²)
end
function predict(model::VBPMFModel, new_data)
R_p = model.U * model.V'
r = zeros(size(new_data)[1])
for i in 1:size(new_data)[1]
r[i] = R_p[new_data[i, 1] + 1, new_data[i, 2] + 1]
end
return r
end
|
Require Import Coq.Program.Basics.
Require Import Coq.Logic.FunctionalExtensionality.
Require Import Coq.Program.Combinators.
Require Import omega.Omega.
Require Import Setoid.
Require Import ZArith.
Require Import FinProof.Common.
Require Import FinProof.CommonInstances.
Require Import FinProof.StateMonad2.
Require Import FinProof.StateMonadInstances.
Require Import FinProof.ProgrammingWith.
Local Open Scope struct_scope.
Require Import FinProof.CommonProofs.
Require Import depoolContract.ProofEnvironment.
Require Import depoolContract.DePoolClass.
Require Import depoolContract.SolidityNotations.
Require Import depoolContract.DePoolFunc.
Module DePoolFuncs := DePoolFuncs XTypesSig StateMonadSig.
Import DePoolFuncs.
Import DePoolSpec.
Import LedgerClass.
Require Import depoolContract.Lib.CommonModelProofs.
Module CommonModelProofs := CommonModelProofs StateMonadSig.
Import CommonModelProofs.
Require Import depoolContract.Lib.Tactics.
Require Import depoolContract.Lib.ErrorValueProofs.
(*Require Import depoolContract.Lib.CommonCommon.*)
(* Require Import depoolContract.Lib.tvmFunctionsProofs. *)
Import DePoolSpec.LedgerClass.SolidityNotations.
Local Open Scope struct_scope.
Local Open Scope Z_scope.
Local Open Scope solidity_scope.
Require Import Lists.List.
Import ListNotations.
Local Open Scope list_scope.
Set Typeclasses Iterative Deepening.
Set Typeclasses Depth 100.
Require Export depoolContract.Scenarios.Common.CommonDefinitions.
Require Export depoolContract.Scenarios.Common.RoundDefinitions.
Definition _participantCorrectPositive (p : DePoolLib_ι_Participant) :=
0 <= DePoolLib_ι_Participant_ι_roundQty p /\
0 <= DePoolLib_ι_Participant_ι_reward p /\
0 <= DePoolLib_ι_Participant_ι_withdrawValue p.
Definition participantCorrectLocally (p : DePoolLib_ι_Participant) :=
_participantCorrectPositive p.
Definition _participantCorrectlyExists (l : Ledger) (p : DePoolLib_ι_Participant) :=
(participantIn l p /\ 0 < DePoolLib_ι_Participant_ι_roundQty p) \/
(participantOut l p /\ 0 = DePoolLib_ι_Participant_ι_roundQty p).
Definition _participantInRound (l : Ledger) (p : DePoolLib_ι_Participant) :=
participantIn l p <->
(exists r addr, roundIn l r /\ addrInRound l r addr /\
isSome (eval_state ( ParticipantBase_Ф_fetchParticipant addr) l) = true).
Definition participantCorrectGlobally (l : Ledger) :=
forall p,
participantIn l p ->
(
participantCorrectLocally p /\
_participantCorrectlyExists l p /\
_participantInRound l p
). |
input := FileTools:-Text:-ReadFile("AoC-2021-17-input.txt" ):
|
struct TypeListItem{TThis, TNext} end
struct EmptyTypeList end
const TypeList = Union{EmptyTypeList, TypeListItem}
encode() = EmptyTypeList
encode(t) = TypeListItem{t, EmptyTypeList}
encode(t, ts...) = TypeListItem{t, encode(ts...)}
decode(t::Tuple) = t
decode(::Type{EmptyTypeList}) = ()
decode(::Type{TypeListItem{TThis, EmptyTypeList}}) where TThis = (TThis,)
decode(::Type{TypeListItem{TThis, TNext}}) where {TThis, TNext} = (TThis, decode(TNext)...)
Base.length(::Type{EmptyTypeList}) = 0
function Base.length(::Type{TypeListItem{TThis, TNext}}) where {TThis, TNext}
return 1 + length(TNext)
end
Base.findfirst(::Type, ::Type{EmptyTypeList}) = nothing
function Base.findfirst(t::Type, ::Type{TypeListItem{TThis, TNext}}) where {TThis, TNext}
t == TThis && return 1
tailidx = findfirst(t, TNext)
return isnothing(tailidx) ? nothing : tailidx + 1
end
pretty(::Type{TypeListItem{TThis, TNext}}) where {TThis, TNext} = begin
return "$(TThis), " * pretty(TNext)
end
pretty(::Type{EmptyTypeList}) = ""
|
(* Title: Subcategory
Author: Eugene W. Stark <[email protected]>, 2017
Maintainer: Eugene W. Stark <[email protected]>
*)
chapter "Subcategory"
text\<open>
In this chapter we give a construction of the subcategory of a category
defined by a predicate on arrows subject to closure conditions. The arrows of
the subcategory are directly identified with the arrows of the ambient category.
We also define the related notions of full subcategory and inclusion functor.
\<close>
theory Subcategory
imports Functor
begin
locale subcategory =
C: category C
for C :: "'a comp" (infixr "\<cdot>\<^sub>C" 55)
and Arr :: "'a \<Rightarrow> bool" +
assumes inclusion: "Arr f \<Longrightarrow> C.arr f"
and dom_closed: "Arr f \<Longrightarrow> Arr (C.dom f)"
and cod_closed: "Arr f \<Longrightarrow> Arr (C.cod f)"
and comp_closed: "\<lbrakk> Arr f; Arr g; C.cod f = C.dom g \<rbrakk> \<Longrightarrow> Arr (g \<cdot>\<^sub>C f)"
begin
no_notation C.in_hom ("\<guillemotleft>_ : _ \<rightarrow> _\<guillemotright>")
notation C.in_hom ("\<guillemotleft>_ : _ \<rightarrow>\<^sub>C _\<guillemotright>")
definition comp (infixr "\<cdot>" 55)
where "g \<cdot> f = (if Arr f \<and> Arr g \<and> C.cod f = C.dom g then g \<cdot>\<^sub>C f else C.null)"
interpretation partial_magma comp
proof
show "\<exists>!n. \<forall>f. n \<cdot> f = n \<and> f \<cdot> n = n"
proof
show 1: "\<forall>f. C.null \<cdot> f = C.null \<and> f \<cdot> C.null = C.null"
by (metis C.comp_null(1) C.ex_un_null comp_def)
show "\<And>n. \<forall>f. n \<cdot> f = n \<and> f \<cdot> n = n \<Longrightarrow> n = C.null"
using 1 C.ex_un_null by metis
qed
qed
lemma null_char [simp]:
shows "null = C.null"
proof -
have "\<forall>f. C.null \<cdot> f = C.null \<and> f \<cdot> C.null = C.null"
by (metis C.comp_null(1) C.ex_un_null comp_def)
thus ?thesis using ex_un_null by (metis comp_null(2))
qed
lemma ideI:
assumes "Arr a" and "C.ide a"
shows "ide a"
unfolding ide_def
using assms null_char C.ide_def comp_def by auto
lemma Arr_iff_dom_in_domain:
shows "Arr f \<longleftrightarrow> C.dom f \<in> domains f"
proof
show "C.dom f \<in> domains f \<Longrightarrow> Arr f"
using domains_def comp_def ide_def by fastforce
show "Arr f \<Longrightarrow> C.dom f \<in> domains f"
proof -
assume f: "Arr f"
have "ide (C.dom f)"
using f inclusion C.dom_in_domains C.has_domain_iff_arr C.domains_def
dom_closed ideI
by auto
moreover have "f \<cdot> C.dom f \<noteq> null"
using f comp_def dom_closed null_char inclusion C.comp_arr_dom by force
ultimately show ?thesis
using domains_def by simp
qed
qed
lemma Arr_iff_cod_in_codomain:
shows "Arr f \<longleftrightarrow> C.cod f \<in> codomains f"
proof
show "C.cod f \<in> codomains f \<Longrightarrow> Arr f"
using codomains_def comp_def ide_def by fastforce
show "Arr f \<Longrightarrow> C.cod f \<in> codomains f"
proof -
assume f: "Arr f"
have "ide (C.cod f)"
using f inclusion C.cod_in_codomains C.has_codomain_iff_arr C.codomains_def
cod_closed ideI
by auto
moreover have "C.cod f \<cdot> f \<noteq> null"
using f comp_def cod_closed null_char inclusion C.comp_cod_arr by force
ultimately show ?thesis
using codomains_def by simp
qed
qed
lemma arr_char:
shows "arr f \<longleftrightarrow> Arr f"
proof
show "Arr f \<Longrightarrow> arr f"
using arr_def comp_def Arr_iff_dom_in_domain Arr_iff_cod_in_codomain by auto
show "arr f \<Longrightarrow> Arr f"
proof -
assume f: "arr f"
obtain a where a: "a \<in> domains f \<or> a \<in> codomains f"
using f arr_def by auto
have "f \<cdot> a \<noteq> C.null \<or> a \<cdot> f \<noteq> C.null"
using a domains_def codomains_def null_char by auto
thus "Arr f"
using comp_def by metis
qed
qed
lemma arrI [intro]:
assumes "Arr f"
shows "arr f"
using assms arr_char by simp
lemma arrE [elim]:
assumes "arr f"
shows "Arr f"
using assms arr_char by simp
interpretation category comp
using comp_def null_char inclusion comp_closed dom_closed cod_closed
apply unfold_locales
apply auto[1]
apply (metis Arr_iff_dom_in_domain Arr_iff_cod_in_codomain arr_char arr_def emptyE)
proof -
fix f g h
assume gf: "seq g f" and hg: "seq h g"
show 1: "seq (h \<cdot> g) f"
using gf hg inclusion comp_closed comp_def by auto
show "(h \<cdot> g) \<cdot> f = h \<cdot> g \<cdot> f"
using gf hg 1 C.not_arr_null inclusion comp_def arr_char
by (metis (full_types) C.cod_comp C.comp_assoc)
next
fix f g h
assume hg: "seq h g" and hgf: "seq (h \<cdot> g) f"
show "seq g f"
using hg hgf comp_def null_char inclusion arr_char comp_closed
by (metis (full_types) C.dom_comp)
next
fix f g h
assume hgf: "seq h (g \<cdot> f)" and gf: "seq g f"
show "seq h g"
using hgf gf comp_def null_char arr_char comp_closed
by (metis C.seqE C.ext C.match_2)
qed
theorem is_category:
shows "category comp" ..
notation in_hom ("\<guillemotleft>_ : _ \<rightarrow> _\<guillemotright>")
lemma dom_simp [simp]:
assumes "arr f"
shows "dom f = C.dom f"
proof -
have "ide (C.dom f)"
using assms ideI
by (meson C.ide_dom arr_char dom_closed inclusion)
moreover have "f \<cdot> C.dom f \<noteq> null"
using assms inclusion comp_def null_char dom_closed not_arr_null C.comp_arr_dom arr_char
by auto
ultimately show ?thesis
using dom_eqI ext by blast
qed
lemma cod_simp [simp]:
assumes "arr f"
shows "cod f = C.cod f"
proof -
have "ide (C.cod f)"
using assms ideI
by (meson C.ide_cod arr_char cod_closed inclusion)
moreover have "C.cod f \<cdot> f \<noteq> null"
using assms inclusion comp_def null_char cod_closed not_arr_null C.comp_cod_arr arr_char
by auto
ultimately show ?thesis
using cod_eqI ext by blast
qed
lemma cod_char:
shows "cod f = (if arr f then C.cod f else C.null)"
using cod_simp cod_def arr_def by auto
lemma in_hom_char:
shows "\<guillemotleft>f : a \<rightarrow> b\<guillemotright> \<longleftrightarrow> arr a \<and> arr b \<and> arr f \<and> \<guillemotleft>f : a \<rightarrow>\<^sub>C b\<guillemotright>"
using inclusion arr_char cod_closed dom_closed
by (metis C.arr_iff_in_hom C.in_homE arr_iff_in_hom cod_simp dom_simp in_homE)
lemma ide_char:
shows "ide a \<longleftrightarrow> arr a \<and> C.ide a"
using ide_in_hom C.ide_in_hom in_hom_char by simp
lemma seq_char:
shows "seq g f \<longleftrightarrow> arr f \<and> arr g \<and> C.seq g f"
proof
show "arr f \<and> arr g \<and> C.seq g f \<Longrightarrow> seq g f"
using arr_char dom_char cod_char by (intro seqI, auto)
show "seq g f \<Longrightarrow> arr f \<and> arr g \<and> C.seq g f"
apply (elim seqE, auto)
using inclusion arr_char by auto
qed
lemma hom_char:
shows "hom a b = C.hom a b \<inter> Collect Arr"
proof
show "hom a b \<subseteq> C.hom a b \<inter> Collect Arr"
using in_hom_char by auto
show "C.hom a b \<inter> Collect Arr \<subseteq> hom a b"
using arr_char dom_char cod_char by force
qed
lemma comp_char:
shows "g \<cdot> f = (if arr f \<and> arr g \<and> C.seq g f then g \<cdot>\<^sub>C f else C.null)"
using arr_char comp_def comp_closed C.ext by force
lemma comp_simp:
assumes "seq g f"
shows "g \<cdot> f = g \<cdot>\<^sub>C f"
using assms comp_char seq_char by metis
lemma inclusion_preserves_inverse:
assumes "inverse_arrows f g"
shows "C.inverse_arrows f g"
using assms ide_char comp_simp arr_char
by (intro C.inverse_arrowsI, auto)
lemma iso_char:
shows "iso f \<longleftrightarrow> C.iso f \<and> arr f \<and> arr (C.inv f)"
proof
assume f: "iso f"
show "C.iso f \<and> arr f \<and> arr (C.inv f)"
proof -
have 1: "inverse_arrows f (inv f)"
using f inv_is_inverse by auto
have 2: "C.inverse_arrows f (inv f)"
using 1 inclusion_preserves_inverse by blast
moreover have "arr (inv f)"
using 1 iso_is_arr iso_inv_iso by blast
moreover have "inv f = C.inv f"
using 1 2 C.inv_is_inverse C.inverse_arrow_unique by blast
ultimately show ?thesis using f 2 iso_is_arr by auto
qed
next
assume f: "C.iso f \<and> arr f \<and> arr (C.inv f)"
show "iso f"
proof
have 1: "C.inverse_arrows f (C.inv f)"
using f C.inv_is_inverse by blast
show "inverse_arrows f (C.inv f)"
proof
have 2: "C.inv f \<cdot> f = C.inv f \<cdot>\<^sub>C f \<and> f \<cdot> C.inv f = f \<cdot>\<^sub>C C.inv f"
using f 1 comp_char by fastforce
have 3: "antipar f (C.inv f)"
using f C.seqE seqI by simp
show "ide (C.inv f \<cdot> f)"
using 1 2 3 ide_char apply (elim C.inverse_arrowsE) by simp
show "ide (f \<cdot> C.inv f)"
using 1 2 3 ide_char apply (elim C.inverse_arrowsE) by simp
qed
qed
qed
lemma inv_char:
assumes "iso f"
shows "inv f = C.inv f"
proof -
have "C.inverse_arrows f (inv f)"
proof
have 1: "inverse_arrows f (inv f)"
using assms iso_char inv_is_inverse by blast
show "C.ide (inv f \<cdot>\<^sub>C f)"
proof -
have "inv f \<cdot> f = inv f \<cdot>\<^sub>C f"
using assms 1 inv_in_hom iso_char [of f] comp_char [of "inv f" f] seq_char by auto
thus ?thesis
using 1 ide_char arr_char by force
qed
show "C.ide (f \<cdot>\<^sub>C inv f)"
proof -
have "f \<cdot> inv f = f \<cdot>\<^sub>C inv f"
using assms 1 inv_in_hom iso_char [of f] comp_char [of f "inv f"] seq_char by auto
thus ?thesis
using 1 ide_char arr_char by force
qed
qed
thus ?thesis using C.inverse_arrow_unique C.inv_is_inverse by blast
qed
end
sublocale subcategory \<subseteq> category comp
using is_category by auto
section "Full Subcategory"
locale full_subcategory =
C: category C
for C :: "'a comp"
and Ide :: "'a \<Rightarrow> bool" +
assumes inclusion: "Ide f \<Longrightarrow> C.ide f"
sublocale full_subcategory \<subseteq> subcategory C "\<lambda>f. C.arr f \<and> Ide (C.dom f) \<and> Ide (C.cod f)"
by (unfold_locales; simp)
context full_subcategory
begin
text \<open>
Isomorphisms in a full subcategory are inherited from the ambient category.
\<close>
lemma iso_char:
shows "iso f \<longleftrightarrow> arr f \<and> C.iso f"
proof
assume f: "iso f"
obtain g where g: "inverse_arrows f g" using f by blast
show "arr f \<and> C.iso f"
proof -
have "C.inverse_arrows f g"
using g apply (elim inverse_arrowsE, intro C.inverse_arrowsI)
using comp_simp ide_char arr_char by auto
thus ?thesis
using f iso_is_arr by blast
qed
next
assume f: "arr f \<and> C.iso f"
obtain g where g: "C.inverse_arrows f g" using f by blast
have "inverse_arrows f g"
proof
show "ide (comp g f)"
using f g
by (metis (no_types, lifting) C.seqE C.ide_compE C.inverse_arrowsE
arr_char dom_simp ide_dom comp_def)
show "ide (comp f g)"
using f g C.inverse_arrows_sym [of f g]
by (metis (no_types, lifting) C.seqE C.ide_compE C.inverse_arrowsE
arr_char dom_simp ide_dom comp_def)
qed
thus "iso f" by auto
qed
end
section "Inclusion Functor"
text \<open>
If \<open>S\<close> is a subcategory of \<open>C\<close>, then there is an inclusion functor
from \<open>S\<close> to \<open>C\<close>. Inclusion functors are faithful embeddings.
\<close>
locale inclusion_functor =
C: category C +
S: subcategory C Arr
for C :: "'a comp"
and Arr :: "'a \<Rightarrow> bool"
begin
interpretation "functor" S.comp C S.map
using S.map_def S.arr_char S.inclusion S.dom_char S.cod_char
S.dom_closed S.cod_closed S.comp_closed S.arr_char S.comp_char
apply unfold_locales
apply auto[4]
by (elim S.seqE, auto)
lemma is_functor:
shows "functor S.comp C S.map" ..
interpretation faithful_functor S.comp C S.map
apply unfold_locales by simp
lemma is_faithful_functor:
shows "faithful_functor S.comp C S.map" ..
interpretation embedding_functor S.comp C S.map
apply unfold_locales by simp
end
sublocale inclusion_functor \<subseteq> faithful_functor S.comp C S.map
using is_faithful_functor by auto
sublocale inclusion_functor \<subseteq> embedding_functor S.comp C S.map
using is_embedding_functor by auto
text \<open>
The inclusion of a full subcategory is a special case.
Such functors are fully faithful.
\<close>
locale full_inclusion_functor =
C: category C +
S: full_subcategory C Ide
for C :: "'a comp"
and Ide :: "'a \<Rightarrow> bool"
sublocale full_inclusion_functor \<subseteq>
inclusion_functor C "\<lambda>f. C.arr f \<and> Ide (C.dom f) \<and> Ide (C.cod f)" ..
context full_inclusion_functor
begin
interpretation full_functor S.comp C S.map
apply unfold_locales
using S.ide_in_hom
by (metis (no_types, lifting) C.in_homE S.arr_char S.in_hom_char S.map_simp)
lemma is_full_functor:
shows "full_functor S.comp C S.map" ..
end
sublocale full_inclusion_functor \<subseteq> full_functor S.comp C S.map
using is_full_functor by auto
sublocale full_inclusion_functor \<subseteq> fully_faithful_functor S.comp C S.map ..
end
|
module Client.Action.Exec
import Client.Action.Build
import Fmt
import Inigo.Async.Base
import Inigo.Async.Package
import Inigo.Async.Promise
import Inigo.Package.CodeGen as CodeGen
import Inigo.Package.Package
import System.Path
execDir : String
execDir =
"build/exec"
-- TODO: Better handling of base paths
export
exec : CodeGen -> Bool -> List String -> Promise ()
exec codeGen build userArgs =
do
pkg <- Client.Action.Build.writeIPkgFile
when build $ runBuild codeGen
let Just e = executable pkg
| Nothing => reject "No executable set in Inigo config"
let (cmd, args) = CodeGen.cmdArgs codeGen (execDir </> e)
log (fmt "Executing %s with args %s..." e (show userArgs))
ignore $ systemWithStdIO cmd (args ++ userArgs) True True
|
using Random, Distributions, Plots
include_model("double_integrator")
T = 10
h = 1.0
u_dist = Distributions.MvNormal(zeros(model.m),
Diagonal(1.0e-1 * ones(model.m)))
u_hist = rand(u_dist, T-1)
x1 = [-1.0; 0.0]
x_hist = [x1]
for t = 1:T-1
w = zeros(model.d)
x⁺ = propagate_dynamics(model, x_hist[end], u_hist[t], w, h, t;
solver = :levenberg_marquardt,
tol_r = 1.0e-8, tol_d = 1.0e-6)
push!(x_hist, x⁺)
end
plot(hcat(x_hist...)')
plot(hcat(u_hist...)')
# LQR
A, B = get_dynamics(model)
Q = @SMatrix [1.0 0.0; 0.0 0.0]
R = @SMatrix [1.0]
function objective(x, u)
T = length(x)
J = 0.0
for t = 1:T
J += x[t]' * Q * x[t]
t < T & continue
J += u[t]' * R * u[t]
end
return J / T
end
K, P = tvlqr([A for t = 1:T-1], [B for t = 1:T-1],
[Q for t = 1:T], [R for t = 1:T-1])
K_vec = [vec(K[t]) for t = 1:T-1]
plot(hcat(K_vec...)')
K_inf = copy(K[1])
x1 = [-1.0; 0.0]
x_hist = [x1]
u_hist = []
for t = 1:T-1
w = zeros(model.d)
# push!(u_hist, -K[t] * x_hist[end])
push!(u_hist, -K_inf * x_hist[end])
x⁺ = propagate_dynamics(model, x_hist[end], u_hist[end], w, h, t;
solver = :levenberg_marquardt,
tol_r = 1.0e-8, tol_d = 1.0e-6)
push!(x_hist, x⁺)
end
plot(hcat(x_hist...)')
plot(hcat(u_hist...)')
J = objective(x_hist, u_hist) # 2.297419
# Gaussian policy
sigmoid(z) = 1.0 / (1.0 + exp(-z))
ds(z) = sigmoid(z) * (1.0 - sigmoid(z))
# plot(range(-10.0, stop = 10.0, length = 100), ds.(range(-10.0, stop = 10.0, length = 100)))
get_μ(θ, x) = θ[1:2]' * x
get_σ(θ, x) = ds(θ[3:4]' * x)
function policy(θ, x, a)
μ = get_μ(θ, x)
σ = get_σ(θ, x)
1.0 / (sqrt(2.0 * π) * σ) * exp(-0.5 * ((a - μ) / (σ))^2.0)
end
function rollout(θ, x1, model, T;
w = zeros(model.d))
# initialize trajectories
x_hist = [x1]
u_hist = []
∇logπ_hist = []
π_dist = []
for t = 1:T-1
# policy distribution
μ = get_μ(θ, x_hist[end])
σ = get_σ(θ, x_hist[end])
π_dist = Distributions.Normal(μ, σ)
# sample control
push!(u_hist, rand(π_dist, 1)[1])
# gradient of policy
logp(z) = log.(policy(z, x_hist[end], u_hist[end]))
push!(∇logπ_hist, ForwardDiff.gradient(logp, θ))
# step dynamics
x⁺ = propagate_dynamics(model, x_hist[end], u_hist[t], w, h, t;
solver = :levenberg_marquardt,
tol_r = 1.0e-8, tol_d = 1.0e-6)
push!(x_hist, x⁺)
end
# evalute trajectory cost
J = objective(x_hist, u_hist)
return x_hist, u_hist, ∇logπ_hist, J
end
θ = 0.1 * rand(m)
# rollout(θ, x1, model, T;
# w = zeros(model.d))
function reinforce(m, x1, model, T;
max_iter = 1,
batch_size = 1,
solver = :sgd,
J_avg_min = Inf)
Random.seed!(1)
# parameters
θ = 1.0e-5 * rand(m)
# cost history
J_hist = [1000.0]
J_avg = [1000.0]
if solver == :adam
# Adam
α = 0.0001
β1 = 0.9
β2 = 0.999
ϵ = 10.0^(-8.0)
mom = zeros(m)
vel = zeros(m)
else
# sgd
α = 1.0e-6
end
for i = 1:max_iter
∇logπ_hist = []
J = []
for j = 1:batch_size
_x_hist, _u_hist, _∇logπ_hist, _J = rollout(θ, copy(x1), model, T)
push!(∇logπ_hist, _∇logπ_hist)
push!(J, _J)
end
G = (1 / batch_size) .* sum([sum(g) for g in ∇logπ_hist]) .* (mean(J) - J_avg[end])#0.0 * x1' * P[1] * x1)
if solver == :adam
mom = β1 .* mom + (1.0 - β1) .* G
vel = β2 .* vel + (1.0 - β2) .* (G.^2.0)
m̂ = mom ./ (1.0 - β1^i)
v̂ = vel ./ (1.0 - β2^i)
θ .-= α * m̂ ./ (sqrt.(v̂) .+ ϵ)
else
θ .-= α * G
end
push!(J_hist, mean(J))
push!(J_avg, J_avg[end] + (mean(J) - J_avg[end]) / length(J_hist))
if J_avg[end] < J_avg_min
return θ, J_hist, J_avg
end
if i % 1000 == 0
println("i: $i")
println(" cost: $(mean(J))")
println(" cost (run. avg.): $(J_avg[end])")
end
end
return θ, J_hist, J_avg
end
θ, J, J_avg = reinforce(4, x1, model, T,
max_iter = 1e6,
batch_size = 10,
solver = :adam,
J_avg_min = 0.3)
plot(log.(J[1:100:end]), xlabel = "epoch (100 ep.)", label = "cost")
plot!(log.(J_avg[1:100:end]), xlabel = "epoch (100 ep.)", label = "cost (run. avg.)",
width = 2.0)
x_hist, = rollout(θ, x1, model, T)
include(joinpath(pwd(), "models/visualize.jl"))
vis = Visualizer()
render(vis)
visualize!(vis, model, x_hist, Δt = h)
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import data.bool tools.helper_tactics
open bool eq.ops decidable helper_tactics
namespace pos_num
theorem succ_not_is_one (a : pos_num) : is_one (succ a) = ff :=
pos_num.induction_on a rfl (take n iH, rfl) (take n iH, rfl)
theorem succ_one : succ one = bit0 one
theorem succ_bit1 (a : pos_num) : succ (bit1 a) = bit0 (succ a)
theorem succ_bit0 (a : pos_num) : succ (bit0 a) = bit1 a
theorem ne_of_bit0_ne_bit0 {a b : pos_num} (H₁ : bit0 a ≠ bit0 b) : a ≠ b :=
suppose a = b,
absurd rfl (this ▸ H₁)
theorem ne_of_bit1_ne_bit1 {a b : pos_num} (H₁ : bit1 a ≠ bit1 b) : a ≠ b :=
suppose a = b,
absurd rfl (this ▸ H₁)
theorem pred_succ : ∀ (a : pos_num), pred (succ a) = a
| one := rfl
| (bit0 a) := by rewrite succ_bit0
| (bit1 a) :=
calc
pred (succ (bit1 a)) = cond (is_one (succ a)) one (bit1 (pred (succ a))) : rfl
... = cond ff one (bit1 (pred (succ a))) : succ_not_is_one
... = bit1 (pred (succ a)) : rfl
... = bit1 a : pred_succ a
section
variables (a b : pos_num)
theorem one_add_one : one + one = bit0 one
theorem one_add_bit0 : one + (bit0 a) = bit1 a
theorem one_add_bit1 : one + (bit1 a) = succ (bit1 a)
theorem bit0_add_one : (bit0 a) + one = bit1 a
theorem bit1_add_one : (bit1 a) + one = succ (bit1 a)
theorem bit0_add_bit0 : (bit0 a) + (bit0 b) = bit0 (a + b)
theorem bit0_add_bit1 : (bit0 a) + (bit1 b) = bit1 (a + b)
theorem bit1_add_bit0 : (bit1 a) + (bit0 b) = bit1 (a + b)
theorem bit1_add_bit1 : (bit1 a) + (bit1 b) = succ (bit1 (a + b))
theorem one_mul : one * a = a
end
theorem mul_one : ∀ a, a * one = a
| one := rfl
| (bit1 n) :=
calc bit1 n * one = bit0 (n * one) + one : rfl
... = bit0 n + one : mul_one n
... = bit1 n : bit0_add_one
| (bit0 n) :=
calc bit0 n * one = bit0 (n * one) : rfl
... = bit0 n : mul_one n
theorem decidable_eq [instance] : ∀ (a b : pos_num), decidable (a = b)
| one one := inl rfl
| one (bit0 b) := inr (by contradiction)
| one (bit1 b) := inr (by contradiction)
| (bit0 a) one := inr (by contradiction)
| (bit0 a) (bit0 b) :=
match decidable_eq a b with
| inl H₁ := inl (by rewrite H₁)
| inr H₁ := inr (by intro H; injection H; contradiction)
end
| (bit0 a) (bit1 b) := inr (by contradiction)
| (bit1 a) one := inr (by contradiction)
| (bit1 a) (bit0 b) := inr (by contradiction)
| (bit1 a) (bit1 b) :=
match decidable_eq a b with
| inl H₁ := inl (by rewrite H₁)
| inr H₁ := inr (by intro H; injection H; contradiction)
end
local notation a < b := (lt a b = tt)
local notation a ` ≮ `:50 b:50 := (lt a b = ff)
theorem lt_one_right_eq_ff : ∀ a : pos_num, a ≮ one
| one := rfl
| (bit0 a) := rfl
| (bit1 a) := rfl
theorem lt_one_succ_eq_tt : ∀ a : pos_num, one < succ a
| one := rfl
| (bit0 a) := rfl
| (bit1 a) := rfl
theorem lt_of_lt_bit0_bit0 {a b : pos_num} (H : bit0 a < bit0 b) : a < b := H
theorem lt_of_lt_bit0_bit1 {a b : pos_num} (H : bit1 a < bit0 b) : a < b := H
theorem lt_of_lt_bit1_bit1 {a b : pos_num} (H : bit1 a < bit1 b) : a < b := H
theorem lt_of_lt_bit1_bit0 {a b : pos_num} (H : bit0 a < bit1 b) : a < succ b := H
theorem lt_bit0_bit0_eq_lt (a b : pos_num) : lt (bit0 a) (bit0 b) = lt a b :=
rfl
theorem lt_bit1_bit1_eq_lt (a b : pos_num) : lt (bit1 a) (bit1 b) = lt a b :=
rfl
theorem lt_bit1_bit0_eq_lt (a b : pos_num) : lt (bit1 a) (bit0 b) = lt a b :=
rfl
theorem lt_bit0_bit1_eq_lt_succ (a b : pos_num) : lt (bit0 a) (bit1 b) = lt a (succ b) :=
rfl
theorem lt_irrefl : ∀ (a : pos_num), a ≮ a
| one := rfl
| (bit0 a) :=
begin
rewrite lt_bit0_bit0_eq_lt, apply lt_irrefl
end
| (bit1 a) :=
begin
rewrite lt_bit1_bit1_eq_lt, apply lt_irrefl
end
theorem ne_of_lt_eq_tt : ∀ {a b : pos_num}, a < b → a = b → false
| one ⌞one⌟ H₁ (eq.refl one) := absurd H₁ ff_ne_tt
| (bit0 a) ⌞(bit0 a)⌟ H₁ (eq.refl (bit0 a)) :=
begin
rewrite lt_bit0_bit0_eq_lt at H₁,
apply ne_of_lt_eq_tt H₁ (eq.refl a)
end
| (bit1 a) ⌞(bit1 a)⌟ H₁ (eq.refl (bit1 a)) :=
begin
rewrite lt_bit1_bit1_eq_lt at H₁,
apply ne_of_lt_eq_tt H₁ (eq.refl a)
end
theorem lt_base : ∀ a : pos_num, a < succ a
| one := rfl
| (bit0 a) :=
begin
rewrite [succ_bit0, lt_bit0_bit1_eq_lt_succ],
apply lt_base
end
| (bit1 a) :=
begin
rewrite [succ_bit1, lt_bit1_bit0_eq_lt],
apply lt_base
end
theorem lt_step : ∀ {a b : pos_num}, a < b → a < succ b
| one one H := rfl
| one (bit0 b) H := rfl
| one (bit1 b) H := rfl
| (bit0 a) one H := absurd H ff_ne_tt
| (bit0 a) (bit0 b) H :=
begin
rewrite [succ_bit0, lt_bit0_bit1_eq_lt_succ, lt_bit0_bit0_eq_lt at H],
apply lt_step H
end
| (bit0 a) (bit1 b) H :=
begin
rewrite [succ_bit1, lt_bit0_bit0_eq_lt, lt_bit0_bit1_eq_lt_succ at H],
exact H
end
| (bit1 a) one H := absurd H ff_ne_tt
| (bit1 a) (bit0 b) H :=
begin
rewrite [succ_bit0, lt_bit1_bit1_eq_lt, lt_bit1_bit0_eq_lt at H],
exact H
end
| (bit1 a) (bit1 b) H :=
begin
rewrite [succ_bit1, lt_bit1_bit0_eq_lt, lt_bit1_bit1_eq_lt at H],
apply lt_step H
end
theorem lt_of_lt_succ_succ : ∀ {a b : pos_num}, succ a < succ b → a < b
| one one H := absurd H ff_ne_tt
| one (bit0 b) H := rfl
| one (bit1 b) H := rfl
| (bit0 a) one H :=
begin
rewrite [succ_bit0 at H, succ_one at H, lt_bit1_bit0_eq_lt at H],
apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H
end
| (bit0 a) (bit0 b) H := by exact H
| (bit0 a) (bit1 b) H := by exact H
| (bit1 a) one H :=
begin
rewrite [succ_bit1 at H, succ_one at H, lt_bit0_bit0_eq_lt at H],
apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff (succ a)) H
end
| (bit1 a) (bit0 b) H :=
begin
rewrite [succ_bit1 at H, succ_bit0 at H, lt_bit0_bit1_eq_lt_succ at H],
rewrite lt_bit1_bit0_eq_lt,
apply lt_of_lt_succ_succ H
end
| (bit1 a) (bit1 b) H :=
begin
rewrite [lt_bit1_bit1_eq_lt, *succ_bit1 at H, lt_bit0_bit0_eq_lt at H],
apply lt_of_lt_succ_succ H
end
theorem lt_succ_succ : ∀ {a b : pos_num}, a < b → succ a < succ b
| one one H := absurd H ff_ne_tt
| one (bit0 b) H :=
begin
rewrite [succ_bit0, succ_one, lt_bit0_bit1_eq_lt_succ],
apply lt_one_succ_eq_tt
end
| one (bit1 b) H :=
begin
rewrite [succ_one, succ_bit1, lt_bit0_bit0_eq_lt],
apply lt_one_succ_eq_tt
end
| (bit0 a) one H := absurd H ff_ne_tt
| (bit0 a) (bit0 b) H := by exact H
| (bit0 a) (bit1 b) H := by exact H
| (bit1 a) one H := absurd H ff_ne_tt
| (bit1 a) (bit0 b) H :=
begin
rewrite [succ_bit1, succ_bit0, lt_bit0_bit1_eq_lt_succ, lt_bit1_bit0_eq_lt at H],
apply lt_succ_succ H
end
| (bit1 a) (bit1 b) H :=
begin
rewrite [lt_bit1_bit1_eq_lt at H, *succ_bit1, lt_bit0_bit0_eq_lt],
apply lt_succ_succ H
end
theorem lt_of_lt_succ : ∀ {a b : pos_num}, succ a < b → a < b
| one one H := absurd_of_eq_ff_of_eq_tt !lt_one_right_eq_ff H
| one (bit0 b) H := rfl
| one (bit1 b) H := rfl
| (bit0 a) one H := absurd_of_eq_ff_of_eq_tt !lt_one_right_eq_ff H
| (bit0 a) (bit0 b) H := by exact H
| (bit0 a) (bit1 b) H :=
begin
rewrite [succ_bit0 at H, lt_bit1_bit1_eq_lt at H, lt_bit0_bit1_eq_lt_succ],
apply lt_step H
end
| (bit1 a) one H := absurd_of_eq_ff_of_eq_tt !lt_one_right_eq_ff H
| (bit1 a) (bit0 b) H :=
begin
rewrite [lt_bit1_bit0_eq_lt, succ_bit1 at H, lt_bit0_bit0_eq_lt at H],
apply lt_of_lt_succ H
end
| (bit1 a) (bit1 b) H :=
begin
rewrite [succ_bit1 at H, lt_bit0_bit1_eq_lt_succ at H, lt_bit1_bit1_eq_lt],
apply lt_of_lt_succ_succ H
end
theorem lt_of_lt_succ_of_ne : ∀ {a b : pos_num}, a < succ b → a ≠ b → a < b
| one one H₁ H₂ := absurd rfl H₂
| one (bit0 b) H₁ H₂ := rfl
| one (bit1 b) H₁ H₂ := rfl
| (bit0 a) one H₁ H₂ :=
begin
rewrite [succ_one at H₁, lt_bit0_bit0_eq_lt at H₁],
apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁
end
| (bit0 a) (bit0 b) H₁ H₂ :=
begin
rewrite [lt_bit0_bit0_eq_lt, succ_bit0 at H₁, lt_bit0_bit1_eq_lt_succ at H₁],
apply lt_of_lt_succ_of_ne H₁ (ne_of_bit0_ne_bit0 H₂)
end
| (bit0 a) (bit1 b) H₁ H₂ :=
begin
rewrite [succ_bit1 at H₁, lt_bit0_bit0_eq_lt at H₁, lt_bit0_bit1_eq_lt_succ],
exact H₁
end
| (bit1 a) one H₁ H₂ :=
begin
rewrite [succ_one at H₁, lt_bit1_bit0_eq_lt at H₁],
apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁
end
| (bit1 a) (bit0 b) H₁ H₂ :=
begin
rewrite [succ_bit0 at H₁, lt_bit1_bit1_eq_lt at H₁, lt_bit1_bit0_eq_lt],
exact H₁
end
| (bit1 a) (bit1 b) H₁ H₂ :=
begin
rewrite [succ_bit1 at H₁, lt_bit1_bit0_eq_lt at H₁, lt_bit1_bit1_eq_lt],
apply lt_of_lt_succ_of_ne H₁ (ne_of_bit1_ne_bit1 H₂)
end
theorem lt_trans : ∀ {a b c : pos_num}, a < b → b < c → a < c
| one b (bit0 c) H₁ H₂ := rfl
| one b (bit1 c) H₁ H₂ := rfl
| a (bit0 b) one H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂
| a (bit1 b) one H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂
| (bit0 a) (bit0 b) (bit0 c) H₁ H₂ :=
begin
rewrite lt_bit0_bit0_eq_lt at *, apply lt_trans H₁ H₂
end
| (bit0 a) (bit0 b) (bit1 c) H₁ H₂ :=
begin
rewrite [lt_bit0_bit1_eq_lt_succ at *, lt_bit0_bit0_eq_lt at H₁],
apply lt_trans H₁ H₂
end
| (bit0 a) (bit1 b) (bit0 c) H₁ H₂ :=
begin
rewrite [lt_bit0_bit1_eq_lt_succ at H₁, lt_bit1_bit0_eq_lt at H₂, lt_bit0_bit0_eq_lt],
apply @by_cases (a = b),
begin
intro H, rewrite -H at H₂, exact H₂
end,
begin
intro H,
apply lt_trans (lt_of_lt_succ_of_ne H₁ H) H₂
end
end
| (bit0 a) (bit1 b) (bit1 c) H₁ H₂ :=
begin
rewrite [lt_bit0_bit1_eq_lt_succ at *, lt_bit1_bit1_eq_lt at H₂],
apply lt_trans H₁ (lt_succ_succ H₂)
end
| (bit1 a) (bit0 b) (bit0 c) H₁ H₂ :=
begin
rewrite [lt_bit0_bit0_eq_lt at H₂, lt_bit1_bit0_eq_lt at *],
apply lt_trans H₁ H₂
end
| (bit1 a) (bit0 b) (bit1 c) H₁ H₂ :=
begin
rewrite [lt_bit1_bit0_eq_lt at H₁, lt_bit0_bit1_eq_lt_succ at H₂, lt_bit1_bit1_eq_lt],
apply @by_cases (b = c),
begin
intro H, rewrite H at H₁, exact H₁
end,
begin
intro H,
apply lt_trans H₁ (lt_of_lt_succ_of_ne H₂ H)
end
end
| (bit1 a) (bit1 b) (bit0 c) H₁ H₂ :=
begin
rewrite [lt_bit1_bit1_eq_lt at H₁, lt_bit1_bit0_eq_lt at H₂, lt_bit1_bit0_eq_lt],
apply lt_trans H₁ H₂
end
| (bit1 a) (bit1 b) (bit1 c) H₁ H₂ :=
begin
rewrite lt_bit1_bit1_eq_lt at *,
apply lt_trans H₁ H₂
end
theorem lt_antisymm : ∀ {a b : pos_num}, a < b → b ≮ a
| one one H := rfl
| one (bit0 b) H := rfl
| one (bit1 b) H := rfl
| (bit0 a) one H := absurd H ff_ne_tt
| (bit0 a) (bit0 b) H :=
begin
rewrite lt_bit0_bit0_eq_lt at *,
apply lt_antisymm H
end
| (bit0 a) (bit1 b) H :=
begin
rewrite lt_bit1_bit0_eq_lt,
rewrite lt_bit0_bit1_eq_lt_succ at H,
have H₁ : succ b ≮ a, from lt_antisymm H,
apply eq_ff_of_ne_tt,
intro H₂,
apply @by_cases (succ b = a),
show succ b = a → false,
begin
intro Hp,
rewrite -Hp at H,
apply absurd_of_eq_ff_of_eq_tt (lt_irrefl (succ b)) H
end,
show succ b ≠ a → false,
begin
intro Hn,
have H₃ : succ b < succ a, from lt_succ_succ H₂,
have H₄ : succ b < a, from lt_of_lt_succ_of_ne H₃ Hn,
apply absurd_of_eq_ff_of_eq_tt H₁ H₄
end,
end
| (bit1 a) one H := absurd H ff_ne_tt
| (bit1 a) (bit0 b) H :=
begin
rewrite lt_bit0_bit1_eq_lt_succ,
rewrite lt_bit1_bit0_eq_lt at H,
have H₁ : lt b a = ff, from lt_antisymm H,
apply eq_ff_of_ne_tt,
intro H₂,
apply @by_cases (b = a),
show b = a → false,
begin
intro Hp,
rewrite -Hp at H,
apply absurd_of_eq_ff_of_eq_tt (lt_irrefl b) H
end,
show b ≠ a → false,
begin
intro Hn,
have H₃ : b < a, from lt_of_lt_succ_of_ne H₂ Hn,
apply absurd_of_eq_ff_of_eq_tt H₁ H₃
end,
end
| (bit1 a) (bit1 b) H :=
begin
rewrite lt_bit1_bit1_eq_lt at *,
apply lt_antisymm H
end
local notation a ≤ b := (le a b = tt)
theorem le_refl : ∀ a : pos_num, a ≤ a :=
lt_base
theorem le_eq_lt_succ {a b : pos_num} : le a b = lt a (succ b) :=
rfl
theorem not_lt_of_le : ∀ {a b : pos_num}, a ≤ b → b < a → false
| one one H₁ H₂ := absurd H₂ ff_ne_tt
| one (bit0 b) H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂
| one (bit1 b) H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂
| (bit0 a) one H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at H₁, succ_one at H₁, lt_bit0_bit0_eq_lt at H₁],
apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁
end
| (bit0 a) (bit0 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at H₁, succ_bit0 at H₁, lt_bit0_bit1_eq_lt_succ at H₁],
rewrite [lt_bit0_bit0_eq_lt at H₂],
apply not_lt_of_le H₁ H₂
end
| (bit0 a) (bit1 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at H₁, succ_bit1 at H₁, lt_bit0_bit0_eq_lt at H₁],
rewrite [lt_bit1_bit0_eq_lt at H₂],
apply not_lt_of_le H₁ H₂
end
| (bit1 a) one H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at H₁, succ_one at H₁, lt_bit1_bit0_eq_lt at H₁],
apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁
end
| (bit1 a) (bit0 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at H₁, succ_bit0 at H₁, lt_bit1_bit1_eq_lt at H₁],
rewrite lt_bit0_bit1_eq_lt_succ at H₂,
have H₃ : a < succ b, from lt_step H₁,
apply @by_cases (b = a),
begin
intro Hba, rewrite -Hba at H₁,
apply absurd_of_eq_ff_of_eq_tt (lt_irrefl b) H₁
end,
begin
intro Hnba,
have H₄ : b < a, from lt_of_lt_succ_of_ne H₂ Hnba,
apply not_lt_of_le H₃ H₄
end
end
| (bit1 a) (bit1 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at H₁, succ_bit1 at H₁, lt_bit1_bit0_eq_lt at H₁],
rewrite [lt_bit1_bit1_eq_lt at H₂],
apply not_lt_of_le H₁ H₂
end
theorem le_antisymm : ∀ {a b : pos_num}, a ≤ b → b ≤ a → a = b
| one one H₁ H₂ := rfl
| one (bit0 b) H₁ H₂ :=
by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff b) H₂
| one (bit1 b) H₁ H₂ :=
by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff b) H₂
| (bit0 a) one H₁ H₂ :=
by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H₁
| (bit0 a) (bit0 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at *, succ_bit0 at *, lt_bit0_bit1_eq_lt_succ at *],
have H : a = b, from le_antisymm H₁ H₂,
rewrite H
end
| (bit0 a) (bit1 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at *, succ_bit1 at H₁, succ_bit0 at H₂],
rewrite [lt_bit0_bit0_eq_lt at H₁, lt_bit1_bit1_eq_lt at H₂],
apply false.rec _ (not_lt_of_le H₁ H₂)
end
| (bit1 a) one H₁ H₂ :=
by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H₁
| (bit1 a) (bit0 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at *, succ_bit0 at H₁, succ_bit1 at H₂],
rewrite [lt_bit1_bit1_eq_lt at H₁, lt_bit0_bit0_eq_lt at H₂],
apply false.rec _ (not_lt_of_le H₂ H₁)
end
| (bit1 a) (bit1 b) H₁ H₂ :=
begin
rewrite [le_eq_lt_succ at *, succ_bit1 at *, lt_bit1_bit0_eq_lt at *],
have H : a = b, from le_antisymm H₁ H₂,
rewrite H
end
theorem le_trans {a b c : pos_num} : a ≤ b → b ≤ c → a ≤ c :=
begin
intro H₁ H₂,
rewrite [le_eq_lt_succ at *],
apply @by_cases (a = b),
begin
intro Hab, rewrite Hab, exact H₂
end,
begin
intro Hnab,
have Haltb : a < b, from lt_of_lt_succ_of_ne H₁ Hnab,
apply lt_trans Haltb H₂
end,
end
end pos_num
namespace num
open pos_num
theorem decidable_eq [instance] : ∀ (a b : num), decidable (a = b)
| zero zero := inl rfl
| zero (pos b) := inr (by contradiction)
| (pos a) zero := inr (by contradiction)
| (pos a) (pos b) :=
if H : a = b then inl (by rewrite H) else inr (suppose pos a = pos b, begin injection this, contradiction end)
end num
|
/*
Copyright 2005-2007 Adobe Systems Incorporated
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).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/
/*************************************************************************************************/
#ifndef GIL_TIFF_DYNAMIC_IO_H
#define GIL_TIFF_DYNAMIC_IO_H
/// \file
/// \brief Support for reading and writing TIFF files
/// Requires libtiff!
/// \author Hailin Jin and Lubomir Bourdev \n
/// Adobe Systems Incorporated
/// \date 2005-2007 \n Last updated June 10, 2006
//
// We are currently providing the following functions:
// template <typename Images> void tiff_read_image(const char*,any_image<Images>)
// template <typename Views> void tiff_write_view(const char*,any_image_view<Views>)
//
#include <string>
#include <boost/mpl/bool.hpp>
#include "../dynamic_image/dynamic_image_all.hpp"
#include "io_error.hpp"
#include "tiff_io.hpp"
#include "dynamic_io.hpp"
namespace boost { namespace gil {
namespace detail {
struct tiff_write_is_supported {
template<typename View> struct apply
: public mpl::bool_<tiff_write_support<View>::is_supported> {};
};
class tiff_writer_dynamic : public tiff_writer {
public:
typedef void result_type;
tiff_writer_dynamic(const char* filename) : tiff_writer(filename) {}
template <typename Views>
void write_view(const any_image_view<Views>& runtime_view) {
dynamic_io_fnobj<tiff_write_is_supported, tiff_writer> op(this);
apply_operation(runtime_view,op);
}
};
class tiff_type_format_checker {
int _bit_depth;
int _color_type;
public:
tiff_type_format_checker(int bit_depth_in,int color_type_in) :
_bit_depth(bit_depth_in),_color_type(color_type_in) {}
template <typename Image>
bool apply() {
return tiff_read_support<typename Image::view_t>::bit_depth==_bit_depth &&
tiff_read_support<typename Image::view_t>::color_type==_color_type;
}
};
struct tiff_read_is_supported {
template<typename View> struct apply
: public mpl::bool_<tiff_read_support<View>::is_supported> {};
};
class tiff_reader_dynamic : public tiff_reader {
public:
tiff_reader_dynamic(const char* filename) : tiff_reader(filename) {}
template <typename Images>
void read_image(any_image<Images>& im) {
int width,height;
unsigned short bps,photometric;
TIFFGetField(_tp,TIFFTAG_IMAGEWIDTH,&width);
TIFFGetField(_tp,TIFFTAG_IMAGELENGTH,&height);
TIFFGetField(_tp,TIFFTAG_BITSPERSAMPLE,&bps);
TIFFGetField(_tp,TIFFTAG_PHOTOMETRIC,&photometric);
if (!construct_matched(im,tiff_type_format_checker(bps,photometric))) {
io_error("tiff_reader_dynamic::read_image(): no matching image type between those of the given any_image and that of the file");
} else {
im.recreate(width,height);
dynamic_io_fnobj<tiff_read_is_supported, tiff_reader> op(this);
apply_operation(view(im),op);
}
}
};
} // namespace detail
/// \ingroup TIFF_IO
/// \brief reads a TIFF image into a run-time instantiated image
/// Opens the given tiff file name, selects the first type in Images whose color space and channel are compatible to those of the image file
/// and creates a new image of that type with the dimensions specified by the image file.
/// Throws std::ios_base::failure if none of the types in Images are compatible with the type on disk.
template <typename Images>
inline void tiff_read_image(const char* filename,any_image<Images>& im) {
detail::tiff_reader_dynamic m(filename);
m.read_image(im);
}
/// \ingroup TIFF_IO
/// \brief reads a TIFF image into a run-time instantiated image
template <typename Images>
inline void tiff_read_image(const std::string& filename,any_image<Images>& im) {
tiff_read_image(filename.c_str(),im);
}
/// \ingroup TIFF_IO
/// \brief Saves the currently instantiated view to a tiff file specified by the given tiff image file name.
/// Throws std::ios_base::failure if the currently instantiated view type is not supported for writing by the I/O extension
/// or if it fails to create the file.
template <typename Views>
inline void tiff_write_view(const char* filename,const any_image_view<Views>& runtime_view) {
detail::tiff_writer_dynamic m(filename);
m.write_view(runtime_view);
}
/// \ingroup TIFF_IO
/// \brief Saves the currently instantiated view to a tiff file specified by the given tiff image file name.
template <typename Views>
inline void tiff_write_view(const std::string& filename,const any_image_view<Views>& runtime_view) {
tiff_write_view(filename.c_str(),runtime_view);
}
} } // namespace boost::gil
#endif
|
------------------------------------------------------------------------
-- "Equational" reasoning combinator setup
------------------------------------------------------------------------
{-# OPTIONS --safe #-}
open import Labelled-transition-system
-- Note that the module parameter is explicit. If the LTS is not given
-- explicitly, then the use of _[ μ ]⟶_ in the instances below can
-- make it hard for Agda to infer what instance to use.
module Labelled-transition-system.Equational-reasoning-instances
{ℓ} (lts : LTS ℓ) where
open import Prelude
open import Equational-reasoning
open LTS lts
private
-- Converts one kind of proof of silence to another kind.
get : ∀ {μ} → T (silent? μ) → Silent μ
get {μ} _ with silent? μ
get {μ} () | no _
get {μ} _ | yes s = s
instance
convert⟶ : ∀ {μ} → Convertible _[ μ ]⟶_ _[ μ ]⟶_
convert⟶ = is-convertible id
convert⟶⇒ : ∀ {μ} {s : T (silent? μ)} → Convertible _[ μ ]⟶_ _⇒_
convert⟶⇒ {s = s} = is-convertible (⟶→⇒ (get s))
convert⟶[]⇒ : ∀ {μ} → Convertible _[ μ ]⟶_ _[ μ ]⇒_
convert⟶[]⇒ = is-convertible ⟶→[]⇒
convert⟶⇒̂ : ∀ {μ} → Convertible _[ μ ]⟶_ _[ μ ]⇒̂_
convert⟶⇒̂ = is-convertible ⟶→⇒̂
convert⟶⟶̂ : ∀ {μ} → Convertible _[ μ ]⟶_ _[ μ ]⟶̂_
convert⟶⟶̂ = is-convertible ⟶→⟶̂
convert⇒ : Convertible _⇒_ _⇒_
convert⇒ = is-convertible id
convert⇒⇒̂ : ∀ {μ} {s : T (silent? μ)} → Convertible _⇒_ _[ μ ]⇒̂_
convert⇒⇒̂ {s = s} = is-convertible (silent (get s))
convert[]⇒ : ∀ {μ} → Convertible _[ μ ]⇒_ _[ μ ]⇒_
convert[]⇒ = is-convertible id
convert[]⇒⇒ : ∀ {μ} {s : T (silent? μ)} → Convertible _[ μ ]⇒_ _⇒_
convert[]⇒⇒ {s = s} = is-convertible ([]⇒→⇒ (get s))
convert[]⇒⇒̂ : ∀ {μ} → Convertible _[ μ ]⇒_ _[ μ ]⇒̂_
convert[]⇒⇒̂ = is-convertible ⇒→⇒̂
convert⇒̂ : ∀ {μ} → Convertible _[ μ ]⇒̂_ _[ μ ]⇒̂_
convert⇒̂ = is-convertible id
convert⇒̂⇒ : ∀ {μ} {s : T (silent? μ)} → Convertible _[ μ ]⇒̂_ _⇒_
convert⇒̂⇒ {s = s} = is-convertible (⇒̂→⇒ (get s))
convert⇒̂[]⇒ : ∀ {μ} {¬s : if (silent? μ) then ⊥ else ⊤} →
Convertible _[ μ ]⇒̂_ _[ μ ]⇒_
convert⇒̂[]⇒ {μ} with silent? μ
convert⇒̂[]⇒ {¬s = ()} | yes _
convert⇒̂[]⇒ | no ¬s = is-convertible (⇒̂→[]⇒ ¬s)
convert⟶̂ : ∀ {μ} → Convertible _[ μ ]⟶̂_ _[ μ ]⟶̂_
convert⟶̂ = is-convertible id
convert⟶̂⇒ : ∀ {μ} {s : T (silent? μ)} → Convertible _[ μ ]⟶̂_ _⇒_
convert⟶̂⇒ {s = s} = is-convertible (⟶̂→⇒ (get s))
convert⟶̂⇒̂ : ∀ {μ} → Convertible _[ μ ]⟶̂_ _[ μ ]⇒̂_
convert⟶̂⇒̂ = is-convertible ⟶̂→⇒̂
reflexive⇒ : Reflexive _⇒_
reflexive⇒ = is-reflexive done
reflexive⟶̂ : ∀ {μ} {s : T (silent? μ)} → Reflexive _[ μ ]⟶̂_
reflexive⟶̂ {s = s} = is-reflexive (done (get s))
reflexive⇒̂ : ∀ {μ} {s : T (silent? μ)} → Reflexive _[ μ ]⇒̂_
reflexive⇒̂ {s = s} = is-reflexive (silent (get s) done)
trans⇒ : Transitive _⇒_ _⇒_
trans⇒ = is-transitive ⇒-transitive
trans⟶⇒ : ∀ {μ} {s : T (silent? μ)} → Transitive _[ μ ]⟶_ _⇒_
trans⟶⇒ {s = s} = is-transitive (⇒-transitive ∘ ⟶→⇒ (get s))
trans⇒̂⇒ : ∀ {μ} {s : T (silent? μ)} → Transitive _[ μ ]⇒̂_ _⇒_
trans⇒̂⇒ {s = s} = is-transitive (⇒-transitive ∘ ⇒̂→⇒ (get s))
trans⟶̂⇒ : ∀ {μ} {s : T (silent? μ)} → Transitive _[ μ ]⟶̂_ _⇒_
trans⟶̂⇒ {s = s} = is-transitive (⇒-transitive ∘ ⟶̂→⇒ (get s))
trans⇒[]⇒ : ∀ {μ} → Transitive _⇒_ _[ μ ]⇒_
trans⇒[]⇒ = is-transitive ⇒[]⇒-transitive
trans⟶[]⇒ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive _[ μ′ ]⟶_ _[ μ ]⇒_
trans⟶[]⇒ {s = s} = is-transitive (⇒[]⇒-transitive ∘ ⟶→⇒ (get s))
trans[]⇒[]⇒ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive _[ μ′ ]⇒_ _[ μ ]⇒_
trans[]⇒[]⇒ {s = s} = is-transitive (⇒[]⇒-transitive ∘ []⇒→⇒ (get s))
trans⟶̂[]⇒ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive _[ μ′ ]⟶̂_ _[ μ ]⇒_
trans⟶̂[]⇒ {s = s} = is-transitive (⇒[]⇒-transitive ∘ ⟶̂→⇒ (get s))
trans⇒⇒̂ : ∀ {μ} → Transitive _⇒_ _[ μ ]⇒̂_
trans⇒⇒̂ = is-transitive ⇒⇒̂-transitive
trans⟶⇒̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive _[ μ′ ]⟶_ _[ μ ]⇒̂_
trans⟶⇒̂ {s = s} = is-transitive (⇒⇒̂-transitive ∘ ⟶→⇒ (get s))
trans[]⇒⇒̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive _[ μ′ ]⇒_ _[ μ ]⇒̂_
trans[]⇒⇒̂ {s = s} = is-transitive (⇒⇒̂-transitive ∘ []⇒→⇒ (get s))
trans[]⇒̂⇒̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive _[ μ′ ]⇒̂_ _[ μ ]⇒̂_
trans[]⇒̂⇒̂ {s = s} = is-transitive (⇒⇒̂-transitive ∘ ⇒̂→⇒ (get s))
trans⟶̂⇒̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive _[ μ′ ]⟶̂_ _[ μ ]⇒̂_
trans⟶̂⇒̂ {s = s} = is-transitive (⇒⇒̂-transitive ∘ ⟶̂→⇒ (get s))
trans′⇒⟶ : ∀ {μ} {s : T (silent? μ)} → Transitive′ _⇒_ _[ μ ]⟶_
trans′⇒⟶ {s = s} =
is-transitive (flip (flip ⇒-transitive ∘ ⟶→⇒ (get s)))
trans′⇒[]⇒ : ∀ {μ} {s : T (silent? μ)} → Transitive′ _⇒_ _[ μ ]⇒_
trans′⇒[]⇒ {s = s} =
is-transitive (flip (flip ⇒-transitive ∘ []⇒→⇒ (get s)))
trans′⇒⇒̂ : ∀ {μ} {s : T (silent? μ)} → Transitive′ _⇒_ _[ μ ]⇒̂_
trans′⇒⇒̂ {s = s} =
is-transitive (flip (flip ⇒-transitive ∘ ⇒̂→⇒ (get s)))
trans′⇒⟶̂ : ∀ {μ} {s : T (silent? μ)} → Transitive′ _⇒_ _[ μ ]⟶̂_
trans′⇒⟶̂ {s = s} =
is-transitive (flip (flip ⇒-transitive ∘ ⟶̂→⇒ (get s)))
trans′[]⇒⟶ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒_ _[ μ′ ]⟶_
trans′[]⇒⟶ {s = s} =
is-transitive (flip (flip []⇒⇒-transitive ∘ ⟶→⇒ (get s)))
trans′[]⇒⇒ : ∀ {μ} → Transitive′ _[ μ ]⇒_ _⇒_
trans′[]⇒⇒ = is-transitive []⇒⇒-transitive
trans′[]⇒[]⇒ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒_ _[ μ′ ]⇒_
trans′[]⇒[]⇒ {s = s} =
is-transitive (flip (flip []⇒⇒-transitive ∘ []⇒→⇒ (get s)))
trans′[]⇒[]⇒̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒_ _[ μ′ ]⇒̂_
trans′[]⇒[]⇒̂ {s = s} =
is-transitive (flip (flip []⇒⇒-transitive ∘ ⇒̂→⇒ (get s)))
trans′[]⇒⟶̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒_ _[ μ′ ]⟶̂_
trans′[]⇒⟶̂ {s = s} =
is-transitive (flip (flip []⇒⇒-transitive ∘ ⟶̂→⇒ (get s)))
trans′⇒̂⟶ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒̂_ _[ μ′ ]⟶_
trans′⇒̂⟶ {s = s} =
is-transitive (flip (flip ⇒̂⇒-transitive ∘ ⟶→⇒ (get s)))
trans′⇒̂⇒ : ∀ {μ} → Transitive′ _[ μ ]⇒̂_ _⇒_
trans′⇒̂⇒ = is-transitive ⇒̂⇒-transitive
trans′⇒̂[]⇒ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒̂_ _[ μ′ ]⇒_
trans′⇒̂[]⇒ {s = s} =
is-transitive (flip (flip ⇒̂⇒-transitive ∘ []⇒→⇒ (get s)))
trans′⇒̂⇒̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒̂_ _[ μ′ ]⇒̂_
trans′⇒̂⇒̂ {s = s} =
is-transitive (flip (flip ⇒̂⇒-transitive ∘ ⇒̂→⇒ (get s)))
trans′⇒̂⟶̂ : ∀ {μ μ′} {s : T (silent? μ′)} →
Transitive′ _[ μ ]⇒̂_ _[ μ′ ]⟶̂_
trans′⇒̂⟶̂ {s = s} =
is-transitive (flip (flip ⇒̂⇒-transitive ∘ ⟶̂→⇒ (get s)))
|
A fairly cold last half of January meant that I went through quite a bit of wood. Just to be safe, I had some replenishment delivered. I wonder will this satisfy the valentine desires for warmth and ambiance ? |
(* Import ListNotations. *)
(* Local Open Scope logic. *)
Require Import HMAC_functional_prog.
Require Import SHA256.
Lemma mkKey_length l: length (HMAC_SHA256.mkKey l) = SHA256_.BlockSize.
Proof. intros. unfold HMAC_SHA256.mkKey.
remember (Zlength l >? Z.of_nat SHA256_.BlockSize) as z.
destruct z. apply zeroPad_BlockSize.
rewrite length_SHA256'.
apply Nat2Z.inj_le. simpl. omega.
apply zeroPad_BlockSize.
rewrite Zlength_correct in Heqz.
apply Nat2Z.inj_le.
specialize (Zgt_cases (Z.of_nat (Datatypes.length l)) (Z.of_nat SHA256.BlockSize)). rewrite <- Heqz. trivial.
Qed. |
example : True := by
apply True.intro
--^ textDocument/hover
example : True := by
simp [True.intro]
--^ textDocument/hover
example (n : Nat) : True := by
match n with
| Nat.zero => _
--^ textDocument/hover
| n + 1 => _
|
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.nilpotent
import algebra.lie.cartan_subalgebra
/-!
# Engel's theorem
This file contains a proof of Engel's theorem providing necessary and sufficient conditions for Lie
algebras and Lie modules to be nilpotent.
The key result `lie_module.is_nilpotent_iff_forall` says that if `M` is a Lie module of a
Noetherian Lie algebra `L`, then `M` is nilpotent iff the image of `L → End(M)` consists of
nilpotent elements. In the special case that we have the adjoint representation `M = L`, this says
that a Lie algebra is nilpotent iff `ad x : End(L)` is nilpotent for all `x : L`.
Engel's theorem is true for any coefficients (i.e., it is really a theorem about Lie rings) and so
we work with coefficients in any commutative ring `R` throughout.
On the other hand, Engel's theorem is not true for infinite-dimensional Lie algebras and so a
finite-dimensionality assumption is required. We prove the theorem subject to the the assumption
that the Lie algebra is Noetherian as an `R`-module, though actually we only need the slightly
weaker property that the relation `>` is well-founded on the complete lattice of Lie subalgebras.
## Remarks about the proof
Engel's theorem is usually proved in the special case that the coefficients are a field, and uses
an inductive argument on the dimension of the Lie algebra. One begins by choosing either a maximal
proper Lie subalgebra (in some proofs) or a maximal nilpotent Lie subalgebra (in other proofs, at
the cost of obtaining a weaker end result).
Since we work with general coefficients, we cannot induct on dimension and an alternate approach
must be taken. The key ingredient is the concept of nilpotency, not just for Lie algebras, but for
Lie modules. Using this concept, we define an _Engelian Lie algebra_ `lie_algebra.is_engelian` to
be one for which a Lie module is nilpotent whenever the action consists of nilpotent endomorphisms.
The argument then proceeds by selecting a maximal Engelian Lie subalgebra and showing that it cannot
be proper.
The first part of the traditional statement of Engel's theorem consists of the statement that if `M`
is a non-trivial `R`-module and `L ⊆ End(M)` is a finite-dimensional Lie subalgebra of nilpotent
elements, then there exists a non-zero element `m : M` that is annihilated by every element of `L`.
This follows trivially from the result established here `lie_module.is_nilpotent_iff_forall`, that
`M` is a nilpotent Lie module over `L`, since the last non-zero term in the lower central series
will consist of such elements `m` (see: `lie_module.nontrivial_max_triv_of_is_nilpotent`). It seems
that this result has not previously been established at this level of generality.
The second part of the traditional statement of Engel's theorem concerns nilpotency of the Lie
algebra and a proof of this for general coefficients appeared in the literature as long ago
[as 1937](zorn1937). This also follows trivially from `lie_module.is_nilpotent_iff_forall` simply by
taking `M = L`.
It is pleasing that the two parts of the traditional statements of Engel's theorem are thus unified
into a single statement about nilpotency of Lie modules. This is not usually emphasised.
## Main definitions
* `lie_algebra.is_engelian`
* `lie_algebra.is_engelian_of_is_noetherian`
* `lie_module.is_nilpotent_iff_forall`
* `lie_algebra.is_nilpotent_iff_forall`
-/
universes u₁ u₂ u₃ u₄
variables {R : Type u₁} {L : Type u₂} {L₂ : Type u₃} {M : Type u₄}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L₂] [lie_algebra R L₂]
variables [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
include R L
namespace lie_submodule
open lie_module
variables {I : lie_ideal R L} {x : L} (hxI : (R ∙ x) ⊔ I = ⊤)
include hxI
lemma exists_smul_add_of_span_sup_eq_top (y : L) : ∃ (t : R) (z ∈ I), y = t • x + z :=
begin
have hy : y ∈ (⊤ : submodule R L) := submodule.mem_top,
simp only [← hxI, submodule.mem_sup, submodule.mem_span_singleton] at hy,
obtain ⟨-, ⟨t, rfl⟩, z, hz, rfl⟩ := hy,
exact ⟨t, z, hz, rfl⟩,
end
lemma lie_top_eq_of_span_sup_eq_top (N : lie_submodule R L M) :
(↑⁅(⊤ : lie_ideal R L), N⁆ : submodule R M) =
(N : submodule R M).map (to_endomorphism R L M x) ⊔ (↑⁅I, N⁆ : submodule R M) :=
begin
simp only [lie_ideal_oper_eq_linear_span', submodule.sup_span, mem_top, exists_prop,
exists_true_left, submodule.map_coe, to_endomorphism_apply_apply],
refine le_antisymm (submodule.span_le.mpr _) (submodule.span_mono (λ z hz, _)),
{ rintros z ⟨y, n, hn : n ∈ N, rfl⟩,
obtain ⟨t, z, hz, rfl⟩ := exists_smul_add_of_span_sup_eq_top hxI y,
simp only [set_like.mem_coe, submodule.span_union, submodule.mem_sup],
exact ⟨t • ⁅x, n⁆, submodule.subset_span ⟨t • n, N.smul_mem' t hn, lie_smul t x n⟩,
⁅z, n⁆, submodule.subset_span ⟨z, hz, n, hn, rfl⟩, by simp⟩, },
{ rcases hz with ⟨m, hm, rfl⟩ | ⟨y, hy, m, hm, rfl⟩,
exacts [⟨x, m, hm, rfl⟩, ⟨y, m, hm, rfl⟩], },
end
lemma lcs_le_lcs_of_is_nilpotent_span_sup_eq_top {n i j : ℕ} (hxn : (to_endomorphism R L M x)^n = 0)
(hIM : lower_central_series R L M i ≤ I.lcs M j) :
lower_central_series R L M (i + n) ≤ I.lcs M (j + 1) :=
begin
suffices : ∀ l, ((⊤ : lie_ideal R L).lcs M (i + l) : submodule R M) ≤
(I.lcs M j : submodule R M).map
((to_endomorphism R L M x)^l) ⊔ (I.lcs M (j + 1) : submodule R M),
{ simpa only [bot_sup_eq, lie_ideal.incl_coe, submodule.map_zero, hxn] using this n, },
intros l,
induction l with l ih,
{ simp only [add_zero, lie_ideal.lcs_succ, pow_zero, linear_map.one_eq_id, submodule.map_id],
exact le_sup_of_le_left hIM, },
{ simp only [lie_ideal.lcs_succ, i.add_succ l, lie_top_eq_of_span_sup_eq_top hxI, sup_le_iff],
refine ⟨(submodule.map_mono ih).trans _, le_sup_of_le_right _⟩,
{ rw [submodule.map_sup, ← submodule.map_comp, ← linear_map.mul_eq_comp, ← pow_succ,
← I.lcs_succ],
exact sup_le_sup_left coe_map_to_endomorphism_le _, },
{ refine le_trans (mono_lie_right _ _ I _) (mono_lie_right _ _ I hIM),
exact antitone_lower_central_series R L M le_self_add, }, },
end
lemma is_nilpotent_of_is_nilpotent_span_sup_eq_top
(hnp : is_nilpotent $ to_endomorphism R L M x) (hIM : is_nilpotent R I M) :
is_nilpotent R L M :=
begin
obtain ⟨n, hn⟩ := hnp,
unfreezingI { obtain ⟨k, hk⟩ := hIM, },
have hk' : I.lcs M k = ⊥,
{ simp only [← coe_to_submodule_eq_iff, I.coe_lcs_eq, hk, bot_coe_submodule], },
suffices : ∀ l, lower_central_series R L M (l * n) ≤ I.lcs M l,
{ use k * n,
simpa [hk'] using this k, },
intros l,
induction l with l ih,
{ simp, },
{ exact (l.succ_mul n).symm ▸ lcs_le_lcs_of_is_nilpotent_span_sup_eq_top hxI hn ih, },
end
end lie_submodule
section lie_algebra
open lie_module (hiding is_nilpotent)
variables (R L)
/-- A Lie algebra `L` is said to be Engelian if a sufficient condition for any `L`-Lie module `M` to
be nilpotent is that the image of the map `L → End(M)` consists of nilpotent elements.
Engel's theorem `lie_algebra.is_engelian_of_is_noetherian` states that any Noetherian Lie algebra is
Engelian. -/
def lie_algebra.is_engelian : Prop :=
∀ (M : Type u₄) [add_comm_group M], by exactI ∀ [module R M] [lie_ring_module L M], by exactI ∀
[lie_module R L M], by exactI ∀ (h : ∀ (x : L), is_nilpotent (to_endomorphism R L M x)),
lie_module.is_nilpotent R L M
variables {R L}
lemma lie_algebra.is_engelian_of_subsingleton [subsingleton L] : lie_algebra.is_engelian R L :=
begin
intros M _i1 _i2 _i3 _i4 h,
use 1,
suffices : (⊤ : lie_ideal R L) = ⊥, { simp [this], },
haveI := (lie_submodule.subsingleton_iff R L L).mpr infer_instance,
apply subsingleton.elim,
end
lemma function.surjective.is_engelian
{f : L →ₗ⁅R⁆ L₂} (hf : function.surjective f) (h : lie_algebra.is_engelian.{u₁ u₂ u₄} R L) :
lie_algebra.is_engelian.{u₁ u₃ u₄} R L₂ :=
begin
introsI M _i1 _i2 _i3 _i4 h',
letI : lie_ring_module L M := lie_ring_module.comp_lie_hom M f,
letI : lie_module R L M := comp_lie_hom M f,
have hnp : ∀ x, is_nilpotent (to_endomorphism R L M x) := λ x, h' (f x),
have surj_id : function.surjective (linear_map.id : M →ₗ[R] M) := function.surjective_id,
haveI : lie_module.is_nilpotent R L M := h M hnp,
apply hf.lie_module_is_nilpotent surj_id,
simp,
end
lemma lie_equiv.is_engelian_iff (e : L ≃ₗ⁅R⁆ L₂) :
lie_algebra.is_engelian.{u₁ u₂ u₄} R L ↔ lie_algebra.is_engelian.{u₁ u₃ u₄} R L₂ :=
⟨e.surjective.is_engelian, e.symm.surjective.is_engelian⟩
lemma lie_algebra.exists_engelian_lie_subalgebra_of_lt_normalizer
{K : lie_subalgebra R L} (hK₁ : lie_algebra.is_engelian.{u₁ u₂ u₄} R K) (hK₂ : K < K.normalizer) :
∃ (K' : lie_subalgebra R L) (hK' : lie_algebra.is_engelian.{u₁ u₂ u₄} R K'), K < K' :=
begin
obtain ⟨x, hx₁, hx₂⟩ := set_like.exists_of_lt hK₂,
let K' : lie_subalgebra R L :=
{ lie_mem' := λ y z, lie_subalgebra.lie_mem_sup_of_mem_normalizer hx₁,
.. (R ∙ x) ⊔ (K : submodule R L) },
have hxK' : x ∈ K' := submodule.mem_sup_left (submodule.subset_span (set.mem_singleton _)),
have hKK' : K ≤ K' := (lie_subalgebra.coe_submodule_le_coe_submodule K K').mp le_sup_right,
have hK' : K' ≤ K.normalizer,
{ rw ← lie_subalgebra.coe_submodule_le_coe_submodule,
exact sup_le ((submodule.span_singleton_le_iff_mem _ _).mpr hx₁) hK₂.le, },
refine ⟨K', _, lt_iff_le_and_ne.mpr ⟨hKK', λ contra, hx₂ (contra.symm ▸ hxK')⟩⟩,
introsI M _i1 _i2 _i3 _i4 h,
obtain ⟨I, hI₁ : (I : lie_subalgebra R K') = lie_subalgebra.of_le hKK'⟩ :=
lie_subalgebra.exists_nested_lie_ideal_of_le_normalizer hKK' hK',
have hI₂ : (R ∙ (⟨x, hxK'⟩ : K')) ⊔ I = ⊤,
{ rw [← lie_ideal.coe_to_lie_subalgebra_to_submodule R K' I, hI₁],
apply submodule.map_injective_of_injective (K' : submodule R L).injective_subtype,
simpa, },
have e : K ≃ₗ⁅R⁆ I := (lie_subalgebra.equiv_of_le hKK').trans
(lie_equiv.of_eq _ _ ((lie_subalgebra.coe_set_eq _ _).mpr hI₁.symm)),
have hI₃ : lie_algebra.is_engelian R I := e.is_engelian_iff.mp hK₁,
exact lie_submodule.is_nilpotent_of_is_nilpotent_span_sup_eq_top hI₂ (h _) (hI₃ _ (λ x, h x)),
end
local attribute [instance] lie_subalgebra.subsingleton_bot
variables [is_noetherian R L]
/-- *Engel's theorem*.
Note that this implies all traditional forms of Engel's theorem via
`lie_module.nontrivial_max_triv_of_is_nilpotent`, `lie_module.is_nilpotent_iff_forall`,
`lie_algebra.is_nilpotent_iff_forall`. -/
lemma lie_algebra.is_engelian_of_is_noetherian : lie_algebra.is_engelian R L :=
begin
introsI M _i1 _i2 _i3 _i4 h,
rw ← is_nilpotent_range_to_endomorphism_iff,
let L' := (to_endomorphism R L M).range,
replace h : ∀ (y : L'), is_nilpotent (y : module.End R M),
{ rintros ⟨-, ⟨y, rfl⟩⟩,
simp [h], },
change lie_module.is_nilpotent R L' M,
let s := { K : lie_subalgebra R L' | lie_algebra.is_engelian R K },
have hs : s.nonempty := ⟨⊥, lie_algebra.is_engelian_of_subsingleton⟩,
suffices : ⊤ ∈ s,
{ rw ← is_nilpotent_of_top_iff,
apply this M,
simp [lie_subalgebra.to_endomorphism_eq, h], },
have : ∀ (K ∈ s), K ≠ ⊤ → ∃ (K' ∈ s), K < K',
{ rintros K (hK₁ : lie_algebra.is_engelian R K) hK₂,
apply lie_algebra.exists_engelian_lie_subalgebra_of_lt_normalizer hK₁,
apply lt_of_le_of_ne K.le_normalizer,
rw [ne.def, eq_comm, K.normalizer_eq_self_iff, ← ne.def,
← lie_submodule.nontrivial_iff_ne_bot R K],
haveI : nontrivial (L' ⧸ K.to_lie_submodule),
{ replace hK₂ : K.to_lie_submodule ≠ ⊤ :=
by rwa [ne.def, ← lie_submodule.coe_to_submodule_eq_iff, K.coe_to_lie_submodule,
lie_submodule.top_coe_submodule, ← lie_subalgebra.top_coe_submodule,
K.coe_to_submodule_eq_iff],
exact submodule.quotient.nontrivial_of_lt_top _ hK₂.lt_top, },
haveI : lie_module.is_nilpotent R K (L' ⧸ K.to_lie_submodule),
{ refine hK₁ _ (λ x, _),
have hx := lie_algebra.is_nilpotent_ad_of_is_nilpotent (h x),
exact module.End.is_nilpotent.mapq _ hx, },
exact nontrivial_max_triv_of_is_nilpotent R K (L' ⧸ K.to_lie_submodule), },
haveI _i5 : is_noetherian R L' :=
is_noetherian_of_surjective L _ (linear_map.range_range_restrict (to_endomorphism R L M)),
obtain ⟨K, hK₁, hK₂⟩ :=
well_founded.well_founded_iff_has_max'.mp (lie_subalgebra.well_founded_of_noetherian R L') s hs,
have hK₃ : K = ⊤,
{ by_contra contra,
obtain ⟨K', hK'₁, hK'₂⟩ := this K hK₁ contra,
specialize hK₂ K' hK'₁ (le_of_lt hK'₂),
replace hK'₂ := (ne_of_lt hK'₂).symm,
contradiction, },
exact hK₃ ▸ hK₁,
end
/-- Engel's theorem. -/
lemma lie_module.is_nilpotent_iff_forall :
lie_module.is_nilpotent R L M ↔ ∀ x, is_nilpotent $ to_endomorphism R L M x :=
⟨begin
introsI h,
obtain ⟨k, hk⟩ := nilpotent_endo_of_nilpotent_module R L M,
exact λ x, ⟨k, hk x⟩,
end,
λ h, lie_algebra.is_engelian_of_is_noetherian M h⟩
/-- Engel's theorem. -/
lemma lie_algebra.is_nilpotent_iff_forall :
lie_algebra.is_nilpotent R L ↔ ∀ x, is_nilpotent $ lie_algebra.ad R L x :=
lie_module.is_nilpotent_iff_forall
end lie_algebra
|
# Euler1 in R
euler1 <- function(size) {
result <- 0
for (x in 1:size) {
if (x %% 3 == 0 || x %% 5 == 0)
result <- result + x
}
result
}
euler1(999)
|
Formal statement is: lemma\<^marker>\<open>tag important\<close> outer_regular_lborel: assumes B: "B \<in> sets borel" and "0 < (e::real)" obtains U where "open U" "B \<subseteq> U" "emeasure lborel (U - B) < e" Informal statement is: For any Borel set $B$ and any $\epsilon > 0$, there exists an open set $U$ such that $B \subseteq U$ and $\mu(U - B) < \epsilon$. |
From Coq Require Import String Arith Psatz Bool List Program.Equality Lists.ListSet .
From DanTrick Require Import DanTrickLanguage DanLogProp DanLogicHelpers
StackLanguage StackLangEval EnvToStack StackLogicGrammar LogicProp TranslationPure FunctionWellFormed ImpVarMap ImpVarMapTheorems StackLangTheorems.
From DanTrick Require Export LogicTranslationBase ParamsWellFormed FunctionWellFormed.
Lemma compile_bool_args_sound_pos :
forall (vals: list bool) (sargs: list bexp_stack) (dargs: list bexp_Dan) (num_args: nat) (idents: list ident),
compile_bool_args num_args idents dargs sargs ->
forall fenv_d fenv_s func_list,
forall (FENV_WF: fenv_well_formed' func_list fenv_d),
fenv_s = compile_fenv fenv_d ->
(forall aD aS,
aS = compile_aexp aD (fun x => one_index_opt x idents) (List.length idents) ->
forall (FUN_APP_AEXP: fun_app_well_formed fenv_d func_list aD),
forall (MAP_WF_AEXP: var_map_wf_wrt_aexp idents aD),
forall nenv dbenv stk n rho,
List.length dbenv = num_args ->
state_to_stack idents nenv dbenv stk ->
a_Dan aD dbenv fenv_d nenv n ->
aexp_stack_sem aS fenv_s (stk ++ rho) (stk ++ rho, n)) ->
(forall bD bS,
bS = compile_bexp bD (fun x => one_index_opt x idents) (List.length idents) ->
forall (FUN_APP_BEXP: fun_app_bexp_well_formed fenv_d func_list bD),
forall (MAP_WF_BEXP: var_map_wf_wrt_bexp idents bD),
forall nenv dbenv stk bl rho,
List.length dbenv = num_args ->
state_to_stack idents nenv dbenv stk ->
b_Dan bD dbenv fenv_d nenv bl ->
bexp_stack_sem bS fenv_s (stk ++ rho) (stk ++ rho, bl)) ->
forall nenv dbenv,
List.length dbenv = num_args ->
(eval_prop_args_rel
(fun (b : bexp_Dan) (v : bool) =>
b_Dan b dbenv fenv_d nenv v) dargs vals) ->
forall (ARGS_FUN_APP: prop_args_rel (V := bool) (fun_app_bexp_well_formed fenv_d func_list) dargs),
forall (ARGS_MAP_WF: prop_args_rel (V := bool) (var_map_wf_wrt_bexp idents) dargs),
forall stk,
state_to_stack idents nenv dbenv stk ->
forall rho,
eval_prop_args_rel
(fun (boolexpr : bexp_stack) (boolval : bool) =>
bexp_stack_sem boolexpr (compile_fenv fenv_d)
(stk ++ rho) (stk ++ rho, boolval)) sargs vals.
Proof.
induction vals.
- intros. inversion H4. subst. inversion H. subst.
inversion H0. subst. apply RelArgsNil.
- intros. inversion H4. subst. inversion H. subst. inversion H0. subst.
inversion ARGS_FUN_APP. inversion ARGS_MAP_WF. subst.
apply RelArgsCons.
+ pose proof (BEXP := H2 arg (comp_bool idents arg)).
eapply BEXP.
-- unfold comp_bool. auto.
-- eauto.
-- eauto.
-- eapply eq_refl.
-- apply H5.
-- auto.
+ pose proof (IHvals args' args (Datatypes.length dbenv) idents) as int.
pose proof (CompiledBoolArgs idents (Datatypes.length dbenv) args args' H9).
pose proof (int H3 fenv_d (compile_fenv fenv_d)) as int2.
pose proof (eq_refl (compile_fenv fenv_d)) as eq.
pose proof (int2 func_list FENV_WF eq H1 H2 nenv dbenv) as int3.
pose proof (eq_refl (Datatypes.length dbenv)) as eq2.
pose proof (int3 eq2 H11 H12 H17 stk H5 rho) as conc.
apply conc.
Qed.
Lemma compile_arith_args_sound_pos :
forall vals sargs dargs num_args idents,
compile_arith_args num_args idents dargs sargs ->
forall fenv_d fenv_s func_list,
forall (FENV_WF: fenv_well_formed' func_list fenv_d),
fenv_s = compile_fenv fenv_d ->
(forall aD aS,
aS = compile_aexp aD (fun x => one_index_opt x idents) (List.length idents) ->
forall (FUN_APP_AEXP: fun_app_well_formed fenv_d func_list aD),
forall (MAP_WF_AEXP: var_map_wf_wrt_aexp idents aD),
forall nenv dbenv stk n rho,
List.length dbenv = num_args ->
state_to_stack idents nenv dbenv stk ->
a_Dan aD dbenv fenv_d nenv n ->
aexp_stack_sem aS fenv_s (stk ++ rho) (stk ++ rho, n)) ->
(forall bD bS,
bS = compile_bexp bD (fun x => one_index_opt x idents) (List.length idents) ->
forall (FUN_APP_BEXP: fun_app_bexp_well_formed fenv_d func_list bD),
forall (MAP_WF_BEXP: var_map_wf_wrt_bexp idents bD),
forall nenv dbenv stk bl rho,
List.length dbenv = num_args ->
state_to_stack idents nenv dbenv stk ->
b_Dan bD dbenv fenv_d nenv bl ->
bexp_stack_sem bS fenv_s (stk ++ rho) (stk ++ rho, bl)) ->
forall nenv dbenv,
List.length dbenv = num_args ->
(eval_prop_args_rel
(fun (b : aexp_Dan) (v : nat) =>
a_Dan b dbenv fenv_d nenv v) dargs vals) ->
forall (ARGS_FUN_APP: prop_args_rel (V := nat) (fun_app_well_formed fenv_d func_list) dargs),
forall (ARGS_MAP_WF: prop_args_rel (V := nat) (var_map_wf_wrt_aexp idents) dargs),
forall stk,
state_to_stack idents nenv dbenv stk ->
forall rho,
eval_prop_args_rel
(fun (boolexpr : aexp_stack) (boolval : nat) =>
aexp_stack_sem boolexpr (compile_fenv fenv_d)
(stk ++ rho) (stk ++ rho, boolval)) sargs vals.
Proof.
induction vals.
- intros. inversion H4. subst. inversion H. subst.
inversion H0. subst. apply RelArgsNil.
- intros. inversion H4. subst. inversion H. subst. inversion H0. subst.
inversion ARGS_FUN_APP. inversion ARGS_MAP_WF. subst.
apply RelArgsCons.
+ pose proof (AEXP := H1 arg (comp_arith idents arg)).
eapply AEXP.
-- auto.
-- auto.
-- auto.
-- reflexivity.
-- eauto.
-- eauto.
+ pose proof (IHvals args' args (Datatypes.length dbenv) idents) as int.
pose proof (CompiledArithArgs idents (Datatypes.length dbenv) args args' H9).
pose proof (int H3 fenv_d (compile_fenv fenv_d)) as int2.
pose proof (eq_refl (compile_fenv fenv_d)) as eq.
pose proof (int2 func_list FENV_WF eq H1 H2 nenv dbenv) as int3.
pose proof (eq_refl (Datatypes.length dbenv)) as eq2.
pose proof (int3 eq2 H11 H12 H17 stk H5 rho) as conc.
apply conc.
Qed.
Lemma trans_sound_pos_assume_comp_basestate_lp_aexp (idents : list DanTrickLanguage.ident)
(dbenv : list nat)
(fenv_d : fun_env)
(func_list : list fun_Dan)
(FENV_WF : fenv_well_formed' func_list fenv_d)
(H1 : forall (aD : aexp_Dan) (aS : aexp_stack),
aS =
compile_aexp aD (fun x : ident => one_index_opt x idents)
(Datatypes.length idents) ->
fun_app_well_formed fenv_d func_list aD ->
var_map_wf_wrt_aexp idents aD ->
forall (nenv : nat_env) (dbenv0 stk : list nat)
(n : nat) (rho : list nat),
Datatypes.length dbenv0 = Datatypes.length dbenv ->
state_to_stack idents nenv dbenv0 stk ->
a_Dan aD dbenv0 fenv_d nenv n ->
aexp_stack_sem aS (compile_fenv fenv_d) (stk ++ rho)
(stk ++ rho, n))
(H2 : forall (bD : bexp_Dan) (bS : bexp_stack),
bS =
compile_bexp bD (fun x : ident => one_index_opt x idents)
(Datatypes.length idents) ->
fun_app_bexp_well_formed fenv_d func_list bD ->
var_map_wf_wrt_bexp idents bD ->
forall (nenv : nat_env) (dbenv0 stk : list nat)
(bl : bool) (rho : list nat),
Datatypes.length dbenv0 = Datatypes.length dbenv ->
state_to_stack idents nenv dbenv0 stk ->
b_Dan bD dbenv0 fenv_d nenv bl ->
bexp_stack_sem bS (compile_fenv fenv_d) (stk ++ rho)
(stk ++ rho, bl))
(OKfuncs: funcs_okay_too func_list (compile_fenv fenv_d))
(OKparams : Forall (fun func => all_params_ok (DanTrickLanguage.Args func) (DanTrickLanguage.Body func)) func_list)
(nenv : nat_env)
(l : LogicProp nat aexp_Dan)
(stk : list nat)
(H5 : state_to_stack idents nenv dbenv stk)
(rho : list nat)
(FUN_APP : Dan_lp_prop_rel (fun_app_well_formed fenv_d func_list)
(fun_app_bexp_well_formed fenv_d func_list)
(Dan_lp_arith l))
(MAP_WF : Dan_lp_prop_rel (var_map_wf_wrt_aexp idents)
(var_map_wf_wrt_bexp idents) (Dan_lp_arith l))
(H0 : Dan_lp_rel (Dan_lp_arith l) fenv_d dbenv nenv)
(s : LogicProp nat aexp_stack)
(TRANSLATE : lp_transrelation (Datatypes.length dbenv) idents
(Dan_lp_arith l) (MetaNat s)):
meta_match_rel (MetaNat s) (compile_fenv fenv_d) (stk ++ rho).
Proof.
invc FUN_APP. invc MAP_WF. invc TRANSLATE. invc H9. invc H0.
constructor.
- Tactics.revert_until s.
revert l.
induction s; intros; invc H.
+ constructor.
+ invs H4.
+ invs H4. econstructor.
* eapply H1; try eauto.
reflexivity. invs H6. assumption. invs H7. assumption.
* assumption.
+ invs H4. invs H7. invs H6. econstructor.
* eapply H1; [reflexivity | | | reflexivity | .. ]; eassumption.
* eapply H1; [reflexivity | | | reflexivity | .. ]; eassumption.
* assumption.
+ invs H4. invs H6. invs H7. econstructor.
* eapply IHs1. eapply H12. eassumption. assumption. assumption.
* eapply IHs2; [ eapply H13 | eassumption .. ].
+ invs H6. invs H7. invs H4; [eapply RelOrPropLeft | eapply RelOrPropRight].
* eapply IHs1; [ eapply H8 | eassumption .. ].
* eapply IHs2; [ eapply H9 | eassumption .. ].
+ invs H4. invs H6. invs H7. econstructor; [ eapply H1; try reflexivity .. |]; eassumption.
+ invs H4. invs H6. invs H7. econstructor; [ | eassumption ].
eapply compile_arith_args_sound_pos; try eassumption.
econstructor. assumption. reflexivity. reflexivity.
- Tactics.revert_until s. revert l.
induction s; intros; invs H.
+ constructor.
+ invs H4.
+ invs H4. eapply arith_compile_prop_rel_implies_pure'; eauto.
+ invs H4. invs H6. invs H7.
eapply arith_compile_prop_rel_implies_pure'; eauto.
+ invs H4. invs H6. invs H7.
econstructor; [ eapply IHs1; [ eapply H13 | ..] | eapply IHs2; [ eapply H14 | .. ]]; eauto.
+ invs H6.
eapply arith_compile_prop_rel_implies_pure'; eauto.
+ invs H6. eapply arith_compile_prop_rel_implies_pure'; eauto.
+ invs H6. invs H7. constructor. eapply arith_compile_prop_args_rel_implies_pure'; eauto.
Qed.
Lemma trans_sound_pos_assume_comp_basestate_lp_bexp (idents : list DanTrickLanguage.ident)
(dbenv : list nat)
(fenv_d : fun_env)
(func_list : list fun_Dan)
(FENV_WF : fenv_well_formed' func_list fenv_d)
(H1 : forall (aD : aexp_Dan) (aS : aexp_stack),
aS =
compile_aexp aD (fun x : ident => one_index_opt x idents)
(Datatypes.length idents) ->
fun_app_well_formed fenv_d func_list aD ->
var_map_wf_wrt_aexp idents aD ->
forall (nenv : nat_env) (dbenv0 stk : list nat)
(n : nat) (rho : list nat),
Datatypes.length dbenv0 = Datatypes.length dbenv ->
state_to_stack idents nenv dbenv0 stk ->
a_Dan aD dbenv0 fenv_d nenv n ->
aexp_stack_sem aS (compile_fenv fenv_d) (stk ++ rho)
(stk ++ rho, n))
(H2 : forall (bD : bexp_Dan) (bS : bexp_stack),
bS =
compile_bexp bD (fun x : ident => one_index_opt x idents)
(Datatypes.length idents) ->
fun_app_bexp_well_formed fenv_d func_list bD ->
var_map_wf_wrt_bexp idents bD ->
forall (nenv : nat_env) (dbenv0 stk : list nat)
(bl : bool) (rho : list nat),
Datatypes.length dbenv0 = Datatypes.length dbenv ->
state_to_stack idents nenv dbenv0 stk ->
b_Dan bD dbenv0 fenv_d nenv bl ->
bexp_stack_sem bS (compile_fenv fenv_d) (stk ++ rho)
(stk ++ rho, bl))
(OKfuncs: funcs_okay_too func_list (compile_fenv fenv_d))
(OKparams : Forall (fun func => all_params_ok (DanTrickLanguage.Args func) (DanTrickLanguage.Body func)) func_list)
(nenv : nat_env)
(s : LogicProp bool bexp_stack)
(l : LogicProp bool bexp_Dan)
(H4 : AbsEnv_rel (AbsEnvLP (Dan_lp_bool l)) fenv_d dbenv nenv)
(stk : list nat)
(H5 : state_to_stack idents nenv dbenv stk)
(rho : list nat)
(FUN_APP : Dan_lp_prop_rel (fun_app_well_formed fenv_d func_list)
(fun_app_bexp_well_formed fenv_d func_list)
(Dan_lp_bool l))
(MAP_WF : Dan_lp_prop_rel (var_map_wf_wrt_aexp idents)
(var_map_wf_wrt_bexp idents) (Dan_lp_bool l))
(H : prop_rel (var_map_wf_wrt_bexp idents) l)
(TRANSLATE : compile_prop_rel (comp_bool idents) l s):
meta_match_rel (MetaBool s) (compile_fenv fenv_d) (stk ++ rho).
Proof.
invc FUN_APP. invc MAP_WF. invc H4. invc H3.
constructor.
- Tactics.revert_until s.
induction s; intros; invs TRANSLATE.
+ constructor.
+ invs H4.
+ invs H4. invs H7. invs H8. econstructor; [ | eassumption ].
eapply H2; try reflexivity; try eassumption.
+ invs H4. invs H7. invs H8. econstructor; [ .. | eassumption ].
all: eapply H2; try reflexivity; try eassumption.
+ invs H4. invs H7. invs H8. econstructor; [ eapply IHs1; [ | eapply H15 | .. ] | eapply IHs2; [ | eapply H16 | .. ]]; eassumption.
+ invs H7. invs H8. invs H4.
* eapply RelOrPropLeft. eapply IHs1; [ | eapply H13 | .. ]; eassumption.
* eapply RelOrPropRight. eapply IHs2; [ | eapply H14 | .. ]; eassumption.
+ invs H4. invs H7. invs H8.
econstructor; [ .. | eassumption ].
all: eapply H2; try reflexivity; try eassumption.
+ invs H4. invs H7. invs H8. econstructor; [ | eassumption ].
eapply compile_bool_args_sound_pos; try reflexivity;
try eassumption.
constructor. assumption.
- Tactics.revert_until s.
induction s; intros; invs TRANSLATE.
+ constructor.
+ constructor.
+ invs H7. invs H8. eapply bool_compile_prop_rel_implies_pure'; try eassumption.
reflexivity. reflexivity.
+ invs H7. invs H8. eapply bool_compile_prop_rel_implies_pure'; eauto.
+ invs H7. invs H8. eapply bool_compile_prop_rel_implies_pure'; eauto.
+ invs H7. invs H8. eapply bool_compile_prop_rel_implies_pure'; eauto.
+ invs H7. invs H8. eapply bool_compile_prop_rel_implies_pure'; eauto.
+ invs H7. invs H8. constructor. eapply bool_compile_prop_args_rel_implies_pure'; eauto.
Qed.
Lemma trans_sound_pos_assume_comp_basestate (m : MetavarPred)
(idents : list DanTrickLanguage.ident)
(dbenv : list nat)
(d : Dan_lp)
(fenv_d : fun_env)
(func_list : list fun_Dan)
(FENV_WF : fenv_well_formed' func_list fenv_d)
(H1 : forall (aD : aexp_Dan) (aS : aexp_stack),
aS =
compile_aexp aD (fun x : ident => one_index_opt x idents)
(Datatypes.length idents) ->
fun_app_well_formed fenv_d func_list aD ->
var_map_wf_wrt_aexp idents aD ->
forall (nenv : nat_env) (dbenv0 stk : list nat)
(n : nat) (rho : list nat),
Datatypes.length dbenv0 = Datatypes.length dbenv ->
state_to_stack idents nenv dbenv0 stk ->
a_Dan aD dbenv0 fenv_d nenv n ->
aexp_stack_sem aS (compile_fenv fenv_d) (stk ++ rho)
(stk ++ rho, n))
(H2 : forall (bD : bexp_Dan) (bS : bexp_stack),
bS =
compile_bexp bD (fun x : ident => one_index_opt x idents)
(Datatypes.length idents) ->
fun_app_bexp_well_formed fenv_d func_list bD ->
var_map_wf_wrt_bexp idents bD ->
forall (nenv : nat_env) (dbenv0 stk : list nat)
(bl : bool) (rho : list nat),
Datatypes.length dbenv0 = Datatypes.length dbenv ->
state_to_stack idents nenv dbenv0 stk ->
b_Dan bD dbenv0 fenv_d nenv bl ->
bexp_stack_sem bS (compile_fenv fenv_d) (stk ++ rho)
(stk ++ rho, bl))
(OKfuncs: funcs_okay_too func_list (compile_fenv fenv_d))
(OKparams : Forall (fun func => all_params_ok (DanTrickLanguage.Args func) (DanTrickLanguage.Body func)) func_list)
(nenv : nat_env)
(H4 : AbsEnv_rel (AbsEnvLP d) fenv_d dbenv nenv)
(stk : list nat)
(H5 : state_to_stack idents nenv dbenv stk)
(rho : list nat)
(H10 : lp_transrelation (Datatypes.length dbenv) idents d m)
(H0 : Dan_lp_rel d fenv_d dbenv nenv)
(MAP_WF : Dan_lp_prop_rel (var_map_wf_wrt_aexp idents)
(var_map_wf_wrt_bexp idents) d)
(FUN_APP : Dan_lp_prop_rel (fun_app_well_formed fenv_d func_list)
(fun_app_bexp_well_formed fenv_d func_list) d):
absstate_match_rel
(BaseState
(AbsStkSize (Datatypes.length idents + Datatypes.length dbenv)) m)
(compile_fenv fenv_d) (stk ++ rho).
Proof.
constructor.
- constructor.
inversion H5. simpl. rewrite app_length. rewrite app_length. rewrite map_length. lia.
- inversion MAP_WF. subst. invs FUN_APP. invs H10. invs H9.
clear H9. eapply trans_sound_pos_assume_comp_basestate_lp_aexp; eauto.
subst. invc H10. invc H8; eauto.
eapply trans_sound_pos_assume_comp_basestate_lp_bexp; eauto.
Qed.
Lemma trans_sound_pos_assume_comp :
forall state dan_log num_args idents,
logic_transrelation num_args idents dan_log state ->
forall fenv_d fenv_s func_list,
forall (FENV_WF: fenv_well_formed' func_list fenv_d)
(OKfuncs: funcs_okay_too func_list (compile_fenv fenv_d))
(OKparams : Forall (fun func => all_params_ok (DanTrickLanguage.Args func) (DanTrickLanguage.Body func)) func_list),
fenv_s = compile_fenv fenv_d ->
(forall aD aS,
aS = compile_aexp aD (fun x => one_index_opt x idents) (List.length idents) ->
forall (FUN_APP_AEXP: fun_app_well_formed fenv_d func_list aD),
forall (MAP_WF_AEXP: var_map_wf_wrt_aexp idents aD),
forall nenv dbenv stk n rho,
List.length dbenv = num_args ->
state_to_stack idents nenv dbenv stk ->
a_Dan aD dbenv fenv_d nenv n ->
aexp_stack_sem aS fenv_s (stk ++ rho) (stk ++ rho, n)) ->
(forall bD bS,
bS = compile_bexp bD (fun x => one_index_opt x idents) (List.length idents) ->
forall (FUN_APP_BEXP: fun_app_bexp_well_formed fenv_d func_list bD),
forall (MAP_WF_BEXP: var_map_wf_wrt_bexp idents bD),
forall nenv dbenv stk bl rho,
List.length dbenv = num_args ->
state_to_stack idents nenv dbenv stk ->
b_Dan bD dbenv fenv_d nenv bl ->
bexp_stack_sem bS fenv_s (stk ++ rho) (stk ++ rho, bl)) ->
forall nenv dbenv,
List.length dbenv = num_args ->
forall (FUN_APP: AbsEnv_prop_rel (fun_app_well_formed fenv_d func_list)
(fun_app_bexp_well_formed fenv_d func_list)
dan_log)
(MAP_WF: AbsEnv_prop_rel (var_map_wf_wrt_aexp idents)
(var_map_wf_wrt_bexp idents)
dan_log),
AbsEnv_rel dan_log fenv_d dbenv nenv ->
forall stk,
state_to_stack idents nenv dbenv stk ->
forall rho,
absstate_match_rel state fenv_s (stk ++ rho).
Proof.
induction state; intros.
- inversion H. subst. clear H. inversion H4. inversion MAP_WF. inversion FUN_APP. subst.
eapply trans_sound_pos_assume_comp_basestate; eauto.
- invs H. invs H4. invs MAP_WF. invs FUN_APP.
constructor.
+ eapply IHstate1; try eassumption; try reflexivity.
+ eapply IHstate2; try eassumption; try reflexivity.
- invs H. invs MAP_WF. invs FUN_APP. invs H4.
+ eapply RelAbsOrLeft. eapply IHstate1; try eassumption; try reflexivity.
+ eapply RelAbsOrRight. eapply IHstate2; try eassumption; try reflexivity.
Qed.
|
(* infotheo (c) AIST. R. Affeldt, M. Hagiwara, J. Senizergues. GNU GPLv3. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div choice fintype.
From mathcomp Require Import tuple finfun bigop prime binomial ssralg finset fingroup finalg.
From mathcomp Require Import matrix.
Require Import Reals Fourier.
Require Import Rssr Reals_ext log2 ssr_ext ssralg_ext tuple_prod.
Local Open Scope reals_ext_scope.
(** * Instantiation of canonical big operators with Coq reals *)
Lemma iter_Rplus n r : ssrnat.iter n (Rplus r) 0 = INR n * r.
Proof.
elim : n r => [r /= | m IHm r]; first by rewrite mul0R.
rewrite iterS IHm S_INR; field.
Qed.
Lemma iter_Rmult n p : ssrnat.iter n (Rmult p) 1 = p ^ n.
Proof. elim : n p => // n0 IH p0 /=; by rewrite IH. Qed.
Lemma morph_Ropp : {morph [eta Ropp] : x y / x + y}.
Proof. by move=> x y /=; field. Qed.
Lemma morph_plus_INR : {morph INR : x y / (x + y)%nat >-> x + y}.
Proof. move=> x y /=; by rewrite plus_INR. Qed.
Lemma morph_mult_INR : {morph INR : x y / (x * y)%nat >-> x * y}.
Proof. move=> x y /=; by rewrite mult_INR. Qed.
Lemma morph_mulRDr a : {morph [eta Rmult a] : x y / x + y}.
Proof. move=> * /=; by rewrite mulRDr. Qed.
Lemma morph_mulRDl a : {morph Rmult^~ a : x y / x + y}.
Proof. move=> x y /=; by rewrite mulRDl. Qed.
Lemma morph_exp2_plus : {morph [eta exp2] : x y / x + y >-> x * y}.
Proof. move=> ? ? /=; by rewrite -exp2_plus. Qed.
Section Abelian.
Variable op : Monoid.com_law 1.
Notation Local "'*%M'" := op (at level 0).
Notation Local "x * y" := (op x y).
Lemma mybig_index_uniq (I : eqType) (i : R) (r : seq I) (E : 'I_(size r) -> R) :
uniq r ->
\big[*%M/1]_i E i = \big[*%M/1]_(x <- r) oapp E i (insub (seq.index x r)).
Proof.
move=> Ur.
apply/esym.
rewrite big_tnth.
apply: eq_bigr => j _.
by rewrite index_uniq // valK.
Qed.
End Abelian.
(** Instantiation of big sums for reals *)
Canonical addR_monoid := Monoid.Law addRA add0R addR0.
Canonical addR_comoid := Monoid.ComLaw addRC.
Canonical mulR_monoid := Monoid.Law mulRA mul1R mulR1.
Canonical mulR_muloid := Monoid.MulLaw mul0R mulR0.
Canonical mulR_comoid := Monoid.ComLaw mulRC.
Canonical addR_addoid := Monoid.AddLaw mulRDl mulRDr.
Notation "\rsum_ ( i <- t ) F" := (\big[Rplus/0%R]_( i <- t) F)
(at level 41, F at level 41, i at level 50,
format "'[' \rsum_ ( i <- t ) '/ ' F ']'") : R_scope.
Notation "\rsum_ ( m <= i < n ) F" := (\big[Rplus/0%R]_( m <= i < n ) F)
(at level 41, F at level 41, i, m, n at level 50,
format "'[' \rsum_ ( m <= i < n ) '/ ' F ']'") : R_scope.
Notation "\rsum_ ( i | P ) F" := (\big[Rplus/0%R]_( i | P) F)
(at level 41, F at level 41, i at level 50,
format "'[' \rsum_ ( i | P ) '/ ' F ']'") : R_scope.
Notation "\rsum_ ( i ':' A | P ) F" := (\big[Rplus/0%R]_( i : A | P ) F)
(at level 41, F at level 41, i, A at level 50,
format "'[' \rsum_ ( i ':' A | P ) '/ ' F ']'") : R_scope.
Notation "\rsum_ ( i : t ) F" := (\big[Rplus/0%R]_( i : t) F)
(at level 41, F at level 41, i at level 50,
format "'[' \rsum_ ( i : t ) '/ ' F ']'") : R_scope.
Notation "\rsum_ ( i < n ) F" := (\big[Rplus/0%R]_( i < n ) F)
(at level 41, F at level 41, i at level 50,
format "'[' \rsum_ ( i < n ) '/ ' F ']'") : R_scope.
Notation "\rsum_ ( i 'in' A | P ) F" := (\big[Rplus/0%R]_( i in A | P ) F)
(at level 41, F at level 41, i, A at level 50,
format "'[' \rsum_ ( i 'in' A | P ) '/ ' F ']'") : R_scope.
Notation "\rsum_ ( a 'in' A ) F" := (\big[Rplus/0%R]_( a in A ) F)
(at level 41, F at level 41, a, A at level 50,
format "'[' \rsum_ ( a 'in' A ) '/ ' F ']'") : R_scope.
Lemma big_Rabs {A : finType} F : Rabs (\rsum_ (a : A) F a) <= \rsum_ (a : A) Rabs (F a).
Proof.
elim: (index_enum _) => [| hd tl IH].
rewrite 2!big_nil Rabs_R0; by apply Rle_refl.
rewrite 2!big_cons.
apply (Rle_trans _ (Rabs (F hd) + Rabs (\rsum_(j <- tl) F j))); first by apply Rabs_triang.
by apply Rplus_le_compat_l.
Qed.
Lemma classify_big {T : finType} k (f : T -> 'I_k) (F : 'I_k -> R) :
\rsum_(s : T) F (f s) = \rsum_(n : 'I_k) INR #|f @^-1: [set n]| * F n.
Proof.
transitivity (\rsum_(n<k) \rsum_(s | true && (f s == n)) F (f s)).
by apply partition_big.
apply eq_bigr => i _ /=.
transitivity (\rsum_(s|f s == i) F i).
by apply eq_bigr => s /eqP ->.
rewrite big_const iter_Rplus.
do 2 f_equal.
apply eq_card => j /=.
by rewrite !inE.
Qed.
(** Rle, Rlt lemmas for big sums of reals *)
Section Rcomparison_rsum.
Variable A : finType.
Variables f g : A -> R.
Variable P Q : pred A.
Lemma Rle_big_P_f_g_X (X : {set A}) : (forall i, i \in X -> P i -> f i <= g i) ->
\rsum_(i in X | P i) f i <= \rsum_(i in X | P i) g i.
Proof.
move=> H.
elim: (index_enum _) => [| hd tl IH].
- rewrite !big_nil; by apply Rle_refl.
- rewrite !big_cons.
set cond := _ && _; move Hcond : cond => []; subst cond => //.
apply Rplus_le_compat => //.
case/andP : Hcond.
by apply H.
Qed.
Lemma Rle_big_P_f_g : (forall i, P i -> f i <= g i) ->
\rsum_(i | P i) f i <= \rsum_(i | P i) g i.
Proof.
move=> H.
elim: (index_enum _) => [| hd tl IH].
- rewrite !big_nil; by apply Rle_refl.
- rewrite !big_cons.
case: ifP => Hcase //.
apply Rplus_le_compat => //.
by apply H.
Qed.
Lemma Rlt_big_f_g_X (X : {set A}) : forall (HA: (0 < #|X|)%nat),
(forall i, i \in X -> f i < g i) ->
\rsum_(i in X) f i < \rsum_(i in X) g i.
Proof.
move Ha : #|X| => a.
move: a X Ha.
elim => // a IHa X Ha _ H.
move: (ltn0Sn a). rewrite -Ha card_gt0. case/set0Pn => a0 Ha0.
rewrite (@big_setD1 _ _ _ _ a0 _ f) //= (@big_setD1 _ _ _ _ a0 _ g) //=.
case: a IHa Ha => IHa Ha.
rewrite (_ : X :\ a0 = set0); last first.
rewrite (cardsD1 a0) Ha0 /= add1n in Ha.
case: Ha.
move/eqP.
rewrite cards_eq0.
by move/eqP.
rewrite !big_set0 2!addR0; by apply H.
move=> HA.
apply Rplus_lt_compat.
by apply H.
apply Ha => //.
rewrite (cardsD1 a0) Ha0 /= add1n in HA.
by case: HA.
move=> i Hi.
rewrite in_setD in Hi.
case/andP : Hi => Hi1 Hi2.
by apply H.
Qed.
Lemma Rle_big_P_Q_f_g : (forall i, P i -> f i <= g i) ->
(forall i, Q i -> 0 <= g i) ->
(forall i, P i -> Q i) ->
\rsum_(i | P i) f i <= \rsum_(i | Q i) g i.
Proof.
move=> f_g Qg H.
elim: (index_enum _) => [| hd tl IH].
- rewrite !big_nil; by apply Rle_refl.
- rewrite !big_cons /=.
case: ifP => Hcase.
rewrite (H _ Hcase).
apply Rplus_le_compat => //.
by apply f_g.
case: ifP => // Qhd.
apply Rle_trans with (\big[Rplus/0]_(j <- tl | Q j) g j).
by apply IH.
rewrite -{1}(add0R (\big[Rplus/0]_(j <- tl | Q j) g j)).
by apply Rplus_le_compat_r, Qg.
Qed.
Lemma Rle_big_P_true_f_g : (forall a, 0 <= g a) ->
(forall i, i \in P -> f i <= g i) ->
\rsum_(i in A | P i) f i <= \rsum_(i in A) g i.
Proof.
move=> K H.
elim: (index_enum _) => [| hd tl IH].
- rewrite !big_nil; by apply Rle_refl.
- rewrite !big_cons.
case/orP : (orbN (hd \in A)) => H1.
rewrite H1 /=.
case: ifP => Hif.
apply Rplus_le_compat => //.
by apply H.
rewrite -[X in X <= _]add0R.
by apply Rplus_le_compat.
rewrite (negbTE H1) /=; exact IH.
Qed.
Lemma Rle_big_f_X_Y : (forall a, 0 <= f a) ->
(forall i, i \in P -> i \in Q) ->
\rsum_(i in P) f i <= \rsum_(i in Q) f i.
Proof.
move=> Hf P'_P.
elim: (index_enum _) => [| hd tl IH].
- rewrite !big_nil; by apply Rle_refl.
- rewrite !big_cons.
set cond := _ \in _; move Hcond : cond => []; subst cond => //=.
rewrite (P'_P _ Hcond).
by apply Rplus_le_compat_l.
set cond := _ \in _; move Hcond2 : cond => []; subst cond => //=.
rewrite -[X in X <= _]add0R.
by apply Rplus_le_compat.
Qed.
Lemma Rle_big_P_Q_f_X (X : pred A) :
(forall a, 0 <= f a) -> (forall i, P i -> Q i) ->
\rsum_(i in X | P i) f i <= \rsum_(i in X | Q i) f i.
Proof.
move=> Hf P_Q.
elim: (index_enum _) => [| hd tl IH].
- rewrite !big_nil; by apply Rle_refl.
- rewrite !big_cons.
set cond := _ \in _; move Hcond : cond => []; subst cond => //=.
case: ifP => // HP.
+ case: ifP => HQ.
* by apply Rplus_le_compat_l.
* by rewrite (P_Q _ HP) in HQ.
+ case: ifP => // HQ.
rewrite -[X in X <= _]add0R.
by apply Rplus_le_compat.
Qed.
Lemma Rle_big_predU_f : (forall a, 0 <= f a) ->
\rsum_(i in A | [predU P & Q] i) f i <=
\rsum_(i in A | P i) f i + \rsum_(i in A | Q i) f i.
Proof.
move=> Hf.
elim: (index_enum _) => //.
- rewrite !big_nil /=; fourier.
- move=> h t IH /=.
rewrite !big_cons /=.
case: ifP => /=.
+ case/orP => [HP1 | HP2].
* rewrite unfold_in in HP1.
rewrite HP1.
case: ifP => // HP2.
- rewrite -addRA; apply Rplus_le_compat_l.
eapply Rle_trans; first by apply IH.
have : forall a b c, 0 <= c -> a + b <= a + (c + b) by move=> *; fourier.
apply.
by apply Hf.
- rewrite -addRA; apply Rplus_le_compat_l.
eapply Rle_trans; first by apply IH.
by apply Req_le.
* rewrite unfold_in in HP2.
rewrite HP2.
case: ifP => // HP1.
- rewrite -addRA; apply Rplus_le_compat_l.
eapply Rle_trans; first by apply IH.
have : forall a b c, 0 <= c -> a + b <= a + (c + b) by move=> *; fourier.
apply.
by apply Hf.
- rewrite -(Rplus_comm (f h + _)) -addRA; apply Rplus_le_compat_l.
eapply Rle_trans; first by apply IH.
by rewrite Rplus_comm; apply Req_le.
+ move/negbT.
rewrite negb_or.
case/andP.
rewrite unfold_in; move/negbTE => ->.
rewrite unfold_in; move/negbTE => ->.
by apply IH.
Qed.
Lemma Rle_big_P_true_f : (forall i : A, 0 <= f i) ->
\rsum_(i in A | P i) f i <= \rsum_(i in A) f i.
Proof.
move=> H.
elim: (index_enum _) => [| hd tl IH].
- rewrite !big_nil; by apply Rle_refl.
- rewrite !big_cons.
case/orP : (orbN (P hd)) => P_hd.
+ rewrite P_hd /=.
apply Rplus_le_compat => //; by apply Rle_refl.
+ rewrite (negbTE P_hd) inE /= -[X in X <= _]add0R; by apply Rplus_le_compat.
Qed.
End Rcomparison_rsum.
Lemma Rlt_big_0_g (A : finType) (g : A -> R) (HA : (0 < #|A|)%nat) :
(forall i, 0 < g i) -> 0 < \rsum_(i in A) g i.
Proof.
move=> H.
rewrite (_ : \rsum_(i in A) g i = \rsum_(i in [set: A]) g i); last first.
apply eq_bigl => x /=; by rewrite !inE.
eapply Rle_lt_trans; last first.
apply Rlt_big_f_g_X with (f := fun x => 0) => //.
by rewrite cardsT.
rewrite big_const_seq iter_Rplus mulR0; by apply Rle_refl.
Qed.
Lemma Rle_big_0_P_g (A : finType) (P : pred A) (g : A -> R) :
(forall i, P i -> 0 <= g i) -> 0 <= \rsum_(i in A | P i) g i.
Proof.
move=> H.
apply Rle_trans with (\rsum_(i|(i \in A) && P i) (fun x => 0) i).
rewrite big_const iter_Rplus mulR0 /=; by apply Rle_refl.
by apply Rle_big_P_f_g.
Qed.
Lemma Rle_big_P_Q_f_X_new {A : finType} (f : A -> R) (P Q : pred A) :
(forall a, 0 <= f a) -> (forall i, P i -> Q i) ->
\rsum_(i | P i) f i <= \rsum_(i | Q i) f i.
Proof.
move=> Hf R_T.
eapply Rle_trans; last by apply (Rle_big_P_Q_f_X A f P Q xpredT).
by apply Req_le.
Qed.
Lemma Req_0_rmul_inv' {A : finType} (f : A -> R) (P Q : pred A) : (forall i, 0 <= f i) ->
forall j, P j -> f j <= \rsum_(i | P i) f i.
Proof.
move=> HF j Hj.
rewrite (_ : f j = \rsum_(i | i == j) f i); last by rewrite big_pred1_eq.
apply: Rle_big_P_Q_f_X_new => //.
move=> i /eqP ?; by subst j.
Qed.
Lemma Req_0_rmul_inv {C : finType} (R : pred C) F (HF : forall a, 0 <= F a) :
0 = \rsum_(i | R i) F i -> (forall i, R i -> 0 = F i).
Proof.
move=> abs i Hi.
case/Rle_lt_or_eq_dec : (HF i) => // Fi.
suff : False by done.
have : F i <= \rsum_(i|R i) F i.
by apply Req_0_rmul_inv'.
rewrite -abs => ?.
fourier.
Qed.
(* old lemmas that better not be used *)
Section old.
Lemma Req_0_rmul {C : finType} (R : pred C) F:
(forall i, R i -> 0 = F i) ->
0 = \rsum_(i | R i) F i.
Proof.
move=> HF.
rewrite (eq_bigr (fun=> 0)); first by rewrite big_const iter_Rplus mulR0.
move=> i Ri; by rewrite -HF.
Qed.
End old.
Lemma psumR_eq0P {B : finType} (g : B -> R) (U : pred B) :
\rsum_(i|U i) g i = 0 ->
(forall i : B, U i -> 0 <= g i) ->
(forall i : B, U i -> g i = 0).
Proof.
move=> H2 H1 i Hi.
suff H : g i = 0 /\ (\rsum_(j|(U j && (j != i))) g j) = 0 by case: H.
apply Rplus_eq_R0.
- apply H1 ; exact Hi.
- apply: Rle_big_0_P_g => i0 Hi0; apply H1.
move/andP in Hi0; by apply Hi0.
- rewrite -bigD1 /=; [exact H2 | exact Hi].
Qed.
Lemma rsum_neq0 {A : finType} (P : {set A}) (g : A -> R) :
\rsum_(t | t \in P) g t != 0 -> [exists t, (t \in P) && (g t != 0)].
Proof.
move=> H1.
apply negbNE.
rewrite negb_exists.
apply/negP => /forallP abs.
move/negP : H1; apply.
rewrite big_mkcond /=.
apply/eqP.
transitivity (\rsum_(a : A) 0); last by rewrite big_const iter_Rplus mulR0.
apply eq_bigr => a _.
case: ifP => // Hcond.
move: (abs a); by rewrite Hcond /= negbK => /eqP.
Qed.
(* TODO: factorize? *)
Lemma Rle_big_eq (B : finType) (f g : B -> R) (U : pred B) :
(forall i : B, U i -> f i <= g i) ->
\rsum_(i|U i) g i = \rsum_(i|U i) f i ->
(forall i : B, U i -> g i = f i).
Proof.
move=> H1 H2 i Hi.
apply (Rplus_eq_reg_l (- (f i))).
rewrite Rplus_opp_l Rplus_comm.
move: i Hi.
apply psumR_eq0P.
- rewrite big_split /= -(big_morph _ morph_Ropp Ropp_0).
by apply Rminus_diag_eq, H2.
- move=> i Hi.
apply (Rplus_le_reg_l (f i)).
rewrite addR0 subRKC; by apply H1.
Qed.
(* TODO: generalize to any bigop *)
Lemma rsum_union {C : finType} (B1 B2 B : {set C}) f :
[disjoint B2 & B1] ->
B = B1 :|: B2 ->
\rsum_(b | b \in B) f b =
\rsum_(b | b \in B1) f b + \rsum_(b | b \in B2) f b.
Proof.
move=> Hdisj ->.
rewrite (@big_setID _ _ _ _ _ B1) /= setUK setDUl setDv set0U.
suff : B2 :\: B1 = B2 by move=> ->.
by apply/setDidPl.
Qed.
(** Big sums lemmas for products *)
Section big_sums_prods.
Variables A B : finType.
Lemma pair_big_fst : forall (F : {: A * B} -> R) P Q,
P =1 Q \o (fun x => x.1) ->
\rsum_(i in A | Q i) \rsum_(j in B) (F (i, j)) = \rsum_(i in {: A * B} | P i) F i.
Proof.
move=> /= F Q' Q Q'Q; rewrite pair_big /=.
apply eq_big.
- case=> /= i1 i2; by rewrite inE andbC Q'Q.
- by case.
Qed.
Lemma pair_big_snd : forall (F : {: A * B} -> R) P Q,
P =1 Q \o (fun x => x.2) ->
\rsum_(i in A) \rsum_(j in B | Q j) (F (i, j)) = \rsum_(i in {: A * B} | P i) F i.
Proof.
move=> /= F Q' Q Q'Q; rewrite pair_big /=.
apply eq_big.
- case=> /= i1 i2; by rewrite Q'Q.
- by case.
Qed.
End big_sums_prods.
(** Switching from a sum on the domain to a sum on the image of function *)
Section sum_dom_codom.
Variable A : finType.
Lemma sum_parti (p : seq A) (X : A -> R) : forall F, uniq p ->
\rsum_(i <- p) (F i) =
\rsum_(r <- undup (map X p)) \big[Rplus/0]_(i <- p | X i == r) (F i).
Proof.
move Hn : (undup (map X (p))) => n.
move: n p X Hn.
elim => [p X HA F Hp | h t IH p X H F Hp].
- rewrite big_nil.
move/undup_nil_inv : HA.
move/map_nil_inv => ->.
by rewrite big_nil.
- rewrite big_cons.
have [preh [pret [H1 [H2 H3]]]] : exists preh pret,
perm_eq p (preh ++ pret) /\ undup (map X preh) = [:: h] /\ undup (map X pret) = t.
by apply undup_perm.
apply trans_eq with (\big[Rplus/0]_(i <- preh ++ pret) F i).
by apply: eq_big_perm.
apply trans_eq with
(\big[Rplus/0]_(i <- preh ++ pret | X i == h) F i +
\rsum_(j <- t) \big[Rplus/0]_(i <- preh ++ pret | X i == j) F i); last first.
f_equal.
apply: eq_big_perm.
by rewrite perm_eq_sym.
apply eq_bigr => i _ /=.
apply: eq_big_perm.
by rewrite perm_eq_sym.
have -> :
\rsum_(j <- t) \big[Rplus/0]_(i <- (preh ++ pret) | X i == j) F i =
\rsum_(j <- t) \big[Rplus/0]_(i <- pret | X i == j) F i.
rewrite big_seq_cond.
symmetry.
rewrite big_seq_cond /=.
apply eq_bigr => i Hi.
rewrite big_cat /=.
have -> : \big[Rplus/0]_(i0 <- preh | X i0 == i) F i0 = 0.
transitivity (\big[Rplus/0]_(i0 <- preh | false) F i0).
rewrite big_seq_cond.
apply eq_bigl => /= j.
apply/negP.
case/andP; move=> Xj_i; move/eqP=> j_preh.
subst i.
have Xj_h : X j \in [:: h].
have H4 : X j \in map X preh by apply/mapP; exists j.
have H5 : X j \in undup (map X preh) by rewrite mem_undup.
by rewrite H2 in H5.
have : uniq (h :: t).
rewrite -H.
apply undup_uniq.
rewrite /= in_cons in_nil orbC /= in Xj_h.
move/eqP : Xj_h => Xj_h.
subst h.
rewrite andbC /= in Hi.
by rewrite /= Hi.
by rewrite big_pred0.
by rewrite add0R.
rewrite -IH //; last first.
have : uniq (preh ++ pret) by rewrite -(@perm_eq_uniq _ _ _ H1).
rewrite cat_uniq.
case/andP => _; by case/andP.
have -> : \big[Rplus/0]_(i <- (preh ++ pret) | X i == h) F i =
\rsum_(i <- preh) F i.
rewrite big_cat /=.
have -> : \big[Rplus/0]_(i <- pret | X i == h) F i = 0.
transitivity (\big[Rplus/0]_(i0 <- pret | false) F i0); last first.
by rewrite big_pred0.
rewrite big_seq_cond.
apply eq_bigl => /= j.
apply/negP.
case/andP; move => j_pret; move/eqP => Xj_h.
subst h.
have Xj_t : X j \in t.
have H4 : X j \in map X pret.
apply/mapP; by exists j.
have H5 : X j \in undup (map X pret).
by rewrite mem_undup.
by rewrite H3 in H5.
have : uniq (X j :: t).
rewrite -H.
by apply undup_uniq.
by rewrite /= Xj_t.
rewrite addR0 big_seq_cond /=.
symmetry.
rewrite big_seq_cond /=.
apply congr_big => //= x.
case/orP : (orbN (x \in preh)) => Y.
+ rewrite Y /=.
symmetry.
have : X x \in [:: h].
rewrite -H2 mem_undup.
apply/mapP.
by exists x.
by rewrite in_cons /= in_nil orbC.
+ by rewrite (negbTE Y) andbC.
by rewrite big_cat.
Qed.
(* NB: use finset.partition_big_imset? *)
Lemma sum_parti_finType (X : A -> R) F :
\rsum_(i in A) (F i) =
\rsum_(r <- undup (map X (enum A))) \big[Rplus/0]_(i in A | X i == r) (F i).
Proof.
move: (@sum_parti (enum A) X F) => /=.
rewrite enum_uniq.
move/(_ (refl_equal _)) => IH.
transitivity (\big[Rplus/0]_(i <- enum A) F i).
apply congr_big => //.
by rewrite enumT.
rewrite IH.
apply eq_bigr => i _.
apply congr_big => //.
by rewrite enumT.
Qed.
End sum_dom_codom.
Local Open Scope R_scope.
Section tmp.
Local Open Scope ring_scope.
(* TODO: rename? *)
Lemma rsum_rV_prod (C D : finType) n f (Q : {set 'rV_n}) :
\rsum_(a in 'rV[C * D]_n | a \in Q) f a =
\rsum_(a in {: 'rV[C]_n * 'rV[D]_n} | (prod_tuple a) \in Q) f (prod_tuple a).
Proof.
rewrite (reindex_onto (fun p => tuple_prod p) (fun y => prod_tuple y)) //=; last first.
move=> i _; by rewrite prod_tupleK.
apply eq_big => /=.
move=> t /=.
by rewrite tuple_prodK eqxx andbC.
move=> i _; by rewrite tuple_prodK.
Qed.
(*Lemma rsum_rV_prod (A B : finType) n f P :
\rsum_(a in 'rV[A * B]_n | P a) f a =
\rsum_(a in {: 'rV[A]_n * 'rV[B]_n} | P (prod_tuple a)) f (prod_tuple a).
Proof.
rewrite (reindex_onto (fun p => tuple_prod p) (fun y => prod_tuple y)) //=; last first.
move=> i _; by rewrite prod_tupleK.
apply eq_big => /=.
move=> t /=.
by rewrite tuple_prodK eqxx andbC.
move=> i _; by rewrite tuple_prodK.
Qed.*)
End tmp.
(*Lemma rsum_tuple_prod (A B : finType) n f P :
\rsum_(a in {:n.-tuple (A * B)%type} | P a) f a =
\rsum_(a in {: n.-tuple A * n.-tuple B} | P (tuple_prod.prod_tuple a)) f (tuple_prod.prod_tuple a).
Proof.
rewrite (reindex_onto (fun p => tuple_prod.tuple_prod p) (fun y => tuple_prod.prod_tuple y)) //=; last first.
move=> i _; by rewrite tuple_prod.prod_tupleK.
apply eq_big => /=.
move=> t /=.
by rewrite tuple_prod.tuple_prodK eqxx andbC.
move=> i _; by rewrite tuple_prod.tuple_prodK.
Qed.
Lemma rsum_tuple_prod_set (A B : finType) n f (P : {set {:n.-tuple (A * B)}}) :
\rsum_(a in {:n.-tuple (A * B)%type} | a \in P) f a =
\rsum_(a in {: n.-tuple A * n.-tuple B} | (tuple_prod.prod_tuple a) \in P) f (tuple_prod.prod_tuple a).
Proof.
rewrite (reindex_onto (fun p => tuple_prod.tuple_prod p) (fun y => tuple_prod.prod_tuple y)) //=; last first.
move=> i _; by rewrite tuple_prod.prod_tupleK.
apply eq_big => /=.
move=> t /=.
by rewrite tuple_prod.tuple_prodK eqxx andbC.
move=> i _; by rewrite tuple_prod.tuple_prodK.
Qed.
*)
Section big_sum_rV.
Context {A : finType}.
Local Open Scope vec_ext_scope.
Local Open Scope ring_scope.
Lemma rsum_rV_1 F G P Q :
(forall i : 'rV[A]_1, F i = G (i ``_ ord0)) ->
(forall i : 'rV[A]_1, P i = Q (i ``_ ord0)) ->
\rsum_(i in 'rV[A]_1 | P i) F i = \rsum_(i in A | Q i) G i.
Proof.
move=> FG PQ.
rewrite (reindex_onto (fun i => \row_(j < 1) i) (fun p => p ``_ ord0)) /=; last first.
move=> m Pm.
apply/matrixP => a b; rewrite {a}(ord1 a) {b}(ord1 b); by rewrite mxE.
apply eq_big => a.
by rewrite PQ mxE eqxx andbT.
by rewrite FG !mxE.
Qed.
End big_sum_rV.
Section big_sums_rV.
Variable A : finType.
Lemma rsum_0rV F Q :
\rsum_( j in 'rV[A]_0 | Q j) F j = if Q (row_of_tuple [tuple]) then F (row_of_tuple [tuple]) else 0.
Proof.
rewrite -big_map /= /index_enum -enumT.
rewrite (_ : enum (matrix_finType A 1 0) = row_of_tuple ([tuple]) :: [::]).
by rewrite /= big_cons big_nil addR0.
apply eq_from_nth with (row_of_tuple [tuple]) => /=.
by rewrite size_tuple card_matrix.
move=> i.
rewrite size_tuple card_matrix expn0.
destruct i => //= _.
set xx := enum _ .
destruct xx => //.
destruct s.
apply val_inj => /=.
apply/ffunP.
case => a.
by case.
Qed.
End big_sums_rV.
Section big_sums_rV2.
Local Open Scope vec_ext_scope.
Local Open Scope ring_scope.
Variable A : finType.
Lemma big_singl_rV (p : A -> R) :
\rsum_(i in A) p i = 1%R -> \rsum_(i in 'rV[A]_1) p (i ``_ ord0) = 1%R.
Proof.
move=> <-.
rewrite (reindex_onto (fun j => \row_(i < 1) j) (fun p => p ``_ ord0)) /=.
- apply eq_big => a; first by rewrite mxE eqxx inE.
move=> _; by rewrite mxE.
- move=> t _; apply/matrixP => a b; by rewrite (ord1 a) (ord1 b) mxE.
Qed.
End big_sums_rV2.
Section big_sums_tuples.
Variable A : finType.
Lemma rsum_1_tuple F G P Q :
(forall i : tuple_finType 1 A, F i = G (thead i)) ->
(forall i : tuple_finType 1 A, P i = Q (thead i)) ->
\rsum_(i in {: 1.-tuple A} | P i) F i = \rsum_(i in A | Q i) G i.
Proof.
move=> FG PQ.
rewrite (reindex_onto (fun i => [tuple of [:: i]]) (fun p => thead p)) /=; last first.
case/tupleP => h t X; by rewrite theadE (tuple0 t).
apply eq_big => x //.
by rewrite (PQ [tuple x]) /= theadE eqxx andbC.
move=> X; by rewrite FG.
Qed.
(* TODO: useless? *)
Lemma rsum_0tuple F Q :
\rsum_( j in {:0.-tuple A} | Q j) F j = if Q [tuple] then F [tuple] else 0.
Proof.
rewrite -big_map /= /index_enum -enumT (_ : enum (tuple_finType 0 A) = [tuple] :: [::]).
by rewrite /= big_cons big_nil addR0.
apply eq_from_nth with [tuple] => /=.
by rewrite size_tuple card_tuple.
move=> i.
rewrite size_tuple card_tuple expn0.
destruct i => //= _.
set xx := enum _ .
destruct xx => //.
destruct s.
apply val_inj => /=.
by destruct tval.
Qed.
Lemma big_singl_tuple (p : A -> R) :
\rsum_(i in A) p i = 1 -> \rsum_(i in {: 1.-tuple A}) p (thead i) = 1.
Proof.
move=> <-.
rewrite (reindex_onto (fun j => [tuple of [:: j]]) (fun p => thead p)) => /=.
- apply eq_bigl => x; by rewrite theadE inE eqxx.
- by move=> i _; apply thead_tuple1.
Qed.
(*Lemma big_head_behead_P n (F : 'rV[A]_n.+1 -> R) (P1 : pred A) (P2 : pred 'rV[A]_n) :
\rsum_(i in A | P1 i) \rsum_(j in 'rV[A]_n | P2 j) (F (row_mx (\row_(k < 1) i) j))
=
\rsum_(p in 'rV[A]_n.+1 | (P1 (p /_ ord0)) && (P2 (tbehead p)) ) (F p).
Proof.
symmetry.
rewrite (@partition_big _ _ _ _ _ _ (fun x : {: n.+1.-tuple A} => thead x)
(fun x : A => P1 x)) //=.
- apply eq_bigr => i Hi.
rewrite (reindex_onto (fun j : {: n.-tuple A} => [tuple of (i :: j)])
(fun p => [tuple of (behead p)])) /=; last first.
move=> j Hj.
case/andP : Hj => Hj1 /eqP => <-.
symmetry.
by apply tuple_eta.
apply congr_big => // x /=.
rewrite !theadE eqxx /= Hi /= -andbA /=.
set tmp := _ == x.
have Htmp : tmp = true.
rewrite /tmp tupleE /behead_tuple /=.
apply/eqP => /=.
by apply val_inj.
rewrite Htmp andbC /=.
f_equal.
by apply/eqP.
move=> i; by case/andP.
Qed.
Lemma big_head_behead_P_set n (F : n.+1.-tuple A -> R) (P1 : {set A}) (P2 : {set {: n.-tuple A}}) :
\rsum_(i in P1) \rsum_(j in P2) (F [tuple of (i :: j)])
=
\rsum_(p | (thead p \in P1) && (tbehead p \in P2)) (F p).
Proof.
symmetry.
rewrite (@partition_big _ _ _ _ _ _ (fun x : {: n.+1.-tuple A} => thead x)
(fun x : A => x \in P1)) //=.
- apply eq_bigr => i Hi.
rewrite (reindex_onto (fun j : {: n.-tuple A} => [tuple of (i :: j)])
(fun p => [tuple of (behead p)])) /=; last first.
move=> j Hj.
case/andP : Hj => Hj1 /eqP => <-.
symmetry.
by apply tuple_eta.
apply congr_big => // x /=.
rewrite !theadE eqxx /= Hi /= -andbA /=.
set tmp := _ == x.
have Htmp : tmp = true.
rewrite /tmp tupleE /behead_tuple /=.
apply/eqP => /=.
by apply val_inj.
rewrite Htmp andbC /=.
f_equal.
by apply/eqP.
move=> i; by case/andP.
Qed.
Lemma big_head_behead n (F : n.+1.-tuple A -> R) :
\rsum_(i in A) \rsum_(j in {: n.-tuple A}) (F [tuple of (i :: j)]) =
\rsum_(p in {: n.+1.-tuple A}) (F p).
Proof. by rewrite big_head_behead_P. Qed.*)
(*Lemma big_cat_tuple m n (F : (m + n)%nat.-tuple A -> R) :
\rsum_(i in {:m.-tuple A} ) \rsum_(j in {: n.-tuple A})
F [tuple of (i ++ j)] = \rsum_(p in {: (m + n)%nat.-tuple A}) (F p).
Proof.
move: m n F.
elim.
- move=> m2 F /=.
transitivity ( \rsum_(i <- [tuple] :: [::])
\rsum_(j in tuple_finType m2 A) F [tuple of i ++ j] ).
apply congr_big => //=.
symmetry.
rewrite /index_enum /=.
rewrite Finite.EnumDef.enumDef /=.
apply eq_from_nth with [tuple] => //=.
by rewrite FinTuple.size_enum expn0.
case=> //= _.
destruct (FinTuple.enum 0 A) => //.
by rewrite (tuple0 t).
rewrite big_cons /= big_nil /= addR0.
apply eq_bigr => // i _.
f_equal.
by apply val_inj.
- move=> m IH n F.
symmetry.
transitivity (\rsum_(p in tuple_finType (m + n).+1 A) F p); first by apply congr_big.
rewrite -big_head_behead -big_head_behead.
apply eq_bigr => i _.
symmetry.
move: {IH}(IH n (fun x => F [tuple of i :: x])) => <-.
apply eq_bigr => i0 _.
apply eq_bigr => i1 _.
f_equal.
by apply val_inj.
Qed.
Lemma big_cat_tuple_seq m n (F : seq A -> R) :
\rsum_(i in {:m.-tuple A} ) \rsum_(j in {: n.-tuple A}) (F (i ++ j)) =
\rsum_(p in {: (m + n)%nat.-tuple A}) (F p).
Proof.
move: (@big_cat_tuple m n (fun l => if size l == (m+n)%nat then F l else 0)) => IH.
set lhs := \rsum_(i in _) _ in IH.
apply trans_eq with lhs.
rewrite /lhs.
apply eq_bigr => i _.
apply eq_bigr => j _.
set test := _ == _.
have Htest : test = true by rewrite /test size_tuple eqxx.
case: ifP => // abs.
by rewrite abs in Htest.
rewrite IH.
apply eq_bigr => i _.
by rewrite size_tuple eqxx.
Qed.*)
Local Open Scope vec_ext_scope.
Local Open Scope ring_scope.
Lemma big_head_rbehead n (F : 'rV[A]_n.+1 -> R) (i : A) :
\rsum_(j in 'rV[A]_n) (F (row_mx (\row_(k < 1) i) j)) =
\rsum_(p in 'rV[A]_n.+1 | p ``_ ord0 == i) (F p).
Proof.
symmetry.
rewrite (reindex_onto (fun j : 'rV[A]_n => (row_mx (\row_(k < 1) i) j))
(fun p : 'rV[A]_n.+1=> rbehead p)) /=; last first.
move=> m Hm.
apply/matrixP => a b; rewrite {a}(ord1 a).
rewrite row_mx_rbehead //.
by apply/eqP.
apply eq_bigl => /= x.
by rewrite rbehead_row_mx eqxx andbT row_mx_row_ord0 eqxx.
Qed.
(*Lemma big_behead_head n (F : n.+1.-tuple A -> R) (i : A) :
\rsum_(j in {: n.-tuple A}) (F [tuple of (i :: j)]) =
\rsum_(p in {: n.+1.-tuple A} | thead p == i) (F p).
Proof.
symmetry.
rewrite (reindex_onto (fun j : {: n.-tuple A} => [tuple of (i :: j)])
(fun p => tbehead p)) /=; last first.
move=> ij /eqP => <-; by rewrite -tuple_eta.
apply eq_bigl => /= x.
rewrite inE /= theadE eqxx /=.
apply/eqP.
rewrite tupleE /behead_tuple /=.
by apply val_inj.
Qed.*)
(* TODO: rename *)
Lemma big_head_big_behead n (F : 'rV[A]_n.+1 -> R) (j : 'rV[A]_n) :
\rsum_(i in A ) (F (row_mx (\row_(k < 1) i) j)) =
\rsum_(p in 'rV[A]_n.+1 | rbehead p == j) (F p).
Proof.
apply/esym.
rewrite (reindex_onto (fun p => row_mx (\row_(k < 1) p) j) (fun p => p ``_ ord0) ) /=; last first.
move=> i /eqP <-.
apply/matrixP => a b; rewrite {a}(ord1 a).
by rewrite row_mx_rbehead.
apply eq_bigl => /= a.
by rewrite rbehead_row_mx eqxx /= row_mx_row_ord0 eqxx.
Qed.
(*Lemma big_head_big_behead n (F : n.+1.-tuple A -> R) (j : {:n.-tuple A}) :
\rsum_(i in A ) (F [tuple of (i :: j)]) =
\rsum_(p in {:n.+1.-tuple A} | behead p == j) (F p).
Proof.
symmetry.
rewrite (reindex_onto (fun p => [tuple of (p :: j)]) (fun p => thead p) ) /=; last first.
case/tupleP => hd tl /=; move/eqP => tl_i.
rewrite !tupleE.
f_equal.
by apply val_inj.
apply eq_bigl => /= a; by rewrite inE /= theadE eqxx /= eqxx.
Qed.*)
Lemma big_head_rbehead_P_set n (F : 'rV[A]_n.+1 -> R) (P1 : {set A}) (P2 : {set {: 'rV[A]_n}}) :
\rsum_(i in P1) \rsum_(j in P2) (F (row_mx (\row_(k < 1) i) j))
=
\rsum_(p in 'rV[A]_n.+1 | (p ``_ ord0 \in P1) && (rbehead p \in P2)) (F p).
Proof.
apply/esym.
rewrite (@partition_big _ _ _ _ _ _ (fun x : 'rV[A]_n.+1 => x ``_ ord0)
(fun x : A => x \in P1)) //=.
- apply eq_bigr => i Hi.
rewrite (reindex_onto (fun j : 'rV[A]_n => row_mx (\row_(k < 1) i) j) rbehead) /=; last first.
move=> j Hj.
case/andP : Hj => Hj1 /eqP => <-.
apply/matrixP => a b; rewrite {a}(ord1 a).
by rewrite row_mx_rbehead.
apply congr_big => // x /=.
by rewrite rbehead_row_mx eqxx andbT row_mx_row_ord0 eqxx Hi andbT.
move=> i; by case/andP.
Qed.
Lemma big_head_behead_P n (F : 'rV[A]_n.+1 -> R) (P1 : pred A) (P2 : pred 'rV[A]_n) :
\rsum_(i in A | P1 i) \rsum_(j in 'rV[A]_n | P2 j) (F (row_mx (\row_(k < 1) i) j))
=
\rsum_(p in 'rV[A]_n.+1 | (P1 (p ``_ ord0)) && (P2 (rbehead p)) ) (F p).
Proof.
symmetry.
rewrite (@partition_big _ _ _ _ _ _ (fun x : 'rV[A]_n.+1 => x ``_ ord0)
(fun x : A => P1 x)) //=.
- apply eq_bigr => i Hi.
rewrite (reindex_onto (fun j : 'rV[A]_n => row_mx (\row_(k < 1) i) j) rbehead) /=; last first.
move=> j Hj.
case/andP : Hj => Hj1 /eqP => <-.
apply/matrixP => a b; rewrite {a}(ord1 a).
by rewrite row_mx_rbehead.
apply congr_big => // x /=.
by rewrite row_mx_row_ord0 rbehead_row_mx 2!eqxx Hi !andbT.
move=> i; by case/andP.
Qed.
Lemma big_head_behead n (F : 'rV[A]_n.+1 -> R) :
\rsum_(i in A) \rsum_(j in 'rV[A]_n) (F (row_mx (\row_(k < 1) i) j)) =
\rsum_(p in 'rV[A]_n.+1) (F p).
Proof. by rewrite big_head_behead_P. Qed.
Lemma big_tcast n (F : n.-tuple A -> R) (P : pred {: n.-tuple A}) m
(n_m : m = n) :
\rsum_(p in {: n.-tuple A} | P p) (F p) =
\rsum_(p in {: m.-tuple A} | P (tcast n_m p)) (F (tcast n_m p)).
Proof.
subst m.
apply eq_bigr => ta.
case/andP => _ H.
by rewrite tcast_id.
Qed.
Local Open Scope tuple_ext_scope.
(* TODO: remove? *)
Lemma rsum_tuple_tnth n i (f : n.+1.-tuple A -> R):
\rsum_(t | t \in {: n.+1.-tuple A}) f t =
\rsum_(a | a \in A) \rsum_(t | t \_ i == a) f t.
Proof.
by rewrite (partition_big (fun x : n.+1.-tuple A => x \_ i) xpredT).
Qed.
Local Close Scope tuple_ext_scope.
End big_sums_tuples.
Section sum_tuple_ffun.
Import Monoid.Theory.
Variable R : Type.
Variable times : Monoid.mul_law 0.
Notation Local "*%M" := times (at level 0).
Variable plus : Monoid.add_law 0 *%M.
Notation Local "+%M" := plus (at level 0).
Lemma sum_tuple_ffun (I J : finType) (F : {ffun I -> J} -> R)
(G : _ -> _ -> _) (jdef : J) (idef : I) :
\big[+%M/0]_(j : #|I|.-tuple J) G (F (Finfun j)) (nth jdef j 0)
= \big[+%M/0]_(f : {ffun I -> J}) G (F f) (f (nth idef (enum I) 0)).
Proof.
rewrite (reindex_onto (fun y => fgraph y) (fun p => Finfun p)) //.
apply eq_big; first by case => t /=; by rewrite eqxx.
move=> i _.
f_equal.
by destruct i.
destruct i as [ [tval Htval] ].
rewrite [fgraph _]/= -(nth_map idef jdef); last first.
rewrite -cardE.
apply/card_gt0P.
by exists idef.
by rewrite -codomE codom_ffun.
Qed.
End sum_tuple_ffun.
Lemma sum_f_R0_rsum : forall k (f : nat -> R),
sum_f_R0 f k = \rsum_(i<k.+1) f i.
Proof.
elim => [f|] /=.
by rewrite big_ord_recl /= big_ord0 addR0.
move=> k IH f.
by rewrite big_ord_recr /= IH.
Qed.
Theorem RPascal k (a b : R) :
(a + b) ^ k = \rsum_(i < k.+1) INR ('C(k, i))* (a ^ (k - i) * b ^ i).
Proof.
rewrite addRC Binomial.binomial sum_f_R0_rsum.
apply eq_bigr => i _.
rewrite combinaison_Coq_SSR; last by rewrite -ltnS.
rewrite -minusE; field.
Qed.
(** Rle, Rlt lemmas for big-mult of reals *)
Reserved Notation "\rmul_ ( i : A | P ) F"
(at level 41, F at level 41, i, A at level 50,
format "'[' \rmul_ ( i : A | P ) '/ ' F ']'").
Reserved Notation "\rmul_ ( i : t ) F"
(at level 41, F at level 41, i at level 50, only parsing).
Reserved Notation "\rmul_ ( i 'in' A ) F"
(at level 41, F at level 41, i, A at level 50,
format "'[' \rmul_ ( i 'in' A ) '/ ' F ']'").
Notation "\rmul_ ( i | P ) F" := (\big[Rmult/1%R]_( i | P) F)
(at level 41, F at level 41, i at level 50,
format "'[' \rmul_ ( i | P ) '/ ' F ']'") : R_scope.
Reserved Notation "\rmul_ ( i < A | P ) F"
(at level 41, F at level 41, i, A at level 50,
format "'[' \rmul_ ( i < A | P ) '/ ' F ']'").
Reserved Notation "\rmul_ ( i < t ) F"
(at level 41, F at level 41, i, t at level 50,
format "'[' \rmul_ ( i < t ) '/ ' F ']'").
Notation "\rmul_ ( i : A | P ) F" := (\big[Rmult/R1]_( i : A | P ) F): R_scope.
Notation "\rmul_ ( i : t ) F" := (\big[Rmult/R1]_( i : t ) F) : R_scope.
Notation "\rmul_ ( i 'in' A ) F" := (\big[Rmult/R1]_( i in A ) F) : R_scope.
Notation "\rmul_ ( i < A | P ) F" := (\big[Rmult/R1]_( i < A | P ) F): R_scope.
Notation "\rmul_ ( i < t ) F" := (\big[Rmult/R1]_( i < t ) F) : R_scope.
Section compare_big_mult.
Lemma Rlt_0_big_mult {A : finType} F : (forall i, 0 < F i) ->
0 < \rmul_(i : A) F i.
Proof.
move=> H.
elim: (index_enum _) => [| hd tl IH].
rewrite big_nil; fourier.
rewrite big_cons; apply Rmult_lt_0_compat => //; by apply H.
Qed.
Lemma Rle_0_big_mult {A : finType} F : (forall i, 0 <= F i) ->
0 <= \rmul_(i : A) F i.
Proof.
move=> H.
elim: (index_enum _) => [| hd tl IH].
rewrite big_nil; fourier.
rewrite big_cons; apply Rmult_le_pos => //; by apply H.
Qed.
Local Open Scope vec_ext_scope.
Local Open Scope ring_scope.
Lemma Rlt_0_rmul_inv {B : finType} F (HF: forall a, 0 <= F a) :
forall n (x : 'rV[B]_n.+1),
0 < \rmul_(i < n.+1) F (x ``_ i) -> forall i, 0 < F (x ``_ i).
Proof.
elim => [x | n IH].
rewrite big_ord_recr /= big_ord0 mul1R => Hi i.
suff : i = ord_max by move=> ->.
rewrite (ord1 i).
by apply/val_inj.
move=> x.
set t := \row_(i < n.+1) (x ``_ (lift ord0 i)).
rewrite big_ord_recl /= => H.
apply Rlt_0_Rmult_inv in H; last 2 first.
by apply HF.
apply Rle_0_big_mult => i; by apply HF.
case.
case=> [Hi | i Hi].
rewrite (_ : Ordinal _ = ord0); last by apply val_inj.
by case: H.
case: H => _ H.
have : 0 < \rmul_(i0 < n.+1) F (t ``_ i0).
suff : \rmul_(i < n.+1) F (x ``_ (lift ord0 i)) =
\rmul_(i0 < n.+1) F (t ``_ i0).
by move=> <-.
apply eq_bigr => j _.
by rewrite mxE.
have Hi' : (i < n.+1)%nat.
clear -Hi; by rewrite ltnS in Hi.
move/IH.
move/(_ (Ordinal Hi')).
set o1 := Ordinal _.
set o2 := Ordinal _.
suff : lift ord0 o1 = o2.
move=> <-.
by rewrite mxE.
by apply val_inj.
Qed.
(*
Lemma Rlt_0_rmul_inv {B : finType} F (HF: forall a, 0 <= F a) :
forall n (x : n.+1.-tuple B),
0 < \rmul_(i < n.+1) F (tnth x i) -> forall i, 0 < F (tnth x i).
Proof.
elim => [x | n IH].
rewrite big_ord_recr /= big_ord0 mul1R => Hi i.
suff : i = ord_max by move=> ->.
rewrite (ord1 i).
by apply/val_inj.
case/tupleP => h t.
rewrite big_ord_recl /= => H.
apply Rlt_0_Rmult_inv in H; last 2 first.
by apply HF.
apply Rle_0_big_mult => i; by apply HF.
case.
case=> [Hi | i Hi].
by case: H.
case: H => _ H.
have : 0 < \rmul_(i0<n.+1) F (tnth t i0).
suff : \rmul_(i<n.+1) F (tnth [tuple of h :: t] (lift ord0 i)) =
\rmul_(i0<n.+1) F (tnth t i0).
by move=> <-.
apply eq_bigr => j _.
f_equal.
have Ht : t = [tuple of behead (h :: t)].
rewrite (tuple_eta t) /=.
by apply/val_inj.
rewrite Ht /=.
rewrite tnth_behead /=.
f_equal.
by apply val_inj.
rewrite -(lift0 j).
by rewrite inord_val.
have Hi' : (i < n.+1)%nat.
clear -Hi; by rewrite ltnS in Hi.
move/IH.
move/(_ (Ordinal Hi')).
suff : (tnth t (Ordinal Hi')) = (tnth [tuple of h :: t] (Ordinal Hi)).
by move=> ->.
have Ht : t = [tuple of behead (h :: t)].
rewrite (tuple_eta t) /=.
by apply/val_inj.
rewrite Ht /= tnth_behead /=.
f_equal.
by apply val_inj.
apply val_inj => /=; by rewrite inordK.
Qed.
*)
Lemma Rle_1_big_mult {A : finType} f : (forall i, 1 <= f i) ->
1 <= \rmul_(i : A) f i.
Proof.
move=> Hf.
elim: (index_enum _) => [| hd tl IH].
- rewrite big_nil; by apply Rle_refl.
- rewrite big_cons -{1}(mulR1 1%R).
apply Rmult_le_compat => // ; fourier.
Qed.
Local Open Scope R_scope.
Lemma Rle_big_mult {A : finType} f g : (forall i, 0 <= f i <= g i) ->
\rmul_(i : A) f i <= \rmul_(i : A) g i.
Proof.
move=> Hfg.
case/orP : (orbN [forall i, f i != 0%R]) ; last first.
- rewrite negb_forall => /existsP Hf.
case: Hf => i0 /negPn/eqP Hi0.
rewrite (bigD1 i0) //= Hi0 mul0R; apply Rle_0_big_mult.
move=> i ; move: (Hfg i) => [Hi1 Hi2] ; by apply (Rle_trans _ _ _ Hi1 Hi2).
- move=> /forallP Hf.
have Hprodf : 0 < \rmul_(i:A) f i.
apply Rlt_0_big_mult => i.
move: (Hf i) (Hfg i) => {Hf}Hf {Hfg}[Hf2 _].
apply/RltP; rewrite Rlt_neqAle eq_sym Hf /=; by apply/RleP.
apply (Rmult_le_reg_r (1 * / \rmul_(i : A) f i) _ _).
apply Rlt_mult_inv_pos => //; fourier.
rewrite mul1R Rinv_r; last by apply not_eq_sym, Rlt_not_eq.
set inv_spec := fun r => if r == 0 then 0 else / r.
rewrite (_ : / (\rmul_(a : A) f a) = inv_spec (\rmul_(a : A) f a)) ; last first.
rewrite /inv_spec (_ : \rmul_(a : A) f a == 0 = false) //.
apply/eqP ; by apply not_eq_sym, Rlt_not_eq.
rewrite (@big_morph _ _ (inv_spec) R1 Rmult R1 Rmult _); last 2 first.
- move=> a b /=.
case/boolP : ((a != 0) && (b != 0)).
- move=> /andP [/negbTE Ha /negbTE Hb] ; rewrite /inv_spec Ha Hb.
move/negbT in Ha ; move/negbT in Hb.
have : (a * b)%R == 0 = false ; last move=> ->.
apply/negP => /eqP Habs.
apply (Rmult_eq_compat_r (/ b)) in Habs ; move: Habs.
rewrite -mulRA mul0R Rinv_r ?mulR1; move/eqP; by apply/negP.
apply Rinv_mult_distr; move/eqP; by apply/negP.
- rewrite negb_and => Hab.
case/orP : (orbN (a != 0)) => Ha.
- rewrite Ha /= in Hab; move/negPn/eqP in Hab; rewrite Hab mulR0 /inv_spec.
by rewrite (_ : 0 == 0 ) // mulR0.
- move/negPn/eqP in Ha ; rewrite Ha mul0R /inv_spec.
by rewrite (_ : 0 == 0 ) // mul0R.
- rewrite /inv_spec.
have : ~~ (1 == 0).
apply/eqP => H01; symmetry in H01; move: H01; apply Rlt_not_eq; fourier.
move/negbTE => -> ; by rewrite Rinv_1.
rewrite -big_split /=.
apply Rle_1_big_mult => i.
move/(_ i) in Hf.
move: Hfg => /(_ i) [Hf2 Hfg].
rewrite /inv_spec.
move/negbTE in Hf ; rewrite Hf ; move/negbT in Hf.
rewrite -(Rinv_r (f i)); last by move/eqP; apply/negP.
apply Rmult_le_compat_r => //.
rewrite -(mul1R (/ f i)).
apply Rle_mult_inv_pos; first fourier.
apply/RltP; rewrite Rlt_neqAle eq_sym Hf /=; by apply/RleP.
Qed.
Local Close Scope R_scope.
End compare_big_mult.
Local Open Scope vec_ext_scope.
Local Open Scope ring_scope.
Lemma log_rmul_rsum_mlog {A : finType} (f : A -> R+) : forall n (ta : 'rV[A]_n.+1),
(forall i, 0 < f ta ``_ i) ->
(- log (\rmul_(i < n.+1) f ta ``_ i) = \rsum_(i < n.+1) - log (f ta ``_ i))%R.
Proof.
elim => [i Hi | n IH].
by rewrite big_ord_recl big_ord0 mulR1 big_ord_recl big_ord0 addR0.
move=> ta Hi.
rewrite big_ord_recl /= log_mult; last 2 first.
by apply Hi.
apply Rlt_0_big_mult => i; by apply Hi.
set tl := \row_(i < n.+1) ta ``_ (lift ord0 i).
have Htmp : forall i0 : 'I_n.+1, 0 < f tl ``_ i0.
move=> i.
rewrite mxE.
by apply Hi.
move: {IH Htmp}(IH _ Htmp) => IH.
have -> : \rmul_(i < n.+1) f ta ``_ (lift ord0 i) = \rmul_(i0<n.+1) f tl ``_ i0.
apply eq_bigr => i _.
congr (f _).
by rewrite /tl mxE.
rewrite Ropp_plus_distr [X in _ = X]big_ord_recl IH.
congr (_ + _)%R.
apply eq_bigr => i _.
by rewrite /tl mxE.
Qed.
(*Lemma log_rmul_rsum_mlog {A : finType} (f : A -> R+) : forall n (ta : n.+1.-tuple A),
(forall i, 0 < f ta \_ i) ->
- log (\rmul_(i < n.+1) f ta \_ i) = \rsum_(i < n.+1) - log (f ta \_ i).
Proof.
elim => [i Hi | n IH].
by rewrite big_ord_recl big_ord0 mulR1 big_ord_recl big_ord0 addR0.
case/tupleP => hd tl Hi.
rewrite big_ord_recl /= log_mult; last 2 first.
by apply Hi.
apply Rlt_0_big_mult => i; by apply Hi.
have Htmp : forall i0 : 'I_n.+1, 0 < f tl \_ i0.
move=> i.
move: {Hi}(Hi (inord i.+1)) => Hi.
set rhs := _ \_ _ in Hi.
suff : tl \_ i = rhs by move=> ->.
rewrite /rhs -tnth_behead /=.
f_equal.
by apply val_inj.
move: {IH Htmp}(IH tl Htmp) => IH.
have -> : \rmul_(i < n.+1) f [tuple of hd :: tl] \_ (lift ord0 i) = \rmul_(i0<n.+1) f tl \_ i0.
apply eq_bigr => i _.
f_equal.
rewrite (_ : lift _ _ = inord i.+1); last by rewrite -lift0 inord_val.
rewrite -tnth_behead /=.
f_equal.
by apply val_inj.
rewrite Ropp_plus_distr [X in _ = X]big_ord_recl IH.
f_equal.
apply eq_bigr => i _.
do 3 f_equal.
rewrite (_ : lift _ _ = inord i.+1); last by rewrite -lift0 inord_val.
rewrite -tnth_behead /=.
f_equal.
by apply val_inj.
Qed.*)
Local Close Scope tuple_ext_scope.
|
#! /usr/bin/Rscript
setwd("/var/textBasedIR/")
library(ggplot2)
df <- read.csv("flickr8k_unigram_hybrid_results.csv",
header = FALSE,
col.names = c("method", "lambda",
"recall@1", "mrr"))
setwd("/home/mandar/Desktop/")
p1 <- ggplot(df, aes(x = recall.1, y = mrr)) +
geom_point(size=3, aes(color=factor(method), shape=factor(method))) +
geom_smooth(aes(color=factor(method)), method = "lm", se = FALSE) +
theme_bw() +
theme(
axis.title.x = element_text(face="bold", color="black", size=12),
axis.title.y = element_text(face="bold", color="black", size=12),
plot.title = element_text(face="bold", color = "black", size=12),
legend.position=c(1,1),
legend.justification=c(1,1)) +
labs(x="Recall@1",
y = "Mean Reciprocal Rank",
title= "Linear Regression (95% CI) of Mean Reciprocal Rank vs Recall@1, by selection method")
p2 <- ggplot(df, aes(x = lambda, y = mrr))+
geom_point(size=3, aes(color=factor(method), shape=factor(method))) +
geom_smooth(aes(color=factor(method)), method = "lm", se = FALSE) +
theme_bw() +
theme(
axis.title.x = element_text(face="bold", color="black", size=12),
axis.title.y = element_text(face="bold", color="black", size=12),
plot.title = element_text(face="bold", color = "black", size=12),
legend.position=c(1,1),
legend.justification=c(1,1)) +
labs(x="Number of Lambda",
y = "Mean Reciprocal Rank",
title= "Linear Regression (95% CI) of Mean Reciprocal Rank vs Lambda, by selection method")
p3 <- ggplot(df, aes(x = lambda, y = recall.1)) +
geom_point(size=3, aes(color=factor(method), shape=factor(method))) +
geom_smooth(aes(color=factor(method)), method = "lm", se = FALSE) +
theme_bw() +
theme(
axis.title.x = element_text(face="bold", color="black", size=12),
axis.title.y = element_text(face="bold", color="black", size=12),
plot.title = element_text(face="bold", color = "black", size=12),
legend.position=c(1,1),
legend.justification=c(1,1)) +
labs(x="Number of Lambda",
y = "Recall@1",
title= "Linear Regression (95% CI) of Recall@1 vs Lambda, by selection method")
|
I was able to capture a video of the "tearing" as well, here is the frame(s) that it happens in on both the source file and the actual playback on catalyst. It is somewhat subtle at times but on videos with more motion it is more noticeable.
I have files that run on the exact same machine that have double that data rate that run fine, they just don't have any fast motion so I don't see it.
This is with 1 layer running, plenty of system resources showing on the meters and no apparent frame drops. In testing I could play back I think 6 layers of this file with no frame drops.
I have more pics if it's helpful.
Any news on the Mavericks patch?
I just had to replace my Mac Pro and the new model won't run osx 10.7 or 10.8!!!
Although it is not a show computer I do use it for pre vis and programming and we start production rehearsals next week!!
I am sure Richard will post the link to the download when he is happy for it to be used on shows. |
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
⊢ AffineIndependent k p ↔
∀ (w : ι → k), ∑ i : ι, w i = 0 → ↑(Finset.weightedVSub Finset.univ p) w = 0 → ∀ (i : ι), w i = 0
[PROOFSTEP]
constructor
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
⊢ AffineIndependent k p →
∀ (w : ι → k), ∑ i : ι, w i = 0 → ↑(Finset.weightedVSub Finset.univ p) w = 0 → ∀ (i : ι), w i = 0
[PROOFSTEP]
exact fun h w hw hs i => h Finset.univ w hw hs i (Finset.mem_univ _)
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
⊢ (∀ (w : ι → k), ∑ i : ι, w i = 0 → ↑(Finset.weightedVSub Finset.univ p) w = 0 → ∀ (i : ι), w i = 0) →
AffineIndependent k p
[PROOFSTEP]
intro h s w hw hs i hi
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h : ∀ (w : ι → k), ∑ i : ι, w i = 0 → ↑(Finset.weightedVSub Finset.univ p) w = 0 → ∀ (i : ι), w i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i : ι
hi : i ∈ s
⊢ w i = 0
[PROOFSTEP]
rw [Finset.weightedVSub_indicator_subset _ _ (Finset.subset_univ s)] at hs
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h : ∀ (w : ι → k), ∑ i : ι, w i = 0 → ↑(Finset.weightedVSub Finset.univ p) w = 0 → ∀ (i : ι), w i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub Finset.univ p) (Set.indicator (↑s) w) = 0
i : ι
hi : i ∈ s
⊢ w i = 0
[PROOFSTEP]
rw [Set.sum_indicator_subset _ (Finset.subset_univ s)] at hw
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h : ∀ (w : ι → k), ∑ i : ι, w i = 0 → ↑(Finset.weightedVSub Finset.univ p) w = 0 → ∀ (i : ι), w i = 0
s : Finset ι
w : ι → k
hw : ∑ i : ι, Set.indicator (↑s) (fun i => w i) i = 0
hs : ↑(Finset.weightedVSub Finset.univ p) (Set.indicator (↑s) w) = 0
i : ι
hi : i ∈ s
⊢ w i = 0
[PROOFSTEP]
replace h := h ((↑s : Set ι).indicator w) hw hs i
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
s : Finset ι
w : ι → k
hw : ∑ i : ι, Set.indicator (↑s) (fun i => w i) i = 0
hs : ↑(Finset.weightedVSub Finset.univ p) (Set.indicator (↑s) w) = 0
i : ι
hi : i ∈ s
h : Set.indicator (↑s) w i = 0
⊢ w i = 0
[PROOFSTEP]
simpa [hi] using h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
⊢ AffineIndependent k p ↔ LinearIndependent k fun i => p ↑i -ᵥ p i1
[PROOFSTEP]
classical
constructor
· intro h
rw [linearIndependent_iff']
intro s g hg i hi
set f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g ⟨x, hx⟩ with hfdef
let s2 : Finset ι := insert i1 (s.map (Embedding.subtype _))
have hfg : ∀ x : { x // x ≠ i1 }, g x = f x := by
intro x
rw [hfdef]
dsimp only
erw [dif_neg x.property, Subtype.coe_eta]
rw [hfg]
have hf : ∑ ι in s2, f ι = 0 :=
by
rw [Finset.sum_insert (Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)),
Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm]
rw [hfdef]
dsimp only
rw [dif_pos rfl]
exact neg_add_self _
have hs2 : s2.weightedVSub p f = (0 : V) :=
by
set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def
set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1)
have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x :=
by
simp only [hf2def]
refine' fun x => _
rw [hfg]
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1), Finset.weightedVSubOfPoint_insert,
Finset.weightedVSubOfPoint_apply, Finset.sum_subtype_map_embedding fun x _ => hf2g2 x]
exact hg
exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 ⟨i, hi, rfl⟩))
· intro h
rw [linearIndependent_iff'] at h
intro s w hw hs i hi
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p hw (p i1), ← s.weightedVSubOfPoint_erase w p i1,
Finset.weightedVSubOfPoint_apply] at hs
let f : ι → V := fun i => w i • (p i -ᵥ p i1)
have hs2 : (∑ i in (s.erase i1).subtype fun i => i ≠ i1, f i) = 0 :=
by
rw [← hs]
convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase
have h2 := h ((s.erase i1).subtype fun i => i ≠ i1) (fun x => w x) hs2
simp_rw [Finset.mem_subtype] at h2
have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := fun i his hi => h2 ⟨i, hi⟩ (Finset.mem_erase_of_ne_of_mem hi his)
exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
⊢ AffineIndependent k p ↔ LinearIndependent k fun i => p ↑i -ᵥ p i1
[PROOFSTEP]
constructor
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
⊢ AffineIndependent k p → LinearIndependent k fun i => p ↑i -ᵥ p i1
[PROOFSTEP]
intro h
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
⊢ LinearIndependent k fun i => p ↑i -ᵥ p i1
[PROOFSTEP]
rw [linearIndependent_iff']
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
⊢ ∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
[PROOFSTEP]
intro s g hg i hi
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
⊢ g i = 0
[PROOFSTEP]
set f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g ⟨x, hx⟩ with hfdef
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
⊢ g i = 0
[PROOFSTEP]
let s2 : Finset ι := insert i1 (s.map (Embedding.subtype _))
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
⊢ g i = 0
[PROOFSTEP]
have hfg : ∀ x : { x // x ≠ i1 }, g x = f x := by
intro x
rw [hfdef]
dsimp only
erw [dif_neg x.property, Subtype.coe_eta]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
⊢ ∀ (x : { x // x ≠ i1 }), g x = f ↑x
[PROOFSTEP]
intro x
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
x : { x // x ≠ i1 }
⊢ g x = f ↑x
[PROOFSTEP]
rw [hfdef]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
x : { x // x ≠ i1 }
⊢ g x = (fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }) ↑x
[PROOFSTEP]
dsimp only
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
x : { x // x ≠ i1 }
⊢ g x = if hx : ↑x = i1 then -∑ y in s, g y else g { val := ↑x, property := hx }
[PROOFSTEP]
erw [dif_neg x.property, Subtype.coe_eta]
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
⊢ g i = 0
[PROOFSTEP]
rw [hfg]
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
⊢ f ↑i = 0
[PROOFSTEP]
have hf : ∑ ι in s2, f ι = 0 :=
by
rw [Finset.sum_insert (Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)),
Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm]
rw [hfdef]
dsimp only
rw [dif_pos rfl]
exact neg_add_self _
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
⊢ ∑ ι in s2, f ι = 0
[PROOFSTEP]
rw [Finset.sum_insert (Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)),
Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
⊢ f i1 + ∑ x in s, g x = 0
[PROOFSTEP]
rw [hfdef]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
⊢ (fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }) i1 + ∑ x in s, g x = 0
[PROOFSTEP]
dsimp only
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
⊢ (if hx : i1 = i1 then -∑ y in s, g y else g { val := i1, property := hx }) + ∑ x in s, g x = 0
[PROOFSTEP]
rw [dif_pos rfl]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
⊢ -∑ y in s, g y + ∑ x in s, g x = 0
[PROOFSTEP]
exact neg_add_self _
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
⊢ f ↑i = 0
[PROOFSTEP]
have hs2 : s2.weightedVSub p f = (0 : V) :=
by
set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def
set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1)
have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x :=
by
simp only [hf2def]
refine' fun x => _
rw [hfg]
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1), Finset.weightedVSubOfPoint_insert,
Finset.weightedVSubOfPoint_apply, Finset.sum_subtype_map_embedding fun x _ => hf2g2 x]
exact hg
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
⊢ ↑(Finset.weightedVSub s2 p) f = 0
[PROOFSTEP]
set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
f2 : ι → V := fun x => f x • (p x -ᵥ p i1)
hf2def : f2 = fun x => f x • (p x -ᵥ p i1)
⊢ ↑(Finset.weightedVSub s2 p) f = 0
[PROOFSTEP]
set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
f2 : ι → V := fun x => f x • (p x -ᵥ p i1)
hf2def : f2 = fun x => f x • (p x -ᵥ p i1)
g2 : { x // x ≠ i1 } → V := fun x => g x • (p ↑x -ᵥ p i1)
hg : Finset.sum s g2 = 0
⊢ ↑(Finset.weightedVSub s2 p) f = 0
[PROOFSTEP]
have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x :=
by
simp only [hf2def]
refine' fun x => _
rw [hfg]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
f2 : ι → V := fun x => f x • (p x -ᵥ p i1)
hf2def : f2 = fun x => f x • (p x -ᵥ p i1)
g2 : { x // x ≠ i1 } → V := fun x => g x • (p ↑x -ᵥ p i1)
hg : Finset.sum s g2 = 0
⊢ ∀ (x : { x // x ≠ i1 }), f2 ↑x = g2 x
[PROOFSTEP]
simp only [hf2def]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
f2 : ι → V := fun x => f x • (p x -ᵥ p i1)
hf2def : f2 = fun x => f x • (p x -ᵥ p i1)
g2 : { x // x ≠ i1 } → V := fun x => g x • (p ↑x -ᵥ p i1)
hg : Finset.sum s g2 = 0
⊢ ∀ (x : { x // x ≠ i1 }),
(if hx : ↑x = i1 then -∑ y in s, g y else g { val := ↑x, property := hx }) • (p ↑x -ᵥ p i1) = g x • (p ↑x -ᵥ p i1)
[PROOFSTEP]
refine' fun x => _
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
f2 : ι → V := fun x => f x • (p x -ᵥ p i1)
hf2def : f2 = fun x => f x • (p x -ᵥ p i1)
g2 : { x // x ≠ i1 } → V := fun x => g x • (p ↑x -ᵥ p i1)
hg : Finset.sum s g2 = 0
x : { x // x ≠ i1 }
⊢ (if hx : ↑x = i1 then -∑ y in s, g y else g { val := ↑x, property := hx }) • (p ↑x -ᵥ p i1) = g x • (p ↑x -ᵥ p i1)
[PROOFSTEP]
rw [hfg]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
f2 : ι → V := fun x => f x • (p x -ᵥ p i1)
hf2def : f2 = fun x => f x • (p x -ᵥ p i1)
g2 : { x // x ≠ i1 } → V := fun x => g x • (p ↑x -ᵥ p i1)
hg : Finset.sum s g2 = 0
hf2g2 : ∀ (x : { x // x ≠ i1 }), f2 ↑x = g2 x
⊢ ↑(Finset.weightedVSub s2 p) f = 0
[PROOFSTEP]
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1), Finset.weightedVSubOfPoint_insert,
Finset.weightedVSubOfPoint_apply, Finset.sum_subtype_map_embedding fun x _ => hf2g2 x]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
f2 : ι → V := fun x => f x • (p x -ᵥ p i1)
hf2def : f2 = fun x => f x • (p x -ᵥ p i1)
g2 : { x // x ≠ i1 } → V := fun x => g x • (p ↑x -ᵥ p i1)
hg : Finset.sum s g2 = 0
hf2g2 : ∀ (x : { x // x ≠ i1 }), f2 ↑x = g2 x
⊢ ∑ x in s, g2 x = 0
[PROOFSTEP]
exact hg
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : AffineIndependent k p
s : Finset { x // x ≠ i1 }
g : { x // x ≠ i1 } → k
hg : ∑ i in s, g i • (p ↑i -ᵥ p i1) = 0
i : { x // x ≠ i1 }
hi : i ∈ s
f : ι → k := fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
hfdef : f = fun x => if hx : x = i1 then -∑ y in s, g y else g { val := x, property := hx }
s2 : Finset ι := insert i1 (Finset.map (Embedding.subtype fun x => x ≠ i1) s)
hfg : ∀ (x : { x // x ≠ i1 }), g x = f ↑x
hf : ∑ ι in s2, f ι = 0
hs2 : ↑(Finset.weightedVSub s2 p) f = 0
⊢ f ↑i = 0
[PROOFSTEP]
exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 ⟨i, hi, rfl⟩))
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
⊢ (LinearIndependent k fun i => p ↑i -ᵥ p i1) → AffineIndependent k p
[PROOFSTEP]
intro h
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h : LinearIndependent k fun i => p ↑i -ᵥ p i1
⊢ AffineIndependent k p
[PROOFSTEP]
rw [linearIndependent_iff'] at h
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
⊢ AffineIndependent k p
[PROOFSTEP]
intro s w hw hs i hi
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i : ι
hi : i ∈ s
⊢ w i = 0
[PROOFSTEP]
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p hw (p i1), ← s.weightedVSubOfPoint_erase w p i1,
Finset.weightedVSubOfPoint_apply] at hs
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
⊢ w i = 0
[PROOFSTEP]
let f : ι → V := fun i => w i • (p i -ᵥ p i1)
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
f : ι → V := fun i => w i • (p i -ᵥ p i1)
⊢ w i = 0
[PROOFSTEP]
have hs2 : (∑ i in (s.erase i1).subtype fun i => i ≠ i1, f i) = 0 :=
by
rw [← hs]
convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
f : ι → V := fun i => w i • (p i -ᵥ p i1)
⊢ ∑ i in Finset.subtype (fun i => i ≠ i1) (Finset.erase s i1), f ↑i = 0
[PROOFSTEP]
rw [← hs]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
f : ι → V := fun i => w i • (p i -ᵥ p i1)
⊢ ∑ i in Finset.subtype (fun i => i ≠ i1) (Finset.erase s i1), f ↑i = ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1)
[PROOFSTEP]
convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
f : ι → V := fun i => w i • (p i -ᵥ p i1)
hs2 : ∑ i in Finset.subtype (fun i => i ≠ i1) (Finset.erase s i1), f ↑i = 0
⊢ w i = 0
[PROOFSTEP]
have h2 := h ((s.erase i1).subtype fun i => i ≠ i1) (fun x => w x) hs2
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
f : ι → V := fun i => w i • (p i -ᵥ p i1)
hs2 : ∑ i in Finset.subtype (fun i => i ≠ i1) (Finset.erase s i1), f ↑i = 0
h2 : ∀ (i : { x // x ≠ i1 }), i ∈ Finset.subtype (fun i => i ≠ i1) (Finset.erase s i1) → (fun x => w ↑x) i = 0
⊢ w i = 0
[PROOFSTEP]
simp_rw [Finset.mem_subtype] at h2
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
f : ι → V := fun i => w i • (p i -ᵥ p i1)
hs2 : ∑ i in Finset.subtype (fun i => i ≠ i1) (Finset.erase s i1), f ↑i = 0
h2 : ∀ (i : { x // x ≠ i1 }), ↑i ∈ Finset.erase s i1 → w ↑i = 0
⊢ w i = 0
[PROOFSTEP]
have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := fun i his hi => h2 ⟨i, hi⟩ (Finset.mem_erase_of_ne_of_mem hi his)
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i1 : ι
h :
∀ (s : Finset { x // x ≠ i1 }) (g : { x // x ≠ i1 } → k),
∑ i in s, g i • (p ↑i -ᵥ p i1) = 0 → ∀ (i : { x // x ≠ i1 }), i ∈ s → g i = 0
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ∑ i in Finset.erase s i1, w i • (p i -ᵥ p i1) = 0
i : ι
hi : i ∈ s
f : ι → V := fun i => w i • (p i -ᵥ p i1)
hs2 : ∑ i in Finset.subtype (fun i => i ≠ i1) (Finset.erase s i1), f ↑i = 0
h2 : ∀ (i : { x // x ≠ i1 }), ↑i ∈ Finset.erase s i1 → w ↑i = 0
h2b : ∀ (i : ι), i ∈ s → i ≠ i1 → w i = 0
⊢ w i = 0
[PROOFSTEP]
exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
⊢ (AffineIndependent k fun p => ↑p) ↔ LinearIndependent k fun v => ↑v
[PROOFSTEP]
rw [affineIndependent_iff_linearIndependent_vsub k (fun p => p : s → P) ⟨p₁, hp₁⟩]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
⊢ (LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }) ↔ LinearIndependent k fun v => ↑v
[PROOFSTEP]
constructor
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
⊢ (LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }) → LinearIndependent k fun v => ↑v
[PROOFSTEP]
intro h
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
h : LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
⊢ LinearIndependent k fun v => ↑v
[PROOFSTEP]
have hv : ∀ v : (fun p => (p -ᵥ p₁ : V)) '' (s \ { p₁ }), (v : V) +ᵥ p₁ ∈ s \ { p₁ } := fun v =>
(vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property)
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
h : LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
hv : ∀ (v : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁}))), ↑v +ᵥ p₁ ∈ s \ {p₁}
⊢ LinearIndependent k fun v => ↑v
[PROOFSTEP]
let f : (fun p : P => (p -ᵥ p₁ : V)) '' (s \ { p₁ }) → { x : s // x ≠ ⟨p₁, hp₁⟩ } := fun x =>
⟨⟨(x : V) +ᵥ p₁, Set.mem_of_mem_diff (hv x)⟩, fun hx => Set.not_mem_of_mem_diff (hv x) (Subtype.ext_iff.1 hx)⟩
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
h : LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
hv : ∀ (v : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁}))), ↑v +ᵥ p₁ ∈ s \ {p₁}
f : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁})) → { x // x ≠ { val := p₁, property := hp₁ } } :=
fun x =>
{ val := { val := ↑x +ᵥ p₁, property := (_ : ↑x +ᵥ p₁ ∈ s) },
property := (_ : { val := ↑x +ᵥ p₁, property := (_ : ↑x +ᵥ p₁ ∈ s) } = { val := p₁, property := hp₁ } → False) }
⊢ LinearIndependent k fun v => ↑v
[PROOFSTEP]
convert h.comp f fun x1 x2 hx => Subtype.ext (vadd_right_cancel p₁ (Subtype.ext_iff.1 (Subtype.ext_iff.1 hx)))
[GOAL]
case h.e'_4.h.h.e
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
h : LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
hv : ∀ (v : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁}))), ↑v +ᵥ p₁ ∈ s \ {p₁}
f : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁})) → { x // x ≠ { val := p₁, property := hp₁ } } :=
fun x =>
{ val := { val := ↑x +ᵥ p₁, property := (_ : ↑x +ᵥ p₁ ∈ s) },
property := (_ : { val := ↑x +ᵥ p₁, property := (_ : ↑x +ᵥ p₁ ∈ s) } = { val := p₁, property := hp₁ } → False) }
x✝ : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁}))
⊢ Subtype.val = (fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }) ∘ f
[PROOFSTEP]
ext v
[GOAL]
case h.e'_4.h.h.e.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
h : LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
hv : ∀ (v : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁}))), ↑v +ᵥ p₁ ∈ s \ {p₁}
f : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁})) → { x // x ≠ { val := p₁, property := hp₁ } } :=
fun x =>
{ val := { val := ↑x +ᵥ p₁, property := (_ : ↑x +ᵥ p₁ ∈ s) },
property := (_ : { val := ↑x +ᵥ p₁, property := (_ : ↑x +ᵥ p₁ ∈ s) } = { val := p₁, property := hp₁ } → False) }
x✝ : ↑((fun p => p -ᵥ p₁) '' (s \ {p₁}))
v : { x // x ∈ (fun p => p -ᵥ p₁) '' (s \ {p₁}) }
⊢ ↑v = ((fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }) ∘ f) v
[PROOFSTEP]
exact (vadd_vsub (v : V) p₁).symm
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
⊢ (LinearIndependent k fun v => ↑v) → LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
[PROOFSTEP]
intro h
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
h : LinearIndependent k fun v => ↑v
⊢ LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
[PROOFSTEP]
let f : { x : s // x ≠ ⟨p₁, hp₁⟩ } → (fun p : P => (p -ᵥ p₁ : V)) '' (s \ { p₁ }) := fun x =>
⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, fun hx => x.property (Subtype.ext hx)⟩, rfl⟩⟩⟩
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
hp₁ : p₁ ∈ s
h : LinearIndependent k fun v => ↑v
f : { x // x ≠ { val := p₁, property := hp₁ } } → ↑((fun p => p -ᵥ p₁) '' (s \ {p₁})) :=
fun x => { val := ↑↑x -ᵥ p₁, property := (_ : ∃ a, a ∈ s \ {p₁} ∧ (fun p => p -ᵥ p₁) a = ↑↑x -ᵥ p₁) }
⊢ LinearIndependent k fun i => ↑↑i -ᵥ ↑{ val := p₁, property := hp₁ }
[PROOFSTEP]
convert h.comp f fun x1 x2 hx => Subtype.ext (Subtype.ext (vsub_left_cancel (Subtype.ext_iff.1 hx)))
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set V
hs : ∀ (v : V), v ∈ s → v ≠ 0
p₁ : P
⊢ (LinearIndependent k fun v => ↑v) ↔ AffineIndependent k fun p => ↑p
[PROOFSTEP]
rw [affineIndependent_set_iff_linearIndependent_vsub k (Set.mem_union_left _ (Set.mem_singleton p₁))]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set V
hs : ∀ (v : V), v ∈ s → v ≠ 0
p₁ : P
⊢ (LinearIndependent k fun v => ↑v) ↔ LinearIndependent k fun v => ↑v
[PROOFSTEP]
have h : (fun p => (p -ᵥ p₁ : V)) '' (({ p₁ } ∪ (fun v => v +ᵥ p₁) '' s) \ { p₁ }) = s :=
by
simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p₁), Set.image_image, Set.image_singleton,
vsub_self, vadd_vsub, Set.image_id']
exact Set.diff_singleton_eq_self fun h => hs 0 h rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set V
hs : ∀ (v : V), v ∈ s → v ≠ 0
p₁ : P
⊢ (fun p => p -ᵥ p₁) '' (({p₁} ∪ (fun v => v +ᵥ p₁) '' s) \ {p₁}) = s
[PROOFSTEP]
simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p₁), Set.image_image, Set.image_singleton, vsub_self,
vadd_vsub, Set.image_id']
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set V
hs : ∀ (v : V), v ∈ s → v ≠ 0
p₁ : P
⊢ s \ {0} = s
[PROOFSTEP]
exact Set.diff_singleton_eq_self fun h => hs 0 h rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set V
hs : ∀ (v : V), v ∈ s → v ≠ 0
p₁ : P
h : (fun p => p -ᵥ p₁) '' (({p₁} ∪ (fun v => v +ᵥ p₁) '' s) \ {p₁}) = s
⊢ (LinearIndependent k fun v => ↑v) ↔ LinearIndependent k fun v => ↑v
[PROOFSTEP]
rw [h]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
⊢ AffineIndependent k p ↔
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
classical
constructor
· intro ha s1 s2 w1 w2 hw1 hw2 heq
ext i
by_cases hi : i ∈ s1 ∪ s2
· rw [← sub_eq_zero]
rw [Set.sum_indicator_subset _ (Finset.subset_union_left s1 s2)] at hw1
rw [Set.sum_indicator_subset _ (Finset.subset_union_right s1 s2)] at hw2
have hws : (∑ i in s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i) = 0 := by simp [hw1, hw2]
rw [Finset.affineCombination_indicator_subset _ _ (Finset.subset_union_left s1 s2),
Finset.affineCombination_indicator_subset _ _ (Finset.subset_union_right s1 s2), ← @vsub_eq_zero_iff_eq V,
Finset.affineCombination_vsub] at heq
exact ha (s1 ∪ s2) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) hws heq i hi
· rw [← Finset.mem_coe, Finset.coe_union] at hi
have h₁ : Set.indicator (↑s1) w1 i = 0 :=
by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h
have h₂ : Set.indicator (↑s2) w2 i = 0 :=
by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h
simp [h₁, h₂]
· intro ha s w hw hs i0 hi0
let w1 : ι → k := Function.update (Function.const ι 0) i0 1
have hw1 : ∑ i in s, w1 i = 1 := by
rw [Finset.sum_update_of_mem hi0]
simp only [Finset.sum_const_zero, add_zero, const_apply]
have hw1s : s.affineCombination k p w1 = p i0 :=
s.affineCombination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_same _ _ _) fun _ _ hne =>
Function.update_noteq hne _ _
let w2 := w + w1
have hw2 : ∑ i in s, w2 i = 1 := by simp_all only [Pi.add_apply, Finset.sum_add_distrib, zero_add]
have hw2s : s.affineCombination k p w2 = p i0 := by
simp_all only [← Finset.weightedVSub_vadd_affineCombination, zero_vadd]
replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s)
have hws : w2 i0 - w1 i0 = 0 := by
rw [← Finset.mem_coe] at hi0
rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self]
simpa using hws
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
⊢ AffineIndependent k p ↔
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
constructor
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
⊢ AffineIndependent k p →
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
intro ha s1 s2 w1 w2 hw1 hw2 heq
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
⊢ Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
ext i
[GOAL]
case mp.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
⊢ Set.indicator (↑s1) w1 i = Set.indicator (↑s2) w2 i
[PROOFSTEP]
by_cases hi : i ∈ s1 ∪ s2
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : i ∈ s1 ∪ s2
⊢ Set.indicator (↑s1) w1 i = Set.indicator (↑s2) w2 i
[PROOFSTEP]
rw [← sub_eq_zero]
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : i ∈ s1 ∪ s2
⊢ Set.indicator (↑s1) w1 i - Set.indicator (↑s2) w2 i = 0
[PROOFSTEP]
rw [Set.sum_indicator_subset _ (Finset.subset_union_left s1 s2)] at hw1
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1 ∪ s2, Set.indicator (↑s1) (fun i => w1 i) i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : i ∈ s1 ∪ s2
⊢ Set.indicator (↑s1) w1 i - Set.indicator (↑s2) w2 i = 0
[PROOFSTEP]
rw [Set.sum_indicator_subset _ (Finset.subset_union_right s1 s2)] at hw2
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1 ∪ s2, Set.indicator (↑s1) (fun i => w1 i) i = 1
hw2 : ∑ i in s1 ∪ s2, Set.indicator (↑s2) (fun i => w2 i) i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : i ∈ s1 ∪ s2
⊢ Set.indicator (↑s1) w1 i - Set.indicator (↑s2) w2 i = 0
[PROOFSTEP]
have hws : (∑ i in s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i) = 0 := by simp [hw1, hw2]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1 ∪ s2, Set.indicator (↑s1) (fun i => w1 i) i = 1
hw2 : ∑ i in s1 ∪ s2, Set.indicator (↑s2) (fun i => w2 i) i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : i ∈ s1 ∪ s2
⊢ ∑ i in s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i = 0
[PROOFSTEP]
simp [hw1, hw2]
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1 ∪ s2, Set.indicator (↑s1) (fun i => w1 i) i = 1
hw2 : ∑ i in s1 ∪ s2, Set.indicator (↑s2) (fun i => w2 i) i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : i ∈ s1 ∪ s2
hws : ∑ i in s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i = 0
⊢ Set.indicator (↑s1) w1 i - Set.indicator (↑s2) w2 i = 0
[PROOFSTEP]
rw [Finset.affineCombination_indicator_subset _ _ (Finset.subset_union_left s1 s2),
Finset.affineCombination_indicator_subset _ _ (Finset.subset_union_right s1 s2), ← @vsub_eq_zero_iff_eq V,
Finset.affineCombination_vsub] at heq
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1 ∪ s2, Set.indicator (↑s1) (fun i => w1 i) i = 1
hw2 : ∑ i in s1 ∪ s2, Set.indicator (↑s2) (fun i => w2 i) i = 1
heq : ↑(Finset.weightedVSub (s1 ∪ s2) p) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) = 0
i : ι
hi : i ∈ s1 ∪ s2
hws : ∑ i in s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i = 0
⊢ Set.indicator (↑s1) w1 i - Set.indicator (↑s2) w2 i = 0
[PROOFSTEP]
exact ha (s1 ∪ s2) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) hws heq i hi
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ s1 ∪ s2
⊢ Set.indicator (↑s1) w1 i = Set.indicator (↑s2) w2 i
[PROOFSTEP]
rw [← Finset.mem_coe, Finset.coe_union] at hi
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
⊢ Set.indicator (↑s1) w1 i = Set.indicator (↑s2) w2 i
[PROOFSTEP]
have h₁ : Set.indicator (↑s1) w1 i = 0 :=
by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
⊢ Set.indicator (↑s1) w1 i = 0
[PROOFSTEP]
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
⊢ i ∈ s1 → w1 i = 0
[PROOFSTEP]
intro h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h : i ∈ s1
⊢ w1 i = 0
[PROOFSTEP]
by_contra
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h : i ∈ s1
x✝ : ¬w1 i = 0
⊢ False
[PROOFSTEP]
exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h₁ : Set.indicator (↑s1) w1 i = 0
⊢ Set.indicator (↑s1) w1 i = Set.indicator (↑s2) w2 i
[PROOFSTEP]
have h₂ : Set.indicator (↑s2) w2 i = 0 :=
by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h₁ : Set.indicator (↑s1) w1 i = 0
⊢ Set.indicator (↑s2) w2 i = 0
[PROOFSTEP]
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h₁ : Set.indicator (↑s1) w1 i = 0
⊢ i ∈ s2 → w2 i = 0
[PROOFSTEP]
intro h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h₁ : Set.indicator (↑s1) w1 i = 0
h : i ∈ s2
⊢ w2 i = 0
[PROOFSTEP]
by_contra
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h₁ : Set.indicator (↑s1) w1 i = 0
h : i ∈ s2
x✝ : ¬w2 i = 0
⊢ False
[PROOFSTEP]
exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
heq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
i : ι
hi : ¬i ∈ ↑s1 ∪ ↑s2
h₁ : Set.indicator (↑s1) w1 i = 0
h₂ : Set.indicator (↑s2) w2 i = 0
⊢ Set.indicator (↑s1) w1 i = Set.indicator (↑s2) w2 i
[PROOFSTEP]
simp [h₁, h₂]
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
⊢ (∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2) →
AffineIndependent k p
[PROOFSTEP]
intro ha s w hw hs i0 hi0
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
⊢ w i0 = 0
[PROOFSTEP]
let w1 : ι → k := Function.update (Function.const ι 0) i0 1
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
⊢ w i0 = 0
[PROOFSTEP]
have hw1 : ∑ i in s, w1 i = 1 := by
rw [Finset.sum_update_of_mem hi0]
simp only [Finset.sum_const_zero, add_zero, const_apply]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
⊢ ∑ i in s, w1 i = 1
[PROOFSTEP]
rw [Finset.sum_update_of_mem hi0]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
⊢ 1 + ∑ x in s \ {i0}, const ι 0 x = 1
[PROOFSTEP]
simp only [Finset.sum_const_zero, add_zero, const_apply]
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
⊢ w i0 = 0
[PROOFSTEP]
have hw1s : s.affineCombination k p w1 = p i0 :=
s.affineCombination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_same _ _ _) fun _ _ hne =>
Function.update_noteq hne _ _
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
⊢ w i0 = 0
[PROOFSTEP]
let w2 := w + w1
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
⊢ w i0 = 0
[PROOFSTEP]
have hw2 : ∑ i in s, w2 i = 1 := by simp_all only [Pi.add_apply, Finset.sum_add_distrib, zero_add]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
⊢ ∑ i in s, w2 i = 1
[PROOFSTEP]
simp_all only [Pi.add_apply, Finset.sum_add_distrib, zero_add]
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
hw2 : ∑ i in s, w2 i = 1
⊢ w i0 = 0
[PROOFSTEP]
have hw2s : s.affineCombination k p w2 = p i0 := by
simp_all only [← Finset.weightedVSub_vadd_affineCombination, zero_vadd]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
hw2 : ∑ i in s, w2 i = 1
⊢ ↑(Finset.affineCombination k s p) w2 = p i0
[PROOFSTEP]
simp_all only [← Finset.weightedVSub_vadd_affineCombination, zero_vadd]
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
hw2 : ∑ i in s, w2 i = 1
hw2s : ↑(Finset.affineCombination k s p) w2 = p i0
⊢ w i0 = 0
[PROOFSTEP]
replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s)
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
hw2 : ∑ i in s, w2 i = 1
hw2s : ↑(Finset.affineCombination k s p) w2 = p i0
ha : Set.indicator (↑s) w2 = Set.indicator (↑s) w1
⊢ w i0 = 0
[PROOFSTEP]
have hws : w2 i0 - w1 i0 = 0 := by
rw [← Finset.mem_coe] at hi0
rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
hw2 : ∑ i in s, w2 i = 1
hw2s : ↑(Finset.affineCombination k s p) w2 = p i0
ha : Set.indicator (↑s) w2 = Set.indicator (↑s) w1
⊢ w2 i0 - w1 i0 = 0
[PROOFSTEP]
rw [← Finset.mem_coe] at hi0
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ ↑s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
hw2 : ∑ i in s, w2 i = 1
hw2s : ↑(Finset.affineCombination k s p) w2 = p i0
ha : Set.indicator (↑s) w2 = Set.indicator (↑s) w1
⊢ w2 i0 - w1 i0 = 0
[PROOFSTEP]
rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self]
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
i0 : ι
hi0 : i0 ∈ s
w1 : ι → k := update (const ι 0) i0 1
hw1 : ∑ i in s, w1 i = 1
hw1s : ↑(Finset.affineCombination k s p) w1 = p i0
w2 : ι → k := w + w1
hw2 : ∑ i in s, w2 i = 1
hw2s : ↑(Finset.affineCombination k s p) w2 = p i0
ha : Set.indicator (↑s) w2 = Set.indicator (↑s) w1
hws : w2 i0 - w1 i0 = 0
⊢ w i0 = 0
[PROOFSTEP]
simpa using hws
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
⊢ AffineIndependent k p ↔
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
[PROOFSTEP]
rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
⊢ (∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2) ↔
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
[PROOFSTEP]
constructor
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
⊢ (∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2) →
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
[PROOFSTEP]
intro h w1 w2 hw1 hw2 hweq
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
w1 w2 : ι → k
hw1 : ∑ i : ι, w1 i = 1
hw2 : ∑ i : ι, w2 i = 1
hweq : ↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2
⊢ w1 = w2
[PROOFSTEP]
simpa only [Set.indicator_univ, Finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
⊢ (∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2) →
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
intro h s1 s2 w1 w2 hw1 hw2 hweq
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h :
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
hweq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
⊢ Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
have hw1' : (∑ i, (s1 : Set ι).indicator w1 i) = 1 := by
rwa [Set.sum_indicator_subset _ (Finset.subset_univ s1)] at hw1
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h :
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
hweq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
⊢ ∑ i : ι, Set.indicator (↑s1) w1 i = 1
[PROOFSTEP]
rwa [Set.sum_indicator_subset _ (Finset.subset_univ s1)] at hw1
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h :
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
hweq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
hw1' : ∑ i : ι, Set.indicator (↑s1) w1 i = 1
⊢ Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
have hw2' : (∑ i, (s2 : Set ι).indicator w2 i) = 1 := by
rwa [Set.sum_indicator_subset _ (Finset.subset_univ s2)] at hw2
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h :
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
hweq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
hw1' : ∑ i : ι, Set.indicator (↑s1) w1 i = 1
⊢ ∑ i : ι, Set.indicator (↑s2) w2 i = 1
[PROOFSTEP]
rwa [Set.sum_indicator_subset _ (Finset.subset_univ s2)] at hw2
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h :
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
hweq : ↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2
hw1' : ∑ i : ι, Set.indicator (↑s1) w1 i = 1
hw2' : ∑ i : ι, Set.indicator (↑s2) w2 i = 1
⊢ Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
rw [Finset.affineCombination_indicator_subset w1 p (Finset.subset_univ s1),
Finset.affineCombination_indicator_subset w2 p (Finset.subset_univ s2)] at hweq
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Fintype ι
p : ι → P
h :
∀ (w1 w2 : ι → k),
∑ i : ι, w1 i = 1 →
∑ i : ι, w2 i = 1 →
↑(Finset.affineCombination k Finset.univ p) w1 = ↑(Finset.affineCombination k Finset.univ p) w2 → w1 = w2
s1 s2 : Finset ι
w1 w2 : ι → k
hw1 : ∑ i in s1, w1 i = 1
hw2 : ∑ i in s2, w2 i = 1
hweq :
↑(Finset.affineCombination k Finset.univ p) (Set.indicator (↑s1) w1) =
↑(Finset.affineCombination k Finset.univ p) (Set.indicator (↑s2) w2)
hw1' : ∑ i : ι, Set.indicator (↑s1) w1 i = 1
hw2' : ∑ i : ι, Set.indicator (↑s2) w2 i = 1
⊢ Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
[PROOFSTEP]
exact h _ _ hw1' hw2' hweq
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
hp : AffineIndependent k p
j : ι
w : ι → kˣ
⊢ AffineIndependent k fun i => ↑(AffineMap.lineMap (p j) (p i)) ↑(w i)
[PROOFSTEP]
rw [affineIndependent_iff_linearIndependent_vsub k _ j] at hp ⊢
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
j : ι
hp : LinearIndependent k fun i => p ↑i -ᵥ p j
w : ι → kˣ
⊢ LinearIndependent k fun i => ↑(AffineMap.lineMap (p j) (p ↑i)) ↑(w ↑i) -ᵥ ↑(AffineMap.lineMap (p j) (p j)) ↑(w j)
[PROOFSTEP]
simp only [AffineMap.lineMap_vsub_left, AffineMap.coe_const, AffineMap.lineMap_same, const_apply]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
j : ι
hp : LinearIndependent k fun i => p ↑i -ᵥ p j
w : ι → kˣ
⊢ LinearIndependent k fun i => ↑(w ↑i) • (p ↑i -ᵥ p j)
[PROOFSTEP]
exact hp.units_smul fun i => w i
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
⊢ Injective p
[PROOFSTEP]
intro i j hij
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
i j : ι
hij : p i = p j
⊢ i = j
[PROOFSTEP]
rw [affineIndependent_iff_linearIndependent_vsub _ _ j] at ha
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
i j : ι
ha : LinearIndependent k fun i => p ↑i -ᵥ p j
hij : p i = p j
⊢ i = j
[PROOFSTEP]
by_contra hij'
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
i j : ι
ha : LinearIndependent k fun i => p ↑i -ᵥ p j
hij : p i = p j
hij' : ¬i = j
⊢ False
[PROOFSTEP]
refine' ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr _)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
i j : ι
ha : LinearIndependent k fun i => p ↑i -ᵥ p j
hij : p i = p j
hij' : ¬i = j
⊢ p ↑{ val := i, property := hij' } = p j
[PROOFSTEP]
simp_all only [ne_eq]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
⊢ AffineIndependent k (p ∘ ↑f)
[PROOFSTEP]
classical
intro fs w hw hs i0 hi0
let fs' := fs.map f
let w' i := if h : ∃ i2, f i2 = i then w h.choose else 0
have hw' : ∀ i2 : ι2, w' (f i2) = w i2 := by
intro i2
have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩
have hs : h.choose = i2 := f.injective h.choose_spec
simp_rw [dif_pos h, hs]
have hw's : ∑ i in fs', w' i = 0 := by
rw [← hw, Finset.sum_map]
simp [hw']
have hs' : fs'.weightedVSub p w' = (0 : V) :=
by
rw [← hs, Finset.weightedVSub_map]
congr with i
simp_all only [comp_apply, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true]
rw [← ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw']
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
⊢ AffineIndependent k (p ∘ ↑f)
[PROOFSTEP]
intro fs w hw hs i0 hi0
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
⊢ w i0 = 0
[PROOFSTEP]
let fs' := fs.map f
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
⊢ w i0 = 0
[PROOFSTEP]
let w' i := if h : ∃ i2, f i2 = i then w h.choose else 0
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
⊢ w i0 = 0
[PROOFSTEP]
have hw' : ∀ i2 : ι2, w' (f i2) = w i2 := by
intro i2
have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩
have hs : h.choose = i2 := f.injective h.choose_spec
simp_rw [dif_pos h, hs]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
⊢ ∀ (i2 : ι2), w' (↑f i2) = w i2
[PROOFSTEP]
intro i2
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
i2 : ι2
⊢ w' (↑f i2) = w i2
[PROOFSTEP]
have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
i2 : ι2
h : ∃ i, ↑f i = ↑f i2
⊢ w' (↑f i2) = w i2
[PROOFSTEP]
have hs : h.choose = i2 := f.injective h.choose_spec
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs✝ : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
i2 : ι2
h : ∃ i, ↑f i = ↑f i2
hs : Exists.choose h = i2
⊢ w' (↑f i2) = w i2
[PROOFSTEP]
simp_rw [dif_pos h, hs]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
⊢ w i0 = 0
[PROOFSTEP]
have hw's : ∑ i in fs', w' i = 0 := by
rw [← hw, Finset.sum_map]
simp [hw']
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
⊢ ∑ i in fs', w' i = 0
[PROOFSTEP]
rw [← hw, Finset.sum_map]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
⊢ ∑ x in fs, w' (↑f x) = ∑ i in fs, w i
[PROOFSTEP]
simp [hw']
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
hw's : ∑ i in fs', w' i = 0
⊢ w i0 = 0
[PROOFSTEP]
have hs' : fs'.weightedVSub p w' = (0 : V) :=
by
rw [← hs, Finset.weightedVSub_map]
congr with i
simp_all only [comp_apply, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
hw's : ∑ i in fs', w' i = 0
⊢ ↑(Finset.weightedVSub fs' p) w' = 0
[PROOFSTEP]
rw [← hs, Finset.weightedVSub_map]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
hw's : ∑ i in fs', w' i = 0
⊢ ↑(Finset.weightedVSub fs (p ∘ ↑f)) (w' ∘ ↑f) = ↑(Finset.weightedVSub fs (p ∘ ↑f)) w
[PROOFSTEP]
congr with i
[GOAL]
case h.e_6.h.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
hw's : ∑ i in fs', w' i = 0
i : ι2
⊢ (w' ∘ ↑f) i = w i
[PROOFSTEP]
simp_all only [comp_apply, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι2 : Type u_5
f : ι2 ↪ ι
p : ι → P
ha : AffineIndependent k p
fs : Finset ι2
w : ι2 → k
hw : ∑ i in fs, w i = 0
hs : ↑(Finset.weightedVSub fs (p ∘ ↑f)) w = 0
i0 : ι2
hi0 : i0 ∈ fs
fs' : Finset ι := Finset.map f fs
w' : ι → k := fun i => if h : ∃ i2, ↑f i2 = i then w (Exists.choose h) else 0
hw' : ∀ (i2 : ι2), w' (↑f i2) = w i2
hw's : ∑ i in fs', w' i = 0
hs' : ↑(Finset.weightedVSub fs' p) w' = 0
⊢ w i0 = 0
[PROOFSTEP]
rw [← ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw']
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
⊢ AffineIndependent k fun x => ↑x
[PROOFSTEP]
let f : Set.range p → ι := fun x => x.property.choose
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
f : ↑(Set.range p) → ι := fun x => Exists.choose (_ : ↑x ∈ Set.range p)
⊢ AffineIndependent k fun x => ↑x
[PROOFSTEP]
have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
f : ↑(Set.range p) → ι := fun x => Exists.choose (_ : ↑x ∈ Set.range p)
hf : ∀ (x : ↑(Set.range p)), p (f x) = ↑x
⊢ AffineIndependent k fun x => ↑x
[PROOFSTEP]
let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
f : ↑(Set.range p) → ι := fun x => Exists.choose (_ : ↑x ∈ Set.range p)
hf : ∀ (x : ↑(Set.range p)), p (f x) = ↑x
fe : ↑(Set.range p) ↪ ι := { toFun := f, inj' := (_ : ∀ (x₁ x₂ : ↑(Set.range p)), f x₁ = f x₂ → x₁ = x₂) }
⊢ AffineIndependent k fun x => ↑x
[PROOFSTEP]
convert ha.comp_embedding fe
[GOAL]
case h.e'_9.h.h.e
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
f : ↑(Set.range p) → ι := fun x => Exists.choose (_ : ↑x ∈ Set.range p)
hf : ∀ (x : ↑(Set.range p)), p (f x) = ↑x
fe : ↑(Set.range p) ↪ ι := { toFun := f, inj' := (_ : ∀ (x₁ x₂ : ↑(Set.range p)), f x₁ = f x₂ → x₁ = x₂) }
x✝ : ↑(Set.range p)
⊢ Subtype.val = p ∘ ↑fe
[PROOFSTEP]
ext
[GOAL]
case h.e'_9.h.h.e.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
ha : AffineIndependent k p
f : ↑(Set.range p) → ι := fun x => Exists.choose (_ : ↑x ∈ Set.range p)
hf : ∀ (x : ↑(Set.range p)), p (f x) = ↑x
fe : ↑(Set.range p) ↪ ι := { toFun := f, inj' := (_ : ∀ (x₁ x₂ : ↑(Set.range p)), f x₁ = f x₂ → x₁ = x₂) }
x✝¹ : ↑(Set.range p)
x✝ : { x // x ∈ Set.range p }
⊢ ↑x✝ = (p ∘ ↑fe) x✝
[PROOFSTEP]
simp [hf]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι' : Type u_5
e : ι ≃ ι'
p : ι' → P
⊢ AffineIndependent k (p ∘ ↑e) ↔ AffineIndependent k p
[PROOFSTEP]
refine' ⟨_, AffineIndependent.comp_embedding e.toEmbedding⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι' : Type u_5
e : ι ≃ ι'
p : ι' → P
⊢ AffineIndependent k (p ∘ ↑e) → AffineIndependent k p
[PROOFSTEP]
intro h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι' : Type u_5
e : ι ≃ ι'
p : ι' → P
h : AffineIndependent k (p ∘ ↑e)
⊢ AffineIndependent k p
[PROOFSTEP]
have : p = p ∘ e ∘ e.symm.toEmbedding := by
ext
simp
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι' : Type u_5
e : ι ≃ ι'
p : ι' → P
h : AffineIndependent k (p ∘ ↑e)
⊢ p = p ∘ ↑e ∘ ↑(Equiv.toEmbedding e.symm)
[PROOFSTEP]
ext
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι' : Type u_5
e : ι ≃ ι'
p : ι' → P
h : AffineIndependent k (p ∘ ↑e)
x✝ : ι'
⊢ p x✝ = (p ∘ ↑e ∘ ↑(Equiv.toEmbedding e.symm)) x✝
[PROOFSTEP]
simp
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι' : Type u_5
e : ι ≃ ι'
p : ι' → P
h : AffineIndependent k (p ∘ ↑e)
this : p = p ∘ ↑e ∘ ↑(Equiv.toEmbedding e.symm)
⊢ AffineIndependent k p
[PROOFSTEP]
rw [this]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
ι' : Type u_5
e : ι ≃ ι'
p : ι' → P
h : AffineIndependent k (p ∘ ↑e)
this : p = p ∘ ↑e ∘ ↑(Equiv.toEmbedding e.symm)
⊢ AffineIndependent k (p ∘ ↑e ∘ ↑(Equiv.toEmbedding e.symm))
[PROOFSTEP]
exact h.comp_embedding e.symm.toEmbedding
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hai : AffineIndependent k (↑f ∘ p)
⊢ AffineIndependent k p
[PROOFSTEP]
cases' isEmpty_or_nonempty ι with h h
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hai : AffineIndependent k (↑f ∘ p)
h : IsEmpty ι
⊢ AffineIndependent k p
[PROOFSTEP]
haveI := h
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hai : AffineIndependent k (↑f ∘ p)
h this : IsEmpty ι
⊢ AffineIndependent k p
[PROOFSTEP]
apply affineIndependent_of_subsingleton
[GOAL]
case inr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hai : AffineIndependent k (↑f ∘ p)
h : Nonempty ι
⊢ AffineIndependent k p
[PROOFSTEP]
obtain ⟨i⟩ := h
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hai : AffineIndependent k (↑f ∘ p)
i : ι
⊢ AffineIndependent k p
[PROOFSTEP]
rw [affineIndependent_iff_linearIndependent_vsub k p i]
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hai : AffineIndependent k (↑f ∘ p)
i : ι
⊢ LinearIndependent k fun i_1 => p ↑i_1 -ᵥ p i
[PROOFSTEP]
simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub] at hai
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
i : ι
hai : LinearIndependent k fun i_1 => ↑f.linear (p ↑i_1 -ᵥ p i)
⊢ LinearIndependent k fun i_1 => p ↑i_1 -ᵥ p i
[PROOFSTEP]
exact LinearIndependent.of_comp f.linear hai
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
hai : AffineIndependent k p
f : P →ᵃ[k] P₂
hf : Injective ↑f
⊢ AffineIndependent k (↑f ∘ p)
[PROOFSTEP]
cases' isEmpty_or_nonempty ι with h h
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
hai : AffineIndependent k p
f : P →ᵃ[k] P₂
hf : Injective ↑f
h : IsEmpty ι
⊢ AffineIndependent k (↑f ∘ p)
[PROOFSTEP]
haveI := h
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
hai : AffineIndependent k p
f : P →ᵃ[k] P₂
hf : Injective ↑f
h this : IsEmpty ι
⊢ AffineIndependent k (↑f ∘ p)
[PROOFSTEP]
apply affineIndependent_of_subsingleton
[GOAL]
case inr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
hai : AffineIndependent k p
f : P →ᵃ[k] P₂
hf : Injective ↑f
h : Nonempty ι
⊢ AffineIndependent k (↑f ∘ p)
[PROOFSTEP]
obtain ⟨i⟩ := h
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
hai : AffineIndependent k p
f : P →ᵃ[k] P₂
hf : Injective ↑f
i : ι
⊢ AffineIndependent k (↑f ∘ p)
[PROOFSTEP]
rw [affineIndependent_iff_linearIndependent_vsub k p i] at hai
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hf : Injective ↑f
i : ι
hai : LinearIndependent k fun i_1 => p ↑i_1 -ᵥ p i
⊢ AffineIndependent k (↑f ∘ p)
[PROOFSTEP]
simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub]
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hf : Injective ↑f
i : ι
hai : LinearIndependent k fun i_1 => p ↑i_1 -ᵥ p i
⊢ LinearIndependent k fun i_1 => ↑f.linear (p ↑i_1 -ᵥ p i)
[PROOFSTEP]
have hf' : LinearMap.ker f.linear = ⊥ := by rwa [LinearMap.ker_eq_bot, f.linear_injective_iff]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hf : Injective ↑f
i : ι
hai : LinearIndependent k fun i_1 => p ↑i_1 -ᵥ p i
⊢ LinearMap.ker f.linear = ⊥
[PROOFSTEP]
rwa [LinearMap.ker_eq_bot, f.linear_injective_iff]
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
p : ι → P
f : P →ᵃ[k] P₂
hf : Injective ↑f
i : ι
hai : LinearIndependent k fun i_1 => p ↑i_1 -ᵥ p i
hf' : LinearMap.ker f.linear = ⊥
⊢ LinearIndependent k fun i_1 => ↑f.linear (p ↑i_1 -ᵥ p i)
[PROOFSTEP]
exact LinearIndependent.map' hai f.linear hf'
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
s : Set P
e : P ≃ᵃ[k] P₂
⊢ AffineIndependent k Subtype.val ↔ AffineIndependent k Subtype.val
[PROOFSTEP]
have : e ∘ ((↑) : s → P) = ((↑) : e '' s → P₂) ∘ (e : P ≃ P₂).image s := rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁶ : Ring k
inst✝⁵ : AddCommGroup V
inst✝⁴ : Module k V
inst✝³ : AffineSpace V P
ι : Type u_4
V₂ : Type u_5
P₂ : Type u_6
inst✝² : AddCommGroup V₂
inst✝¹ : Module k V₂
inst✝ : AffineSpace V₂ P₂
s : Set P
e : P ≃ᵃ[k] P₂
this : ↑e ∘ Subtype.val = Subtype.val ∘ ↑(Equiv.image (↑e) s)
⊢ AffineIndependent k Subtype.val ↔ AffineIndependent k Subtype.val
[PROOFSTEP]
rw [← e.affineIndependent_iff, this, affineIndependent_equiv]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
p0 : P
hp0s1 : p0 ∈ affineSpan k (p '' s1)
hp0s2 : p0 ∈ affineSpan k (p '' s2)
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
rw [Set.image_eq_range] at hp0s1 hp0s2
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
p0 : P
hp0s1 : p0 ∈ affineSpan k (Set.range fun x => p ↑x)
hp0s2 : p0 ∈ affineSpan k (Set.range fun x => p ↑x)
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
rw [mem_affineSpan_iff_eq_affineCombination, ← Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype] at
hp0s1 hp0s2
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
p0 : P
hp0s1 : ∃ fs x w x, p0 = ↑(Finset.affineCombination k fs p) w
hp0s2 : ∃ fs x w x, p0 = ↑(Finset.affineCombination k fs p) w
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩
[GOAL]
case intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
p0 : P
hp0s2 : ∃ fs x w x, p0 = ↑(Finset.affineCombination k fs p) w
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
p0 : P
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
fs2 : Finset ι
hfs2 : ↑fs2 ⊆ s2
w2 : ι → k
hw2 : ∑ i in fs2, w2 i = 1
hp0s2 : p0 = ↑(Finset.affineCombination k fs2 p) w2
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] at ha
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha :
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 →
↑(Finset.affineCombination k s1 p) w1 = ↑(Finset.affineCombination k s2 p) w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2
s1 s2 : Set ι
p0 : P
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
fs2 : Finset ι
hfs2 : ↑fs2 ⊆ s2
w2 : ι → k
hw2 : ∑ i in fs2, w2 i = 1
hp0s2 : p0 = ↑(Finset.affineCombination k fs2 p) w2
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2)
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
s1 s2 : Set ι
p0 : P
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
fs2 : Finset ι
hfs2 : ↑fs2 ⊆ s2
w2 : ι → k
hw2 : ∑ i in fs2, w2 i = 1
hp0s2 : p0 = ↑(Finset.affineCombination k fs2 p) w2
ha : Set.indicator (↑fs1) w1 = Set.indicator (↑fs2) w2
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
have hnz : ∑ i in fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
s1 s2 : Set ι
p0 : P
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
fs2 : Finset ι
hfs2 : ↑fs2 ⊆ s2
w2 : ι → k
hw2 : ∑ i in fs2, w2 i = 1
hp0s2 : p0 = ↑(Finset.affineCombination k fs2 p) w2
ha : Set.indicator (↑fs1) w1 = Set.indicator (↑fs2) w2
hnz : ∑ i in fs1, w1 i ≠ 0
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
rcases Finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
s1 s2 : Set ι
p0 : P
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
fs2 : Finset ι
hfs2 : ↑fs2 ⊆ s2
w2 : ι → k
hw2 : ∑ i in fs2, w2 i = 1
hp0s2 : p0 = ↑(Finset.affineCombination k fs2 p) w2
ha : Set.indicator (↑fs1) w1 = Set.indicator (↑fs2) w2
hnz : ∑ i in fs1, w1 i ≠ 0
i : ι
hifs1 : i ∈ fs1
hinz : w1 i ≠ 0
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
simp_rw [← Set.indicator_of_mem (Finset.mem_coe.2 hifs1) w1, ha] at hinz
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
s1 s2 : Set ι
p0 : P
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
fs2 : Finset ι
hfs2 : ↑fs2 ⊆ s2
w2 : ι → k
hw2 : ∑ i in fs2, w2 i = 1
hp0s2 : p0 = ↑(Finset.affineCombination k fs2 p) w2
ha : Set.indicator (↑fs1) w1 = Set.indicator (↑fs2) w2
hnz : ∑ i in fs1, w1 i ≠ 0
i : ι
hifs1 : i ∈ fs1
hinz : Set.indicator (↑fs2) w2 i ≠ 0
⊢ ∃ i, i ∈ s1 ∩ s2
[PROOFSTEP]
use i, hfs1 hifs1
[GOAL]
case right
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
s1 s2 : Set ι
p0 : P
fs1 : Finset ι
hfs1 : ↑fs1 ⊆ s1
w1 : ι → k
hw1 : ∑ i in fs1, w1 i = 1
hp0s1 : p0 = ↑(Finset.affineCombination k fs1 p) w1
fs2 : Finset ι
hfs2 : ↑fs2 ⊆ s2
w2 : ι → k
hw2 : ∑ i in fs2, w2 i = 1
hp0s2 : p0 = ↑(Finset.affineCombination k fs2 p) w2
ha : Set.indicator (↑fs1) w1 = Set.indicator (↑fs2) w2
hnz : ∑ i in fs1, w1 i ≠ 0
i : ι
hifs1 : i ∈ fs1
hinz : Set.indicator (↑fs2) w2 i ≠ 0
⊢ i ∈ s2
[PROOFSTEP]
exact hfs2 (Set.mem_of_indicator_ne_zero hinz)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
hd : Disjoint s1 s2
⊢ Disjoint ↑(affineSpan k (p '' s1)) ↑(affineSpan k (p '' s2))
[PROOFSTEP]
refine' Set.disjoint_left.2 fun p0 hp0s1 hp0s2 => _
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
hd : Disjoint s1 s2
p0 : P
hp0s1 : p0 ∈ ↑(affineSpan k (p '' s1))
hp0s2 : p0 ∈ ↑(affineSpan k (p '' s2))
⊢ False
[PROOFSTEP]
cases' ha.exists_mem_inter_of_exists_mem_inter_affineSpan hp0s1 hp0s2 with i hi
[GOAL]
case intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
s1 s2 : Set ι
hd : Disjoint s1 s2
p0 : P
hp0s1 : p0 ∈ ↑(affineSpan k (p '' s1))
hp0s2 : p0 ∈ ↑(affineSpan k (p '' s2))
i : ι
hi : i ∈ s1 ∩ s2
⊢ False
[PROOFSTEP]
exact Set.disjoint_iff.1 hd hi
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
i : ι
s : Set ι
⊢ p i ∈ affineSpan k (p '' s) ↔ i ∈ s
[PROOFSTEP]
constructor
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
i : ι
s : Set ι
⊢ p i ∈ affineSpan k (p '' s) → i ∈ s
[PROOFSTEP]
intro hs
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
i : ι
s : Set ι
hs : p i ∈ affineSpan k (p '' s)
⊢ i ∈ s
[PROOFSTEP]
have h :=
AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan ha hs
(mem_affineSpan k (Set.mem_image_of_mem _ (Set.mem_singleton _)))
[GOAL]
case mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
i : ι
s : Set ι
hs : p i ∈ affineSpan k (p '' s)
h : ∃ i_1, i_1 ∈ s ∩ {i}
⊢ i ∈ s
[PROOFSTEP]
rwa [← Set.nonempty_def, Set.inter_singleton_nonempty] at h
[GOAL]
case mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
i : ι
s : Set ι
⊢ i ∈ s → p i ∈ affineSpan k (p '' s)
[PROOFSTEP]
exact fun h => mem_affineSpan k (Set.mem_image_of_mem p h)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : Ring k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
ι : Type u_4
inst✝ : Nontrivial k
p : ι → P
ha : AffineIndependent k p
i : ι
s : Set ι
⊢ ¬p i ∈ affineSpan k (p '' (s \ {i}))
[PROOFSTEP]
simp [ha]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
h : ¬AffineIndependent k Subtype.val
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x, x ∈ t ∧ f x ≠ 0
[PROOFSTEP]
classical
rw [affineIndependent_iff_of_fintype] at h
simp only [exists_prop, not_forall] at h
obtain ⟨w, hw, hwt, i, hi⟩ := h
simp only [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ w ((↑) : t → V) hw 0, vsub_eq_sub,
Finset.weightedVSubOfPoint_apply, sub_zero] at hwt
let f : ∀ x : V, x ∈ t → k := fun x hx => w ⟨x, hx⟩
refine' ⟨fun x => if hx : x ∈ t then f x hx else (0 : k), _, _, by use i; simp [hi]⟩
suffices (∑ e : V in t, dite (e ∈ t) (fun hx => f e hx • e) fun _ => 0) = 0
by
convert this
rename V => x
by_cases hx : x ∈ t <;> simp [hx]
all_goals simp only [Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
h : ¬AffineIndependent k Subtype.val
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x, x ∈ t ∧ f x ≠ 0
[PROOFSTEP]
rw [affineIndependent_iff_of_fintype] at h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
h :
¬∀ (w : { x // x ∈ t } → k),
∑ i : { x // x ∈ t }, w i = 0 →
↑(Finset.weightedVSub Finset.univ Subtype.val) w = 0 → ∀ (i : { x // x ∈ t }), w i = 0
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x, x ∈ t ∧ f x ≠ 0
[PROOFSTEP]
simp only [exists_prop, not_forall] at h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
h : ∃ x, ∑ i : { x // x ∈ t }, x i = 0 ∧ ↑(Finset.weightedVSub Finset.univ Subtype.val) x = 0 ∧ ∃ x_1, ¬x x_1 = 0
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x, x ∈ t ∧ f x ≠ 0
[PROOFSTEP]
obtain ⟨w, hw, hwt, i, hi⟩ := h
[GOAL]
case intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
hwt : ↑(Finset.weightedVSub Finset.univ Subtype.val) w = 0
i : { x // x ∈ t }
hi : ¬w i = 0
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x, x ∈ t ∧ f x ≠ 0
[PROOFSTEP]
simp only [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ w ((↑) : t → V) hw 0, vsub_eq_sub,
Finset.weightedVSubOfPoint_apply, sub_zero] at hwt
[GOAL]
case intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x, x ∈ t ∧ f x ≠ 0
[PROOFSTEP]
let f : ∀ x : V, x ∈ t → k := fun x hx => w ⟨x, hx⟩
[GOAL]
case intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ ∃ f, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x, x ∈ t ∧ f x ≠ 0
[PROOFSTEP]
refine' ⟨fun x => if hx : x ∈ t then f x hx else (0 : k), _, _, by use i; simp [hi]⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ ∃ x, x ∈ t ∧ (fun x => if hx : x ∈ t then f x hx else 0) x ≠ 0
[PROOFSTEP]
use i
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ ↑i ∈ t ∧ (fun x => if hx : x ∈ t then f x hx else 0) ↑i ≠ 0
[PROOFSTEP]
simp [hi]
[GOAL]
case intro.intro.intro.intro.refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ ∑ e in t, (fun x => if hx : x ∈ t then f x hx else 0) e • e = 0
case intro.intro.intro.intro.refine'_2
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ ∑ e in t, (fun x => if hx : x ∈ t then f x hx else 0) e = 0
[PROOFSTEP]
suffices (∑ e : V in t, dite (e ∈ t) (fun hx => f e hx • e) fun _ => 0) = 0
by
convert this
rename V => x
by_cases hx : x ∈ t <;> simp [hx]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
this : (∑ e in t, if hx : e ∈ t then f e hx • e else 0) = 0
⊢ ∑ e in t, (fun x => if hx : x ∈ t then f x hx else 0) e • e = 0
[PROOFSTEP]
convert this
[GOAL]
case h.e'_2.a
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
this : (∑ e in t, if hx : e ∈ t then f e hx • e else 0) = 0
x✝ : V
a✝ : x✝ ∈ t
⊢ (fun x => if hx : x ∈ t then f x hx else 0) x✝ • x✝ = if hx : x✝ ∈ t then f x✝ hx • x✝ else 0
[PROOFSTEP]
rename V => x
[GOAL]
case h.e'_2.a
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
this : (∑ e in t, if hx : e ∈ t then f e hx • e else 0) = 0
x : V
a✝ : x ∈ t
⊢ (fun x => if hx : x ∈ t then f x hx else 0) x • x = if hx : x ∈ t then f x hx • x else 0
[PROOFSTEP]
by_cases hx : x ∈ t
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
this : (∑ e in t, if hx : e ∈ t then f e hx • e else 0) = 0
x : V
a✝ hx : x ∈ t
⊢ (fun x => if hx : x ∈ t then f x hx else 0) x • x = if hx : x ∈ t then f x hx • x else 0
[PROOFSTEP]
simp [hx]
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
this : (∑ e in t, if hx : e ∈ t then f e hx • e else 0) = 0
x : V
a✝ : x ∈ t
hx : ¬x ∈ t
⊢ (fun x => if hx : x ∈ t then f x hx else 0) x • x = if hx : x ∈ t then f x hx • x else 0
[PROOFSTEP]
simp [hx]
[GOAL]
case intro.intro.intro.intro.refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ (∑ e in t, if hx : e ∈ t then f e hx • e else 0) = 0
case intro.intro.intro.intro.refine'_2
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ ∑ e in t, (fun x => if hx : x ∈ t then f x hx else 0) e = 0
[PROOFSTEP]
all_goals simp only [Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw]
[GOAL]
case intro.intro.intro.intro.refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ (∑ e in t, if hx : e ∈ t then f e hx • e else 0) = 0
[PROOFSTEP]
simp only [Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw]
[GOAL]
case intro.intro.intro.intro.refine'_2
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
t : Finset V
w : { x // x ∈ t } → k
hw : ∑ i : { x // x ∈ t }, w i = 0
i : { x // x ∈ t }
hi : ¬w i = 0
hwt : ∑ x : { x // x ∈ t }, w x • ↑x = 0
f : (x : V) → x ∈ t → k := fun x hx => w { val := x, property := hx }
⊢ ∑ e in t, (fun x => if hx : x ∈ t then f x hx else 0) e = 0
[PROOFSTEP]
simp only [Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι✝ : Type u_4
ι : Type u_5
p : ι → V
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
⊢ (↑(Finset.weightedVSub s p) w = 0 → ∀ (i : ι), i ∈ s → w i = 0) ↔ ∑ e in s, w e • p e = 0 → ∀ (e : ι), e ∈ s → w e = 0
[PROOFSTEP]
simp [s.weightedVSub_eq_linear_combination hw]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
⊢ ↑(Finset.weightedVSub s p) w ∈
vectorSpan k {↑(Finset.affineCombination k s p) w₁, ↑(Finset.affineCombination k s p) w₂} ↔
∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
rw [mem_vectorSpan_pair]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
⊢ (∃ r,
r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) =
↑(Finset.weightedVSub s p) w) ↔
∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
refine' ⟨fun h => _, fun h => _⟩
[GOAL]
case refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h✝ : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
h :
∃ r, r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
⊢ ∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
rcases h with ⟨r, hr⟩
[GOAL]
case refine'_1.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr : r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
⊢ ∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
refine' ⟨r, fun i hi => _⟩
[GOAL]
case refine'_1.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr : r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
i : ι
hi : i ∈ s
⊢ w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
rw [s.affineCombination_vsub, ← s.weightedVSub_const_smul, ← sub_eq_zero, ← map_sub] at hr
[GOAL]
case refine'_1.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr✝ : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂)) = ↑(Finset.weightedVSub s p) w
hr : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂) - w) = 0
i : ι
hi : i ∈ s
⊢ w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
have hw' : (∑ j in s, (r • (w₁ - w₂) - w) j) = 0 := by
simp_rw [Pi.sub_apply, Pi.smul_apply, Pi.sub_apply, smul_sub, Finset.sum_sub_distrib, ← Finset.smul_sum, hw, hw₁, hw₂,
sub_self]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr✝ : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂)) = ↑(Finset.weightedVSub s p) w
hr : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂) - w) = 0
i : ι
hi : i ∈ s
⊢ ∑ j in s, (r • (w₁ - w₂) - w) j = 0
[PROOFSTEP]
simp_rw [Pi.sub_apply, Pi.smul_apply, Pi.sub_apply, smul_sub, Finset.sum_sub_distrib, ← Finset.smul_sum, hw, hw₁, hw₂,
sub_self]
[GOAL]
case refine'_1.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr✝ : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂)) = ↑(Finset.weightedVSub s p) w
hr : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂) - w) = 0
i : ι
hi : i ∈ s
hw' : ∑ j in s, (r • (w₁ - w₂) - w) j = 0
⊢ w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
have hr' := h s _ hw' hr i hi
[GOAL]
case refine'_1.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr✝ : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂)) = ↑(Finset.weightedVSub s p) w
hr : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂) - w) = 0
i : ι
hi : i ∈ s
hw' : ∑ j in s, (r • (w₁ - w₂) - w) j = 0
hr' : (r • (w₁ - w₂) - w) i = 0
⊢ w i = r * (w₁ i - w₂ i)
[PROOFSTEP]
rw [eq_comm, ← sub_eq_zero, ← smul_eq_mul]
[GOAL]
case refine'_1.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr✝ : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂)) = ↑(Finset.weightedVSub s p) w
hr : ↑(Finset.weightedVSub s p) (r • (w₁ - w₂) - w) = 0
i : ι
hi : i ∈ s
hw' : ∑ j in s, (r • (w₁ - w₂) - w) j = 0
hr' : (r • (w₁ - w₂) - w) i = 0
⊢ r • (w₁ i - w₂ i) - w i = 0
[PROOFSTEP]
exact hr'
[GOAL]
case refine'_2
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h✝ : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
h : ∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
⊢ ∃ r, r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
[PROOFSTEP]
rcases h with ⟨r, hr⟩
[GOAL]
case refine'_2.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr : ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
⊢ ∃ r, r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
[PROOFSTEP]
refine' ⟨r, _⟩
[GOAL]
case refine'_2.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr : ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
⊢ r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
[PROOFSTEP]
let w' i := r * (w₁ i - w₂ i)
[GOAL]
case refine'_2.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
hr : ∀ (i : ι), i ∈ s → w i = r * (w₁ i - w₂ i)
w' : ι → k := fun i => r * (w₁ i - w₂ i)
⊢ r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
[PROOFSTEP]
change ∀ i ∈ s, w i = w' i at hr
[GOAL]
case refine'_2.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
w' : ι → k := fun i => r * (w₁ i - w₂ i)
hr : ∀ (i : ι), i ∈ s → w i = w' i
⊢ r • (↑(Finset.affineCombination k s p) w₁ -ᵥ ↑(Finset.affineCombination k s p) w₂) = ↑(Finset.weightedVSub s p) w
[PROOFSTEP]
rw [s.weightedVSub_congr hr fun _ _ => rfl, s.affineCombination_vsub, ← s.weightedVSub_const_smul]
[GOAL]
case refine'_2.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 0
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
r : k
w' : ι → k := fun i => r * (w₁ i - w₂ i)
hr : ∀ (i : ι), i ∈ s → w i = w' i
⊢ ↑(Finset.weightedVSub s p) (r • (w₁ - w₂)) = ↑(Finset.weightedVSub s fun x => p x) fun i => w' i
[PROOFSTEP]
congr
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
x✝ : ∑ i in s, w i = 1
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
⊢ ↑(Finset.affineCombination k s p) w ∈
affineSpan k {↑(Finset.affineCombination k s p) w₁, ↑(Finset.affineCombination k s p) w₂} ↔
∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₂ i - w₁ i) + w₁ i
[PROOFSTEP]
rw [← vsub_vadd (s.affineCombination k p w) (s.affineCombination k p w₁),
AffineSubspace.vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _), direction_affineSpan,
s.affineCombination_vsub, Set.pair_comm, weightedVSub_mem_vectorSpan_pair h _ hw₂ hw₁]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
x✝ : ∑ i in s, w i = 1
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
⊢ (∃ r, ∀ (i : ι), i ∈ s → (w - w₁) i = r * (w₂ i - w₁ i)) ↔ ∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₂ i - w₁ i) + w₁ i
[PROOFSTEP]
simp only [Pi.sub_apply, sub_eq_iff_eq_add]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
x✝ : ∑ i in s, w i = 1
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
⊢ ∑ i in s, (w - w₁) i = 0
[PROOFSTEP]
simp_all only [Pi.sub_apply, Finset.sum_sub_distrib, sub_self]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
h : AffineIndependent k fun p => ↑p
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
rcases s.eq_empty_or_nonempty with (rfl | ⟨p₁, hp₁⟩)
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have p₁ : P := AddTorsor.Nonempty.some
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
let hsv := Basis.ofVectorSpace k V
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have hsvi := hsv.linearIndependent
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
hsvi : LinearIndependent k ↑hsv
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have hsvt := hsv.span_eq
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
hsvi : LinearIndependent k ↑hsv
hsvt : Submodule.span k (Set.range ↑hsv) = ⊤
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
rw [Basis.coe_ofVectorSpace] at hsvi hsvt
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have h0 : ∀ v : V, v ∈ Basis.ofVectorSpaceIndex _ _ → v ≠ 0 :=
by
intro v hv
simpa using hsv.ne_zero ⟨v, hv⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
⊢ ∀ (v : V), v ∈ Basis.ofVectorSpaceIndex (?m.389241 v) V → v ≠ 0
[PROOFSTEP]
intro v hv
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
v : V
hv : v ∈ Basis.ofVectorSpaceIndex (?m.389241 v) V
⊢ v ≠ 0
[PROOFSTEP]
simpa using hsv.ne_zero ⟨v, hv⟩
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
h0 : ∀ (v : V), v ∈ Basis.ofVectorSpaceIndex k V → v ≠ 0
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
h : AffineIndependent k fun p => ↑p
p₁ : P
hsv : Basis (↑(Basis.ofVectorSpaceIndex k V)) k V := Basis.ofVectorSpace k V
hsvi : AffineIndependent k fun p => ↑p
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
h0 : ∀ (v : V), v ∈ Basis.ofVectorSpaceIndex k V → v ≠ 0
⊢ ∃ t, ∅ ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
exact
⟨{ p₁ } ∪ (fun v => v +ᵥ p₁) '' _, Set.empty_subset _, hsvi,
affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
h : AffineIndependent k fun p => ↑p
p₁ : P
hp₁ : p₁ ∈ s
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁] at h
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
let bsv := Basis.extend h
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have hsvi := bsv.linearIndependent
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : LinearIndependent k ↑bsv
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have hsvt := bsv.span_eq
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : LinearIndependent k ↑bsv
hsvt : Submodule.span k (Set.range ↑bsv) = ⊤
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
rw [Basis.coe_extend] at hsvi hsvt
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have hsv := h.subset_extend (Set.subset_univ _)
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
have h0 : ∀ v : V, v ∈ h.extend _ → v ≠ 0 := by
intro v hv
simpa using bsv.ne_zero ⟨v, hv⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
⊢ ∀ (v : V), v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ ?m.393529 v) → v ≠ 0
[PROOFSTEP]
intro v hv
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
v : V
hv : v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ ?m.393529 v)
⊢ v ≠ 0
[PROOFSTEP]
simpa using bsv.ne_zero ⟨v, hv⟩
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : LinearIndependent k Subtype.val
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
h0 : ∀ (v : V), v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ) → v ≠ 0
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : AffineIndependent k fun p => ↑p
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
h0 : ∀ (v : V), v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ) → v ≠ 0
⊢ ∃ t, s ⊆ t ∧ (AffineIndependent k fun p => ↑p) ∧ affineSpan k t = ⊤
[PROOFSTEP]
refine' ⟨{ p₁ } ∪ (fun v => v +ᵥ p₁) '' h.extend (Set.subset_univ _), _, _⟩
[GOAL]
case inr.intro.refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : AffineIndependent k fun p => ↑p
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
h0 : ∀ (v : V), v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ) → v ≠ 0
⊢ s ⊆ {p₁} ∪ (fun v => v +ᵥ p₁) '' LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
[PROOFSTEP]
refine' Set.Subset.trans _ (Set.union_subset_union_right _ (Set.image_subset _ hsv))
[GOAL]
case inr.intro.refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : AffineIndependent k fun p => ↑p
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
h0 : ∀ (v : V), v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ) → v ≠ 0
⊢ s ⊆ {p₁} ∪ (fun v => v +ᵥ p₁) '' ((fun p => p -ᵥ p₁) '' (s \ {p₁}))
[PROOFSTEP]
simp [Set.image_image]
[GOAL]
case inr.intro.refine'_2
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : AffineIndependent k fun p => ↑p
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
h0 : ∀ (v : V), v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ) → v ≠ 0
⊢ (AffineIndependent k fun p => ↑p) ∧
affineSpan k
({p₁} ∪ (fun v => v +ᵥ p₁) '' LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)) =
⊤
[PROOFSTEP]
use hsvi
[GOAL]
case right
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p₁ : P
h : LinearIndependent k fun v => ↑v
hp₁ : p₁ ∈ s
bsv : Basis (↑(LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ))) k V := Basis.extend h
hsvi : AffineIndependent k fun p => ↑p
hsvt : Submodule.span k (Set.range Subtype.val) = ⊤
hsv : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)
h0 : ∀ (v : V), v ∈ LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ) → v ≠ 0
⊢ affineSpan k
({p₁} ∪ (fun v => v +ᵥ p₁) '' LinearIndependent.extend h (_ : (fun p => p -ᵥ p₁) '' (s \ {p₁}) ⊆ Set.univ)) =
⊤
[PROOFSTEP]
exact affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
⊢ ∃ t x, affineSpan k t = affineSpan k s ∧ AffineIndependent k Subtype.val
[PROOFSTEP]
rcases s.eq_empty_or_nonempty with (rfl | ⟨p, hp⟩)
[GOAL]
case inl
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
⊢ ∃ t x, affineSpan k t = affineSpan k ∅ ∧ AffineIndependent k Subtype.val
[PROOFSTEP]
exact ⟨∅, Set.empty_subset ∅, rfl, affineIndependent_of_subsingleton k _⟩
[GOAL]
case inr.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
⊢ ∃ t x, affineSpan k t = affineSpan k s ∧ AffineIndependent k Subtype.val
[PROOFSTEP]
obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linearIndependent k ((Equiv.vaddConst p).symm '' s)
[GOAL]
case inr.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = Submodule.span k (↑(Equiv.vaddConst p).symm '' s)
hb₃ : LinearIndependent k Subtype.val
⊢ ∃ t x, affineSpan k t = affineSpan k s ∧ AffineIndependent k Subtype.val
[PROOFSTEP]
have hb₀ : ∀ v : V, v ∈ b → v ≠ 0 := fun v hv => hb₃.ne_zero (⟨v, hv⟩ : b)
[GOAL]
case inr.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = Submodule.span k (↑(Equiv.vaddConst p).symm '' s)
hb₃ : LinearIndependent k Subtype.val
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ ∃ t x, affineSpan k t = affineSpan k s ∧ AffineIndependent k Subtype.val
[PROOFSTEP]
rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k hb₀ p] at hb₃
[GOAL]
case inr.intro.intro.intro.intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = Submodule.span k (↑(Equiv.vaddConst p).symm '' s)
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ ∃ t x, affineSpan k t = affineSpan k s ∧ AffineIndependent k Subtype.val
[PROOFSTEP]
refine' ⟨{ p } ∪ Equiv.vaddConst p '' b, _, _, hb₃⟩
[GOAL]
case inr.intro.intro.intro.intro.refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = Submodule.span k (↑(Equiv.vaddConst p).symm '' s)
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ {p} ∪ ↑(Equiv.vaddConst p) '' b ⊆ s
[PROOFSTEP]
apply Set.union_subset (Set.singleton_subset_iff.mpr hp)
[GOAL]
case inr.intro.intro.intro.intro.refine'_1
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = Submodule.span k (↑(Equiv.vaddConst p).symm '' s)
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ ↑(Equiv.vaddConst p) '' b ⊆ s
[PROOFSTEP]
rwa [← (Equiv.vaddConst p).subset_image' b s]
[GOAL]
case inr.intro.intro.intro.intro.refine'_2
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = Submodule.span k (↑(Equiv.vaddConst p).symm '' s)
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ affineSpan k ({p} ∪ ↑(Equiv.vaddConst p) '' b) = affineSpan k s
[PROOFSTEP]
rw [Equiv.coe_vaddConst_symm, ← vectorSpan_eq_span_vsub_set_right k hp] at hb₂
[GOAL]
case inr.intro.intro.intro.intro.refine'_2
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ affineSpan k ({p} ∪ ↑(Equiv.vaddConst p) '' b) = affineSpan k s
[PROOFSTEP]
apply AffineSubspace.ext_of_direction_eq
[GOAL]
case inr.intro.intro.intro.intro.refine'_2.hd
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ AffineSubspace.direction (affineSpan k ({p} ∪ ↑(Equiv.vaddConst p) '' b)) = AffineSubspace.direction (affineSpan k s)
[PROOFSTEP]
have : Submodule.span k b = Submodule.span k (insert 0 b) := by simp
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ Submodule.span k b = Submodule.span k (insert 0 b)
[PROOFSTEP]
simp
[GOAL]
case inr.intro.intro.intro.intro.refine'_2.hd
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
this : Submodule.span k b = Submodule.span k (insert 0 b)
⊢ AffineSubspace.direction (affineSpan k ({p} ∪ ↑(Equiv.vaddConst p) '' b)) = AffineSubspace.direction (affineSpan k s)
[PROOFSTEP]
simp only [direction_affineSpan, ← hb₂, Equiv.coe_vaddConst, Set.singleton_union,
vectorSpan_eq_span_vsub_set_right k (Set.mem_insert p _), this]
[GOAL]
case inr.intro.intro.intro.intro.refine'_2.hd
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
this : Submodule.span k b = Submodule.span k (insert 0 b)
⊢ Submodule.span k ((fun x => x -ᵥ p) '' insert p ((fun a => a +ᵥ p) '' b)) = Submodule.span k (insert 0 b)
[PROOFSTEP]
congr
[GOAL]
case inr.intro.intro.intro.intro.refine'_2.hd.e_s
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
this : Submodule.span k b = Submodule.span k (insert 0 b)
⊢ (fun x => x -ᵥ p) '' insert p ((fun a => a +ᵥ p) '' b) = insert 0 b
[PROOFSTEP]
change (Equiv.vaddConst p).symm '' insert p (Equiv.vaddConst p '' b) = _
[GOAL]
case inr.intro.intro.intro.intro.refine'_2.hd.e_s
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
this : Submodule.span k b = Submodule.span k (insert 0 b)
⊢ ↑(Equiv.vaddConst p).symm '' insert p (↑(Equiv.vaddConst p) '' b) = insert 0 b
[PROOFSTEP]
rw [Set.image_insert_eq, ← Set.image_comp]
[GOAL]
case inr.intro.intro.intro.intro.refine'_2.hd.e_s
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
this : Submodule.span k b = Submodule.span k (insert 0 b)
⊢ insert (↑(Equiv.vaddConst p).symm p) (↑(Equiv.vaddConst p).symm ∘ ↑(Equiv.vaddConst p) '' b) = insert 0 b
[PROOFSTEP]
simp
[GOAL]
case inr.intro.intro.intro.intro.refine'_2.hn
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ Set.Nonempty (↑(affineSpan k ({p} ∪ ↑(Equiv.vaddConst p) '' b)) ∩ ↑(affineSpan k s))
[PROOFSTEP]
use p
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ p ∈ ↑(affineSpan k ({p} ∪ ↑(Equiv.vaddConst p) '' b)) ∩ ↑(affineSpan k s)
[PROOFSTEP]
simp only [Equiv.coe_vaddConst, Set.singleton_union, Set.mem_inter_iff, coe_affineSpan]
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : Set P
p : P
hp : p ∈ s
b : Set V
hb₁ : b ⊆ ↑(Equiv.vaddConst p).symm '' s
hb₂ : Submodule.span k b = vectorSpan k s
hb₃ : AffineIndependent k fun p_1 => ↑p_1
hb₀ : ∀ (v : V), v ∈ b → v ≠ 0
⊢ p ∈ spanPoints k (insert p ((fun a => a +ᵥ p) '' b)) ∧ p ∈ spanPoints k s
[PROOFSTEP]
exact ⟨mem_spanPoints k _ _ (Set.mem_insert p _), mem_spanPoints k _ _ hp⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
⊢ AffineIndependent k ![p₁, p₂]
[PROOFSTEP]
rw [affineIndependent_iff_linearIndependent_vsub k ![p₁, p₂] 0]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
⊢ LinearIndependent k fun i => Matrix.vecCons p₁ ![p₂] ↑i -ᵥ Matrix.vecCons p₁ ![p₂] 0
[PROOFSTEP]
let i₁ : { x // x ≠ (0 : Fin 2) } := ⟨1, by norm_num⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
⊢ 1 ≠ 0
[PROOFSTEP]
norm_num
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
⊢ LinearIndependent k fun i => Matrix.vecCons p₁ ![p₂] ↑i -ᵥ Matrix.vecCons p₁ ![p₂] 0
[PROOFSTEP]
have he' : ∀ i, i = i₁ := by
rintro ⟨i, hi⟩
ext
fin_cases i
· simp at hi
· simp only [Fin.val_one]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
⊢ ∀ (i : { x // x ≠ 0 }), i = i₁
[PROOFSTEP]
rintro ⟨i, hi⟩
[GOAL]
case mk
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
i : Fin 2
hi : i ≠ 0
⊢ { val := i, property := hi } = i₁
[PROOFSTEP]
ext
[GOAL]
case mk.a.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
i : Fin 2
hi : i ≠ 0
⊢ ↑↑{ val := i, property := hi } = ↑↑i₁
[PROOFSTEP]
fin_cases i
[GOAL]
case mk.a.h.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
hi : { val := 0, isLt := (_ : 0 < 2) } ≠ 0
⊢ ↑↑{ val := { val := 0, isLt := (_ : 0 < 2) }, property := hi } = ↑↑i₁
[PROOFSTEP]
simp at hi
[GOAL]
case mk.a.h.tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
hi : { val := 1, isLt := (_ : (fun a => a < 2) 1) } ≠ 0
⊢ ↑↑{ val := { val := 1, isLt := (_ : (fun a => a < 2) 1) }, property := hi } = ↑↑i₁
[PROOFSTEP]
simp only [Fin.val_one]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
he' : ∀ (i : { x // x ≠ 0 }), i = i₁
⊢ LinearIndependent k fun i => Matrix.vecCons p₁ ![p₂] ↑i -ᵥ Matrix.vecCons p₁ ![p₂] 0
[PROOFSTEP]
haveI : Unique { x // x ≠ (0 : Fin 2) } := ⟨⟨i₁⟩, he'⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
he' : ∀ (i : { x // x ≠ 0 }), i = i₁
this : Unique { x // x ≠ 0 }
⊢ LinearIndependent k fun i => Matrix.vecCons p₁ ![p₂] ↑i -ᵥ Matrix.vecCons p₁ ![p₂] 0
[PROOFSTEP]
apply linearIndependent_unique
[GOAL]
case a
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
he' : ∀ (i : { x // x ≠ 0 }), i = i₁
this : Unique { x // x ≠ 0 }
⊢ Matrix.vecCons p₁ ![p₂] ↑default -ᵥ Matrix.vecCons p₁ ![p₂] 0 ≠ 0
[PROOFSTEP]
rw [he' default]
[GOAL]
case a
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p₁ p₂ : P
h : p₁ ≠ p₂
i₁ : { x // x ≠ 0 } := { val := 1, property := (_ : 1 ≠ 0) }
he' : ∀ (i : { x // x ≠ 0 }), i = i₁
this : Unique { x // x ≠ 0 }
⊢ Matrix.vecCons p₁ ![p₂] ↑i₁ -ᵥ Matrix.vecCons p₁ ![p₂] 0 ≠ 0
[PROOFSTEP]
simpa using h.symm
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
⊢ AffineIndependent k p
[PROOFSTEP]
classical
intro s w hw hs
let s' : Finset { y // y ≠ i } := s.subtype (· ≠ i)
let p' : { y // y ≠ i } → P := fun x => p x
by_cases his : i ∈ s ∧ w i ≠ 0
· refine' False.elim (hi _)
let wm : ι → k := -(w i)⁻¹ • w
have hms : s.weightedVSub p wm = (0 : V) := by simp [hs]
have hwm : ∑ i in s, wm i = 0 := by simp [← Finset.mul_sum, hw]
have hwmi : wm i = -1 := by simp [his.2]
let w' : { y // y ≠ i } → k := fun x => wm x
have hw' : ∑ x in s', w' x = 1 := by
simp_rw [Finset.sum_subtype_eq_sum_filter]
rw [← s.sum_filter_add_sum_filter_not (· ≠ i)] at hwm
simp_rw [Classical.not_not] at hwm
erw [Finset.filter_eq'] at hwm
simp_rw [if_pos his.1, Finset.sum_singleton, hwmi, ← sub_eq_add_neg, sub_eq_zero] at hwm
exact hwm
rw [← s.affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one hms his.1 hwmi, ←
(Subtype.range_coe : _ = {x | x ≠ i}), ← Set.range_comp, ← s.affineCombination_subtype_eq_filter]
exact affineCombination_mem_affineSpan hw' p'
· rw [not_and_or, Classical.not_not] at his
let w' : { y // y ≠ i } → k := fun x => w x
have hw' : ∑ x in s', w' x = 0 := by
simp_rw [Finset.sum_subtype_eq_sum_filter]
rw [Finset.sum_filter_of_ne, hw]
rintro x hxs hwx rfl
exact hwx (his.neg_resolve_left hxs)
have hs' : s'.weightedVSub p' w' = (0 : V) :=
by
simp_rw [Finset.weightedVSub_subtype_eq_filter]
rw [Finset.weightedVSub_filter_of_ne, hs]
rintro x hxs hwx rfl
exact hwx (his.neg_resolve_left hxs)
intro j hj
by_cases hji : j = i
· rw [hji] at hj
exact hji.symm ▸ his.neg_resolve_left hj
· exact ha s' w' hw' hs' ⟨j, hji⟩ (Finset.mem_subtype.2 hj)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
⊢ AffineIndependent k p
[PROOFSTEP]
intro s w hw hs
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
let s' : Finset { y // y ≠ i } := s.subtype (· ≠ i)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
let p' : { y // y ≠ i } → P := fun x => p x
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
by_cases his : i ∈ s ∧ w i ≠ 0
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
refine' False.elim (hi _)
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
⊢ p i ∈ affineSpan k (p '' {x | x ≠ i})
[PROOFSTEP]
let wm : ι → k := -(w i)⁻¹ • w
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
⊢ p i ∈ affineSpan k (p '' {x | x ≠ i})
[PROOFSTEP]
have hms : s.weightedVSub p wm = (0 : V) := by simp [hs]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
⊢ ↑(Finset.weightedVSub s p) wm = 0
[PROOFSTEP]
simp [hs]
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
⊢ p i ∈ affineSpan k (p '' {x | x ≠ i})
[PROOFSTEP]
have hwm : ∑ i in s, wm i = 0 := by simp [← Finset.mul_sum, hw]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
⊢ ∑ i in s, wm i = 0
[PROOFSTEP]
simp [← Finset.mul_sum, hw]
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
⊢ p i ∈ affineSpan k (p '' {x | x ≠ i})
[PROOFSTEP]
have hwmi : wm i = -1 := by simp [his.2]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
⊢ wm i = -1
[PROOFSTEP]
simp [his.2]
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
hwmi : wm i = -1
⊢ p i ∈ affineSpan k (p '' {x | x ≠ i})
[PROOFSTEP]
let w' : { y // y ≠ i } → k := fun x => wm x
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
⊢ p i ∈ affineSpan k (p '' {x | x ≠ i})
[PROOFSTEP]
have hw' : ∑ x in s', w' x = 1 := by
simp_rw [Finset.sum_subtype_eq_sum_filter]
rw [← s.sum_filter_add_sum_filter_not (· ≠ i)] at hwm
simp_rw [Classical.not_not] at hwm
erw [Finset.filter_eq'] at hwm
simp_rw [if_pos his.1, Finset.sum_singleton, hwmi, ← sub_eq_add_neg, sub_eq_zero] at hwm
exact hwm
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
⊢ ∑ x in s', w' x = 1
[PROOFSTEP]
simp_rw [Finset.sum_subtype_eq_sum_filter]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
⊢ ∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x = 1
[PROOFSTEP]
rw [← s.sum_filter_add_sum_filter_not (· ≠ i)] at hwm
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ x in Finset.filter (fun x => x ≠ i) s, wm x + ∑ x in Finset.filter (fun x => ¬x ≠ i) s, wm x = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
⊢ ∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x = 1
[PROOFSTEP]
simp_rw [Classical.not_not] at hwm
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
hwm :
∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x +
∑ x in Finset.filter (fun x => x = i) s, (-(w i)⁻¹ • w) x =
0
⊢ ∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x = 1
[PROOFSTEP]
erw [Finset.filter_eq'] at hwm
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
hwm : ∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x + ∑ x in if i ∈ s then {i} else ∅, (-(w i)⁻¹ • w) x = 0
⊢ ∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x = 1
[PROOFSTEP]
simp_rw [if_pos his.1, Finset.sum_singleton, hwmi, ← sub_eq_add_neg, sub_eq_zero] at hwm
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
hwm : ∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x = 1
⊢ ∑ x in Finset.filter (fun x => x ≠ i) s, (-(w i)⁻¹ • w) x = 1
[PROOFSTEP]
exact hwm
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
hw' : ∑ x in s', w' x = 1
⊢ p i ∈ affineSpan k (p '' {x | x ≠ i})
[PROOFSTEP]
rw [← s.affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one hms his.1 hwmi, ←
(Subtype.range_coe : _ = {x | x ≠ i}), ← Set.range_comp, ← s.affineCombination_subtype_eq_filter]
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : i ∈ s ∧ w i ≠ 0
wm : ι → k := -(w i)⁻¹ • w
hms : ↑(Finset.weightedVSub s p) wm = 0
hwm : ∑ i in s, wm i = 0
hwmi : wm i = -1
w' : { y // y ≠ i } → k := fun x => wm ↑x
hw' : ∑ x in s', w' x = 1
⊢ (↑(Finset.affineCombination k (Finset.subtype (fun x => x ≠ i) s) fun i_1 => p ↑i_1) fun i_1 => wm ↑i_1) ∈
affineSpan k (Set.range (p ∘ Subtype.val))
[PROOFSTEP]
exact affineCombination_mem_affineSpan hw' p'
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬(i ∈ s ∧ w i ≠ 0)
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
rw [not_and_or, Classical.not_not] at his
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
let w' : { y // y ≠ i } → k := fun x => w x
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
have hw' : ∑ x in s', w' x = 0 := by
simp_rw [Finset.sum_subtype_eq_sum_filter]
rw [Finset.sum_filter_of_ne, hw]
rintro x hxs hwx rfl
exact hwx (his.neg_resolve_left hxs)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
⊢ ∑ x in s', w' x = 0
[PROOFSTEP]
simp_rw [Finset.sum_subtype_eq_sum_filter]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
⊢ ∑ x in Finset.filter (fun x => x ≠ i) s, w x = 0
[PROOFSTEP]
rw [Finset.sum_filter_of_ne, hw]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
⊢ ∀ (x : ι), x ∈ s → w x ≠ 0 → x ≠ i
[PROOFSTEP]
rintro x hxs hwx rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
x : ι
hxs : x ∈ s
hwx : w x ≠ 0
ha : AffineIndependent k fun x_1 => p ↑x_1
hi : ¬p x ∈ affineSpan k (p '' {x_1 | x_1 ≠ x})
s' : Finset { y // y ≠ x } := Finset.subtype (fun x_1 => x_1 ≠ x) s
p' : { y // y ≠ x } → P := fun x_1 => p ↑x_1
his : ¬x ∈ s ∨ w x = 0
w' : { y // y ≠ x } → k := fun x_1 => w ↑x_1
⊢ False
[PROOFSTEP]
exact hwx (his.neg_resolve_left hxs)
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
have hs' : s'.weightedVSub p' w' = (0 : V) :=
by
simp_rw [Finset.weightedVSub_subtype_eq_filter]
rw [Finset.weightedVSub_filter_of_ne, hs]
rintro x hxs hwx rfl
exact hwx (his.neg_resolve_left hxs)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
⊢ ↑(Finset.weightedVSub s' p') w' = 0
[PROOFSTEP]
simp_rw [Finset.weightedVSub_subtype_eq_filter]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
⊢ ↑(Finset.weightedVSub (Finset.filter (fun x => x ≠ i) s) p) w = 0
[PROOFSTEP]
rw [Finset.weightedVSub_filter_of_ne, hs]
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
⊢ ∀ (i_1 : ι), i_1 ∈ s → w i_1 ≠ 0 → i_1 ≠ i
[PROOFSTEP]
rintro x hxs hwx rfl
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
x : ι
hxs : x ∈ s
hwx : w x ≠ 0
ha : AffineIndependent k fun x_1 => p ↑x_1
hi : ¬p x ∈ affineSpan k (p '' {x_1 | x_1 ≠ x})
s' : Finset { y // y ≠ x } := Finset.subtype (fun x_1 => x_1 ≠ x) s
p' : { y // y ≠ x } → P := fun x_1 => p ↑x_1
his : ¬x ∈ s ∨ w x = 0
w' : { y // y ≠ x } → k := fun x_1 => w ↑x_1
hw' : ∑ x in s', w' x = 0
⊢ False
[PROOFSTEP]
exact hwx (his.neg_resolve_left hxs)
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
hs' : ↑(Finset.weightedVSub s' p') w' = 0
⊢ ∀ (i : ι), i ∈ s → w i = 0
[PROOFSTEP]
intro j hj
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
hs' : ↑(Finset.weightedVSub s' p') w' = 0
j : ι
hj : j ∈ s
⊢ w j = 0
[PROOFSTEP]
by_cases hji : j = i
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
hs' : ↑(Finset.weightedVSub s' p') w' = 0
j : ι
hj : j ∈ s
hji : j = i
⊢ w j = 0
[PROOFSTEP]
rw [hji] at hj
[GOAL]
case pos
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
hs' : ↑(Finset.weightedVSub s' p') w' = 0
j : ι
hj : i ∈ s
hji : j = i
⊢ w j = 0
[PROOFSTEP]
exact hji.symm ▸ his.neg_resolve_left hj
[GOAL]
case neg
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
i : ι
ha : AffineIndependent k fun x => p ↑x
hi : ¬p i ∈ affineSpan k (p '' {x | x ≠ i})
s : Finset ι
w : ι → k
hw : ∑ i in s, w i = 0
hs : ↑(Finset.weightedVSub s p) w = 0
s' : Finset { y // y ≠ i } := Finset.subtype (fun x => x ≠ i) s
p' : { y // y ≠ i } → P := fun x => p ↑x
his : ¬i ∈ s ∨ w i = 0
w' : { y // y ≠ i } → k := fun x => w ↑x
hw' : ∑ x in s', w' x = 0
hs' : ↑(Finset.weightedVSub s' p') w' = 0
j : ι
hj : j ∈ s
hji : ¬j = i
⊢ w j = 0
[PROOFSTEP]
exact ha s' w' hw' hs' ⟨j, hji⟩ (Finset.mem_subtype.2 hj)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
⊢ AffineIndependent k ![p₁, p₂, p₃]
[PROOFSTEP]
have ha : AffineIndependent k fun x : { x : Fin 3 // x ≠ 2 } => ![p₁, p₂, p₃] x :=
by
rw [← affineIndependent_equiv (finSuccAboveEquiv (2 : Fin 3)).toEquiv]
convert affineIndependent_of_ne k hp₁p₂
ext x
fin_cases x <;> rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
⊢ AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
[PROOFSTEP]
rw [← affineIndependent_equiv (finSuccAboveEquiv (2 : Fin 3)).toEquiv]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
⊢ AffineIndependent k ((fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x) ∘ ↑(finSuccAboveEquiv 2).toEquiv)
[PROOFSTEP]
convert affineIndependent_of_ne k hp₁p₂
[GOAL]
case h.e'_9
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
⊢ (fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x) ∘ ↑(finSuccAboveEquiv 2).toEquiv = ![p₁, p₂]
[PROOFSTEP]
ext x
[GOAL]
case h.e'_9.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
x : Fin 2
⊢ ((fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x) ∘ ↑(finSuccAboveEquiv 2).toEquiv) x = Matrix.vecCons p₁ ![p₂] x
[PROOFSTEP]
fin_cases x
[GOAL]
case h.e'_9.h.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
⊢ ((fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x) ∘ ↑(finSuccAboveEquiv 2).toEquiv) { val := 0, isLt := (_ : 0 < 2) } =
Matrix.vecCons p₁ ![p₂] { val := 0, isLt := (_ : 0 < 2) }
[PROOFSTEP]
rfl
[GOAL]
case h.e'_9.h.tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
⊢ ((fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x) ∘ ↑(finSuccAboveEquiv 2).toEquiv)
{ val := 1, isLt := (_ : (fun a => a < 2) 1) } =
Matrix.vecCons p₁ ![p₂] { val := 1, isLt := (_ : (fun a => a < 2) 1) }
[PROOFSTEP]
rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
⊢ AffineIndependent k ![p₁, p₂, p₃]
[PROOFSTEP]
refine' ha.affineIndependent_of_not_mem_span _
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
⊢ ¬Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
[PROOFSTEP]
intro h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
h : Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
⊢ False
[PROOFSTEP]
refine' hp₃ ((AffineSubspace.le_def' _ s).1 _ p₃ h)
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
h : Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
⊢ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2}) ≤ s
[PROOFSTEP]
simp_rw [affineSpan_le, Set.image_subset_iff, Set.subset_def, Set.mem_preimage]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
h : Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
⊢ ∀ (x : Fin 3), x ∈ {x | x ≠ 2} → Matrix.vecCons p₁ ![p₂, p₃] x ∈ ↑s
[PROOFSTEP]
intro x
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
h : Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
x : Fin 3
⊢ x ∈ {x | x ≠ 2} → Matrix.vecCons p₁ ![p₂, p₃] x ∈ ↑s
[PROOFSTEP]
fin_cases x
[GOAL]
case head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
h : Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
⊢ { val := 0, isLt := (_ : 0 < 3) } ∈ {x | x ≠ 2} → Matrix.vecCons p₁ ![p₂, p₃] { val := 0, isLt := (_ : 0 < 3) } ∈ ↑s
[PROOFSTEP]
simp [hp₁, hp₂]
[GOAL]
case tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
h : Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
⊢ { val := 1, isLt := (_ : (fun a => a < 3) 1) } ∈ {x | x ≠ 2} →
Matrix.vecCons p₁ ![p₂, p₃] { val := 1, isLt := (_ : (fun a => a < 3) 1) } ∈ ↑s
[PROOFSTEP]
simp [hp₁, hp₂]
[GOAL]
case tail.tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₂ : p₁ ≠ p₂
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : ¬p₃ ∈ s
ha : AffineIndependent k fun x => Matrix.vecCons p₁ ![p₂, p₃] ↑x
h : Matrix.vecCons p₁ ![p₂, p₃] 2 ∈ affineSpan k (![p₁, p₂, p₃] '' {x | x ≠ 2})
⊢ { val := 2, isLt := (_ : (fun a => (fun a => a < 3) a) 2) } ∈ {x | x ≠ 2} →
Matrix.vecCons p₁ ![p₂, p₃] { val := 2, isLt := (_ : (fun a => (fun a => a < 3) a) 2) } ∈ ↑s
[PROOFSTEP]
simp [hp₁, hp₂]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₃ : p₁ ≠ p₃
hp₁ : p₁ ∈ s
hp₂ : ¬p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ AffineIndependent k ![p₁, p₂, p₃]
[PROOFSTEP]
rw [← affineIndependent_equiv (Equiv.swap (1 : Fin 3) 2)]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₃ : p₁ ≠ p₃
hp₁ : p₁ ∈ s
hp₂ : ¬p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ AffineIndependent k (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 1 2))
[PROOFSTEP]
convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp₁p₃ hp₁ hp₃ hp₂ using 1
[GOAL]
case h.e'_9
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₃ : p₁ ≠ p₃
hp₁ : p₁ ∈ s
hp₂ : ¬p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ ![p₁, p₂, p₃] ∘ ↑(Equiv.swap 1 2) = ![p₁, p₃, p₂]
[PROOFSTEP]
ext x
[GOAL]
case h.e'_9.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₃ : p₁ ≠ p₃
hp₁ : p₁ ∈ s
hp₂ : ¬p₂ ∈ s
hp₃ : p₃ ∈ s
x : Fin 3
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 1 2)) x = Matrix.vecCons p₁ ![p₃, p₂] x
[PROOFSTEP]
fin_cases x
[GOAL]
case h.e'_9.h.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₃ : p₁ ≠ p₃
hp₁ : p₁ ∈ s
hp₂ : ¬p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 1 2)) { val := 0, isLt := (_ : 0 < 3) } =
Matrix.vecCons p₁ ![p₃, p₂] { val := 0, isLt := (_ : 0 < 3) }
[PROOFSTEP]
rfl
[GOAL]
case h.e'_9.h.tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₃ : p₁ ≠ p₃
hp₁ : p₁ ∈ s
hp₂ : ¬p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 1 2)) { val := 1, isLt := (_ : (fun a => a < 3) 1) } =
Matrix.vecCons p₁ ![p₃, p₂] { val := 1, isLt := (_ : (fun a => a < 3) 1) }
[PROOFSTEP]
rfl
[GOAL]
case h.e'_9.h.tail.tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₁p₃ : p₁ ≠ p₃
hp₁ : p₁ ∈ s
hp₂ : ¬p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 1 2)) { val := 2, isLt := (_ : (fun a => (fun a => a < 3) a) 2) } =
Matrix.vecCons p₁ ![p₃, p₂] { val := 2, isLt := (_ : (fun a => (fun a => a < 3) a) 2) }
[PROOFSTEP]
rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₂p₃ : p₂ ≠ p₃
hp₁ : ¬p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ AffineIndependent k ![p₁, p₂, p₃]
[PROOFSTEP]
rw [← affineIndependent_equiv (Equiv.swap (0 : Fin 3) 2)]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₂p₃ : p₂ ≠ p₃
hp₁ : ¬p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ AffineIndependent k (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 0 2))
[PROOFSTEP]
convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp₂p₃.symm hp₃ hp₂ hp₁ using 1
[GOAL]
case h.e'_9
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₂p₃ : p₂ ≠ p₃
hp₁ : ¬p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ ![p₁, p₂, p₃] ∘ ↑(Equiv.swap 0 2) = ![p₃, p₂, p₁]
[PROOFSTEP]
ext x
[GOAL]
case h.e'_9.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₂p₃ : p₂ ≠ p₃
hp₁ : ¬p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : p₃ ∈ s
x : Fin 3
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 0 2)) x = Matrix.vecCons p₃ ![p₂, p₁] x
[PROOFSTEP]
fin_cases x
[GOAL]
case h.e'_9.h.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₂p₃ : p₂ ≠ p₃
hp₁ : ¬p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 0 2)) { val := 0, isLt := (_ : 0 < 3) } =
Matrix.vecCons p₃ ![p₂, p₁] { val := 0, isLt := (_ : 0 < 3) }
[PROOFSTEP]
rfl
[GOAL]
case h.e'_9.h.tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₂p₃ : p₂ ≠ p₃
hp₁ : ¬p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 0 2)) { val := 1, isLt := (_ : (fun a => a < 3) 1) } =
Matrix.vecCons p₃ ![p₂, p₁] { val := 1, isLt := (_ : (fun a => a < 3) 1) }
[PROOFSTEP]
rfl
[GOAL]
case h.e'_9.h.tail.tail.head
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
s : AffineSubspace k P
p₁ p₂ p₃ : P
hp₂p₃ : p₂ ≠ p₃
hp₁ : ¬p₁ ∈ s
hp₂ : p₂ ∈ s
hp₃ : p₃ ∈ s
⊢ (![p₁, p₂, p₃] ∘ ↑(Equiv.swap 0 2)) { val := 2, isLt := (_ : (fun a => (fun a => a < 3) a) 2) } =
Matrix.vecCons p₃ ![p₂, p₁] { val := 2, isLt := (_ : (fun a => (fun a => a < 3) a) 2) }
[PROOFSTEP]
rfl
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
hs :
↑(Finset.affineCombination k s p) w ∈
affineSpan k {↑(Finset.affineCombination k s p) w₁, ↑(Finset.affineCombination k s p) w₂}
i j : ι
hi : i ∈ s
hj : j ∈ s
hi0 : w₁ i = 0
hj0 : w₁ j = 0
hij : ↑SignType.sign (w₂ i) = ↑SignType.sign (w₂ j)
⊢ ↑SignType.sign (w i) = ↑SignType.sign (w j)
[PROOFSTEP]
rw [affineCombination_mem_affineSpan_pair h hw hw₁ hw₂] at hs
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
hs : ∃ r, ∀ (i : ι), i ∈ s → w i = r * (w₂ i - w₁ i) + w₁ i
i j : ι
hi : i ∈ s
hj : j ∈ s
hi0 : w₁ i = 0
hj0 : w₁ j = 0
hij : ↑SignType.sign (w₂ i) = ↑SignType.sign (w₂ j)
⊢ ↑SignType.sign (w i) = ↑SignType.sign (w j)
[PROOFSTEP]
rcases hs with ⟨r, hr⟩
[GOAL]
case intro
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w w₁ w₂ : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
hw₁ : ∑ i in s, w₁ i = 1
hw₂ : ∑ i in s, w₂ i = 1
i j : ι
hi : i ∈ s
hj : j ∈ s
hi0 : w₁ i = 0
hj0 : w₁ j = 0
hij : ↑SignType.sign (w₂ i) = ↑SignType.sign (w₂ j)
r : k
hr : ∀ (i : ι), i ∈ s → w i = r * (w₂ i - w₁ i) + w₁ i
⊢ ↑SignType.sign (w i) = ↑SignType.sign (w j)
[PROOFSTEP]
rw [hr i hi, hr j hj, hi0, hj0, add_zero, add_zero, sub_zero, sub_zero, sign_mul, sign_mul, hij]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
i₁ i₂ i₃ : ι
h₁ : i₁ ∈ s
h₂ : i₂ ∈ s
h₃ : i₃ ∈ s
h₁₂ : i₁ ≠ i₂
h₁₃ : i₁ ≠ i₃
h₂₃ : i₂ ≠ i₃
c : k
hc0 : 0 < c
hc1 : c < 1
hs : ↑(Finset.affineCombination k s p) w ∈ affineSpan k {p i₁, ↑(AffineMap.lineMap (p i₂) (p i₃)) c}
⊢ ↑SignType.sign (w i₂) = ↑SignType.sign (w i₃)
[PROOFSTEP]
classical
rw [← s.affineCombination_affineCombinationSingleWeights k p h₁, ←
s.affineCombination_affineCombinationLineMapWeights p h₂ h₃ c] at hs
refine'
sign_eq_of_affineCombination_mem_affineSpan_pair h hw (s.sum_affineCombinationSingleWeights k h₁)
(s.sum_affineCombinationLineMapWeights h₂ h₃ c) hs h₂ h₃
(Finset.affineCombinationSingleWeights_apply_of_ne k h₁₂.symm)
(Finset.affineCombinationSingleWeights_apply_of_ne k h₁₃.symm) _
rw [Finset.affineCombinationLineMapWeights_apply_left h₂₃, Finset.affineCombinationLineMapWeights_apply_right h₂₃]
simp_all only [sub_pos, sign_pos]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
i₁ i₂ i₃ : ι
h₁ : i₁ ∈ s
h₂ : i₂ ∈ s
h₃ : i₃ ∈ s
h₁₂ : i₁ ≠ i₂
h₁₃ : i₁ ≠ i₃
h₂₃ : i₂ ≠ i₃
c : k
hc0 : 0 < c
hc1 : c < 1
hs : ↑(Finset.affineCombination k s p) w ∈ affineSpan k {p i₁, ↑(AffineMap.lineMap (p i₂) (p i₃)) c}
⊢ ↑SignType.sign (w i₂) = ↑SignType.sign (w i₃)
[PROOFSTEP]
rw [← s.affineCombination_affineCombinationSingleWeights k p h₁, ←
s.affineCombination_affineCombinationLineMapWeights p h₂ h₃ c] at hs
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
i₁ i₂ i₃ : ι
h₁ : i₁ ∈ s
h₂ : i₂ ∈ s
h₃ : i₃ ∈ s
h₁₂ : i₁ ≠ i₂
h₁₃ : i₁ ≠ i₃
h₂₃ : i₂ ≠ i₃
c : k
hc0 : 0 < c
hc1 : c < 1
hs :
↑(Finset.affineCombination k s p) w ∈
affineSpan k
{↑(Finset.affineCombination k s p) (Finset.affineCombinationSingleWeights k i₁),
↑(Finset.affineCombination k s p) (Finset.affineCombinationLineMapWeights i₂ i₃ c)}
⊢ ↑SignType.sign (w i₂) = ↑SignType.sign (w i₃)
[PROOFSTEP]
refine'
sign_eq_of_affineCombination_mem_affineSpan_pair h hw (s.sum_affineCombinationSingleWeights k h₁)
(s.sum_affineCombinationLineMapWeights h₂ h₃ c) hs h₂ h₃
(Finset.affineCombinationSingleWeights_apply_of_ne k h₁₂.symm)
(Finset.affineCombinationSingleWeights_apply_of_ne k h₁₃.symm) _
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
i₁ i₂ i₃ : ι
h₁ : i₁ ∈ s
h₂ : i₂ ∈ s
h₃ : i₃ ∈ s
h₁₂ : i₁ ≠ i₂
h₁₃ : i₁ ≠ i₃
h₂₃ : i₂ ≠ i₃
c : k
hc0 : 0 < c
hc1 : c < 1
hs :
↑(Finset.affineCombination k s p) w ∈
affineSpan k
{↑(Finset.affineCombination k s p) (Finset.affineCombinationSingleWeights k i₁),
↑(Finset.affineCombination k s p) (Finset.affineCombinationLineMapWeights i₂ i₃ c)}
⊢ ↑SignType.sign (Finset.affineCombinationLineMapWeights i₂ i₃ c i₂) =
↑SignType.sign (Finset.affineCombinationLineMapWeights i₂ i₃ c i₃)
[PROOFSTEP]
rw [Finset.affineCombinationLineMapWeights_apply_left h₂₃, Finset.affineCombinationLineMapWeights_apply_right h₂₃]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : LinearOrderedRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
ι : Type u_4
p : ι → P
h : AffineIndependent k p
w : ι → k
s : Finset ι
hw : ∑ i in s, w i = 1
i₁ i₂ i₃ : ι
h₁ : i₁ ∈ s
h₂ : i₂ ∈ s
h₃ : i₃ ∈ s
h₁₂ : i₁ ≠ i₂
h₁₃ : i₁ ≠ i₃
h₂₃ : i₂ ≠ i₃
c : k
hc0 : 0 < c
hc1 : c < 1
hs :
↑(Finset.affineCombination k s p) w ∈
affineSpan k
{↑(Finset.affineCombination k s p) (Finset.affineCombinationSingleWeights k i₁),
↑(Finset.affineCombination k s p) (Finset.affineCombinationLineMapWeights i₂ i₃ c)}
⊢ ↑SignType.sign (1 - c) = ↑SignType.sign c
[PROOFSTEP]
simp_all only [sub_pos, sign_pos]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
p : P
⊢ Subsingleton (Fin (1 + 0))
[PROOFSTEP]
rw [add_zero]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
p : P
⊢ Subsingleton (Fin 1)
[PROOFSTEP]
infer_instance
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s1 s2 : Simplex k P n
h : ∀ (i : Fin (n + 1)), points s1 i = points s2 i
⊢ s1 = s2
[PROOFSTEP]
cases s1
[GOAL]
case mk
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s2 : Simplex k P n
points✝ : Fin (n + 1) → P
Independent✝ : AffineIndependent k points✝
h : ∀ (i : Fin (n + 1)), points { points := points✝, Independent := Independent✝ } i = points s2 i
⊢ { points := points✝, Independent := Independent✝ } = s2
[PROOFSTEP]
cases s2
[GOAL]
case mk.mk
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
points✝¹ : Fin (n + 1) → P
Independent✝¹ : AffineIndependent k points✝¹
points✝ : Fin (n + 1) → P
Independent✝ : AffineIndependent k points✝
h :
∀ (i : Fin (n + 1)),
points { points := points✝¹, Independent := Independent✝¹ } i =
points { points := points✝, Independent := Independent✝ } i
⊢ { points := points✝¹, Independent := Independent✝¹ } = { points := points✝, Independent := Independent✝ }
[PROOFSTEP]
congr with i
[GOAL]
case mk.mk.e_points.h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
points✝¹ : Fin (n + 1) → P
Independent✝¹ : AffineIndependent k points✝¹
points✝ : Fin (n + 1) → P
Independent✝ : AffineIndependent k points✝
h :
∀ (i : Fin (n + 1)),
points { points := points✝¹, Independent := Independent✝¹ } i =
points { points := points✝, Independent := Independent✝ } i
i : Fin (n + 1)
⊢ points✝¹ i = points✝ i
[PROOFSTEP]
exact h i
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s : Simplex k P n
i : Fin (n + 1)
⊢ face s (_ : Finset.card {i} = 1) = mkOfPoint k (points s i)
[PROOFSTEP]
ext
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s : Simplex k P n
i : Fin (n + 1)
i✝ : Fin (0 + 1)
⊢ points (face s (_ : Finset.card {i} = 1)) i✝ = points (mkOfPoint k (points s i)) i✝
[PROOFSTEP]
simp only [Affine.Simplex.mkOfPoint_points, Affine.Simplex.face_points]
-- Porting note: `simp` can't use the next lemma
[GOAL]
case h
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s : Simplex k P n
i : Fin (n + 1)
i✝ : Fin (0 + 1)
⊢ points s (↑(Finset.orderEmbOfFin {i} (_ : Finset.card {i} = 1)) i✝) = points s i
[PROOFSTEP]
rw [Finset.orderEmbOfFin_singleton]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s : Simplex k P n
fs : Finset (Fin (n + 1))
m : ℕ
h : Finset.card fs = m + 1
⊢ Set.range (face s h).points = s.points '' ↑fs
[PROOFSTEP]
rw [face_points', Set.range_comp, Finset.range_orderEmbOfFin]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
m n : ℕ
s : Simplex k P m
e : Fin (m + 1) ≃ Fin (n + 1)
⊢ reindex (reindex s e) e.symm = s
[PROOFSTEP]
rw [← reindex_trans, Equiv.self_trans_symm, reindex_refl]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
m n : ℕ
s : Simplex k P m
e : Fin (n + 1) ≃ Fin (m + 1)
⊢ reindex (reindex s e.symm) e = s
[PROOFSTEP]
rw [← reindex_trans, Equiv.symm_trans_self, reindex_refl]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : Ring k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
m n : ℕ
s : Simplex k P m
e : Fin (m + 1) ≃ Fin (n + 1)
⊢ Set.range (reindex s e).points = Set.range s.points
[PROOFSTEP]
rw [reindex, Set.range_comp, Equiv.range_eq_univ, Set.image_univ]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s : Simplex k P n
fs : Finset (Fin (n + 1))
m : ℕ
h : Finset.card fs = m + 1
⊢ Finset.centroid k Finset.univ (face s h).points = Finset.centroid k fs s.points
[PROOFSTEP]
convert (Finset.univ.centroid_map k (fs.orderEmbOfFin h).toEmbedding s.points).symm
[GOAL]
case h.e'_3.h.e'_9
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s : Simplex k P n
fs : Finset (Fin (n + 1))
m : ℕ
h : Finset.card fs = m + 1
⊢ fs = Finset.map (Finset.orderEmbOfFin fs h).toEmbedding Finset.univ
[PROOFSTEP]
rw [← Finset.coe_inj, Finset.coe_map, Finset.coe_univ, Set.image_univ]
[GOAL]
case h.e'_3.h.e'_9
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s : Simplex k P n
fs : Finset (Fin (n + 1))
m : ℕ
h : Finset.card fs = m + 1
⊢ ↑fs = Set.range ↑(Finset.orderEmbOfFin fs h).toEmbedding
[PROOFSTEP]
simp
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
⊢ Finset.centroid k fs₁ s.points = Finset.centroid k fs₂ s.points ↔ fs₁ = fs₂
[PROOFSTEP]
refine' ⟨fun h => _, @congrArg _ _ fs₁ fs₂ (fun z => Finset.centroid k z s.points)⟩
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h : Finset.centroid k fs₁ s.points = Finset.centroid k fs₂ s.points
⊢ fs₁ = fs₂
[PROOFSTEP]
rw [Finset.centroid_eq_affineCombination_fintype, Finset.centroid_eq_affineCombination_fintype] at h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
⊢ fs₁ = fs₂
[PROOFSTEP]
have ha :=
(affineIndependent_iff_indicator_eq_of_affineCombination_eq k s.points).1 s.Independent _ _ _ _
(fs₁.sum_centroidWeightsIndicator_eq_one_of_card_eq_add_one k h₁)
(fs₂.sum_centroidWeightsIndicator_eq_one_of_card_eq_add_one k h₂) h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
ha :
(Set.indicator ↑Finset.univ fun i => Finset.centroidWeightsIndicator k fs₁ i) =
Set.indicator ↑Finset.univ fun i => Finset.centroidWeightsIndicator k fs₂ i
⊢ fs₁ = fs₂
[PROOFSTEP]
simp_rw [Finset.coe_univ, Set.indicator_univ, Function.funext_iff, Finset.centroidWeightsIndicator_def,
Finset.centroidWeights, h₁, h₂] at ha
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
ha :
∀ (a : Fin (n + 1)),
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) a =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) a
⊢ fs₁ = fs₂
[PROOFSTEP]
ext i
[GOAL]
case a
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
ha :
∀ (a : Fin (n + 1)),
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) a =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) a
i : Fin (n + 1)
⊢ i ∈ fs₁ ↔ i ∈ fs₂
[PROOFSTEP]
specialize ha i
[GOAL]
case a
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
⊢ i ∈ fs₁ ↔ i ∈ fs₂
[PROOFSTEP]
have key : ∀ n : ℕ, (n : k) + 1 ≠ 0 := fun n h => by norm_cast at h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n✝ : ℕ
s : Simplex k P n✝
fs₁ fs₂ : Finset (Fin (n✝ + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h✝ :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n✝ + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n✝ + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n✝ + 1)) (↑(m₂ + 1))⁻¹) i
n : ℕ
h : ↑n + 1 = 0
⊢ False
[PROOFSTEP]
norm_cast at h
[GOAL]
case a
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
key : ∀ (n : ℕ), ↑n + 1 ≠ 0
⊢ i ∈ fs₁ ↔ i ∈ fs₂
[PROOFSTEP]
constructor
[GOAL]
case a.mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
key : ∀ (n : ℕ), ↑n + 1 ≠ 0
⊢ i ∈ fs₁ → i ∈ fs₂
[PROOFSTEP]
intro hi
[GOAL]
case a.mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
key : ∀ (n : ℕ), ↑n + 1 ≠ 0
⊢ i ∈ fs₂ → i ∈ fs₁
[PROOFSTEP]
intro hi
[GOAL]
case a.mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
key : ∀ (n : ℕ), ↑n + 1 ≠ 0
hi : i ∈ fs₁
⊢ i ∈ fs₂
[PROOFSTEP]
by_contra hni
[GOAL]
case a.mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
key : ∀ (n : ℕ), ↑n + 1 ≠ 0
hi : i ∈ fs₂
⊢ i ∈ fs₁
[PROOFSTEP]
by_contra hni
[GOAL]
case a.mp
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
key : ∀ (n : ℕ), ↑n + 1 ≠ 0
hi : i ∈ fs₁
hni : ¬i ∈ fs₂
⊢ False
[PROOFSTEP]
simp [hni, hi, key] at ha
[GOAL]
case a.mpr
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
h :
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₁) =
↑(Finset.affineCombination k Finset.univ s.points) (Finset.centroidWeightsIndicator k fs₂)
i : Fin (n + 1)
ha :
Set.indicator (↑fs₁) (const (Fin (n + 1)) (↑(m₁ + 1))⁻¹) i =
Set.indicator (↑fs₂) (const (Fin (n + 1)) (↑(m₂ + 1))⁻¹) i
key : ∀ (n : ℕ), ↑n + 1 ≠ 0
hi : i ∈ fs₂
hni : ¬i ∈ fs₁
⊢ False
[PROOFSTEP]
simpa [hni, hi, key] using ha.symm
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
⊢ Finset.centroid k Finset.univ (face s h₁).points = Finset.centroid k Finset.univ (face s h₂).points ↔ fs₁ = fs₂
[PROOFSTEP]
rw [face_centroid_eq_centroid, face_centroid_eq_centroid]
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝⁴ : DivisionRing k
inst✝³ : AddCommGroup V
inst✝² : Module k V
inst✝¹ : AffineSpace V P
inst✝ : CharZero k
n : ℕ
s : Simplex k P n
fs₁ fs₂ : Finset (Fin (n + 1))
m₁ m₂ : ℕ
h₁ : Finset.card fs₁ = m₁ + 1
h₂ : Finset.card fs₂ = m₂ + 1
⊢ Finset.centroid k fs₁ s.points = Finset.centroid k fs₂ s.points ↔ fs₁ = fs₂
[PROOFSTEP]
exact s.centroid_eq_iff h₁ h₂
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s₁ s₂ : Simplex k P n
h : Set.range s₁.points = Set.range s₂.points
⊢ Finset.centroid k Finset.univ s₁.points = Finset.centroid k Finset.univ s₂.points
[PROOFSTEP]
rw [← Set.image_univ, ← Set.image_univ, ← Finset.coe_univ] at h
[GOAL]
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
n : ℕ
s₁ s₂ : Simplex k P n
h✝ : s₁.points '' Set.univ = s₂.points '' Set.univ
h : s₁.points '' ↑Finset.univ = s₂.points '' ↑Finset.univ
⊢ Finset.centroid k Finset.univ s₁.points = Finset.centroid k Finset.univ s₂.points
[PROOFSTEP]
exact
Finset.univ.centroid_eq_of_inj_on_of_image_eq k _ (fun _ _ _ _ he => AffineIndependent.injective s₁.Independent he)
(fun _ _ _ _ he => AffineIndependent.injective s₂.Independent he) h
|
[STATEMENT]
lemma (in group_hom) normal_kernel: "(kernel G H h) \<lhd> G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. kernel G H h \<lhd> G
[PROOF STEP]
apply (simp only: G.normal_inv_iff subgroup_kernel)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. True \<and> (\<forall>x\<in>carrier G. \<forall>ha\<in>kernel G H h. x \<otimes> ha \<otimes> inv x \<in> kernel G H h)
[PROOF STEP]
apply (simp add: kernel_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
\newpage
\appendix
\chapter{License Terms}
\section{General Terms}
License is granted to copy or use `` for ``Dieharder, a Gnu Public
License Random Number Generator Tester'' according to the Open Public
License (OPL, enclosed below), which is a Public License, developed by
the GNU Foundation, which applies to ``open source'' generic documents.
There are two modifications to the general OPL given below:
\begin{enumerate}
\item Distribution of substantively modified versions of this document
is prohibited without the explicit permission of the copyright holder.
(This is to prevent errors from being introduced which would reflect
badly on the author's professional abilities.)
\item Distribution of the work or derivative of the work in any
standard (paper) book form is prohibited unless prior permission is
obtained from the copyright holder. (This is so that the author can make
at least some money if this work is republished as a book and sold
commercially for -- somebody's -- profit.)
\end{enumerate}
Electronic versions of the \die manual can be freely redistributed, and
of course any user of \die is welcome to print out such a version for
their own use if they so desire. However, if such a user wishes to
contribute in a small way to the development of the tool, they should
consider buying a paper or electronic copy of the book if and when they
are distributed by the author in forms that can be sold.
\section{OPEN PUBLICATION LICENSE Draft v0.4, 8 June 1999}
{\bf I. REQUIREMENTS ON BOTH UNMODIFIED AND MODIFIED VERSIONS}
The Open Publication works may be reproduced and distributed in whole or
in part, in any medium physical or electronic, provided that the terms
of this license are adhered to, and that this license or an
incorporation of it by reference (with any options elected by the
author(s) and/or publisher) is displayed in the reproduction.
Proper form for an incorporation by reference is as follows:
Copyright (c) $<$year$>$ by $<$author's name or designee$>$. This material
may be distributed only subject to the terms and conditions set forth in
the Open Publication License, vX.Y or later (the latest version is
presently available at http://www.opencontent.org/openpub/).
The reference must be immediately followed with any options elected by
the author(s) and/or publisher of the document (see section VI).
Commercial redistribution of Open Publication-licensed material is
permitted.
Any publication in standard (paper) book form shall require the citation
of the original publisher and author. The publisher and author's names
shall appear on all outer surfaces of the book. On all outer surfaces of
the book the original publisher's name shall be as large as the title of
the work and cited as possessive with respect to the title.
{\bf II. COPYRIGHT}
The copyright to each Open Publication is owned by its author(s) or
designee.
{\bf III. SCOPE OF LICENSE}
The following license terms apply to all Open Publication works, unless
otherwise explicitly stated in the document.
Mere aggregation of Open Publication works or a portion of an Open
Publication work with other works or programs on the same media shall
not cause this license to apply to those other works. The aggregate work
shall contain a notice specifying the inclusion of the Open Publication
material and appropriate copyright notice.
SEVERABILITY. If any part of this license is found to be unenforceable
in any jurisdiction, the remaining portions of the license remain in
force.
NO WARRANTY. Open Publication works are licensed and provided "as is"
without warranty of any kind, express or implied, including, but not
limited to, the implied warranties of merchantability and fitness for a
particular purpose or a warranty of non-infringement.
{\bf IV. REQUIREMENTS ON MODIFIED WORKS}
All modified versions of documents covered by this license, including
translations, anthologies, compilations and partial documents, must meet
the following requirements:
\begin{enumerate}
\item The modified version must be labeled as such.
\item The person making the modifications must be identified and the
modifications dated.
\item Acknowledgement of the original author and publisher if
applicable must be retained according to normal academic citation
practices.
\item The location of the original unmodified document must be
identified.
\item The original author's (or authors') name(s) may not be used to
assert or imply endorsement of the resulting document without the
original author's (or authors') permission.
\end{enumerate}
{\bf V. GOOD-PRACTICE RECOMMENDATIONS}
In addition to the requirements of this license, it is requested from
and strongly recommended of redistributors that:
\begin{enumerate}
\item If you are distributing Open Publication works on hardcopy or
CD-ROM, you provide email notification to the authors of your intent to
redistribute at least thirty days before your manuscript or media
freeze, to give the authors time to provide updated documents. This
notification should describe modifications, if any, made to the
document.
\item All substantive modifications (including deletions) be either
clearly marked up in the document or else described in an attachment to
the document.
\end{enumerate}
Finally, while it is not mandatory under this license, it is considered
good form to offer a free copy of any hardcopy and CD-ROM expression of
an Open Publication-licensed work to its author(s).
{\bf VI. LICENSE OPTIONS}
The author(s) and/or publisher of an Open Publication-licensed document
may elect certain options by appending language to the reference to or
copy of the license. These options are considered part of the license
instance and must be included with the license (or its incorporation by
reference) in derived works.
A. To prohibit distribution of substantively modified versions without
the explicit permission of the author(s). "Substantive modification" is
defined as a change to the semantic content of the document, and
excludes mere changes in format or typographical corrections.
To accomplish this, add the phrase `Distribution of substantively
modified versions of this document is prohibited without the explicit
permission of the copyright holder.' to the license reference or copy.
B. To prohibit any publication of this work or derivative works in whole
or in part in standard (paper) book form for commercial purposes is
prohibited unless prior permission is obtained from the copyright
holder.
To accomplish this, add the phrase 'Distribution of the work or
derivative of the work in any standard (paper) book form is prohibited
unless prior permission is obtained from the copyright holder.' to the
license reference or copy.
{\bf OPEN PUBLICATION POLICY APPENDIX:}
(This is not considered part of the license.)
Open Publication works are available in source format via the Open
Publication home page at http://works.opencontent.org/.
Open Publication authors who want to include their own license on Open
Publication works may do so, as long as their terms are not more
restrictive than the Open Publication license.
If you have questions about the Open Publication License, please contact
TBD, and/or the Open Publication Authors' List at [email protected],
via email.
\vspace*{\fill}
\newpage
|
function x2c!(c::Array{Complex{Float64},1},ψ::Array{Complex{Float64},1},tinfo::ProjectedGPE.Tinfo)
c = tinfo.Tx'*(tinfo.W.*ψ)
end
function x2c!(c::Array{Complex{Float64},2},ψ::Array{Complex{Float64},2},tinfo::ProjectedGPE.Tinfo)
c .= tinfo.Tx'*(tinfo.W.*ψ)*tinfo.Ty
end
function x2c!(c::Array{Complex{Float64},3},ψ::Array{Complex{Float64},3},tinfo::ProjectedGPE.Tinfo)
sa = size(ψ);sx = size(tinfo.Tx');sy = size(tinfo.Ty');sz = size(tinfo.Tz')
Ax = reshape(tinfo.W.*ψ,(sa[1],sa[2]*sa[3]))
Ax = reshape(tinfo.Tx'*Ax,(sx[1],sa[2],sa[3]))
Ax = permutedims(Ax,(2,3,1));sa = size(Ax)
Ay = reshape(Ax,(sa[1],sa[2]*sa[3]))
Ay = reshape(tinfo.Ty'*Ay,(sy[1],sa[2],sa[3]))
Ay = permutedims(Ay,(2,3,1));sa = size(Ay)
Az = reshape(Ay,(sa[1],sa[2]*sa[3]))
Az = reshape(tinfo.Tz'*Az,(sz[1],sa[2],sa[3]))
ψ = permutedims(Az,(2,3,1))
end
|
function [ y, next ] = p08_equil ( neqn, next )
%*****************************************************************************80
%
%% P08_EQUIL returns equilibrium solutions of problem p08.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 19 February 2013
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, integer NEQN, the number of equations.
%
% Input, integer NEXT, the index of the previous
% equilibrium, which should be 0 on first call.
%
% Output, real Y(NEQN), the "next" equilibrium solution, if any.
%
% Output, integer NEXT, the index of the current equilibrium,
% or 0 if there are no more.
%
if ( next == 0 )
next = 1;
y(1:neqn,1) = [ 0.0; 0.0; 0.0 ];
else
next = 0;
y = [];
end
return
end
|
## One Step Method
Applying the Euler formula to the first order equation
\begin{equation}
y^{'} = (1-x)y^2-y
\end{equation}
is approximated by
\begin{equation}
\frac{w_{i+1}-w_i}{h}=(1-x_i)w_i^2-w_i
\end{equation}
Rearranging
\begin{equation}
w_{i+1}=w_i+h((1-x_i)w_i^2-w_i)
\end{equation}
## DECLARING LIBRARIES
```python
import numpy as np
import math
%matplotlib inline
import matplotlib.pyplot as plt # side-stepping mpl backend
import matplotlib.gridspec as gridspec # subplots
import warnings
warnings.filterwarnings("ignore")
```
## Setting up X
```python
h=0.25
x_end=1
INITIALCONDITION=1
N=int(x_end/h)
Numerical_Solution=np.zeros(N+1)
x=np.zeros(N+1)
```
## NUMERICAL SOLUTION
```python
Numerical_Solution[0]=INITIALCONDITION
x[0]=0
Analytic_Solution[0]=INITIALCONDITION
for i in range (1,N+1):
Numerical_Solution[i]=Numerical_Solution[i-1]+h*((1-x[i-1])*Numerical_Solution[i-1]*Numerical_Solution[i-1]-Numerical_Solution[i-1])
x[i]=x[i-1]+h
```
## Plotting
```python
fig = plt.figure(figsize=(8,4))
plt.plot(x,Numerical_Solution,color='red')
#ax.legend(loc='best')
plt.title('Numerical Solution')
# --- right hand plot
print('x')
print(x)
print('Numerical Solutions')
print(Numerical_Solution)
```
```python
```
|
[STATEMENT]
lemma btree_Node [forward_ent]:
"btree (tree.Node lt k v rt) p \<Longrightarrow>\<^sub>A (\<exists>\<^sub>Alp rp. the p \<mapsto>\<^sub>r Node lp k v rp * btree lt lp * btree rt rp * \<up>(p \<noteq> None))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. btree (tree.Node lt k v rt) p \<Longrightarrow>\<^sub>A \<exists>\<^sub>Alp rp. the p \<mapsto>\<^sub>r node.Node lp k v rp * btree lt lp * btree rt rp * \<up> (p \<noteq> None)
[PROOF STEP]
@proof
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. btree (tree.Node lt k v rt) p \<Longrightarrow>\<^sub>A \<exists>\<^sub>Alp rp. the p \<mapsto>\<^sub>r node.Node lp k v rp * btree lt lp * btree rt rp * \<up> (p \<noteq> None)
[PROOF STEP]
@case "p = None"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. btree (tree.Node lt k v rt) p \<Longrightarrow>\<^sub>A \<exists>\<^sub>Alp rp. the p \<mapsto>\<^sub>r node.Node lp k v rp * btree lt lp * btree rt rp * \<up> (p \<noteq> None)
[PROOF STEP]
@qed |
Require Import List.
Require Export Util Val.
Set Implicit Arguments.
Definition external := positive.
Inductive extern :=
ExternI {
extern_fnc : external;
extern_args : list val;
extern_res : val
}.
Inductive event :=
| EvtExtern (call:extern)
(* | EvtTerminate (res:val) *)
| EvtTau.
(** ** [filter_tau] *)
Definition filter_tau (o:event) (L:list event) : list event :=
match o with
| EvtTau => L
| e => e :: L
end.
Lemma filter_tau_nil evt B
: (filter_tau evt nil ++ B)%list = filter_tau evt B.
Proof.
destruct evt; simpl; eauto.
Qed.
Lemma filter_tau_app evt A B
: (filter_tau evt A ++ B)%list = filter_tau evt (A ++ B).
Proof.
destruct evt; eauto.
Qed.
Lemma filter_tau_nil_eq
: nil = filter_tau EvtTau nil.
Proof.
reflexivity.
Qed.
Hint Extern 5 (nil = filter_tau _ nil) => apply filter_tau_nil_eq.
Inductive extevent :=
| EEvtExtern (evt:event)
| EEvtTerminate (res:option val).
|
plusId : (n, m, o : Nat) -> (n = m) -> (m = o) -> n + m = m + o
plusId n m o prf prf1 = rewrite prf in rewrite prf1 in Refl
mult0Plus : (n, m : Nat) -> (0 + n) * m = n * (0 + m)
mult0Plus n m = Refl
mult_S_1 : (n, m : Nat) -> (m = S n) -> m * (1 + n) = m * m
mult_S_1 n m prf = rewrite prf in Refl
andb_true_elim_2 : (b, c : Bool) -> b && c = True -> c = True
andb_true_elim_2 False False Refl impossible
andb_true_elim_2 True False Refl impossible
andb_true_elim_2 False True prf = Refl
andb_true_elim_2 True True prf = Refl
zero_nbeq_plus_1 : (n : Nat) -> 0 == (n + 1) = False
zero_nbeq_plus_1 Z = Refl
zero_nbeq_plus_1 (S k) = Refl
|
section \<open>Implementation of Safety Property Model Checker \label{sec:find_path_impl}\<close>
theory Find_Path_Impl
imports
Find_Path
CAVA_Automata.Digraph_Impl
begin
section \<open>Workset Algorithm\<close>
text \<open>A simple implementation is by a workset algorithm.\<close>
definition "ws_update E u p V ws \<equiv> RETURN (
V \<union> E``{u},
ws ++ (\<lambda>v. if (u,v)\<in>E \<and> v\<notin>V then Some (u#p) else None))"
definition "s_init U0 \<equiv> RETURN (None,U0,\<lambda>u. if u\<in>U0 then Some [] else None)"
definition "wset_find_path E U0 P \<equiv> do {
ASSERT (finite U0);
s0 \<leftarrow> s_init U0;
(res,_,_) \<leftarrow> WHILET
(\<lambda>(res,V,ws). res=None \<and> ws\<noteq>Map.empty)
(\<lambda>(res,V,ws). do {
ASSERT (ws\<noteq>Map.empty);
(u,p) \<leftarrow> SPEC (\<lambda>(u,p). ws u = Some p);
let ws=ws |` (-{u});
if P u then
RETURN (Some (rev p,u),V,ws)
else do {
ASSERT (finite (E``{u}));
ASSERT (dom ws \<subseteq> V);
(V,ws) \<leftarrow> ws_update E u p V ws;
RETURN (None,V,ws)
}
}) s0;
RETURN res
}"
lemma wset_find_path_correct:
fixes E :: "('v\<times>'v) set"
shows "wset_find_path E U0 P \<le> find_path E U0 P"
proof -
define inv where "inv = (\<lambda>(res,V,ws). case res of
None \<Rightarrow>
dom ws\<subseteq>V
\<and> finite (dom ws) \<comment> \<open>Derived\<close>
\<and> V\<subseteq>E\<^sup>*``U0
\<and> E``(V-dom ws) \<subseteq> V
\<and> (\<forall>v\<in>V-dom ws. \<not> P v)
\<and> U0 \<subseteq> V
\<and> (\<forall>v p. ws v = Some p
\<longrightarrow> ((\<forall>v\<in>set p. \<not>P v) \<and> (\<exists>u0\<in>U0. path E u0 (rev p) v)))
| Some (p,v) \<Rightarrow> (\<exists>u0\<in>U0. path E u0 p v \<and> P v \<and> (\<forall>v\<in>set p. \<not>P v)))"
define var where "var = inv_image
(brk_rel (finite_psupset (E\<^sup>*``U0) <*lex*> measure (card o dom)))
(\<lambda>(res::('v list \<times> 'v) option,V::'v set,ws::'v\<rightharpoonup>'v list).
(res\<noteq>None,V,ws))"
(*have [simp, intro!]: "wf var"
unfolding var_def
by (auto intro: FIN)*)
have [simp]: "\<And>u p V. dom (\<lambda>v. if (u, v) \<in> E \<and> v \<notin> V then Some (u # p)
else None) = E``{u} - V"
by (auto split: if_split_asm)
{
fix V ws u p
assume INV: "inv (None,V,ws)"
assume WSU: "ws u = Some p"
from INV WSU have
[simp]: "V \<subseteq> E\<^sup>*``U0"
and [simp]: "u \<in> V"
and UREACH: "\<exists>u0\<in>U0. (u0,u)\<in>E\<^sup>*"
and [simp]: "finite (dom ws)"
unfolding inv_def
apply simp_all
apply auto []
apply clarsimp
apply blast
done
have "(V \<union> E `` {u}, V) \<in> finite_psupset (E\<^sup>* `` U0) \<or>
V \<union> E `` {u} = V \<and>
card (E `` {u} - V \<union> (dom ws - {u})) < card (dom ws)"
proof (subst disj_commute, intro disjCI conjI)
assume "(V \<union> E `` {u}, V) \<notin> finite_psupset (E\<^sup>* `` U0)"
thus "V \<union> E `` {u} = V" using UREACH
by (auto simp: finite_psupset_def intro: rev_ImageI)
hence [simp]: "E``{u} - V = {}" by force
show "card (E `` {u} - V \<union> (dom ws - {u})) < card (dom ws)"
using WSU
by (auto intro: card_Diff1_less)
qed
} note wf_aux=this
{
fix V ws u p
assume FIN: "finite (E\<^sup>*``U0)"
assume "inv (None,V,ws)" "ws u = Some p"
then obtain u0 where "u0\<in>U0" "(u0,u)\<in>E\<^sup>*" unfolding inv_def
by clarsimp blast
hence "E``{u} \<subseteq> E\<^sup>*``U0" by (auto intro: rev_ImageI)
hence "finite (E``{u})" using FIN(1) by (rule finite_subset)
} note succs_finite=this
{
fix V ws u p
assume FIN: "finite (E\<^sup>*``U0)"
assume INV: "inv (None,V,ws)"
assume WSU: "ws u = Some p"
assume NVD: "\<not> P u"
have "inv (None, V \<union> E `` {u},
ws |` (- {u}) ++
(\<lambda>v. if (u, v) \<in> E \<and> v \<notin> V then Some (u # p)
else None))"
unfolding inv_def
apply (simp, intro conjI)
using INV WSU apply (auto simp: inv_def) []
using INV WSU apply (auto simp: inv_def) []
using INV WSU apply (auto simp: succs_finite FIN) []
using INV apply (auto simp: inv_def) []
using INV apply (auto simp: inv_def) []
using INV WSU apply (auto
simp: inv_def
intro: rtrancl_image_advance
) []
using INV WSU apply (auto simp: inv_def) []
using INV NVD apply (auto simp: inv_def) []
using INV NVD apply (auto simp: inv_def) []
using INV WSU NVD apply (fastforce
simp: inv_def restrict_map_def
intro!: path_conc path1
split: if_split_asm
) []
done
} note ip_aux=this
show ?thesis
unfolding wset_find_path_def find_path_def ws_update_def s_init_def
apply (refine_rcg refine_vcg le_ASSERTI
WHILET_rule[where
R = var and I = inv]
)
using [[goals_limit = 1]]
apply (auto simp: var_def) []
apply (auto
simp: inv_def dom_def
split: if_split_asm) []
apply simp
apply (auto simp: inv_def) []
apply (auto simp: var_def brk_rel_def) []
apply (simp add: succs_finite)
apply (auto simp: inv_def) []
apply clarsimp
apply (simp add: ip_aux)
apply clarsimp
apply (simp add: var_def brk_rel_def wf_aux) []
apply (fastforce
simp: inv_def
split: option.splits
intro: rev_ImageI
dest: Image_closed_trancl) []
done
qed
text \<open>We refine the algorithm to use a foreach-loop\<close>
definition "ws_update_foreach E u p V ws \<equiv>
FOREACH (LIST_SET_REV_TAG (E``{u})) (\<lambda>v (V,ws).
if v\<in>V then
RETURN (V,ws)
else do {
ASSERT (v\<notin>dom ws);
RETURN (insert v V,ws( v \<mapsto> u#p))
}
) (V,ws)"
lemma ws_update_foreach_refine[refine]:
assumes FIN: "finite (E``{u})"
assumes WSS: "dom ws \<subseteq> V"
assumes ID: "(E',E)\<in>Id" "(u',u)\<in>Id" "(p',p)\<in>Id" "(V',V)\<in>Id" "(ws',ws)\<in>Id"
shows "ws_update_foreach E' u' p' V' ws' \<le> \<Down>Id (ws_update E u p V ws)"
unfolding ID[simplified]
unfolding ws_update_foreach_def ws_update_def LIST_SET_REV_TAG_def
apply (refine_rcg refine_vcg FIN
FOREACH_rule[where I="\<lambda>it (V',ws').
V'=V \<union> (E``{u}-it)
\<and> dom ws' \<subseteq> V'
\<and> ws' = ws ++ (\<lambda>v. if (u,v)\<in>E \<and> v\<notin>it \<and> v\<notin>V then Some (u#p) else None)"]
)
using WSS
apply (auto
simp: Map.map_add_def
split: option.splits if_split_asm
intro!: ext[where 'a='a and 'b="'b list option"])
apply fastforce+
done
definition "s_init_foreach U0 \<equiv> do {
(U0,ws) \<leftarrow> FOREACH U0 (\<lambda>x (U0,ws).
RETURN (insert x U0,ws(x\<mapsto>[]))) ({},Map.empty);
RETURN (None,U0,ws)
}"
lemma s_init_foreach_refine[refine]:
assumes FIN: "finite U0"
assumes ID: "(U0',U0)\<in>Id"
shows "s_init_foreach U0' \<le>\<Down>Id (s_init U0)"
unfolding s_init_foreach_def s_init_def ID[simplified]
apply (refine_rcg refine_vcg
FOREACH_rule[where
I = "\<lambda>it (U,ws).
U = U0-it
\<and> ws = (\<lambda>x. if x\<in>U0-it then Some [] else None)"]
)
apply (auto
simp: FIN
intro!: ext
)
done
definition "wset_find_path' E U0 P \<equiv> do {
ASSERT (finite U0);
s0\<leftarrow>s_init_foreach U0;
(res,_,_) \<leftarrow> WHILET
(\<lambda>(res,V,ws). res=None \<and> ws\<noteq>Map.empty)
(\<lambda>(res,V,ws). do {
ASSERT (ws\<noteq>Map.empty);
((u,p),ws) \<leftarrow> op_map_pick_remove ws;
if P u then
RETURN (Some (rev p,u),V,ws)
else do {
(V,ws) \<leftarrow> ws_update_foreach E u p V ws;
RETURN (None,V,ws)
}
})
s0;
RETURN res
}"
lemma wset_find_path'_refine:
"wset_find_path' E U0 P \<le> \<Down>Id (wset_find_path E U0 P)"
unfolding wset_find_path'_def wset_find_path_def
unfolding op_map_pick_remove_alt
apply (refine_rcg IdI)
apply assumption
apply simp_all
done
section \<open>Refinement to efficient data structures\<close>
schematic_goal wset_find_path'_refine_aux:
fixes U0::"'a set" and P::"'a \<Rightarrow> bool" and E::"('a\<times>'a) set"
and Pimpl :: "'ai \<Rightarrow> bool"
and node_rel :: "('ai \<times> 'a) set"
and node_eq_impl :: "'ai \<Rightarrow> 'ai \<Rightarrow> bool"
and node_hash_impl
and node_def_hash_size
assumes [autoref_rules]:
"(succi,E)\<in>\<langle>node_rel\<rangle>slg_rel"
"(Pimpl,P)\<in>node_rel \<rightarrow> bool_rel"
"(node_eq_impl, (=)) \<in> node_rel \<rightarrow> node_rel \<rightarrow> bool_rel"
"(U0',U0)\<in>\<langle>node_rel\<rangle>list_set_rel"
assumes [autoref_ga_rules]:
"is_bounded_hashcode node_rel node_eq_impl node_hash_impl"
"is_valid_def_hm_size TYPE('ai) node_def_hash_size"
notes [autoref_tyrel] =
TYRELI[where
R="\<langle>node_rel,\<langle>node_rel\<rangle>list_rel\<rangle>list_map_rel"]
TYRELI[where R="\<langle>node_rel\<rangle>map2set_rel (ahm_rel node_hash_impl)"]
(*notes [autoref_rules] =
IdI[of P, unfolded fun_rel_id_simp[symmetric]]*)
shows "(?c::?'c,wset_find_path' E U0 P) \<in> ?R"
unfolding wset_find_path'_def ws_update_foreach_def s_init_foreach_def
using [[autoref_trace_failed_id]]
using [[autoref_trace_intf_unif]]
using [[autoref_trace_pat]]
apply (autoref (keep_goal))
done
find_theorems list_map_update
concrete_definition wset_find_path_impl for node_eq_impl succi U0' Pimpl
uses wset_find_path'_refine_aux
section \<open>Autoref Setup\<close>
context begin interpretation autoref_syn .
lemma [autoref_itype]:
"find_path ::\<^sub>i \<langle>I\<rangle>\<^sub>ii_slg \<rightarrow>\<^sub>i \<langle>I\<rangle>\<^sub>ii_set \<rightarrow>\<^sub>i (I\<rightarrow>\<^sub>ii_bool)
\<rightarrow>\<^sub>i \<langle>\<langle>\<langle>\<langle>I\<rangle>\<^sub>ii_list, I\<rangle>\<^sub>ii_prod\<rangle>\<^sub>ii_option\<rangle>\<^sub>ii_nres" by simp
lemma wset_find_path_autoref[autoref_rules]:
fixes node_rel :: "('ai \<times> 'a) set"
assumes eq: "GEN_OP node_eq_impl (=) (node_rel\<rightarrow>node_rel\<rightarrow>bool_rel)"
assumes hash: "SIDE_GEN_ALGO (is_bounded_hashcode node_rel node_eq_impl node_hash_impl)"
assumes hash_dsz: "SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('ai) node_def_hash_size)"
shows "(
wset_find_path_impl node_hash_impl node_def_hash_size node_eq_impl,
find_path)
\<in> \<langle>node_rel\<rangle>slg_rel \<rightarrow> \<langle>node_rel\<rangle>list_set_rel \<rightarrow> (node_rel\<rightarrow>bool_rel)
\<rightarrow> \<langle>\<langle>\<langle>node_rel\<rangle>list_rel\<times>\<^sub>rnode_rel\<rangle>option_rel\<rangle>nres_rel"
proof -
note EQI = GEN_OP_D[OF eq]
note HASHI = SIDE_GEN_ALGO_D[OF hash]
note DSZI = SIDE_GEN_ALGO_D[OF hash_dsz]
note wset_find_path_impl.refine[THEN nres_relD, OF _ _ EQI _ HASHI DSZI]
also note wset_find_path'_refine
also note wset_find_path_correct
finally show ?thesis
by (fastforce intro!: nres_relI)
qed
end
schematic_goal wset_find_path_transfer_aux:
"RETURN ?c \<le> wset_find_path_impl hashi dszi eqi E U0 P"
unfolding wset_find_path_impl_def
by (refine_transfer (post))
concrete_definition wset_find_path_code
for E ?U0.0 P uses wset_find_path_transfer_aux
lemmas [refine_transfer] = wset_find_path_code.refine
export_code wset_find_path_code checking SML
section \<open>Nontrivial paths\<close>
definition "find_path1_gen E u0 P \<equiv> do {
res \<leftarrow> find_path E (E``{u0}) P;
case res of None \<Rightarrow> RETURN None
| Some (p,v) \<Rightarrow> RETURN (Some (u0#p,v))
}"
lemma find_path1_gen_correct: "find_path1_gen E u0 P \<le> find_path1 E u0 P"
unfolding find_path1_gen_def find_path_def find_path1_def
apply (refine_rcg refine_vcg le_ASSERTI)
apply (auto
intro: path_prepend
dest: tranclD
elim: finite_subset[rotated]
)
done
schematic_goal find_path1_impl_aux:
fixes node_rel :: "('ai \<times> 'a) set"
assumes [autoref_rules]: "(node_eq_impl, (=)) \<in> node_rel \<rightarrow> node_rel \<rightarrow> bool_rel"
assumes [autoref_ga_rules]:
"is_bounded_hashcode node_rel node_eq_impl node_hash_impl"
"is_valid_def_hm_size TYPE('ai) node_def_hash_size"
shows "(?c,find_path1_gen::(_\<times>_) set \<Rightarrow> _) \<in> \<langle>node_rel\<rangle>slg_rel \<rightarrow> node_rel \<rightarrow> (node_rel \<rightarrow> bool_rel) \<rightarrow> \<langle>\<langle>\<langle>node_rel\<rangle>list_rel \<times>\<^sub>r node_rel\<rangle>option_rel\<rangle>nres_rel"
unfolding find_path1_gen_def[abs_def]
apply (autoref (trace,keep_goal))
done
lemma [autoref_itype]:
"find_path1 ::\<^sub>i \<langle>I\<rangle>\<^sub>ii_slg \<rightarrow>\<^sub>i I \<rightarrow>\<^sub>i (I\<rightarrow>\<^sub>ii_bool)
\<rightarrow>\<^sub>i \<langle>\<langle>\<langle>\<langle>I\<rangle>\<^sub>ii_list, I\<rangle>\<^sub>ii_prod\<rangle>\<^sub>ii_option\<rangle>\<^sub>ii_nres" by simp
concrete_definition find_path1_impl uses find_path1_impl_aux
lemma find_path1_autoref[autoref_rules]:
fixes node_rel :: "('ai \<times> 'a) set"
assumes eq: "GEN_OP node_eq_impl (=) (node_rel\<rightarrow>node_rel\<rightarrow>bool_rel)"
assumes hash: "SIDE_GEN_ALGO (is_bounded_hashcode node_rel node_eq_impl node_hash_impl)"
assumes hash_dsz: "SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('ai) node_def_hash_size)"
shows "(find_path1_impl node_eq_impl node_hash_impl node_def_hash_size,find_path1)
\<in> \<langle>node_rel\<rangle>slg_rel \<rightarrow>node_rel \<rightarrow> (node_rel \<rightarrow> bool_rel) \<rightarrow>
\<langle>\<langle>\<langle>node_rel\<rangle>list_rel \<times>\<^sub>r node_rel\<rangle>Relators.option_rel\<rangle>nres_rel"
proof -
note EQI = GEN_OP_D[OF eq]
note HASHI = SIDE_GEN_ALGO_D[OF hash]
note DSZI = SIDE_GEN_ALGO_D[OF hash_dsz]
note R = find_path1_impl.refine[param_fo, THEN nres_relD, OF EQI HASHI DSZI]
note R
also note find_path1_gen_correct
finally show ?thesis by (blast intro: nres_relI)
qed
schematic_goal find_path1_transfer_aux:
"RETURN ?c \<le> find_path1_impl eqi hashi dszi E u P"
unfolding find_path1_impl_def
by refine_transfer
concrete_definition find_path1_code for E u P uses find_path1_transfer_aux
lemmas [refine_transfer] = find_path1_code.refine
end
|
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p✝ : ℕ
μ✝ : Measure Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
⊢ ℝ
[PROOFSTEP]
have m := fun (x : Ω) =>
μ[X]
-- Porting note: Lean deems `μ[(X - fun x => μ[X]) ^ p]` ambiguous
[GOAL]
Ω : Type u_1
ι : Type u_2
m✝ : MeasurableSpace Ω
X✝ : Ω → ℝ
p✝ : ℕ
μ✝ : Measure Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
m : Ω → ℝ
⊢ ℝ
[PROOFSTEP]
exact μ[(X - m) ^ p]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
hp : p ≠ 0
⊢ moment 0 p μ = 0
[PROOFSTEP]
simp only [moment, hp, zero_pow', Ne.def, not_false_iff, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
hp : p ≠ 0
⊢ centralMoment 0 p μ = 0
[PROOFSTEP]
simp only [centralMoment, hp, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, zero_sub, Pi.pow_apply,
Pi.neg_apply, neg_zero, zero_pow', Ne.def, not_false_iff]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsFiniteMeasure μ
h_int : Integrable X
⊢ centralMoment X 1 μ = (1 - ENNReal.toReal (↑↑μ Set.univ)) * ∫ (x : Ω), X x ∂μ
[PROOFSTEP]
simp only [centralMoment, Pi.sub_apply, pow_one]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsFiniteMeasure μ
h_int : Integrable X
⊢ ∫ (x : Ω), X x - ∫ (x : Ω), X x ∂μ ∂μ = (1 - ENNReal.toReal (↑↑μ Set.univ)) * ∫ (x : Ω), X x ∂μ
[PROOFSTEP]
rw [integral_sub h_int (integrable_const _)]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsFiniteMeasure μ
h_int : Integrable X
⊢ ∫ (a : Ω), X a ∂μ - ∫ (a : Ω), ∫ (x : Ω), X x ∂μ ∂μ = (1 - ENNReal.toReal (↑↑μ Set.univ)) * ∫ (x : Ω), X x ∂μ
[PROOFSTEP]
simp only [sub_mul, integral_const, smul_eq_mul, one_mul]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
⊢ centralMoment X 1 μ = 0
[PROOFSTEP]
by_cases h_int : Integrable X μ
[GOAL]
case pos
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : Integrable X
⊢ centralMoment X 1 μ = 0
[PROOFSTEP]
rw [centralMoment_one' h_int]
[GOAL]
case pos
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : Integrable X
⊢ (1 - ENNReal.toReal (↑↑μ Set.univ)) * ∫ (x : Ω), X x ∂μ = 0
[PROOFSTEP]
simp only [measure_univ, ENNReal.one_toReal, sub_self, zero_mul]
[GOAL]
case neg
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
⊢ centralMoment X 1 μ = 0
[PROOFSTEP]
simp only [centralMoment, Pi.sub_apply, pow_one]
[GOAL]
case neg
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
⊢ ∫ (x : Ω), X x - ∫ (x : Ω), X x ∂μ ∂μ = 0
[PROOFSTEP]
have : ¬Integrable (fun x => X x - integral μ X) μ :=
by
refine' fun h_sub => h_int _
have h_add : X = (fun x => X x - integral μ X) + fun _ => integral μ X := by ext1 x; simp
rw [h_add]
exact h_sub.add (integrable_const _)
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
⊢ ¬Integrable fun x => X x - integral μ X
[PROOFSTEP]
refine' fun h_sub => h_int _
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
h_sub : Integrable fun x => X x - integral μ X
⊢ Integrable X
[PROOFSTEP]
have h_add : X = (fun x => X x - integral μ X) + fun _ => integral μ X := by ext1 x; simp
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
h_sub : Integrable fun x => X x - integral μ X
⊢ X = (fun x => X x - integral μ X) + fun x => integral μ X
[PROOFSTEP]
ext1 x
[GOAL]
case h
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
h_sub : Integrable fun x => X x - integral μ X
x : Ω
⊢ X x = ((fun x => X x - integral μ X) + fun x => integral μ X) x
[PROOFSTEP]
simp
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
h_sub : Integrable fun x => X x - integral μ X
h_add : X = (fun x => X x - integral μ X) + fun x => integral μ X
⊢ Integrable X
[PROOFSTEP]
rw [h_add]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
h_sub : Integrable fun x => X x - integral μ X
h_add : X = (fun x => X x - integral μ X) + fun x => integral μ X
⊢ Integrable ((fun x => X x - integral μ X) + fun x => integral μ X)
[PROOFSTEP]
exact h_sub.add (integrable_const _)
[GOAL]
case neg
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
h_int : ¬Integrable X
this : ¬Integrable fun x => X x - integral μ X
⊢ ∫ (x : Ω), X x - ∫ (x : Ω), X x ∂μ ∂μ = 0
[PROOFSTEP]
rw [integral_undef this]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsFiniteMeasure μ
hX : Memℒp X 2
⊢ centralMoment X 2 μ = variance X μ
[PROOFSTEP]
rw [hX.variance_eq]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
inst✝ : IsFiniteMeasure μ
hX : Memℒp X 2
⊢ centralMoment X 2 μ = ∫ (x : Ω), ((X - fun x => ∫ (x : Ω), X x ∂μ) ^ 2) x ∂μ
[PROOFSTEP]
rfl
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ mgf 0 μ t = ENNReal.toReal (↑↑μ Set.univ)
[PROOFSTEP]
simp only [mgf, Pi.zero_apply, mul_zero, exp_zero, integral_const, smul_eq_mul, mul_one]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ cgf 0 μ t = log (ENNReal.toReal (↑↑μ Set.univ))
[PROOFSTEP]
simp only [cgf, mgf_zero_fun]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ mgf X 0 t = 0
[PROOFSTEP]
simp only [mgf, integral_zero_measure]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ cgf X 0 t = 0
[PROOFSTEP]
simp only [cgf, log_zero, mgf_zero_measure]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t c : ℝ
⊢ mgf (fun x => c) μ t = ENNReal.toReal (↑↑μ Set.univ) * exp (t * c)
[PROOFSTEP]
simp only [mgf, integral_const, smul_eq_mul]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t c : ℝ
inst✝ : IsProbabilityMeasure μ
⊢ mgf (fun x => c) μ t = exp (t * c)
[PROOFSTEP]
simp only [mgf_const', measure_univ, ENNReal.one_toReal, one_mul]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
hμ : μ ≠ 0
c : ℝ
⊢ cgf (fun x => c) μ t = log (ENNReal.toReal (↑↑μ Set.univ)) + t * c
[PROOFSTEP]
simp only [cgf, mgf_const']
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
hμ : μ ≠ 0
c : ℝ
⊢ log (ENNReal.toReal (↑↑μ Set.univ) * exp (t * c)) = log (ENNReal.toReal (↑↑μ Set.univ)) + t * c
[PROOFSTEP]
rw [log_mul _ (exp_pos _).ne']
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
hμ : μ ≠ 0
c : ℝ
⊢ log (ENNReal.toReal (↑↑μ Set.univ)) + log (exp (t * c)) = log (ENNReal.toReal (↑↑μ Set.univ)) + t * c
[PROOFSTEP]
rw [log_exp _]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
hμ : μ ≠ 0
c : ℝ
⊢ ENNReal.toReal (↑↑μ Set.univ) ≠ 0
[PROOFSTEP]
rw [Ne.def, ENNReal.toReal_eq_zero_iff, Measure.measure_univ_eq_zero]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
hμ : μ ≠ 0
c : ℝ
⊢ ¬(μ = 0 ∨ ↑↑μ Set.univ = ⊤)
[PROOFSTEP]
simp only [hμ, measure_ne_top μ Set.univ, or_self_iff, not_false_iff]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
c : ℝ
⊢ cgf (fun x => c) μ t = t * c
[PROOFSTEP]
simp only [cgf, mgf_const, log_exp]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ mgf X μ 0 = ENNReal.toReal (↑↑μ Set.univ)
[PROOFSTEP]
simp only [mgf, zero_mul, exp_zero, integral_const, smul_eq_mul, mul_one]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
⊢ mgf X μ 0 = 1
[PROOFSTEP]
simp only [mgf_zero', measure_univ, ENNReal.one_toReal]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ cgf X μ 0 = log (ENNReal.toReal (↑↑μ Set.univ))
[PROOFSTEP]
simp only [cgf, mgf_zero']
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
⊢ cgf X μ 0 = 0
[PROOFSTEP]
simp only [cgf_zero', measure_univ, ENNReal.one_toReal, log_one]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hX : ¬Integrable fun ω => exp (t * X ω)
⊢ mgf X μ t = 0
[PROOFSTEP]
simp only [mgf, integral_undef hX]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hX : ¬Integrable fun ω => exp (t * X ω)
⊢ cgf X μ t = 0
[PROOFSTEP]
simp only [cgf, mgf_undef hX, log_zero]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ 0 ≤ mgf X μ t
[PROOFSTEP]
refine' integral_nonneg _
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ 0 ≤ fun x => (fun ω => exp (t * X ω)) x
[PROOFSTEP]
intro ω
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
ω : Ω
⊢ OfNat.ofNat 0 ω ≤ (fun x => (fun ω => exp (t * X ω)) x) ω
[PROOFSTEP]
simp only [Pi.zero_apply]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
ω : Ω
⊢ 0 ≤ exp (t * X ω)
[PROOFSTEP]
exact (exp_pos _).le
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
⊢ 0 < mgf X μ t
[PROOFSTEP]
simp_rw [mgf]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
⊢ 0 < ∫ (x : Ω), exp (t * X x) ∂μ
[PROOFSTEP]
have : ∫ x : Ω, exp (t * X x) ∂μ = ∫ x : Ω in Set.univ, exp (t * X x) ∂μ := by simp only [Measure.restrict_univ]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
⊢ ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
[PROOFSTEP]
simp only [Measure.restrict_univ]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
⊢ 0 < ∫ (x : Ω), exp (t * X x) ∂μ
[PROOFSTEP]
rw [this, set_integral_pos_iff_support_of_nonneg_ae _ _]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
⊢ 0 < ↑↑μ ((Function.support fun x => exp (t * X x)) ∩ Set.univ)
[PROOFSTEP]
have h_eq_univ : (Function.support fun x : Ω => exp (t * X x)) = Set.univ :=
by
ext1 x
simp only [Function.mem_support, Set.mem_univ, iff_true_iff]
exact (exp_pos _).ne'
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
⊢ (Function.support fun x => exp (t * X x)) = Set.univ
[PROOFSTEP]
ext1 x
[GOAL]
case h
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
x : Ω
⊢ (x ∈ Function.support fun x => exp (t * X x)) ↔ x ∈ Set.univ
[PROOFSTEP]
simp only [Function.mem_support, Set.mem_univ, iff_true_iff]
[GOAL]
case h
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
x : Ω
⊢ exp (t * X x) ≠ 0
[PROOFSTEP]
exact (exp_pos _).ne'
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
h_eq_univ : (Function.support fun x => exp (t * X x)) = Set.univ
⊢ 0 < ↑↑μ ((Function.support fun x => exp (t * X x)) ∩ Set.univ)
[PROOFSTEP]
rw [h_eq_univ, Set.inter_univ _]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
h_eq_univ : (Function.support fun x => exp (t * X x)) = Set.univ
⊢ 0 < ↑↑μ Set.univ
[PROOFSTEP]
refine' Ne.bot_lt _
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
h_eq_univ : (Function.support fun x => exp (t * X x)) = Set.univ
⊢ ↑↑μ Set.univ ≠ ⊥
[PROOFSTEP]
simp only [hμ, ENNReal.bot_eq_zero, Ne.def, Measure.measure_univ_eq_zero, not_false_iff]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
⊢ 0 ≤ᵐ[Measure.restrict μ Set.univ] fun x => exp (t * X x)
[PROOFSTEP]
refine' eventually_of_forall fun x => _
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
x : Ω
⊢ OfNat.ofNat 0 x ≤ (fun x => exp (t * X x)) x
[PROOFSTEP]
rw [Pi.zero_apply]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
x : Ω
⊢ 0 ≤ (fun x => exp (t * X x)) x
[PROOFSTEP]
exact (exp_pos _).le
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
hμ : μ ≠ 0
h_int_X : Integrable fun ω => exp (t * X ω)
this : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in Set.univ, exp (t * X x) ∂μ
⊢ IntegrableOn (fun x => exp (t * X x)) Set.univ
[PROOFSTEP]
rwa [integrableOn_univ]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ mgf (-X) μ t = mgf X μ (-t)
[PROOFSTEP]
simp_rw [mgf, Pi.neg_apply, mul_neg, neg_mul]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
⊢ cgf (-X) μ t = cgf X μ (-t)
[PROOFSTEP]
simp_rw [cgf, mgf_neg]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t✝ : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
s t : ℝ
⊢ IndepFun (fun ω => exp (s * X ω)) fun ω => exp (t * Y ω)
[PROOFSTEP]
have h_meas : ∀ t, Measurable fun x => exp (t * x) := fun t => (measurable_id'.const_mul t).exp
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t✝ : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
s t : ℝ
h_meas : ∀ (t : ℝ), Measurable fun x => exp (t * x)
⊢ IndepFun (fun ω => exp (s * X ω)) fun ω => exp (t * Y ω)
[PROOFSTEP]
change IndepFun ((fun x => exp (s * x)) ∘ X) ((fun x => exp (t * x)) ∘ Y) μ
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t✝ : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
s t : ℝ
h_meas : ∀ (t : ℝ), Measurable fun x => exp (t * x)
⊢ IndepFun ((fun x => exp (s * x)) ∘ X) ((fun x => exp (t * x)) ∘ Y)
[PROOFSTEP]
exact IndepFun.comp h_indep (h_meas s) (h_meas t)
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
hX : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ
hY : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ
⊢ mgf (X + Y) μ t = mgf X μ t * mgf Y μ t
[PROOFSTEP]
simp_rw [mgf, Pi.add_apply, mul_add, exp_add]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
hX : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ
hY : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ
⊢ ∫ (x : Ω), exp (t * X x) * exp (t * Y x) ∂μ = (∫ (x : Ω), exp (t * X x) ∂μ) * ∫ (x : Ω), exp (t * Y x) ∂μ
[PROOFSTEP]
exact (h_indep.exp_mul t t).integral_mul hX hY
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
hX : AEStronglyMeasurable X μ
hY : AEStronglyMeasurable Y μ
⊢ mgf (X + Y) μ t = mgf X μ t * mgf Y μ t
[PROOFSTEP]
have A : Continuous fun x : ℝ => exp (t * x) := by continuity
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
hX : AEStronglyMeasurable X μ
hY : AEStronglyMeasurable Y μ
⊢ Continuous fun x => exp (t * x)
[PROOFSTEP]
continuity
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
hX : AEStronglyMeasurable X μ
hY : AEStronglyMeasurable Y μ
A : Continuous fun x => exp (t * x)
⊢ mgf (X + Y) μ t = mgf X μ t * mgf Y μ t
[PROOFSTEP]
have h'X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ := A.aestronglyMeasurable.comp_aemeasurable hX.aemeasurable
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
hX : AEStronglyMeasurable X μ
hY : AEStronglyMeasurable Y μ
A : Continuous fun x => exp (t * x)
h'X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ
⊢ mgf (X + Y) μ t = mgf X μ t * mgf Y μ t
[PROOFSTEP]
have h'Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ := A.aestronglyMeasurable.comp_aemeasurable hY.aemeasurable
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
hX : AEStronglyMeasurable X μ
hY : AEStronglyMeasurable Y μ
A : Continuous fun x => exp (t * x)
h'X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ
h'Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ
⊢ mgf (X + Y) μ t = mgf X μ t * mgf Y μ t
[PROOFSTEP]
exact h_indep.mgf_add h'X h'Y
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
h_int_X : Integrable fun ω => exp (t * X ω)
h_int_Y : Integrable fun ω => exp (t * Y ω)
⊢ cgf (X + Y) μ t = cgf X μ t + cgf Y μ t
[PROOFSTEP]
by_cases hμ : μ = 0
[GOAL]
case pos
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
h_int_X : Integrable fun ω => exp (t * X ω)
h_int_Y : Integrable fun ω => exp (t * Y ω)
hμ : μ = 0
⊢ cgf (X + Y) μ t = cgf X μ t + cgf Y μ t
[PROOFSTEP]
simp [hμ]
[GOAL]
case neg
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
h_int_X : Integrable fun ω => exp (t * X ω)
h_int_Y : Integrable fun ω => exp (t * Y ω)
hμ : ¬μ = 0
⊢ cgf (X + Y) μ t = cgf X μ t + cgf Y μ t
[PROOFSTEP]
simp only [cgf, h_indep.mgf_add h_int_X.aestronglyMeasurable h_int_Y.aestronglyMeasurable]
[GOAL]
case neg
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
h_int_X : Integrable fun ω => exp (t * X ω)
h_int_Y : Integrable fun ω => exp (t * Y ω)
hμ : ¬μ = 0
⊢ log (mgf X μ t * mgf Y μ t) = log (mgf X μ t) + log (mgf Y μ t)
[PROOFSTEP]
exact log_mul (mgf_pos' hμ h_int_X).ne' (mgf_pos' hμ h_int_Y).ne'
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_int_X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ
h_int_Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * (X + Y) ω)) μ
[PROOFSTEP]
simp_rw [Pi.add_apply, mul_add, exp_add]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_int_X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ
h_int_Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * X ω) * exp (t * Y ω)) μ
[PROOFSTEP]
exact AEStronglyMeasurable.mul h_int_X h_int_Y
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * Finset.sum s (fun i => X i) ω)) μ
[PROOFSTEP]
classical
induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int
· simp only [Pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero]
exact aestronglyMeasurable_const
· have : ∀ i : ι, i ∈ s → AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi =>
h_int i (mem_insert_of_mem hi)
specialize h_rec this
rw [sum_insert hi_notin_s]
apply aestronglyMeasurable_exp_mul_add (h_int i (mem_insert_self _ _)) h_rec
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * Finset.sum s (fun i => X i) ω)) μ
[PROOFSTEP]
induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int
[GOAL]
case empty
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
h_int : ∀ (i : ι), i ∈ ∅ → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * Finset.sum ∅ (fun i => X i) ω)) μ
[PROOFSTEP]
simp only [Pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero]
[GOAL]
case empty
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
h_int : ∀ (i : ι), i ∈ ∅ → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
⊢ AEStronglyMeasurable (fun ω => 1) μ
[PROOFSTEP]
exact aestronglyMeasurable_const
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_rec :
(∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ) →
AEStronglyMeasurable (fun ω => exp (t * Finset.sum s (fun i => X i) ω)) μ
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → AEStronglyMeasurable (fun ω => exp (t * X i_1 ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * Finset.sum (insert i s) (fun i => X i) ω)) μ
[PROOFSTEP]
have : ∀ i : ι, i ∈ s → AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi =>
h_int i (mem_insert_of_mem hi)
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_rec :
(∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ) →
AEStronglyMeasurable (fun ω => exp (t * Finset.sum s (fun i => X i) ω)) μ
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → AEStronglyMeasurable (fun ω => exp (t * X i_1 ω)) μ
this : ∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * Finset.sum (insert i s) (fun i => X i) ω)) μ
[PROOFSTEP]
specialize h_rec this
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → AEStronglyMeasurable (fun ω => exp (t * X i_1 ω)) μ
this : ∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
h_rec : AEStronglyMeasurable (fun ω => exp (t * Finset.sum s (fun i => X i) ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * Finset.sum (insert i s) (fun i => X i) ω)) μ
[PROOFSTEP]
rw [sum_insert hi_notin_s]
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X : ι → Ω → ℝ
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → AEStronglyMeasurable (fun ω => exp (t * X i_1 ω)) μ
this : ∀ (i : ι), i ∈ s → AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
h_rec : AEStronglyMeasurable (fun ω => exp (t * Finset.sum s (fun i => X i) ω)) μ
⊢ AEStronglyMeasurable (fun ω => exp (t * (X i + ∑ x in s, X x) ω)) μ
[PROOFSTEP]
apply aestronglyMeasurable_exp_mul_add (h_int i (mem_insert_self _ _)) h_rec
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
h_int_X : Integrable fun ω => exp (t * X ω)
h_int_Y : Integrable fun ω => exp (t * Y ω)
⊢ Integrable fun ω => exp (t * (X + Y) ω)
[PROOFSTEP]
simp_rw [Pi.add_apply, mul_add, exp_add]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
X Y : Ω → ℝ
h_indep : IndepFun X Y
h_int_X : Integrable fun ω => exp (t * X ω)
h_int_Y : Integrable fun ω => exp (t * Y ω)
⊢ Integrable fun ω => exp (t * X ω) * exp (t * Y ω)
[PROOFSTEP]
exact (h_indep.exp_mul t t).integrable_mul h_int_X h_int_Y
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
⊢ Integrable fun ω => exp (t * Finset.sum s (fun i => X i) ω)
[PROOFSTEP]
classical
induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int
· simp only [Pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero]
exact integrable_const _
· have : ∀ i : ι, i ∈ s → Integrable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi => h_int i (mem_insert_of_mem hi)
specialize h_rec this
rw [sum_insert hi_notin_s]
refine' IndepFun.integrable_exp_mul_add _ (h_int i (mem_insert_self _ _)) h_rec
exact (h_indep.indepFun_finset_sum_of_not_mem h_meas hi_notin_s).symm
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
⊢ Integrable fun ω => exp (t * Finset.sum s (fun i => X i) ω)
[PROOFSTEP]
induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int
[GOAL]
case empty
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
h_int : ∀ (i : ι), i ∈ ∅ → Integrable fun ω => exp (t * X i ω)
⊢ Integrable fun ω => exp (t * Finset.sum ∅ (fun i => X i) ω)
[PROOFSTEP]
simp only [Pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero]
[GOAL]
case empty
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
h_int : ∀ (i : ι), i ∈ ∅ → Integrable fun ω => exp (t * X i ω)
⊢ Integrable fun ω => 1
[PROOFSTEP]
exact integrable_const _
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → Integrable fun ω => exp (t * X i ω)
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_rec :
(∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)) → Integrable fun ω => exp (t * Finset.sum s (fun i => X i) ω)
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → Integrable fun ω => exp (t * X i_1 ω)
⊢ Integrable fun ω => exp (t * Finset.sum (insert i s) (fun i => X i) ω)
[PROOFSTEP]
have : ∀ i : ι, i ∈ s → Integrable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi => h_int i (mem_insert_of_mem hi)
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → Integrable fun ω => exp (t * X i ω)
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_rec :
(∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)) → Integrable fun ω => exp (t * Finset.sum s (fun i => X i) ω)
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → Integrable fun ω => exp (t * X i_1 ω)
this : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
⊢ Integrable fun ω => exp (t * Finset.sum (insert i s) (fun i => X i) ω)
[PROOFSTEP]
specialize h_rec this
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → Integrable fun ω => exp (t * X i ω)
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → Integrable fun ω => exp (t * X i_1 ω)
this : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
h_rec : Integrable fun ω => exp (t * Finset.sum s (fun i => X i) ω)
⊢ Integrable fun ω => exp (t * Finset.sum (insert i s) (fun i => X i) ω)
[PROOFSTEP]
rw [sum_insert hi_notin_s]
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → Integrable fun ω => exp (t * X i ω)
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → Integrable fun ω => exp (t * X i_1 ω)
this : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
h_rec : Integrable fun ω => exp (t * Finset.sum s (fun i => X i) ω)
⊢ Integrable fun ω => exp (t * (X i + ∑ x in s, X x) ω)
[PROOFSTEP]
refine' IndepFun.integrable_exp_mul_add _ (h_int i (mem_insert_self _ _)) h_rec
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s✝ : Finset ι
h_int✝ : ∀ (i : ι), i ∈ s✝ → Integrable fun ω => exp (t * X i ω)
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_int : ∀ (i_1 : ι), i_1 ∈ insert i s → Integrable fun ω => exp (t * X i_1 ω)
this : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
h_rec : Integrable fun ω => exp (t * Finset.sum s (fun i => X i) ω)
⊢ IndepFun (X i) (∑ x in s, X x)
[PROOFSTEP]
exact (h_indep.indepFun_finset_sum_of_not_mem h_meas hi_notin_s).symm
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
⊢ mgf (∑ i in s, X i) μ t = ∏ i in s, mgf (X i) μ t
[PROOFSTEP]
classical
induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int
· simp only [sum_empty, mgf_zero_fun, measure_univ, ENNReal.one_toReal, prod_empty]
· have h_int' : ∀ i : ι, AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i =>
((h_meas i).const_mul t).exp.aestronglyMeasurable
rw [sum_insert hi_notin_s,
IndepFun.mgf_add (h_indep.indepFun_finset_sum_of_not_mem h_meas hi_notin_s).symm (h_int' i)
(aestronglyMeasurable_exp_mul_sum fun i _ => h_int' i),
h_rec, prod_insert hi_notin_s]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
⊢ mgf (∑ i in s, X i) μ t = ∏ i in s, mgf (X i) μ t
[PROOFSTEP]
induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int
[GOAL]
case empty
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
⊢ mgf (∑ i in ∅, X i) μ t = ∏ i in ∅, mgf (X i) μ t
[PROOFSTEP]
simp only [sum_empty, mgf_zero_fun, measure_univ, ENNReal.one_toReal, prod_empty]
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_rec : mgf (∑ i in s, X i) μ t = ∏ i in s, mgf (X i) μ t
⊢ mgf (∑ i in insert i s, X i) μ t = ∏ i in insert i s, mgf (X i) μ t
[PROOFSTEP]
have h_int' : ∀ i : ι, AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i =>
((h_meas i).const_mul t).exp.aestronglyMeasurable
[GOAL]
case insert
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
i : ι
s : Finset ι
hi_notin_s : ¬i ∈ s
h_rec : mgf (∑ i in s, X i) μ t = ∏ i in s, mgf (X i) μ t
h_int' : ∀ (i : ι), AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ
⊢ mgf (∑ i in insert i s, X i) μ t = ∏ i in insert i s, mgf (X i) μ t
[PROOFSTEP]
rw [sum_insert hi_notin_s,
IndepFun.mgf_add (h_indep.indepFun_finset_sum_of_not_mem h_meas hi_notin_s).symm (h_int' i)
(aestronglyMeasurable_exp_mul_sum fun i _ => h_int' i),
h_rec, prod_insert hi_notin_s]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
⊢ cgf (∑ i in s, X i) μ t = ∑ i in s, cgf (X i) μ t
[PROOFSTEP]
simp_rw [cgf]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
⊢ log (mgf (∑ i in s, X i) μ t) = ∑ x in s, log (mgf (X x) μ t)
[PROOFSTEP]
rw [← log_prod _ _ fun j hj => ?_]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
⊢ log (mgf (∑ i in s, X i) μ t) = log (∏ i in s, mgf (X i) μ t)
[PROOFSTEP]
rw [h_indep.mgf_sum h_meas]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X✝ : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsProbabilityMeasure μ
X : ι → Ω → ℝ
h_indep : iIndepFun (fun i => inferInstance) X
h_meas : ∀ (i : ι), Measurable (X i)
s : Finset ι
h_int : ∀ (i : ι), i ∈ s → Integrable fun ω => exp (t * X i ω)
j : ι
hj : j ∈ s
⊢ mgf (X j) μ t ≠ 0
[PROOFSTEP]
exact (mgf_pos (h_int j hj)).ne'
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
⊢ ENNReal.toReal (↑↑μ {ω | ε ≤ X ω}) ≤ exp (-t * ε) * mgf X μ t
[PROOFSTEP]
cases' ht.eq_or_lt with ht_zero_eq ht_pos
[GOAL]
case inl
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_zero_eq : 0 = t
⊢ ENNReal.toReal (↑↑μ {ω | ε ≤ X ω}) ≤ exp (-t * ε) * mgf X μ t
[PROOFSTEP]
rw [ht_zero_eq.symm]
[GOAL]
case inl
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_zero_eq : 0 = t
⊢ ENNReal.toReal (↑↑μ {ω | ε ≤ X ω}) ≤ exp (-0 * ε) * mgf X μ 0
[PROOFSTEP]
simp only [neg_zero, zero_mul, exp_zero, mgf_zero', one_mul]
[GOAL]
case inl
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_zero_eq : 0 = t
⊢ ENNReal.toReal (↑↑μ {ω | ε ≤ X ω}) ≤ ENNReal.toReal (↑↑μ Set.univ)
[PROOFSTEP]
rw [ENNReal.toReal_le_toReal (measure_ne_top μ _) (measure_ne_top μ _)]
[GOAL]
case inl
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_zero_eq : 0 = t
⊢ ↑↑μ {ω | ε ≤ X ω} ≤ ↑↑μ Set.univ
[PROOFSTEP]
exact measure_mono (Set.subset_univ _)
[GOAL]
case inr
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
⊢ ENNReal.toReal (↑↑μ {ω | ε ≤ X ω}) ≤ exp (-t * ε) * mgf X μ t
[PROOFSTEP]
calc
(μ {ω | ε ≤ X ω}).toReal = (μ {ω | exp (t * ε) ≤ exp (t * X ω)}).toReal :=
by
congr with ω
simp only [Set.mem_setOf_eq, exp_le_exp, gt_iff_lt]
exact ⟨fun h => mul_le_mul_of_nonneg_left h ht_pos.le, fun h => le_of_mul_le_mul_left h ht_pos⟩
_ ≤ (exp (t * ε))⁻¹ * μ[fun ω => exp (t * X ω)] :=
by
have : exp (t * ε) * (μ {ω | exp (t * ε) ≤ exp (t * X ω)}).toReal ≤ μ[fun ω => exp (t * X ω)] :=
mul_meas_ge_le_integral_of_nonneg (fun x => (exp_pos _).le) h_int _
rwa [mul_comm (exp (t * ε))⁻¹, ← div_eq_mul_inv, le_div_iff' (exp_pos _)]
_ = exp (-t * ε) * mgf X μ t := by rw [neg_mul, exp_neg]; rfl
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
⊢ ENNReal.toReal (↑↑μ {ω | ε ≤ X ω}) = ENNReal.toReal (↑↑μ {ω | exp (t * ε) ≤ exp (t * X ω)})
[PROOFSTEP]
congr with ω
[GOAL]
case e_a.e_a.h
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
ω : Ω
⊢ ω ∈ {ω | ε ≤ X ω} ↔ ω ∈ {ω | exp (t * ε) ≤ exp (t * X ω)}
[PROOFSTEP]
simp only [Set.mem_setOf_eq, exp_le_exp, gt_iff_lt]
[GOAL]
case e_a.e_a.h
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
ω : Ω
⊢ ε ≤ X ω ↔ t * ε ≤ t * X ω
[PROOFSTEP]
exact ⟨fun h => mul_le_mul_of_nonneg_left h ht_pos.le, fun h => le_of_mul_le_mul_left h ht_pos⟩
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
⊢ ENNReal.toReal (↑↑μ {ω | exp (t * ε) ≤ exp (t * X ω)}) ≤ (exp (t * ε))⁻¹ * ∫ (x : Ω), (fun ω => exp (t * X ω)) x ∂μ
[PROOFSTEP]
have : exp (t * ε) * (μ {ω | exp (t * ε) ≤ exp (t * X ω)}).toReal ≤ μ[fun ω => exp (t * X ω)] :=
mul_meas_ge_le_integral_of_nonneg (fun x => (exp_pos _).le) h_int _
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
this : exp (t * ε) * ENNReal.toReal (↑↑μ {ω | exp (t * ε) ≤ exp (t * X ω)}) ≤ ∫ (x : Ω), (fun ω => exp (t * X ω)) x ∂μ
⊢ ENNReal.toReal (↑↑μ {ω | exp (t * ε) ≤ exp (t * X ω)}) ≤ (exp (t * ε))⁻¹ * ∫ (x : Ω), (fun ω => exp (t * X ω)) x ∂μ
[PROOFSTEP]
rwa [mul_comm (exp (t * ε))⁻¹, ← div_eq_mul_inv, le_div_iff' (exp_pos _)]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
⊢ (exp (t * ε))⁻¹ * ∫ (x : Ω), (fun ω => exp (t * X ω)) x ∂μ = exp (-t * ε) * mgf X μ t
[PROOFSTEP]
rw [neg_mul, exp_neg]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
ht_pos : 0 < t
⊢ (exp (t * ε))⁻¹ * ∫ (x : Ω), (fun ω => exp (t * X ω)) x ∂μ = (exp (t * ε))⁻¹ * mgf X μ t
[PROOFSTEP]
rfl
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ ENNReal.toReal (↑↑μ {ω | X ω ≤ ε}) ≤ exp (-t * ε) * mgf X μ t
[PROOFSTEP]
rw [← neg_neg t, ← mgf_neg, neg_neg, ← neg_mul_neg (-t)]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ ENNReal.toReal (↑↑μ {ω | X ω ≤ ε}) ≤ exp (- -t * -ε) * mgf (-X) μ (-t)
[PROOFSTEP]
refine' Eq.trans_le _ (measure_ge_le_exp_mul_mgf (-ε) (neg_nonneg.mpr ht) _)
[GOAL]
case refine'_1
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ ENNReal.toReal (↑↑μ {ω | X ω ≤ ε}) = ENNReal.toReal (↑↑μ {ω | -ε ≤ (-X) ω})
[PROOFSTEP]
congr with ω
[GOAL]
case refine'_1.e_a.e_a.h
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
ω : Ω
⊢ ω ∈ {ω | X ω ≤ ε} ↔ ω ∈ {ω | -ε ≤ (-X) ω}
[PROOFSTEP]
simp only [Pi.neg_apply, neg_le_neg_iff]
[GOAL]
case refine'_2
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ Integrable fun ω => exp (-t * (-X) ω)
[PROOFSTEP]
simp_rw [Pi.neg_apply, neg_mul_neg]
[GOAL]
case refine'_2
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ Integrable fun ω => exp (t * X ω)
[PROOFSTEP]
exact h_int
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
⊢ ENNReal.toReal (↑↑μ {ω | ε ≤ X ω}) ≤ exp (-t * ε + cgf X μ t)
[PROOFSTEP]
refine' (measure_ge_le_exp_mul_mgf ε ht h_int).trans _
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
⊢ exp (-t * ε) * mgf (fun ω => X ω) μ t ≤ exp (-t * ε + cgf X μ t)
[PROOFSTEP]
rw [exp_add]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : 0 ≤ t
h_int : Integrable fun ω => exp (t * X ω)
⊢ exp (-t * ε) * mgf (fun ω => X ω) μ t ≤ exp (-t * ε) * exp (cgf X μ t)
[PROOFSTEP]
exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ ENNReal.toReal (↑↑μ {ω | X ω ≤ ε}) ≤ exp (-t * ε + cgf X μ t)
[PROOFSTEP]
refine' (measure_le_le_exp_mul_mgf ε ht h_int).trans _
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ exp (-t * ε) * mgf (fun ω => X ω) μ t ≤ exp (-t * ε + cgf X μ t)
[PROOFSTEP]
rw [exp_add]
[GOAL]
Ω : Type u_1
ι : Type u_2
m : MeasurableSpace Ω
X : Ω → ℝ
p : ℕ
μ : Measure Ω
t : ℝ
inst✝ : IsFiniteMeasure μ
ε : ℝ
ht : t ≤ 0
h_int : Integrable fun ω => exp (t * X ω)
⊢ exp (-t * ε) * mgf (fun ω => X ω) μ t ≤ exp (-t * ε) * exp (cgf X μ t)
[PROOFSTEP]
exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le
|
clear all; close all;
I=imread('cameraman.tif');
I=im2double(I);
J=fftshift(fft2(I));
[x, y]=meshgrid(-128:127, -128:127);
z=sqrt(x.^2+y.^2);
D1=10; D2=30;
n=6;
H1=1./(1+(z/D1).^(2*n));
H2=1./(1+(z/D2).^(2*n));
K1=J.*H1;
K2=J.*H2;
L1=ifft2(ifftshift(K1));
L2=ifft2(ifftshift(K2));
figure;
subplot(131);
imshow(I);
subplot(132);
imshow(real(L1));
subplot(133);
imshow(real(L2))
|
lemma fun_complex_eq: "f = (\<lambda>x. Re (f x) + \<i> * Im (f x))" |
import topology.continuous_function.polynomial -- hide
/- # Using apply
In this problem you will show that a specific polynomial is continuous, you can do this using
the basic facts in the left sidebar: that adding continuous functions is continuous,
likewise multiplying continuous functions remains continuous, constant functions are continuous,
and the identity function is continuous. The way these lemmas are stated is very general, they work
for any continuous functions on arbitrary topological spaces, but by using `apply` we can let Lean
work out the details automatically.
But how do we talk about the functions themselves?
The basic method to speak about an unnamed function in Lean makes use of the lambda syntax.
In mathematics we might just write $x ^ 3 + 7$ to describe a polynomial function, leaving it
implicit that $x$ is the variable.
In Lean we use the symbol λ (`\lambda`) to describe a function by placing the name of the variable
after the lambda.
So `λ x, x^3 + 7` defines the function which takes input `x` and outputs `x^3 + 7` in Lean.
Watch out! Some of these lemmas have names with a dot like `continuous.add` (these ones
prove continuity of a combination of functions) and some have an underscore like
`continuous_const` (these ones state that some specific function is continuous).
-/
/- Tactic : apply
## Summary
If `h : P → Q` is a hypothesis, and the goal is `⊢ Q` then
`apply h` changes the goal to `⊢ P`.
## Details
If you have a function `h : P → Q` and your goal is `⊢ Q`
then `apply h` changes the goal to `⊢ P`. The logic is
simple: if you are trying to create a term of type `Q`,
but `h` is a function which turns terms of type `P` into
terms of type `Q`, then it will suffice to construct a
term of type `P`. A mathematician might say: "we need
to construct an element of $Q$, but we have a function $h:P\to Q$
so it suffices to construct an element of $P$". Or alternatively
"we need to prove $Q$, but we have a proof $h$ that $P\implies Q$
so it suffices to prove $P$".
-/
open polynomial-- hide
/- Axiom : Adding two continuous functions is continuous
continuous.add : ∀ {X M : Type} [topological_space X] [topological_space M] [has_add M]
[has_continuous_add M] {f g : X → M},
continuous f → continuous g → continuous (λ (x : X), f x + g x)
-/
/- Axiom : Multiplying two continuous functions is continuous
continuous.mul : ∀ {X M : Type} [topological_space X] [ topological_space M]
[has_mul M] [has_continuous_mul M] {f g : X → M},
continuous f → continuous g → continuous (λ (x : X), f x * g x)
-/
/- Axiom :
continuous.pow : ∀ {X M : Type} [topological_space X] [topological_space M] [monoid M]
[has_continuous_mul M] {f : X → M},
continuous f → ∀ (n : ℕ), continuous (λ (b : X), f b ^ n)
-/
/- Axiom : A constant function is continuous
continuous_const : ∀ {α β : Type} [topological_space α] [topological_space β] {b : β},
continuous (λ (a : α), b)
-/
/- Axiom : The identity function is continuous
continuous_id : ∀ {α : Type} [topological_space α], continuous (λ x, x)
-/
/- Lemma : no-side-bar
-/
lemma poly_continuous : continuous (λ x : ℝ, 5 * x ^ 2 + x + 6) :=
begin
apply continuous.add,
apply continuous.add,
apply continuous.mul,
apply continuous_const,
apply continuous.pow,
apply continuous_id,
apply continuous_id,
apply continuous_const,
end
|
lemma Reals_minus_iff [simp]: "- a \<in> \<real> \<longleftrightarrow> a \<in> \<real>" |
# *************************************************************************
# CMI2NI: Conditional mutual inclusive information(CMI2)-based Network
# Inference method from gene expression data
# *************************************************************************
# This is matlab code for netwrk inference method CMI2NI.
# Input:
# 'data' is expression of variable,in which row is varible and column is the sample;
# 'lamda' is the parameter decide the dependence;
# 'order0' is the parameter to end the program when order=order0;
# If nargin==2,the algorithm will be terminated untill there is no change
# in network toplogy.
# Output:
# 'G' is the 0-1 network or graph after pc algorithm;
# 'Gval' is the network with strenthness of dependence;
# 'order' is the order of the pc algorithm, here is equal to order0;
# Example:
#
# Author: Xiujun Zhang.
# Version: Sept.2014.
#
# Downloaded from: http://www.comp-sysbio.org/cmi2ni/
CMI2NI <- function(data,lamda,order0=NULL){
data = t(data) # In original implementation, data is given as pxn
n_gene <- dim(data)[1]
G <- matrix(1,n_gene,n_gene)
G[lower.tri(G, diag=T)] <- 0
G <- G+t(G)
Gval <- G
order <- -1
t <- 0
while (t == 0){
order <- order+1
if (!is.null(order0)){
if (order>order0){
order <- order-1
return(list(G=G,Gval=Gval,order=order))
}
}
res.temp <- edgereduce(G,Gval,order,data,t,lamda)
G = res.temp$G
Gval = res.temp$Gval
t = res.temp$t
if (t==0){
print('No edge is reduced! Algorithm finished!')
return(list(G=G,Gval=Gval,order=order))
} else {
t <- 0
}
}
order <- order-1 # The value of order is the last order of the algorithm
return(list(G=G,Gval=Gval,order=order))
}
## edgereduce
edgereduce <- function(G,Gval,order,data,t,lamda){
G0 <- G
if (order==0){
for (i in 1:dim(G)[1]){
for (j in 1:dim(G)[1]){
if (G[i,j]!=0){
cmiv <- cmi(data[i,],data[j,])
Gval[i,j] <- cmiv
Gval[j,i] <- cmiv
if (cmiv<lamda){
G[i,j] <- 0
G[j,i] <- 0
}
}
}
}
t <- t+1
return(list(G=G,Gval=Gval,t=t))
}
else {
for (i in 1:dim(G)[1]){
for (j in 1:dim(G)[1]){
if (G[i,j]!=0){
adj <- c()
for (k in 1:dim(G)[1]){
if (G[i,k]!=0 & G[j,k]!=0){
adj <- c(adj,k)
}
}
if (length(adj)>=order){
if(length(adj)==1){ # Need a special case as combn does not work allow single element arguments
combntnslist <- as.matrix(adj)
}
else{
combntnslist <- t(combn(adj,order))
}
combntnsrow <- dim(combntnslist)[1]
cmiv <- 0
v1 <- data[i,]
v2 <- data[j,]
for (k in 1:combntnsrow){
vcs <- data[combntnslist[k,],]
a <- MI2(v1,v2,vcs)
cmiv <- max(cmiv,a)
}
Gval[i,j] <- cmiv
Gval[j,i] <- cmiv
if (cmiv<lamda){
G[i,j] <- 0
G[j,i] <- 0
}
t <- t+1
}
}
}
}
return(list(G=G,Gval=Gval,t=t))
}
}
## compute conditional mutual information of x and y
cmi <- function(v1,v2,vcs=NULL){
if (is.null(vcs)){
c1 <- (var(v1)) # removed det as this is just a scalar
c2 <- (var(v2))
c3 <- det(cov(t(rbind(v1,v2)))) # cov in r only gives a matrix if we give one, so must use rbind
cmiv <- 0.5*log(c1*c2/c3)
}
else if (!is.null(vcs)){
c1 <- det(cov(t(rbind(v1,vcs))))
c2 <- det(cov(t(rbind(v2,vcs))))
c3 <- (var(t(vcs)))
c4 <- det(cov(t(rbind(v1,v2,vcs))))
cmiv <- 0.5*log((c1*c2)/(c3*c4))
}
if (cmiv == Inf){
cmiv <- 1.0e+010
}
return(cmiv)
}
# Conditional mutual inclusive information (CMI2)
MI2 <- function(x,y,z){
r_dmi <- (cas(x,y,z) + cas(y,x,z))/2
return(r_dmi)
}
# x and y are 1*m dimensional vector; z is n1*m dimensional.
cas <- function(x,y,z){
# x,y,z are row vectors;
if(is.null(dim(z))){
n1 = 1
}
else{
n1 <- dim(z)[1] # This is equal to the order
}
n <- n1 +2
Cov <- var(x)
Covm <- cov(t(rbind(x,y,z)))
Covm1 <- cov(t(rbind(x,z)))
InvCov <- solve(Cov)
InvCovm <- solve(Covm)
InvCovm1 <- solve(Covm1)
C11 <- InvCovm1[1,1] # 1x1
C12 <- 0 # 1x1
C13 <- InvCovm1[1,2:(1+n1)] # 1x n1
C23 <- InvCovm[2,3:(2+n1)]-(InvCovm[1,2] * as.numeric(1/(InvCovm[1,1]-InvCovm1[1,1]+InvCov[1,1]))) %*% (InvCovm[1,3:(2+n1)] - InvCovm1[1,2:(1+n1)]) # 1x n1
C22 <- InvCovm[2,2]- InvCovm[1,2]^2 * (1/(InvCovm[1,1]-InvCovm1[1,1]+InvCov[1,1])) # 1x1
C33 <- InvCovm[3:(2+n1),3:(2+n1)]- (as.numeric((1/(InvCovm[1,1]-InvCovm1[1,1]+InvCov[1,1]))) * (t(t(InvCovm[1,3:(2+n1)]-
InvCovm1[1,2:(1+n1)]))%*%(InvCovm[1,3:(2+n1)]-InvCovm1[1,2:(1+n1)]))) # n1 x n1
InvC <- rbind(c(C11,C12,C13),c(C12,C22,C23),cbind(C13,t(C23),C33))
C0 <- Cov * (InvCovm[1,1] - InvCovm1[1,1] + InvCov[1,1])
CS <- 0.5 * (sum(diag(InvC%*%Covm))+log(C0)-n)
return(CS)
}
|
# The Deconfounder in Action
In this notebook, we are going to see **the deconfounder in action**.
We will perform **causal inference** with the deconfounder on a **breast cancer** dataset.
**Goal:**
To convince all of us that the deconfounder is **easy** to use!
The **deconfounder** operates in three steps:
1. **Fit** a factor model to the assigned causes; it leads to a candidate substitute confounder.
2. **Check** the factor model with a predictive check.
3. **Correct** for the substitute confounder in a causal inference.
Let's get started!
# Getting ready to work!
```python
!pip install tensorflow_probability
```
Requirement already satisfied: tensorflow_probability in /usr/local/lib/python3.6/dist-packages (0.9.0)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow_probability) (1.12.0)
Requirement already satisfied: gast>=0.2 in /usr/local/lib/python3.6/dist-packages (from tensorflow_probability) (0.3.3)
Requirement already satisfied: cloudpickle>=1.2.2 in /usr/local/lib/python3.6/dist-packages (from tensorflow_probability) (1.3.0)
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from tensorflow_probability) (1.18.2)
Requirement already satisfied: decorator in /usr/local/lib/python3.6/dist-packages (from tensorflow_probability) (4.4.2)
```python
%tensorflow_version 1.x
import tensorflow as tf
import numpy as np
import numpy.random as npr
import pandas as pd
import tensorflow as tf
import tensorflow_probability as tfp
import statsmodels.api as sm
from tensorflow_probability import edward2 as ed
from sklearn.datasets import load_breast_cancer
from pandas.plotting import scatter_matrix
from scipy import sparse, stats
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, classification_report, roc_auc_score, roc_curve
import matplotlib
matplotlib.rcParams.update({'font.sans-serif' : 'Helvetica',
'axes.labelsize': 10,
'xtick.labelsize' : 6,
'ytick.labelsize' : 6,
'axes.titlesize' : 10})
import matplotlib.pyplot as plt
import seaborn as sns
color_names = ["windows blue",
"amber",
"crimson",
"faded green",
"dusty purple",
"greyish"]
colors = sns.xkcd_palette(color_names)
sns.set(style="white", palette=sns.xkcd_palette(color_names), color_codes = False)
```
TensorFlow 1.x selected.
/usr/local/lib/python3.6/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
import pandas.util.testing as tm
```python
!pip show tensorflow
```
Name: tensorflow
Version: 1.15.2
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /tensorflow-1.15.2/python3.6
Requires: absl-py, keras-preprocessing, astor, tensorboard, tensorflow-estimator, wrapt, six, google-pasta, keras-applications, numpy, opt-einsum, termcolor, grpcio, protobuf, wheel, gast
Required-by: stable-baselines, magenta, fancyimpute
```python
!pip show tensorflow_probability
```
Name: tensorflow-probability
Version: 0.7.0
Summary: Probabilistic modeling and statistical inference in TensorFlow
Home-page: http://github.com/tensorflow/probability
Author: Google LLC
Author-email: [email protected]
License: Apache 2.0
Location: /tensorflow-1.15.2/python3.6
Requires: decorator, cloudpickle, six, numpy
Required-by: tensorflow-gan, tensor2tensor, magenta, kfac, dm-sonnet
```python
# set random seed so everyone gets the same number
import random
randseed = 123
print("random seed: ", randseed)
random.seed(randseed)
np.random.seed(randseed)
tf.set_random_seed(randseed)
```
random seed: 123
## The scikit-learn breast cancer dataset
* It is a data set about **breast cancer**.
* We are interested in how tumor properties **affect** cancer diagnosis.
* The **(multiple) causes** are tumor properties, e.g. sizes, compactness, symmetry, texture.
* The **outcome** is tumor diagnosis, whether the breast cancer is diagnosed as malignant or benign.
```python
data = load_breast_cancer()
```
```python
print(data['DESCR'])
```
.. _breast_cancer_dataset:
Breast cancer wisconsin (diagnostic) dataset
--------------------------------------------
**Data Set Characteristics:**
:Number of Instances: 569
:Number of Attributes: 30 numeric, predictive attributes and the class
:Attribute Information:
- radius (mean of distances from center to points on the perimeter)
- texture (standard deviation of gray-scale values)
- perimeter
- area
- smoothness (local variation in radius lengths)
- compactness (perimeter^2 / area - 1.0)
- concavity (severity of concave portions of the contour)
- concave points (number of concave portions of the contour)
- symmetry
- fractal dimension ("coastline approximation" - 1)
The mean, standard error, and "worst" or largest (mean of the three
largest values) of these features were computed for each image,
resulting in 30 features. For instance, field 3 is Mean Radius, field
13 is Radius SE, field 23 is Worst Radius.
- class:
- WDBC-Malignant
- WDBC-Benign
:Summary Statistics:
===================================== ====== ======
Min Max
===================================== ====== ======
radius (mean): 6.981 28.11
texture (mean): 9.71 39.28
perimeter (mean): 43.79 188.5
area (mean): 143.5 2501.0
smoothness (mean): 0.053 0.163
compactness (mean): 0.019 0.345
concavity (mean): 0.0 0.427
concave points (mean): 0.0 0.201
symmetry (mean): 0.106 0.304
fractal dimension (mean): 0.05 0.097
radius (standard error): 0.112 2.873
texture (standard error): 0.36 4.885
perimeter (standard error): 0.757 21.98
area (standard error): 6.802 542.2
smoothness (standard error): 0.002 0.031
compactness (standard error): 0.002 0.135
concavity (standard error): 0.0 0.396
concave points (standard error): 0.0 0.053
symmetry (standard error): 0.008 0.079
fractal dimension (standard error): 0.001 0.03
radius (worst): 7.93 36.04
texture (worst): 12.02 49.54
perimeter (worst): 50.41 251.2
area (worst): 185.2 4254.0
smoothness (worst): 0.071 0.223
compactness (worst): 0.027 1.058
concavity (worst): 0.0 1.252
concave points (worst): 0.0 0.291
symmetry (worst): 0.156 0.664
fractal dimension (worst): 0.055 0.208
===================================== ====== ======
:Missing Attribute Values: None
:Class Distribution: 212 - Malignant, 357 - Benign
:Creator: Dr. William H. Wolberg, W. Nick Street, Olvi L. Mangasarian
:Donor: Nick Street
:Date: November, 1995
This is a copy of UCI ML Breast Cancer Wisconsin (Diagnostic) datasets.
https://goo.gl/U2Uwz2
Features are computed from a digitized image of a fine needle
aspirate (FNA) of a breast mass. They describe
characteristics of the cell nuclei present in the image.
Separating plane described above was obtained using
Multisurface Method-Tree (MSM-T) [K. P. Bennett, "Decision Tree
Construction Via Linear Programming." Proceedings of the 4th
Midwest Artificial Intelligence and Cognitive Science Society,
pp. 97-101, 1992], a classification method which uses linear
programming to construct a decision tree. Relevant features
were selected using an exhaustive search in the space of 1-4
features and 1-3 separating planes.
The actual linear program used to obtain the separating plane
in the 3-dimensional space is that described in:
[K. P. Bennett and O. L. Mangasarian: "Robust Linear
Programming Discrimination of Two Linearly Inseparable Sets",
Optimization Methods and Software 1, 1992, 23-34].
This database is also available through the UW CS ftp server:
ftp ftp.cs.wisc.edu
cd math-prog/cpo-dataset/machine-learn/WDBC/
.. topic:: References
- W.N. Street, W.H. Wolberg and O.L. Mangasarian. Nuclear feature extraction
for breast tumor diagnosis. IS&T/SPIE 1993 International Symposium on
Electronic Imaging: Science and Technology, volume 1905, pages 861-870,
San Jose, CA, 1993.
- O.L. Mangasarian, W.N. Street and W.H. Wolberg. Breast cancer diagnosis and
prognosis via linear programming. Operations Research, 43(4), pages 570-577,
July-August 1995.
- W.H. Wolberg, W.N. Street, and O.L. Mangasarian. Machine learning techniques
to diagnose breast cancer from fine-needle aspirates. Cancer Letters 77 (1994)
163-171.
***For simplicity, we will work with the first 10 features, i.e. the mean radius/texture/perimeter***/....
```python
num_fea = 10
df = pd.DataFrame(data["data"][:,:num_fea], columns=data["feature_names"][:num_fea])
```
```python
df.shape
```
(569, 10)
```python
df.head()
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>mean radius</th>
<th>mean texture</th>
<th>mean perimeter</th>
<th>mean area</th>
<th>mean smoothness</th>
<th>mean compactness</th>
<th>mean concavity</th>
<th>mean concave points</th>
<th>mean symmetry</th>
<th>mean fractal dimension</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>17.99</td>
<td>10.38</td>
<td>122.80</td>
<td>1001.0</td>
<td>0.11840</td>
<td>0.27760</td>
<td>0.3001</td>
<td>0.14710</td>
<td>0.2419</td>
<td>0.07871</td>
</tr>
<tr>
<th>1</th>
<td>20.57</td>
<td>17.77</td>
<td>132.90</td>
<td>1326.0</td>
<td>0.08474</td>
<td>0.07864</td>
<td>0.0869</td>
<td>0.07017</td>
<td>0.1812</td>
<td>0.05667</td>
</tr>
<tr>
<th>2</th>
<td>19.69</td>
<td>21.25</td>
<td>130.00</td>
<td>1203.0</td>
<td>0.10960</td>
<td>0.15990</td>
<td>0.1974</td>
<td>0.12790</td>
<td>0.2069</td>
<td>0.05999</td>
</tr>
<tr>
<th>3</th>
<td>11.42</td>
<td>20.38</td>
<td>77.58</td>
<td>386.1</td>
<td>0.14250</td>
<td>0.28390</td>
<td>0.2414</td>
<td>0.10520</td>
<td>0.2597</td>
<td>0.09744</td>
</tr>
<tr>
<th>4</th>
<td>20.29</td>
<td>14.34</td>
<td>135.10</td>
<td>1297.0</td>
<td>0.10030</td>
<td>0.13280</td>
<td>0.1980</td>
<td>0.10430</td>
<td>0.1809</td>
<td>0.05883</td>
</tr>
</tbody>
</table>
</div>
```python
dfy = data["target"]
```
```python
dfy.shape, dfy[:100] # binary outcomes
```
((569,),
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0,
1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0,
1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0]))
## Preparing the dataset for the deconfounder
### Only one step of preprocessing needed!
### We need to get rid of the highly correlated causes
**Why** do we need to get rid of highly correlated causes?
If two causes are **highly correlated**, a valid substitute confounder will largely **inflate the variance** of causal estimates downstream.
This phenomenon is **closely related to** the variance inflation phenomenon in linear regression.
***A more technical explanation (ignorable)***
Think of the extreme case where two causes are perfectly collinear $A_1 = 5A_2$. The only random variable Z that
$$A_1 \perp A_2 | Z,$$
$(A_1, A_2)$ **must** be a **deterministic function** of Z. For example, $Z = A_1$ or $Z = A_2$.
Such a substitute confounder Z **breaks one of the conditions** the deconfounder requires. See "***A note on overlap***" in the theory section of the paper.
**How** do we get rid of highly correlated causes?
* We first make a **scatter plot** of **all pairs** of the causes.
* It reveals which causes are **highly correlated**.
* We will **exclude** these highly correlated causes by hand.
```python
sns.pairplot(df, size=1.5)
```
```python
# perimeter and area are highly correlated with radius
fea_cols = df.columns[[(not df.columns[i].endswith("perimeter")) \
and (not df.columns[i].endswith("area")) \
for i in range(df.shape[1])]]
```
```python
dfX = pd.DataFrame(df[fea_cols])
print(dfX.shape, dfy.shape)
```
(569, 8) (569,)
### How does the dataset look like after preprocessing?
```python
# The causes
dfX.head()
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>mean radius</th>
<th>mean texture</th>
<th>mean smoothness</th>
<th>mean compactness</th>
<th>mean concavity</th>
<th>mean concave points</th>
<th>mean symmetry</th>
<th>mean fractal dimension</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>17.99</td>
<td>10.38</td>
<td>0.11840</td>
<td>0.27760</td>
<td>0.3001</td>
<td>0.14710</td>
<td>0.2419</td>
<td>0.07871</td>
</tr>
<tr>
<th>1</th>
<td>20.57</td>
<td>17.77</td>
<td>0.08474</td>
<td>0.07864</td>
<td>0.0869</td>
<td>0.07017</td>
<td>0.1812</td>
<td>0.05667</td>
</tr>
<tr>
<th>2</th>
<td>19.69</td>
<td>21.25</td>
<td>0.10960</td>
<td>0.15990</td>
<td>0.1974</td>
<td>0.12790</td>
<td>0.2069</td>
<td>0.05999</td>
</tr>
<tr>
<th>3</th>
<td>11.42</td>
<td>20.38</td>
<td>0.14250</td>
<td>0.28390</td>
<td>0.2414</td>
<td>0.10520</td>
<td>0.2597</td>
<td>0.09744</td>
</tr>
<tr>
<th>4</th>
<td>20.29</td>
<td>14.34</td>
<td>0.10030</td>
<td>0.13280</td>
<td>0.1980</td>
<td>0.10430</td>
<td>0.1809</td>
<td>0.05883</td>
</tr>
</tbody>
</table>
</div>
```python
# The outcome
dfy[:25]
```
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
0, 0, 0])
# The dataset is ready. Let's do causal inference with the deconfounder!
## Step 1: Fit a factor model to the assigned causes; it leads to a substitute confounder.
### We start with trying out a random factor model. How about a probabilistic PCA model?
The matrix of assigned causes $X$
* It has N=569 rows and D=8 columns.
* N is the number of subjects/data points.
* D is the number of causes/data dimension.
### Step 1.1: Some chores first...
#### Standardize the data
This step is optional to the deconfounder.
It only makes finding a good probabilistic PCA model easier.
```python
# dfX.std()
```
```python
# standardize the data for PPCA
X = np.array((dfX - dfX.mean())/dfX.std())
```
#### Then holdout some data!
We will later need to check the factor model with some heldout data.
So let's holdout some now.
```python
# randomly holdout some entries of X
num_datapoints, data_dim = X.shape
holdout_portion = 0.2
n_holdout = int(holdout_portion * num_datapoints * data_dim)
holdout_row = np.random.randint(num_datapoints, size=n_holdout)
holdout_col = np.random.randint(data_dim, size=n_holdout)
holdout_mask = (sparse.coo_matrix((np.ones(n_holdout), \
(holdout_row, holdout_col)), \
shape = X.shape)).toarray()
holdout_subjects = np.unique(holdout_row)
holdout_mask = np.minimum(1, holdout_mask)
x_train = np.multiply(1-holdout_mask, X)
x_vad = np.multiply(holdout_mask, X)
```
### Step 1.2: We are ready to fit a probabilistic PCA model to x_train.
This step of "**fitting** a factor model" involves **inferring latent variables** in probability models.
We will rely on **Tensorflow Probability**, a library for probabilistic reasoning and statistical analysis in TensorFlow.
There are many **other probabilistic programming toolboxes** for fitting factor models, e.g. Pyro, Stan.
Some of the latent variable models can also be fit with **scikit-learn**.
We are free to use any of these with the deconfounder!
**What does a probabilistic PCA model look like?**
* Probabilistic PCA is a dimensionality reduction technique. It models data with a lower dimensional latent space.
* We consider the assigned causes of the $n$th subject. We write it as $\mathbf{x}_n$, which is a $D=8$ dimensional vector.
* The probabilistic PCA assumes the following data generating process for each $\mathbf{x}_n$, $n = 1, ..., N$:
\begin{equation*}
\mathbf{z}_{n} \stackrel{iid}{\sim} N(\mathbf{0}, \mathbf{I}_K),
\end{equation*}
\begin{equation*}
\mathbf{x}_n \mid \mathbf{z}_n
\sim N(\mathbf{z}_n\mathbf{W}, \sigma^2\mathbf{I}_D).
\end{equation*}
* We construct a $K$-dimensional substitute confounder $\mathbf{z}_{n}$ for each subject $n$, $n = 1, ..., N$.
* Each $\mathbf{z}_{n}$ is a $K$-dimensional latent vector, $n = 1, ..., N$.
```python
# we allow both linear and quadratic model
# for linear model x_n has mean z_n * W
# for quadratic model x_n has mean b + z_n * W + (z_n**2) * W_2
# quadractice model needs to change the checking step accordingly
def ppca_model(data_dim, latent_dim, num_datapoints, stddv_datapoints, mask, form="linear"):
w = ed.Normal(loc=tf.zeros([latent_dim, data_dim]),
scale=tf.ones([latent_dim, data_dim]),
name="w") # parameter
z = ed.Normal(loc=tf.zeros([num_datapoints, latent_dim]),
scale=tf.ones([num_datapoints, latent_dim]),
name="z") # local latent variable / substitute confounder
if form == "linear":
x = ed.Normal(loc=tf.multiply(tf.matmul(z, w), mask),
scale=stddv_datapoints * tf.ones([num_datapoints, data_dim]),
name="x") # (modeled) data
elif form == "quadratic":
b = ed.Normal(loc=tf.zeros([1, data_dim]),
scale=tf.ones([1, data_dim]),
name="b") # intercept
w2 = ed.Normal(loc=tf.zeros([latent_dim, data_dim]),
scale=tf.ones([latent_dim, data_dim]),
name="w2") # quadratic parameter
x = ed.Normal(loc=tf.multiply(b + tf.matmul(z, w) + tf.matmul(tf.square(z), w2), mask),
scale=stddv_datapoints * tf.ones([num_datapoints, data_dim]),
name="x") # (modeled) data
return x, (w, z)
log_joint = ed.make_log_joint_fn(ppca_model)
```
**Let's fit a probabilistic PCA model.**
```python
latent_dim = 2
stddv_datapoints = 0.1
model = ppca_model(data_dim=data_dim,
latent_dim=latent_dim,
num_datapoints=num_datapoints,
stddv_datapoints=stddv_datapoints,
mask=1-holdout_mask)
```
The cell below implements **variational inference** for probabilistic PCA in tensorflow probability.
You are free to fit the probabilistic PCA in your favourite ways with your favourite package.
Note: approximate inference is perfectly fine!
It is orthogonal to our discussion around the deconfounder.
Let's **ignore** that for now (and forever).
```python
def variational_model(qb_mean, qb_stddv, qw_mean, qw_stddv,
qw2_mean, qw2_stddv, qz_mean, qz_stddv):
qb = ed.Normal(loc=qb_mean, scale=qb_stddv, name="qb")
qw = ed.Normal(loc=qw_mean, scale=qw_stddv, name="qw")
qw2 = ed.Normal(loc=qw2_mean, scale=qw2_stddv, name="qw2")
qz = ed.Normal(loc=qz_mean, scale=qz_stddv, name="qz")
return qb, qw, qw2, qz
log_q = ed.make_log_joint_fn(variational_model)
def target(b, w, w2, z):
"""Unnormalized target density as a function of the parameters."""
return log_joint(data_dim=data_dim,
latent_dim=latent_dim,
num_datapoints=num_datapoints,
stddv_datapoints=stddv_datapoints,
mask=1-holdout_mask,
w=w, z=z, w2=w2, b=b, x=x_train)
def target_q(qb, qw, qw2, qz):
return log_q(qb_mean=qb_mean, qb_stddv=qb_stddv,
qw_mean=qw_mean, qw_stddv=qw_stddv,
qw2_mean=qw2_mean, qw2_stddv=qw2_stddv,
qz_mean=qz_mean, qz_stddv=qz_stddv,
qw=qw, qz=qz, qw2=qw2, qb=qb)
qb_mean = tf.Variable(np.ones([1, data_dim]), dtype=tf.float32)
qw_mean = tf.Variable(np.ones([latent_dim, data_dim]), dtype=tf.float32)
qw2_mean = tf.Variable(np.ones([latent_dim, data_dim]), dtype=tf.float32)
qz_mean = tf.Variable(np.ones([num_datapoints, latent_dim]), dtype=tf.float32)
qb_stddv = tf.nn.softplus(tf.Variable(0 * np.ones([1, data_dim]), dtype=tf.float32))
qw_stddv = tf.nn.softplus(tf.Variable(-4 * np.ones([latent_dim, data_dim]), dtype=tf.float32))
qw2_stddv = tf.nn.softplus(tf.Variable(-4 * np.ones([latent_dim, data_dim]), dtype=tf.float32))
qz_stddv = tf.nn.softplus(tf.Variable(-4 * np.ones([num_datapoints, latent_dim]), dtype=tf.float32))
qb, qw, qw2, qz = variational_model(qb_mean=qb_mean, qb_stddv=qb_stddv,
qw_mean=qw_mean, qw_stddv=qw_stddv,
qw2_mean=qw2_mean, qw2_stddv=qw2_stddv,
qz_mean=qz_mean, qz_stddv=qz_stddv)
energy = target(qb, qw, qw2, qz)
entropy = -target_q(qb, qw, qw2, qz)
elbo = energy + entropy
optimizer = tf.train.AdamOptimizer(learning_rate = 0.05)
train = optimizer.minimize(-elbo)
init = tf.global_variables_initializer()
t = []
num_epochs = 500
with tf.Session() as sess:
sess.run(init)
for i in range(num_epochs):
sess.run(train)
if i % 5 == 0:
t.append(sess.run([elbo]))
b_mean_inferred = sess.run(qb_mean)
b_stddv_inferred = sess.run(qb_stddv)
w_mean_inferred = sess.run(qw_mean)
w_stddv_inferred = sess.run(qw_stddv)
w2_mean_inferred = sess.run(qw2_mean)
w2_stddv_inferred = sess.run(qw2_stddv)
z_mean_inferred = sess.run(qz_mean)
z_stddv_inferred = sess.run(qz_stddv)
print("Inferred axes:")
print(w_mean_inferred)
print("Standard Deviation:")
print(w_stddv_inferred)
plt.plot(range(1, num_epochs, 5), t)
plt.show()
def replace_latents(b, w, w2, z):
def interceptor(rv_constructor, *rv_args, **rv_kwargs):
"""Replaces the priors with actual values to generate samples from."""
name = rv_kwargs.pop("name")
if name == "b":
rv_kwargs["value"] = b
elif name == "w":
rv_kwargs["value"] = w
elif name == "w":
rv_kwargs["value"] = w2
elif name == "z":
rv_kwargs["value"] = z
return rv_constructor(*rv_args, **rv_kwargs)
return interceptor
```
So we just played some **magic** to **fit the probabilistic PCA** to the matrix of assigned causes $\mathbf{X}$.
**The only important thing here is: **
We have **inferred** the latent variables $\mathbf{z}_n, n=1, ..., N$ and the parameters $\mathbf{W}$.
Specifically, we have obtained from this step
```
w_mean_inferred,
w_stddv_inferred,
z_mean_inferred,
z_stddv_inferred.
```
## Step 2: Check the factor model with a predictive check.
Now we are ready to **check** the probabilistic PCA model.
The checking step is **very important** to the deconfounder.
Pleeeeeze **always** check the factor model!
**How** do we perform the predictive check?
1. We will **generate** some replicated datasets for the heldout entries.
2. And then **compare** the replicated datasets with the original dataset on the heldout entries.
3. If they **look similar**, then we are good to go.
#### Step 2.1: We generate some replicated datasets first.
* We will start with generating some **replicated datasets** from the predictive distribution of the assigned causes $X$:
\begin{align}
p(\mathbf{X^{rep}_{n,heldout}} \,|\, \mathbf{X_{n, obs}}) =
\int p(\mathbf{X_{n, heldout}} \,|\, \mathbf{z}_n) p(\mathbf{z_n} \,|\, \mathbf{X}_{n, obs}) \mathrm{d} \mathbf{z_n}.
\end{align}
* That is, we generate these datasets from a probabilistic PCA model given the **inferred** latent variables $\hat{p}(\mathbf{z}_n)$ and $\hat{p}(\mathbf{W})$:
\begin{equation*}
\mathbf{z}_{n} \sim \hat{p}(\mathbf{z}_n),
\end{equation*}
\begin{equation*}
\mathbf{W} \sim \hat{p}(\mathbf{W}),
\end{equation*}
\begin{equation*}
\mathbf{x}_n \mid \mathbf{z}_n
\sim N(\mathbf{z}_n\mathbf{W}, \sigma^2\mathbf{I}_D).
\end{equation*}
* These replicated datasets tell us what the assigned causes $X$ **should look like** if it is indeed generated by the fitted probabilistic PCA model.
```python
n_rep = 100 # number of replicated datasets we generate
holdout_gen = np.zeros((n_rep,*(x_train.shape)))
for i in range(n_rep):
b_sample = npr.normal(b_mean_inferred, b_stddv_inferred)
w_sample = npr.normal(w_mean_inferred, w_stddv_inferred)
w2_sample = npr.normal(w2_mean_inferred, w2_stddv_inferred)
z_sample = npr.normal(z_mean_inferred, z_stddv_inferred)
with ed.interception(replace_latents(b_sample, w_sample, w2_sample, z_sample)):
generate = ppca_model(
data_dim=data_dim, latent_dim=latent_dim,
num_datapoints=num_datapoints, stddv_datapoints=stddv_datapoints,
mask=np.ones(x_train.shape))
with tf.Session() as sess:
x_generated, _ = sess.run(generate)
# look only at the heldout entries
holdout_gen[i] = np.multiply(x_generated, holdout_mask)
```
#### Step 2.2: Then we compute the test statistic on both the original and the replicated dataset.
* We use the **test statistic** of **expected heldout log likelihood**:
\begin{align}
t(\mathbf{X_{n,heldout}}) = \mathbb{E}_{\mathbf{Z}, \mathbf{W}}[{\log p(\mathbf{X_{n,heldout}} \,|\, \mathbf{Z}, \mathbf{W}) \,|\,
\mathbf{X_{n,obs}}}].
\end{align}
* We calculate this test statistic **for each $n$** and for **both** the **original** dataset $\mathbf{X_{n,heldout}}$ and the **replicated** dataset $\mathbf{X^{rep}_{n,heldout}}$.
```python
n_eval = 100 # we draw samples from the inferred Z and W
obs_ll = []
rep_ll = []
for j in range(n_eval):
w_sample = npr.normal(w_mean_inferred, w_stddv_inferred)
z_sample = npr.normal(z_mean_inferred, z_stddv_inferred)
holdoutmean_sample = np.multiply(z_sample.dot(w_sample), holdout_mask)
obs_ll.append(np.mean(stats.norm(holdoutmean_sample, \
stddv_datapoints).logpdf(x_vad), axis=1))
rep_ll.append(np.mean(stats.norm(holdoutmean_sample, \
stddv_datapoints).logpdf(holdout_gen),axis=2))
obs_ll_per_zi, rep_ll_per_zi = np.mean(np.array(obs_ll), axis=0), np.mean(np.array(rep_ll), axis=0)
```
#### Step 2.3: Finally we compare the test statistic of the original and the replicated dataset.
* We compare the test statistics via the $p$-values.
\begin{equation*}
\text{$p$-value} = p\left(t(\mathbf{X_{n,heldout}^{rep}}) < t(\mathbf{X_{n, heldout}})\right).
\end{equation*}
* The **smaller** the $p$-value is, the **more different** the original dataset is from the replicated dataset.
* We **fail** the check if the $p$-value is **small**.
* Note this goes in the opposite direction to the conventional usage of $p$-values.
We compute a $p$-value for each $n$ and output the average $p$-values.
```python
pvals = np.array([np.mean(rep_ll_per_zi[:,i] < obs_ll_per_zi[i]) for i in range(num_datapoints)])
holdout_subjects = np.unique(holdout_row)
overall_pval = np.mean(pvals[holdout_subjects])
print("Predictive check p-values", overall_pval)
```
Predictive check p-values 0.10207589285714287
**We passed the check!**
The substitute confounder $\mathbf{z}_n$ constructed in Step 1 is valid. We are ready to move on!
#### An optional step
We can also peak at **the predictive check of individual subjects**.
This step is just for fun. It is how we generate Figure 2 of the paper.
* We randomly choose a subject.
* Plot the kernel density estimate of the test statistic on the replicated datasets.
* Plot the test statistic on the original dataset (the dashed vertical line).
```python
subject_no = npr.choice(holdout_subjects)
sns.kdeplot(rep_ll_per_zi[:,subject_no]).set_title("Predictive check for subject "+str(subject_no))
plt.axvline(x=obs_ll_per_zi[subject_no], linestyle='--')
```
## Step 3: Correct for the substitute confounder in a causal inference.
**How** to estimate causal effects?
* For simplicity, we fit a logistic regression as an outcome model here.
* The target is the observed outcome $y_n$, $n=1,\ldots, N$.
* The regressor is the multiple causes $\mathbf{X}_n$, $n=1,\ldots, N$.
**How** to correct for the substitute confounder?
* We include the substitute confounder $\mathbf{Z}_n$, $n=1,\ldots, N$, into the regressors.
```python
# approximate the (random variable) substitute confounders with their inferred mean.
Z_hat = z_mean_inferred
# augment the regressors to be both the assigned causes X and the substitute confounder Z
X_aug = np.column_stack([X, Z_hat])
```
```python
# holdout some data from prediction later
X_train, X_test, y_train, y_test = train_test_split(X_aug, dfy, test_size=0.2, random_state=0)
```
```python
dcfX_train = sm.add_constant(X_train)
dcflogit_model = sm.Logit(y_train, dcfX_train)
dcfresult = dcflogit_model.fit_regularized(maxiter=5000)
print(dcfresult.summary())
```
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.13286976182886223
Iterations: 85
Function evaluations: 85
Gradient evaluations: 85
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 444
Method: MLE Df Model: 10
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7971
Time: 23:28:08 Log-Likelihood: -60.456
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 9.348e-96
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7997 0.260 3.074 0.002 0.290 1.309
x1 -2.9778 0.964 -3.088 0.002 -4.868 -1.088
x2 -1.4487 0.381 -3.804 0.000 -2.195 -0.702
x3 -1.4633 0.744 -1.968 0.049 -2.921 -0.006
x4 0.3681 0.872 0.422 0.673 -1.342 2.078
x5 -1.1352 0.900 -1.261 0.207 -2.900 0.630
x6 -1.6511 1.240 -1.332 0.183 -4.081 0.779
x7 -0.5368 0.506 -1.060 0.289 -1.530 0.456
x8 0.4164 0.765 0.544 0.586 -1.083 1.916
x9 0.3544 1.734 0.204 0.838 -3.044 3.753
x10 -1.0729 1.360 -0.789 0.430 -3.739 1.593
==============================================================================
Possibly complete quasi-separation: A fraction 0.17 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
```python
res = pd.DataFrame({"causal_mean": dcfresult.params[:data_dim+1], \
"causal_std": dcfresult.bse[:data_dim+1], \
"causal_025": dcfresult.conf_int()[:data_dim+1,0], \
"causal_975": dcfresult.conf_int()[:data_dim+1,1], \
"causal_pval": dcfresult.pvalues[:data_dim+1]})
res["causal_sig"] = (res["causal_pval"] < 0.05)
res = res.T
res.columns = np.concatenate([["intercept"], np.array(dfX.columns)])
res = res.T
```
```python
res
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>causal_mean</th>
<th>causal_std</th>
<th>causal_025</th>
<th>causal_975</th>
<th>causal_pval</th>
<th>causal_sig</th>
</tr>
</thead>
<tbody>
<tr>
<th>intercept</th>
<td>0.799657</td>
<td>0.260116</td>
<td>0.289839</td>
<td>1.30947</td>
<td>0.00211043</td>
<td>True</td>
</tr>
<tr>
<th>mean radius</th>
<td>-2.97783</td>
<td>0.964373</td>
<td>-4.86796</td>
<td>-1.08769</td>
<td>0.0020162</td>
<td>True</td>
</tr>
<tr>
<th>mean texture</th>
<td>-1.44867</td>
<td>0.380799</td>
<td>-2.19502</td>
<td>-0.702313</td>
<td>0.000142218</td>
<td>True</td>
</tr>
<tr>
<th>mean smoothness</th>
<td>-1.46326</td>
<td>0.743651</td>
<td>-2.92079</td>
<td>-0.00573425</td>
<td>0.0491055</td>
<td>True</td>
</tr>
<tr>
<th>mean compactness</th>
<td>0.368069</td>
<td>0.87232</td>
<td>-1.34165</td>
<td>2.07778</td>
<td>0.673067</td>
<td>False</td>
</tr>
<tr>
<th>mean concavity</th>
<td>-1.13524</td>
<td>0.90044</td>
<td>-2.90007</td>
<td>0.629588</td>
<td>0.207394</td>
<td>False</td>
</tr>
<tr>
<th>mean concave points</th>
<td>-1.65108</td>
<td>1.23964</td>
<td>-4.08072</td>
<td>0.778573</td>
<td>0.182893</td>
<td>False</td>
</tr>
<tr>
<th>mean symmetry</th>
<td>-0.536826</td>
<td>0.506479</td>
<td>-1.52951</td>
<td>0.455855</td>
<td>0.289182</td>
<td>False</td>
</tr>
<tr>
<th>mean fractal dimension</th>
<td>0.416358</td>
<td>0.765082</td>
<td>-1.08318</td>
<td>1.91589</td>
<td>0.586304</td>
<td>False</td>
</tr>
</tbody>
</table>
</div>
We check the predictions to see if the logistic outcome model is a good outcome model.
```python
# make predictions with the causal model
dcfX_test = X_test
dcfy_predprob = dcfresult.predict(sm.add_constant(dcfX_test))
dcfy_pred = (dcfy_predprob > 0.5)
print(classification_report(y_test, dcfy_pred))
```
precision recall f1-score support
0 0.96 0.91 0.93 47
1 0.94 0.97 0.96 67
accuracy 0.95 114
macro avg 0.95 0.94 0.95 114
weighted avg 0.95 0.95 0.95 114
# We are done!
We have computed the average causal effect of raising the causes by one unit (see the "causal mean" column above).
# Is the deconfounder worth the effort?
We finally compare the **causal** estimation (with the deconfounder) with the **noncausal** estimation (with vanilla regression).
## The classical logistic regression! Note it is noncausal :-(
```python
# regress the outcome against the causes only (no substitute confounders)
nodcfX_train = sm.add_constant(X_train[:,:X.shape[1]])
nodcflogit_model = sm.Logit(y_train, nodcfX_train)
nodcfresult = nodcflogit_model.fit_regularized(maxiter=5000)
print(nodcfresult.summary())
```
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.13451539390572878
Iterations: 71
Function evaluations: 71
Gradient evaluations: 71
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 446
Method: MLE Df Model: 8
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7946
Time: 23:28:08 Log-Likelihood: -61.205
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 3.283e-97
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7632 0.255 2.998 0.003 0.264 1.262
x1 -3.2642 0.904 -3.611 0.000 -5.036 -1.492
x2 -1.7189 0.307 -5.602 0.000 -2.320 -1.117
x3 -1.2257 0.498 -2.462 0.014 -2.202 -0.250
x4 0.3115 0.741 0.420 0.674 -1.142 1.765
x5 -1.1317 0.717 -1.578 0.115 -2.538 0.274
x6 -2.0079 1.172 -1.714 0.087 -4.304 0.289
x7 -0.5413 0.324 -1.673 0.094 -1.176 0.093
x8 0.5775 0.677 0.853 0.394 -0.750 1.905
==============================================================================
Possibly complete quasi-separation: A fraction 0.15 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
```python
res["noncausal_mean"] = np.array(nodcfresult.params)
res["noncausal_std"] = np.array(nodcfresult.bse)
res["noncausal_025"] = np.array(nodcfresult.conf_int()[:,0])
res["noncausal_975"] = np.array(nodcfresult.conf_int()[:,1])
res["noncausal_pval"] = np.array(nodcfresult.pvalues)
res["noncausal_sig"] = (res["noncausal_pval"] < 0.05)
```
```python
res["diff"] = res["causal_mean"] - res["noncausal_mean"]
res["pval_diff"] = res["causal_pval"] - res["noncausal_pval"]
```
```python
nodcfX_test = sm.add_constant(X_test[:,:X.shape[1]])
nodcfy_predprob = nodcfresult.predict(nodcfX_test)
nodcfy_pred = (nodcfy_predprob > 0.5)
```
**Causal models do not hurt predictions here!**
```python
dcflogit_roc_auc = roc_auc_score(y_test, dcfy_pred)
dcffpr, dcftpr, dcfthresholds = roc_curve(y_test, dcfy_predprob)
nodcflogit_roc_auc = roc_auc_score(y_test, nodcfy_pred)
nodcffpr, nodcftpr, nodcfthresholds = roc_curve(y_test, nodcfy_predprob)
plt.figure()
plt.plot(nodcffpr, nodcftpr, label='Noncausal Logistic Regression (area = %0.9f)' % nodcflogit_roc_auc)
plt.plot(dcffpr, dcftpr, label='Causal Logistic Regression (area = %0.9f)' % dcflogit_roc_auc)
plt.plot([0, 1], [0, 1],'r--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic')
plt.legend(loc="lower right")
plt.savefig('Log_ROC')
plt.show()
```
**But causal models do change the regression coefficients and which features are significant.**
* The mean smoothness is a feature **significantly correlated** with the cancer diagnosis.
* But it does **not significantly** **causally affect** the cancer diagnosis.
* The effect of all features are **over-estimated** with the noncausal model except the "mean compactness".
```python
res.sort_values("pval_diff", ascending=True)[["pval_diff", "causal_pval", "noncausal_pval", "causal_sig", "noncausal_sig", "causal_mean", "noncausal_mean"]]
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>pval_diff</th>
<th>causal_pval</th>
<th>noncausal_pval</th>
<th>causal_sig</th>
<th>noncausal_sig</th>
<th>causal_mean</th>
<th>noncausal_mean</th>
</tr>
</thead>
<tbody>
<tr>
<th>mean compactness</th>
<td>-0.00130945</td>
<td>0.673067</td>
<td>6.743764e-01</td>
<td>False</td>
<td>False</td>
<td>0.368069</td>
<td>0.311494</td>
</tr>
<tr>
<th>intercept</th>
<td>-0.00060616</td>
<td>0.00211043</td>
<td>2.716595e-03</td>
<td>True</td>
<td>True</td>
<td>0.799657</td>
<td>0.763172</td>
</tr>
<tr>
<th>mean texture</th>
<td>0.000142197</td>
<td>0.000142218</td>
<td>2.123746e-08</td>
<td>True</td>
<td>True</td>
<td>-1.44867</td>
<td>-1.718860</td>
</tr>
<tr>
<th>mean radius</th>
<td>0.00171102</td>
<td>0.0020162</td>
<td>3.051830e-04</td>
<td>True</td>
<td>True</td>
<td>-2.97783</td>
<td>-3.264181</td>
</tr>
<tr>
<th>mean smoothness</th>
<td>0.0352701</td>
<td>0.0491055</td>
<td>1.383540e-02</td>
<td>True</td>
<td>True</td>
<td>-1.46326</td>
<td>-1.225668</td>
</tr>
<tr>
<th>mean concavity</th>
<td>0.0927253</td>
<td>0.207394</td>
<td>1.146687e-01</td>
<td>False</td>
<td>False</td>
<td>-1.13524</td>
<td>-1.131677</td>
</tr>
<tr>
<th>mean concave points</th>
<td>0.0963094</td>
<td>0.182893</td>
<td>8.658376e-02</td>
<td>False</td>
<td>False</td>
<td>-1.65108</td>
<td>-2.007921</td>
</tr>
<tr>
<th>mean fractal dimension</th>
<td>0.192521</td>
<td>0.586304</td>
<td>3.937831e-01</td>
<td>False</td>
<td>False</td>
<td>0.416358</td>
<td>0.577489</td>
</tr>
<tr>
<th>mean symmetry</th>
<td>0.194775</td>
<td>0.289182</td>
<td>9.440683e-02</td>
<td>False</td>
<td>False</td>
<td>-0.536826</td>
<td>-0.541292</td>
</tr>
</tbody>
</table>
</div>
* We include causes into the regression **one-by-one**.
* The deconfounder coefficients **does not** flip signs.
* But classical logistic regression coefficients **does** flip signs.
* This suggests that **the deconfounder is causal**.
* It is because **causal** coefficients **do not change** as we include more variables into the system; causal estimation already controls for confounders so that it is causal.
* However, **correlation** coefficients **can change** as we include more variables into the system; if the added variable is a confounder, than the regression coefficients change to account for the confounding effects.
```python
# The deconfounder with causes added one-by-one
# The first i coefficient is the causal coefficient of the first i causes.
# i = 1, ..., 8.
for i in range(X.shape[1]):
print(i, "causes included")
# augment the regressors to be both the assigned causes X and the substitute confounder Z
X_aug = np.column_stack([X[:,:i], Z_hat])
# holdout some data from prediction later
X_train, X_test, y_train, y_test = train_test_split(X_aug, dfy, test_size=0.2, random_state=0)
dcfX_train = sm.add_constant(X_train)
dcflogit_model = sm.Logit(y_train, dcfX_train)
dcfresult = dcflogit_model.fit_regularized(maxiter=5000)
print(dcfresult.summary())
```
0 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.18480230713099138
Iterations: 22
Function evaluations: 22
Gradient evaluations: 22
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 452
Method: MLE Df Model: 2
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7178
Time: 23:28:09 Log-Likelihood: -84.085
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 1.267e-93
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.9124 0.206 4.436 0.000 0.509 1.315
x1 -0.7687 0.211 -3.643 0.000 -1.182 -0.355
x2 -5.0965 0.543 -9.394 0.000 -6.160 -4.033
==============================================================================
1 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.1627111817680479
Iterations: 30
Function evaluations: 30
Gradient evaluations: 30
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 451
Method: MLE Df Model: 3
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7516
Time: 23:28:09 Log-Likelihood: -74.034
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 9.246e-97
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7397 0.217 3.410 0.001 0.315 1.165
x1 -2.1235 0.513 -4.143 0.000 -3.128 -1.119
x2 -1.2129 0.253 -4.800 0.000 -1.708 -0.718
x3 -3.8954 0.621 -6.276 0.000 -5.112 -2.679
==============================================================================
2 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.15261356019021724
Iterations: 37
Function evaluations: 37
Gradient evaluations: 37
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 450
Method: MLE Df Model: 4
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7670
Time: 23:28:09 Log-Likelihood: -69.439
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 1.268e-97
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7502 0.227 3.309 0.001 0.306 1.195
x1 -3.3034 0.701 -4.710 0.000 -4.678 -1.929
x2 -1.0262 0.344 -2.985 0.003 -1.700 -0.352
x3 -1.7916 0.355 -5.040 0.000 -2.488 -1.095
x4 -2.4318 0.785 -3.097 0.002 -3.971 -0.893
==============================================================================
Possibly complete quasi-separation: A fraction 0.10 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
3 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.14196497629747212
Iterations: 44
Function evaluations: 44
Gradient evaluations: 44
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 449
Method: MLE Df Model: 5
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7832
Time: 23:28:09 Log-Likelihood: -64.594
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 1.173e-98
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.9137 0.247 3.700 0.000 0.430 1.398
x1 -3.4320 0.752 -4.564 0.000 -4.906 -1.958
x2 -1.1337 0.363 -3.119 0.002 -1.846 -0.421
x3 -1.3748 0.462 -2.976 0.003 -2.280 -0.469
x4 -0.7584 0.495 -1.533 0.125 -1.728 0.211
x5 -2.6149 0.804 -3.251 0.001 -4.191 -1.039
==============================================================================
Possibly complete quasi-separation: A fraction 0.15 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
4 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.1402052748348448
Iterations: 57
Function evaluations: 57
Gradient evaluations: 57
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 448
Method: MLE Df Model: 6
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7859
Time: 23:28:09 Log-Likelihood: -63.793
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 5.396e-98
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.8689 0.248 3.504 0.000 0.383 1.355
x1 -3.4797 0.755 -4.608 0.000 -4.960 -2.000
x2 -1.1444 0.363 -3.153 0.002 -1.856 -0.433
x3 -1.1184 0.466 -2.399 0.016 -2.032 -0.205
x4 0.9297 0.722 1.288 0.198 -0.485 2.345
x5 -1.6538 0.827 -2.000 0.045 -3.274 -0.033
x6 -3.1811 0.932 -3.413 0.001 -5.008 -1.354
==============================================================================
Possibly complete quasi-separation: A fraction 0.15 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
5 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.13737900142942064
Iterations: 60
Function evaluations: 60
Gradient evaluations: 60
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 447
Method: MLE Df Model: 7
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7902
Time: 23:28:09 Log-Likelihood: -62.507
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 1.395e-97
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.8515 0.251 3.393 0.001 0.360 1.343
x1 -3.7237 0.770 -4.836 0.000 -5.233 -2.215
x2 -1.2666 0.367 -3.451 0.001 -1.986 -0.547
x3 -1.7016 0.617 -2.756 0.006 -2.912 -0.492
x4 0.8248 0.694 1.189 0.235 -0.535 2.185
x5 -1.1228 0.704 -1.594 0.111 -2.503 0.257
x6 -0.5378 1.062 -0.506 0.613 -2.620 1.544
x7 -2.2185 1.087 -2.041 0.041 -4.349 -0.088
==============================================================================
Possibly complete quasi-separation: A fraction 0.18 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
6 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.13516533343345713
Iterations: 71
Function evaluations: 71
Gradient evaluations: 71
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 446
Method: MLE Df Model: 8
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7936
Time: 23:28:09 Log-Likelihood: -61.500
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 4.396e-97
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7814 0.256 3.049 0.002 0.279 1.284
x1 -3.1186 0.854 -3.652 0.000 -4.792 -1.445
x2 -1.3462 0.367 -3.664 0.000 -2.066 -0.626
x3 -1.1913 0.691 -1.724 0.085 -2.546 0.163
x4 1.0127 0.716 1.415 0.157 -0.390 2.415
x5 -0.5867 0.792 -0.741 0.459 -2.139 0.966
x6 -1.6608 1.187 -1.399 0.162 -3.987 0.665
x7 -0.6526 1.062 -0.615 0.539 -2.734 1.428
x8 -1.8720 1.099 -1.703 0.089 -4.026 0.282
==============================================================================
Possibly complete quasi-separation: A fraction 0.16 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
7 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.1331994800829468
Iterations: 77
Function evaluations: 77
Gradient evaluations: 77
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 445
Method: MLE Df Model: 9
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7966
Time: 23:28:09 Log-Likelihood: -60.606
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 1.448e-96
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7813 0.258 3.033 0.002 0.276 1.286
x1 -3.2282 0.861 -3.748 0.000 -4.916 -1.540
x2 -1.4509 0.382 -3.798 0.000 -2.200 -0.702
x3 -1.5318 0.738 -2.075 0.038 -2.978 -0.085
x4 0.5140 0.829 0.620 0.535 -1.111 2.139
x5 -1.0940 0.894 -1.224 0.221 -2.846 0.658
x6 -1.8328 1.201 -1.527 0.127 -4.186 0.520
x7 -0.6254 0.483 -1.294 0.196 -1.572 0.322
x8 0.7810 1.558 0.501 0.616 -2.273 3.835
x9 -0.8963 1.326 -0.676 0.499 -3.496 1.703
==============================================================================
Possibly complete quasi-separation: A fraction 0.17 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
```python
# Logistic regression with causes added one-by-one
# The first i coefficient is the causal coefficient of the first i causes.
# i = 1, ..., 8.
for i in range(X.shape[1]):
print(i, "causes included")
# augment the regressors to be both the assigned causes X and the substitute confounder Z
X_aug = np.column_stack([X[:,:i]])
# holdout some data from prediction later
X_train, X_test, y_train, y_test = train_test_split(X_aug, dfy, test_size=0.2, random_state=0)
dcfX_train = sm.add_constant(X_train)
dcflogit_model = sm.Logit(y_train, dcfX_train)
dcfresult = dcflogit_model.fit_regularized(maxiter=5000)
print(dcfresult.summary())
```
0 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.6549205599225008
Iterations: 6
Function evaluations: 6
Gradient evaluations: 6
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 454
Method: MLE Df Model: 0
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 7.357e-13
Time: 23:28:09 Log-Likelihood: -297.99
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: nan
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.5639 0.098 5.783 0.000 0.373 0.755
==============================================================================
1 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.2953829271568602
Iterations: 15
Function evaluations: 15
Gradient evaluations: 15
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 453
Method: MLE Df Model: 1
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.5490
Time: 23:28:09 Log-Likelihood: -134.40
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 3.955e-73
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.6566 0.155 4.225 0.000 0.352 0.961
x1 -3.5061 0.353 -9.934 0.000 -4.198 -2.814
==============================================================================
2 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.2592096971350075
Iterations: 20
Function evaluations: 20
Gradient evaluations: 20
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 452
Method: MLE Df Model: 2
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.6042
Time: 23:28:09 Log-Likelihood: -117.94
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 6.397e-79
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.6744 0.168 4.018 0.000 0.345 1.003
x1 -3.6479 0.390 -9.347 0.000 -4.413 -2.883
x2 -0.9815 0.181 -5.424 0.000 -1.336 -0.627
==============================================================================
3 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.162465976738943
Iterations: 28
Function evaluations: 29
Gradient evaluations: 28
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 451
Method: MLE Df Model: 3
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7519
Time: 23:28:09 Log-Likelihood: -73.922
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 8.272e-97
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.9963 0.231 4.306 0.000 0.543 1.450
x1 -4.9102 0.601 -8.170 0.000 -6.088 -3.732
x2 -1.7394 0.284 -6.115 0.000 -2.297 -1.182
x3 -2.2080 0.336 -6.578 0.000 -2.866 -1.550
==============================================================================
Possibly complete quasi-separation: A fraction 0.12 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
4 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.15485253636195323
Iterations: 35
Function evaluations: 35
Gradient evaluations: 35
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 450
Method: MLE Df Model: 4
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7636
Time: 23:28:10 Log-Likelihood: -70.458
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 3.495e-97
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.9646 0.233 4.146 0.000 0.509 1.421
x1 -4.6125 0.614 -7.509 0.000 -5.816 -3.409
x2 -1.6563 0.295 -5.610 0.000 -2.235 -1.078
x3 -1.7342 0.372 -4.667 0.000 -2.463 -1.006
x4 -0.9279 0.353 -2.631 0.009 -1.619 -0.237
==============================================================================
Possibly complete quasi-separation: A fraction 0.13 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
5 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.14242454080229494
Iterations: 44
Function evaluations: 45
Gradient evaluations: 44
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 449
Method: MLE Df Model: 5
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7825
Time: 23:28:10 Log-Likelihood: -64.803
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 1.444e-98
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.8234 0.242 3.396 0.001 0.348 1.299
x1 -4.6125 0.636 -7.252 0.000 -5.859 -3.366
x2 -1.7131 0.303 -5.648 0.000 -2.308 -1.119
x3 -1.9515 0.395 -4.941 0.000 -2.726 -1.177
x4 0.4077 0.512 0.797 0.425 -0.595 1.410
x5 -1.7514 0.464 -3.777 0.000 -2.660 -0.843
==============================================================================
Possibly complete quasi-separation: A fraction 0.16 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
6 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.13837349335376822
Iterations: 60
Function evaluations: 60
Gradient evaluations: 60
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 448
Method: MLE Df Model: 6
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7887
Time: 23:28:10 Log-Likelihood: -62.960
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 2.361e-98
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7376 0.248 2.975 0.003 0.252 1.223
x1 -3.5398 0.807 -4.384 0.000 -5.122 -1.957
x2 -1.6821 0.302 -5.563 0.000 -2.275 -1.089
x3 -1.3522 0.491 -2.756 0.006 -2.314 -0.391
x4 0.6207 0.527 1.177 0.239 -0.413 1.655
x5 -1.0073 0.623 -1.617 0.106 -2.228 0.214
x6 -2.1317 1.138 -1.873 0.061 -4.362 0.098
==============================================================================
Possibly complete quasi-separation: A fraction 0.14 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
7 causes included
Optimization terminated successfully. (Exit mode 0)
Current function value: 0.135339334890979
Iterations: 62
Function evaluations: 62
Gradient evaluations: 62
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 455
Model: Logit Df Residuals: 447
Method: MLE Df Model: 7
Date: Fri, 03 Apr 2020 Pseudo R-squ.: 0.7933
Time: 23:28:10 Log-Likelihood: -61.579
converged: True LL-Null: -297.99
Covariance Type: nonrobust LLR p-value: 5.570e-98
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 0.7287 0.250 2.916 0.004 0.239 1.219
x1 -3.6556 0.796 -4.592 0.000 -5.216 -2.095
x2 -1.7323 0.307 -5.644 0.000 -2.334 -1.131
x3 -1.1122 0.483 -2.304 0.021 -2.058 -0.166
x4 0.7408 0.542 1.367 0.172 -0.321 1.803
x5 -0.8364 0.614 -1.363 0.173 -2.039 0.366
x6 -2.2682 1.139 -1.992 0.046 -4.500 -0.037
x7 -0.5397 0.324 -1.666 0.096 -1.175 0.095
==============================================================================
Possibly complete quasi-separation: A fraction 0.15 of observations can be
perfectly predicted. This might indicate that there is complete
quasi-separation. In this case some parameters will not be identified.
**We note that the causal coefficient of x4 is stable with the (causal) deconfounder but the correlation coefficent of x4 flips sign with the (noncausal) logistic regression.**
# Takeaways
* The deconfounder is **not hard** to use.
* We simply **fit** a factor model, **check** it, and **infer** causal effects with the substitute confounder.
* Please **always check** the factor model.
* The deconfounder **makes a difference**.
* The deconfounder **deconfounds**.
# Acknowledgements
We thank Suresh Naidu for suggesting the adding-causes-one-by-one idea.
|
------------------------------------------------------------------------
-- Universe levels
------------------------------------------------------------------------
module Common.Level where
postulate
Level : Set
lzero : Level
lsuc : (i : Level) → Level
_⊔_ : Level -> Level -> Level
{-# IMPORT Common.FFI #-}
{-# COMPILED_TYPE Level Common.FFI.Level #-}
{-# COMPILED lzero Common.FFI.Zero #-}
{-# COMPILED lsuc Common.FFI.Suc #-}
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO lzero #-}
{-# BUILTIN LEVELSUC lsuc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
infixl 6 _⊔_
|
Require Import Coq.Program.Basics.
Require Import Tactics Algebra.Utils SetoidUtils Algebra.SetoidCat Algebra.SetoidCat.ListUtils Algebra.Monad Algebra.SetoidCat.PairUtils Algebra.SetoidCat.MaybeUtils Algebra.Monad.Maybe QAL.Definitions QAL.Command QAL.AbstractHeap QAL.AbstractStore.
Require Import FMapWeakList Coq.Lists.List RelationClasses Relation_Definitions Morphisms SetoidClass.
Section Assert.
Context
{builtin : Type}.
Inductive assertion :=
| emp : assertion
| primitive : builtin -> assertion
| sepConj : assertion -> assertion -> assertion
| sepImp : assertion -> assertion -> assertion
| atrue : assertion
| aAnd : assertion -> assertion -> assertion
| aNot : assertion -> assertion
| aExists : var -> assertion -> assertion
.
Program Instance assertionS : Setoid assertion.
End Assert.
Notation "a ∧ b" := (aAnd a b) (left associativity, at level 81).
Notation "¬ a" := (aNot a) (at level 80).
(* Notation "[[ addr , p ]] ⟼ val" := (singleton addr p val) (at level 79). *)
Notation "a ∗ b" := (sepConj a b) (left associativity, at level 83).
Notation "a -∗ b" := (sepImp a b) (right associativity, at level 84).
Notation "∃ v , a" := (aExists v a) (at level 85).
Notation "⊤" := (atrue) (at level 85).
Module Type PrimitiveAssertion (PT : PredType) (VT : ValType) (S : AbstractStore VT) (H : AbstractHeap PT VT).
Parameter primitiveAssertion : Type.
Parameter primitiveAssertionS : Setoid primitiveAssertion.
Parameter interpretPrimitiveAssertion : primitiveAssertionS ~> S.tS ~~> H.tS ~~> iff_setoid.
End PrimitiveAssertion.
Module AssertModel (PT : PredType) (VT : ValType) (S : AbstractStore VT) (H : AbstractHeap PT VT) (PA: PrimitiveAssertion PT VT S H).
Import S H PA.
Definition assertion := @assertion primitiveAssertion.
Instance assertionS : Setoid assertion := @assertionS primitiveAssertion.
Fixpoint _models (a : assertion) (s : S.t) (h : H.t) {struct a} : Prop :=
match a with
| emp => isEmpty @ h
| primitive pa => interpretPrimitiveAssertion @ pa @ s @ h
| a0 ∗ a1 => exists h0 h1,
h0 ⊥ h1 /\ h0 ⋅ h1 == h /\ _models a0 s h0 /\ _models a1 s h1
| a0 -∗ a1 => forall h',
h ⊥ h' -> _models a0 s h' -> _models a1 s (h ⋅ h')
| ¬ a => ~ _models a s h
| a0 ∧ a1 => _models a0 s h /\ _models a1 s h
| ⊤ => True
| ∃ v, a => exists val, _models a (S.update @ v @ val @ s) h
end.
Definition models : assertionS ~> S.tS ~~> H.tS ~~> iff_setoid.
simple refine (injF3 _models _).
Lemma models_1 : Proper (equiv ==> equiv ==> equiv ==> equiv) _models.
Proof.
autounfold. intros x y H. rewrite H. clear x H. induction y.
intros. unfold _models. rewritesr.
intros. unfold _models. rewritesr.
intros. simpl. split.
intros. destruct H1. destruct H1. exists x1. exists x2. rewrite <- (IHy1 x y H x1 x1 (reflexivity x1)) , <- (IHy2 x y H x2 x2 (reflexivity x2)). rewrite <- H0. auto.
intros. destruct H1. destruct H1. exists x1. exists x2. rewrite (IHy1 x y H x1 x1 (reflexivity x1)) , (IHy2 x y H x2 x2 (reflexivity x2)). rewrite H0. auto.
intros. unfold _models. fold _models. split.
intros. rewrite <- (IHy2 _ _ H (x0 ⋅ h') (y0 ⋅ h')). apply H1. rewrite H0. auto. rewrite (IHy1 _ _ H h' h'). auto. reflexivity. rewrite H0. reflexivity.
intros. rewrite (IHy2 _ _ H (x0 ⋅ h') (y0 ⋅ h')). apply H1. rewrite <- H0. auto. rewrite <- (IHy1 _ _ H h' h'). auto. reflexivity. rewrite H0. reflexivity.
intros. simpl. tauto.
intros. simpl. rewrite (IHy1 _ _ H _ _ H0), (IHy2 _ _ H _ _ H0). tauto.
intros. simpl. rewrite (IHy _ _ H _ _ H0). tauto.
intros. simpl. split.
intros. destruct H1. exists x1. assert (x [v ↦ x1 ]s == y0 [v ↦ x1 ]s). rewrite H. reflexivity. rewrite <- (IHy (x [v ↦ x1 ]s) (y0 [v ↦ x1 ]s) H2 x0 y1 H0). auto.
intros. destruct H1. exists x1. assert (x [v ↦ x1 ]s == y0 [v ↦ x1 ]s). rewrite H. reflexivity. rewrite (IHy (x [v ↦ x1 ]s) (y0 [v ↦ x1 ]s) H2 x0 y1 H0). auto.
Qed.
apply models_1.
Defined.
Notation "⟦ a ⟧" := (fun s h => models @ a @ s @ h) (at level 50, left associativity).
Definition simply a a2 := forall s h, ⟦ a ⟧ s h -> ⟦ a2 ⟧ s h.
Notation "a ⇒ a2" := (simply a a2) (at level 50).
End AssertModel.
|
lemma zero_in_bigtheta_iff [simp]: "(\<lambda>_. 0) \<in> \<Theta>[F](f) \<longleftrightarrow> eventually (\<lambda>x. f x = 0) F" |
/-
Copyright (c) 2022 Kyle Miller, Adam Topaz, Rémi Bottinelli, Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller, Adam Topaz, Rémi Bottinelli, Junyan Xu
-/
import category_theory.filtered
import data.set.finite
import topology.category.Top.limits
/-!
# Cofiltered systems
This file deals with properties of cofiltered (and inverse) systems.
## Main definitions
Given a functor `F : J ⥤ Type v`:
* For `j : J`, `F.eventual_range j` is the intersections of all ranges of morphisms `F.map f`
where `f` has codomain `j`.
* `F.is_mittag_leffler` states that the functor `F` satisfies the Mittag-Leffler
condition: the ranges of morphisms `F.map f` (with `f` having codomain `j`) stabilize.
* If `J` is cofiltered `F.to_eventual_ranges` is the subfunctor of `F` obtained by restriction
to `F.eventual_range`.
* `F.to_preimages` restricts a functor to preimages of a given set in some `F.obj i`. If `J` is
cofiltered, then it is Mittag-Leffler if `F` is, see `is_mittag_leffler.to_preimages`.
## Main statements
* `nonempty_sections_of_finite_cofiltered_system` shows that if `J` is cofiltered and each
`F.obj j` is nonempty and finite, `F.sections` is nonempty.
* `nonempty_sections_of_finite_inverse_system` is a specialization of the above to `J` being a
directed set (and `F : Jᵒᵖ ⥤ Type v`).
* `is_mittag_leffler_of_exists_finite_range` shows that if `J` is cofiltered and for all `j`,
there exists some `i` and `f : i ⟶ j` such that the range of `F.map f` is finite, then
`F` is Mittag-Leffler.
* `to_eventual_ranges_surjective` shows that if `F` is Mittag-Leffler, then `F.to_eventual_ranges`
has all morphisms `F.map f` surjective.
## Todo
* Prove [Stacks: Lemma 0597](https://stacks.math.columbia.edu/tag/0597)
## References
* [Stacks: Mittag-Leffler systems](https://stacks.math.columbia.edu/tag/0594)
## Tags
Mittag-Leffler, surjective, eventual range, inverse system,
-/
universes u v w
open category_theory category_theory.is_cofiltered set category_theory.functor_to_types
section finite_konig
/-- This bootstraps `nonempty_sections_of_finite_inverse_system`. In this version,
the `F` functor is between categories of the same universe, and it is an easy
corollary to `Top.nonempty_limit_cone_of_compact_t2_inverse_system`. -/
lemma nonempty_sections_of_finite_cofiltered_system.init
{J : Type u} [small_category J] [is_cofiltered_or_empty J] (F : J ⥤ Type u)
[hf : ∀ j, finite (F.obj j)] [hne : ∀ j, nonempty (F.obj j)] :
F.sections.nonempty :=
begin
let F' : J ⥤ Top := F ⋙ Top.discrete,
haveI : ∀ j, discrete_topology (F'.obj j) := λ _, ⟨rfl⟩,
haveI : ∀ j, finite (F'.obj j) := hf,
haveI : ∀ j, nonempty (F'.obj j) := hne,
obtain ⟨⟨u, hu⟩⟩ := Top.nonempty_limit_cone_of_compact_t2_cofiltered_system F',
exact ⟨u, λ _ _, hu⟩,
end
/-- The cofiltered limit of nonempty finite types is nonempty.
See `nonempty_sections_of_finite_inverse_system` for a specialization to inverse limits. -/
theorem nonempty_sections_of_finite_cofiltered_system
{J : Type u} [category.{w} J] [is_cofiltered_or_empty J] (F : J ⥤ Type v)
[∀ (j : J), finite (F.obj j)] [∀ (j : J), nonempty (F.obj j)] :
F.sections.nonempty :=
begin
-- Step 1: lift everything to the `max u v w` universe.
let J' : Type (max w v u) := as_small.{max w v} J,
let down : J' ⥤ J := as_small.down,
let F' : J' ⥤ Type (max u v w) := down ⋙ F ⋙ ulift_functor.{(max u w) v},
haveI : ∀ i, nonempty (F'.obj i) := λ i, ⟨⟨classical.arbitrary (F.obj (down.obj i))⟩⟩,
haveI : ∀ i, finite (F'.obj i) := λ i, finite.of_equiv (F.obj (down.obj i)) equiv.ulift.symm,
-- Step 2: apply the bootstrap theorem
casesI is_empty_or_nonempty J,
{ fsplit; exact is_empty_elim },
haveI : is_cofiltered J := ⟨⟩,
obtain ⟨u, hu⟩ := nonempty_sections_of_finite_cofiltered_system.init F',
-- Step 3: interpret the results
use λ j, (u ⟨j⟩).down,
intros j j' f,
have h := @hu (⟨j⟩ : J') (⟨j'⟩ : J') (ulift.up f),
simp only [as_small.down, functor.comp_map, ulift_functor_map, functor.op_map] at h,
simp_rw [←h],
refl,
end
/-- The inverse limit of nonempty finite types is nonempty.
See `nonempty_sections_of_finite_cofiltered_system` for a generalization to cofiltered limits.
That version applies in almost all cases, and the only difference is that this version
allows `J` to be empty.
This may be regarded as a generalization of Kőnig's lemma.
To specialize: given a locally finite connected graph, take `Jᵒᵖ` to be `ℕ` and
`F j` to be length-`j` paths that start from an arbitrary fixed vertex.
Elements of `F.sections` can be read off as infinite rays in the graph. -/
theorem nonempty_sections_of_finite_inverse_system
{J : Type u} [preorder J] [is_directed J (≤)] (F : Jᵒᵖ ⥤ Type v)
[∀ (j : Jᵒᵖ), finite (F.obj j)] [∀ (j : Jᵒᵖ), nonempty (F.obj j)] :
F.sections.nonempty :=
begin
casesI is_empty_or_nonempty J,
{ haveI : is_empty Jᵒᵖ := ⟨λ j, is_empty_elim j.unop⟩, -- TODO: this should be a global instance
exact ⟨is_empty_elim, is_empty_elim⟩, },
{ exact nonempty_sections_of_finite_cofiltered_system _, },
end
end finite_konig
namespace category_theory
namespace functor
variables {J : Type u} [category J] (F : J ⥤ Type v) {i j k : J} (s : set (F.obj i))
/--
The eventual range of the functor `F : J ⥤ Type v` at index `j : J` is the intersection
of the ranges of all maps `F.map f` with `i : J` and `f : i ⟶ j`.
-/
def eventual_range (j : J) := ⋂ i (f : i ⟶ j), range (F.map f)
lemma mem_eventual_range_iff {x : F.obj j} :
x ∈ F.eventual_range j ↔ ∀ ⦃i⦄ (f : i ⟶ j), x ∈ range (F.map f) := mem_Inter₂
/--
The functor `F : J ⥤ Type v` satisfies the Mittag-Leffler condition if for all `j : J`,
there exists some `i : J` and `f : i ⟶ j` such that for all `k : J` and `g : k ⟶ j`, the range
of `F.map f` is contained in that of `F.map g`;
in other words (see `is_mittag_leffler_iff_eventual_range`), the eventual range at `j` is attained
by some `f : i ⟶ j`.
-/
def is_mittag_leffler : Prop :=
∀ j : J, ∃ i (f : i ⟶ j), ∀ ⦃k⦄ (g : k ⟶ j), range (F.map f) ⊆ range (F.map g)
lemma is_mittag_leffler_iff_eventual_range : F.is_mittag_leffler ↔
∀ j : J, ∃ i (f : i ⟶ j), F.eventual_range j = range (F.map f) :=
forall_congr $ λ j, exists₂_congr $ λ i f,
⟨λ h, (Inter₂_subset _ _).antisymm $ subset_Inter₂ h, λ h, h ▸ Inter₂_subset⟩
lemma is_mittag_leffler.subset_image_eventual_range (h : F.is_mittag_leffler) (f : j ⟶ i) :
F.eventual_range i ⊆ F.map f '' (F.eventual_range j) :=
begin
obtain ⟨k, g, hg⟩ := F.is_mittag_leffler_iff_eventual_range.1 h j,
rw hg, intros x hx,
obtain ⟨x, rfl⟩ := F.mem_eventual_range_iff.1 hx (g ≫ f),
refine ⟨_, ⟨x, rfl⟩, by simpa only [F.map_comp]⟩,
end
lemma eventual_range_eq_range_precomp (f : i ⟶ j) (g : j ⟶ k)
(h : F.eventual_range k = range (F.map g)) :
F.eventual_range k = range (F.map $ f ≫ g) :=
begin
apply subset_antisymm,
{ apply Inter₂_subset, },
{ rw [h, F.map_comp], apply range_comp_subset_range, }
end
lemma is_mittag_leffler_of_surjective
(h : ∀ ⦃i j : J⦄ (f :i ⟶ j), (F.map f).surjective) : F.is_mittag_leffler :=
λ j, ⟨j, 𝟙 j, λ k g, by rw [map_id, types_id, range_id, (h g).range_eq]⟩
/-- The subfunctor of `F` obtained by restricting to the preimages of a set `s ∈ F.obj i`. -/
@[simps] def to_preimages : J ⥤ Type v :=
{ obj := λ j, ⋂ f : j ⟶ i, F.map f ⁻¹' s,
map := λ j k g, maps_to.restrict (F.map g) _ _ $ λ x h, begin
rw [mem_Inter] at h ⊢, intro f,
rw [← mem_preimage, preimage_preimage],
convert h (g ≫ f), rw F.map_comp, refl,
end,
map_id' := λ j, by { simp_rw F.map_id, ext, refl },
map_comp' := λ j k l f g, by { simp_rw F.map_comp, refl } }
instance to_preimages_finite [∀ j, finite (F.obj j)] :
∀ j, finite ((F.to_preimages s).obj j) := λ j, subtype.finite
variable [is_cofiltered_or_empty J]
lemma eventual_range_maps_to (f : j ⟶ i) :
(F.eventual_range j).maps_to (F.map f) (F.eventual_range i) :=
λ x hx, begin
rw mem_eventual_range_iff at hx ⊢,
intros k f',
obtain ⟨l, g, g', he⟩ := cospan f f',
obtain ⟨x, rfl⟩ := hx g,
rw [← map_comp_apply, he, F.map_comp],
exact ⟨_, rfl⟩,
end
lemma is_mittag_leffler.eq_image_eventual_range (h : F.is_mittag_leffler) (f : j ⟶ i) :
F.eventual_range i = F.map f '' (F.eventual_range j) :=
(h.subset_image_eventual_range F f).antisymm $ maps_to'.1 (F.eventual_range_maps_to f)
lemma eventual_range_eq_iff {f : i ⟶ j} :
F.eventual_range j = range (F.map f) ↔
∀ ⦃k⦄ (g : k ⟶ i), range (F.map f) ⊆ range (F.map $ g ≫ f) :=
begin
rw [subset_antisymm_iff, eventual_range, and_iff_right (Inter₂_subset _ _), subset_Inter₂_iff],
refine ⟨λ h k g, h _ _, λ h j' f', _⟩,
obtain ⟨k, g, g', he⟩ := cospan f f',
refine (h g).trans _,
rw [he, F.map_comp],
apply range_comp_subset_range,
end
lemma is_mittag_leffler_iff_subset_range_comp : F.is_mittag_leffler ↔
∀ j : J, ∃ i (f : i ⟶ j), ∀ ⦃k⦄ (g : k ⟶ i), range (F.map f) ⊆ range (F.map $ g ≫ f) :=
by simp_rw [is_mittag_leffler_iff_eventual_range, eventual_range_eq_iff]
lemma is_mittag_leffler.to_preimages (h : F.is_mittag_leffler) :
(F.to_preimages s).is_mittag_leffler :=
(is_mittag_leffler_iff_subset_range_comp _).2 $ λ j, begin
obtain ⟨j₁, g₁, f₁, -⟩ := cone_objs i j,
obtain ⟨j₂, f₂, h₂⟩ := F.is_mittag_leffler_iff_eventual_range.1 h j₁,
refine ⟨j₂, f₂ ≫ f₁, λ j₃ f₃, _⟩,
rintro _ ⟨⟨x, hx⟩, rfl⟩,
have : F.map f₂ x ∈ F.eventual_range j₁, { rw h₂, exact ⟨_, rfl⟩ },
obtain ⟨y, hy, h₃⟩ := h.subset_image_eventual_range F (f₃ ≫ f₂) this,
refine ⟨⟨y, mem_Inter.2 $ λ g₂, _⟩, subtype.ext _⟩,
{ obtain ⟨j₄, f₄, h₄⟩ := cone_maps g₂ ((f₃ ≫ f₂) ≫ g₁),
obtain ⟨y, rfl⟩ := F.mem_eventual_range_iff.1 hy f₄,
rw ← map_comp_apply at h₃,
rw [mem_preimage, ← map_comp_apply, h₄, ← category.assoc, map_comp_apply, h₃, ← map_comp_apply],
apply mem_Inter.1 hx },
{ simp_rw [to_preimages_map, maps_to.coe_restrict_apply, subtype.coe_mk],
rw [← category.assoc, map_comp_apply, h₃, map_comp_apply] },
end
lemma is_mittag_leffler_of_exists_finite_range
(h : ∀ (j : J), ∃ i (f : i ⟶ j), (range $ F.map f).finite) :
F.is_mittag_leffler :=
λ j, begin
obtain ⟨i, hi, hf⟩ := h j,
obtain ⟨m, ⟨i, f, hm⟩, hmin⟩ := finset.is_well_founded_lt.wf.has_min
{s : finset (F.obj j) | ∃ i (f : i ⟶ j), ↑s = range (F.map f)} ⟨_, i, hi, hf.coe_to_finset⟩,
refine ⟨i, f, λ k g,
(directed_on_range.mp $ F.ranges_directed j).is_bot_of_is_min ⟨⟨i, f⟩, rfl⟩ _ _ ⟨⟨k, g⟩, rfl⟩⟩,
rintro _ ⟨⟨k', g'⟩, rfl⟩ hl,
refine (eq_of_le_of_not_lt hl _).ge,
have := hmin _ ⟨k', g', (m.finite_to_set.subset $ hm.substr hl).coe_to_finset⟩,
rwa [finset.lt_iff_ssubset, ← finset.coe_ssubset, set.finite.coe_to_finset, hm] at this,
end
/--
The subfunctor of `F` obtained by restricting to the eventual range at each index.
-/
@[simps] def to_eventual_ranges : J ⥤ Type v :=
{ obj := λ j, F.eventual_range j,
map := λ i j f, (F.eventual_range_maps_to f).restrict _ _ _,
map_id' := λ i, by { simp_rw F.map_id, ext, refl },
map_comp' := λ _ _ _ _ _, by { simp_rw F.map_comp, refl } }
instance to_eventual_ranges_finite [∀ j, finite (F.obj j)] :
∀ j, finite (F.to_eventual_ranges.obj j) := λ j, subtype.finite
/--
The sections of the functor `F : J ⥤ Type v` are in bijection with the sections of
`F.eventual_ranges`.
-/
def to_eventual_ranges_sections_equiv : F.to_eventual_ranges.sections ≃ F.sections :=
{ to_fun := λ s, ⟨_, λ i j f, subtype.coe_inj.2 $ s.prop f⟩,
inv_fun := λ s, ⟨λ j, ⟨_, mem_Inter₂.2 $ λ i f, ⟨_, s.prop f⟩⟩, λ i j f, subtype.ext $ s.prop f⟩,
left_inv := λ _, by { ext, refl },
right_inv := λ _, by { ext, refl } }
/--
If `F` satisfies the Mittag-Leffler condition, its restriction to eventual ranges is a surjective
functor.
-/
lemma surjective_to_eventual_ranges (h : F.is_mittag_leffler) ⦃i j⦄ (f : i ⟶ j) :
(F.to_eventual_ranges.map f).surjective :=
λ ⟨x, hx⟩, by { obtain ⟨y, hy, rfl⟩ := h.subset_image_eventual_range F f hx, exact ⟨⟨y, hy⟩, rfl⟩ }
/-- If `F` is nonempty at each index and Mittag-Leffler, then so is `F.to_eventual_ranges`. -/
lemma to_eventual_ranges_nonempty (h : F.is_mittag_leffler) [∀ (j : J), nonempty (F.obj j)]
(j : J) : nonempty (F.to_eventual_ranges.obj j) :=
let ⟨i, f, h⟩ := F.is_mittag_leffler_iff_eventual_range.1 h j in
by { rw [to_eventual_ranges_obj, h], apply_instance }
/-- If `F` has all arrows surjective, then it "factors through a poset". -/
lemma thin_diagram_of_surjective (Fsur : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f).surjective)
{i j} (f g : i ⟶ j) : F.map f = F.map g :=
let ⟨k, φ, hφ⟩ := cone_maps f g in
(Fsur φ).injective_comp_right $ by simp_rw [← types_comp, ← F.map_comp, hφ]
lemma to_preimages_nonempty_of_surjective [hFn : ∀ (j : J), nonempty (F.obj j)]
(Fsur : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f).surjective)
(hs : s.nonempty) (j) : nonempty ((F.to_preimages s).obj j) :=
begin
simp only [to_preimages_obj, nonempty_coe_sort, nonempty_Inter, mem_preimage],
obtain (h|⟨⟨ji⟩⟩) := is_empty_or_nonempty (j ⟶ i),
{ exact ⟨(hFn j).some, λ ji, h.elim ji⟩, },
{ obtain ⟨y, ys⟩ := hs,
obtain ⟨x, rfl⟩ := Fsur ji y,
exact ⟨x, λ ji', (F.thin_diagram_of_surjective Fsur ji' ji).symm ▸ ys⟩, },
end
lemma eval_section_injective_of_eventually_injective
{j} (Finj : ∀ i (f : i ⟶ j), (F.map f).injective) (i) (f : i ⟶ j) :
(λ s : F.sections, s.val j).injective :=
begin
refine λ s₀ s₁ h, subtype.ext $ funext $ λ k, _,
obtain ⟨m, mi, mk, _⟩ := cone_objs i k,
dsimp at h,
rw [←s₀.prop (mi ≫ f), ←s₁.prop (mi ≫ f)] at h,
rw [←s₀.prop mk, ←s₁.prop mk],
refine congr_arg _ (Finj m (mi ≫ f) h),
end
section finite_cofiltered_system
variables [∀ (j : J), nonempty (F.obj j)] [∀ (j : J), finite (F.obj j)]
(Fsur : ∀ ⦃i j : J⦄ (f :i ⟶ j), (F.map f).surjective)
include Fsur
lemma eval_section_surjective_of_surjective (i : J) :
(λ s : F.sections, s.val i).surjective := λ x,
begin
let s : set (F.obj i) := {x},
haveI := F.to_preimages_nonempty_of_surjective s Fsur (singleton_nonempty x),
obtain ⟨sec, h⟩ := nonempty_sections_of_finite_cofiltered_system (F.to_preimages s),
refine ⟨⟨λ j, (sec j).val, λ j k jk, by simpa [subtype.ext_iff] using h jk⟩, _⟩,
{ have := (sec i).prop,
simp only [mem_Inter, mem_preimage, mem_singleton_iff] at this,
replace this := this (𝟙 i), rwa [map_id_apply] at this, },
end
lemma eventually_injective [nonempty J] [finite F.sections] :
∃ j, ∀ i (f : i ⟶ j), (F.map f).injective :=
begin
haveI : ∀ j, fintype (F.obj j) := λ j, fintype.of_finite (F.obj j),
haveI : fintype F.sections := fintype.of_finite F.sections,
have card_le : ∀ j, fintype.card (F.obj j) ≤ fintype.card F.sections :=
λ j, fintype.card_le_of_surjective _ (F.eval_section_surjective_of_surjective Fsur j),
let fn := λ j, fintype.card F.sections - fintype.card (F.obj j),
refine ⟨fn.argmin nat.well_founded_lt.wf, λ i f, ((fintype.bijective_iff_surjective_and_card _).2
⟨Fsur f, le_antisymm _ (fintype.card_le_of_surjective _ $ Fsur f)⟩).1⟩,
rw [← nat.sub_sub_self (card_le i), tsub_le_iff_tsub_le],
apply fn.argmin_le,
end
end finite_cofiltered_system
end functor
end category_theory
|
*=======================================================================
* Program: STREAM
* Programmer: John D. McCalpin
*-----------------------------------------------------------------------
* Copyright 1991-2003: John D. McCalpin
*-----------------------------------------------------------------------
* License:
* 1. You are free to use this program and/or to redistribute
* this program.
* 2. You are free to modify this program for your own use,
* including commercial use, subject to the publication
* restrictions in item 3.
* 3. You are free to publish results obtained from running this
* program, or from works that you derive from this program,
* with the following limitations:
* 3a. In order to be referred to as "STREAM benchmark results",
* published results must be in conformance to the STREAM
* Run Rules, (briefly reviewed below) published at
* http://www.cs.virginia.edu/stream/ref.html
* and incorporated herein by reference.
* As the copyright holder, John McCalpin retains the
* right to determine conformity with the Run Rules.
* 3b. Results based on modified source code or on runs not in
* accordance with the STREAM Run Rules must be clearly
* labelled whenever they are published. Examples of
* proper labelling include:
* "tuned STREAM benchmark results"
* "based on a variant of the STREAM benchmark code"
* Other comparable, clear and reasonable labelling is
* acceptable.
* 3c. Submission of results to the STREAM benchmark web site
* is encouraged, but not required.
* 4. Use of this program or creation of derived works based on this
* program constitutes acceptance of these licensing restrictions.
* 5. Absolutely no warranty is expressed or implied.
*-----------------------------------------------------------------------
* This program measures sustained memory transfer rates in MB/s for
* simple computational kernels coded in FORTRAN.
*
* The intent is to demonstrate the extent to which ordinary user
* code can exploit the main memory bandwidth of the system under
* test.
*=======================================================================
* The STREAM web page is at:
* http://www.streambench.org
*
* Most of the content is currently hosted at:
* http://www.cs.virginia.edu/stream/
*
* BRIEF INSTRUCTIONS:
* 0) See http://www.cs.virginia.edu/stream/ref.html for details
* 1) STREAM requires a timing function called mysecond().
* Several examples are provided in this directory.
* "CPU" timers are only allowed for uniprocessor runs.
* "Wall-clock" timers are required for all multiprocessor runs.
* 2) The STREAM array sizes must be set to size the test.
* The value "N" must be chosen so that each of the three
* arrays is at least 4x larger than the sum of all the last-
* level caches used in the run, or 1 million elements, which-
* ever is larger.
* ------------------------------------------------------------
* Note that you are free to use any array length and offset
* that makes each array 4x larger than the last-level cache.
* The intent is to determine the *best* sustainable bandwidth
* available with this simple coding. Of course, lower values
* are usually fairly easy to obtain on cached machines, but
* by keeping the test to the *best* results, the answers are
* easier to interpret.
* You may put the arrays in common or not, at your discretion.
* There is a commented-out COMMON statement below.
* Fortran90 "allocatable" arrays are fine, too.
* ------------------------------------------------------------
* 3) Compile the code with full optimization. Many compilers
* generate unreasonably bad code before the optimizer tightens
* things up. If the results are unreasonably good, on the
* other hand, the optimizer might be too smart for me
* Please let me know if this happens.
* 4) Mail the results to [email protected]
* Be sure to include:
* a) computer hardware model number and software revision
* b) the compiler flags
* c) all of the output from the test case.
* Please let me know if you do not want your name posted along
* with the submitted results.
* 5) See the web page for more comments about the run rules and
* about interpretation of the results.
*
* Thanks,
* Dr. Bandwidth
*=========================================================================
*
PROGRAM stream
* IMPLICIT NONE
C .. Parameters ..
INTEGER n,offset,ndim,ntimes
PARAMETER (n=2000000,offset=0,ndim=n+offset,ntimes=10)
C ..
C .. Local Scalars ..
DOUBLE PRECISION scalar,t
INTEGER j,k,nbpw,quantum
C ..
C .. Local Arrays ..
DOUBLE PRECISION maxtime(4),mintime(4),avgtime(4),
$ times(4,ntimes)
INTEGER bytes(4)
CHARACTER label(4)*11
C ..
C .. External Functions ..
DOUBLE PRECISION mysecond
INTEGER checktick,realsize
EXTERNAL mysecond,checktick,realsize
!$ INTEGER omp_get_num_threads
!$ EXTERNAL omp_get_num_threads
C ..
C .. Intrinsic Functions ..
C
INTRINSIC dble,max,min,nint,sqrt
C ..
C .. Arrays in Common ..
DOUBLE PRECISION a(ndim),b(ndim),c(ndim)
C ..
C .. Common blocks ..
* COMMON a,b,c
C ..
C .. Data statements ..
DATA avgtime/4*0.0D0/,mintime/4*1.0D+36/,maxtime/4*0.0D0/
DATA label/'Copy: ','Scale: ','Add: ',
$ 'Triad: '/
DATA bytes/2,2,3,3/
C ..
* --- SETUP --- determine precision and check timing ---
nbpw = realsize()
PRINT *,'----------------------------------------------'
PRINT *,'STREAM Version $Revision$'
PRINT *,'----------------------------------------------'
WRITE (*,FMT=9010) 'Array size = ',n
WRITE (*,FMT=9010) 'Offset = ',offset
WRITE (*,FMT=9020) 'The total memory requirement is ',
$ 3*nbpw*n/ (1024*1024),' MB'
WRITE (*,FMT=9030) 'You are running each test ',ntimes,' times'
WRITE (*,FMT=9030) '--'
WRITE (*,FMT=9030) 'The *best* time for each test is used'
WRITE (*,FMT=9030) '*EXCLUDING* the first and last iterations'
!$OMP PARALLEL
!$OMP MASTER
PRINT *,'----------------------------------------------'
!$ PRINT *,'Number of Threads = ',OMP_GET_NUM_THREADS()
!$OMP END MASTER
!$OMP END PARALLEL
PRINT *,'----------------------------------------------'
!$OMP PARALLEL
PRINT *,'Printing one line per active thread....'
!$OMP END PARALLEL
!$OMP PARALLEL DO
DO 10 j = 1,n
a(j) = 2.0d0
b(j) = 0.5D0
c(j) = 0.0D0
10 CONTINUE
t = mysecond()
!$OMP PARALLEL DO
DO 20 j = 1,n
a(j) = 0.5d0*a(j)
20 CONTINUE
t = mysecond() - t
PRINT *,'----------------------------------------------------'
quantum = checktick()
WRITE (*,FMT=9000)
$ 'Your clock granularity/precision appears to be ',quantum,
$ ' microseconds'
PRINT *,'----------------------------------------------------'
* --- MAIN LOOP --- repeat test cases NTIMES times ---
scalar = 0.5d0*a(1)
DO 70 k = 1,ntimes
t = mysecond()
a(1) = a(1) + t
!$OMP PARALLEL DO
DO 30 j = 1,n
c(j) = a(j)
30 CONTINUE
t = mysecond() - t
c(n) = c(n) + t
times(1,k) = t
t = mysecond()
c(1) = c(1) + t
!$OMP PARALLEL DO
DO 40 j = 1,n
b(j) = scalar*c(j)
40 CONTINUE
t = mysecond() - t
b(n) = b(n) + t
times(2,k) = t
t = mysecond()
a(1) = a(1) + t
!$OMP PARALLEL DO
DO 50 j = 1,n
c(j) = a(j) + b(j)
50 CONTINUE
t = mysecond() - t
c(n) = c(n) + t
times(3,k) = t
t = mysecond()
b(1) = b(1) + t
!$OMP PARALLEL DO
DO 60 j = 1,n
a(j) = b(j) + scalar*c(j)
60 CONTINUE
t = mysecond() - t
a(n) = a(n) + t
times(4,k) = t
70 CONTINUE
* --- SUMMARY ---
DO 90 k = 2,ntimes
DO 80 j = 1,4
avgtime(j) = avgtime(j) + times(j,k)
mintime(j) = min(mintime(j),times(j,k))
maxtime(j) = max(maxtime(j),times(j,k))
80 CONTINUE
90 CONTINUE
WRITE (*,FMT=9040)
DO 100 j = 1,4
avgtime(j) = avgtime(j)/dble(ntimes-1)
WRITE (*,FMT=9050) label(j),n*bytes(j)*nbpw/mintime(j)/1.0D6,
$ avgtime(j),mintime(j),maxtime(j)
100 CONTINUE
PRINT *,'----------------------------------------------------'
CALL checksums (a,b,c,n,ntimes)
PRINT *,'----------------------------------------------------'
9000 FORMAT (1x,a,i6,a)
9010 FORMAT (1x,a,i10)
9020 FORMAT (1x,a,i4,a)
9030 FORMAT (1x,a,i3,a,a)
9040 FORMAT ('Function',5x,'Rate (MB/s) Avg time Min time Max time'
$ )
9050 FORMAT (a,4 (f10.4,2x))
END
*-------------------------------------
* INTEGER FUNCTION dblesize()
*
* A semi-portable way to determine the precision of DOUBLE PRECISION
* in Fortran.
* Here used to guess how many bytes of storage a DOUBLE PRECISION
* number occupies.
*
INTEGER FUNCTION realsize()
* IMPLICIT NONE
C .. Local Scalars ..
DOUBLE PRECISION result,test
INTEGER j,ndigits
C ..
C .. Local Arrays ..
DOUBLE PRECISION ref(30)
C ..
C .. External Subroutines ..
EXTERNAL confuse
C ..
C .. Intrinsic Functions ..
INTRINSIC abs,acos,log10,sqrt
C ..
C Test #1 - compare single(1.0d0+delta) to 1.0d0
10 DO 20 j = 1,30
ref(j) = 1.0d0 + 10.0d0** (-j)
20 CONTINUE
DO 30 j = 1,30
test = ref(j)
ndigits = j
CALL confuse(test,result)
IF (test.EQ.1.0D0) THEN
GO TO 40
END IF
30 CONTINUE
GO TO 50
40 WRITE (*,FMT='(a)')
$ '----------------------------------------------'
WRITE (*,FMT='(1x,a,i2,a)') 'Double precision appears to have ',
$ ndigits,' digits of accuracy'
IF (ndigits.LE.8) THEN
realsize = 4
ELSE
realsize = 8
END IF
WRITE (*,FMT='(1x,a,i1,a)') 'Assuming ',realsize,
$ ' bytes per DOUBLE PRECISION word'
WRITE (*,FMT='(a)')
$ '----------------------------------------------'
RETURN
50 PRINT *,'Hmmmm. I am unable to determine the size.'
PRINT *,'Please enter the number of Bytes per DOUBLE PRECISION',
$ ' number : '
READ (*,FMT=*) realsize
IF (realsize.NE.4 .AND. realsize.NE.8) THEN
PRINT *,'Your answer ',realsize,' does not make sense.'
PRINT *,'Try again.'
PRINT *,'Please enter the number of Bytes per ',
$ 'DOUBLE PRECISION number : '
READ (*,FMT=*) realsize
END IF
PRINT *,'You have manually entered a size of ',realsize,
$ ' bytes per DOUBLE PRECISION number'
WRITE (*,FMT='(a)')
$ '----------------------------------------------'
END
SUBROUTINE confuse(q,r)
* IMPLICIT NONE
C .. Scalar Arguments ..
DOUBLE PRECISION q,r
C ..
C .. Intrinsic Functions ..
INTRINSIC cos
C ..
r = cos(q)
RETURN
END
* A semi-portable way to determine the clock granularity
* Adapted from a code by John Henning of Digital Equipment Corporation
*
INTEGER FUNCTION checktick()
* IMPLICIT NONE
C .. Parameters ..
INTEGER n
PARAMETER (n=20)
C ..
C .. Local Scalars ..
DOUBLE PRECISION t1,t2
INTEGER i,j,jmin
C ..
C .. Local Arrays ..
DOUBLE PRECISION timesfound(n)
C ..
C .. External Functions ..
DOUBLE PRECISION mysecond
EXTERNAL mysecond
C ..
C .. Intrinsic Functions ..
INTRINSIC max,min,nint
C ..
i = 0
10 t2 = mysecond()
IF (t2.EQ.t1) GO TO 10
t1 = t2
i = i + 1
timesfound(i) = t1
IF (i.LT.n) GO TO 10
jmin = 1000000
DO 20 i = 2,n
j = nint((timesfound(i)-timesfound(i-1))*1d6)
jmin = min(jmin,max(j,0))
20 CONTINUE
IF (jmin.GT.0) THEN
checktick = jmin
ELSE
PRINT *,'Your clock granularity appears to be less ',
$ 'than one microsecond'
checktick = 1
END IF
RETURN
* PRINT 14, timesfound(1)*1d6
* DO 20 i=2,n
* PRINT 14, timesfound(i)*1d6,
* & nint((timesfound(i)-timesfound(i-1))*1d6)
* 14 FORMAT (1X, F18.4, 1X, i8)
* 20 CONTINUE
END
SUBROUTINE checksums(a,b,c,n,ntimes)
* IMPLICIT NONE
C ..
C .. Arguments ..
DOUBLE PRECISION a(*),b(*),c(*)
INTEGER n,ntimes
C ..
C .. Local Scalars ..
DOUBLE PRECISION aa,bb,cc,scalar,suma,sumb,sumc,epsilon
INTEGER k
C ..
C Repeat the main loop, but with scalars only.
C This is done to check the sum & make sure all
C iterations have been executed correctly.
aa = 2.0D0
bb = 0.5D0
cc = 0.0D0
aa = 0.5D0*aa
scalar = 0.5d0*aa
DO k = 1,ntimes
cc = aa
bb = scalar*cc
cc = aa + bb
aa = bb + scalar*cc
END DO
aa = aa*DBLE(n-2)
bb = bb*DBLE(n-2)
cc = cc*DBLE(n-2)
C Now sum up the arrays, excluding the first and last
C elements, which are modified using the timing results
C to confuse aggressive optimizers.
suma = 0.0d0
sumb = 0.0d0
sumc = 0.0d0
!$OMP PARALLEL DO REDUCTION(+:suma,sumb,sumc)
DO 110 j = 2,n-1
suma = suma + a(j)
sumb = sumb + b(j)
sumc = sumc + c(j)
110 CONTINUE
epsilon = 1.D-6
IF (ABS(suma-aa)/suma .GT. epsilon) THEN
PRINT *,'Failed Validation on array a()'
PRINT *,'Target Sum of a is = ',aa
PRINT *,'Computed Sum of a is = ',suma
ELSEIF (ABS(sumb-bb)/sumb .GT. epsilon) THEN
PRINT *,'Failed Validation on array b()'
PRINT *,'Target Sum of b is = ',bb
PRINT *,'Computed Sum of b is = ',sumb
ELSEIF (ABS(sumc-cc)/sumc .GT. epsilon) THEN
PRINT *,'Failed Validation on array c()'
PRINT *,'Target Sum of c is = ',cc
PRINT *,'Computed Sum of c is = ',sumc
ELSE
PRINT *,'Solution Validates!'
ENDIF
END
|
-- conversion to/from Data.Vector.Storable
-- from Roman Leshchinskiy "vector" package
--
-- In the future Data.Packed.Vector will be replaced by Data.Vector.Storable
-------------------------------------------
import Numeric.LinearAlgebra as H
import Data.Packed.Development(unsafeFromForeignPtr, unsafeToForeignPtr)
import Foreign.Storable
import qualified Data.Vector.Storable as V
fromVector :: Storable t => V.Vector t -> H.Vector t
fromVector v = unsafeFromForeignPtr p i n where
(p,i,n) = V.unsafeToForeignPtr v
toVector :: Storable t => H.Vector t -> V.Vector t
toVector v = V.unsafeFromForeignPtr p i n where
(p,i,n) = unsafeToForeignPtr v
-------------------------------------------
v = V.slice 5 10 (V.fromList [1 .. 10::Double] V.++ V.replicate 10 7)
w = subVector 2 3 (linspace 5 (0,1)) :: Vector Double
main = do
print v
print $ fromVector v
print w
print $ toVector w
|
Everyone needs a bike to roll around on when they’re not on a group ride, racing off road, or training for the Olympics, and The Shadow Conspiracy and LA streetwear kings The Hundreds have created just the right 26 inch BMX bike for doing that.
The one-of-a-kind bike comes with an old-school drop nose seat adorned by a sublimated custom graphic and retro-inspired pad set. This bike isn’t just a looker, built with the guts and glory of The Shadow Conspiracy proprietary custom parts, including their signature Shadow Chain.
The bike, along withmatching jersey, tees, pullover, and hat, to go along with it, will be released tomorrow, March 28, 2019. If you want to check it out, roll by The Hundreds on Fairfax in Los Angeles at 5:30 PM for an “LA Mash” to Lock & Key on Vermont. For all the details, follow the jump.
The Shadow Conspiracy’s bloody, brutal, black-and-blue motif have been a staple of the brand since the beginning and show how many times you have to fall before you stomp it and achieve success. While the bike collaboration focuses on brighter colors and shiny chrome, Shadow’s attitude still shines through on the collection of clothing and accessories being released alongside it. The limited edition capsule features a collaborative jersey made of moisture-wicking coolmax mesh, as well as a dual-branded graphic T-shirt, pullover hoodie, and snapback. |
Formal statement is: lemma complex_Im_of_int [simp]: "Im (of_int z) = 0" Informal statement is: The imaginary part of an integer is zero. |
[STATEMENT]
lemma bounded_linear_ident[simp]: "bounded_linear (\<lambda>x. x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. bounded_linear (\<lambda>x. x)
[PROOF STEP]
by standard (auto intro!: exI[of _ 1]) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.