text
stringlengths 0
3.34M
|
---|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
! This file was ported from Lean 3 source module order.atoms.finite
! leanprover-community/mathlib commit d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Set.Finite
import Mathlib.Order.Atoms
/-!
# Atoms, Coatoms, Simple Lattices, and Finiteness
This module contains some results on atoms and simple lattices in the finite context.
## Main results
* `Finite.to_isAtomic`, `Finite.to_isCoatomic`: Finite partial orders with bottom resp. top
are atomic resp. coatomic.
-/
variable {α β : Type _}
namespace IsSimpleOrder
section DecidableEq
/- It is important that `IsSimpleOrder` is the last type-class argument of this instance,
so that type-class inference fails quickly if it doesn't apply. -/
instance (priority := 200) {α} [DecidableEq α] [LE α] [BoundedOrder α] [IsSimpleOrder α] :
Fintype α :=
Fintype.ofEquiv Bool equivBool.symm
end DecidableEq
end IsSimpleOrder
namespace Fintype
namespace IsSimpleOrder
variable [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α] [DecidableEq α]
theorem univ : (Finset.univ : Finset α) = {⊤, ⊥} := by
change Finset.map _ (Finset.univ : Finset Bool) = _
rw [Fintype.univ_bool]
simp only [Finset.map_insert, Function.Embedding.coeFn_mk, Finset.map_singleton]
rfl
#align fintype.is_simple_order.univ Fintype.IsSimpleOrder.univ
theorem card : Fintype.card α = 2 :=
(Fintype.ofEquiv_card _).trans Fintype.card_bool
#align fintype.is_simple_order.card Fintype.IsSimpleOrder.card
end IsSimpleOrder
end Fintype
namespace Bool
instance : IsSimpleOrder Bool :=
⟨fun a =>
by
rw [← Finset.mem_singleton, Or.comm, ← Finset.mem_insert, top_eq_true, bot_eq_false, ←
Fintype.univ_bool]
apply Finset.mem_univ⟩
end Bool
section Fintype
open Finset
-- see Note [lower instance priority]
instance (priority := 100) Finite.to_isCoatomic [PartialOrder α] [OrderTop α] [Finite α] :
IsCoatomic α := by
refine' IsCoatomic.mk fun b => or_iff_not_imp_left.2 fun ht => _
obtain ⟨c, hc, hmax⟩ :=
Set.Finite.exists_maximal_wrt id { x : α | b ≤ x ∧ x ≠ ⊤ } (Set.toFinite _) ⟨b, le_rfl, ht⟩
refine' ⟨c, ⟨hc.2, fun y hcy => _⟩, hc.1⟩
by_contra hyt
obtain rfl : c = y := hmax y ⟨hc.1.trans hcy.le, hyt⟩ hcy.le
exact (lt_self_iff_false _).mp hcy
#align finite.to_is_coatomic Finite.to_isCoatomic
-- see Note [lower instance priority]
instance (priority := 100) Finite.to_isAtomic [PartialOrder α] [OrderBot α] [Finite α] :
IsAtomic α :=
isCoatomic_dual_iff_isAtomic.mp Finite.to_isCoatomic
#align finite.to_is_atomic Finite.to_isAtomic
end Fintype
|
(*
* Copyright 2014, NICTA
*
* This software may be distributed and modified according to the terms of
* the GNU General Public License version 2. Note that NO WARRANTY is provided.
* See "LICENSE_GPLv2.txt" for details.
*
* @TAG(NICTA_GPL)
*)
chapter {* Event Receive *}
(*<*)
theory EventTo imports
"../../tools/c-parser/CTranslation"
"../../tools/autocorres/AutoCorres"
begin
(* THIS THEORY IS GENERATED. DO NOT EDIT. *)
declare [[allow_underscore_idents=true]]
install_C_file "EventTo.c"
autocorres [ts_rules = nondet, no_heap_abs = seL4_SetMR] "EventTo.c"
context EventTo begin
(* Repeated constants from C. *)
abbreviation "seL4_MsgMaxLength \<equiv> 120"
(* Introduce this definition here so we can refer to it in the locale extension below. *)
definition
seL4_SetMR_lifted' :: "int \<Rightarrow> word32 \<Rightarrow> lifted_globals \<Rightarrow> (unit \<times> lifted_globals) set \<times> bool"
where
"seL4_SetMR_lifted' i val \<equiv>
do
ret' \<leftarrow> seL4_GetIPCBuffer';
guard (\<lambda>s. i < seL4_MsgMaxLength);
guard (\<lambda>s. 0 \<le> i);
modify (\<lambda>s. s \<lparr>heap_seL4_IPCBuffer__C :=
(heap_seL4_IPCBuffer__C s)(ret' :=
msg_C_update (\<lambda>a. Arrays.update a (nat i) val)
(heap_seL4_IPCBuffer__C s ret'))
\<rparr>)
od"
end
locale EventTo_glue = EventTo +
assumes seL4_SetMR_axiom: "exec_concrete lift_global_heap (seL4_SetMR' i val) = seL4_SetMR_lifted' i val"
assumes swi_safe_to_ignore[simplified, simp]:
"asm_semantics_ok_to_ignore TYPE(nat) true (''swi '' @ x)"
begin
definition
globals_frame_intact :: "lifted_globals \<Rightarrow> bool"
where
"globals_frame_intact s \<equiv> is_valid_seL4_IPCBuffer__C'ptr s (Ptr (scast seL4_GlobalsFrame))"
definition
ipc_buffer_valid :: "lifted_globals \<Rightarrow> bool"
where
"ipc_buffer_valid s \<equiv> is_valid_seL4_IPCBuffer__C s (heap_seL4_IPCBuffer__C'ptr s (Ptr (scast seL4_GlobalsFrame)))"
definition
setMR :: "lifted_globals \<Rightarrow> nat \<Rightarrow> word32 \<Rightarrow> lifted_globals"
where
"setMR s i v \<equiv>
s\<lparr>heap_seL4_IPCBuffer__C := (heap_seL4_IPCBuffer__C s)
(heap_seL4_IPCBuffer__C'ptr s (Ptr (scast seL4_GlobalsFrame)) :=
msg_C_update (\<lambda>a. Arrays.update a i v)
(heap_seL4_IPCBuffer__C s (heap_seL4_IPCBuffer__C'ptr s (Ptr (scast seL4_GlobalsFrame)))))\<rparr>"
definition
setMRs :: "lifted_globals \<Rightarrow> word32 \<Rightarrow> word32 \<Rightarrow>
word32 \<Rightarrow> word32 \<Rightarrow> lifted_globals"
where
"setMRs s mr0 mr1 mr2 mr3 \<equiv> setMR (setMR (setMR (setMR s 0 mr0) 1 mr1) 2 mr2) 3 mr3"
lemma seL4_SetMR_wp[wp_unsafe]:
notes seL4_SetMR_axiom[simp]
shows
"\<lbrace>\<lambda>s. globals_frame_intact s \<and>
ipc_buffer_valid s \<and>
i \<ge> 0 \<and>
i < seL4_MsgMaxLength \<and>
(\<forall>x. P x (setMR s (nat i) v))\<rbrace>
exec_concrete lift_global_heap (seL4_SetMR' i v)
\<lbrace>P\<rbrace>!"
apply (simp add:seL4_SetMR_lifted'_def seL4_GetIPCBuffer'_def)
apply wp
apply (simp add:setMR_def globals_frame_intact_def ipc_buffer_valid_def)
done
lemma seL4_GetIPCBuffer_wp[wp_unsafe]: "\<lbrace>\<lambda>s. \<forall>x. P x s\<rbrace> seL4_GetIPCBuffer' \<lbrace>P\<rbrace>"
apply (unfold seL4_GetIPCBuffer'_def)
apply wp
apply clarsimp
done
definition
thread_count :: word32
where
"thread_count \<equiv> 2"
definition
tls_ptr :: "lifted_globals \<Rightarrow> camkes_tls_t_C ptr"
where
"tls_ptr s \<equiv> Ptr (ptr_val (heap_seL4_IPCBuffer__C'ptr s
(Ptr (scast seL4_GlobalsFrame))) && 0xFFFFF000)"
definition
tls :: "lifted_globals \<Rightarrow> camkes_tls_t_C"
where
"tls s \<equiv> heap_camkes_tls_t_C s (tls_ptr s)"
definition
tls_valid :: "lifted_globals \<Rightarrow> bool"
where
"tls_valid s \<equiv> is_valid_camkes_tls_t_C s (tls_ptr s)"
lemma camkes_get_tls_wp':
"\<forall>s'. \<lbrace>\<lambda>s. tls_valid s \<and> globals_frame_intact s \<and> s = s'\<rbrace>
camkes_get_tls'
\<lbrace>\<lambda>r s. s = s' \<and> r = tls_ptr s\<rbrace>!"
apply (rule allI)
apply (simp add:camkes_get_tls'_def seL4_GetIPCBuffer'_def tls_valid_def)
apply wp
apply (clarsimp simp:globals_frame_intact_def tls_ptr_def)
done
lemmas camkes_get_tls_wp[wp] =
camkes_get_tls_wp'[THEN validNF_make_schematic_post, simplified]
lemma abort_wp[wp]:
"\<lbrace>\<lambda>_. False\<rbrace> abort' \<lbrace>P\<rbrace>!"
apply (rule validNF_false_pre)
done
lemma seL4_Poll_wp[wp_unsafe]:
"\<lbrace>\<lambda>s. globals_frame_intact s \<and>
ipc_buffer_valid s \<and>
(\<forall>x b v0 v1 v2 v3. P x (heap_w32_update (\<lambda>a. a(badge := b)) (setMRs s v0 v1 v2 v3))) \<and>
badge \<noteq> NULL \<and>
is_valid_w32 s badge \<rbrace>
seL4_Poll' cap badge
\<lbrace>P\<rbrace>!"
apply (simp add:seL4_Poll'_def seL4_GetIPCBuffer'_def)
apply (wp seL4_SetMR_wp)
apply (simp add:globals_frame_intact_def ipc_buffer_valid_def setMRs_def setMR_def)
done
lemma seL4_Wait_wp[wp_unsafe]:
"\<lbrace>\<lambda>s. globals_frame_intact s \<and>
ipc_buffer_valid s \<and>
(\<forall>x v0 v1 v2 v3. P x (setMRs s v0 v1 v2 v3))\<rbrace>
seL4_Wait' cap NULL
\<lbrace>P\<rbrace>!"
apply (simp add:seL4_Wait'_def seL4_GetIPCBuffer'_def)
apply (wp seL4_SetMR_wp)
apply (simp add:globals_frame_intact_def ipc_buffer_valid_def setMRs_def setMR_def)
done
(*>*)
text {*
The glue code for receiving an event provides two functions, poll and wait. These functions
perform a non-blocking and blocking check for an incoming event, respectively. To show the safety
of these two generated functions we make a number of assumptions. Namely, that the globals frame,
IPC buffer and TLS regions have not been interfered with and that any necessary thread-local
variables are still valid. Non-malicious user code should never touch any of these
resources. The generated code for poll and its safety proof are as follows.
\clisting{eventto-poll.c}
*}
lemma EventTo_poll_nf:
notes seL4_SetMR_wp[wp]
shows
"\<lbrace>\<lambda>s. is_valid_w32 s (Ptr (symbol_table ''badge_1'')) \<and>
Ptr (symbol_table ''badge_1'') \<noteq> NULL \<and>
is_valid_w32 s (Ptr (symbol_table ''badge_2'')) \<and>
Ptr (symbol_table ''badge_2'') \<noteq> NULL \<and>
globals_frame_intact s \<and>
ipc_buffer_valid s \<and>
tls_valid s \<and>
thread_index_C (tls s) \<in> {1..thread_count}\<rbrace>
EventTo_poll'
\<lbrace>\<lambda>r s. is_valid_w32 s (Ptr (symbol_table ''badge_1'')) \<and>
Ptr (symbol_table ''badge_1'') \<noteq> NULL \<and>
is_valid_w32 s (Ptr (symbol_table ''badge_2'')) \<and>
Ptr (symbol_table ''badge_2'') \<noteq> NULL \<and>
globals_frame_intact s \<and>
ipc_buffer_valid s \<and>
tls_valid s \<and>
thread_index_C (tls s) \<in> {1..thread_count} \<and>
(r = 0 \<or> r = 1)\<rbrace>!"
apply (simp add:EventTo_poll'_def get_badge'_def)
apply (wp seL4_Poll_wp)
apply (clarsimp simp:globals_frame_intact_def seL4_GetIPCBuffer'_def
thread_count_def setMRs_def setMR_def
ipc_buffer_valid_def tls_valid_def tls_ptr_def
tls_def)
apply unat_arith
done
(*<*)
(* This function is invoked on startup of this connector and, while we can show its correctness as
* below, it is not interesting for the purposes of this report.
*)
lemma EventTo_run_nf: "\<lbrace>\<lambda>s. \<forall>r. P r s\<rbrace> EventTo__run' \<lbrace>P\<rbrace>!"
apply (unfold EventTo__run'_def)
apply wp
apply simp
done
(*>*)
text {*
The code for wait is somewhat simpler as it is just a wrapper around the seL4 primitive.
\clisting{eventto-wait.c}
*}
lemma EventTo_wait_nf:
notes seL4_SetMR_wp[wp]
shows
"\<lbrace>\<lambda>s. globals_frame_intact s \<and> ipc_buffer_valid s\<rbrace>
EventTo_wait'
\<lbrace>\<lambda>_ s. globals_frame_intact s \<and> ipc_buffer_valid s\<rbrace>!"
apply (simp add:EventTo_wait'_def)
apply (wp seL4_Wait_wp)
apply (simp add:globals_frame_intact_def ipc_buffer_valid_def setMRs_def
setMR_def)
done
(*<*)
end
end
(*>*)
|
theory Proof_6_351
imports Proofs6
begin
theorem proof_6_351: "VC351 inv6 env s0 PdOut paid_value opened_value"
apply(unfold VC351_def)
apply simp
apply(unfold inv6_def R6_def)
apply(rule impI)
apply(erule conjE)
apply(erule conjE)
apply(rule conjI)
apply(rule conjI)
apply simp
apply(unfold extraInv_def)
subgoal premises vc_prems
apply(rule allI)
apply(rule impI)
apply(simp split: if_splits)
using vc_prems(1,3) substate_refl[of s0] apply blast
using vc_prems(2) by auto
|
module Doc
||| World!
export
world : Nat -> Nat
world x = x*2
nope : Nat
nope = 0
export
||| Hello!
hello : Int -> Int
hello x = x*2
public export
data WrappedInt : Type where
MkWrappedInt : Int -> WrappedInt
public export
record SimpleRec where
constructor MkSimpleRec
a : Int
b : String
namespace NS
namespace NestedNS
||| A type of Foo
Foo : Type
Foo = ()
|
Galveston is the home of several of the largest teaching hospitals in the state , located on the campus of the University of Texas Medical Branch at Galveston . Prior to Hurricane Ike , the University employed more than 12 @,@ 000 people . Its significant growth in the 1970s and 1980s was attributable to a uniquely qualified management and medical faculty including : Mr. John Thompson ; Dr. William James <unk> , Dr. William Levin , Dr. David <unk> and many more .
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import Init.Data.UInt
@[inline, reducible] def isValidChar (n : UInt32) : Prop :=
n < 0xd800 ∨ (0xdfff < n ∧ n < 0x110000)
namespace Char
protected def lt (a b : Char) : Prop := a.val < b.val
protected def le (a b : Char) : Prop := a.val ≤ b.val
instance : LT Char := ⟨Char.lt⟩
instance : LE Char := ⟨Char.le⟩
instance (a b : Char) : Decidable (a < b) :=
UInt32.decLt _ _
instance (a b : Char) : Decidable (a ≤ b) :=
UInt32.decLe _ _
abbrev isValidCharNat (n : Nat) : Prop :=
n < 0xd800 ∨ (0xdfff < n ∧ n < 0x110000)
theorem isValidUInt32 (n : Nat) (h : isValidCharNat n) : n < UInt32.size := by
match h with
| Or.inl h =>
apply Nat.lt_trans h
decide
| Or.inr ⟨h₁, h₂⟩ =>
apply Nat.lt_trans h₂
decide
theorem isValidChar_of_isValidChar_Nat (n : Nat) (h : isValidCharNat n) : isValidChar (UInt32.ofNat' n (isValidUInt32 n h)) :=
match h with
| Or.inl h => Or.inl h
| Or.inr ⟨h₁, h₂⟩ => Or.inr ⟨h₁, h₂⟩
theorem isValidChar_zero : isValidChar 0 :=
Or.inl (by decide)
@[inline] def toNat (c : Char) : Nat :=
c.val.toNat
instance : Inhabited Char where
default := 'A'
def isWhitespace (c : Char) : Bool :=
c = ' ' || c = '\t' || c = '\r' || c = '\n'
def isUpper (c : Char) : Bool :=
c.val ≥ 65 && c.val ≤ 90
def isLower (c : Char) : Bool :=
c.val ≥ 97 && c.val ≤ 122
def isAlpha (c : Char) : Bool :=
c.isUpper || c.isLower
def isDigit (c : Char) : Bool :=
c.val ≥ 48 && c.val ≤ 57
def isAlphanum (c : Char) : Bool :=
c.isAlpha || c.isDigit
def toLower (c : Char) : Char :=
let n := toNat c;
if n >= 65 ∧ n <= 90 then ofNat (n + 32) else c
def toUpper (c : Char) : Char :=
let n := toNat c;
if n >= 97 ∧ n <= 122 then ofNat (n - 32) else c
end Char
|
{-
This file contains:
- Definitions equivalences
- Glue types
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Core.Glue where
open import Cubical.Core.Primitives
open import Agda.Builtin.Cubical.Glue public
using ( isEquiv -- ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ ⊔ ℓ')
; equiv-proof -- ∀ (y : B) → isContr (fiber f y)
; _≃_ -- ∀ {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') → Type (ℓ ⊔ ℓ')
; equivFun -- ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → A ≃ B → A → B
; equivProof -- ∀ {ℓ ℓ'} (T : Type ℓ) (A : Type ℓ') (w : T ≃ A) (a : A) φ →
-- Partial φ (fiber (equivFun w) a) → fiber (equivFun w) a
; primGlue -- ∀ {ℓ ℓ'} (A : Type ℓ) {φ : I} (T : Partial φ (Type ℓ'))
-- → (e : PartialP φ (λ o → T o ≃ A)) → Type ℓ'
; prim^unglue -- ∀ {ℓ ℓ'} {A : Type ℓ} {φ : I} {T : Partial φ (Type ℓ')}
-- → {e : PartialP φ (λ o → T o ≃ A)} → primGlue A T e → A
-- The ∀ operation on I. This is commented out as it is not currently used for anything
-- ; primFaceForall -- (I → I) → I
)
renaming ( prim^glue to glue -- ∀ {ℓ ℓ'} {A : Type ℓ} {φ : I} {T : Partial φ (Type ℓ')}
-- → {e : PartialP φ (λ o → T o ≃ A)}
-- → PartialP φ T → A → primGlue A T e
; pathToEquiv to lineToEquiv -- ∀ {ℓ : I → Level} (P : (i : I) → Type (ℓ i)) → P i0 ≃ P i1
)
private
variable
ℓ ℓ' : Level
-- Uncurry Glue to make it more pleasant to use
Glue : (A : Type ℓ) {φ : I}
→ (Te : Partial φ (Σ[ T ∈ Type ℓ' ] T ≃ A))
→ Type ℓ'
Glue A Te = primGlue A (λ x → Te x .fst) (λ x → Te x .snd)
-- Make the φ argument of prim^unglue explicit
unglue : {A : Type ℓ} (φ : I) {T : Partial φ (Type ℓ')}
{e : PartialP φ (λ o → T o ≃ A)} → primGlue A T e → A
unglue φ = prim^unglue {φ = φ}
|
set_option synthInstance.etaExperiment true -- TODO: make work by default
class NonUnitalNonAssocSemiring (α : Type u)
class NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α
class Semiring (α : Type u) extends NonUnitalSemiring α
class NonUnitalCommSemiring (α : Type u) extends NonUnitalSemiring α
class CommSemiring (R : Type u) extends Semiring R
class NonUnitalNonAssocRing (α : Type u) extends NonUnitalNonAssocSemiring α
class NonUnitalRing (α : Type _) extends NonUnitalNonAssocRing α, NonUnitalSemiring α
class Ring (R : Type u) extends Semiring R
class NonUnitalCommRing (α : Type u) extends NonUnitalRing α
class CommRing (α : Type u) extends Ring α
instance (priority := 100) NonUnitalCommRing.toNonUnitalCommSemiring [s : NonUnitalCommRing α] :
NonUnitalCommSemiring α :=
{ s with }
instance (priority := 100) CommRing.toCommSemiring [s : CommRing α] : CommSemiring α :=
{ s with }
instance (priority := 100) CommSemiring.toNonUnitalCommSemiring [s : CommSemiring α] :
NonUnitalCommSemiring α :=
{ s with }
instance (priority := 100) CommRing.toNonUnitalCommRing [s : CommRing α] : NonUnitalCommRing α :=
{ s with }
class StarRing' (R : Type _) [NonUnitalSemiring R]
def starGizmo [CommSemiring R] [StarRing' R] : R → R := id
theorem starGizmo_foo [CommRing R] [StarRing' R] (x : R) : starGizmo x = x := rfl
namespace ReidMWE
class A (α : Type u)
class B (α : Type u) extends A α
class C (α : Type u) extends B α
class D (α : Type u) extends B α
class E (α : Type u) extends C α, D α
class F (α : Type u) extends A α
class G (α : Type u) extends F α, B α
class H (α : Type u) extends C α
class I (α : Type u) extends G α, D α
class J (α : Type u) extends H α, I α, E α
class StarRing' (R : Type 0) [B R]
def starGizmo [E R] [StarRing' R] : R → R := id
theorem starGizmo_foo [J R] [StarRing' R] (x : R) : starGizmo x = x := rfl
theorem T (i : J R) : (@D.toB.{0} R (@E.toD.{0} R (@J.toE.{0} R i))) = i.toB := rfl
|
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
! This file was ported from Lean 3 source module topology.algebra.module.simple
! leanprover-community/mathlib commit f430769b562e0cedef59ee1ed968d67e0e0c86ba
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.RingTheory.SimpleModule
import Mathbin.Topology.Algebra.Module.Basic
/-!
# The kernel of a linear function is closed or dense
In this file we prove (`linear_map.is_closed_or_dense_ker`) that the kernel of a linear function `f
: M →ₗ[R] N` is either closed or dense in `M` provided that `N` is a simple module over `R`. This
applies, e.g., to the case when `R = N` is a division ring.
-/
universe u v w
variable {R : Type u} {M : Type v} {N : Type w} [Ring R] [TopologicalSpace R] [TopologicalSpace M]
[AddCommGroup M] [AddCommGroup N] [Module R M] [ContinuousSMul R M] [Module R N] [ContinuousAdd M]
[IsSimpleModule R N]
/-- The kernel of a linear map taking values in a simple module over the base ring is closed or
dense. Applies, e.g., to the case when `R = N` is a division ring. -/
theorem LinearMap.isClosed_or_dense_ker (l : M →ₗ[R] N) :
IsClosed (l.ker : Set M) ∨ Dense (l.ker : Set M) :=
by
rcases l.surjective_or_eq_zero with (hl | rfl)
· exact l.ker.is_closed_or_dense_of_is_coatom (LinearMap.isCoatom_ker_of_surjective hl)
· rw [LinearMap.ker_zero]
left
exact isClosed_univ
#align linear_map.is_closed_or_dense_ker LinearMap.isClosed_or_dense_ker
|
lemmas isCont_Re [simp] = bounded_linear.isCont [OF bounded_linear_Re] |
[GOAL]
⊢ Inhabited RelCat
[PROOFSTEP]
unfold RelCat
[GOAL]
⊢ Inhabited (Type ?u.6)
[PROOFSTEP]
infer_instance
|
[GOAL]
n : ℕ
⊢ IsReduced (ZMod n) ↔ Squarefree n ∨ n = 0
[PROOFSTEP]
rw [← RingHom.ker_isRadical_iff_reduced_of_surjective (ZMod.ringHom_surjective <| Int.castRingHom <| ZMod n),
ZMod.ker_int_castRingHom, ← isRadical_iff_span_singleton, isRadical_iff_squarefree_or_zero, Int.squarefree_coe_nat,
Nat.cast_eq_zero]
|
/-
Copyright (c) 2021 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import data.fintype.card_embedding
/-!
# Birthday Problem
This file proves Theorem 93 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).
As opposed to the standard probabilistic statement, we instead state the birthday problem
in terms of injective functions. The general result about `fintype.card (α ↪ β)` which this proof
uses is `fintype.card_embedding_eq`.
-/
local notation `‖` x `‖` := fintype.card x
/-- **Birthday Problem** -/
theorem birthday :
2 * ‖fin 23 ↪ fin 365‖ < ‖fin 23 → fin 365‖ ∧ 2 * ‖fin 22 ↪ fin 365‖ > ‖fin 22 → fin 365‖ :=
begin
simp only [nat.desc_factorial, fintype.card_fin, fintype.card_embedding_eq, fintype.card_fun],
norm_num
end
|
#' rexp
#'
#' Generate from a exponential distribution using a gpu.
#'
#' @details
#' We use the cuRAND uniform generator together with the fact that if
#' \eqn{X \sim U(0, 1)} then \eqn{Y = -\lambda^{-1}\log(X) \sim Exp(\lambda)}.
#'
#' @param n
#' The number of values to generate
#' @param rate
#' Parameter for exponential random variables.
#' @param seed
#' Seed for the random number generation.
#' @param type
#' 'double' or 'float'
#'
#' @references
#' Casella, G. and Berger, R.L., 2002. Statistical inference (Vol. 2). Pacific
#' Grove, CA: Duxbury.
#'
#' Rizzo, M.L., 2007. Statistical computing with R. Chapman and Hall/CRC.
#'
#' @useDynLib curand R_curand_rexp
#' @export
rexp = function(n, rate=1, seed=getseed(), type="double")
{
type = match.arg(tolower(type), c("double", "float"))
type = ifelse(type == "double", TYPE_DOUBLE, TYPE_FLOAT)
if (n < 0)
stop("invalid arguments")
else if (n == 0)
{
if (type == TYPE_DOUBLE)
return(numeric(0))
else
return(float(0))
}
n1 = floor(sqrt(n))
n2 = n - n1*n1
if (rate < 0 || is.badval(rate))
{
warning("NAs produced")
ret = setnan(n1, n2, type)
}
else
ret = .Call(R_curand_rexp, as.integer(n1), as.integer(n2), as.double(rate), as.integer(seed), type)
if (type == TYPE_DOUBLE)
ret
else
float32(ret)
}
|
[GOAL]
a b : ℕ+
⊢ card (Icc a b) = ↑b + 1 - ↑a
[PROOFSTEP]
rw [← Nat.card_Icc]
-- porting note: I had to change this to `erw` *and* provide the proof, yuck.
-- https://github.com/leanprover-community/mathlib4/issues/5164
[GOAL]
a b : ℕ+
⊢ card (Icc a b) = card (Icc ↑a ↑b)
[PROOFSTEP]
erw [← Finset.map_subtype_embedding_Icc _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)]
[GOAL]
a b : ℕ+
⊢ card (Icc a b) = card (map (Embedding.subtype fun n => 0 < n) (Icc a b))
[PROOFSTEP]
rw [card_map]
[GOAL]
a b : ℕ+
⊢ card (Ico a b) = ↑b - ↑a
[PROOFSTEP]
rw [← Nat.card_Ico]
-- porting note: I had to change this to `erw` *and* provide the proof, yuck.
-- https://github.com/leanprover-community/mathlib4/issues/5164
[GOAL]
a b : ℕ+
⊢ card (Ico a b) = card (Ico ↑a ↑b)
[PROOFSTEP]
erw [← Finset.map_subtype_embedding_Ico _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)]
[GOAL]
a b : ℕ+
⊢ card (Ico a b) = card (map (Embedding.subtype fun n => 0 < n) (Ico a b))
[PROOFSTEP]
rw [card_map]
[GOAL]
a b : ℕ+
⊢ card (Ioc a b) = ↑b - ↑a
[PROOFSTEP]
rw [← Nat.card_Ioc]
-- porting note: I had to change this to `erw` *and* provide the proof, yuck.
-- https://github.com/leanprover-community/mathlib4/issues/5164
[GOAL]
a b : ℕ+
⊢ card (Ioc a b) = card (Ioc ↑a ↑b)
[PROOFSTEP]
erw [← Finset.map_subtype_embedding_Ioc _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)]
[GOAL]
a b : ℕ+
⊢ card (Ioc a b) = card (map (Embedding.subtype fun n => 0 < n) (Ioc a b))
[PROOFSTEP]
rw [card_map]
[GOAL]
a b : ℕ+
⊢ card (Ioo a b) = ↑b - ↑a - 1
[PROOFSTEP]
rw [← Nat.card_Ioo]
-- porting note: I had to change this to `erw` *and* provide the proof, yuck.
-- https://github.com/leanprover-community/mathlib4/issues/5164
[GOAL]
a b : ℕ+
⊢ card (Ioo a b) = card (Ioo ↑a ↑b)
[PROOFSTEP]
erw [← Finset.map_subtype_embedding_Ioo _ a b (fun c x _ hx _ hc _ => hc.trans_le hx)]
[GOAL]
a b : ℕ+
⊢ card (Ioo a b) = card (map (Embedding.subtype fun n => 0 < n) (Ioo a b))
[PROOFSTEP]
rw [card_map]
[GOAL]
a b : ℕ+
⊢ card (uIcc a b) = Int.natAbs (↑↑b - ↑↑a) + 1
[PROOFSTEP]
rw [← Nat.card_uIcc, ← map_subtype_embedding_uIcc, card_map]
[GOAL]
a b : ℕ+
⊢ Fintype.card ↑(Set.Icc a b) = ↑b + 1 - ↑a
[PROOFSTEP]
rw [← card_Icc, Fintype.card_ofFinset]
[GOAL]
a b : ℕ+
⊢ Fintype.card ↑(Set.Ico a b) = ↑b - ↑a
[PROOFSTEP]
rw [← card_Ico, Fintype.card_ofFinset]
[GOAL]
a b : ℕ+
⊢ Fintype.card ↑(Set.Ioc a b) = ↑b - ↑a
[PROOFSTEP]
rw [← card_Ioc, Fintype.card_ofFinset]
[GOAL]
a b : ℕ+
⊢ Fintype.card ↑(Set.Ioo a b) = ↑b - ↑a - 1
[PROOFSTEP]
rw [← card_Ioo, Fintype.card_ofFinset]
[GOAL]
a b : ℕ+
⊢ Fintype.card ↑(Set.uIcc a b) = Int.natAbs (↑↑b - ↑↑a) + 1
[PROOFSTEP]
rw [← card_uIcc, Fintype.card_ofFinset]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
! This file was ported from Lean 3 source module number_theory.legendre_symbol.gauss_eisenstein_lemmas
! leanprover-community/mathlib commit e1452ef24e117a92df20b6d45f80b53cabe5a177
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.NumberTheory.LegendreSymbol.QuadraticReciprocity
/-!
# Lemmas of Gauss and Eisenstein
This file contains code for the proof of the Lemmas of Gauss and Eisenstein
on the Legendre symbol. The main results are `zmod.gauss_lemma_aux` and
`zmod.eisenstein_lemma_aux`.
-/
open Function Finset Nat FiniteField ZMod
open BigOperators Nat
namespace ZMod
section Wilson
variable (p : ℕ) [Fact p.Prime]
/-- **Wilson's Lemma**: the product of `1`, ..., `p-1` is `-1` modulo `p`. -/
@[simp]
theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 :=
by
refine'
calc
((p - 1)! : ZMod p) = ∏ x in Ico 1 (succ (p - 1)), x := by
rw [← Finset.prod_Ico_id_eq_factorial, prod_nat_cast]
_ = ∏ x : (ZMod p)ˣ, x := _
_ = -1 := by
simp_rw [← Units.coeHom_apply, ← (Units.coeHom (ZMod p)).map_prod,
prod_univ_units_id_eq_neg_one, Units.coeHom_apply, Units.val_neg, Units.val_one]
have hp : 0 < p := (Fact.out p.prime).Pos
symm
refine' prod_bij (fun a _ => (a : ZMod p).val) _ _ _ _
· intro a ha
rw [mem_Ico, ← Nat.succ_sub hp, Nat.succ_sub_one]
constructor
· apply Nat.pos_of_ne_zero
rw [← @val_zero p]
intro h
apply Units.ne_zero a (val_injective p h)
· exact val_lt _
· intro a ha
simp only [cast_id, nat_cast_val]
· intro _ _ _ _ h
rw [Units.ext_iff]
exact val_injective p h
· intro b hb
rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, succ_sub_one, pos_iff_ne_zero] at hb
refine' ⟨Units.mk0 b _, Finset.mem_univ _, _⟩
· intro h
apply hb.1
apply_fun val at h
simpa only [val_cast_of_lt hb.right, val_zero] using h
· simp only [val_cast_of_lt hb.right, Units.val_mk0]
#align zmod.wilsons_lemma ZMod.wilsons_lemma
@[simp]
theorem prod_Ico_one_prime : (∏ x in Ico 1 p, (x : ZMod p)) = -1 :=
by
conv in Ico 1 p => rw [← succ_sub_one p, succ_sub (Fact.out p.prime).Pos]
rw [← prod_nat_cast, Finset.prod_Ico_id_eq_factorial, wilsons_lemma]
#align zmod.prod_Ico_one_prime ZMod.prod_Ico_one_prime
end Wilson
end ZMod
section GaussEisenstein
namespace ZMod
/-- The image of the map sending a non zero natural number `x ≤ p / 2` to the absolute value
of the element of interger in the interval `(-p/2, p/2]` congruent to `a * x` mod p is the set
of non zero natural numbers `x` such that `x ≤ p / 2` -/
theorem Ico_map_valMinAbs_natAbs_eq_Ico_map_id (p : ℕ) [hp : Fact p.Prime] (a : ZMod p)
(hap : a ≠ 0) :
((Ico 1 (p / 2).succ).1.map fun x => (a * x).valMinAbs.natAbs) =
(Ico 1 (p / 2).succ).1.map fun a => a :=
by
have he : ∀ {x}, x ∈ Ico 1 (p / 2).succ → x ≠ 0 ∧ x ≤ p / 2 := by
simp (config := { contextual := true }) [Nat.lt_succ_iff, Nat.succ_le_iff, pos_iff_ne_zero]
have hep : ∀ {x}, x ∈ Ico 1 (p / 2).succ → x < p := fun x hx =>
lt_of_le_of_lt (he hx).2 (Nat.div_lt_self hp.1.Pos (by decide))
have hpe : ∀ {x}, x ∈ Ico 1 (p / 2).succ → ¬p ∣ x := fun x hx hpx =>
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero (he hx).1) hpx) (hep hx)
have hmem :
∀ (x : ℕ) (hx : x ∈ Ico 1 (p / 2).succ),
(a * x : ZMod p).valMinAbs.natAbs ∈ Ico 1 (p / 2).succ :=
by
intro x hx
simp [hap, CharP.cast_eq_zero_iff (ZMod p) p, hpe hx, lt_succ_iff, succ_le_iff, pos_iff_ne_zero,
nat_abs_val_min_abs_le _]
have hsurj :
∀ (b : ℕ) (hb : b ∈ Ico 1 (p / 2).succ),
∃ x ∈ Ico 1 (p / 2).succ, b = (a * x : ZMod p).valMinAbs.natAbs :=
by
intro b hb
refine' ⟨(b / a : ZMod p).valMinAbs.natAbs, mem_Ico.mpr ⟨_, _⟩, _⟩
· apply Nat.pos_of_ne_zero
simp only [div_eq_mul_inv, hap, CharP.cast_eq_zero_iff (ZMod p) p, hpe hb, not_false_iff,
val_min_abs_eq_zero, inv_eq_zero, Int.natAbs_eq_zero, Ne.def, mul_eq_zero, or_self_iff]
· apply lt_succ_of_le
apply nat_abs_val_min_abs_le
· rw [nat_cast_nat_abs_val_min_abs]
split_ifs
·
erw [mul_div_cancel' _ hap, val_min_abs_def_pos, val_cast_of_lt (hep hb),
if_pos (le_of_lt_succ (mem_Ico.1 hb).2), Int.natAbs_ofNat]
·
erw [mul_neg, mul_div_cancel' _ hap, nat_abs_val_min_abs_neg, val_min_abs_def_pos,
val_cast_of_lt (hep hb), if_pos (le_of_lt_succ (mem_Ico.1 hb).2), Int.natAbs_ofNat]
exact
Multiset.map_eq_map_of_bij_of_nodup _ _ (Finset.nodup _) (Finset.nodup _)
(fun x _ => (a * x : ZMod p).valMinAbs.natAbs) hmem (fun _ _ => rfl)
(inj_on_of_surj_on_of_card_le _ hmem hsurj le_rfl) hsurj
#align zmod.Ico_map_val_min_abs_nat_abs_eq_Ico_map_id ZMod.Ico_map_valMinAbs_natAbs_eq_Ico_map_id
private theorem gauss_lemma_aux₁ (p : ℕ) [Fact p.Prime] [Fact (p % 2 = 1)] {a : ℤ}
(hap : (a : ZMod p) ≠ 0) :
(a ^ (p / 2) * (p / 2)! : ZMod p) =
(-1) ^ ((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => ¬(a * x : ZMod p).val ≤ p / 2).card *
(p / 2)! :=
calc
(a ^ (p / 2) * (p / 2)! : ZMod p) = ∏ x in Ico 1 (p / 2).succ, a * x := by
rw [prod_mul_distrib, ← prod_nat_cast, prod_Ico_id_eq_factorial, prod_const, card_Ico,
succ_sub_one] <;>
simp
_ = ∏ x in Ico 1 (p / 2).succ, (a * x : ZMod p).val := by simp
_ =
∏ x in Ico 1 (p / 2).succ,
(if (a * x : ZMod p).val ≤ p / 2 then 1 else -1) * (a * x : ZMod p).valMinAbs.natAbs :=
(prod_congr rfl fun _ _ =>
by
simp only [nat_cast_nat_abs_val_min_abs]
split_ifs <;> simp)
_ =
(-1) ^ ((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => ¬(a * x : ZMod p).val ≤ p / 2).card *
∏ x in Ico 1 (p / 2).succ, (a * x : ZMod p).valMinAbs.natAbs :=
by
have :
(∏ x in Ico 1 (p / 2).succ, if (a * x : ZMod p).val ≤ p / 2 then (1 : ZMod p) else -1) =
∏ x in (Ico 1 (p / 2).succ).filterₓ fun x : ℕ => ¬(a * x : ZMod p).val ≤ p / 2, -1 :=
prod_bij_ne_one (fun x _ _ => x)
(fun x => by split_ifs <;> simp_all (config := { contextual := true }))
(fun _ _ _ _ _ _ => id) (fun b h _ => ⟨b, by simp_all [-not_le]⟩)
(by intros <;> split_ifs at * <;> simp_all)
rw [prod_mul_distrib, this] <;> simp
_ =
(-1) ^ ((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => ¬(a * x : ZMod p).val ≤ p / 2).card *
(p / 2)! :=
by
rw [← prod_nat_cast, Finset.prod_eq_multiset_prod,
Ico_map_val_min_abs_nat_abs_eq_Ico_map_id p a hap, ← Finset.prod_eq_multiset_prod,
prod_Ico_id_eq_factorial]
#align zmod.gauss_lemma_aux₁ zmod.gauss_lemma_aux₁
theorem gauss_lemma_aux (p : ℕ) [hp : Fact p.Prime] [Fact (p % 2 = 1)] {a : ℤ}
(hap : (a : ZMod p) ≠ 0) :
(a ^ (p / 2) : ZMod p) =
(-1) ^ ((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => p / 2 < (a * x : ZMod p).val).card :=
(mul_left_inj'
(show ((p / 2)! : ZMod p) ≠ 0 by
rw [Ne.def, CharP.cast_eq_zero_iff (ZMod p) p, hp.1.dvd_factorial, not_le] <;>
exact Nat.div_lt_self hp.1.Pos (by decide))).1 <|
by simpa using gauss_lemma_aux₁ p hap
#align zmod.gauss_lemma_aux ZMod.gauss_lemma_aux
/-- Gauss' lemma. The legendre symbol can be computed by considering the number of naturals less
than `p/2` such that `(a * x) % p > p / 2` -/
theorem gauss_lemma {p : ℕ} [Fact p.Prime] {a : ℤ} (hp : p ≠ 2) (ha0 : (a : ZMod p) ≠ 0) :
legendreSym p a =
(-1) ^ ((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => p / 2 < (a * x : ZMod p).val).card :=
by
haveI hp' : Fact (p % 2 = 1) := ⟨nat.prime.mod_two_eq_one_iff_ne_two.mpr hp⟩
have :
(legendreSym p a : ZMod p) =
(((-1) ^ ((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => p / 2 < (a * x : ZMod p).val).card : ℤ) :
ZMod p) :=
by rw [legendreSym.eq_pow, gauss_lemma_aux p ha0] <;> simp
cases legendreSym.eq_one_or_neg_one p ha0 <;>
cases
neg_one_pow_eq_or ℤ
((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => p / 2 < (a * x : ZMod p).val).card <;>
simp_all [ne_neg_self p one_ne_zero, (ne_neg_self p one_ne_zero).symm]
#align zmod.gauss_lemma ZMod.gauss_lemma
private theorem eisenstein_lemma_aux₁ (p : ℕ) [Fact p.Prime] [hp2 : Fact (p % 2 = 1)] {a : ℕ}
(hap : (a : ZMod p) ≠ 0) :
((∑ x in Ico 1 (p / 2).succ, a * x : ℕ) : ZMod 2) =
(((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => p / 2 < (a * x : ZMod p).val).card +
∑ x in Ico 1 (p / 2).succ, x) +
(∑ x in Ico 1 (p / 2).succ, a * x / p : ℕ) :=
have hp2 : (p : ZMod 2) = (1 : ℕ) := (eq_iff_modEq_nat _).2 hp2.1
calc
((∑ x in Ico 1 (p / 2).succ, a * x : ℕ) : ZMod 2) =
((∑ x in Ico 1 (p / 2).succ, a * x % p + p * (a * x / p) : ℕ) : ZMod 2) :=
by simp only [mod_add_div]
_ =
(∑ x in Ico 1 (p / 2).succ, ((a * x : ℕ) : ZMod p).val : ℕ) +
(∑ x in Ico 1 (p / 2).succ, a * x / p : ℕ) :=
by
simp only [val_nat_cast] <;>
simp [sum_add_distrib, mul_sum.symm, Nat.cast_add, Nat.cast_mul, Nat.cast_sum, hp2]
_ = _ :=
congr_arg₂ (· + ·)
(calc
((∑ x in Ico 1 (p / 2).succ, ((a * x : ℕ) : ZMod p).val : ℕ) : ZMod 2) =
∑ x in Ico 1 (p / 2).succ,
(((a * x : ZMod p).valMinAbs + if (a * x : ZMod p).val ≤ p / 2 then 0 else p : ℤ) :
ZMod 2) :=
by simp only [(val_eq_ite_val_min_abs _).symm] <;> simp [Nat.cast_sum]
_ =
((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => p / 2 < (a * x : ZMod p).val).card +
(∑ x in Ico 1 (p / 2).succ, (a * x : ZMod p).valMinAbs.natAbs : ℕ) :=
by simp [ite_cast, add_comm, sum_add_distrib, Finset.sum_ite, hp2, Nat.cast_sum]
_ = _ := by
rw [Finset.sum_eq_multiset_sum, Ico_map_val_min_abs_nat_abs_eq_Ico_map_id p a hap, ←
Finset.sum_eq_multiset_sum] <;>
simp [Nat.cast_sum]
)
rfl
#align zmod.eisenstein_lemma_aux₁ zmod.eisenstein_lemma_aux₁
theorem eisenstein_lemma_aux (p : ℕ) [Fact p.Prime] [Fact (p % 2 = 1)] {a : ℕ} (ha2 : a % 2 = 1)
(hap : (a : ZMod p) ≠ 0) :
((Ico 1 (p / 2).succ).filterₓ fun x : ℕ => p / 2 < (a * x : ZMod p).val).card ≡
∑ x in Ico 1 (p / 2).succ, x * a / p [MOD 2] :=
have ha2 : (a : ZMod 2) = (1 : ℕ) := (eq_iff_modEq_nat _).2 ha2
(eq_iff_modEq_nat 2).1 <|
sub_eq_zero.1 <| by
simpa [add_left_comm, sub_eq_add_neg, finset.mul_sum.symm, mul_comm, ha2, Nat.cast_sum,
add_neg_eq_iff_eq_add.symm, neg_eq_self_mod_two, add_assoc] using
Eq.symm (eisenstein_lemma_aux₁ p hap)
#align zmod.eisenstein_lemma_aux ZMod.eisenstein_lemma_aux
theorem div_eq_filter_card {a b c : ℕ} (hb0 : 0 < b) (hc : a / b ≤ c) :
a / b = ((Ico 1 c.succ).filterₓ fun x => x * b ≤ a).card :=
calc
a / b = (Ico 1 (a / b).succ).card := by simp
_ = ((Ico 1 c.succ).filterₓ fun x => x * b ≤ a).card :=
congr_arg _ <|
Finset.ext fun x =>
by
have : x * b ≤ a → x ≤ c := fun h => le_trans (by rwa [le_div_iff_mul_le hb0]) hc
simp [lt_succ_iff, le_div_iff_mul_le hb0] <;> tauto
#align zmod.div_eq_filter_card ZMod.div_eq_filter_card
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/-- The given sum is the number of integer points in the triangle formed by the diagonal of the
rectangle `(0, p/2) × (0, q/2)` -/
private theorem sum_Ico_eq_card_lt {p q : ℕ} :
(∑ a in Ico 1 (p / 2).succ, a * q / p) =
((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filterₓ fun x : ℕ × ℕ =>
x.2 * p ≤ x.1 * q).card :=
if hp0 : p = 0 then by simp [hp0, Finset.ext_iff]
else
calc
(∑ a in Ico 1 (p / 2).succ, a * q / p) =
∑ a in Ico 1 (p / 2).succ, ((Ico 1 (q / 2).succ).filterₓ fun x => x * p ≤ a * q).card :=
Finset.sum_congr rfl fun x hx =>
div_eq_filter_card (Nat.pos_of_ne_zero hp0)
(calc
x * q / p ≤ p / 2 * q / p :=
Nat.div_le_div_right
(mul_le_mul_of_nonneg_right (le_of_lt_succ <| (mem_Ico.mp hx).2) (Nat.zero_le _))
_ ≤ _ := Nat.div_mul_div_le_div _ _ _
)
_ = _ := by
rw [← card_sigma] <;>
exact
card_congr (fun a _ => ⟨a.1, a.2⟩)
(by
simp (config := { contextual := true }) only [mem_filter, mem_sigma, and_self_iff,
forall_true_iff, mem_product])
(fun ⟨_, _⟩ ⟨_, _⟩ => by
simp (config := { contextual := true }) only [Prod.mk.inj_iff, eq_self_iff_true,
and_self_iff, heq_iff_eq, forall_true_iff])
fun ⟨b₁, b₂⟩ h =>
⟨⟨b₁, b₂⟩, by
revert h <;>
simp (config := { contextual := true }) only [mem_filter, eq_self_iff_true,
exists_prop_of_true, mem_sigma, and_self_iff, forall_true_iff, mem_product]⟩
#align zmod.sum_Ico_eq_card_lt zmod.sum_Ico_eq_card_lt
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/-- Each of the sums in this lemma is the cardinality of the set integer points in each of the
two triangles formed by the diagonal of the rectangle `(0, p/2) × (0, q/2)`. Adding them
gives the number of points in the rectangle. -/
theorem sum_mul_div_add_sum_mul_div_eq_mul (p q : ℕ) [hp : Fact p.Prime] (hq0 : (q : ZMod p) ≠ 0) :
((∑ a in Ico 1 (p / 2).succ, a * q / p) + ∑ a in Ico 1 (q / 2).succ, a * p / q) =
p / 2 * (q / 2) :=
by
have hswap :
((Ico 1 (q / 2).succ ×ˢ Ico 1 (p / 2).succ).filterₓ fun x : ℕ × ℕ => x.2 * q ≤ x.1 * p).card =
((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filterₓ fun x : ℕ × ℕ =>
x.1 * q ≤ x.2 * p).card :=
card_congr (fun x _ => Prod.swap x)
(fun ⟨_, _⟩ => by
simp (config := { contextual := true }) only [mem_filter, and_self_iff, Prod.swap_prod_mk,
forall_true_iff, mem_product])
(fun ⟨_, _⟩ ⟨_, _⟩ => by
simp (config := { contextual := true }) only [Prod.mk.inj_iff, eq_self_iff_true,
and_self_iff, Prod.swap_prod_mk, forall_true_iff])
fun ⟨x₁, x₂⟩ h =>
⟨⟨x₂, x₁⟩, by
revert h <;>
simp (config := { contextual := true }) only [mem_filter, eq_self_iff_true, and_self_iff,
exists_prop_of_true, Prod.swap_prod_mk, forall_true_iff, mem_product]⟩
have hdisj :
Disjoint ((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filterₓ fun x : ℕ × ℕ => x.2 * p ≤ x.1 * q)
((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filterₓ fun x : ℕ × ℕ => x.1 * q ≤ x.2 * p) :=
by
apply disjoint_filter.2 fun x hx hpq hqp => _
have hxp : x.1 < p :=
lt_of_le_of_lt
(show x.1 ≤ p / 2 by simp_all only [lt_succ_iff, mem_Ico, mem_product] <;> tauto)
(Nat.div_lt_self hp.1.Pos (by decide))
have : (x.1 : ZMod p) = 0 := by
simpa [hq0] using congr_arg (coe : ℕ → ZMod p) (le_antisymm hpq hqp)
apply_fun ZMod.val at this
rw [val_cast_of_lt hxp, val_zero] at this
simpa only [this, nonpos_iff_eq_zero, mem_Ico, one_ne_zero, false_and_iff, mem_product] using hx
have hunion :
(((Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filterₓ fun x : ℕ × ℕ => x.2 * p ≤ x.1 * q) ∪
(Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ).filterₓ fun x : ℕ × ℕ => x.1 * q ≤ x.2 * p) =
Ico 1 (p / 2).succ ×ˢ Ico 1 (q / 2).succ :=
Finset.ext fun x => by
have := le_total (x.2 * p) (x.1 * q) <;>
simp only [mem_union, mem_filter, mem_Ico, mem_product] <;>
tauto
rw [sum_Ico_eq_card_lt, sum_Ico_eq_card_lt, hswap, ← card_disjoint_union hdisj, hunion,
card_product]
simp only [card_Ico, tsub_zero, succ_sub_succ_eq_sub]
#align zmod.sum_mul_div_add_sum_mul_div_eq_mul ZMod.sum_mul_div_add_sum_mul_div_eq_mul
theorem eisenstein_lemma {p : ℕ} [Fact p.Prime] (hp : p ≠ 2) {a : ℕ} (ha1 : a % 2 = 1)
(ha0 : (a : ZMod p) ≠ 0) : legendreSym p a = (-1) ^ ∑ x in Ico 1 (p / 2).succ, x * a / p :=
by
haveI hp' : Fact (p % 2 = 1) := ⟨nat.prime.mod_two_eq_one_iff_ne_two.mpr hp⟩
have ha0' : ((a : ℤ) : ZMod p) ≠ 0 := by
norm_cast
exact ha0
rw [neg_one_pow_eq_pow_mod_two, gauss_lemma hp ha0', neg_one_pow_eq_pow_mod_two,
(by norm_cast : ((a : ℤ) : ZMod p) = (a : ZMod p)),
show _ = _ from eisenstein_lemma_aux p ha1 ha0]
#align zmod.eisenstein_lemma ZMod.eisenstein_lemma
end ZMod
end GaussEisenstein
|
[GOAL]
α : Type u
T : Set (Set α)
empty_mem : ∅ ∈ T
sInter_mem : ∀ (A : Set (Set α)), A ⊆ T → ⋂₀ A ∈ T
union_mem : ∀ (A : Set α), A ∈ T → ∀ (B : Set α), B ∈ T → A ∪ B ∈ T
⊢ (fun X => Xᶜ ∈ T) univ
[PROOFSTEP]
simp [empty_mem]
[GOAL]
α : Type u
T : Set (Set α)
empty_mem : ∅ ∈ T
sInter_mem : ∀ (A : Set (Set α)), A ⊆ T → ⋂₀ A ∈ T
union_mem : ∀ (A : Set α), A ∈ T → ∀ (B : Set α), B ∈ T → A ∪ B ∈ T
s t : Set α
hs : (fun X => Xᶜ ∈ T) s
ht : (fun X => Xᶜ ∈ T) t
⊢ (fun X => Xᶜ ∈ T) (s ∩ t)
[PROOFSTEP]
simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht
[GOAL]
α : Type u
T : Set (Set α)
empty_mem : ∅ ∈ T
sInter_mem : ∀ (A : Set (Set α)), A ⊆ T → ⋂₀ A ∈ T
union_mem : ∀ (A : Set α), A ∈ T → ∀ (B : Set α), B ∈ T → A ∪ B ∈ T
s : Set (Set α)
hs : ∀ (t : Set α), t ∈ s → (fun X => Xᶜ ∈ T) t
⊢ (fun X => Xᶜ ∈ T) (⋃₀ s)
[PROOFSTEP]
simp only [Set.compl_sUnion]
[GOAL]
α : Type u
T : Set (Set α)
empty_mem : ∅ ∈ T
sInter_mem : ∀ (A : Set (Set α)), A ⊆ T → ⋂₀ A ∈ T
union_mem : ∀ (A : Set α), A ∈ T → ∀ (B : Set α), B ∈ T → A ∪ B ∈ T
s : Set (Set α)
hs : ∀ (t : Set α), t ∈ s → (fun X => Xᶜ ∈ T) t
⊢ ⋂₀ (compl '' s) ∈ T
[PROOFSTEP]
exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
t t' : TopologicalSpace α
h : ∀ (s : Set α), IsOpen s ↔ IsOpen s
⊢ t = t'
[PROOFSTEP]
ext
[GOAL]
case a.h.a
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
t t' : TopologicalSpace α
h : ∀ (s : Set α), IsOpen s ↔ IsOpen s
x✝ : Set α
⊢ IsOpen x✝ ↔ IsOpen x✝
[PROOFSTEP]
exact h _
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
h₁ : IsOpen s₁
h₂ : IsOpen s₂
⊢ IsOpen (s₁ ∪ s₂)
[PROOFSTEP]
rw [union_eq_iUnion]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
h₁ : IsOpen s₁
h₂ : IsOpen s₂
⊢ IsOpen (⋃ (b : Bool), bif b then s₁ else s₂)
[PROOFSTEP]
exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩)
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
⊢ IsOpen ∅
[PROOFSTEP]
rw [← sUnion_empty]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
⊢ IsOpen (⋃₀ ∅)
[PROOFSTEP]
exact isOpen_sUnion fun a => False.elim
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set (Set α)
hs : Set.Finite s
x✝ : ∀ (t : Set α), t ∈ ∅ → IsOpen t
⊢ IsOpen (⋂₀ ∅)
[PROOFSTEP]
rw [sInter_empty]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set (Set α)
hs : Set.Finite s
x✝ : ∀ (t : Set α), t ∈ ∅ → IsOpen t
⊢ IsOpen univ
[PROOFSTEP]
exact isOpen_univ
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝¹ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set (Set α)
hs : Set.Finite s
a✝ : Set α
s✝ : Set (Set α)
x✝¹ : ¬a✝ ∈ s✝
x✝ : Set.Finite s✝
ih : (∀ (t : Set α), t ∈ s✝ → IsOpen t) → IsOpen (⋂₀ s✝)
h : ∀ (t : Set α), t ∈ insert a✝ s✝ → IsOpen t
⊢ IsOpen (⋂₀ insert a✝ s✝)
[PROOFSTEP]
simp only [sInter_insert, ball_insert_iff] at h ⊢
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝¹ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set (Set α)
hs : Set.Finite s
a✝ : Set α
s✝ : Set (Set α)
x✝¹ : ¬a✝ ∈ s✝
x✝ : Set.Finite s✝
ih : (∀ (t : Set α), t ∈ s✝ → IsOpen t) → IsOpen (⋂₀ s✝)
h : IsOpen a✝ ∧ ∀ (x : Set α), x ∈ s✝ → IsOpen x
⊢ IsOpen (a✝ ∩ ⋂₀ s✝)
[PROOFSTEP]
exact h.1.inter (ih h.2)
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p : Prop
⊢ IsOpen {_a | p}
[PROOFSTEP]
by_cases p
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p : Prop
⊢ IsOpen {_a | p}
[PROOFSTEP]
by_cases p
[GOAL]
case pos
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p : Prop
h : p
⊢ IsOpen {_a | p}
[PROOFSTEP]
simp [*]
[GOAL]
case neg
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p : Prop
h : ¬p
⊢ IsOpen {_a | p}
[PROOFSTEP]
simp [*]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
⊢ IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂)
[PROOFSTEP]
simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set (Set α)
⊢ (∀ (t : Set α), t ∈ s → IsClosed t) → IsClosed (⋂₀ s)
[PROOFSTEP]
simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ IsClosed sᶜ ↔ IsOpen s
[PROOFSTEP]
rw [← isOpen_compl_iff, compl_compl]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
h₁ : IsClosed s₁
h₂ : IsClosed s₂
⊢ IsClosed (s₁ ∩ s₂)
[PROOFSTEP]
rw [← isOpen_compl_iff] at *
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
h₁ : IsOpen s₁ᶜ
h₂ : IsOpen s₂ᶜ
⊢ IsOpen (s₁ ∩ s₂)ᶜ
[PROOFSTEP]
rw [compl_inter]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
h₁ : IsOpen s₁ᶜ
h₂ : IsOpen s₂ᶜ
⊢ IsOpen (s₁ᶜ ∪ s₂ᶜ)
[PROOFSTEP]
exact IsOpen.union h₁ h₂
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set β
f : β → Set α
hs : Set.Finite s
h : ∀ (i : β), i ∈ s → IsClosed (f i)
⊢ IsClosed (⋃ (i : β) (_ : i ∈ s), f i)
[PROOFSTEP]
simp only [← isOpen_compl_iff, compl_iUnion] at *
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set β
f : β → Set α
hs : Set.Finite s
h : ∀ (i : β), i ∈ s → IsOpen (f i)ᶜ
⊢ IsOpen (⋂ (i : β) (_ : i ∈ s), (f i)ᶜ)
[PROOFSTEP]
exact isOpen_biInter hs h
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
inst✝ : Finite ι
s : ι → Set α
h : ∀ (i : ι), IsClosed (s i)
⊢ IsClosed (⋃ (i : ι), s i)
[PROOFSTEP]
simp only [← isOpen_compl_iff, compl_iUnion] at *
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
inst✝ : Finite ι
s : ι → Set α
h : ∀ (i : ι), IsOpen (s i)ᶜ
⊢ IsOpen (⋂ (i : ι), (s i)ᶜ)
[PROOFSTEP]
exact isOpen_iInter h
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p q : α → Prop
hp : IsOpen {x | p x}
hq : IsClosed {x | q x}
⊢ IsClosed {x | p x → q x}
[PROOFSTEP]
simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
x : α
⊢ x ∈ interior s ↔ ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t
[PROOFSTEP]
simp only [interior, mem_sUnion, mem_setOf_eq, and_assoc, and_left_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ s ⊆ interior s ↔ IsOpen s
[PROOFSTEP]
simp only [interior_eq_iff_isOpen.symm, Subset.antisymm_iff, interior_subset, true_and]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ interior (⋂ (i : ι) (_ : i ∈ s), f i) = ⋂ (i : ι) (_ : i ∈ s), interior (f i)
[PROOFSTEP]
classical
refine' s.induction_on (by simp) _
intro i s _ h₂
simp [h₂]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ interior (⋂ (i : ι) (_ : i ∈ s), f i) = ⋂ (i : ι) (_ : i ∈ s), interior (f i)
[PROOFSTEP]
refine' s.induction_on (by simp) _
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ interior (⋂ (i : ι) (_ : i ∈ ∅), f i) = ⋂ (i : ι) (_ : i ∈ ∅), interior (f i)
[PROOFSTEP]
simp
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ ∀ ⦃a : ι⦄ {s : Finset ι},
¬a ∈ s →
interior (⋂ (i : ι) (_ : i ∈ s), f i) = ⋂ (i : ι) (_ : i ∈ s), interior (f i) →
interior (⋂ (i : ι) (_ : i ∈ insert a s), f i) = ⋂ (i : ι) (_ : i ∈ insert a s), interior (f i)
[PROOFSTEP]
intro i s _ h₂
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝¹ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s✝ : Finset ι
f : ι → Set α
i : ι
s : Finset ι
a✝ : ¬i ∈ s
h₂ : interior (⋂ (i : ι) (_ : i ∈ s), f i) = ⋂ (i : ι) (_ : i ∈ s), interior (f i)
⊢ interior (⋂ (i_1 : ι) (_ : i_1 ∈ insert i s), f i_1) = ⋂ (i_1 : ι) (_ : i_1 ∈ insert i s), interior (f i_1)
[PROOFSTEP]
simp [h₂]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
⊢ interior (⋂ (i : ι), f i) = ⋂ (i : ι), interior (f i)
[PROOFSTEP]
cases nonempty_fintype ι
[GOAL]
case intro
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
val✝ : Fintype ι
⊢ interior (⋂ (i : ι), f i) = ⋂ (i : ι), interior (f i)
[PROOFSTEP]
convert Finset.univ.interior_iInter f
[GOAL]
case h.e'_2.h.e'_3.h.e'_3.h
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
val✝ : Fintype ι
x✝ : ι
⊢ f x✝ = ⋂ (_ : x✝ ∈ Finset.univ), f x✝
[PROOFSTEP]
simp
[GOAL]
case h.e'_3.h.e'_3.h
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
val✝ : Fintype ι
x✝ : ι
⊢ interior (f x✝) = ⋂ (_ : x✝ ∈ Finset.univ), interior (f x✝)
[PROOFSTEP]
simp
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
h₁ : IsClosed s
h₂ : interior t = ∅
x : α
x✝ : x ∈ interior (s ∪ t)
u : Set α
hu₁ : IsOpen u
hu₂ : u ⊆ s ∪ t
hx₁ : x ∈ u
hx₂ : ¬x ∈ s
this : u \ s ⊆ t
⊢ u \ s ⊆ interior t
[PROOFSTEP]
rwa [(IsOpen.sdiff hu₁ h₁).subset_interior_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
h₁ : IsClosed s
h₂ : interior t = ∅
x : α
x✝ : x ∈ interior (s ∪ t)
u : Set α
hu₁ : IsOpen u
hu₂ : u ⊆ s ∪ t
hx₁ : x ∈ u
hx₂ : ¬x ∈ s
this✝ : u \ s ⊆ t
this : u \ s ⊆ interior t
⊢ u \ s ⊆ ∅
[PROOFSTEP]
rwa [h₂] at this
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
⊢ IsOpen s ↔ ∀ (x : α), x ∈ s → ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t
[PROOFSTEP]
rw [← subset_interior_iff_isOpen]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
⊢ s ⊆ interior s ↔ ∀ (x : α), x ∈ s → ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t
[PROOFSTEP]
simp only [subset_def, mem_interior]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
S : Set (Set α)
⊢ interior (⋂₀ S) = interior (⋂ (s : Set α) (_ : s ∈ S), s)
[PROOFSTEP]
rw [sInter_eq_biInter]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
⊢ s \ t ⊆ closure t ↔ s ⊆ closure t
[PROOFSTEP]
rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : closure s ⊆ s
⊢ IsClosed s
[PROOFSTEP]
rw [subset_closure.antisymm h]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : closure s ⊆ s
⊢ IsClosed (closure s)
[PROOFSTEP]
exact isClosed_closure
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ Set.Nonempty (closure s) ↔ Set.Nonempty s
[PROOFSTEP]
simp only [nonempty_iff_ne_empty, Ne.def, closure_empty_iff]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ closure (⋃ (i : ι) (_ : i ∈ s), f i) = ⋃ (i : ι) (_ : i ∈ s), closure (f i)
[PROOFSTEP]
classical
refine' s.induction_on (by simp) _
intro i s _ h₂
simp [h₂]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ closure (⋃ (i : ι) (_ : i ∈ s), f i) = ⋃ (i : ι) (_ : i ∈ s), closure (f i)
[PROOFSTEP]
refine' s.induction_on (by simp) _
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ closure (⋃ (i : ι) (_ : i ∈ ∅), f i) = ⋃ (i : ι) (_ : i ∈ ∅), closure (f i)
[PROOFSTEP]
simp
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s : Finset ι
f : ι → Set α
⊢ ∀ ⦃a : ι⦄ {s : Finset ι},
¬a ∈ s →
closure (⋃ (i : ι) (_ : i ∈ s), f i) = ⋃ (i : ι) (_ : i ∈ s), closure (f i) →
closure (⋃ (i : ι) (_ : i ∈ insert a s), f i) = ⋃ (i : ι) (_ : i ∈ insert a s), closure (f i)
[PROOFSTEP]
intro i s _ h₂
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s✝¹ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
s✝ : Finset ι
f : ι → Set α
i : ι
s : Finset ι
a✝ : ¬i ∈ s
h₂ : closure (⋃ (i : ι) (_ : i ∈ s), f i) = ⋃ (i : ι) (_ : i ∈ s), closure (f i)
⊢ closure (⋃ (i_1 : ι) (_ : i_1 ∈ insert i s), f i_1) = ⋃ (i_1 : ι) (_ : i_1 ∈ insert i s), closure (f i_1)
[PROOFSTEP]
simp [h₂]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
⊢ closure (⋃ (i : ι), f i) = ⋃ (i : ι), closure (f i)
[PROOFSTEP]
cases nonempty_fintype ι
[GOAL]
case intro
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
val✝ : Fintype ι
⊢ closure (⋃ (i : ι), f i) = ⋃ (i : ι), closure (f i)
[PROOFSTEP]
convert Finset.univ.closure_biUnion f
[GOAL]
case h.e'_2.h.e'_3.h.e'_3.h
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
val✝ : Fintype ι
x✝ : ι
⊢ f x✝ = ⋃ (_ : x✝ ∈ Finset.univ), f x✝
[PROOFSTEP]
simp
[GOAL]
case h.e'_3.h.e'_3.h
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
inst✝ : Finite ι
f : ι → Set α
val✝ : Fintype ι
x✝ : ι
⊢ closure (f x✝) = ⋃ (_ : x✝ ∈ Finset.univ), closure (f x✝)
[PROOFSTEP]
simp
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ closure s = (interior sᶜ)ᶜ
[PROOFSTEP]
rw [interior, closure, compl_sUnion, compl_image_set_of]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ ⋂₀ {t | IsClosed t ∧ s ⊆ t} = ⋂₀ {s_1 | IsOpen s_1ᶜ ∧ s_1ᶜ ⊆ sᶜ}
[PROOFSTEP]
simp only [compl_subset_compl, isOpen_compl_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ interior sᶜ = (closure s)ᶜ
[PROOFSTEP]
simp [closure_eq_compl_interior_compl]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ closure sᶜ = (interior s)ᶜ
[PROOFSTEP]
simp [closure_eq_compl_interior_compl]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
l : Filter α
h : l = ⊥
⊢ Filter.lift' ⊥ closure = ⊥
[PROOFSTEP]
rw [lift'_bot (monotone_closure _), closure_empty, principal_empty]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ interior s = ∅ ↔ Dense sᶜ
[PROOFSTEP]
rw [dense_iff_closure_eq, closure_compl, compl_univ_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : Dense s
⊢ Dense sᶜᶜ
[PROOFSTEP]
rwa [compl_compl]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ Dense (closure s) ↔ Dense s
[PROOFSTEP]
rw [Dense, Dense, closure_closure]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ Dense s ↔ ∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)
[PROOFSTEP]
constructor
[GOAL]
case mp
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ Dense s → ∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)
[PROOFSTEP]
intro h
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ (∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)) → Dense s
[PROOFSTEP]
intro h
[GOAL]
case mp
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : Dense s
⊢ ∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)
[PROOFSTEP]
rintro U U_op ⟨x, x_in⟩
[GOAL]
case mp.intro
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : Dense s
U : Set α
U_op : IsOpen U
x : α
x_in : x ∈ U
⊢ Set.Nonempty (U ∩ s)
[PROOFSTEP]
exact mem_closure_iff.1 (h _) U U_op x_in
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : ∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)
⊢ Dense s
[PROOFSTEP]
intro x
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : ∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)
x : α
⊢ x ∈ closure s
[PROOFSTEP]
rw [mem_closure_iff]
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : ∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)
x : α
⊢ ∀ (o : Set α), IsOpen o → x ∈ o → Set.Nonempty (o ∩ s)
[PROOFSTEP]
intro U U_op x_in
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : ∀ (U : Set α), IsOpen U → Set.Nonempty U → Set.Nonempty (U ∩ s)
x : α
U : Set α
U_op : IsOpen U
x_in : x ∈ U
⊢ Set.Nonempty (U ∩ s)
[PROOFSTEP]
exact h U U_op ⟨_, x_in⟩
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
⊢ Dense {x}ᶜ ↔ ¬IsOpen {x}
[PROOFSTEP]
constructor
[GOAL]
case mp
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
⊢ Dense {x}ᶜ → ¬IsOpen {x}
[PROOFSTEP]
intro hd ho
[GOAL]
case mp
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
hd : Dense {x}ᶜ
ho : IsOpen {x}
⊢ False
[PROOFSTEP]
exact (hd.inter_open_nonempty _ ho (singleton_nonempty _)).ne_empty (inter_compl_self _)
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
⊢ ¬IsOpen {x} → Dense {x}ᶜ
[PROOFSTEP]
refine' fun ho => dense_iff_inter_open.2 fun U hU hne => inter_compl_nonempty_iff.2 fun hUx => _
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
ho : ¬IsOpen {x}
U : Set α
hU : IsOpen U
hne : Set.Nonempty U
hUx : U ⊆ {x}
⊢ False
[PROOFSTEP]
obtain rfl : U = { x }
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
ho : ¬IsOpen {x}
U : Set α
hU : IsOpen U
hne : Set.Nonempty U
hUx : U ⊆ {x}
⊢ U = {x}
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
ho : ¬IsOpen {x}
hU : IsOpen {x}
hne : Set.Nonempty {x}
hUx : {x} ⊆ {x}
⊢ False
[PROOFSTEP]
exact eq_singleton_iff_nonempty_unique_mem.2 ⟨hne, hUx⟩
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
ho : ¬IsOpen {x}
hU : IsOpen {x}
hne : Set.Nonempty {x}
hUx : {x} ⊆ {x}
⊢ False
[PROOFSTEP]
exact ho hU
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ closure s \ frontier s = interior s
[PROOFSTEP]
rw [frontier, diff_diff_right_self, inter_eq_self_of_subset_right interior_subset_closure]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ s \ frontier s = interior s
[PROOFSTEP]
rw [frontier, diff_diff_right, diff_eq_empty.2 subset_closure, inter_eq_self_of_subset_right interior_subset,
empty_union]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ frontier s = closure s ∩ closure sᶜ
[PROOFSTEP]
rw [closure_compl, frontier, diff_eq]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ frontier sᶜ = frontier s
[PROOFSTEP]
simp only [frontier_eq_closure_inter_closure, compl_compl, inter_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
⊢ frontier univ = ∅
[PROOFSTEP]
simp [frontier]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
⊢ frontier ∅ = ∅
[PROOFSTEP]
simp [frontier]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
⊢ frontier (s ∩ t) ⊆ frontier s ∩ closure t ∪ closure s ∩ frontier t
[PROOFSTEP]
simp only [frontier_eq_closure_inter_closure, compl_inter, closure_union]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
⊢ closure (s ∩ t) ∩ (closure sᶜ ∪ closure tᶜ) ⊆
closure s ∩ closure sᶜ ∩ closure t ∪ closure s ∩ (closure t ∩ closure tᶜ)
[PROOFSTEP]
refine' (inter_subset_inter_left _ (closure_inter_subset_inter_closure s t)).trans_eq _
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
⊢ closure s ∩ closure t ∩ (closure sᶜ ∪ closure tᶜ) =
closure s ∩ closure sᶜ ∩ closure t ∪ closure s ∩ (closure t ∩ closure tᶜ)
[PROOFSTEP]
simp only [inter_distrib_left, inter_distrib_right, inter_assoc, inter_comm (closure t)]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
⊢ frontier (s ∪ t) ⊆ frontier s ∩ closure tᶜ ∪ closure sᶜ ∩ frontier t
[PROOFSTEP]
simpa only [frontier_compl, ← compl_union] using frontier_inter_subset sᶜ tᶜ
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
hs : IsClosed s
⊢ frontier s = s \ interior s
[PROOFSTEP]
rw [frontier, hs.closure_eq]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
hs : IsOpen s
⊢ frontier s = closure s \ s
[PROOFSTEP]
rw [frontier, hs.interior_eq]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
hs : IsOpen s
⊢ s ∩ frontier s = ∅
[PROOFSTEP]
rw [hs.frontier_eq, inter_diff_self]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ IsClosed (frontier s)
[PROOFSTEP]
rw [frontier_eq_closure_inter_closure]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ IsClosed (closure s ∩ closure sᶜ)
[PROOFSTEP]
exact IsClosed.inter isClosed_closure isClosed_closure
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
⊢ interior (frontier s) = ∅
[PROOFSTEP]
have A : frontier s = s \ interior s := h.frontier_eq
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
A : frontier s = s \ interior s
⊢ interior (frontier s) = ∅
[PROOFSTEP]
have B : interior (frontier s) ⊆ interior s := by rw [A]; exact interior_mono (diff_subset _ _)
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
A : frontier s = s \ interior s
⊢ interior (frontier s) ⊆ interior s
[PROOFSTEP]
rw [A]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
A : frontier s = s \ interior s
⊢ interior (s \ interior s) ⊆ interior s
[PROOFSTEP]
exact interior_mono (diff_subset _ _)
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
A : frontier s = s \ interior s
B : interior (frontier s) ⊆ interior s
⊢ interior (frontier s) = ∅
[PROOFSTEP]
have C : interior (frontier s) ⊆ frontier s := interior_subset
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
A : frontier s = s \ interior s
B : interior (frontier s) ⊆ interior s
C : interior (frontier s) ⊆ frontier s
⊢ interior (frontier s) = ∅
[PROOFSTEP]
have : interior (frontier s) ⊆ interior s ∩ (s \ interior s) := subset_inter B (by simpa [A] using C)
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
A : frontier s = s \ interior s
B : interior (frontier s) ⊆ interior s
C : interior (frontier s) ⊆ frontier s
⊢ interior (frontier s) ⊆ s \ interior s
[PROOFSTEP]
simpa [A] using C
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
h : IsClosed s
A : frontier s = s \ interior s
B : interior (frontier s) ⊆ interior s
C : interior (frontier s) ⊆ frontier s
this : interior (frontier s) ⊆ interior s ∩ (s \ interior s)
⊢ interior (frontier s) = ∅
[PROOFSTEP]
rwa [inter_diff_self, subset_empty_iff] at this
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ frontier s = (interior s)ᶜ ∩ (interior sᶜ)ᶜ
[PROOFSTEP]
rw [← frontier_compl, ← closure_compl]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ frontier sᶜ = closure sᶜ ∩ (interior sᶜ)ᶜ
[PROOFSTEP]
rfl
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ (frontier s)ᶜ = interior s ∪ interior sᶜ
[PROOFSTEP]
rw [frontier_eq_inter_compl_interior]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ ((interior s)ᶜ ∩ (interior sᶜ)ᶜ)ᶜ = interior s ∪ interior sᶜ
[PROOFSTEP]
simp only [compl_inter, compl_compl]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
⊢ 𝓝 a = ⨅ (s : Set α) (_ : IsOpen s) (_ : a ∈ s), 𝓟 s
[PROOFSTEP]
simp only [nhds_def, mem_setOf_eq, @and_comm (a ∈ _), iInf_and]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
⊢ HasBasis (𝓝 a) (fun s => a ∈ s ∧ IsOpen s) fun s => s
[PROOFSTEP]
rw [nhds_def]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
⊢ HasBasis (⨅ (s : Set α) (_ : s ∈ {s | a ∈ s ∧ IsOpen s}), 𝓟 s) (fun s => a ∈ s ∧ IsOpen s) fun s => s
[PROOFSTEP]
exact
hasBasis_biInf_principal
(fun s ⟨has, hs⟩ t ⟨hat, ht⟩ =>
⟨s ∩ t, ⟨⟨has, hat⟩, IsOpen.inter hs ht⟩, ⟨inter_subset_left _ _, inter_subset_right _ _⟩⟩)
⟨univ, ⟨mem_univ a, isOpen_univ⟩⟩
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
t : Set α
⊢ (∃ x, (a ∈ xᶜ ∧ IsOpen xᶜ) ∧ xᶜ ⊆ t) ↔ ∃ i, (¬a ∈ i ∧ IsClosed i) ∧ iᶜ ⊆ t
[PROOFSTEP]
simp only [isOpen_compl_iff, mem_compl_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
a : α
⊢ f ≤ 𝓝 a ↔ ∀ (s : Set α), a ∈ s → IsOpen s → s ∈ f
[PROOFSTEP]
simp [nhds_def]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
a : α
s : Set α
h : a ∈ s
o : IsOpen s
sf : 𝓟 s ≤ f
⊢ 𝓝 a ≤ f
[PROOFSTEP]
rw [nhds_def]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
a : α
s : Set α
h : a ∈ s
o : IsOpen s
sf : 𝓟 s ≤ f
⊢ ⨅ (s : Set α) (_ : s ∈ {s | a ∈ s ∧ IsOpen s}), 𝓟 s ≤ f
[PROOFSTEP]
exact iInf₂_le_of_le s ⟨h, o⟩ sf
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
p : α → Prop
⊢ (∃ t, t ⊆ {x | (fun x => p x) x} ∧ IsOpen t ∧ a ∈ t) ↔ ∃ t, (∀ (x : α), x ∈ t → p x) ∧ IsOpen t ∧ a ∈ t
[PROOFSTEP]
simp only [subset_def, exists_prop, mem_setOf_eq]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
⊢ HasBasis (𝓝 a) (fun s => s ∈ 𝓝 a ∧ IsOpen s) fun x => x
[PROOFSTEP]
convert nhds_basis_opens a using 2
[GOAL]
case h.e'_4.h.a
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
x✝ : Set α
⊢ x✝ ∈ 𝓝 a ∧ IsOpen x✝ ↔ a ∈ x✝ ∧ IsOpen x✝
[PROOFSTEP]
exact and_congr_left_iff.2 IsOpen.mem_nhds_iff
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s U : Set α
h : U ∈ ⨆ (x : α) (_ : x ∈ s), 𝓝 x
⊢ ∀ (x : α), x ∈ s → U ∈ 𝓝 x
[PROOFSTEP]
simpa using h
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p : α → Prop
a : α
⊢ (∃ᶠ (y : α) in 𝓝 a, ∃ᶠ (x : α) in 𝓝 y, p x) ↔ ∃ᶠ (x : α) in 𝓝 a, p x
[PROOFSTEP]
rw [← not_iff_not]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p : α → Prop
a : α
⊢ (¬∃ᶠ (y : α) in 𝓝 a, ∃ᶠ (x : α) in 𝓝 y, p x) ↔ ¬∃ᶠ (x : α) in 𝓝 a, p x
[PROOFSTEP]
simp only [not_frequently, eventually_eventually_nhds]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
P : Set α → Prop
hP : ∀ (s t : Set α), s ⊆ t → P s → P t
⊢ (∀ (i : Set α), x ∈ i ∧ IsOpen i → P i) ↔ ∀ (s : Set α), IsOpen s → x ∈ s → P s
[PROOFSTEP]
simp only [@and_comm (x ∈ _), and_imp]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝² : TopologicalSpace α
inst✝¹ : Nonempty β
inst✝ : SemilatticeSup β
f : β → α
a : α
⊢ (∀ (ib : Set α), a ∈ ib ∧ IsOpen ib → ∃ ia, True ∧ ∀ (x : β), x ∈ Ici ia → f x ∈ ib) ↔
∀ (U : Set α), a ∈ U → IsOpen U → ∃ N, ∀ (n : β), N ≤ n → f n ∈ U
[PROOFSTEP]
simp only [and_imp, exists_prop, true_and_iff, mem_Ici, ge_iff_le]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
F : Filter α
⊢ ClusterPt x F ↔ ¬Disjoint (𝓝 x) F
[PROOFSTEP]
rw [disjoint_iff, ClusterPt, neBot_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
s : Set α
⊢ ClusterPt x (𝓟 s) ↔ ∃ᶠ (y : α) in 𝓝 x, y ∈ s
[PROOFSTEP]
simp only [clusterPt_principal_iff, frequently_iff, Set.Nonempty, exists_prop, mem_inter_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
x : α
f : Filter α
H : f ≤ 𝓝 x
inst✝ : NeBot f
⊢ ClusterPt x f
[PROOFSTEP]
rwa [ClusterPt, inf_eq_right.mpr H]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
f : Filter α
H : 𝓝 x ≤ f
⊢ ClusterPt x f
[PROOFSTEP]
simp only [ClusterPt, inf_eq_left.mpr H, nhds_neBot]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
x : α
F : Filter ι
u : ι → α
⊢ MapClusterPt x F u ↔ ∀ (s : Set α), s ∈ 𝓝 x → ∃ᶠ (a : ι) in F, u a ∈ s
[PROOFSTEP]
simp_rw [MapClusterPt, ClusterPt, inf_neBot_iff_frequently_left, frequently_map]
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
ι : Type u_1
x : α
F : Filter ι
u : ι → α
⊢ (∀ {p : α → Prop}, (∀ᶠ (x : α) in 𝓝 x, p x) → ∃ᶠ (a : ι) in F, p (u a)) ↔
∀ (s : Set α), s ∈ 𝓝 x → ∃ᶠ (a : ι) in F, u a ∈ s
[PROOFSTEP]
rfl
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
δ : Type u_2
F : Filter ι
φ : δ → ι
p : Filter δ
x : α
u : ι → α
inst✝ : NeBot p
h : Tendsto φ p F
H : Tendsto (u ∘ φ) p (𝓝 x)
⊢ MapClusterPt x F u
[PROOFSTEP]
have :=
calc
map (u ∘ φ) p = map u (map φ p) := map_map
_ ≤ map u F := map_mono h
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
δ : Type u_2
F : Filter ι
φ : δ → ι
p : Filter δ
x : α
u : ι → α
inst✝ : NeBot p
h : Tendsto φ p F
H : Tendsto (u ∘ φ) p (𝓝 x)
this : map (u ∘ φ) p ≤ map u F
⊢ MapClusterPt x F u
[PROOFSTEP]
have : map (u ∘ φ) p ≤ 𝓝 x ⊓ map u F := le_inf H this
[GOAL]
α : Type u
β : Type v
ι✝ : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
ι : Type u_1
δ : Type u_2
F : Filter ι
φ : δ → ι
p : Filter δ
x : α
u : ι → α
inst✝ : NeBot p
h : Tendsto φ p F
H : Tendsto (u ∘ φ) p (𝓝 x)
this✝ : map (u ∘ φ) p ≤ map u F
this : map (u ∘ φ) p ≤ 𝓝 x ⊓ map u F
⊢ MapClusterPt x F u
[PROOFSTEP]
exact neBot_of_le this
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
F : Filter α
⊢ AccPt x F ↔ ClusterPt x (𝓟 {x}ᶜ ⊓ F)
[PROOFSTEP]
rw [AccPt, nhdsWithin, ClusterPt, inf_assoc]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
C : Set α
⊢ AccPt x (𝓟 C) ↔ ClusterPt x (𝓟 (C \ {x}))
[PROOFSTEP]
rw [acc_iff_cluster, inf_principal, inter_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
C : Set α
⊢ ClusterPt x (𝓟 (C ∩ {x}ᶜ)) ↔ ClusterPt x (𝓟 (C \ {x}))
[PROOFSTEP]
rfl
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
C : Set α
⊢ AccPt x (𝓟 C) ↔ ∀ (U : Set α), U ∈ 𝓝 x → ∃ y, y ∈ U ∩ C ∧ y ≠ x
[PROOFSTEP]
simp [acc_principal_iff_cluster, clusterPt_principal_iff, Set.Nonempty, exists_prop, and_assoc, @and_comm (¬_ = x)]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
x : α
C : Set α
⊢ AccPt x (𝓟 C) ↔ ∃ᶠ (y : α) in 𝓝 x, y ≠ x ∧ y ∈ C
[PROOFSTEP]
simp [acc_principal_iff_cluster, clusterPt_principal_iff_frequently, and_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
x : α
⊢ x ∈ interior s ↔ x ∈ {a | s ∈ 𝓝 a}
[PROOFSTEP]
simp only [mem_interior, mem_nhds_iff, mem_setOf_eq]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ {a | s ∈ 𝓝 a} = {a | 𝓝 a ≤ 𝓟 s}
[PROOFSTEP]
simp only [le_principal_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
p : α → Prop
⊢ IsOpen {x | ∀ᶠ (y : α) in 𝓝 x, p y}
[PROOFSTEP]
simp only [← interior_setOf_eq, isOpen_interior]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s V : Set α
⊢ s ⊆ interior V ↔ ∀ (x : α), x ∈ s → V ∈ 𝓝 x
[PROOFSTEP]
simp_rw [subset_def, mem_interior_iff_mem_nhds]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ s ⊆ interior s ↔ ∀ (a : α), a ∈ s → 𝓝 a ≤ 𝓟 s
[PROOFSTEP]
rw [interior_eq_nhds]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ s ⊆ {a | 𝓝 a ≤ 𝓟 s} ↔ ∀ (a : α), a ∈ s → 𝓝 a ≤ 𝓟 s
[PROOFSTEP]
rfl
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ IsOpen s ↔ ∀ (x : α), x ∈ s → ∀ (l : Ultrafilter α), ↑l ≤ 𝓝 x → s ∈ l
[PROOFSTEP]
simp_rw [isOpen_iff_mem_nhds, ← mem_iff_ultrafilter]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
⊢ IsOpen {a} ↔ 𝓝 a = pure a
[PROOFSTEP]
constructor
[GOAL]
case mp
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
⊢ IsOpen {a} → 𝓝 a = pure a
[PROOFSTEP]
intro h
[GOAL]
case mp
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
h : IsOpen {a}
⊢ 𝓝 a = pure a
[PROOFSTEP]
apply le_antisymm _ (pure_le_nhds a)
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
h : IsOpen {a}
⊢ 𝓝 a ≤ pure a
[PROOFSTEP]
rw [le_pure_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
h : IsOpen {a}
⊢ {a} ∈ 𝓝 a
[PROOFSTEP]
exact h.mem_nhds (mem_singleton a)
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
⊢ 𝓝 a = pure a → IsOpen {a}
[PROOFSTEP]
intro h
[GOAL]
case mpr
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
h : 𝓝 a = pure a
⊢ IsOpen {a}
[PROOFSTEP]
simp [isOpen_iff_nhds, h]
[GOAL]
α✝ : Type u
β : Type v
ι : Sort w
a✝ : α✝
s s₁ s₂ t : Set α✝
p p₁ p₂ : α✝ → Prop
inst✝¹ : TopologicalSpace α✝
α : Type u_1
inst✝ : TopologicalSpace α
a : α
⊢ IsOpen {a} ↔ 𝓝[{a}ᶜ] a = ⊥
[PROOFSTEP]
rw [isOpen_singleton_iff_nhds_eq_pure, nhdsWithin, ← mem_iff_inf_principal_compl, ← le_pure_iff, nhds_neBot.le_pure_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
a : α
⊢ a ∈ closure s ↔ ∃ᶠ (x : α) in 𝓝 a, x ∈ s
[PROOFSTEP]
rw [Filter.Frequently, Filter.Eventually, ← mem_interior_iff_mem_nhds, closure_eq_compl_interior_compl]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
a : α
⊢ a ∈ (interior sᶜ)ᶜ ↔ ¬a ∈ interior {x | ¬x ∈ s}
[PROOFSTEP]
rfl
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ IsClosed s ↔ ∀ (x : α), (∃ᶠ (y : α) in 𝓝 x, y ∈ s) → x ∈ s
[PROOFSTEP]
rw [← closure_subset_iff_isClosed]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ closure s ⊆ s ↔ ∀ (x : α), (∃ᶠ (y : α) in 𝓝 x, y ∈ s) → x ∈ s
[PROOFSTEP]
refine' forall_congr' fun x => _
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
x : α
⊢ x ∈ closure s → x ∈ s ↔ (∃ᶠ (y : α) in 𝓝 x, y ∈ s) → x ∈ s
[PROOFSTEP]
rw [mem_closure_iff_frequently]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
⊢ IsClosed {x | ClusterPt x f}
[PROOFSTEP]
simp only [ClusterPt, inf_neBot_iff_frequently_left, setOf_forall, imp_iff_not_or]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
⊢ IsClosed (⋂ (i : α → Prop), {x | (¬∀ᶠ (x : α) in 𝓝 x, i x) ∨ ∃ᶠ (x : α) in f, i x})
[PROOFSTEP]
refine' isClosed_iInter fun p => IsClosed.union _ _
[GOAL]
case refine'_1
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
p : α → Prop
⊢ IsClosed fun x => (∀ᶠ (x : α) in 𝓝 x, p x) → False
[PROOFSTEP]
apply isClosed_compl_iff.2
[GOAL]
case refine'_2
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
p : α → Prop
⊢ IsClosed fun x => (∀ᶠ (x : α) in f, ¬(fun x => p x) x) → False
[PROOFSTEP]
apply isClosed_compl_iff.2
[GOAL]
case refine'_1
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
p : α → Prop
⊢ IsOpen fun x => sets (𝓝 x) {x | (fun x => p x) x}
case refine'_2
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : Filter α
p : α → Prop
⊢ IsOpen fun x => sets f {x | (fun x => ¬(fun x => p x) x) x}
[PROOFSTEP]
exacts [isOpen_setOf_eventually_nhds, isOpen_const]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
x : α
inst✝ : NeBot (𝓝[{x}ᶜ] x)
⊢ Dense {x}ᶜ
[PROOFSTEP]
intro y
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
x : α
inst✝ : NeBot (𝓝[{x}ᶜ] x)
y : α
⊢ y ∈ closure {x}ᶜ
[PROOFSTEP]
rcases eq_or_ne y x with (rfl | hne)
[GOAL]
case inl
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
y : α
inst✝ : NeBot (𝓝[{y}ᶜ] y)
⊢ y ∈ closure {y}ᶜ
[PROOFSTEP]
rwa [mem_closure_iff_nhdsWithin_neBot]
[GOAL]
case inr
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝¹ : TopologicalSpace α
x : α
inst✝ : NeBot (𝓝[{x}ᶜ] x)
y : α
hne : y ≠ x
⊢ y ∈ closure {x}ᶜ
[PROOFSTEP]
exact subset_closure hne
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
a : α
⊢ a ∈ closure s ↔ ∀ (t : Set α), t ∈ 𝓝 a → ∃ y, ↑y ∈ t
[PROOFSTEP]
simp only [mem_closure_iff_nhds, Set.inter_nonempty_iff_exists_right, SetCoe.exists, exists_prop]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
A : Set α
x : α
⊢ x ∈ closure A ↔ NeBot (comap Subtype.val (𝓝 x))
[PROOFSTEP]
simp_rw [mem_closure_iff_nhds, comap_neBot_iff, Set.inter_nonempty_iff_exists_right, SetCoe.exists, exists_prop]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t✝ : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
p : ι → Prop
s : ι → Set α
h : HasBasis (𝓝 a) p s
t : Set α
⊢ (∀ ⦃i : ι⦄, p i → ∀ ⦃j : Unit⦄, True → Set.Nonempty (s i ∩ t)) ↔ ∀ (i : ι), p i → Set.Nonempty (s i ∩ t)
[PROOFSTEP]
simp only [exists_prop, forall_const]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t✝ : Set α
p✝ p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
a : α
p : ι → Prop
s : ι → Set α
h : HasBasis (𝓝 a) p s
t : Set α
⊢ (∀ (i : ι), p i → Set.Nonempty (s i ∩ t)) ↔ ∀ (i : ι), p i → ∃ y, y ∈ t ∧ y ∈ s i
[PROOFSTEP]
simp only [Set.Nonempty, mem_inter_iff, exists_prop, and_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
F : Filter α
a : α
⊢ ClusterPt a F ↔ ∀ (s : Set α), s ∈ F → a ∈ closure s
[PROOFSTEP]
simp_rw [ClusterPt, inf_neBot_iff, mem_closure_iff_nhds]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
F : Filter α
a : α
⊢ (∀ ⦃s : Set α⦄, s ∈ 𝓝 a → ∀ ⦃s' : Set α⦄, s' ∈ F → Set.Nonempty (s ∩ s')) ↔
∀ (s : Set α), s ∈ F → ∀ (t : Set α), t ∈ 𝓝 a → Set.Nonempty (t ∩ s)
[PROOFSTEP]
rw [forall₂_swap]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
F : Filter α
a : α
⊢ ClusterPt a F ↔ pure a ≤ Filter.lift' F closure
[PROOFSTEP]
simp_rw [clusterPt_iff_forall_mem_closure, (hasBasis_pure _).le_basis_iff F.basis_sets.lift'_closure, id,
singleton_subset_iff, true_and, exists_const]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
F : Filter α
a : α
⊢ ClusterPt a F ↔ NeBot (Filter.lift' F closure ⊓ pure a)
[PROOFSTEP]
rw [clusterPt_iff_lift'_closure, ← Ultrafilter.coe_pure, inf_comm, Ultrafilter.inf_neBot_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
F : Filter α
a : α
⊢ ClusterPt a (Filter.lift' F closure) ↔ ClusterPt a F
[PROOFSTEP]
simp [clusterPt_iff_lift'_closure, lift'_lift'_assoc (monotone_closure α) (monotone_closure α)]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
x : α
⊢ x ∈ closure s ↔ ∃ u, s ∈ u ∧ ↑u ≤ 𝓝 x
[PROOFSTEP]
simp [closure_eq_cluster_pts, ClusterPt, ← exists_ultrafilter_iff, and_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ closure s ⊆ s ↔ ∀ (a : α), ClusterPt a (𝓟 s) → a ∈ s
[PROOFSTEP]
simp only [subset_def, mem_closure_iff_clusterPt]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s : Set α
⊢ IsClosed s ↔ ∀ (x : α), (∀ (U : Set α), U ∈ 𝓝 x → Set.Nonempty (U ∩ s)) → x ∈ s
[PROOFSTEP]
simp_rw [isClosed_iff_clusterPt, ClusterPt, inf_principal_neBot_iff]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
h : IsClosed t
⊢ interior (s ∪ t) ⊆ interior s ∪ t
[PROOFSTEP]
simpa only [union_comm _ t] using h.interior_union_left
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
h : IsOpen s
⊢ (closure (s ∩ t))ᶜ ⊆ (s ∩ closure t)ᶜ
[PROOFSTEP]
simpa only [← interior_compl, compl_inter] using IsClosed.interior_union_left h.isClosed_compl
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
h : IsOpen t
⊢ closure s ∩ t ⊆ closure (s ∩ t)
[PROOFSTEP]
simpa only [inter_comm t] using h.inter_closure
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
hs : Dense s
ht : IsOpen t
⊢ t = t ∩ closure s
[PROOFSTEP]
rw [hs.closure_eq, inter_univ]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁✝ s₂✝ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s₁ s₂ : Set α
x : α
h : x ∈ closure (s₁ ∪ s₂)
h₁ : s₁ᶜ ∈ 𝓝 x
⊢ x ∈ closure s₂
[PROOFSTEP]
rw [mem_closure_iff_nhds_neBot] at *
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁✝ s₂✝ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s₁ s₂ : Set α
x : α
h : 𝓝 x ⊓ 𝓟 (s₁ ∪ s₂) ≠ ⊥
h₁ : s₁ᶜ ∈ 𝓝 x
⊢ 𝓝 x ⊓ 𝓟 s₂ ≠ ⊥
[PROOFSTEP]
rwa [←
calc
𝓝 x ⊓ principal (s₁ ∪ s₂) = 𝓝 x ⊓ (principal s₁ ⊔ principal s₂) := by rw [sup_principal]
_ = 𝓝 x ⊓ principal s₁ ⊔ 𝓝 x ⊓ principal s₂ := inf_sup_left
_ = ⊥ ⊔ 𝓝 x ⊓ principal s₂ := by rw [inf_principal_eq_bot.mpr h₁]
_ = 𝓝 x ⊓ principal s₂ := bot_sup_eq]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁✝ s₂✝ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s₁ s₂ : Set α
x : α
h : 𝓝 x ⊓ 𝓟 (s₁ ∪ s₂) ≠ ⊥
h₁ : s₁ᶜ ∈ 𝓝 x
⊢ 𝓝 x ⊓ 𝓟 (s₁ ∪ s₂) = 𝓝 x ⊓ (𝓟 s₁ ⊔ 𝓟 s₂)
[PROOFSTEP]
rw [sup_principal]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s s₁✝ s₂✝ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s₁ s₂ : Set α
x : α
h : 𝓝 x ⊓ 𝓟 (s₁ ∪ s₂) ≠ ⊥
h₁ : s₁ᶜ ∈ 𝓝 x
⊢ 𝓝 x ⊓ 𝓟 s₁ ⊔ 𝓝 x ⊓ 𝓟 s₂ = ⊥ ⊔ 𝓝 x ⊓ 𝓟 s₂
[PROOFSTEP]
rw [inf_principal_eq_bot.mpr h₁]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
hs : Dense s
ht : Dense t
hso : IsOpen s
x : α
⊢ x ∈ closure (s ∩ closure t)
[PROOFSTEP]
simp [hs.closure_eq, ht.closure_eq]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
⊢ closure s \ closure t = (closure t)ᶜ ∩ closure s
[PROOFSTEP]
simp only [diff_eq, inter_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
s t : Set α
⊢ closure ((closure t)ᶜ ∩ s) = closure (s \ closure t)
[PROOFSTEP]
simp only [diff_eq, inter_comm]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : ∀ (x : β), ¬x ∈ s → f x = a
⊢ Tendsto f (l ⊓ 𝓟 s) (𝓝 a) ↔ Tendsto f l (𝓝 a)
[PROOFSTEP]
rw [tendsto_iff_comap, tendsto_iff_comap]
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : ∀ (x : β), ¬x ∈ s → f x = a
⊢ l ⊓ 𝓟 s ≤ comap f (𝓝 a) ↔ l ≤ comap f (𝓝 a)
[PROOFSTEP]
replace h : 𝓟 sᶜ ≤ comap f (𝓝 a)
[GOAL]
case h
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : ∀ (x : β), ¬x ∈ s → f x = a
⊢ 𝓟 sᶜ ≤ comap f (𝓝 a)
[PROOFSTEP]
rintro U ⟨t, ht, htU⟩ x hx
[GOAL]
case h.intro.intro
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : ∀ (x : β), ¬x ∈ s → f x = a
U : Set β
t : Set α
ht : t ∈ 𝓝 a
htU : f ⁻¹' t ⊆ U
x : β
hx : x ∈ sᶜ
⊢ x ∈ U
[PROOFSTEP]
have : f x ∈ t := (h x hx).symm ▸ mem_of_mem_nhds ht
[GOAL]
case h.intro.intro
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t✝ : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : ∀ (x : β), ¬x ∈ s → f x = a
U : Set β
t : Set α
ht : t ∈ 𝓝 a
htU : f ⁻¹' t ⊆ U
x : β
hx : x ∈ sᶜ
this : f x ∈ t
⊢ x ∈ U
[PROOFSTEP]
exact htU this
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : 𝓟 sᶜ ≤ comap f (𝓝 a)
⊢ l ⊓ 𝓟 s ≤ comap f (𝓝 a) ↔ l ≤ comap f (𝓝 a)
[PROOFSTEP]
refine' ⟨fun h' => _, le_trans inf_le_left⟩
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : 𝓟 sᶜ ≤ comap f (𝓝 a)
h' : l ⊓ 𝓟 s ≤ comap f (𝓝 a)
⊢ l ≤ comap f (𝓝 a)
[PROOFSTEP]
have := sup_le h' h
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : 𝓟 sᶜ ≤ comap f (𝓝 a)
h' : l ⊓ 𝓟 s ≤ comap f (𝓝 a)
this : l ⊓ 𝓟 s ⊔ 𝓟 sᶜ ≤ comap f (𝓝 a)
⊢ l ≤ comap f (𝓝 a)
[PROOFSTEP]
rw [sup_inf_right, sup_principal, union_compl_self, principal_univ, inf_top_eq, sup_le_iff] at this
[GOAL]
α : Type u
β : Type v
ι : Sort w
a✝ : α
s✝ s₁ s₂ t : Set α
p p₁ p₂ : α → Prop
inst✝ : TopologicalSpace α
f : β → α
l : Filter β
s : Set β
a : α
h : 𝓟 sᶜ ≤ comap f (𝓝 a)
h' : l ⊓ 𝓟 s ≤ comap f (𝓝 a)
this : l ≤ comap f (𝓝 a) ∧ 𝓟 sᶜ ≤ comap f (𝓝 a)
⊢ l ≤ comap f (𝓝 a)
[PROOFSTEP]
exact this.1
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f g : α → β
h : Continuous f
h' : ∀ (x : α), f x = g x
⊢ Continuous g
[PROOFSTEP]
convert h
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f g : α → β
h : Continuous f
h' : ∀ (x : α), f x = g x
⊢ g = f
[PROOFSTEP]
ext
[GOAL]
case h.e'_5.h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f g : α → β
h : Continuous f
h' : ∀ (x : α), f x = g x
x✝ : α
⊢ g x✝ = f x✝
[PROOFSTEP]
rw [h']
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f g : α → β
x : α
h : f =ᶠ[𝓝 x] g
⊢ ContinuousAt f x ↔ ContinuousAt g x
[PROOFSTEP]
simp only [ContinuousAt, tendsto_congr' h, h.eq_of_nhds]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : TopologicalSpace γ
M₀ : Type u_5
inst✝ : Zero M₀
a : α
f : α → M₀
⊢ f =ᶠ[𝓝 a] 0 ↔ ¬a ∈ closure (Function.support f)
[PROOFSTEP]
rw [← mem_compl_iff, ← interior_compl, mem_interior_iff_mem_nhds, Function.compl_support]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : TopologicalSpace γ
M₀ : Type u_5
inst✝ : Zero M₀
a : α
f : α → M₀
⊢ f =ᶠ[𝓝 a] 0 ↔ {x | f x = 0} ∈ 𝓝 a
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
g : β → γ
f : α → β
x : α
y : β
hg : ContinuousAt g y
hf : ContinuousAt f x
hy : f x = y
⊢ ContinuousAt (g ∘ f) x
[PROOFSTEP]
subst hy
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
g : β → γ
f : α → β
x : α
hf : ContinuousAt f x
hg : ContinuousAt g (f x)
⊢ ContinuousAt (g ∘ f) x
[PROOFSTEP]
exact hg.comp hf
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f : α → β
⊢ (∀ (x : Set β), IsOpen xᶜ → IsOpen (f ⁻¹' xᶜ)) ↔ ∀ (s : Set β), IsClosed s → IsClosed (f ⁻¹' s)
[PROOFSTEP]
simp only [isOpen_compl_iff, preimage_compl]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f : α → β
⊢ Continuous f ↔ ∀ (x : α) (g : Ultrafilter α), ↑g ≤ 𝓝 x → Tendsto f (↑g) (𝓝 (f x))
[PROOFSTEP]
simp only [continuous_iff_continuousAt, continuousAt_iff_ultrafilter]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f : α → β
hf : Continuous f
t : Set β
⊢ closure (f ⁻¹' t) ⊆ f ⁻¹' closure t
[PROOFSTEP]
rw [← (isClosed_closure.preimage hf).closure_eq]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f : α → β
hf : Continuous f
t : Set β
⊢ closure (f ⁻¹' t) ⊆ closure (f ⁻¹' closure t)
[PROOFSTEP]
exact closure_mono (preimage_mono subset_closure)
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
s : Set α
t : Set β
f : α → β
h : MapsTo f s t
hc : Continuous f
⊢ MapsTo f (closure s) (closure t)
[PROOFSTEP]
simp only [MapsTo, mem_closure_iff_clusterPt]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
s : Set α
t : Set β
f : α → β
h : MapsTo f s t
hc : Continuous f
⊢ ∀ ⦃x : α⦄, ClusterPt x (𝓟 s) → ClusterPt (f x) (𝓟 t)
[PROOFSTEP]
exact fun x hx => hx.map hc.continuousAt (tendsto_principal_principal.2 h)
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f : α → β
s : Set α
h : Continuous f
⊢ closure s ⊆ f ⁻¹' closure (f '' s)
[PROOFSTEP]
rw [← Set.image_subset_iff]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
f : α → β
s : Set α
h : Continuous f
⊢ f '' closure s ⊆ closure (f '' s)
[PROOFSTEP]
exact image_closure_subset_closure_image h
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f : κ → β
g : β → γ
hf : Surjective f
x : β
⊢ x ∈ closure (range f)
[PROOFSTEP]
simp [hf.range_eq]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f : κ → β
g : β → γ
s : Set α
h : Dense s
⊢ DenseRange Subtype.val
[PROOFSTEP]
simpa only [DenseRange, Subtype.range_coe_subtype]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f✝ : κ → β
g : β → γ
f : α → β
hf : Continuous f
s : Set α
hs : Dense s
⊢ range f ⊆ closure (f '' s)
[PROOFSTEP]
rw [← image_univ, ← hs.closure_eq]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f✝ : κ → β
g : β → γ
f : α → β
hf : Continuous f
s : Set α
hs : Dense s
⊢ f '' closure s ⊆ closure (f '' s)
[PROOFSTEP]
exact image_closure_subset_closure_image hf
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f : κ → β
g : β → γ
hf : DenseRange f
s : Set β
hs : IsOpen s
⊢ s ⊆ closure (f '' (f ⁻¹' s))
[PROOFSTEP]
rw [image_preimage_eq_inter_range]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f : κ → β
g : β → γ
hf : DenseRange f
s : Set β
hs : IsOpen s
⊢ s ⊆ closure (s ∩ range f)
[PROOFSTEP]
exact hf.open_subset_closure_inter hs
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f✝ : κ → β
g✝ g : β → γ
f : κ → β
hg : DenseRange g
hf : DenseRange f
cg : Continuous g
⊢ DenseRange (g ∘ f)
[PROOFSTEP]
rw [DenseRange, range_comp]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
inst✝² : TopologicalSpace α
inst✝¹ : TopologicalSpace β
inst✝ : TopologicalSpace γ
κ : Type u_5
ι : Type u_6
f✝ : κ → β
g✝ g : β → γ
f : κ → β
hg : DenseRange g
hf : DenseRange f
cg : Continuous g
⊢ Dense (g '' range f)
[PROOFSTEP]
exact hg.dense_image cg hf
|
# -*- coding: utf-8 -*-
################################################################################################################
#Importing Libraries
################################################################################################################
import matplotlib
import sys
import numpy
import csv
import ephem
global debug, interactive
debug = 0
interactive = 1
from pylab import *
from math import *
from random import *
import os
from time import clock, time, localtime
import shutil
import astropy
from astropy.io import ascii
from astropy.table import Table, Column
import scipy as scipy
from aux.gameModelPars32 import *
from aux.gamePlotUtils32 import *
from aux.gameFunctions32 import *
from aux.GaMe_v32 import *
from aux.export_txt_Reid32 import *
import re
################################################################################################################
#Defining the parameter txt file
################################################################################################################
file_name = ''
if (len(sys.argv) == 2):
file_name = sys.argv[1]
else:
print 'File name expected'
try:
control = parse_com(file_name)
except:
print 'Done nothing'
################################################################################################################
#Creating one galaxy
################################################################################################################
gsample,par,file_masers,fname_directory,MMB,Arecibo,prt1,prt2,prt3,prt7,prt8,prt9,prt10=full_model(file_name)
path=os.getcwd()
################################################################################################################
#Taking values of the control txt file
################################################################################################################
sam_selec_control =float(control['sam_selec'])
sam_complete_control =float(control['sam_complete'])
sam_bri_dec_control =float(control['sam_bri_dec'])
many_control =int(control['many'])
Bri_faint_control =int(control['Bri_faint'])
include_BeSSeL_control =int(control['BeSSeL_include'])
samp_rand_control =float(control['samp_rand'])
many_rand_control =int(control['many_rand'])
plots_control =float(control['plots'])
Specific_Unc_control =float(control['Unc_confirmation_spec'])
Fudge_Factor_control =float(control['Fudge_Factor'])
################################################################################################################
#Creating Plots directories
################################################################################################################
if(plots_control==1):
os.chdir(path+'/output/'+fname_directory)
os.makedirs('output_plots')
################################################################################################################
#Creating Sample Selection
################################################################################################################
if(sam_selec_control==1):
os.chdir(path+'/output/'+fname_directory)
################################################################################################################
#By bright of sources
################################################################################################################
if(sam_bri_dec_control==1):
Ns =create_array_control(control,'N_sour')
dds=create_array_control(control,'down_limit')
dus=create_array_control(control,'up_limit')
brisamples={}
if(Specific_Unc_control==2):
unc_mu_xy=create_array_control(control,'Values_Unc')
if(Fudge_Factor_control==1):
fudge_values=create_array_control(control,'Values_Fudge')
for i in range(many_control):
directory_nsources='brig_dec_sample'+file_masers[9:-4]+'_'+str(i)
os.chdir(path+'/output/'+fname_directory)
os.makedirs(directory_nsources)
print('Brightest sources with certain declination sample saved in folder: %s' % directory_nsources)
globals()['variable{}'.format(i)] = 0
#Creating the subsamples (bright or faint)
sample_small,sample_small_file=Sample_Selection(gsample,Ns[i],dds[i],dus[i],file_masers,i,Bri_faint_control,include_BeSSeL_control)
#Printing txt files
if(Specific_Unc_control==2):
if(Fudge_Factor_control==1):
Create_txt_Reid(sample_small_file,directory_nsources,Fudge_Factor_control,err_mu_xy[i],fudge_values[i])
elif(Fudge_Factor_control==0):
Create_txt_Reid(sample_small_file,directory_nsources,Fudge_Factor_control,unc_mu_xy[i])
elif(Specific_Unc_control==0 or Specific_Unc_control==1):
if(Fudge_Factor_control==1):
Create_txt_Reid(sample_small_file,directory_nsources,Fudge_Factor_control,0,fudge_values[i])
elif(Fudge_Factor_control==0):
Create_txt_Reid(sample_small_file,directory_nsources,Fudge_Factor_control)
if(plots_control==1):
create_dir_plots(path,fname_directory,'bri_sample',i)
do_plots(sample_small,par)
os.chdir(path+'/output/'+fname_directory)
################################################################################################################
#Random selection
################################################################################################################
if(samp_rand_control==1):
Nsrand=create_array_control(control,'N_sour_rand')
for i in range(many_rand_control):
directory_random='random_sample'+file_masers[9:-4]+'_'+str(i)
os.chdir(path+'/output/'+fname_directory)
os.makedirs(directory_random)
print('Random sample saved in folder: %s' % directory_random)
#Creating sample
random_sampl,random_sampl_file=Sample_Selection_random(gsample,Nsrand[i],file_masers,i)
#Printing txt files
Create_txt_Reid(file_masers,directory_complete,Fudge_Factor_control)
#PLots
if(plots_control==1):
create_dir_plots(path,fname_directory,'rand_sample',i)
do_plots(random_sampl,par)
os.chdir(path+'/output/'+fname_directory)
################################################################################################################
#Complete sample
################################################################################################################
if (sam_complete_control==1):
#Still creating the whole sample without fudge value or unc assigment
directory_complete='complete_sample'+file_masers[9:-4]
os.chdir(path+'/output/'+fname_directory)
os.makedirs(directory_complete)
print('Complete sample saved in folder: %s' % directory_complete)
Create_txt_Reid(file_masers,directory_complete,Fudge_Factor_control)
if(plots_control==1):
create_dir_plots(path,fname_directory,'complete_sample','')
do_plots(gsample,par)
os.chdir(path+'/output/'+fname_directory)
else:
print('No Sample Selection, making complete sample')
directory_complete='complete_sample'+file_masers[9:-4]
os.chdir(path+'/output/'+fname_directory)
os.makedirs(directory_complete)
print('Complete sample saved in folder: %s' % directory_complete)
Create_txt_Reid(file_masers,directory_complete,Fudge_Factor_control)
if(plots_control==1):
create_dir_plots(path,fname_directory,'complete_sample','')
do_plots(gsample,par)
os.chdir(path+'/output/'+fname_directory)
################################################################################################################
#Creating the output txt file with the input and output parameteres
################################################################################################################
os.chdir(path)
shutil.copy2(path+'/'+file_name,path+'/output/'+fname_directory+'/outpara_'+file_masers[9:-4]+'.txt')
os.chdir(path+'/output/'+fname_directory+'/')
with open("outpara_"+file_masers[9:-4]+".txt", "a") as myfile:
myfile.write('\n')
myfile.write('-------------------------------------------------------------------------------')
myfile.write('\n Output results for simulation number: \n')
myfile.write(file_masers[9:-4])
myfile.write('\n ------------------------------------------------------------------------------- \n')
myfile.write(prt1)
myfile.write(prt2)
myfile.write(prt3)
myfile.write(prt7)
myfile.write(prt8)
myfile.write(prt9)
myfile.write(prt10)
myfile.write('\n ------------------------------------------------------------------------------- \n')
myfile.write('Comparison with Surveys: \n')
myfile.write('Sources that satisfy Arecibo limits: 76 (Observed) vs Simulated=\n')
myfile.write(str(Arecibo[0]))
myfile.write('\n Flux density slope in Arecibo: -0.471 (Observed) vs Simulated=\n')
myfile.write(str(round(Arecibo[1],3)))
myfile.write('\n Sources that satisfy MMB limits: 666 (Observed) vs Simulated=\n')
myfile.write(str(MMB[0]))
myfile.write('\n Flux density slope in MMB: -0.533 (Observed) vs Simulated=\n')
myfile.write(str(round(MMB[1],3)))
myfile.write('\n ------------------------------------------------------------------------------- \n')
os.chdir(path)
################################################################################################################
print ('Methanol masers simulation %s appears to be end successfully') %file_masers[10:-4]
print ('Please check the folder output/%s where all the outputs of this simulations were saved.' %fname_directory) |
#include <stdio.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_const_cgsm.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include "global.h"
#include "eos_pres.h"
#include "eos_rho.h"
#include "param.h"
// the system of ODEs to be integrated
int
func (double r, const double y[], double f[], void *params)
{
struct param *myparams = (struct param *) params;
double (*pres) (double, void *); // EOS pressure pointer
double (*rho) (double, void *); // EOS density pointer
pres = &eos_pres;
rho = &eos_rho;
// set a minimum pressure cutoff. if we don't, the ODE solver will wobble all
// over the surface and crash, or if you make the error tolerance really strict
// it'll integrate forever
if (y[1] < 1.0e-9 * myparams->pinit)
{
if (myparams->single_star == 0)
{
printf ("surface reached!\n");
printf ("%12s %12s %12s\n", "R (km)", "M (M_sun)",
"rho(0) (g/cm^3)");
}
printf ("%12le %12le %12le\n", r / 1.0e+5,
y[0] / GSL_CONST_CGSM_SOLAR_MASS, myparams->rho_init);
return GSL_EBADFUNC; // this flag tells GSL integrator to quit
}
// for a single star we can print M, P and rho as functions of r
if (myparams->single_star == 0)
{
printf ("%12le %12le %12le %12le\n", r / 1.0e+5,
y[0] / GSL_CONST_CGSM_SOLAR_MASS, y[1], rho (y[1], myparams));
}
// mass conservation equation
f[0] = 4.0 * M_PI * pow (r, 2.0) * rho (y[1], myparams);
// TOV equation
f[1] = -(GSL_CONST_CGSM_GRAVITATIONAL_CONSTANT / pow (r, 2.0))
* (rho (y[1], myparams)
+ (y[1] / pow (GSL_CONST_CGSM_SPEED_OF_LIGHT, 2.0)))
* (y[0] + 4 * M_PI * pow (r, 3.0)
* y[1] / pow (GSL_CONST_CGSM_SPEED_OF_LIGHT, 2.0))
/ (1.0 - (2.0 * GSL_CONST_CGSM_GRAVITATIONAL_CONSTANT * y[0]
/ (pow (GSL_CONST_CGSM_SPEED_OF_LIGHT, 2.0) * r)));
// ODEs tend to return NaNs at the same radius where P < 0
if ((gsl_isnan (f[0]) || gsl_isnan (f[1])))
{
/* print values at the radius where ODEs diverge. this is almost
always at the surface */
printf ("%12f %12f %12f\n", r / 1.0e+5,
y[0] / GSL_CONST_CGSM_SOLAR_MASS, myparams->rho_init);
return GSL_EBADFUNC;
}
return GSL_SUCCESS;
}
|
[STATEMENT]
lemma connected_local:
"connected S \<longleftrightarrow>
\<not> (\<exists>e1 e2.
openin (top_of_set S) e1 \<and>
openin (top_of_set S) e2 \<and>
S \<subseteq> e1 \<union> e2 \<and>
e1 \<inter> e2 = {} \<and>
e1 \<noteq> {} \<and>
e2 \<noteq> {})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. connected S = (\<nexists>e1 e2. openin (top_of_set S) e1 \<and> openin (top_of_set S) e2 \<and> S \<subseteq> e1 \<union> e2 \<and> e1 \<inter> e2 = {} \<and> e1 \<noteq> {} \<and> e2 \<noteq> {})
[PROOF STEP]
unfolding connected_def openin_open
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<nexists>A B. open A \<and> open B \<and> S \<subseteq> A \<union> B \<and> A \<inter> B \<inter> S = {} \<and> A \<inter> S \<noteq> {} \<and> B \<inter> S \<noteq> {}) = (\<nexists>e1 e2. (\<exists>T. open T \<and> e1 = S \<inter> T) \<and> (\<exists>T. open T \<and> e2 = S \<inter> T) \<and> S \<subseteq> e1 \<union> e2 \<and> e1 \<inter> e2 = {} \<and> e1 \<noteq> {} \<and> e2 \<noteq> {})
[PROOF STEP]
by safe blast+ |
"Cleans and pre-processes offender profile data from http://www.csc-scc.gc.ca/005/opendata-donneesouvertes/Open%20Data%20File%2020170409%20v3%20(English).csv.
Usage: src/sample_docopt.r --raw_data_path=<raw_data_path> --processed_dir_path=<processed_dir_path>
Options:
--raw_data_path=<raw_data_path> Path to the raw data including the file name and extension to raw data
--processed_dir_path=<processed_dir_path> Path to where the processed data should be written.
" -> doc
library(tidyverse)
library(docopt)
library(janitor)
library(testthat)
# don't change the seed for reproduceability purposes
set.seed(2020)
opt <- docopt(doc)
main <- function(raw_data_path, processed_dir_path) {
# read data and convert class to factor
raw_data <- readr::read_csv(raw_data_path, skip = 1)
print(raw_data)
# write scale factor to a file
try({
dir.create(processed_dir_path, showWarnings = FALSE)
})
processed_data <- raw_data |> clean_names() |>
filter(sentence_type == "DETERMINATE") |>
select(race_grouping, aggregate_sentence_length)
processed_data_path <- paste(
processed_dir_path,
"/processed_offender_profile.csv",
sep = ""
)
write.csv(
processed_data,
processed_data_path
)
expect_true(
file.exists(processed_data_path),
paste(processed_data_path, "does not exist.")
)
}
main(opt[["--raw_data_path"]], opt[["--processed_dir_path"]])
|
[STATEMENT]
lemma RBT_Impl_rbt_all_simps [simp, code]:
"RBT_Impl_rbt_all P rbt.Empty \<longleftrightarrow> True"
"RBT_Impl_rbt_all P (Branch c l k v r) \<longleftrightarrow> P k v \<and> RBT_Impl_rbt_all P l \<and> RBT_Impl_rbt_all P r"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. RBT_Impl_rbt_all P rbt.Empty = True &&& RBT_Impl_rbt_all P (Branch c l k v r) = (P k v \<and> RBT_Impl_rbt_all P l \<and> RBT_Impl_rbt_all P r)
[PROOF STEP]
by(auto simp add: RBT_Impl_rbt_all_def) |
include("Hiker.jl")
import .Hiker
using Test
@test Hiker.answer() == 42
|
\documentclass[xcolor={dvipsnames,table},16pt]{beamer}
\usepackage{lmodern}
\mode<presentation>
{
\usetheme{UIUC}
}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear-comp]{biblatex}
\bibliography{ref.bib}
\input{macros.tex}
\title[\MultiSE]{\MultiSE: Multi-path Symbolic Execution using Value Summaries}
\author[C. Hsieh]{
Koushik Sen, George Necula, Liang Gong, Wontae Choi\texorpdfstring{\\}{}
EECS, UC Berkeley\texorpdfstring{\\}{}
\texorpdfstring{\bigskip}{\space}
Presenter: Chiao Hsieh
}
\institute[@ UIUC CS]{}
\date{\today}
\begin{document}
{\nologo
\begin{frame}
\titlepage
\end{frame}
}
\begin{frame}{Motivation}
\begin{itemize}
\item \emph{Symbolic Execution} is a key program analysis technique in a variety of applications
such as Automated Test-case Generation and Program Verification
\item \emph{Path/State Explosion} problem is one major factor that limits Symbolic Execution to be scalable
\item This paper addresses Path/State Explosion with \emph{\ValSums}
\end{itemize}
\end{frame}
% Uncomment these lines for an automatically generated outline.
\begin{frame}{Outline}
\tableofcontents
\end{frame}
\section{Symbolic Execution}\label{sec:sym-exe}
\begin{frame}{\SymExe}
\textit{
``\dots an alternative \underline{``Symbolic Execution'' semantics} for a
programming language where the real data store need not to be used but can be
represented by \underline{arbitrary symbols}.''
}
\medskip
\textit{
``Computational definition for the basic operators of the language are extended
to accept \underline{symbolic inputs} and produce \underline{symbolic formulas as output}.''
} - \cite{King76}
\begin{center}
\myopinion
Extended program semantics with program states represented by symbolic inputs
\end{center}
\end{frame}
\begin{frame}[fragile]{(Traditional) \SymExe}
\begin{columns}
\begin{column}{.45\textwidth}
\begin{overlayarea}{\columnwidth}{.8\textheight}
\lstinputlisting{example.cs}
\only<1-6>{
Concrete execution with $x=30, r=2, z=5$
}\only<7->{
\only<7>{
Symbolic execution with symbolic value $x_0, r_0, z_0$
}\only<8>{
Symbolic stores:
Symbolic expressions as values
}\only<9>{
Assignments:
Update with new semantic of operators to construct symbolic expressions
}\only<10>{
Conditional:
Track path conditions \pc
\alert{Fork} when both branches are feasible,
concurrently execute both
}\only<11>{
Visualized as Symbolic Execution Tree
Program Configuration is the set of Symbolic Stores on frontier nodes
}\only<12>{
(Ideal) path condition \pc:
Assignment $\alpha$ satisfies \pc
$\iff$ program with input $\alpha$ executes along the path
}\only<13>{
Symbolic execution terminates when all forked processes terminate
}
}
\end{overlayarea}
\end{column}
\begin{column}{.55\textwidth}
\centering
\begin{tikzpicture}[
overlay, -stealth,
every node/.style={
circle,draw,inner sep=1pt, text centered, minimum height=1em,
color=Black
},
cond/.style={draw=none, font=\scriptsize},
desc/.style={draw=none, align=center, font=\tiny,inner sep=0pt},
node distance=0pt,
level distance=25pt,
level 3/.style={sibling distance=30mm},
level 4/.style={sibling distance=15mm},
level 5/.style={sibling distance=7mm}
]
\node (1) at (-1, 3) {1}
child[visible on=<{2-6,8-}>] {node (2) {2}
child[visible on=<{3-6,9-}>]{node (3) {3}
child[visible on=<{10-}>]{node (4) {4}
child[visible on=<{13-}>]{node {5}
child{node {6}
child{node {7}
child{node {8}}
}
child{node {\color{red}X}}
}
}
child[visible on=<{13-}>]{node {6}
child{node {7}
child{node {8}}
}
child{node {8}}
}
edge from parent node[cond, left] {$(x > 100)$}
}
child[visible on=<{4-6,10-}>]{node (6) {6}
child[visible on=<{5-6,11-}>]{node (7) {7}
child[visible on=<{6,12-}>]{node (8) {8}}
edge from parent node[cond, left] {$(r > 1)$}
}
child[visible on=<{11-}>]{
node (80) {8}
edge from parent node[cond, right] {$\neg(r > 1)$}
}
edge from parent node[cond, right] {$\neg(x > 100)$}
}
}
}
;
\foreach \Cont in {1,2,3,6,7,8}
\node[desc, visible on=<+>, left=of \Cont]
{\footnotesize
$\left\{
\begin{alignedat}{4}
loc& \mapsto \Cont &,
r& \mapsto \only<1>{\bot}\only<2->{\alert<2>{2}},\\
x& \mapsto \only<1>{\bot}\only<2>{\alert<2>{30}}\only<3->{\alert<3>{60}} &,
z& \mapsto \only<1>{\bot}\only<2-5>{\alert<2>{5}}\only<6>{\alert{1}}
\end{alignedat}
\right\}$
};
%% SymExe states
\arraycolsep=1pt
\foreach \Cont in {1,2,3}
\node[desc, visible on=<+>, right=of \Cont]
{\footnotesize
$\left\{
\begin{array}{rlrl}
\multicolumn{4}{c}{\pc \mapsto \TT,}\\
loc&\mapsto \Cont &,
r&\mapsto \only<7>{\bot}\only<8-9>{\alert<8>{r_0}},\\
x&\mapsto \only<7>{\bot}\only<8>{\alert{x_0}}\only<9>{\alert{2x_0}} &,
z&\mapsto \only<7>{\bot}\only<8-9>{\alert<8>{z_0}}
\end{array}
\right\}$
};
\node[desc, visible on=<10-12>, below=-1cm of 4]
{
$\left\{
\begin{array}{rlrl}
\multicolumn{4}{c}{\pc \mapsto \alert{2x_0 > 100},}\\
loc&\mapsto 4 &,
r&\mapsto r_0,\\
x&\mapsto 2x_0 &,
z&\mapsto z_0
\end{array}
\right\}$
};
\node[desc, visible on=<10>, below=-1cm of 6]
{
$\left\{
\begin{array}{rlrl}
\multicolumn{4}{c}{\pc \mapsto \alert{\neg(2x_0 > 100)},}\\
loc&\mapsto 6 &,
r&\mapsto r_0,\\
x&\mapsto 2x_0 &,
z&\mapsto z_0
\end{array}
\right\}$
};
\node[desc, visible on=<11>, below left=-5mm of 7]
{
$\left\{
\begin{array}{rlrl}
\pc & \multicolumn{3}{c}{\mapsto \neg(2x_0 > 100)}\\
& \multicolumn{3}{c}{\alert{\land (r_0 > 1)},}\\
loc&\mapsto 7 &,
r&\mapsto r_0,\\
x&\mapsto 2x_0 &,
z&\mapsto z_0
\end{array}
\right\}$
};
\node[desc, visible on=<11->, below right=-5mm of 80]
{
$\left\{
\begin{array}{rlrl}
\pc & \multicolumn{3}{c}{\mapsto \neg(2x_0 > 100)}\\
& \multicolumn{3}{c}{\alert{\land \neg(r_0 > 1)},}\\
loc&\mapsto 8 &,
r&\mapsto r_0,\\
x&\mapsto 2x_0 &,
z&\mapsto z_0
\end{array}
\right\}$
};
\node[desc, visible on=<12->, below=-1cm of 8]
{
$\left\{
\begin{array}{rlrl}
\pc & \multicolumn{3}{c}{\mapsto \neg(2x_0 > 100)}\\
& \multicolumn{3}{c}{\alert<12>{\land (r_0 > 1)},}\\
loc&\mapsto 8 &,
r&\mapsto r_0,\\
x&\mapsto 2x_0 &,
z&\mapsto \alert{r_0-1}
\end{array}
\right\}$
};
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{Path/State Explosion Problem}
\begin{columns}
\begin{column}{0.55\textwidth}
\begin{overlayarea}{\columnwidth}{.8\textheight}
\footnotesize
$
\begin{array}{l|l|llll}
& \pc & loc & r & x & z \\ \hline
M8_1 & \pc_1 & 8 & r_0^2 + 2 & \only<2>{\cellcolor{Lavender}}2x_0 & r_0^2 + 1 \\
M8_2 & \pc_2 & 8 & \only<2>{\cellcolor{Lavender}}r_0 & \only<2>{\cellcolor{Lavender}}2x_0 & \only<2>{\cellcolor{YellowGreen}}r_0 - 1 \\
M8_3 & \pc_3 & 8 & \only<2>{\cellcolor{Lavender}}r_0 & \only<2>{\cellcolor{Lavender}}2x_0 & z_0 \\
M8_4 & \pc_4 & 8 & \only<2>{\cellcolor{Lavender}}r_0 & \only<2>{\cellcolor{Lavender}}2x_0 & \only<2>{\cellcolor{YellowGreen}}r_0 - 1 \\
M8_5 & \pc_5 & 8 & \only<2>{\cellcolor{Lavender}}r_0 & \only<2>{\cellcolor{Lavender}}2x_0 & z_0
\end{array}
$
$
\begin{array}{l}
\pc_1 = 2x_0>0 \land z_0 = 1 \land r_0^2 + 2 > 1 \\
\pc_2 = 2x_0>0 \land \neg(z_0 = 1) \land r_0 > 1 \\
\pc_3 = 2x_0>0 \land \neg(z_0 = 1) \land \neg(r_0 > 1) \\
\pc_4 = \neg(2x_0>0) \land (r_0 > 1) \\
\pc_5 = \neg(2x_0>0) \land \neg(r_0 > 1) \\
\end{array}
$
\bigskip
\only<1>{
\# paths can grow exponentially many w.r.t \# branches
for loop-free program
\medskip
\# paths can be infinite for programs w/ loops
}
\only<2>{
Observation:
Symbolic stores of same $loc$ share same symbolic expressions
Redundant \textcolor{Lavender}{stores} and \textcolor{YellowGreen}{computations} among paths
}
\end{overlayarea}
\end{column}
\begin{column}{0.45\textwidth}
\centering
\begin{tikzpicture}[
overlay, -stealth,
every node/.style={circle,draw,inner sep=1pt, text centered, minimum height=1em},
every label/.style={label position=below, rectangle, draw=none, align=center, left},
desc/.style={rectangle, draw=none, align=center, font=\tiny,inner sep=0pt},
node distance=10pt,
level distance=25pt,
level 3/.style={sibling distance=30mm},
level 4/.style={sibling distance=15mm},
level 5/.style={sibling distance=7mm}
]
\node (1) at (0, 3) {1}
child{node (2) {2}
child{node (3) {3}
child{node {4}
child{node {5}
child{node {6}
child{node {7}
child{node [label=left:{$M8_1$}] {8}}
}
child{node {\color{red}X}}
}
}
child{node {6}
child{node {7}
child{node [label={$M8_2$}] {8}}
}
child{node [label={$M8_3$}]{8}}
}
}
child{node {6}
child{node {7}
child{node [label={$M8_4$}] {8}}
}
child{node [label={$M8_5$}] {8}}
}
}
}
;
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\begin{frame} {Intuition on State Merging}
\begin{overlayarea}{\textwidth}{.55\textheight}
\centering
\begin{tikzpicture}[
overlay, -stealth,
every node/.style={circle,draw,inner sep=1pt, text centered, minimum height=1em},
every label/.style={label position=below, rectangle, draw=none, align=center, left},
desc/.style={rectangle, draw=none, align=center, font=\tiny,inner sep=0pt},
node distance=25pt,
level distance=25pt,
level 3/.style={sibling distance=30mm},
level 4/.style={sibling distance=15mm},
level 5/.style={sibling distance=7mm}
]
\node (1) at (-2.5, 0.5) {1}
child{node (2) {2}
child{node (3) {3}
child{node {4}
child{node {5}
child{node [label={\only<1>{$M6_1$}}] {6}
child[visible on=<2->]{node [label={$M7_1$}] {7}
% child{node [label=left:{$M8_1$}] {8}}
}
child[visible on=<2->]{node {\color{red}X}}
}
}
child{node [label={\only<1>{$M6_2$}}] {6}
child[visible on=<2->]{node [label={$M7_2$}] {7}
% child{node [label={$M8_2$}] {8}}
}
child[visible on=<2>]{node [label={$M8_3$}]{8}}
}
}
child{node [label={\only<1>{$M6_3$}}] {6}
child[visible on=<2->]{node [label={$M7_3$}] {7}
% child{node [label={$M8_4$}] {8}}
}
child[visible on=<2->]{node [label={$M8_5$}] {8}}
}
}
}
;
\node [right=5.5 of 1] {1}
child{node {2}
child{node (m3) {3}
child{node (m4) {4}
child{node (m5) {5}}
child[invisible]{}
}
child[invisible]{}
}
}
;
\coordinate [below of=m3] (c1)
child {node [label=right:{\only<2->{\color{Red}}$\widehat{M6}$}] (m6) {6}
child[visible on=<2>]{node [label={$\widehat{M7}$}] {7}
% child{node {8}}
}
child[visible on=<2>]{node [label={$\widehat{M8}$}] {8}}
}
;
\draw
(m3) edge (m6)
(m4) edge (m6)
(m5) edge (m6)
;
\end{tikzpicture}
\end{overlayarea}
\flushright
\begin{overlayarea}{0.9\textwidth}{.16\textheight}
\only<1>{
A new representation to approximate some or all frontier symbolic stores at same $loc$.
I.e. $\widehat{M6} \approxeq \{M6_1, M6_2, M6_3\}$
}\only<2>{
Symbolic Execution with the new representation should preserve the approximation.
I.e. $\widehat{M7} \approxeq \{M7_1, M7_2, M7_3\}$ and
$\widehat{M8} \approxeq \{M8_3, M8_5\}$
}
\end{overlayarea}
\end{frame}
\begin{frame}{Conventional State Merging}
{\footnotesize
$
\begin{array}{l|l|cccc}
& \pc & loc & r & x & z \\ \hline
\only<1>{M6_1}\only<2>{M7_1} & \pc_1 \only<2->{\alert{\land r_0^2+2>1}} & 6 & r_0^2+2 & 2x_0 & z_0 \\
\only<1>{M6_2}\only<2>{M7_2} & \pc_2 \only<2->{\alert{\land r_0>1}} & 6 & r_0 & 2x_0 & z_0 \\
\only<1>{M6_3}\only<2>{M7_3} & \pc_3 \only<2->{\alert{\land r_0>1}} & 6 & r_0 & 2x_0 & z_0 \\ \hline \hline
\widehat{M6} & \widehat{\pc} \equiv
\left(\begin{array}{l}
(\pc_1 \land \textcolor{red}{r_1 = r_0^2 + 2}) \\
\lor(\pc_2 \land \textcolor{red}{r_1 = r_0}) \\
\lor(\pc_3 \land \textcolor{red}{r_1 = r_0})
\end{array}\right) & 6 & \alert{r_1} & 2x_0 & z_0 \\\hline
\uncover<2->{\widehat{M7} & \widehat{\pc} \land \alert{(r_1 > 1)} & 7 & \alert{r_1} & 2x_0 & z_0} \\
\uncover<2->{\widehat{M8} & \widehat{\pc} \land \alert{\neg(r_1 > 1)} & 8 & \alert{r_1} & 2x_0 & z_0}
\end{array}
$}
\begin{overlayarea}{\textwidth}{.29\textheight}
\begin{itemize}
\only<1>{
\item Add aux variables to path conditions when symbolic expressions are different
\item Disjunction of path conditions from different paths
\item Same symbolic execution semantic after merging
}\only<2>{
\item May introduce predicates with higher complexity to solve
\begin{itemize}
\item E.g. $r_0^2+2>1$ in $M7_1$ can be simplified to \TT\\
However, we cannot simplify $\widehat{M7}$
\end{itemize}
\item Some approaches need to compute joint $loc$ statically
{\myopinion
and restrict search strategy on symbolic execution tree
} % \todoline{cite DSM MergePoint}
}
\end{itemize}
\end{overlayarea}
\end{frame}
\section{MultiSE Algorithm}\label{sec:algo}
\begin{frame}
\vfill
\centering
\usebeamerfont{title}\insertsectionhead
\vfill
\end{frame}
\begin{frame}[fragile]{\ValSums}
\begin{overlayarea}{\textwidth}{0.39\textheight}
\begin{center}
\footnotesize
$
\begin{array}{@{}l|@{}c@{}c@{}c@{}c@{}}
& loc & r & x & z \\ \hline
\Sigma_6 &
\begin{array}{@{}l@{}}
\{(\pc_{loc}, 6)\} \text{ where } \\
\pc_{loc} \equiv \pc_1 \lor \pc_2 \lor \pc_3\\
\end{array}
&
\left\{
\begin{array}{@{}l@{}}
(\pc_1, r_0^2 + 2),\\
(\pc_2 \lor \pc_3, r_0)
\end{array} \right\}& \{(\pc_{loc}, 2x_0)\} & \{(\pc_{loc}, z_0)\} \\ \hline
\Sigma_{78}&
\only<1-2>{
\left\{
\begin{array}{@{}l@{}}
(\pc_{loc} \land \alert{\pc_1 \only<1>{\land \bcancel{(r_0^2 + 2 > 1)}\TT}}, 7), \\
(\pc_{loc} \land \alert{(\pc_2 \lor \pc_3) \land (r_0 > 1)}, 7), \\
(\only<2>{\bcancel}{\pc_{loc} \land \alert{\pc_1 \land \only<1>{\bcancel{\neg(r_0^2 + 2 > 1)}}\FF}, 8}), \\
(\pc_{loc} \land \alert{(\pc_2 \lor \pc_3) \land \neg(r_0 > 1)}, 8)\\
\end{array}\right\}
}\only<3->{
\left\{
\begin{array}{@{}l@{}}
(
\left.
\begin{array}{@{}l@{}}
\pc_{loc} \land \pc_1 \ \lor \\
\pc_{loc} \land (\pc_2 \lor \pc_3) \land (r_0 > 1) \\
\end{array}\right., 7), \\
\\
(\pc_{loc} \land (\pc_2 \lor \pc_3) \land \neg(r_0 > 1), 8) \\
\end{array}\right\}
}
&
\left\{
\begin{array}{@{}l@{}}
(\pc_1, r_0^2 + 2),\\
(\pc_2 \lor \pc_3, r_0)
\end{array}\right\} & \{(\pc_{loc}, 2x_0)\} & \{(\pc_{loc}, z_0)\} \\
\end{array}
$
\end{center}
\end{overlayarea}
\begin{overlayarea}{\textwidth}{.44\textheight}
\only<1>{
Program configuration $\Sigma$ maps a variable to a \alert{\emph{\ValSum}}\\
\begin{itemize}
\item A \ValSum is a set of \emph{\GuardExps}\\
\item A \GuardExp is a pair of guard \pc and symbolic expression $e$
\item Each $(\pc, e) \in \Sigma(r)$ can be regarded as $\pc \land (r_1 = e)$ in last slide
\end{itemize}
}\only<2>{
\begin{itemize}
\item Merged path condition is encoded by $\pc_{loc}$ in $\Sigma(loc)$
\item Operators are extended to accept \textbf{combinations} of \GuardExps
\begin{itemize}
\item Theoretically \ValSums grow exponentially
\end{itemize}
\end{itemize}
}\only<3->{
Eager simplification on the value summary of each variable
\begin{itemize}
\item Remove $(\pc, v)$ when $\pc \equiv \FF$ (Check UNSATisfiable)
\item Merge $(\pc, v)$ and $(\pc', v)$ to $(\pc \lor \pc', v)$
\begin{itemize}
\item Dynamically merge at joint point (same $loc$ value)
\end{itemize}
\item Represent and manipulate guards using Binary Decision Diagram~(BDD)
\end{itemize}
}
\end{overlayarea}
\end{frame}
\begin{frame}[fragile]{Comparison}
{\footnotesize
$$
\begin{array}{l|c|cccc}
& \pc & loc & r & x & z \\ \hline
\widehat{M6} & \widehat{\pc} \equiv
\left(\begin{array}{l}
(\pc_1 \land \textcolor{red}{r_1 = r_0^2 + 2}) \\
\lor(\pc_2 \land \textcolor{red}{r_1 = r_0}) \\
\lor(\pc_3 \land \textcolor{red}{r_1 = r_0})
\end{array}\right) & 6 & \alert{r_1} & 2x_0 & z_0 \\\hline
\widehat{M7} & \widehat{\pc} \land \alert{(r_1 > 1)} & 7 & \alert{r_1} & 2x_0 & z_0 \\
\widehat{M8} & \widehat{\pc} \land \alert{\neg(r_1 > 1)} & 8 & \alert{r_1} & 2x_0 & z_0
\end{array}
$$
$
\begin{array}{@{}l|@{}c@{}c@{}c@{}c@{}}
& loc & r & x & z \\ \hline
\Sigma_6 &
\begin{array}{@{}l@{}}
\{(\pc_{loc}, 6)\} \text{ where } \\
\pc_{loc} \equiv \pc_1 \lor \pc_2 \lor \pc_3\\
\end{array}
&
\left\{
\begin{array}{@{}l@{}}
(\pc_1, r_0^2 + 2),\\
(\pc_2 \lor \pc_3, r_0)
\end{array} \right\}& \{(\pc_{loc}, 2x_0)\} & \{(\pc_{loc}, z_0)\} \\ \hline
\Sigma_{78} &
\left\{
\begin{array}{@{}l@{}}
(\left.
\begin{array}{@{}l@{}}
\pc_{loc} \land \pc_1 \ \lor \\
\pc_{loc} \land (\pc_2 \lor \pc_3) \land (r_0 > 1) \\
\end{array}\right., 7), \\
(\pc_{loc} \land(\pc_2 \lor \pc_3) \land \neg(r_0 > 1), 8), \\
\end{array}
\right\}
&
\left\{
\begin{array}{@{}l@{}}
(\pc_1, r_0^2 + 2),\\
(\pc_2 \lor \pc_3, r_0)
\end{array}\right\} & \{(\pc_{loc}, 2x_0)\} & \{(\pc_{loc}, z_0)\} \\
\end{array}
$}
Benefits of Value Summaries
\begin{itemize}
\item Avoid predicate $r_1 = r_0^2 + 2$
\myopinion
\item Explicitly exclude infeasible path $r_1 = r_0^2 + 2 \land \neg (r_1 > 1)$
\item Can possibly simplify $\pc_{loc}$ to \TT
\end{itemize}
\end{frame}
\begin{frame}{BDD Representation for Guards}
\begin{itemize}
\item Represent Boolean formulas using Binary Decision Diagram~(BDD)
\begin{itemize}
\item Check UNSAT with BDD before UNSAT with SMT solver
{\myopinion
\item Mapping from predicates to Boolean variables\\
E.g. $\pc = \neg(2x_0 > 0) \land (r_0 > 1)$ \\
Let $(2x_0 > 0) \mapsto b_1$ and $(r_0 > 1) \mapsto b_2$ \\
BDD stores the formula $\neg b_1 \land b_2$
\item This is a SAT-preserving transformation to Boolean formula
}
\end{itemize}
\item Benefits of using BDD
\begin{itemize}
\myopinion
\item Simplify and canonicalize Boolean formula by construction
\item Fast UNSAT checking
\begin{itemize}
\myopinion
\item Detect infeasible paths with UNSAT path conditions
\item Remove \GuardExps with UNSAT guards
\end{itemize}
\end{itemize}
\end{itemize}
\end{frame}
\section{Implementation}\label{sec:impl}
\begin{frame}{Implementation}
\MultiSE execution for JavaScript using the Jalangi framework
\begin{itemize}
\item \url{https://github.com/SRA-SiliconValley/jalangi/tree/multise}
\item SMT Solver: CVC3
\begin{itemize}
\item Theory of Linear Integer Arithmetic and Strings
\end{itemize}
\item BDD Package: author implemented
\end{itemize}
\end{frame}
\section{Evaluation}\label{sec:eval}
\begin{frame}{Evaluation Setup}
Experiment Environment
\begin{itemize}
\item Laptop with 2.3 GHz Intel Core i7 and 16 GB RAM
\end{itemize}
Benchmark
\begin{itemize}
\item 15 JavaScript programs provided by authors
\end{itemize}
Research Questions
\begin{itemize}
\item RQ1: Effectiveness of sharing using \ValSums
\item RQ2: Runtime cost of \MultiSE among its components
\item RQ3: Performance gains compared to traditional SE
\item RQ4: Increase on \emph{precise} state merging compared to CSM
\begin{itemize}
\item Imprecise state merging happens when unsupported predicates appear in path conditions
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Evaluation}
\includegraphics[width=\textwidth]{evaluation.png}
\begin{itemize}
\only<1>{
\item RQ1: Average Size of \ValSum for each variable is between 1-30
and \# Paths/Size ratio shows that the sharing is effective
\item RQ2: BDD query is actually negligible in most benchmarks
}\only<2>{
\item RQ3: Speed up due to much less solver queries using \ValSum
\item RQ4: Large amount of imprecise merges in CSM in some benchmarks
}
\end{itemize}
\end{frame}
\section{Conclusion}
\begin{frame}{Conclusion}
\begin{itemize}
\item \ValSums maintain symbolic values separated from path conditions
\begin{itemize}
\myopinion
\item Symbolic values not used in if-condition does not complicate
path conditions
\item If symbolic values is used in if-condition,
the path condition may still be simplified for infeasible paths
\end{itemize}
\item \MultiSE dynamically finds and merges at joint points
\begin{itemize}
\myopinion
\item More search strategies are applicable
\end{itemize}
\item Evaluation shows size of \ValSums normally is much less than \# Paths
\end{itemize}
\end{frame}
\begin{frame}
\printbibliography
\end{frame}
\appendix
\section*{Appendices}
\begin{frame}{My Questions}
\begin{itemize}
\item How would different search strategies on SE Tree affects \MultiSE?
\end{itemize}
\end{frame}
%\begin{frame}{\SymExe Variants}
% \begin{itemize}
% \item (Static) \SymExe
% \item \DynSymExe a.k.a. Concolic Testing
% \end{itemize}
% \todoline{Cite DART CUTE}
%\end{frame}
%
%\begin{frame}{\SymExe Semantics}
%
%\end{frame}
\begin{frame}{\MultiSE Semantics}
\includegraphics[width=\textwidth]{semantics.png}
\end{frame}
\end{document}
|
To address the many challenges facing today’s eye care practices amidst unprecedented change in the industry, CooperVision, Inc. has unveiled the Best Practices EYEdea Lab. This first-of-its-kind “think tank” will take place on June 21 in the exhibit hall at Optometry’s Meeting 2018 in Denver. In the EYEdea Lab, Best Practices honorees will leverage their collective experiences and expertise to advance the profession. |
[STATEMENT]
lemma nres_of_simps[simp]:
"nres_of dSUCCEED = SUCCEED"
"nres_of dFAIL = FAIL"
"nres_of (dRETURN x) = RETURN x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. nres_of dSUCCEED = SUCCEED &&& nres_of dFAIL = FAIL &&& nres_of (dRETURN x) = RETURN x
[PROOF STEP]
apply -
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. nres_of dSUCCEED = SUCCEED
2. nres_of dFAIL = FAIL
3. nres_of (dRETURN x) = RETURN x
[PROOF STEP]
unfolding nres_of_def bot_dres_def top_dres_def
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. (case dSUCCEEDi of dSUCCEEDi \<Rightarrow> SUCCEED | dFAILi \<Rightarrow> FAIL | dRETURN x \<Rightarrow> RETURN x) = SUCCEED
2. (case dFAILi of dSUCCEEDi \<Rightarrow> SUCCEED | dFAILi \<Rightarrow> FAIL | dRETURN x \<Rightarrow> RETURN x) = FAIL
3. (case dRETURN x of dSUCCEEDi \<Rightarrow> SUCCEED | dFAILi \<Rightarrow> FAIL | dRETURN x \<Rightarrow> RETURN x) = RETURN x
[PROOF STEP]
by (auto simp del: dres_internal_simps) |
[STATEMENT]
lemma USUP_true [simp]: "(\<Squnion> P | F(P) \<bullet> true) = true"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. USUP F (\<lambda>P. true) = true
[PROOF STEP]
by (pred_auto) |
I new to the site. I live in Cape Town South Africa, and have recently been diagnosed with Severe allergies. Main ones pollution and pollen, but I feel I am getting worse.. the GP has given me Pulmicort turbuhaler and Asthavent inhaler, not sure I am getting any relieve from the Pulmicort..
please let me know about your experiences with these.
Welcome to this forum. To answer your question, the pulmicort turbo haler is a steroid inhaler that will reduce the inflammation in your lungs. It will not give you instant relief. You need to use it as prescribed. This is a really good drug, but it takes about a week to 10 days to start having an effect and up to 3 weeks to reach its full effectiveness.
Asthavent, is albuterol, a quick acting reliever to reduce immediate symptoms.
As someone who is newly diagnosed it may take a while for your doctor to get your drugs at the right level. If you are still very symptomatic after taking these medications for a couple of weeks you need to go back to your doctor. There are lots and lots of different Asthma medications and some work better for some people than others.
If you are not taking an antihistamine, perhaps that would help. Also as you are allergic ask your doctor about taking a montelukast when you next see them.
Thank you so much for replying to my message. This is a something new for me to deal with, and it doesn't help that a live in a beautiful country like Cape Town..
I have been taking the Pulmicort haler for 3 mths now and wasn't told it was this information.
Some days I can hardly breath with it, I was working and living in Dubai up to December 2016 and I was never this bad, only allergic to mosquito which caused me to be very sick indeed..
I've just put a load of stuff about salt therapy in other threads. Look it up on the internet. Salt inhaler, salt lights.
I have a salt inhaler & am convinced it's helped me.
Hi Martin, thanks for replying to me, I do have a himalaya lamp which helps but now the summer is coming I feel so ill with the pollen and pollution I have a very bad reaction to mosquitoes and now I have sand bites from my hike yesterday.. just so fed up.. it's only since I moved to Cape Town I suffer with asthma etc.
Pollen & pollution are a problem for many in a lot of places. Defo try the Himalayan salt inhaler. It claims to help with allergy problems. I have a duoresp spiromax inhaler that I just use once in the morning & once in the evening. I've found that brilliant.
Don't know your full situation but you make the comment.. "it's only since I moved to Cape Town I suffer with asthma etc.".
Where were you before? Could you move back or somewhere different?
In search for a school for severe asthma!
Food and drink allergies and asthma. |
/-
Copyright (c) 2022 Matthias Uschold. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Matthias Uschold.
-/
import ..free_groups
import ..subgroup
open function
open bounded_continuous_function
/-!
# DEMO : Implementation of Amenable Groups in Lean
In this file, we demonstrate the implementation of amenable groups in Lean.
This is intended to be done during a talk
## Main Steps
* Definition of Amenability
* Definition of (left invariant) means
* Theorem: If a group contains a free group (more precisely:
of rank at least 2), then it is not amenable
## Note
We sometimes use the namespace 'hidden' in this file to avoid name clashes with existing declarations
(mainly for amenable, etc.).
-/
namespace hidden
variables (G:Type*) [group G]
structure mean
:= mk ::
(lin_map : (bounded_continuous_function G ℝ) →ₗ[ℝ] ℝ)
(normality : lin_map (const G 1) = 1)
(positivity: ∀ {f : bounded_continuous_function G ℝ},
(∀ (x:G), f x ≥ 0) → lin_map f ≥ 0)
structure left_invariant_mean
extends mean G
:= mk ::
(left_invariance: ∀ g:G , ∀ f, lin_map (g•f) = lin_map f)
def amenable
: Prop
:= nonempty (left_invariant_mean G)
end hidden
section
/-!
### Example
If a group G contains a free group
(more precisely: If there is an injective group homomorphisms from a free group (of rank at least 2) into
the group), then it is not amenable
-/
theorem contains_free_implies_not_amenable
{G : Type*} [group G]
{X : Type*}
{x y : X}
(x_neq_y : x ≠ y) -- needs to be added later
{i : free_group X →* G}
(i_injective : injective i)
: ¬ amenable G
:= begin
assume G_amenable : amenable G,
have range_amenable : amenable i.range
:= amenable_of_subgroup i.range G_amenable,
have iso_freeX : i.range ≃* free_group X
:= iso_range_of_injective' i_injective,
have freeX_amenable : amenable (free_group X)
:= amenable_of_iso iso_freeX range_amenable,
have freeX_not_amenable : ¬ amenable (free_group X)
:= not_amenable_of_free x_neq_y,
contradiction,
end
#check @not_amenable_of_free
end
|
[STATEMENT]
lemma useful_tautologies_9[PLM]:
"[(\<phi> \<^bold>\<rightarrow> \<psi>) \<^bold>\<rightarrow> ((\<^bold>\<not>\<phi> \<^bold>\<rightarrow> \<psi>) \<^bold>\<rightarrow> \<psi>) in v]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. [\<phi> \<^bold>\<rightarrow> \<psi> \<^bold>\<rightarrow> (\<^bold>\<not>\<phi> \<^bold>\<rightarrow> \<psi> \<^bold>\<rightarrow> \<psi>) in v]
[PROOF STEP]
by (metis CP useful_tautologies_4 vdash_properties_10) |
/* cdf/poisson.c
*
* Copyright (C) 2004 Jason H. Stover.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* Computes the cumulative distribution function for a Poisson
* random variable. For a Poisson random variable X with parameter
* mu,
*
* Pr( X <= k ) = Pr( Y >= p )
*
* where Y is a gamma random variable with parameters k+1 and 1.
*
* Reference:
*
* W. Feller, "An Introduction to Probability and Its
* Applications," volume 1. Wiley, 1968. Exercise 46, page 173,
* chapter 6.
*/
#include <config.h>
#include <math.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_cdf.h>
#include "error.h"
/*
* Pr (X <= k) for a Poisson random variable X.
*/
double
gsl_cdf_poisson_P (const unsigned int k, const double mu)
{
double P;
double a;
if (mu <= 0.0)
{
CDF_ERROR ("mu <= 0", GSL_EDOM);
}
a = (double) k + 1.0;
P = gsl_cdf_gamma_Q (mu, a, 1.0);
return P;
}
/*
* Pr ( X > k ) for a Possion random variable X.
*/
double
gsl_cdf_poisson_Q (const unsigned int k, const double mu)
{
double Q;
double a;
if (mu <= 0.0)
{
CDF_ERROR ("mu <= 0", GSL_EDOM);
}
a = (double) k + 1.0;
Q = gsl_cdf_gamma_P (mu, a, 1.0);
return Q;
}
|
------------------------------------------------------------------------
-- Lists of identifiers
------------------------------------------------------------------------
-- This example is based on one in Swierstra and Chitil's "Linear,
-- bounded, functional pretty-printing".
{-# OPTIONS --guardedness #-}
module Examples.Identifier-list where
open import Codata.Musical.Notation
open import Data.List
import Data.List.NonEmpty as List⁺
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Examples.Identifier
open import Grammar.Infinite as Grammar
using (Grammar) hiding (module Grammar)
open import Pretty using (Pretty-printer)
open import Renderer
open import Utilities
identifier-list-body : Grammar (List Identifier)
identifier-list-body =
return []
∣ List⁺.toList <$> (identifier-w sep-by symbol′ ",")
where open Grammar
identifier-list : Grammar (List Identifier)
identifier-list = symbol′ "[" ⊛> identifier-list-body <⊛ symbol′ "]"
where open Grammar
open Pretty
identifier-list-printer : Pretty-printer identifier-list
identifier-list-printer ns = symbol ⊛> body ns <⊛ symbol
where
body : Pretty-printer identifier-list-body
body [] = left nil
body (n ∷ ns) =
right (<$> (<$> identifier-w-printer n
⊛
map⋆ (λ n → group symbol-line ⊛>
identifier-w-printer n)
ns))
identifiers : List Identifier
identifiers = str⁺ "aaa" ∷ str⁺ "bbbbb" ∷ str⁺ "ccc" ∷
str⁺ "dd" ∷ str⁺ "eee" ∷ []
test₁ : render 80 (identifier-list-printer identifiers) ≡
"[aaa, bbbbb, ccc, dd, eee]"
test₁ = refl
test₂ : render 11 (identifier-list-printer identifiers) ≡
"[aaa,\nbbbbb, ccc,\ndd, eee]"
test₂ = refl
test₃ : render 8 (identifier-list-printer identifiers) ≡
"[aaa,\nbbbbb,\nccc, dd,\neee]"
test₃ = refl
|
Formal statement is: lemma snd_im_cbox [simp]: "cbox a b \<noteq> {} \<Longrightarrow> (snd ` cbox (a,c) (b,d)) = cbox c d" Informal statement is: If $a < b$, then the image of the box $[a,b] \times [c,d]$ under the projection onto the second coordinate is the interval $[c,d]$. |
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
Sums of finite geometric series
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.group_with_zero.power
import Mathlib.algebra.big_operators.order
import Mathlib.algebra.big_operators.ring
import Mathlib.algebra.big_operators.intervals
import Mathlib.PostPort
universes u u_1
namespace Mathlib
/-- Sum of the finite geometric series $\sum_{i=0}^{n-1} x^i$. -/
def geom_series {α : Type u} [semiring α] (x : α) (n : ℕ) : α :=
finset.sum (finset.range n) fun (i : ℕ) => x ^ i
theorem geom_series_def {α : Type u} [semiring α] (x : α) (n : ℕ) : geom_series x n = finset.sum (finset.range n) fun (i : ℕ) => x ^ i :=
rfl
@[simp] theorem geom_series_zero {α : Type u} [semiring α] (x : α) : geom_series x 0 = 0 :=
rfl
@[simp] theorem geom_series_one {α : Type u} [semiring α] (x : α) : geom_series x 1 = 1 := sorry
@[simp] theorem op_geom_series {α : Type u} [ring α] (x : α) (n : ℕ) : opposite.op (geom_series x n) = geom_series (opposite.op x) n := sorry
/-- Sum of the finite geometric series $\sum_{i=0}^{n-1} x^i y^{n-1-i}$. -/
def geom_series₂ {α : Type u} [semiring α] (x : α) (y : α) (n : ℕ) : α :=
finset.sum (finset.range n) fun (i : ℕ) => x ^ i * y ^ (n - 1 - i)
theorem geom_series₂_def {α : Type u} [semiring α] (x : α) (y : α) (n : ℕ) : geom_series₂ x y n = finset.sum (finset.range n) fun (i : ℕ) => x ^ i * y ^ (n - 1 - i) :=
rfl
@[simp] theorem geom_series₂_zero {α : Type u} [semiring α] (x : α) (y : α) : geom_series₂ x y 0 = 0 :=
rfl
@[simp] theorem geom_series₂_one {α : Type u} [semiring α] (x : α) (y : α) : geom_series₂ x y 1 = 1 := sorry
@[simp] theorem geom_series₂_with_one {α : Type u} [semiring α] (x : α) (n : ℕ) : geom_series₂ x 1 n = geom_series x n := sorry
/-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/
protected theorem commute.geom_sum₂_mul_add {α : Type u} [semiring α] {x : α} {y : α} (h : commute x y) (n : ℕ) : geom_series₂ (x + y) y n * x + y ^ n = (x + y) ^ n := sorry
theorem geom_series₂_self {α : Type u_1} [comm_ring α] (x : α) (n : ℕ) : geom_series₂ x x n = ↑n * x ^ (n - 1) := sorry
/-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/
theorem geom_sum₂_mul_add {α : Type u} [comm_semiring α] (x : α) (y : α) (n : ℕ) : geom_series₂ (x + y) y n * x + y ^ n = (x + y) ^ n :=
commute.geom_sum₂_mul_add (commute.all x y) n
theorem geom_sum_mul_add {α : Type u} [semiring α] (x : α) (n : ℕ) : geom_series (x + 1) n * x + 1 = (x + 1) ^ n :=
eq.mp (Eq._oldrec (Eq.refl (geom_series₂ (x + 1) 1 n * x + 1 = (x + 1) ^ n)) (geom_series₂_with_one (x + 1) n))
(eq.mp (Eq._oldrec (Eq.refl (geom_series₂ (x + 1) 1 n * x + 1 ^ n = (x + 1) ^ n)) (one_pow n))
(commute.geom_sum₂_mul_add (commute.one_right x) n))
theorem geom_sum₂_mul_comm {α : Type u} [ring α] {x : α} {y : α} (h : commute x y) (n : ℕ) : geom_series₂ x y n * (x - y) = x ^ n - y ^ n := sorry
theorem geom_sum₂_mul {α : Type u} [comm_ring α] (x : α) (y : α) (n : ℕ) : geom_series₂ x y n * (x - y) = x ^ n - y ^ n :=
geom_sum₂_mul_comm (commute.all x y) n
theorem geom_sum_mul {α : Type u} [ring α] (x : α) (n : ℕ) : geom_series x n * (x - 1) = x ^ n - 1 :=
eq.mp (Eq._oldrec (Eq.refl (geom_series₂ x 1 n * (x - 1) = x ^ n - 1)) (geom_series₂_with_one x n))
(eq.mp (Eq._oldrec (Eq.refl (geom_series₂ x 1 n * (x - 1) = x ^ n - 1 ^ n)) (one_pow n))
(geom_sum₂_mul_comm (commute.one_right x) n))
theorem mul_geom_sum {α : Type u} [ring α] (x : α) (n : ℕ) : (x - 1) * geom_series x n = x ^ n - 1 := sorry
theorem geom_sum_mul_neg {α : Type u} [ring α] (x : α) (n : ℕ) : geom_series x n * (1 - x) = 1 - x ^ n := sorry
theorem mul_neg_geom_sum {α : Type u} [ring α] (x : α) (n : ℕ) : (1 - x) * geom_series x n = 1 - x ^ n := sorry
theorem geom_sum {α : Type u} [division_ring α] {x : α} (h : x ≠ 1) (n : ℕ) : geom_series x n = (x ^ n - 1) / (x - 1) := sorry
theorem geom_sum_Ico_mul {α : Type u} [ring α] (x : α) {m : ℕ} {n : ℕ} (hmn : m ≤ n) : (finset.sum (finset.Ico m n) fun (i : ℕ) => x ^ i) * (x - 1) = x ^ n - x ^ m := sorry
theorem geom_sum_Ico_mul_neg {α : Type u} [ring α] (x : α) {m : ℕ} {n : ℕ} (hmn : m ≤ n) : (finset.sum (finset.Ico m n) fun (i : ℕ) => x ^ i) * (1 - x) = x ^ m - x ^ n := sorry
theorem geom_sum_Ico {α : Type u} [division_ring α] {x : α} (hx : x ≠ 1) {m : ℕ} {n : ℕ} (hmn : m ≤ n) : (finset.sum (finset.Ico m n) fun (i : ℕ) => x ^ i) = (x ^ n - x ^ m) / (x - 1) := sorry
theorem geom_sum_inv {α : Type u} [division_ring α] {x : α} (hx1 : x ≠ 1) (hx0 : x ≠ 0) (n : ℕ) : geom_series (x⁻¹) n = x - 1⁻¹ * (x - x⁻¹ ^ n * x) := sorry
theorem ring_hom.map_geom_series {α : Type u} {β : Type u_1} [semiring α] [semiring β] (x : α) (n : ℕ) (f : α →+* β) : coe_fn f (geom_series x n) = geom_series (coe_fn f x) n := sorry
theorem ring_hom.map_geom_series₂ {α : Type u} {β : Type u_1} [semiring α] [semiring β] (x : α) (y : α) (n : ℕ) (f : α →+* β) : coe_fn f (geom_series₂ x y n) = geom_series₂ (coe_fn f x) (coe_fn f y) n := sorry
|
(* Set Typeclasses Strict Resolution. *)
(* Set Typeclasses Unique Solutions. *)
Require Import UniDB.Spec.Core.
Require Import UniDB.Spec.Subst.
(******************************************************************************)
Instance iUpUnit : Up unit := fun _ _ => tt.
Instance iIdmUnit : Idm unit := tt.
Instance iCompUnit : Comp unit := fun _ _ => tt.
Instance iUpHomUnit : UpHom unit.
Proof. constructor; intro ξ; destruct ξ; reflexivity. Qed.
Instance iUpIdmUnit : UpIdm unit.
Proof. constructor; reflexivity. Qed.
Instance iLkUnit {T : Type} `{Vr T} : Lk T unit := fun _ i => vr T i.
Instance iLkIdmUnit {T : Type} `{Vr T} : LkIdm T unit.
Proof. constructor. Qed.
Instance iLkRenUnit {T : Type} `{Vr T} : LkRen T unit.
Proof. constructor. Qed.
Instance iLkUpUnit {T : Type} `{WkVr T} : LkUp T unit.
Proof. now apply make_lkup_inst_ren. Qed.
Class TrIdmUnit (T : Type) {vrT : Vr T} (X : Type) {trTX : Tr T X} :=
tr_idm_unit : ∀ (x : X), tr T X unit x tt = x.
(******************************************************************************)
|
Formal statement is: lemma (in algebra) smallest_ccdi_sets_Int: assumes b: "b \<in> smallest_ccdi_sets \<Omega> M" shows "a \<in> smallest_ccdi_sets \<Omega> M \<Longrightarrow> a \<inter> b \<in> smallest_ccdi_sets \<Omega> M" Informal statement is: If $b$ is a smallest closed-and-discrete set in $\Omega$ with respect to $M$, then for any smallest closed-and-discrete set $a$ in $\Omega$ with respect to $M$, $a \cap b$ is a smallest closed-and-discrete set in $\Omega$ with respect to $M$. |
[STATEMENT]
lemma abs_Gromov_completion_in_Gromov_boundary [simp]:
assumes "Gromov_converging_at_boundary u"
shows "abs_Gromov_completion u \<in> Gromov_boundary"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. abs_Gromov_completion u \<in> Gromov_boundary
[PROOF STEP]
using Gromov_completion_rel_to_const Gromov_converging_at_boundary_imp_not_constant'
Gromov_converging_at_boundary_rel[OF assms]
Quotient3_rel[OF Quotient3_Gromov_completion] assms not_in_Gromov_boundary to_Gromov_completion_def
[PROOF STATE]
proof (prove)
using this:
Gromov_completion_rel ?u (\<lambda>n. ?x) \<Longrightarrow> ?u ?n = ?x
Gromov_converging_at_boundary ?u \<Longrightarrow> \<not> (\<forall>m n. ?u m = ?u n)
Gromov_completion_rel u u
(Gromov_completion_rel ?r ?r \<and> Gromov_completion_rel ?s ?s \<and> abs_Gromov_completion ?r = abs_Gromov_completion ?s) = Gromov_completion_rel ?r ?s
Gromov_converging_at_boundary u
?x \<notin> Gromov_boundary \<Longrightarrow> \<exists>a. ?x = to_Gromov_completion a
to_Gromov_completion ?x = abs_Gromov_completion (\<lambda>n. ?x)
goal (1 subgoal):
1. abs_Gromov_completion u \<in> Gromov_boundary
[PROOF STEP]
by fastforce |
cd(@__DIR__)
using Pkg
Pkg.activate(".")
Pkg.instantiate()
module TestModule
export plusOne, multiply # functions, structs, and other objects that will be directly available once `using ModuleName` is typed
plusOne(x) = x + 1
multiply(x,y) = x * y
end
using .TestModule
plusOne(1.0)
plusOne(1)
multiply(2,3)
include("includedfoo.jl") # which strings will be printed ?
x # error not defined
foo.x
using foo # error: looking up for a package and of course can't find it
using .foo
x
foo.z()
foo.c() |
---
author: Nathan Carter ([email protected])
---
This answer assumes you have imported SymPy as follows.
```python
from sympy import * # load all math functions
init_printing( use_latex='mathjax' ) # use pretty math output
```
Here we define a simple mathematical formula, $\frac{x^2-x-2}{x-2}$,
and compute the limit as $x$ approaches 2. We use SymPy's built-in
`limit` function, which takes the formula $f(x)$, the variable $x$,
and the value $a$.
```python
var( 'x' )
formula = ( x**2 - x - 2 ) / ( x - 2 )
limit( formula, x, 2 )
```
$\displaystyle 3$
You can also compute one-sided limits. For instance,
the limit of $\frac{\vert x\vert}{x}$ is $1$ as $x$ approaches 0 from the right,
but it is $-1$ as $x$ approaches 0 from the left.
```python
limit( abs(x)/x, x, 0, "-" ) # "-" means from the left
```
$\displaystyle -1$
```python
limit( abs(x)/x, x, 0, "+" ) # "+" means from the right
```
$\displaystyle 1$
|
import tactic natree.pre
--natural trees are pre-trees quotiented by pre-tree equivalence
def natree := quotient natree.pre.equiv
namespace natree
notation `𝕋` := natree
def node : 𝕋 := ⟦▢⟧
notation `△` := node
def app' : 𝕋' → 𝕋' → 𝕋 := λ t₁ t₂, ⟦t₁ ◦ t₂⟧
lemma app'_liftable {a₁ a₂ b₁ b₂} (h₁ : a₁ ≈ b₁) (h₂ : a₂ ≈ b₂) : app' a₁ a₂ = app' b₁ b₂ := begin
repeat {rw wrapp},
apply quotient.sound,
apply pre.equiv.congr,
repeat {assumption}
end
def app : 𝕋 → 𝕋 → 𝕋 := quotient.lift₂ app' @app'_liftable
infixl `⬝`:60 := app
def ref (c) := ⟦pre.ref c⟧
prefix `&`:60 := ref
theorem quot_dist_app {a b} : ⟦a ◦ b⟧ = ⟦a⟧ ⬝ ⟦b⟧ := rfl
theorem kernel {y z} : △⬝△⬝y⬝z = y := begin
have h₁ := quotient.exists_rep y, cases h₁ with y' h₁, rw ←h₁,
have h₂ := quotient.exists_rep z, cases h₂ with z' h₂, rw ←h₂,
rw node,
repeat {rw ←quot_dist_app},
apply quotient.sound,
apply pre.equiv.kernel,
end
theorem stem {x y z} : △⬝(△⬝x)⬝y⬝z = y⬝z⬝(x⬝z) := begin
have h₁ := quotient.exists_rep x, cases h₁ with x' h₁, rw ←h₁,
have h₂ := quotient.exists_rep y, cases h₂ with y' h₂, rw ←h₂,
have h₃ := quotient.exists_rep z, cases h₃ with z' h₃, rw ←h₃,
rw node,
repeat {rw ←quot_dist_app},
apply quotient.sound,
apply pre.equiv.stem,
end
theorem fork {w x y z} : △⬝(△⬝w⬝x)⬝y⬝z = z⬝w⬝x := begin
have h₁ := quotient.exists_rep w, cases h₁ with w' h₁, rw ←h₁,
have h₂ := quotient.exists_rep x, cases h₂ with x' h₂, rw ←h₂,
have h₃ := quotient.exists_rep y, cases h₃ with y' h₃, rw ←h₃,
have h₄ := quotient.exists_rep z, cases h₄ with z' h₄, rw ←h₄,
rw node,
repeat {rw ←quot_dist_app},
apply quotient.sound,
apply pre.equiv.fork,
end
end natree |
[STATEMENT]
lemma ii_squared [simp]: "quat_ii\<^sup>2 = -1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<i>\<^sup>2 = - 1
[PROOF STEP]
by (simp add: power2_eq_square quat.expand) |
function alpha=solveAlpha(I,consts_map,consts_vals,varargin)
[h,w,c]=size(I);
img_size=w*h;
A=getLaplacian1(I,consts_map,varargin{:});
D=spdiags(consts_map(:),0,img_size,img_size);
lambda=100;
x=(A+lambda*D)\(lambda*consts_map(:).*consts_vals(:));
alpha=max(min(reshape(x,h,w),1),0);
|
\section*{Run \#28}
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{images/28/stream_image}
\end{figure}
\begin{figure}[H]
\centering
\includegraphics[width=\textwidth]{images/28/trajectories}
\end{figure}
|
/-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
! This file was ported from Lean 3 source module data.finite.set
! leanprover-community/mathlib commit 327c3c0d9232d80e250dc8f65e7835b82b266ea5
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Data.Fintype.Card
/-!
# Lemmas about `finite` and `set`s
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we prove two lemmas about `finite` and `set`s.
## Tags
finiteness, finite sets
-/
open Set
universe u v w x
variable {α : Type u} {β : Type v} {ι : Sort w}
#print Finite.Set.finite_of_finite_image /-
theorem Finite.Set.finite_of_finite_image (s : Set α) {f : α → β} (h : s.InjOn f)
[Finite (f '' s)] : Finite s :=
Finite.of_equiv _ (Equiv.ofBijective _ h.bijOn_image.Bijective).symm
#align finite.set.finite_of_finite_image Finite.Set.finite_of_finite_image
-/
#print Finite.of_injective_finite_range /-
theorem Finite.of_injective_finite_range {f : ι → α} (hf : Function.Injective f)
[Finite (range f)] : Finite ι :=
Finite.of_injective (Set.rangeFactorization f) (hf.codRestrict _)
#align finite.of_injective_finite_range Finite.of_injective_finite_range
-/
|
module photochem_wrk
use iso_c_binding, only: c_ptr
implicit none
public
integer, private, parameter :: real_kind = kind(1.0d0)
! this module contains stuff that changes
! over the course of a single integration. This includes
! initial conditions to non-linear solves, that must be preserved
! from one iteration to the next.
! this includes ANYTHING that gets written to during the course of an integration
! or anything that SHOULD get written to that i haven't fixed.
! needed in read_atmosphere.f90
real*8, allocatable, dimension(:,:) :: aersol ! aersol parameter
real*8, allocatable, dimension(:,:) :: wfall ! aersol parameter
real*8, allocatable, dimension(:,:) :: rpar ! aersol parameter
! needed in Aercon.f90
real*8, allocatable, dimension(:) :: FSULF
real*8, allocatable, dimension(:) :: H2SO4S
real*8, allocatable, dimension(:) :: S8S
! needed in photo.f90
real*8, allocatable, dimension(:,:,:) :: QEXTT, W0T, GFT
real(8), allocatable :: surf_radiance(:)
real(8), allocatable :: amean(:,:)
! needed in rates.f90
real*8, allocatable, dimension(:,:) :: A ! reaction rate coefficients
! needed in rainout.f90
real*8, allocatable, dimension(:,:) :: H
real*8, allocatable, dimension(:,:) :: RAINGC
real*8, allocatable, dimension(:) :: RAIN
real*8, allocatable, dimension(:,:) :: XSAVE
! needed in ltning.f90
real(8) :: prod_rates(8)
! needed in Difco.f90
real*8, allocatable, dimension(:) :: HSCALE
real*8, allocatable, dimension(:) :: tauedd
real*8, allocatable, dimension(:) :: DK
real*8, allocatable, dimension(:) :: H_ATM
real*8, allocatable, dimension(:,:) :: bx1x2
real*8, allocatable, dimension(:,:) :: SCALE_H
! needed in setup.f90
real*8, allocatable, dimension(:,:) :: DD,DL,DU,ADL,ADU,ADD
! needed in integrate.f90
real*8, allocatable, dimension(:,:) :: yp
real*8, allocatable, dimension(:,:) :: yl
real*8, allocatable, dimension(:,:) :: D ! density
! cvode
real*8 :: time_prev = -1.d0 ! for printing time
integer :: nsteps_previous = -10
character(len=1000) :: global_err = ''
!f2py integer(8) :: cvode_mem
type(c_ptr) :: cvode_mem
end module |
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_)
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub
open import Agda.Builtin.Cubical.Sub using () renaming (Sub to _[_↦_]; primSubOut to ouc)
open import Agda.Primitive renaming (_⊔_ to ℓ-max)
open import Agda.Builtin.Sigma
transpFill : ∀ {ℓ} {A' : Set ℓ} (φ : I)
(A : (i : I) → Set ℓ [ φ ↦ (\ _ → A') ]) →
(u0 : ouc (A i0)) →
PathP (λ i → ouc (A i)) u0 (primTransp (λ i → ouc (A i)) φ u0)
transpFill φ A u0 i = primTransp (\ j → ouc (A (i ∧ j))) (~ i ∨ φ) u0
-- private
-- internalFiber : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) (y : B) → Set (ℓ-max ℓ ℓ')
-- internalFiber {A = A} f y = Σ A \ x → y ≡ f x
-- infix 4 _≃_
-- postulate
-- _≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ-max ℓ ℓ')
-- equivFun : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → A ≃ B → A → B
-- equivProof : ∀ {la lt} (T : Set la) (A : Set lt) → (w : T ≃ A) → (a : A)
-- → ∀ ψ → (Partial ψ (internalFiber (equivFun w) a)) → internalFiber (equivFun w) a
-- {-# BUILTIN EQUIV _≃_ #-}
-- {-# BUILTIN EQUIVFUN equivFun #-}
-- {-# BUILTIN EQUIVPROOF equivProof #-}
-- -- This is a module so we can easily rename the primitives.
-- module GluePrims where
-- primitive
-- primGlue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
-- → (T : Partial φ (Set ℓ')) → (e : PartialP φ (λ o → T o ≃ A))
-- → Set ℓ'
-- prim^glue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
-- → {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
-- → PartialP φ T → A → primGlue A T e
-- prim^unglue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
-- → {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
-- → primGlue A T e → A
-- -- Needed for transp in Glue.
-- primFaceForall : (I → I) → I
open import Agda.Builtin.Cubical.Glue public
renaming ( prim^glue to glue
; prim^unglue to unglue)
-- We uncurry Glue to make it a bit more pleasant to use
Glue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
→ (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
→ Set ℓ'
Glue A Te = primGlue A (λ x → Te x .fst) (λ x → Te x .snd)
module TestHComp {ℓ ℓ'} (A : Set ℓ) {φ : I} (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
(ψ : I) (u : I → Partial ψ (Glue A Te)) (u0 : Sub (Glue A Te) ψ (u i0) ) where
result : Glue A Te
result = glue {φ = φ} (\ { (φ = i1) → primHComp {A = Te itIsOne .fst} u (primSubOut u0) })
(primHComp {A = A} (\ i → \ { (ψ = i1) → unglue {φ = φ} (u i itIsOne)
; (φ = i1) → equivFun (Te itIsOne .snd)
(primHComp (\ j → \ { (ψ = i1) → u (i ∧ j) itIsOne
; (i = i0) → primSubOut u0 })
(primSubOut u0)) })
(unglue {φ = φ} (primSubOut u0)))
test : primHComp {A = Glue A Te} {ψ} u (primSubOut u0) ≡ result
test i = primHComp {A = Glue A Te} {ψ} u (primSubOut u0)
module TestTransp {ℓ ℓ'} (A : Set ℓ) {φ : I} (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
(u0 : (Glue A Te)) where
ψ = i0
a0 = unglue {φ = φ} u0
a1 = primComp (\ _ → A)
φ
(\ { i (φ = i1) → equivFun (Te itIsOne .snd) (transpFill {A' = Te itIsOne .fst} ψ (\ i → inc (Te itIsOne .fst)) u0 i) })
a0
pair : PartialP φ λ o → Helpers.fiber (Te o .snd .fst) a1
pair o = equivProof (Te o .fst) A (Te o .snd) a1 φ \ { (φ = i1) → _ , Helpers.refl }
result : Glue A Te
result = glue {φ = φ} (λ o → pair o .fst) (primHComp (\ { j (φ = i1) → pair itIsOne .snd j}) a1)
test : primTransp (\ _ → Glue A Te) ψ u0 ≡ result
test = Helpers.refl
|
[STATEMENT]
lemma Rwhile_sound: assumes "Rwhile S = Some S'"
shows "\<forall>C \<in> S'. Resolution S C"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<forall>C\<in>S'. S \<turnstile> C
[PROOF STEP]
apply(rule while_option_rule[OF _ assms[unfolded Rwhile_def]])
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>s. \<lbrakk>\<forall>C\<in>s. S \<turnstile> C; \<box> \<notin> s \<and> \<not> res s \<subseteq> s\<rbrakk> \<Longrightarrow> \<forall>C\<in>res s \<union> s. S \<turnstile> C
2. \<forall>C\<in>S. S \<turnstile> C
[PROOF STEP]
apply (auto simp: Ass R res_def split: if_splits literal.splits)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
(* Piet programming language *)
(*
Coloure cycles:
* Hue Cycle: red -> yellow -> green -> cyan -> blue -> magenta -> red
* Lightness Cycle: light -> normal -> dark -> light
*)
Inductive Hue : Type :=
| Red
| Yellow
| Green
| Cyan
| Blue
| Magenta
| Black
| White
.
Inductive Lightness : Type :=
| Light
| Normal
| Dark
.
Definition hue_cycle (h : Hue) : Hue :=
match h with
| Red => Yellow
| Yellow => Green
| Green => Cyan
| Cyan => Blue
| Blue => Magenta
| Magenta => Red
| Black => Black
| White => White
end.
Definition lightness_cycle (l : Lightness) : Lightness :=
match l with
| Light => Normal
| Normal => Dark
| Dark => Light
end.
Lemma hue_one_loop (h : Hue) : (hue_cycle (hue_cycle (hue_cycle (hue_cycle (hue_cycle (hue_cycle h)))))) = h.
destruct h.
all: simpl.
all: reflexivity.
Qed.
Lemma lightness_one_loop (l : Lightness) : (lightness_cycle (lightness_cycle (lightness_cycle l))) = l.
destruct l.
all: simpl.
all: reflexivity.
Qed.
Lemma foo : forall A:Type, forall P:A->Prop, forall x y:A, (x=y) -> (P x = P y).
Proof.
intros.
rewrite H.
reflexivity.
Qed.
|
module BoltzmannMachinesPlots
# This module allows to run the examples without plotting anything,
# such that the testing does not have the BoltzmannMachinesPlots package
# as a requirement.
function plotevaluation(args1...; kwargs...) end
function crossvalidationcurve(args1...; kwargs...) end
end |
lemma holomorphic_on_Un [holomorphic_intros]: assumes "f holomorphic_on A" "f holomorphic_on B" "open A" "open B" shows "f holomorphic_on (A \<union> B)" |
#ifndef TOURNAMENTPIVOTING_H
#define TOURNAMENTPIVOTING_H
#include <stdio.h>
#include <stdlib.h>
#include "SuiteSparseQR_C.h"
#include <string.h>
#include <math.h>
#include <mpi.h>
#ifdef MKL
#include <mkl.h>
#else
#include <lapacke.h>
#endif
#define ASSERT(t_) if(!(t_)) printf("WARNING %s, line %d\n",__FILE__,__LINE__)
#ifndef MAX
#define MAX(a_,b_) ((a_)>(b_)?(a_):(b_))
#endif
#define DBL_EPSILON 1e-15
int preAlps_tournamentPivoting(MPI_Comm comm, int *colPtr, int *rowInd, double *a, int m, int n, int nnz, long col_offset, int k, long *Jc,
double *Sval, int printSVal, int ordering);
int preAlps_tournamentPivotingQR(MPI_Comm comm, int *colPtr, int *rowInd, double *a, int m, int n, int nnz,
long col_offset, int k, long *Jc, double *Sval, int printSVal, int checkFact, int printFact, int ordering);
int preAlps_tournamentPivotingCUR(MPI_Comm comm, int *colPtr, int *rowInd, double *a, int m, int n, int nnz,
long col_offset, int k, long *Jr, long *Jc, double *Sval, int printSVal, int checkFact, int printFact, int ordering);
#endif
|
SUBROUTINE ITEMA2 (STATE, I1,I2,GOT)
C READ FOR UPDATE AND LOCK AN ITEM-SET
C GF 20.08.1980
C
INCLUDE 'PARS.f'
INCLUDE 'ITES.f'
INCLUDE 'STAS.f'
INCLUDE 'PRIS.f'
INTEGER*2 PARASK
INTEGER*2 I1,I2
= ,GOT ! = 1 (0) IF THE STATE WAS (NOT) REALLY READ
= ,STATE ! ACCESS TO THIS ITEM-SET
C
ITE(1) = STAITE(STATE)
I1 = 1
I2 = ITE(1)
RETURN
C----
IF (ITEPAG .GT. 1 .OR. ITEPAG .LT. 0)
= CALL ASSERT (152,STATE,STAITE(STATE))
CALL ITEMA1 (STATE, ITE(1),GOT)
I1 = 1
I2 = ITE(1)
RETURN
END
|
import data.nat.basic
import tactic.ring
import tactic
noncomputable theory
open_locale classical
open nat
open set
variable {α : Type}
variables { a b c : set α}
theorem first_theorem : a ∩ b ⊆ a :=
begin
intros x h,
exact h.left,
end
theorem second_theorem : a ∩ b = b ∩ a :=
begin
ext x,
split,
intro h,
exact ⟨h.right, h.left⟩,
intro h,
exact ⟨h.right, h.left⟩,
end
theorem third_theorem : a ⊆ a ∪ b :=
begin
intros x h,
left,
exact h,
end
|
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import topology.instances.real
import order.filter.archimedean
/-!
# Convergence of subadditive sequences
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
A subadditive sequence `u : ℕ → ℝ` is a sequence satisfying `u (m + n) ≤ u m + u n` for all `m, n`.
We define this notion as `subadditive u`, and prove in `subadditive.tendsto_lim` that, if `u n / n`
is bounded below, then it converges to a limit (that we denote by `subadditive.lim` for
convenience). This result is known as Fekete's lemma in the literature.
-/
noncomputable theory
open set filter
open_locale topology
/-- A real-valued sequence is subadditive if it satisfies the inequality `u (m + n) ≤ u m + u n`
for all `m, n`. -/
def subadditive (u : ℕ → ℝ) : Prop :=
∀ m n, u (m + n) ≤ u m + u n
namespace subadditive
variables {u : ℕ → ℝ} (h : subadditive u)
include h
/-- The limit of a bounded-below subadditive sequence. The fact that the sequence indeed tends to
this limit is given in `subadditive.tendsto_lim` -/
@[irreducible, nolint unused_arguments]
protected def lim := Inf ((λ (n : ℕ), u n / n) '' (Ici 1))
lemma lim_le_div (hbdd : bdd_below (range (λ n, u n / n))) {n : ℕ} (hn : n ≠ 0) :
h.lim ≤ u n / n :=
begin
rw subadditive.lim,
apply cInf_le _ _,
{ rcases hbdd with ⟨c, hc⟩,
exact ⟨c, λ x hx, hc (image_subset_range _ _ hx)⟩ },
{ apply mem_image_of_mem,
exact zero_lt_iff.2 hn }
end
lemma apply_mul_add_le (k n r) : u (k * n + r) ≤ k * u n + u r :=
begin
induction k with k IH, { simp only [nat.cast_zero, zero_mul, zero_add] },
calc
u ((k+1) * n + r)
= u (n + (k * n + r)) : by { congr' 1, ring }
... ≤ u n + u (k * n + r) : h _ _
... ≤ u n + (k * u n + u r) : add_le_add_left IH _
... = (k+1 : ℕ) * u n + u r : by simp; ring
end
lemma eventually_div_lt_of_div_lt {L : ℝ} {n : ℕ} (hn : n ≠ 0) (hL : u n / n < L) :
∀ᶠ p in at_top, u p / p < L :=
begin
have I : ∀ (i : ℕ), 0 < i → (i : ℝ) ≠ 0,
{ assume i hi, simp only [hi.ne', ne.def, nat.cast_eq_zero, not_false_iff] },
obtain ⟨w, nw, wL⟩ : ∃ w, u n / n < w ∧ w < L := exists_between hL,
obtain ⟨x, hx⟩ : ∃ x, ∀ i < n, u i - i * w ≤ x,
{ obtain ⟨x, hx⟩ : bdd_above (↑(finset.image (λ i, u i - i * w) (finset.range n))) :=
finset.bdd_above _,
refine ⟨x, λ i hi, _⟩,
simp only [upper_bounds, mem_image, and_imp, forall_exists_index, mem_set_of_eq,
forall_apply_eq_imp_iff₂, finset.mem_range, finset.mem_coe, finset.coe_image] at hx,
exact hx _ hi },
have A : ∀ (p : ℕ), u p ≤ p * w + x,
{ assume p,
let s := p / n,
let r := p % n,
have hp : p = s * n + r, by rw [mul_comm, nat.div_add_mod],
calc u p = u (s * n + r) : by rw hp
... ≤ s * u n + u r : h.apply_mul_add_le _ _ _
... = s * n * (u n / n) + u r : by { field_simp [I _ hn.bot_lt], ring }
... ≤ s * n * w + u r : add_le_add_right
(mul_le_mul_of_nonneg_left nw.le (mul_nonneg (nat.cast_nonneg _) (nat.cast_nonneg _))) _
... = (s * n + r) * w + (u r - r * w) : by ring
... = p * w + (u r - r * w) : by { rw hp, simp only [nat.cast_add, nat.cast_mul] }
... ≤ p * w + x : add_le_add_left (hx _ (nat.mod_lt _ hn.bot_lt)) _ },
have B : ∀ᶠ p in at_top, u p / p ≤ w + x / p,
{ refine eventually_at_top.2 ⟨1, λ p hp, _⟩,
simp only [I p hp, ne.def, not_false_iff] with field_simps,
refine div_le_div_of_le_of_nonneg _ (nat.cast_nonneg _),
rw mul_comm,
exact A _ },
have C : ∀ᶠ (p : ℕ) in at_top, w + x / p < L,
{ have : tendsto (λ (p : ℕ), w + x / p) at_top (𝓝 (w + 0)) :=
tendsto_const_nhds.add (tendsto_const_nhds.div_at_top tendsto_coe_nat_at_top_at_top),
rw add_zero at this,
exact (tendsto_order.1 this).2 _ wL },
filter_upwards [B, C] with _ hp h'p using hp.trans_lt h'p,
end
/-- Fekete's lemma: a subadditive sequence which is bounded below converges. -/
theorem tendsto_lim (hbdd : bdd_below (range (λ n, u n / n))) :
tendsto (λ n, u n / n) at_top (𝓝 h.lim) :=
begin
refine tendsto_order.2 ⟨λ l hl, _, λ L hL, _⟩,
{ refine eventually_at_top.2
⟨1, λ n hn, hl.trans_le (h.lim_le_div hbdd ((zero_lt_one.trans_le hn).ne'))⟩ },
{ obtain ⟨n, npos, hn⟩ : ∃ (n : ℕ), 0 < n ∧ u n / n < L,
{ rw subadditive.lim at hL,
rcases exists_lt_of_cInf_lt (by simp) hL with ⟨x, hx, xL⟩,
rcases (mem_image _ _ _).1 hx with ⟨n, hn, rfl⟩,
exact ⟨n, zero_lt_one.trans_le hn, xL⟩ },
exact h.eventually_div_lt_of_div_lt npos.ne' hn }
end
end subadditive
|
(* This file is automatically generated from the OCaml source file
<repository_root>/ml_sources/examples/reliable_communication/lib/repdb/log_code.ml *)
From aneris.aneris_lang Require Import ast.
From aneris.aneris_lang.lib Require Import list_code.
(** Operations on log of requests *)
Definition log_create : val := λ: <>, ref ([], #0).
Definition log_add_entry : val :=
λ: "log" "req",
let: "lp" := ! "log" in
let: "data" := Fst "lp" in
let: "next" := Snd "lp" in
let: "data'" := list_append "data" ["req"] in
"log" <- ("data'", ("next" + #1)).
Definition log_next : val := λ: "log", Snd ! "log".
Definition log_length : val := λ: "log", Snd ! "log".
Definition log_get : val := λ: "log" "i", list_nth (Fst ! "log") "i".
Definition log_wait_until : val :=
λ: "log" "mon" "i",
letrec: "aux" <> :=
let: "n" := log_next "log" in
(if: "n" = "i"
then monitor_wait "mon";;
"aux" #()
else assert: ("i" < "n")) in
(if: ("i" < #0) || ((log_next "log") < "i")
then assert: #false
else "aux" #()).
|
module Oscar.Category where
open import Oscar.Level
open import Oscar.Function
record Setoid {𝔬} (𝔒 : Ø 𝔬) 𝔮 : Ø 𝔬 ∙̂ ↑̂ 𝔮 where
infix 4 _≋_
field
_≋_ : 𝔒 → 𝔒 → Ø 𝔮
≋-reflexivity : ∀ {x} → x ≋ x
≋-symmetry : ∀ {x y} → x ≋ y → y ≋ x
≋-transitivity : ∀ {x y} → x ≋ y → ∀ {z} → y ≋ z → x ≋ z
record Semigroupoid
{𝔬} {𝔒 : Ø 𝔬}
{𝔪} (𝔐 : 𝔒 → 𝔒 → Ø 𝔪)
{𝔮} (𝔐-setoid : ∀ {x y} → Setoid (𝔐 x y) 𝔮)
: Ø 𝔬 ∙̂ 𝔪 ∙̂ 𝔮 where
instance _ = λ {x y} → 𝔐-setoid {x} {y}
open Setoid ⦃ … ⦄ using (_≋_)
infixr 9 _∙_
field
_∙_ : ∀ {y z} → 𝔐 y z → ∀ {x} → 𝔐 x y → 𝔐 x z
∙-extensionality : ∀ {x y} {f₁ f₂ : 𝔐 x y} → f₁ ≋ f₂ → ∀ {z} {g₁ g₂ : 𝔐 y z} → g₁ ≋ g₂ → g₁ ∙ f₁ ≋ g₂ ∙ f₂
∙-associativity : ∀ {w x} (f : 𝔐 w x) {y} (g : 𝔐 x y) {z} (h : 𝔐 y z) → (h ∙ g) ∙ f ≋ h ∙ (g ∙ f)
record Category
{𝔬} {𝔒 : Ø 𝔬}
{𝔪} {𝔐 : 𝔒 → 𝔒 → Ø 𝔪}
{𝔮} {𝔐-setoid : ∀ {x y} → Setoid (𝔐 x y) 𝔮}
(semigroupoid : Semigroupoid 𝔐 𝔐-setoid)
: Ø 𝔬 ∙̂ 𝔪 ∙̂ 𝔮 where
instance _ = λ {x y} → 𝔐-setoid {x} {y}
open Setoid ⦃ … ⦄ using (_≋_)
open Semigroupoid semigroupoid using (_∙_)
field
ε : ∀ {x} → 𝔐 x x
ε-left-identity : ∀ {x y} {f : 𝔐 x y} → ε ∙ f ≋ f
ε-right-identity : ∀ {x y} {f : 𝔐 x y} → f ∙ ε ≋ f
record Semifunctor
{𝔬₁} {𝔒₁ : Ø 𝔬₁}
{𝔪₁} {𝔐₁ : 𝔒₁ → 𝔒₁ → Ø 𝔪₁}
{𝔮₁} {𝔐₁-setoid : ∀ {x y} → Setoid (𝔐₁ x y) 𝔮₁}
(semigroupoid₁ : Semigroupoid 𝔐₁ 𝔐₁-setoid)
{𝔬₂} {𝔒₂ : Ø 𝔬₂}
{𝔪₂} {𝔐₂ : 𝔒₂ → 𝔒₂ → Ø 𝔪₂}
{𝔮₂} {𝔐₂-setoid : ∀ {x y} → Setoid (𝔐₂ x y) 𝔮₂}
(semigroupoid₂ : Semigroupoid 𝔐₂ 𝔐₂-setoid)
: Ø 𝔬₁ ∙̂ 𝔪₁ ∙̂ 𝔮₁ ∙̂ 𝔬₂ ∙̂ 𝔪₂ ∙̂ 𝔮₂
where
instance _ = λ {x y} → 𝔐₁-setoid {x} {y}
instance _ = λ {x y} → 𝔐₂-setoid {x} {y}
open Setoid ⦃ … ⦄ using (_≋_)
module ⒈ = Semigroupoid semigroupoid₁
module ⒉ = Semigroupoid semigroupoid₂
field
{μ} : 𝔒₁ → 𝔒₂
𝔣 : ∀ {x y} → 𝔐₁ x y → 𝔐₂ (μ x) (μ y)
𝔣-extensionality : ∀ {x y} → {f₁ f₂ : 𝔐₁ x y} → f₁ ≋ f₂ → 𝔣 f₁ ≋ 𝔣 f₂
𝔣-commutativity : ∀ {x y} {f : 𝔐₁ x y} {z} {g : 𝔐₁ y z} → 𝔣 (g ⒈.∙ f) ≋ 𝔣 g ⒉.∙ 𝔣 f
record Functor
{𝔬₁} {𝔒₁ : Ø 𝔬₁}
{𝔪₁} {𝔐₁ : 𝔒₁ → 𝔒₁ → Ø 𝔪₁}
{𝔮₁} {𝔐₁-setoid : ∀ {x y} → Setoid (𝔐₁ x y) 𝔮₁}
{semigroupoid₁ : Semigroupoid 𝔐₁ 𝔐₁-setoid}
{𝔬₂} {𝔒₂ : Ø 𝔬₂}
{𝔪₂} {𝔐₂ : 𝔒₂ → 𝔒₂ → Ø 𝔪₂}
{𝔮₂} {𝔐₂-setoid : ∀ {x y} → Setoid (𝔐₂ x y) 𝔮₂}
{semigroupoid₂ : Semigroupoid 𝔐₂ 𝔐₂-setoid}
(semifunctor : Semifunctor semigroupoid₁ semigroupoid₂)
(category₁ : Category semigroupoid₁)
(category₂ : Category semigroupoid₂)
: Ø 𝔬₁ ∙̂ 𝔪₁ ∙̂ 𝔮₁ ∙̂ 𝔬₂ ∙̂ 𝔪₂ ∙̂ 𝔮₂
where
instance _ = λ {x y} → 𝔐₂-setoid {x} {y}
open Setoid ⦃ … ⦄ using (_≋_)
open Semifunctor semifunctor using (𝔣; μ)
module ⒈ = Category category₁
module ⒉ = Category category₂
field
𝔣-identity : ∀ {x : 𝔒₁} → 𝔣 (⒈.ε {x = x}) ≋ (⒉.ε {x = μ x})
|
State Before: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
⊢ (a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) State After: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
⊢ (a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) Tactic: have h_rpow : ∀ a : ℝ≥0∞, a ^ q = (a ^ p) ^ (q / p) := fun a => by
rw [← ENNReal.rpow_mul, _root_.mul_div_cancel' _ hp_pos.ne'] State Before: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
⊢ (a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) State After: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
h_rpow_add_rpow_le_add : ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p
⊢ (a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) Tactic: have h_rpow_add_rpow_le_add :
((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p := by
refine' rpow_add_rpow_le_add (a ^ p) (b ^ p) _
rwa [one_le_div hp_pos] State Before: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
h_rpow_add_rpow_le_add : ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p
⊢ (a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) State After: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
h_rpow_add_rpow_le_add : ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p
⊢ ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (p / q) ≤ a ^ p + b ^ p Tactic: rw [h_rpow a, h_rpow b, ENNReal.le_rpow_one_div_iff hp_pos, ← ENNReal.rpow_mul, mul_comm,
mul_one_div] State Before: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
h_rpow_add_rpow_le_add : ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p
⊢ ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (p / q) ≤ a ^ p + b ^ p State After: no goals Tactic: rwa [one_div_div] at h_rpow_add_rpow_le_add State Before: ι : Type u
s : Finset ι
p q : ℝ
a✝ b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
a : ℝ≥0∞
⊢ a ^ q = (a ^ p) ^ (q / p) State After: no goals Tactic: rw [← ENNReal.rpow_mul, _root_.mul_div_cancel' _ hp_pos.ne'] State Before: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
⊢ ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p State After: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
⊢ 1 ≤ q / p Tactic: refine' rpow_add_rpow_le_add (a ^ p) (b ^ p) _ State Before: ι : Type u
s : Finset ι
p q : ℝ
a b : ℝ≥0∞
hp_pos : 0 < p
hpq : p ≤ q
h_rpow : ∀ (a : ℝ≥0∞), a ^ q = (a ^ p) ^ (q / p)
⊢ 1 ≤ q / p State After: no goals Tactic: rwa [one_le_div hp_pos] |
import number_theory.bernoulli
--OUTPUT 1
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
apply nat.strong_induction_on n,
clear n,
assume n hn x,
-- We want to prove that for all $m < d$, we have $B_{m} (1 + x) = B_{m} (x) + m x^{m - 1}$
assume h1 : ∀ m : ℕ, m < n → (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1),
-- We want to show that $$B_{d} (1 + x) = B_{d} (x) + d x^{d - 1}$$
have h2 : (polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1),
{
-- Multiplying both sides by $d + 1$, and using the fact that, for all $l \in \mathbb{N}$, $\sum_{k = 0}^{l} {l + 1 \choose k} B_k = (l + 1) X^l$ (where $B_k$ is the $k$-th Bernoulli number), we get that
have h3 : (n + 1) * (1 + x)^n - (n + 1) * x^n = (n + 1) * ∑ (l : ℕ) in finset.range (n + 1), (n + 1) * (finset.range (n + 1)).sum (λ (k : ℕ) (hk : k ∈ finset.range (n + 1)), (n + 1) * (polynomial.bernoulli k).eval x^k) * x^(l - 1),
{
apply polynomial.ext,
assume i,
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h4 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * ∑ (l : ℕ) in finset.range (n + 1), (n + 1) * (finset.range (n + 1)).sum (λ (k : ℕ) (hk : k ∈ finset.range (n + 1)), (n + 1) * (polynomial.bernoulli k).eval x^k) * x^(l - 1),
{
-- We want to prove that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h5 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto,
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h6 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h7 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h8 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h9 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h10 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h11 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h12 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h13 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h14 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
have h15 : (n + 1) * (1 + x)^i - (n + 1) * x^i = (n + 1) * (1 + x)^i - (n + 1) * x^i, from by auto [mul_sub],
-- We want to show that $$(d + 1) (1 + x)^i - (d + 1) x^i = \sum_{l = 0}^{d} {
end --Needs more than 2000 tokens!
--OUTPUT 2
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
-- We apply strong induction on $n$
by_cases (n = 0),
{
assume h0 : n = 0,
show (polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1), from by auto [h0, polynomial.bernoulli_zero]
},
{
assume h0 : n ≠ 0,
have h1 : ∀ (m : ℕ) (h : m < n), (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [lt_of_le_of_ne, polynomial.bernoulli_eval_one_add_lemma],
have h2 : ∀ (m : ℕ) (h : m > n), (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [lt_of_le_of_ne, polynomial.bernoulli_eval_one_add_lemma],
have h3 : ∀ (m : ℕ) (h : m = n), (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [lt_of_le_of_ne, polynomial.bernoulli_eval_one_add_lemma],
show (polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1), from by auto [h1, h2, h3, lt_irrefl, nat.not_succ_le_zero, nat.not_succ_le_self, nat.succ_pos, lt_or_eq_of_le, ne.def, eq.symm, lt_of_lt_of_le, lt_of_le_of_ne]
},
end
--OUTPUT 3
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
-- apply strong induction on $n$
apply nat.strong_induction_on n,
assume n (ih : ∀ m : ℕ, m < n → (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1)),
show (polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1),
-- multiply both sides by $d + 1$
calc (polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + (n + 1) * x^n : by auto [bernoulli_eval_add]
-- Using the fact that, for all $l \in \mathbb{N}$, $\sum_{k = 0}^{l} {l + 1 \choose k} B_k = (l + 1) X^l$
... = (polynomial.bernoulli n).eval x + (n + 1) * x^n : by rw [nat.sum_eq_sum_binomial, add_comm, polynomial.eval_pow, polynomial.eval_C],
-- The conclusion then follows easily.
... = (polynomial.bernoulli n).eval x + n * x^(n - 1) : by rw [nat.sub_add_cancel, nat.sub_add_cancel]
end
--OUTPUT 4
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
-- We apply strong induction on $n$.
induction n with d hd,
-- So, for all $m < d$, we have $B_{m} (1 + x) = B_{m} (x) + m x^{m - 1}$
-- and we want to show that $$B_{d} (1 + x) = B_{d} (x) + d x^{d - 1}$$
have h1 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h2 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h3 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h4 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h5 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h6 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h7 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h8 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h9 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h10 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h11 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h12 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h13 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h14 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h15 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h16 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h17 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h18 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h19 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h20 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h21 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h22 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h23 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h24 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h25 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h26 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h27 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h28 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h29 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h30 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h31 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h32 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h33 : ∀ m < d, (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from by auto [hd],
have h34 : ∀ m < d, (polynomial.bernoulli
end --Needs more than 2000 tokens!
--OUTPUT 5
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
have h1 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli m = (m + 1) * polynomial.X^m - ∑ l in finset.range (m + 1), (m + 1) * (finset.range (m + 1)).sum (λ (k : ℕ), (m + 1) * (polynomial.X^k) * polynomial.bernoulli k / (k + 1)), from
by auto [polynomial.eval_sum, polynomial.eval_pow, polynomial.eval_X, polynomial.eval_C, polynomial.X_ne_zero, polynomial.eval_smul, polynomial.eval_add, polynomial.eval_sub, polynomial.eval_C],
have h2 : ∀ (m : ℕ) (x : ℚ), (m + 1) * polynomial.X^m - ∑ l in finset.range (m + 1), (m + 1) * (finset.range (m + 1)).sum (λ (k : ℕ), (m + 1) * (polynomial.X^k) * polynomial.bernoulli k / (k + 1)) = m * polynomial.X^m - ∑ l in finset.range m, m * (finset.range m).sum (λ (k : ℕ), m * (polynomial.X^k) * polynomial.bernoulli k / (k + 1)), from
by auto [polynomial.eval_sum, polynomial.eval_pow, polynomial.eval_X, polynomial.eval_C, polynomial.X_ne_zero, polynomial.eval_smul, polynomial.eval_add, polynomial.eval_sub, polynomial.eval_C],
have h3 : ∀ (m : ℕ) (x : ℚ), (m + 1) * polynomial.X^m - ∑ l in finset.range m, m * (finset.range m).sum (λ (k : ℕ), m * (polynomial.X^k) * polynomial.bernoulli k / (k + 1)) = m * polynomial.X^m - ∑ l in finset.range m, m * (finset.range m).sum (λ (k : ℕ), m * (polynomial.X^k) * polynomial.bernoulli k / (k + 1)) + polynomial.X^m + m * polynomial.X^(m - 1) * polynomial.bernoulli m / (m + 1), from
by auto [polynomial.eval_sum, polynomial.eval_pow, polynomial.eval_X, polynomial.eval_C, polynomial.X_ne_zero, polynomial.eval_smul, polynomial.eval_add, polynomial.eval_sub, polynomial.eval_C],
have h4 : ∀ (m : ℕ) (x : ℚ), m * polynomial.X^m - ∑ l in finset.range m, m * (finset.range m).sum (λ (k : ℕ), m * (polynomial.X^k) * polynomial.bernoulli k / (k + 1)) + polynomial.X^m + m * polynomial.X^(m - 1) * polynomial.bernoulli m / (m + 1) = polynomial.X^m + m * polynomial.X^(m - 1) * polynomial.bernoulli m / (m + 1), from
by auto [polynomial.eval_sum, polynomial.eval_pow, polynomial.eval_X, polynomial.eval_C, polynomial.X_ne_zero, polynomial.eval_smul, polynomial.eval_add, polynomial.eval_sub, polynomial.eval_C],
have h5 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli m = polynomial.X^m + m * polynomial.X^(m - 1) * polynomial.bernoulli m / (m + 1), from
by auto [h1, h2, h3, h4],
have h6 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli m = polynomial.X^m + m * polynomial.X^(m - 1) * polynomial.bernoulli m / (m + 1), from
by auto [h5],
have h7 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h6],
have h8 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h7],
have h9 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h8],
have h10 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h9],
have h11 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h10],
have h12 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h11],
have h13 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h12],
have h14 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h13],
have h15 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h14],
have h16 : ∀ (m : ℕ) (x : ℚ), polynomial.bernoulli (m + 1) = polynomial.bernoulli m + (m + 1) * polynomial.X^m * polynomial.bernoulli (m + 1) / (m + 2), from
by auto [h15],
have h17 : ∀ (m :
end --Needs more than 2000 tokens!
--OUTPUT 6
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
have h1 : (∀ m : ℕ, m < n → (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1)),
{ assume m,
assume hm : m < n,
induction m with m IH hm,
{ -- base case
show (polynomial.bernoulli 0).eval (1 + x) = (polynomial.bernoulli 0).eval x + 0 * x^(0 - 1),
by auto using [bernoulli_zero, eval_zero, eval_one, zero_add, zero_mul]
},
{ -- inductive step
have hm1 : m < n, from nat.lt_of_succ_lt hm,
have h1 : (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1), from IH hm1,
have h2 : (polynomial.bernoulli (m + 1)).eval (1 + x) = (polynomial.bernoulli (m + 1)).eval x + (m + 1) * x^((m + 1) - 1),
{
calc (polynomial.bernoulli (m + 1)).eval (1 + x) = (polynomial.bernoulli (m + 1)).eval x + m * (1 + x)^(m + 1) - (m + 1) * x^(m + 1) : by auto [bernoulli_add_one, eval_add, eval_mul, eval_pow]
... = (polynomial.bernoulli (m + 1)).eval x + m * (1 + x)^m * (1 + x) - (m + 1) * x^(m + 1) : by rw nat.succ_eq_add_one
... = (polynomial.bernoulli (m + 1)).eval x + m * (1 + x)^m * (1 + x) - (m + 1) * x^m * x : by rw nat.succ_eq_add_one
... = (polynomial.bernoulli (m + 1)).eval x + m * (1 + x)^m * (1 + x) - m * x^m * x - x^m * x : by rw nat.add_sub_cancel
... = (polynomial.bernoulli (m + 1)).eval x + m * (1 + x)^m * (1 + x) - m * x^m * x - x^m * x : by rw mul_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * (1 + x)^m * 1 - m * x^m * x - x^m * x : by rw mul_one
... = (polynomial.bernoulli (m + 1)).eval x + m * (1 + x)^m * 1 - m * x^m * x - x^m * x : by rw one_mul
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m * 1) - m * x^m * x - x^m * x : by rw mul_one
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m * 1) - (m * x^m * x + x^m * x) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m * 1) - m * x^m * x - x^m * x : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m * 1) - (m * x^m * x + x^m * x) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m * 1) - (m * x^m + x^m) * x : by rw mul_add
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m * 1) - m * x^m * x - x^m * x : by rw mul_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - m * x^m * x - x^m * x : by rw mul_one
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * x^m * x + x^m * x) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * x^m * x + x^m * x) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - m * x^m * x - x^m * x : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * x^m * x + x^m * x) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * x^m + x^m) * x : by rw mul_add
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - m * x^m * x - x^m * x : by rw mul_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * x^m * x + x^m * x) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * x^m + x^m) * x : by rw mul_add
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - m * x^m * x - x^m * x : by rw mul_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * x^m * x + x^m * x) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - ((m * x^m * x + x^m * x) + (m * ((1 + x)^m) - (m * x^m * x + x^m * x))) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - ((m * ((1 + x)^m) + (m * x^m * x + x^m * x)) + (m * ((1 + x)^m) - (m * x^m * x + x^m * x))) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * ((1 + x)^m) + (m * ((1 + x)^m) - (m * x^m * x + x^m * x))) : by rw add_comm
... = (polynomial.bernoulli (m + 1)).eval x + m * ((1 + x)^m) - (m * ((1 + x)^m) + ((m * ((1 + x)^m) - (m * x^m * x + x^m * x)) + (m * x^m * x + x^m * x))) : by rw add_comm
... = (polynomial.bernoulli (
end --Needs more than 2000 tokens!
--OUTPUT 7
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
-- We apply strong induction on $n$
apply nat.strong_induction_on n,
-- So, for all $m < d$, we have $B_{m} (1 + x) = B_{m} (x) + m x^{m - 1}$ and we want to show that $$B_{d} (1 + x) = B_{d} (x) + d x^{d - 1}$$
assume d,
assume h : ∀ m : ℕ, m < d → (polynomial.bernoulli m).eval (1 + x) = (polynomial.bernoulli m).eval x + m * x^(m - 1),
-- Multiplying both sides by $d + 1$, and using the fact that, for all $l \in \mathbb{N}$, $\sum_{k = 0}^{l} {l + 1 \choose k} B_k = (l + 1) X^l$ (where $B_k$ is the $k$-th Bernoulli number), we get that
have h1 : (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval x = (d + 1) * (x^d),
begin
-- Multiplying both sides by $d + 1$
calc (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval x = (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval x : by auto [ring]
... = (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x + -x) : by auto [ring]
... = (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x) + (d + 1) * (polynomial.bernoulli d).eval x : by auto [ring]
... = (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x) + (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval x : by auto [ring]
... = (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x) + (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval x : by auto [ring]
... = (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x) + (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x) - (d + 1) * (polynomial.bernoulli d).eval (1 + x) + (d + 1) * (polynomial.bernoulli d).eval x : by auto [ring]
... = (d + 1) * ((polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval x) : by auto [ring]
... = (d + 1) * ((polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval x) : by auto [ring]
... = (d + 1) * ((polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval x) : by auto [ring]
... = (d + 1) * ((polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval x) : by auto [ring]
... = (d + 1) * ((polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval x) : by auto [ring]
... = (d + 1) * ((polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval x) : by auto [ring]
... = (d + 1) * ((polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bernoulli d).eval (1 + x) + (polynomial.bernoulli d).eval (1 + x) - (polynomial.bern
end --Needs more than 2000 tokens!
--OUTPUT 8
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
begin
induction n with d hd,
{
-- base case
show (polynomial.bernoulli 0).eval (1 + x) = (polynomial.bernoulli 0).eval x + 0 * x^(0 - 1), from by auto [ring],
},
{
-- inductive case
have h1 : (polynomial.bernoulli d).eval (1 + x) = (polynomial.bernoulli d).eval x + d * x^(d - 1), from hd,
have h2 : (d + 1) * (polynomial.bernoulli (d + 1)).eval (1 + x) = (d + 1) * (polynomial.bernoulli (d + 1)).eval x + (d + 1) * (d + 1) * x^(d + 1 - 1), by auto [ring, h1],
have h3 : (d + 1) * (polynomial.bernoulli (d + 1)).eval (1 + x) = (d + 1) * (polynomial.bernoulli (d + 1)).eval x + (d + 1) * (d + 1) * x^(d), from by auto [ring],
have h4 : (d + 1) * (polynomial.bernoulli (d + 1)).eval (1 + x) - (d + 1) * (polynomial.bernoulli (d + 1)).eval x = (d + 1) * (d + 1) * x^(d), from by auto [ring],
have h5 : (d + 1) * (polynomial.bernoulli (d + 1)).eval (1 + x) - (d + 1) * (polynomial.bernoulli (d + 1)).eval x = (d + 1) * (d + 1 - 1) * x^(d - 1) + (d + 1) * x^(d - 1), from by auto [ring],
have h6 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (d + 1 - 1) * x^(d - 1) + (d + 1) * x^(d - 1), from by auto [ring, h4],
have h7 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (d + 1 - 1) * x^(d - 1) + (d + 1) * x^(d - 1), from by auto [ring],
have h8 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (d * x^(d - 1)) + (d + 1) * x^(d - 1), from by auto [ring],
have h9 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = d * (d + 1) * x^(d - 1) + (d + 1) * x^(d - 1), from by auto [ring],
have h10 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * ((d + 1) * x^(d - 1) + x^(d - 1)), from by auto [ring],
have h11 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + d * x^(d - 1) + x^(d - 1)), from by auto [ring],
have h12 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1) * d * x^(d - 1) + (d + 1) * x^(d - 1), from by auto [ring],
have h13 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1) * d * x^(d - 1) + (d + 1) * x^(d - 1), from by auto [ring],
have h14 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1) * x^(d - 1) + (d + 1) * d * x^(d - 1), from by auto [ring],
have h15 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1) * x^(d - 1) + (d + 1) * d * x^(d - 1), from by auto [ring],
have h16 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1) * (x^(d - 1) + d * x^(d - 1)), from by auto [ring],
have h17 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1) * ((d + 1) * x^(d - 1)), from by auto [ring],
have h18 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1)^2 * x^(d - 1), from by auto [ring],
have h19 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * x^(d - 1) + (d + 1)^2 * x^(d - 1), from by auto [ring],
have h20 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x^(d - 1)), from by auto [ring],
have h21 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x^(d - 1)), from by auto [ring],
have h22 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x^(d - 1)), from by auto [ring],
have h23 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x^(d - 1)), from by auto [ring],
have h24 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x^(d - 1)), from by auto [ring],
have h25 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x^(d - 1)), from by auto [ring],
have h26 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x^(d - 1)), from by auto [ring],
have h27 : (d + 1) * ((1 + x)^(d + 1) - x^(d + 1)) = (d + 1) * (x^(d - 1) + (d + 1) * x
end --Needs more than 2000 tokens!
/- FEW SHOT PROMPTS TO CODEX(START)
/--`theorem`
Power Set is Closed under Intersection
Let $S$ be a set.
Let $\powerset S$ be the power set of $S$.
Then:
:$\forall A, B \in \powerset S: A \cap B \in \powerset S$
`proof`
Let $A, B \in \powerset S$.
Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$.
From Intersection is Subset we have that $A \cap B \subseteq A$.
It follows from Subset Relation is Transitive that $A \cap B \subseteq S$.
Thus $A \cap B \in \powerset S$ and closure is proved.
{{qed}}
-/
theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=
begin
-- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$
assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),
-- Then $A ⊆ S$ and $B ⊆ S$, by power set definition
have h1 : (A ⊆ S) ∧ (B ⊆ S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],
-- Then $(A ∩ B) ⊆ A$, by intersection of set is a subset
have h2 : (A ∩ B) ⊆ A, from by auto [set.inter_subset_left],
-- Then $(A ∩ B) ⊆ S$, by subset relation is transitive
have h3 : (A ∩ B) ⊆ S, from by auto [set.subset.trans],
-- Hence $(A ∩ B) ∈ 𝒫 S$, by power set definition
show (A ∩ B) ∈ 𝒫 S, from by auto [set.mem_powerset],
end
/--`theorem`
Square of Sum
:$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$
`proof`
Follows from the distribution of multiplication over addition:
{{begin-eqn}}
{{eqn | l = \left({x + y}\right)^2
| r = \left({x + y}\right) \cdot \left({x + y}\right)
}}
{{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right)
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x^2 + 2xy + y^2
| c =
}}
{{end-eqn}}
{{qed}}
-/
theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) :=
begin
-- expand the power
calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]
-- distributive property of multiplication over addition gives:
... = x*(x+y) + y*(x+y) : by auto [add_mul]
-- applying the above property further gives:
... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]
-- rearranging the terms using commutativity and adding gives:
... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring]
end
/--`theorem`
Identity of Group is Unique
Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$.
`proof`
From Group has Latin Square Property, there exists a unique $x \in G$ such that:
:$a x = b$
and there exists a unique $y \in G$ such that:
:$y a = b$
Setting $b = a$, this becomes:
There exists a unique $x \in G$ such that:
:$a x = a$
and there exists a unique $y \in G$ such that:
:$y a = a$
These $x$ and $y$ are both $e$, by definition of identity element.
{{qed}}
-/
theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=
begin
-- Group has Latin Square Property
have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by auto using [use (a⁻¹ * b)],
have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by auto using [use b * a⁻¹],
-- Setting $b = a$, this becomes:
have h3 : ∀ a : G, ∃! x : G, a * x = a, from by auto [h1],
have h4 : ∀ a : G, ∃! y : G, y * a = a, from by auto [h2],
-- These $x$ and $y$ are both $(1 : G)$, by definition of identity element
have h5 : ∀ a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one],
have h6 : ∀ a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul],
show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)],
end
/--`theorem`
Bernoulli polynomial evaluation
Given a natural number $n$ and a rational $x$, let $B_n (x)$ denote the $n$-th Bernoulli polynomial evaluated at $x$. Then, $$B_n (1 + x) = B_n (x) + n x^{n - 1}$$
`proof`
We apply strong induction on $n$. So, for all $m < d$, we have $B_{m} (1 + x) = B_{m} (x) + m x^{m - 1}$ and we want to show that $$B_{d} (1 + x) = B_{d} (x) + d x^{d - 1}$$
Multiplying both sides by $d + 1$, and using the fact that, for all $l \in \mathbb{N}$, $\sum_{k = 0}^{l} {l + 1 \choose k} B_k = (l + 1) X^l$ (where $B_k$ is the $k$-th Bernoulli number), we get that
$$ (d + 1) (1 + x)^d - (d + 1) x^d = \sum_{l = 0}^{d} {d + 1 \choose l} l x^{l - 1} $$
The conclusion then follows easily.
QED
-/
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(polynomial.bernoulli n).eval (1 + x) = (polynomial.bernoulli n).eval x + n * x^(n - 1) :=
FEW SHOT PROMPTS TO CODEX(END)-/
|
import data.bool.subbool
import data.bool.misc
import algebra.theory
import algebra.theory.free
import .basic
/-
* F2-vector space structure on `bool`
-/
attribute [instance,reducible]
definition bool_bxor : model binary_module bool :=
{
act := λ n f, vect.foldl bxor ff,
haxiom :=
begin
intros,
cases r,
case binary_module.rels.left_zero {
dsimp [binary_module],
repeat {
csimp only [optree.elim_opnode,optree.elim_varleaf],
try {dsimp [vect.map,vect.foldl]}
},
rw [ff_bxor_safe],
},
case binary_module.rels.right_zero {
dsimp [binary_module],
repeat {
csimp only [optree.elim_opnode,optree.elim_varleaf],
try {dsimp [vect.map,vect.foldl]}
},
rw [bxor_ff_safe, ff_bxor_safe]
},
case binary_module.rels.add_self {
dsimp [binary_module],
repeat {
csimp only [optree.elim_opnode,optree.elim_varleaf],
try {dsimp [vect.map,vect.foldl]}
},
rw [ff_bxor_safe],
exact bxor_self_safe _
},
case binary_module.rels.add_comm {
dsimp [binary_module],
repeat {
csimp only [optree.elim_opnode,optree.elim_varleaf],
try {dsimp [vect.map,vect.foldl]}
},
rw [ff_bxor_safe,ff_bxor_safe],
exact bxor_comm _ _
},
case binary_module.rels.add_assoc {
dsimp [binary_module],
repeat {
csimp only [optree.elim_opnode,optree.elim_varleaf],
try {dsimp [vect.map,vect.foldl]}
},
repeat {rw [ff_bxor_safe]},
exact bxor_assoc _ _ _
},
end
}
#print axioms bool_bxor
namespace binary_module
definition generate {α : Type _} [model binary_module α] (a : α) : morphism binary_module bool α :=
{
val := @bool.rec (λ_, α) (binary_module.zero α) a,
property :=
begin
intros n f as,
cases f,
case binary_module.ops.zero {
cases as,
dsimp [premodel.act,vect.map,vect.foldl],
dunfold binary_module.zero,
refl
},
case binary_module.ops.add {
cases as with _ x bs; cases bs with _ y cs; cases cs,
dsimp [premodel.act],
cases x,
case bool.ff {
cases y,
case bool.ff {
let h := binary_module.add_zero (binary_module.zero α),
dunfold binary_module.add at h,
have : (vect.foldl bxor ff (vect.cons ff (vect.cons ff vect.nil)))=ff,
by refl,
rw [this]; dsimp at *,
dunfold vect.map,
rw [h],
},
case bool.tt {
let h := binary_module.zero_add a,
dunfold binary_module.add at h,
have : (vect.foldl bxor ff (vect.cons ff (vect.cons tt vect.nil)))=tt,
by refl,
rw [this]; dsimp at *,
dunfold vect.map,
rw [h]
}
},
case bool.tt {
cases y,
case bool.ff {
let h := binary_module.add_zero a,
dunfold binary_module.add at h,
have : (vect.foldl bxor ff (vect.cons tt (vect.cons ff vect.nil)))=tt,
by refl,
rw [this]; dsimp *,
dunfold vect.map,
rw [h]
},
case bool.tt {
let h := binary_module.add_self a,
dunfold binary_module.add at h,
have : (vect.foldl bxor ff (vect.cons tt (vect.cons tt vect.nil)))=ff,
by refl,
rw [this]; dsimp *,
dunfold vect.map,
rw [h]
}
},
}
end
}
#print axioms binary_module.generate
theorem bool_free : is_free binary_module (function.const unit tt) :=
begin
dunfold is_free,
intros γ hmc f,
existsi @generate _ hmc (f ()),
split; dsimp *,
focus {
intro a; cases a,
unfold generate
},
focus {
intros g hy,
dunfold generate,
dunfold function.const at hy,
apply subtype.eq; dunfold subtype.val,
apply funext,
intros b,
cases b,
case bool.ff {
let h := g.property binary_module.ops.zero vect.nil,
unfold premodel.act at h,
unfold vect.foldl at h,
dsimp * at *,
rw [h],
refl
},
case bool.tt {
dsimp *,
rw [hy]
},
}
end
#print axioms binary_module.bool_free
end binary_module
@[instance]
definition subbool_binmod (p : Prop) : model binary_module (subbool p) :=
{
act := λ n f, vect.foldl subbool.xor (subbool.ff p),
haxiom :=
begin
intros n r var,
cases r,
case binary_module.rels.left_zero {
dsimp [binary_module],
repeat { unfold optree.elim; try {unfold optree.elim_aux} },
dunfold vect.foldl,
exact subbool.ff_xor _
},
case binary_module.rels.right_zero {
dsimp [binary_module],
repeat { unfold optree.elim; try {unfold optree.elim_aux} },
dunfold vect.foldl,
rw [subbool.xor_ff,subbool.ff_xor],
},
case binary_module.rels.add_self {
dsimp [binary_module],
repeat { unfold optree.elim; try {unfold optree.elim_aux} },
dunfold vect.foldl,
rw [subbool.ff_xor, subbool.xor_self]
},
case binary_module.rels.add_comm {
dsimp [binary_module],
repeat { unfold optree.elim; try {unfold optree.elim_aux} },
dunfold vect.foldl,
csimp only [subbool.ff_xor, subbool.xor_comm]
},
case binary_module.rels.add_assoc {
dsimp [binary_module],
repeat { unfold optree.elim; try {unfold optree.elim_aux} },
dunfold vect.foldl,
csimp only [subbool.ff_xor, subbool.xor_assoc]
},
end
}
#print axioms subbool_binmod
namespace binary_module
@[reducible]
definition generate_p (p : Prop) {α : Type _} [model binary_module α] (a : p → α) : morphism binary_module (subbool p) α :=
{
val := λ x, @subtype.rec_on _ _ (λ_, α) x (λ b, @bool.cases_on (λ b, p∨b=ff → α) b (λ_, binary_module.zero α) (λ h, a (or.elim h id (λ h, by injection h)))),
property :=
begin
intros n f as,
dsimp *,
cases f,
case binary_module.ops.zero {
cases as,
dsimp [premodel.act,vect.map,vect.foldl],
unfold binary_module.zero,
},
case binary_module.ops.add {
cases as with _ x bs; cases bs with _ y cs; cases cs,
dsimp [premodel.act],
cases x; cases x_val,
case bool.ff {
cases y; cases y_val,
case bool.ff {
let h := binary_module.add_zero (binary_module.zero α),
unfold binary_module.add at h,
have : vect.foldl subbool.xor (subbool.ff p) ⁅⟨ff, x_property⟩, ⟨ff, y_property⟩⁆ = subbool.ff p,
by refl,
rw [this],
unfold vect.map,
rw [h],
},
case bool.tt {
have : p, from or.elim y_property id (λ h, by injection h),
let h := binary_module.zero_add (a this),
unfold binary_module.add at h,
have : vect.foldl subbool.xor (subbool.ff p) ⁅⟨ff, x_property⟩, ⟨tt, y_property⟩⁆ = subbool.tt (y_property.elim id (λ x, by injection x)),
by refl,
rw [this],
unfold vect.map,
rw [h],
}
},
case bool.tt {
cases y; cases y_val,
case bool.ff {
have : p, from or.elim x_property id (λ h, by injection h),
let h := binary_module.add_zero (a this),
unfold binary_module.add at h,
have : vect.foldl subbool.xor (subbool.ff p) ⁅⟨tt, x_property⟩, ⟨ff, y_property⟩⁆ = subbool.tt (x_property.elim id (λ x, by injection x)),
by refl,
rw [this],
unfold vect.map,
rw [h]
},
case bool.tt {
have : p, from or.elim x_property id (λ h, by injection h),
let h := binary_module.add_self (a this),
unfold binary_module.add at h,
have : vect.foldl subbool.xor (subbool.ff p) ⁅⟨tt, x_property⟩, ⟨tt, y_property⟩⁆ = subbool.ff p,
by refl,
rw [this],
unfold vect.map,
rw [h]
}
}
}
end
}
#print axioms generate_p
theorem subbool_free (p : Prop) : is_free binary_module (@subbool.tt p) :=
begin
intros γ mc f,
existsi @generate_p _ _ mc f,
split; dsimp *,
focus {
intro; refl
},
focus {
intros g hg,
unfold generate_p,
simp *,
apply subtype.eq; dunfold subtype.val,
apply funext,
intros x,
cases x,
cases x_val,
case bool.ff {
dsimp * at *,
let h := g.property binary_module.ops.zero vect.nil,
dsimp [premodel.act,vect.foldl] at h,
rw [h],
refl
},
case bool.tt {
dsimp * at *,
have : p,
from x_property.elim id (λ h, by injection h),
exact hg this
},
}
end
#print axioms subbool_free
end binary_module
|
sum_list <- sum |
-- Jesper, 2019-07-27. Cut down this example from a latent bug in
-- @antiUnify@, which was using @unAbs@ instead of @absBody@.
{-# OPTIONS --double-check #-}
open import Agda.Primitive
postulate
I : Set
T : ∀ {p} → Set (lsuc p) → Set (lsuc p)
t : ∀ {p} → (B : Set (lsuc p)) → (I → I → Set) → B → T B
x0 : I
R0 : I → I → Set
P0 : ∀ p → R0 x0 x0 → Set p
d0 : R0 x0 x0
C : ∀ {p} (X : Set) (x : (T (X → Set p))) → Set
f : ∀ {p} (R : I → I → Set) (P : R x0 x0 → Set p)
→ {{_ : C (R x0 x0) (t (R x0 x0 → Set p) R P)}}
→ (d : R x0 x0) → P d
instance
iDP : ∀ {p} → C (R0 x0 x0) (t (R0 x0 x0 → Set p) R0 (P0 p))
fails : ∀ p → P0 p d0
fails p = f _ (P0 p) d0
|
import Data.Bool
import Data.Complex (Complex((:+)), magnitude)
mandelbrot
:: RealFloat a
=> Complex a -> Complex a
mandelbrot a = iterate ((a +) . (^ 2)) 0 !! 50
main :: IO ()
main =
mapM_
putStrLn
[ [ bool ' ' '*' (2 > magnitude (mandelbrot (x :+ y)))
| x <- [-2,-1.9685 .. 0.5] ]
| y <- [1,0.95 .. -1] ]
|
Thailand officially observes 23 national holidays and several religious observances.
Buddhism is the predominant religion, practiced by around 95 percent of Thai citizens. The majority of traditional holidays are based on Buddhist culture and beliefs.
Government offices and immigration offices in Thailand are closed on these days so keep that in mind if you need to extend your visa or require consular services. Thai embassies and consulates outside of Thailand may also be closed on these dates. Where the actual date of the holiday falls on a Saturday or Sunday, a substitute holiday has been granted on the Monday. |
module Math.Ray where
import Numeric.LinearAlgebra
import Codec.Picture
type Vec3 = Vector Double
vec3 :: Double -> Double -> Double -> Vec3
vec3 x y z= vector $! [x,y,z]
data Ray = Ray
{-# UNPACK #-} !Vec3
{-# UNPACK #-} !Vec3
deriving Show
parametric :: Ray -> (Double -> Vec3)
parametric (Ray p v) k = p + scale k v
{-# INLINE parametric #-} |
module list-thms where
-- see list-thms2 for more
open import bool
open import bool-thms
open import functions
open import list
open import nat
open import nat-thms
open import product-thms
open import logic
++[] : ∀{ℓ}{A : Set ℓ} → (l : 𝕃 A) → l ++ [] ≡ l
++[] [] = refl
++[] (x :: xs) rewrite ++[] xs = refl
++-assoc : ∀ {ℓ}{A : Set ℓ} (l1 l2 l3 : 𝕃 A) →
(l1 ++ l2) ++ l3 ≡ l1 ++ (l2 ++ l3)
++-assoc [] l2 l3 = refl
++-assoc (x :: xs) l2 l3 rewrite ++-assoc xs l2 l3 = refl
length-++ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) →
length (l1 ++ l2) ≡ (length l1) + (length l2)
length-++ [] l2 = refl
length-++ (h :: t) l2 rewrite length-++ t l2 = refl
map-append : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} →
(f : A → B) (l1 l2 : 𝕃 A) →
map f (l1 ++ l2) ≡ (map f l1) ++ (map f l2)
map-append f [] l2 = refl
map-append f (x :: xs) l2 rewrite map-append f xs l2 = refl
map-compose : ∀ {ℓ ℓ' ℓ''} {A : Set ℓ} {B : Set ℓ'}{C : Set ℓ''} →
(f : B → C) (g : A → B) (l : 𝕃 A) →
map f (map g l) ≡ map (f ∘ g) l
map-compose f g [] = refl
map-compose f g (x :: xs) rewrite map-compose f g xs = refl
foldr-monoid : ∀{ℓ}{A B : Set ℓ}{l₁ l₂ : 𝕃 A}{_⊗_ : B → B → B}{f : A → B}{b : B}
{p-sym : ∀{a} → b ⊗ a ≡ a}
{p-assoc : ∀{a b c} → a ⊗ (b ⊗ c) ≡ (a ⊗ b) ⊗ c}
→ (foldr (λ x r → (f x) ⊗ r) b l₁) ⊗ (foldr (λ x r → (f x) ⊗ r) b l₂) ≡ foldr (λ x r → (f x) ⊗ r) b (l₁ ++ l₂)
foldr-monoid {ℓ}{A}{B}{[]}{l₂}{_⊗_}{f}{b}{p-sym} rewrite p-sym {foldr (λ x → _⊗_ (f x)) b l₂} = refl
foldr-monoid {ℓ}{A}{B}{y :: ys}{l₂}{_⊗_}{f}{b}{p-sym}{p-assoc}
rewrite
sym (p-assoc {f y}{foldr (λ x → _⊗_ (f x)) b ys}{foldr (λ x → _⊗_ (f x)) b l₂})
| foldr-monoid {l₁ = ys}{l₂}{_⊗_}{f}{b}{p-sym}{p-assoc}
= refl
foldr-append : ∀{ℓ₂}{B : Set ℓ₂}{l₁ l₂ : 𝕃 (𝕃 B)} → (foldr _++_ [] l₁) ++ (foldr _++_ [] l₂) ≡ foldr _++_ [] (l₁ ++ l₂)
foldr-append {l₁ = []}{l₂} = refl
foldr-append {_}{B}{l₁ = x :: xs}{l₂} rewrite sym (foldr-append {l₁ = xs}{l₂}) = ++-assoc x (foldr _++_ [] xs) (foldr _++_ [] l₂)
foldr-append-fun : ∀{ℓ₁ ℓ₂}{A : Set ℓ₁}{B : Set ℓ₂}{l₁ l₂ : 𝕃 (A → 𝕃 B)}{a : A}
→ (foldr (λ f → _++_ (f a)) [] l₁) ++ (foldr (λ f → _++_ (f a)) [] l₂) ≡ foldr (λ f → _++_ (f a)) [] (l₁ ++ l₂)
foldr-append-fun {l₁ = []}{_}{a} = refl
foldr-append-fun {l₁ = x :: l₁}{l₂}{a}
rewrite
++-assoc (x a) (foldr (λ f → _++_ (f a)) [] l₁) (foldr (λ f → _++_ (f a)) [] l₂)
| foldr-append-fun {l₁ = l₁}{l₂}{a}
= refl
foldr-map : ∀{ℓ}{A : Set ℓ}{l : 𝕃 A} → l ≡ foldr _++_ [] (map (λ x₁ → x₁ :: []) l)
foldr-map {_}{_}{[]} = refl
foldr-map {ℓ}{A}{x :: xs} rewrite sym (foldr-map {ℓ}{A}{xs}) = refl
invert𝕃 : ∀{ℓ}{A : Set ℓ}{t : A}{ts : 𝕃 A} → t :: ts ≢ []
invert𝕃 ()
length-repeat : ∀{ℓ}{A : Set ℓ} (n : ℕ) (a : A) → length (repeat n a) ≡ n
length-repeat 0 a = refl
length-repeat (suc n) a rewrite length-repeat n a = refl
map-repeat : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}(n : ℕ)(a : A)(f : A → B) → map f (repeat n a) ≡ repeat n (f a)
map-repeat 0 a f = refl
map-repeat (suc x) a f rewrite map-repeat x a f = refl
length-map : ∀{ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B)(l : 𝕃 A) → length (map f l) ≡ length l
length-map f [] = refl
length-map f (head :: tail) rewrite length-map f tail = refl
length-reverse-helper : ∀{ℓ}{A : Set ℓ}(h l : 𝕃 A) →
length (reverse-helper h l) ≡ length h + length l
length-reverse-helper h [] rewrite +0 (length h) = refl
length-reverse-helper h (x :: xs) rewrite length-reverse-helper (x :: h) xs = sym (+suc (length h) (length xs))
length-reverse : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → length (reverse l) ≡ length l
length-reverse l = length-reverse-helper [] l
reverse-++h : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → reverse-helper l1 l2 ≡ reverse-helper [] l2 ++ l1
reverse-++h l1 [] = refl
reverse-++h l1 (x :: xs) rewrite reverse-++h (x :: l1) xs | reverse-++h (x :: []) xs | ++-assoc (reverse xs) (x :: []) l1 = refl
reverse-++ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → reverse(l1 ++ l2) ≡ reverse(l2) ++ reverse(l1)
reverse-++ [] l2 rewrite ++[] (reverse l2) = refl
reverse-++ (x :: xs) l2 rewrite reverse-++h (x :: []) (xs ++ l2) | reverse-++ xs l2 | ++-assoc (reverse l2) (reverse xs) (x :: []) | sym (reverse-++h (x :: []) xs) = refl
reverse-involution-aux : ∀{ℓ}{A : Set ℓ}(h h' l : 𝕃 A) → reverse-helper h (reverse-helper h' l) ≡ (reverse-helper [] h') ++ l ++ h
reverse-involution-aux h h' [] = reverse-++h h h'
reverse-involution-aux h h' (x₁ :: l) rewrite reverse-involution-aux h (x₁ :: h') l | reverse-++h (x₁ :: []) h' | ++-assoc (reverse-helper [] h') (x₁ :: []) (l ++ h) = refl
reverse-involution : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → reverse (reverse l) ≡ l
reverse-involution l rewrite reverse-involution-aux [] [] l = ++[] l
reverse-++-bad : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → reverse-bad (l1 ++ l2) ≡ reverse-bad l2 ++ reverse-bad l1
reverse-++-bad [] l2 = sym (++[] (reverse-bad l2))
reverse-++-bad (x :: l1) l2 rewrite reverse-++-bad l1 l2 = ++-assoc (reverse-bad l2) (reverse-bad l1) (x :: [])
reverse-involution-bad : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → reverse-bad (reverse-bad l) ≡ l
reverse-involution-bad [] = refl
reverse-involution-bad (x :: xs) rewrite reverse-++-bad (reverse-bad xs) (x :: []) | reverse-involution-bad xs = refl
=𝕃-refl : ∀{ℓ}{A : Set ℓ}{l1 : 𝕃 A} → (eq : A → A → 𝔹) → ((x y : A) → x ≡ y → eq x y ≡ tt) → =𝕃 eq l1 l1 ≡ tt
=𝕃-refl{l1 = []} eq rise = refl
=𝕃-refl{l1 = x :: xs} eq rise = &&-combo (rise x x refl) (=𝕃-refl{l1 = xs} eq rise)
≡𝕃-from-= : ∀{ℓ}{A : Set ℓ}{l1 l2 : 𝕃 A} → (eq : A → A → 𝔹) → ((x y : A) → eq x y ≡ tt → x ≡ y) → =𝕃 eq l1 l2 ≡ tt → l1 ≡ l2
≡𝕃-from-={l1 = []}{[]} eq drop p = refl
≡𝕃-from-={l1 = x :: xs}{[]} eq drop ()
≡𝕃-from-={l1 = []}{y :: ys} eq drop ()
≡𝕃-from-={l1 = x :: xs}{y :: ys} eq drop p rewrite ≡𝕃-from-={l1 = xs} eq drop (&&-snd{eq x y}{=𝕃 eq xs ys} p) | drop x y (&&-fst p) = refl
=𝕃-from-≡ : ∀{ℓ}{A : Set ℓ}{l1 l2 : 𝕃 A} → (eq : A → A → 𝔹) → ((x y : A) → x ≡ y → eq x y ≡ tt) → l1 ≡ l2 → =𝕃 eq l1 l2 ≡ tt
=𝕃-from-≡{l2 = l2} eq rise p rewrite p = =𝕃-refl{l1 = l2} eq rise
multi++-assoc : ∀{ℓ}{A : Set ℓ} → (Ls : 𝕃 (𝕃 A)) → (l0 : 𝕃 A) → (foldr _++_ [] Ls) ++ l0 ≡ (foldr _++_ [] (Ls ++ [ l0 ]))
multi++-assoc [] l' rewrite ++[] l' = refl
multi++-assoc (l :: ls) l' rewrite ++-assoc l (foldr _++_ [] ls) l' | multi++-assoc ls l' = refl
concat-foldr : ∀{ℓ}{A : Set ℓ} → (ls : 𝕃 (𝕃 A)) → (l : 𝕃 A) → concat ls ++ l ≡ foldr _++_ l ls
concat-foldr [] l = refl
concat-foldr (l' :: ls) l rewrite ++-assoc l' (concat ls) l | concat-foldr ls l = refl
--concat-foldr (l' :: (l'' :: ls)) l rewrite ++-assoc l' (concat (l'' :: ls)) l | concat-foldr (l'' :: ls) l = refl
longer-trans : ∀{ℓ}{A : Set ℓ}(l1 l2 l3 : 𝕃 A) →
l1 longer l2 ≡ tt →
l2 longer l3 ≡ tt →
l1 longer l3 ≡ tt
longer-trans [] l2 l3 () q
longer-trans (x :: l1) [] l3 p ()
longer-trans (x :: l1) (x₁ :: l2) [] p q = refl
longer-trans (x :: l1) (x₁ :: l2) (x₂ :: l3) p q = longer-trans l1 l2 l3 p q
filter-idem : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l : 𝕃 A) →
(filter p (filter p l)) ≡ (filter p l)
filter-idem p [] = refl
filter-idem p (x :: l) with keep (p x)
filter-idem p (x :: l) | tt , p' rewrite p' | p' | filter-idem p l = refl
filter-idem p (x :: l) | ff , p' rewrite p' = filter-idem p l
length-filter : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l : 𝕃 A) →
length (filter p l) ≤ length l ≡ tt
length-filter p [] = refl
length-filter p (x :: l) with p x
length-filter p (x :: l) | tt = length-filter p l
length-filter p (x :: l) | ff =
≤-trans{length (filter p l)} (length-filter p l) (≤-suc (length l))
filter-++ : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l1 l2 : 𝕃 A) → filter p (l1 ++ l2) ≡ filter p l1 ++ filter p l2
filter-++ p [] l2 = refl
filter-++ p (x :: l1) l2 with p x
filter-++ p (x :: l1) l2 | tt rewrite (filter-++ p l1 l2) = refl
filter-++ p (x :: l1) l2 | ff rewrite (filter-++ p l1 l2) = refl
remove-++ : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l1 l2 : 𝕃 A) →
remove eq a (l1 ++ l2) ≡ remove eq a l1 ++ remove eq a l2
remove-++ eq a l1 l2 = filter-++ (λ x → ~ (eq a x)) l1 l2
::-injective : ∀{ℓ}{A : Set ℓ}{x y : A}{xs ys : 𝕃 A} →
x :: xs ≡ y :: ys → x ≡ y ∧ xs ≡ ys
::-injective refl = refl , refl
concat-++ : ∀{ℓ}{A : Set ℓ}(ls1 ls2 : 𝕃 (𝕃 A)) → concat (ls1 ++ ls2) ≡ (concat ls1) ++ (concat ls2)
concat-++ [] ls2 = refl
concat-++ (l :: ls) ls2 rewrite concat-++ ls ls2 = sym (++-assoc l (concat ls) (concat ls2))
-- This holds as long as we have the equations p₁ and p₂. We know
-- that these equations are consistant to adopt, because they are
-- equivalent up and an isomorphism, and hence, by univalence they are
-- consistent as equations. The respective isomorphisms can be found
-- in products-thms.agda.
all-pred-append : ∀{X : Set}{f : X → Set}{l₁ l₂}
→ (p₁ : ∀{ℓ}{A : Set ℓ} → A ≡ ((⊤ {ℓ}) ∧ A))
→ (p₂ : ∀{ℓ}{A B C : Set ℓ} → (A ∧ (B ∧ C)) ≡ ((A ∧ B) ∧ C))
→ all-pred f (l₁ ++ l₂) ≡ ((all-pred f l₁) ∧ (all-pred f l₂))
all-pred-append {l₁ = []} {l₂} p₁ p₂ = p₁
all-pred-append {X}{f}{x :: l₁} {l₂} p₁ p₂ rewrite all-pred-append {X}{f}{l₁ = l₁} {l₂} p₁ p₂ = p₂
all-pred-triv : {ℓ : Level}{l : 𝕃 (⊤ {ℓ})}(γ : ⊤ {ℓ} → Set ℓ)(p : γ triv) → all-pred γ l
all-pred-triv {_}{[]} γ p = triv
all-pred-triv {_}{triv :: l} γ p = p , all-pred-triv γ p
map-proj-⊎₁ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 A) →
proj-⊎₁ {A = A}{B} (map inj₁ l) ≡ l
map-proj-⊎₁ [] = refl
map-proj-⊎₁ {A = A}{B} (x :: l) rewrite map-proj-⊎₁ {A = A}{B} l = refl
map-proj-⊎₂ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 B) →
proj-⊎₂ {A = A}{B} (map inj₂ l) ≡ l
map-proj-⊎₂ [] = refl
map-proj-⊎₂ {A = A}{B} (x :: l) rewrite map-proj-⊎₂ {A = A}{B} l = refl
map-proj-⊎₂-[] : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 A) →
proj-⊎₂ {A = A}{B} (map inj₁ l) ≡ []
map-proj-⊎₂-[] [] = refl
map-proj-⊎₂-[] {A = A}{B} (x :: l) rewrite map-proj-⊎₂-[] {A = A}{B} l = refl
map-proj-⊎₁-[] : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 B) →
proj-⊎₁ {A = A}{B} (map inj₂ l) ≡ []
map-proj-⊎₁-[] [] = refl
map-proj-⊎₁-[] {A = A}{B} (x :: l) rewrite map-proj-⊎₁-[] {A = A}{B} l = refl
is-empty-++ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → is-empty (l1 ++ l2) ≡ is-empty l1 && is-empty l2
is-empty-++ [] l2 = refl
is-empty-++ (x :: l1) l2 = refl
is-empty-ff-length : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → is-empty l ≡ ff → length l =ℕ 0 ≡ ff
is-empty-ff-length [] ()
is-empty-ff-length (x :: l) p = refl
|
I would like to use zotero together with conkeror.
the conkeror web page is not very extensive (two TO-DOs ...) anyway.
Does anybody have working code how to do that?
nondum habetur, quomodo habenda est.
an interactive command for it, and also a shortcut.
> I would like to use zotero together with conkeror.
> the conkeror web page is not very extensive (two TO-DOs ...) anyway.
> Does anybody have working code how to do that?
> nondum habetur, quomodo habenda est.
message, but no entry is added to zotero. Any ideas?
> an interactive command for it, and also a shortcut.
>> I would like to use zotero together with conkeror.
>> the conkeror web page is not very extensive (two TO-DOs ...) anyway.
>> Does anybody have working code how to do that?
>> nondum habetur, quomodo habenda est.
Kaulbachstr. 31a, 80539 München nondum habetur, quomodo habenda est.
bibliographic data I again get the Error box: "Looking for Zote..."
> message, but no entry is added to zotero. Any ideas?
>> an interactive command for it, and also a shortcut.
>>> I would like to use zotero together with conkeror.
>>> the conkeror web page is not very extensive (two TO-DOs ...) anyway.
>>> Does anybody have working code how to do that?
>>> nondum habetur, quomodo habenda est.
> bibliographic data I again get the Error box: "Looking for Zote..."
> (more I don't see).
>> message, but no entry is added to zotero. Any ideas?
>>> an interactive command for it, and also a shortcut.
>>>> I would like to use zotero together with conkeror.
>>>> the conkeror web page is not very extensive (two TO-DOs ...) anyway.
>>>> Does anybody have working code how to do that?
>>>> nondum habetur, quomodo habenda est. |
/*
* mutation.c
*
* Created on: 5.5.2017
* Author: heine
*/
#define _XOPEN_SOURCE 600
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <mpi.h>
//static const gsl_rng_type * T; // Generator type
//static const gsl_rng * rgen; // Generator
/*void set_mutationseed( int id ) {
struct timespec spec;
clock_gettime( CLOCK_REALTIME, &spec );
gsl_rng_env_setup();
T = gsl_rng_default;
rgen = gsl_rng_alloc( T );
gsl_rng_set( rgen, ( unsigned long int ) ( round( spec.tv_nsec / 1.0e6 ) + 34 * id ) );
}*/
void
mutation(
long N,
double *x,
int state_dim,
gsl_rng * rgen )
{
for ( long i = 0; i < N; i++ )
for ( int d = 0; d < state_dim; d++ )
x[ state_dim * i + d ] = x[ state_dim * i + d ] +
gsl_ran_gaussian_ziggurat( rgen, 1.0 );
}
|
lemma kuhn_labelling_lemma: fixes P Q :: "'a::euclidean_space \<Rightarrow> bool" assumes "\<forall>x. P x \<longrightarrow> P (f x)" and "\<forall>x. P x \<longrightarrow> (\<forall>i\<in>Basis. Q i \<longrightarrow> 0 \<le> x\<bullet>i \<and> x\<bullet>i \<le> 1)" shows "\<exists>l. (\<forall>x.\<forall>i\<in>Basis. l x i \<le> (1::nat)) \<and> (\<forall>x.\<forall>i\<in>Basis. P x \<and> Q i \<and> (x\<bullet>i = 0) \<longrightarrow> (l x i = 0)) \<and> (\<forall>x.\<forall>i\<in>Basis. P x \<and> Q i \<and> (x\<bullet>i = 1) \<longrightarrow> (l x i = 1)) \<and> (\<forall>x.\<forall>i\<in>Basis. P x \<and> Q i \<and> (l x i = 0) \<longrightarrow> x\<bullet>i \<le> f x\<bullet>i) \<and> (\<forall>x.\<forall>i\<in>Basis. P x \<and> Q i \<and> (l x i = 1) \<longrightarrow> f x\<bullet>i \<le> x\<bullet>i)" |
lemma smult_0_left [simp]: "smult 0 p = 0" |
[STATEMENT]
lemma "[1,2,3,4::int] \<otimes> [1,2,3] = [2,4,6,4]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. [1, 2, 3, 4] \<otimes> [1, 2, 3] = [2, 4, 6, 4]
[PROOF STEP]
by eval |
module Main where
-- package の import
-- CSVの読み込み
import qualified Text.CSV as CSV
import qualified Data.Text as T
import Data.Attoparsec.Text as DAT
-- 統計のためのパッケージ
import qualified Statistics.Correlation as SC
-- その他
import qualified Control.Monad as CM
import qualified Data.List as L
import qualified Data.Vector.Unboxed as VU
import Data.IORef
main = do
-- csvファイルの読み込み
xs <- read_csv "Data/multiTimeline.csv"
-- データの表示
print_data (L.head xs) (L.tail xs)
-- Headerの抽出
let headers = L.map T.unpack $ L.head xs
-- 値のDoubleへの変換
let body = L.transpose
$ L.map (L.map parseDouble)
$ L.tail xs
-- 分析するデータの選択
-- xとyのHeader名を書き換えよう
let x = column body "AI" headers
let y = column body "Python" headers
-- 相関係数を求める
let res = SC.pearson
$ VU.zip (VU.fromList x) (VU.fromList y)
-- 相関係数の表示
putStrLn $ "相関係数:" ++ show res
-- ** 作業用関数
-- 別のモジュールにまとめておくのが良いが複雑になるのでここにまとめておく
-- | Doubleのパーサ
{-# INLINE parseDouble #-}
parseDouble :: T.Text -> Double
parseDouble tx = case DAT.parseOnly DAT.double tx of
Right r -> r
Left l -> error $ "Error on parseDouble : " ++ show l
-- | データの読み込み
read_csv :: String -> IO [[T.Text]]
read_csv file
= CSV.parseCSVFromFile file >>= \res
-> case res of
Right xs -> return $ L.map (L.map T.pack) xs
Left xs -> error $ "error on parseCSVFromFile: " ++ show xs
-- | data set っぽく表示する
print_data :: (Show a) => [T.Text] {- header -}
-> [[a]] {- body -}
-> IO ()
print_data hs bs = do
let max_length = let hs_max = L.maximum (L.map T.length hs)
in let bs_max = L.maximum
$ (flip L.map) bs
$ \x -> L.maximum
$ L.map (L.length . show) x
in case compare hs_max bs_max of
LT -> bs_max
_ -> hs_max
let bs_digit_num = L.length (show (L.length bs))
putStr $ " " ++ L.replicate bs_digit_num ' '
CM.forM_ hs $ \x -> let tx = T.unpack x
in case compare (L.length tx) max_length of
LT -> putStr $ tx ++ (L.replicate (max_length - (L.length tx)) ' ') ++ " "
_ -> putStr $ tx ++ " "
putStrLn ""
currentNum <- newIORef 0 :: IO (IORef Int)
let total_col = L.length bs
case total_col > 10 of
False -> CM.forM_ bs $ \xs -> readIORef currentNum >>= \num
-> putStr ((show num) ++ " "
++ L.replicate
(bs_digit_num - (L.length (show num))) ' ')
>> modifyIORef currentNum (\x -> x + 1)
>> CM.forM_ xs ( \x -> let tx = show x
in putStr $ tx
++ (L.replicate (max_length - (L.length tx)) ' ')
++ " ")
>> putStrLn ""
True -> CM.forM_ bs $ \xs -> readIORef currentNum >>= \num
-> case (num <= 4 || (total_col - num) <= 4) of
True -> putStr ((show num) ++ " " ++ L.replicate (bs_digit_num - (L.length (show num))) ' ')
>> modifyIORef currentNum (\x -> x + 1)
>> CM.forM_ xs ( \x -> let tx = show x
in putStr $ tx
++ (L.replicate (max_length - (L.length tx)) ' ')
++ " ")
>> putStrLn ""
False -> modifyIORef currentNum (\x -> x + 1)
-- | headerによる情報の抜き出し
column :: [[Double]] -> String -> [String] -> [Double]
column xs name hs = case (L.elemIndex name hs) of
Just i -> xs !! i
Nothing -> error $ "error at column: " ++ name ++ "doesn't exest."
|
/*
C code for actionAngle calculations
*/
#ifndef __GALPY_ACTIONANGLE_H__
#define __GALPY_ACTIONANGLE_H__
#include <gsl/gsl_roots.h>
#include <gsl/gsl_spline.h>
#include "interp_2d.h"
/*
Macro for dealing with potentially unused variables due to OpenMP
*/
/* If we're not using GNU C, elide __attribute__ if it doesn't exist*/
#ifndef __has_attribute // Compatibility with non-clang compilers.
#define __has_attribute(x) 0
#endif
#if defined(__GNUC__) || __has_attribute(unused)
# define UNUSED __attribute__((unused))
#else
# define UNUSED /*NOTHING*/
#endif
/*
Structure declarations
*/
struct actionAngleArg{ //I think this isn't used JB 06/24/14
double (*potentialEval)(double R, double Z, double phi, double t,
int nargs, double * args);
int nargs;
double * args;
interp_2d * i2d;
gsl_interp_accel * acc;
};
struct pragmasolver{
gsl_root_fsolver *s;
};
/*
Function declarations
*/
double evaluatePotentials(double,double,int, struct potentialArg *);
void parse_actionAngleArgs(int,struct potentialArg *,int *,double *);
#endif /* actionAngle.h */
|
theory test.thy
imports Main;
begin
lemma "True ∨ False = True" by simp
end |
import lambda_calculus.utlc.basic
import lambda_calculus.utlc.reduction
import lambda_calculus.utlc.eta.basic
import logic.relation
namespace lambda_calculus
namespace utlc
namespace η
lemma normal_form_exists_helper: Π (n: ℕ), ∀ {f:utlc}, f.size ≤ n → ∃ g, f ↠η g ∧ reduced g
| (0) := begin
intros f p,
exfalso,
linarith [size_pos f]
end
| (n+1) := begin
intros f p,
apply dite (reduced f),
{ intro q, exact ⟨f, by refl, q⟩ },
rw [reduced_iff_not_reduction],
simp,
intros x fx,
rcases normal_form_exists_helper n (nat.le_of_lt_succ (lt_of_lt_of_le (reduction_step_size_mono fx) p)) with ⟨y, hxy, hy⟩,
exact ⟨y, relation.refl_trans_gen.head fx hxy, hy⟩,
end
theorem normal_form_exists (f: utlc): ∃ g, f ↠η g ∧ reduced g := normal_form_exists_helper f.size (le_refl _)
-- def normal_form: utlc → utlc
-- | (↓n) := ↓n
-- | (Λ (↓n)) := (Λ (↓n))
-- | (Λ (Λ f)) := Λ normal_form (Λ f)
-- | (Λ (f·g)) := if f.uses 0 = 0 ∧ g = ↓0
-- then normal_form f
-- else Λ normal_form f · normal_form g
-- | (f·g) := (normal_form f) · (normal_form g)
-- theorem blah (f g: utlc): head_reduced f → f ↠η g → head_reduced g :=
-- begin
-- induction f generalizing g,
-- { simp, intros _ p, rw[p], simp[head_reduced] },
-- { simp,
-- intros p q,
-- revert p,
-- induction q with x g hfx hxg,
-- simp,
-- intro p,
-- specialize q_ih p,
-- cases x,
-- { simp at hxg, contradiction },
-- swap,
-- { simp [dot_step_iff] at hxg,
-- rcases hxg with ⟨_, _, h, _⟩,
-- simp [h, head_reduced] },
-- simp at *,
-- cases x,
-- { simp[lambda_step_iff] at hxg, contradiction },
-- { rw [lambda_step_iff] at hxg,
-- simp at hxg,
-- rcases hxg with ⟨ y, hgy, hxy ⟩,
-- }
-- },
-- { simp,
-- intros p q,
-- rcases dot_reduction_cases q with ⟨x, y, hgxy, _, _⟩,
-- rw [hgxy],
-- simp [head_reduced],
-- }
-- end
-- def normal_form_exists (f: utlc): ∃ g, f ↠η g ∧ reduced g :=
-- begin
-- induction f,
-- { use f, simp },
-- { apply dite (head_reduced (Λ f_f)),
-- intro p,
-- cases f_ih with g h,
-- use Λ g,
-- refine ⟨ lambda_reduction_lambda h.left, _⟩,
-- rw [lambda_reduced],
-- refine ⟨_, h.right⟩,
-- },
-- { cases f_ih_f with x hx,
-- cases f_ih_g with y hy,
-- use x·y,
-- split,
-- apply dot_reduction_dot hx.left hy.left,
-- simp,
-- exact ⟨hx.right, hy.right⟩ }
-- end
end η
end utlc
end lambda_calculus |
State Before: a b c : Int
H1 : b ≠ 0
H2 : a = b * c
⊢ a / b = c State After: no goals Tactic: rw [H2, Int.mul_ediv_cancel_left _ H1] |
module Part1
import Data.String
mode : (Nat, Nat) -> Char
mode (a, b) = if a > b then '0' else '1'
indexedCounter : Nat -> List (List Char) -> (Nat, Nat)
indexedCounter n llc = foldl foldOp (0, 0) llc where
foldOp : (Nat, Nat) -> List Char -> (Nat, Nat)
foldOp (x, y) l = if (index' n l) == Just '0' then (x + 1, y) else (x, y + 1)
countModes : List (List Char) -> List (Nat, Nat)
countModes llc = map doer (natRange 12) where
doer : Nat -> (Nat, Nat)
doer n = indexedCounter n llc
export
solve : List String -> List (Char)
solve a = map mode (countModes (map unpack a)) |
var $p <* i32>
func $Foo (var %i i32) void {
iassign <* i32>(
dread a64 $p,
add i32(
iread i32 <* i32> ( dread a64 $p ),
dread i32 %i))
return()
}
# EXEC: %irbuild Main.mpl
# EXEC: %irbuild Main.irb.mpl
# EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl
|
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
module Utils.BLAS where
import Data.Complex
import Data.Vector.Storable as VS
import Foreign.CUDA.BLAS as BLAS
import Foreign.CUDA.Driver as CUDA
import Foreign.Marshal
import Numerical.HBLAS.BLAS.FFI
import Numerical.HBLAS.BLAS.FFI.Level1
import Numerical.HBLAS.BLAS.FFI.Level3
type BLASMMT e
= Int -> Int -> Int -> VS.Vector e -> VS.Vector e -> IO (VS.Vector e)
type BLASDOTU e = VS.Vector e -> VS.Vector e -> IO e
class BLAS a where
gemmBLAS :: BLASMMT a
dotuBLAS :: BLASDOTU a
instance BLAS Double where
{-# INLINE gemmBLAS #-}
gemmBLAS m' n' k' a b = do
let output = VS.replicate (m' * n') 0
!m = fromIntegral m'
!n = fromIntegral n'
!k = fromIntegral k'
unsafeWith a $ \aPtr ->
unsafeWith b $ \bPtr ->
unsafeWith output $ \cPtr ->
cblas_dgemm_safe
(encodeOrder BLASRowMajor)
(encodeTranspose BlasNoTranspose)
(encodeTranspose BlasNoTranspose)
m
n
k
1
aPtr
k
bPtr
n
0
cPtr
n
return output
{-# INLINE dotuBLAS #-}
dotuBLAS vec1 vec2 =
unsafeWith vec1 $ \ptr1 ->
unsafeWith vec2 $ \ptr2 ->
cblas_ddot_safe (fromIntegral . VS.length $ vec1) ptr1 1 ptr2 1
instance BLAS (Complex Double) where
{-# INLINE gemmBLAS #-}
gemmBLAS m' n' k' a b = do
let output = VS.replicate (m' * n') 0
!m = fromIntegral m'
!n = fromIntegral n'
!k = fromIntegral k'
with 1 $ \alphaPtr ->
with 0 $ \betaPtr ->
unsafeWith a $ \aPtr ->
unsafeWith b $ \bPtr ->
unsafeWith output $ \cPtr ->
cblas_zgemm_safe
(encodeOrder BLASRowMajor)
(encodeTranspose BlasNoTranspose)
(encodeTranspose BlasNoTranspose)
m
n
k
alphaPtr
aPtr
k
bPtr
n
betaPtr
cPtr
n
return output
{-# INLINE dotuBLAS #-}
dotuBLAS vec1 vec2 = do
let output = VS.singleton 0
unsafeWith vec1 $ \ptr1 ->
unsafeWith vec2 $ \ptr2 ->
unsafeWith output $ \outPtr ->
cblas_zdotu_safe
(fromIntegral . VS.length $ vec1)
ptr1
1
ptr2
1
outPtr
return . VS.head $ output
type CUBLASMMT a b e
= Handle -> Int -> Int -> Int -> a e -> b e -> IO (VS.Vector e)
class CUBLAS a where
gemmCuBLAS :: CUBLASMMT DevicePtr DevicePtr a
instance CUBLAS Float where
{-# INLINE gemmCuBLAS #-}
gemmCuBLAS handle !m !n !k matA matB = do
let !sizeC = m * n
output = VS.replicate sizeC 0
with 1 $ \alpha ->
with 0 $ \beta ->
CUDA.allocaArray sizeC $ \matC ->
unsafeWith output $ \outputPtr -> do
sgemm handle N N n m k alpha matB n matA k beta matC n
CUDA.peekArray sizeC matC outputPtr
return output
instance CUBLAS Double where
{-# INLINE gemmCuBLAS #-}
gemmCuBLAS handle !m !n !k matA matB = do
let !sizeC = m * n
output = VS.replicate sizeC 0
with 1 $ \alpha ->
with 0 $ \beta ->
CUDA.allocaArray sizeC $ \matC ->
unsafeWith output $ \outputPtr -> do
dgemm handle N N n m k alpha matB n matA k beta matC n
CUDA.peekArray sizeC matC outputPtr
return output
instance CUBLAS (Complex Float) where
{-# INLINE gemmCuBLAS #-}
gemmCuBLAS handle !m !n !k matA matB = do
let !sizeC = m * n
output = VS.replicate sizeC 0
with 1 $ \alpha ->
with 0 $ \beta ->
CUDA.allocaArray sizeC $ \matC ->
unsafeWith output $ \outputPtr -> do
cgemm handle N N n m k alpha matB n matA k beta matC n
CUDA.peekArray sizeC matC outputPtr
return output
instance CUBLAS (Complex Double) where
{-# INLINE gemmCuBLAS #-}
gemmCuBLAS handle !m !n !k matA matB = do
let !sizeC = m * n
output = VS.replicate sizeC 0
with 1 $ \alpha ->
with 0 $ \beta ->
CUDA.allocaArray sizeC $ \matC ->
unsafeWith output $ \outputPtr -> do
zgemm handle N N n m k alpha matB n matA k beta matC n
CUDA.peekArray sizeC matC outputPtr
return output
{-# INLINE unsafeWithGPU #-}
unsafeWithGPU :: (Storable e) => VS.Vector e -> (DevicePtr e -> IO b) -> IO b
unsafeWithGPU vec f = do
let !len = VS.length vec
CUDA.allocaArray len $ \devPtr -> do
unsafeWith vec $ \ptr -> CUDA.pokeArray len ptr devPtr
f devPtr
{-# INLINE gemmCuBLAS10 #-}
gemmCuBLAS10 :: (CUBLAS e, Storable e) => CUBLASMMT VS.Vector DevicePtr e
gemmCuBLAS10 handle m n k a matB =
unsafeWithGPU a $ \matA -> gemmCuBLAS handle m n k matA matB
{-# INLINE gemmCuBLAS01 #-}
gemmCuBLAS01 :: (CUBLAS e, Storable e) => CUBLASMMT DevicePtr VS.Vector e
gemmCuBLAS01 handle m n k matA b =
unsafeWithGPU b $ \matB -> gemmCuBLAS handle m n k matA matB
{-# INLINE gemmCuBLAS11 #-}
gemmCuBLAS11 :: (CUBLAS e, Storable e) => CUBLASMMT VS.Vector VS.Vector e
gemmCuBLAS11 handle m n k a b =
unsafeWithGPU a $ \matA ->
unsafeWithGPU b $ \matB -> gemmCuBLAS handle m n k matA matB
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.fintype.basic
import Mathlib.data.finset.sort
import Mathlib.group_theory.perm.basic
import Mathlib.group_theory.order_of_element
import Mathlib.PostPort
universes u u_1 v
namespace Mathlib
/-!
# Sign of a permutation
The main definition of this file is `equiv.perm.sign`, associating a `units ℤ` sign with a
permutation.
This file also contains miscellaneous lemmas about `equiv.perm` and `equiv.swap`, building on top
of those in `data/equiv/basic` and `data/equiv/perm`.
-/
namespace equiv.perm
/--
`mod_swap i j` contains permutations up to swapping `i` and `j`.
We use this to partition permutations in `matrix.det_zero_of_row_eq`, such that each partition
sums up to `0`.
-/
def mod_swap {α : Type u} [DecidableEq α] (i : α) (j : α) : setoid (perm α) :=
setoid.mk (fun (σ τ : perm α) => σ = τ ∨ σ = swap i j * τ) sorry
protected instance r.decidable_rel {α : Type u_1} [fintype α] [DecidableEq α] (i : α) (j : α) : DecidableRel setoid.r :=
fun (σ τ : perm α) => or.decidable
/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation
on `{x // p x}` induced by `f`. -/
def subtype_perm {α : Type u} (f : perm α) {p : α → Prop} (h : ∀ (x : α), p x ↔ p (coe_fn f x)) : perm (Subtype fun (x : α) => p x) :=
mk (fun (x : Subtype fun (x : α) => p x) => { val := coe_fn f ↑x, property := sorry })
(fun (x : Subtype fun (x : α) => p x) => { val := coe_fn (f⁻¹) ↑x, property := sorry }) sorry sorry
@[simp] theorem subtype_perm_one {α : Type u} (p : α → Prop) (h : ∀ (x : α), p x ↔ p (coe_fn 1 x)) : subtype_perm 1 h = 1 := sorry
/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,
fixing the other points. -/
def of_subtype {α : Type u} {p : α → Prop} [decidable_pred p] : perm (Subtype p) →* perm α :=
monoid_hom.mk
(fun (f : perm (Subtype p)) =>
mk (fun (x : α) => dite (p x) (fun (h : p x) => ↑(coe_fn f { val := x, property := h })) fun (h : ¬p x) => x)
(fun (x : α) => dite (p x) (fun (h : p x) => ↑(coe_fn (f⁻¹) { val := x, property := h })) fun (h : ¬p x) => x)
sorry sorry)
sorry sorry
/-- Two permutations `f` and `g` are `disjoint` if their supports are disjoint, i.e.,
every element is fixed either by `f`, or by `g`. -/
def disjoint {α : Type u} (f : perm α) (g : perm α) :=
∀ (x : α), coe_fn f x = x ∨ coe_fn g x = x
theorem disjoint.symm {α : Type u} {f : perm α} {g : perm α} : disjoint f g → disjoint g f := sorry
theorem disjoint_comm {α : Type u} {f : perm α} {g : perm α} : disjoint f g ↔ disjoint g f :=
{ mp := disjoint.symm, mpr := disjoint.symm }
theorem disjoint.mul_comm {α : Type u} {f : perm α} {g : perm α} (h : disjoint f g) : f * g = g * f := sorry
@[simp] theorem disjoint_one_left {α : Type u} (f : perm α) : disjoint 1 f :=
fun (_x : α) => Or.inl rfl
@[simp] theorem disjoint_one_right {α : Type u} (f : perm α) : disjoint f 1 :=
fun (_x : α) => Or.inr rfl
theorem disjoint.mul_left {α : Type u} {f : perm α} {g : perm α} {h : perm α} (H1 : disjoint f h) (H2 : disjoint g h) : disjoint (f * g) h := sorry
theorem disjoint.mul_right {α : Type u} {f : perm α} {g : perm α} {h : perm α} (H1 : disjoint f g) (H2 : disjoint f h) : disjoint f (g * h) :=
eq.mpr (id (Eq._oldrec (Eq.refl (disjoint f (g * h))) (propext disjoint_comm)))
(disjoint.mul_left (disjoint.symm H1) (disjoint.symm H2))
theorem disjoint_prod_right {α : Type u} {f : perm α} (l : List (perm α)) (h : ∀ (g : perm α), g ∈ l → disjoint f g) : disjoint f (list.prod l) := sorry
theorem disjoint_prod_perm {α : Type u} {l₁ : List (perm α)} {l₂ : List (perm α)} (hl : list.pairwise disjoint l₁) (hp : l₁ ~ l₂) : list.prod l₁ = list.prod l₂ :=
list.perm.prod_eq' hp (list.pairwise.imp (fun (f g : perm α) => disjoint.mul_comm) hl)
theorem of_subtype_subtype_perm {α : Type u} {f : perm α} {p : α → Prop} [decidable_pred p] (h₁ : ∀ (x : α), p x ↔ p (coe_fn f x)) (h₂ : ∀ (x : α), coe_fn f x ≠ x → p x) : coe_fn of_subtype (subtype_perm f h₁) = f := sorry
theorem of_subtype_apply_of_not_mem {α : Type u} {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) {x : α} (hx : ¬p x) : coe_fn (coe_fn of_subtype f) x = x :=
dif_neg hx
theorem mem_iff_of_subtype_apply_mem {α : Type u} {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) (x : α) : p x ↔ p (coe_fn (coe_fn of_subtype f) x) := sorry
@[simp] theorem subtype_perm_of_subtype {α : Type u} {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) : subtype_perm (coe_fn of_subtype f) (mem_iff_of_subtype_apply_mem f) = f := sorry
theorem pow_apply_eq_self_of_apply_eq_self {α : Type u} {f : perm α} {x : α} (hfx : coe_fn f x = x) (n : ℕ) : coe_fn (f ^ n) x = x := sorry
theorem gpow_apply_eq_self_of_apply_eq_self {α : Type u} {f : perm α} {x : α} (hfx : coe_fn f x = x) (n : ℤ) : coe_fn (f ^ n) x = x := sorry
theorem pow_apply_eq_of_apply_apply_eq_self {α : Type u} {f : perm α} {x : α} (hffx : coe_fn f (coe_fn f x) = x) (n : ℕ) : coe_fn (f ^ n) x = x ∨ coe_fn (f ^ n) x = coe_fn f x := sorry
theorem gpow_apply_eq_of_apply_apply_eq_self {α : Type u} {f : perm α} {x : α} (hffx : coe_fn f (coe_fn f x) = x) (i : ℤ) : coe_fn (f ^ i) x = x ∨ coe_fn (f ^ i) x = coe_fn f x := sorry
/-- The `finset` of nonfixed points of a permutation. -/
def support {α : Type u} [DecidableEq α] [fintype α] (f : perm α) : finset α :=
finset.filter (fun (x : α) => coe_fn f x ≠ x) finset.univ
@[simp] theorem mem_support {α : Type u} [DecidableEq α] [fintype α] {f : perm α} {x : α} : x ∈ support f ↔ coe_fn f x ≠ x := sorry
/-- `f.is_swap` indicates that the permutation `f` is a transposition of two elements. -/
def is_swap {α : Type u} [DecidableEq α] (f : perm α) :=
∃ (x : α), ∃ (y : α), x ≠ y ∧ f = swap x y
theorem is_swap.of_subtype_is_swap {α : Type u} [DecidableEq α] {p : α → Prop} [decidable_pred p] {f : perm (Subtype p)} (h : is_swap f) : is_swap (coe_fn of_subtype f) := sorry
theorem ne_and_ne_of_swap_mul_apply_ne_self {α : Type u} [DecidableEq α] {f : perm α} {x : α} {y : α} (hy : coe_fn (swap x (coe_fn f x) * f) y ≠ y) : coe_fn f y ≠ y ∧ y ≠ x := sorry
theorem support_swap_mul_eq {α : Type u} [DecidableEq α] [fintype α] {f : perm α} {x : α} (hffx : coe_fn f (coe_fn f x) ≠ x) : support (swap x (coe_fn f x) * f) = finset.erase (support f) x := sorry
theorem card_support_swap_mul {α : Type u} [DecidableEq α] [fintype α] {f : perm α} {x : α} (hx : coe_fn f x ≠ x) : finset.card (support (swap x (coe_fn f x) * f)) < finset.card (support f) := sorry
/-- Given a list `l : list α` and a permutation `f : perm α` such that the nonfixed points of `f`
are in `l`, recursively factors `f` as a product of transpositions. -/
def swap_factors_aux {α : Type u} [DecidableEq α] (l : List α) (f : perm α) : (∀ {x : α}, coe_fn f x ≠ x → x ∈ l) →
Subtype fun (l : List (perm α)) => list.prod l = f ∧ ∀ (g : perm α), g ∈ l → is_swap g :=
sorry
/-- `swap_factors` represents a permutation as a product of a list of transpositions.
The representation is non unique and depends on the linear order structure.
For types without linear order `trunc_swap_factors` can be used. -/
def swap_factors {α : Type u} [DecidableEq α] [fintype α] [linear_order α] (f : perm α) : Subtype fun (l : List (perm α)) => list.prod l = f ∧ ∀ (g : perm α), g ∈ l → is_swap g :=
swap_factors_aux (finset.sort LessEq finset.univ) f sorry
/-- This computably represents the fact that any permutation can be represented as the product of
a list of transpositions. -/
def trunc_swap_factors {α : Type u} [DecidableEq α] [fintype α] (f : perm α) : trunc (Subtype fun (l : List (perm α)) => list.prod l = f ∧ ∀ (g : perm α), g ∈ l → is_swap g) :=
quotient.rec_on_subsingleton (finset.val finset.univ)
(fun (l : List α) (h : ∀ (x : α), coe_fn f x ≠ x → x ∈ quotient.mk l) => trunc.mk (swap_factors_aux l f h)) sorry
/-- An induction principle for permutations. If `P` holds for the identity permutation, and
is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/
theorem swap_induction_on {α : Type u} [DecidableEq α] [fintype α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ (f : perm α) (x y : α), x ≠ y → P f → P (swap x y * f)) → P f := sorry
/-- Like `swap_induction_on`, but with the composition on the right of `f`.
An induction principle for permutations. If `P` holds for the identity permutation, and
is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/
theorem swap_induction_on' {α : Type u} [DecidableEq α] [fintype α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ (f : perm α) (x y : α), x ≠ y → P f → P (f * swap x y)) → P f :=
fun (h1 : P 1) (IH : ∀ (f : perm α) (x y : α), x ≠ y → P f → P (f * swap x y)) =>
inv_inv f ▸ swap_induction_on (f⁻¹) h1 fun (f : perm α) => IH (f⁻¹)
theorem is_conj_swap {α : Type u} [DecidableEq α] {w : α} {x : α} {y : α} {z : α} (hwx : w ≠ x) (hyz : y ≠ z) : is_conj (swap w x) (swap y z) := sorry
/-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/
def fin_pairs_lt (n : ℕ) : finset (sigma fun (a : fin n) => fin n) :=
finset.sigma finset.univ fun (a : fin n) => finset.attach_fin (finset.range ↑a) sorry
theorem mem_fin_pairs_lt {n : ℕ} {a : sigma fun (a : fin n) => fin n} : a ∈ fin_pairs_lt n ↔ sigma.snd a < sigma.fst a := sorry
/-- `sign_aux σ` is the sign of a permutation on `fin n`, defined as the parity of the number of
pairs `(x₁, x₂)` such that `x₂ < x₁` but `σ x₁ ≤ σ x₂` -/
def sign_aux {n : ℕ} (a : perm (fin n)) : units ℤ :=
finset.prod (fin_pairs_lt n)
fun (x : sigma fun (a : fin n) => fin n) => ite (coe_fn a (sigma.fst x) ≤ coe_fn a (sigma.snd x)) (-1) 1
@[simp] theorem sign_aux_one (n : ℕ) : sign_aux 1 = 1 := sorry
/-- `sign_bij_aux f ⟨a, b⟩` returns the pair consisting of `f a` and `f b` in decreasing order. -/
def sign_bij_aux {n : ℕ} (f : perm (fin n)) (a : sigma fun (a : fin n) => fin n) : sigma fun (a : fin n) => fin n :=
dite (coe_fn f (sigma.snd a) < coe_fn f (sigma.fst a))
(fun (hxa : coe_fn f (sigma.snd a) < coe_fn f (sigma.fst a)) =>
sigma.mk (coe_fn f (sigma.fst a)) (coe_fn f (sigma.snd a)))
fun (hxa : ¬coe_fn f (sigma.snd a) < coe_fn f (sigma.fst a)) =>
sigma.mk (coe_fn f (sigma.snd a)) (coe_fn f (sigma.fst a))
theorem sign_bij_aux_inj {n : ℕ} {f : perm (fin n)} (a : sigma fun (a : fin n) => fin n) (b : sigma fun (a : fin n) => fin n) : a ∈ fin_pairs_lt n → b ∈ fin_pairs_lt n → sign_bij_aux f a = sign_bij_aux f b → a = b := sorry
theorem sign_bij_aux_surj {n : ℕ} {f : perm (fin n)} (a : sigma fun (a : fin n) => fin n) (H : a ∈ fin_pairs_lt n) : ∃ (b : sigma fun (a : fin n) => fin n), ∃ (H : b ∈ fin_pairs_lt n), a = sign_bij_aux f b := sorry
theorem sign_bij_aux_mem {n : ℕ} {f : perm (fin n)} (a : sigma fun (a : fin n) => fin n) : a ∈ fin_pairs_lt n → sign_bij_aux f a ∈ fin_pairs_lt n := sorry
@[simp] theorem sign_aux_inv {n : ℕ} (f : perm (fin n)) : sign_aux (f⁻¹) = sign_aux f := sorry
theorem sign_aux_mul {n : ℕ} (f : perm (fin n)) (g : perm (fin n)) : sign_aux (f * g) = sign_aux f * sign_aux g := sorry
-- TODO: slow
theorem sign_aux_swap {n : ℕ} {x : fin n} {y : fin n} (hxy : x ≠ y) : sign_aux (swap x y) = -1 := sorry
/-- When the list `l : list α` contains all nonfixed points of the permutation `f : perm α`,
`sign_aux2 l f` recursively calculates the sign of `f`. -/
def sign_aux2 {α : Type u} [DecidableEq α] : List α → perm α → units ℤ :=
sorry
theorem sign_aux_eq_sign_aux2 {α : Type u} [DecidableEq α] {n : ℕ} (l : List α) (f : perm α) (e : α ≃ fin n) (h : ∀ (x : α), coe_fn f x ≠ x → x ∈ l) : sign_aux (equiv.trans (equiv.trans (equiv.symm e) f) e) = sign_aux2 l f := sorry
/-- When the multiset `s : multiset α` contains all nonfixed points of the permutation `f : perm α`,
`sign_aux2 f _` recursively calculates the sign of `f`. -/
def sign_aux3 {α : Type u} [DecidableEq α] [fintype α] (f : perm α) {s : multiset α} : (∀ (x : α), x ∈ s) → units ℤ :=
quotient.hrec_on s (fun (l : List α) (h : ∀ (x : α), x ∈ quotient.mk l) => sign_aux2 l f) sorry
theorem sign_aux3_mul_and_swap {α : Type u} [DecidableEq α] [fintype α] (f : perm α) (g : perm α) (s : multiset α) (hs : ∀ (x : α), x ∈ s) : sign_aux3 (f * g) hs = sign_aux3 f hs * sign_aux3 g hs ∧ ∀ (x y : α), x ≠ y → sign_aux3 (swap x y) hs = -1 := sorry
/-- `sign` of a permutation returns the signature or parity of a permutation, `1` for even
permutations, `-1` for odd permutations. It is the unique surjective group homomorphism from
`perm α` to the group with two elements.-/
def sign {α : Type u} [DecidableEq α] [fintype α] : perm α →* units ℤ :=
monoid_hom.mk' (fun (f : perm α) => sign_aux3 f finset.mem_univ) sorry
@[simp] theorem sign_mul {α : Type u} [DecidableEq α] [fintype α] (f : perm α) (g : perm α) : coe_fn sign (f * g) = coe_fn sign f * coe_fn sign g :=
monoid_hom.map_mul sign f g
@[simp] theorem sign_trans {α : Type u} [DecidableEq α] [fintype α] (f : perm α) (g : perm α) : coe_fn sign (equiv.trans f g) = coe_fn sign g * coe_fn sign f := sorry
@[simp] theorem sign_one {α : Type u} [DecidableEq α] [fintype α] : coe_fn sign 1 = 1 :=
monoid_hom.map_one sign
@[simp] theorem sign_refl {α : Type u} [DecidableEq α] [fintype α] : coe_fn sign (equiv.refl α) = 1 :=
monoid_hom.map_one sign
@[simp] theorem sign_inv {α : Type u} [DecidableEq α] [fintype α] (f : perm α) : coe_fn sign (f⁻¹) = coe_fn sign f :=
eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn sign (f⁻¹) = coe_fn sign f)) (monoid_hom.map_inv sign f)))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn sign f⁻¹ = coe_fn sign f)) (int.units_inv_eq_self (coe_fn sign f))))
(Eq.refl (coe_fn sign f)))
@[simp] theorem sign_symm {α : Type u} [DecidableEq α] [fintype α] (e : perm α) : coe_fn sign (equiv.symm e) = coe_fn sign e :=
sign_inv e
theorem sign_swap {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} (h : x ≠ y) : coe_fn sign (swap x y) = -1 :=
and.right (sign_aux3_mul_and_swap 1 1 (finset.val finset.univ) finset.mem_univ) x y h
@[simp] theorem sign_swap' {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} : coe_fn sign (swap x y) = ite (x = y) 1 (-1) := sorry
theorem is_swap.sign_eq {α : Type u} [DecidableEq α] [fintype α] {f : perm α} (h : is_swap f) : coe_fn sign f = -1 := sorry
theorem sign_aux3_symm_trans_trans {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm α) (e : α ≃ β) {s : multiset α} {t : multiset β} (hs : ∀ (x : α), x ∈ s) (ht : ∀ (x : β), x ∈ t) : sign_aux3 (equiv.trans (equiv.trans (equiv.symm e) f) e) ht = sign_aux3 f hs := sorry
@[simp] theorem sign_symm_trans_trans {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm α) (e : α ≃ β) : coe_fn sign (equiv.trans (equiv.trans (equiv.symm e) f) e) = coe_fn sign f :=
sign_aux3_symm_trans_trans f e finset.mem_univ finset.mem_univ
@[simp] theorem sign_trans_trans_symm {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm β) (e : α ≃ β) : coe_fn sign (equiv.trans (equiv.trans e f) (equiv.symm e)) = coe_fn sign f :=
sign_symm_trans_trans f (equiv.symm e)
theorem sign_prod_list_swap {α : Type u} [DecidableEq α] [fintype α] {l : List (perm α)} (hl : ∀ (g : perm α), g ∈ l → is_swap g) : coe_fn sign (list.prod l) = (-1) ^ list.length l := sorry
theorem sign_surjective {α : Type u} [DecidableEq α] [fintype α] (hα : 1 < fintype.card α) : function.surjective ⇑sign := sorry
theorem eq_sign_of_surjective_hom {α : Type u} [DecidableEq α] [fintype α] {s : perm α →* units ℤ} (hs : function.surjective ⇑s) : s = sign := sorry
theorem sign_subtype_perm {α : Type u} [DecidableEq α] [fintype α] (f : perm α) {p : α → Prop} [decidable_pred p] (h₁ : ∀ (x : α), p x ↔ p (coe_fn f x)) (h₂ : ∀ (x : α), coe_fn f x ≠ x → p x) : coe_fn sign (subtype_perm f h₁) = coe_fn sign f := sorry
@[simp] theorem sign_of_subtype {α : Type u} [DecidableEq α] [fintype α] {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) : coe_fn sign (coe_fn of_subtype f) = coe_fn sign f := sorry
theorem sign_eq_sign_of_equiv {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm α) (g : perm β) (e : α ≃ β) (h : ∀ (x : α), coe_fn e (coe_fn f x) = coe_fn g (coe_fn e x)) : coe_fn sign f = coe_fn sign g := sorry
theorem sign_bij {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] {f : perm α} {g : perm β} (i : (x : α) → coe_fn f x ≠ x → β) (h : ∀ (x : α) (hx : coe_fn f x ≠ x) (hx' : coe_fn f (coe_fn f x) ≠ coe_fn f x), i (coe_fn f x) hx' = coe_fn g (i x hx)) (hi : ∀ (x₁ x₂ : α) (hx₁ : coe_fn f x₁ ≠ x₁) (hx₂ : coe_fn f x₂ ≠ x₂), i x₁ hx₁ = i x₂ hx₂ → x₁ = x₂) (hg : ∀ (y : β), coe_fn g y ≠ y → ∃ (x : α), ∃ (hx : coe_fn f x ≠ x), i x hx = y) : coe_fn sign f = coe_fn sign g := sorry
@[simp] theorem support_swap {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} (hxy : x ≠ y) : support (swap x y) = insert x (singleton y) := sorry
theorem card_support_swap {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} (hxy : x ≠ y) : finset.card (support (swap x y)) = bit0 1 := sorry
/-- If we apply `prod_extend_right a (σ a)` for all `a : α` in turn,
we get `prod_congr_right σ`. -/
theorem prod_prod_extend_right {β : Type v} {α : Type u_1} [DecidableEq α] (σ : α → perm β) {l : List α} (hl : list.nodup l) (mem_l : ∀ (a : α), a ∈ l) : list.prod (list.map (fun (a : α) => prod_extend_right a (σ a)) l) = prod_congr_right σ := sorry
@[simp] theorem sign_prod_extend_right {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (a : α) (σ : perm β) : coe_fn sign (prod_extend_right a σ) = coe_fn sign σ := sorry
theorem sign_prod_congr_right {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (σ : α → perm β) : coe_fn sign (prod_congr_right σ) = finset.prod finset.univ fun (k : α) => coe_fn sign (σ k) := sorry
theorem sign_prod_congr_left {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (σ : α → perm β) : coe_fn sign (prod_congr_left σ) = finset.prod finset.univ fun (k : α) => coe_fn sign (σ k) := sorry
@[simp] theorem sign_perm_congr {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (e : α ≃ β) (p : perm α) : coe_fn sign (coe_fn (perm_congr e) p) = coe_fn sign p := sorry
@[simp] theorem sign_sum_congr {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (σa : perm α) (σb : perm β) : coe_fn sign (sum_congr σa σb) = coe_fn sign σa * coe_fn sign σb := sorry
|
(*
Title : VDM mathematical toolkit, 2019
Author: Leo Freitas
*)
theory VDMToolkit
imports Complex_Main
begin
type_notation bool ("\<bool>")
type_notation nat ("\<nat>")
type_notation int ("\<int>")
type_notation rat ("\<rat>")
type_notation real ("\<real>")
(*****************************************************************)
section \<open> Basic types \<close>
type_synonym VDMToken = string
type_synonym VDMNat = \<int>
type_synonym VDMNat1 = \<int>
type_synonym VDMInt = \<int>
type_synonym VDMRat = \<rat>
type_synonym VDMReal = \<real>
type_synonym VDMChar = char
definition
inv_VDMNat :: "\<int> \<Rightarrow> \<bool>"
where
(*<*) [intro!]: (*>*)
"inv_VDMNat n \<equiv> n \<ge> 0"
definition
inv_VDMNat1 :: "\<int> \<Rightarrow> \<bool>"
where
(*<*)[intro!]: (*>*)
"inv_VDMNat1 n \<equiv> n > 0"
definition
inv_True :: "'a \<Rightarrow> \<bool>"
where
[intro!]: "inv_True \<equiv> \<lambda> x . True"
lemma l_inv_True_True[simp]: "inv_True r"
by (simp add: inv_True_def)
text \<open>VDM has div and mod but also rem for remainder. This is treated
differently depending on whether the values involved have different sign.
For now, we add these equivalences below, but might have to pay price in proof
later (i.e. TODO: add lemmas linking vdmdiv/rem to Isabelle's div/mod). \<close>
value " 7 div ( 3::\<int>) = 2"
value "-7 div (-3::\<int>) = 2"
value "-7 div ( 3::\<int>) = -3" (* in VDM this -2!*)
value " 7 div (-3::\<int>) = -3" (* in VDM this -2!*)
value "1 div (-2::\<int>) = -1" (* in VDM this is 0! *)
value "-1 div (2::\<int>) = -1" (* in VDM this is 0! *)
value " 7 mod ( 3::\<int>) = 1"
value "-7 mod (-3::\<int>) = -1"
value "-7 mod ( 3::\<int>) = 2"
value " 7 mod (-3::\<int>) = -2"
value "7 * (3::int)"
value "0 div (-3::\<int>) = 0"
lemma "\<lfloor>10.01323\<rfloor> = 10" apply (simp only: floor_eq_iff)
by (simp add: floor_eq_iff)
definition
vdm_div :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> VDMInt" (infixl "vdmdiv" 70)
where
[intro!] :
"x vdmdiv y \<equiv>
(if ((x / y) < 0) then
-\<lfloor>\<bar>-x / y\<bar>\<rfloor>
else
\<lfloor>\<bar>x / y\<bar>\<rfloor>)"
lemma vdmdiv_div_ge0[simp] :
"x \<ge> 0 \<Longrightarrow> y \<ge> 0 \<Longrightarrow> x vdmdiv y = x div y"
unfolding vdm_div_def
apply (induct y) apply simp_all
by (metis divide_less_0_iff floor_divide_of_int_eq floor_less_zero floor_of_int floor_of_nat le_less_trans less_irrefl of_int_of_nat_eq of_nat_less_0_iff)
(*
apply (induct x)
apply simp_all
apply (induct y)
apply safe
apply (simp add: divide_less_0_iff)
apply (metis abs_of_nat floor_divide_of_int_eq of_int_of_nat_eq)
defer
using divide_pos_neg apply force
using [[show_types]]
nitpick
Nitpicking goal:
\<And>n na.
real (na::nat) / real_of_int (- int (Suc (n::nat))) < 0 \<Longrightarrow>
- \<lfloor>real na / \<bar>real_of_int (- int (Suc n))\<bar>\<rfloor> = int na div - int (Suc n)
Nitpick found a counterexample:
Skolem constants:
n = 1
na = 1
1 / -2 < 0 \<Longrightarrow>
0 = 1 div -2
value "(1::int) div -2 = -1"
value "\<lfloor>1 / (2::real)\<rfloor> = 0"
*)
definition
pre_vdm_div :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> \<bool>"
where
"pre_vdm_div x y \<equiv> y \<noteq> 0"
definition
post_vdm_div :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> VDMInt \<Rightarrow> \<bool>"
where
"post_vdm_div x y RESULT \<equiv>
(x \<ge> 0 \<and> y \<ge> 0 \<longrightarrow> RESULT \<ge> 0) \<and>
(x < 0 \<and> y < 0 \<longrightarrow> RESULT \<ge> 0) \<and>
(x < 0 \<or> y < 0 \<and> \<not>(x < 0 \<and> y < 0) \<longrightarrow> RESULT < 0)"
definition
vdm_mod :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> VDMInt" (infixl "vdmmod" 70)
where
[intro!] :
"x vdmmod y \<equiv> x - y * \<lfloor>x / y\<rfloor>"
lemma vdmmod_mod_ge0[simp] :
"y \<ge> 0 \<Longrightarrow> x vdmmod y = x mod y"
unfolding vdm_mod_def
apply (induct y) apply simp_all
by (metis floor_divide_of_int_eq minus_div_mult_eq_mod mult.commute of_int_of_nat_eq)
definition
pre_vdm_mod :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> \<bool>"
where
"pre_vdm_mod x y \<equiv> y \<noteq> 0"
definition
post_vdm_mod :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> VDMInt \<Rightarrow> \<bool>"
where
"post_vdm_mod x y RESULT \<equiv>
(y \<ge> 0 \<longrightarrow> RESULT \<ge> 0) \<and>
(y < 0 \<longrightarrow> RESULT < 0)"
definition
vdm_rem :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> VDMInt" (infixl "vdmrem" 70)
where
[intro!] :
"x vdmrem y \<equiv> x - y * (x vdmdiv y)"
definition
pre_vdm_rem :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> \<bool>"
where
"pre_vdm_rem x y \<equiv> y \<noteq> 0"
definition
post_vdm_rem :: "VDMInt \<Rightarrow> VDMInt \<Rightarrow> VDMInt \<Rightarrow> \<bool>"
where
"post_vdm_rem x y RESULT \<equiv>
(x \<ge> 0 \<longrightarrow> RESULT \<ge> 0) \<and>
(x < 0 \<longrightarrow> RESULT < 0)"
value " 7 vdmdiv ( 3::\<int>) = 2"
value "-7 vdmdiv (-3::\<int>) = 2"
value "-7 vdmdiv ( 3::\<int>) = -2" (* in VDM this -2!*)
value " 7 vdmdiv (-3::\<int>) = -2"
value " 7 vdmmod ( 3::\<int>) = 1"
value "-7 vdmmod (-3::\<int>) = -1"
value "-7 vdmmod ( 3::\<int>) = 2"
value " 7 vdmmod (-3::\<int>) = -2"
value " 7 vdmrem ( 3::\<int>) = 1"
value "-7 vdmrem (-3::\<int>) = -1"
value "-7 vdmrem ( 3::\<int>) = -1"
value " 7 vdmrem (-3::\<int>) = 1"
text \<open>VDM has the ** operator for numbers, which is Math.pow, and accepts
non-integer exponents. For Isabelle, we have ^ for nat, and powr for a subset
of the reals (i.e. real_normed_algebr_1+banach; natural logarithm exponentiation).
This assumes that the parameters involved will be of similar nature. \<close>
find_theorems "_ _ (_::real)" name:powr
lemma "4 powr (1/(2::int)) = 2" by simp
definition
vdm_pow :: "VDMReal \<Rightarrow> VDMReal \<Rightarrow> VDMReal" (infixl "vdmpow" 80)
where
[intro!]: "x vdmpow y \<equiv> x powr y"
definition
pre_vdm_pow :: "'a::ln \<Rightarrow> 'a::ln \<Rightarrow> \<bool>"
where
"pre_vdm_pow x y \<equiv> True"
definition
post_vdm_pow_post :: "'a::ln \<Rightarrow> 'a::ln \<Rightarrow> 'a::ln \<Rightarrow> \<bool>"
where
"post_vdm_pow_post x y RESULT \<equiv> True"
text \<open>For floor and abs, we just use Isabelle's. Note that in VDM abs of int
will return int, so this will entail more complicated translations. \<close>
find_theorems "_ (_::'a list list)" name:concat
definition
vdm_floor :: "VDMReal \<Rightarrow> VDMInt"
where
[intro!]: "vdm_floor x \<equiv> \<lfloor>x\<rfloor>"
definition
post_vdm_floor :: "VDMReal \<Rightarrow> VDMInt \<Rightarrow> \<bool>"
where
"post_vdm_floor x RESULT \<equiv>
of_int RESULT \<le> x \<and> x < of_int (RESULT + 1)"
(* same as the floor_correct axiom of Archimedian_Field*)
definition
vdm_abs :: "VDMReal \<Rightarrow> VDMReal"
where
[intro!]: "vdm_abs x \<equiv> \<bar>x\<bar>"
definition
post_vdm_abs :: "VDMReal \<Rightarrow> VDMReal \<Rightarrow> \<bool>"
where
"post_vdm_abs x RESULT \<equiv> RESULT \<ge> 0" (*inv_VDMNat RESULT"*)
(*****************************************************************)
section \<open> Sets \<close>
type_synonym 'a VDMSet = "'a set"
type_synonym 'a VDMSet1 = "'a set"
definition
inv_VDMSet :: "'a VDMSet \<Rightarrow> \<bool>"
where
[intro!]: "inv_VDMSet s \<equiv> finite s"
lemma l_invVDMSet_finite_f: "inv_VDMSet s \<Longrightarrow> finite s"
using inv_VDMSet_def by auto
definition
inv_VDMSet1 :: "'a VDMSet1 \<Rightarrow> \<bool>"
where
[intro!]: "inv_VDMSet1 s \<equiv> inv_VDMSet s \<and> s \<noteq> {}"
lemmas inv_VDMSet1_defs = inv_VDMSet1_def inv_VDMSet_def
definition
inv_SetElems :: "('a \<Rightarrow> \<bool>) \<Rightarrow> 'a VDMSet \<Rightarrow> \<bool>"
where
"inv_SetElems einv s \<equiv> \<forall> e \<in> s . einv e"
lemma l_inv_SetElems_Cons[simp]: "(inv_SetElems f (insert a s)) = (f a \<and> (inv_SetElems f s))"
unfolding inv_SetElems_def
by auto
lemma l_inv_SetElems_Un[simp]: "(inv_SetElems f (S \<union> T)) = (inv_SetElems f S \<and> inv_SetElems f T)"
unfolding inv_SetElems_def
by auto
lemma l_inv_SetElems_Int[simp]: "(inv_SetElems f (S \<inter> T)) = (inv_SetElems f (S \<inter> T))"
unfolding inv_SetElems_def
by auto
lemma l_inv_SetElems_empty[simp]: "inv_SetElems f {}"
unfolding inv_SetElems_def by simp
lemma l_invSetElems_inv_True_True[simp]: "inv_SetElems inv_True r"
by (simp add: inv_SetElems_def)
definition
vdm_card :: "'a VDMSet \<Rightarrow> VDMNat"
where
"vdm_card s \<equiv> (if inv_VDMSet s then int (card s) else undefined)"
definition
pre_vdm_card :: "'a VDMSet \<Rightarrow> \<bool>"
where
[intro!]: "pre_vdm_card s \<equiv> inv_VDMSet s"
definition
post_vdm_card :: "'a VDMSet \<Rightarrow> VDMNat \<Rightarrow> \<bool>"
where
[intro!]: "post_vdm_card s RESULT \<equiv> pre_vdm_card s \<longrightarrow> inv_VDMNat RESULT"
lemmas vdm_card_defs = vdm_card_def inv_VDMSet_def
lemma "vdm_card {0,1,(2::int)} = 3"
unfolding vdm_card_def inv_VDMSet_def by simp
lemma l_vdm_card_finite[simp]: "finite s \<Longrightarrow> vdm_card s = int (card s)"
unfolding vdm_card_defs by simp
lemma l_vdm_card_range[simp]: "x \<le> y \<Longrightarrow> vdm_card {x .. y} = y - x + 1"
unfolding vdm_card_defs by simp
lemma l_vdm_card_positive[simp]:
"finite s \<Longrightarrow> 0 \<le> vdm_card s"
by simp
lemma l_vdm_card_VDMNat[simp]:
"finite s \<Longrightarrow> inv_VDMNat (vdm_card s)"
by (simp add: inv_VDMSet_def inv_VDMNat_def)
lemma l_vdm_card_non_negative[simp]:
"finite s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> 0 < vdm_card s"
by (simp add: card_gt_0_iff)
theorem PO_feas_vdm_card:
"pre_vdm_card s \<Longrightarrow> post_vdm_card s (vdm_card s)"
by (simp add: inv_VDMNat_def inv_VDMSet_def post_vdm_card_def pre_vdm_card_def)
lemma l_vdm_card_isa_card[simp]:
"finite s \<Longrightarrow> card s \<le> i \<Longrightarrow> vdm_card s \<le> i"
by simp
lemma l_isa_card_inter_bound:
"finite T \<Longrightarrow> card T \<le> i \<Longrightarrow> card (S \<inter> T) \<le> i"
thm card_mono inf_le2 le_trans card_seteq Int_commute nat_le_linear
by (meson card_mono inf_le2 le_trans)
lemma l_vdm_card_inter_bound:
"finite T \<Longrightarrow> vdm_card T \<le> i \<Longrightarrow> vdm_card (S \<inter> T) \<le> i"
proof -
assume a1: "vdm_card T \<le> i"
assume a2: "finite T"
have f3: "\<forall>A Aa. ((card (A::'a set) \<le> card (Aa::'a set) \<or> \<not> vdm_card A \<le> vdm_card Aa) \<or> infinite A) \<or> infinite Aa"
by (metis (full_types) l_vdm_card_finite of_nat_le_iff)
{ assume "T \<inter> S \<noteq> T"
then have "vdm_card (T \<inter> S) \<noteq> vdm_card T \<and> T \<inter> S \<noteq> T \<or> vdm_card (T \<inter> S) \<le> i"
using a1 by presburger
then have "vdm_card (T \<inter> S) \<le> i"
using f3 a2 a1 by (meson card_seteq dual_order.trans inf_le1 infinite_super verit_la_generic) }
then show ?thesis
using a1 by (metis (no_types) Int_commute)
qed
text \<open> @TODO power set \<close>
(*****************************************************************)
section \<open> Sequences \<close>
type_synonym 'a VDMSeq = "'a list"
type_synonym 'a VDMSeq1 = "'a list"
definition
inv_VDMSeq1 :: "'a VDMSeq1 \<Rightarrow> \<bool>"
where
[intro!]: "inv_VDMSeq1 s \<equiv> s \<noteq> []"
text\<open> Sequences may have invariants within their inner type. \<close>
definition
inv_SeqElems :: "('a \<Rightarrow> \<bool>) \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool>"
where
[intro!]: "inv_SeqElems einv s \<equiv> list_all einv s"
definition
inv_SeqElems0 :: "('a \<Rightarrow> \<bool>) \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool>"
where
"inv_SeqElems0 einv s \<equiv> \<forall> e \<in> (set s) . einv e"
text \<open> Isabelle's list @{term hd} and @{term tl} functions have the
same name as VDM. Nevertheless, their results is defined for empty lists.
We need to rule them out.
\<close>
(*****************************************************************)
subsection \<open> Sequence operators specification \<close>
definition
len :: "'a VDMSeq \<Rightarrow> VDMNat"
where
[intro!]: "len l \<equiv> int (length l)"
definition
post_len :: "'a VDMSeq \<Rightarrow> VDMNat \<Rightarrow> \<bool>"
where
"post_len s R \<equiv> inv_VDMNat(R)"
definition
elems :: "'a VDMSeq \<Rightarrow> 'a VDMSet"
where
[intro!]: "elems l \<equiv> set l"
text \<open> Be careful with representation differences
VDM lists are 1-based, whereas Isabelle list
are 0-based. This function returns {0,1,2}
for sequence [A, B, C] instead of {1,2,3} \<close>
definition
inds0 :: "'a VDMSeq \<Rightarrow> VDMNat set"
where
"inds0 l \<equiv> {0 ..< len l}"
value "inds0 [A, B, C]"
(* indexes are 0, 1, 2; VDM would give 1, 2, 3 *)
definition
inds :: "'a VDMSeq \<Rightarrow> VDMNat1 set"
where
[intro!]: "inds l \<equiv> {1 .. len l}"
definition
post_inds :: "'a VDMSeq \<Rightarrow> VDMNat1 set \<Rightarrow> \<bool>"
where
"post_inds l R \<equiv> (length l) = (card R)"
definition
inds_as_nat :: "'a VDMSeq \<Rightarrow> \<nat> set"
where
"inds_as_nat l \<equiv> {1 .. nat (len l)}"
text \<open> @{term applyList} plays with @{typ "'a option"} type instead of @{term undefined}. \<close>
definition
applyList :: "'a VDMSeq \<Rightarrow> \<nat> \<Rightarrow> 'a option"
where
"applyList l n \<equiv> (if (n > 0 \<and> int n \<le> len l) then
Some(l ! (n - (1::nat)))
else
None)"
text \<open> @{term applyVDMSeq} sticks with @{term undefined}. \<close>
definition
applyVDMSeq :: "'a VDMSeq \<Rightarrow> VDMNat1 \<Rightarrow> 'a" (infixl "$" 100)
where
"applyVDMSeq l n \<equiv> (if (inv_VDMNat1 n \<and> n \<le> len l) then
(l ! nat (n - 1))
else
undefined)"
text \<open> VDM \verb'l1 ++ l2' is just @{term "l1 @ l2"} \<close>
thm append_def
lemmas applyVDMSeq_defs = applyVDMSeq_def inv_VDMNat1_def len_def
definition
pre_applyVDMSeq :: "'a VDMSeq \<Rightarrow> VDMNat1 \<Rightarrow> \<bool>"
where
"pre_applyVDMSeq xs i \<equiv> inv_VDMNat1 i \<and> i \<le> len xs" (*\<and> i \<in> inds xs?*)
definition
post_applyVDMSeq :: "'a VDMSeq \<Rightarrow> VDMNat1 \<Rightarrow> 'a \<Rightarrow> \<bool>"
where
"post_applyVDMSeq xs i R \<equiv> pre_applyVDMSeq xs i \<longrightarrow> R = xs $ i"
definition
post_append :: "'a VDMSeq \<Rightarrow> 'a VDMSeq \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool>"
where
"post_append s t r \<equiv> r = s @ t"
lemmas VDMSeq_defs = elems_def inds_def applyVDMSeq_defs
lemma l_applyVDMSeq_inds[simp]:
"pre_applyVDMSeq xs i = (i \<in> inds xs)"
unfolding pre_applyVDMSeq_def inv_VDMNat1_def len_def inds_def
by auto
text \<open> Isabelle @{term hd} and @{term tl} is the same as VDM \<close>
definition
pre_hd :: "'a VDMSeq \<Rightarrow> \<bool>"
where
"pre_hd s \<equiv> s \<noteq> []"
definition
post_hd :: "'a VDMSeq \<Rightarrow> 'a \<Rightarrow> \<bool>"
where
"post_hd s RESULT \<equiv> pre_hd s \<longrightarrow> (RESULT \<in> elems s \<or> RESULT = s$1)"
definition
pre_tl :: "'a VDMSeq \<Rightarrow> \<bool>"
where
"pre_tl s \<equiv> s \<noteq> []"
definition
post_tl :: "'a VDMSeq \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool>"
where
"post_tl s RESULT \<equiv> pre_tl s \<longrightarrow> elems RESULT \<subseteq> elems s"
definition
reverse :: "'a VDMSeq \<Rightarrow> 'a VDMSeq"
where
[intro!]: "reverse xs \<equiv> rev xs"
definition
post_reverse :: "'a VDMSeq \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool>"
where
"post_reverse xs R \<equiv> elems xs = elems R"
definition
conc :: "'a VDMSeq VDMSeq \<Rightarrow> 'a VDMSeq"
where
[intro!]: "conc xs \<equiv> concat xs"
definition
vdmtake :: "VDMNat \<Rightarrow> 'a VDMSeq \<Rightarrow> 'a VDMSeq"
where
"vdmtake n s \<equiv> (if inv_VDMNat n then take (nat n) s else [])"
definition
post_vdmtake :: "VDMNat \<Rightarrow> 'a VDMSeq \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool>"
where
"post_vdmtake n s RESULT \<equiv>
len RESULT = min n (len s)
\<and> elems RESULT \<subseteq> elems s"
definition
seq_prefix :: "'a VDMSeq \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool>" ("(_/ \<sqsubseteq> _)" [51, 51] 50)
where
"s \<sqsubseteq> t \<equiv> (s = t) \<or> (s = []) \<or> (len s \<le> len t \<and> (\<exists> i \<in> inds t . s = vdmtake i t))"
definition
post_seq_prefix :: "'a VDMSeq \<Rightarrow> 'a VDMSeq \<Rightarrow> \<bool> \<Rightarrow> \<bool>"
where
"post_seq_prefix s t RESULT \<equiv>
RESULT \<longrightarrow> (elems s \<subseteq> elems t \<and> len s \<le> len t)"
(*****************************************************************)
subsection \<open> Sequence operators lemmas \<close>
lemma l_inv_VDMSet_finite[simp]:
"finite xs \<Longrightarrow> inv_VDMSet xs"
unfolding inv_VDMSet_def by simp
lemma l_inv_SeqElems_alt: "inv_SeqElems einv s = inv_SeqElems0 einv s"
by (simp add: elems_def inv_SeqElems0_def inv_SeqElems_def list_all_iff)
lemma l_inv_SeqElems_empty[simp]: "inv_SeqElems f []"
by (simp add: inv_SeqElems_def)
lemma l_inv_SeqElems_Cons: "(inv_SeqElems f (a#s)) = (f a \<and> (inv_SeqElems f s))"
unfolding inv_SeqElems_def elems_def by auto
lemma l_inv_SeqElems_append: "(inv_SeqElems f (xs @ [x])) = (f x \<and> (inv_SeqElems f xs))"
unfolding inv_SeqElems_def elems_def by auto
lemma l_invSeqElems_inv_True_True[simp]: "inv_SeqElems inv_True r"
by (simp add: inv_SeqElems_def rev_induct)
lemma l_len_append_single[simp]: "len(xs @ [x]) = 1 + len xs"
apply (induct xs)
apply simp_all
unfolding len_def by simp_all
lemma l_len_empty[simp]: "len [] = 0" unfolding len_def by simp
lemma l_len_cons[simp]: "len(x # xs) = 1 + len xs"
apply (induct xs)
unfolding len_def by simp_all
lemma l_elems_append[simp]: "elems (xs @ [x]) = insert x (elems xs)"
unfolding elems_def by simp
lemma l_elems_cons[simp]: "elems (x # xs) = insert x (elems xs)"
unfolding elems_def by simp
lemma l_elems_empty[simp]: "elems [] = {}" unfolding elems_def by simp
lemma l_inj_seq: "distinct s \<Longrightarrow> nat (len s) = card (elems s)"
by (induct s) (simp_all add: elems_def len_def) (* add: l_elems_cons *)
lemma l_elems_finite[simp]:
"finite (elems l)"
by (simp add: elems_def)
lemma l_inds_append[simp]: "inds (xs @ [x]) = insert (len (xs @ [x])) (inds xs)"
unfolding inds_def
by (simp add: atLeastAtMostPlus1_int_conv len_def)
lemma l_inds_cons[simp]: "inds (x # xs) = {1 .. (len xs + 1)}"
unfolding inds_def len_def
by simp
lemma l_len_within_inds[simp]: "s \<noteq> [] \<Longrightarrow> len s \<in> inds s"
unfolding len_def inds_def
apply (induct s)
by simp_all
lemma l_inds_empty[simp]: "inds [] = {}"
unfolding inds_def len_def by simp
lemma l_inds_as_nat_append: "inds_as_nat (xs @ [x]) = insert (length (xs @ [x])) (inds_as_nat xs)"
unfolding inds_as_nat_def len_def by auto
lemma l_len_nat1[simp]: "s \<noteq> [] \<Longrightarrow> 0 < len s"
unfolding len_def by simp
lemma l_applyVDM_len1: "s $ (len s + 1) = undefined"
unfolding applyVDMSeq_def len_def by simp
lemma l_applyVDM_zero[simp]: "s $ 0 = undefined"
unfolding applyVDMSeq_defs by simp
(* this goal is too specific; they are useful in specific situations *)
lemma l_applyVDM1: "(x # xs) $ 1 = x"
by (simp add: applyVDMSeq_defs)
lemma l_applyVDM2: "(x # xs) $ 2 = xs $ 1"
by (simp add: applyVDMSeq_defs)
(* generalise previous failure for a better matching goal: trade $ for ! *)
lemma l_applyVDM1_gen[simp]: "s \<noteq> [] \<Longrightarrow> s $ 1 = s ! 0"
by (induct s, simp_all add: applyVDMSeq_defs)
lemma l_applyVDMSeq_i[simp]: "i \<in> inds s \<Longrightarrow> s $ i = s ! nat(i - 1)"
unfolding applyVDMSeq_defs inds_def by simp
lemma l_applyVDM_cons_gt1empty: "i > 1 \<Longrightarrow> (x # []) $ i = undefined"
by (simp add: applyVDMSeq_defs)
lemma l_applyVDM_cons_gt1: "len xs > 0 \<Longrightarrow> i > 1 \<Longrightarrow> (x # xs) $ i = xs $ (i - 1)"
apply (simp add: applyVDMSeq_defs) (* again too complex; try avoiding the trade $ for ! again *)
apply (intro impI)
apply (induct xs rule: length_induct)
apply simp_all
by (smt nat_1 nat_diff_distrib)
lemma l_applyVDMSeq_defined: "s \<noteq> [] \<Longrightarrow> inv_SeqElems (\<lambda> x . x \<noteq> undefined) s \<Longrightarrow> s $ (len s) \<noteq> undefined"
unfolding applyVDMSeq_defs
apply (simp) (* add: l_len_nat1)*)
apply (cases "nat (int (length s) - 1)")
apply simp_all
apply (cases s)
apply simp_all
unfolding inv_SeqElems_def
apply simp
by (simp add: list_all_length)
(*thm ssubst[OF l_inv_SeqElems_alt]
apply (subst ssubst[OF l_inv_SeqElems_alt])*)
lemma l_applyVDMSeq_append_last:
"(ms @ [m]) $ (len (ms @ [m])) = m"
unfolding applyVDMSeq_defs
by (simp)
lemma l_applyVDMSeq_cons_last:
"(m # ms) $ (len (m # ms)) = (if ms = [] then m else ms $ (len ms))"
apply (simp)
unfolding applyVDMSeq_defs
by (simp add: nat_diff_distrib')
lemma l_inds_in_set:
"i \<in> inds s \<Longrightarrow> s$i \<in> set s"
unfolding inds_def applyVDMSeq_def inv_VDMNat1_def len_def
apply (simp,safe)
by (simp)
lemma l_inv_SeqElems_inds_inv_T:
"inv_SeqElems inv_T s \<Longrightarrow> i \<in> inds s \<Longrightarrow> inv_T (s$i)"
apply (simp add: l_inv_SeqElems_alt)
unfolding inv_SeqElems0_def
apply (erule_tac x="s$i" in ballE)
apply simp
using l_inds_in_set by blast
lemma l_inv_SeqElems_all:
"inv_SeqElems inv_T s = (\<forall> i \<in> inds s . inv_T (s$i))"
unfolding inv_SeqElems_def
apply (simp add: list_all_length)
unfolding inds_def len_def
apply (safe,simp, safe)
apply (erule_tac x="nat(i-1)" in allE)
apply simp
apply (erule_tac x="int n + 1" in ballE)
by simp+
lemma l_inds_upto: "(i \<in> inds s) = (i \<in> {1..len s})"
by (simp add: inds_def)
lemma l_vdmtake_take[simp]: "vdmtake n s = take n s"
unfolding vdmtake_def inv_VDMNat_def
by simp
lemma l_seq_prefix_append_empty[simp]: "s \<sqsubseteq> s @ []"
unfolding seq_prefix_def
by simp
lemma l_seq_prefix_id[simp]: "s \<sqsubseteq> s"
unfolding seq_prefix_def
by simp
lemma l_len_append[simp]: "len s \<le> len (s @ t)"
apply (induct t)
by (simp_all add: len_def)
lemma l_vdmtake_len[simp]: "vdmtake (len s) s = s"
unfolding vdmtake_def len_def inv_VDMNat_def by simp
lemma l_vdmtake_len_append[simp]: "vdmtake (len s) (s @ t) = s"
unfolding vdmtake_def len_def inv_VDMNat_def by simp
lemma l_vdmtake_append[simp]: "vdmtake (len s + len t) (s @ t) = (s @ t)"
apply (induct t)
apply simp_all
unfolding vdmtake_def len_def inv_VDMNat_def
by simp
value "vdmtake (1 + len [a,b,c]) ([a,b,c] @ [a])"
lemma l_seq_prefix_append[simp]: "s \<sqsubseteq> s @ t"
unfolding seq_prefix_def
apply (induct t)
apply simp+
apply (elim disjE)
apply (simp_all)
apply (cases s, simp)
apply (rule disjI2, rule disjI2)
apply (rule_tac x="len s" in bexI)
apply (metis l_vdmtake_len_append)
using l_len_within_inds apply blast
by (metis (full_types) atLeastAtMost_iff inds_def l_len_append l_len_within_inds l_vdmtake_len_append)
(*****************************************************************)
section \<open> Optional inner type invariant check \<close>
definition
inv_Option :: "('a \<Rightarrow> \<bool>) \<Rightarrow> 'a option \<Rightarrow> \<bool>"
where
[intro!]: "inv_Option inv_type v \<equiv> v \<noteq> None \<longrightarrow> inv_type (the v)"
lemma l_inv_option_Some[simp]:
"inv_Option inv_type (Some x) = inv_type x"
unfolding inv_Option_def
by simp
lemma l_inv_option_None[simp]:
"inv_Option inv_type None"
unfolding inv_Option_def
by simp
(*****************************************************************)
section \<open> Maps \<close>
(*type_synonym ('a, 'b) "VDMMap" = "'a \<rightharpoonup> 'b" (infixr "\<rightharpoonup>" 0)*)
definition
inv_Map :: "('a \<Rightarrow> \<bool>) \<Rightarrow> ('b \<Rightarrow> \<bool>) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow>\<bool>"
where
[intro!]:
"inv_Map inv_Dom inv_Rng m \<equiv>
inv_VDMSet (dom m) \<and>
inv_VDMSet (ran m) \<and>
inv_SetElems inv_Dom (dom m) \<and>
inv_SetElems inv_Rng (ran m)"
(*
Some VDM functions for map domain/range restriction and filtering. You use some like <: and :>.
The use of som of these funcions is one reason that makes the use of maps a bit more demanding,
but it works fine. Given these are new definitions, "apply auto" won't finish proofs as Isabelle
needs to know more (lemmas) about the new operators.
*)
definition
inv_Map1 :: "('a \<Rightarrow> \<bool>) \<Rightarrow> ('b \<Rightarrow> \<bool>) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> \<bool>"
where
[intro!]: "inv_Map1 inv_Dom inv_Ran m \<equiv>
inv_Map inv_Dom inv_Ran m \<and> m \<noteq> Map.empty"
(*vdm_card (dom m) > 0 \<and> is worst more complicated for nothing*)
definition
inv_Inmap :: "('a \<Rightarrow> \<bool>) \<Rightarrow> ('b \<Rightarrow> \<bool>) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> \<bool>"
where
[intro!]: "inv_Inmap inv_Dom inv_Ran m \<equiv>
inv_Map inv_Dom inv_Ran m \<and> inj m"
(* dom exists already *)
thm dom_def
lemma "inj m" unfolding inj_on_def apply simp oops
definition
rng :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'b VDMSet"
where
[intro!]: "rng m = ran m"
lemmas rng_defs = rng_def ran_def
definition
dagger :: "('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b)" (infixl "\<dagger>" 100)
where
[intro!]: "f \<dagger> g \<equiv> f ++ g"
definition
munion :: "('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b)" (infixl "\<union>m" 90)
where
[intro!]: "f \<union>m g \<equiv> (if dom f \<inter> dom g = {} then f \<dagger> g else undefined)"
definition
dom_restr :: "'a set \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b)" (infixr "\<triangleleft>" 110)
where
[intro!]: "s \<triangleleft> m \<equiv> m |` s"
(* same as VDM s <: m *)
definition
dom_antirestr :: "'a set \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b)" (infixr "-\<triangleleft>" 110)
where
[intro!]: "s -\<triangleleft> m \<equiv> (\<lambda>x. if x : s then None else m x)"
(* same as VDM s <-: m *)
definition
rng_restr :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'b set \<Rightarrow> ('a \<rightharpoonup> 'b)" (infixl "\<triangleright>" 105)
where
[intro!]: "m \<triangleright> s \<equiv> (\<lambda>x . if (\<exists> y. m x = Some y \<and> y \<in> s) then m x else None)"
(* same as VDM m :> s *)
definition
rng_antirestr :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'b set \<Rightarrow> ('a \<rightharpoonup> 'b)" (infixl "\<triangleright>-" 105)
where
[intro!]: "m \<triangleright>- s \<equiv> (\<lambda>x . if (\<exists> y. m x = Some y \<and> y \<in> s) then None else m x)"
(* same as VDM m :-> s *)
definition
map_subset :: "('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> \<bool>) \<Rightarrow> \<bool>" ("((_)/ \<subseteq>\<^sub>s (_)/, (_))" [0, 0, 50] 50)
where
"(m\<^sub>1 \<subseteq>\<^sub>s m\<^sub>2, subset_of) \<longleftrightarrow> (dom m\<^sub>1 \<subseteq> dom m\<^sub>2 \<and> (\<forall>a \<in> dom m\<^sub>1. subset_of (the(m\<^sub>1 a)) (the(m\<^sub>2 a))))"
text \<open> Map application is just function application, but the result is an optional type,
so it is up to the user to unpick the optional type with the @{term the} operator.
It means we shouldn't get to undefined,
rather than we are handling undefinedness. That's because the value
is comparable (see next lemma). In effect, if we ever reach undefined
it means we have some partial function application outside its domain
somewhere within any rewriting chain. As one cannot reason about this
value, it can be seen as a flag for an error to be avoided.\<close>
definition
map_comp :: "('b \<rightharpoonup> 'c) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'c)" (infixl "\<circ>m" 55)
where
"f \<circ>m g \<equiv> (\<lambda> x . if x \<in> dom g then f (the (g x)) else None)"
subsection \<open> Set translations: enumeration, comprehension, ranges \<close>
(* { expr | var . filter }, { var \<in> type . filter }, { var . filter } *)
value "{ x+x | x . x \<in> {(1::nat),2,3,4,5,6} }"
value "{ x+x | x . x \<in> {(1::nat),2,3} }"
(*value "{ x+x | x . x \<in> {(1::nat)..3} }" --"not always work"*)
value "{0..(2::int)}"
value "{0..<(3::int)}"
value "{0<..<(3::int)}"
subsection \<open> Seq translations: enumeration, comprehension, ranges \<close>
value "{ [A,B,C] ! i | i . i \<in> {0,1,2} }"
value "{ [A,B,C,D,E,F] ! i | i . i \<in> {0,2,4} }"
(* { s(i) | i in set inds s & i mod 2 = 0 } *)
(* List application (i.e. s(x)) is available in Isabelle, but is zero based *)
value "[A, B, C] ! 0"
value "[A, B, C] ! 1"
value "[A, B, C] ! 2"
value "[A, B, C] ! 3"
value "nth [A, B, C] 0"
value "applyList [A, B] 0" \<comment> \<open>out of range\<close>
value "applyList [A, B] 1"
value "applyList [A, B] 2"
value "applyList [A, B] 3" \<comment> \<open>out of range\<close>
value "[A,B,C,D] $ 0"
lemma "[A,B,C] $ 4 = A" unfolding applyVDMSeq_defs apply simp oops
lemma "[A,B,C] $ 1 = A" unfolding applyVDMSeq_defs apply simp done
value "[a] $ (len [(a::nat)])"
value "[A, B] $ 0" \<comment> \<open>out of range\<close>
value "[A,B]$1"
value "[A, B]$ 1"
value "[A, B]$ 2"
value "[A, B]$ 3" \<comment> \<open>out of range\<close>
(* List comprehension *)
value "{ [A,B,C] ! i | i . i \<in> {0,1,2} }"
value "[ x . x \<leftarrow> [0,1,(2::int)] ]" (*avoid if possible... *)
value "[ x . x \<leftarrow> [0 .. 3] ]"
value "len [A, B, C]"
value "elems [A, B, C, A, B]"
value "elems [(0::nat), 1, 2]"
value "inds [A,B,C]"
value "inds_as_nat [A,B,C]"
value "card (elems [10, 20, 30, 1, 2, 3, 4, (5::nat), 10])"
value "len [10, 20, 30, 1, 2, 3, 4, (5::nat), 10]"
(* MySeq = seq of nat1
inv s == len s \<le> 9 and card(elem s) = len s and (forall i in set elems s . i \<le> 9)*)
type_synonym MySeq = "VDMNat1 list"
definition
inv_MySeq :: "MySeq \<Rightarrow> \<bool>"
where
"inv_MySeq s \<equiv> (inv_SeqElems inv_VDMNat1 s) \<and>
len s \<le> 9 \<and> int (card (elems s)) = len s \<and>
(\<forall> i \<in> elems s . i > 0 \<and> i \<le> 9)"
value "inv_MySeq [1, 2, 3]"
(*
type_synonym ('a,'b) "map" = "'a \<Rightarrow> 'b option" (infixr "~=>" 0)
*)
text \<open>
In Isabelle, VDM maps can be declared by the @{text "\<rightharpoonup>"} operator (not @{text "\<Rightarrow>"})
(i.e. type 'right' and you will see the arrow on dropdown menu).
It represents a function to an optional result as follows:
VDM : map X to Y
Isabelle: @{text "X \<rightharpoonup> Y"}
which is the same as
Isabelle: @{text "X \<Rightarrow> Y option"}
where an optional type is like using nil in VDM (map X to [Y]).
That is, Isabele makes the map total by mapping everything outside
the domain to None (or nil). In Isabelle
@{text "datatype 'a option = None | Some 'a"}
\<close>
text \<open> VDM maps auxiliary functions \<close>
(* dom exists already *)
thm dom_def
find_theorems "dom _"
subsection \<open> Map translations: enumeration, comprehension \<close>
(* map values are given as *)
value "[ (0::nat) \<mapsto> (7::nat), 1 \<mapsto> 5 ]"
value "[ (0::int) \<mapsto> (1::int), 1 \<mapsto> 5 ] 0"
value "the ([ (0::int) \<mapsto> (1::int), 1 \<mapsto> 5 ] 0)"
value "the (Some b)"
value "Map.empty(A \<mapsto> 0)"
value "Map.empty(A := Some 0)"
value "[A \<mapsto> 0]"
value "[A \<mapsto> 0, B \<mapsto> 1]"
(*
value "the None"
value "Map.empty"
value "the ([ (1::int) \<mapsto> (1::int), 2 \<mapsto> 1, 3 \<mapsto> 2 ] (4::int)) + (3::int)"
value "the ([ (0::nat) \<mapsto> (0::nat), 1 \<mapsto> 5 ] (4::nat))"
*)
lemma "the ([ (1::int) \<mapsto> (1::int), 2 \<mapsto> 1, 3 \<mapsto> 2 ] (4::int)) + (3::int) = A" apply simp oops
lemma "the ([ (1::int) \<mapsto> (1::int), 2 \<mapsto> 1, 3 \<mapsto> 2 ] 2) + 3 = 4" by simp
find_theorems "the _"
text \<open> Not always it's possible to see their values as
maps encodings are more complex. You could use
Isabelle prover as a debugger
\<close>
lemma "dom [ A \<mapsto> 0, B \<mapsto> 1] = LOOK_HERE" apply simp oops
value "Map.empty(A \<mapsto> 0)"
value "Map.empty(A := Some 0)"
value "[A \<mapsto> 0]"
value "[A \<mapsto> 0, B \<mapsto> 1]"
lemma "dom [ A \<mapsto> 0, B \<mapsto> 1] = LOOK_HERE" apply simp oops
lemma "ran [ A \<mapsto> (0::nat), B \<mapsto> 1] = {0,1}" apply simp oops
(* rng also exists as ran *)
thm ran_def
find_theorems "ran _"
lemma "ran [ A \<mapsto> (0::nat), B \<mapsto> 1] = {0,1}" apply simp oops
(*========================================================================*)
section \<open> Set operators lemmas \<close>
(*========================================================================*)
lemma l_psubset_insert: "x \<notin> S \<Longrightarrow> S \<subset> insert x S"
by blast
lemma l_right_diff_left_dist: "S - (T - U) = (S - T) \<union> (S \<inter> U)"
by (metis Diff_Compl Diff_Int diff_eq)
thm Diff_Compl
Diff_Int
diff_eq
lemma l_diff_un_not_equal: "R \<subset> T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> S - T \<union> R \<noteq> S"
by auto
(*========================================================================*)
section \<open> Map operators lemmas \<close>
(*========================================================================*)
lemma l_map_non_empty_has_elem_conv:
"g \<noteq> Map.empty \<longleftrightarrow> (\<exists> x . x \<in> dom g)"
by (metis domIff)
lemma l_map_non_empty_dom_conv:
"g \<noteq> Map.empty \<longleftrightarrow> dom g \<noteq> {}"
by (metis dom_eq_empty_conv)
lemma l_map_non_empty_ran_conv:
"g \<noteq> Map.empty \<longleftrightarrow> ran g \<noteq> {}"
by (metis empty_iff equals0I
fun_upd_triv option.exhaust
ranI ran_restrictD restrict_complement_singleton_eq)
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
subsubsection \<open> Domain restriction weakening lemmas [EXPERT] \<close>
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
(* Lemma: dom restriction set inter equiv [ZEVES-LEMMA] *)
lemma l_dom_r_iff: "dom(S \<triangleleft> g) = S \<inter> dom g"
by (metis Int_commute dom_restr_def dom_restrict)
(* Lemma: dom restriction set inter equiv [ZEVES-LEMMA] *)
lemma l_dom_r_subset: "(S \<triangleleft> g) \<subseteq>\<^sub>m g"
by (metis Int_iff dom_restr_def l_dom_r_iff map_le_def restrict_in)
(* Lemma: dom restriction set inter equiv [ZEVES-LEMMA] *)
lemma l_dom_r_accum: "S \<triangleleft> (T \<triangleleft> g) = (S \<inter> T) \<triangleleft> g"
by (metis Int_commute dom_restr_def restrict_restrict)
(* Lemma: dom restriction set inter equiv [ZEVES-LEMMA] *)
lemma l_dom_r_nothing: "{} \<triangleleft> f = Map.empty"
by (metis dom_restr_def restrict_map_to_empty)
(* Lemma: dom restriction set inter equiv [ZEVES-LEMMA] *)
lemma l_dom_r_empty: "S \<triangleleft> Map.empty = Map.empty"
by (metis dom_restr_def restrict_map_empty)
lemma l_dom_r_nothing_empty: "S = {} \<Longrightarrow> S \<triangleleft> f = Map.empty"
by (metis l_dom_r_nothing)
(* FD: in specific dom subsumes application (over Some+None) [ZEVES-LEMMA] *)
(*
lemmX f_in_dom_r_apply_elem:
"l \<in> dom f \<and> l \<in> S \<Longrightarrow> ((S \<triangleleft> f) l) = (f l)"
unfolding dom_restr_def
by (cases "l\<in>S", auto)
*)
(* IJW: Simplified as doesn't need the l:dom f case *)
lemma f_in_dom_r_apply_elem: " x \<in> S \<Longrightarrow> ((S \<triangleleft> f) x) = (f x)"
by (metis dom_restr_def restrict_in)
lemma f_in_dom_r_apply_the_elem: "x \<in> dom f \<Longrightarrow> x \<in> S \<Longrightarrow> ((S \<triangleleft> f) x) = Some(the(f x))"
by (metis domIff f_in_dom_r_apply_elem option.collapse)
(* IJW: TODO: classify; rename. *)
lemma l_dom_r_disjoint_weakening: "A \<inter> B = {} \<Longrightarrow> dom(A \<triangleleft> f) \<inter> dom(B \<triangleleft> f) = {}"
by (metis dom_restr_def dom_restrict inf_bot_right inf_left_commute restrict_restrict)
(* IJW: TODO: classify; rename - refactor out for l_dom_r_iff? *)
lemma l_dom_r_subseteq: "S \<subseteq> dom f \<Longrightarrow> dom (S \<triangleleft> f) = S" unfolding dom_restr_def
by (metis Int_absorb1 dom_restrict)
(* IJW: TODO: classift; rename - refactor out for l_dom_r_subset? *)
lemma l_dom_r_dom_subseteq: "(dom ( S \<triangleleft> f)) \<subseteq> dom f"
unfolding dom_restr_def by auto
lemma l_the_dom_r: "x \<in> dom f \<Longrightarrow> x \<in> S \<Longrightarrow> the (( S \<triangleleft> f) x) = the (f x)"
by (metis f_in_dom_r_apply_elem)
lemma l_in_dom_dom_r: "x \<in> dom (S \<triangleleft> f) \<Longrightarrow> x \<in> S"
by (metis Int_iff l_dom_r_iff)
lemma l_dom_r_singleton: "x \<in> dom f \<Longrightarrow> ({x} \<triangleleft> f) = [x \<mapsto> the (f x)]"
unfolding dom_restr_def
by auto
lemma singleton_map_dom:
assumes "dom f = {x}" shows "f = [x \<mapsto> the (f x)]"
proof -
from assms obtain y where "f = [x \<mapsto> y]"
by (metis dom_eq_singleton_conv)
then have "y = the (f x)"
by (metis fun_upd_same option.sel)
thus ?thesis by (metis `f = [x \<mapsto> y]`)
qed
lemma l_relimg_ran_subset:
"ran (S \<triangleleft> m) \<subseteq> ran m"
by (metis (full_types) dom_restr_def ranI ran_restrictD subsetI)
lemma f_in_relimg_ran:
"y \<in> ran (S \<triangleleft> m) \<Longrightarrow> y \<in> ran m"
by (meson l_relimg_ran_subset subsetCE)
(* IJW: An experiment - not sure which are the best rules to choose! *)
lemmas restr_simps = l_dom_r_iff l_dom_r_accum l_dom_r_nothing l_dom_r_empty
f_in_dom_r_apply_elem l_dom_r_disjoint_weakening l_dom_r_subseteq
l_dom_r_dom_subseteq
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
subsubsection \<open> Domain anti restriction weakening lemmas [EXPERT] \<close>
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
(* FD: dom elem subsume dom ar *)
lemma f_in_dom_ar_subsume: "l \<in> dom (S -\<triangleleft> f) \<Longrightarrow> l \<in> dom f"
unfolding dom_antirestr_def
by (cases "l\<in>S", auto)
(* FD: in specific dom_ar cannot be what's filtered *)
lemma f_in_dom_ar_notelem: "l \<in> dom ({r} -\<triangleleft> f) \<Longrightarrow> l \<noteq> r"
unfolding dom_antirestr_def
by auto
(* FD: in specific dom_ar subsumes application (over Some) *)
lemma f_in_dom_ar_the_subsume:
"l \<in> dom (S -\<triangleleft> f) \<Longrightarrow> the ((S -\<triangleleft> f) l) = the (f l)"
unfolding dom_antirestr_def
by (cases "l\<in>S", auto)
(* FD: in specific dom_ar subsumes application (over Some+None) *)
lemma f_in_dom_ar_apply_subsume:
"l \<in> dom (S -\<triangleleft> f) \<Longrightarrow> ((S -\<triangleleft> f) l) = (f l)"
unfolding dom_antirestr_def
by (cases "l\<in>S", auto)
(* FD: in specific dom subsumes application (over Some+None) [ZEVES-LEMMA] *)
(*
lemmX f_in_dom_ar_apply_not_elem:
"l \<in> dom f \<and> l \<notin> S \<Longrightarrow> ((S -\<triangleleft> f) l) = (f l)"
unfolding dom_antirestr_def
by (cases "l\<in>S", auto)
*)
(* IJW: TODO: I had a more general lemma: *)
lemma f_in_dom_ar_apply_not_elem: "l \<notin> S \<Longrightarrow> (S -\<triangleleft> f) l = f l"
by (metis dom_antirestr_def)
(* FD: dom_ar subset dom [ZEVES-LEMMA] *)
lemma f_dom_ar_subset_dom:
"dom(S -\<triangleleft> f) \<subseteq> dom f"
unfolding dom_antirestr_def dom_def
by auto
(* Lemma: dom_ar as set different [ZEVES-LEMMA] *)
lemma l_dom_dom_ar:
"dom(S -\<triangleleft> f) = dom f - S"
unfolding dom_antirestr_def
by (smt Collect_cong domIff dom_def set_diff_eq)
(* Lemma: dom_ar accumulates to left [ZEVES-LEMMA] *)
lemma l_dom_ar_accum:
"S -\<triangleleft> (T -\<triangleleft> f) = (S \<union> T) -\<triangleleft> f"
unfolding dom_antirestr_def
by auto
(* Lemma: dom_ar subsumption [ZEVES-LEMMA] *)
lemma l_dom_ar_nothing:
"S \<inter> dom f = {} \<Longrightarrow> S -\<triangleleft> f = f"
unfolding dom_antirestr_def
apply (simp add: fun_eq_iff)
by (metis disjoint_iff_not_equal domIff)
(* NOTE: After finding fun_eq_iff, there is also map_le_antisym for maps!*)
(* Lemma: dom_ar nothing LHS [ZEVES-LEMMA] *)
lemma l_dom_ar_empty_lhs:
"{} -\<triangleleft> f = f"
by (metis Int_empty_left l_dom_ar_nothing)
(* Lemma: dom_ar nothing RHS [ZEVES-LEMMA] *)
lemma l_dom_ar_empty_rhs:
"S -\<triangleleft> Map.empty = Map.empty"
by (metis Int_empty_right dom_empty l_dom_ar_nothing)
(* Lemma: dom_ar all RHS is empty [ZEVES-LEMMA] *)
lemma l_dom_ar_everything:
"dom f \<subseteq> S \<Longrightarrow> S -\<triangleleft> f = Map.empty"
by (metis domIff dom_antirestr_def in_mono)
(* Lemma: dom_ar submap [ZEVES-LEMMA] *)
lemma l_map_dom_ar_subset: "S -\<triangleleft> f \<subseteq>\<^sub>m f"
by (metis domIff dom_antirestr_def map_le_def)
(* Lemma: dom_ar nothing RHS is f [ZEVES-LEMMA] *)
lemma l_dom_ar_none: "{} -\<triangleleft> f = f"
unfolding dom_antirestr_def
by (simp add: fun_eq_iff)
(* Lemma: dom_ar something RHS isn't f [ZEVES-LEMMA] *)
lemma l_map_dom_ar_neq: "S \<subseteq> dom f \<Longrightarrow> S \<noteq> {} \<Longrightarrow> S -\<triangleleft> f \<noteq> f"
apply (subst fun_eq_iff)
apply (insert ex_in_conv[of S])
apply simp
apply (erule exE)
unfolding dom_antirestr_def
apply (rule exI)
apply simp
apply (intro impI conjI)
apply simp_all
by (metis domIff set_mp)
(* IJW: TODO classify; rename *)
lemma l_dom_ar_not_in_dom:
assumes *: "x \<notin> dom f"
shows "x \<notin> dom (s -\<triangleleft> f)"
by (metis * domIff dom_antirestr_def)
(* IJW: TODO: classify; rename *)
lemma l_dom_ar_not_in_dom2: "x \<in> F \<Longrightarrow> x \<notin> dom (F -\<triangleleft> f)"
by (metis domIff dom_antirestr_def)
lemma l_dom_ar_notin_dom_or: "x \<notin> dom f \<or> x \<in> S \<Longrightarrow> x \<notin> dom (S -\<triangleleft> f)"
by (metis Diff_iff l_dom_dom_ar)
(* IJW: TODO: classify - shows conditions for being in antri restr dom *)
lemma l_in_dom_ar: "x \<notin> F \<Longrightarrow> x \<in> dom f \<Longrightarrow> x \<in> dom (F -\<triangleleft> f)"
by (metis f_in_dom_ar_apply_not_elem domIff)
lemma l_Some_in_dom:
"f x = Some y \<Longrightarrow> x \<in> dom f" by auto
(* IJW: TODO: classify; fix proof; rename; decide whether needed?! *)
lemma l_dom_ar_insert: "((insert x F) -\<triangleleft> f) = {x} -\<triangleleft> (F-\<triangleleft> f)"
proof
fix xa
show "(insert x F -\<triangleleft> f) xa = ({x} -\<triangleleft> F -\<triangleleft> f) xa"
apply (cases "x= xa")
apply (simp add: dom_antirestr_def)
apply (cases "xa\<in>F")
apply (simp add: dom_antirestr_def)
apply (subst f_in_dom_ar_apply_not_elem)
apply simp
apply (subst f_in_dom_ar_apply_not_elem)
apply simp
apply (subst f_in_dom_ar_apply_not_elem)
apply simp
apply simp
done
qed
(* IJW: TODO: classify; rename?; subsume by l_dom_ar_accum? *)
(* IJW: Think it may also be unused? *)
lemma l_dom_ar_absorb_singleton: "x \<in> F \<Longrightarrow> ({x} -\<triangleleft> F -\<triangleleft> f) =(F -\<triangleleft> f)"
by (metis l_dom_ar_insert insert_absorb)
(* IJW: TODO: rename; classify; generalise? *)
lemma l_dom_ar_disjoint_weakening:
"dom f \<inter> Y = {} \<Longrightarrow> dom (X -\<triangleleft> f) \<inter> Y = {}"
by (metis Diff_Int_distrib2 empty_Diff l_dom_dom_ar)
(* IJW: TODO: not used? *)
lemma l_dom_ar_singletons_comm: "{x}-\<triangleleft> {y} -\<triangleleft> f = {y}-\<triangleleft> {x} -\<triangleleft> f"
by (metis l_dom_ar_insert insert_commute)
lemmas antirestr_simps = f_in_dom_ar_subsume f_in_dom_ar_notelem f_in_dom_ar_the_subsume
f_in_dom_ar_apply_subsume f_in_dom_ar_apply_not_elem f_dom_ar_subset_dom
l_dom_dom_ar l_dom_ar_accum l_dom_ar_nothing l_dom_ar_empty_lhs l_dom_ar_empty_rhs
l_dom_ar_everything l_dom_ar_none l_dom_ar_not_in_dom l_dom_ar_not_in_dom2
l_dom_ar_notin_dom_or l_in_dom_ar l_dom_ar_disjoint_weakening
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
subsubsection \<open> Map override weakening lemmas [EXPERT] \<close>
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
(* Lemma: dagger associates [ZEVES-LEMMA] *)
lemma l_dagger_assoc:
"f \<dagger> (g \<dagger> h) = (f \<dagger> g) \<dagger> h"
by (metis dagger_def map_add_assoc)
thm ext option.split fun_eq_iff (* EXT! Just found function extensionality! *)
(* Lemma: dagger application [ZEVES-LEMMA] *)
lemma l_dagger_apply:
"(f \<dagger> g) x = (if x \<in> dom g then (g x) else (f x))"
unfolding dagger_def
by (metis (full_types) map_add_dom_app_simps(1) map_add_dom_app_simps(3))
(* Lemma: dagger domain [ZEVES-LEMMA] *)
lemma l_dagger_dom:
"dom(f \<dagger> g) = dom f \<union> dom g"
unfolding dagger_def
by (metis dom_map_add sup_commute)
(* Lemma: dagger absorption LHS *)
lemma l_dagger_lhs_absorb:
"dom f \<subseteq> dom g \<Longrightarrow> f \<dagger> g = g"
apply (rule ext)
by(metis dagger_def l_dagger_apply map_add_dom_app_simps(2) set_rev_mp)
lemma l_dagger_lhs_absorb_ALT_PROOF:
"dom f \<subseteq> dom g \<Longrightarrow> f \<dagger> g = g"
apply (rule ext)
apply (simp add: l_dagger_apply)
apply (rule impI)
find_theorems "_ \<notin> _ \<Longrightarrow> _" name:Set
apply (drule contra_subsetD)
unfolding dom_def
by (simp_all) (* NOTE: foun nice lemmas to be used: contra_subsetD*)
(* Lemma: dagger empty absorption lhs [ZEVES-LEMMA] *)
lemma l_dagger_empty_lhs:
"Map.empty \<dagger> f = f"
by (metis dagger_def empty_map_add)
(* Lemma: dagger empty absorption rhs [ZEVES-LEMMA] *)
lemma l_dagger_empty_rhs:
"f \<dagger> Map.empty = f"
by (metis dagger_def map_add_empty)
(* Interesting observation here:
A few times I have spotted this. I then to get these
lemmas and use them in Isar; whereas Leo, you don't seem
to use this variety. Probably because the automation takes
care of the reasoning?...
*)
(* IJW: TODO: Rename; classify *)
lemma dagger_notemptyL:
"f \<noteq> Map.empty \<Longrightarrow> f \<dagger> g \<noteq> Map.empty" by (metis dagger_def map_add_None)
lemma dagger_notemptyR:
"g \<noteq> Map.empty \<Longrightarrow> f \<dagger> g \<noteq> Map.empty" by (metis dagger_def map_add_None)
(* Lemma: dagger associates with dom_ar [ZEVES-LEMMA] *)
(* IJW: It's not really an assoc prop? Well, kinda, but also kinda distrib *)
lemma l_dagger_dom_ar_assoc:
"S \<inter> dom g = {} \<Longrightarrow> (S -\<triangleleft> f) \<dagger> g = S -\<triangleleft> (f \<dagger> g)"
apply (simp add: fun_eq_iff)
apply (simp add: l_dagger_apply)
apply (intro allI impI conjI)
unfolding dom_antirestr_def
apply (simp_all add: l_dagger_apply)
by (metis dom_antirestr_def l_dom_ar_nothing)
thm map_add_comm
(* NOTE: This should be provable, if only I know how to do map extensionality :-(. Now I do! fun_eq_iff!
Thm map_add_comm is quite nice lemma two, and could be used here, yet l_dagger_apply seems nicer.
*)
lemma l_dagger_not_empty:
"g \<noteq> Map.empty \<Longrightarrow> f \<dagger> g \<noteq> Map.empty"
by (metis dagger_def map_add_None)
(* IJW TODO: Following 6 need renamed; classified? LEO: how do you do such choices? *)
lemma in_dagger_domL:
"x \<in> dom f \<Longrightarrow> x \<in> dom(f \<dagger> g)"
by (metis dagger_def domIff map_add_None)
lemma in_dagger_domR:
"x \<in> dom g \<Longrightarrow> x \<in> dom(f \<dagger> g)"
by (metis dagger_def domIff map_add_None)
lemma the_dagger_dom_right:
assumes "x \<in> dom g"
shows "the ((f \<dagger> g) x) = the (g x)"
by (metis assms dagger_def map_add_dom_app_simps(1))
lemma the_dagger_dom_left:
assumes "x \<notin> dom g"
shows "the ((f \<dagger> g) x) = the (f x)"
by (metis assms dagger_def map_add_dom_app_simps(3))
lemma the_dagger_mapupd_dom: "x\<noteq>y \<Longrightarrow> (f \<dagger> [y \<mapsto> z]) x = f x "
by (metis dagger_def fun_upd_other map_add_empty map_add_upd)
lemma dagger_upd_dist: "f \<dagger> fa(e \<mapsto> r) = (f \<dagger> fa)(e \<mapsto> r)" by (metis dagger_def map_add_upd)
(* IJW TOD): rename *)
lemma antirestr_then_dagger_notin: "x \<notin> dom f \<Longrightarrow> {x} -\<triangleleft> (f \<dagger> [x \<mapsto> y]) = f"
proof
fix z
assume "x \<notin> dom f"
show "({x} -\<triangleleft> (f \<dagger> [x \<mapsto> y])) z = f z"
by (metis `x \<notin> dom f` domIff dom_antirestr_def fun_upd_other insertI1 l_dagger_apply singleton_iff)
qed
lemma antirestr_then_dagger: "r\<in> dom f \<Longrightarrow> {r} -\<triangleleft> f \<dagger> [r \<mapsto> the (f r)] = f"
proof
fix x
assume *: "r\<in>dom f"
show "({r} -\<triangleleft> f \<dagger> [r \<mapsto> the (f r)]) x = f x"
proof (subst l_dagger_apply,simp,intro conjI impI)
assume "x=r" then show "Some (the (f r)) = f r" using * by auto
next
assume "x \<noteq>r" then show " ({r} -\<triangleleft> f) x = f x" by (metis f_in_dom_ar_apply_not_elem singleton_iff)
qed
qed
(* IJW: TODO: rename; classify *)
lemma dagger_notin_right: "x \<notin> dom g \<Longrightarrow> (f \<dagger> g) x = f x"
by (metis l_dagger_apply)
(* IJW: TODO: rename; classify *)
lemma dagger_notin_left: "x \<notin> dom f \<Longrightarrow> (f \<dagger> g) x = g x"
by (metis dagger_def map_add_dom_app_simps(2))
lemma l_dagger_commute: "dom f \<inter> dom g = {} \<Longrightarrow>f \<dagger> g = g \<dagger> f"
unfolding dagger_def
apply (rule map_add_comm)
by simp
lemmas dagger_simps = l_dagger_assoc l_dagger_apply l_dagger_dom l_dagger_lhs_absorb
l_dagger_empty_lhs l_dagger_empty_rhs dagger_notemptyL dagger_notemptyR l_dagger_not_empty
in_dagger_domL in_dagger_domR the_dagger_dom_right the_dagger_dom_left the_dagger_mapupd_dom
dagger_upd_dist antirestr_then_dagger_notin antirestr_then_dagger dagger_notin_right
dagger_notin_left
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
subsubsection \<open> Map update weakening lemmas [EXPERT] \<close>
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
text \<open> without the condition nitpick finds counter example \<close>
lemma l_inmapupd_dom_iff:
"l \<noteq> x \<Longrightarrow> (l \<in> dom (f(x \<mapsto> y))) = (l \<in> dom f)"
by (metis (full_types) domIff fun_upd_apply)
lemma l_inmapupd_dom:
"l \<in> dom f \<Longrightarrow> l \<in> dom (f(x \<mapsto> y))"
by (metis dom_fun_upd insert_iff option.distinct(1))
lemma l_dom_extend:
"x \<notin> dom f \<Longrightarrow> dom (f1(x \<mapsto> y)) = dom f1 \<union> {x}"
by simp
lemma l_updatedom_eq:
"x=l \<Longrightarrow> the ((f(x \<mapsto> the (f x) - s)) l) = the (f l) - s"
by auto
lemma l_updatedom_neq:
"x\<noteq>l \<Longrightarrow> the ((f(x \<mapsto> the (f x) - s)) l) = the (f l)"
by auto
\<comment> \<open>A helper lemma to have map update when domain is updated\<close>
lemma l_insertUpdSpec_aux: "dom f = insert x F \<Longrightarrow> (f0 = (f |` F)) \<Longrightarrow> f = f0 (x \<mapsto> the (f x))"
proof auto
assume insert: "dom f = insert x F"
then have "x \<in> dom f" by simp
then show "f = (f |` F)(x \<mapsto> the (f x))" using insert
unfolding dom_def
apply simp
apply (rule ext)
apply auto
done
qed
lemma l_the_map_union_right: "x \<in> dom g \<Longrightarrow>dom f \<inter> dom g = {} \<Longrightarrow> the ((f \<union>m g) x) = the (g x)"
by (metis l_dagger_apply munion_def)
lemma l_the_map_union_left: "x \<in> dom f \<Longrightarrow>dom f \<inter> dom g = {} \<Longrightarrow> the ((f \<union>m g) x) = the (f x)"
by (metis l_dagger_apply l_dagger_commute munion_def)
lemma l_the_map_union: "dom f \<inter> dom g = {} \<Longrightarrow> the ((f \<union>m g) x) = (if x \<in> dom f then the (f x) else the (g x))"
by (metis l_dagger_apply l_dagger_commute munion_def)
lemmas upd_simps = l_inmapupd_dom_iff l_inmapupd_dom l_dom_extend
l_updatedom_eq l_updatedom_neq
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
subsubsection \<open> Map union (VDM-specific) weakening lemmas [EXPERT] \<close>
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
(* Weaken: munion point-wise update well-definedness condition *)
lemma k_munion_map_upd_wd:
"x \<notin> dom f \<Longrightarrow> dom f \<inter> dom [x\<mapsto> y] = {}"
by (metis Int_empty_left Int_insert_left dom_eq_singleton_conv inf_commute)
(* NOTE: munion updates are often over singleton sets. This weakening rule
states that's enough to show x is not in f to enable the application
of f \<union>m [x \<mapsto> y].
*)
(* Lemma: munion application *)
lemma l_munion_apply:
"dom f \<inter> dom g = {} \<Longrightarrow> (f \<union>m g) x = (if x \<in> dom g then (g x) else (f x))"
unfolding munion_def
by (simp add: l_dagger_apply)
(* Lemma: munion domain *)
lemma l_munion_dom:
"dom f \<inter> dom g = {} \<Longrightarrow> dom(f \<union>m g) = dom f \<union> dom g"
unfolding munion_def
by (simp add: l_dagger_dom)
lemma l_diff_union: "(A - B) \<union> C = (A \<union> C) - (B - C)"
by (metis Compl_Diff_eq Diff_eq Un_Int_distrib2)
lemma l_munion_ran: "dom f \<inter> dom g = {} \<Longrightarrow> ran(f \<union>m g) = ran f \<union> ran g"
apply (unfold munion_def)
apply simp
find_theorems "(_ \<dagger> _) = _"
(*apply (simp add: b_dagger_munion)*)
apply (intro set_eqI iffI)
unfolding ran_def
thm l_dagger_apply
apply (simp_all add: l_dagger_apply split_ifs)
apply metis
by (metis Int_iff all_not_in_conv domIff option.distinct(1))
(* Bridge: dagger defined through munion [ZEVES-LEMMA] *)
lemma b_dagger_munion_aux:
"dom(dom g -\<triangleleft> f) \<inter> dom g = {}"
apply (simp add: l_dom_dom_ar)
by (metis Diff_disjoint inf_commute)
lemma b_dagger_munion:
"(f \<dagger> g) = (dom g -\<triangleleft> f) \<union>m g"
find_theorems (300) "_ = (_::(_ \<Rightarrow> _))" -name:Predicate -name:Product -name:Quick -name:New -name:Record -name:Quotient
-name:Hilbert -name:Nitpick -name:Random -name:Transitive -name:Sum_Type -name:DSeq -name:Datatype -name:Enum
-name:Big -name:Code -name:Divides
thm fun_eq_iff[of "f \<dagger> g" "(dom g -\<triangleleft> f) \<union>m g"]
apply (simp add: fun_eq_iff)
apply (simp add: l_dagger_apply)
apply (cut_tac b_dagger_munion_aux[of g f]) (* TODO: How to make this more automatic? Iain, help? subgoal_tac! Try that. *)
apply (intro allI impI conjI)
apply (simp_all add: l_munion_apply)
unfolding dom_antirestr_def
by simp
lemma l_munion_assoc:
"dom f \<inter> dom g = {} \<Longrightarrow> dom g \<inter> dom h = {} \<Longrightarrow> (f \<union>m g) \<union>m h = f \<union>m (g \<union>m h)"
unfolding munion_def
apply (simp add: l_dagger_dom)
apply (intro conjI impI)
apply (metis l_dagger_assoc)
apply (simp_all add: disjoint_iff_not_equal)
apply (erule_tac [1-] bexE)
apply blast
apply blast
done
lemma l_munion_commute:
"dom f \<inter> dom g = {} \<Longrightarrow> f \<union>m g = g \<union>m f"
by (metis b_dagger_munion l_dagger_commute l_dom_ar_nothing munion_def)
lemma l_munion_subsume:
"x \<in> dom f \<Longrightarrow> the(f x) = y \<Longrightarrow> f = ({x} -\<triangleleft> f) \<union>m [x \<mapsto> y]"
apply (subst fun_eq_iff)
apply (intro allI)
apply (subgoal_tac "dom({x} -\<triangleleft> f) \<inter> dom [x \<mapsto> y] = {}")
apply (simp add: l_munion_apply)
apply (metis domD dom_antirestr_def singletonE option.sel)
by (metis Diff_disjoint Int_commute dom_eq_singleton_conv l_dom_dom_ar)
text_raw \<open> Perhaps add @{text "g \<subseteq>\<^sub>m f"} instead? \<close>
lemma l_munion_subsumeG:
"dom g \<subseteq> dom f \<Longrightarrow> \<forall>x \<in> dom g . f x = g x \<Longrightarrow> f = (dom g -\<triangleleft> f) \<union>m g"
unfolding munion_def
apply (subgoal_tac "dom (dom g -\<triangleleft> f) \<inter> dom g = {}")
apply simp
apply (subst fun_eq_iff)
apply (rule allI)
apply (simp add: l_dagger_apply)
apply (intro conjI impI)+
unfolding dom_antirestr_def
apply (simp)
apply (fold dom_antirestr_def)
by (metis Diff_disjoint inf_commute l_dom_dom_ar)
lemma l_munion_dom_ar_assoc:
"S \<subseteq> dom f \<Longrightarrow> dom f \<inter> dom g = {} \<Longrightarrow> (S -\<triangleleft> f) \<union>m g = S -\<triangleleft> (f \<union>m g)"
unfolding munion_def
apply (subgoal_tac "dom (S -\<triangleleft> f) \<inter> dom g = {}")
defer 1
apply (metis Diff_Int_distrib2 empty_Diff l_dom_dom_ar)
apply simp
apply (rule l_dagger_dom_ar_assoc)
by (metis equalityE inf_mono subset_empty)
lemma l_munion_empty_rhs:
"(f \<union>m Map.empty) = f"
unfolding munion_def
by (metis dom_empty inf_bot_right l_dagger_empty_rhs)
lemma l_munion_empty_lhs:
"(Map.empty \<union>m f) = f"
unfolding munion_def
by (metis dom_empty inf_bot_left l_dagger_empty_lhs)
lemma k_finite_munion:
"finite (dom f) \<Longrightarrow> finite(dom g) \<Longrightarrow> dom f \<inter> dom g = {} \<Longrightarrow> finite(dom(f \<union>m g))"
by (metis finite_Un l_munion_dom)
lemma l_munion_singleton_not_empty:
"x \<notin> dom f \<Longrightarrow> f \<union>m [x \<mapsto> y] \<noteq> Map.empty"
apply (cases "f = Map.empty")
apply (metis l_munion_empty_lhs map_upd_nonempty)
unfolding munion_def
apply simp
by (metis dagger_def map_add_None)
lemma l_munion_empty_iff:
"dom f \<inter> dom g = {} \<Longrightarrow> (f \<union>m g = Map.empty) \<longleftrightarrow> (f = Map.empty \<and> g = Map.empty)"
apply (rule iffI)
apply (simp only: dom_eq_empty_conv[symmetric] l_munion_dom)
apply (metis Un_empty)
by (simp add: l_munion_empty_lhs l_munion_empty_rhs)
lemma l_munion_dom_ar_singleton_subsume:
"x \<notin> dom f \<Longrightarrow> {x} -\<triangleleft> (f \<union>m [x \<mapsto> y]) = f"
apply (subst fun_eq_iff)
apply (rule allI)
unfolding dom_antirestr_def
by (auto simp: l_munion_apply)
(*
lemmX l_dom_ar_union:
"S -\<triangleleft> (f \<union>m g) = (S -\<triangleleft> f) \<union>m (S -\<triangleleft> g)"
apply (rule ext)
unfolding munion_def
apply (split split_if, intro conjI impI)+
apply (simp_all add: l_dagger_apply)
apply (intro conjI impI)
apply (insert f_dom_ar_subset_dom[of S f])
apply (insert f_dom_ar_subset_dom[of S g])
oops
*)
(* IJW: TODO: rename? *)
lemma l_munion_upd: "dom f \<inter> dom [x \<mapsto> y] = {} \<Longrightarrow> f \<union>m [x \<mapsto> y] = f(x \<mapsto>y)"
unfolding munion_def
apply simp
by (metis dagger_def map_add_empty map_add_upd)
(* IJW: TODO: Do I really need these?! *)
lemma munion_notemp_dagger: "dom f \<inter> dom g = {} \<Longrightarrow> f \<union>m g\<noteq>Map.empty \<Longrightarrow> f \<dagger> g \<noteq> Map.empty"
by (metis munion_def)
lemma dagger_notemp_munion: "dom f \<inter> dom g = {} \<Longrightarrow> f \<dagger> g\<noteq>Map.empty \<Longrightarrow> f \<union>m g \<noteq> Map.empty"
by (metis munion_def)
lemma munion_notempty_left: "dom f \<inter> dom g = {} \<Longrightarrow> f \<noteq> Map.empty \<Longrightarrow> f \<union>m g \<noteq> Map.empty"
by (metis dagger_notemp_munion dagger_notemptyL)
lemma munion_notempty_right: "dom f \<inter> dom g = {} \<Longrightarrow> g \<noteq> Map.empty \<Longrightarrow> f \<union>m g \<noteq> Map.empty"
by (metis dagger_notemp_munion dagger_notemptyR)
lemma unionm_in_dom_left: "x \<in> dom (f \<union>m g) \<Longrightarrow> (dom f \<inter> dom g) = {} \<Longrightarrow> x \<notin> dom g \<Longrightarrow> x \<in> dom f"
by (simp add: l_munion_dom)
lemma unionm_in_dom_right: "x \<in> dom (f \<union>m g) \<Longrightarrow> (dom f \<inter> dom g) = {} \<Longrightarrow> x \<notin> dom f \<Longrightarrow> x \<in> dom g"
by (simp add: l_munion_dom)
lemma unionm_notin_dom: "x \<notin> dom f \<Longrightarrow> x \<notin> dom g \<Longrightarrow> (dom f \<inter> dom g) = {} \<Longrightarrow> x \<notin> dom (f \<union>m g)"
by (metis unionm_in_dom_right)
lemmas munion_simps = k_munion_map_upd_wd l_munion_apply l_munion_dom b_dagger_munion
l_munion_subsume l_munion_subsumeG l_munion_dom_ar_assoc l_munion_empty_rhs
l_munion_empty_lhs k_finite_munion l_munion_upd munion_notemp_dagger
dagger_notemp_munion munion_notempty_left munion_notempty_right
lemmas vdm_simps = restr_simps antirestr_simps dagger_simps upd_simps munion_simps
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
subsubsection \<open> Map finiteness weakening lemmas [EXPERT] \<close>
(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)
\<comment> \<open>Need to have the lemma options, otherwise it fails somehow\<close>
lemma finite_map_upd_induct [case_names empty insert, induct set: finite]:
assumes fin: "finite (dom f)"
and empty: "P Map.empty"
and insert: "\<And>e r f. finite (dom f) \<Longrightarrow> e \<notin> dom f \<Longrightarrow> P f \<Longrightarrow> P (f(e \<mapsto> r))"
shows "P f" using fin
proof (induct "dom f" arbitrary: "f" rule:finite_induct) \<comment> \<open>arbitrary statement is a must in here, otherwise cannot prove it\<close>
case empty then have "dom f = {}" by simp \<comment> \<open>need to reverse to apply rules\<close>
then have "f = Map.empty" by simp
thus ?case by (simp add: assms(2))
next
case (insert x F)
\<comment> \<open>Show that update of the domain means an update of the map\<close>
assume domF: "insert x F = dom f" then have domFr: "dom f = insert x F" by simp
then obtain f0 where f0Def: "f0 = f |` F" by simp
with domF have domF0: "F = dom f0" by auto
with insert have "finite (dom f0)" and "x \<notin> dom f0" and "P f0" by simp_all
then have PFUpd: "P (f0(x \<mapsto> the (f x)))"
by (simp add: assms(3))
from domFr f0Def have "f = f0(x \<mapsto> the (f x))" by (auto intro: l_insertUpdSpec_aux)
with PFUpd show ?case by simp
qed
lemma finiteRan: "finite (dom f) \<Longrightarrow> finite (ran f)"
proof (induct rule:finite_map_upd_induct)
case empty thus ?case by simp
next
case (insert e r f) then have ranIns: "ran (f(e \<mapsto> r)) = insert r (ran f)" by auto
assume "finite (ran f)" then have "finite (insert r (ran f))" by (intro finite.insertI)
thus ?case apply (subst ranIns)
by simp
qed
(* IJW: TODO: classify; rename; relocate? *)
lemma l_dom_r_finite: "finite (dom f) \<Longrightarrow> finite (dom ( S \<triangleleft> f))"
apply (rule_tac B="dom f" in finite_subset)
apply (simp add: l_dom_r_dom_subseteq)
apply assumption
done
lemma dagger_finite: "finite (dom f) \<Longrightarrow> finite (dom g) \<Longrightarrow> finite (dom (f \<dagger> g))"
by (metis dagger_def dom_map_add finite_Un)
lemma finite_singleton: "finite (dom [a \<mapsto> b])"
by (metis dom_eq_singleton_conv finite.emptyI finite_insert)
lemma not_in_dom_ar: "finite (dom f) \<Longrightarrow> s \<inter> dom f = {} \<Longrightarrow> dom (s -\<triangleleft> f) = dom f"
apply (induct rule: finite_map_upd_induct)
apply (unfold dom_antirestr_def) apply simp
by (metis IntI domIff empty_iff)
(* LF: why go for induction ? *)
lemma not_in_dom_ar_2: "finite (dom f) \<Longrightarrow> s \<inter> dom f = {} \<Longrightarrow> dom (s -\<triangleleft> f) = dom f"
apply (subst set_eq_subset)
apply (rule conjI)
apply (rule_tac[!] subsetI)
apply (metis l_dom_ar_not_in_dom)
by (metis l_dom_ar_nothing)
(* ======== *)
lemma l_dom_ar_commute_quickspec:
"S -\<triangleleft> (T -\<triangleleft> f) = T -\<triangleleft> (S -\<triangleleft> f)"
by (metis l_dom_ar_accum sup_commute)
lemma l_dom_ar_same_subsume_quickspec:
"S -\<triangleleft> (S -\<triangleleft> f) = S -\<triangleleft> f"
by (metis l_dom_ar_accum sup_idem)
lemma l_map_with_range_not_dom_empty: "dom m \<noteq> {} \<Longrightarrow> ran m \<noteq> {}"
by (simp add: l_map_non_empty_ran_conv)
lemma l_map_dom_ran: "dom f = A \<Longrightarrow> x \<in> A \<Longrightarrow> f x \<noteq> None"
by blast
(* Sequential composition combinator *)
definition
seqcomp :: "('a \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a" ("((_)/ ;; (_)/, (_))" [0, 0, 10] 10)
where
[intro!]: "(P ;; Q, bst) \<equiv> let mst = P bst in (Q mst)"
lemma l_seq_comp_simp[simp]: "(P ;; Q, bst) = Q (P bst)" unfolding seqcomp_def by simp
lemma l_inv_SetElems_inv_MapTrue[simp]: "inv_SetElems inv_True S"
by (simp add: inv_True_def inv_SetElems_def)
lemma l_ranE_frule:
"e \<in> ran f \<Longrightarrow> \<exists> x . f x = Some e"
unfolding ran_def by safe
lemma l_ranE_frule':
"e \<in> ran f \<Longrightarrow> \<exists> x . e = the(f x)"
by (metis l_ranE_frule option.sel)
lemma l_inv_MapTrue:
"finite (dom m) \<Longrightarrow> inv_Map inv_True inv_True m"
unfolding inv_Map_def inv_VDMSet_def
by (simp add: finite_ran)
lemma l_invMap_domr_absorb:
"inv_Map di ri m \<Longrightarrow> inv_Map di ri (S \<triangleleft> m)"
unfolding inv_Map_def inv_VDMSet_def
by (metis (mono_tags, lifting) domIff f_in_dom_r_apply_elem f_in_relimg_ran finiteRan inv_SetElems_def l_dom_r_finite l_in_dom_dom_r)
lemma l_inv_Map_on_dom: "inv_Map inv_Dom inv_Ran m \<Longrightarrow> inv_SetElems inv_Dom (dom m)"
unfolding inv_Map_def by auto
lemma l_inv_Map_on_ran: "inv_Map inv_Dom inv_Ran m \<Longrightarrow> inv_SetElems inv_Ran (ran m)"
unfolding inv_Map_def by auto
lemma l_invMap_di_absorb:
"inv_Map di ri m \<Longrightarrow> inv_Map inv_True ri m"
by (simp add: inv_Map_def)
(*<*)end(*>*)
|
-- Only forced indices can be large.
data Img {a b} {A : Set a} {B : Set b} (f : A → B) : B → Set where
inv : ∀ x → Img f (f x)
|
/-
Copyright (c) 2021 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import topology.sheaves.sheaf_condition.pairwise_intersections
/-!
# functors between categories of sheaves
Show that the pushforward of a sheaf is a sheaf, and define
the pushforward functor from the category of C-valued sheaves
on X to that of sheaves on Y, given a continuous map between
topological spaces X and Y.
TODO: pullback for presheaves and sheaves
-/
noncomputable theory
universes v u u₁
open category_theory
open category_theory.limits
open topological_space
variables {C : Type u₁} [category.{v} C]
variables {X Y : Top.{v}} (f : X ⟶ Y)
variables ⦃ι : Type v⦄ {U : ι → opens Y}
namespace Top
namespace presheaf.sheaf_condition_pairwise_intersections
lemma map_diagram :
pairwise.diagram U ⋙ opens.map f = pairwise.diagram ((opens.map f).obj ∘ U) :=
begin
apply functor.hext,
abstract obj_eq {intro i, cases i; refl},
intros i j g, apply subsingleton.helim,
iterate 2 {rw map_diagram.obj_eq},
end
lemma map_cocone : (opens.map f).map_cocone (pairwise.cocone U)
== pairwise.cocone ((opens.map f).obj ∘ U) :=
begin
unfold functor.map_cocone cocones.functoriality, dsimp, congr,
iterate 2 {rw map_diagram, rw opens.map_supr},
apply subsingleton.helim, rw [map_diagram, opens.map_supr],
apply proof_irrel_heq,
end
theorem pushforward_sheaf_of_sheaf {F : presheaf C X}
(h : F.is_sheaf_pairwise_intersections) :
(f _* F).is_sheaf_pairwise_intersections :=
λ ι U, begin
convert h ((opens.map f).obj ∘ U) using 2,
rw ← map_diagram, refl,
change F.map_cone ((opens.map f).map_cocone _).op == _,
congr, iterate 2 {rw map_diagram}, apply map_cocone,
end
end presheaf.sheaf_condition_pairwise_intersections
namespace sheaf
open presheaf
variables [has_products.{v} C]
/--
The pushforward of a sheaf (by a continuous map) is a sheaf.
-/
theorem pushforward_sheaf_of_sheaf
{F : presheaf C X} (h : F.is_sheaf) : (f _* F).is_sheaf :=
by rw is_sheaf_iff_is_sheaf_pairwise_intersections at h ⊢;
exact sheaf_condition_pairwise_intersections.pushforward_sheaf_of_sheaf f h
/--
The pushforward functor.
-/
def pushforward (f : X ⟶ Y) : X.sheaf C ⥤ Y.sheaf C :=
{ obj := λ ℱ, ⟨f _* ℱ.1, pushforward_sheaf_of_sheaf f ℱ.2⟩,
map := λ _ _, pushforward_map f }
end sheaf
end Top
|
There exists a prime number greater than $n$. |
(* -*- mode: coq; coq-prog-args: ("-emacs" "-R" "." "Top" "-top" "min_bug_poly2") -*- *)
(* File reduced by coq-bug-finder from original input, then from 469 lines to 112 lines, then from 128 lines to 112 lines *)
(* coqc version 8.6.1 (August 2017) compiled on Aug 22 2017 10:37:48 with OCaml 4.02.3
coqtop version 8.6.1 (August 2017) *)
Axiom proof_admitted : False.
Tactic Notation "admit" := abstract case proof_admitted.
(* commenting this makes it work *)
Set Universe Polymorphism.
Inductive list (A : Type) : Type :=
| nil : list A
| cons : A -> list A -> list A.
Arguments nil {A}.
Local Open Scope list_scope.
Notation "[m: ]" := nil (format "[m: ]") : list_scope.
Inductive option A := Some : A -> option A | None.
Arguments Some {A} _.
Arguments None {A}.
Inductive eq {A : Type} (x : A) : A -> Prop := eq_refl : eq x x.
Arguments eq_refl {A} _.
Inductive goal :=
| Goal : forall {A}, A -> goal.
Inductive t : Type -> Prop :=
| ret : forall {A : Type}, A -> t A
| bind : forall {A : Type} {B : Type},
t A -> (A -> t B) -> t B
| unify {A : Type} (x y : A) : t (option (x = y))
| unify_univ (A B : Type) : t (option (A -> B))
.
Declare Scope M_scope.
Delimit Scope M_scope with MC.
Open Scope M_scope.
Notation "r '<-' t1 ';' t2" := (@bind _ _ t1 (fun r=> t2%MC))
(at level 81, right associativity, format "'[' r '<-' '[' t1 ; ']' ']' '/' t2 ") : M_scope.
Notation "t1 ';;' t2" := (bind t1 (fun _ => t2%MC))
(at level 81, right associativity, format "'[' '[' t1 ;; ']' ']' '/' t2 ") : M_scope.
Notation "t >>= f" := (bind t f) (at level 70) : M_scope.
Definition unify_cumul {A B} (x: A) (y: B) : t bool :=
of <- unify_univ A B;
match of with
| Some f =>
let fx := f x in
oeq <- unify fx y;
match oeq with Some _ => ret true | None => ret false end
| None => ret false
end.
Definition cumul_or_fail
{A B} (x: A) (y: B) : t unit :=
b <- unify_cumul x y;
ret tt.
Notation M := t.
Definition gtactic (A : Type) := goal -> M (list (A * goal)).
Notation tactic := (gtactic unit).
Fail Definition exact {A} (x:A) : tactic := fun g =>
match g with
| Goal g => cumul_or_fail x g;; ret [m:]
end.
|
program generate_ascii_table
use iso_fortran_env, only: i8 => int8
use fortran_ascii
implicit none
integer(i8) :: tables(0:12,-128:127)
integer :: i
character(len=1) :: c
character(len=40) :: fmt
! Initialize all bits to zero
tables = 0
do i = 0, 127
c = achar(i)
if (is_upper(c)) tables(0,i) = 1
if (is_lower(c)) tables(1,i) = 1
if (is_alpha(c)) tables(2,i) = 1
if (is_digit(c)) tables(3,i) = 1
if (is_hex_digit(c)) tables(4,i) = 1
if (is_octal_digit(c)) tables(5,i) = 1
if (is_white(c)) tables(6,i) = 1
if (is_printable(c)) tables(7,i) = 1
if (is_graphical(c)) tables(8,i) = 1
if (is_control(c)) tables(9,i) = 1
if (is_punctuation(c)) tables(10,i) = 1
if (is_alphanum(c)) tables(11,i) = 1
if (is_blank(c)) tables(12,i) = 1
end do
fmt = "(*(16(I1,:,',',X),/))"
write(*,*) "is_upper"
write(*,fmt) tables(0,:)
write(*,*) "is_lower"
write(*,fmt) tables(1,:)
write(*,*) "is_alpha"
write(*,fmt) tables(2,:)
write(*,*) "is_digit"
write(*,fmt) tables(3,:)
write(*,*) "is_hex_digit"
write(*,fmt) tables(4,:)
write(*,*) "is_octal_digit"
write(*,fmt) tables(5,:)
write(*,*) "is_white"
write(*,fmt) tables(6,:)
write(*,*) "is_printable"
write(*,fmt) tables(7,:)
write(*,*) "is_graphical"
write(*,fmt) tables(8,:)
write(*,*) "is_control"
write(*,fmt) tables(9,:)
write(*,*) "is_punctuation"
write(*,fmt) tables(10,:)
write(*,*) "is_alphanum"
write(*,fmt) tables(11,:)
write(*,*) "is_blank"
write(*,fmt) tables(12,:)
end program |
WASHINGTON -- With television lights glaring, 20 lawmakers will gather next week to revisit the fight that consumed Congress before Christmas over renewing a Social Security payroll tax cut and unemployment benefits.
With the House's fractious conservative wing balking until the very end, the fight made the GOP look like it was opposing the tax reduction -- which Democrats contrasted with Republican support for tax breaks for the wealthy. Most Republicans want this year's fight to end quickly so they can change the subject to their own efforts to cut taxes, federal spending and Obama administration regulations. |
constant α : Type
constant empty_set : set α
constant full_set : set α
axiom empty.branch {A : set α} : A = empty_set ∨ A ≠ empty_set
constant element : α → set α → Prop
local notation a ` ∈ ` b := element a b
reserve infix ` ∈ `: 50
-- Subset
constant subset : set α → set α → Prop
axiom subset.empty_some {A : set α} : subset empty_set A
lemma subset.not_some_empty {A : set α} (h : A ≠ empty_set) :
¬ subset A empty_set := sorry
lemma subset.empty_empty : subset empty_set empty_set := subset.empty_some
-- Inverse
constant inverse : set α → set α
axiom inverse.empty : inverse empty_set = full_set
lemma full_set.def : full_set = inverse empty_set := inverse.empty.symm
-- Intersection
constant intersect : set α → set α → set α
axiom intersect.empty {A : set α} : intersect A empty_set = empty_set
axiom intersect.full_set {A : set α} : intersect A full_set = A
axiom intersect.subset {A B : set α} (h : subset A B) : intersect A B = A
lemma intersect.empty_empty : intersect empty_set empty_set = empty_set :=
@intersect.empty empty_set
lemma intersect.full_full : intersect full_set full_set = full_set :=
@intersect.full_set full_set
lemma intersect.def {x : α} {A B : set α} : (x ∈ intersect A B) ↔ (x ∈ A ∧ x ∈ B) := sorry
-- Subtraction
constant subtract : set α → set α → set α
axiom subtract.def (A B : set α) : subtract A B = intersect A (inverse B)
-- Union
constant union : set α → set α → set α
axiom union.empty {A : set α} : union A empty_set = A
axiom union.step {A B C : set α} (h : subset C B) :
union A B = union C (union A (subtract B C))
lemma union.def {x : α} {A B : set α} : (x ∈ union A B) ↔ (x ∈ A ∨ x ∈ B) := sorry
lemma union.comm {A B : set α} : union A B = union B A := sorry
#print union.def
#print union.empty
lemma empty_union (A : set α) : union empty_set A = A :=
begin
rw union.comm,
apply union.empty,
-- give shorter proof:
-- =>> λ (A : set α), (id ((eq.refl (union empty_set A = A)).rec
-- (union.comm empty_set A))).mpr (union.empty A)
-- than rewrite tactic:
-- rw union.empty,
-- =>> λ (A : set α),
-- (id ((eq.refl (union empty_set A = A)).rec (union.comm empty_set A))).mpr
-- ((id ((eq.refl (union A empty_set = A)).rec (union.empty A))).mpr (eq.refl A))
end
constant is_empty : set α → Prop
axiom is_empty.base : is_empty empty_set
constant singleton_set : α → set α
constant set.without : set α → α → set α
axiom set.without.base (x : α) : set.without empty_set x = empty_set
-- Singleton ≈ set that contains only one element
lemma set.without.singleton (x : α) (A : set α) :
(singleton_set x).without x = empty_set := sorry
constant size_of_set : set α → ℕ
axiom size_of_set.base : size_of_set empty_set = 0
axiom size_of_set.step (x : α) (A : set α) :
element x A → size_of_set A = size_of_set (A.without x)
-- Definition of branching by assumption
constant subset_from_prop : (α → Prop) → set α → set α
axiom subset_from_prop.def (property : α → Prop) (A : set α) :
subset_from_prop (λ _, true) A =
union
(subset_from_prop property A)
(subset_from_prop (λ x : α, ¬ property x) A)
∧ subset (subset_from_prop property A) A
∧ subset (subset_from_prop (λ x : α, ¬ property x) A) A
-- lemma not_empty_imp_has_element (A : set α) :
-- A
/--
if A ≠ ∅ we have:
⊢ A ≠ ∅ → union A A = A
=> by: ∀ A : set, union A A = ∅ → A = ∅
| union A A ≠ ∅
=> by: ∀ A : set α, A ≠ ∅ → ∃ (x : α), x ∈ A
| (∃ x, x ∈ A)
...
(x ∈ union A A) ↔ (x ∈ A ∨ x ∈ A)
...
otherwise A = ∅:
⊢ union ∅ ∅ = ∅
by: union.empty: ∀ A : set, union A ∅ = A
| union ∅ ∅ = ∅
Qed.
-/
lemma union.self₁ (A : set α) : union A A = A :=
begin
sorry,
end
lemma union.self₂ (x : α) (A : set α) : element x (union A A) = element x A :=
begin
have h := @union.def x A A,
have h2 := or_self (element x A),
rw ←h2,
exact h.to_eq,
end
|
(* HCOL metaoperators *)
Require Import Util.Misc.
Require Import Helix.Util.VecSetoid.
Require Import Helix.HCOL.CarrierType.
Require Import Coq.Arith.Arith.
Require Import Coq.Program.Program. (* compose *)
Require Import Coq.Classes.Morphisms.
Require Import Coq.Classes.RelationClasses.
Require Import Coq.Relations.Relations.
Require Import Helix.Tactics.HelixTactics.
Require Import Coq.Logic.FunctionalExtensionality.
(* CoRN MathClasses *)
Require Import MathClasses.interfaces.abstract_algebra.
Require Import MathClasses.orders.minmax MathClasses.interfaces.orders.
Import VectorNotations.
Open Scope vector_scope.
Section WithCarrierA.
Context `{CAPROPS: @CarrierProperties CADEFS}.
(* --------- *)
Section THCOL_implementations.
(* Apply 2 functions to the same input returning tuple of results *)
Definition Stack {D R F: Type} (fg:(D->R)*(D->F)) (x:D) : (R*F) :=
match fg with
| (f,g) => pair (f x) (g x)
end.
(* Apply 2 functions to 2 inputs returning tuple of results *)
Definition Cross {D R E F: Type} (fg:(D->R)*(E->F)) (x:D*E) : (R*F) :=
match fg with
| (f,g) => match x with
| (x0,x1) => pair (f x0) (g x1)
end
end.
(* --- Pointwise Comparison --- *)
(* Zero/One version *)
Definition ZVLess {n}
(ab: (avector n)*(avector n)) : avector n :=
match ab with
| (a,b) => Vmap2 (Zless) a b
end.
Instance ZVLess_proper {n:nat}:
Proper ((=) ==> (=)) (@ZVLess n).
Proof.
(* solve_proper. *)
intros x y E.
unfold ZVLess.
repeat break_let.
inversion E. simpl in *.
unfold equiv, vec_Equiv.
rewrite H0, H.
reflexivity.
Qed.
End THCOL_implementations.
Section THCOL_implementation_proper.
Global Instance Cross_arg_proper
`{Equiv D,Equiv R,Equiv E,Equiv F}
`{pF: !Proper ((=) ==> (=)) (f: D -> R)}
`{pG: !Proper ((=) ==> (=)) (g: E -> F)}:
Proper ((=) ==> (=)) (Cross (f,g)).
Proof.
intros fg fg' fgE.
destruct fg, fg'.
destruct fgE as [M2 M1]. simpl in *.
split; simpl.
apply pF; assumption.
apply pG; assumption.
Qed.
Global Instance Stack_arg_proper
`{Equiv D,Equiv R,Equiv F}
`{pF: !Proper ((=) ==> (=)) (f: D -> R)}
`{pG: !Proper ((=) ==> (=)) (g: D -> F)}:
Proper ((=) ==> (=)) (Stack (f,g)).
Proof.
intros fg fg' fgE.
split; simpl.
apply pF; assumption.
apply pG; assumption.
Qed.
End THCOL_implementation_proper.
End WithCarrierA.
|
lemma fract_poly_1 [simp]: "fract_poly 1 = 1" |
import world7.level1
import world7.level9
local attribute [instance, priority 10] classical.prop_decidable
lemma contrapositive2 (P Q : Prop) : (¬ Q → ¬ P) → (P → Q) :=
begin
by_cases p : P; by_cases q : Q,
{
intros nqnp p,
exact q,
},
{
intro nqnp,
have np := nqnp q,
have pnp := (both_and P ¬ P) p np,
have q := (contra P Q) pnp,
intro p,
exact q,
},
{
intros nqnp p,
exact q,
},
{
intro nqnp,
intro yp,
have pnp := (both_and P ¬ P) yp p,
have q := (contra P Q) pnp,
exact q,
},
end |
```python
from scipy.stats import binom, poisson, norm, lognorm
import matplotlib.pyplot as plt
from iminuit import Minuit # The actual fitting tool, better than scipy's
from scipy import stats
import sympy as sy
import numpy as np
import math
import sys
sys.path.append(r'/home/saim/External_Functions')
from ExternalFunctions import Chi2Regression, BinnedLH, UnbinnedLH
from ExternalFunctions import nice_string_output, add_text_to_ax
```
```python
# Plotting stuff
plt.rcParams['font.size'] = 18
plt.style.use(['science', 'notebook', 'grid'])
pink = '#e377c2'
blue = '#1f77b4'
golden = '#ff7f0e'
green = '#2ca02c'
red = '#d62728'
purple = '#9467bd'
light_blue = '#17becf'
```
```python
r = np.random
r.seed(42)
```
```python
def chi2_eval(fitted_object, Npoints, Nparams):
Chi2_value = fitted_object.fval
Ndof = Npoints - Nparams # Number of degrees of freedom
Chi2_prob = stats.chi2.sf(Chi2_value, Ndof)
return Chi2_value, Ndof, Chi2_prob
```
```python
# Turning histogram data into x, y, and sigma_y values for all non-zero entries (not considered in Chi2 fit):
def hist_data(data, Nbins, mini, maxi):
counts, bin_edges = np.histogram(data,
bins = Nbins,
range = (mini, maxi),
density = False)
bin_centers = (bin_edges[1:] + bin_edges[:-1]) / 2
x = bin_centers[counts > 0]
y = counts[counts > 0]
sy = np.sqrt(y)
return x, y, sy
```
```python
def draw_chi2fit(Nparams, x_values, x_min, x_max, PDF,
fitted_dist, Nbins, x_bin, y_bin, sigma):
# Produce the points for drawing the fit:
x_axis = np.linspace(x_min, x_max, Nbins)
y_axis = PDF(x_axis, *fitted_dist.values[:]
)
# Produce figure with histogram (with error bars) and fit overlayed:
fig, ax = plt.subplots(figsize=(14, 6))
ax.errorbar(x_bin, y_bin, sigma, fmt = '.', color = '#1f77b4', label = 'Data')
ax.plot(x_axis, y_axis, '-', color = golden, label = 'Fit')
ax.set(xlabel = "Value",
ylabel = "Frequency",
title = "")
ax.legend(loc = 'lower right',
fontsize=14);
# Fitting results
chi2_value = fitted_dist.fval
Ndof = Nbins - fitted_dist.nfit
chi2_prob = stats.chi2.sf(chi2_value, Ndof)
# Define figure text
d = {'Entries': len(x_values),
'Chi2': chi2_value,
'ndf': Ndof,
'Prob': chi2_prob,
}
for name in fitted_dist.parameters:
d[name] = [fitted_dist.values[name], fitted_dist.errors[name]]
text = nice_string_output(d, extra_spacing = 2, decimals = 3)
add_text_to_ax(0.69, 0.95, text, ax, fontsize = 15)
fig.tight_layout()
```
## Gaussian chi2 fit
```python
Npointz = 10000 # Number of random points produced
x_all = r.normal(loc = 0.2,
scale = 1.1,
size = Npointz)
Nbinz = 100
xmin, xmax = np.min(x_all), np.max(x_all)
binwidth_gauss = np.ptp(x_all) / Nbinz
#binwidth = (xmax - xmin) / Nbins
# Fitting function which is NOT normalised but has normalisation constants "N" in,
# and includes the bin width:
def func_gauss_norm(x, N, mu, sigma) :
norm = binwidth_gauss * N / np.sqrt(2.0 * np.pi) / sigma
z = (x - mu) / sigma
return norm * np.exp(-0.5 * (z**2))
def func_gaussian_alt(x, N, mu, sigma) :
return binwidth_gauss * N * norm.pdf(x, mu, sigma)
```
```python
x1, y1, sy1 = hist_data(x_all, Nbinz, xmin, xmax)
```
```python
# Fitting
chi2_gaussian = Chi2Regression(func_gauss_norm, x1, y1, sy1) # Fitting object
chi2_gaussian.errordef = Minuit.LEAST_SQUARES
minuit_gaussian = Minuit(chi2_gaussian,
N = Npointz,
mu = 0,
sigma = 0.05)
minuit_gaussian.migrad() # Perform the actual fit
```
<table>
<tr>
<td colspan="2" style="text-align:left" title="Minimum value of function"> FCN = 75.35 </td>
<td colspan="3" style="text-align:center" title="No. of function evaluations in last call and total number"> Nfcn = 196 (196 total) </td>
</tr>
<tr>
<td colspan="2" style="text-align:left" title="Estimated distance to minimum and goal"> EDM = 2.32e-07 (Goal: 0.0002) </td>
<td colspan="3" style="text-align:center" title="No. of gradient evaluations in last call and total number"> </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Minimum </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Parameters </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> No Parameters at limit </td>
</tr>
<tr>
<td colspan="2" style="text-align:center;background-color:#92CCA6;color:black"> Below EDM threshold (goal x 10) </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> Below call limit </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Hesse ok </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Has Covariance </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix accurate?"> Accurate </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix positive definite?"> Pos. def. </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Was positive definiteness enforced by Minuit?"> Not forced </td>
</tr>
</table><table>
<tr>
<td></td>
<th title="Variable name"> Name </th>
<th title="Value of parameter"> Value </th>
<th title="Hesse error"> Hesse Error </th>
<th title="Minos lower error"> Minos Error- </th>
<th title="Minos upper error"> Minos Error+ </th>
<th title="Lower limit of the parameter"> Limit- </th>
<th title="Upper limit of the parameter"> Limit+ </th>
<th title="Is the parameter fixed in the fit"> Fixed </th>
</tr>
<tr>
<th> 0 </th>
<td> N </td>
<td> 9.93e3 </td>
<td> 0.10e3 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 1 </th>
<td> mu </td>
<td> 0.199 </td>
<td> 0.011 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 2 </th>
<td> sigma </td>
<td> 1.094 </td>
<td> 0.008 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
```python
draw_chi2fit(3, x_all, xmin, xmax, func_gauss_norm,
minuit_gaussian, Nbinz, x1, y1, sy1)
```
## Linear chi2 fit
```python
# Fitting function
def func_linear(x, alpha0, alpha1):
return alpha0 + alpha1*x
```
```python
# Parameters
alpha0 = 3.6
alpha1 = 0.3
sigma_y = 0.5
```
```python
lin_Npoints = 50 # Number of random points produced
lin_x = np.arange(lin_Npoints) # Generate points in array
#exLin = np.zeros_like(lin_x)
lin_y = alpha0 + alpha1 * lin_x + r.normal(0, sigma_y, lin_Npoints) # linear function + gaussian errors
error_lin_y = sigma_y * np.ones_like(lin_x)
```
```python
# Fitting
chi2_linear = Chi2Regression(func_linear, lin_x, lin_y, error_lin_y) # Fitting object
chi2_linear.errordef = Minuit.LEAST_SQUARES
# Give fitting function, its parameters their starting fitting values
minuit_linear = Minuit(chi2_linear,
alpha0 = 2,
alpha1 = 0.1)
minuit_linear.migrad() # perform the actual fit
```
<table>
<tr>
<td colspan="2" style="text-align:left" title="Minimum value of function"> FCN = 37.08 </td>
<td colspan="3" style="text-align:center" title="No. of function evaluations in last call and total number"> Nfcn = 32 (32 total) </td>
</tr>
<tr>
<td colspan="2" style="text-align:left" title="Estimated distance to minimum and goal"> EDM = 1.82e-21 (Goal: 0.0002) </td>
<td colspan="3" style="text-align:center" title="No. of gradient evaluations in last call and total number"> </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Minimum </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Parameters </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> No Parameters at limit </td>
</tr>
<tr>
<td colspan="2" style="text-align:center;background-color:#92CCA6;color:black"> Below EDM threshold (goal x 10) </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> Below call limit </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Hesse ok </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Has Covariance </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix accurate?"> Accurate </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix positive definite?"> Pos. def. </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Was positive definiteness enforced by Minuit?"> Not forced </td>
</tr>
</table><table>
<tr>
<td></td>
<th title="Variable name"> Name </th>
<th title="Value of parameter"> Value </th>
<th title="Hesse error"> Hesse Error </th>
<th title="Minos lower error"> Minos Error- </th>
<th title="Minos upper error"> Minos Error+ </th>
<th title="Lower limit of the parameter"> Limit- </th>
<th title="Upper limit of the parameter"> Limit+ </th>
<th title="Is the parameter fixed in the fit"> Fixed </th>
</tr>
<tr>
<th> 0 </th>
<td> alpha0 </td>
<td> 3.63 </td>
<td> 0.14 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 1 </th>
<td> alpha1 </td>
<td> 0.301 </td>
<td> 0.005 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
```python
chi2_linear, Ndof_linear, pval_linear = chi2_eval(minuit_linear, len(lin_x), 2)
```
```python
figLin, axLin = plt.subplots(figsize=(16, 8))
axLin.errorbar(lin_x,
lin_y,
error_lin_y,
fmt = 'ro',
ecolor = 'k',
elinewidth = 1,
capsize = 1,
capthick = 1)
axLin.plot(lin_x,
func_linear(lin_x, *minuit_linear.values[:]),
'-r',
color = blue)
d = {'Intercept':[minuit_linear.values['alpha0'], minuit_linear.errors['alpha0']],
'Slope': [minuit_linear.values['alpha1'], minuit_linear.errors['alpha1']],
'Chi2': chi2_linear,
'ndf': Ndof_linear,
'Prob': pval_linear,
}
text = nice_string_output(d, extra_spacing=2, decimals=3)
add_text_to_ax(0.04, 0.95, text, axLin, fontsize=20)
figLin.tight_layout()
```
## Monte Carlo Simulation and Fitting
```python
N_points = 10000
N_bins = 100
# inverse integrated function added to itself 4 times
exp_inv = sum(-0.8*np.log(r.uniform(size = N_points)) for i in range(4))
# Function given in problem statement which is summed 4 times
def exp_func(x):
return sum(r.exponential(0.8, N_points) for i in range(4))
xmin_exp = 0
xmax_exp = 20
x_axis_exp = np.linspace(start = xmin_exp,
stop = xmax_exp,
num = 10000)
y_axis_exp = exp_func(x_axis_exp)
```
```python
# Init plot object
fig, ax = plt.subplots(figsize=(15, 9))
# Plot generated data
ax.hist(exp_inv,
bins = N_bins,
range = (xmin_exp, xmax_exp),
color = blue,
histtype = 'step'
)
# Plot labels
ax.set(xlabel = "x - following f(x)",
ylabel = "Frequency",
xlim = (xmin_exp -1.0 , xmax_exp+1.0))
# Define figure text
textstr = '\n'.join((
r'$\mathrm{Entries}=%.2f$' % (len(exp_inv), ),
r'$\mathrm{Mean}=%.2f$' % (exp_inv.mean(), ),
r'$\mathrm{Std}=%.2f$' % (exp_inv.std(ddof=1), )))
# Plot figure text
props = dict(boxstyle = 'round',
facecolor = 'white',
edgecolor = 'black',
alpha=0.5)
# place a text box in upper left in axes coords
ax.text(0.86,
0.95,
textstr,
transform = ax.transAxes,
fontsize = 14,
verticalalignment='top',
bbox = props)
fig.tight_layout()
```
```python
# Binning the data
x3, y3, sigma_y3 = hist_data(exp_inv, 100, 0, 20)
```
```python
# Fitting
chi2_MC_Gauss = Chi2Regression(func_gauss_norm, x3, y3, sigma_y3) # Fitting object
chi2_MC_Gauss.errordef = Minuit.LEAST_SQUARES
minuit_MC_Gauss = Minuit(chi2_MC_Gauss,
N = N_points,
mu = 3,
sigma = 1.6)
minuit_MC_Gauss.migrad() # Perform the actual fit
```
<table>
<tr>
<td colspan="2" style="text-align:left" title="Minimum value of function"> FCN = 1148 </td>
<td colspan="3" style="text-align:center" title="No. of function evaluations in last call and total number"> Nfcn = 65 (65 total) </td>
</tr>
<tr>
<td colspan="2" style="text-align:left" title="Estimated distance to minimum and goal"> EDM = 2.98e-05 (Goal: 0.0002) </td>
<td colspan="3" style="text-align:center" title="No. of gradient evaluations in last call and total number"> </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Minimum </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Parameters </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> No Parameters at limit </td>
</tr>
<tr>
<td colspan="2" style="text-align:center;background-color:#92CCA6;color:black"> Below EDM threshold (goal x 10) </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> Below call limit </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Hesse ok </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Has Covariance </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix accurate?"> Accurate </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix positive definite?"> Pos. def. </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Was positive definiteness enforced by Minuit?"> Not forced </td>
</tr>
</table><table>
<tr>
<td></td>
<th title="Variable name"> Name </th>
<th title="Value of parameter"> Value </th>
<th title="Hesse error"> Hesse Error </th>
<th title="Minos lower error"> Minos Error- </th>
<th title="Minos upper error"> Minos Error+ </th>
<th title="Lower limit of the parameter"> Limit- </th>
<th title="Upper limit of the parameter"> Limit+ </th>
<th title="Is the parameter fixed in the fit"> Fixed </th>
</tr>
<tr>
<th> 0 </th>
<td> N </td>
<td> 20.82e3 </td>
<td> 0.22e3 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 1 </th>
<td> mu </td>
<td> 3.126 </td>
<td> 0.019 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 2 </th>
<td> sigma </td>
<td> 1.349 </td>
<td> 0.015 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
```python
draw_chi2fit(3, exp_inv, xmin_exp, xmax_exp,
func_gaussian_alt, minuit_MC_Gauss, N_bins, x3, y3, sigma_y3)
```
## Exponential Fit
```python
N_exp = 10000 # Number of random points produced
x_exp = r.exponential(np.e, N_exp)
exp_bins = 100
binwidth_exp = np.ptp(x_exp) / exp_bins
exp_min, exp_max = np.min(x_exp), np.max(x_exp)
```
```python
def exp_pdf(x, N, tau):
return N * binwidth_exp / tau * np.exp(-x/tau)
```
```python
# Binning data
x4, y4, sy4 = hist_data(x_exp, exp_bins, exp_min, exp_max)
```
```python
# Fitting
chi2_exp = Chi2Regression(exp_pdf, x4, y4, sy4) # Fitting object
chi2_exp.errordef = Minuit.LEAST_SQUARES
minuit_exp = Minuit(chi2_exp,
N = 10000,
tau = 2)
minuit_exp.migrad() # Perform the actual fit
```
<table>
<tr>
<td colspan="2" style="text-align:left" title="Minimum value of function"> FCN = 85.13 </td>
<td colspan="3" style="text-align:center" title="No. of function evaluations in last call and total number"> Nfcn = 38 (38 total) </td>
</tr>
<tr>
<td colspan="2" style="text-align:left" title="Estimated distance to minimum and goal"> EDM = 7.49e-07 (Goal: 0.0002) </td>
<td colspan="3" style="text-align:center" title="No. of gradient evaluations in last call and total number"> </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Minimum </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Parameters </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> No Parameters at limit </td>
</tr>
<tr>
<td colspan="2" style="text-align:center;background-color:#92CCA6;color:black"> Below EDM threshold (goal x 10) </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> Below call limit </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Hesse ok </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Has Covariance </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix accurate?"> Accurate </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix positive definite?"> Pos. def. </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Was positive definiteness enforced by Minuit?"> Not forced </td>
</tr>
</table><table>
<tr>
<td></td>
<th title="Variable name"> Name </th>
<th title="Value of parameter"> Value </th>
<th title="Hesse error"> Hesse Error </th>
<th title="Minos lower error"> Minos Error- </th>
<th title="Minos upper error"> Minos Error+ </th>
<th title="Lower limit of the parameter"> Limit- </th>
<th title="Upper limit of the parameter"> Limit+ </th>
<th title="Is the parameter fixed in the fit"> Fixed </th>
</tr>
<tr>
<th> 0 </th>
<td> N </td>
<td> 9.93e3 </td>
<td> 0.10e3 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 1 </th>
<td> tau </td>
<td> 2.693 </td>
<td> 0.027 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
```python
draw_chi2fit(2, x_exp, exp_min, exp_max, exp_pdf,
minuit_exp, exp_bins, x4, y4, sy4)
```
## Power Law Fit
```python
N_pow = 10000 # Number of random points produced
x_pow = r.power(a = 15,
size = N_pow)
pow_bins = 100
binwidth_pow = np.ptp(x_pow) / pow_bins
pow_min, pow_max = np.min(x_pow), np.max(x_pow)
```
```python
def power_pdf(x, N, a, b):
return N * binwidth_pow / a * np.power(x, b)
```
```python
# Binning data
x5, y5, sy5 = hist_data(x_pow, pow_bins, pow_min, pow_max)
```
```python
# Fitting
chi2_pow = Chi2Regression(power_pdf, x5, y5, sy5) # Fitting object
chi2_pow.errordef = Minuit.LEAST_SQUARES
minuit_pow = Minuit(chi2_pow,
N = 10000,
a = 4,
b = 1)
minuit_pow.migrad() # Perform the actual fit
```
<table>
<tr>
<td colspan="2" style="text-align:left" title="Minimum value of function"> FCN = 59.57 </td>
<td colspan="3" style="text-align:center" title="No. of function evaluations in last call and total number"> Nfcn = 129 (129 total) </td>
</tr>
<tr>
<td colspan="2" style="text-align:left" title="Estimated distance to minimum and goal"> EDM = 1.17e-05 (Goal: 0.0002) </td>
<td colspan="3" style="text-align:center" title="No. of gradient evaluations in last call and total number"> </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Minimum </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Valid Parameters </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> No Parameters at limit </td>
</tr>
<tr>
<td colspan="2" style="text-align:center;background-color:#92CCA6;color:black"> Below EDM threshold (goal x 10) </td>
<td colspan="3" style="text-align:center;background-color:#92CCA6;color:black"> Below call limit </td>
</tr>
<tr>
<td style="text-align:center;background-color:#92CCA6;color:black"> Hesse ok </td>
<td style="text-align:center;background-color:#92CCA6;color:black"> Has Covariance </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix accurate?"> Accurate </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Is covariance matrix positive definite?"> Pos. def. </td>
<td style="text-align:center;background-color:#92CCA6;color:black" title="Was positive definiteness enforced by Minuit?"> Not forced </td>
</tr>
</table><table>
<tr>
<td></td>
<th title="Variable name"> Name </th>
<th title="Value of parameter"> Value </th>
<th title="Hesse error"> Hesse Error </th>
<th title="Minos lower error"> Minos Error- </th>
<th title="Minos upper error"> Minos Error+ </th>
<th title="Lower limit of the parameter"> Limit- </th>
<th title="Upper limit of the parameter"> Limit+ </th>
<th title="Is the parameter fixed in the fit"> Fixed </th>
</tr>
<tr>
<th> 0 </th>
<td> N </td>
<td> 0.11e6 </td>
<td> 0.12e6 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 1 </th>
<td> a </td>
<td> 0.7 </td>
<td> 0.8 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> 2 </th>
<td> b </td>
<td> 14.24 </td>
<td> 0.16 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
```python
draw_chi2fit(3, x_pow, pow_min, pow_max, power_pdf,
minuit_pow, pow_bins, x5, y5, sy5)
```
```python
stats.anderson(x_exp, dist='expon')
```
AndersonResult(statistic=0.8263378287992964, critical_values=array([0.922, 1.078, 1.341, 1.606, 1.957]), significance_level=array([15. , 10. , 5. , 2.5, 1. ]))
```python
# Null is accepted at all significance levels as test statistic is lower than critical values
```
|
HONG KONG: Asian markets gained on Monday, following a Wall Street rally on upbeat jobs data, while the dollar and euro held on to healthy gains made against the yen at the end of last week. Tokyo climbed 0.36 percent to a 33-month high, Hong Kong added 0.68 percent, Shanghai rose 0.50 percent, Seoul advanced 0.20 percent and Sydney was flat.
US traders sent the Dow to a more than five-year high Friday on the back of the latest jobs data.
The labour department report showed employers added 157,000 jobs in January, fewer than expected, and the jobless rate inched up to 7.9 percent.
However, revised data for all of 2012 showed net job growth at an average of 181,000 a month, up from a prior estimate of 153,000.
The Dow rallied 1.08 percent to 14,009.79, above 14,000 points for the first time since October 2007. The index is just shy of the record high 14,164.53 seen on October 9, 2007.
The broad-based S&P 500 added 1.01 percent and the Nasdaq jumped 1.18 percent.
"The US is basking in good news at the moment because the debt negotiations have kicked the can down the road," he added, referring to a delay until May to negotiations on raising the country's debt ceiling.
And UniCredit's Harm Bandholz in the United States said the updates to the 2012 data "highlight even more how remarkably resilient the US labor market has been over the last two quarters".
The jobs figures sent the dollar and euro higher against the yen on Friday, and the units edged down slightly on profit-taking on Monday in Tokyo forex trade.
The dollar bought 92.76 yen against 92.80 yen in New York late Friday, while the euro sat at 126.35 yen and $1.3624, compared with 126.60 yen and $1.3637.
Oil prices fell, with New York's main contract, light sweet crude for delivery in March dropping 27 cents to $97.50 a barrel and Brent North Sea crude for March delivery shedding 30 cents to $116.46. |
Formal statement is: lemma homeomorphism_empty [simp]: "homeomorphism {} {} f g" Informal statement is: The identity map is a homeomorphism from the empty set to itself. |
lemmas tendsto_mult_zero = bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult] |
Require Import Arith.
Require Import "unfold_tactic".
Fixpoint trav (P : nat -> Prop)
(b : P 0)
(f : forall k, P k -> P (S k))
(n : nat) :=
match n return P n with
| 0 => b
| S n' => f n' (trav P b f n')
end.
Check trav.
Check Prop.
Definition specification_of_foo (foo : nat -> nat) :=
forall n : nat,
foo (2 * n) = n.
Theorem there_is_only_one_foo :
forall f g : nat -> nat,
specification_of_foo f ->
specification_of_foo g ->
forall x : nat,
f (x) = g (x).
Proof.
intros f g.
unfold specification_of_foo.
intros Hf Hg.
intro x.
rewrite -> Hf.
rewrite -> Hg.
reflexivity.
Qed.
Lemma unfold_add_v1_bc :
forall j : nat,
plus 0 j = j.
(* left-hand side in the base case
=
the corresponding conditional branch *)
Proof.
unfold_tactic plus.
Qed.
Lemma unfold_add_v1_ic :
forall i' j : nat,
plus (S i') j = S (plus i' j).
(* left-hand side in the inductive case
=
the corresponding conditional branch *)
Proof.
unfold_tactic plus.
Qed.
(*
Lemma unfold_add_v2_ic :
forall i' j : nat,
plus (S i') j = plus i' (S j).
(* left-hand side in the inductive case
=
the corresponding conditional branch *)
Proof.
intros i' j.
rewrite -> (unfold_add_v1_ic i' j).
rewrite -> (plus_comm i' (S j)).
rewrite -> (unfold_add_v1_ic j i').
rewrite -> (plus_comm j i').
reflexivity.
Qed.
*)
(* A useful lemma: *)
(*
Proposition add_v2_ic_right :
forall i j : nat,
plus i (S j) = S (plus i j).
Proof.
intro i.
induction i as [ | i' IHi'].
intro j.
rewrite -> unfold_add_v1_bc.
rewrite -> unfold_add_v1_bc.
reflexivity.
intro j.
rewrite -> unfold_add_v2_ic.
rewrite -> unfold_add_v2_ic.
rewrite -> (IHi' (S j)).
reflexivity.
Qed.
*)
Proposition plus_1_S :
forall n : nat,
S n = plus 1 n.
Proof.
intro n.
induction n as [ | n' IHn'].
rewrite -> (plus_0_r 1).
reflexivity.
rewrite -> (unfold_add_v1_ic).
rewrite -> (plus_0_l (S n')).
reflexivity.
Qed.
Fixpoint fac (x : nat) :=
match x with
| 0 => 1
| S x' => mult (S x') (fac x')
end.
Definition specification_of_the_mystery_function_12 (f : nat -> nat * nat) :=
(f 0 = (0, 1))
/\
(forall n' : nat,
f (S n') = let (x, y) := f n'
in (S x, y * S x)).
Definition fac_co_help (x : nat) : nat * nat :=
(x, fac x).
Compute(fac_co_help 3).
Lemma negb_negb_b_equals_b :
forall b : bool,
negb (negb b) = b.
Proof.
intro b.
case b.
unfold negb.
reflexivity.
unfold negb.
reflexivity.
Qed.
|
module Data.MyPolynomial.Print
where
import Data.MyPolynomial.Type
import Data.Complex (realPart, imagPart, Complex)
import Data.List (sort)
import Data.IntMap.Lazy (lookupLT, lookupGE, IntMap)
-- `procelain' functions are intended for canonical printing :
-- i.e. Show instances, i.e. serialization, i.e. Read reciprocal
-- `pretty' functions are intended for pretty printing only :
-- i.e. absolutly no consistent Read <=> Show reciprocity.
-- `prints' functions are general purpose printing functions;
-- they either use `pretty' or `porcelain' to generate output.
-- The 3rd person-like terminal 's' is a general Haskell convention
-- for functions using a provided interface to do a specific job.
-- S suffixed functions return a String difference list (ShowS)
-- for efficient arbitrary concatenation.
-- M suffixed functions take a polynomial represented by
-- an IntMap Float instance.
---------------------------------------------------------------------------
---- Abstract printers
---------------------------------------------------------------------------
printsPolynomialS :: (Monomial -> ShowS) -> Polynomial -> ShowS
printsPolynomialS _ [] = ('0':)
printsPolynomialS pfS (mn:[]) = pfS mn
printsPolynomialS pfS (m1:(m2@(c2 :*^: p2)):ms) = pfS m1 . signBridge . next
where
signBridge
| c2 < 0 = (" - " ++)
| otherwise = (" + " ++)
next
| c2 < 0 = printsPolynomialS pfS (((-c2) :*^: p2):ms)
| otherwise = printsPolynomialS pfS (m2:ms)
printsPolynomialSM :: (Polynomial -> ShowS) -> IntMap Float -> ShowS
printsPolynomialSM pfS mmap = ( pfS . sort ) $ consUp (smallest 0 mmap) mmap ([]++) []
where
smallest k map = case lookupLT k map of { Nothing -> k; Just (k, _) -> smallest k map; }
consUp k map dl = case lookupGE k map of Nothing -> dl
Just (kn, v) -> consUp (kn + 1) map (((v :*^: kn):) . dl)
printsEquationS :: (Polynomial -> ShowS) -> Equation -> ShowS
printsEquationS pfS (Eq (l, r)) = memb l . showString " = " . memb r
where
memb [] = ('0':)
memb p = pfS p
---------------------------------------------------------------------------
---- Canonical printing ( Read <=> Show )
---------------------------------------------------------------------------
porcelainMonomialS :: Monomial -> ShowS
porcelainMonomialS (c :*^: p) = shows c . showString " * X^" . shows p
porcelainPolynomialS :: Polynomial -> ShowS
porcelainPolynomialS = printsPolynomialS porcelainMonomialS
porcelainEquationS :: Equation -> ShowS
porcelainEquationS = printsEquationS porcelainPolynomialS
porcelainPolynomialSM :: IntMap Float -> ShowS
porcelainPolynomialSM = printsPolynomialSM porcelainPolynomialS
---------------------------------------------------------------------------
---- Pretty printing
---------------------------------------------------------------------------
prettyMonomialS :: Monomial -> ShowS
prettyMonomialS (0 :*^: _) = showString ""
prettyMonomialS (c :*^: 0) = shows c
prettyMonomialS (c :*^: 1) = shows c . showString " X"
prettyMonomialS (c :*^: p) = prettyMonomialS (c :*^: 1) . ('^':) . shows p
prettyMonomial :: Monomial -> String
prettyMonomial mn = prettyMonomialS mn ""
prettyPolynomialS :: Polynomial -> ShowS
prettyPolynomialS = ( printsPolynomialS prettyMonomialS ) . purgeHollow
where purgeHollow = filter ( \(c :*^: _) -> c /= 0 )
prettyPolynomial :: Polynomial -> String
prettyPolynomial p = prettyPolynomialS p ""
prettyPolynomialSM :: IntMap Float -> ShowS
prettyPolynomialSM = printsPolynomialSM prettyPolynomialS
prettyPolynomialM :: IntMap Float -> String
prettyPolynomialM m = prettyPolynomialSM m []
prettyEquationS :: Equation -> ShowS
prettyEquationS = printsEquationS (printsPolynomialS porcelainMonomialS)
prettyEquation :: Equation -> String
prettyEquation eq = prettyEquationS eq []
prettyComplexS :: (Ord c, Num c, Show c, RealFloat c) => Complex c -> ShowS
prettyComplexS c = shows a . img
where
a = realPart c
img
| b < 0 = (" - " ++) . shows (-b) . ('i':)
| b > 0 = (" + " ++) . shows b . ('i':)
| b == 0 = showString ""
where
b = imagPart c
prettyComplex :: (Ord c, Num c, Show c, RealFloat c) => Complex c -> String
prettyComplex c = prettyComplexS c ""
---------------------------------------------------------------------------
---- Show instances
---------------------------------------------------------------------------
instance Show Monomial where
showsPrec _ = porcelainMonomialS
showList = porcelainPolynomialS
instance Show Equation where
showsPrec _ = porcelainEquationS
|
[STATEMENT]
lemma Cnext_solve_kills:
\<open>(\<C>\<^sub>n\<^sub>e\<^sub>x\<^sub>t (\<Gamma>, n \<turnstile> ((K\<^sub>1 kills K\<^sub>2) # \<Psi>) \<triangleright> \<Phi>))
\<supseteq> { ((K\<^sub>1 \<not>\<Up> n) # \<Gamma>), n \<turnstile> \<Psi> \<triangleright> ((K\<^sub>1 kills K\<^sub>2) # \<Phi>),
((K\<^sub>1 \<Up> n) # (K\<^sub>2 \<not>\<Up> \<ge> n) # \<Gamma>), n \<turnstile> \<Psi> \<triangleright> ((K\<^sub>1 kills K\<^sub>2) # \<Phi>) }\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. {K\<^sub>1 \<not>\<Up> n # \<Gamma>, n \<turnstile> \<Psi> \<triangleright> (K\<^sub>1 kills K\<^sub>2) # \<Phi>, K\<^sub>1 \<Up> n # K\<^sub>2 \<not>\<Up> \<ge> n # \<Gamma>, n \<turnstile> \<Psi> \<triangleright> (K\<^sub>1 kills K\<^sub>2) # \<Phi>} \<subseteq> \<C>\<^sub>n\<^sub>e\<^sub>x\<^sub>t \<Gamma>, n \<turnstile> (K\<^sub>1 kills K\<^sub>2) # \<Psi> \<triangleright> \<Phi>
[PROOF STEP]
by (simp add: operational_semantics_step.simps operational_semantics_elim.kills_e1
operational_semantics_elim.kills_e2) |
[STATEMENT]
lemma BasicRuleTC:
assumes "p \<subseteq> {s. f s \<in> q}"
shows "ValidTC p (Basic f) a q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ValidTC p (Basic f) a q
[PROOF STEP]
by (metis assms Ball_Collect Sem.intros(1) ValidTC_def) |
//=======================================================================
// Copyright (c) 2015
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
/**
* @file serialization.hpp
* @brief
* @author Tomasz Strozak
* @version 1.0
* @date 2015-06-23
*/
#ifndef PAAL_SERIALIZATION_HPP
#define PAAL_SERIALIZATION_HPP
#include "test_utils/get_test_dir.hpp"
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
template <typename Model>
void serialize_test(Model const &model, std::string const &filename) {
auto fname = paal::system::get_temp_file_path(filename);
{
std::ofstream ofs(fname);
boost::archive::binary_oarchive oa(ofs);
oa << model;
}
Model model_test;
std::ifstream ifs(fname);
boost::archive::binary_iarchive ia(ifs);
ia >> model_test;
BOOST_CHECK(model == model_test);
paal::system::remove_tmp_path(fname);
}
#endif // PAAL_SERIALIZATION_HPP
|
theory Proof_1_2
imports HandDryer VCTheoryLemmas Extra
begin
theorem proof_1_2:
"VC2 inv1 s0 hands_value"
apply(simp only: VC2_def inv1_def R1_def dryer_def)
apply(rule impI; rule conjI)
proof -
assume VC: "((toEnvP s0 \<and>
(\<forall>s1 s2.
substate s1 s2 \<and>
substate s2 s0 \<and>
toEnvP s1 \<and>
toEnvP s2 \<and>
toEnvNum s1 s2 = hands \<and>
getVarBool s1 hands = OFF \<and>
getVarBool s1 (Suc (Suc 0)) = OFF \<and>
getVarBool s2 hands = ON \<longrightarrow>
(\<exists>s4. toEnvP s4 \<and>
substate s2 s4 \<and>
substate s4 s0 \<and>
toEnvNum s2 s4 \<le> hands \<and>
getVarBool s4 (Suc (Suc 0)) = ON \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow>
getVarBool s3 hands = ON)))) \<and>
extraInv s0) \<and>
env (setVarAny s0 hands_value) hands_value \<and>
getPstate (setVarAny s0 hands_value) Ctrl =
waiting \<and>
getVarBool (setVarAny s0 hands_value) hands =
ON"
show " toEnvP
(toEnv
(setPstate
(setVarBool (setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
(\<forall>s1 s2.
substate s1 s2 \<and>
substate s2
(toEnv
(setPstate
(setVarBool (setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
toEnvP s1 \<and>
toEnvP s2 \<and>
toEnvNum s1 s2 = hands \<and>
getVarBool s1 hands = OFF \<and>
getVarBool s1 (Suc (Suc 0)) = OFF \<and>
getVarBool s2 hands = ON \<longrightarrow>
(\<exists>s4. toEnvP s4 \<and>
substate s2 s4 \<and>
substate s4
(toEnv
(setPstate
(setVarBool
(setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
toEnvNum s2 s4 \<le> hands \<and>
getVarBool s4 (Suc (Suc 0)) = ON \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s4 \<and>
s3 \<noteq> s4 \<longrightarrow>
getVarBool s3 hands = ON)))"
apply(rule conjI)
apply(simp)
proof(rule allI; rule allI; rule impI)
fix s1 s2
assume req_prems: " substate s1 s2 \<and>
substate s2
(toEnv
(setPstate
(setVarBool (setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
toEnvP s1 \<and>
toEnvP s2 \<and>
toEnvNum s1 s2 = hands \<and>
getVarBool s1 hands = OFF \<and>
getVarBool s1 (Suc (Suc 0)) = OFF \<and>
getVarBool s2 hands = ON "
show " \<exists>s4. toEnvP s4 \<and>
substate s2 s4 \<and>
substate s4
(toEnv
(setPstate
(setVarBool
(setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
toEnvNum s2 s4 \<le> hands \<and>
getVarBool s4 (Suc (Suc 0)) = ON \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s4 \<and>
s3 \<noteq> s4 \<longrightarrow>
getVarBool s3 hands = ON)"
proof cases
assume 1: "s2 = (toEnv
(setPstate
(setVarBool
(setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying))"
have " (toEnvP s2 \<and>
substate s2 s2 \<and>
substate s2
(toEnv
(setPstate
(setVarBool (setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
toEnvNum s2 s2 \<le> hands \<and>
getVarBool s2 (Suc (Suc 0)) = ON) \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s2 \<and>
s3 \<noteq> s2 \<longrightarrow>
getVarBool s3 hands = ON)"
proof
from 1 show "toEnvP s2 \<and>
substate s2 s2 \<and>
substate s2
(toEnv
(setPstate
(setVarBool (setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
toEnvNum s2 s2 \<le> hands \<and>
getVarBool s2 (Suc (Suc 0)) = ON" by auto
next
from substate_asym show " \<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s2 \<and> s3 \<noteq> s2 \<longrightarrow>
getVarBool s3 hands = ON"
by auto
qed
thus ?thesis by blast
next
assume 1: "s2 \<noteq> (toEnv
(setPstate
(setVarBool
(setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying))"
with req_prems have 2: "substate s2 s0"
by (simp split: if_splits)
from VC req_prems 2 obtain "\<exists>s4. toEnvP s4 \<and>
substate s2 s4 \<and>
substate s4 s0 \<and>
toEnvNum s2 s4 \<le> hands \<and>
getVarBool s4 (Suc (Suc 0)) = ON \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow>
getVarBool s3 hands = ON)"by auto
then obtain s4 where 3: "toEnvP s4 \<and>
substate s2 s4 \<and>
substate s4 s0 \<and>
toEnvNum s2 s4 \<le> hands \<and>
getVarBool s4 (Suc (Suc 0)) = ON \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow>
getVarBool s3 hands = ON)" ..
have "toEnvP s4 \<and>
substate s2 s4 \<and>
substate s4
(toEnv
(setPstate
(setVarBool (setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying)) \<and>
toEnvNum s2 s4 \<le> hands \<and>
getVarBool s4 (Suc (Suc 0)) = ON \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow>
getVarBool s3 hands = ON)"
using 3 by auto
thus ?thesis ..
qed
qed
next
assume VC: "((toEnvP s0 \<and>
(\<forall>s1 s2.
substate s1 s2 \<and>
substate s2 s0 \<and>
toEnvP s1 \<and>
toEnvP s2 \<and>
toEnvNum s1 s2 = hands \<and>
getVarBool s1 hands = OFF \<and>
getVarBool s1 (Suc (Suc 0)) = OFF \<and>
getVarBool s2 hands = ON \<longrightarrow>
(\<exists>s4. toEnvP s4 \<and>
substate s2 s4 \<and>
substate s4 s0 \<and>
toEnvNum s2 s4 \<le> hands \<and>
getVarBool s4 (Suc (Suc 0)) = ON \<and>
(\<forall>s3. toEnvP s3 \<and>
substate s2 s3 \<and>
substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow>
getVarBool s3 hands = ON)))) \<and>
extraInv s0) \<and>
env (setVarAny s0 hands_value) hands_value \<and>
getPstate (setVarAny s0 hands_value) Ctrl =
waiting \<and>
getVarBool (setVarAny s0 hands_value) hands =
ON"
with extra2 show " extraInv
(toEnv
(setPstate
(setVarBool (setVarAny s0 hands_value)
(Suc (Suc 0)) ON)
Ctrl drying))"
by (auto simp add: VC2_def dryer_def)
qed
end
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.