text
stringlengths 0
3.34M
|
---|
# a function returning unary(i + j) * -998
func $foo (
var %i i32,
var %j i32) f32 {
return (
recip f32(
sqrt f32(
cvt f32 i32(
mul i32 (
extractbits i32 1 23 ( add i32 ( bnot i32 (dread i32 %i), lnot i32 (dread i32 %j))),
neg i32 ( constval i32 -998))))))}
# EXEC: %irbuild Main.mpl
# EXEC: %irbuild Main.irb.mpl
# EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl
|
#include "moja/flint/configuration/externalvariable.h"
#include <boost/algorithm/string.hpp>
namespace moja {
namespace flint {
namespace configuration {
ExternalVariable::ExternalVariable(const std::string& name, std::shared_ptr<Transform> transform)
: IVariable(VariableType::External, name), _transform(transform) {}
} // namespace configuration
} // namespace flint
} // namespace moja
|
#!/usr/bin/env python3
"""
This file contains the logic to read and pre-process the data.
:Author: Pranay Chandekar
"""
import os
import keras
import numpy as np
from constants import TRAINING_PATH, NUM_CLASSES, X_TRAIN, Y_TRAIN, X_TEST, Y_TEST
class DataReader:
"""
This class contains the methods to read and pre-process the data.
"""
@staticmethod
def get_data():
"""
This method calls the other methods in an order to read, pre-process
and split the data in train-test sets.
:return: The processed data.
"""
print("\nReading the data.")
features, labels = DataReader.read_data()
features, labels = DataReader.process_data(features, labels)
processed_data = DataReader.test_train_split(features, labels)
print("Finished data reading and pre-processing.")
return processed_data
@staticmethod
def read_data():
"""
This method reads the data from the data file.
:return: The features and the labels.
"""
labels = list()
features = list()
with open(os.path.join(TRAINING_PATH, "data_set")) as data_file:
for data_point in data_file.readlines():
temp = data_point.split(",")
label = temp[0]
feature = temp[1:]
labels.append(label)
features.append(feature)
return features, labels
@staticmethod
def process_data(features: list, labels: list):
"""
This method performs pre-processing of the data.
:param features: The features of the data.
:param labels: The target labels corresponding to features
:return: The processed features and labels
"""
features = np.asarray(features)
features = features.astype("float32")
features /= 255
print("\nNumber of data samples: ", features.shape[0])
labels = np.asarray(labels)
labels = labels.astype(dtype=np.float32)
labels = labels.astype(dtype=np.int)
labels = keras.utils.to_categorical(labels, NUM_CLASSES)
print("Number of data labels: ", labels.shape[0])
return features, labels
@staticmethod
def test_train_split(features: list, labels: list):
"""
This method performs the train-test split on the data.
:param features: The features of the data.
:param labels: The target labels corresponding to features
:return: The train-test split
"""
processed_data = dict()
processed_data[X_TRAIN] = features[0:8000]
processed_data[X_TEST] = features[8000:]
processed_data[Y_TRAIN] = labels[0:8000]
processed_data[Y_TEST] = labels[8000:]
print(
"\nNumber of training samples: ",
(processed_data[X_TRAIN].shape, processed_data[Y_TRAIN].shape),
)
print(
"Number of test samples: ",
(processed_data[X_TEST].shape, processed_data[Y_TEST].shape),
)
return processed_data
|
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
! This file was ported from Lean 3 source module group_theory.perm.cycle.concrete
! leanprover-community/mathlib commit 00638177efd1b2534fc5269363ebf42a7871df9a
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Data.List.Cycle
import Mathbin.GroupTheory.Perm.Cycle.Type
import Mathbin.GroupTheory.Perm.List
/-!
# Properties of cyclic permutations constructed from lists/cycles
In the following, `{α : Type*} [fintype α] [decidable_eq α]`.
## Main definitions
* `cycle.form_perm`: the cyclic permutation created by looping over a `cycle α`
* `equiv.perm.to_list`: the list formed by iterating application of a permutation
* `equiv.perm.to_cycle`: the cycle formed by iterating application of a permutation
* `equiv.perm.iso_cycle`: the equivalence between cyclic permutations `f : perm α`
and the terms of `cycle α` that correspond to them
* `equiv.perm.iso_cycle'`: the same equivalence as `equiv.perm.iso_cycle`
but with evaluation via choosing over fintypes
* The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)`
* A `has_repr` instance for any `perm α`, by representing the `finset` of
`cycle α` that correspond to the cycle factors.
## Main results
* `list.is_cycle_form_perm`: a nontrivial list without duplicates, when interpreted as
a permutation, is cyclic
* `equiv.perm.is_cycle.exists_unique_cycle`: there is only one nontrivial `cycle α`
corresponding to each cyclic `f : perm α`
## Implementation details
The forward direction of `equiv.perm.iso_cycle'` uses `fintype.choose` of the uniqueness
result, relying on the `fintype` instance of a `cycle.nodup` subtype.
It is unclear if this works faster than the `equiv.perm.to_cycle`, which relies
on recursion over `finset.univ`.
Running `#eval` on even a simple noncyclic permutation `c[(1 : fin 7), 2, 3] * c[0, 5]`
to show it takes a long time. TODO: is this because computing the cycle factors is slow?
-/
open Equiv Equiv.Perm List
variable {α : Type _}
namespace List
variable [DecidableEq α] {l l' : List α}
theorem formPerm_disjoint_iff (hl : Nodup l) (hl' : Nodup l') (hn : 2 ≤ l.length)
(hn' : 2 ≤ l'.length) : Perm.Disjoint (formPerm l) (formPerm l') ↔ l.Disjoint l' :=
by
rw [disjoint_iff_eq_or_eq, List.Disjoint]
constructor
· rintro h x hx hx'
specialize h x
rw [form_perm_apply_mem_eq_self_iff _ hl _ hx, form_perm_apply_mem_eq_self_iff _ hl' _ hx'] at h
rcases h with (hl | hl') <;> linarith
· intro h x
by_cases hx : x ∈ l
by_cases hx' : x ∈ l'
· exact (h hx hx').elim
all_goals have := form_perm_eq_self_of_not_mem _ _ ‹_›; tauto
#align list.form_perm_disjoint_iff List.formPerm_disjoint_iff
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
theorem isCycle_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) : IsCycle (formPerm l) :=
by
cases' l with x l
· norm_num at hn
induction' l with y l IH generalizing x
· norm_num at hn
· use x
constructor
· rwa [form_perm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _)]
· intro w hw
have : w ∈ x::y::l := mem_of_form_perm_ne_self _ _ hw
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem this
use k
simp only [zpow_ofNat, form_perm_pow_apply_head _ _ hl k, Nat.mod_eq_of_lt hk]
#align list.is_cycle_form_perm List.isCycle_formPerm
theorem pairwise_sameCycle_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) :
Pairwise l.formPerm.SameCycle l :=
Pairwise.imp_mem.mpr
(pairwise_of_forall fun x y hx hy =>
(isCycle_formPerm hl hn).SameCycle ((formPerm_apply_mem_ne_self_iff _ hl _ hx).mpr hn)
((formPerm_apply_mem_ne_self_iff _ hl _ hy).mpr hn))
#align list.pairwise_same_cycle_form_perm List.pairwise_sameCycle_formPerm
theorem cycleOf_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) (x) :
cycleOf l.attach.formPerm x = l.attach.formPerm :=
have hn : 2 ≤ l.attach.length := by rwa [← length_attach] at hn
have hl : l.attach.Nodup := by rwa [← nodup_attach] at hl
(isCycle_formPerm hl hn).cycleOf_eq
((formPerm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn)
#align list.cycle_of_form_perm List.cycleOf_formPerm
theorem cycleType_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) :
cycleType l.attach.formPerm = {l.length} :=
by
rw [← length_attach] at hn
rw [← nodup_attach] at hl
rw [cycle_type_eq [l.attach.form_perm]]
· simp only [map, Function.comp_apply]
rw [support_form_perm_of_nodup _ hl, card_to_finset, dedup_eq_self.mpr hl]
· simp
· intro x h
simpa [h, Nat.succ_le_succ_iff] using hn
· simp
· simpa using is_cycle_form_perm hl hn
· simp
#align list.cycle_type_form_perm List.cycleType_formPerm
theorem formPerm_apply_mem_eq_next (hl : Nodup l) (x : α) (hx : x ∈ l) :
formPerm l x = next l x hx :=
by
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem hx
rw [next_nth_le _ hl, form_perm_apply_nth_le _ hl]
#align list.form_perm_apply_mem_eq_next List.formPerm_apply_mem_eq_next
end List
namespace Cycle
variable [DecidableEq α] (s s' : Cycle α)
/-- A cycle `s : cycle α` , given `nodup s` can be interpreted as a `equiv.perm α`
where each element in the list is permuted to the next one, defined as `form_perm`.
-/
def formPerm : ∀ (s : Cycle α) (h : Nodup s), Equiv.Perm α := fun s =>
Quot.hrecOn s (fun l h => formPerm l) fun l₁ l₂ (h : l₁ ~r l₂) =>
by
ext
· exact h.nodup_iff
· intro h₁ h₂ _
exact hEq_of_eq (form_perm_eq_of_is_rotated h₁ h)
#align cycle.form_perm Cycle.formPerm
@[simp]
theorem formPerm_coe (l : List α) (hl : l.Nodup) : formPerm (l : Cycle α) hl = l.formPerm :=
rfl
#align cycle.form_perm_coe Cycle.formPerm_coe
theorem formPerm_subsingleton (s : Cycle α) (h : Subsingleton s) : formPerm s h.Nodup = 1 :=
by
induction s using Quot.inductionOn
simp only [form_perm_coe, mk_eq_coe]
simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h
cases' s with hd tl
· simp
· simp only [length_eq_zero, add_le_iff_nonpos_left, List.length, nonpos_iff_eq_zero] at h
simp [h]
#align cycle.form_perm_subsingleton Cycle.formPerm_subsingleton
theorem isCycle_formPerm (s : Cycle α) (h : Nodup s) (hn : Nontrivial s) : IsCycle (formPerm s h) :=
by
induction s using Quot.inductionOn
exact List.isCycle_formPerm h (length_nontrivial hn)
#align cycle.is_cycle_form_perm Cycle.isCycle_formPerm
theorem support_formPerm [Fintype α] (s : Cycle α) (h : Nodup s) (hn : Nontrivial s) :
support (formPerm s h) = s.toFinset :=
by
induction s using Quot.inductionOn
refine' support_form_perm_of_nodup s h _
rintro _ rfl
simpa [Nat.succ_le_succ_iff] using length_nontrivial hn
#align cycle.support_form_perm Cycle.support_formPerm
theorem formPerm_eq_self_of_not_mem (s : Cycle α) (h : Nodup s) (x : α) (hx : x ∉ s) :
formPerm s h x = x := by
induction s using Quot.inductionOn
simpa using List.formPerm_eq_self_of_not_mem _ _ hx
#align cycle.form_perm_eq_self_of_not_mem Cycle.formPerm_eq_self_of_not_mem
theorem formPerm_apply_mem_eq_next (s : Cycle α) (h : Nodup s) (x : α) (hx : x ∈ s) :
formPerm s h x = next s h x hx :=
by
induction s using Quot.inductionOn
simpa using List.formPerm_apply_mem_eq_next h _ _
#align cycle.form_perm_apply_mem_eq_next Cycle.formPerm_apply_mem_eq_next
theorem formPerm_reverse (s : Cycle α) (h : Nodup s) :
formPerm s.reverse (nodup_reverse_iff.mpr h) = (formPerm s h)⁻¹ :=
by
induction s using Quot.inductionOn
simpa using form_perm_reverse _ h
#align cycle.form_perm_reverse Cycle.formPerm_reverse
theorem formPerm_eq_formPerm_iff {α : Type _} [DecidableEq α] {s s' : Cycle α} {hs : s.Nodup}
{hs' : s'.Nodup} :
s.formPerm hs = s'.formPerm hs' ↔ s = s' ∨ s.Subsingleton ∧ s'.Subsingleton :=
by
rw [Cycle.length_subsingleton_iff, Cycle.length_subsingleton_iff]
revert s s'
intro s s'
apply Quotient.inductionOn₂' s s'
intro l l'
simpa using form_perm_eq_form_perm_iff
#align cycle.form_perm_eq_form_perm_iff Cycle.formPerm_eq_formPerm_iff
end Cycle
namespace Equiv.Perm
section Fintype
variable [Fintype α] [DecidableEq α] (p : Equiv.Perm α) (x : α)
/-- `equiv.perm.to_list (f : perm α) (x : α)` generates the list `[x, f x, f (f x), ...]`
until looping. That means when `f x = x`, `to_list f x = []`.
-/
def toList : List α :=
(List.range (cycleOf p x).support.card).map fun k => (p ^ k) x
#align equiv.perm.to_list Equiv.Perm.toList
@[simp]
theorem toList_one : toList (1 : Perm α) x = [] := by simp [to_list, cycle_of_one]
#align equiv.perm.to_list_one Equiv.Perm.toList_one
@[simp]
theorem toList_eq_nil_iff {p : Perm α} {x} : toList p x = [] ↔ x ∉ p.support := by simp [to_list]
#align equiv.perm.to_list_eq_nil_iff Equiv.Perm.toList_eq_nil_iff
@[simp]
theorem length_toList : length (toList p x) = (cycleOf p x).support.card := by simp [to_list]
#align equiv.perm.length_to_list Equiv.Perm.length_toList
theorem toList_ne_singleton (y : α) : toList p x ≠ [y] :=
by
intro H
simpa [card_support_ne_one] using congr_arg length H
#align equiv.perm.to_list_ne_singleton Equiv.Perm.toList_ne_singleton
theorem two_le_length_toList_iff_mem_support {p : Perm α} {x : α} :
2 ≤ length (toList p x) ↔ x ∈ p.support := by simp
#align equiv.perm.two_le_length_to_list_iff_mem_support Equiv.Perm.two_le_length_toList_iff_mem_support
theorem length_toList_pos_of_mem_support (h : x ∈ p.support) : 0 < length (toList p x) :=
zero_lt_two.trans_le (two_le_length_toList_iff_mem_support.mpr h)
#align equiv.perm.length_to_list_pos_of_mem_support Equiv.Perm.length_toList_pos_of_mem_support
theorem nthLe_toList (n : ℕ) (hn : n < length (toList p x)) : nthLe (toList p x) n hn = (p ^ n) x :=
by simp [to_list]
#align equiv.perm.nth_le_to_list Equiv.Perm.nthLe_toList
theorem toList_nthLe_zero (h : x ∈ p.support) :
(toList p x).nthLe 0 (length_toList_pos_of_mem_support _ _ h) = x := by simp [to_list]
#align equiv.perm.to_list_nth_le_zero Equiv.Perm.toList_nthLe_zero
variable {p} {x}
theorem mem_toList_iff {y : α} : y ∈ toList p x ↔ SameCycle p x y ∧ x ∈ p.support :=
by
simp only [to_list, mem_range, mem_map]
constructor
· rintro ⟨n, hx, rfl⟩
refine' ⟨⟨n, rfl⟩, _⟩
contrapose! hx
rw [← support_cycle_of_eq_nil_iff] at hx
simp [hx]
· rintro ⟨h, hx⟩
simpa using h.exists_pow_eq_of_mem_support hx
#align equiv.perm.mem_to_list_iff Equiv.Perm.mem_toList_iff
theorem nodup_toList (p : Perm α) (x : α) : Nodup (toList p x) :=
by
by_cases hx : p x = x
· rw [← not_mem_support, ← to_list_eq_nil_iff] at hx
simp [hx]
have hc : is_cycle (cycle_of p x) := is_cycle_cycle_of p hx
rw [nodup_iff_nth_le_inj]
rintro n m hn hm
rw [length_to_list, ← hc.order_of] at hm hn
rw [← cycle_of_apply_self, ← Ne.def, ← mem_support] at hx
rw [nth_le_to_list, nth_le_to_list, ← cycle_of_pow_apply_self p x n, ←
cycle_of_pow_apply_self p x m]
cases n <;> cases m
· simp
· rw [← hc.support_pow_of_pos_of_lt_order_of m.zero_lt_succ hm, mem_support,
cycle_of_pow_apply_self] at hx
simp [hx.symm]
· rw [← hc.support_pow_of_pos_of_lt_order_of n.zero_lt_succ hn, mem_support,
cycle_of_pow_apply_self] at hx
simp [hx]
intro h
have hn' : ¬orderOf (p.cycle_of x) ∣ n.succ := Nat.not_dvd_of_pos_of_lt n.zero_lt_succ hn
have hm' : ¬orderOf (p.cycle_of x) ∣ m.succ := Nat.not_dvd_of_pos_of_lt m.zero_lt_succ hm
rw [← hc.support_pow_eq_iff] at hn' hm'
rw [← Nat.mod_eq_of_lt hn, ← Nat.mod_eq_of_lt hm, ← pow_inj_mod]
refine' support_congr _ _
· rw [hm', hn']
exact Finset.Subset.refl _
· rw [hm']
intro y hy
obtain ⟨k, rfl⟩ := hc.exists_pow_eq (mem_support.mp hx) (mem_support.mp hy)
rw [← mul_apply, (Commute.pow_pow_self _ _ _).Eq, mul_apply, h, ← mul_apply, ← mul_apply,
(Commute.pow_pow_self _ _ _).Eq]
#align equiv.perm.nodup_to_list Equiv.Perm.nodup_toList
theorem next_toList_eq_apply (p : Perm α) (x y : α) (hy : y ∈ toList p x) :
next (toList p x) y hy = p y := by
rw [mem_to_list_iff] at hy
obtain ⟨k, hk, hk'⟩ := hy.left.exists_pow_eq_of_mem_support hy.right
rw [← nth_le_to_list p x k (by simpa using hk)] at hk'
simp_rw [← hk']
rw [next_nth_le _ (nodup_to_list _ _), nth_le_to_list, nth_le_to_list, ← mul_apply, ← pow_succ,
length_to_list, pow_apply_eq_pow_mod_order_of_cycle_of_apply p (k + 1), is_cycle.order_of]
exact is_cycle_cycle_of _ (mem_support.mp hy.right)
#align equiv.perm.next_to_list_eq_apply Equiv.Perm.next_toList_eq_apply
theorem toList_pow_apply_eq_rotate (p : Perm α) (x : α) (k : ℕ) :
p.toList ((p ^ k) x) = (p.toList x).rotate k :=
by
apply ext_le
· simp only [length_to_list, cycle_of_self_apply_pow, length_rotate]
· intro n hn hn'
rw [nth_le_to_list, nth_le_rotate, nth_le_to_list, length_to_list,
pow_mod_card_support_cycle_of_self_apply, pow_add, mul_apply]
#align equiv.perm.to_list_pow_apply_eq_rotate Equiv.Perm.toList_pow_apply_eq_rotate
theorem SameCycle.toList_isRotated {f : Perm α} {x y : α} (h : SameCycle f x y) :
toList f x ~r toList f y := by
by_cases hx : x ∈ f.support
· obtain ⟨_ | k, hk, hy⟩ := h.exists_pow_eq_of_mem_support hx
· simp only [coe_one, id.def, pow_zero] at hy
simp [hy]
use k.succ
rw [← to_list_pow_apply_eq_rotate, hy]
· rw [to_list_eq_nil_iff.mpr hx, is_rotated_nil_iff', eq_comm, to_list_eq_nil_iff]
rwa [← h.mem_support_iff]
#align equiv.perm.same_cycle.to_list_is_rotated Equiv.Perm.SameCycle.toList_isRotated
theorem pow_apply_mem_toList_iff_mem_support {n : ℕ} : (p ^ n) x ∈ p.toList x ↔ x ∈ p.support :=
by
rw [mem_to_list_iff, and_iff_right_iff_imp]
refine' fun _ => same_cycle.symm _
rw [same_cycle_pow_left]
#align equiv.perm.pow_apply_mem_to_list_iff_mem_support Equiv.Perm.pow_apply_mem_toList_iff_mem_support
theorem toList_formPerm_nil (x : α) : toList (formPerm ([] : List α)) x = [] := by simp
#align equiv.perm.to_list_form_perm_nil Equiv.Perm.toList_formPerm_nil
theorem toList_formPerm_singleton (x y : α) : toList (formPerm [x]) y = [] := by simp
#align equiv.perm.to_list_form_perm_singleton Equiv.Perm.toList_formPerm_singleton
theorem toList_formPerm_nontrivial (l : List α) (hl : 2 ≤ l.length) (hn : Nodup l) :
toList (formPerm l) (l.nthLe 0 (zero_lt_two.trans_le hl)) = l :=
by
have hc : l.form_perm.is_cycle := List.isCycle_formPerm hn hl
have hs : l.form_perm.support = l.to_finset :=
by
refine' support_form_perm_of_nodup _ hn _
rintro _ rfl
simpa [Nat.succ_le_succ_iff] using hl
rw [to_list, hc.cycle_of_eq (mem_support.mp _), hs, card_to_finset, dedup_eq_self.mpr hn]
· refine' List.ext_nthLe (by simp) fun k hk hk' => _
simp [form_perm_pow_apply_nth_le _ hn, Nat.mod_eq_of_lt hk']
· simpa [hs] using nth_le_mem _ _ _
#align equiv.perm.to_list_form_perm_nontrivial Equiv.Perm.toList_formPerm_nontrivial
theorem toList_formPerm_isRotated_self (l : List α) (hl : 2 ≤ l.length) (hn : Nodup l) (x : α)
(hx : x ∈ l) : toList (formPerm l) x ~r l :=
by
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem hx
have hr : l ~r l.rotate k := ⟨k, rfl⟩
rw [form_perm_eq_of_is_rotated hn hr]
rw [← nth_le_rotate' l k k]
simp only [Nat.mod_eq_of_lt hk, tsub_add_cancel_of_le hk.le, Nat.mod_self]
rw [to_list_form_perm_nontrivial]
· simp
· simpa using hl
· simpa using hn
#align equiv.perm.to_list_form_perm_is_rotated_self Equiv.Perm.toList_formPerm_isRotated_self
theorem formPerm_toList (f : Perm α) (x : α) : formPerm (toList f x) = f.cycleOf x :=
by
by_cases hx : f x = x
·
rw [(cycle_of_eq_one_iff f).mpr hx, to_list_eq_nil_iff.mpr (not_mem_support.mpr hx),
form_perm_nil]
ext y
by_cases hy : same_cycle f x y
· obtain ⟨k, hk, rfl⟩ := hy.exists_pow_eq_of_mem_support (mem_support.mpr hx)
rw [cycle_of_apply_apply_pow_self, List.formPerm_apply_mem_eq_next (nodup_to_list f x),
next_to_list_eq_apply, pow_succ, mul_apply]
rw [mem_to_list_iff]
exact ⟨⟨k, rfl⟩, mem_support.mpr hx⟩
· rw [cycle_of_apply_of_not_same_cycle hy, form_perm_apply_of_not_mem]
simp [mem_to_list_iff, hy]
#align equiv.perm.form_perm_to_list Equiv.Perm.formPerm_toList
/-- Given a cyclic `f : perm α`, generate the `cycle α` in the order
of application of `f`. Implemented by finding an element `x : α`
in the support of `f` in `finset.univ`, and iterating on using
`equiv.perm.to_list f x`.
-/
def toCycle (f : Perm α) (hf : IsCycle f) : Cycle α :=
Multiset.recOn (Finset.univ : Finset α).val (Quot.mk _ [])
(fun x s l => if f x = x then l else toList f x)
(by
intro x y m s
refine' hEq_of_eq _
split_ifs with hx hy hy <;> try rfl
· have hc : same_cycle f x y := is_cycle.same_cycle hf hx hy
exact Quotient.sound' hc.to_list_is_rotated)
#align equiv.perm.to_cycle Equiv.Perm.toCycle
theorem toCycle_eq_toList (f : Perm α) (hf : IsCycle f) (x : α) (hx : f x ≠ x) :
toCycle f hf = toList f x :=
by
have key : (Finset.univ : Finset α).val = x ::ₘ finset.univ.val.erase x := by simp
rw [to_cycle, key]
simp [hx]
#align equiv.perm.to_cycle_eq_to_list Equiv.Perm.toCycle_eq_toList
theorem nodup_toCycle (f : Perm α) (hf : IsCycle f) : (toCycle f hf).Nodup :=
by
obtain ⟨x, hx, -⟩ := id hf
simpa [to_cycle_eq_to_list f hf x hx] using nodup_to_list _ _
#align equiv.perm.nodup_to_cycle Equiv.Perm.nodup_toCycle
theorem nontrivial_toCycle (f : Perm α) (hf : IsCycle f) : (toCycle f hf).Nontrivial :=
by
obtain ⟨x, hx, -⟩ := id hf
simp [to_cycle_eq_to_list f hf x hx, hx, Cycle.nontrivial_coe_nodup_iff (nodup_to_list _ _)]
#align equiv.perm.nontrivial_to_cycle Equiv.Perm.nontrivial_toCycle
/-- Any cyclic `f : perm α` is isomorphic to the nontrivial `cycle α`
that corresponds to repeated application of `f`.
The forward direction is implemented by `equiv.perm.to_cycle`.
-/
def isoCycle : { f : Perm α // IsCycle f } ≃ { s : Cycle α // s.Nodup ∧ s.Nontrivial }
where
toFun f := ⟨toCycle (f : Perm α) f.Prop, nodup_toCycle f f.Prop, nontrivial_toCycle _ f.Prop⟩
invFun s := ⟨(s : Cycle α).formPerm s.Prop.left, (s : Cycle α).isCycle_formPerm _ s.Prop.right⟩
left_inv f := by
obtain ⟨x, hx, -⟩ := id f.prop
simpa [to_cycle_eq_to_list (f : perm α) f.prop x hx, form_perm_to_list, Subtype.ext_iff] using
f.prop.cycle_of_eq hx
right_inv s := by
rcases s with ⟨⟨s⟩, hn, ht⟩
obtain ⟨x, -, -, hx, -⟩ := id ht
have hl : 2 ≤ s.length := by simpa using Cycle.length_nontrivial ht
simp only [Cycle.mk_eq_coe, Cycle.nodup_coe_iff, Cycle.mem_coe_iff, Subtype.coe_mk,
Cycle.formPerm_coe] at hn hx⊢
rw [to_cycle_eq_to_list _ _ x]
· refine' Quotient.sound' _
exact to_list_form_perm_is_rotated_self _ hl hn _ hx
· rw [← mem_support, support_form_perm_of_nodup _ hn]
· simpa using hx
· rintro _ rfl
simpa [Nat.succ_le_succ_iff] using hl
#align equiv.perm.iso_cycle Equiv.Perm.isoCycle
end Fintype
section Finite
variable [Finite α] [DecidableEq α]
theorem IsCycle.existsUnique_cycle {f : Perm α} (hf : IsCycle f) :
∃! s : Cycle α, ∃ h : s.Nodup, s.formPerm h = f :=
by
cases nonempty_fintype α
obtain ⟨x, hx, hy⟩ := id hf
refine' ⟨f.to_list x, ⟨nodup_to_list f x, _⟩, _⟩
· simp [form_perm_to_list, hf.cycle_of_eq hx]
· rintro ⟨l⟩ ⟨hn, rfl⟩
simp only [Cycle.mk_eq_coe, Cycle.coe_eq_coe, Subtype.coe_mk, Cycle.formPerm_coe]
refine' (to_list_form_perm_is_rotated_self _ _ hn _ _).symm
· contrapose! hx
suffices form_perm l = 1 by simp [this]
rw [form_perm_eq_one_iff _ hn]
exact Nat.le_of_lt_succ hx
· rw [← mem_to_finset]
refine' support_form_perm_le l _
simpa using hx
#align equiv.perm.is_cycle.exists_unique_cycle Equiv.Perm.IsCycle.existsUnique_cycle
theorem IsCycle.existsUnique_cycle_subtype {f : Perm α} (hf : IsCycle f) :
∃! s : { s : Cycle α // s.Nodup }, (s : Cycle α).formPerm s.Prop = f :=
by
obtain ⟨s, ⟨hs, rfl⟩, hs'⟩ := hf.exists_unique_cycle
refine' ⟨⟨s, hs⟩, rfl, _⟩
rintro ⟨t, ht⟩ ht'
simpa using hs' _ ⟨ht, ht'⟩
#align equiv.perm.is_cycle.exists_unique_cycle_subtype Equiv.Perm.IsCycle.existsUnique_cycle_subtype
theorem IsCycle.existsUnique_cycle_nontrivial_subtype {f : Perm α} (hf : IsCycle f) :
∃! s : { s : Cycle α // s.Nodup ∧ s.Nontrivial }, (s : Cycle α).formPerm s.Prop.left = f :=
by
obtain ⟨⟨s, hn⟩, hs, hs'⟩ := hf.exists_unique_cycle_subtype
refine' ⟨⟨s, hn, _⟩, _, _⟩
· rw [hn.nontrivial_iff]
subst f
intro H
refine' hf.ne_one _
simpa using Cycle.formPerm_subsingleton _ H
· simpa using hs
· rintro ⟨t, ht, ht'⟩ ht''
simpa using hs' ⟨t, ht⟩ ht''
#align equiv.perm.is_cycle.exists_unique_cycle_nontrivial_subtype Equiv.Perm.IsCycle.existsUnique_cycle_nontrivial_subtype
end Finite
variable [Fintype α] [DecidableEq α]
/-- Any cyclic `f : perm α` is isomorphic to the nontrivial `cycle α`
that corresponds to repeated application of `f`.
The forward direction is implemented by finding this `cycle α` using `fintype.choose`.
-/
def isoCycle' : { f : Perm α // IsCycle f } ≃ { s : Cycle α // s.Nodup ∧ s.Nontrivial }
where
toFun f := Fintype.choose _ f.Prop.existsUnique_cycle_nontrivial_subtype
invFun s := ⟨(s : Cycle α).formPerm s.Prop.left, (s : Cycle α).isCycle_formPerm _ s.Prop.right⟩
left_inv f := by
simpa [Subtype.ext_iff] using
Fintype.choose_spec _ f.prop.exists_unique_cycle_nontrivial_subtype
right_inv := fun ⟨s, hs, ht⟩ => by
simp [Subtype.coe_mk]
convert Fintype.choose_subtype_eq (fun s' : Cycle α => s'.Nodup ∧ s'.Nontrivial) _
ext ⟨s', hs', ht'⟩
simp [Cycle.formPerm_eq_formPerm_iff, iff_not_comm.mp hs.nontrivial_iff,
iff_not_comm.mp hs'.nontrivial_iff, ht]
#align equiv.perm.iso_cycle' Equiv.Perm.isoCycle'
-- mathport name: «exprc[ ,]»
notation3"c["(l", "* => foldr (h t => List.cons h t) List.nil)"]" =>
Cycle.formPerm (↑l) (Cycle.nodup_coe_iff.mpr (by decide))
unsafe instance repr_perm [Repr α] : Repr (Perm α) :=
⟨fun f =>
repr
(Multiset.pmap (fun (g : Perm α) (hg : g.IsCycle) => isoCycle ⟨g, hg⟩)
(-- to_cycle is faster?
Perm.cycleFactorsFinset
f).val
fun g hg => (mem_cycleFactorsFinset_iff.mp (Finset.mem_def.mpr hg)).left)⟩
#align equiv.perm.repr_perm equiv.perm.repr_perm
end Equiv.Perm
|
theory int_mul_assoc
imports Main
"$HIPSTER_HOME/IsaHipster"
begin
datatype Sign = Pos | Neg
datatype Nat = Zero | Succ "Nat"
datatype Z = P "Nat" | N "Nat"
fun toInteger :: "Sign => Nat => Z" where
"toInteger (Pos) y = P y"
| "toInteger (Neg) (Zero) = P Zero"
| "toInteger (Neg) (Succ m) = N m"
fun sign2 :: "Z => Sign" where
"sign2 (P y) = Pos"
| "sign2 (N z) = Neg"
fun plus :: "Nat => Nat => Nat" where
"plus (Zero) y = y"
| "plus (Succ n) y = Succ (plus n y)"
fun opposite :: "Sign => Sign" where
"opposite (Pos) = Neg"
| "opposite (Neg) = Pos"
fun timesSign :: "Sign => Sign => Sign" where
"timesSign (Pos) y = y"
| "timesSign (Neg) y = opposite y"
fun mult :: "Nat => Nat => Nat" where
"mult (Zero) y = Zero"
| "mult (Succ n) y = plus y (mult n y)"
fun absVal :: "Z => Nat" where
"absVal (P n) = n"
| "absVal (N m) = Succ m"
fun times :: "Z => Z => Z" where
"times x y =
toInteger
(timesSign (sign2 x) (sign2 y)) (mult (absVal x) (absVal y))"
(*hipster toInteger
sign2
plus
opposite
timesSign
mult
absVal
times *)
theorem x0 :
"!! (x :: Z) (y :: Z) (z :: Z) .
(times x (times y z)) = (times (times x y) z)"
by (tactic \<open>Subgoal.FOCUS_PARAMS (K (Tactic_Data.hard_tac @{context})) @{context} 1\<close>)
end
|
State Before: p q x y : ℝ
r : ℚ
m : ℤ
n : ℕ
⊢ LiouvilleWith p (↑n - x) ↔ LiouvilleWith p x State After: no goals Tactic: simp [sub_eq_add_neg] |
Set Primitive Projections.
Record foo : Type := bar { x : unit }.
Goal forall t u, bar t = bar u -> t = u.
Proof.
intros.
injection H.
trivial.
Qed.
(* Was: Error: Pattern-matching expression on an object of inductive type foo has invalid information. *)
(** Dependent pattern-matching is ok on this one as it has eta *)
Definition baz (x : foo) :=
match x as x' return x' = x' with
| bar u => eq_refl
end.
Inductive foo' : Type := bar' {x' : unit; y: foo'}.
(** Dependent pattern-matching is not ok on this one *)
Fail Definition baz' (x : foo') :=
match x as x' return x' = x' with
| bar' u y => eq_refl
end.
|
function g
%here is how one creates a function ("callback") which does something
%(prints the node label) when you click on the node's text in Matlab figure.
%
% Leon Peshkin http://www.ai.mit.edu/~pesha
%
%draw_graph(...)
% "gca" is the current "axes" object, parent of all objects in figure
% "gcbo" is the handle of the object whose callback is being executed
% "findall" gives handles to all elements of a given type in the figure
text_elms = findall(gca,'Type','text');
for ndx = 1:length(text_elms)
callbk = 'my_call(str2num(get(gcbo,''String'')))';
set(text_elms(ndx), 'ButtonDownFcn', callbk); % assume the node label is a number
end
|
# -*- coding: utf-8 -*-
import os
import tensorflow as tf
from time import time
import numpy as np
import pandas as pd
import math
import random
import heapq
import argparse
from gensim.models import KeyedVectors
from collections import defaultdict
from aarm import AARM
def parse_args():
parser = argparse.ArgumentParser(description="Run AARM model")
parser.add_argument('--process_name', nargs='?', default="aarm", help='the name of process')
parser.add_argument('--gpu', type=int, default=0, help="Specify which GPU to use (default=0)")
# dataset
parser.add_argument('--productName', nargs='?', default='Beauty', help='specify the dataset used in experiment')
parser.add_argument('--MaxPerUser', type=int, default=12, help='Maximum number of aspects per user.')
parser.add_argument('--MaxPerItem', type=int, default=15, help='Maximum number of aspects per item.')
parser.add_argument('--auto_max', type=int, default=1, help='1: set MaxPerUser (MaxPerItem) as the 75% quantile of the sizes of all user (item) aspect set; 0: using the args of MaxPerUser and MaxPerItem')
# regularization
parser.add_argument('--is_l2_regular', type=int, default=0, help='1: use l2_regularization for embedding matrix')
parser.add_argument('--is_out_l2', type=int, default=0, help='1: to use l2 regularization in output layer')
parser.add_argument('--lamda_l2', type=float, default=0.1, help='parameter of the l2_regularization for embedding matrix')
parser.add_argument('--lamda_out_l2', type=float, default=0.1,help='parameter of the l2_regularization for output layer')
parser.add_argument('--dropout', type=float, default=0.5, help='the keep probability of dropout')
# training
parser.add_argument('--learning_rate', type=float, default=0.003, help='learning rate')
parser.add_argument('--num_epoch', type=int, default=300, help='Maximum number of epochs')
parser.add_argument('--optimizer_type', type=int, default=1, help="1: AdamOptimizer, 2: AdagradOptimizer, 3: GradientDescentOptimizer, 4:MomentumOptimizer")
parser.add_argument('--num_aspect_factor', type=int, default=128, help='dimension of aspect embedding')
parser.add_argument('--num_mf_factor', type=int, default=128, help='dimension of global user/item embedding')
parser.add_argument('--num_attention', type=int, default=64, help='dimension of attention module')
parser.add_argument('--num_batch', type=int, default=1024,help='batch size of training')
parser.add_argument('--is_save_params', type=int, default=1, help='1: save the parameters which achieved the best validation performance.')
parser.add_argument('--patience_no_improve', type=int, default=300, help="The number of patience epochs. The training would be stopped if half of the four measures decreased for 'patience_no_improve' success epochs")
parser.add_argument('--seed', type=int, default=1000, help='random seed')
# evaluate
parser.add_argument('--K', type=int, default=10, help='top-K recommendation.')
parser.add_argument('--test_batch_size', type=int, default=4096, help='batch size of test evaluation')
return parser.parse_args()
class Running():
def __init__(self, args):
self.args = args
self.productName = self.args.productName
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
self.sess = tf.Session(config=config)
self.load_dataset()
self.load_emb()
# initialize AARM models
self.model = AARM(args, self.num_user, self.num_item, self.num_aspect, self.MaxPerUser, self.MaxPerItem, self.user_aspect_padded,
self.item_aspect_padded, self.aspect_vectors)
self.model.build_graph()
self.save_path_name = "../temp/%s/" % (args.process_name)
self.restore_path_name = "../temp/%s/" % (args.process_name)
if not os.path.exists(self.save_path_name):
os.makedirs(self.save_path_name)
if not os.path.exists(self.restore_path_name):
os.makedirs(self.restore_path_name)
self.saver = tf.train.Saver()
# initialize graph
self.sess.run(tf.global_variables_initializer())
# number of params
total_parameters = 0
for variable in self.model.all_weights.values():
shape = variable.get_shape() # shape is an array of tf.Dimension
variable_parameters = 1
for dim in shape:
variable_parameters *= dim.value
total_parameters += variable_parameters
print("#params: %d" % total_parameters)
#### training
def _get_train_batch(self, iter):
user_input = []
item_p_input = []
item_n_input = []
for index in range(iter * self.args.num_batch, min(len(self.train_pairs), (iter + 1) * self.args.num_batch)):
u, i = self.train_pairs[index]
user_input.append(u)
item_p_input.append(i)
j = np.random.randint(self.num_item)
while j in self.user2items_train[u]:
j = np.random.randint(self.num_item)
item_n_input.append(j)
return (user_input, item_p_input, item_n_input)
def generate_train_batch(self):
num_iters = len(self.train_pairs) // self.args.num_batch + 1
user_list = []
item_pos_list = []
item_dns_list = []
for iter in range(num_iters):
u_l, v_pos_l, v_neg_l = self._get_train_batch(iter)
user_list.append(u_l)
item_pos_list.append(v_pos_l)
item_dns_list.append(v_neg_l)
return user_list, item_pos_list, item_dns_list, num_iters
def train(self):
self.best_result = [(0, 0, 0, 0)] # [(precision, recall, ndcg, hr)]
self.counter_no_improve = 0 # how many epochs that no improvements on ranking measures
for epoch in range(self.args.num_epoch):
self.counter_no_improve += 1
if self.counter_no_improve > self.args.patience_no_improve:
break
t1 = time()
loss_list = []
trainBpr_batch = []
user_list, item_pos_list, item_dns_list, num_iters = self.generate_train_batch()
for i in range(num_iters):
user_batch, item_p_batch, item_n_batch = user_list[i], item_pos_list[i], item_dns_list[i]
feed_dict = {self.model.user_input:user_batch, self.model.item_p_input:item_p_batch, self.model.item_n_input:item_n_batch,
self.model.dropout_keep:args.dropout}
loss_, bprloss_, opt = self.sess.run((self.model.loss, self.model.bprloss, self.model.train_op), feed_dict=feed_dict)
loss_list.append(loss_)
trainBpr_batch.append(bprloss_)
train_loss = np.mean(loss_list)
train_bprloss = np.mean(trainBpr_batch)
if (epoch+1) % 10 == 0:
t2 = time()
precision, recall, ndcg, hr = self.evaluate_model(self.users4valid, mode='valid')
print("Epoch %d [%.1f s]\tloss=%.6f\tbprloss=%.6f" % (epoch + 1, t2 - t1, train_loss, train_bprloss))
print("validation: precision=%.6f\trecall=%.6f\tNDCG=%.6f\tHT=%.6f [%.1f s]"
% (precision, recall, ndcg, hr, time() - t2))
if self.args.is_save_params:
for p,r,n,h in self.best_result:
if np.sign(precision-p) + np.sign(recall-r) + np.sign(ndcg-n) + np.sign(hr-h) >= 0:
self.counter_no_improve = 0
self.best_result = [(precision, recall, ndcg, hr)]
save_path = self.saver.save(self.sess, self.save_path_name+'save_net.ckpt')
print("epoch %d save to %s" % (epoch+1, save_path))
def test(self):
if self.args.is_save_params:
self.saver.restore(self.sess, self.restore_path_name+'save_net.ckpt')
t3 = time()
precision, recall, ndcg, hr = self.evaluate_model(range(self.num_user), mode='test')
print("test_precision=%.6f\ttest_recall=%.6f\ttest_NDCG=%.6f\ttest_HT=%.6f [%.1f s]"
% (precision, recall, ndcg, hr, time() - t3))
print("MaxPerUser is %d, MaxPerItem is %d" %(self.MaxPerUser, self.MaxPerItem))
#### load datasets
def load_dataset(self):
data_path = '../data/'+self.productName
random.seed(self.args.seed)
np.random.seed(self.args.seed)
tf.set_random_seed(self.args.seed)
# load training and test pairs
self.train_pairs = []
with open(data_path+'/train_pairs.txt') as f:
for line in f:
self.train_pairs.append(list(map(int, line.split(','))))
perm = np.random.permutation(range(len(self.train_pairs)))
self.train_pairs = np.array(self.train_pairs)[perm]
self.valid_pairs = []
with open(data_path+'/valid_pairs.txt') as f:
for line in f:
self.valid_pairs.append(list(map(int, line.split(','))))
perm = np.random.permutation(range(len(self.valid_pairs)))
self.valid_pairs = np.array(self.valid_pairs)[perm]
self.test_pairs = []
with open(data_path+'/test_pairs.txt') as f:
for line in f:
self.test_pairs.append(list(map(int, line.split(','))))
perm = np.random.permutation(range(len(self.test_pairs)))
self.test_pairs = np.array(self.test_pairs)[perm]
# load id2user, id2item, id2aspect
with open(data_path+'/users.txt') as users_f:
self.id2user = {}
self.user2id = {}
index = 0
for line in users_f:
name = line.strip()
self.id2user[index] = name
self.user2id[name] = index
index += 1
with open(data_path+'/product.txt') as products_f:
self.id2item = {}
self.item2id = {}
index = 0
for line in products_f:
name = line.strip()
self.id2item[index] = name
self.item2id[name] = index
index += 1
with open(data_path+'/aspect.txt') as f:
self.id2aspect = {}
self.aspect2id = {}
index = 0
for line in f:
name = line.strip()
self.id2aspect[index] = name
self.aspect2id[name] = index
index += 1
self.num_user = len(self.id2user)
self.num_item = len(self.id2item)
self.num_aspect = len(self.id2aspect)
self.item_set = set(self.id2item.keys())
# generate user2items, dict: {u:[v1,v2,...], ...}
self.user2items_train = defaultdict(list)
self.user2items_valid = defaultdict(list)
self.user2items_test = defaultdict(list)
for u,v in self.train_pairs:
self.user2items_train[u].append(v)
self.users4valid = []
for u,v in self.valid_pairs:
self.user2items_valid[u].append(v)
self.users4valid.append(u)
for u,v in self.test_pairs:
self.user2items_test[u].append(v)
# load ranked user/item aspect sets
self.user_aspect_rank_dict = {}
with open(data_path+'/user_aspect_rank.txt') as f:
index = 0
for line in f:
if line.strip():
tokens = [int(t) for t in line.strip().split(',')]
self.user_aspect_rank_dict[index] = tokens
else:
self.user_aspect_rank_dict[index] = []
index += 1
self.item_aspect_rank_dict = {}
with open(data_path+'/item_aspect_rank.txt') as f:
index = 0
for line in f:
if line.strip():
tokens = [int(t) for t in line.strip().split(',')]
self.item_aspect_rank_dict[index] = tokens
else:
self.item_aspect_rank_dict[index] = []
index += 1
self.get_history_aspect()
def get_history_aspect(self):
user_aspect_list = [[]] * self.num_user
item_aspect_list = [[]] * self.num_item
len_users = [len(self.user_aspect_rank_dict[u]) for u in self.user_aspect_rank_dict]
len_items = [len(self.item_aspect_rank_dict[v]) for v in self.item_aspect_rank_dict]
lens_u_series = pd.Series(len_users)
lens_v_series = pd.Series(len_items)
if self.args.auto_max:
self.MaxPerUser = int(lens_u_series.quantile(0.75))
self.MaxPerItem = int(lens_v_series.quantile(0.75))
else:
self.MaxPerUser = self.args.MaxPerUser
self.MaxPerItem = self.args.MaxPerItem
print("MaxPerUser is %d, MaxPerItem is %d" %(self.MaxPerUser, self.MaxPerItem))
for u in self.user_aspect_rank_dict.keys():
user_aspect_list[u] = self.user_aspect_rank_dict[u]
for v in self.item_aspect_rank_dict.keys():
item_aspect_list[v] = self.item_aspect_rank_dict[v]
self.user_aspect_padded = np.zeros((self.num_user, self.MaxPerUser), dtype=np.int32)
self.item_aspect_padded = np.zeros((self.num_item, self.MaxPerItem), dtype=np.int32)
for idx, s in enumerate(user_aspect_list):
trunc = np.asarray(s[:self.MaxPerUser])
self.user_aspect_padded[idx, :len(trunc)] = trunc
for idx, s in enumerate(item_aspect_list):
trunc = np.asarray(s[:self.MaxPerItem])
self.item_aspect_padded[idx, :len(trunc)] = trunc
def load_emb(self):
embedding = KeyedVectors.load_word2vec_format('../data/' + self.productName + '/emb' + str(self.args.num_aspect_factor) + '.vector')
# construct a dict from vocab's index to embedding's index
embed_dict = {} # {word:index,...}
for index, word in enumerate(embedding.index2word):
embed_dict[word] = index
self.aspect_vectors = np.zeros((self.num_aspect, self.args.num_aspect_factor),dtype=np.float32)
trained_aspects = []
untrained_aspects = []
aspect_set = self.aspect2id.keys()
for a in aspect_set:
a_ = '_'.join(a.split())
if a_ in embed_dict:
trained_aspects.append(a)
self.aspect_vectors[self.aspect2id[a]] = embedding.syn0[embed_dict[a_]]
else:
untrained_aspects.append(a)
print('trained aspects: %d, untrained aspects: %d' % (len(trained_aspects), len(untrained_aspects)))
#### evaluate
def eval_one_user(self, u, mode):
if mode == 'valid':
gtItems = self.user2items_valid[u]
elif mode == 'test':
gtItems = self.user2items_test[u]
test_neg = list(self.item_set - set(self.user2items_train[u]) - set(gtItems))
item_list = gtItems + test_neg
permut = np.random.permutation(len(item_list))
item_list = np.array(item_list, dtype=np.int32)[permut]
user_list = np.full(len(item_list),u,dtype='int32')
num_batch = len(item_list) // self.args.test_batch_size
predictions = []
for i in range(num_batch+1):
feed_dict = {self.model.user_input: user_list[(i)*self.args.test_batch_size:(i+1)*self.args.test_batch_size],
self.model.item_p_input: item_list[(i)*self.args.test_batch_size:(i+1)*self.args.test_batch_size],
self.model.dropout_keep: 1}
predictions.extend( list(self.sess.run((self.model.rating_preds_pos), feed_dict=feed_dict).squeeze()) )
map_item_score = {}
for i in range(len(item_list)):
v = item_list[i]
map_item_score[v] = predictions[i]
# Evaluate top rank list
ranklist = heapq.nlargest(self.args.K, map_item_score, key=map_item_score.get) # top K
recall, ndcg, hr, precision = self.metrics(ranklist, gtItems)
return precision,recall,ndcg,hr
def evaluate_model(self, users, mode):
precision_list = []
recall_list = []
ndcg_list = []
hr_list = []
for u in users:
(p,r,ndcg,hr) = self.eval_one_user(u, mode)
precision_list.append(p)
recall_list.append(r)
ndcg_list.append(ndcg)
hr_list.append(hr)
return (np.mean(precision_list), np.mean(recall_list), np.mean(ndcg_list), np.mean(hr_list))
def metrics(self, doc_list, rel_set):
dcg = 0.0
hit_num = 0.0
for i in range(len(doc_list)):
if doc_list[i] in rel_set:
#dcg
dcg += 1/(math.log(i+2)/math.log(2))
hit_num += 1
#idcg
idcg = 0.0
for i in range(min(len(rel_set),len(doc_list))):
idcg += 1/(math.log(i+2)/math.log(2))
ndcg = dcg/idcg
recall = hit_num / len(rel_set)
precision = hit_num / len(doc_list)
#compute hit_ratio
hit = 1.0 if hit_num > 0 else 0.0
return recall, ndcg, hit, precision
if __name__ == '__main__':
args = parse_args()
print("Arguments: %s" % (args))
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]=str(args.gpu)
runner = Running(args)
runner.train()
runner.test() |
Require Import VST.msl.Extensionality.
Require Import VST.msl.simple_CCC.
Require Import VST.msl.seplog.
Require Import VST.msl.log_normalize.
Require Import Coq.Lists.List.
Local Open Scope logic.
Lemma fold_right_andp {A} `{NatDed A}: forall (l: list A) (P: A),
In P l -> exists Q: A, fold_right andp TT l = P && Q.
Proof.
induction l; intros; simpl. 1: inversion H0. simpl in H0. destruct H0.
- subst a. exists (fold_right andp TT l). reflexivity.
- apply IHl in H0. destruct H0 as [QQ ?]. rewrite H0.
rewrite andp_comm, andp_assoc. exists (QQ && a). reflexivity.
Qed.
Lemma exp_uncurry: forall {A} `{NatDed A} (S T: Type) (P: S -> T -> A),
exp (fun s => exp (P s)) = exp (fun st => P (fst st) (snd st)).
Proof.
intros.
apply pred_ext.
+ apply exp_left; intro s.
apply exp_left; intro t.
apply (exp_right (s, t)).
apply derives_refl.
+ apply exp_left; intros [s t].
apply (exp_right s).
apply (exp_right t).
apply derives_refl.
Qed.
Lemma exp_curry: forall {A} `{NatDed A} (S T: Type) (P: S * T -> A),
exp P = exp (fun s => exp (fun t => P (s, t))).
Proof.
intros.
apply pred_ext.
+ apply exp_left; intros [s t].
apply (exp_right s).
apply (exp_right t).
apply derives_refl.
+ apply exp_left; intro s.
apply exp_left; intro t.
apply (exp_right (s, t)).
apply derives_refl.
Qed.
Lemma exp_FF: forall {A B} `{NatDed A}, (EX x: B, FF) = FF.
Proof.
intros.
apply pred_ext; [| apply FF_left].
apply exp_left; intros; auto.
Qed.
Lemma allp_derives': forall {A B} `{NatDed A} (P Q : B -> A),
P |-- Q -> allp P |-- allp Q.
Proof. intros; apply allp_derives; auto. Qed.
Lemma imp_prop_ext: forall {A} {NA: NatDed A} (P P' :Prop) (Q Q': A),
(P <-> P') -> (P -> Q = Q') -> !!P --> Q = !!P' --> Q'.
Proof.
intros.
apply pred_ext.
+ apply imp_andp_adjoint.
normalize.
rewrite prop_imp by tauto.
rewrite H0 by tauto.
auto.
+ apply imp_andp_adjoint.
normalize.
rewrite prop_imp by tauto.
rewrite H0 by tauto.
auto.
Qed.
Lemma sepcon_left1_corable_right: forall {A} `{CorableSepLog A} P Q R, corable R -> P |-- R -> P * Q |-- R.
Proof.
intros.
rewrite (add_andp _ _ H1).
rewrite corable_andp_sepcon2 by auto.
apply andp_left1; auto.
Qed.
Lemma sepcon_left2_corable_right: forall {A} `{CorableSepLog A} P Q R, corable R -> Q |-- R -> P * Q |-- R.
Proof.
intros.
rewrite sepcon_comm.
apply sepcon_left1_corable_right; auto.
Qed.
Lemma corable_wand_corable: forall {A} {NA: NatDed A} {SA: SepLog A} {ClA: ClassicalSep A} {CoA: CorableSepLog A} (P Q: A),
corable P ->
corable Q ->
P --> Q |-- P -* Q.
Proof.
intros.
apply wand_sepcon_adjoint.
rewrite sepcon_corable_corable, andp_comm; auto.
apply modus_ponens.
Qed.
Lemma corable_andp_wand_corable_andp: forall {A} {NA: NatDed A} {SA: SepLog A} {ClA: ClassicalSep A} {CoA: CorableSepLog A} (P1 P2 Q1 Q2: A),
corable P1 ->
corable Q1 ->
(P1 --> Q1) && (P2 -* Q2) |-- P1 && P2 -* Q1 && Q2.
Proof.
intros.
rewrite (andp_left_corable P1), (andp_left_corable Q1), (andp_left_corable (P1 --> Q1)) by auto.
eapply derives_trans; [| apply wand_sepcon_wand].
apply sepcon_derives; [| auto].
rewrite <- wand_sepcon_adjoint.
normalize.
rewrite <- andp_assoc.
apply andp_derives; [| auto].
rewrite andp_comm; apply modus_ponens.
Qed.
Lemma wand_corable_andp: forall {A} {NA: NatDed A} {SA: SepLog A} {CoA: CorableSepLog A} (P Q R: A),
corable Q ->
Q && (P -* R) |-- P -* Q && R.
Proof.
intros.
apply wand_sepcon_adjoint.
normalize.
apply andp_derives; auto.
apply wand_sepcon_adjoint.
auto.
Qed.
(*
Lemma ocon_sep_true: forall {A} `{OverlapSepLog A} (P Q: A), ocon P Q |-- P * TT.
Proof.
intros.
eapply derives_trans.
+ apply ocon_derives; [apply derives_refl | apply TT_right].
+ rewrite ocon_TT.
apply derives_refl.
Qed.
*)
Lemma exp_allp: forall {A} `{NatDed A} (S T: Type) (P: S -> T -> A),
exp (fun s => allp (P s)) |-- allp (fun t => exp (fun s => P s t)).
Proof.
intros.
apply exp_left; intro s.
apply allp_right; intro t.
apply (exp_right s).
eapply allp_left.
apply derives_refl.
Qed.
Lemma allp_left': forall {B A: Type} {NA: NatDed A} (x: B) (P Q: B -> A),
P |-- Q ->
allp P |-- Q x.
Proof.
intros.
apply (allp_left _ x).
apply H.
Qed.
(*
Lemma precise_andp_left: forall {A} `{PreciseSepLog A} P Q, precise P -> precise (P && Q).
Proof.
intros.
apply derives_precise with P; auto.
apply andp_left1; auto.
Qed.
Lemma precise_andp_right: forall {A} `{PreciseSepLog A} P Q, precise Q -> precise (P && Q).
Proof.
intros.
apply derives_precise with Q; auto.
apply andp_left2; auto.
Qed.
Lemma precise_exp_andp_left: forall {A B} `{PreciseSepLog A} (P Q: B -> A), precise (exp P) -> precise (exp (P && Q)).
Proof.
intros.
apply derives_precise with (exp P); auto.
apply exp_left; intro b; apply (exp_right b).
simpl.
apply andp_left1; auto.
Qed.
Lemma precise_exp_andp_right: forall {A B} `{PreciseSepLog A} (P Q: B -> A), precise (exp Q) -> precise (exp (P && Q)).
Proof.
intros.
apply derives_precise with (exp Q); auto.
apply exp_left; intro b; apply (exp_right b).
simpl.
apply andp_left2; auto.
Qed.
Lemma FF_precise: forall {A} `{PreciseSepLog A}, precise FF.
Proof.
intros.
apply derives_precise with emp.
+ apply FF_left.
+ apply precise_emp.
Qed.
Lemma exp_FF_precise: forall {A B} `{PreciseSepLog A}, precise (EX x: B, FF).
Proof.
intros.
rewrite exp_FF.
apply FF_precise.
Qed.
Lemma precise_prop_andp: forall {A} `{PreciseSepLog A} P Q, (P \/ ~ P) -> (P -> precise Q) -> precise (!!P && Q).
Proof.
intros.
destruct H0.
+ apply precise_andp_right.
auto.
+ apply precise_andp_left.
apply derives_precise with FF; [| apply FF_precise].
apply prop_derives; auto.
Qed.
Lemma precise_exp_prop_andp: forall {A B} `{PreciseSepLog A} (P: B -> Prop) (Q: B -> A),
((exists x, P x) \/ (~ exists x, P x)) ->
(forall x, precise (Q x)) ->
(forall x y, P x -> P y -> Q x = Q y) ->
precise (EX x: B, !! P x && Q x).
Proof.
intros.
destruct H0 as [[x ?] | ?].
+ apply derives_precise with (Q x).
- apply exp_left; intro y.
normalize.
pose proof H2 _ _ H0 H3.
rewrite H4; auto.
- apply H1.
+ apply derives_precise with FF.
- normalize; intros x ?.
specialize (H0 (ex_intro _ x H3)); tauto.
- apply FF_precise.
Qed.
*)
Lemma exp_sepcon: forall {A} `{SepLog A} {B} (P Q: B -> A), exp (P * Q) |-- exp P * exp Q.
Proof.
intros.
apply exp_left; intro.
simpl.
apply sepcon_derives; apply (exp_right x); apply derives_refl.
Qed.
Lemma sepcon_wand_wand_sepcon: forall {A} `{SepLog A} (P Q R: A), (P -* Q) * R |-- P -* Q * R.
Proof.
intros.
rewrite <- wand_sepcon_adjoint.
rewrite (sepcon_comm _ P), <- sepcon_assoc.
apply sepcon_derives; auto.
apply modus_ponens_wand.
Qed.
(*
Lemma precise_left_sepcon_andp_sepcon: forall {A} `{PreciseSepLog A} P Q R, precise P -> (P * Q) && (P * R) |-- P * (Q && R).
Proof.
intros.
eapply derives_trans.
+ apply precise_left_sepcon_andp_distr with P; auto.
+ apply sepcon_derives; auto.
apply andp_left1; auto.
Qed.
Lemma precise_exp_sepcon: forall {A} `{PreciseSepLog A} {B} (P Q: B -> A), precise (exp P) -> precise (exp Q) -> precise (exp (P * Q)).
Proof.
intros.
eapply derives_precise.
+ apply exp_sepcon.
+ apply precise_sepcon; auto.
Qed.
Lemma emp_ocon: forall {A} `{OverlapSepLog A} P, ocon emp P = P.
Proof.
intros.
rewrite ocon_comm.
apply ocon_emp.
Qed.
Lemma ocon_andp_prop': forall {A} `{OverlapSepLog A} P Q R,
ocon (!!P && Q) R = !!P && ocon Q R.
Proof.
intros. rewrite ocon_comm. rewrite ocon_andp_prop. rewrite ocon_comm. auto.
Qed.
Lemma ocon_self: forall {A} {ND: NatDed A} {SL: SepLog A} {CLS: ClassicalSep A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} P, P |-- ocon P P.
Proof.
intros.
apply ocon_contain.
apply sepcon_TT.
Qed.
Lemma precise_ocon_self: forall {A} {ND: NatDed A} {SL: SepLog A} {CLS: ClassicalSep A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P, precise P -> P = ocon P P.
Proof.
intros.
apply precise_ocon_contain; auto.
Qed.
Lemma ocon_sepcon_cancel: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P Q, P * Q |-- ocon P (P * Q).
Proof.
intros.
apply ocon_contain.
apply sepcon_derives; auto.
apply TT_right.
Qed.
Lemma precise_ocon_sepcon_cancel: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P Q, precise P -> P * Q = ocon P (P * Q).
Proof.
intros.
apply precise_ocon_contain; auto.
apply sepcon_derives; auto.
apply TT_right.
Qed.
Lemma emp_disj: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P, disjointed emp P.
Proof.
intros.
apply disj_comm, disj_emp.
Qed.
Lemma disj_FF: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P, disjointed P FF.
Proof.
intros.
eapply disj_derives; [| | apply disj_emp].
apply derives_refl.
apply FF_left.
Qed.
Lemma FF_disj: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P, disjointed FF P.
Proof.
intros.
apply disj_comm, disj_FF.
Qed.
Lemma disj_ocon_left: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P Q R, disjointed Q P -> disjointed R P -> disjointed (ocon Q R) P.
Proof.
intros.
apply disj_comm.
apply disj_comm in H.
apply disj_comm in H0.
apply disj_ocon_right; auto.
Qed.
Lemma disj_sepcon_right: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P Q R, disjointed P Q -> disjointed P R -> disjointed P (Q * R).
Proof.
intros.
pose proof disj_ocon_right _ _ _ H H0.
eapply disj_derives; [apply derives_refl | | exact H1].
apply sepcon_ocon.
Qed.
Lemma disj_sepcon_left: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} P Q R, disjointed Q P -> disjointed R P -> disjointed (Q * R) P.
Proof.
intros.
apply disj_comm.
apply disj_comm in H.
apply disj_comm in H0.
apply disj_sepcon_right; auto.
Qed.
Lemma disj_prop_andp_left: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} (P: Prop) Q R, ({P} + {~ P}) -> (P -> disjointed Q R) -> disjointed ((!! P) && Q) R.
Proof.
intros.
destruct H.
+ apply H0 in p.
eapply disj_derives; [ | | exact p].
- apply andp_left2, derives_refl.
- apply derives_refl.
+ eapply disj_derives; [ | | apply FF_disj].
- apply andp_left1. normalize.
- apply derives_refl.
Qed.
Lemma disj_prop_andp_right: forall {A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {DSL: DisjointedSepLog A} (P: Prop) Q R, ({P} + {~ P}) -> (P -> disjointed R Q) -> disjointed R ((!! P) && Q).
Proof.
intros.
apply disj_comm.
apply disj_prop_andp_left; auto.
intros; apply disj_comm; auto.
Qed.
Lemma mapsto_precise: forall {Addr Val: Type} {AV: AbsAddr Addr Val} {A} {mapsto: Addr -> Val -> A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {MSL: MapstoSepLog AV mapsto} p v , precise (mapsto p v).
Proof.
intros.
eapply derives_precise; [| apply mapsto__precise].
apply (exp_right v).
apply derives_refl.
Qed.
Lemma disj_mapsto: forall {Addr Val: Type} {AV: AbsAddr Addr Val} {A} {mapsto: Addr -> Val -> A} {ND: NatDed A} {SL: SepLog A} {PSL: PreciseSepLog A} {OSL: OverlapSepLog A} {MSL: MapstoSepLog AV mapsto} {DSL: DisjointedSepLog A} {SMSL: StaticMapstoSepLog AV mapsto} p1 p2 v1 v2, addr_conflict p1 p2 = false -> disjointed (mapsto p1 v1) (mapsto p2 v2).
Proof.
intros.
eapply disj_derives; [| | apply disj_mapsto_]; eauto.
+ apply (exp_right v1). apply derives_refl.
+ apply (exp_right v2). apply derives_refl.
Qed.
Lemma corable_andp_ocon2 {A} `{CorableOverlapSepLog A}:
forall P Q R : A, corable P -> ocon (Q && P) R = P && (ocon Q R).
Proof.
intros. rewrite andp_comm. apply corable_andp_ocon1. auto.
Qed.
Lemma corable_ocon_andp1 {A} `{CorableOverlapSepLog A}:
forall P Q R : A, corable P -> ocon Q (P && R) = P && (ocon Q R).
Proof.
intros. rewrite ocon_comm. rewrite corable_andp_ocon1; auto. rewrite ocon_comm; auto.
Qed.
Lemma corable_ocon_andp2 {A} `{CorableOverlapSepLog A}:
forall P Q R : A, corable P -> ocon Q (R && P) = P && (ocon Q R).
Proof.
intros. rewrite ocon_comm. rewrite andp_comm. rewrite corable_andp_ocon1; auto. rewrite ocon_comm; auto.
Qed.
Lemma tri_sepcon_ocon {A} `{OverlapSepLog A}:
forall P Q R, P * Q * R |-- ocon (P * Q) (Q * R).
Proof.
intros.
eapply derives_trans; [| apply ocon_wand].
instantiate (1 := Q).
rewrite sepcon_assoc.
rewrite (sepcon_comm Q R).
rewrite <- sepcon_assoc.
repeat apply sepcon_derives; auto.
+ apply wand_sepcon_adjoint; auto.
+ apply wand_sepcon_adjoint; auto.
Qed.
Instance ocon_owand_CCC: forall A `{OverlapSepLog A}, CCCviaNatDed A ocon owand.
Proof.
intros.
constructor.
apply ocon_comm.
apply ocon_assoc.
apply owand_ocon_adjoint.
intros; apply ocon_derives; auto.
Defined.
Lemma exp_ocon1 {A} `{OverlapSepLog A}: forall B (p: B -> A) q, ocon (exp p) q = (exp (fun x => ocon (p x) q)).
Proof.
eapply CCC_exp_prod1.
apply ocon_owand_CCC.
Qed.
Lemma exp_ocon2 {A} `{OverlapSepLog A}: forall B (p: A) (q: B -> A) , ocon p (exp q) = exp (fun x => ocon p (q x)).
Proof.
eapply CCC_exp_prod2.
apply ocon_owand_CCC.
Qed.
*)
(* Can be moved into VST/msl/log_normalize. *)
Lemma CCC_expo_expo_comm': forall A prod expo {ND: NatDed A} {CCC: CCCviaNatDed A prod expo},
forall P Q R, (expo P (expo Q R)) |-- (expo Q (expo P R)).
Proof.
intros.
apply (proj1 (@CartesianClosedCat.adjoint _ _ _ _ _ CCC _ _ _)).
apply (proj1 (@CartesianClosedCat.adjoint _ _ _ _ _ CCC _ _ _)).
rewrite CartesianClosedCat.assoc by eauto.
rewrite (@CartesianClosedCat.comm _ _ _ _ _ CCC Q P).
rewrite <- CartesianClosedCat.assoc by eauto.
apply (proj2 (@CartesianClosedCat.adjoint _ _ _ _ _ CCC _ _ _)).
apply (proj2 (@CartesianClosedCat.adjoint _ _ _ _ _ CCC _ _ _)).
apply derives_refl.
Qed.
Lemma CCC_expo_expo_comm: forall A prod expo {ND: NatDed A} {CCC: CCCviaNatDed A prod expo},
forall P Q R, expo P (expo Q R) = expo Q (expo P R).
Proof.
intros; apply pred_ext; eapply CCC_expo_expo_comm'; eauto.
Qed.
Lemma wand_wand_comm: forall {A} `{SepLog A}, forall P Q R, P -* (Q -* R) = Q -* (P -* R).
Proof.
intros.
eapply CCC_expo_expo_comm.
exact (sepcon_wand_CCC _).
Qed.
Lemma sepcon_weaken: forall {A} {NA: NatDed A} {SA: SepLog A} (P Q R R': A),
R' |-- R ->
P |-- Q * R' ->
P |-- Q * R.
Proof.
intros.
eapply derives_trans; eauto.
apply sepcon_derives; auto.
Qed.
(*
Ltac normalize_overlap :=
repeat
match goal with
| |- context [ocon ?P (!!?Q && ?R)] => rewrite (ocon_andp_prop P Q R)
| |- context [ocon (!!?P && ?Q) ?R] => rewrite (ocon_andp_prop' P Q R)
| |- context [ocon (?P && ?Q) ?R] => rewrite (corable_andp_ocon1 P Q R) by (auto with norm)
| |- context [ocon ?Q (?P && ?R)] => rewrite (corable_ocon_andp1 P Q R) by (auto with norm)
| |- context [ocon (?Q && ?P) ?R] => rewrite (corable_andp_ocon2 P Q R) by (auto with norm)
| |- context [ocon ?Q (?R && ?P)] => rewrite (corable_ocon_andp2 P Q R) by (auto with norm)
| |- context [ocon (exp ?P) ?Q] => rewrite (exp_ocon1 _ P Q)
| |- context [ocon ?P (exp ?Q)] => rewrite (exp_ocon2 _ P Q)
| |- _ => eauto with typeclass_instances
end;
repeat rewrite <- andp_assoc;
try normalize.
*)
Lemma exp_emp: forall {A B} `{ClassicalSep B} (P: A -> B), EX x:A, P x * emp = EX x: A, P x.
Proof.
intros.
apply exp_congr.
intros.
rewrite sepcon_emp.
auto.
Qed.
|
From iris.base_logic Require Export bi.
From iris.bi Require Export bi.
Set Default Proof Using "Type".
Import bi base_logic.bi.uPred.
(** Derived laws for Iris-specific primitive connectives (own, valid).
This file does NOT unseal! *)
Module uPred.
Section derived.
Context {M : ucmraT}.
Implicit Types φ : Prop.
Implicit Types P Q : uPred M.
Implicit Types A : Type.
(* Force implicit argument M *)
Notation "P ⊢ Q" := (bi_entails (PROP:=uPredI M) P%I Q%I).
Notation "P ⊣⊢ Q" := (equiv (A:=uPredI M) P%I Q%I).
(** Propers *)
Global Instance uPred_valid_proper : Proper ((⊣⊢) ==> iff) (@uPred_valid M).
Proof. solve_proper. Qed.
Global Instance uPred_valid_mono : Proper ((⊢) ==> impl) (@uPred_valid M).
Proof. solve_proper. Qed.
Global Instance uPred_valid_flip_mono :
Proper (flip (⊢) ==> flip impl) (@uPred_valid M).
Proof. solve_proper. Qed.
Global Instance ownM_proper: Proper ((≡) ==> (⊣⊢)) (@uPred_ownM M) := ne_proper _.
Global Instance cmra_valid_proper {A : cmraT} :
Proper ((≡) ==> (⊣⊢)) (@uPred_cmra_valid M A) := ne_proper _.
(** Own and valid derived *)
Lemma persistently_cmra_valid_1 {A : cmraT} (a : A) : ✓ a ⊢ <pers> (✓ a : uPred M).
Proof. by rewrite {1}plainly_cmra_valid_1 plainly_elim_persistently. Qed.
Lemma intuitionistically_ownM (a : M) : CoreId a → □ uPred_ownM a ⊣⊢ uPred_ownM a.
Proof.
rewrite /bi_intuitionistically affine_affinely=>?; apply (anti_symm _);
[by rewrite persistently_elim|].
by rewrite {1}persistently_ownM_core core_id_core.
Qed.
Lemma ownM_invalid (a : M) : ¬ ✓{0} a → uPred_ownM a ⊢ False.
Proof. by intros; rewrite ownM_valid cmra_valid_elim. Qed.
Global Instance ownM_mono : Proper (flip (≼) ==> (⊢)) (@uPred_ownM M).
Proof. intros a b [b' ->]. by rewrite ownM_op sep_elim_l. Qed.
Lemma ownM_unit' : uPred_ownM ε ⊣⊢ True.
Proof. apply (anti_symm _); first by apply pure_intro. apply ownM_unit. Qed.
Lemma plainly_cmra_valid {A : cmraT} (a : A) : ■ ✓ a ⊣⊢ ✓ a.
Proof. apply (anti_symm _), plainly_cmra_valid_1. apply plainly_elim, _. Qed.
Lemma intuitionistically_cmra_valid {A : cmraT} (a : A) : □ ✓ a ⊣⊢ ✓ a.
Proof.
rewrite /bi_intuitionistically affine_affinely. intros; apply (anti_symm _);
first by rewrite persistently_elim.
apply:persistently_cmra_valid_1.
Qed.
Lemma bupd_ownM_update x y : x ~~> y → uPred_ownM x ⊢ |==> uPred_ownM y.
Proof.
intros; rewrite (bupd_ownM_updateP _ (y =)); last by apply cmra_update_updateP.
by apply bupd_mono, exist_elim=> y'; apply pure_elim_l=> ->.
Qed.
(** Timeless instances *)
Global Instance valid_timeless {A : cmraT} `{CmraDiscrete A} (a : A) :
Timeless (✓ a : uPred M)%I.
Proof. rewrite /Timeless !discrete_valid. apply (timeless _). Qed.
Global Instance ownM_timeless (a : M) : Discrete a → Timeless (uPred_ownM a).
Proof.
intros ?. rewrite /Timeless later_ownM. apply exist_elim=> b.
rewrite (timeless (a≡b)) (except_0_intro (uPred_ownM b)) -except_0_and.
apply except_0_mono. rewrite internal_eq_sym.
apply (internal_eq_rewrite' b a (uPred_ownM) _);
auto using and_elim_l, and_elim_r.
Qed.
(** Plainness *)
Global Instance cmra_valid_plain {A : cmraT} (a : A) :
Plain (✓ a : uPred M)%I.
Proof. rewrite /Persistent. apply plainly_cmra_valid_1. Qed.
(** Persistence *)
Global Instance cmra_valid_persistent {A : cmraT} (a : A) :
Persistent (✓ a : uPred M)%I.
Proof. rewrite /Persistent. apply persistently_cmra_valid_1. Qed.
Global Instance ownM_persistent a : CoreId a → Persistent (@uPred_ownM M a).
Proof.
intros. rewrite /Persistent -{2}(core_id_core a). apply persistently_ownM_core.
Qed.
(** For big ops *)
Global Instance uPred_ownM_sep_homomorphism :
MonoidHomomorphism op uPred_sep (≡) (@uPred_ownM M).
Proof. split; [split; try apply _|]. apply ownM_op. apply ownM_unit'. Qed.
(** Consistency/soundness statement *)
Lemma soundness φ n : (▷^n ⌜ φ ⌝ : uPred M)%I → φ.
Proof. rewrite laterN_iter. apply soundness_iter. Qed.
Corollary consistency_modal n : ¬ (▷^n False : uPred M)%I.
Proof. exact (soundness False n). Qed.
Corollary consistency : ¬(False : uPred M)%I.
Proof. exact (consistency_modal 0). Qed.
End derived.
End uPred.
|
\subsection{Illuminant and Surface Data Sources} \label{sec:coldata}
A useful guide to some of the existing datasets has been provided by \citet{kohonen_databases_2006}, though many of the links have rotted since publication. Additionally, some new datasets have become available, and some datasets that weren't included have become known to me. In this section I shall describe the datasets available for use in studies such as this.
\subsubsection{Daylight datasets}
It is standard practice (see for example \citet{barrionuevo_contributions_2014}) to use illuminants generated from CIE D-series formulae (see \gls{PTB} function `GenerateCIEDay') which are derived from data reported by \citet{judd_spectral_1964}. Whilst the D-series provides a good approximation of daylight spectra, empirical data better represents any link between chromaticity and luminance, and any bias in the likelihood of one spectrum occurring over another. It is thought that the original data of Judd et al. is no longer available \citep[p.~60]{maloney_computational_1984}. The first three principal components of the data are available through \gls{PTB} as `B\_cieday'.
\paragraph{Granada Data.}
The Granada daylight database \citep{hernandez-andres_color_2001} contains 2600 measurements of daylight taken over the course of two years at a single site in Granada, Spain. Data is recorded for 300-1100nm with a sampling interval of 5nm.\footnote{This data has been made available at \url{http://colorimaginglab.ugr.es/pages/Data}}
\paragraph{Other sources.}
The Parkkinen and Silfsten data described by \citet{kohonen_databases_2006}\footnote{Available at \url{http://cs.joensuu.fi/spectral/databases/download/daylight.htm}} comprises 14 measurements of daylight from afternoon and evening. The wavelength range is 390nm - 1070nm, with 4nm intervals.
The other potential sources of data, in addition to the \citet{judd_spectral_1964} data, do not seem to be currently available, but for completeness I provide them here: \citet{condit_spectral_1964, tarrant_spectral_1968, dicarlo_illuminant_2000, taylor_distribution_1941, henderson_spectral_1964, sastri_typical_1968, dixon_spectral_1978, sastri_spectral_1966,williams_statistical_2009,bui_group_2004}.
There are two authoritative reference books on the subject: \citet{henderson_daylight_1970,henderson_daylight_1977} (first and second editions) and \cite{robinson_solar_1966}. Also of interest may be \citet{minnaert_light_1993} (various editions), and \citet{lynch_color_2001} (various editions).
Two further datasets which are available only upon request are held by Dr Andrew Smedley of The Univesity of Manchester (320nm to 2800nm, since 2010, data collection ongoing) and Marina Khazova of Public Health England\footnote{Minimally described here: \url{https://uk-air.defra.gov.uk/research/ozone-uv/uv-uk-monitoring}} (350nm - 830nm, 1nm interval). It is hoped that these datasets may be made openly available at some point in the future.
Data specifically for dawn and dusk (with a small amount of data extending into what could be considered `daylight') is available from \citet{spitschan_variation_2016} as open access supplementary material from the journal publisher.
An interesting additional source of data may be the work of \citet{peyvandi_colorimetric_2016}, who simulate a very large number of daylight, sunlight and skylight spectra.
Finally, there is also a large corpus of information specifically about the light conditions in forest environments, although I have not had an opportunity to investigate whether collected datasets have been made available \citep{sumner_catarrhine_2000,chiao_characterization_2000,federer_spectral_1966,geiger_climate_2003,thery_forest_2001,xu_changes_2013,wang_real-time_2006,endler_color_1993,brinkmann_light_1971,de_castro_light_2000,freyman_spectral_1968,fassnacht_review_2016,blackburn_seasonal_1995}.
%hutchison_relighting_2009
\subsubsection{Surface Reflectance datasets}
\label{sec:surfs}
\paragraph{Krinov data.}
The Krinov data was originally published in 1947 \citep{krinov_spektralnaya_1947}, though it is now mainly accessed through a Canadian translation published a few years later \cite{krinov_spectral_1953}. It has recently been made available through \gls{PTB} \cite{brainard_psychophysics_1997} (as sur\_krinov.mat), and forms part of the SFU dataset \cite{barnard_data_2002}. It consists of 370 measurements of natural surfaces, measured at 9 locations around the USSR. It includes a large number of repeated measures (generally of objects at different angles), and has many measurements of objects which might be described as `background' surfaces rather than objects per se (e.g. soil, sand, turf). Measurements are available at a sampling interval of 10nm, mostly between 400 and 650nm, with some extending as far as 900nm, and some without data at parts of the range. The \gls{PTB} version of the data is a reduced set of 191 measurements, having excluded a number of measurements of various types of grass.
\paragraph{`Natural Colors' data.}
The `Natural Colors' data \citep{parkkinen_spectral_1988,jaaskelainen_vector-subspace_1990} was collected to allow investigators to explore how well reflectances could be represented by low dimensional models\footnote{It is available at: \url{http://www.uef.fi/web/spectral/natural-colors}}. The data consists of 219 reflectance spectra (though information provided by the authors suggests there should only be 218) of different leaves and flowers, between 400 and 700nm at a sampling interval of 5nm. It has recently been made available through \gls{PTB} (as sur\_koivisto.mat).
\paragraph{Vrhel et al. data.}
The \citet{vrhel_measurement_1994} data in its complete form comprised measurements of 64 Munsell chips, 120 Du Pont paint chips and 170 natural and non-natural objects. Similarly to the `Natural Colors' data, this data was again collected to allow investigations into the dimensionality of natural reflectance functions. The authors noted that they aimed to improve upon the Krinov data by decreasing the sampling interval (to 2nm), increasing the range of objects measured (and focusing on more object-like objects as opposed to background objects) and increasing the sampling range (to 390-730nm). To my knowledge only part of this set is currently available, as the FTP server referenced in the original publication is no longer accessible. The object reflectances alone are available through \gls{PTB} (as `sur\_vrhel.mat').
\paragraph{The Derby Set.}
One data-set which has been made available very recently is the data of \citet{cheung_colour_2000}. The website from where they are now available\footnote{\url{http://stephenwestland.co.uk/spectra/index.htm}} states that `The reflectance factors of 274 objects (mainly leaves) were collected directly using a Macbeth 7000A reflectance spectrophotometer with specular component included. Each object was measured front and back to create 494 spectra.' Unusually, photographs of each object measured are available from the same source. \citet{cheung_color_2004} describe this source as containing `leaves, petals, grasses and barks'.
\paragraph{Standard Object Colour Spectra Database for Colour Reproduction Evaluation (SOCS) data.}
This international standard \citep{tajima_development_1998,iso/tc_130_graphic_technology_iso/tr_2003} collates more than 50,000 spectral reflectances of a wide range of type of surfaces, grouped into several categories. The database was originally created in order to allow for the assessment of colour reproduction of image input devices. Unfortunately, this data proves very difficult to access, and as yet I have been unable to assess it.
\paragraph{NASA data.}
The NASA data-set \citep{david_e._bowker_spectral_1985} comprises 156 measurements of different terrains and materials, presented to aid in the design of remote imaging systems to optimally detect surfaces of interest and to detect changes over time in these surfaces where this is of interest (e.g. changes in spectral signatures that reveal growth or disease of specific crops). Data was not collected by the authors, but digitised from 58 different sources, and so range and interval are not consistent throughout the set. Whilst the authors seem to have devoted a great deal of energy and care to accurate digitisation, `digitisation' seems to be limited to the printing of tabulated values rather than provision of digital files (we've come a long way since 1985) and so any use of this data may need to start with an extended period of careful transcription. The surfaces chosen for this set are sensibly biased towards those of interest to remote sensing applications, and so use of this data in vision science would likely require careful consideration. It is expected that there may be other similar datasets tailored to the needs of remote sensing which may be available, should this type of data be appropriate.
\paragraph{Foster et al. hyperspectral images.}
The hyperspectral images of \citet{nascimento_statistics_2002} and \citet{foster_frequency_2006} provide nominal \glspl{SRF} for full natural and suburban scenes. This data is valuable and rich in many ways.
Notably, it can begin to represent the ubiquity/rarity of certain types of reflectances in the natural world, whereas the statistical distribution of surface variability in the abstracted databases so far considered is at the mercy of the collator. As Maloney puts it: ``in sampling spectral reflectances, we weight each spectral reflectance by its frequency of occurrence under whatever selection procedure we choose'' \cite{maloney_computational_1984}.
Additionally, the spatial inter-relationships between surfaces can be considered, which may be of particular value in trying to understand how an organism might operate under real-world conditions.
\begin{figure}[htbp]
\includegraphics[max width=\textwidth]{figs/LitRev/Foster.png}
\caption{A visualisation of the hyperspectral data for the first four images of the \citet{nascimento_statistics_2002} data. The other four available images are of non-natural environments.}
\label{fig:Foster}
\end{figure}
%In many ways hyperspectral images represent the ideal data for this type of experiment. They are much more closely linked to the real-world challenges faced by the human visual system in terms of statistical and spatial distribution of reflectances than data comprising abstracted spectral reflectances of a selected range of sampled surfaces. The statistical distribution of surface variability in an abstracted database is at the mercy of the collator, as Maloney puts it: ``in sampling spectral reflectances, we weight each spectral reflectance by its frequency of occurrence under whatever selection procedure we choose''\cite{maloney_computational_1984}. Of course the individual scenes still need to be selected in some way, with implicit assumptions about the goals of the human visual system being baked in at this stage (for example - should scenes include grassy landscapes and flora, trees laden with fruit, predators in hiding or human skin tones?).
%Using two-dimensional images would also allow for more advanced chromatic adaptation models to be considered, such as the group of algorithms based on Weijer et al.'s `Grey Edge' ideas \cite{weijer_edge-based_2007}.
However, caution must be taken when using such data; whilst the hyperspectral images available are nominally `reflectance' images, the way in which reflectance is computed may make them unsuitable for some uses. Reflectance is estimated from radiance images by assuming uniform illumination across the scene, which for some uses may be a particularly problematic simplification. This is an acceptably minor distinction for many use cases, but in this specific case this introduces error in precisely the place where it needs to be avoided. In considering the effectiveness of chromatic adaptation transforms the goal is to separate the effect of variable reflectance functions from variable power distributions, and the ability to do this is hindered if an element of the power distribution variability is baked into the reflectance functions.
%'Natural Minolta' %Note: referenced in kohonen_databases_2006 but I can't find anything else about it or access it anywhere
A final note here - whilst the use of spectral reflectance data from natural sources is often preferable to that from non-natural sources, it is possible that the careful use of non-natural data could be permitted following the finding of Maloney \cite{maloney_evaluation_1986} that basis elements derived from measurements of Munsell colour samples provide excellent fits to natural data (specifically, the Krinov data).
Going further, it may be possible in some cases to use entirely artificial data; \citet{chen_physical_2005} showed that an artificial dataset, generated following the physical constraints on real \glspl{SRF} (as discussed by \citet{nassau_physics_2001}), seems to strongly resemble real datasets. |
The translation $x \mapsto a + x$ is injective on any set $A$. |
{-# LANGUAGE FlexibleContexts #-}
module SentimentAnalysis where
import Numeric.LinearAlgebra as LA
import Data.Bifunctor (Bifunctor(bimap))
import Data.List.Split (splitOn)
hingeLossSingle :: (Ord a, Numeric a) => Vector a -> a -> Vector a -> a -> a
hingeLossSingle x y theta theta0 = max 0 (1 - y * (theta LA.<.> x + theta0))
hingeLossFull :: (Numeric a, Ord a, Num (Vector a), Fractional a) => Matrix a -> Vector a -> Vector a -> a -> a
hingeLossFull x y theta theta0 = loss
where
theta0s = size y |> repeat theta0
ones = size y |> repeat 1.0
agreement = y * (theta LA.<# LA.tr' x + theta0s)
losses = LA.cmap (max 0) (ones - agreement)
loss = sumElements losses / fromIntegral (size losses)
perceptronSingleStepUpdate :: (Ord b, Numeric b, Num (Vector b)) => Vector b -> b -> Vector b -> b -> (Vector b, b)
perceptronSingleStepUpdate x y theta theta0 =
if y * (theta LA.<.> x + theta0) <= 0
then (theta + (scalar y * x), theta0 + y)
else (theta, theta0)
perceptronUpdate :: (Ord t, Numeric t, Num (Vector t)) => [Vector t] -> [t] -> Vector t -> t -> [Int] -> (Vector t, t)
perceptronUpdate _ _ theta theta0 [] = (theta, theta0)
perceptronUpdate xs ys theta theta0 (z:zs) =
let (theta', theta0') = perceptronSingleStepUpdate (xs !! z) (ys !! z) theta theta0
in perceptronUpdate xs ys theta' theta0' zs
perceptron :: (Ord t, Numeric t, Num (Vector t)) => Matrix t -> Vector t -> Int -> [Int] -> (Vector t, t)
perceptron x y t indices = iterate step (cols x |> repeat 0, 0) !! t
where step (theta, theta0) = perceptronUpdate (toRows x) (toList y) theta theta0 indices
averagePerceptronUpdate :: (Ord t, Numeric t, Num (Vector t))
=> [Vector t] -> [t] -> Vector t -> t -> [Int] -> [(Vector t, t)]
averagePerceptronUpdate _ _ theta theta0 [] = []
averagePerceptronUpdate xs ys theta theta0 (z:zs) =
let (theta', theta0') = perceptronSingleStepUpdate (xs !! z) (ys !! z) theta theta0
in (theta', theta0') : averagePerceptronUpdate xs ys theta' theta0' zs
averagePerceptronList :: (Ord t, Numeric t, Num (Vector t)) => Matrix t -> Vector t -> [Int] -> [[(Vector t, t)]]
averagePerceptronList x y indices = iterate step [(cols x |> repeat 0, 0)]
where
step xs = averagePerceptronUpdate (toRows x) (toList y) theta theta0 indices
where (theta, theta0) = last xs
averagePerceptron :: (Fractional t, Ord t, Numeric t, Num (Vector t))
=> Matrix t -> Vector t -> Int -> [Int] -> (Vector t, t)
averagePerceptron x y t indices = (bimap ((/ scalar n) . sum) ((/ n) . sum) . unzip . concat) xss
where
n = fromIntegral $ t * rows x
xss = drop 1 $ take (t + 1) $ averagePerceptronList x y indices
pegasosSingleStepUpdate :: (Ord e, Numeric e, Num (Vector e)) => Vector e -> e -> e -> e -> Vector e -> e -> (Vector e, e)
pegasosSingleStepUpdate x y lambda eta theta theta0 =
if y * (theta LA.<.> x + theta0) <= 1
then
(scalar (1 - eta * lambda) * theta + scalar (eta * y) * x, theta0 + eta * y)
else
(scalar (1 - eta * lambda) * theta, theta0)
pegasosUpdate :: (Ord t, Numeric t, Num (Vector t), Floating t)
=> [Vector t] -> [t] -> t -> t -> Vector t -> t -> [Int] -> (Vector t, t, t)
pegasosUpdate _ _ lambda i theta theta0 [] = (theta, theta0, i)
pegasosUpdate xs ys lambda i theta theta0 (z:zs) =
let (theta', theta0') = pegasosSingleStepUpdate (xs !! z) (ys !! z) lambda (1 / sqrt i) theta theta0
in pegasosUpdate xs ys lambda (i + 1) theta' theta0' zs
pegasos :: (Ord t, Numeric t, Floating t, Num (Vector t)) => Matrix t -> Vector t -> Int -> t -> [Int] -> (Vector t, t)
pegasos x y t lambda indices = (theta', theta0')
where
(theta', theta0', i') = iterate step (cols x |> repeat 0, 0, 1.0) !! t
step (theta, theta0, i) = pegasosUpdate (toRows x) (toList y) lambda i theta theta0 indices
main :: IO ()
main = do
dta <- loadMatrix "toy_data.tsv"
orderDta <- readFile "200.txt"
let t = 10
let lambda = 0.2
let x = dta ¿ [1, 2]
let y = flatten $ dta ¿ [0]
let indices = map read $ splitOn "," orderDta
let (theta, theta0) = perceptron x y t indices
putStrLn "Perceptron:"
print theta
print theta0
let (theta, theta0) = averagePerceptron x y t indices
putStrLn "Average Perceptron:"
print theta
print theta0
let (theta, theta0) = pegasos x y t lambda indices
putStrLn "Pegasos:"
print theta
print theta0
|
//////////////////////////////////////////////////////////////////////////////
// cross_validation::include.hpp //
// //
// (C) Copyright 2009 Erwann Rogard //
// Use, modification and distribution are subject to the //
// Boost Software License, Version 1.0. (See accompanying file //
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_INCLUDE_HPP_ER_2009
#define BOOST_STATISTICS_DETAIL_CROSS_VALIDATION_INCLUDE_HPP_ER_2009
#include <boost/statistics/detail/cross_validation/algorithm/include.hpp>
#include <boost/statistics/detail/cross_validation/data/include.hpp>
#include <boost/statistics/detail/cross_validation/functional/include.hpp>
#endif |
(*
File: AbGroup.thy
Author: Bohua Zhan
Abelian groups.
*)
theory AbGroup
imports AlgStructure
begin
section \<open>Monoids\<close>
definition is_ab_monoid :: "i \<Rightarrow> o" where [rewrite]:
"is_ab_monoid(G) \<longleftrightarrow> (is_abgroup_raw(G) \<and> is_add_id(G) \<and> is_plus_comm(G) \<and> is_plus_assoc(G))"
lemma is_ab_monoidD [forward]:
"is_ab_monoid(G) \<Longrightarrow> is_abgroup_raw(G)"
"is_ab_monoid(G) \<Longrightarrow> is_add_id(G)"
"is_ab_monoid(G) \<Longrightarrow> is_plus_comm(G)"
"is_ab_monoid(G) \<Longrightarrow> is_plus_assoc(G)" by auto2+
setup {* del_prfstep_thm_eqforward @{thm is_ab_monoid_def} *}
lemma is_ab_monoid_abgroup_prop [forward]:
"is_abgroup_raw(H) \<Longrightarrow> is_ab_monoid(G) \<Longrightarrow> eq_str_abgroup(G,H) \<Longrightarrow> is_ab_monoid(H)" by auto2
section \<open>Abelian groups\<close>
definition has_add_inverse :: "i \<Rightarrow> o" where [rewrite]:
"has_add_inverse(G) \<longleftrightarrow> (\<forall>x\<in>.G. \<exists>y\<in>.G. x +\<^sub>G y = \<zero>\<^sub>G)"
lemma has_add_inverseD [backward]:
"has_add_inverse(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> \<exists>y\<in>.G. x +\<^sub>G y = \<zero>\<^sub>G" by auto2
lemma has_add_inverseI [backward1]:
"unary_fun(carrier(G),f) \<Longrightarrow> \<forall>x\<in>.G. x +\<^sub>G f(x) = \<zero>\<^sub>G \<Longrightarrow> has_add_inverse(G)" by auto2
setup {* del_prfstep_thm @{thm has_add_inverse_def} *}
lemma has_add_inverse_abgroup_prop [forward]:
"is_abgroup_raw(H) \<Longrightarrow> has_add_inverse(G) \<Longrightarrow> eq_str_abgroup(G,H) \<Longrightarrow> has_add_inverse(H)"
@proof @have "\<forall>x\<in>.H. x +\<^sub>H (SOME y\<in>.G. x +\<^sub>G y = \<zero>\<^sub>G) = \<zero>\<^sub>H" @qed
definition is_abgroup :: "i \<Rightarrow> o" where [rewrite]:
"is_abgroup(G) \<longleftrightarrow> (is_ab_monoid(G) \<and> has_add_inverse(G))"
lemma is_abgroupD [forward]:
"is_abgroup(G) \<Longrightarrow> is_ab_monoid(G)"
"is_abgroup(G) \<Longrightarrow> has_add_inverse(G)" by auto2+
setup {* del_prfstep_thm_eqforward @{thm is_abgroup_def} *}
lemma is_abgroup_abgroup_prop [forward]:
"is_abgroup_raw(H) \<Longrightarrow> is_abgroup(G) \<Longrightarrow> eq_str_abgroup(G,H) \<Longrightarrow> is_abgroup(H)" by auto2
section \<open>Negation and subtraction\<close>
setup {* fold add_rewrite_rule [@{thm plus_commD}, @{thm plus_assoc_left}] *}
lemma has_left_inverse [backward]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> \<exists>y\<in>.G. y +\<^sub>G x = \<zero>\<^sub>G"
@proof @obtain "y\<in>.G" where "x +\<^sub>G y = \<zero>\<^sub>G" @qed
lemma add_cancel_left [forward]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> z \<in>. G \<Longrightarrow> x +\<^sub>G y = x +\<^sub>G z \<Longrightarrow> y = z"
@proof @obtain "x'\<in>.G" where "x' +\<^sub>G x = \<zero>\<^sub>G" @have "x' +\<^sub>G (x +\<^sub>G y) = y" @qed
lemma add_cancel_right [forward]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> z \<in>. G \<Longrightarrow> y +\<^sub>G x = z +\<^sub>G x \<Longrightarrow> y = z" by auto2
definition neg :: "i \<Rightarrow> i \<Rightarrow> i" ("-\<^sub>_ _" [81,81] 80) where [rewrite]:
"-\<^sub>G x = (THE y. y \<in>. G \<and> x +\<^sub>G y = \<zero>\<^sub>G)"
setup {* register_wellform_data ("-\<^sub>G x", ["x \<in>. G"]) *}
lemma abgroup_neg_type [typing]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> -\<^sub>G x \<in>. G" by auto2
lemma abgroup_neg_left [rewrite]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> -\<^sub>G x +\<^sub>G x = \<zero>\<^sub>G" by auto2
lemma abgroup_neg_right [rewrite]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> x +\<^sub>G -\<^sub>G x = \<zero>\<^sub>G" by auto2
lemma abgroup_neg_unique [forward]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> x +\<^sub>G -\<^sub>G y = \<zero>\<^sub>G \<Longrightarrow> x = y" by auto2
lemma abgroup_neg_eq [resolve]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> x +\<^sub>G y = \<zero>\<^sub>G \<Longrightarrow> -\<^sub>G x = y"
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> y +\<^sub>G x = \<zero>\<^sub>G \<Longrightarrow> -\<^sub>G x = y"
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> x +\<^sub>G y = \<zero>\<^sub>G \<Longrightarrow> y = -\<^sub>G x"
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> y +\<^sub>G x = \<zero>\<^sub>G \<Longrightarrow> y = -\<^sub>G x" by auto2+
lemma neg_abgroup_fun [rewrite]:
"is_abgroup_raw(H) \<Longrightarrow> is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> eq_str_abgroup(G,H) \<Longrightarrow> -\<^sub>G x = -\<^sub>H x" by auto2
lemma abgroup_neg_zero [rewrite]:
"is_abgroup(G) \<Longrightarrow> -\<^sub>G(\<zero>\<^sub>G) = \<zero>\<^sub>G" by auto2
lemma abgroup_neg_zero_back [forward]:
"is_abgroup(G) \<Longrightarrow> a \<in>. G \<Longrightarrow> -\<^sub>G a = \<zero>\<^sub>G \<Longrightarrow> a = \<zero>\<^sub>G" by auto2
lemma abgroup_neg_neg [rewrite]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> -\<^sub>G (-\<^sub>G x) = x" by auto2
setup {* del_prfstep_thm @{thm neg_def} *}
lemma abgroup_neg_distrib:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> -\<^sub>G (x +\<^sub>G y) = -\<^sub>G x +\<^sub>G -\<^sub>G y \<and> -\<^sub>G x \<in>. G \<and> -\<^sub>G y \<in>. G"
@proof @have "(x +\<^sub>G y) +\<^sub>G (-\<^sub>G x +\<^sub>G -\<^sub>G y) = \<zero>\<^sub>G" @qed
lemma abgroup_neg_distrib':
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> -\<^sub>G x +\<^sub>G -\<^sub>G y = -\<^sub>G (x +\<^sub>G y) \<and> x +\<^sub>G y \<in>. G"
@proof @have "(x +\<^sub>G y) +\<^sub>G (-\<^sub>G x +\<^sub>G -\<^sub>G y) = \<zero>\<^sub>G" @qed
lemma abgroup_neg_inj [forward]: "is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> -\<^sub>G x = -\<^sub>G y \<Longrightarrow> x = y"
@proof @have "x = -\<^sub>G (-\<^sub>G x)" @qed
definition minus :: "i \<Rightarrow> i \<Rightarrow> i \<Rightarrow> i" where [rewrite]:
"minus(G,x,y) = (THE z. z \<in>. G \<and> z +\<^sub>G y = x)"
abbreviation minus_notation ("(_/ -\<^sub>_ _)" [65,65,66] 65) where "x -\<^sub>G y \<equiv> minus(G,x,y)"
setup {* register_wellform_data ("x -\<^sub>G y", ["x \<in>. G", "y \<in>. G"]) *}
lemma minusI:
"z \<in>. G \<Longrightarrow> z +\<^sub>G y = x \<Longrightarrow> \<forall>z'\<in>.G. z' +\<^sub>G y = x \<longrightarrow> z' = z \<Longrightarrow> minus(G,x,y) = z" by auto2
lemma minus_exist [backward2]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> \<exists>z\<in>.G. z +\<^sub>G y = x"
@proof @have "(x +\<^sub>G (-\<^sub>G y)) +\<^sub>G y = x" @qed
lemma minus_type [typing]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> x -\<^sub>G y \<in>. G" by auto2
lemma minusD [rewrite]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> x -\<^sub>G y = x +\<^sub>G -\<^sub>G y \<and> -\<^sub>G y \<in>. G" by auto2
setup {* del_prfstep_thm @{thm minus_def} *}
lemma minus_abgroup_fun [rewrite]:
"is_abgroup_raw(H) \<Longrightarrow> is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow>
eq_str_abgroup(G,H) \<Longrightarrow> x -\<^sub>G y = x -\<^sub>H y"
@proof @have "x -\<^sub>G y = x +\<^sub>G -\<^sub>G y" @qed
setup {* fold del_prfstep_thm [@{thm plus_commD}, @{thm plus_assoc_left}, @{thm minusD}] *}
ML_file "alg_abgroup.ML"
lemma minus_zero [rewrite]: "is_abgroup(R) \<Longrightarrow> a \<in>. R \<Longrightarrow> a -\<^sub>R \<zero>\<^sub>R = a" by auto2
lemma minus_same_eq_zero [rewrite]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> x -\<^sub>G x = \<zero>\<^sub>G" by auto2
lemma minus_eq_zero_same [forward]:
"is_abgroup(G) \<Longrightarrow> x \<in>. G \<Longrightarrow> y \<in>. G \<Longrightarrow> x -\<^sub>G y = \<zero>\<^sub>G \<Longrightarrow> x = y"
@proof @have "x -\<^sub>G y = x +\<^sub>G -\<^sub>G y" @qed
section \<open>Subset of an abelian group\<close>
definition nonzero_elts :: "i \<Rightarrow> i" where [rewrite]:
"nonzero_elts(R) = {x\<in>.R. x \<noteq> \<zero>\<^sub>R}"
lemma nonzero_eltsD [forward]: "x \<in> nonzero_elts(R) \<Longrightarrow> x \<in>. R \<and> x \<noteq> \<zero>\<^sub>R" by auto2
lemma nonzero_eltsI [backward2]: "x \<in>. R \<Longrightarrow> x \<noteq> \<zero>\<^sub>R \<Longrightarrow> x \<in> nonzero_elts(R)" by auto2
end
|
// (C) Copyright John Maddock 2006.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "test_1F0.hpp"
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
BOOST_AUTO_TEST_CASE( test_main )
{
#ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
test_spots(0.0F);
#endif
test_spots(0.0);
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test_spots(0.0L);
#ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
test_spots(boost::math::concepts::real_concept(0.1));
#endif
#endif
test_spots(boost::multiprecision::cpp_bin_float_quad());
test_spots(boost::multiprecision::cpp_dec_float_50());
}
|
// Distributed under the MIT License.
// See LICENSE.txt for details.
#pragma once
#include <algorithm>
#include <array>
#include <boost/functional/hash.hpp>
#include <cstddef>
#include <functional>
#include <tuple>
#include <type_traits>
#include <utility> // IWYU pragma: keep // for std::forward
#include "DataStructures/DataBox/DataBoxTag.hpp"
#include "DataStructures/DataBox/PrefixHelpers.hpp"
#include "DataStructures/DataBox/Prefixes.hpp"
#include "DataStructures/Matrix.hpp"
#include "DataStructures/Variables.hpp"
#include "Domain/Direction.hpp"
#include "Domain/ElementId.hpp"
#include "Domain/Mesh.hpp"
#include "ErrorHandling/Assert.hpp"
#include "NumericalAlgorithms/DiscontinuousGalerkin/LiftFlux.hpp"
#include "NumericalAlgorithms/LinearOperators/ApplyMatrices.hpp"
#include "NumericalAlgorithms/Spectral/Projection.hpp"
#include "Utilities/Algorithm.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeArray.hpp"
#include "Utilities/TMPL.hpp"
/// \cond
template <size_t VolumeDim>
class ElementId;
template <size_t VolumeDim>
class OrientationMap;
// IWYU pragma: no_forward_declare Variables
/// \endcond
namespace dg {
template <size_t VolumeDim>
using MortarId = std::pair<::Direction<VolumeDim>, ElementId<VolumeDim>>;
template <size_t MortarDim>
using MortarSize = std::array<Spectral::MortarSize, MortarDim>;
template <size_t VolumeDim, typename ValueType>
using MortarMap = std::unordered_map<MortarId<VolumeDim>, ValueType,
boost::hash<MortarId<VolumeDim>>>;
/// \ingroup DiscontinuousGalerkinGroup
/// Find a mesh for a mortar capable of representing data from either
/// of two faces.
template <size_t Dim>
Mesh<Dim> mortar_mesh(const Mesh<Dim>& face_mesh1,
const Mesh<Dim>& face_mesh2) noexcept;
/// \ingroup DiscontinuousGalerkinGroup
/// Determine the size of the mortar (i.e., the part of the face it
/// covers) for communicating with a neighbor. This is the size
/// relative to the size of \p self, and will not generally agree with
/// that determined by \p neighbor.
template <size_t Dim>
MortarSize<Dim - 1> mortar_size(
const ElementId<Dim>& self, const ElementId<Dim>& neighbor,
size_t dimension, const OrientationMap<Dim>& orientation) noexcept;
/// \ingroup DiscontinuousGalerkinGroup
/// Determine whether data on an element face needs to be projected to a mortar.
/// If no projection is necessary the data may be used on the mortar as-is.
template <size_t Dim>
bool needs_projection(const Mesh<Dim>& face_mesh, const Mesh<Dim>& mortar_mesh,
const MortarSize<Dim>& mortar_size) noexcept {
return mortar_mesh != face_mesh or
alg::any_of(mortar_size, [](const Spectral::MortarSize& size) noexcept {
return size != Spectral::MortarSize::Full;
});
}
/// \ingroup DiscontinuousGalerkinGroup
/// Project variables from a face to a mortar.
template <typename Tags, size_t Dim>
Variables<Tags> project_to_mortar(const Variables<Tags>& vars,
const Mesh<Dim>& face_mesh,
const Mesh<Dim>& mortar_mesh,
const MortarSize<Dim>& mortar_size) noexcept {
const Matrix identity{};
auto projection_matrices = make_array<Dim>(std::cref(identity));
const auto face_slice_meshes = face_mesh.slices();
const auto mortar_slice_meshes = mortar_mesh.slices();
for (size_t i = 0; i < Dim; ++i) {
const auto& face_slice_mesh = gsl::at(face_slice_meshes, i);
const auto& mortar_slice_mesh = gsl::at(mortar_slice_meshes, i);
const auto& slice_size = gsl::at(mortar_size, i);
if (slice_size != Spectral::MortarSize::Full or
face_slice_mesh != mortar_slice_mesh) {
gsl::at(projection_matrices, i) = projection_matrix_element_to_mortar(
slice_size, mortar_slice_mesh, face_slice_mesh);
}
}
return apply_matrices(projection_matrices, vars, face_mesh.extents());
}
/// \ingroup DiscontinuousGalerkinGroup
/// Project variables from a mortar to a face.
template <typename Tags, size_t Dim>
Variables<Tags> project_from_mortar(
const Variables<Tags>& vars, const Mesh<Dim>& face_mesh,
const Mesh<Dim>& mortar_mesh, const MortarSize<Dim>& mortar_size) noexcept {
ASSERT(face_mesh != mortar_mesh or
alg::any_of(mortar_size,
[](const Spectral::MortarSize& size) noexcept {
return size != Spectral::MortarSize::Full;
}),
"project_from_mortar should not be called if the interface mesh and "
"mortar mesh are identical. Please elide the copy instead.");
const Matrix identity{};
auto projection_matrices = make_array<Dim>(std::cref(identity));
const auto face_slice_meshes = face_mesh.slices();
const auto mortar_slice_meshes = mortar_mesh.slices();
for (size_t i = 0; i < Dim; ++i) {
const auto& face_slice_mesh = gsl::at(face_slice_meshes, i);
const auto& mortar_slice_mesh = gsl::at(mortar_slice_meshes, i);
const auto& slice_size = gsl::at(mortar_size, i);
if (slice_size != Spectral::MortarSize::Full or
face_slice_mesh != mortar_slice_mesh) {
gsl::at(projection_matrices, i) = projection_matrix_mortar_to_element(
slice_size, face_slice_mesh, mortar_slice_mesh);
}
}
return apply_matrices(projection_matrices, vars, mortar_mesh.extents());
}
namespace MortarHelpers_detail {
template <typename NormalDotNumericalFluxComputer,
typename... NumericalFluxTags, typename... SelfTags,
typename... PackagedTags>
void apply_normal_dot_numerical_flux(
const gsl::not_null<Variables<tmpl::list<NumericalFluxTags...>>*>
numerical_fluxes,
const NormalDotNumericalFluxComputer& normal_dot_numerical_flux_computer,
const Variables<tmpl::list<SelfTags...>>& self_packaged_data,
const Variables<tmpl::list<PackagedTags...>>&
neighbor_packaged_data) noexcept {
normal_dot_numerical_flux_computer(
make_not_null(&get<NumericalFluxTags>(*numerical_fluxes))...,
get<PackagedTags>(self_packaged_data)...,
get<PackagedTags>(neighbor_packaged_data)...);
}
} // namespace MortarHelpers_detail
/// \ingroup DiscontinuousGalerkinGroup
/// Compute the lifted data resulting from computing the numerical flux.
///
/// \details
/// This applies the numerical flux, projects the result to the face
/// mesh if necessary, and then lifts it to the volume (still
/// presented only on the face mesh as all other points are zero).
///
/// Projection must happen after the numerical flux calculation so
/// that the elements on either side of the mortar calculate the same
/// result. Projection must happen before flux lifting because we
/// want the factor of the magnitude of the unit normal added during
/// the lift to cancel the Jacobian factor in integrals to preserve
/// conservation; this only happens if the two operations are done on
/// the same grid.
template <typename FluxCommTypes, typename NormalDotNumericalFluxComputer,
size_t Dim, typename LocalData>
auto compute_boundary_flux_contribution(
const NormalDotNumericalFluxComputer& normal_dot_numerical_flux_computer,
LocalData&& local_data,
const typename FluxCommTypes::PackagedData& remote_data,
const Mesh<Dim>& face_mesh, const Mesh<Dim>& mortar_mesh,
const size_t extent_perpendicular_to_boundary,
const MortarSize<Dim>& mortar_size) noexcept
-> db::const_item_type<
db::remove_tag_prefix<typename FluxCommTypes::normal_dot_fluxes_tag>> {
static_assert(std::is_same_v<std::decay_t<LocalData>,
typename FluxCommTypes::LocalData>,
"Second argument must be a FluxCommTypes::LocalData");
using variables_tag =
db::remove_tag_prefix<typename FluxCommTypes::normal_dot_fluxes_tag>;
db::const_item_type<db::add_tag_prefix<Tags::NormalDotNumericalFlux,
variables_tag>>
normal_dot_numerical_fluxes(mortar_mesh.number_of_grid_points(), 0.0);
MortarHelpers_detail::apply_normal_dot_numerical_flux(
make_not_null(&normal_dot_numerical_fluxes),
normal_dot_numerical_flux_computer, local_data.mortar_data, remote_data);
tmpl::for_each<db::get_variables_tags_list<variables_tag>>(
[&normal_dot_numerical_fluxes, &local_data](const auto tag) noexcept {
using Tag = tmpl::type_from<decltype(tag)>;
auto& numerical_flux =
get<Tags::NormalDotNumericalFlux<Tag>>(normal_dot_numerical_fluxes);
const auto& local_flux =
get<Tags::NormalDotFlux<Tag>>(local_data.mortar_data);
for (size_t i = 0; i < numerical_flux.size(); ++i) {
numerical_flux[i] -= local_flux[i];
}
});
const bool refining =
face_mesh != mortar_mesh or
std::any_of(mortar_size.begin(), mortar_size.end(),
[](const Spectral::MortarSize s) noexcept {
return s != Spectral::MortarSize::Full;
});
return dg::lift_flux(
refining ? project_from_mortar(normal_dot_numerical_fluxes, face_mesh,
mortar_mesh, mortar_size)
: std::move(normal_dot_numerical_fluxes),
extent_perpendicular_to_boundary,
std::forward<LocalData>(local_data).magnitude_of_face_normal);
}
} // namespace dg
|
%% PRIME_BATCH_ITHACA uses the BATCH command to run the PRIME code on the VT ITHACA cluster.
%
% Discussion:
%
% The PRIME code is a function, so first we must write a script
% called PRIME_SCRIPT that runs the function.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 01 April 2010
%
% Author:
%
% John Burkardt
%
clear
fprintf ( 1, '\n' );
fprintf ( 1, 'PRIME_BATCH_ITHACA:\n' );
fprintf ( 1, ' Run PRIME_SCRIPT on Ithaca.\n' );
%
% The BATCH command sends the script for execution.
%
my_job = batch ( 'prime_script', ...
'Configuration', 'ithaca_2009b', ...
'CaptureDiary', true, ...
'FileDependencies', { 'prime_fun' }, ...
'CurrentDirectory', '/home/burkardt/matlab', ...
'matlabpool', 4 );
%
% WAIT pauses the MATLAB session til the job completes.
%
wait ( my_job );
%
% DIARY displays any messages printed during execution.
%
diary ( my_job );
%
% LOAD makes the script's workspace available.
%
% total = total number of primes.
%
load ( my_job );
fprintf ( 1, '\n' );
fprintf ( 1, ' Total number of primes = %d\n', total );
%
% DESTROY cleans up data about the job we no longer need.
%
destroy ( my_job );
fprintf ( 1, '\n' );
fprintf ( 1, 'PRIME_BATCH_ITHACA:\n' );
fprintf ( 1, ' Normal end of execution.\n' ); |
function [Y] = mci_ramsay_gen (P,M,U)
% Generate data from Ramsay model
% FORMAT [Y] = mci_ramsay_gen (P,M,U)
%
% P Parameters
% M Model structure
% U Inputs
%
% Y Data
%__________________________________________________________________________
% Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging
% Will Penny
% $Id: mci_ramsay_gen.m 6548 2015-09-11 12:39:47Z will $
[G,x] = spm_mci_fwd (P,M,U);
[N,l] = size(G);
e = randn(N,l)*sqrt(M.Ce);
Y = G + e;
|
///////////////////////////////////////////////////////////////////////////////////////
// distribution::survival::models::importance_sampling::log_ratio_pdf_statistics.hpp //
// //
// Copyright 2009 Erwann Rogard. Distributed under the Boost //
// Software License, Version 1.0. (See accompanying file //
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
///////////////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_STATISTICS_DETAIL_DISTRIBUTION_SURVIVAL_MODELS_IMPORTANCE_SAMPLING_LOG_RATIO_PDF_STATISTICS_HPP_ER_2009
#define BOOST_STATISTICS_DETAIL_DISTRIBUTION_SURVIVAL_MODELS_IMPORTANCE_SAMPLING_LOG_RATIO_PDF_STATISTICS_HPP_ER_2009
#include <boost/fusion/include/make_map.hpp>
#include <boost/statistics/detail/importance_sampling/statistics/percentage_effective_sample_size.hpp> //
#include <boost/statistics/detail/math/constant/shortcut.hpp>
namespace boost{
namespace statistics{
namespace detail{
namespace distribution{
namespace survival{
template<typename T>
struct log_ratio_pdf_statistics{
typedef accumulator::tag::percentage_effective_sample_size tag_ess_;
typedef accumulator::tag::proportion_less_than tag_plt_;
typedef boost::accumulators::stats<tag_ess_,tag_plt_> stats_;
typedef boost::accumulators::accumulator_set<T,stats_> acc_;
public:
log_ratio_pdf_statistics(){}
template<typename It_w,typename T1>
void operator()(It_w b_w,It_w e_w,const T1& eps)
{
typedef T val_;
acc_ a = std::for_each(
b_w,
e_w,
acc_(( accumulator::keyword::threshold = eps ))
);
this->ess_ = boost::accumulators::extract_result<tag_ess_>(a);
this->plt_ = boost::accumulators::extract_result<tag_plt_>(a);
}
template<typename It_w,typename T1>
void operator()(It_w b_w,It_w e_w){
return (*this)(b_w,e_w,boost::math::tools::epsilon<T>());
}
T ess()const{ return this->ess_; }
T percent_lt_eps()const{ return this->plt_; }
private:
T ess_,plt_;
};
}// survival
}// distribution
}// detail
}// statistics
}// boost
#endif |
We are reserving seats on a Southwest non-stop flight from LAX to Reno on the afternoon of Thursday April 25th. We anticipate students will board the buses for the airport after lunch. We will return to Los Angeles early afternoon on Sunday, April 28th. The anticipated cost of the trip will be APPROXIMATELY $600.00 per student. In past years the price included round-trip airfare, 3 nights’ hotel accommodations at Circus Circus, festival fees, 2 full breakfasts, transportation in Reno, Mr. Steiner and parent chaperones. Booking early will allow us to get the best rate possible and save us all money.
• Please fill out the form on the second page and include the $200.00 deposit payable to PVPHS Jazz Band and send it with your student by Friday November 2, 2012.
• An additional installment of $200.00 will be due in January, and a final payment by Friday February 22, 2013. |
module HelloWorld
export
hello : String
hello = "Goodbye, Mars!"
export
version : String
version = "1.0.0"
|
# License
https://raw.githubusercontent.com/computational-sediment-hyd/a-rudimentary-knowledge-of-river-bed-variation/master/LICENSE
# import module
```python
import numpy as np
import pandas as pd
import numba
import sys
import os
import json
import glob as glob
```
# Governing Equation of River flow
\begin{align}
\frac{\partial A}{\partial t}+\frac{\partial Q}{\partial x} = 0 \\
\end{align}
\begin{align}
\frac{\partial Q}{\partial t}+\frac{\partial}{\partial x}\left(\frac{ Q^2}{ A}\right) + gA\frac{\partial H}{\partial x}+gAi_e = 0
\end{align}
```python
@numba.jit(nopython=True, parallel=False)
def flowmodel(A, Q, Adown, Qup, dAb, zb, B, dx, dt, g, manning):
imax = len(A)
Anew, Qnew = np.zeros(imax), np.zeros(imax)
# continuous equation
for i in numba.prange(1, imax-1) : Anew[i] = A[i] - dt * ( Q[i] - Q[i-1] ) / dx
Anew[0], Anew[-1] = Anew[1], Adown
# moumentum equation
for i in numba.prange(1,imax-1):
ip, ic, im = (i+1, i, i-1)
Cr1 = 0.5*( Q[ic]/A[ic] + Q[ip]/A[ip] )*dt/dx
Cr2 = 0.5*( Q[ic]/A[ic] + Q[im]/A[im] )*dt/dx
dHdx1 = ( Anew[ip]/B[ip] + zb[ip] + dAb[ip]/B[ip] - Anew[ic]/B[ic] - zb[ic] - dAb[ic]/B[ic] ) / dx
dHdx2 = ( Anew[ic]/B[ic] + zb[ic] + dAb[ic]/B[ic] - Anew[im]/B[im] - zb[im] - dAb[im]/B[im] ) / dx
dHdx = (1.0 - Cr1) * dHdx1 + Cr2 * dHdx2
Qnew[ic] = Q[ic] - dt * ( Q[ic]**2/A[ic] - Q[im]**2/A[im] ) / dx \
- dt * g * Anew[ic] * dHdx \
- dt * g * A[ic] * manning**2 * Q[ic]**2 / B[ic]**2 / ( A[ic]/B[ic] )**(10.0/3.0)
Qnew[0], Qnew[-1] = Qup, Qnew[-2]
return Anew, Qnew
```
# Governing Equation of River Bed : Hirano model
\begin{align}
(1-\lambda)\frac{\partial A_{b}}{\partial t}+\frac{\partial }{\partial x} \sum_{i=1}^n ( Q_{bi}P_i)= 0 \\
\end{align}
\begin{align}
\frac{\partial P_i}{\partial t} &= - \frac{1}{(1-\lambda)E_dB} \frac{\partial (Q_{bi}P_i)}{\partial x} - \frac{P_{si}}{E_d B}\frac{\partial A_b}{\partial t} \\
&= - \frac{1}{E_d B}\left(\frac{\partial A_{bi}}{\partial t} + P_{si}\frac{\partial A_b}{\partial t}\right)
\end{align}
\begin{align}
&P_{si} =
\left\{ \begin{array}{ll}
P_i \mbox{ in exchange layer} & \left(\dfrac{\partial A_b}{\partial t} > 0 \right) \\
P_i \mbox{ under exchange layer} & \left(\dfrac{\partial A_b}{\partial t} < 0 \right) \\
\end{array} \right. \\
\end{align}
$Q_{bi}$ : Ashida-Michiue Eq. and Egiazaroff Eq.
$E_d$ : thickness of exchange layer
\begin{align}
\frac{\tau_{*c i}}{\tau_{*cm}} &= 0.85 \frac{D_m}{D_i} \qquad & \left(\frac{D_i}{D_m} < 0.4 \right) \\
\dfrac{\tau_{*ci}}{\tau_{*cm}} &= \left( \dfrac{ \displaystyle \log_e 19 }{ \displaystyle \log_e \left(19\dfrac{D_i}{D_m} \right) } \right)^2 \qquad & \left(\frac{D_i}{D_m} \geq 0.4 \right)
\end{align}
```python
@numba.jit(nopython=True, parallel=False)
def sedimentmodel(dAb, dratio, A, Q, B, dx, dt, g, manning, dsize, dratioStandard, hExlayer, Qbup):
rhosw = 1.65 # grain specific gravity in water
porosity = 0.4
tscAve = 0.05 # critical tractive force of average grain size
dAbnew = np.zeros_like( dAb )
drationew = np.zeros_like( dratio )
Qbsub = np.zeros_like( dratio )
dAbsub = np.zeros_like( dratio )
imax, lmax = len(dratio), len(dratio[0])
for i in numba.prange(imax):
Ap, Qp, dr, Bp = A[i], Q[i], dratio[i], B[i]
dAve = np.sum(dsize * dr)
us = np.sqrt(g * Ap/Bp) * Qp/Ap * manning / (Ap/Bp)**(2/3)
tsAve = us**2.0/rhosw/g/dAve
use = Qp/Ap / ( 6.0 + 2.5 * np.log( Ap/Bp/dAve/( 1.0+2.0*tsAve) ) )
Kc=1.0
for l in range(lmax):
dri, dsi = dr[l], dsize[l]
ts = us**2.0 /rhosw/g/dsi
tse = use**2.0/rhosw/g/dsi
# Egiazaroff Eq.
x = dsi/dAve
tscbytscm = (np.log(19)/np.log(19*x))**2 if x > 0.4 else 0.85/x
tsc = Kc * tscbytscm * tscAve
if ts > tsc :
# Ashida-Michiue Eq.
Qbsub[i][l] = np.sqrt(rhosw * g * dsi**3.0) \
* 17.0 * tse**1.5 * ( 1.0 - tsc / ts) * ( 1.0 - np.sqrt(tsc / ts) ) \
* dri * B[i]
else:
Qbsub[i][l] = 0.0
for i in numba.prange(imax):
Qbs = Qbsub[i]
if i == 0:
if np.min(Qbup) < 0.0 : # equilibrium sand supply
dAbsub[i][:] = 0.0
else:
for l in range(lmax):
dAbsub[i][l] = - dt / (1.0 - porosity) * ( Qbsub[i][l]-Qbup[l] )/dx
if np.abs(dAbsub[i][l]) > hExlayer :
print(i) ; print('dzsub-error')
else:
for l in range(lmax):
dAbsub[i][l] = - dt / (1.0 - porosity) * ( Qbsub[i][l] - Qbsub[i-1][l] )/dx
if np.abs(dAbsub[i][l]) > hExlayer :
print(i) ; print('dzsub-error')
for i in numba.prange(imax):
Qbs = Qbsub[i]
# update dAb
dAball = np.sum( dAbsub[i] )
if np.abs(dAball) > hExlayer:
print(i) ; print('dz-error')
dAbnew[i] = dAb[i] + dAball
# update dratio
dratioIn = dratioStandard[i][:] if dAball < 0.0 else dratio[i][:]
for l in range(lmax):
drationew[i][l] = dratio[i][l] + ( dAbsub[i][l] - dAball * dratioIn[l] ) /hExlayer/B[i]
if drationew[i][l] < 0.0 : drationew[i][l] = 0.0
# correct ration so that sum of ration become 100%
sumdr = np.sum( drationew[i] )
drationew[i] /= sumdr
return dAbnew, drationew, Qbsub
```
# main
```python
def bedvariation(
dx,dt,manning,totalTime,outTimeStep,RunUpTime
,dsize ,dratioStandard ,dratio ,hExlayer ,A ,Q ,B ,zb ,dAb ,Qup ,Adown
,outputfilename, screenclass
):
g = 9.8
Qbup = np.full( ( len(dsize) ), -9999.0 ) # when equilibrium sand supply, set qbup to minus value
# run-up calculation
for i in range(int(RunUpTime/dt)):
ib = ( ( dAb[-2]/B[-2] + zb[-2] ) - ( dAb[-1]/B[-1] + zb[-1] ) )/dx
Adownp = Adown(0.0, Q[-1], dAb[-1]/B[-1], ib)
Qupp = Qup(0.0)
A, Q = flowmodel(A, Q, Adownp, Qupp, dAb, zb, B, dx, dt, g, manning)
# main calculation
for i in range( int(totalTime/dt) ):
# cal bed variation
dAb, dratio, Qbsub = sedimentmodel(dAb, dratio, A, Q, B, dx, dt, g, manning, dsize, dratioStandard, hExlayer, Qbup)
# cal water profile
ib = ( ( dAb[-2]/B[-2] + zb[-2] ) - ( dAb[-1]/B[-1] + zb[-1] ) )/dx
Adownp = Adown(i*dt, Q[-1], dAb[-1]/B[-1], ib)
Qupp = Qup(i*dt)
A, Q = flowmodel(A, Q, Adownp, Qupp, dAb, zb, B, dx, dt, g, manning)
# output
if( int(i*dt) % int(outTimeStep) ) == 0 :
print( str( int(i*dt) ) + ' second')
profile = []
for ii, (ap, qp, z, r, q) in enumerate(zip(A, Q, dAb, dratio, Qbsub)) :
profile.append({'distance' : int(ii*dx), 'A':ap, 'Q':qp, 'dAb':z, 'ratio':list(r), 'Qb':list(q)})
json.dump( {'time':int(i*dt), 'profile' : profile}, open('%010d' % int(i*dt) + 'sec.json', 'w') )
# join json files
d = [ json.load( open(f, 'r') ) for f in glob.glob('*sec.json') ]
# delete json files
for f in glob.glob('*sec.json') : os.remove(f)
d.sort(key=lambda x: x['time'])
cond = {'width':list(B), 'elevation':list(zb), 'screenclass':list(screenclass), 'dsize':list(dsize) }
json.dump( {'condition':cond, 'output':d}, open(outputfilename, 'w') )
```
|
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{qtree} % for diagram
\usepackage{listings} % for code excerpt
\usepackage{color} % for code excerpt
\lstset{
basicstyle=\ttfamily\footnotesize,
language=SQL,
keywordstyle=\color{blue},
otherkeywords={IMPUTE, impute}
}
\usepackage{booktabs} % for table
\title{6.830 Project Proposal \\
\large Data Imputation as a Query Optimization}
\author{Jose Cambronero \& John Feser \& Micah Smith}
\begin{document}
\maketitle
\section{Problem Statement}
Data imputation is a well studied problem in the machine learning literature, but some aspects related to the implementation of imputation in database systems have not been sufficiently examined. Previous work has viewed imputation as a pre-processing step on a table, rather than as an active step in each query. Particularly, existing work has not incorporated imputation into query optimization, nor has it investigated the relative impact of early versus late stage imputation on the quality of query results.
\section{Approach}
In order to study the placement of an imputation step, we propose to create a logical imputation operator (along with respective physical instances) and incorporate its placement as part of the query plan optimization process in SimpleDB. We will introduce measures of uncertainty and completeness of query results as well as the cost of imputation, which outline the main trade-offs in the imputation placement. We add these measures into our cost estimation, allowing us to intelligently place the data imputation step during query planning. Finally, we will produce empirical results that show the trade-offs between efficiency and accuracy for simple data imputation models. We will focus on queries that perform aggregate operations or return a significant number of tuples (in contrast to simple point-queries). These types of queries are likely to provide opportunities for imputation of missing values and represent an increasingly large portion of workloads in modern OLAP warehouses. Finally, we will compare our results to existing approaches.
\section{Example}
In this section, we use a simple example to show that placing the imputation operator at different points in the query plan has a significant impact on the query results.
We start with the relation \lstinline{Employees(id, salary, dept)} shown in Table~\ref{example-table}. We impute by averaging over \lstinline{salary}, and we compare two plans for the query \lstinline{SELECT AVG(salary) FROM Employees GROUP BY dept}.
\begin{table}[h]
\centering
\caption{Example table with missing data}
\label{example-table}
\begin{tabular}{@{}lll@{}}
\toprule
id & salary & dept \\ \midrule
1 & 10 & 1 \\
2 & 15 & 1 \\
3 & NA & 1 \\
4 & 5 & 2 \\ \bottomrule
\end{tabular}
\end{table}
\begin{figure}
\begin{minipage}[b]{0.5\textwidth}
\Tree [.\lstinline{AVG(salary)} [.\lstinline{GROUP BY (dept)} [.\lstinline{IMPUTE(Salary)} \lstinline{Employees} ] ] ]
\caption{Early placement of impute operator}
\label{early-fig}
\end{minipage}
\hfill
\begin{minipage}[b]{0.5\textwidth}
\Tree [.\lstinline{AVG(salary)} [.\lstinline{IMPUTE(Salary)} [.\lstinline{GROUP BY (dept)} \lstinline{Employees} ] ] ]
\caption{Late placement of impute operator}
\label{late-fig}
\end{minipage}
\end{figure}
In the early case (Figure~\ref{early-fig}), we impute over all salaries, and obtain as a final result \lstinline{[(1, 11.67), (2, 5)]}. The late case (Figure~\ref{late-fig}) averages over salaries within a department and results in \lstinline{[(1, 12.5), (2, 5)]}.
This example shows that the imputation operator, even in its simplest form, can have a significant impact on query results. Furthermore, this example fails to capture other important dimensions such as cost of imputation.
\section{Evaluation}
We are considering several data sources for our evaluation. Existing literature uses the American Community Survey, so we think this is a good choice for our experiments as well. The ACS data is a good test dataset because of its scale and relative simplicity. Additionally, we may be able to compare directly to existing work that uses ACS data.
In order to measure the accuracy of our imputation algorithm, we plan to compute results with and without missing values where possible, and use standard error measures to compare to our results. The best-case scenario for imputation is a dataset where data is removed uniformly at random. It should be easy to construct a test dataset simply by removing data from an existing dataset; artificially degrading an existing dataset also means that we will have ground truth with which to compare our results.
In contrast to pre-processing-based imputation, we plan to make a case for imputation on intermediate query results. This approach is similar to a view, as neither alter the original table and both provide logical independence. Many modern database servers have a variety of clients with different needs, so one imputation strategy is unlikely to satisfy everyone. Consider a financial data warehouse with a business strategy client and an actuarial client. It is unlikely that the queries issued by these two groups will require or benefit from the same imputation strategy. If a salary value is missing for a customer, the business strategy query may not require a costly regression model estimate and a simple heuristic could be enough to return a reasonable answer. It may be cheaper to do imputation on the fly than to maintain a separate copy of the data for each imputation strategy.
Furthermore, we believe that there is an opportunity for more efficient imputation on (smaller) intermediate results. In very large databases it may not be feasible to perform imputation on the base tables, particularly if the imputation method of choice is expensive. However, queries often return results that are smaller than the base tables, so it may be faster to perform imputation on intermediate results than on the base tables. The intermediate results could then be stored as a materialized view if they are expected to be reused or they could be recomputed as necessary.
\section{Project Milestones}
We outline a series of milestones to be completed:
\begin{enumerate}
\item Initial data collection and query workload for evaluation.
\item Consolidate set of imputation strategies.
\item Formalize a measure of uncertainty, completeness and cost in imputation as related to 2.
\item Formalize the possible query rewrites when using an imputation operator.
\item Incorporate imputation-related measures into cost estimation for SimpleDB.
\item Incorporate imputation-related rewrites for SimpleDB.
\item Evaluate performance.
\end{enumerate}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
|
function chx = bbp_pi ( d )
%*****************************************************************************80
%
%% BBP_PI implements the Bailey-Borwein-Plouffe algorithm.
%
% Discussion:
%
% The BBP algorithm can be used to compute a a few hex digits of pi starting
% at any position.
%
% In particular, bbp_pi ( d ) is a char string of hex digits d+1 through
% d+13 in the hexadecimal expansion of pi.
%
% This function does not require extended precision arithmetic or
% symbolic computation.
%
% The results are usually accurate to about 11 or 12 of the 13 digits.
%
% This program is derived from a C program by David H. Bailey dated
% 2006-09-08, http://www.experimentalmath.info/bbp-codes/piqpr8.c
%
% For many other references: Google "BBP Pi".
%
% Licensing:
%
% Copyright (c) 2011, The MathWorks, Inc.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
% * Neither the name of the The MathWorks, Inc. nor the names
% of its contributors may be used to endorse or promote products derived
% from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Modified:
%
% 27 February 2012
%
% Author:
%
% Cleve Moler
%
% Reference:
%
% Cleve Moler,
% Cleve's Corner, "Computing Pi",
% http://www.mathworks.com/company/newsletters/news_notes/2011/
%
% Parameters:
%
% Input, integer D, the number of decimal digits desired.
%
% Output, symbolic P, the value of pi to D digits.
%
s1 = series ( 1, d );
s2 = series ( 4, d );
s3 = series ( 5, d );
s4 = series ( 6, d );
P = 4. * s1 - 2. * s2 - s3 - s4;
P = P - floor ( P ) + 1.;
chx = hexchar ( P, 13 );
return
end
function s = series ( m, d )
%*****************************************************************************80
%
%% SERIES
%
% s = series(m,d) = sum_k 16^(d-k)/(8*k+m)
% using the modular powering technique.
%
s = 0;
k = 0;
t = Inf;
while k < 13 || t > eps
ak = 8 * k + m;
if k < d
t = powmod(16, d - k, ak) / ak;
else
t = 16^(d - k) / ak;
end
s = mod(s + t, 1);
k = k + 1;
end
return
end
function r = powmod ( b, p, a )
%*****************************************************************************80
%
%% POWMOD computes mod(b^p,a) without computing b^p.
%
persistent twop
if isempty ( twop )
twop = 2.^(0:25)';
end
if a == 1
r = 0;
return
end
n = find ( p <= twop, 1, 'first' );
pt = twop ( n );
r = 1;
for j = 1 : n
if p >= pt
r = mod ( b * r, a );
p = p - pt;
end
pt = 0.5 * pt;
if pt >= 1
r = mod ( r * r, a );
end
end
return
end
function chx = hexchar ( s, n )
%*****************************************************************************80
%
%% HEXCHAR returns hex digits.
%
% chx(s,n) = string of the first n hex digits of s.
%
hx = '0123456789ABCDEF';
s = abs ( s );
for j = 1 : n
s = 16. * mod ( s, 1 );
chx(j) = hx ( floor ( s ) + 1 );
end
return
end
|
import algebra.ring algebra.group_power group_theory.submonoid order.boolean_algebra
import algebra.geom_sum
import commutative_algebra.nilpotent commutative_algebra.regular
import tactic.ring
universe u
variables {A : Type u} [comm_ring A]
namespace commutative_algebra
def is_idempotent (a : A) := a * a = a
theorem is_idempotent' {a : A} : is_idempotent a ↔ a * (1 - a) = 0 :=
by { dsimp [is_idempotent], rw [mul_sub, mul_one,sub_eq_zero], exact comm}
namespace is_idempotent
/-- 0 and 1 are idempotent, and (1,0) and (0,1) are idempotent in
a product ring.
-/
theorem zero : is_idempotent (0 : A) := mul_zero 0
theorem one : is_idempotent (1 : A) := mul_one 1
theorem left {B : Type*} {C : Type*} [comm_ring B] [comm_ring C] :
is_idempotent (⟨1, 0⟩ : B × C) :=
show prod.mk ((1 : B) * (1 : B)) ((0 : C) * (0 : C)) = ⟨1, 0⟩,
by { rw [mul_one, mul_zero] }
theorem right {B : Type*} {C : Type*} [comm_ring B] [comm_ring C] :
is_idempotent (⟨0, 1⟩ : B × C) :=
show prod.mk ((0 : B) * (0 : B)) ((1 : C) * (1 : C)) = ⟨0, 1⟩,
by { rw [mul_one, mul_zero] }
/-- If a is idempotent, then (1 - 2 * a) ^ 2 = 1 -/
def invol (a : A) := 1 - 2 * a
section one_variable
variables {a : A} (ha : is_idempotent a)
include ha
/-- Positive powers of idempotents are idempotent -/
theorem pow : ∀ (n : ℕ), a ^ (n + 1) = a
| 0 := by { rw [zero_add, pow_one] }
| (n + 1) := by { have : a * a = a := ha, rw [pow_succ, pow n, this] }
/-- If a is idempotent, then so is 1 - a. We call this (not a),
because it is the negation operation for a boolean algebra structure
on the set of idempotents.
-/
theorem not : is_idempotent (1 - a) :=
by { rw [is_idempotent'] at ha ⊢, rw [mul_comm, sub_sub_cancel], exact ha }
/-- 1 is the only regular idempotent -/
theorem regular (hr : is_regular a) : a = 1 :=
by { symmetry, rw [← sub_eq_zero], exact hr _ (is_idempotent'.mp ha) }
/-- 0 is the only nilpotent idempotent -/
theorem nilpotent (hn : is_nilpotent a) : a = 0 :=
by { rcases hn with ⟨n, hn'⟩, rw [← pow ha n, pow_succ, hn', mul_zero] }
theorem mul_self_invol : a * (invol a) = - a :=
by { dsimp [is_idempotent, invol] at *,
rw [mul_sub, mul_one, two_mul, mul_add, ha],
rw [← sub_sub, sub_self, zero_sub] }
theorem invol_square : (invol a) * (invol a) = 1 :=
begin
change (1 - 2 * a) * invol a = 1,
rw [sub_mul, mul_assoc, mul_self_invol ha, one_mul],
dsimp [invol],
rw[mul_neg, sub_sub, add_neg_self, sub_zero]
end
end one_variable
section two_variables
variables {a b : A} (ha : is_idempotent a) (hb : is_idempotent b)
include ha hb
/-- The set of idempotents is a boolean algebra under the
operations given below.
-/
theorem and : is_idempotent (a * b) :=
show (a * b) * (a * b) = a * b,
by { dsimp [is_idempotent] at ha hb,
rw [mul_assoc, mul_comm b, mul_assoc, hb, ← mul_assoc, ha] }
theorem add (hab : a * b = 0) : is_idempotent (a + b) :=
by { dsimp [is_idempotent] at *,
rw [mul_add, add_mul, add_mul, mul_comm b a, ha, hb, hab,
zero_add, add_zero] }
theorem or : is_idempotent (a + b - a * b) :=
begin
have : a + b - a * b = a + (1 - a) * b :=
by { rw [sub_mul, one_mul, add_sub] },
rw [this],
apply add ha (and (not ha) hb),
rw [← mul_assoc, is_idempotent'.mp ha, zero_mul],
end
theorem xor : is_idempotent (a + b - 2 * a * b) :=
begin
let u := a * (1 - b),
let v := (1 - a) * b,
have : a + b - 2 * a * b = u + v := by { dsimp [u, v], ring },
rw [this],
have hu := and ha (not hb),
have hv := and (not ha) hb,
have huv : u * v = 0 :=
by { dsimp [u, v], rw [mul_comm a, mul_assoc, ← mul_assoc a],
have : a * (1 - a) = 0 := is_idempotent'.mp ha,
rw [this, zero_mul, mul_zero] },
exact add hu hv huv
end
end two_variables
/-- Idempotents are equal if their difference is nilpotent -/
theorem eq_of_sub_nilp {e₀ e₁ : A}
(h₀ : is_idempotent e₀) (h₁ : is_idempotent e₁)
(h : is_nilpotent (e₀ - e₁)) : e₀ = e₁ :=
begin
dsimp [is_idempotent] at h₀ h₁,
let x := e₀ - e₁,
let u := 1 - 2 * e₀,
let v := 1 + u * x,
have hvx := calc
v * x = (e₀ * e₀ - e₀) * (4 * e₁ - 2 * e₀ - 1) +
(e₁ * e₁ - e₁) * (1 - 2 * e₀) :
by { dsimp [v, u, x], ring }
... = 0 : by { rw [h₀, h₁, sub_self, sub_self, zero_mul, zero_mul, zero_add] },
have hv : is_regular v :=
regular.add_nilpotent_aux (is_regular_one A) (is_nilpotent_smul u h),
have hx : x = 0 := hv x hvx,
rw [← sub_eq_zero],
exact hx,
end
/-- If e * (1 - e) is nilpotent, then there is a unique idempotent
that is congruent to e mod nilpotents.
-/
def lift : ∀ (e : A) (h : as_nilpotent (e * (1 - e))), A :=
λ e ⟨n, hx⟩, let y := (1 - e ^ (n + 2) - (1 - e) ^ (n + 2)) in
e ^ (n + 2) * (finset.range n).sum (λ i, y ^ i)
def lift_spec (e : A) (h : as_nilpotent (e * (1 - e))) :
pprod (is_idempotent (lift e h)) (as_nilpotent ((lift e h) - e)) :=
begin
rcases h with ⟨n, hx⟩,
let x := e * (1 - e), change x ^ n = 0 at hx,
let y := 1 - e ^ (n + 2) - (1 - e) ^ (n + 2),
let u := (finset.range n).sum (λ i, y ^ i),
let e₁ := e ^ (n + 2) * u,
have : lift e ⟨n, hx⟩ = e₁ := rfl,
rw [this],
let f := λ (i : ℕ), e ^ i * (1 - e) ^ (n + 2 - i) * nat.choose (n + 2) i,
let z := (finset.range (n + 1)).sum
(λ j, e ^ j * (1 - e) ^ (n - j) * (nat.choose (n + 2) (j + 1))),
let xz := (finset.range (n + 1)).sum (f ∘ nat.succ),
have hxz : x * z = xz := by {
dsimp [xz, x], rw [finset.mul_sum], apply finset.sum_congr rfl, intros i hi,
replace hi : i ≤ n := nat.le_of_lt_succ (finset.mem_range.mp hi),
have : (f ∘ nat.succ) i = f (i + 1) := rfl, rw [this], dsimp [f],
have : n + 2 - (i + 1) = (n - i) + 1 := calc
n + 2 - (i + 1) = n + 1 - i : by { rw [nat.succ_sub_succ] }
... = (i + (n - i)) + 1 - i : by { rw [nat.add_sub_of_le hi] }
... = (n - i) + 1 : by { simp only [add_comm, add_assoc, nat.add_sub_cancel_left] },
rw [this, pow_succ, pow_succ], repeat { rw [mul_assoc] }, congr' 1,
repeat { rw [← mul_assoc] }, rw [mul_comm (1 - e) (e ^ i)],
},
have hf₀ : f 0 = (1 - e) ^ (n + 2) :=
by { dsimp [f], rw [nat.choose, nat.cast_one, pow_zero, one_mul, mul_one] },
have hf₁ := finset.sum_range_succ' f (n + 1),
rw[hf₀] at hf₁,
have hf₂ : f (n + 2) = e ^ (n + 2) :=
by { dsimp [f], rw [nat.choose_self, nat.cast_one, nat.sub_self, pow_zero, mul_one, mul_one] },
have hf₃ := finset.sum_range_succ f (n + 2),
rw[hf₂] at hf₃,
have := calc
(1 : A) = (1 : A) ^ (n + 2) : (one_pow (n + 2)).symm
... = (e + (1 - e)) ^ (n + 2) :
by { congr, rw [add_sub, add_comm, add_sub_cancel] }
... = (finset.range (n + 2).succ).sum f : add_pow e (1 - e) (n + 2)
... = ((finset.range (n + 2)).sum f) + e ^ (n + 2): hf₃
... = (xz + (1 - e) ^ (n + 2)) + e ^ (n + 2) : by { rw [hf₁] }
... = (x * z + (1 - e) ^ (n + 2)) + e ^ (n + 2) : by { rw [hxz] },
have hxyz := calc
y = 1 - e ^ (n + 2) - (1 - e) ^ (n + 2) : rfl
... = ((x * z + (1 - e) ^ (n + 2)) + e ^ (n + 2)) - e ^ (n + 2) - (1 - e) ^ (n + 2) :
by { congr' 2 }
... = x * z : by { simp only [sub_eq_add_neg, add_comm, add_left_comm,
add_neg_cancel_left, add_neg_cancel_right] },
have hy : y ^ n = 0 := by { rw [hxyz, mul_pow, hx, zero_mul] },
have hu : u * (y - 1) = y ^ n - 1 := geom_sum_mul y n,
rw [mul_comm, hy, zero_sub] at hu, replace hu := congr_arg has_neg.neg hu,
rw [neg_neg, neg_mul_eq_neg_mul, neg_sub] at hu,
have : 1 - y = e ^ (n + 2) + (1 - e) ^ (n + 2) :=
calc 1 - y = 1 - (1 - e ^ (n + 2) - (1 - e) ^ (n + 2)) : by { simp only [y] }
... = e ^ (n + 2) + (1 - e) ^ (n + 2) : by rw [sub_sub, sub_sub_cancel],
let hu' := hu, rw [this] at hu',
have := calc
1 - e₁ = (e ^ (n + 2) + (1 - e) ^ (n + 2)) * u - e₁ : by { rw [hu'] }
... = e ^ (n + 2) * u + (1 - e) ^ (n + 2) * u - e ^ (n + 2) * u :
by { rw [add_mul] }
... = (1 - e) ^ (n + 2) * u : by { rw [add_comm, add_sub_cancel] },
have := calc
e₁ * (1 - e₁) = (e ^ (n + 2) * u) * (1 - e₁) : rfl
... = u * (e ^ (n + 2) * (1 - e₁)) : by { rw [mul_comm (e ^ (n + 2))], rw [← mul_assoc] }
... = u * (e ^ (n + 2) * (1 - e) ^ (n + 2) * u) : by { rw [this, mul_assoc] }
... = u * (x ^ (n + 2) * u) : by { rw [mul_pow, pow_add] }
... = 0 : by { rw [pow_add, hx, zero_mul, zero_mul, mul_zero] },
split, exact is_idempotent'.mpr this,
let w := geom_sum₂ 1 e (n + 1),
have hw : x * w = e - e ^ (n + 2) := calc
x * w = e * (w * (1 - e)) : by { dsimp [x], rw [mul_assoc, mul_comm _ w] }
... = e * (1 - e ^ (n + 1)) : by { rw [geom_sum₂_mul 1 e (n + 1), one_pow] }
... = e - e ^ (n + 2) : by { rw [mul_sub, mul_one, pow_succ e (n + 1)] },
have hu'' : u = 1 + x * z * u := by {
rw [sub_mul, hxyz, one_mul] at hu, rw [← hu, sub_add_cancel],
},
have := calc
e₁ - e = e ^ (n + 2) * u - e : rfl
... = e ^ (n + 2) * (1 + x * z * u) - e : by { congr' 2 }
... = (e ^ (n + 2) * (x * z * u) + e ^ (n + 2)) - e :
by { rw [mul_add, mul_one, add_comm] }
... = x * (e ^ (n + 2) * z * u) - (e - e ^ (n + 2)) :
by { rw [← sub_add, sub_eq_add_neg, sub_eq_add_neg],
rw [← mul_assoc, ← mul_assoc, mul_comm (e ^ (n + 2))],
repeat { rw [add_assoc] }, rw [add_comm (e ^ (n + 2))],
repeat { rw [mul_assoc] } }
... = x * (e ^ (n + 2) * z * u - w) : by { rw [mul_sub, hw] },
have : (e₁ - e) ^ n = 0 := by { rw [this, mul_pow, hx, zero_mul] },
exact ⟨n, this⟩,
end
theorem lift_unique (e e₁ : A)
(h : as_nilpotent (e * (1 - e))) (hi : is_idempotent e₁)
(hn : is_nilpotent (e₁ - e)) : e₁ = lift e h :=
begin
rcases lift_spec e h with ⟨hi', hn'⟩,
apply eq_of_sub_nilp hi hi',
have : e₁ - lift e h = (e₁ - e) - (lift e h - e) :=
by { rw [sub_sub_sub_cancel_right] },
rw [this], apply is_nilpotent_sub hn ⟨hn'⟩
end
end is_idempotent
namespace is_idempotent
variables {e : A} (he : is_idempotent e)
include he
/-- An idempotent e gives a splitting of the form A ≃ B × C.
The first factor will be denoted by (axis he), where he
is the proof that e is idempotent.
-/
def axis := {b : A // b * e = b}
namespace axis
instance : has_coe (axis he) A := ⟨subtype.val⟩
theorem eq (b₁ b₂ : axis he) : (b₁ : A) = (b₂ : A) → b₁ = b₂ := subtype.eq
def mk (b : A) (hb : b * e = b) : axis he := ⟨b, hb⟩
theorem coe_mk {b : A} (hb : b * e = b) : ((mk he b hb) : A) = b := rfl
instance : has_zero (axis he) := ⟨⟨(0 : A), zero_mul e⟩⟩
instance : has_one (axis he) := ⟨⟨e, he⟩⟩
instance : has_neg (axis he) :=
⟨λ b, axis.mk he (- b.val) (by { rw [← neg_mul_eq_neg_mul, b.property] })⟩
instance : has_add (axis he) :=
⟨λ b₁ b₂, axis.mk he (b₁.val + b₂.val) (by { rw [add_mul, b₁.property, b₂.property] })⟩
instance : has_mul (axis he) :=
⟨λ b₁ b₂, axis.mk he (b₁.val * b₂.val) (by { rw [mul_assoc, b₂.property] })⟩
@[simp] theorem zero_coe : ((0 : axis he) : A) = 0 := rfl
@[simp] theorem one_coe : ((1 : axis he) : A) = e := rfl
@[simp] theorem neg_coe (b : axis he) : (((- b) : axis he) : A) = - b := rfl
@[simp] theorem add_coe (b₁ b₂ : axis he) :
((b₁ + b₂ : axis he) : A) = b₁ + b₂ := rfl
@[simp] theorem mul_coe (b₁ b₂ : axis he) :
((b₁ * b₂ : axis he) : A) = b₁ * b₂ := rfl
instance : comm_ring (axis he) := begin
refine_struct {
zero := has_zero.zero, add := (+), neg := has_neg.neg, sub := λ a b, a + (-b),
one := has_one.one, mul := (*),
nsmul := nsmul_rec,
npow := npow_rec,
zsmul := zsmul_rec,
nsmul_zero' := λ x, rfl,
nsmul_succ' := λ n x, rfl,
zsmul_zero' := λ x, rfl,
zsmul_succ' := λ n x, rfl,
zsmul_neg' := λ n x, rfl,
npow_zero' := λ x, rfl,
npow_succ' := λ n x, rfl
};
try { rintro a };
try { rintro b };
try { rintro c };
apply eq;
repeat { rw[add_coe] };
repeat { rw[neg_coe] };
repeat { rw[mul_coe] };
repeat { rw[add_coe] };
repeat { rw[zero_coe] };
repeat { rw[one_coe] },
{ rw[add_assoc] },
{ rw[zero_add] },
{ rw[add_zero] },
{ rw[neg_add_self] },
{ rw[add_comm] },
{ rw[mul_assoc] },
{ rw[mul_comm], exact a.property },
{ exact a.property },
{ rw[mul_add] },
{ rw[add_mul] },
{ rw[mul_comm] }
end
def proj : A →+* axis he := {
to_fun := λ a, ⟨a * e, by { dsimp [is_idempotent] at he, rw [mul_assoc, he] }⟩,
map_zero' := by { apply eq, change 0 * e = 0, exact zero_mul e },
map_one' := by { apply eq, change 1 * e = e, exact one_mul e },
map_add' := λ a b, by { apply eq,
change (a + b) * e = a * e + b * e,
rw [add_mul] },
map_mul' := λ a b, by { dsimp [is_idempotent] at he,
apply eq,
change (a * b) * e = (a * e) * (b * e),
rw [mul_assoc a e, ← mul_assoc e b e, mul_comm e b,
mul_assoc b e, he, mul_assoc] }
}
def split : A →+* (axis he) × (axis (is_idempotent.not he)) :=
let he' := is_idempotent.not he in {
to_fun := λ a, ⟨(proj he a), (proj (is_idempotent.not he) a)⟩,
map_zero' := by { rw[(proj he).map_zero, (proj _).map_zero], refl },
map_one' := by { rw[(proj he).map_one, (proj _).map_one], refl },
map_add' := λ a b, by { rw[(proj he).map_add, (proj _).map_add], refl },
map_mul' := λ a b, by { rw[(proj he).map_mul, (proj _).map_mul], refl }
}
theorem mul_eq_zero (b : axis he) (c : axis (is_idempotent.not he)) :
(b : A) * (c : A) = 0 :=
begin
rcases b with ⟨b, hb⟩,
rcases c with ⟨c, hc⟩,
change b * c = 0,
exact calc
b * c = (b * e) * (c * (1 - e)) : by rw [hb, hc]
... = b * (e * (1 - e)) * c :
by { rw [mul_comm c, mul_assoc, mul_assoc, mul_assoc] }
... = 0 : by { rw [is_idempotent'.mp he, mul_zero, zero_mul] }
end
def combine : (axis he) × (axis (is_idempotent.not he)) →+* A := {
to_fun := λ bc, (bc.1 : A) + (bc.2 : A),
map_zero' := by {
change ((0 : axis he) : A) + ((0 : axis (is_idempotent.not he)) : A) = 0,
rw[zero_coe, zero_coe, zero_add]
},
map_one' := by {
change e + (1 - e) = 1, rw [add_sub_cancel'_right]
},
map_add' := λ bc₁ bc₂, by {
rcases bc₁ with ⟨⟨b₁, hb₁⟩, ⟨c₁, hc₁⟩⟩,
rcases bc₂ with ⟨⟨b₂, hb₂⟩, ⟨c₂, hc₂⟩⟩,
change (b₁ + b₂) + (c₁ + c₂) = (b₁ + c₁) + (b₂ + c₂),
rw [add_assoc, ← add_assoc b₂, add_comm b₂ c₁, add_assoc, add_assoc] },
map_mul' := λ bc₁ bc₂, by {
rcases bc₁ with ⟨⟨b₁, hb₁⟩, ⟨c₁, hc₁⟩⟩,
rcases bc₂ with ⟨⟨b₂, hb₂⟩, ⟨c₂, hc₂⟩⟩,
change (b₁ * b₂) + (c₁ * c₂) = (b₁ + c₁) * (b₂ + c₂),
have ebc : b₁ * c₂ = 0 := mul_eq_zero he ⟨b₁, hb₁⟩ ⟨c₂, hc₂⟩,
have ecb : b₂ * c₁ = 0 := mul_eq_zero he ⟨b₂, hb₂⟩ ⟨c₁, hc₁⟩,
rw [mul_comm] at ecb,
rw [mul_add, add_mul, add_mul, ebc, ecb, zero_add, add_zero] } }
theorem combine_split (a : A) : combine he (split he a) = a :=
by { change a * e + a * (1 - e) = a,
rw [mul_sub, mul_one, add_sub_cancel'_right] }
theorem split_combine (bc : (axis he) × (axis (is_idempotent.not he))) :
split he (combine he bc) = bc :=
begin
have he' : e * (1 - e) = 0 := is_idempotent'.mp he,
rcases bc with ⟨⟨b, hb⟩, ⟨c, hc⟩⟩,
ext,
{ change (b + c) * e = b,
rw [← hc, add_mul, hb, mul_assoc, mul_comm (1 - e), he', mul_zero, add_zero] },
{ change (b + c) * (1 - e) = c,
rw [← hb, add_mul, hc, mul_assoc, he', mul_zero, zero_add] }
end
end axis
end is_idempotent
variable (A)
def idempotent := {a : A // is_idempotent a}
variable {A}
namespace idempotent
variables (a b c : idempotent A)
instance : has_coe (idempotent A) A := ⟨subtype.val⟩
theorem eq (a₁ a₂ : idempotent A) : (a₁ : A) = (a₂ : A) → a₁ = a₂ :=
subtype.eq
theorem mul_self : (a * a : A) = a := a.property
theorem mul_not : (a * (1 - a) : A) = 0 := is_idempotent'.mp a.property
instance : has_le (idempotent A) := ⟨λ a b, (a * b : A) = a⟩
instance : has_bot (idempotent A) := ⟨⟨0, is_idempotent.zero⟩⟩
instance : has_top (idempotent A) := ⟨⟨1, is_idempotent.one⟩⟩
instance : has_compl (idempotent A) :=
⟨λ a, ⟨((1 - a) : A), is_idempotent.not a.property⟩⟩
instance : has_inf (idempotent A) :=
⟨λ a b, ⟨a * b, is_idempotent.and a.property b.property⟩⟩
instance : has_sup (idempotent A) :=
⟨λ a b, ⟨a + b - a * b, is_idempotent.or a.property b.property⟩⟩
theorem le_iff {a b : idempotent A} : a ≤ b ↔ (a * b : A) = a := by { refl }
theorem bot_coe : ((⊥ : idempotent A) : A) = 0 := rfl
theorem top_coe : ((⊤ : idempotent A) : A) = 1 := rfl
theorem compl_coe : ((aᶜ : idempotent A) : A) = 1 - a := rfl
theorem inf_coe : ((a ⊓ b : idempotent A) : A) = a * b := rfl
theorem sup_coe : ((a ⊔ b : idempotent A) : A) = a + b - a * b := rfl
theorem compl_compl : aᶜᶜ = a :=
by { apply eq, rw [compl_coe, compl_coe, sub_sub_cancel] }
theorem compl_inj {a b : idempotent A} (h : aᶜ = bᶜ) : a = b :=
by { rw [← compl_compl a, ← compl_compl b, h] }
theorem compl_le_compl {a b : idempotent A} : a ≤ b ↔ bᶜ ≤ aᶜ :=
begin
rw [le_iff, le_iff, compl_coe, compl_coe, mul_sub, sub_mul, sub_mul],
rw [mul_one, mul_one, one_mul, sub_sub, mul_comm (b : A)],
rw[sub_right_inj],
split,
{ intro h, rw [h, sub_self, add_zero] },
{ intro h, symmetry, rw [← sub_eq_zero],
exact (add_right_inj (b : A)).mp (h.trans (add_zero (b : A)).symm) }
end
theorem compl_bot : (⊥ : idempotent A)ᶜ = ⊤ :=
by { apply eq, rw [compl_coe, bot_coe, top_coe, sub_zero] }
theorem compl_sup : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ :=
by { apply eq, rw [compl_coe, sup_coe, inf_coe, compl_coe, compl_coe], ring }
theorem compl_top : (⊤ : idempotent A)ᶜ = ⊥ :=
by { apply eq, rw [compl_coe, bot_coe, top_coe, sub_self] }
theorem compl_inf : (a ⊓ b)ᶜ = aᶜ ⊔ bᶜ :=
by { apply compl_inj, rw [compl_sup, compl_compl, compl_compl, compl_compl] }
theorem le_refl : a ≤ a := by { rw [le_iff, a.mul_self] }
theorem le_antisymm {a b : idempotent A} (hab : a ≤ b) (hba : b ≤ a) : a = b :=
by { apply eq, rw [le_iff] at *, rw [mul_comm] at hba, exact hab.symm.trans hba }
theorem le_trans {a b c : idempotent A} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
by { rw [le_iff] at *, exact calc
((a * c) : A) = a * b * c : by rw [hab]
... = a : by rw [mul_assoc, hbc, hab] }
theorem le_top : a ≤ ⊤ := by rw [le_iff, top_coe, mul_one]
theorem le_inf (hab : a ≤ b) (hac : a ≤ c) : a ≤ b ⊓ c :=
by { rw [le_iff] at *, rw [inf_coe, ← mul_assoc, hab, hac] }
theorem inf_le_left : a ⊓ b ≤ a :=
by { rw [le_iff, inf_coe, mul_comm, ← mul_assoc, a.mul_self] }
theorem inf_le_right : a ⊓ b ≤ b :=
by { rw [le_iff, inf_coe, mul_assoc, b.mul_self] }
theorem bot_le : ⊥ ≤ a :=
by { rw [le_iff, bot_coe, zero_mul] }
theorem sup_le (hac : a ≤ c) (hbc : b ≤ c) : a ⊔ b ≤ c :=
by { rw [compl_le_compl] at *, rw [compl_sup], exact le_inf _ _ _ hac hbc }
theorem le_sup_left : a ≤ a ⊔ b :=
by { rw [compl_le_compl, compl_sup], apply inf_le_left }
theorem le_sup_right : b ≤ a ⊔ b :=
by { rw [compl_le_compl, compl_sup], apply inf_le_right }
theorem inf_sup_distrib : a ⊓ (b ⊔ c) = (a ⊓ b) ⊔ (a ⊓ c) :=
by { apply eq, simp only [inf_coe, sup_coe, mul_add, mul_sub],
congr' 1, rw [← mul_assoc, ← mul_assoc], congr' 1,
rw [mul_assoc, mul_comm (b : A), ← mul_assoc, a.mul_self] }
theorem sup_inf_distrib : a ⊔ (b ⊓ c) = (a ⊔ b) ⊓ (a ⊔ c) :=
by { apply compl_inj,
rw [compl_sup, compl_inf], rw[compl_inf, compl_sup, compl_sup, inf_sup_distrib] }
theorem inf_compl_eq_bot (a : idempotent A) : a ⊓ aᶜ = ⊥ :=
by { apply eq, rw [inf_coe, bot_coe, compl_coe, mul_not] }
theorem sup_compl_eq_top (a : idempotent A) : a ⊔ aᶜ = ⊤ :=
by { apply compl_inj, rw [compl_sup, compl_top, inf_compl_eq_bot] }
instance : boolean_algebra (idempotent A) := boolean_algebra.of_core {
le := has_le.le,
bot := ⊥,
top := ⊤,
sup := has_sup.sup,
inf := has_inf.inf,
compl := has_compl.compl,
le_refl := le_refl,
le_antisymm := λ a b hab hba, le_antisymm hab hba,
le_trans := λ a b c hab hbc, le_trans hab hbc,
bot_le := bot_le,
le_top := le_top,
le_inf := le_inf,
inf_le_left := inf_le_left,
inf_le_right := inf_le_right,
sup_le := sup_le,
le_sup_left := le_sup_left,
le_sup_right := le_sup_right,
le_sup_inf := λ a b c, by { rw [sup_inf_distrib] },
inf_compl_le_bot := λ a, by { rw[inf_compl_eq_bot] },
top_le_sup_compl := λ a, by { rw[sup_compl_eq_top] }
}
end idempotent
end commutative_algebra |
module Main
import Effects
import Effect.StdIO
import Effect.Default
import Effect.Msg
import System.Protocol
import Greeter.Example
usage : String
usage = unwords $ intersperse "\n" ["Usage:",
"\t greeter-app <num>"]
processArgs : (List String) -> Maybe Int
processArgs [x] = Nothing
processArgs (x::y::Nil) = Just $ cast y
processArgs _ = Nothing
main : IO ()
main = do
args <- getArgs
case processArgs args of
Just i => doGreeterProcess i
Nothing => do
putStrLn "Greeter takes a number"
putStrLn usage
-- --------------------------------------------------------------- [ EOF ]
|
/* mopub_exchange_connector.cc
Jeremy Barnes, 15 March 2013
Implementation of the MoPub exchange connector.
*/
#include <algorithm>
#include <boost/tokenizer.hpp>
#include "mopub_exchange_connector.h"
#include "rtbkit/plugins/bid_request/openrtb_bid_request_parser.h"
#include "rtbkit/plugins/exchange/http_auction_handler.h"
#include "rtbkit/core/agent_configuration/agent_config.h"
#include "rtbkit/openrtb/openrtb_parsing.h"
#include "soa/types/json_printing.h"
#include "soa/service/logs.h"
#include <boost/any.hpp>
#include <boost/lexical_cast.hpp>
#include "jml/utils/file_functions.h"
#include "crypto++/blowfish.h"
#include "crypto++/modes.h"
#include "crypto++/filters.h"
using namespace std;
using namespace Datacratic;
namespace {
Logging::Category mopubExchangeConnectorTrace("MoPub Exchange Connector");
Logging::Category mopubExchangeConnectorError("[ERROR] MoPub Exchange Connector", mopubExchangeConnectorTrace);
}
namespace RTBKIT {
/*****************************************************************************/
/* MOPUB EXCHANGE CONNECTOR */
/*****************************************************************************/
MoPubExchangeConnector::
MoPubExchangeConnector(ServiceBase & owner, const std::string & name)
: OpenRTBExchangeConnector(owner, name),
configuration_("mopub")
{
this->auctionResource = "/auctions";
this->auctionVerb = "POST";
init();
}
MoPubExchangeConnector::
MoPubExchangeConnector(const std::string & name,
std::shared_ptr<ServiceProxies> proxies)
: OpenRTBExchangeConnector(name, proxies),
configuration_("mopub")
{
this->auctionResource = "/auctions";
this->auctionVerb = "POST";
init();
}
void
MoPubExchangeConnector::init()
{
}
ExchangeConnector::ExchangeCompatibility
MoPubExchangeConnector::
getCampaignCompatibility(const AgentConfig & config,
bool includeReasons) const {
ExchangeCompatibility result;
result.setCompatible();
auto cpinfo = std::make_shared<CampaignInfo>();
const Json::Value & pconf = config.providerConfig["mopub"];
try {
cpinfo->seat = Id(pconf["seat"].asString());
if (!cpinfo->seat)
result.setIncompatible("providerConfig.mopub.seat is null",
includeReasons);
} catch (const std::exception & exc) {
result.setIncompatible
(string("providerConfig.mopub.seat parsing error: ")
+ exc.what(), includeReasons);
return result;
}
try {
cpinfo->iurl = pconf["iurl"].asString();
if (!cpinfo->iurl.size())
result.setIncompatible("providerConfig.mopub.iurl is null",
includeReasons);
} catch (const std::exception & exc) {
result.setIncompatible
(string("providerConfig.mopub.iurl parsing error: ")
+ exc.what(), includeReasons);
return result;
}
result.info = cpinfo;
return result;
}
namespace {
using Datacratic::jsonDecode;
/** Given a configuration field, convert it to the appropriate JSON */
template<typename T>
void getAttr(ExchangeConnector::ExchangeCompatibility & result,
const Json::Value & config,
const char * fieldName,
T & field,
bool includeReasons) {
try {
if (!config.isMember(fieldName)) {
result.setIncompatible
("creative[].providerConfig.mopub." + string(fieldName)
+ " must be specified", includeReasons);
return;
}
const Json::Value & val = config[fieldName];
jsonDecode(val, field);
} catch (const std::exception & exc) {
result.setIncompatible("creative[].providerConfig.mopub."
+ string(fieldName) + ": error parsing field: "
+ exc.what(), includeReasons);
return;
}
}
} // file scope
ExchangeConnector::ExchangeCompatibility
MoPubExchangeConnector::
getCreativeCompatibility(const Creative & creative,
bool includeReasons) const {
ExchangeCompatibility result;
result.setCompatible();
auto crinfo = std::make_shared<CreativeInfo>();
const Json::Value & pconf = creative.providerConfig["mopub"];
std::string tmp;
boost::char_separator<char> sep(" ,");
// 1. Must have mopub.attr containing creative attributes. These
// turn into MoPubCreativeAttribute filters.
getAttr(result, pconf, "attr", tmp, includeReasons);
if (!tmp.empty()) {
boost::tokenizer<boost::char_separator<char>> tok(tmp, sep);
auto& ints = crinfo->attr;
std::transform(tok.begin(), tok.end(),
std::inserter(ints, ints.begin()),[&](const std::string& s) {
return atoi(s.data());
});
}
tmp.clear();
// 2. Must have mopub.type containing attribute type.
getAttr(result, pconf, "type", tmp, includeReasons);
if (!tmp.empty()) {
boost::tokenizer<boost::char_separator<char>> tok(tmp, sep);
auto& ints = crinfo->type;
std::transform(tok.begin(), tok.end(),
std::inserter(ints, ints.begin()),[&](const std::string& s) {
return atoi(s.data());
});
}
tmp.clear();
// 3. Must have mopub.cat containing attribute type.
getAttr(result, pconf, "cat", tmp, includeReasons);
if (!tmp.empty()) {
boost::tokenizer<boost::char_separator<char>> tok(tmp, sep);
auto& strs = crinfo->cat;
copy(tok.begin(),tok.end(),inserter(strs,strs.begin()));
}
tmp.clear();
// 4. Must have mopub.adm that includes MoPub's macro
getAttr(result, pconf, "adm", crinfo->adm, includeReasons);
if (crinfo->adm.find("${AUCTION_PRICE}") == string::npos)
result.setIncompatible
("creative[].providerConfig.mopub.adm ad markup must contain "
"encrypted win price macro ${AUCTION_PRICE}",
includeReasons);
// 5. Must have creative ID in mopub.crid
getAttr(result, pconf, "crid", crinfo->crid, includeReasons);
if (!crinfo->crid)
result.setIncompatible
("creative[].providerConfig.mopub.crid is null",
includeReasons);
// 6. Must have advertiser names array in mopub.adomain
getAttr(result, pconf, "adomain", crinfo->adomain, includeReasons);
if (crinfo->adomain.empty())
result.setIncompatible
("creative[].providerConfig.mopub.adomain is empty",
includeReasons);
getAttr(result, pconf, "nurl", crinfo->nurl, includeReasons);
if (crinfo->nurl.empty())
result.setIncompatible
("creative[].providerConfig.mopub.nurl is empty",
includeReasons);
// Cache the information
result.info = crinfo;
return result;
}
std::shared_ptr<BidRequest>
MoPubExchangeConnector::
parseBidRequest(HttpAuctionHandler & connection,
const HttpHeader & header,
const std::string & payload) {
std::shared_ptr<BidRequest> res;
// Check for JSON content-type
if (header.contentType != "application/json") {
connection.sendErrorResponse("non-JSON request");
return res;
}
// Parse the bid request
// TODO Check with MoPub if they send the x-openrtb-version header
// and if they support 2.2 now.
ML::Parse_Context context("Bid Request", payload.c_str(), payload.size());
res.reset(OpenRTBBidRequestParser::openRTBBidRequestParserFactory("2.1")->parseBidRequest(context, exchangeName(), exchangeName()));
// get restrictions enforced by MoPub.
//1) blocked category
std::vector<std::string> strv;
for (const auto& cat: res->blockedCategories)
strv.push_back(cat.val);
res->restrictions.addStrings("blockedCategories", strv);
//2) per slot: blocked type and attribute;
//3) per slot: check ext field if we have video object.
//4) per slot: check for mraid object.. not supported for now
std::vector<int> intv;
for (auto& spot: res->imp) {
for (const auto& t: spot.banner->btype) {
intv.push_back (t.val);
}
spot.restrictions.addInts("blockedTypes", intv);
intv.clear();
for (const auto& a: spot.banner->battr) {
intv.push_back (a.val);
}
spot.restrictions.addInts("blockedAttrs", intv);
// Check for a video bid
if(spot.ext.isMember("video")) {
auto video = spot.ext["video"];
if(video.isMember("linearity")) {
spot.video->linearity.val = video["linearity"].asInt();
}
if(video.isMember("type")) {
bool vast = false;
bool html = false;
// Type is defined as an array in MoPub 2.1 spec
for(auto it = video["type"].begin(); it != video["type"].end(); it++) {
const std::string &s = (*it).asString();
if(s == "VAST 2.0") {
// If VAST 2.0 is there.. protocol will be 2
// according to Table 6.7 of OpenRTB 2.1
spot.video->protocol.val = 2;
vast = true;
}
if(s == "HTML5") {
// Not sure what to do with this
html = true;
}
}
if(html && vast) {
// TO DO figure out which openrtb video protocol when we have both these tags
// for now, assume protocol = vast 2.0
spot.video->protocol.val = 2;
}
}
/** Minimum video duration
* Maximum video duration
* Making sure that max >= min
*/
int minduration = -1;
if(video.isMember("minduration")) {
minduration = video["minduration"].asInt();
spot.video->minduration = minduration;
}
if(video.isMember("maxduration")) {
if(video.isMember("minduration") &&
minduration <= video["maxduration"].asInt()) {
spot.video->maxduration = video["maxduration"].asInt();
} else {
// Makes no sense that maxduration < minduration
THROW(mopubExchangeConnectorError) << "minduration cannot be higher than maxduration" << endl;
}
}
// Since MoPub removes the Mime type, we will add none as a Mime-Type
spot.video->mimes.push_back(OpenRTB::MimeType("none"));
// Note : There is no need to add height and width since they
// should be included in the banner object and thus will be populated
// in the format object of the AdSpot object.
}
if(spot.ext.isMember("mraid")) {
LOG(mopubExchangeConnectorTrace) << "Mobile Rich Media Ad Interface Definition is not supported." << endl;
}
}
return res;
}
void
MoPubExchangeConnector::
setSeatBid(Auction const & auction,
int spotNum,
OpenRTB::BidResponse & response) const {
const Auction::Data * current = auction.getCurrentData();
// Get the winning bid
auto & resp = current->winningResponse(spotNum);
// Find how the agent is configured. We need to copy some of the
// fields into the bid.
const AgentConfig * config =
std::static_pointer_cast<const AgentConfig>(resp.agentConfig).get();
std::string en = exchangeName();
// Get the exchange specific data for this campaign
auto cpinfo = config->getProviderData<CampaignInfo>(en);
// Put in the fixed parts from the creative
int creativeIndex = resp.agentCreativeIndex;
auto & creative = config->creatives.at(creativeIndex);
// Get the exchange specific data for this creative
auto crinfo = creative.getProviderData<CreativeInfo>(en);
// Find the index in the seats array
int seatIndex = 0;
while(response.seatbid.size() != seatIndex) {
if(response.seatbid[seatIndex].seat == cpinfo->seat) break;
++seatIndex;
}
// Create if required
if(seatIndex == response.seatbid.size()) {
response.seatbid.emplace_back();
response.seatbid.back().seat = cpinfo->seat;
}
// Get the seatBid object
OpenRTB::SeatBid & seatBid = response.seatbid.at(seatIndex);
// Add a new bid to the array
seatBid.bid.emplace_back();
auto & b = seatBid.bid.back();
// Put in the variable parts
b.cid = Id(resp.agent);
b.id = Id(auction.id, auction.request->imp[0].id);
b.impid = auction.request->imp[spotNum].id;
b.price.val = getAmountIn<CPM>(resp.price.maxPrice);
b.adm = crinfo->adm;
b.adomain = crinfo->adomain;
b.crid = crinfo->crid;
b.iurl = cpinfo->iurl;
b.nurl = crinfo->nurl;
}
template <typename T>
bool disjoint (const set<T>& s1, const set<T>& s2) {
auto i = s1.begin(), j = s2.begin();
while (i != s1.end() && j != s2.end()) {
if (*i == *j)
return false;
else if (*i < *j)
++i;
else
++j;
}
return true;
}
bool
MoPubExchangeConnector::
bidRequestCreativeFilter(const BidRequest & request,
const AgentConfig & config,
const void * info) const {
const auto crinfo = reinterpret_cast<const CreativeInfo*>(info);
// 1) we first check for blocked content categories
const auto& blocked_categories = request.restrictions.get("blockedCategories");
for (const auto& cat: crinfo->cat)
if (blocked_categories.contains(cat)) {
this->recordHit ("blockedCategory");
return false;
}
// 2) now go throught the spots.
for (const auto& spot: request.imp) {
const auto& blocked_types = spot.restrictions.get("blockedTypes");
for (const auto& t: crinfo->type)
if (blocked_types.contains(t)) {
this->recordHit ("blockedType");
return false;
}
const auto& blocked_attr = spot.restrictions.get("blockedAttrs");
for (const auto& a: crinfo->attr)
if (blocked_attr.contains(a)) {
this->recordHit ("blockedAttr");
return false;
}
}
return true;
}
} // namespace RTBKIT
namespace {
using namespace RTBKIT;
struct AtInit {
AtInit() {
ExchangeConnector::registerFactory<MoPubExchangeConnector>();
}
} atInit;
}
|
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Implementation.Standard.Data.These where
open import Light.Library.Data.These using (Library ; Dependencies)
instance dependencies : Dependencies
dependencies = record {}
instance library : Library dependencies
library = record { Implementation }
where
module Implementation where
open import Data.These using (These ; this ; that ; these) public
|
function tryincrement(energy :: Vector{Vector{Int}}, x, y)
if (1 <= x <= length(energy)) && (1 <= y <= length(first(energy)))
energy[x][y] += 1
end
end
function part1()
lines = readlines("inputD11.txt")
energy = [[parse(Int, i) for i in line] for line in lines]
flashes = 0
for step in 1:100
energy = [[i+1 for i in row] for row in energy]
flashed = Tuple{Int, Int}[]
oldflashed = 0
running = true
while running
for (x, row) in enumerate(energy)
for (y, val) in enumerate(row)
if val >= 10 && !((x, y) in flashed)
push!(flashed, (x, y))
tryincrement(energy, x - 1, y - 1)
tryincrement(energy, x - 1, y)
tryincrement(energy, x - 1, y + 1)
tryincrement(energy, x, y - 1)
tryincrement(energy, x, y + 1)
tryincrement(energy, x + 1, y - 1)
tryincrement(energy, x + 1, y)
tryincrement(energy, x + 1, y + 1)
end
end
end
numflashed = length(flashed)
if numflashed == oldflashed
running = false
flashes += numflashed
else
oldflashed = numflashed
end
end
for x in 1:length(energy)
for y in 1:length(energy[x])
if energy[x][y] >= 10
energy[x][y] = 0
end
end
end
end
return flashes
end
function part2()
lines = readlines("inputD11.txt")
energy = [[parse(Int, i) for i in line] for line in lines]
flashes = 0
step = 0
while true
step += 1
energy = [[i+1 for i in row] for row in energy]
flashed = Tuple{Int, Int}[]
oldflashed = 0
running = true
while running
for (x, row) in enumerate(energy)
for (y, val) in enumerate(row)
if val >= 10 && !((x, y) in flashed)
push!(flashed, (x, y))
tryincrement(energy, x - 1, y - 1)
tryincrement(energy, x - 1, y)
tryincrement(energy, x - 1, y + 1)
tryincrement(energy, x, y - 1)
tryincrement(energy, x, y + 1)
tryincrement(energy, x + 1, y - 1)
tryincrement(energy, x + 1, y)
tryincrement(energy, x + 1, y + 1)
end
end
end
numflashed = length(flashed)
if numflashed == oldflashed
running = false
flashes += numflashed
else
oldflashed = numflashed
end
end
for x in 1:length(energy)
for y in 1:length(energy[x])
if energy[x][y] >= 10
energy[x][y] = 0
end
end
end
if iszero(energy)
return step
end
end
end
println(part1())
println(part2()) |
# 第十九讲:微分动态规划及线性二次型高斯
在继续学习之前,我们先来回顾一下[上一讲](chapter18.ipynb)的内容:
* 其目标是$\displaystyle\max_a\mathrm E\left[R^{(0)}(s_0,a_0)+R^{(1)}(s_1,a_1)+\cdots+R^{(T)}(s_T,a_T)\right]$;
* 之后我们应用了动态规划算法:
$$
\begin{align}
V_T^*(s)&=\max_{a_T}R(s_T,a_T)\tag{1}\\
V_t^*(s)&=\max_a\left(R(s,a)+\sum_{s'}P_{sa}^{(t)}\left(s'\right)V_{t+1}^*\left(s'\right)\right)\tag{2}\\
\pi_t^*(s)&=\arg\max_a\left(R(s,a)+\sum_{s'}P_{sa}^{(t)}\left(s'\right)V_{t+1}^*\left(s'\right)\right)\tag{3}
\end{align}
$$
其中$(1)$式是有限时域MDP的最后一步;得出最后一步后就可以使用$(2)$式向后递推每一个$V_{T-1},\cdots,V_{0}$;最后,在使用$\arg\max$对每一步价值函数最大化的部分做运算,就可以得到每一步的最优策略。
* 接下来我们介绍了一个具体的LQR问题:
* 状态为$S\in\mathbb R^n$;
* 动作为$A\in\mathbb R^d$;
* 将下一步作为关于当前状态及动作的函数$s_{t+1}=A_ts_t+B_ta_t+w_t$,此处的$w_t\sim\mathcal N(0,\varSigma_w)$是一个期望为零、协方差为$\varSigma_w$的高斯噪音项。
* 上面定义中有了关于当前状态及动作的函数$s_{t+1}=f(s_t,a_t)$,我们就可以选择一个系统长时间保持的状态(系统通常都会都处于这种状态)$(\bar s_t,\bar a_t)$,在该点使用线性函数近似非线性函数$s_{t+1}=f(s_t,a_t)$,进而得到$\displaystyle s_{t+1}\approx f(\bar s_t,\bar a_t)+(\nabla_sf(\bar s_t,\bar a_t))^T(s_t-\bar s_t)+(\nabla_af(\bar s_t,\bar a_t))^T(a_t-\bar a_t)$。最终能够在$(\bar s_t,\bar a_t)$附近得到一个线性函数$s_{t+1}=A_ts_t+B_ta_t$。
* LQR的奖励函数为$\displaystyle R^{(t)}(s_t,a_t)=-\left(s_t^TU_ts_t+a^TV_ta_t\right)$,其中矩阵$U,V$是半正定的,所以这个奖励函数总是非正数;
* 对LQR使用上面的动态规划得到求解方法:
* 使用$\varPhi_t=-U_t,\varPsi_t=0$初始化$V_T^*$;
* 向后递推计算$\varPhi_t,\varPsi_t$,使用离散时间Riccati方程,将其当做关于$\varPhi_{t+1},\varPsi_{t+1}$的线性函数;(依次求出$t=T-1,T-2,\cdots,0$。)
$$
\begin{align}
\varPhi_t&=A_t^T\left(\varPhi_{t+1}-\varPhi_{t+1}B_t\left(B_t^T\varPhi_{t+1}B_t-V_t\right)^{-1}B_t\varPhi_{t+1}\right)A_t-U_t\\
\varPsi_t&=-\mathrm{tr}\varSigma_w\varPhi_{t+1}+\varPsi_{t+1}
\end{align}
$$
* 计算$\displaystyle L_t=\left(B_t^T\varPhi_{t+1}B_t-V_t\right)^{-1}B_t^T\varPhi_{t+1}A_t$,这是一个关于$\varPhi_{t+1},\varPsi_{t+1}$的函数;
* 计算$\pi^*(s_t)=L_ts_t$,这是一个关于$s_t$的线性函数,系数是$L_t$。
这个算法中有趣的一点是,$L_t$不依靠$\varPsi_t$,$\varPhi_t$也不依赖于$\varPsi_t$。所以,即使我们从不考虑$\varPsi$也不会影响最终的结果。另一个有趣的地方在于$\varSigma_w$只在$\varPsi_t$中出现,再看LQR定义中的$s_{t+1}=A_ts_t+B_ta_t+w_t$可以得出,即使在不知道噪音项协方差的前提下,也可以正确的求出最优策略(但不要忘了最优价值函数是受$\varPsi$影响的)。最后,这两点都是对这个特殊LQR模型(非线性动力系统)独有的,一旦我们对模型做出改变,则这两个特性将不复存在,也就是只有在这个例子中才有“最优策略不受噪音项协方差影响”。在后面讨论Kalman滤波的时候会用到这个性质。
## 8. 强化学习算法的调试
我们在[第十一讲](chapter11.ipynb)中,在关于机器学习算法的调试介绍过直升机模型提到:
1. 搭建一个遥控直升机模拟器,主要是对状态转换概率$P_{sa}$进行建模(比如通过学习物理知识,依照空气动力学原理编写模拟器;或者也可以收集大量试验数据,通过拟合这些数据一个线性或非线性模型,以得到一个用当前状态、当前操作表示下一步状态的函数);
2. 选择奖励函数,比如$R(s)=\left\lVert s-s_\mathrm{desired}\right\rVert^2$($s$代表直升机当前的位置,这里示例的函数表示直升机实际位置与期望位置的平方误差,我们在[上一讲](chapter18.ipynb)的LQR中已经使用过这个奖励函数了);
3. 在模拟器中运行强化学习算法控制直升机并尝试最大化奖励函数,$\mathrm E\left[R(s_0)+R(s_1)+\cdots+R(s_T)\right]$,进而求得对应的策略$\pi_\mathrm{RL}$。
现在,假设我们已经按照上述步骤得到了控制模型,但是发现该模型比人类直接操作差很多,接下来应该怎么办呢?我们可能会:
* 改进模拟器(也许模拟器所用的模型不是线性或非线性的;也许需要收集更多数据来拟合模型;也许需要调整拟合模型时所使用的特征值);
* 修改奖励函数$R$(也许它不只是一个二次函数);
* 改进学习算法(也许RL并不适合这个问题;也许需要对状态进行更精细的描述;也许在价值函数近似过程中使用的特征值需要调整);
对于调整算法这样的任务,我们有太多的选择方向,如果选择错误,则将会浪费大量的时间精力。
接下来我们假设:
1. 直升机模拟器足够精确;
2. RL算法能够在模拟器中正确的控制飞机,因此算法正确的最大化了预期总收益$V_t^{\pi_\mathrm{RL}}(s_0)=\mathrm E\left[R(s_0)+R(s_1)+\cdots+R(s_T)\mid\pi_\mathrm{RL},s_t=s_0\right]$;
3. 最大化预期总收益与模型正确的操作飞机强相关。
如果上述三条假设均正确,则可以推出$\pi_\mathrm{RL}$能够控制好真正的直升机。
于是,我们可以**依次**做出如下诊断:
1. 首先,如果$\pi_\mathrm{RL}$在模拟器中飞的很好,但是在实际飞机上却表现不好,则说明是模拟器的问题;
2. 然后,用$\pi_\mathrm{human}$表示人类操纵者在操纵直升机时使用的策略,比较人类和算法的策略所对应的价值函数,如果$V^{\pi_\mathrm{RL}}\lt V^{\pi_\mathrm{human}}$,则说明是RL算法的问题。(算法并没有成功的最大化预期总收益。)
3. 最后,如果经比较发现$V^{\pi_\mathrm{RL}}\gt V^{\pi_\mathrm{human}}$,则说明问题出在奖励函数上。(最大化这个奖励函数并没有使得飞行水平提高。)
以上仅是一个强化学习调试的例子,因为我们恰好找到了一个极优秀的直升机操纵者,如果没有的话则需要想出别的调试方法。在通常的问题中,我们都需要自己找出针对问题的有效的调试方法。
## 9. 微分动态规划(DDP: Differential Dynamic Programming)
继续使用遥控直升机的例子,假设我们已经有模拟器并可以通过模拟器知道$s_{t+1}=f(s_t,a_t)$(即下一个状态是一个关于当前状态及动作的函数),而且这个模拟器是非线性、确定性的,噪音项也比较小。我们现在想要让直升机飞出一些特定轨迹,于是:
1. 先写出这个轨迹:$(\bar s_0,\bar a_0),(\bar s_1,\bar a_1),\cdots,(\bar s_T,\bar a_T)$,这也称为**标准轨迹(nominal trajectory)**;(这个轨迹也可能来自一个很粗糙的控制算法,但是虽然粗糙,却也是描述的我们想要做出的动作,比如在空中做$90^\circ$转弯之类的动作。)
2. 然后,我们在这个轨迹附近线性化$f$得到:$\displaystyle s_{t+1}\approx f(\bar s_t,\bar a_t)+(\nabla_sf(\bar s_t,\bar a_t))^T(s_t-\bar s_t)+(\nabla_af(\bar s_t,\bar a_t))^T(a_t-\bar a_t)$,也就是说能够得到一个线性函数$s_{t+1}=A_ts_t+B_ta_t$。我们这是在课程中第一次使用LQR来处理有限时域上的非平稳的动态问题,尤其要注意的是这里的$A_t,B_t$是依赖于时间的(也就是这是一系列不相等的矩阵);(即使标准轨迹来自一套很糟糕的控制,但我们仍然希望系统在$t$时刻的状态和动作能够近似于这个糟糕的轨迹。也许这个控制算法做的工作很马虎,但毕竟这个轨迹描述了我们想要得到的动作,也就是希望$(s_t,a_t)\approx(\bar s_t,\bar a_t)$。)
3. 有了线性模型,再使用LQR计算最优策略$\pi_t$,于是我们就会得到一个更好的策略;
4. 在模拟器中按照新的策略实现一个新的轨迹,也就是:
* 用$\bar s_0$初始化模拟器;
* 用刚学到的$\pi_t$控制每一步的动作$a_t=\pi_t(\bar s_t)$;
* 最终得到一套新的轨迹$\bar s_{t+1}=f(\bar s_t,\bar a_t)$
5. 得到新的轨迹后,我们就可以继续重复上面的操作,不停的优化这个轨迹(也就是重复步骤2-5)。
在实践中能够知道,这是一个非常有效的算法,DDP实际上是一种局部搜索算法,在每次迭代中,找到一个稍好的点进行线性化,进而得到一个稍好的策略,重复这个动作最终就可以得到一个比较好的策略了。(“微分”指的就是每次迭代我们都会选择一个点并通过求导做线性化。)
## 10. 线性二次型高斯(LQG: Linear Quadratic Gaussian)
### 10.1 Kalman滤波(Kalman Filter)
现在介绍另一种类型的MDP,在这种MDP中,我们并不能直接观察到每一步的状态(在前面的MDP中我们都会假设系统的状态已知,于是可以计算出策略,它是一个关于状态的函数;在LQR中我们也是计算$L_ts_t$,状态都是已知的)。
我们暂时先不谈控制,来说说普通的不能观察到状态信息的动态系统。举个例子,我们对“使用雷达追踪飞行器”的过程进行极其简化的建模:线性模型$s_{t+1}=As_t+w_t$,其中$s_t=\begin{bmatrix}x_t\\\dot x_t\\y_t\\\dot y_t\end{bmatrix},\ A=\begin{bmatrix}1&1&0&0\\0&0.9&0&0\\0&0&1&1\\0&0&0&0.9\end{bmatrix}$(这是一个非常简化的模型,可以理解为一架在2D空间中移动的飞机)。
在这个简化模型中我们无法观察到每一步的状态,但假设我们可以观察到另一个量——$y_t=Cs_t+v_t,\ v_t\sim\mathcal N(0,\varSigma_v)$:比如$C=\begin{bmatrix}1&0&0&0\\0&0&1&0\end{bmatrix}$,则有$Cs_t=\begin{bmatrix}x_t\\y_t\end{bmatrix}$。这个量可能是雷达追踪到的飞行器的位置(只能得到位置相关的状态,而不能得到加速度相关的状态)。比如说在$\mathrm{xOy}$平面上,有一个雷达位于$x$轴某点,其视角沿$y$轴正方向大致对着飞行器,并依次观察到一系列飞行器移动过程中的不连续的点,因为雷达视角沿$y$轴正半轴方向,所以得到的点的坐标的纵坐标的噪音(方差)应该大于横坐标的方差,可以说这些点分别位于一个个小的高斯分布中,而这些高斯分布的协方差矩阵应该型为$\varSigma=\begin{bmatrix}a&0\\0&b\end{bmatrix},\ a\gt b$(即因为在$y$轴方向上的观测结果更容易出现偏差,所以等高线图中椭圆的长轴会沿着$y$轴方向。)而我们想要做的就是通过观测到的一系列坐标估计飞行器在每个观测点的状态$P(s_t\mid y_1,\cdots,y_t)$。
$s_0,\cdots,s_t;\ y_0,\cdots,y_t$组成了一个高斯分布的联合分布(多元正态分布),可以用$z=\begin{bmatrix}s_0\\\vdots\\s_t\\y_0\\\vdots\\y_t\end{bmatrix},\ z\sim\mathcal N(\mu,\varSigma)$表示,再结合[第十三讲](chapter13.ipynb)中了解的多元正态分布的边缘分布与条件分布的计算方法,我们就可以对$P(s_t\mid y_1,\cdots,y_t)$进行求解。虽然这个思路在概念上是可行的,但是在实际中跟踪一个飞行器会得到成千上万个位置,于是就会有一个巨大的协方差矩阵(期望向量和协方差矩阵都会随着时间、步数的增长呈线性增长,在计算过程中需要用到的边缘分布、条件分布都可能会使用协方差的逆,而计算协方差的逆的复杂度是矩阵规模的平方级别),所以对于计算来说可行性较低。
于是我们引入**Kalman滤波(Kalman Filter)**算法来解决这个效率问题。这个算法实际上是一个隐式马尔可夫模型,使用递推的方式计算,下面写出算法的步骤,算法的思路可以在[Hidden Markov Models](http://cs229.stanford.edu/section/cs229-hmm.pdf)中找到:
* 第一步称为**预测(predict)**步骤,使用$P(s_t\mid y_1,\cdots,y_t)$对$P(s_{t+1}\mid y_1,\cdots,y_t)$进行预测;
* 有$s_t\mid y_0,\cdots,y_t\sim\mathcal N\left(s_{t\mid t},\varSigma_{t\mid t}\right)$;
* 则有$s_{t+1}\mid y_0,\cdots,y_t\sim\mathcal N\left(s_{t+1\mid t},\varSigma_{t+1\mid t}\right)$;
* 其中$\begin{cases}s_{t+1\mid t}&=As_{t\mid t}\\ \varSigma_{t+1\mid t}&=A\varSigma_{t\mid t}A^T+\varSigma_t\end{cases}$;
* 需要说明的是,我们使用诸如$s_t,y_t$表示模型的真实状态(如为观测到的实际状态,已观测到的实际位置),而使用$s_{t\mid t},s_{t+1\mid t},\varSigma_{t\mid t}$表示由计算得到的值;
* 第二步称为**更新(update)**步骤,使用上一步预测的$P(s_{t+1}\mid y_1,\cdots,y_t)$更新$P(s_{t+1}\mid y_1,\cdots,y_{t+1})$,也就是有了预测结果之后再将对应的样本纳入模型:
* 其中$s_{t+1\mid t+1}=s_{t+1\mid t}+K_{t+1}\cdot\left(y_{t+1}-Cs_{t+1\mid t}\right)$;
* 而$K_{t+1}=\varSigma_{t+1\mid t}C^T\left(C\varSigma_{t+1\mid t}C^T+\varSigma_t\right)^{-1}$;
* $\varSigma_{t+1\mid t+1}=\varSigma_{t+1\mid t}+\varSigma_{t+1\mid t}\cdot C^T\left(C\varSigma_{t+1\mid t}C^T+\varSigma_t\right)^{-1}C\varSigma_{t+1\mid t}$
Kalman滤波算法的复杂度比计算协方差矩阵的逆低很多,因为采用了递推的计算过程,每当步骤增加,则只需多执行一步迭代,而且无需保留太多数据在内存中,相比于求一个巨大矩阵的逆而言,算法复杂度低了很多:
$$
\require{AMScd}
\begin{CD}
y_1 @. y_2 @. y_3 \\
@VVV @VVV @VVV \\
P\left(s_1\mid y_1\right) @>>> P\left(s_2\mid y_1,y_2\right) @>>> P\left(s_3\mid y_1,y_2,y_3\right) @>>> \cdots
\end{CD}
$$
从这个草图可以看出来,当计算$P\left(s_3\mid y_1,y_2,y_3\right)$时,我们并不需要$y_1,y_2,P\left(s_1\mid y_1\right)$,每步计算只需要知道最新的观测值和上一步得出的概率估计即可。
### 10.2 LQG
将Kalman滤波与LQR结合起来就可以得到**线性二次高斯(LQG: Linear Quadratic Gaussian)**线性二次高速算法。在LQR问题中,我们将动作$a_t$加回到模型中:设非线性动力学系统为$s_{t+1}=As_t+Ba_t+w_t,\ w\sim\mathcal N(0,\varSigma_w)$,而且我们无法直接观测到状态,只能观测到$y_t=Cs_t+v_t,\ v\sim\mathcal N(0,\varSigma_v)$。现在使用Kalman滤波估计状态:
* 假设初始状态为$s_{0\mid0}=s_0,\varSigma_{0\mid0}=0$;(如果不知道确切初始状态,测可以大致估计初始状态$s_0\sim\mathcal N\left(s_{0\mid0},\varSigma_{0\mid0}\right)$,即使用初始状态的平均值和协方差的估计。)
* 预测步骤,$\begin{cases}s_{t+1\mid t}&=As_{t\mid t}+Ba_t\\\varSigma_{t+1\mid t}&=A\varSigma_{t\mid t}A^T+\varSigma_t\end{cases}$。如此,我们就“解决”为了状态观测不到的问题(这里的$A,B$都是已知项);
* 控制步骤,按照LQR算法中的最优动作$a_t=L_ts_t$计算其中的$L_t$,并暂时忽略观测不到状态的问题;得到$L_t$后,选择$a_t=L_ts_{t\mid t}$作为最优动作(换句话说,因为不知道状态,所以我们对状态的最佳估计就是$s_{t\mid t}$)。
这个算法实际上是先设计了一个状态估计算法,然后再使用了一个控制算法,把两个算法结合起来就得到了LQG。
|
[STATEMENT]
lemma subset_f_image_iff: "(B \<subseteq> xs `\<^sup>f A) = (\<exists>A'\<subseteq>A. B = xs `\<^sup>f A')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (B \<subseteq> xs `\<^sup>f A) = (\<exists>A'\<subseteq>A. B = xs `\<^sup>f A')
[PROOF STEP]
apply (rule iffI)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. B \<subseteq> xs `\<^sup>f A \<Longrightarrow> \<exists>A'\<subseteq>A. B = xs `\<^sup>f A'
2. \<exists>A'\<subseteq>A. B = xs `\<^sup>f A' \<Longrightarrow> B \<subseteq> xs `\<^sup>f A
[PROOF STEP]
apply (rule_tac x="{ n. n \<in> A \<and> n < length xs \<and> xs ! n \<in> B }" in exI)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. B \<subseteq> xs `\<^sup>f A \<Longrightarrow> {n \<in> A. n < length xs \<and> xs ! n \<in> B} \<subseteq> A \<and> B = xs `\<^sup>f {n \<in> A. n < length xs \<and> xs ! n \<in> B}
2. \<exists>A'\<subseteq>A. B = xs `\<^sup>f A' \<Longrightarrow> B \<subseteq> xs `\<^sup>f A
[PROOF STEP]
apply blast
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>A'\<subseteq>A. B = xs `\<^sup>f A' \<Longrightarrow> B \<subseteq> xs `\<^sup>f A
[PROOF STEP]
apply (blast intro: f_image_mono)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
module Categories.Monoidal.CartesianClosed where
|
theory InferComplete
imports InferRange AltLBoundLemma
begin
(* ##### defines specialization properties *)
definition spec_env :: "nat res_env \<Rightarrow> pt_env \<Rightarrow> dir_type_subst \<Rightarrow> bool" where
"spec_env env_v env t_subx = (\<forall> x. case env_v x of
None \<Rightarrow> env x = None
| Some a \<Rightarrow> env x = t_subx a
)"
lemma self_spec_env: "spec_env env_v (dir_subst_tenv t_sub env_v) t_sub"
apply (simp add: spec_env_def)
apply (auto)
apply (case_tac "env_v x")
apply (auto)
apply (simp add: dir_subst_tenv_def)
apply (simp add: dir_subst_tenv_def)
done
lemma eq_spec_env: "\<lbrakk> dir_subst_tenv t_sub env_v = dir_subst_tenv t_sub' env_v \<rbrakk> \<Longrightarrow> spec_env env_v (dir_subst_tenv t_sub env_v) t_sub'"
apply (simp)
apply (rule_tac self_spec_env)
done
(* #### fresh list lemmas *)
lemma dom_list_set_contain: "\<lbrakk> x \<in> dom_list_set l \<rbrakk> \<Longrightarrow> list_contain (dom_list l) x"
apply (induct l)
apply (auto)
done
lemma dom_list_set_use: "\<lbrakk> list_contain (dom_list l) x; dom_list_set l \<subseteq> ds\<rbrakk> \<Longrightarrow> x \<in> ds"
apply (induct l)
apply (auto)
done
lemma append_contain_dom_list: "\<lbrakk> list_contain (dom_list (l1 @ l2)) a \<rbrakk> \<Longrightarrow> list_contain (dom_list l1) a \<or> list_contain (dom_list l2) a"
apply (auto)
apply (induct l1)
apply (auto)
done
lemma append_fresh_in_list: "\<lbrakk> fresh_in_list (dom_list l1); \<forall>x. list_contain (dom_list l2) x \<longrightarrow> \<not> list_contain (dom_list l1) x;
fresh_in_list (dom_list l2) \<rbrakk> \<Longrightarrow> fresh_in_list (dom_list (l1 @ l2))"
apply (induct l1)
apply (auto)
apply (cut_tac a="a" and ?l1.0="l1" and ?l2.0="l2" in append_contain_dom_list)
apply (auto)
done
lemma append_fresh_list: "\<lbrakk> fresh_list ds (dom_list l1); tsub_dom (dir_list_add_env t_sub l1) ds';
fresh_list ds' (dom_list l2); ds \<subseteq> ds' \<rbrakk> \<Longrightarrow> fresh_list ds (dom_list (l1 @ l2))"
apply (simp add: fresh_list_def)
apply (auto)
(* first we prove that l1 @ l2 is fresh internally *)
apply (rule_tac append_fresh_in_list)
apply (auto)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (auto)
apply (cut_tac l="l1" and ds="ds'" in list_add_dls)
apply (auto)
apply (cut_tac x="x" and ds="ds'" and l="l1" in dom_list_set_use)
apply (auto)
(* next we want to prove that if x is in l1 @ l2, x \<notin> ds *)
apply (cut_tac ?l1.0="l1" and ?l2.0="l2" and a="x" in append_contain_dom_list)
apply (auto)
done
lemma add_list_contain: "\<lbrakk> list_contain (dom_list l) x \<rbrakk> \<Longrightarrow> dir_list_add_env t_sub l x \<noteq> None"
apply (induct l)
apply (auto)
apply (simp add: dir_add_env_def)
apply (simp add: dir_add_env_def)
done
lemma add_fresh_list: "\<lbrakk> fresh_list ds (dom_list l); tsub_dom (dir_list_add_env t_sub l) ds';
x \<notin> ds'; ds \<subseteq> ds' \<rbrakk> \<Longrightarrow> fresh_list ds (dom_list ((x, t) # l))"
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: tsub_dom_def)
apply (erule_tac x="x" in allE)
apply (auto)
apply (cut_tac t_sub="t_sub" and l="l" and x="x" in add_list_contain)
apply (auto)
done
lemma append_fresh_list2: "\<lbrakk> fresh_list ds (dom_list l2); tsub_dom (dir_list_add_env t_sub l2) ds';
fresh_list ds' (dom_list l1); ds \<subseteq> ds' \<rbrakk> \<Longrightarrow> fresh_list ds (dom_list (l1 @ l2))"
apply (simp add: fresh_list_def)
apply (auto)
(* first we prove that l1 @ l2 is fresh internally *)
apply (rule_tac append_fresh_in_list)
apply (auto)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (auto)
apply (cut_tac l="l2" and ds="ds'" in list_add_dls)
apply (auto)
apply (cut_tac x="x" and ds="ds'" and l="l2" in dom_list_set_use)
apply (auto)
(* next we want to prove that if x is in l1 @ l2, x \<notin> ds *)
apply (cut_tac ?l1.0="l1" and ?l2.0="l2" and a="x" in append_contain_dom_list)
apply (auto)
done
(* #### unsorted lemmas *)
lemma add_subst_perm: "\<lbrakk> x \<notin> pvar_set_perm p \<rbrakk> \<Longrightarrow> sol_subst_perm (add_use_env p_sub x r) p = sol_subst_perm p_sub p"
apply (case_tac p)
apply (auto)
apply (simp add: add_use_env_def)
done
lemma add_subst_permx: "\<lbrakk> x \<notin> pvar_set px \<rbrakk> \<Longrightarrow> dir_subst_permx t_sub (add_use_env p_sub x r) px = dir_subst_permx t_sub p_sub px"
apply (induct px)
apply (auto)
apply (simp_all add: add_subst_perm)
done
lemma add_psub_leq_use_env: "\<lbrakk> pvar_range r_xv ds; x \<notin> ds; leq_use_env (dir_subst_penv t_sub p_sub r_xv) r_s \<rbrakk> \<Longrightarrow>
leq_use_env (dir_subst_penv t_sub (add_use_env p_sub x r) r_xv) r_s"
apply (simp add: leq_use_env_def)
apply (simp add: dir_subst_penv_def)
apply (auto)
apply (rule_tac t="dir_subst_permx t_sub (add_use_env p_sub x r) (r_xv xa)"
and s="dir_subst_permx t_sub p_sub (r_xv xa)" in subst)
apply (case_tac "x \<notin> pvar_set (r_xv xa)")
apply (simp add: add_subst_permx)
apply (simp add: pvar_range_def)
apply (erule_tac x="xa" in allE)
apply (auto)
done
lemma add_psub_use_env: "\<lbrakk> pvar_range r_xv ds; x \<notin> ds \<rbrakk> \<Longrightarrow>
dir_subst_penv t_sub (add_use_env p_sub x r) r_xv = dir_subst_penv t_sub p_sub r_xv"
apply (case_tac "\<forall> y. dir_subst_penv t_sub (add_use_env p_sub x r) r_xv y = dir_subst_penv t_sub p_sub r_xv y")
apply (auto)
apply (simp add: dir_subst_penv_def)
apply (cut_tac t_sub="t_sub" and p_sub="p_sub" and x="x" and px="r_xv y" and r="r" in add_subst_permx)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="y" in allE)
apply (auto)
done
lemma comp_subst_perm: "\<lbrakk> psub_dom p_sub2 ds'; pvar_set_perm p \<subseteq> ds; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
sol_subst_perm (comp_use_env p_sub1 p_sub2) p = sol_subst_perm p_sub1 p"
apply (case_tac p)
apply (auto)
apply (simp add: comp_use_env_def)
apply (simp add: psub_dom_def)
apply (erule_tac x="x2" in allE)
apply (auto)
apply (case_tac "p_sub1 x2")
apply (auto)
done
lemma comp_subst_permx: "\<lbrakk> psub_dom p_sub2 ds'; pvar_set px \<subseteq> ds; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_subst_permx t_sub (comp_use_env p_sub1 p_sub2) px = dir_subst_permx t_sub p_sub1 px"
apply (induct px)
apply (auto)
apply (simp add: comp_subst_perm)
apply (simp add: comp_subst_perm)
apply (simp add: comp_subst_perm)
done
lemma comp_psub_leq_use_env1: "\<lbrakk> psub_dom p_sub2 ds'; pvar_range r_xv ds; ds \<inter> ds' = {};
leq_use_env (dir_subst_penv t_sub p_sub1 r_xv) r_s \<rbrakk> \<Longrightarrow>
leq_use_env (dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv) r_s"
apply (simp add: leq_use_env_def)
apply (simp add: dir_subst_penv_def)
apply (auto)
apply (rule_tac t="dir_subst_permx t_sub (comp_use_env p_sub1 p_sub2) (r_xv x)"
and s="dir_subst_permx t_sub p_sub1 (r_xv x)" in subst)
apply (case_tac "pvar_set (r_xv x) \<subseteq> ds")
apply (simp add: comp_subst_permx)
apply (simp add: pvar_range_def)
apply (auto)
done
lemma comp_psub_use_env1: "\<lbrakk> psub_dom p_sub2 ds'; pvar_range r_xv ds; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv = dir_subst_penv t_sub p_sub1 r_xv"
apply (case_tac "\<forall> x. dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv x = dir_subst_penv t_sub p_sub1 r_xv x")
apply (auto)
apply (simp add: dir_subst_penv_def)
apply (cut_tac t_sub="t_sub" and ?p_sub1.0="p_sub1" and ?p_sub2.0="p_sub2" and ds="ds" and ds'="ds'" and px="r_xv x" in comp_subst_permx)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="x" in allE)
apply (auto)
done
lemma comp_psub_leq_use_env2: "\<lbrakk> psub_dom p_sub1 ds'; pvar_range r_xv ds; ds \<inter> ds' = {};
leq_use_env (dir_subst_penv t_sub p_sub2 r_xv) r_s \<rbrakk> \<Longrightarrow>
leq_use_env (dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv) r_s"
apply (cut_tac r_s="p_sub1" and r_x="p_sub2" in comm_comp_use_env)
apply (auto)
apply (rule_tac comp_psub_leq_use_env1)
apply (auto)
done
lemma comp_psub_use_env2: "\<lbrakk> psub_dom p_sub2 ds'; pvar_range r_xv ds; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_subst_penv t_sub (comp_use_env p_sub2 p_sub1) r_xv = dir_subst_penv t_sub p_sub1 r_xv"
apply (simp add: comm_comp_use_env)
apply (rule_tac comp_psub_use_env1)
apply (auto)
done
lemma diff_leq_use_env_rev: "\<lbrakk> leq_use_env (diff_use_env r_x r_ex) r_s; leq_use_env r_ex r_s \<rbrakk> \<Longrightarrow> leq_use_env r_x r_s"
apply (simp add: leq_use_env_def)
apply (simp add: diff_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (case_tac "r_x x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_ex x")
apply (auto)
apply (case_tac "r_ex x")
apply (auto)
done
lemma dist_union_use_leq: "\<lbrakk> leq_perm p r; leq_perm q r \<rbrakk> \<Longrightarrow> leq_perm (union_perm p q) r"
apply (case_tac r)
apply (auto)
apply (case_tac p)
apply (auto)
apply (case_tac q)
apply (auto)
apply (case_tac p)
apply (auto)
apply (case_tac q)
apply (auto)
apply (case_tac q)
apply (auto)
done
lemma union_use_leq1: "\<lbrakk> leq_perm p q \<rbrakk> \<Longrightarrow> leq_perm p (union_perm q r)"
apply (case_tac q)
apply (auto)
apply (case_tac r)
apply (auto)
apply (case_tac p)
apply (auto)
apply (case_tac r)
apply (auto)
done
lemma union_use_leq2: "\<lbrakk> leq_perm p r \<rbrakk> \<Longrightarrow> leq_perm p (union_perm q r)"
apply (case_tac r)
apply (auto)
apply (case_tac q)
apply (auto)
apply (case_tac p)
apply (auto)
apply (case_tac q)
apply (auto)
apply (case_tac q)
apply (auto)
done
lemma dir_add_leq_permx: "\<lbrakk> t_sub x = None \<rbrakk> \<Longrightarrow> leq_perm (dir_subst_permx t_sub p_sub r) (dir_subst_permx (dir_add_env t_sub x tau) p_sub r)"
apply (induct r)
apply (auto)
apply (case_tac "sol_subst_perm p_sub xa")
apply (auto)
apply (simp add: dir_add_env_def)
apply (auto)
apply (case_tac "t_sub xa")
apply (auto)
apply (case_tac "as_perm (req_type a)")
apply (auto)
apply (rule_tac dist_union_use_leq)
apply (rule_tac union_use_leq1)
apply (auto)
apply (rule_tac union_use_leq2)
apply (auto)
apply (case_tac "dir_subst_permx t_sub p_sub r")
apply (auto)
apply (case_tac "dir_subst_permx t_sub p_sub r1")
apply (auto)
done
lemma dir_add_leq_use_env: "\<lbrakk> tsub_dom t_sub ds; x \<notin> ds \<rbrakk> \<Longrightarrow> leq_use_env (dir_subst_penv t_sub p_sub r_sv) (dir_subst_penv (dir_add_env t_sub x tau) p_sub r_sv)"
apply (simp add: leq_use_env_def)
apply (simp add: dir_subst_penv_def)
apply (auto)
apply (simp add: tsub_dom_def)
apply (erule_tac x="x" in allE)
apply (auto)
apply (rule_tac dir_add_leq_permx)
apply (simp)
done
lemma dom_list_contain: "\<lbrakk> x \<in> dom_list_set l \<rbrakk> \<Longrightarrow> list_contain (dom_list l) x"
apply (induct l)
apply (auto)
done
lemma dom_list_contain_rev: "\<lbrakk> list_contain (dom_list l) x \<rbrakk> \<Longrightarrow> x \<in> dom_list_set l"
apply (induct l)
apply (auto)
done
lemma dir_list_add_leq_use_env: "\<lbrakk> tsub_dom t_sub ds; fresh_list ds (dom_list l) \<rbrakk> \<Longrightarrow>
leq_use_env (dir_subst_penv t_sub p_sub r_sv) (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv)"
apply (induct l)
apply (auto)
apply (rule_tac id_leq_use_env)
apply (rule_tac r_sb="dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv" in trans_leq_use_env)
apply (rule_tac ds="ds \<union> (dom_list_set l)" in dir_add_leq_use_env)
apply (rule_tac ds="ds" in list_add_tsub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (cut_tac x="a" and l="l" in dom_list_contain)
apply (simp)
apply (simp add: fresh_list_def)
apply (simp add: fresh_list_def)
done
lemma dir_list_append_eq_ih: "dir_list_add_env t_sub (l @ la) a = dir_list_add_env (dir_list_add_env t_sub la) l a"
apply (induct l)
apply (auto)
apply (simp add: dir_add_env_def)
done
lemma dir_list_append_eq: "dir_list_add_env t_sub (l @ la) = dir_list_add_env (dir_list_add_env t_sub la) l"
apply (case_tac "\<forall> a. dir_list_add_env t_sub (l @ la) a = dir_list_add_env (dir_list_add_env t_sub la) l a")
apply (auto)
apply (simp add: dir_list_append_eq_ih)
done
lemma ifz_sol_subst_penv: "\<lbrakk> p_sub p = NoPerm \<rbrakk> \<Longrightarrow> dir_subst_penv t_sub p_sub (ifz_var_env (XPerm (SVar p)) r_sv) = empty_use_env"
apply (case_tac "\<forall> x. dir_subst_penv t_sub p_sub (ifz_var_env (XPerm (SVar p)) r_sv) x = empty_use_env x")
apply (auto)
apply (simp add: dir_subst_penv_def)
apply (simp add: ifz_var_env_def)
apply (simp add: empty_use_env_def)
apply (case_tac "r_sv x = XPerm (SPerm NoPerm)")
apply (auto)
done
(* #### pvar / tvar lemmas *)
fun pvar_aff where
"pvar_aff (AffConst a) = {}"
| "pvar_aff (AffVar v) = {v}"
fun pvar_type where
"pvar_type IntScheme = {}"
| "pvar_type BoolScheme = {}"
| "pvar_type UnitScheme = {}"
| "pvar_type (VarScheme v) = {}"
| "pvar_type (ArrayScheme tau) = pvar_type tau"
| "pvar_type (PairScheme t1 t2 p) = pvar_type t1 \<union> pvar_type t2 \<union> pvar_set_perm p"
| "pvar_type (FunScheme t1 t2 p a) = pvar_type t1 \<union> pvar_type t2 \<union> pvar_set_perm p \<union> pvar_aff a"
| "pvar_type (ChanScheme tau c_end) = pvar_type tau"
lemma comp_subst_aff: "\<lbrakk> psub_dom p_subx ds; pvar_aff a \<inter> ds = {} \<rbrakk> \<Longrightarrow>
sol_subst_aff p_sub a = sol_subst_aff (comp_use_env p_sub p_subx) a"
apply (case_tac a)
apply (auto)
apply (simp add: psub_dom_def)
apply (simp add: comp_use_env_def)
apply (erule_tac x="x2" in allE)
apply (auto)
apply (case_tac "p_sub x2")
apply (auto)
done
lemma comp_dir_subst_type1: "\<lbrakk> dir_subst_type t_sub p_sub tau_v tau;
pvar_type tau_v \<subseteq> ds; psub_dom p_subx ds'; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_subst_type t_sub (comp_use_env p_sub p_subx) tau_v tau"
apply (induct tau_v arbitrary: tau)
apply (auto)
apply (simp add: comp_subst_perm)
apply (simp add: comp_subst_perm)
apply (rule_tac comp_subst_aff)
apply (auto)
done
lemma comp_dir_subst_type2: "\<lbrakk> dir_subst_type t_sub p_subx tau_v tau;
pvar_type tau_v \<subseteq> ds; psub_dom p_sub ds'; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_subst_type t_sub (comp_use_env p_sub p_subx) tau_v tau"
apply (cut_tac r_s="p_sub" and r_x="p_subx" in comm_comp_use_env)
apply (auto)
apply (rule_tac comp_dir_subst_type1)
apply (auto)
done
lemma add_subst_aff: "\<lbrakk> p \<notin> pvar_aff a \<rbrakk> \<Longrightarrow>
sol_subst_aff p_sub a = sol_subst_aff (add_use_env p_sub p r) a"
apply (case_tac a)
apply (auto)
apply (simp add: add_use_env_def)
done
lemma add_dir_subst_type: "\<lbrakk> dir_subst_type t_sub p_sub tau_v tau; p \<notin> pvar_type tau_v \<rbrakk> \<Longrightarrow>
dir_subst_type t_sub (add_use_env p_sub p r) tau_v tau"
apply (induct tau_v arbitrary: tau)
apply (auto)
apply (simp add: add_subst_perm)
apply (simp add: add_subst_perm)
apply (rule_tac add_subst_aff)
apply (auto)
done
lemma dir_add_subst_permx: "\<lbrakk> x \<notin> tvar_set px \<rbrakk> \<Longrightarrow>
dir_subst_permx (dir_add_env t_sub x tau) p_sub px = dir_subst_permx t_sub p_sub px"
apply (induct px)
apply (auto)
apply (simp add: dir_add_env_def)
done
lemma dir_add_subst_type: "\<lbrakk> dir_subst_type t_sub p_sub tau_v tau; x \<notin> tvar_type tau_v \<rbrakk> \<Longrightarrow>
dir_subst_type (dir_add_env t_sub x t) p_sub tau_v tau"
apply (induct tau_v arbitrary: tau)
apply (auto)
apply (simp add: dir_add_env_def)
done
lemma dir_list_add_subst_type: "\<lbrakk> dir_subst_type t_sub p_sub tau_v tau; tvar_type tau_v \<inter> dom_list_set l = {} \<rbrakk> \<Longrightarrow>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau"
apply (induct l arbitrary: tau_v tau)
apply (auto)
apply (rule_tac dir_add_subst_type)
apply (auto)
done
lemma infer_tvar_type: "\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \<rbrakk> \<Longrightarrow> tvar_type tau_v \<subseteq> ds'"
apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')
apply (auto)
(* const + op case *)
apply (case_tac x)
apply (auto)
apply (simp_all add: pure_fun_s_def)
apply (case_tac x)
apply (auto)
apply (simp_all add: pure_fun_s_def)
(* var case *)
apply (simp add: sub_range_def)
apply (erule_tac x="res_name x" in allE)
apply (auto)
(* pair case *)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (simp)
apply (cut_tac c="x" and A="tvar_type t1" and B="ds2" in contra_subsetD)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (auto)
apply (cut_tac c="x" and A="tvar_type t2" and B="ds3" in contra_subsetD)
apply (auto)
(* if case *)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (simp)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (auto)
apply (case_tac "x \<in> ds'")
apply (auto)
apply (cut_tac c="x" and A="tvar_type t2" and B="ds3" in contra_subsetD)
apply (auto)
(* lam case *)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and x="Var x1a" and a="a" in add_sub_range)
apply (auto)
apply (cut_tac c="x" and A="tvar_type t2" and B="ds2" in contra_subsetD)
apply (auto)
done
lemma ipvt_const: "\<lbrakk>sub_range env_v ds; xa \<in> pvar_type tau_v; const_scheme x ds tau_v c_list ds'\<rbrakk> \<Longrightarrow> xa \<in> set_diff ds' ds"
apply (case_tac x)
apply (auto)
apply (simp_all add: pure_fun_s_def)
apply (simp_all add: set_diff_def)
apply (simp_all add: fresh_list_def)
apply (auto)
done
lemma infer_pvar_type: "\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \<rbrakk> \<Longrightarrow> pvar_type tau_v \<subseteq> set_diff ds' ds"
apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')
apply (auto)
(* const + op case *)
apply (rule_tac ipvt_const)
apply (auto)
apply (case_tac x)
apply (auto)
apply (simp_all add: pure_fun_s_def)
(* pair case p1. *)
apply (simp add: set_diff_def)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (simp)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (case_tac "\<not> pvar_type t1 \<subseteq> ds2 - ds")
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac "x \<notin> ds2")
apply (auto)
apply (case_tac "x \<in> ds")
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
(* pair case p2. *)
apply (case_tac "\<not> pvar_type t2 \<subseteq> ds3 - ds2")
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac "x \<notin> ds3")
apply (auto)
apply (case_tac "x \<in> ds2")
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
(* if case *)
apply (case_tac "\<not> pvar_type t2 \<subseteq> ds3 - ds2")
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (simp)
apply (simp add: set_diff_def)
apply (case_tac "x \<notin> ds3")
apply (auto)
apply (case_tac "x \<in> ds2")
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
(* lam case *)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac "\<not> pvar_type t2 \<subseteq> ds2 - (insert a ds)")
apply (cut_tac env_v="env_v" and ds="ds" and x="Var x1a" and a="a" in add_sub_range)
apply (simp)
apply (simp add: set_diff_def)
apply (case_tac "p \<notin> ds2")
apply (auto)
apply (case_tac "a \<in> insert a ds")
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)(*
apply (cut_tac env_v="add_env env_v (Var x1a) a" and r_sv="r_s'" and ds'="ds2" in infer_s_sub_range)
apply (auto)*)
apply (cut_tac env_v="env_v" and ds="ds" and x="Var x1a" and a="a" in add_sub_range)
apply (auto)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac c="x" and A="pvar_type t2" and B="ds2 - (insert a ds)" in contra_subsetD)
apply (auto)
apply (cut_tac c="x" and A="pvar_type t2" and B="ds2 - (insert a ds)" in contra_subsetD)
apply (auto)
done
(* #### auxiliary lemmas *)
(*
when we call "infer" on an expression, we receive a constraint set representing the set of all possible solutions for well-typedness.
suppose that an expression is well-typed, and we have a partial solution to the constraint set, solving all permission based constraints,
reducing all constraints to just type-based constraints.
Gamma, P1 |- e: tau, P2, Q \<and> Infer(Gamma*, X, e) = (tau*, P*, Q*, R*, K, X') \<and>
\<rho>( P* ) \<le> P1 \<and> \<rho>( tau* ) \<le> tau \<and> Gamma* \<le> Gamma \<Longrightarrow>
(\<exists> \<sigma>. \<sigma> |= \<rho>(K) \<and> \<sigma>( Gamma* ) = Gamma \<and> \<sigma>(\<rho>( tau* )) = tau)
Gamma, P1 |- e: tau, P2, Q \<and> Infer(Gamma*, X, e) = (tau*, P*, Q*, R*, K, X')
Gamma* \<le> Gamma \<Longrightarrow>
(\<exists> \<sigma>. \<sigma> |~ K \<and> \<sigma>( Gamma* ) = Gamma \<and> \<sigma>( tau* ) = tau)
*)
lemma dir_subst_spec_env_ex: "\<lbrakk> spec_env env_v env t_subx \<rbrakk> \<Longrightarrow> dir_subst_tenv t_subx env_v = env"
apply (case_tac "\<forall> x. dir_subst_tenv t_subx env_v x = env x")
apply (auto)
apply (simp add: dir_subst_tenv_def)
apply (simp add: spec_env_def)
apply (erule_tac x="x" in allE)
apply (case_tac "env_v x")
apply (auto)
done
lemma dir_subst_spec_env: "\<lbrakk> spec_env env_v env t_subx \<rbrakk> \<Longrightarrow> \<exists>t_sub. dir_subst_tenv t_sub env_v = env"
apply (rule_tac x="t_subx" in exI)
apply (rule_tac dir_subst_spec_env_ex)
apply (simp)
done
lemma ivrcc_prim_case: "\<lbrakk> spec_env env_v env t_sub; tsub_dom t_sub ds \<rbrakk> \<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds \<and>
fresh_list ds (dom_list l) \<and> dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and> (\<exists>p_sub. psub_dom p_sub {})"
apply (rule_tac x="[]" in exI)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac dir_subst_spec_env_ex)
apply (simp)
apply (rule_tac x="empty_use_env" in exI)
apply (simp add: psub_dom_def)
apply (simp add: empty_use_env_def)
done
lemma ivrcc_array_case: "\<lbrakk> spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds;
ta \<notin> ds; req_type t \<noteq> Aff \<rbrakk> \<Longrightarrow>
\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert ta ds) \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (insert ta ds - ds)) \<and>
dir_list_add_env t_sub l ta = Some t \<and> (\<exists>tau_x. dir_list_add_env t_sub l ta = Some tau_x \<and> aff_leq (req_type tau_x) UsePerm)"
apply (rule_tac x="[(ta, t)]" in exI)
apply (auto)
apply (rule_tac add_tsub_dom)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac ds="ds" in dir_add_eq_env)
apply (rule_tac dir_subst_spec_env_ex)
apply (auto)
apply (rule_tac x="empty_use_env" in exI)
apply (rule_tac empty_psub_dom)
apply (simp add: dir_add_env_def)
apply (rule_tac x="t" in exI)
apply (simp add: dir_add_env_def)
apply (case_tac "req_type t")
apply (auto)
done
lemma ivrcc_chan_case: "\<lbrakk> spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; ta \<notin> ds \<rbrakk> \<Longrightarrow>
\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert ta ds) \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and> (\<exists>p_sub. psub_dom p_sub (insert ta ds - ds)) \<and> dir_list_add_env t_sub l ta = Some t"
apply (rule_tac x="[(ta, t)]" in exI)
apply (auto)
apply (rule_tac add_tsub_dom)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac dir_add_eq_env)
apply (rule_tac dir_subst_spec_env_ex)
apply (auto)
apply (rule_tac x="empty_use_env" in exI)
apply (rule_tac empty_psub_dom)
apply (simp add: dir_add_env_def)
done
lemma empty_cut_use_env: "cut_use_env empty_use_env = empty_use_env"
apply (case_tac "\<forall> x. cut_use_env empty_use_env x = empty_use_env x")
apply (auto)
apply (simp add: cut_use_env_def)
apply (simp add: empty_use_env_def)
done
lemma ivr_const_case: "\<lbrakk>spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; tau \<in> const_type x; const_scheme x ds tau_v c_list ds';
leq_use_env (diff_use_env r_s r_ex) r_s; leq_use_env r_x (diff_use_env r_s r_ex)\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)"
apply (simp add: empty_leq_var_env)
apply (simp add: subst_empty_var_env)
apply (simp add: diff_empty_use_env1)
apply (simp add: empty_cut_use_env)
apply (simp add: leq_empty_use_env)
apply (case_tac x)
apply (auto)
apply (simp_all add: pure_fun_def)
apply (simp_all add: pure_fun_s_def)
apply (simp_all add: unlim_def)
apply (simp_all add: set_diff_def)
(* basic cases *)
apply (rule_tac ivrcc_prim_case)
apply (auto)
apply (rule_tac ivrcc_prim_case)
apply (auto)
apply (rule_tac ivrcc_prim_case)
apply (auto)
(* fixed point *)
apply (case_tac t)
apply (auto)
apply (rule_tac x="[(t2, x62), (t1, x61)]" in exI)
apply (auto)
apply (rule_tac add_tsub_dom)
apply (rule_tac add_tsub_dom)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac ds="ds" in dir_add_eq_env)
apply (rule_tac ds="ds" in dir_add_eq_env)
apply (rule_tac dir_subst_spec_env_ex)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: dir_add_env_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac x="add_use_env (add_use_env empty_use_env p x63) q (as_perm x64)" in exI)
apply (auto)
apply (rule_tac add_psub_dom)
apply (rule_tac add_psub_dom)
apply (rule_tac empty_psub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (simp add: add_use_env_def)
apply (simp add: trip_convert)
apply (simp add: fresh_list_def)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (simp add: add_use_env_def)
apply (simp add: trip_convert)
apply (simp add: add_use_env_def)
apply (case_tac x64)
apply (auto)
(* array cases *)
apply (rule_tac ivrcc_array_case)
apply (auto)
apply (rule_tac ivrcc_array_case)
apply (auto)
apply (rule_tac ivrcc_array_case)
apply (auto)
apply (rule_tac ivrcc_array_case)
apply (auto)
(* unpack *)
apply (rule_tac x="[(t1a, t1), (t2a, t2), (txa, tx)]" in exI)
apply (auto)
apply (rule_tac add_tsub_dom)
apply (rule_tac add_tsub_dom)
apply (rule_tac add_tsub_dom)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac ds="ds" in dir_add_eq_env)
apply (rule_tac ds="ds" in dir_add_eq_env)
apply (rule_tac ds="ds" in dir_add_eq_env)
apply (rule_tac dir_subst_spec_env_ex)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (rule_tac x="add_use_env (add_use_env empty_use_env p r) p' r'" in exI)
apply (auto)
apply (rule_tac add_psub_dom)
apply (rule_tac add_psub_dom)
apply (rule_tac empty_psub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: dir_add_env_def)
apply (simp add: dir_add_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: dir_add_env_def)
apply (simp add: dir_add_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: dir_add_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: dir_add_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (auto)
(* simp chan cases *)
apply (simp_all add: is_own_def)
apply (rule_tac ivrcc_chan_case)
apply (auto)
apply (rule_tac ivrcc_chan_case)
apply (auto)
apply (rule_tac ivrcc_chan_case)
apply (auto)
(* fork *)
apply (rule_tac x="[]" in exI)
apply (auto)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac dir_subst_spec_env_ex)
apply (auto)
apply (rule_tac x="add_use_env empty_use_env p (as_perm a)" in exI)
apply (auto)
apply (rule_tac add_psub_dom)
apply (rule_tac empty_psub_dom)
apply (auto)
apply (simp add: add_use_env_def)
apply (simp add: trip_convert)
done
lemma ivr_op_case: "\<lbrakk>spec_env env_v env t_sub; sub_range env_v ds'; tsub_dom t_sub ds'; leq_use_env (diff_use_env r_s r_ex) r_s; leq_use_env r_x (diff_use_env r_s r_ex)\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds' (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds') \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub (op_scheme x) (op_type x))"
apply (rule_tac x="[]" in exI)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac dir_subst_spec_env_ex)
apply (simp)
apply (rule_tac x="empty_use_env" in exI)
apply (simp add: empty_psub_dom)
apply (simp add: empty_leq_var_env)
apply (simp add: subst_empty_var_env)
apply (simp add: diff_empty_use_env1)
apply (simp add: empty_cut_use_env)
apply (simp add: leq_empty_use_env)
apply (case_tac x)
apply (auto)
apply (simp_all add: pure_fun_def)
apply (simp_all add: pure_fun_s_def)
done
(*
we want to show that if we subtract EX from our constructed requirements - constructed subtractant,
we will end up with a result contained in Q. (that our total construction is minimal).
`(X - M) - EX \<le> Q`
by induction, our constructed reqs should be less than the real reqs. the key then is to make
sure that we are subtracting our "enough". both the real subtractant + the artificial subtractant.
we can know that we are since EX subtracts more than both of these.
(X - M) \<le> rx \<and> rx - EX' \<le> Q \<le> P1 - EX' \<le> P1 - EX
*)
lemma squish_leq_use_env: "\<lbrakk> leq_use_env (diff_use_env r_s r_ex') (diff_use_env r_c r_ex);
leq_use_env (diff_use_env r_c r_ex) (diff_use_env r_c r_ex'); leq_use_env r_x r_s; leq_use_env r_s r_c \<rbrakk> \<Longrightarrow>
leq_use_env (diff_use_env r_x r_ex) (diff_use_env r_s r_ex')"
apply (simp add: leq_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (simp add: diff_use_env_def)
apply (case_tac "r_x x")
apply (auto)
apply (case_tac "r_ex x")
apply (auto)
apply (case_tac "r_ex x")
apply (auto)
apply (case_tac "r_ex' x")
apply (auto)
apply (case_tac "r_c x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_ex' x")
apply (auto)
apply (case_tac "r_c x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_c x")
apply (auto)
done
lemma crush_leq_use_env: "\<lbrakk> leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s r_ex'); leq_use_env r_xa r_s;
leq_use_env (diff_use_env r_xb r_ex) r_xa \<rbrakk> \<Longrightarrow>
leq_use_env (diff_use_env r_xb r_ex) (diff_use_env r_xa r_ex')"
apply (simp add: leq_use_env_def)
apply (simp add: diff_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (case_tac "r_ex x")
apply (auto)
apply (case_tac "r_ex' x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_xa x")
apply (auto)
apply (case_tac "r_ex' x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_xa x")
apply (auto)
done
lemma dist_diff_leq_use_env_rev: "\<lbrakk> leq_use_env r_exa r_s; leq_use_env (diff_use_env r_s r_exb) (diff_use_env r_s r_exa) \<rbrakk> \<Longrightarrow>
leq_use_env (cut_use_env r_exa) r_exb"
apply (simp add: leq_use_env_def)
apply (simp add: diff_use_env_def)
apply (simp add: cut_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (case_tac "r_exa x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
done
lemma ivrvc_ineq: "\<lbrakk> t_sub b = Some tau_x \<rbrakk> \<Longrightarrow>
leq_use_env (dir_subst_penv t_sub p_sub (one_var_env (owner_name x) (XType b))) (ereq_use_env (owner_name x) tau_x)"
apply (simp add: leq_use_env_def)
apply (simp add: dir_subst_penv_def)
apply (simp add: one_var_env_def)
apply (simp add: ereq_use_env_def)
apply (simp add: one_use_env_def)
apply (simp add: end_req_perm_def)
apply (case_tac "req_type tau_x")
apply (auto)
done
lemma dist_cut_leq_use_env: "\<lbrakk> leq_use_env r_x r_s \<rbrakk> \<Longrightarrow> leq_use_env (cut_use_env r_x) (cut_use_env r_s)"
apply (simp add: leq_use_env_def)
apply (simp add: cut_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (case_tac "r_x x")
apply (auto)
done
lemma rhs_cut_leq_use_env: "\<lbrakk> leq_use_env (cut_use_env r_x) r_s \<rbrakk> \<Longrightarrow> leq_use_env (cut_use_env r_x) (cut_use_env r_s)"
apply (simp add: leq_use_env_def)
apply (simp add: cut_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (case_tac "r_x x")
apply (auto)
done
lemma dist_cut_comp_use_env: "cut_use_env (comp_use_env r_s r_x) = comp_use_env (cut_use_env r_s) (cut_use_env r_x)"
apply (case_tac "\<forall> x. cut_use_env (comp_use_env r_s r_x) x = comp_use_env (cut_use_env r_s) (cut_use_env r_x) x")
apply (auto)
apply (simp add: cut_use_env_def)
apply (simp add: comp_use_env_def)
apply (case_tac "r_s x")
apply (auto)
apply (simp_all add: comp_use_env_def)
apply (case_tac "r_x x")
apply (auto)
apply (simp_all add: comp_use_env_def)
apply (case_tac "r_x x")
apply (auto)
apply (simp add: comp_use_env_def)
done
lemma lhs_dist_cut_leq_use_env: "\<lbrakk> leq_use_env (comp_use_env (cut_use_env r_s) (cut_use_env r_x)) r_c \<rbrakk> \<Longrightarrow>
leq_use_env (cut_use_env (comp_use_env r_s r_x)) r_c"
apply (simp add: dist_cut_comp_use_env)
done
lemma ivr_var_case: "\<lbrakk>spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; env (res_name x) = Some tau; env_v (res_name x) = Some a;
env (owner_name x) = Some tau_x; value_req x tau tau_x; env_v (owner_name x) = Some b; leq_use_env (ereq_use_env (owner_name x) tau_x) r_s;
leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)); leq_use_env r_x (diff_use_env r_s r_ex);
leq_use_env r_exa r_s; leq_use_env (diff_use_env (ereq_use_env (owner_name x) tau_x) (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)) r_x\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (one_var_env (owner_name x) (XType b))) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (one_var_env (owner_name x) (XType b))) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (one_var_env (owner_name x) (XType b)))) r_ex \<and>
dir_list_add_env t_sub l a = Some tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub (var_val_crn x (VarScheme a) (VarScheme b)))"
apply (rule_tac x="[]" in exI)
apply (auto)
apply (simp add: fresh_list_def)
apply (rule_tac dir_subst_spec_env_ex)
apply (simp)
apply (case_tac "t_sub a \<noteq> Some tau")
apply (simp add: spec_env_def)
apply (erule_tac x="res_name x" in allE)
apply (case_tac "env_v (res_name x)")
apply (auto)
apply (case_tac "t_sub b \<noteq> Some tau_x")
apply (simp add: spec_env_def)
apply (erule_tac x="owner_name x" in allE)
apply (case_tac "env_v (owner_name x)")
apply (auto)
apply (cut_tac t_sub="t_sub" and x="x" and b="b" and tau_x="tau_x" in ivrvc_ineq)
apply (auto)
apply (rule_tac x="empty_use_env" in exI)
apply (auto)
apply (rule_tac empty_psub_dom)
apply (rule_tac r_sb="ereq_use_env (owner_name x) tau_x" in trans_leq_use_env)
apply (simp_all)(*
apply (rule_tac st_diff_comp_leq_use_env)*)
apply (rule_tac r_sb="diff_use_env (ereq_use_env (owner_name x) tau_x) (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)" in trans_leq_use_env)
apply (simp)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (simp_all)
apply (rule_tac diff_leq_use_env)
apply (simp)
apply (rule_tac r_sb="cut_use_env (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)" in trans_leq_use_env)
apply (rule_tac r_s="r_s" in dist_diff_leq_use_env_rev)
apply (rule_tac dist_comp_leq_use_env)
apply (simp_all)
apply (rule_tac dist_cut_leq_use_env)
apply (rule_tac comp_leq_use_env1)
apply (simp)
apply (case_tac x)
apply (auto)(*
apply (rule_tac r_sb="diff_use_env (ereq_use_env (owner_name x) tau_x) (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)" in trans_leq_use_env)
apply (auto)
apply (rule_tac r_c="r_s" in squish_leq_use_env)
apply (rule_tac r_sb="r_x" in trans_leq_use_env)
apply (auto)*)
done
lemma ivrpc_coerce: "\<lbrakk> \<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds \<rbrakk> \<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)"
apply (auto)
done
lemma sub_snorm_use_env: "\<lbrakk> leq_use_env r_exa r_s; leq_use_env r_x (diff_use_env r_s r_exa);
\<forall> x. super_norm_use_env (diff_use_env r_s r_exa) r_x x = diff_use_env (diff_use_env r_s r_exa) r_exb x \<rbrakk> \<Longrightarrow>
diff_use_env r_s (comp_use_env r_exa r_exb) = super_norm_use_env r_s r_x"
apply (case_tac "\<forall> x. diff_use_env r_s (comp_use_env r_exa r_exb) x = super_norm_use_env r_s r_x x")
apply (auto)
apply (erule_tac x="x" in allE)
apply (simp add: leq_use_env_def)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (simp add: super_norm_use_env_def)
apply (simp add: diff_use_env_def)
apply (simp add: comp_use_env_def)
apply (case_tac "diff_perm (r_s x) (r_exa x) = OwnPerm \<and> r_x x = NoPerm")
apply (auto)
apply (case_tac "r_exa x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (simp add: diff_use_env_def)
apply (case_tac "r_s x = OwnPerm \<and> r_x x = NoPerm")
apply (auto)
apply (case_tac "r_exa x")
apply (auto)
apply (case_tac "r_exa x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_exa x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (case_tac "r_x x")
apply (auto)
apply (simp add: diff_use_env_def)
apply (case_tac "r_exa x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (case_tac "r_exb x")
apply (auto)
apply (case_tac "r_x x")
apply (auto)
done
lemma ivr_induct_format: "\<lbrakk> well_typed env r_s1 e1 t1 r_s2 rx1; well_typed env r_s2 e2 t2 r_s3 rx2 \<rbrakk> \<Longrightarrow>
(\<exists> r_exa r_exb. leq_use_env r_exa r_s1 \<and> leq_use_env r_exb (diff_use_env r_s1 r_exa) \<and>
super_norm_use_env r_s1 r_s3 = diff_use_env r_s1 (comp_use_env r_exa r_exb) \<and>
well_typed env r_s1 e1 t1 (diff_use_env r_s1 r_exa) rx1 \<and>
well_typed env (diff_use_env r_s1 r_exa) e2 t2 (diff_use_env (diff_use_env r_s1 r_exa) r_exb) rx2)"
apply (cut_tac env="env" and e="e1" in well_typed_sstr_end_perm)
apply (auto)
apply (cut_tac env="env" and r_c="super_norm_use_env r_s1 r_s2" and e="e2" in well_typed_incr_start_perm)
apply (auto)
apply (rule_tac rhs_snorm_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac id_leq_use_env)
apply (cut_tac r_s="r_s1" and r_x="r_s2" in snorm_diff_use_env)
apply (auto)
apply (cut_tac env="env" and ?r_s1.0="diff_use_env r_s1 r_ex" and e="e2" in well_typed_sstr_end_perm)
apply (auto)
apply (cut_tac r_s="diff_use_env r_s1 r_ex" and r_x="r_s3" in snorm_diff_use_env)
apply (auto)
apply (rule_tac x="r_ex" in exI)
apply (auto)
apply (rule_tac x="r_exa" in exI)
apply (auto)
apply (cut_tac r_s="r_s1" and r_x="r_s3" and r_exa="r_ex" and r_exb="r_exa" in sub_snorm_use_env)
apply (auto)
apply (rule_tac well_typed_perm_leq)
apply (auto)
done
lemma sol_sat_split: "\<lbrakk> dir_sol_sat t_sub p_sub cl1; dir_sol_sat t_sub p_sub cl2 \<rbrakk> \<Longrightarrow> dir_sol_sat t_sub p_sub (cl1 @ cl2)"
apply (induct cl1)
apply (auto)
done
fun tvar_crn where
"tvar_crn (UnifyCrn t1 t2) = (tvar_type t1 \<union> tvar_type t2)"
| "tvar_crn (MemValCrn tau tau_x) = (tvar_type tau \<union> tvar_type tau_x)"
| "tvar_crn (LeqCrn px q) = (tvar_set px)"
| "tvar_crn (LeqTypeCrn tau px) = (tvar_type tau)"
| "tvar_crn (DisjCrn px qx) = (tvar_set px \<union> tvar_set qx)"
| "tvar_crn (SemiDisjCrn px qx) = (tvar_set px \<union> tvar_set qx)"
fun tvar_crn_list where
"tvar_crn_list [] = {}"
| "tvar_crn_list (c # c_t) = (tvar_crn c \<union> tvar_crn_list c_t)"
fun pvar_crn where
"pvar_crn (UnifyCrn t1 t2) = (pvar_type t1 \<union> pvar_type t2)"
| "pvar_crn (MemValCrn tau tau_x) = (pvar_type tau \<union> pvar_type tau_x)"
| "pvar_crn (LeqCrn px q) = (pvar_set px \<union> pvar_set_perm q)"
| "pvar_crn (LeqTypeCrn tau px) = (pvar_type tau \<union> pvar_set_perm px)"
| "pvar_crn (DisjCrn px qx) = (pvar_set px \<union> pvar_set qx)"
| "pvar_crn (SemiDisjCrn px qx) = (pvar_set px \<union> pvar_set qx)"
fun pvar_crn_list where
"pvar_crn_list [] = {}"
| "pvar_crn_list (c # c_t) = (pvar_crn c \<union> pvar_crn_list c_t)"
lemma dir_add_sol_crn: "\<lbrakk> dir_sol_crn t_sub p_sub c; x \<notin> tvar_crn c \<rbrakk> \<Longrightarrow> dir_sol_crn (dir_add_env t_sub x tau) p_sub c"
apply (case_tac c)
apply (auto)
apply (simp_all add: dir_add_subst_permx)
apply (rule_tac x="tau_x" in exI)
apply (simp add: dir_add_subst_type)
apply (rule_tac x="t'" in exI)
apply (rule_tac x="tx'" in exI)
apply (simp add: dir_add_subst_type)
apply (rule_tac x="tau_x" in exI)
apply (simp add: dir_add_subst_type)
done
lemma dir_add_sol_sat: "\<lbrakk> dir_sol_sat t_sub p_sub c_list; x \<notin> tvar_crn_list c_list \<rbrakk> \<Longrightarrow> dir_sol_sat (dir_add_env t_sub x tau) p_sub c_list"
apply (induct c_list)
apply (auto)
apply (rule_tac dir_add_sol_crn)
apply (auto)
done
(* if we add variables to t_sub, and those variables are fresh from c_list, solution satisfaction is maintained *)
lemma dir_list_add_sol_sat: "\<lbrakk> dir_sol_sat t_sub p_sub c_list; (dom_list_set l) \<inter> (tvar_crn_list c_list) = {} \<rbrakk> \<Longrightarrow>
dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list"
apply (induct l)
apply (auto)
apply (rule_tac dir_add_sol_sat)
apply (auto)
done
lemma add_psub_sol_crn: "\<lbrakk> dir_sol_crn t_sub p_sub c; x \<notin> pvar_crn c \<rbrakk> \<Longrightarrow>
dir_sol_crn t_sub (add_use_env p_sub x r) c"
apply (case_tac c)
apply (auto)
apply (simp_all add: add_subst_permx)
apply (rule_tac x="tau_x" in exI)
apply (simp add: add_dir_subst_type)
apply (rule_tac x="t'" in exI)
apply (rule_tac x="tx'" in exI)
apply (simp add: add_dir_subst_type)
apply (simp add: add_subst_perm)
apply (rule_tac x="tau_x" in exI)
apply (auto)
apply (simp add: add_dir_subst_type)
apply (simp add: add_subst_perm)
done
lemma add_psub_sol_sat: "\<lbrakk> dir_sol_sat t_sub p_sub c_list; x \<notin> pvar_crn_list c_list \<rbrakk> \<Longrightarrow>
dir_sol_sat t_sub (add_use_env p_sub x r) c_list"
apply (induct c_list)
apply (auto)
apply (simp add: add_psub_sol_crn)
done
lemma comp_psub_sol_crn: "\<lbrakk> dir_sol_crn t_sub p_sub c; pvar_crn c \<subseteq> ds; psub_dom p_subx ds'; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_sol_crn t_sub (comp_use_env p_sub p_subx) c"
apply (induct c)
apply (auto)
apply (simp_all add: comp_subst_permx)
apply (rule_tac x="tau_x" in exI)
apply (simp add: comp_dir_subst_type1)
apply (rule_tac x="t'" in exI)
apply (rule_tac x="tx'" in exI)
apply (simp add: comp_dir_subst_type1)
apply (simp add: comp_subst_perm)
apply (rule_tac x="tau_x" in exI)
apply (simp add: comp_dir_subst_type1)
apply (simp add: comp_subst_perm)
done
lemma comp_psub_sol_sat1: "\<lbrakk> dir_sol_sat t_sub p_sub c_list; pvar_crn_list c_list \<subseteq> ds; psub_dom p_subx ds'; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_sol_sat t_sub (comp_use_env p_sub p_subx) c_list"
apply (induct c_list)
apply (auto)
apply (simp add: comp_psub_sol_crn)
done
lemma comp_psub_sol_sat2: "\<lbrakk> dir_sol_sat t_sub p_sub c_list; pvar_crn_list c_list \<subseteq> ds; psub_dom p_subx ds'; ds \<inter> ds' = {} \<rbrakk> \<Longrightarrow>
dir_sol_sat t_sub (comp_use_env p_subx p_sub) c_list"
apply (simp add: comm_comp_use_env)
apply (rule_tac comp_psub_sol_sat1)
apply (auto)
done
lemma derive_dom_list_set: "\<lbrakk> tsub_dom (dir_list_add_env t_sub l) ds';
fresh_list ds (dom_list l) \<rbrakk> \<Longrightarrow> dom_list_set l \<subseteq> set_diff ds' ds"
apply (induct l)
apply (auto)
apply (simp add: set_diff_def)
apply (simp add: tsub_dom_def)
apply (simp add: fresh_list_def)
apply (simp add: dir_add_env_def)
apply (case_tac "tsub_dom (dir_list_add_env t_sub l) ds'")
apply (case_tac "fresh_list ds (dom_list l)")
apply (auto)
apply (simp add: fresh_list_def)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and x="a" and ds="ds'" and tau="b" in add_tsub_dom_rev)
apply (auto)
done
(*
lemma infer_tvar_crn_list: "\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds' \<rbrakk> \<Longrightarrow> tvar_crn_list c_list \<subseteq> ds'"
apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')
apply (auto)
*)
lemma tvar_clist_split: "\<lbrakk> x \<in> tvar_crn_list (cl1 @ cl2) \<rbrakk> \<Longrightarrow> x \<in> tvar_crn_list cl1 \<or> x \<in> tvar_crn_list cl2"
apply (induct cl1)
apply (auto)
done
lemma tvar_clist_disj: "\<lbrakk> x \<in> tvar_crn_list (disj_crn r_s r_x d); tvar_range r_s ds; tvar_range r_x ds \<rbrakk> \<Longrightarrow> x \<in> ds"
apply (induct d)
apply (auto)
apply (simp add: tvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
apply (simp add: tvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
done
lemma tvar_clist_semi_disj: "\<lbrakk> x \<in> tvar_crn_list (semi_disj_crn r_s r_x d); tvar_range r_s ds; tvar_range r_x ds \<rbrakk> \<Longrightarrow> x \<in> ds"
apply (induct d)
apply (auto)
apply (simp add: tvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
apply (simp add: tvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
done
lemma tvar_clist_aff: "\<lbrakk> x \<in> tvar_crn_list (aff_crn r_s p d); tvar_range r_s ds; tvar_set_perm p \<subseteq> ds \<rbrakk> \<Longrightarrow> x \<in> ds"
apply (induct d)
apply (auto)
apply (simp add: tvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
done
lemma pvar_clist_split: "\<lbrakk> x \<in> pvar_crn_list (cl1 @ cl2) \<rbrakk> \<Longrightarrow> x \<in> pvar_crn_list cl1 \<or> x \<in> pvar_crn_list cl2"
apply (induct cl1)
apply (auto)
done
lemma pvar_clist_disj: "\<lbrakk> x \<in> pvar_crn_list (disj_crn r_s r_x d); pvar_range r_s ds; pvar_range r_x ds \<rbrakk> \<Longrightarrow> x \<in> ds"
apply (induct d)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
done
lemma pvar_clist_semi_disj: "\<lbrakk> x \<in> pvar_crn_list (semi_disj_crn r_s r_x d); pvar_range r_s ds; pvar_range r_x ds \<rbrakk> \<Longrightarrow> x \<in> ds"
apply (induct d)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
done
lemma pvar_clist_aff: "\<lbrakk> x \<in> pvar_crn_list (aff_crn r_s p d); pvar_range r_s ds; pvar_set_perm p \<subseteq> ds \<rbrakk> \<Longrightarrow> x \<in> ds"
apply (induct d)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="a" in allE)
apply (auto)
done
definition induct_clist where
"induct_clist v_list ds = (v_list \<subseteq> ds)"
lemma infer_tvar_crn_list_ih: "\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \<rbrakk> \<Longrightarrow> induct_clist (tvar_crn_list c_list) ds'"
apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')
apply (auto)
(* const + op case *)
apply (simp add: induct_clist_def)
apply (case_tac x)
apply (auto)
apply (simp add: induct_clist_def)
(* var case *)
apply (simp add: induct_clist_def)
apply (case_tac x)
apply (auto)
apply (simp add: sub_range_def)
apply (erule_tac x="Loc x22" in allE)
apply (auto)
apply (simp add: sub_range_def)
apply (erule_tac x="Loc x21" in allE)
apply (auto)
(* pair case *)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" and env_v="env_v" in subset_sub_range)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_tvar_type)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_tvar_type)
apply (auto)
apply (cut_tac r_sv="r_s1" and r_xv="r_x1" and e="e1" and env_v="env_v" and ds="ds" and ds'="ds2" in infer_tvar_range)
apply (auto)
apply (cut_tac r_sv="r_s2" and r_xv="r_x2" and e="e2" and env_v="env_v" and ds="ds2" and ds'="ds3" in infer_tvar_range)
apply (auto)
apply (cut_tac r_mv="r_m1" and e="e1" and env_v="env_v" and ds="ds" and ds'="ds2" in infer_m_tvar_range)
apply (auto)
apply (cut_tac r_mv="r_m2" and e="e2" and env_v="env_v" and ds="ds2" and ds'="ds3" in infer_m_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d" and
?cl2.0="semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="lift_var_env r_x1 (SVar p)" and r_x="lift_var_env r_x2 (SVar p)" and x="x" and ds="insert p ds3" in tvar_clist_disj)
apply (simp)
apply (rule_tac lift_tvar_range)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (auto)
apply (rule_tac lift_tvar_range)
apply (rule_tac ds="ds3" in subset_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m2 r_x1 d" and
?cl2.0="semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m2" and r_x="r_x1" and x="x" and ds="insert p ds3" in tvar_clist_semi_disj)
apply (simp)
apply (rule_tac ds="ds3" in subset_tvar_range)
apply (auto)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m1 r_s2 d" and ?cl2.0="cl1 @ cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m1" and r_x="r_s2" and x="x" and ds="ds3" in tvar_clist_semi_disj)
apply (simp)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl1" and ?cl2.0="cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac c="x" and A="tvar_crn_list cl1" and B="ds2" in Set.rev_subsetD)
apply (auto)
apply (cut_tac c="x" and A="tvar_crn_list cl2" and B="ds3" in Set.rev_subsetD)
apply (auto)
(* if case *)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and ds'="ds3" in subset_sub_range)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_tvar_type)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_tvar_type)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_tvar_type)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m1 (comp_var_env r_s2 r_s3) d" and
?cl2.0="cl1 @ cl2 @ cl3" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m1" and r_x="comp_var_env r_s2 r_s3" and x="x" and ds="ds'" in tvar_clist_semi_disj)
apply (simp)
apply (cut_tac r_mv="r_m1" and e="e1" and env_v="env_v" and ds="ds" and ds'="ds2" in infer_m_tvar_range)
apply (auto)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (auto)
apply (rule_tac comp_tvar_range)
apply (cut_tac r_sv="r_s2" and e="e2" and env_v="env_v" and ds="ds2" and ds'="ds3" in infer_tvar_range)
apply (auto)
apply (rule_tac ds="ds3" in subset_tvar_range)
apply (auto)
apply (cut_tac r_sv="r_s3" and e="e3" and env_v="env_v" and ds="ds3" and ds'="ds'" in infer_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl1" and ?cl2.0="cl2 @ cl3" in tvar_clist_split)
apply (auto)
apply (cut_tac c="x" and A="tvar_crn_list cl1" and B="ds2" in Set.rev_subsetD)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl2" and ?cl2.0="cl3" in tvar_clist_split)
apply (auto)
apply (cut_tac c="x" and A="tvar_crn_list cl2" and B="ds3" in Set.rev_subsetD)
apply (auto)
apply (cut_tac c="x" and A="tvar_crn_list cl3" and B="ds'" in Set.rev_subsetD)
apply (auto)
(* lam case *)
apply (simp add: induct_clist_def)
apply (auto)
apply (cut_tac r_sv="r_s'" and e="e" and env_v="add_env env_v (Var x1a) a" in infer_tvar_range)
apply (auto)
apply (rule_tac add_sub_range)
apply (simp)
apply (simp add: tvar_range_def)
apply (erule_tac x="Var x1a" in allE)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d" and ?cl2.0="cl" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="rem_var_env r_s' (Var x1a)" and x="x" and p="SVar q" and ds="insert q ds2" in tvar_clist_aff)
apply (simp)
apply (rule_tac rem_tvar_range)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (cut_tac r_sv="r_s'" and e="e" and env_v="add_env env_v (Var x1a) a" in infer_tvar_range)
apply (auto)
apply (cut_tac e="e" and ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (rule_tac add_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and x="Var x1a" and a="a" in add_sub_range)
apply (simp_all)
apply (cut_tac c="x" and A="tvar_crn_list cl" and B="ds2" in Set.rev_subsetD)
apply (auto)
(* app case *)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (cut_tac r_sv="r_s1" and e="e1" and env_v="env_v" in infer_tvar_range)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_tvar_type)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_tvar_type)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d" and
?cl2.0="semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_x1" and r_x="lift_var_env r_x2 (SVar p)" and x="x" and ds="insert p ds3" in tvar_clist_disj)
apply (auto)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (cut_tac r_sv="r_s1" and e="e1" and env_v="env_v" in infer_tvar_range)
apply (auto)
apply (rule_tac lift_tvar_range)
apply (auto)
apply (rule_tac ds="ds3" in subset_tvar_range)
apply (auto)
apply (cut_tac r_sv="r_s2" and e="e2" and ds="ds2" and env_v="env_v" in infer_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m2 r_x1 d" and ?cl2.0="semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m2" and r_x="r_x1" and x="x" and ds="insert p ds3" in tvar_clist_semi_disj)
apply (auto)
apply (rule_tac ds="ds3" in subset_tvar_range)
apply (auto)
apply (rule_tac env_v="env_v" and ds="ds2" in infer_m_tvar_range)
apply (auto)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" in infer_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m1 r_s2 d" and ?cl2.0="cl1 @ cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m1" and r_x="r_s2" and x="x" and ds="insert p ds3" in tvar_clist_semi_disj)
apply (auto)
apply (rule_tac ds="ds2" in subset_tvar_range)
apply (auto)
apply (rule_tac env_v="env_v" and ds="ds" in infer_m_tvar_range)
apply (auto)
apply (rule_tac ds="ds3" in subset_tvar_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" in infer_tvar_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl1" and ?cl2.0="cl2" in tvar_clist_split)
apply (auto)
apply (cut_tac c="x" and A="tvar_crn_list cl1" and B="ds2" in Set.rev_subsetD)
apply (auto)
apply (cut_tac c="x" and A="tvar_crn_list cl2" and B="ds3" in Set.rev_subsetD)
apply (auto)
done
lemma infer_tvar_crn_list: "\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \<rbrakk> \<Longrightarrow> tvar_crn_list c_list \<subseteq> ds'"
apply (cut_tac env_v="env_v" and e="e" and ds="ds" and ds'="ds'" in infer_tvar_crn_list_ih)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
done
lemma infer_pvar_crn_list_ih: "\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \<rbrakk> \<Longrightarrow> induct_clist (pvar_crn_list c_list) (set_diff ds' ds)"
apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')
apply (auto)
(* const + op case *)
apply (simp add: induct_clist_def)
apply (simp add: set_diff_def)
apply (case_tac x)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: induct_clist_def)
(* var case *)
apply (simp add: induct_clist_def)
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac x)
apply (auto)
(* pair case *)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_pvar_type)
apply (auto)
apply (rule_tac ds="ds" in subset_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac r_sv="r_s1" and r_xv="r_x1" and e="e1" and env_v="env_v" and ds="ds" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (cut_tac r_sv="r_s2" and r_xv="r_x2" and e="e2" and env_v="env_v" and ds="ds2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac r_mv="r_m1" and e="e1" and env_v="env_v" and ds="ds" and ds'="ds2" in infer_m_sub_range)
apply (auto)
apply (cut_tac r_mv="r_m2" and e="e2" and env_v="env_v" and ds="ds2" and ds'="ds3" in infer_m_sub_range)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d" and
?cl2.0="semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="lift_var_env r_x1 (SVar p)" and r_x="lift_var_env r_x2 (SVar p)" and x="x" and ds="set_diff (insert p ds3) ds" in pvar_clist_disj)
apply (simp)
apply (rule_tac lift_pvar_range)
apply (rule_tac ds="set_diff ds2 ds" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac lift_pvar_range)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m2 r_x1 d" and
?cl2.0="semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m2" and r_x="r_x1" and x="x" and ds="set_diff (insert p ds3) ds" in pvar_clist_semi_disj)
apply (simp)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds2 ds" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m1 r_s2 d" and ?cl2.0="cl1 @ cl2" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m1" and r_x="r_s2" and x="x" and ds="set_diff (insert p ds3) ds" in pvar_clist_semi_disj)
apply (simp)
apply (rule_tac ds="set_diff ds2 ds" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl1" and ?cl2.0="cl2" in pvar_clist_split)
apply (auto)
apply (case_tac "x \<in> set_diff ds2 ds")
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac c="x" and A="pvar_crn_list cl1" and B="set_diff ds2 ds" in Set.rev_subsetD)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (auto)
apply (cut_tac c="x" and A="pvar_crn_list cl2" and B="set_diff ds3 ds2" in Set.rev_subsetD)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
(* if case *)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and ds'="ds3" in subset_sub_range)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m1 (comp_var_env r_s2 r_s3) d" and
?cl2.0="cl1 @ cl2 @ cl3" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m1" and r_x="comp_var_env r_s2 r_s3" and x="x" and ds="set_diff ds' ds" in pvar_clist_semi_disj)
apply (simp)
apply (cut_tac r_mv="r_m1" and e="e1" and env_v="env_v" and ds="ds" and ds'="ds2" in infer_m_sub_range)
apply (auto)
apply (rule_tac ds="set_diff ds2 ds" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac comp_pvar_range)
apply (cut_tac r_sv="r_s2" and e="e2" and env_v="env_v" and ds="ds2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac r_sv="r_s3" and e="e3" and env_v="env_v" and ds="ds3" and ds'="ds'" in infer_s_sub_range)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_pvar_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl1" and ?cl2.0="cl2 @ cl3" in pvar_clist_split)
apply (auto)
apply (cut_tac c="x" and A="pvar_crn_list cl1" and B="set_diff ds2 ds" in Set.rev_subsetD)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl2" and ?cl2.0="cl3" in pvar_clist_split)
apply (auto)
apply (cut_tac c="x" and A="pvar_crn_list cl2" and B="set_diff ds3 ds2" in Set.rev_subsetD)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac c="x" and A="pvar_crn_list cl3" and B="set_diff ds' ds3" in Set.rev_subsetD)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
(* lam case *)
apply (simp add: induct_clist_def)
apply (auto)
apply (case_tac "p \<in> ds")
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac r_sv="r_s'" and e="e" and env_v="add_env env_v (Var x1a) a" in infer_s_sub_range)
apply (auto)
apply (simp add: pvar_range_def)
apply (erule_tac x="Var x1a" in allE)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d" and ?cl2.0="cl" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="rem_var_env r_s' (Var x1a)" and x="x" and p="SVar q" and ds="set_diff (insert q ds2) ds" in pvar_clist_aff)
apply (simp)
apply (rule_tac rem_pvar_range)
apply (rule_tac ds="set_diff ds2 (insert a ds)" in subset_pvar_range)
apply (cut_tac r_sv="r_s'" and e="e" and env_v="add_env env_v (Var x1a) a" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (case_tac "q \<in> ds")
apply (cut_tac e="e" and ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (simp add: set_diff_def)
apply (cut_tac env_v="env_v" and ds="ds" and x="Var x1a" and a="a" in add_sub_range)
apply (simp)
apply (cut_tac c="x" and A="pvar_crn_list cl" and B="set_diff ds2 (insert a ds)" in Set.rev_subsetD)
apply (auto)
apply (simp add: set_diff_def)
(* app case *)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (cut_tac r_sv="r_s1" and e="e1" and env_v="env_v" in infer_s_sub_range)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
apply (case_tac "q \<in> ds3")
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac "p \<in> ds3")
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d" and
?cl2.0="semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_x1" and r_x="lift_var_env r_x2 (SVar p)" and x="x" and ds="set_diff (insert p ds3) ds" in pvar_clist_disj)
apply (auto)
apply (rule_tac ds="set_diff ds2 ds" in subset_pvar_range)
apply (cut_tac r_sv="r_s1" and e="e1" and env_v="env_v" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac r_sv="r_s2" and e="e2" and env_v="env_v" in infer_s_sub_range)
apply (auto)
apply (rule_tac lift_pvar_range)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac "p \<in> ds3")
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m2 r_x1 d" and
?cl2.0="semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m2" and r_x="r_x1" and x="x" and ds="set_diff (insert p ds3) ds" in pvar_clist_semi_disj)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (rule_tac infer_m_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds2 ds" in subset_pvar_range)
apply (cut_tac ds="ds" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="semi_disj_crn r_m1 r_s2 d" and
?cl2.0="cl1 @ cl2" in pvar_clist_split)
apply (auto)
apply (cut_tac r_s="r_m1" and r_x="r_s2" and x="x" and ds="set_diff (insert p ds3) ds" in pvar_clist_semi_disj)
apply (auto)
apply (rule_tac ds="set_diff ds2 ds" in subset_pvar_range)
apply (rule_tac infer_m_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and ?cl1.0="cl1" and ?cl2.0="cl2" in pvar_clist_split)
apply (auto)
apply (cut_tac c="x" and A="pvar_crn_list cl1" and B="set_diff ds2 ds" in Set.rev_subsetD)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac c="x" and A="pvar_crn_list cl2" and B="set_diff ds3 ds2" in Set.rev_subsetD)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
done
lemma infer_pvar_crn_list: "\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \<rbrakk> \<Longrightarrow> pvar_crn_list c_list \<subseteq> set_diff ds' ds"
apply (cut_tac env_v="env_v" and e="e" and ds="ds" and ds'="ds'" in infer_pvar_crn_list_ih)
apply (auto)
apply (simp add: induct_clist_def)
apply (auto)
done
lemma sol_sat_disj: "\<lbrakk> disj_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_x) \<rbrakk> \<Longrightarrow> dir_sol_sat t_sub p_sub (disj_crn r_s r_x d)"
apply (induct d)
apply (auto)
apply (simp add: disj_use_env_def)
apply (simp add: mini_disj_use_env_def)
apply (simp add: dir_subst_penv_def)
apply (simp add: disj_use_env_def)
apply (simp add: mini_disj_use_env_def)
apply (simp add: dir_subst_penv_def)
done
lemma sol_sat_mini_disj: "\<lbrakk> mini_disj_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_x) \<rbrakk> \<Longrightarrow>
dir_sol_sat t_sub p_sub (semi_disj_crn r_s r_x d)"
apply (induct d)
apply (auto)
apply (simp add: mini_disj_use_env_def)
apply (simp add: dir_subst_penv_def)
done
(*
lemma sol_sat_aff: "\<lbrakk> aff_use_env (dir_subst_penv t_sub p_sub r_s) a \<rbrakk> \<Longrightarrow> dir_sol_sat t_sub p_sub (aff_crn r_s (SVar p) d)" *)
lemma cut_disj_use_env: "\<lbrakk> mini_disj_use_env r_x r_s \<rbrakk> \<Longrightarrow> disj_use_env r_s (cut_use_env r_x)"
apply (simp add: disj_use_env_def)
apply (simp add: mini_disj_use_env_def)
apply (simp add: cut_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (auto)
apply (case_tac "r_x x")
apply (auto)
done
lemma swap_diff_cut_leq_use_env: "\<lbrakk> leq_use_env r_x r_s; leq_use_env r_ex (diff_use_env r_s r_x) \<rbrakk> \<Longrightarrow>
leq_use_env (cut_use_env r_x) (diff_use_env r_s r_ex)"
apply (simp add: leq_use_env_def)
apply (simp add: cut_use_env_def)
apply (simp add: diff_use_env_def)
apply (auto)
apply (erule_tac x="x" in allE)
apply (erule_tac x="x" in allE)
apply (case_tac "r_x x")
apply (auto)
apply (case_tac "r_s x")
apply (auto)
apply (case_tac "r_ex x")
apply (auto)
done
lemma cut_mini_disj_use_env: "\<lbrakk> mini_disj_use_env (cut_use_env r_s) r_x \<rbrakk> \<Longrightarrow> mini_disj_use_env r_s r_x"
apply (simp add: mini_disj_use_env_def)
apply (simp add: cut_use_env_def)
done
lemma ivrpc_main: "\<lbrakk>
spec_env env_v (dir_subst_tenv (dir_list_add_env t_sub l) env_v) t_sub; sub_range env_v ds; tsub_dom t_sub ds;
infer_type env_v ds e1 t1a r_s1 r_x1 r_m1 cl1 ds2;
infer_type env_v ds2 e2 t2a r_s2 r_x2 r_m2 cl2 ds3;
leq_use_env (lift_use_env rx1 r) r_s3; leq_use_env (lift_use_env rx2 r) r_s3; aff_leq (max_aff (req_type t1) (req_type t2)) r;
disj_use_env (lift_use_env rx1 r) (lift_use_env rx2 r); leq_use_env r_s3 r_s;
finite_dom (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))) d;
leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 r_exa); p \<notin> ds3; leq_use_env r_exa r_s;
leq_use_env (pair_req (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_exa (PairTy t1 t2 r)) r_x; leq_use_env r_exaa r_s;
leq_use_env r_exb (diff_use_env r_s r_exaa); super_norm_use_env r_s r_s3 = diff_use_env r_s (comp_use_env r_exaa r_exb);
well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s e1 t1 (diff_use_env r_s r_exaa) rx1;
well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) (diff_use_env r_s r_exaa) e2 t2 (diff_use_env (diff_use_env r_s r_exaa) r_exb) rx2;
tsub_dom (dir_list_add_env t_sub l) ds2; fresh_list ds (dom_list l); env = dir_subst_tenv (dir_list_add_env t_sub l) env_v;
psub_dom p_sub (set_diff ds2 ds); leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_s1) r_s;
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_x1) r_exaa) rx1;
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_m1)) r_exaa; dir_subst_type (dir_list_add_env t_sub l) p_sub t1a t1;
dir_sol_sat (dir_list_add_env t_sub l) p_sub cl1; tsub_dom (dir_list_add_env (dir_list_add_env t_sub l) la) ds3; fresh_list ds2 (dom_list la);
dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;
psub_dom p_suba (set_diff ds3 ds2); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_s2) (diff_use_env r_s r_exaa);
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_x2) r_exb) rx2;
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_m2)) r_exb;
dir_subst_type (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba t2a t2; dir_sol_sat (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba cl2\<rbrakk>
\<Longrightarrow> \<exists>la. tsub_dom (dir_list_add_env t_sub la) (insert p ds3) \<and>
fresh_list ds (dom_list la) \<and>
dir_subst_tenv (dir_list_add_env t_sub la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff (insert p ds3) ds) \<and>
leq_use_env
(dir_subst_penv (dir_list_add_env t_sub la) p_sub
(comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))))
r_s \<and>
leq_use_env
(diff_use_env
(dir_subst_penv (dir_list_add_env t_sub la) p_sub
(ifz_var_env (XPerm (SVar p)) (comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)))))
r_ex)
r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_m1 r_m2))) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub la) p_sub t1a t1 \<and>
dir_subst_type (dir_list_add_env t_sub la) p_sub t2a t2 \<and>
r = p_sub p \<and>
(\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t1a tau_x \<and> aff_leq (req_type tau_x) (p_sub p)) \<and>
(\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t2a tau_x \<and> aff_leq (req_type tau_x) (p_sub p)) \<and>
dir_sol_sat (dir_list_add_env t_sub la) p_sub
(disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d @
semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2))"
(* defining new t_sub *)
apply (rule_tac x="la @ l" in exI)
apply (auto)
apply (rule_tac append_tsub_dom)
apply (rule_tac ds="ds" in list_add_tsub_dom)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="t_sub" and l="l" and ds="ds2" in list_add_dls)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and ds="ds3" in list_add_dls)
apply (auto)
apply (rule_tac ds="ds" and ds'="ds2" in append_fresh_list2)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: dir_list_append_eq)
(* P* inequality 1 *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_s1) r_s")
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r"
and r_sv="r_s1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_tvar_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_s1" and ds="set_diff ds2 ds" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="p_suba" and r_xv="r_s1" and ds="set_diff ds2 ds" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* P* inequality 2 *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_s2) (diff_use_env r_s r_exaa)")
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_s2" and ds="set_diff ds3 ds2" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_sub" and r_xv="r_s2" and ds="set_diff ds3 ds2" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* X* inequality 1 *)
apply (case_tac "\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa) rx1")
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r"
and r_sv="r_x1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_tvar_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_x1" and ds="set_diff ds2 ds" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="p_suba" and r_xv="r_x1" and ds="set_diff ds2 ds" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* X* inequality 2 *)
apply (case_tac "\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2) r_exb) rx2")
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_x2" and ds="set_diff ds3 ds2" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_sub" and r_xv="r_x2" and ds="set_diff ds3 ds2" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* M* inequality 1 *)
apply (case_tac "\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_m1)) r_exaa")
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r"
and r_sv="r_m1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_m_tvar_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_m_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_m1" and ds="set_diff ds2 ds" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="p_suba" and r_xv="r_m1" and ds="set_diff ds2 ds" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* M* inequality 2 *)
apply (case_tac "\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_m2)) r_exb")
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_m_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_m2" and ds="set_diff ds3 ds2" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_sub" and r_xv="r_m2" and ds="set_diff ds3 ds2" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* - prelim: (t_sub, p_sub)(t1a) = t1 *)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and
tau_v="t1a" and tau="t1" in dir_list_add_subst_type)
apply (rule_tac add_dir_subst_type)
apply (rule_tac ds="set_diff ds2 ds" in comp_dir_subst_type1)
apply (simp)
apply (rule_tac infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac tau_v="t1a" and ds'="ds2" and ds="ds" in infer_pvar_type)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and l="la" in dom_list_contain)
apply (simp)
apply (cut_tac tau_v="t1a" and ds'="ds2" and ds="ds" in infer_tvar_type)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
(* - prelim: (t_sub, p_sub)(t2a) = t2 *)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and p="p" and r="r" and
tau_v="t2a" and tau="t2" in add_dir_subst_type)
apply (rule_tac ds="set_diff ds3 ds2" in comp_dir_subst_type2)
apply (simp)
apply (rule_tac infer_pvar_type)
apply (auto)
apply (rule_tac ds="ds" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (simp)
apply (simp add: set_diff_def)
apply (cut_tac tau_v="t2a" and ds'="ds3" and ds="ds2" in infer_pvar_type)
apply (auto)
apply (rule_tac ds="ds" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
(* defining new p_sub *)
apply (rule_tac x="add_use_env (comp_use_env p_sub p_suba) p r" in exI)
apply (auto)
(* - psub domain containment *)
apply (rule_tac add_psub_dom)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds2 ds" in subset_psub_dom)
apply (simp)
apply (rule_tac set_diff_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_psub_dom)
apply (simp)
apply (rule_tac set_diff_subset)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
(* - p_sub(r_sv) \<le> r_s *)
apply (rule_tac dist_comp_leq_var_env)
apply (simp add: dir_list_append_eq)
apply (rule_tac dist_comp_leq_var_env)
apply (auto)
apply (rule_tac t="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))"
and s="lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1)
(sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))" in subst)
apply (rule_tac lift_sol_subst_penv)
apply (auto)
apply (case_tac "add_use_env (comp_use_env p_sub p_suba) p r p \<noteq> r")
apply (simp add: add_use_env_def)
apply (auto)
apply (rule_tac r_ex="r_exaa" in diff_leq_use_env_rev)
apply (simp add: lift_diff_use_env)
apply (rule_tac r_sb="lift_use_env rx1 r" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)
(* > part 2. *)
apply (simp add: dir_list_append_eq)
apply (rule_tac dist_comp_leq_var_env)
apply (rule_tac r_sb="diff_use_env r_s r_exaa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
apply (rule_tac t="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))"
and s="lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)
(sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))" in subst)
apply (rule_tac lift_sol_subst_penv)
apply (rule_tac r_ex="r_exb" in diff_leq_use_env_rev)
apply (simp add: lift_diff_use_env)
apply (rule_tac r_sb="lift_use_env rx2 r" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (case_tac "add_use_env (comp_use_env p_sub p_suba) p r p \<noteq> r")
apply (simp add: add_use_env_def)
apply (auto)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)
apply (rule_tac r_sb="diff_use_env r_s r_exaa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
(* - p_sub(r_xv) \<le> r_x. primitive case *)
apply (case_tac "r = NoPerm")
apply (cut_tac t_sub="dir_list_add_env t_sub (la @ l)" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and p="p" and
r_sv="comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p))" in ifz_sol_subst_penv)
apply (auto)
apply (simp add: add_use_env_def)
apply (rule_tac diff_leq_use_env)
apply (rule_tac leq_empty_use_env)
apply (simp add: pair_req_def)
(* > non-primitive case *)
apply (simp add: dir_list_append_eq)
apply (case_tac "as_aff r = Prim")
apply (case_tac r)
apply (auto)
apply (rule_tac r_sb="diff_use_env
(dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r)
(comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)))) r_ex" in trans_leq_use_env)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac lhs_dist_dcl_use_env)
apply (rule_tac r_sb="diff_use_env (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_exa" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac t="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))"
and s="lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1)
(sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))" in subst)
apply (rule_tac lift_sol_subst_penv)
apply (rule_tac r_sb="diff_use_env (lift_use_env rx1 r) r_exa" in trans_leq_use_env)
apply (rule_tac dist_diff_leq_use_env)
apply (rule_tac self_comp_leq_use_env1)
apply (simp add: lift_diff_use_env)
apply (case_tac "add_use_env (comp_use_env p_sub p_suba) p r p \<noteq> r")
apply (simp add: add_use_env_def)
apply (simp)
apply (rule_tac dist_lift_leq_use_env)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s3 r_exa" in trans_leq_use_env)
apply (rule_tac dist_diff_leq_use_env)
apply (simp_all)
apply (rule_tac r_sb="lift_use_env rx1 r" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (rule_tac self_lift_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)
(add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa" in trans_leq_use_env)
apply (simp)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac rhs_snorm_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s3 r_exa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
apply (rule_tac r_sb="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)
(add_use_env (comp_use_env p_sub p_suba) p r) r_s1" in trans_leq_use_env)
apply (simp)
apply (rule_tac infer_x_leq_use_env)
apply (auto)
apply (rule_tac self_diff_leq_use_env)
(* > transformation proving removal of extra substitutions is sound *)
(* > part 2. *)
apply (rule_tac t="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))"
and s="lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)
(sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))" in subst)
apply (rule_tac lift_sol_subst_penv)
apply (rule_tac rhs_dist_dcl_use_env)
apply (rule_tac comp_leq_use_env2)
apply (simp add: lift_diff_use_env)
apply (case_tac "add_use_env (comp_use_env p_sub p_suba) p r p \<noteq> r")
apply (simp add: add_use_env_def)
apply (simp)
apply (rule_tac dist_lift_leq_use_env)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s3 r_exa" in trans_leq_use_env)
apply (rule_tac dist_diff_leq_use_env)
apply (simp_all)
apply (rule_tac r_sb="lift_use_env rx2 r" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (rule_tac self_lift_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)
r_exb" in trans_leq_use_env)
apply (simp)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac rhs_snorm_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s3 r_exa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
apply (rule_tac r_sb="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_s2" in trans_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s r_exaa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
apply (rule_tac infer_x_leq_use_env)
apply (auto)
apply (rule_tac self_diff_leq_use_env)
(* > finishing the case *)
apply (rule_tac dist_diff_leq_use_env)
apply (rule_tac if_zero_leq_var_env)
apply (rule_tac id_leq_use_env)
(* - (t_sub, p_sub)( M1* ) \<le> EX. r_s - r_ex <= r_s3 <= r_s1 - (r_exaa + r_exb) *)
apply (rule_tac r_sb="cut_use_env (comp_use_env r_exaa r_exb)" in trans_leq_use_env)
apply (rule_tac r_s="r_s" in dist_diff_leq_use_env_rev)
apply (rule_tac dist_comp_leq_use_env)
apply (simp)
apply (rule_tac r_sb="diff_use_env r_s r_exaa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
apply (rule_tac r_sb="diff_use_env r_s3 r_exa" in trans_leq_use_env)
apply (rule_tac diff_leq_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac id_leq_use_env)
apply (rule_tac rhs_snorm_leq_use_env)
apply (simp)
apply (rule_tac id_leq_use_env)
apply (simp)
apply (rule_tac rhs_cut_leq_use_env)
apply (simp add: comp_sol_subst_penv)
apply (simp add: dist_cut_comp_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env1)
apply (simp add: dir_list_append_eq)
apply (rule_tac comp_leq_use_env2)
apply (simp add: dir_list_append_eq)
(* - type equivalences *)
apply (simp add: dir_list_append_eq)
apply (simp add: dir_list_append_eq)
(* - pair permission *)
apply (simp add: add_use_env_def)
(* - further type equivalence *)
apply (rule_tac x="t1" in exI)
apply (simp add: dir_list_append_eq)
apply (simp add: add_use_env_def)
apply (case_tac "req_type t2")
apply (auto)
apply (case_tac "req_type t1")
apply (auto)
apply (case_tac r)
apply (auto)
apply (case_tac "req_type t1")
apply (auto)
apply (case_tac "req_type t1")
apply (simp_all)
apply (rule_tac x="t2" in exI)
apply (simp add: dir_list_append_eq)
apply (simp add: add_use_env_def)
apply (case_tac "req_type t1")
apply (auto)
apply (case_tac "req_type t2")
apply (simp_all)
apply (case_tac r)
apply (simp_all)
apply (case_tac "req_type t2")
apply (simp_all)
apply (case_tac "req_type t2")
apply (simp_all)
(* - solution satisfiability. disjointness *)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_disj)
apply (simp add: dir_list_append_eq)
apply (rule_tac r_s="comp_use_env (lift_use_env rx1 r) (cut_use_env r_exaa)" in disj_leq_use_env1)
apply (rule_tac r_s="comp_use_env (lift_use_env rx2 r) (cut_use_env r_exb)" in disj_leq_use_env2)
apply (rule_tac disj_comp_use_env1)
apply (rule_tac disj_comp_use_env2)
apply (simp)
apply (rule_tac cut_disj_use_env)
apply (rule_tac r_s="diff_use_env r_s r_exb" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (simp_all)
apply (rule_tac disj_comp_use_env2)
apply (rule_tac comm_disj_use_env)
apply (rule_tac cut_disj_use_env)
apply (rule_tac r_s="diff_use_env r_s r_exaa" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (simp_all)
apply (rule_tac comm_disj_use_env)
apply (rule_tac cut_disj_use_env)
apply (rule_tac r_s="diff_use_env r_s r_exaa" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac cut_leq_use_env)
apply (simp)
(* > proving the inequality for r_x2 vs rx2 *)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)
(add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))) r_exb" in trans_leq_use_env)
apply (rule_tac s="lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)
(add_use_env (comp_use_env p_sub p_suba) p r p)" and
t="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))" in subst)
apply (simp add: lift_sol_subst_penvx)
apply (simp add: lift_diff_use_env)
apply (rule_tac r_sb="lift_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)
(add_use_env (comp_use_env p_sub p_suba) p r) r_x2) r_exb) r" in trans_leq_use_env)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)(*
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and
r_xv="r_x2" and ds="set_diff ds3 ds2" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_sub" and
r_xv="r_x2" and ds="set_diff ds3 ds2" and ds'="set_diff ds2 ds" in comp_psub_use_env2)
apply (simp_all)
apply (simp add: set_diff_def)
apply (auto)*)
apply (rule_tac dist_lift_leq_use_env_gen)
apply (simp add: add_use_env_def)
apply (case_tac r)
apply (simp_all)
apply (rule_tac dist_diff_leq_use_env_cut)
apply (rule_tac id_leq_use_env)
apply (rule_tac id_leq_use_env)
(* > proving the inequality for r_x1 vs rx1 *)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)
(add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))) r_exaa" in trans_leq_use_env)
apply (rule_tac t="dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))"
and s="lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1)
(add_use_env (comp_use_env p_sub p_suba) p r p)" in subst)
apply (simp add: lift_sol_subst_penvx)
apply (simp add: lift_diff_use_env)
apply (rule_tac r_sb="lift_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)
(add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa) r" in trans_leq_use_env)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)
apply (rule_tac dist_lift_leq_use_env_gen)
apply (simp add: add_use_env_def)
apply (case_tac r)
apply (simp_all)
apply (rule_tac dist_diff_leq_use_env_cut)
apply (rule_tac id_leq_use_env)
apply (rule_tac id_leq_use_env)
(* > semi-disjointness 1 *)
apply (simp add: dir_list_append_eq)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_mini_disj)
apply (rule_tac cut_mini_disj_use_env)
apply (rule_tac r_s="r_exb" in mini_disj_leq_use_env1)
apply (rule_tac r_s="diff_use_env r_s r_exb" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="comp_use_env (diff_use_env r_s r_exb) (cut_use_env r_exaa)" in trans_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac id_leq_use_env)
apply (rule_tac swap_diff_cut_leq_use_env)
apply (simp_all)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)
(add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa" in trans_leq_use_env)
apply (rule_tac r_sb="lift_use_env rx1 r" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (rule_tac mini_disj_diff_leq_use_env2)
apply (simp)
apply (rule_tac r_s="diff_use_env r_s r_exb" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (rule_tac id_leq_use_env)
apply (simp_all)
apply (rule_tac lift_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_cut)
apply (rule_tac id_leq_use_env)
apply (rule_tac id_leq_use_env)
(* > semi-disjointness 2 *)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_mini_disj)
apply (rule_tac cut_mini_disj_use_env)
apply (rule_tac r_s="r_exaa" in mini_disj_leq_use_env1)
apply (rule_tac r_s="diff_use_env r_s r_exaa" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (simp_all)
(* > constraint list 1 correctness *)
apply (rule_tac sol_sat_split)
apply (cut_tac c_list="cl1" and ds="ds" and ds'="ds2" in infer_tvar_crn_list)
apply (auto)
apply (cut_tac c_list="cl1" and ds="ds" and ds'="ds2" in infer_pvar_crn_list)
apply (auto)
apply (rule_tac dir_list_add_sol_sat)
apply (rule_tac add_psub_sol_sat)
apply (rule_tac ds="set_diff ds2 ds" in comp_psub_sol_sat1)
apply (simp_all)
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac "p \<in> ds2")
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and l="la" in dom_list_set_contain)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
(* > constraint list 2 correctness *)
apply (cut_tac c_list="cl2" and ds="ds2" and ds'="ds3" in infer_pvar_crn_list)
apply (auto)
apply (rule_tac ds="ds" in subset_sub_range)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (rule_tac add_psub_sol_sat)
apply (rule_tac ds="set_diff ds3 ds2" in comp_psub_sol_sat2)
apply (simp_all)
apply (simp add: set_diff_def)
apply (auto)
apply (case_tac "p \<in> ds2")
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
done
lemma ivr_pair_case: "\<lbrakk>\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e1 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e1 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e2 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e2 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; infer_type env_v ds e1 t1a r_s1 r_x1 r_m1 cl1 ds2; well_typed env r_s e1 t1 r_s2a rx1;
infer_type env_v ds2 e2 t2a r_s2 r_x2 r_m2 cl2 ds3; well_typed env r_s2a e2 t2 r_s3 rx2; leq_use_env (lift_use_env rx1 r) r_s3;
leq_use_env (lift_use_env rx2 r) r_s3; aff_leq (max_aff (req_type t1) (req_type t2)) r; disj_use_env (lift_use_env rx1 r) (lift_use_env rx2 r);
finite_dom (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))) d;
leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 r_exa); leq_use_env r_x (diff_use_env r_s r_ex); p \<notin> ds3; leq_use_env r_exa r_s;
leq_use_env (pair_req (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_exa (PairTy t1 t2 r)) r_x\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert p ds3) \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff (insert p ds3) ds) \<and>
leq_use_env
(dir_subst_penv (dir_list_add_env t_sub l) p_sub
(comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))))
r_s \<and>
leq_use_env
(diff_use_env
(dir_subst_penv (dir_list_add_env t_sub l) p_sub
(ifz_var_env (XPerm (SVar p)) (comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)))))
r_ex)
r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_m1 r_m2))) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub t1a t1 \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub t2a t2 \<and>
r = p_sub p \<and>
(\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t1a tau_x \<and> aff_leq (req_type tau_x) (p_sub p)) \<and>
(\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t2a tau_x \<and> aff_leq (req_type tau_x) (p_sub p)) \<and>
dir_sol_sat (dir_list_add_env t_sub l) p_sub
(disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d @
semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2))"
apply (cut_tac env="env" and ?e1.0="e1" and ?e2.0="e2" in ivr_induct_format)
apply (auto)
apply (cut_tac e="e1" and env_v="env_v" and t_sub="t_sub" and ds="ds" in ivrpc_coerce)
apply (auto)
apply (cut_tac e="e2" and env_v="env_v" and t_sub="dir_list_add_env t_sub l" and ds="ds2" in ivrpc_coerce)
apply (auto)
apply (rule_tac self_spec_env)
apply (rule_tac ds="ds" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (auto)
apply (rule_tac env_v="env_v" and r_s="r_s" and ?r_s3.0="r_s3" and ?e1.0="e1" and ?e2.0="e2"
and ?r_s1.0="r_s1" and ?r_x1.0="r_x1" and ?r_m1.0="r_m1" and ?r_s2.0="r_s2" and ?r_x2.0="r_x2" and ?r_m2.0="r_m2" in ivrpc_main)
apply (auto)
apply (rule_tac r_sb="r_s2a" in trans_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac well_typed_perm_leq)
apply (auto)
done
lemma ivric_coerce: "\<lbrakk> \<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds \<rbrakk> \<Longrightarrow>
\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)"
apply (auto)
done
lemma subset_fresh_list: "\<lbrakk> ds \<subseteq> ds'; fresh_list ds' l \<rbrakk> \<Longrightarrow> fresh_list ds l"
apply (simp add: fresh_list_def)
apply (auto)
done
lemma ivric_main: "\<lbrakk> spec_env env_v (dir_subst_tenv (dir_list_add_env t_sub l) env_v) t_sub; sub_range env_v ds; tsub_dom t_sub ds;
well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s e1 BoolTy r_s2 rx'; infer_type env_v ds e1 t1 r_s1 r_x1 r_m1 cl1 ds2;
well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s2 e2 tau (diff_use_env r_s r_ex) rx1; infer_type env_v ds2 e2 t2 r_s2a r_x2 r_m2 cl2 ds3;
well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s2 e3 tau (diff_use_env r_s r_ex) rx2; infer_type env_v ds3 e3 t3 r_s3 r_x3 r_m3 cl3 ds';
finite_dom (comp_var_env r_s1 (comp_var_env r_s2a r_s3)) d; super_norm_use_env r_s r_s2 = diff_use_env r_s r_exa; leq_use_env r_exa r_s;
tsub_dom (dir_list_add_env t_sub l) ds2; fresh_list ds (dom_list l); env = dir_subst_tenv (dir_list_add_env t_sub l) env_v;
psub_dom p_sub (set_diff ds2 ds); leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_s1) r_s;
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_x1) r_exa) rx';
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_m1)) r_exa; dir_subst_type (dir_list_add_env t_sub l) p_sub t1 BoolTy;
dir_sol_sat (dir_list_add_env t_sub l) p_sub cl1; tsub_dom (dir_list_add_env (dir_list_add_env t_sub l) la) ds3; fresh_list ds2 (dom_list la);
dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;
psub_dom p_suba (set_diff ds3 ds2); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_s2a) r_s2;
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_x2) r_ex) rx1;
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_m2)) r_ex;
dir_subst_type (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba t2 tau; dir_sol_sat (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba cl2;
tsub_dom (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) ds'; fresh_list ds3 (dom_list lb);
dir_subst_tenv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;
psub_dom p_subb (set_diff ds' ds3); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb r_s3) r_s2;
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb r_x3) r_ex) rx2;
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb r_m3)) r_ex;
dir_subst_type (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb t3 tau;
dir_sol_sat (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb cl3\<rbrakk>
\<Longrightarrow> \<exists>la. tsub_dom (dir_list_add_env t_sub la) ds' \<and>
fresh_list ds (dom_list la) \<and>
dir_subst_tenv (dir_list_add_env t_sub la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_s1 (comp_var_env r_s2a r_s3))) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_x2 r_x3)) r_ex) (comp_use_env rx1 rx2) \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_m1 (comp_var_env r_m2 r_m3)))) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub la) p_sub t2 tau \<and>
dir_subst_type (dir_list_add_env t_sub la) p_sub t1 BoolTy \<and>
(\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t2 tau_x \<and> dir_subst_type (dir_list_add_env t_sub la) p_sub t3 tau_x) \<and>
dir_sol_sat (dir_list_add_env t_sub la) p_sub (semi_disj_crn r_m1 (comp_var_env r_s2a r_s3) d @ cl1 @ cl2 @ cl3))"
(* P* inequality 1 *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_s1) r_s")
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_tvar_range)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and l="lb" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)"
and r_sv="r_s1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (rule_tac ds'="ds3" in subset_fresh_list)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)"
and r_sv="r_s1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="comp_use_env p_suba p_subb"
and r_xv="r_s1" and ds="set_diff ds2 ds" and ds'="set_diff ds' ds2" in comp_psub_use_env1)
apply (auto)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds3 ds2" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
(* P* inequality 2 *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_s2a) r_s2")
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_tvar_range)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and l="lb" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)"
and r_sv="r_s2a" and ds="ds3" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub2.0="p_sub" and ?p_sub1.0="comp_use_env p_suba p_subb"
and r_xv="r_s2a" and ds'="set_diff ds2 ds" and ds="set_diff ds' ds2" in comp_psub_use_env2)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_subb"
and r_xv="r_s2a" and ds="set_diff ds3 ds2" and ds'="set_diff ds' ds3" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* P* inequality 3 *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_s3) r_s2")
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds3" and e="e3" and ds'="ds'" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb" and ?p_sub2.0="p_sub" and
?p_sub1.0="comp_use_env p_suba p_subb" and r_xv="r_s3" and ds'="set_diff ds2 ds" and ds="set_diff ds' ds2" in comp_psub_use_env2)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_pvar_range)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb" and ?p_sub2.0="p_suba" and ?p_sub1.0="p_subb"
and r_xv="r_s3" and ds'="set_diff ds3 ds2" and ds="set_diff ds' ds3" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* X* inequality 2 *)
apply (case_tac "\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_x2) r_ex) rx1")
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_tvar_range)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and l="lb" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)"
and r_sv="r_x2" and ds="ds3" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub2.0="p_sub" and ?p_sub1.0="comp_use_env p_suba p_subb"
and r_xv="r_x2" and ds'="set_diff ds2 ds" and ds="set_diff ds' ds2" in comp_psub_use_env2)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_subb"
and r_xv="r_x2" and ds="set_diff ds3 ds2" and ds'="set_diff ds' ds3" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* X* inequality 3 *)
apply (case_tac "\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_x3) r_ex) rx2")
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds3" and e="e3" and ds'="ds'" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb" and ?p_sub2.0="p_sub" and
?p_sub1.0="comp_use_env p_suba p_subb" and r_xv="r_x3" and ds'="set_diff ds2 ds" and ds="set_diff ds' ds2" in comp_psub_use_env2)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_pvar_range)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb" and ?p_sub2.0="p_suba" and ?p_sub1.0="p_subb"
and r_xv="r_x3" and ds'="set_diff ds3 ds2" and ds="set_diff ds' ds3" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* M* inequality 1 *)
apply (case_tac "\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_m1)) r_exa")
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_m_tvar_range)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and l="lb" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)"
and r_sv="r_m1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (rule_tac ds'="ds3" in subset_fresh_list)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)"
and r_sv="r_m1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_m_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="comp_use_env p_suba p_subb"
and r_xv="r_m1" and ds="set_diff ds2 ds" and ds'="set_diff ds' ds2" in comp_psub_use_env1)
apply (auto)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds3 ds2" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
(* M* inequality 2 *)
apply (case_tac "\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_m2)) r_ex")
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_m_tvar_range)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and l="lb" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)"
and r_sv="r_m2" and ds="ds3" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_m_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub2.0="p_sub" and ?p_sub1.0="comp_use_env p_suba p_subb"
and r_xv="r_m2" and ds'="set_diff ds2 ds" and ds="set_diff ds' ds2" in comp_psub_use_env2)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_pvar_range)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_subb"
and r_xv="r_m2" and ds="set_diff ds3 ds2" and ds'="set_diff ds' ds3" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* M* inequality 3 *)
apply (case_tac "\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)
(comp_use_env p_sub (comp_use_env p_suba p_subb)) r_m3)) r_ex")
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds3" and e="e3" and ds'="ds'" in infer_m_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb" and ?p_sub2.0="p_sub" and
?p_sub1.0="comp_use_env p_suba p_subb" and r_xv="r_m3" and ds'="set_diff ds2 ds" and ds="set_diff ds' ds2" in comp_psub_use_env2)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_pvar_range)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb" and ?p_sub2.0="p_suba" and ?p_sub1.0="p_subb"
and r_xv="r_m3" and ds'="set_diff ds3 ds2" and ds="set_diff ds' ds3" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* proving type equivalence for t2 *)
apply (case_tac "\<not> dir_subst_type (dir_list_add_env t_sub (lb @ la @ l)) (comp_use_env p_sub (comp_use_env p_suba p_subb)) t2 tau")
apply (simp add: dir_list_append_eq)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (simp)
apply (cut_tac tau_v="t2" and ds="ds2" and ds'="ds3" in infer_pvar_type)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and l="lb" and p_sub="comp_use_env p_sub (comp_use_env p_suba p_subb)" and
tau_v="t2" and tau="tau" in dir_list_add_subst_type)
apply (rule_tac ds="set_diff ds' ds2" in comp_dir_subst_type2)
apply (rule_tac ds="set_diff ds3 ds2" in comp_dir_subst_type1)
apply (auto)
apply (simp add: set_diff_def)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac x="x" and l="lb" in dom_list_contain)
apply (simp)
apply (cut_tac tau_v="t2" and ds'="ds3" and ds="ds2" in infer_tvar_type)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
(* proving type equivalence for t3 *)
apply (case_tac "\<not> dir_subst_type (dir_list_add_env t_sub (lb @ la @ l)) (comp_use_env p_sub (comp_use_env p_suba p_subb)) t3 tau")
apply (simp add: dir_list_append_eq)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds3" in subset_sub_range)
apply (auto)
apply (cut_tac tau_v="t3" and ds="ds3" and ds'="ds'" in infer_pvar_type)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb" and
p_sub="p_sub" and p_subx="comp_use_env p_suba p_subb" and ds="set_diff ds' ds2" in comp_dir_subst_type2)
apply (rule_tac ds="set_diff ds' ds3" in comp_dir_subst_type2)
apply (auto)
apply (simp add: set_diff_def)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (rule_tac x="lb @ la @ l" in exI)
apply (auto)
(* type subst domain containment *)
apply (simp add: dir_list_append_eq)
(* freshness of lb, la, l *)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (rule_tac t_sub="t_sub" and ds="ds" and ds'="ds3" in append_fresh_list2)
apply (auto)
apply (rule_tac ds="ds" and ds'="ds2" in append_fresh_list2)
apply (auto)
apply (simp add: dir_list_append_eq)
(* tenv equality *)
apply (simp add: dir_list_append_eq)
(* defining new p_sub *)
apply (rule_tac x="comp_use_env p_sub (comp_use_env p_suba p_subb)" in exI)
apply (auto)
(* p_sub containment *)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds2 ds" in subset_psub_dom)
apply (simp)
apply (rule_tac set_diff_subset)
apply (auto)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds3 ds2" in subset_psub_dom)
apply (simp)
apply (rule_tac set_diff_subset)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_psub_dom)
apply (simp)
apply (rule_tac set_diff_subset)
apply (auto)
(* initial permission environment containment *)
apply (simp add: dir_list_append_eq)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac dist_comp_leq_use_env)
apply (simp)
apply (rule_tac r_sb="r_s2" in trans_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac dist_comp_leq_use_env)
apply (simp_all)
(* requirements containment *)
apply (simp add: dir_list_append_eq)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac lhs_dist_dcl_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env1)
apply (simp)
apply (rule_tac comp_leq_use_env2)
apply (simp)
(* subtractant containment *)
apply (simp add: dir_list_append_eq)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac lhs_dist_cut_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac r_sb="cut_use_env r_exa" in trans_leq_use_env)
apply (rule_tac r_s="r_s" in dist_diff_leq_use_env_rev)
apply (simp)
apply (rule_tac t="diff_use_env r_s r_exa" and s="super_norm_use_env r_s r_s2" in subst)
apply (simp)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (rule_tac well_typed_perm_leq)
apply (simp)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac rhs_cut_leq_use_env)
apply (simp)
apply (rule_tac lhs_dist_cut_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (simp_all)
(* type equivalence *)
apply (simp add: dir_list_append_eq)
apply (cut_tac tau_v="t1" and ds="ds" and ds'="ds2" in infer_pvar_type)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (simp_all)
apply (cut_tac tau_v="t1" and ds'="ds2" and ds="ds" in infer_tvar_type)
apply (auto)
apply (rule_tac dir_list_add_subst_type)
apply (rule_tac dir_list_add_subst_type)
apply (rule_tac ds="set_diff ds2 ds" and ds'="set_diff ds' ds2" in comp_dir_subst_type1)
apply (simp_all)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds3 ds2" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac x="x" and l="la" in dom_list_contain)
apply (simp)
apply (simp add: fresh_list_def)
apply (auto)
apply (cut_tac x="x" and l="lb" in dom_list_contain)
apply (simp)
apply (simp add: fresh_list_def)
apply (auto)
(* constraint list correctness. disjointness *)
apply (simp add: dir_list_append_eq)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_mini_disj)
apply (rule_tac cut_mini_disj_use_env)
apply (rule_tac r_s="r_exa" in mini_disj_leq_use_env1)
apply (rule_tac r_s="diff_use_env r_s r_exa" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="r_s2" in trans_leq_use_env)
apply (rule_tac t="diff_use_env r_s r_exa" and s="super_norm_use_env r_s r_s2" in subst)
apply (simp)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (rule_tac id_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac dist_comp_leq_use_env)
apply (simp_all)
(* - constraint list 1 correctness *)
apply (rule_tac sol_sat_split)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac c_list="cl1" and ds="ds" and ds'="ds2" in infer_tvar_crn_list)
apply (auto)
apply (cut_tac c_list="cl1" and ds="ds" and ds'="ds2" in infer_pvar_crn_list)
apply (auto)
apply (rule_tac dir_list_add_sol_sat)
apply (rule_tac dir_list_add_sol_sat)
apply (rule_tac ds="set_diff ds2 ds" and ds'="set_diff ds' ds2" in comp_psub_sol_sat1)
apply (simp_all)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds3 ds2" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (rule_tac ds="set_diff ds' ds3" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac x="x" and l="la" in dom_list_set_contain)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (cut_tac x="x" and l="lb" in dom_list_set_contain)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
(* - constraint list 2 correctness *)
apply (rule_tac sol_sat_split)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds3" and ds'="ds'" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (auto)
apply (cut_tac c_list="cl2" and ds="ds2" and ds'="ds3" in infer_tvar_crn_list)
apply (auto)
apply (cut_tac c_list="cl2" and ds="ds2" and ds'="ds3" in infer_pvar_crn_list)
apply (auto)
apply (rule_tac dir_list_add_sol_sat)
apply (rule_tac ds="set_diff ds' ds2" and ds'="set_diff ds2 ds" in comp_psub_sol_sat2)
apply (rule_tac ds="set_diff ds3 ds2" in comp_psub_sol_sat1)
apply (simp_all)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac x="x" and l="lb" in dom_list_set_contain)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
(* - constraint list 3 correctness *)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds3" in subset_sub_range)
apply (auto)
apply (cut_tac c_list="cl3" and ds="ds3" and ds'="ds'" in infer_tvar_crn_list)
apply (auto)
apply (cut_tac c_list="cl3" and ds="ds3" and ds'="ds'" in infer_pvar_crn_list)
apply (auto)
apply (rule_tac ds="set_diff ds' ds2" and ds'="set_diff ds2 ds" in comp_psub_sol_sat2)
apply (rule_tac ds="set_diff ds' ds3" in comp_psub_sol_sat2)
apply (simp_all)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
done
lemma ivr_if_case: "\<lbrakk>\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e1 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e1 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e2 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e2 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e3 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e3 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; well_typed env r_s e1 BoolTy r_s2 rx'; infer_type env_v ds e1 t1 r_s1 r_x1 r_m1 cl1 ds2;
well_typed env r_s2 e2 tau (diff_use_env r_s r_ex) rx1; infer_type env_v ds2 e2 t2 r_s2a r_x2 r_m2 cl2 ds3;
well_typed env r_s2 e3 tau (diff_use_env r_s r_ex) rx2; infer_type env_v ds3 e3 t3 r_s3 r_x3 r_m3 cl3 ds';
finite_dom (comp_var_env r_s1 (comp_var_env r_s2a r_s3)) d\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_s1 (comp_var_env r_s2a r_s3))) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_x2 r_x3)) r_ex) (comp_use_env rx1 rx2) \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_m1 (comp_var_env r_m2 r_m3)))) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub t2 tau \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub t1 BoolTy \<and>
(\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t2 tau_x \<and> dir_subst_type (dir_list_add_env t_sub l) p_sub t3 tau_x) \<and>
dir_sol_sat (dir_list_add_env t_sub l) p_sub (semi_disj_crn r_m1 (comp_var_env r_s2a r_s3) d @ cl1 @ cl2 @ cl3))"
apply (cut_tac r_s="r_s" and r_x="r_s2" in snorm_diff_use_env)
apply (auto)
apply (cut_tac e="e1" and env="env" and env_v="env_v" and t_sub="t_sub" and ds="ds" and r_s="r_s" and r_ex="r_exa" in ivric_coerce)
apply (auto)
apply (cut_tac env="env" and ?r_s1.0="r_s" and ?r_s2.0="r_s2" and e="e1" in well_typed_sstr_end_perm)
apply (auto)
apply (cut_tac e="e2" and env="dir_subst_tenv (dir_list_add_env t_sub l) env_v" and env_v="env_v" and
t_sub="dir_list_add_env t_sub l" and ds="ds2" and r_s="r_s2" and r_ex="r_ex" in ivric_coerce)
apply (auto)
apply (rule_tac r_c="diff_use_env r_s r_ex" in well_typed_decr_end_perm)
apply (auto)
apply (rule_tac dist_diff_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac mini_disj_diff_leq_use_env2)
apply (rule_tac r_sb="diff_use_env r_s r_ex" in trans_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac well_typed_perm_leqx)
apply (auto)
apply (rule_tac r_s="diff_use_env r_s r_ex" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac well_typed_perm_leqx)
apply (auto)
apply (rule_tac self_spec_env)
apply (rule_tac ds="ds" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (auto)
apply (cut_tac e="e3" and env="dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v" and env_v="env_v" and
t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ds="ds3" and r_s="r_s2" and r_ex="r_ex" in ivric_coerce)
apply (auto)
apply (rule_tac r_c="diff_use_env r_s r_ex" in well_typed_decr_end_perm)
apply (auto)
apply (rule_tac dist_diff_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac mini_disj_diff_leq_use_env2)
apply (rule_tac r_sb="diff_use_env r_s r_ex" in trans_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac well_typed_perm_leqx)
apply (auto)
apply (rule_tac r_s="diff_use_env r_s r_ex" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac well_typed_perm_leqx)
apply (auto)
apply (rule_tac eq_spec_env)
apply (auto)
apply (rule_tac ds="ds" in subset_sub_range)
apply (simp)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (rule_tac env_v="env_v" and r_s="r_s" and ?r_s3.0="r_s3" and ?e1.0="e1" and ?e2.0="e2" and ?e3.0="e3"
and ?r_s1.0="r_s1" and ?r_x1.0="r_x1" and ?r_m1.0="r_m1" and ?r_s2.0="r_s2" and ?r_x2.0="r_x2" and ?r_m2.0="r_m2"
and ?r_s3.0="r_s3" and ?r_x3.0="r_x3" and ?r_m3.0="r_m3" and t_sub="t_sub" and p_sub="p_sub" and p_suba="p_suba"
and p_subb="p_subb" and l="l" and la="la" and lb="lb" and ds="ds" and ?ds2.0="ds2" and ?ds3.0="ds3" and ds'="ds'" in ivric_main)
apply (auto)
done
lemma ivrlc_coerce: "\<lbrakk> \<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds \<rbrakk> \<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)"
apply (auto)
done
lemma add_spec_env: "\<lbrakk> sub_range env_v ds; a \<notin> ds; spec_env env_v env t_sub \<rbrakk> \<Longrightarrow>
spec_env (add_env env_v x a) (add_env env x tau) (dir_add_env t_sub a tau)"
apply (simp add: spec_env_def)
apply (simp add: add_env_def)
apply (auto)
apply (simp add: dir_add_env_def)
apply (erule_tac x="xa" in allE)
apply (case_tac "env xa")
apply (case_tac "env_v xa")
apply (auto)
apply (simp add: add_env_def)
apply (simp add: add_env_def)
apply (simp add: dir_add_env_def)
apply (simp add: sub_range_def)
apply (erule_tac x="xa" in allE)
apply (auto)
apply (case_tac "env_v xa")
apply (auto)
apply (simp add: add_env_def)
apply (simp add: dir_add_env_def)
apply (auto)
apply (simp add: sub_range_def)
apply (erule_tac x="xa" in allE)
apply (auto)
done
(* tau1 <: tau2 indicates that tau1 represents a stricter class of values. ie t1 can be used where t2 is used. *)
function sub_type :: "p_type \<Rightarrow> p_type \<Rightarrow> bool" where
"sub_type IntTy s = (s = IntTy)"
| "sub_type UnitTy s = (s = UnitTy)"
| "sub_type BoolTy s = (s = BoolTy)"
| "sub_type (ArrayTy t) s = (s = ArrayTy t)"
| "sub_type (PairTy t1 t2 r) s = (s = PairTy t1 t2 r)"
| "sub_type (FunTy t1 t2 r a) s = (case s of
FunTy s1 s2 q b \<Rightarrow> sub_type s1 t1 \<and> sub_type t2 s2 \<and> leq_perm q r \<and> leq_perm (as_perm a) (as_perm b)
| sx \<Rightarrow> False)"
| "sub_type (ChanTy t c_end) s = (s = ChanTy t c_end)"
by pat_completeness auto
termination
apply (rule_tac R="measure (\<lambda> (t, s). max (size t) (size s))" in local.termination)
apply (auto)
done
fun weaken_type where
"weaken_type (FunTy t1 t2 r a) s = (case s of
FunTy s1 s2 q b \<Rightarrow> t1 = s1 \<and> t2 = s2 \<and> r = q \<and> leq_perm (as_perm a) (as_perm b)
| sx \<Rightarrow> False)"
| "weaken_type t s = (t = s)"
lemma dir_list_ex: "\<lbrakk> t_sub x = tau; fresh_list ds (dom_list l); x \<in> ds \<rbrakk> \<Longrightarrow> dir_list_add_env t_sub l x = tau"
apply (induct l)
apply (auto)
apply (case_tac "\<not> fresh_list ds (dom_list l)")
apply (simp add: fresh_list_def)
apply (auto)
apply (simp add: dir_add_env_def)
apply (simp add: fresh_list_def)
apply (auto)
done
lemma sol_sat_aff: "\<lbrakk> aff_use_env (dir_subst_penv t_sub p_sub r_s) (as_aff (sol_subst_perm p_sub p)) \<rbrakk> \<Longrightarrow>
dir_sol_sat t_sub p_sub (aff_crn r_s p d)"
apply (induct d)
apply (auto)
apply (simp add: dir_subst_penv_def)
apply (simp add: aff_use_env_def)
apply (case_tac "sol_subst_perm p_sub p")
apply (auto)
apply (simp add: null_use_env_def)
apply (simp add: weak_use_env_def)
apply (case_tac "dir_subst_permx t_sub p_sub (r_s a)")
apply (auto)
done
lemma ivrlc_main: "\<lbrakk>
spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; infer_type (add_env env_v (Var x1a) a) (insert a ds) e t2 r_s' r_x' r_m' cl ds2;
well_typed (add_env env (Var x1a) t1) (add_use_env rx (Var x1a) r) e t2a r_s'a r_end; aff_use_env rx aa; leq_use_env rx r_s;
leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s r_exa); leq_use_env r_x (diff_use_env r_s r_ex); x1a \<notin> ref_vars e; leq_use_env r_exa r_s;
leq_use_env (diff_use_env rx r_exa) r_x; finite_dom (rem_var_env r_s' (Var x1a)) d; a \<notin> ds; p \<noteq> q; p \<notin> ds2; q \<notin> ds2;
tsub_dom (dir_list_add_env (dir_add_env t_sub a t1) l) ds2; fresh_list (insert a ds) (dom_list l);
dir_subst_tenv (dir_list_add_env (dir_add_env t_sub a t1) l) (add_env env_v (Var x1a) a) = add_env env (Var x1a) t1;
psub_dom p_sub (set_diff ds2 (insert a ds));
leq_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub r_s') (add_use_env rx (Var x1a) r);
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub r_x') (add_use_env rx (Var x1a) r))
(diff_use_env r_end (add_use_env rx (Var x1a) r));
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub r_m')) (add_use_env rx (Var x1a) r);
dir_subst_type (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub t2 t2a; dir_sol_sat (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub cl\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert p (insert q ds2)) \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff (insert p (insert q ds2)) ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \<and>
dir_list_add_env t_sub l a = Some t1 \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub t2 t2a \<and>
r = p_sub p \<and>
aa = as_aff (p_sub q) \<and>
leq_perm (dir_subst_permx (dir_list_add_env t_sub l) p_sub (r_s' (Var x1a))) (p_sub p) \<and>
dir_sol_sat (dir_list_add_env t_sub l) p_sub (aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d @ cl))"
(* defining new type substitution *)
apply (rule_tac x="l @ [(a, t1)]" in exI)
apply (auto)
apply (simp add: dir_list_append_eq)
apply (rule_tac ds="ds2" in subset_tsub_dom)
apply (auto)
apply (rule_tac t_sub="t_sub" and ds'="insert a ds" in append_fresh_list2)
apply (simp add: fresh_list_def)
apply (auto)
apply (rule_tac add_tsub_dom)
apply (auto)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
apply (cut_tac t_sub="t_sub" and l="l @ [(a, t1)]" and env_v="env_v" and ds="ds" in dir_list_cancel_add_eq_env)
apply (simp)
apply (rule_tac t_sub="t_sub" and ds'="insert a ds " in append_fresh_list2)
apply (simp add: fresh_list_def)
apply (auto)
apply (rule_tac add_tsub_dom)
apply (auto)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
apply (rule_tac dir_subst_spec_env_ex)
apply (simp)
(* prelim: initial permission containment *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) (add_use_env (add_use_env p_sub p r) q (as_perm aa)) r_s')
(add_use_env rx (Var x1a) r)")
apply (cut_tac t_sub="dir_list_add_env (dir_add_env t_sub a t1) l" and p_sub="add_use_env p_sub p r" and
r_xv="r_s'" and ds="set_diff ds2 (insert a ds)" and x="q" and r="as_perm aa" in add_psub_use_env)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_add_env t_sub a t1) l" and p_sub="p_sub" and
r_xv="r_s'" and ds="set_diff ds2 (insert a ds)" and x="p" and r="r" in add_psub_use_env)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
(* defining new permission substitution *)
apply (rule_tac x="add_use_env (add_use_env p_sub p r) q (as_perm aa)" in exI)
apply (auto)
(* p_sub containment *)
apply (rule_tac add_psub_dom)
apply (rule_tac add_psub_dom)
apply (rule_tac ds="set_diff ds2 (insert a ds)" in subset_psub_dom)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_x_subset)
apply (auto)
(* initial permission containment *)
apply (rule_tac r_sb="rem_use_env (add_use_env rx (Var x1a) r) (Var x1a)" in trans_leq_use_env)
apply (rule_tac r="r" in rem_add_leq_use_env)
apply (rule_tac dist_add_leq_use_env)
apply (simp)
apply (simp add: rem_sol_subst_penv)
apply (rule_tac dist_rem_leq_use_env)
apply (simp add: dir_list_append_eq)
(* requirements containment *)
apply (rule_tac r_sb="diff_use_env rx r_exa" in trans_leq_use_env)
apply (simp)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (simp_all)
apply (rule_tac diff_leq_use_env)
apply (simp add: rem_sol_subst_penv)
apply (rule_tac r="r" in rem_add_leq_use_env)
apply (simp add: dir_list_append_eq)
apply (cut_tac t_sub="dir_list_add_env (dir_add_env t_sub a t1) l" and p_sub="add_use_env p_sub p r" and
r_xv="r_s'" and ds="set_diff ds2 (insert a ds)" and x="q" and r="as_perm aa" in add_psub_use_env)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_add_env t_sub a t1) l" and p_sub="p_sub" and
r_xv="r_s'" and ds="set_diff ds2 (insert a ds)" and x="p" and r="r" in add_psub_use_env)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (simp add: set_diff_def)
(* subtractant containment *)
apply (rule_tac cut_leq_use_env)
apply (rule_tac empty_leq_var_env)
(* proof of a's type *)
apply (simp add: dir_list_append_eq)
apply (rule_tac ds="insert a ds" in dir_list_ex)
apply (simp add: dir_add_env_def)
apply (auto)
(* correctness for t2 *)
apply (simp add: dir_list_append_eq)
apply (cut_tac ds="insert a ds" and ds'="ds2" in infer_pvar_type)
apply (simp)
apply (rule_tac add_sub_range)
apply (simp)
apply (rule_tac add_dir_subst_type)
apply (rule_tac add_dir_subst_type)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
(* correctness of p + q *)
apply (simp add: add_use_env_def)
apply (simp add: add_use_env_def)
apply (case_tac aa)
apply (auto)
(* correctness of p with respect to r_s' *)
apply (case_tac "\<not> leq_perm ((dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l)
(add_use_env (add_use_env p_sub p r) q (as_perm aa)) r_s') (Var x1a)) ((add_use_env rx (Var x1a) r) (Var x1a))")
apply (simp add: leq_use_env_def)
apply (simp add: dir_list_append_eq)
apply (simp add: add_use_env_def)
apply (simp add: dir_subst_penv_def)
(* constraint list: affinity *)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_aff)
apply (case_tac "\<not> as_aff (sol_subst_perm (add_use_env (add_use_env p_sub p r) q (as_perm aa)) (SVar q)) = aa")
apply (simp add: add_use_env_def)
apply (case_tac "aa")
apply (auto)
apply (rule_tac r_s="rx" in aff_leq_use_env)
apply (simp)
apply (simp add: dir_list_append_eq)
apply (simp add: rem_sol_subst_penv)
apply (rule_tac rem_add_leq_use_env)
apply (simp)
(* - sub-constraint list correctness *)
apply (cut_tac c_list="cl" and ds="insert a ds" and ds'="ds2" in infer_pvar_crn_list)
apply (auto)
apply (rule_tac add_sub_range)
apply (simp)
apply (simp add: dir_list_append_eq)
apply (rule_tac add_psub_sol_sat)
apply (rule_tac add_psub_sol_sat)
apply (simp)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
done
lemma ivr_lam_case: "\<lbrakk>\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; infer_type (add_env env_v (Var x1a) a) (insert a ds) e t2 r_s' r_x' r_m' cl ds2;
well_typed (add_env env (Var x1a) t1) (add_use_env rx (Var x1a) r) e t2a r_s'a r_end; aff_use_env rx aa; leq_use_env rx r_s;
leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s r_exa); leq_use_env r_x (diff_use_env r_s r_ex); x1a \<notin> ref_vars e; leq_use_env r_exa r_s;
leq_use_env (diff_use_env rx r_exa) r_x; finite_dom (rem_var_env r_s' (Var x1a)) d; a \<notin> ds; p \<noteq> q; p \<notin> ds2; q \<notin> ds2\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert p (insert q ds2)) \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff (insert p (insert q ds2)) ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \<and>
dir_list_add_env t_sub l a = Some t1 \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub t2 t2a \<and>
r = p_sub p \<and>
aa = as_aff (p_sub q) \<and>
leq_perm (dir_subst_permx (dir_list_add_env t_sub l) p_sub (r_s' (Var x1a))) (p_sub p) \<and>
dir_sol_sat (dir_list_add_env t_sub l) p_sub (aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d @ cl))"
(* initial induction *)
apply (cut_tac env_v="add_env env_v (Var x1a) a" and env="add_env env (Var x1a) t1" and e="e"
and r_s="add_use_env rx (Var x1a) r" and r_ex="add_use_env rx (Var x1a) r" and ds="insert a ds" and t_sub="dir_add_env t_sub a t1" in ivrlc_coerce)
apply (auto)
apply (rule_tac well_typed_end_perm_lbound)
apply (auto)
apply (rule_tac ds="ds" in add_spec_env)
apply (simp_all)
apply (rule_tac add_sub_range)
apply (simp_all)
apply (rule_tac add_tsub_dom)
apply (rule_tac ds="ds" in subset_tsub_dom)
apply (auto)
(* main lemma *)
apply (rule_tac ivrlc_main)
apply (auto)
done
lemma add_fresh_list_ex: "\<lbrakk> fresh_list ds (dom_list l); tsub_dom (dir_list_add_env t_sub l) ds';
x \<notin> ds'; ds \<subseteq> ds' \<rbrakk> \<Longrightarrow> fresh_list ds (x # (dom_list l))"
apply (cut_tac x="x" and ds="ds" and l="l" and ds'="ds'" in add_fresh_list)
apply (auto)
done
lemma ivrac_coerce: "\<lbrakk> \<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds \<rbrakk> \<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)"
apply (auto)
done
lemma dir_add_cancel_use_env: "\<lbrakk> tvar_range r_sv ds; a \<notin> ds \<rbrakk> \<Longrightarrow>
dir_subst_penv (dir_add_env t_sub a tau) p_sub r_sv = dir_subst_penv t_sub p_sub r_sv"
apply (case_tac "\<forall> x. dir_subst_penv (dir_add_env t_sub a tau) p_sub r_sv x = dir_subst_penv t_sub p_sub r_sv x")
apply (auto)
apply (cut_tac t_sub="t_sub" and a="a" and r_sv="r_sv" and tau="tau" in dir_add_cancel_use_env_ih)
apply (auto)
done
lemma ifz_sol_subst_penv_gen: "\<lbrakk> dir_subst_permx t_sub p_sub px = NoPerm \<rbrakk> \<Longrightarrow> dir_subst_penv t_sub p_sub (ifz_var_env px r_sv) = empty_use_env"
apply (case_tac "\<forall> x. dir_subst_penv t_sub p_sub (ifz_var_env px r_sv) x = empty_use_env x")
apply (auto)
apply (simp add: dir_subst_penv_def)
apply (simp add: ifz_var_env_def)
apply (simp add: empty_use_env_def)
apply (case_tac "r_sv x = XPerm (SPerm NoPerm)")
apply (auto)
done
lemma ivrac_main: "\<lbrakk>
spec_env env_v (dir_subst_tenv (dir_list_add_env t_sub l) env_v) t_sub; sub_range env_v ds; tsub_dom t_sub ds;
infer_type env_v ds e1 tau_f r_s1 r_x1 r_m1 cl1 ds2;
infer_type env_v ds2 e2 t1a r_s2a r_x2 r_m2 cl2 ds3; leq_use_env r_s3 r_s;
leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa));
leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s3; disj_use_env rx1 (lift_use_env rx2 r); leq_use_env r_x (diff_use_env r_s r_ex);
leq_use_env r_exa r_s; leq_use_env (app_req rx1 rx2 r tau r_exa) r_x;
finite_dom (comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))) d; fresh_list ds3 [aa, p, q]; leq_use_env r_exaa r_s;
leq_use_env r_exb (diff_use_env r_s r_exaa); super_norm_use_env r_s r_s3 = diff_use_env r_s (comp_use_env r_exaa r_exb);
well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s e1 (FunTy t1 tau r a) (diff_use_env r_s r_exaa) rx1;
well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) (diff_use_env r_s r_exaa) e2 t1 (diff_use_env (diff_use_env r_s r_exaa) r_exb) rx2;
tsub_dom (dir_list_add_env t_sub l) ds2; fresh_list ds (dom_list l); env = dir_subst_tenv (dir_list_add_env t_sub l) env_v;
psub_dom p_sub (set_diff ds2 ds); leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_s1) r_s;
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_x1) r_exaa) rx1;
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_m1)) r_exaa;
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_f (FunTy t1 tau r a); dir_sol_sat (dir_list_add_env t_sub l) p_sub cl1;
tsub_dom (dir_list_add_env (dir_list_add_env t_sub l) la) ds3; fresh_list ds2 (dom_list la);
dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;
psub_dom p_suba (set_diff ds3 ds2); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_s2a) (diff_use_env r_s r_exaa);
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_x2) r_exb) rx2;
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_m2)) r_exb;
dir_subst_type (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba t1a t1; dir_sol_sat (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba cl2\<rbrakk>
\<Longrightarrow> \<exists>la. tsub_dom (dir_list_add_env t_sub la) (insert aa (insert p (insert q ds3))) \<and>
fresh_list ds (dom_list la) \<and>
dir_subst_tenv (dir_list_add_env t_sub la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff (insert aa (insert p (insert q ds3))) ds) \<and>
leq_use_env
(dir_subst_penv (dir_list_add_env t_sub la) p_sub
(comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))))
r_s \<and>
leq_use_env
(diff_use_env
(dir_subst_penv (dir_list_add_env t_sub la) p_sub (ifz_var_env (XType aa) (comp_var_env r_x1 (lift_var_env r_x2 (SVar p))))) r_ex)
r_x \<and>
leq_use_env
(cut_use_env
(dir_subst_penv (dir_list_add_env t_sub la) p_sub
(comp_var_env (comp_var_env r_m1 r_x1) (comp_var_env r_m2 (lift_var_env r_x2 (SVar p))))))
r_ex \<and>
dir_list_add_env t_sub la aa = Some tau \<and>
(\<exists>tau_x. (\<exists>t1_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t1a t1_x \<and>
(\<exists>t2_x. dir_list_add_env t_sub la aa = Some t2_x \<and> tau_x = FunTy t1_x t2_x (p_sub p) (as_aff (p_sub q)))) \<and>
dir_subst_type (dir_list_add_env t_sub la) p_sub tau_f tau_x) \<and>
dir_sol_sat (dir_list_add_env t_sub la) p_sub
(disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d @ semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2a d @ cl1 @ cl2))"
(* prelim: type subst domain *)
apply (cut_tac t_sub="t_sub" and ?l1.0="la" and ?l2.0="l" and ds="ds3" in append_tsub_dom)
apply (rule_tac ds="ds" in list_add_tsub_dom)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="t_sub" and l="l" and ds="ds2" in list_add_dls)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and ds="ds3" in list_add_dls)
apply (auto)
(* defining new t_sub *)
apply (rule_tac x="[(aa, tau)] @ la @ l" in exI)
apply (auto)
apply (rule_tac add_tsub_dom)
apply (rule_tac ds="ds3" in subset_tsub_dom)
apply (auto)
apply (rule_tac t_sub="t_sub" and ds'="ds3" in add_fresh_list_ex)
apply (rule_tac ds="ds" and ds'="ds2" in append_fresh_list2)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (rule_tac ds="ds" in dir_add_eq_env)
apply (simp add: dir_list_append_eq)
apply (simp)
apply (case_tac "aa \<in> ds3")
apply (simp add: fresh_list_def)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
(* p \<notin> ds3 *)
apply (case_tac "p \<in> ds3")
apply (simp add: fresh_list_def)
apply (auto)
apply (case_tac "aa \<in> ds3")
apply (simp add: fresh_list_def)
apply (auto)
apply (case_tac "q \<in> ds3")
apply (simp add: fresh_list_def)
apply (auto)
(* prelim: sub_range env_v ds2 *)
apply (cut_tac env_v="env_v" and ds="ds" and ds'="ds2" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (simp)
(* P* inequality 1 *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_s1) r_s")
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_tvar_range)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and a="aa" and tau="tau" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and r_sv="r_s1" and ds="ds2" in dir_add_cancel_use_env)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)"
and r_sv="r_s1" and ds="ds2" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and r_xv="r_s1"
and ds="set_diff ds2 ds" and x="q" and r="as_perm a" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_s1" and ds="set_diff ds2 ds" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="p_suba" and r_xv="r_s1" and ds="set_diff ds2 ds" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* P* inequality 2 *)
apply (case_tac "\<not> leq_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_s2a) (diff_use_env r_s r_exaa)")
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_tvar_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and a="aa" and tau="tau" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and r_sv="r_s2a" and ds="ds3" in dir_add_cancel_use_env)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and
r_xv="r_s2a" and ds="set_diff ds3 ds2" and x="q" and r="as_perm a" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_s2a" and ds="set_diff ds3 ds2" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_sub" and r_xv="r_s2a" and ds="set_diff ds3 ds2" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* X* inequality 1 *)
apply (case_tac "\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1) r_exaa) rx1")
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_tvar_range)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and a="aa" and tau="tau" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and r_sv="r_x1" and ds="ds2" in dir_add_cancel_use_env)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and r_sv="r_x1" and ds="ds2" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_s_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and
r_xv="r_x1" and ds="set_diff ds2 ds" and x="q" and r="as_perm a" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_x1" and ds="set_diff ds2 ds" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="p_suba" and r_xv="r_x1" and ds="set_diff ds2 ds" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* X* inequality 2 *)
apply (case_tac "\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) rx2")
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_s_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_tvar_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and a="aa" and tau="tau" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and r_sv="r_x2" and ds="ds3" in dir_add_cancel_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and
r_xv="r_x2" and ds="set_diff ds3 ds2" and x="q" and r="as_perm a" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_x2" and ds="set_diff ds3 ds2" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_sub" and r_xv="r_x2" and ds="set_diff ds3 ds2" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* M* inequality 1 *)
apply (case_tac "\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_m1)) r_exaa")
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_m_tvar_range)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and a="aa" and tau="tau" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and r_sv="r_m1" and ds="ds2" in dir_add_cancel_use_env)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and l="la" and r_sv="r_m1" and ds="ds2" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" in dir_list_add_cancel_use_env)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds" and e="e1" and ds'="ds2" in infer_m_sub_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and
r_xv="r_m1" and ds="set_diff ds2 ds" and x="q" and r="as_perm a" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_m1" and ds="set_diff ds2 ds" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env t_sub l" and ?p_sub1.0="p_sub" and ?p_sub2.0="p_suba" and r_xv="r_m1" and ds="set_diff ds2 ds" in comp_psub_use_env1)
apply (auto)
apply (simp add: set_diff_def)
(* M* inequality 2 *)
apply (case_tac "\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_m2)) r_exb")
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_m_sub_range)
apply (auto)
apply (cut_tac env_v="env_v" and ds="ds2" and e="e2" and ds'="ds3" in infer_m_tvar_range)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and a="aa" and tau="tau" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and r_sv="r_m2" and ds="ds3" in dir_add_cancel_use_env)
apply (auto)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="add_use_env (comp_use_env p_sub p_suba) p r" and
r_xv="r_m2" and ds="set_diff ds3 ds2" and x="q" and r="as_perm a" in add_psub_use_env)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and p_sub="comp_use_env p_sub p_suba" and r_xv="r_m2" and ds="set_diff ds3 ds2" and x="p" and r="r" in add_psub_use_env)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and ?p_sub1.0="p_suba" and ?p_sub2.0="p_sub" and r_xv="r_m2" and ds="set_diff ds3 ds2" in comp_psub_use_env2)
apply (auto)
apply (simp add: set_diff_def)
(* prelim: (t_sub, p_sub)(tau_f) = FunTy t1 tau r a *)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and x="aa" and t="tau" and tau_v="tau_f" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and tau="FunTy t1 tau r a" in dir_add_subst_type)
apply (rule_tac dir_list_add_subst_type)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (simp)
apply (cut_tac tau_v="tau_f" and ds'="ds2" and ds="ds" in infer_pvar_type)
apply (auto)
apply (rule_tac add_dir_subst_type)
apply (rule_tac add_dir_subst_type)
apply (rule_tac ds="set_diff ds2 ds" in comp_dir_subst_type1)
apply (simp)
apply (rule_tac infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and l="la" in dom_list_contain)
apply (simp)
apply (cut_tac tau_v="tau_f" and ds'="ds2" and ds="ds" in infer_tvar_type)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
apply (cut_tac tau_v="tau_f" and ds'="ds2" and ds="ds" in infer_tvar_type)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
(* prelim: (t_sub, p_sub)(t1a) = t1 *)
apply (cut_tac t_sub="dir_list_add_env (dir_list_add_env t_sub l) la" and x="aa" and t="tau" and tau_v="t1a" and
p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and tau="t1" in dir_add_subst_type)
apply (rule_tac add_dir_subst_type)
apply (rule_tac add_dir_subst_type)
apply (rule_tac ds="set_diff ds3 ds2" in comp_dir_subst_type2)
apply (simp)
apply (rule_tac infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (cut_tac tau_v="t1a" and ds'="ds3" and ds="ds2" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac tau_v="t1a" and ds="ds2" and ds'="ds3" in infer_pvar_type)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac tau_v="t1a" and ds'="ds3" and ds="ds2" in infer_tvar_type)
apply (auto)
(* prelim: rewriting of lift r_x2 *)
apply (case_tac "dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) (lift_var_env r_x2 (SVar p)) \<noteq>
lift_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r")
apply (cut_tac t_sub="dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau"
and p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and r_s="r_x2" and r="SVar p" in lift_sol_subst_penv)
apply (case_tac "add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a) p \<noteq> r")
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (auto)
(* prelim: (t_sub, p_sub)( X1* ) \<le> P1 *)
apply (cut_tac r_sc="dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1"
and r_sb="comp_use_env rx1 r_exaa" and r_sa="r_s" in trans_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac r_sb="comp_use_env rx1 (lift_use_env rx2 r)" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac st_diff_comp_leq_use_env)
apply (simp)
(* prelim: (t_sub, p_sub)(lift( X2* )) \<le> P1 *)
apply (cut_tac r_sc="lift_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r"
and r_sb="comp_use_env (lift_use_env rx2 r) r_exb" and r_sa="r_s" in trans_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac r_sb="comp_use_env rx1 (lift_use_env rx2 r)" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac r_sb="diff_use_env r_s r_exaa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac t="diff_use_env (lift_use_env
(dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb" and
s="lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r" in subst)
apply (simp add: lift_diff_use_env)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)
(* defining new p_sub *)
apply (rule_tac x="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" in exI)
apply (auto)
(* p_sub domain containment *)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (rule_tac add_psub_dom)
apply (rule_tac add_psub_dom)
apply (rule_tac comp_psub_dom)
apply (rule_tac ds="set_diff ds2 ds" in subset_psub_dom)
apply (simp)
apply (rule_tac set_diff_subset)
apply (auto)
apply (rule_tac ds="set_diff ds3 ds2" in subset_psub_dom)
apply (simp)
apply (rule_tac set_diff_subset)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
(* initial permission containment *)
apply (simp add: dir_list_append_eq)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (simp_all)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s r_exaa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp_all)
(* requirements containment. primitive case *)
apply (case_tac "req_type tau = Prim")
apply (cut_tac t_sub="dir_add_env (dir_list_add_env t_sub (la @ l)) aa tau" and r_sv="comp_var_env r_x1 (lift_var_env r_x2 (SVar p))"
and p_sub="add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)" and px="XType aa" in ifz_sol_subst_penv_gen)
apply (simp add: dir_add_env_def)
apply (auto)
apply (rule_tac diff_leq_use_env)
apply (rule_tac leq_empty_use_env)
(* - non-primitive case *)
apply (simp add: app_req_def)
apply (simp add: dir_list_append_eq)
apply (rule_tac r_sb="diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)" in trans_leq_use_env)
apply (simp)
apply (rule_tac r_sb="diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)" in trans_leq_use_env)
apply (rule_tac lhs_dist_dcl_use_env)
apply (rule_tac rhs_dist_dcl_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac unroll_dcl_use_env)
apply (rule_tac dist_diff_leq_use_env)
apply (rule_tac lhs_flip_use_env)
apply (rule_tac rhs_flip_use_env)
apply (rule_tac unroll_dcl_use_env)
apply (rule_tac dist_diff_leq_use_env)
apply (rule_tac spec_diff_lift_leq_use_env)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)" in trans_leq_use_env)
apply (rule_tac dist_diff_leq_use_env)
apply (simp_all)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) (comp_var_env r_x1 (lift_var_env r_x2 (SVar p)))) r_ex" in trans_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a))
(comp_var_env r_x1 (lift_var_env r_x2 (SVar p)))) (comp_use_env r_exaa r_exb)" in trans_leq_use_env)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac lhs_dist_dcl_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env1)
apply (rule_tac lhs_unroll_dcl_use_env)
apply (rule_tac diff_leq_use_env)
apply (simp)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac lhs_flip_use_env)
apply (rule_tac lhs_unroll_dcl_use_env)
apply (rule_tac diff_leq_use_env)
apply (rule_tac t="diff_use_env (lift_use_env
(dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb" and
s="lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r" in subst)
apply (simp add: lift_diff_use_env)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)
apply (rule_tac r_s="r_s" in crush_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)" in trans_leq_use_env)
apply (rule_tac t="diff_use_env r_s (comp_use_env r_exaa r_exb)" and s="super_norm_use_env r_s r_s3" in subst)
apply (simp)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (rule_tac self_diff_leq_use_env)
apply (simp_all)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac dist_comp_leq_use_env)
apply (simp_all)
apply (rule_tac self_diff_leq_use_env)
apply (rule_tac dist_diff_leq_use_env)
apply (rule_tac if_zero_leq_var_env)
apply (rule_tac id_leq_use_env)
(* subtractant containment *)
apply (rule_tac r_sb="cut_use_env (comp_use_env (comp_use_env rx1 r_exaa) (comp_use_env (lift_use_env rx2 r) r_exb))" in trans_leq_use_env)
apply (rule_tac r_s="r_s" in dist_diff_leq_use_env_rev)
apply (rule_tac r_sb="comp_use_env r_s (comp_use_env rx1 (lift_use_env rx2 r))" in trans_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac id_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (simp_all)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac comp_leq_use_env1)
apply (simp)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac comp_leq_use_env1)
apply (rule_tac r_sb="diff_use_env r_s r_exaa" in trans_leq_use_env)
apply (rule_tac self_diff_leq_use_env)
apply (simp)
apply (rule_tac r_sb="diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)" in trans_leq_use_env)
apply (rule_tac r_sb="diff_use_env r_s (comp_use_env (comp_use_env r_exaa r_exb) (comp_use_env rx1 (lift_use_env rx2 r)))" in trans_leq_use_env)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac comp_leq_use_env1)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac comp_leq_use_env1)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac rhs_unroll_dcl_use_env)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac t="diff_use_env r_s (comp_use_env r_exaa r_exb)" and s="super_norm_use_env r_s r_s3" in subst)
apply (simp)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (rule_tac id_leq_use_env)
apply (simp_all)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac rhs_cut_leq_use_env)
apply (simp add: dir_list_append_eq)
apply (simp add: comp_sol_subst_penv)
apply (rule_tac lhs_dist_cut_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac lhs_dist_cut_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env1)
apply (rule_tac comp_leq_use_env2)
apply (simp)
apply (rule_tac cut_leq_use_env)
apply (rule_tac comp_leq_use_env1)
apply (rule_tac st_diff_comp_leq_use_env)
apply (simp)
apply (rule_tac lhs_dist_cut_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac comp_leq_use_env2)
apply (simp)
apply (rule_tac cut_leq_use_env)
apply (rule_tac comp_leq_use_env2)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac t="diff_use_env (lift_use_env
(dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb" and
s="lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r" in subst)
apply (simp add: lift_diff_use_env)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)
(* correctness of expression type *)
apply (simp add: dir_add_env_def)
(* correctness of unification constraint *)
apply (simp add: dir_list_append_eq)
apply (rule_tac x="FunTy t1 tau r a" in exI)
apply (auto)
apply (simp add: dir_add_env_def)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (simp add: add_use_env_def)
apply (simp add: fresh_list_def)
apply (case_tac a)
apply (auto)
(* correctness of constraints: disjointness *)
apply (simp add: dir_list_append_eq)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_disj)
apply (rule_tac r_s="comp_use_env rx1 (cut_use_env r_exaa)" in disj_leq_use_env1)
apply (rule_tac r_s="comp_use_env (lift_use_env rx2 r) (cut_use_env r_exb)" in disj_leq_use_env2)
apply (rule_tac disj_comp_use_env1)
apply (rule_tac disj_comp_use_env2)
apply (simp)
apply (rule_tac cut_disj_use_env)
apply (rule_tac r_s="diff_use_env r_s r_exb" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="comp_use_env rx1 (lift_use_env rx2 r)" in trans_leq_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (simp_all)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac disj_comp_use_env2)
apply (rule_tac comm_disj_use_env)
apply (rule_tac cut_disj_use_env)
apply (rule_tac r_s="diff_use_env r_s r_exaa" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="comp_use_env rx1 (lift_use_env rx2 r)" in trans_leq_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env1)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (simp_all)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac comm_disj_use_env)
apply (rule_tac cut_disj_use_env)
apply (rule_tac r_s="diff_use_env r_s r_exaa" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac cut_leq_use_env)
apply (simp)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac r_sb="diff_use_env (lift_use_env
(dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb" in trans_leq_use_env)
apply (rule_tac t="diff_use_env (lift_use_env
(dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb" and
s="lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r" in subst)
apply (simp add: lift_diff_use_env)
apply (rule_tac dist_lift_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_cut)
apply (rule_tac id_leq_use_env)
apply (rule_tac id_leq_use_env)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1) r_exaa" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_cut)
apply (rule_tac id_leq_use_env)
apply (rule_tac id_leq_use_env)
(* - semi-disjointness 1 *)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_mini_disj)
apply (rule_tac cut_mini_disj_use_env)
apply (rule_tac r_s="r_exb" in mini_disj_leq_use_env1)
apply (rule_tac r_s="diff_use_env r_s r_exb" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="comp_use_env (diff_use_env r_s r_exb) (cut_use_env r_exaa)" in trans_leq_use_env)
apply (rule_tac dist_comp_leq_use_env)
apply (rule_tac id_leq_use_env)
apply (rule_tac swap_diff_cut_leq_use_env)
apply (simp_all)
apply (rule_tac st_diff_comp_leq_use_env)
apply (rule_tac r_sb="diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)
(add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1) r_exaa" in trans_leq_use_env)
apply (rule_tac r_sb="comp_use_env rx1 (lift_use_env rx2 r)" in trans_leq_use_env)
apply (rule_tac r_sb="r_s3" in trans_leq_use_env)
apply (rule_tac mini_disj_diff_leq_use_env2)
apply (simp)
apply (rule_tac r_s="diff_use_env r_s r_exb" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (rule_tac r_sb="super_norm_use_env r_s r_s3" in trans_leq_use_env)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_gen)
apply (rule_tac id_leq_use_env)
apply (rule_tac self_comp_leq_use_env2)
apply (rule_tac rhs_snorm_leq_use_env2)
apply (rule_tac id_leq_use_env)
apply (simp_all)
apply (rule_tac comp_leq_use_env1)
apply (simp)
apply (rule_tac dist_diff_leq_use_env_cut)
apply (rule_tac id_leq_use_env)
apply (rule_tac id_leq_use_env)
(* - semi-disjointness 2 *)
apply (rule_tac sol_sat_split)
apply (rule_tac sol_sat_mini_disj)
apply (rule_tac cut_mini_disj_use_env)
apply (rule_tac r_s="r_exaa" in mini_disj_leq_use_env1)
apply (rule_tac r_s="diff_use_env r_s r_exaa" in mini_disj_leq_use_env2)
apply (rule_tac mini_disj_diff_use_env)
apply (simp_all)
(* > constraint list 1 correctness *)
apply (rule_tac sol_sat_split)
apply (cut_tac c_list="cl1" and ds="ds" and ds'="ds2" in infer_tvar_crn_list)
apply (auto)
apply (cut_tac c_list="cl1" and ds="ds" and ds'="ds2" in infer_pvar_crn_list)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (rule_tac dir_add_sol_sat)
apply (rule_tac dir_list_add_sol_sat)
apply (rule_tac add_psub_sol_sat)
apply (rule_tac add_psub_sol_sat)
apply (rule_tac ds="set_diff ds2 ds" in comp_psub_sol_sat1)
apply (simp_all)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (cut_tac x="x" and l="la" in dom_list_set_contain)
apply (auto)
apply (simp add: fresh_list_def)
apply (auto)
(* > constraint list 2 correctness *)
apply (cut_tac c_list="cl2" and ds="ds2" and ds'="ds3" in infer_tvar_crn_list)
apply (auto)
apply (cut_tac c_list="cl2" and ds="ds2" and ds'="ds3" in infer_pvar_crn_list)
apply (auto)
apply (cut_tac ds="ds" and ds'="ds2" in infer_x_subset)
apply (auto)
apply (cut_tac ds="ds2" and ds'="ds3" in infer_x_subset)
apply (auto)
apply (rule_tac dir_add_sol_sat)
apply (rule_tac add_psub_sol_sat)
apply (rule_tac add_psub_sol_sat)
apply (rule_tac ds="set_diff ds3 ds2" in comp_psub_sol_sat2)
apply (simp_all)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
apply (simp add: set_diff_def)
apply (auto)
done
lemma ivr_app_case: "\<lbrakk>\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e1 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e1 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.
\<lbrakk>well_typed env r_s e2 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e2 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \<and>
leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \<and>
leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);
spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; well_typed env r_s e1 (FunTy t1 tau r a) r_s2 rx1;
infer_type env_v ds e1 tau_f r_s1 r_x1 r_m1 cl1 ds2; well_typed env r_s2 e2 t1 r_s3 rx2; infer_type env_v ds2 e2 t1a r_s2a r_x2 r_m2 cl2 ds3;
leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa));
leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s3; disj_use_env rx1 (lift_use_env rx2 r); leq_use_env r_x (diff_use_env r_s r_ex);
leq_use_env r_exa r_s; leq_use_env (app_req rx1 rx2 r tau r_exa) r_x;
finite_dom (comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))) d; fresh_list ds3 [aa, p, q]\<rbrakk>
\<Longrightarrow> \<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert aa (insert p (insert q ds3))) \<and>
fresh_list ds (dom_list l) \<and>
dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \<and>
(\<exists>p_sub. psub_dom p_sub (set_diff (insert aa (insert p (insert q ds3))) ds) \<and>
leq_use_env
(dir_subst_penv (dir_list_add_env t_sub l) p_sub
(comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))))
r_s \<and>
leq_use_env
(diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (ifz_var_env (XType aa) (comp_var_env r_x1 (lift_var_env r_x2 (SVar p)))))
r_ex)
r_x \<and>
leq_use_env
(cut_use_env
(dir_subst_penv (dir_list_add_env t_sub l) p_sub
(comp_var_env (comp_var_env r_m1 r_x1) (comp_var_env r_m2 (lift_var_env r_x2 (SVar p))))))
r_ex \<and>
dir_list_add_env t_sub l aa = Some tau \<and>
(\<exists>tau_x. (\<exists>t1_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t1a t1_x \<and>
(\<exists>t2_x. dir_list_add_env t_sub l aa = Some t2_x \<and> tau_x = FunTy t1_x t2_x (p_sub p) (as_aff (p_sub q)))) \<and>
dir_subst_type (dir_list_add_env t_sub l) p_sub tau_f tau_x) \<and>
dir_sol_sat (dir_list_add_env t_sub l) p_sub
(disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d @ semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2a d @ cl1 @ cl2))"
apply (cut_tac env="env" and ?e1.0="e1" and ?e2.0="e2" in ivr_induct_format)
apply (auto)
apply (cut_tac e="e1" and env_v="env_v" and t_sub="t_sub" and ds="ds" in ivrac_coerce)
apply (auto)
apply (cut_tac e="e2" and env_v="env_v" and t_sub="dir_list_add_env t_sub l" and ds="ds2" in ivrac_coerce)
apply (auto)
apply (rule_tac self_spec_env)
apply (rule_tac ds="ds" in subset_sub_range)
apply (simp)
apply (rule_tac infer_x_subset)
apply (auto)
apply (rule_tac env_v="env_v" and r_s="r_s" and ?r_s3.0="r_s3" and ?e1.0="e1" and ?e2.0="e2"
and ?r_s1.0="r_s1" and ?r_x1.0="r_x1" and ?r_m1.0="r_m1" and r_s2a="r_s2a" and ?r_x2.0="r_x2" and ?r_m2.0="r_m2" in ivrac_main)
apply (auto)
apply (rule_tac r_sb="r_s2" in trans_leq_use_env)
apply (rule_tac well_typed_perm_leq)
apply (auto)
apply (rule_tac well_typed_perm_leq)
apply (auto)
done
(*
[ Gamma, P |- e: tau, P - EX, Q \<and> Infer(Gamma*, X, e) = (tau*, P*, Q*, R*, K, X') \<and> \<sigma>( Gamma* ) = Gamma
\<and> range( Gamma* ) \<subseteq> X \<and> dom(\<sigma>) \<subseteq> X ] \<Longrightarrow>
(\<exists> \<sigma>* \<sigma>' \<rho>. \<sigma>' = \<sigma> o \<sigma>* \<and> dom(\<sigma>') \<subseteq> X \<and> fresh(\<sigma>*, X) \<and> \<sigma>'( Gamma* ) = Gamma
\<and> dom( \<rho> ) \<subseteq> X' - X \<and> (\<sigma>', \<rho>)( P* ) \<le> P \<and> (\<sigma>', \<rho>)( Q* ) - EX \<le> Q \<and> (\<sigma>', \<rho>)( R* ) \<le> EX
\<and> (\<sigma>', \<rho>)( tau* ) = tau \<and> (\<sigma>', \<rho>) |= K)
*)
lemma ivr_partial: "\<lbrakk> well_typed env r_s e tau (diff_use_env r_s r_ex) r_x;
infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;
sub_range env_v ds; tsub_dom t_sub ds \<rbrakk> \<Longrightarrow>
(\<exists> l t_subx p_sub. t_subx = dir_list_add_env t_sub l \<and> tsub_dom t_subx ds' \<and>
fresh_list ds (dom_list l) \<and> dir_subst_tenv t_subx env_v = env \<and>
psub_dom p_sub (set_diff ds' ds) \<and> leq_use_env (dir_subst_penv t_subx p_sub r_sv) r_s \<and>
leq_use_env (diff_use_env (dir_subst_penv t_subx p_sub r_xv) r_ex) r_x \<and> leq_use_env (cut_use_env (dir_subst_penv t_subx p_sub r_mv)) r_ex \<and>
dir_subst_type t_subx p_sub tau_v tau \<and> dir_sol_sat t_subx p_sub c_list)"
apply (induct e arbitrary: tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub)
apply (auto)
(* const case *)
apply (rule_tac ivr_const_case)
apply (auto)
(* op case *)
apply (rule_tac ivr_op_case)
apply (auto)
(* var case *)
apply (rule_tac ivr_var_case)
apply (auto)
(* pair case *)
apply (rule_tac ivr_pair_case)
apply (auto)
(* if case *)
apply (rule_tac ivr_if_case)
apply (auto)
(* lam case *)
apply (rule_tac ivr_lam_case)
apply (auto)
(* app case *)
apply (rule_tac ivr_app_case)
apply (auto)
done
lemma infer_valid_right: "\<lbrakk> well_typed empty_env r_s1 e tau r_s2 rx; infer_type empty_env ds e tau_v r_sv r_xv r_mv c_list ds' \<rbrakk> \<Longrightarrow> \<exists> t_sub p_sub. dir_sol_sat t_sub p_sub c_list"
apply (cut_tac env="empty_env" and env_v="empty_env" and e="e" and r_s="r_s1" and r_x="diff_use_env rx r_s1" and r_ex="r_s1" and t_sub="empty_env" in ivr_partial)
apply (auto)
apply (rule_tac well_typed_end_perm_lbound)
apply (simp)
apply (simp add: spec_env_def)
apply (simp add: empty_env_def)
apply (simp add: sub_range_def)
apply (simp add: empty_env_def)
apply (simp add: tsub_dom_def)
apply (simp add: empty_env_def)
done
end |
[STATEMENT]
lemma holomorphic_log:
assumes "connected S" and holf: "f holomorphic_on S" and nz: "\<And>z. z \<in> S \<Longrightarrow> f z \<noteq> 0"
and prev: "\<And>f. f holomorphic_on S \<Longrightarrow> \<exists>h. \<forall>z \<in> S. (h has_field_derivative f z) (at z)"
shows "\<exists>g. g holomorphic_on S \<and> (\<forall>z \<in> S. f z = exp(g z))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
[PROOF STEP]
have "(\<lambda>z. deriv f z / f z) holomorphic_on S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<lambda>z. deriv f z / f z) holomorphic_on S
[PROOF STEP]
by (simp add: openS holf holomorphic_deriv holomorphic_on_divide nz)
[PROOF STATE]
proof (state)
this:
(\<lambda>z. deriv f z / f z) holomorphic_on S
goal (1 subgoal):
1. \<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>z. deriv f z / f z) holomorphic_on S
[PROOF STEP]
obtain g where g: "\<And>z. z \<in> S \<Longrightarrow> (g has_field_derivative deriv f z / f z) (at z)"
[PROOF STATE]
proof (prove)
using this:
(\<lambda>z. deriv f z / f z) holomorphic_on S
goal (1 subgoal):
1. (\<And>g. (\<And>z. z \<in> S \<Longrightarrow> (g has_field_derivative deriv f z / f z) (at z)) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using prev [of "\<lambda>z. deriv f z / f z"]
[PROOF STATE]
proof (prove)
using this:
(\<lambda>z. deriv f z / f z) holomorphic_on S
(\<lambda>z. deriv f z / f z) holomorphic_on S \<Longrightarrow> \<exists>h. \<forall>z\<in>S. (h has_field_derivative deriv f z / f z) (at z)
goal (1 subgoal):
1. (\<And>g. (\<And>z. z \<in> S \<Longrightarrow> (g has_field_derivative deriv f z / f z) (at z)) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
?z \<in> S \<Longrightarrow> (g has_field_derivative deriv f ?z / f ?z) (at ?z)
goal (1 subgoal):
1. \<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
[PROOF STEP]
have hfd: "\<And>x. x \<in> S \<Longrightarrow> ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>x. x \<in> S \<Longrightarrow> ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at x)
[PROOF STEP]
apply (rule derivative_eq_intros g| simp)+
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<And>x. x \<in> S \<Longrightarrow> (f has_field_derivative ?E1 x) (at x)
2. \<And>x. x \<in> S \<Longrightarrow> f x \<noteq> 0
3. \<And>x. x \<in> S \<Longrightarrow> (exp (g x) * deriv f x / f x * f x - exp (g x) * ?E1 x) / (f x * f x) = 0
[PROOF STEP]
apply (subst DERIV_deriv_iff_field_differentiable)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<And>x. x \<in> S \<Longrightarrow> f field_differentiable at x
2. \<And>x. x \<in> S \<Longrightarrow> f x \<noteq> 0
3. \<And>x. x \<in> S \<Longrightarrow> (exp (g x) * deriv f x / f x * f x - exp (g x) * deriv f x) / (f x * f x) = 0
[PROOF STEP]
using openS holf holomorphic_on_imp_differentiable_at nz
[PROOF STATE]
proof (prove)
using this:
open S
f holomorphic_on S
\<lbrakk>?f holomorphic_on ?s; open ?s; ?x \<in> ?s\<rbrakk> \<Longrightarrow> ?f field_differentiable at ?x
?z \<in> S \<Longrightarrow> f ?z \<noteq> 0
goal (3 subgoals):
1. \<And>x. x \<in> S \<Longrightarrow> f field_differentiable at x
2. \<And>x. x \<in> S \<Longrightarrow> f x \<noteq> 0
3. \<And>x. x \<in> S \<Longrightarrow> (exp (g x) * deriv f x / f x * f x - exp (g x) * deriv f x) / (f x * f x) = 0
[PROOF STEP]
apply auto
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
?x \<in> S \<Longrightarrow> ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at ?x)
goal (1 subgoal):
1. \<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
[PROOF STEP]
obtain c where c: "\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<And>c. (\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
proof (rule DERIV_zero_connected_constant[OF \<open>connected S\<close> openS finite.emptyI])
[PROOF STATE]
proof (state)
goal (3 subgoals):
1. (\<And>c. (\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c) \<Longrightarrow> thesis) \<Longrightarrow> continuous_on S ?f2
2. (\<And>c. (\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c) \<Longrightarrow> thesis) \<Longrightarrow> \<forall>x\<in>S - {}. (?f2 has_field_derivative 0) (at x)
3. \<And>c. \<lbrakk>\<And>c. (\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c) \<Longrightarrow> thesis; \<And>x. x \<in> S \<Longrightarrow> ?f2 x = c\<rbrakk> \<Longrightarrow> thesis
[PROOF STEP]
show "continuous_on S (\<lambda>z. exp (g z) / f z)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. continuous_on S (\<lambda>z. exp (g z) / f z)
[PROOF STEP]
by (metis (full_types) openS g continuous_on_divide continuous_on_exp holf holomorphic_on_imp_continuous_on holomorphic_on_open nz)
[PROOF STATE]
proof (state)
this:
continuous_on S (\<lambda>z. exp (g z) / f z)
goal (2 subgoals):
1. (\<And>c. (\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c) \<Longrightarrow> thesis) \<Longrightarrow> \<forall>x\<in>S - {}. ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at x)
2. \<And>c. \<lbrakk>\<And>c. (\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c) \<Longrightarrow> thesis; \<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c\<rbrakk> \<Longrightarrow> thesis
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
continuous_on S (\<lambda>z. exp (g z) / f z)
[PROOF STEP]
show "\<forall>x\<in>S - {}. ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at x)"
[PROOF STATE]
proof (prove)
using this:
continuous_on S (\<lambda>z. exp (g z) / f z)
goal (1 subgoal):
1. \<forall>x\<in>S - {}. ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at x)
[PROOF STEP]
using hfd
[PROOF STATE]
proof (prove)
using this:
continuous_on S (\<lambda>z. exp (g z) / f z)
?x \<in> S \<Longrightarrow> ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at ?x)
goal (1 subgoal):
1. \<forall>x\<in>S - {}. ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at x)
[PROOF STEP]
by (blast intro: DERIV_zero_connected_constant [OF \<open>connected S\<close> openS finite.emptyI, of "\<lambda>z. exp(g z) / f z"])
[PROOF STATE]
proof (state)
this:
\<forall>x\<in>S - {}. ((\<lambda>z. exp (g z) / f z) has_field_derivative 0) (at x)
goal (1 subgoal):
1. \<And>c. \<lbrakk>\<And>c. (\<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c) \<Longrightarrow> thesis; \<And>x. x \<in> S \<Longrightarrow> exp (g x) / f x = c\<rbrakk> \<Longrightarrow> thesis
[PROOF STEP]
qed auto
[PROOF STATE]
proof (state)
this:
?x \<in> S \<Longrightarrow> exp (g ?x) / f ?x = c
goal (1 subgoal):
1. \<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
[PROOF STEP]
proof (intro exI ballI conjI)
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. ?g holomorphic_on S
2. \<And>z. z \<in> S \<Longrightarrow> f z = exp (?g z)
[PROOF STEP]
show "(\<lambda>z. Ln(inverse c) + g z) holomorphic_on S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<lambda>z. Ln (inverse c) + g z) holomorphic_on S
[PROOF STEP]
apply (intro holomorphic_intros)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. g holomorphic_on S
[PROOF STEP]
using openS g holomorphic_on_open
[PROOF STATE]
proof (prove)
using this:
open S
?z \<in> S \<Longrightarrow> (g has_field_derivative deriv f ?z / f ?z) (at ?z)
open ?s \<Longrightarrow> (?f holomorphic_on ?s) = (\<forall>x\<in>?s. \<exists>f'. (?f has_field_derivative f') (at x))
goal (1 subgoal):
1. g holomorphic_on S
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
(\<lambda>z. Ln (inverse c) + g z) holomorphic_on S
goal (1 subgoal):
1. \<And>z. z \<in> S \<Longrightarrow> f z = exp (Ln (inverse c) + g z)
[PROOF STEP]
fix z :: complex
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<And>z. z \<in> S \<Longrightarrow> f z = exp (Ln (inverse c) + g z)
[PROOF STEP]
assume "z \<in> S"
[PROOF STATE]
proof (state)
this:
z \<in> S
goal (1 subgoal):
1. \<And>z. z \<in> S \<Longrightarrow> f z = exp (Ln (inverse c) + g z)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
z \<in> S
[PROOF STEP]
have "exp (g z) / c = f z"
[PROOF STATE]
proof (prove)
using this:
z \<in> S
goal (1 subgoal):
1. exp (g z) / c = f z
[PROOF STEP]
by (metis c divide_divide_eq_right exp_not_eq_zero nonzero_mult_div_cancel_left)
[PROOF STATE]
proof (state)
this:
exp (g z) / c = f z
goal (1 subgoal):
1. \<And>z. z \<in> S \<Longrightarrow> f z = exp (Ln (inverse c) + g z)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
exp (g z) / c = f z
goal (1 subgoal):
1. \<And>z. z \<in> S \<Longrightarrow> f z = exp (Ln (inverse c) + g z)
[PROOF STEP]
have "1 / c \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. 1 / c \<noteq> 0
[PROOF STEP]
using \<open>z \<in> S\<close> c nz
[PROOF STATE]
proof (prove)
using this:
z \<in> S
?x \<in> S \<Longrightarrow> exp (g ?x) / f ?x = c
?z \<in> S \<Longrightarrow> f ?z \<noteq> 0
goal (1 subgoal):
1. 1 / c \<noteq> 0
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
1 / c \<noteq> 0
goal (1 subgoal):
1. \<And>z. z \<in> S \<Longrightarrow> f z = exp (Ln (inverse c) + g z)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
exp (g z) / c = f z
1 / c \<noteq> 0
[PROOF STEP]
show "f z = exp (Ln (inverse c) + g z)"
[PROOF STATE]
proof (prove)
using this:
exp (g z) / c = f z
1 / c \<noteq> 0
goal (1 subgoal):
1. f z = exp (Ln (inverse c) + g z)
[PROOF STEP]
by (simp add: exp_add inverse_eq_divide)
[PROOF STATE]
proof (state)
this:
f z = exp (Ln (inverse c) + g z)
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<exists>g. g holomorphic_on S \<and> (\<forall>z\<in>S. f z = exp (g z))
goal:
No subgoals!
[PROOF STEP]
qed |
#define BOOST_TEST_MODULE TestAccessPoint
#include <boost/test/included/unit_test.hpp>
#include "db.h"
#include "helper.cpp"
using namespace odb;
using namespace std;
BOOST_AUTO_TEST_SUITE( test_suite )
BOOST_AUTO_TEST_CASE( test_default )
{
dbDatabase* db;
db = createSimpleDB();
auto block = db->getChip()->getBlock();
auto and2 = db->findMaster("and2");
auto term = and2->findMTerm("a");
auto layer = db->getTech()->findLayer("L1");
auto pin = dbMPin::create(term);
auto ap = dbAccessPoint::create(block, pin, 0);
auto inst = dbInst::create(db->getChip()->getBlock(), and2, "i1");
auto iterm = inst->getITerm(term);
ap->setPoint(Point(10,250));
ap->setLayer(layer);
ap->setHighType(dbAccessType::HalfGrid);
ap->setAccess(true, dbDirection::DOWN);
iterm->setAccessPoint(pin, ap);
FILE *write, *read;
std::string path = std::string(std::getenv("BASE_DIR"))
+ "/results/TestAccessPointDbRW";
write = fopen(path.c_str(), "w");
db->write(write);
dbDatabase::destroy(db);
dbDatabase* db2 = dbDatabase::create();
read = fopen(path.c_str(), "r");
db2->read(read);
auto aps = db2->getChip()->getBlock()->findInst("i1")->findITerm("a")->getPrefAccessPoints();
BOOST_TEST(aps.size() == 1);
ap = aps[0];
BOOST_TEST(ap->getPoint().x() == 10);
BOOST_TEST(ap->getPoint().y() == 250);
BOOST_TEST(ap->getMPin()->getMTerm()->getName() == "a");
BOOST_TEST(ap->getLayer()->getName() == "L1");
BOOST_TEST(ap->hasAccess());
BOOST_TEST(ap->getHighType() == dbAccessType::HalfGrid);
BOOST_TEST(ap->hasAccess(dbDirection::DOWN));
std::vector<dbDirection> dirs;
ap->getAccesses(dirs);
BOOST_TEST(dirs.size() == 1);
BOOST_TEST(dirs[0] == dbDirection::DOWN);
odb::dbAccessPoint::destroy(ap);
aps = db2->getChip()->getBlock()->findInst("i1")->findITerm("a")->getPrefAccessPoints();
BOOST_TEST(aps.size() == 0);
dbDatabase::destroy(db2);
}
BOOST_AUTO_TEST_SUITE_END()
|
lemma islimptI: assumes "\<And>T. x \<in> T \<Longrightarrow> open T \<Longrightarrow> \<exists>y\<in>S. y \<in> T \<and> y \<noteq> x" shows "x islimpt S" |
foo : Maybe Int -> Bool -> Int
foo Nothing _ = 42
foo Nothing True = 94
foo (Just x) _ = x
foo Nothing False = 42
|
With internet acquiring the opportunity to achieve corners all over the world a typical brick-and-mortar shop simply does not, it’s not question that internet sales are out performing traditional high-street spending. However, having a increase in shops browsing on the web, such potential growth ensures that almost every other web store will most likely do the identical. Which makes it much more imperative that you differentiate themselves in the game.
With plenty of websites online, it could get not only just a little crowded and competitive. Ecommerce websites have to be constantly developing to make sure optimal exposure online. Listed here are three key reasons for you to get a professional ecommerce Internet internet search engine optimization agency that will assist you gain online success.
While using the ultimate goal to boost Roi (Return on investment), it is crucial may be the ball with industry trends. Specialist ecommerce internet marketing agencies contain the understanding along with the tools to complete exactly that. Select a company with proof of past eCommerce success, the understanding and experience acquired from various successes provides you with a solid idea of how their service may benefit your company.
Christmas and Black Friday would be the finest ecommerce occasions that occur each year. Last year, Black Friday saw empty highstreets but internet sales soar. Specialist agencies contain the experience and finest practice to make sure your website is optimised willing and able to learn readily available shopping options. Internet internet search engine optimization could be a marketing funnel that take time to see results and collaborating obtaining a business who already practical understanding in particularly growing Return on investment for other online stores, ensures they knows the rules and methods to make sure your campaign could be a success initially.
With experience and understanding of eCommerce trends, specialist internet marketing agencies could make tailored strategies which will achieve your ultimate goals. For instance, a specialist eCommerce digital agency can identify keyword options that provides on commercial goals round the national or local campaign. The business can devise a effective Internet internet search engine optimization strategy that can help an online business raise brand awareness and most importantly boost their Return on investment using keywords with past driving new clients.
Calculating the prosperity of an internet site is essential to knowing if you’re getting that-important Return on investment out of your website. A specialist eCommerce Internet internet search engine optimization agency can precisely monitor your site performance and follow Internet internet search engine optimization strategies particularly tailored to growing sales. These agencies will learn to determine Key Performance Indicators (KPIs) and the ways to measure progress in your campaign.
Although, we’ve not seen the dying of high-street right now, it’s apparent that as every year passes the attention in internet shopping grows. Last November, an enormous study was transported out into 60 5 million eCommerce orders which proven the very best causes of traffic driving sales. Direct traffic takes charge with 40% of traffic and organic takes second place with 34% of traffic. Showing using the correct expertise your site might be reaping the net sales advantages of Internet internet search engine optimization. |
module Main
import Data.List
import Data.Strings
import System
import System.File
import Sat
import Data.DIMACS
main : IO ()
main = do
(_::fname::_) <- getArgs
| _ => putStrLn $ "missing input filename"
(Right cnfText) <- readFile fname
| Left readErr => putStrLn $ "error reading input file: " ++ show readErr
case parseDIMACS cnfText of
Right problem => do
--printLn problem
case sat problem.numVars problem.clauses of
Nothing => putStrLn "unsat"
Just assignment => do putStrLn "sat"
putStrLn $ unwords $ map showDIMACS assignment
Left error => putStrLn $ "parsing error: " ++ error
|
Require Import Infrastructure.
Require Import SourceProperty.
Require Import LR.
Require Import Assumed.
Require Import TargetProperty.
Require Import Disjoint.
(* ********************************************************************** *)
(** * Coercion Compatibility *)
Lemma E_coercion2 : forall A1 A2 A0 c p d d' e1 e2,
sub d' A1 A2 c ->
same_stctx d d' ->
swfte d ->
rel_d d p ->
E A0 (mtsubst_in_sty p A1) e2 e1 ->
E A0 (mtsubst_in_sty p A2) e2 (exp_capp c e1).
Proof with eauto.
introv ? ? ? ? EH.
apply E_sym in EH.
apply E_sym.
eapply E_coercion1...
Qed.
Lemma coercion_compatibility1 : forall A0 A1 A2 c D G e1 e2,
sub D A1 A2 c ->
swfte D ->
E_open D G e1 e2 A1 A0 ->
E_open D G (exp_capp c e1) e2 A2 A0.
Proof with eauto using subtype_well_type, swft_wft, E_coercion1.
introv Sub Uniq H.
destruct H as (? & ? & ? & ? & EH).
lets (? & ?): sub_regular Sub.
splits...
introv RelD RelG.
specializes EH RelD RelG.
autorewrite with lr_rewrite...
Qed.
Lemma coercion_compatibility2 : forall A0 A1 A2 c D G e1 e2,
sub D A1 A2 c ->
swfte D ->
E_open D G e1 e2 A0 A1 ->
E_open D G e1 (exp_capp c e2) A0 A2.
Proof with eauto using subtype_well_type, swft_wft, E_coercion2.
introv Sub Uniq H.
destruct H as (? & ? & ? & ? & EH).
lets (? & ?): sub_regular Sub.
splits...
introv RelD RelG.
specializes EH RelD RelG.
autorewrite with lr_rewrite...
Qed.
Hint Extern 1 (swfte ?E) =>
match goal with
| H: has_type _ _ _ _ _ _ |- _ => apply (proj2 (proj2 (proj2 (styping_regular _ _ _ _ _ _ H))))
end.
Hint Extern 1 (swft ?A ?B) =>
match goal with
| H: has_type _ _ _ _ _ _ |- _ => apply (proj1 (proj2 (proj2 (styping_regular _ _ _ _ _ _ H))))
end.
Lemma disjoint_compatibility : forall Δ Γ E1 e1 A1 E2 e2 A2 dir dir',
has_type Δ Γ E1 dir A1 e1 ->
has_type Δ Γ E2 dir' A2 e2 ->
disjoint Δ A1 A2 ->
E_open Δ Γ e1 e2 A1 A2.
Proof with eauto using swft_wft, swfe_wfe, elaboration_well_type, swft_from_swfe, mtsubst_swft, uniq_from_swfte.
introv Ty1 Ty2 Dis.
splits...
introv RelD RelG.
forwards (? & ?): rel_d_uniq RelD.
forwards : rel_d_same RelD...
forwards Ty3 : elaboration_well_type Ty1...
forwards Ty4 : elaboration_well_type Ty2...
forwards (Ty5 & ?) : subst_close RelD RelG Ty3.
forwards (? & Ty6) : subst_close RelD RelG Ty4.
splits...
lets (v1 & ? & ?) : normalization Ty5.
lets (v2 & ? & ?) : normalization Ty6.
exists v1 v2.
splits...
eapply disjoint_value...
apply preservation_multi_step with (e := msubst_in_exp g1 (mtsubst_in_exp p e1))...
apply preservation_multi_step with (e := msubst_in_exp g2 (mtsubst_in_exp p e2))...
Qed.
(* ********************************************************************** *)
(** * Pair compatibility *)
Lemma pair_compatibility : forall D G e1 e2 e1' e2' A B A' B',
E_open D G e1 e1' A A' ->
E_open D G e2 e2' B B' ->
swfte D ->
disjoint D A B' ->
disjoint D A' B ->
E_open D G (exp_pair e1 e2) (exp_pair e1' e2') (sty_and A B) (sty_and A' B').
Proof with eauto using preservation_multi_step.
introv EH1 EH2 Wfte Dis1 Dis2.
destruct EH1 as (? & ? & ? & ? & EH1).
destruct EH2 as (? & ? & ? & ? & EH2).
splits; simpls...
introv RelD RelG.
specializes EH1 RelD RelG.
specializes EH2 RelD RelG.
destruct EH1 as (? & ? & ? & ? & v1 & v1' & ? & ? & ? & ? & VH1).
destruct EH2 as (? & ? & ? & ? & v2 & v2' & ? & ? & ? & ? & VH2).
splits; autorewrite with lr_rewrite; simpls...
exists (exp_pair v1 v2) (exp_pair v1' v2').
splits...
apply V_andl...
splits...
apply V_andr...
splits...
eapply disjoint_value...
apply V_andr...
splits...
eapply disjoint_value...
eapply disjoint_symmetric...
Qed.
|
theory CFGExit imports CFG begin
subsection \<open>Adds an exit node to the abstract CFG\<close>
locale CFGExit = CFG sourcenode targetnode kind valid_edge Entry
for sourcenode :: "'edge \<Rightarrow> 'node" and targetnode :: "'edge \<Rightarrow> 'node"
and kind :: "'edge \<Rightarrow> 'state edge_kind" and valid_edge :: "'edge \<Rightarrow> bool"
and Entry :: "'node" ("'('_Entry'_')") +
fixes Exit::"'node" ("'('_Exit'_')")
assumes Exit_source [dest]: "\<lbrakk>valid_edge a; sourcenode a = (_Exit_)\<rbrakk> \<Longrightarrow> False"
and Entry_Exit_edge: "\<exists>a. valid_edge a \<and> sourcenode a = (_Entry_) \<and>
targetnode a = (_Exit_) \<and> kind a = (\<lambda>s. False)\<^sub>\<surd>"
begin
lemma Entry_noteq_Exit [dest]:
assumes eq:"(_Entry_) = (_Exit_)" shows "False"
proof -
from Entry_Exit_edge obtain a where "sourcenode a = (_Entry_)"
and "valid_edge a" by blast
with eq show False by simp(erule Exit_source)
qed
lemma Exit_noteq_Entry [dest]:"(_Exit_) = (_Entry_) \<Longrightarrow> False"
by(rule Entry_noteq_Exit[OF sym],simp)
lemma [simp]: "valid_node (_Exit_)"
proof -
from Entry_Exit_edge obtain a where "targetnode a = (_Exit_)"
and "valid_edge a" by blast
thus ?thesis by(fastforce simp:valid_node_def)
qed
definition inner_node :: "'node \<Rightarrow> bool"
where inner_node_def:
"inner_node n \<equiv> valid_node n \<and> n \<noteq> (_Entry_) \<and> n \<noteq> (_Exit_)"
lemma inner_is_valid:
"inner_node n \<Longrightarrow> valid_node n"
by(simp add:inner_node_def valid_node_def)
lemma [dest]:
"inner_node (_Entry_) \<Longrightarrow> False"
by(simp add:inner_node_def)
lemma [dest]:
"inner_node (_Exit_) \<Longrightarrow> False"
by(simp add:inner_node_def)
lemma [simp]:"\<lbrakk>valid_edge a; targetnode a \<noteq> (_Exit_)\<rbrakk>
\<Longrightarrow> inner_node (targetnode a)"
by(simp add:inner_node_def,rule ccontr,simp,erule Entry_target)
lemma [simp]:"\<lbrakk>valid_edge a; sourcenode a \<noteq> (_Entry_)\<rbrakk>
\<Longrightarrow> inner_node (sourcenode a)"
by(simp add:inner_node_def,rule ccontr,simp,erule Exit_source)
lemma valid_node_cases [consumes 1, case_names "Entry" "Exit" "inner"]:
"\<lbrakk>valid_node n; n = (_Entry_) \<Longrightarrow> Q; n = (_Exit_) \<Longrightarrow> Q;
inner_node n \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
apply(auto simp:valid_node_def)
apply(case_tac "sourcenode a = (_Entry_)") apply auto
apply(case_tac "targetnode a = (_Exit_)") apply auto
done
lemma path_Exit_source [dest]:
assumes "(_Exit_) -as\<rightarrow>* n'" shows "n' = (_Exit_)" and "as = []"
using \<open>(_Exit_) -as\<rightarrow>* n'\<close>
proof(induct n\<equiv>"(_Exit_)" as n' rule:path.induct)
case (Cons_path n'' as n' a)
from \<open>sourcenode a = (_Exit_)\<close> \<open>valid_edge a\<close> have False
by -(rule Exit_source,simp_all)
{ case 1 with \<open>False\<close> show ?case ..
next
case 2 with \<open>False\<close> show ?case ..
}
qed simp_all
lemma Exit_no_sourcenode[dest]:
assumes isin:"(_Exit_) \<in> set (sourcenodes as)" and path:"n -as\<rightarrow>* n'"
shows False
proof -
from isin obtain ns' ns'' where "sourcenodes as = ns'@(_Exit_)#ns''"
by(auto dest:split_list simp:sourcenodes_def)
then obtain as' as'' a where "as = as'@a#as''"
and source:"sourcenode a = (_Exit_)"
by(fastforce elim:map_append_append_maps simp:sourcenodes_def)
with path have "valid_edge a" by(fastforce dest:path_split)
with source show ?thesis by -(erule Exit_source)
qed
end
end
|
import category_theory.category.default
universes v u -- The order in this declaration matters: v often needs to be explicitly specified while u often can be omitted
namespace category_theory
variables (C : Type u) [category.{v} C]
/-
# Category world
## Level 1: Definition of category
A category `C` consists of
* a collection of objects `X, Y, Z, ...`
* a collection of morphisms `f, g, h, ...`
so that:
* each morphism has specified domain and codomain objects;
`f : X ⟶ Y` signifies that `f` is a morphism with
domain `X` and codomain `Y`
* each object has a designated identity morphism `𝟙 X : X ⟶ X`
* for any pair of morphisms `f, g` with the codomain of `f` equal
to the domain of `g`,the exists a specified composite morphism
`f ≫ g` whose domain is that of `f` and codomain that of `g`,
i.e. `f : X ⟶ Y, g : Y ⟶ Z` then `f ≫ g : X ⟶ Z`
This data is subject to the following axioms:
* For any `f : X ⟶ Y`,
-/
/- Axiom :
f ≫ 𝟙 Y = f-/
/- Axiom:
𝟙 X ≫ f = f-/
/-* For any composable triple of morphisms `f, g, h`, we have associativity
`f ≫ (g ≫ h) = (f ≫ g) ≫ h`-/
/- Axiom:
f ≫ (g ≫ h) = (f ≫ g) ≫ h-/
/-First we start out with some easy lemmas to get us warmed up.-/
/- Lemma
If $$f : X ⟶ Y$$ and $$g : X ⟶ Y$$ are morphisms such that $$f = g$$, then $$f ≫ h = g ≫ h$$.
-/
lemma eq_precomp_eq {X Y Z : C} {f g : X ⟶ Y} (w : f = g) (h : Y ⟶ Z) : f ≫ h = g ≫ h :=
begin
rw w,
end
end category_theory |
SUBROUTINE deallocate_memory
!**************************************************************************
! Subroutine deallocates all memory used for analysing a specific dumpfile
!**************************************************************************
use sphdata
use sphneighbourdata
use tachedata, only: tensorchoice
implicit none
print*, 'Deallocating Memory'
deallocate(nneigh,neighb)
if(allocated(occ)) deallocate(occ)
if(allocated(n_occ)) deallocate(n_occ)
print*, 'Tree memory deallocated'
deallocate(iphase,isteps,isort)
if(allocated(iorig)) deallocate(iorig)
deallocate(xyzmh,vxyzu,rho)
deallocate(listpm,spinx,spiny,spinz)
deallocate(angaddx,angaddy,angaddz)
deallocate(spinadx,spinady,spinadz)
if(allocated(dgrav)) deallocate(dgrav)
if(allocated(alphaMM)) deallocate(alphaMM)
if(allocated(gradh)) deallocate(gradh)
if(allocated(gradhsoft)) deallocate(gradhsoft)
if(tensorchoice=='tidal') deallocate(gravxyz,poten)
print*, 'SPH memory deallocated'
! Some MPI arrays might need to be deallocated too
if(allocated(nelementblocks)) deallocate(nelementblocks)
if(allocated(iunique)) deallocate(iunique)
END SUBROUTINE deallocate_memory
|
If $f$ is a holomorphic function on an open set $M$ that does not have a limit at $z \in M$, then there exists a point $a \in \mathbb{C}$ such that the set $\{x \in M - \{z\} : f(x) = a\}$ is infinite. |
#ifndef _IOEVENT_HTTP_CONNECTION_H
#define _IOEVENT_HTTP_CONNECTION_H
#include <boost/beast/http/read.hpp>
#include <boost/beast/http/write.hpp>
#include <boost/noncopyable.hpp>
namespace IOEvent
{
namespace Http
{
template <typename Derived, typename CompletionExecutor>
class Connection
{
using self_type = Connection;
Derived &derived()
{
return static_cast<Derived&>(*this);
}
public:
template <typename Function, typename Buffer, typename Parser>
auto async_read(Buffer& buffer, Parser& parse, Function&& function) ->decltype(void())
{
boost::beast::http::async_read(derived().stream(), buffer, parse,
boost::asio::bind_executor(completion_executor_, std::forward<Function>(function)));
}
template <typename Function, typename Serializer>
auto async_write(Serializer &serializer, Function &&function) ->decltype(void())
{
boost::beast::http::async_write(derived().stream(), serializer,
boost::asio::bind_executor(completion_executor_, std::forward<Function>(function)));
}
template <typename Buffer, typename Parser>
auto read(Buffer &buffer, Parser &parse) -> decltype(boost::system::error_code{})
{
boost::system::error_code error;
boost::beast::http::read(derived().stream(), buffer, parse, error);
return error;
}
template <typename Serializer>
auto write(Serializer &serializer) -> decltype(boost::system::error_code{})
{
boost::system::error_code error;
boost::beast::http::write(derived().stream(), serializer, error);
return error;
}
protected:
explicit Connection(CompletionExecutor const &executor)
:completion_executor_(executor)
{}
CompletionExecutor completion_executor_;
};
}
template <typename Socket, typename CompletionExecutor>
class Connection
: public Http::Connection<Connection<Socket, CompletionExecutor>, CompletionExecutor>,
boost::noncopyable
{
using self_type = Connection;
using http_connection = Http::Connection<self_type, CompletionExecutor>;
public:
using socket_type = Socket;
using shutdown_type = typename socket_type::shutdown_type;
public:
explicit Connection(socket_type &&socket, const CompletionExecutor &executor)
:http_connection{ executor },
socket_{std::move(socket)}
{}
auto shutdown(shutdown_type type) -> decltype(boost::system::error_code{})
{
auto error = boost::system::error_code{};
socket_.shutdown(type, error);
return error;
}
auto close() ->decltype(boost::system::error_code{})
{
auto error = boost::system::error_code{};
socket_.close(error);
return error;
}
socket_type &stream()
{
return socket_;
}
socket_type &asio_socket()
{
return socket_;
}
private:
socket_type socket_;
};
}
#endif // !_IOEVENT_HTTP_CONNECTION_H |
module Data.LeftPad
import Data.List
import Data.List.Predicates.Interleaving
%default total
%access public export
data Padding : (s : List Char) -> (target : Nat) -> Type where
Pad : (pad : Nat) -> Padding s (length s + pad)
Nop : Padding (ys ++ x :: xs) (length ys)
padding : (s : List Char) -> (target : Nat) -> Padding s target
padding [] t = Pad t
padding (x :: xs) Z = Nop {ys = []}
padding (x :: xs) (S t) with (padding xs t)
padding (x :: xs) (S (plus (length xs) p)) | Pad p = Pad p
padding (y :: ys ++ z :: zs) (S (length ys)) | Nop = Nop {ys=y::ys}
pad : (s : List Char) -> (c : Char) -> (target : Nat) -> List Char
pad s c target with (padding s target)
pad s c (length s + pad) | Pad pad = replicate pad c ++ s
pad (ys ++ x :: xs) c (length ys) | Nop {ys} = ys ++ x :: xs
namespace MorePad
Pad : (s : List Char) -> (c : Char) -> (target : Nat) -> Type
Pad s c target with (padding s target)
Pad s c ((length s) + pad) | (Pad pad) = let ps = replicate pad c in Interleaving ps s (ps ++ s)
Pad (ys ++ (x :: xs)) c (length ys) | Nop = Interleaving Nil (ys ++ (x :: xs)) (ys ++ (x :: xs))
noPad : (s : List Char) -> Interleaving Nil s s
noPad [] = Empty
noPad (x :: xs) = RightAdd x (noPad xs)
addPadd : (pad : List Char) -> (s : List Char) -> Interleaving pad s (pad ++ s)
addPadd [] s = noPad s
addPadd (x :: xs) s = LeftAdd x (addPadd xs s)
pad : (s : List Char) -> (c : Char) -> (target : Nat) -> Pad s c target
pad s c target with (padding s target)
pad s c ((length s) + pad) | (Pad pad) = let ps = replicate pad c in addPadd ps s
pad (ys ++ (x :: xs)) c (length ys) | Nop = noPad (ys ++ (x::xs))
|
module Parser.Rule.Package
import public Parser.Lexer.Package
import Data.List
import Data.List1
import Core.Name.Namespace
%default total
public export
Rule : Type -> Type
Rule = Grammar () Token True
public export
EmptyRule : Type -> Type
EmptyRule = Grammar () Token False
export
equals : Rule ()
equals = terminal "Expected equals" $
\case
Equals => Just ()
_ => Nothing
export
lte : Rule ()
lte = terminal "Expected <=" $
\case
LTE => Just ()
_ => Nothing
export
gte : Rule ()
gte = terminal "Expected >=" $
\case
GTE => Just ()
_ => Nothing
export
lt : Rule ()
lt = terminal "Expected <=" $
\case
LT => Just ()
_ => Nothing
export
gt : Rule ()
gt = terminal "Expected >=" $
\case
GT => Just ()
_ => Nothing
export
eqop : Rule ()
eqop = terminal "Expected ==" $
\case
EqOp => Just ()
_ => Nothing
export
andop : Rule ()
andop = terminal "Expected &&" $
\case
AndOp => Just ()
_ => Nothing
export
eoi : Rule ()
eoi = terminal "Expected end of input" $
\case
EndOfInput => Just ()
_ => Nothing
export
exactProperty : String -> Rule String
exactProperty p = terminal ("Expected property " ++ p) $
\case
DotSepIdent Nothing p' =>
if p == p' then Just p else Nothing
_ => Nothing
export
stringLit : Rule String
stringLit = terminal "Expected string" $
\case
StringLit str => Just str
_ => Nothing
export
integerLit : Rule Integer
integerLit = terminal "Expected integer" $
\case
IntegerLit i => Just i
_ => Nothing
export
namespacedIdent : Rule (Maybe Namespace, String)
namespacedIdent = terminal "Expected namespaced identifier" $
\case
DotSepIdent ns n => Just (ns, n)
_ => Nothing
export
moduleIdent : Rule ModuleIdent
moduleIdent = terminal "Expected module identifier" $
\case
DotSepIdent ns m =>
Just $ nsAsModuleIdent $
mkNestedNamespace ns m
_ => Nothing
export
packageName : Rule String
packageName = terminal "Expected package name" $
\case
DotSepIdent Nothing str =>
if isIdent AllowDashes str
then Just str
else Nothing
_ => Nothing
export
dot' : Rule ()
dot' = terminal "Expected dot" $
\case
Dot => Just ()
_ => Nothing
sep' : Rule ()
sep' = terminal "Expected separator" $
\case
Separator => Just ()
_ => Nothing
export
sep : Rule t -> Rule (List t)
sep rule = forget <$> sepBy1 sep' rule
|
Recipe: Easter Lamb: a different Raffaello-Strawberry Cake – Recipes. Simply delicious.
Easter is this week! It’s not easy to find visually pleasing and tasty food that has an Easter feel to it, so we decided to take a classic and delicious Raffaello-Strawberry Cake and transform it into a cute Easter lamb. ☺ If you’re planning not to concentrate on the Easter Bunny and Easter Eggs theme, but on the original theme here is an easy recipe for something totally yummy: have fun with this Raffaello delight.
Outside of Easter, the Raffaello-Strawberry Cake in its original form is easy to make and remains just as delicious: a wonderfully creamy dessert and an impressive cake for on the coffee table.
Separate the eggs and beat the egg whites with the salt to stiff peaks. In a separate bowl beat together the egg yolks and ½ cup of the sugar until foamy. With a spoon, carefully fold the egg whites into the egg yolk foam. Finally, stir in the flour, cornstarch and baking powder, a bit at a time.
Put 14 of the Raffaello balls aside for the decoration and cut the rest of the balls into small pieces. Wash the strawberries and set about 10 of them aside also for the decoration. Cut the rest of the strawberries into small pieces. Now beat 1 ¼ cup of the whipping cream together with the vanilla sugar and 3 tsp. granulated sugar until firm peaks form. Carefully mix in the Raffaello and strawberry piece and your filling is ready.
Spread the Raffaello – Strawberry Filling onto one of the cake layers and carefully place the other layer on top. Whip the remaining 1 ¼ cup of whipping cream to firm peaks and cover the cake with it. Roast the grated coconut in a non-stick pan on high heat for about 2 minutes, stirring continuously so they don’t get to brown. Sprinkle the coconut evenly over the whole cake. Place 3 Raffaello balls in the middle of the cake and place the rest evenly around the top edge. Cut the strawberries in half and lay them in between the Raffaello balls.
For the Easter Lamb, do the exact same as for the normal cake, just without putting the strawberries on top of the cake. Instead, cover the whole top of the cake with the Raffaello balls. Create the head and ears of the lamb with the marzipan. Have a look at our picture to see the shape of the head and ears and it should be pretty easy to make. Make the eyes with the coffee or chocolate beans and with the end of a tea spoon make the nostril indents. Now just place the head carefully on the cake and voilà: the cute Easter Lamb is ready. For the final touch, cut the strawberries in half of lengthwise in slices and place them along the bottom edge all the way around the cake. Now your lamb is sitting on a lovely strawberry field. |
\section{Conclusions}
This paper presents an end-to-end method for automatic, monocular 3D dog reconstruction. This is achieved using only weak 2D supervision, provided by the StanfordExtra dataset which has been introduced in this chapter. Further, it has been shown that a more detailed shape prior can be learned by tuning a gaussian mixture during model training and this leads to improved reconstructions. In addition, the WLDO method improves over competitive baselines, even when they are given access to ground truth data at test time.
Future work should involve tackling some failure cases of our system, for example handling multiple overlapping dogs or dealing with heavy motion blur. Other areas for research include extending the EM formulation introduced here to handle video input to take advantage of multi-view shape constraints. Finally, an interesting direction may be to transfer knowledge accumulated through training on StanfordExtra dogs to enable accurate 3D shape reconstruction for other species.
% \input{Chapter5/FigTex/fig_qualresults_sup.tex}
\input{Chapter5/FigTex/fig_qualresults_se_1.tex}
\input{Chapter5/FigTex/fig_qualresults_se_2.tex}
\input{Chapter5/FigTex/fig_qualresults_se_3.tex}
\input{Chapter5/FigTex/fig_qualresults_ani.tex} |
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details
Class(BarrierScratchUnparserProg, CScratchUnparserProg, rec(
barrier_cmd := (self,o,i,is) >> Print(Blanks(i), self.opts.barrierCMD(self.opts), self.pinfix(o.args, ", "), ";\n"),
nop_cmd := (self,o,i,is) >> Print(""),
register := (self,o,i,is) >> Print(Blanks(i), "if(count == 0) ", self.opts.register(self.opts), self.pinfix(o.args, ", "), ";\n"),
initialization := (self, o, i, is) >> Print(Blanks(i), self.opts.initialization(self.opts), self.pinfix(o.args, ", "), ";\n"),
par_exec := (self,o,i,is) >> Print(Blanks(i), "parallel((void*)&sub_cpu) \n",
Blanks(i), "{\n", self(o.cmds[1],i+is,is),
Blanks(i),"}\n"),
));
|
[STATEMENT]
lemma ZN_sum [transfer_rule]:
"bi_unique A \<Longrightarrow> ((A ===> ZN) ===> rel_set A ===> ZN) sum sum"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. bi_unique A \<Longrightarrow> ((A ===> ZN) ===> rel_set A ===> ZN) sum sum
[PROOF STEP]
apply (intro rel_funI)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>x y xa ya. \<lbrakk>bi_unique A; (A ===> ZN) x y; rel_set A xa ya\<rbrakk> \<Longrightarrow> ZN (sum x xa) (sum y ya)
[PROOF STEP]
apply (erule (1) bi_unique_rel_set_lemma)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>x y xa ya f. \<lbrakk>(A ===> ZN) x y; rel_set A xa ya; ya = f ` xa; inj_on f xa; \<forall>x\<in>xa. A x (f x)\<rbrakk> \<Longrightarrow> ZN (sum x xa) (sum y ya)
[PROOF STEP]
apply (simp add: sum.reindex int_sum ZN_def rel_fun_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>x y xa ya f. \<lbrakk>\<forall>xa ya. A xa ya \<longrightarrow> x xa = int (y ya); rel_set A xa (f ` xa); ya = f ` xa; inj_on f xa; \<forall>x\<in>xa. A x (f x)\<rbrakk> \<Longrightarrow> sum x xa = (\<Sum>x\<in>xa. int (y (f x)))
[PROOF STEP]
apply (rule sum.cong)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>x y xa ya f. \<lbrakk>\<forall>xa ya. A xa ya \<longrightarrow> x xa = int (y ya); rel_set A xa (f ` xa); ya = f ` xa; inj_on f xa; \<forall>x\<in>xa. A x (f x)\<rbrakk> \<Longrightarrow> xa = xa
2. \<And>x y xa ya f xb. \<lbrakk>\<forall>xa ya. A xa ya \<longrightarrow> x xa = int (y ya); rel_set A xa (f ` xa); ya = f ` xa; inj_on f xa; \<forall>x\<in>xa. A x (f x); xb \<in> xa\<rbrakk> \<Longrightarrow> x xb = int (y (f xb))
[PROOF STEP]
apply simp_all
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
module Effekt.IteratedStaged
import Effekt.CpsStaged
import Effekt.IteratedUnstaged
STM : List Type -> Type -> Type
STM [] a = Exp a
STM (r :: rs) a = (Exp a -> STM rs r) -> STM rs r
pure : Exp a -> STM rs a
pure{ rs= []} a = a
pure{ rs= r :: rs} a = \k => k a
push : (Exp a -> STM (r :: rs) b) -> (Exp b -> STM rs r) -> (Exp a -> STM rs r)
push f k = \a => f a k
bind : STM rs a -> (Exp a -> STM rs b) -> STM rs b
bind{ rs= []} m f = f m
bind{ rs= r :: rs} m f = \k => m (push f k)
(>>=) : STM rs a -> (Exp a -> STM rs b) -> STM rs b
(>>=) = bind
lift : STM rs a -> STM (r :: rs) a
lift = bind
shift0 : ((Exp a -> STM rs r) -> STM rs r) -> STM (r :: rs) a
shift0 = id
runIn0 : STM (r :: rs) a -> (Exp a -> STM rs r) -> STM rs r
runIn0 = id
reset0 : STM (a :: rs) a -> STM rs a
reset0 m = runIn0 m pure
mutual
reify : STM rs a -> Exp (Stm rs a)
reify {rs = []} m = m
reify {rs = (q :: qs)} m =
(Lam $ \ k => reify (m (\a => reflect {a = q} {rs = qs} (App k a))))
reflect : Exp (Stm rs a) -> STM rs a
reflect {rs = []} m = m
reflect {rs = (q :: qs)} m =
\k => reflect (App m ((Lam $ \ a => reify (k a))))
emit : Exp Int -> STM (List Int :: rs) ()
emit {rs} a = shift0 (\c => do
as <- c Uni
pure {rs} (Con a as))
emitTwice : Exp Int -> STM (List Int :: List Int :: rs) ()
emitTwice {rs} a =
bind {rs=List Int::List Int::rs} (emit {rs=List Int::rs} a) (\u =>
lift {r=List Int} {rs=List Int::rs} (emit a))
export
reifiedEmitTwice : Exp (Int -> Stm [List Int,List Int] ())
reifiedEmitTwice = Lam (\x => reify {rs=[List Int,List Int]} (emitTwice x))
export
reifiedEmitTwice' : Exp (Int -> Stm [List Int,List Int,()] ())
reifiedEmitTwice' = Lam (\x => reify {rs=[List Int,List Int,()]} (emitTwice {rs=[()]} x))
|
(* Author: Alexander Maletzky *)
section \<open>Preliminaries\<close>
theory Prelims
imports Polynomials.Utils Groebner_Bases.General
begin
subsection \<open>Lists\<close>
subsubsection \<open>Sequences of Lists\<close>
lemma list_seq_length_mono:
fixes seq :: "nat \<Rightarrow> 'a list"
assumes "\<And>i. (\<exists>x. seq (Suc i) = x # seq i)" and "i < j"
shows "length (seq i) < length (seq j)"
proof -
from assms(2) obtain k where "j = Suc (i + k)" using less_iff_Suc_add by auto
show ?thesis unfolding \<open>j = Suc (i + k)\<close>
proof (induct k)
case 0
from assms(1) obtain x where eq: "seq (Suc i) = x # seq i" ..
show ?case by (simp add: eq)
next
case (Suc k)
from assms(1) obtain x where "seq (Suc (i + Suc k)) = x # seq (i + Suc k)" ..
hence eq: "seq (Suc (Suc (i + k))) = x # seq (Suc (i + k))" by simp
note Suc
also have "length (seq (Suc (i + k))) < length (seq (Suc (i + Suc k)))" by (simp add: eq)
finally show ?case .
qed
qed
corollary list_seq_length_mono_weak:
fixes seq :: "nat \<Rightarrow> 'a list"
assumes "\<And>i. (\<exists>x. seq (Suc i) = x # seq i)" and "i \<le> j"
shows "length (seq i) \<le> length (seq j)"
proof (cases "i = j")
case True
thus ?thesis by simp
next
case False
with assms(2) have "i < j" by simp
with assms(1) have "length (seq i) < length (seq j)" by (rule list_seq_length_mono)
thus ?thesis by simp
qed
lemma list_seq_indexE_length:
fixes seq :: "nat \<Rightarrow> 'a list"
assumes "\<And>i. (\<exists>x. seq (Suc i) = x # seq i)"
obtains j where "i < length (seq j)"
proof (induct i arbitrary: thesis)
case 0
have "0 \<le> length (seq 0)" by simp
also from assms lessI have "... < length (seq (Suc 0))" by (rule list_seq_length_mono)
finally show ?case by (rule 0)
next
case (Suc i)
obtain j where "i < length (seq j)" by (rule Suc(1))
hence "Suc i \<le> length (seq j)" by simp
also from assms lessI have "... < length (seq (Suc j))" by (rule list_seq_length_mono)
finally show ?case by (rule Suc(2))
qed
lemma list_seq_nth:
fixes seq :: "nat \<Rightarrow> 'a list"
assumes "\<And>i. (\<exists>x. seq (Suc i) = x # seq i)" and "i < length (seq j)" and "j \<le> k"
shows "rev (seq k) ! i = rev (seq j) ! i"
proof -
from assms(3) obtain l where "k = j + l" using nat_le_iff_add by blast
show ?thesis unfolding \<open>k = j + l\<close>
proof (induct l)
case 0
show ?case by simp
next
case (Suc l)
note assms(2)
also from assms(1) le_add1 have "length (seq j) \<le> length (seq (j + l))"
by (rule list_seq_length_mono_weak)
finally have i: "i < length (seq (j + l))" .
from assms(1) obtain x where "seq (Suc (j + l)) = x # seq (j + l)" ..
thus ?case by (simp add: nth_append i Suc)
qed
qed
corollary list_seq_nth':
fixes seq :: "nat \<Rightarrow> 'a list"
assumes "\<And>i. (\<exists>x. seq (Suc i) = x # seq i)" and "i < length (seq j)" and "i < length (seq k)"
shows "rev (seq k) ! i = rev (seq j) ! i"
proof (rule linorder_cases)
assume "j < k"
hence "j \<le> k" by simp
with assms(1, 2) show ?thesis by (rule list_seq_nth)
next
assume "k < j"
hence "k \<le> j" by simp
with assms(1, 3) have "rev (seq j) ! i = rev (seq k) ! i" by (rule list_seq_nth)
thus ?thesis by (rule HOL.sym)
next
assume "j = k"
thus ?thesis by simp
qed
subsubsection \<open>@{const filter}\<close>
lemma filter_merge_wrt_1:
assumes "\<And>y. y \<in> set ys \<Longrightarrow> P y \<Longrightarrow> False"
shows "filter P (merge_wrt rel xs ys) = filter P xs"
using assms
proof (induct rel xs ys rule: merge_wrt.induct)
case (1 rel xs)
show ?case by simp
next
case (2 rel y ys)
hence "P y \<Longrightarrow> False" and "\<And>z. z \<in> set ys \<Longrightarrow> P z \<Longrightarrow> False" by auto
thus ?case by (auto simp: filter_empty_conv)
next
case (3 rel x xs y ys)
hence "\<not> P y" and x: "\<And>z. z \<in> set ys \<Longrightarrow> P z \<Longrightarrow> False" by auto
have a: "filter P (merge_wrt rel xs ys) = filter P xs" if "x = y" using that x by (rule 3(1))
have b: "filter P (merge_wrt rel xs (y # ys)) = filter P xs" if "x \<noteq> y" and "rel x y"
using that 3(4) by (rule 3(2))
have c: "filter P (merge_wrt rel (x # xs) ys) = filter P (x # xs)" if "x \<noteq> y" and "\<not> rel x y"
using that x by (rule 3(3))
show ?case by (simp add: a b c \<open>\<not> P y\<close>)
qed
lemma filter_merge_wrt_2:
assumes "\<And>x. x \<in> set xs \<Longrightarrow> P x \<Longrightarrow> False"
shows "filter P (merge_wrt rel xs ys) = filter P ys"
using assms
proof (induct rel xs ys rule: merge_wrt.induct)
case (1 rel xs)
thus ?case by (auto simp: filter_empty_conv)
next
case (2 rel y ys)
show ?case by simp
next
case (3 rel x xs y ys)
hence "\<not> P x" and x: "\<And>z. z \<in> set xs \<Longrightarrow> P z \<Longrightarrow> False" by auto
have a: "filter P (merge_wrt rel xs ys) = filter P ys" if "x = y" using that x by (rule 3(1))
have b: "filter P (merge_wrt rel xs (y # ys)) = filter P (y # ys)" if "x \<noteq> y" and "rel x y"
using that x by (rule 3(2))
have c: "filter P (merge_wrt rel (x # xs) ys) = filter P ys" if "x \<noteq> y" and "\<not> rel x y"
using that 3(4) by (rule 3(3))
show ?case by (simp add: a b c \<open>\<not> P x\<close>)
qed
lemma length_filter_le_1:
assumes "length (filter P xs) \<le> 1" and "i < length xs" and "j < length xs"
and "P (xs ! i)" and "P (xs ! j)"
shows "i = j"
proof -
have *: thesis if "a < b" and "b < length xs"
and "\<And>as bs cs. as @ ((xs ! a) # (bs @ ((xs ! b) # cs))) = xs \<Longrightarrow> thesis" for a b thesis
proof (rule that(3))
from that(1, 2) have 1: "a < length xs" by simp
with that(1, 2) have 2: "b - Suc a < length (drop (Suc a) xs)" by simp
from that(1) \<open>a < length xs\<close> have eq: "xs ! b = drop (Suc a) xs ! (b - Suc a)" by simp
show "(take a xs) @ ((xs ! a) # ((take (b - Suc a) (drop (Suc a) xs)) @ ((xs ! b) #
drop (Suc (b - Suc a)) (drop (Suc a) xs)))) = xs"
by (simp only: eq id_take_nth_drop[OF 1, symmetric] id_take_nth_drop[OF 2, symmetric])
qed
show ?thesis
proof (rule linorder_cases)
assume "i < j"
then obtain as bs cs where "as @ ((xs ! i) # (bs @ ((xs ! j) # cs))) = xs"
using assms(3) by (rule *)
hence "filter P xs = filter P (as @ ((xs ! i) # (bs @ ((xs ! j) # cs))))" by simp
also from assms(4, 5) have "... = (filter P as) @ ((xs ! i) # ((filter P bs) @ ((xs ! j) # (filter P cs))))"
by simp
finally have "\<not> length (filter P xs) \<le> 1" by simp
thus ?thesis using assms(1) ..
next
assume "j < i"
then obtain as bs cs where "as @ ((xs ! j) # (bs @ ((xs ! i) # cs))) = xs"
using assms(2) by (rule *)
hence "filter P xs = filter P (as @ ((xs ! j) # (bs @ ((xs ! i) # cs))))" by simp
also from assms(4, 5) have "... = (filter P as) @ ((xs ! j) # ((filter P bs) @ ((xs ! i) # (filter P cs))))"
by simp
finally have "\<not> length (filter P xs) \<le> 1" by simp
thus ?thesis using assms(1) ..
qed
qed
lemma length_filter_eq [simp]: "length (filter ((=) x) xs) = count_list xs x"
by (induct xs, simp_all)
subsubsection \<open>@{const drop}\<close>
lemma nth_in_set_dropI:
assumes "j \<le> i" and "i < length xs"
shows "xs ! i \<in> set (drop j xs)"
using assms
proof (induct xs arbitrary: i j)
case Nil
thus ?case by simp
next
case (Cons x xs)
show ?case
proof (cases j)
case 0
with Cons(3) show ?thesis by (metis drop0 nth_mem)
next
case (Suc j0)
with Cons(2) Suc_le_D obtain i0 where i: "i = Suc i0" by blast
with Cons(2) have "j0 \<le> i0" by (simp add: \<open>j = Suc j0\<close>)
moreover from Cons(3) have "i0 < length xs" by (simp add: i)
ultimately have "xs ! i0 \<in> set (drop j0 xs)" by (rule Cons(1))
thus ?thesis by (simp add: i \<open>j = Suc j0\<close>)
qed
qed
subsubsection \<open>@{const count_list}\<close>
lemma count_list_append [simp]: "count_list (xs @ ys) a = count_list xs a + count_list ys a"
by (induct xs, simp_all)
lemma count_list_upt [simp]: "count_list [a..<b] x = (if a \<le> x \<and> x < b then 1 else 0)"
proof (cases "a \<le> b")
case True
then obtain k where "b = a + k" using le_Suc_ex by blast
show ?thesis unfolding \<open>b = a + k\<close> by (induct k, simp_all)
next
case False
thus ?thesis by simp
qed
subsubsection \<open>@{const sorted_wrt}\<close>
lemma sorted_wrt_upt_iff: "sorted_wrt rel [a..<b] \<longleftrightarrow> (\<forall>i j. a \<le> i \<longrightarrow> i < j \<longrightarrow> j < b \<longrightarrow> rel i j)"
proof (cases "a \<le> b")
case True
then obtain k where "b = a + k" using le_Suc_ex by blast
show ?thesis unfolding \<open>b = a + k\<close>
proof (induct k)
case 0
show ?case by simp
next
case (Suc k)
show ?case
proof (simp add: sorted_wrt_append Suc, intro iffI allI ballI impI conjI)
fix i j
assume "(\<forall>i\<ge>a. \<forall>j>i. j < a + k \<longrightarrow> rel i j) \<and> (\<forall>x\<in>{a..<a + k}. rel x (a + k))"
hence 1: "\<And>i' j'. a \<le> i' \<Longrightarrow> i' < j' \<Longrightarrow> j' < a + k \<Longrightarrow> rel i' j'"
and 2: "\<And>x. a \<le> x \<Longrightarrow> x < a + k \<Longrightarrow> rel x (a + k)" by simp_all
assume "a \<le> i" and "i < j"
assume "j < Suc (a + k)"
hence "j < a + k \<or> j = a + k" by auto
thus "rel i j"
proof
assume "j < a + k"
with \<open>a \<le> i\<close> \<open>i < j\<close> show ?thesis by (rule 1)
next
assume "j = a + k"
from \<open>a \<le> i\<close> \<open>i < j\<close> show ?thesis unfolding \<open>j = a + k\<close> by (rule 2)
qed
next
fix i j
assume "\<forall>i\<ge>a. \<forall>j>i. j < Suc (a + k) \<longrightarrow> rel i j" and "a \<le> i" and "i < j" and "j < a + k"
thus "rel i j" by simp
next
fix x
assume "x \<in> {a..<a + k}"
hence "a \<le> x" and "x < a + k" by simp_all
moreover assume "\<forall>i\<ge>a. \<forall>j>i. j < Suc (a + k) \<longrightarrow> rel i j"
ultimately show "rel x (a + k)" by simp
qed
qed
next
case False
thus ?thesis by simp
qed
subsubsection \<open>@{const insort_wrt} and @{const merge_wrt}\<close>
lemma map_insort_wrt:
assumes "\<And>x. x \<in> set xs \<Longrightarrow> r2 (f y) (f x) \<longleftrightarrow> r1 y x"
shows "map f (insort_wrt r1 y xs) = insort_wrt r2 (f y) (map f xs)"
using assms
proof (induct xs)
case Nil
show ?case by simp
next
case (Cons x xs)
have "x \<in> set (x # xs)" by simp
hence "r2 (f y) (f x) = r1 y x" by (rule Cons(2))
moreover have "map f (insort_wrt r1 y xs) = insort_wrt r2 (f y) (map f xs)"
proof (rule Cons(1))
fix x'
assume "x' \<in> set xs"
hence "x' \<in> set (x # xs)" by simp
thus "r2 (f y) (f x') = r1 y x'" by (rule Cons(2))
qed
ultimately show ?case by simp
qed
lemma map_merge_wrt:
assumes "f ` set xs \<inter> f ` set ys = {}"
and "\<And>x y. x \<in> set xs \<Longrightarrow> y \<in> set ys \<Longrightarrow> r2 (f x) (f y) \<longleftrightarrow> r1 x y"
shows "map f (merge_wrt r1 xs ys) = merge_wrt r2 (map f xs) (map f ys)"
using assms
proof (induct r1 xs ys rule: merge_wrt.induct)
case (1 uu xs)
show ?case by simp
next
case (2 r1 v va)
show ?case by simp
next
case (3 r1 x xs y ys)
from 3(4) have "f x \<noteq> f y" and 1: "f ` set xs \<inter> f ` set (y # ys) = {}"
and 2: "f ` set (x # xs) \<inter> f ` set ys = {}" by auto
from this(1) have "x \<noteq> y" by auto
have eq2: "map f (merge_wrt r1 xs (y # ys)) = merge_wrt r2 (map f xs) (map f (y # ys))"
if "r1 x y" using \<open>x \<noteq> y\<close> that 1
proof (rule 3(2))
fix a b
assume "a \<in> set xs"
hence "a \<in> set (x # xs)" by simp
moreover assume "b \<in> set (y # ys)"
ultimately show "r2 (f a) (f b) \<longleftrightarrow> r1 a b" by (rule 3(5))
qed
have eq3: "map f (merge_wrt r1 (x # xs) ys) = merge_wrt r2 (map f (x # xs)) (map f ys)"
if "\<not> r1 x y" using \<open>x \<noteq> y\<close> that 2
proof (rule 3(3))
fix a b
assume "a \<in> set (x # xs)"
assume "b \<in> set ys"
hence "b \<in> set (y # ys)" by simp
with \<open>a \<in> set (x # xs)\<close> show "r2 (f a) (f b) \<longleftrightarrow> r1 a b" by (rule 3(5))
qed
have eq4: "r2 (f x) (f y) \<longleftrightarrow> r1 x y" by (rule 3(5), simp_all)
show ?case by (simp add: eq2 eq3 eq4 \<open>f x \<noteq> f y\<close> \<open>x \<noteq> y\<close>)
qed
subsection \<open>Recursive Functions\<close>
locale recursive =
fixes h' :: "'b \<Rightarrow> 'b"
fixes b :: 'b
assumes b_fixpoint: "h' b = b"
begin
context
fixes Q :: "'a \<Rightarrow> bool"
fixes g :: "'a \<Rightarrow> 'b"
fixes h :: "'a \<Rightarrow> 'a"
begin
function (domintros) recfun_aux :: "'a \<Rightarrow> 'b" where
"recfun_aux x = (if Q x then g x else h' (recfun_aux (h x)))"
by pat_completeness auto
lemmas [induct del] = recfun_aux.pinduct
definition dom :: "'a \<Rightarrow> bool"
where "dom x \<longleftrightarrow> (\<exists>k. Q ((h ^^ k) x))"
lemma domI:
assumes "\<not> Q x \<Longrightarrow> dom (h x)"
shows "dom x"
proof (cases "Q x")
case True
hence "Q ((h ^^ 0) x)" by simp
thus ?thesis unfolding dom_def ..
next
case False
hence "dom (h x)" by (rule assms)
then obtain k where "Q ((h ^^ k) (h x))" unfolding dom_def ..
hence "Q ((h ^^ (Suc k)) x)" by (simp add: funpow_swap1)
thus ?thesis unfolding dom_def ..
qed
lemma domD:
assumes "dom x" and "\<not> Q x"
shows "dom (h x)"
proof -
from assms(1) obtain k where *: "Q ((h ^^ k) x)" unfolding dom_def ..
with assms(2) have "k \<noteq> 0" using funpow_0 by fastforce
then obtain m where "k = Suc m" using nat.exhaust by blast
with * have "Q ((h ^^ m) (h x))" by (simp add: funpow_swap1)
thus ?thesis unfolding dom_def ..
qed
lemma recfun_aux_domI:
assumes "dom x"
shows "recfun_aux_dom x"
proof -
from assms obtain k where "Q ((h ^^ k) x)" unfolding dom_def ..
thus ?thesis
proof (induct k arbitrary: x)
case 0
hence "Q x" by simp
with recfun_aux.domintros show ?case by blast
next
case (Suc k)
from Suc(2) have "Q ((h ^^ k) (h x))" by (simp add: funpow_swap1)
hence "recfun_aux_dom (h x)" by (rule Suc(1))
with recfun_aux.domintros show ?case by blast
qed
qed
lemma recfun_aux_domD:
assumes "recfun_aux_dom x"
shows "dom x"
using assms
proof (induct x rule: recfun_aux.pinduct)
case (1 x)
show ?case
proof (cases "Q x")
case True
with domI show ?thesis by blast
next
case False
hence "dom (h x)" by (rule 1(2))
thus ?thesis using domI by blast
qed
qed
corollary recfun_aux_dom_alt: "recfun_aux_dom = dom"
by (auto dest: recfun_aux_domI recfun_aux_domD)
definition "fun" :: "'a \<Rightarrow> 'b"
where "fun x = (if recfun_aux_dom x then recfun_aux x else b)"
lemma simps: "fun x = (if Q x then g x else h' (fun (h x)))"
proof (cases "dom x")
case True
hence dom: "recfun_aux_dom x" by (rule recfun_aux_domI)
show ?thesis
proof (cases "Q x")
case True
with dom show ?thesis by (simp add: fun_def recfun_aux.psimps)
next
case False
have "recfun_aux_dom (h x)" by (rule recfun_aux_domI, rule domD, fact True, fact False)
thus ?thesis by (simp add: fun_def dom False recfun_aux.psimps)
qed
next
case False
moreover have "\<not> Q x"
proof
assume "Q x"
hence "dom x" using domI by blast
with False show False ..
qed
moreover have "\<not> dom (h x)"
proof
assume "dom (h x)"
hence "dom x" using domI by blast
with False show False ..
qed
ultimately show ?thesis by (simp add: recfun_aux_dom_alt fun_def b_fixpoint split del: if_split)
qed
lemma eq_fixpointI: "\<not> dom x \<Longrightarrow> fun x = b"
by (simp add: fun_def recfun_aux_dom_alt)
lemma pinduct: "dom x \<Longrightarrow> (\<And>x. dom x \<Longrightarrow> (\<not> Q x \<Longrightarrow> P (h x)) \<Longrightarrow> P x) \<Longrightarrow> P x"
unfolding recfun_aux_dom_alt[symmetric] by (fact recfun_aux.pinduct)
end
end (* recursive *)
interpretation tailrec: recursive "\<lambda>x. x" undefined
by (standard, fact refl)
subsection \<open>Binary Relations\<close>
lemma almost_full_on_Int:
assumes "almost_full_on P1 A1" and "almost_full_on P2 A2"
shows "almost_full_on (\<lambda>x y. P1 x y \<and> P2 x y) (A1 \<inter> A2)" (is "almost_full_on ?P ?A")
proof (rule almost_full_onI)
fix f :: "nat \<Rightarrow> 'a"
assume a: "\<forall>i. f i \<in> ?A"
define g where "g = (\<lambda>i. (f i, f i))"
from assms have "almost_full_on (prod_le P1 P2) (A1 \<times> A2)" by (rule almost_full_on_Sigma)
moreover from a have "\<And>i. g i \<in> A1 \<times> A2" by (simp add: g_def)
ultimately obtain i j where "i < j" and "prod_le P1 P2 (g i) (g j)" by (rule almost_full_onD)
from this(2) have "?P (f i) (f j)" by (simp add: g_def prod_le_def)
with \<open>i < j\<close> show "good ?P f" by (rule goodI)
qed
corollary almost_full_on_same:
assumes "almost_full_on P1 A" and "almost_full_on P2 A"
shows "almost_full_on (\<lambda>x y. P1 x y \<and> P2 x y) A"
proof -
from assms have "almost_full_on (\<lambda>x y. P1 x y \<and> P2 x y) (A \<inter> A)" by (rule almost_full_on_Int)
thus ?thesis by simp
qed
context ord
begin
definition is_le_rel :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
where "is_le_rel rel = (rel = (=) \<or> rel = (\<le>) \<or> rel = (<))"
lemma is_le_relI [simp]: "is_le_rel (=)" "is_le_rel (\<le>)" "is_le_rel (<)"
by (simp_all add: is_le_rel_def)
lemma is_le_relE:
assumes "is_le_rel rel"
obtains "rel = (=)" | "rel = (\<le>)" | "rel = (<)"
using assms unfolding is_le_rel_def by blast
end (* ord *)
context preorder
begin
lemma is_le_rel_le:
assumes "is_le_rel rel"
shows "rel x y \<Longrightarrow> x \<le> y"
using assms by (rule is_le_relE, auto dest: less_imp_le)
lemma is_le_rel_trans:
assumes "is_le_rel rel"
shows "rel x y \<Longrightarrow> rel y z \<Longrightarrow> rel x z"
using assms by (rule is_le_relE, auto dest: order_trans less_trans)
lemma is_le_rel_trans_le_left:
assumes "is_le_rel rel"
shows "x \<le> y \<Longrightarrow> rel y z \<Longrightarrow> x \<le> z"
using assms by (rule is_le_relE, auto dest: order_trans le_less_trans less_imp_le)
lemma is_le_rel_trans_le_right:
assumes "is_le_rel rel"
shows "rel x y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
using assms by (rule is_le_relE, auto dest: order_trans less_le_trans less_imp_le)
lemma is_le_rel_trans_less_left:
assumes "is_le_rel rel"
shows "x < y \<Longrightarrow> rel y z \<Longrightarrow> x < z"
using assms by (rule is_le_relE, auto dest: less_le_trans less_imp_le)
lemma is_le_rel_trans_less_right:
assumes "is_le_rel rel"
shows "rel x y \<Longrightarrow> y < z \<Longrightarrow> x < z"
using assms by (rule is_le_relE, auto dest: le_less_trans less_imp_le)
end (* preorder *)
context order
begin
lemma is_le_rel_distinct:
assumes "is_le_rel rel"
shows "rel x y \<Longrightarrow> x \<noteq> y \<Longrightarrow> x < y"
using assms by (rule is_le_relE, auto)
lemma is_le_rel_antisym:
assumes "is_le_rel rel"
shows "rel x y \<Longrightarrow> rel y x \<Longrightarrow> x = y"
using assms by (rule is_le_relE, auto)
end (* order *)
end (* theory *)
|
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.Parser.Term
import Lean.Parser.Do
namespace Lean
namespace Parser
/-- Syntax quotation for terms. -/
@[builtin_term_parser] def Term.quot := leading_parser
"`(" >> withoutPosition (incQuotDepth termParser) >> ")"
@[builtin_term_parser] def Term.precheckedQuot := leading_parser
"`" >> Term.quot
namespace Command
/--
Syntax quotation for (sequences of) commands.
The identical syntax for term quotations takes priority,
so ambiguous quotations like `` `($x $y) `` will be parsed as an application,
not two commands. Use `` `($x:command $y:command) `` instead.
Multiple commands will be put in a `` `null `` node,
but a single command will not (so that you can directly
match against a quotation in a command kind's elaborator). -/
@[builtin_term_parser low] def quot := leading_parser
"`(" >> withoutPosition (incQuotDepth (many1Unbox commandParser)) >> ")"
/-
A mutual block may be broken in different cliques,
we identify them using an `ident` (an element of the clique).
We provide two kinds of hints to the termination checker:
1- A wellfounded relation (`p` is `termParser`)
2- A tactic for proving the recursive applications are "decreasing" (`p` is `tacticSeq`)
-/
def terminationHintMany (p : Parser) := leading_parser
atomic (lookahead (ident >> " => ")) >>
many1Indent (group (ppLine >> ident >> " => " >> p >> optional ";"))
def terminationHint1 (p : Parser) := leading_parser p
def terminationHint (p : Parser) := terminationHintMany p <|> terminationHint1 p
def terminationByCore := leading_parser
"termination_by' " >> terminationHint termParser
def decreasingBy := leading_parser
"decreasing_by " >> terminationHint Tactic.tacticSeq
def terminationByElement := leading_parser
ppLine >> (ident <|> Term.hole) >> many (ident <|> Term.hole) >>
" => " >> termParser >> optional ";"
def terminationBy := leading_parser
ppLine >> "termination_by " >> many1Indent terminationByElement
def terminationSuffix :=
optional (terminationBy <|> terminationByCore) >> optional decreasingBy
@[builtin_command_parser]
def moduleDoc := leading_parser ppDedent <|
"/-!" >> commentBody >> ppLine
def namedPrio := leading_parser
atomic ("(" >> nonReservedSymbol "priority") >> " := " >> withoutPosition priorityParser >> ")"
def optNamedPrio := optional (ppSpace >> namedPrio)
def «private» := leading_parser "private "
def «protected» := leading_parser "protected "
def visibility := «private» <|> «protected»
def «noncomputable» := leading_parser "noncomputable "
def «unsafe» := leading_parser "unsafe "
def «partial» := leading_parser "partial "
def «nonrec» := leading_parser "nonrec "
def declModifiers (inline : Bool) := leading_parser
optional docComment >>
optional (Term.«attributes» >> if inline then skip else ppDedent ppLine) >>
optional visibility >>
optional «noncomputable» >>
optional «unsafe» >>
optional («partial» <|> «nonrec»)
def declId := leading_parser
ident >> optional (".{" >> sepBy1 ident ", " >> "}")
def declSig := leading_parser
many (ppSpace >> (Term.binderIdent <|> Term.bracketedBinder)) >> Term.typeSpec
def optDeclSig := leading_parser
many (ppSpace >> (Term.binderIdent <|> Term.bracketedBinder)) >> Term.optType
def declValSimple := leading_parser
" :=" >> ppHardLineUnlessUngrouped >> termParser >> optional Term.whereDecls
def declValEqns := leading_parser
Term.matchAltsWhereDecls
def whereStructField := leading_parser
Term.letDecl
def whereStructInst := leading_parser
ppIndent ppSpace >> "where" >> sepByIndent (ppGroup whereStructField) "; " (allowTrailingSep := true) >>
optional Term.whereDecls
/-
Remark: we should not use `Term.whereDecls` at `declVal`
because `Term.whereDecls` is defined using `Term.letRecDecl` which may contain attributes.
Issue #753 showns an example that fails to be parsed when we used `Term.whereDecls`.
-/
def declVal :=
withAntiquot (mkAntiquot "declVal" `Lean.Parser.Command.declVal (isPseudoKind := true)) <|
declValSimple <|> declValEqns <|> whereStructInst
def «abbrev» := leading_parser
"abbrev " >> declId >> ppIndent optDeclSig >> declVal >> terminationSuffix
def optDefDeriving :=
optional (atomic ("deriving " >> notSymbol "instance") >> sepBy1 ident ", ")
def «def» := leading_parser
"def " >> declId >> ppIndent optDeclSig >> declVal >> optDefDeriving >> terminationSuffix
def «theorem» := leading_parser
"theorem " >> declId >> ppIndent declSig >> declVal >> terminationSuffix
def «opaque» := leading_parser
"opaque " >> declId >> ppIndent declSig >> optional declValSimple
/- As `declSig` starts with a space, "instance" does not need a trailing space
if we put `ppSpace` in the optional fragments. -/
def «instance» := leading_parser
Term.attrKind >> "instance" >> optNamedPrio >>
optional (ppSpace >> declId) >> ppIndent declSig >> declVal >> terminationSuffix
def «axiom» := leading_parser
"axiom " >> declId >> ppIndent declSig
/- As `declSig` starts with a space, "example" does not need a trailing space. -/
def «example» := leading_parser
"example" >> ppIndent optDeclSig >> declVal
def ctor := leading_parser
atomic (optional docComment >> "\n| ") >>
ppGroup (declModifiers true >> rawIdent >> optDeclSig)
def derivingClasses := sepBy1 (group (ident >> optional (" with " >> Term.structInst))) ", "
def optDeriving := leading_parser
optional (ppLine >> atomic ("deriving " >> notSymbol "instance") >> derivingClasses)
def computedField := leading_parser
declModifiers true >> ident >> " : " >> termParser >> Term.matchAlts
def computedFields := leading_parser
"with" >> manyIndent (ppLine >> ppGroup computedField)
/--
In Lean, every concrete type other than the universes
and every type constructor other than dependent arrows
is an instance of a general family of type constructions known as inductive types.
It is remarkable that it is possible to construct a substantial edifice of mathematics
based on nothing more than the type universes, dependent arrow types, and inductive types;
everything else follows from those.
Intuitively, an inductive type is built up from a specified list of constructor.
For example, `List α` is the list of elements of type `α`, and is defined as follows:
```
inductive List (α : Type u) where
| nil
| cons (head : α) (tail : List α)
```
A list of elements of type `α` is either the empty list, `nil`,
or an element `head : α` followed by a list `tail : List α`.
For more information about [inductive types](https://leanprover.github.io/theorem_proving_in_lean4/inductive_types.html).
-/
def «inductive» := leading_parser
"inductive " >> declId >> optDeclSig >> optional (symbol " :=" <|> " where") >>
many ctor >> optional (ppDedent ppLine >> computedFields) >> optDeriving
def classInductive := leading_parser
atomic (group (symbol "class " >> "inductive ")) >>
declId >> ppIndent optDeclSig >>
optional (symbol " :=" <|> " where") >> many ctor >> optDeriving
def structExplicitBinder := leading_parser
atomic (declModifiers true >> "(") >>
withoutPosition (many1 ident >> ppIndent optDeclSig >>
optional (Term.binderTactic <|> Term.binderDefault)) >> ")"
def structImplicitBinder := leading_parser
atomic (declModifiers true >> "{") >> withoutPosition (many1 ident >> declSig) >> "}"
def structInstBinder := leading_parser
atomic (declModifiers true >> "[") >> withoutPosition (many1 ident >> declSig) >> "]"
def structSimpleBinder := leading_parser
atomic (declModifiers true >> ident) >> optDeclSig >>
optional (Term.binderTactic <|> Term.binderDefault)
def structFields := leading_parser
manyIndent <|
ppLine >> checkColGe >> ppGroup (
structExplicitBinder <|> structImplicitBinder <|>
structInstBinder <|> structSimpleBinder)
def structCtor := leading_parser
atomic (declModifiers true >> ident >> " :: ")
def structureTk := leading_parser
"structure "
def classTk := leading_parser
"class "
def «extends» := leading_parser
" extends " >> sepBy1 termParser ", "
def «structure» := leading_parser
(structureTk <|> classTk) >>
declId >> many (ppSpace >> Term.bracketedBinder) >>
optional «extends» >> Term.optType >>
optional ((symbol " := " <|> " where ") >> optional structCtor >> structFields) >>
optDeriving
@[builtin_command_parser] def declaration := leading_parser
declModifiers false >>
(«abbrev» <|> «def» <|> «theorem» <|> «opaque» <|> «instance» <|> «axiom» <|> «example» <|>
«inductive» <|> classInductive <|> «structure»)
@[builtin_command_parser] def «deriving» := leading_parser
"deriving " >> "instance " >> derivingClasses >> " for " >> sepBy1 ident ", "
@[builtin_command_parser] def noncomputableSection := leading_parser
"noncomputable " >> "section " >> optional ident
@[builtin_command_parser] def «section» := leading_parser
"section " >> optional ident
@[builtin_command_parser] def «namespace» := leading_parser
"namespace " >> ident
@[builtin_command_parser] def «end» := leading_parser
"end " >> optional ident
@[builtin_command_parser] def «variable» := leading_parser
"variable" >> many1 (ppSpace >> Term.bracketedBinder)
@[builtin_command_parser] def «universe» := leading_parser
"universe " >> many1 ident
@[builtin_command_parser] def check := leading_parser
"#check " >> termParser
@[builtin_command_parser] def check_failure := leading_parser
"#check_failure " >> termParser -- Like `#check`, but succeeds only if term does not type check
@[builtin_command_parser] def reduce := leading_parser
"#reduce " >> termParser
@[builtin_command_parser] def eval := leading_parser
"#eval " >> termParser
@[builtin_command_parser] def synth := leading_parser
"#synth " >> termParser
@[builtin_command_parser] def exit := leading_parser
"#exit"
@[builtin_command_parser] def print := leading_parser
"#print " >> (ident <|> strLit)
@[builtin_command_parser] def printAxioms := leading_parser
"#print " >> nonReservedSymbol "axioms " >> ident
@[builtin_command_parser] def «init_quot» := leading_parser
"init_quot"
def optionValue := nonReservedSymbol "true" <|> nonReservedSymbol "false" <|> strLit <|> numLit
@[builtin_command_parser] def «set_option» := leading_parser
"set_option " >> ident >> ppSpace >> optionValue
def eraseAttr := leading_parser
"-" >> rawIdent
@[builtin_command_parser] def «attribute» := leading_parser
"attribute " >> "[" >>
withoutPosition (sepBy1 (eraseAttr <|> Term.attrInstance) ", ") >>
"] " >> many1 ident
@[builtin_command_parser] def «export» := leading_parser
"export " >> ident >> " (" >> many1 ident >> ")"
@[builtin_command_parser] def «import» := leading_parser
"import" -- not a real command, only for error messages
def openHiding := leading_parser
atomic (ident >> "hiding") >> many1 (checkColGt >> ident)
def openRenamingItem := leading_parser
ident >> unicodeSymbol " → " " -> " >> checkColGt >> ident
def openRenaming := leading_parser
atomic (ident >> "renaming") >> sepBy1 openRenamingItem ", "
def openOnly := leading_parser
atomic (ident >> " (") >> many1 ident >> ")"
def openSimple := leading_parser
many1 (checkColGt >> ident)
def openScoped := leading_parser
"scoped " >> many1 (checkColGt >> ident)
def openDecl :=
withAntiquot (mkAntiquot "openDecl" `Lean.Parser.Command.openDecl (isPseudoKind := true)) <|
openHiding <|> openRenaming <|> openOnly <|> openSimple <|> openScoped
@[builtin_command_parser] def «open» := leading_parser
withPosition ("open " >> openDecl)
@[builtin_command_parser] def «mutual» := leading_parser
"mutual " >> many1 (ppLine >> notSymbol "end" >> commandParser) >>
ppDedent (ppLine >> "end") >> terminationSuffix
def initializeKeyword := leading_parser
"initialize " <|> "builtin_initialize "
@[builtin_command_parser] def «initialize» := leading_parser
declModifiers false >> initializeKeyword >>
optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq
@[builtin_command_parser] def «in» := trailing_parser withOpen (" in " >> commandParser)
@[builtin_command_parser] def addDocString := leading_parser
docComment >> "add_decl_doc" >> ident
/--
This is an auxiliary command for generation constructor injectivity theorems for
inductive types defined at `Prelude.lean`.
It is meant for bootstrapping purposes only. -/
@[builtin_command_parser] def genInjectiveTheorems := leading_parser
"gen_injective_theorems% " >> ident
/-- No-op parser used as syntax kind for attaching remaining whitespace to at the end of the input. -/
@[run_builtin_parser_attribute_hooks] def eoi : Parser := leading_parser ""
builtin_initialize
registerBuiltinNodeKind ``eoi
@[run_builtin_parser_attribute_hooks] abbrev declModifiersF := declModifiers false
@[run_builtin_parser_attribute_hooks] abbrev declModifiersT := declModifiers true
builtin_initialize
register_parser_alias (kind := ``declModifiers) "declModifiers" declModifiersF
register_parser_alias (kind := ``declModifiers) "nestedDeclModifiers" declModifiersT
register_parser_alias declId
register_parser_alias declSig
register_parser_alias declVal
register_parser_alias optDeclSig
register_parser_alias openDecl
register_parser_alias docComment
end Command
namespace Term
/--
`open Foo in e` is like `open Foo` but scoped to a single term.
It makes the given namespaces available in the term `e`.
-/
@[builtin_term_parser] def «open» := leading_parser:leadPrec
"open " >> Command.openDecl >> withOpenDecl (" in " >> termParser)
/--
`set_option opt val in e` is like `set_option opt val` but scoped to a single term.
It sets the option `opt` to the value `val` in the term `e`.
-/
@[builtin_term_parser] def «set_option» := leading_parser:leadPrec
"set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> termParser
end Term
namespace Tactic
/-- `open Foo in tacs` (the tactic) acts like `open Foo` at command level,
but it opens a namespace only within the tactics `tacs`. -/
@[builtin_tactic_parser] def «open» := leading_parser:leadPrec
"open " >> Command.openDecl >> withOpenDecl (" in " >> tacticSeq)
/-- `set_option opt val in tacs` (the tactic) acts like `set_option opt val` at the command level,
but it sets the option only within the tactics `tacs`. -/
@[builtin_tactic_parser] def «set_option» := leading_parser:leadPrec
"set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> tacticSeq
end Tactic
end Parser
end Lean
|
section \<open>Number theory problems\<close>
subsection \<open>IMO 2018 SL - N5\<close>
theory IMO_2018_SL_N5
imports Main
begin
definition perfect_square :: "int \<Rightarrow> bool" where
"perfect_square s \<longleftrightarrow> (\<exists> r. s = r * r)"
(*
lemma perfect_square_root_pos:
assumes "perfect_square s"
shows "\<exists> r. r \<ge> 0 \<and> s = r * r"
sorry
lemma not_perfect_square_15:
fixes q::int
shows "q^2 \<noteq> 15"
sorry
lemma not_perfect_square_12:
fixes q::int
shows "q^2 \<noteq> 12"
sorry
lemma not_perfect_square_8:
fixes q::int
shows "q^2 \<noteq> 8"
sorry
lemma not_perfect_square_7:
fixes q::int
shows "q^2 \<noteq> 7"
sorry
lemma not_perfect_square_5:
fixes q::int
shows "q^2 \<noteq> 5"
sorry
lemma not_perfect_square_3:
fixes q::int
shows "q^2 \<noteq> 3"
sorry
*)
lemma IMO2018SL_N5_lemma:
fixes s a b c d :: int
assumes "s^2 = a^2 + b^2" "s^2 = c^2 + d^2" "2*s = a^2 - c^2"
assumes "s > 0" "a \<ge> 0" "d \<ge> 0" "b \<ge> 0" "c \<ge> 0" "b > 0 \<or> c > 0" "b \<ge> c"
shows False
sorry
theorem IMO2018SL_N5:
fixes x y z t :: int
assumes pos: "x > 0" "y > 0" "z > 0" "t > 0"
assumes eq: "x*y - z*t = x + y" "x + y = z + t"
shows " \<not> (perfect_square (x*y) \<and> perfect_square (z*t))"
sorry
end |
#pragma once
#include "BasicBox.h"
#include "BasicTypes.h"
#include "BoxTypes.h"
#include "General.h"
#include "NodeDim.h"
#include "NodeListDim.h"
#include <gsl.h>
namespace formulae{ namespace node {
/**
*
* @param width
* @param node center node -> reference point, (must be Box0 or Rule !!!)
* @param upList above center, enumerated from bottom to top
* @param dnList below center, enumerated from top to bottom
* @return
*/
template<typename VList1=vlist_t, typename VList2=vlist_t, typename Node=NodeRef>
box_t makeVBox(dist_t width, Node && node,
VList1 && upList, VList2 && dnList) {
using general::revAppend;
using general::transfer;
auto h = vlistVsize(upList) + node.height();
auto d = vlistVsize(dnList) + node.depth();
std::remove_reference_t<VList1> emptyList;
auto nodeList = revAppend(std::forward<VList1>(upList), emptyList);
nodeList.push_back(std::forward<Node>(node));
transfer(nodeList, std::forward<VList2>(dnList));
return vbox(dim_t{width, h, d}, std::move(nodeList));
}
/**
*
* @param width
* @param center center node -> reference point,
* @param upList above center, enumerated from bottom to top
* @return
*/
template <typename Box = box_t, typename VList = vlist_t>
box_t upVBox(dist_t width, Box && center, VList&& upList) {
std::remove_reference_t<VList> emptyList;
return makeVBox(width, NodeRef{Box0(std::forward<Box>(center))},
std::forward<VList>(upList), emptyList);
}
/**
*
* @param width
* @param center center node -> reference point
* @param dnList below center, enumerated from top to bottom
* @return
*/
template <typename Box = box_t, typename VList = vlist_t>
box_t dnVBox(dist_t width, Box && center, VList && dnList) {
std::remove_reference_t<VList> emptyList;
return makeVBox(width, Box0(std::forward<Box>(center)), emptyList, std::forward<VList>(dnList));
}
/**
*
* @param n1
* @param dist1 distance from bottom of n1 to baseline
* @param dist vertical distance between n1 and n2
* @param n2
* @return
*/
template <typename Node = NodeRef, typename DownNode=NodeRef>
NodeRef above(Node && n1, dist_t dist1, dist_t dist, DownNode && n2) {
auto w = std::max(n1.vwidth(), n2.vwidth());
auto h = n1.vsize() + dist1;
auto d = n2.vsize() + dist - dist1;
using E = std::remove_reference_t<Node>;
list_t<E> nodeList;
nodeList.push_back(std::forward<Node>(n1));
nodeList.push_back(Kern_t::create(dist));
nodeList.push_back(std::forward<DownNode>(n2));
return Box0(vbox(dim_t{w, h, d}, std::move(nodeList)));
};
}
} |
--Haskell Quil compiler
--Copyright Laurence Emms 2018
module Lib (compile) where
import Data.Complex
import Data.List
import Register
import Instruction
import ClassicalCircuit
import QuantumCircuit
import Util
testRXCircuit :: (Floating a, Show a, Ord a) => Circuit a
testRXCircuit = let parameters@[Left a] = [Left (MetaQubitRegister "a")]
instructions = [(RX (ComplexConstant (5.0 :+ 10.0)) a)]
in Circuit "TESTRX" parameters instructions
hadamardRotateXYZ :: (Floating a, Show a, Ord a) => Complex a -> Circuit a
hadamardRotateXYZ rotation
= let parameters@[Left a, Left b, Right r, Left z] = [Left (MetaQubitRegister "a"), Left (MetaQubitRegister "b"), Right (MetaRegister "r"), Left (MetaQubitRegister "z")]
instructions = [(Hadamard a),
(MeasureOut a r)] ++
(ifC "HROTXYZTHEN0" "HROTXYZEND0"
r
[(RX (ComplexConstant rotation) z)]
([(Hadamard b),
(MeasureOut b r)] ++
(ifC "HROTXYZTHEN1" "HROTXYZEND1"
r
[(RY (ComplexConstant rotation) z)]
[(RZ (ComplexConstant rotation) z)])))
in Circuit "HROTXYZ" parameters instructions
compile :: IO ()
compile = putStrLn "Compiling quantum executable" >>
--Test registers
putStrLn (show $ QubitRegister 10) >>
putStrLn (show $ Register 5) >>
putStrLn (show $ ComplexConstant (6.0 :+ 7.0)) >>
putStrLn (show $ ComplexConstant ((-8.0) :+ 1.0)) >>
putStrLn (show $ ComplexConstant (2.0 :+ (-3.0))) >>
putStrLn (show $ ComplexConstant ((-4.0) :+ (-6.0))) >>
--Test instructions
putStrLn (show $ CNot (QubitRegister 0) (QubitRegister 1)) >>
putStrLn (show $ PSwap (ComplexConstant (5.0 :+ (-3.2))) (QubitRegister 0) (QubitRegister 1)) >>
putStrLn (show $ Measure (QubitRegister 4)) >>
putStrLn (show $ MeasureOut (QubitRegister 4) (Register 5)) >>
--Test circuits
putStrLn (show $ DefCircuit bell) >>
putStrLn (show $ CallCircuit bell [Left (QubitRegister 5), Left (QubitRegister 3)]) >>
putStrLn (show $ DefCircuit testRXCircuit) >>
putStrLn (show $ CallCircuit testRXCircuit [Left (QubitRegister 1)]) >>
putStrLn (show $ DefCircuit xor) >>
putStrLn (show $ CallCircuit xor [Right (Register 0), Right (Register 1), Right (Register 2)]) >>
putStrLn (show $ DefCircuit halfAdder) >>
putStrLn (show $ CallCircuit halfAdder [Right (Register 0), Right (Register 1), Right (Register 2), Right (Register 3)]) >>
putStrLn (show $ DefCircuit adder) >>
putStrLn (show $ CallCircuit adder [Right (Register 0), Right (Register 1), Right (Register 2), Right (Register 3), Right (Register 4)]) >>
--Load the integer 53 into registers [0-31]
putStrLn (intercalate "\n" (fmap show (loadIntToRegisters 53 0))) >>
--Load the integer 18 into registers [32-63]
putStrLn (intercalate "\n" (fmap show (loadIntToRegisters 18 32))) >>
--Add [0-31] + [32-63] into [64-95]
let carry = 128
temp = 129
in putStrLn (intercalate "\n" (fmap show (addRegisters carry temp 0 32 64))) >>
putStrLn (show $ DefCircuit (hadamardRotateXYZ (0.70710678118 :+ 0.70710678118))) >>
putStrLn (show $ CallCircuit (hadamardRotateXYZ (0.70710678118 :+ 0.70710678118)) [Left (QubitRegister 0), Left (QubitRegister 1), Right (Register 0), Left (QubitRegister 2)])
|
! this is a comment
program alloctest
! this is a comment
! this is a comment
integer, allocatable :: a(:, :)
integer :: i, j !this is a comment
allocate(a(2, 2))
! this is a comment
! this is a comment
!this is a comment
do i = 1, 2
do j = 1, 2
a(i, j) = i * j
end do
!this is a comment
end do
print *, a
!this is a comment
end program alloctest
! this is a comment
|
[STATEMENT]
lemma servTicket_authentic_Kas:
"\<lbrakk> Crypt (shrK B) \<lbrace>Agent A, Agent B, Key servK, Number Ts\<rbrace>
\<in> parts (spies evs); B \<noteq> Tgs; B \<notin> bad;
evs \<in> kerbIV_gets \<rbrakk>
\<Longrightarrow> \<exists>authK Ta.
Says Kas A
(Crypt (shrK A) \<lbrace>Key authK, Agent Tgs, Number Ta,
Crypt (shrK Tgs) \<lbrace>Agent A, Agent Tgs, Key authK, Number Ta\<rbrace>\<rbrace>)
\<in> set evs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>Crypt (shrK B) \<lbrace>Agent A, Agent B, Key servK, Number Ts\<rbrace> \<in> parts (knows Spy evs); B \<noteq> Tgs; B \<notin> bad; evs \<in> kerbIV_gets\<rbrakk> \<Longrightarrow> \<exists>authK Ta. Says Kas A (Crypt (shrK A) \<lbrace>Key authK, Agent Tgs, Number Ta, Crypt (shrK Tgs) \<lbrace>Agent A, Agent Tgs, Key authK, Number Ta\<rbrace>\<rbrace>) \<in> set evs
[PROOF STEP]
by (blast dest!: servTicket_authentic_Tgs K4_imp_K2) |
program assignboolean;
var x
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2011 *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
(****************************************************************************)
(* *)
(* Naive Set Theory in Coq *)
(* *)
(* INRIA INRIA *)
(* Rocquencourt Sophia-Antipolis *)
(* *)
(* Coq V6.1 *)
(* *)
(* Gilles Kahn *)
(* Gerard Huet *)
(* *)
(* *)
(* *)
(* Acknowledgments: This work was started in July 1993 by F. Prost. Thanks *)
(* to the Newton Institute for providing an exceptional work environment *)
(* in Summer 1995. Several developments by E. Ledinot were an inspiration. *)
(****************************************************************************)
(*i $Id: Relations_3_facts.v 14641 2011-11-06 11:59:10Z herbelin $ i*)
Require Export Relations_1.
Require Export Relations_1_facts.
Require Export Relations_2.
Require Export Relations_2_facts.
Require Export Relations_3.
Theorem Rstar_imp_coherent :
forall (U:Type) (R:Relation U) (x y:U), Rstar U R x y -> coherent U R x y.
Proof.
intros U R x y H'; red in |- *.
exists y; auto with sets.
Qed.
Hint Resolve Rstar_imp_coherent.
Theorem coherent_symmetric :
forall (U:Type) (R:Relation U), Symmetric U (coherent U R).
Proof.
unfold coherent at 1 in |- *.
intros U R; red in |- *.
intros x y H'; elim H'.
intros z H'0; exists z; tauto.
Qed.
Theorem Strong_confluence :
forall (U:Type) (R:Relation U), Strongly_confluent U R -> Confluent U R.
Proof.
intros U R H'; red in |- *.
intro x; red in |- *; intros a b H'0.
unfold coherent at 1 in |- *.
generalize b; clear b.
elim H'0; clear H'0.
intros x0 b H'1; exists b; auto with sets.
intros x0 y z H'1 H'2 H'3 b H'4.
generalize (Lemma1 U R); intro h; lapply h;
[ intro H'0; generalize (H'0 x0 b); intro h0; lapply h0;
[ intro H'5; generalize (H'5 y); intro h1; lapply h1;
[ intro h2; elim h2; intros z0 h3; elim h3; intros H'6 H'7;
clear h h0 h1 h2 h3
| clear h h0 h1 ]
| clear h h0 ]
| clear h ]; auto with sets.
generalize (H'3 z0); intro h; lapply h;
[ intro h0; elim h0; intros z1 h1; elim h1; intros H'8 H'9; clear h h0 h1
| clear h ]; auto with sets.
exists z1; split; auto with sets.
apply Rstar_n with z0; auto with sets.
Qed.
Theorem Strong_confluence_direct :
forall (U:Type) (R:Relation U), Strongly_confluent U R -> Confluent U R.
Proof.
intros U R H'; red in |- *.
intro x; red in |- *; intros a b H'0.
unfold coherent at 1 in |- *.
generalize b; clear b.
elim H'0; clear H'0.
intros x0 b H'1; exists b; auto with sets.
intros x0 y z H'1 H'2 H'3 b H'4.
cut (ex (fun t:U => Rstar U R y t /\ R b t)).
intro h; elim h; intros t h0; elim h0; intros H'0 H'5; clear h h0.
generalize (H'3 t); intro h; lapply h;
[ intro h0; elim h0; intros z0 h1; elim h1; intros H'6 H'7; clear h h0 h1
| clear h ]; auto with sets.
exists z0; split; [ assumption | idtac ].
apply Rstar_n with t; auto with sets.
generalize H'1; generalize y; clear H'1.
elim H'4.
intros x1 y0 H'0; exists y0; auto with sets.
intros x1 y0 z0 H'0 H'1 H'5 y1 H'6.
red in H'.
generalize (H' x1 y0 y1); intro h; lapply h;
[ intro H'7; lapply H'7;
[ intro h0; elim h0; intros z1 h1; elim h1; intros H'8 H'9;
clear h H'7 h0 h1
| clear h ]
| clear h ]; auto with sets.
generalize (H'5 z1); intro h; lapply h;
[ intro h0; elim h0; intros t h1; elim h1; intros H'7 H'10; clear h h0 h1
| clear h ]; auto with sets.
exists t; split; auto with sets.
apply Rstar_n with z1; auto with sets.
Qed.
Theorem Noetherian_contains_Noetherian :
forall (U:Type) (R R':Relation U),
Noetherian U R -> contains U R R' -> Noetherian U R'.
Proof.
unfold Noetherian at 2 in |- *.
intros U R R' H' H'0 x.
elim (H' x); auto with sets.
Qed.
Theorem Newman :
forall (U:Type) (R:Relation U),
Noetherian U R -> Locally_confluent U R -> Confluent U R.
Proof.
intros U R H' H'0; red in |- *; intro x.
elim (H' x); unfold confluent in |- *.
intros x0 H'1 H'2 y z H'3 H'4.
generalize (Rstar_cases U R x0 y); intro h; lapply h;
[ intro h0; elim h0;
[ clear h h0; intro h1
| intro h1; elim h1; intros u h2; elim h2; intros H'5 H'6;
clear h h0 h1 h2 ]
| clear h ]; auto with sets.
elim h1; auto with sets.
generalize (Rstar_cases U R x0 z); intro h; lapply h;
[ intro h0; elim h0;
[ clear h h0; intro h1
| intro h1; elim h1; intros v h2; elim h2; intros H'7 H'8;
clear h h0 h1 h2 ]
| clear h ]; auto with sets.
elim h1; generalize coherent_symmetric; intro t; red in t; auto with sets.
unfold Locally_confluent, locally_confluent, coherent in H'0.
generalize (H'0 x0 u v); intro h; lapply h;
[ intro H'9; lapply H'9;
[ intro h0; elim h0; intros t h1; elim h1; intros H'10 H'11;
clear h H'9 h0 h1
| clear h ]
| clear h ]; auto with sets.
clear H'0.
unfold coherent at 1 in H'2.
generalize (H'2 u); intro h; lapply h;
[ intro H'0; generalize (H'0 y t); intro h0; lapply h0;
[ intro H'9; lapply H'9;
[ intro h1; elim h1; intros y1 h2; elim h2; intros H'12 H'13;
clear h h0 H'9 h1 h2
| clear h h0 ]
| clear h h0 ]
| clear h ]; auto with sets.
generalize Rstar_transitive; intro T; red in T.
generalize (H'2 v); intro h; lapply h;
[ intro H'9; generalize (H'9 y1 z); intro h0; lapply h0;
[ intro H'14; lapply H'14;
[ intro h1; elim h1; intros z1 h2; elim h2; intros H'15 H'16;
clear h h0 H'14 h1 h2
| clear h h0 ]
| clear h h0 ]
| clear h ]; auto with sets.
red in |- *; (exists z1; split); auto with sets.
apply T with y1; auto with sets.
apply T with t; auto with sets.
Qed. |
Formal statement is: lemma to_fract_eq_0_iff [simp]: "to_fract x = 0 \<longleftrightarrow> x = 0" Informal statement is: The fractional part of a real number is zero if and only if the real number is zero. |
import Paraiso
import Data.Complex
import System.Environment
main = do
args <- getArgs
let arch = if "--cuda" `elem` args then
CUDA 128 128
else
X86
putStrLn $ compile arch code
where
code = do
parallel 16384 $ do
z <- allocate
z0<- allocate
z =$ (Rand (-2.0) 2.0) :+ (Rand (-2.0) 2.0)
z0=$ (z:: Complex (Expr Double))
cuda $ do
sequential 65536 $ do
z =$ z * z - 1
output [realPart z0,imagPart z0, realPart z, imagPart z]
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2010 *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
Require Import Rbase.
Require Import Rfunctions.
Require Import Ranalysis1.
Require Import RList.
Require Import Classical_Prop.
Require Import Classical_Pred_Type.
Open Local Scope R_scope.
(** * General definitions and propositions *)
Definition included (D1 D2:R -> Prop) : Prop := forall x:R, D1 x -> D2 x.
Definition disc (x:R) (delta:posreal) (y:R) : Prop := Rabs (y - x) < delta.
Definition neighbourhood (V:R -> Prop) (x:R) : Prop :=
exists delta : posreal, included (disc x delta) V.
Definition open_set (D:R -> Prop) : Prop :=
forall x:R, D x -> neighbourhood D x.
Definition complementary (D:R -> Prop) (c:R) : Prop := ~ D c.
Definition closed_set (D:R -> Prop) : Prop := open_set (complementary D).
Definition intersection_domain (D1 D2:R -> Prop) (c:R) : Prop := D1 c /\ D2 c.
Definition union_domain (D1 D2:R -> Prop) (c:R) : Prop := D1 c \/ D2 c.
Definition interior (D:R -> Prop) (x:R) : Prop := neighbourhood D x.
Lemma interior_P1 : forall D:R -> Prop, included (interior D) D.
Proof.
intros; unfold included in |- *; unfold interior in |- *; intros;
unfold neighbourhood in H; elim H; intros; unfold included in H0;
apply H0; unfold disc in |- *; unfold Rminus in |- *;
rewrite Rplus_opp_r; rewrite Rabs_R0; apply (cond_pos x0).
Qed.
Lemma interior_P2 : forall D:R -> Prop, open_set D -> included D (interior D).
Proof.
intros; unfold open_set in H; unfold included in |- *; intros;
assert (H1 := H _ H0); unfold interior in |- *; apply H1.
Qed.
Definition point_adherent (D:R -> Prop) (x:R) : Prop :=
forall V:R -> Prop,
neighbourhood V x -> exists y : R, intersection_domain V D y.
Definition adherence (D:R -> Prop) (x:R) : Prop := point_adherent D x.
Lemma adherence_P1 : forall D:R -> Prop, included D (adherence D).
Proof.
intro; unfold included in |- *; intros; unfold adherence in |- *;
unfold point_adherent in |- *; intros; exists x;
unfold intersection_domain in |- *; split.
unfold neighbourhood in H0; elim H0; intros; unfold included in H1; apply H1;
unfold disc in |- *; unfold Rminus in |- *; rewrite Rplus_opp_r;
rewrite Rabs_R0; apply (cond_pos x0).
apply H.
Qed.
Lemma included_trans :
forall D1 D2 D3:R -> Prop,
included D1 D2 -> included D2 D3 -> included D1 D3.
Proof.
unfold included in |- *; intros; apply H0; apply H; apply H1.
Qed.
Lemma interior_P3 : forall D:R -> Prop, open_set (interior D).
Proof.
intro; unfold open_set, interior in |- *; unfold neighbourhood in |- *;
intros; elim H; intros.
exists x0; unfold included in |- *; intros.
set (del := x0 - Rabs (x - x1)).
cut (0 < del).
intro; exists (mkposreal del H2); intros.
cut (included (disc x1 (mkposreal del H2)) (disc x x0)).
intro; assert (H5 := included_trans _ _ _ H4 H0).
apply H5; apply H3.
unfold included in |- *; unfold disc in |- *; intros.
apply Rle_lt_trans with (Rabs (x3 - x1) + Rabs (x1 - x)).
replace (x3 - x) with (x3 - x1 + (x1 - x)); [ apply Rabs_triang | ring ].
replace (pos x0) with (del + Rabs (x1 - x)).
do 2 rewrite <- (Rplus_comm (Rabs (x1 - x))); apply Rplus_lt_compat_l;
apply H4.
unfold del in |- *; rewrite <- (Rabs_Ropp (x - x1)); rewrite Ropp_minus_distr;
ring.
unfold del in |- *; apply Rplus_lt_reg_r with (Rabs (x - x1));
rewrite Rplus_0_r;
replace (Rabs (x - x1) + (x0 - Rabs (x - x1))) with (pos x0);
[ idtac | ring ].
unfold disc in H1; rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply H1.
Qed.
Lemma complementary_P1 :
forall D:R -> Prop,
~ (exists y : R, intersection_domain D (complementary D) y).
Proof.
intro; red in |- *; intro; elim H; intros;
unfold intersection_domain, complementary in H0; elim H0;
intros; elim H2; assumption.
Qed.
Lemma adherence_P2 :
forall D:R -> Prop, closed_set D -> included (adherence D) D.
Proof.
unfold closed_set in |- *; unfold open_set, complementary in |- *; intros;
unfold included, adherence in |- *; intros; assert (H1 := classic (D x));
elim H1; intro.
assumption.
assert (H3 := H _ H2); assert (H4 := H0 _ H3); elim H4; intros;
unfold intersection_domain in H5; elim H5; intros;
elim H6; assumption.
Qed.
Lemma adherence_P3 : forall D:R -> Prop, closed_set (adherence D).
Proof.
intro; unfold closed_set, adherence in |- *;
unfold open_set, complementary, point_adherent in |- *;
intros;
set
(P :=
fun V:R -> Prop =>
neighbourhood V x -> exists y : R, intersection_domain V D y);
assert (H0 := not_all_ex_not _ P H); elim H0; intros V0 H1;
unfold P in H1; assert (H2 := imply_to_and _ _ H1);
unfold neighbourhood in |- *; elim H2; intros; unfold neighbourhood in H3;
elim H3; intros; exists x0; unfold included in |- *;
intros; red in |- *; intro.
assert (H8 := H7 V0);
cut (exists delta : posreal, (forall x:R, disc x1 delta x -> V0 x)).
intro; assert (H10 := H8 H9); elim H4; assumption.
cut (0 < x0 - Rabs (x - x1)).
intro; set (del := mkposreal _ H9); exists del; intros;
unfold included in H5; apply H5; unfold disc in |- *;
apply Rle_lt_trans with (Rabs (x2 - x1) + Rabs (x1 - x)).
replace (x2 - x) with (x2 - x1 + (x1 - x)); [ apply Rabs_triang | ring ].
replace (pos x0) with (del + Rabs (x1 - x)).
do 2 rewrite <- (Rplus_comm (Rabs (x1 - x))); apply Rplus_lt_compat_l;
apply H10.
unfold del in |- *; simpl in |- *; rewrite <- (Rabs_Ropp (x - x1));
rewrite Ropp_minus_distr; ring.
apply Rplus_lt_reg_r with (Rabs (x - x1)); rewrite Rplus_0_r;
replace (Rabs (x - x1) + (x0 - Rabs (x - x1))) with (pos x0);
[ rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply H6 | ring ].
Qed.
Definition eq_Dom (D1 D2:R -> Prop) : Prop :=
included D1 D2 /\ included D2 D1.
Infix "=_D" := eq_Dom (at level 70, no associativity).
Lemma open_set_P1 : forall D:R -> Prop, open_set D <-> D =_D interior D.
Proof.
intro; split.
intro; unfold eq_Dom in |- *; split.
apply interior_P2; assumption.
apply interior_P1.
intro; unfold eq_Dom in H; elim H; clear H; intros; unfold open_set in |- *;
intros; unfold included, interior in H; unfold included in H0;
apply (H _ H1).
Qed.
Lemma closed_set_P1 : forall D:R -> Prop, closed_set D <-> D =_D adherence D.
Proof.
intro; split.
intro; unfold eq_Dom in |- *; split.
apply adherence_P1.
apply adherence_P2; assumption.
unfold eq_Dom in |- *; unfold included in |- *; intros;
assert (H0 := adherence_P3 D); unfold closed_set in H0;
unfold closed_set in |- *; unfold open_set in |- *;
unfold open_set in H0; intros; assert (H2 : complementary (adherence D) x).
unfold complementary in |- *; unfold complementary in H1; red in |- *; intro;
elim H; clear H; intros _ H; elim H1; apply (H _ H2).
assert (H3 := H0 _ H2); unfold neighbourhood in |- *;
unfold neighbourhood in H3; elim H3; intros; exists x0;
unfold included in |- *; unfold included in H4; intros;
assert (H6 := H4 _ H5); unfold complementary in H6;
unfold complementary in |- *; red in |- *; intro;
elim H; clear H; intros H _; elim H6; apply (H _ H7).
Qed.
Lemma neighbourhood_P1 :
forall (D1 D2:R -> Prop) (x:R),
included D1 D2 -> neighbourhood D1 x -> neighbourhood D2 x.
Proof.
unfold included, neighbourhood in |- *; intros; elim H0; intros; exists x0;
intros; unfold included in |- *; unfold included in H1;
intros; apply (H _ (H1 _ H2)).
Qed.
Lemma open_set_P2 :
forall D1 D2:R -> Prop,
open_set D1 -> open_set D2 -> open_set (union_domain D1 D2).
Proof.
unfold open_set in |- *; intros; unfold union_domain in H1; elim H1; intro.
apply neighbourhood_P1 with D1.
unfold included, union_domain in |- *; tauto.
apply H; assumption.
apply neighbourhood_P1 with D2.
unfold included, union_domain in |- *; tauto.
apply H0; assumption.
Qed.
Lemma open_set_P3 :
forall D1 D2:R -> Prop,
open_set D1 -> open_set D2 -> open_set (intersection_domain D1 D2).
Proof.
unfold open_set in |- *; intros; unfold intersection_domain in H1; elim H1;
intros.
assert (H4 := H _ H2); assert (H5 := H0 _ H3);
unfold intersection_domain in |- *; unfold neighbourhood in H4, H5;
elim H4; clear H; intros del1 H; elim H5; clear H0;
intros del2 H0; cut (0 < Rmin del1 del2).
intro; set (del := mkposreal _ H6).
exists del; unfold included in |- *; intros; unfold included in H, H0;
unfold disc in H, H0, H7.
split.
apply H; apply Rlt_le_trans with (pos del).
apply H7.
unfold del in |- *; simpl in |- *; apply Rmin_l.
apply H0; apply Rlt_le_trans with (pos del).
apply H7.
unfold del in |- *; simpl in |- *; apply Rmin_r.
unfold Rmin in |- *; case (Rle_dec del1 del2); intro.
apply (cond_pos del1).
apply (cond_pos del2).
Qed.
Lemma open_set_P4 : open_set (fun x:R => False).
Proof.
unfold open_set in |- *; intros; elim H.
Qed.
Lemma open_set_P5 : open_set (fun x:R => True).
Proof.
unfold open_set in |- *; intros; unfold neighbourhood in |- *.
exists (mkposreal 1 Rlt_0_1); unfold included in |- *; intros; trivial.
Qed.
Lemma disc_P1 : forall (x:R) (del:posreal), open_set (disc x del).
Proof.
intros; assert (H := open_set_P1 (disc x del)).
elim H; intros; apply H1.
unfold eq_Dom in |- *; split.
unfold included, interior, disc in |- *; intros;
cut (0 < del - Rabs (x - x0)).
intro; set (del2 := mkposreal _ H3).
exists del2; unfold included in |- *; intros.
apply Rle_lt_trans with (Rabs (x1 - x0) + Rabs (x0 - x)).
replace (x1 - x) with (x1 - x0 + (x0 - x)); [ apply Rabs_triang | ring ].
replace (pos del) with (del2 + Rabs (x0 - x)).
do 2 rewrite <- (Rplus_comm (Rabs (x0 - x))); apply Rplus_lt_compat_l.
apply H4.
unfold del2 in |- *; simpl in |- *; rewrite <- (Rabs_Ropp (x - x0));
rewrite Ropp_minus_distr; ring.
apply Rplus_lt_reg_r with (Rabs (x - x0)); rewrite Rplus_0_r;
replace (Rabs (x - x0) + (del - Rabs (x - x0))) with (pos del);
[ rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply H2 | ring ].
apply interior_P1.
Qed.
Lemma continuity_P1 :
forall (f:R -> R) (x:R),
continuity_pt f x <->
(forall W:R -> Prop,
neighbourhood W (f x) ->
exists V : R -> Prop,
neighbourhood V x /\ (forall y:R, V y -> W (f y))).
Proof.
intros; split.
intros; unfold neighbourhood in H0.
elim H0; intros del1 H1.
unfold continuity_pt in H; unfold continue_in in H; unfold limit1_in in H;
unfold limit_in in H; simpl in H; unfold R_dist in H.
assert (H2 := H del1 (cond_pos del1)).
elim H2; intros del2 H3.
elim H3; intros.
exists (disc x (mkposreal del2 H4)).
intros; unfold included in H1; split.
unfold neighbourhood, disc in |- *.
exists (mkposreal del2 H4).
unfold included in |- *; intros; assumption.
intros; apply H1; unfold disc in |- *; case (Req_dec y x); intro.
rewrite H7; unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0;
apply (cond_pos del1).
apply H5; split.
unfold D_x, no_cond in |- *; split.
trivial.
apply (sym_not_eq (A:=R)); apply H7.
unfold disc in H6; apply H6.
intros; unfold continuity_pt in |- *; unfold continue_in in |- *;
unfold limit1_in in |- *; unfold limit_in in |- *;
intros.
assert (H1 := H (disc (f x) (mkposreal eps H0))).
cut (neighbourhood (disc (f x) (mkposreal eps H0)) (f x)).
intro; assert (H3 := H1 H2).
elim H3; intros D H4; elim H4; intros; unfold neighbourhood in H5; elim H5;
intros del1 H7.
exists (pos del1); split.
apply (cond_pos del1).
intros; elim H8; intros; simpl in H10; unfold R_dist in H10; simpl in |- *;
unfold R_dist in |- *; apply (H6 _ (H7 _ H10)).
unfold neighbourhood, disc in |- *; exists (mkposreal eps H0);
unfold included in |- *; intros; assumption.
Qed.
Definition image_rec (f:R -> R) (D:R -> Prop) (x:R) : Prop := D (f x).
(**********)
Lemma continuity_P2 :
forall (f:R -> R) (D:R -> Prop),
continuity f -> open_set D -> open_set (image_rec f D).
Proof.
intros; unfold open_set in H0; unfold open_set in |- *; intros;
assert (H2 := continuity_P1 f x); elim H2; intros H3 _;
assert (H4 := H3 (H x)); unfold neighbourhood, image_rec in |- *;
unfold image_rec in H1; assert (H5 := H4 D (H0 (f x) H1));
elim H5; intros V0 H6; elim H6; intros; unfold neighbourhood in H7;
elim H7; intros del H9; exists del; unfold included in H9;
unfold included in |- *; intros; apply (H8 _ (H9 _ H10)).
Qed.
(**********)
Lemma continuity_P3 :
forall f:R -> R,
continuity f <->
(forall D:R -> Prop, open_set D -> open_set (image_rec f D)).
Proof.
intros; split.
intros; apply continuity_P2; assumption.
intros; unfold continuity in |- *; unfold continuity_pt in |- *;
unfold continue_in in |- *; unfold limit1_in in |- *;
unfold limit_in in |- *; simpl in |- *; unfold R_dist in |- *;
intros; cut (open_set (disc (f x) (mkposreal _ H0))).
intro; assert (H2 := H _ H1).
unfold open_set, image_rec in H2; cut (disc (f x) (mkposreal _ H0) (f x)).
intro; assert (H4 := H2 _ H3).
unfold neighbourhood in H4; elim H4; intros del H5.
exists (pos del); split.
apply (cond_pos del).
intros; unfold included in H5; apply H5; elim H6; intros; apply H8.
unfold disc in |- *; unfold Rminus in |- *; rewrite Rplus_opp_r;
rewrite Rabs_R0; apply H0.
apply disc_P1.
Qed.
(**********)
Theorem Rsepare :
forall x y:R,
x <> y ->
exists V : R -> Prop,
(exists W : R -> Prop,
neighbourhood V x /\
neighbourhood W y /\ ~ (exists y : R, intersection_domain V W y)).
Proof.
intros x y Hsep; set (D := Rabs (x - y)).
cut (0 < D / 2).
intro; exists (disc x (mkposreal _ H)).
exists (disc y (mkposreal _ H)); split.
unfold neighbourhood in |- *; exists (mkposreal _ H); unfold included in |- *;
tauto.
split.
unfold neighbourhood in |- *; exists (mkposreal _ H); unfold included in |- *;
tauto.
red in |- *; intro; elim H0; intros; unfold intersection_domain in H1;
elim H1; intros.
cut (D < D).
intro; elim (Rlt_irrefl _ H4).
change (Rabs (x - y) < D) in |- *;
apply Rle_lt_trans with (Rabs (x - x0) + Rabs (x0 - y)).
replace (x - y) with (x - x0 + (x0 - y)); [ apply Rabs_triang | ring ].
rewrite (double_var D); apply Rplus_lt_compat.
rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply H2.
apply H3.
unfold Rdiv in |- *; apply Rmult_lt_0_compat.
unfold D in |- *; apply Rabs_pos_lt; apply (Rminus_eq_contra _ _ Hsep).
apply Rinv_0_lt_compat; prove_sup0.
Qed.
Record family : Type := mkfamily
{ind : R -> Prop;
f :> R -> R -> Prop;
cond_fam : forall x:R, (exists y : R, f x y) -> ind x}.
Definition family_open_set (f:family) : Prop := forall x:R, open_set (f x).
Definition domain_finite (D:R -> Prop) : Prop :=
exists l : Rlist, (forall x:R, D x <-> In x l).
Definition family_finite (f:family) : Prop := domain_finite (ind f).
Definition covering (D:R -> Prop) (f:family) : Prop :=
forall x:R, D x -> exists y : R, f y x.
Definition covering_open_set (D:R -> Prop) (f:family) : Prop :=
covering D f /\ family_open_set f.
Definition covering_finite (D:R -> Prop) (f:family) : Prop :=
covering D f /\ family_finite f.
Lemma restriction_family :
forall (f:family) (D:R -> Prop) (x:R),
(exists y : R, (fun z1 z2:R => f z1 z2 /\ D z1) x y) ->
intersection_domain (ind f) D x.
Proof.
intros; elim H; intros; unfold intersection_domain in |- *; elim H0; intros;
split.
apply (cond_fam f0); exists x0; assumption.
assumption.
Qed.
Definition subfamily (f:family) (D:R -> Prop) : family :=
mkfamily (intersection_domain (ind f) D) (fun x y:R => f x y /\ D x)
(restriction_family f D).
Definition compact (X:R -> Prop) : Prop :=
forall f:family,
covering_open_set X f ->
exists D : R -> Prop, covering_finite X (subfamily f D).
(**********)
Lemma family_P1 :
forall (f:family) (D:R -> Prop),
family_open_set f -> family_open_set (subfamily f D).
Proof.
unfold family_open_set in |- *; intros; unfold subfamily in |- *;
simpl in |- *; assert (H0 := classic (D x)).
elim H0; intro.
cut (open_set (f0 x) -> open_set (fun y:R => f0 x y /\ D x)).
intro; apply H2; apply H.
unfold open_set in |- *; unfold neighbourhood in |- *; intros; elim H3;
intros; assert (H6 := H2 _ H4); elim H6; intros; exists x1;
unfold included in |- *; intros; split.
apply (H7 _ H8).
assumption.
cut (open_set (fun y:R => False) -> open_set (fun y:R => f0 x y /\ D x)).
intro; apply H2; apply open_set_P4.
unfold open_set in |- *; unfold neighbourhood in |- *; intros; elim H3;
intros; elim H1; assumption.
Qed.
Definition bounded (D:R -> Prop) : Prop :=
exists m : R, (exists M : R, (forall x:R, D x -> m <= x <= M)).
Lemma open_set_P6 :
forall D1 D2:R -> Prop, open_set D1 -> D1 =_D D2 -> open_set D2.
Proof.
unfold open_set in |- *; unfold neighbourhood in |- *; intros.
unfold eq_Dom in H0; elim H0; intros.
assert (H4 := H _ (H3 _ H1)).
elim H4; intros.
exists x0; apply included_trans with D1; assumption.
Qed.
(**********)
Lemma compact_P1 : forall X:R -> Prop, compact X -> bounded X.
Proof.
intros; unfold compact in H; set (D := fun x:R => True);
set (g := fun x y:R => Rabs y < x);
cut (forall x:R, (exists y : _, g x y) -> True);
[ intro | intro; trivial ].
set (f0 := mkfamily D g H0); assert (H1 := H f0);
cut (covering_open_set X f0).
intro; assert (H3 := H1 H2); elim H3; intros D' H4;
unfold covering_finite in H4; elim H4; intros; unfold family_finite in H6;
unfold domain_finite in H6; elim H6; intros l H7;
unfold bounded in |- *; set (r := MaxRlist l).
exists (- r); exists r; intros.
unfold covering in H5; assert (H9 := H5 _ H8); elim H9; intros;
unfold subfamily in H10; simpl in H10; elim H10; intros;
assert (H13 := H7 x0); simpl in H13; cut (intersection_domain D D' x0).
elim H13; clear H13; intros.
assert (H16 := H13 H15); unfold g in H11; split.
cut (x0 <= r).
intro; cut (Rabs x < r).
intro; assert (H19 := Rabs_def2 x r H18); elim H19; intros; left; assumption.
apply Rlt_le_trans with x0; assumption.
apply (MaxRlist_P1 l x0 H16).
cut (x0 <= r).
intro; apply Rle_trans with (Rabs x).
apply RRle_abs.
apply Rle_trans with x0.
left; apply H11.
assumption.
apply (MaxRlist_P1 l x0 H16).
unfold intersection_domain, D in |- *; tauto.
unfold covering_open_set in |- *; split.
unfold covering in |- *; intros; simpl in |- *; exists (Rabs x + 1);
unfold g in |- *; pattern (Rabs x) at 1 in |- *; rewrite <- Rplus_0_r;
apply Rplus_lt_compat_l; apply Rlt_0_1.
unfold family_open_set in |- *; intro; case (Rtotal_order 0 x); intro.
apply open_set_P6 with (disc 0 (mkposreal _ H2)).
apply disc_P1.
unfold eq_Dom in |- *; unfold f0 in |- *; simpl in |- *;
unfold g, disc in |- *; split.
unfold included in |- *; intros; unfold Rminus in H3; rewrite Ropp_0 in H3;
rewrite Rplus_0_r in H3; apply H3.
unfold included in |- *; intros; unfold Rminus in |- *; rewrite Ropp_0;
rewrite Rplus_0_r; apply H3.
apply open_set_P6 with (fun x:R => False).
apply open_set_P4.
unfold eq_Dom in |- *; split.
unfold included in |- *; intros; elim H3.
unfold included, f0 in |- *; simpl in |- *; unfold g in |- *; intros; elim H2;
intro;
[ rewrite <- H4 in H3; assert (H5 := Rabs_pos x0);
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H5 H3))
| assert (H6 := Rabs_pos x0); assert (H7 := Rlt_trans _ _ _ H3 H4);
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H6 H7)) ].
Qed.
(**********)
Lemma compact_P2 : forall X:R -> Prop, compact X -> closed_set X.
Proof.
intros; assert (H0 := closed_set_P1 X); elim H0; clear H0; intros _ H0;
apply H0; clear H0.
unfold eq_Dom in |- *; split.
apply adherence_P1.
unfold included in |- *; unfold adherence in |- *;
unfold point_adherent in |- *; intros; unfold compact in H;
assert (H1 := classic (X x)); elim H1; clear H1; intro.
assumption.
cut (forall y:R, X y -> 0 < Rabs (y - x) / 2).
intro; set (D := X);
set (g := fun y z:R => Rabs (y - z) < Rabs (y - x) / 2 /\ D y);
cut (forall x:R, (exists y : _, g x y) -> D x).
intro; set (f0 := mkfamily D g H3); assert (H4 := H f0);
cut (covering_open_set X f0).
intro; assert (H6 := H4 H5); elim H6; clear H6; intros D' H6.
unfold covering_finite in H6; decompose [and] H6;
unfold covering, subfamily in H7; simpl in H7;
unfold family_finite, subfamily in H8; simpl in H8;
unfold domain_finite in H8; elim H8; clear H8; intros l H8;
set (alp := MinRlist (AbsList l x)); cut (0 < alp).
intro; assert (H10 := H0 (disc x (mkposreal _ H9)));
cut (neighbourhood (disc x (mkposreal alp H9)) x).
intro; assert (H12 := H10 H11); elim H12; clear H12; intros y H12;
unfold intersection_domain in H12; elim H12; clear H12;
intros; assert (H14 := H7 _ H13); elim H14; clear H14;
intros y0 H14; elim H14; clear H14; intros; unfold g in H14;
elim H14; clear H14; intros; unfold disc in H12; simpl in H12;
cut (alp <= Rabs (y0 - x) / 2).
intro; assert (H18 := Rlt_le_trans _ _ _ H12 H17);
cut (Rabs (y0 - x) < Rabs (y0 - x)).
intro; elim (Rlt_irrefl _ H19).
apply Rle_lt_trans with (Rabs (y0 - y) + Rabs (y - x)).
replace (y0 - x) with (y0 - y + (y - x)); [ apply Rabs_triang | ring ].
rewrite (double_var (Rabs (y0 - x))); apply Rplus_lt_compat; assumption.
apply (MinRlist_P1 (AbsList l x) (Rabs (y0 - x) / 2)); apply AbsList_P1;
elim (H8 y0); clear H8; intros; apply H8; unfold intersection_domain in |- *;
split; assumption.
assert (H11 := disc_P1 x (mkposreal alp H9)); unfold open_set in H11;
apply H11.
unfold disc in |- *; unfold Rminus in |- *; rewrite Rplus_opp_r;
rewrite Rabs_R0; apply H9.
unfold alp in |- *; apply MinRlist_P2; intros;
assert (H10 := AbsList_P2 _ _ _ H9); elim H10; clear H10;
intros z H10; elim H10; clear H10; intros; rewrite H11;
apply H2; elim (H8 z); clear H8; intros; assert (H13 := H12 H10);
unfold intersection_domain, D in H13; elim H13; clear H13;
intros; assumption.
unfold covering_open_set in |- *; split.
unfold covering in |- *; intros; exists x0; simpl in |- *; unfold g in |- *;
split.
unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0;
unfold Rminus in H2; apply (H2 _ H5).
apply H5.
unfold family_open_set in |- *; intro; simpl in |- *; unfold g in |- *;
elim (classic (D x0)); intro.
apply open_set_P6 with (disc x0 (mkposreal _ (H2 _ H5))).
apply disc_P1.
unfold eq_Dom in |- *; split.
unfold included, disc in |- *; simpl in |- *; intros; split.
rewrite <- (Rabs_Ropp (x0 - x1)); rewrite Ropp_minus_distr; apply H6.
apply H5.
unfold included, disc in |- *; simpl in |- *; intros; elim H6; intros;
rewrite <- (Rabs_Ropp (x1 - x0)); rewrite Ropp_minus_distr;
apply H7.
apply open_set_P6 with (fun z:R => False).
apply open_set_P4.
unfold eq_Dom in |- *; split.
unfold included in |- *; intros; elim H6.
unfold included in |- *; intros; elim H6; intros; elim H5; assumption.
intros; elim H3; intros; unfold g in H4; elim H4; clear H4; intros _ H4;
apply H4.
intros; unfold Rdiv in |- *; apply Rmult_lt_0_compat.
apply Rabs_pos_lt; apply Rminus_eq_contra; red in |- *; intro;
rewrite H3 in H2; elim H1; apply H2.
apply Rinv_0_lt_compat; prove_sup0.
Qed.
(**********)
Lemma compact_EMP : compact (fun _:R => False).
Proof.
unfold compact in |- *; intros; exists (fun x:R => False);
unfold covering_finite in |- *; split.
unfold covering in |- *; intros; elim H0.
unfold family_finite in |- *; unfold domain_finite in |- *; exists nil; intro.
split.
simpl in |- *; unfold intersection_domain in |- *; intros; elim H0.
elim H0; clear H0; intros _ H0; elim H0.
simpl in |- *; intro; elim H0.
Qed.
Lemma compact_eqDom :
forall X1 X2:R -> Prop, compact X1 -> X1 =_D X2 -> compact X2.
Proof.
unfold compact in |- *; intros; unfold eq_Dom in H0; elim H0; clear H0;
unfold included in |- *; intros; assert (H3 : covering_open_set X1 f0).
unfold covering_open_set in |- *; unfold covering_open_set in H1; elim H1;
clear H1; intros; split.
unfold covering in H1; unfold covering in |- *; intros;
apply (H1 _ (H0 _ H4)).
apply H3.
elim (H _ H3); intros D H4; exists D; unfold covering_finite in |- *;
unfold covering_finite in H4; elim H4; intros; split.
unfold covering in H5; unfold covering in |- *; intros;
apply (H5 _ (H2 _ H7)).
apply H6.
Qed.
(** Borel-Lebesgue's lemma *)
Lemma compact_P3 : forall a b:R, compact (fun c:R => a <= c <= b).
Proof.
intros; case (Rle_dec a b); intro.
unfold compact in |- *; intros;
set
(A :=
fun x:R =>
a <= x <= b /\
(exists D : R -> Prop,
covering_finite (fun c:R => a <= c <= x) (subfamily f0 D)));
cut (A a).
intro; cut (bound A).
intro; cut (exists a0 : R, A a0).
intro; assert (H3 := completeness A H1 H2); elim H3; clear H3; intros m H3;
unfold is_lub in H3; cut (a <= m <= b).
intro; unfold covering_open_set in H; elim H; clear H; intros;
unfold covering in H; assert (H6 := H m H4); elim H6;
clear H6; intros y0 H6; unfold family_open_set in H5;
assert (H7 := H5 y0); unfold open_set in H7; assert (H8 := H7 m H6);
unfold neighbourhood in H8; elim H8; clear H8; intros eps H8;
cut (exists x : R, A x /\ m - eps < x <= m).
intro; elim H9; clear H9; intros x H9; elim H9; clear H9; intros;
case (Req_dec m b); intro.
rewrite H11 in H10; rewrite H11 in H8; unfold A in H9; elim H9; clear H9;
intros; elim H12; clear H12; intros Dx H12;
set (Db := fun x:R => Dx x \/ x = y0); exists Db;
unfold covering_finite in |- *; split.
unfold covering in |- *; unfold covering_finite in H12; elim H12; clear H12;
intros; unfold covering in H12; case (Rle_dec x0 x);
intro.
cut (a <= x0 <= x).
intro; assert (H16 := H12 x0 H15); elim H16; clear H16; intros; exists x1;
simpl in H16; simpl in |- *; unfold Db in |- *; elim H16;
clear H16; intros; split; [ apply H16 | left; apply H17 ].
split.
elim H14; intros; assumption.
assumption.
exists y0; simpl in |- *; split.
apply H8; unfold disc in |- *; rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr;
rewrite Rabs_right.
apply Rlt_trans with (b - x).
unfold Rminus in |- *; apply Rplus_lt_compat_l; apply Ropp_lt_gt_contravar;
auto with real.
elim H10; intros H15 _; apply Rplus_lt_reg_r with (x - eps);
replace (x - eps + (b - x)) with (b - eps);
[ replace (x - eps + eps) with x; [ apply H15 | ring ] | ring ].
apply Rge_minus; apply Rle_ge; elim H14; intros _ H15; apply H15.
unfold Db in |- *; right; reflexivity.
unfold family_finite in |- *; unfold domain_finite in |- *;
unfold covering_finite in H12; elim H12; clear H12;
intros; unfold family_finite in H13; unfold domain_finite in H13;
elim H13; clear H13; intros l H13; exists (cons y0 l);
intro; split.
intro; simpl in H14; unfold intersection_domain in H14; elim (H13 x0);
clear H13; intros; case (Req_dec x0 y0); intro.
simpl in |- *; left; apply H16.
simpl in |- *; right; apply H13.
simpl in |- *; unfold intersection_domain in |- *; unfold Db in H14;
decompose [and or] H14.
split; assumption.
elim H16; assumption.
intro; simpl in H14; elim H14; intro; simpl in |- *;
unfold intersection_domain in |- *.
split.
apply (cond_fam f0); rewrite H15; exists m; apply H6.
unfold Db in |- *; right; assumption.
simpl in |- *; unfold intersection_domain in |- *; elim (H13 x0).
intros _ H16; assert (H17 := H16 H15); simpl in H17;
unfold intersection_domain in H17; split.
elim H17; intros; assumption.
unfold Db in |- *; left; elim H17; intros; assumption.
set (m' := Rmin (m + eps / 2) b); cut (A m').
intro; elim H3; intros; unfold is_upper_bound in H13;
assert (H15 := H13 m' H12); cut (m < m').
intro; elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H15 H16)).
unfold m' in |- *; unfold Rmin in |- *; case (Rle_dec (m + eps / 2) b); intro.
pattern m at 1 in |- *; rewrite <- Rplus_0_r; apply Rplus_lt_compat_l;
unfold Rdiv in |- *; apply Rmult_lt_0_compat;
[ apply (cond_pos eps) | apply Rinv_0_lt_compat; prove_sup0 ].
elim H4; intros.
elim H17; intro.
assumption.
elim H11; assumption.
unfold A in |- *; split.
split.
apply Rle_trans with m.
elim H4; intros; assumption.
unfold m' in |- *; unfold Rmin in |- *; case (Rle_dec (m + eps / 2) b); intro.
pattern m at 1 in |- *; rewrite <- Rplus_0_r; apply Rplus_le_compat_l; left;
unfold Rdiv in |- *; apply Rmult_lt_0_compat;
[ apply (cond_pos eps) | apply Rinv_0_lt_compat; prove_sup0 ].
elim H4; intros.
elim H13; intro.
assumption.
elim H11; assumption.
unfold m' in |- *; apply Rmin_r.
unfold A in H9; elim H9; clear H9; intros; elim H12; clear H12; intros Dx H12;
set (Db := fun x:R => Dx x \/ x = y0); exists Db;
unfold covering_finite in |- *; split.
unfold covering in |- *; unfold covering_finite in H12; elim H12; clear H12;
intros; unfold covering in H12; case (Rle_dec x0 x);
intro.
cut (a <= x0 <= x).
intro; assert (H16 := H12 x0 H15); elim H16; clear H16; intros; exists x1;
simpl in H16; simpl in |- *; unfold Db in |- *.
elim H16; clear H16; intros; split; [ apply H16 | left; apply H17 ].
elim H14; intros; split; assumption.
exists y0; simpl in |- *; split.
apply H8; unfold disc in |- *; unfold Rabs in |- *; case (Rcase_abs (x0 - m));
intro.
rewrite Ropp_minus_distr; apply Rlt_trans with (m - x).
unfold Rminus in |- *; apply Rplus_lt_compat_l; apply Ropp_lt_gt_contravar;
auto with real.
apply Rplus_lt_reg_r with (x - eps);
replace (x - eps + (m - x)) with (m - eps).
replace (x - eps + eps) with x.
elim H10; intros; assumption.
ring.
ring.
apply Rle_lt_trans with (m' - m).
unfold Rminus in |- *; do 2 rewrite <- (Rplus_comm (- m));
apply Rplus_le_compat_l; elim H14; intros; assumption.
apply Rplus_lt_reg_r with m; replace (m + (m' - m)) with m'.
apply Rle_lt_trans with (m + eps / 2).
unfold m' in |- *; apply Rmin_l.
apply Rplus_lt_compat_l; apply Rmult_lt_reg_l with 2.
prove_sup0.
unfold Rdiv in |- *; rewrite <- (Rmult_comm (/ 2)); rewrite <- Rmult_assoc;
rewrite <- Rinv_r_sym.
rewrite Rmult_1_l; pattern (pos eps) at 1 in |- *; rewrite <- Rplus_0_r;
rewrite double; apply Rplus_lt_compat_l; apply (cond_pos eps).
discrR.
ring.
unfold Db in |- *; right; reflexivity.
unfold family_finite in |- *; unfold domain_finite in |- *;
unfold covering_finite in H12; elim H12; clear H12;
intros; unfold family_finite in H13; unfold domain_finite in H13;
elim H13; clear H13; intros l H13; exists (cons y0 l);
intro; split.
intro; simpl in H14; unfold intersection_domain in H14; elim (H13 x0);
clear H13; intros; case (Req_dec x0 y0); intro.
simpl in |- *; left; apply H16.
simpl in |- *; right; apply H13; simpl in |- *;
unfold intersection_domain in |- *; unfold Db in H14;
decompose [and or] H14.
split; assumption.
elim H16; assumption.
intro; simpl in H14; elim H14; intro; simpl in |- *;
unfold intersection_domain in |- *.
split.
apply (cond_fam f0); rewrite H15; exists m; apply H6.
unfold Db in |- *; right; assumption.
elim (H13 x0); intros _ H16.
assert (H17 := H16 H15).
simpl in H17.
unfold intersection_domain in H17.
split.
elim H17; intros; assumption.
unfold Db in |- *; left; elim H17; intros; assumption.
elim (classic (exists x : R, A x /\ m - eps < x <= m)); intro.
assumption.
elim H3; intros; cut (is_upper_bound A (m - eps)).
intro; assert (H13 := H11 _ H12); cut (m - eps < m).
intro; elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H13 H14)).
pattern m at 2 in |- *; rewrite <- Rplus_0_r; unfold Rminus in |- *;
apply Rplus_lt_compat_l; apply Ropp_lt_cancel; rewrite Ropp_involutive;
rewrite Ropp_0; apply (cond_pos eps).
set (P := fun n:R => A n /\ m - eps < n <= m);
assert (H12 := not_ex_all_not _ P H9); unfold P in H12;
unfold is_upper_bound in |- *; intros;
assert (H14 := not_and_or _ _ (H12 x)); elim H14;
intro.
elim H15; apply H13.
elim (not_and_or _ _ H15); intro.
case (Rle_dec x (m - eps)); intro.
assumption.
elim H16; auto with real.
unfold is_upper_bound in H10; assert (H17 := H10 x H13); elim H16; apply H17.
elim H3; clear H3; intros.
unfold is_upper_bound in H3.
split.
apply (H3 _ H0).
apply (H4 b); unfold is_upper_bound in |- *; intros; unfold A in H5; elim H5;
clear H5; intros H5 _; elim H5; clear H5; intros _ H5;
apply H5.
exists a; apply H0.
unfold bound in |- *; exists b; unfold is_upper_bound in |- *; intros;
unfold A in H1; elim H1; clear H1; intros H1 _; elim H1;
clear H1; intros _ H1; apply H1.
unfold A in |- *; split.
split; [ right; reflexivity | apply r ].
unfold covering_open_set in H; elim H; clear H; intros; unfold covering in H;
cut (a <= a <= b).
intro; elim (H _ H1); intros y0 H2; set (D' := fun x:R => x = y0); exists D';
unfold covering_finite in |- *; split.
unfold covering in |- *; simpl in |- *; intros; cut (x = a).
intro; exists y0; split.
rewrite H4; apply H2.
unfold D' in |- *; reflexivity.
elim H3; intros; apply Rle_antisym; assumption.
unfold family_finite in |- *; unfold domain_finite in |- *;
exists (cons y0 nil); intro; split.
simpl in |- *; unfold intersection_domain in |- *; intro; elim H3; clear H3;
intros; unfold D' in H4; left; apply H4.
simpl in |- *; unfold intersection_domain in |- *; intro; elim H3; intro.
split; [ rewrite H4; apply (cond_fam f0); exists a; apply H2 | apply H4 ].
elim H4.
split; [ right; reflexivity | apply r ].
apply compact_eqDom with (fun c:R => False).
apply compact_EMP.
unfold eq_Dom in |- *; split.
unfold included in |- *; intros; elim H.
unfold included in |- *; intros; elim H; clear H; intros;
assert (H1 := Rle_trans _ _ _ H H0); elim n; apply H1.
Qed.
Lemma compact_P4 :
forall X F:R -> Prop, compact X -> closed_set F -> included F X -> compact F.
Proof.
unfold compact in |- *; intros; elim (classic (exists z : R, F z));
intro Hyp_F_NE.
set (D := ind f0); set (g := f f0); unfold closed_set in H0.
set (g' := fun x y:R => f0 x y \/ complementary F y /\ D x).
set (D' := D).
cut (forall x:R, (exists y : R, g' x y) -> D' x).
intro; set (f' := mkfamily D' g' H3); cut (covering_open_set X f').
intro; elim (H _ H4); intros DX H5; exists DX.
unfold covering_finite in |- *; unfold covering_finite in H5; elim H5;
clear H5; intros.
split.
unfold covering in |- *; unfold covering in H5; intros.
elim (H5 _ (H1 _ H7)); intros y0 H8; exists y0; simpl in H8; simpl in |- *;
elim H8; clear H8; intros.
split.
unfold g' in H8; elim H8; intro.
apply H10.
elim H10; intros H11 _; unfold complementary in H11; elim H11; apply H7.
apply H9.
unfold family_finite in |- *; unfold domain_finite in |- *;
unfold family_finite in H6; unfold domain_finite in H6;
elim H6; clear H6; intros l H6; exists l; intro; assert (H7 := H6 x);
elim H7; clear H7; intros.
split.
intro; apply H7; simpl in |- *; unfold intersection_domain in |- *;
simpl in H9; unfold intersection_domain in H9; unfold D' in |- *;
apply H9.
intro; assert (H10 := H8 H9); simpl in H10; unfold intersection_domain in H10;
simpl in |- *; unfold intersection_domain in |- *;
unfold D' in H10; apply H10.
unfold covering_open_set in |- *; unfold covering_open_set in H2; elim H2;
clear H2; intros.
split.
unfold covering in |- *; unfold covering in H2; intros.
elim (classic (F x)); intro.
elim (H2 _ H6); intros y0 H7; exists y0; simpl in |- *; unfold g' in |- *;
left; assumption.
cut (exists z : R, D z).
intro; elim H7; clear H7; intros x0 H7; exists x0; simpl in |- *;
unfold g' in |- *; right.
split.
unfold complementary in |- *; apply H6.
apply H7.
elim Hyp_F_NE; intros z0 H7.
assert (H8 := H2 _ H7).
elim H8; clear H8; intros t H8; exists t; apply (cond_fam f0); exists z0;
apply H8.
unfold family_open_set in |- *; intro; simpl in |- *; unfold g' in |- *;
elim (classic (D x)); intro.
apply open_set_P6 with (union_domain (f0 x) (complementary F)).
apply open_set_P2.
unfold family_open_set in H4; apply H4.
apply H0.
unfold eq_Dom in |- *; split.
unfold included, union_domain, complementary in |- *; intros.
elim H6; intro; [ left; apply H7 | right; split; assumption ].
unfold included, union_domain, complementary in |- *; intros.
elim H6; intro; [ left; apply H7 | right; elim H7; intros; apply H8 ].
apply open_set_P6 with (f0 x).
unfold family_open_set in H4; apply H4.
unfold eq_Dom in |- *; split.
unfold included, complementary in |- *; intros; left; apply H6.
unfold included, complementary in |- *; intros.
elim H6; intro.
apply H7.
elim H7; intros _ H8; elim H5; apply H8.
intros; elim H3; intros y0 H4; unfold g' in H4; elim H4; intro.
apply (cond_fam f0); exists y0; apply H5.
elim H5; clear H5; intros _ H5; apply H5.
(* Cas ou F est l'ensemble vide *)
cut (compact F).
intro; apply (H3 f0 H2).
apply compact_eqDom with (fun _:R => False).
apply compact_EMP.
unfold eq_Dom in |- *; split.
unfold included in |- *; intros; elim H3.
assert (H3 := not_ex_all_not _ _ Hyp_F_NE); unfold included in |- *; intros;
elim (H3 x); apply H4.
Qed.
(**********)
Lemma compact_P5 : forall X:R -> Prop, closed_set X -> bounded X -> compact X.
Proof.
intros; unfold bounded in H0.
elim H0; clear H0; intros m H0.
elim H0; clear H0; intros M H0.
assert (H1 := compact_P3 m M).
apply (compact_P4 (fun c:R => m <= c <= M) X H1 H H0).
Qed.
(**********)
Lemma compact_carac :
forall X:R -> Prop, compact X <-> closed_set X /\ bounded X.
Proof.
intro; split.
intro; split; [ apply (compact_P2 _ H) | apply (compact_P1 _ H) ].
intro; elim H; clear H; intros; apply (compact_P5 _ H H0).
Qed.
Definition image_dir (f:R -> R) (D:R -> Prop) (x:R) : Prop :=
exists y : R, x = f y /\ D y.
(**********)
Lemma continuity_compact :
forall (f:R -> R) (X:R -> Prop),
(forall x:R, continuity_pt f x) -> compact X -> compact (image_dir f X).
Proof.
unfold compact in |- *; intros; unfold covering_open_set in H1.
elim H1; clear H1; intros.
set (D := ind f1).
set (g := fun x y:R => image_rec f0 (f1 x) y).
cut (forall x:R, (exists y : R, g x y) -> D x).
intro; set (f' := mkfamily D g H3).
cut (covering_open_set X f').
intro; elim (H0 f' H4); intros D' H5; exists D'.
unfold covering_finite in H5; elim H5; clear H5; intros;
unfold covering_finite in |- *; split.
unfold covering, image_dir in |- *; simpl in |- *; unfold covering in H5;
intros; elim H7; intros y H8; elim H8; intros; assert (H11 := H5 _ H10);
simpl in H11; elim H11; intros z H12; exists z; unfold g in H12;
unfold image_rec in H12; rewrite H9; apply H12.
unfold family_finite in H6; unfold domain_finite in H6;
unfold family_finite in |- *; unfold domain_finite in |- *;
elim H6; intros l H7; exists l; intro; elim (H7 x);
intros; split; intro.
apply H8; simpl in H10; simpl in |- *; apply H10.
apply (H9 H10).
unfold covering_open_set in |- *; split.
unfold covering in |- *; intros; simpl in |- *; unfold covering in H1;
unfold image_dir in H1; unfold g in |- *; unfold image_rec in |- *;
apply H1.
exists x; split; [ reflexivity | apply H4 ].
unfold family_open_set in |- *; unfold family_open_set in H2; intro;
simpl in |- *; unfold g in |- *;
cut ((fun y:R => image_rec f0 (f1 x) y) = image_rec f0 (f1 x)).
intro; rewrite H4.
apply (continuity_P2 f0 (f1 x) H (H2 x)).
reflexivity.
intros; apply (cond_fam f1); unfold g in H3; unfold image_rec in H3; elim H3;
intros; exists (f0 x0); apply H4.
Qed.
Lemma Rlt_Rminus : forall a b:R, a < b -> 0 < b - a.
Proof.
intros; apply Rplus_lt_reg_r with a; rewrite Rplus_0_r;
replace (a + (b - a)) with b; [ assumption | ring ].
Qed.
Lemma prolongement_C0 :
forall (f:R -> R) (a b:R),
a <= b ->
(forall c:R, a <= c <= b -> continuity_pt f c) ->
exists g : R -> R,
continuity g /\ (forall c:R, a <= c <= b -> g c = f c).
Proof.
intros; elim H; intro.
set
(h :=
fun x:R =>
match Rle_dec x a with
| left _ => f0 a
| right _ =>
match Rle_dec x b with
| left _ => f0 x
| right _ => f0 b
end
end).
assert (H2 : 0 < b - a).
apply Rlt_Rminus; assumption.
exists h; split.
unfold continuity in |- *; intro; case (Rtotal_order x a); intro.
unfold continuity_pt in |- *; unfold continue_in in |- *;
unfold limit1_in in |- *; unfold limit_in in |- *;
simpl in |- *; unfold R_dist in |- *; intros; exists (a - x);
split.
change (0 < a - x) in |- *; apply Rlt_Rminus; assumption.
intros; elim H5; clear H5; intros _ H5; unfold h in |- *.
case (Rle_dec x a); intro.
case (Rle_dec x0 a); intro.
unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0; assumption.
elim n; left; apply Rplus_lt_reg_r with (- x);
do 2 rewrite (Rplus_comm (- x)); apply Rle_lt_trans with (Rabs (x0 - x)).
apply RRle_abs.
assumption.
elim n; left; assumption.
elim H3; intro.
assert (H5 : a <= a <= b).
split; [ right; reflexivity | left; assumption ].
assert (H6 := H0 _ H5); unfold continuity_pt in H6; unfold continue_in in H6;
unfold limit1_in in H6; unfold limit_in in H6; simpl in H6;
unfold R_dist in H6; unfold continuity_pt in |- *;
unfold continue_in in |- *; unfold limit1_in in |- *;
unfold limit_in in |- *; simpl in |- *; unfold R_dist in |- *;
intros; elim (H6 _ H7); intros; exists (Rmin x0 (b - a));
split.
unfold Rmin in |- *; case (Rle_dec x0 (b - a)); intro.
elim H8; intros; assumption.
change (0 < b - a) in |- *; apply Rlt_Rminus; assumption.
intros; elim H9; clear H9; intros _ H9; cut (x1 < b).
intro; unfold h in |- *; case (Rle_dec x a); intro.
case (Rle_dec x1 a); intro.
unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0; assumption.
case (Rle_dec x1 b); intro.
elim H8; intros; apply H12; split.
unfold D_x, no_cond in |- *; split.
trivial.
red in |- *; intro; elim n; right; symmetry in |- *; assumption.
apply Rlt_le_trans with (Rmin x0 (b - a)).
rewrite H4 in H9; apply H9.
apply Rmin_l.
elim n0; left; assumption.
elim n; right; assumption.
apply Rplus_lt_reg_r with (- a); do 2 rewrite (Rplus_comm (- a));
rewrite H4 in H9; apply Rle_lt_trans with (Rabs (x1 - a)).
apply RRle_abs.
apply Rlt_le_trans with (Rmin x0 (b - a)).
assumption.
apply Rmin_r.
case (Rtotal_order x b); intro.
assert (H6 : a <= x <= b).
split; left; assumption.
assert (H7 := H0 _ H6); unfold continuity_pt in H7; unfold continue_in in H7;
unfold limit1_in in H7; unfold limit_in in H7; simpl in H7;
unfold R_dist in H7; unfold continuity_pt in |- *;
unfold continue_in in |- *; unfold limit1_in in |- *;
unfold limit_in in |- *; simpl in |- *; unfold R_dist in |- *;
intros; elim (H7 _ H8); intros; elim H9; clear H9;
intros.
assert (H11 : 0 < x - a).
apply Rlt_Rminus; assumption.
assert (H12 : 0 < b - x).
apply Rlt_Rminus; assumption.
exists (Rmin x0 (Rmin (x - a) (b - x))); split.
unfold Rmin in |- *; case (Rle_dec (x - a) (b - x)); intro.
case (Rle_dec x0 (x - a)); intro.
assumption.
assumption.
case (Rle_dec x0 (b - x)); intro.
assumption.
assumption.
intros; elim H13; clear H13; intros; cut (a < x1 < b).
intro; elim H15; clear H15; intros; unfold h in |- *; case (Rle_dec x a);
intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ r H4)).
case (Rle_dec x b); intro.
case (Rle_dec x1 a); intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ r0 H15)).
case (Rle_dec x1 b); intro.
apply H10; split.
assumption.
apply Rlt_le_trans with (Rmin x0 (Rmin (x - a) (b - x))).
assumption.
apply Rmin_l.
elim n1; left; assumption.
elim n0; left; assumption.
split.
apply Ropp_lt_cancel; apply Rplus_lt_reg_r with x;
apply Rle_lt_trans with (Rabs (x1 - x)).
rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply RRle_abs.
apply Rlt_le_trans with (Rmin x0 (Rmin (x - a) (b - x))).
assumption.
apply Rle_trans with (Rmin (x - a) (b - x)).
apply Rmin_r.
apply Rmin_l.
apply Rplus_lt_reg_r with (- x); do 2 rewrite (Rplus_comm (- x));
apply Rle_lt_trans with (Rabs (x1 - x)).
apply RRle_abs.
apply Rlt_le_trans with (Rmin x0 (Rmin (x - a) (b - x))).
assumption.
apply Rle_trans with (Rmin (x - a) (b - x)); apply Rmin_r.
elim H5; intro.
assert (H7 : a <= b <= b).
split; [ left; assumption | right; reflexivity ].
assert (H8 := H0 _ H7); unfold continuity_pt in H8; unfold continue_in in H8;
unfold limit1_in in H8; unfold limit_in in H8; simpl in H8;
unfold R_dist in H8; unfold continuity_pt in |- *;
unfold continue_in in |- *; unfold limit1_in in |- *;
unfold limit_in in |- *; simpl in |- *; unfold R_dist in |- *;
intros; elim (H8 _ H9); intros; exists (Rmin x0 (b - a));
split.
unfold Rmin in |- *; case (Rle_dec x0 (b - a)); intro.
elim H10; intros; assumption.
change (0 < b - a) in |- *; apply Rlt_Rminus; assumption.
intros; elim H11; clear H11; intros _ H11; cut (a < x1).
intro; unfold h in |- *; case (Rle_dec x a); intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ r H4)).
case (Rle_dec x1 a); intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ r H12)).
case (Rle_dec x b); intro.
case (Rle_dec x1 b); intro.
rewrite H6; elim H10; intros; elim r0; intro.
apply H14; split.
unfold D_x, no_cond in |- *; split.
trivial.
red in |- *; intro; rewrite <- H16 in H15; elim (Rlt_irrefl _ H15).
rewrite H6 in H11; apply Rlt_le_trans with (Rmin x0 (b - a)).
apply H11.
apply Rmin_l.
rewrite H15; unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0;
assumption.
rewrite H6; unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0;
assumption.
elim n1; right; assumption.
rewrite H6 in H11; apply Ropp_lt_cancel; apply Rplus_lt_reg_r with b;
apply Rle_lt_trans with (Rabs (x1 - b)).
rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply RRle_abs.
apply Rlt_le_trans with (Rmin x0 (b - a)).
assumption.
apply Rmin_r.
unfold continuity_pt in |- *; unfold continue_in in |- *;
unfold limit1_in in |- *; unfold limit_in in |- *;
simpl in |- *; unfold R_dist in |- *; intros; exists (x - b);
split.
change (0 < x - b) in |- *; apply Rlt_Rminus; assumption.
intros; elim H8; clear H8; intros.
assert (H10 : b < x0).
apply Ropp_lt_cancel; apply Rplus_lt_reg_r with x;
apply Rle_lt_trans with (Rabs (x0 - x)).
rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply RRle_abs.
assumption.
unfold h in |- *; case (Rle_dec x a); intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ r H4)).
case (Rle_dec x b); intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ r H6)).
case (Rle_dec x0 a); intro.
elim (Rlt_irrefl _ (Rlt_trans _ _ _ H1 (Rlt_le_trans _ _ _ H10 r))).
case (Rle_dec x0 b); intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ r H10)).
unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0; assumption.
intros; elim H3; intros; unfold h in |- *; case (Rle_dec c a); intro.
elim r; intro.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H4 H6)).
rewrite H6; reflexivity.
case (Rle_dec c b); intro.
reflexivity.
elim n0; assumption.
exists (fun _:R => f0 a); split.
apply derivable_continuous; apply (derivable_const (f0 a)).
intros; elim H2; intros; rewrite H1 in H3; cut (b = c).
intro; rewrite <- H5; rewrite H1; reflexivity.
apply Rle_antisym; assumption.
Qed.
(**********)
Lemma continuity_ab_maj :
forall (f:R -> R) (a b:R),
a <= b ->
(forall c:R, a <= c <= b -> continuity_pt f c) ->
exists Mx : R, (forall c:R, a <= c <= b -> f c <= f Mx) /\ a <= Mx <= b.
Proof.
intros;
cut
(exists g : R -> R,
continuity g /\ (forall c:R, a <= c <= b -> g c = f0 c)).
intro HypProl.
elim HypProl; intros g Hcont_eq.
elim Hcont_eq; clear Hcont_eq; intros Hcont Heq.
assert (H1 := compact_P3 a b).
assert (H2 := continuity_compact g (fun c:R => a <= c <= b) Hcont H1).
assert (H3 := compact_P2 _ H2).
assert (H4 := compact_P1 _ H2).
cut (bound (image_dir g (fun c:R => a <= c <= b))).
cut (exists x : R, image_dir g (fun c:R => a <= c <= b) x).
intros; assert (H7 := completeness _ H6 H5).
elim H7; clear H7; intros M H7; cut (image_dir g (fun c:R => a <= c <= b) M).
intro; unfold image_dir in H8; elim H8; clear H8; intros Mxx H8; elim H8;
clear H8; intros; exists Mxx; split.
intros; rewrite <- (Heq c H10); rewrite <- (Heq Mxx H9); intros;
rewrite <- H8; unfold is_lub in H7; elim H7; clear H7;
intros H7 _; unfold is_upper_bound in H7; apply H7;
unfold image_dir in |- *; exists c; split; [ reflexivity | apply H10 ].
apply H9.
elim (classic (image_dir g (fun c:R => a <= c <= b) M)); intro.
assumption.
cut
(exists eps : posreal,
(forall y:R,
~
intersection_domain (disc M eps)
(image_dir g (fun c:R => a <= c <= b)) y)).
intro; elim H9; clear H9; intros eps H9; unfold is_lub in H7; elim H7;
clear H7; intros;
cut (is_upper_bound (image_dir g (fun c:R => a <= c <= b)) (M - eps)).
intro; assert (H12 := H10 _ H11); cut (M - eps < M).
intro; elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H12 H13)).
pattern M at 2 in |- *; rewrite <- Rplus_0_r; unfold Rminus in |- *;
apply Rplus_lt_compat_l; apply Ropp_lt_cancel; rewrite Ropp_0;
rewrite Ropp_involutive; apply (cond_pos eps).
unfold is_upper_bound, image_dir in |- *; intros; cut (x <= M).
intro; case (Rle_dec x (M - eps)); intro.
apply r.
elim (H9 x); unfold intersection_domain, disc, image_dir in |- *; split.
rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; rewrite Rabs_right.
apply Rplus_lt_reg_r with (x - eps);
replace (x - eps + (M - x)) with (M - eps).
replace (x - eps + eps) with x.
auto with real.
ring.
ring.
apply Rge_minus; apply Rle_ge; apply H12.
apply H11.
apply H7; apply H11.
cut
(exists V : R -> Prop,
neighbourhood V M /\
(forall y:R,
~ intersection_domain V (image_dir g (fun c:R => a <= c <= b)) y)).
intro; elim H9; intros V H10; elim H10; clear H10; intros.
unfold neighbourhood in H10; elim H10; intros del H12; exists del; intros;
red in |- *; intro; elim (H11 y).
unfold intersection_domain in |- *; unfold intersection_domain in H13;
elim H13; clear H13; intros; split.
apply (H12 _ H13).
apply H14.
cut (~ point_adherent (image_dir g (fun c:R => a <= c <= b)) M).
intro; unfold point_adherent in H9.
assert
(H10 :=
not_all_ex_not _
(fun V:R -> Prop =>
neighbourhood V M ->
exists y : R,
intersection_domain V (image_dir g (fun c:R => a <= c <= b)) y) H9).
elim H10; intros V0 H11; exists V0; assert (H12 := imply_to_and _ _ H11);
elim H12; clear H12; intros.
split.
apply H12.
apply (not_ex_all_not _ _ H13).
red in |- *; intro; cut (adherence (image_dir g (fun c:R => a <= c <= b)) M).
intro; elim (closed_set_P1 (image_dir g (fun c:R => a <= c <= b)));
intros H11 _; assert (H12 := H11 H3).
elim H8.
unfold eq_Dom in H12; elim H12; clear H12; intros.
apply (H13 _ H10).
apply H9.
exists (g a); unfold image_dir in |- *; exists a; split.
reflexivity.
split; [ right; reflexivity | apply H ].
unfold bound in |- *; unfold bounded in H4; elim H4; clear H4; intros m H4;
elim H4; clear H4; intros M H4; exists M; unfold is_upper_bound in |- *;
intros; elim (H4 _ H5); intros _ H6; apply H6.
apply prolongement_C0; assumption.
Qed.
(**********)
Lemma continuity_ab_min :
forall (f:R -> R) (a b:R),
a <= b ->
(forall c:R, a <= c <= b -> continuity_pt f c) ->
exists mx : R, (forall c:R, a <= c <= b -> f mx <= f c) /\ a <= mx <= b.
Proof.
intros.
cut (forall c:R, a <= c <= b -> continuity_pt (- f0) c).
intro; assert (H2 := continuity_ab_maj (- f0)%F a b H H1); elim H2;
intros x0 H3; exists x0; intros; split.
intros; rewrite <- (Ropp_involutive (f0 x0));
rewrite <- (Ropp_involutive (f0 c)); apply Ropp_le_contravar;
elim H3; intros; unfold opp_fct in H5; apply H5; apply H4.
elim H3; intros; assumption.
intros.
assert (H2 := H0 _ H1).
apply (continuity_pt_opp _ _ H2).
Qed.
(********************************************************)
(** * Proof of Bolzano-Weierstrass theorem *)
(********************************************************)
Definition ValAdh (un:nat -> R) (x:R) : Prop :=
forall (V:R -> Prop) (N:nat),
neighbourhood V x -> exists p : nat, (N <= p)%nat /\ V (un p).
Definition intersection_family (f:family) (x:R) : Prop :=
forall y:R, ind f y -> f y x.
Lemma ValAdh_un_exists :
forall (un:nat -> R) (D:=fun x:R => exists n : nat, x = INR n)
(f:=
fun x:R =>
adherence
(fun y:R => (exists p : nat, y = un p /\ x <= INR p) /\ D x))
(x:R), (exists y : R, f x y) -> D x.
Proof.
intros; elim H; intros; unfold f in H0; unfold adherence in H0;
unfold point_adherent in H0;
assert (H1 : neighbourhood (disc x0 (mkposreal _ Rlt_0_1)) x0).
unfold neighbourhood, disc in |- *; exists (mkposreal _ Rlt_0_1);
unfold included in |- *; trivial.
elim (H0 _ H1); intros; unfold intersection_domain in H2; elim H2; intros;
elim H4; intros; apply H6.
Qed.
Definition ValAdh_un (un:nat -> R) : R -> Prop :=
let D := fun x:R => exists n : nat, x = INR n in
let f :=
fun x:R =>
adherence
(fun y:R => (exists p : nat, y = un p /\ x <= INR p) /\ D x) in
intersection_family (mkfamily D f (ValAdh_un_exists un)).
Lemma ValAdh_un_prop :
forall (un:nat -> R) (x:R), ValAdh un x <-> ValAdh_un un x.
Proof.
intros; split; intro.
unfold ValAdh in H; unfold ValAdh_un in |- *;
unfold intersection_family in |- *; simpl in |- *;
intros; elim H0; intros N H1; unfold adherence in |- *;
unfold point_adherent in |- *; intros; elim (H V N H2);
intros; exists (un x0); unfold intersection_domain in |- *;
elim H3; clear H3; intros; split.
assumption.
split.
exists x0; split; [ reflexivity | rewrite H1; apply (le_INR _ _ H3) ].
exists N; assumption.
unfold ValAdh in |- *; intros; unfold ValAdh_un in H;
unfold intersection_family in H; simpl in H;
assert
(H1 :
adherence
(fun y0:R =>
(exists p : nat, y0 = un p /\ INR N <= INR p) /\
(exists n : nat, INR N = INR n)) x).
apply H; exists N; reflexivity.
unfold adherence in H1; unfold point_adherent in H1; assert (H2 := H1 _ H0);
elim H2; intros; unfold intersection_domain in H3;
elim H3; clear H3; intros; elim H4; clear H4; intros;
elim H4; clear H4; intros; elim H4; clear H4; intros;
exists x1; split.
apply (INR_le _ _ H6).
rewrite H4 in H3; apply H3.
Qed.
Lemma adherence_P4 :
forall F G:R -> Prop, included F G -> included (adherence F) (adherence G).
Proof.
unfold adherence, included in |- *; unfold point_adherent in |- *; intros;
elim (H0 _ H1); unfold intersection_domain in |- *;
intros; elim H2; clear H2; intros; exists x0; split;
[ assumption | apply (H _ H3) ].
Qed.
Definition family_closed_set (f:family) : Prop :=
forall x:R, closed_set (f x).
Definition intersection_vide_in (D:R -> Prop) (f:family) : Prop :=
forall x:R,
(ind f x -> included (f x) D) /\
~ (exists y : R, intersection_family f y).
Definition intersection_vide_finite_in (D:R -> Prop)
(f:family) : Prop := intersection_vide_in D f /\ family_finite f.
(**********)
Lemma compact_P6 :
forall X:R -> Prop,
compact X ->
(exists z : R, X z) ->
forall g:family,
family_closed_set g ->
intersection_vide_in X g ->
exists D : R -> Prop, intersection_vide_finite_in X (subfamily g D).
Proof.
intros X H Hyp g H0 H1.
set (D' := ind g).
set (f' := fun x y:R => complementary (g x) y /\ D' x).
assert (H2 : forall x:R, (exists y : R, f' x y) -> D' x).
intros; elim H2; intros; unfold f' in H3; elim H3; intros; assumption.
set (f0 := mkfamily D' f' H2).
unfold compact in H; assert (H3 : covering_open_set X f0).
unfold covering_open_set in |- *; split.
unfold covering in |- *; intros; unfold intersection_vide_in in H1;
elim (H1 x); intros; unfold intersection_family in H5;
assert
(H6 := not_ex_all_not _ (fun y:R => forall y0:R, ind g y0 -> g y0 y) H5 x);
assert (H7 := not_all_ex_not _ (fun y0:R => ind g y0 -> g y0 x) H6);
elim H7; intros; exists x0; elim (imply_to_and _ _ H8);
intros; unfold f0 in |- *; simpl in |- *; unfold f' in |- *;
split; [ apply H10 | apply H9 ].
unfold family_open_set in |- *; intro; elim (classic (D' x)); intro.
apply open_set_P6 with (complementary (g x)).
unfold family_closed_set in H0; unfold closed_set in H0; apply H0.
unfold f0 in |- *; simpl in |- *; unfold f' in |- *; unfold eq_Dom in |- *;
split.
unfold included in |- *; intros; split; [ apply H4 | apply H3 ].
unfold included in |- *; intros; elim H4; intros; assumption.
apply open_set_P6 with (fun _:R => False).
apply open_set_P4.
unfold eq_Dom in |- *; unfold included in |- *; split; intros;
[ elim H4
| simpl in H4; unfold f' in H4; elim H4; intros; elim H3; assumption ].
elim (H _ H3); intros SF H4; exists SF;
unfold intersection_vide_finite_in in |- *; split.
unfold intersection_vide_in in |- *; simpl in |- *; intros; split.
intros; unfold included in |- *; intros; unfold intersection_vide_in in H1;
elim (H1 x); intros; elim H6; intros; apply H7.
unfold intersection_domain in H5; elim H5; intros; assumption.
assumption.
elim (classic (exists y : R, intersection_domain (ind g) SF y)); intro Hyp'.
red in |- *; intro; elim H5; intros; unfold intersection_family in H6;
simpl in H6.
cut (X x0).
intro; unfold covering_finite in H4; elim H4; clear H4; intros H4 _;
unfold covering in H4; elim (H4 x0 H7); intros; simpl in H8;
unfold intersection_domain in H6; cut (ind g x1 /\ SF x1).
intro; assert (H10 := H6 x1 H9); elim H10; clear H10; intros H10 _; elim H8;
clear H8; intros H8 _; unfold f' in H8; unfold complementary in H8;
elim H8; clear H8; intros H8 _; elim H8; assumption.
split.
apply (cond_fam f0).
exists x0; elim H8; intros; assumption.
elim H8; intros; assumption.
unfold intersection_vide_in in H1; elim Hyp'; intros; assert (H8 := H6 _ H7);
elim H8; intros; cut (ind g x1).
intro; elim (H1 x1); intros; apply H12.
apply H11.
apply H9.
apply (cond_fam g); exists x0; assumption.
unfold covering_finite in H4; elim H4; clear H4; intros H4 _;
cut (exists z : R, X z).
intro; elim H5; clear H5; intros; unfold covering in H4; elim (H4 x0 H5);
intros; simpl in H6; elim Hyp'; exists x1; elim H6;
intros; unfold intersection_domain in |- *; split.
apply (cond_fam f0); exists x0; apply H7.
apply H8.
apply Hyp.
unfold covering_finite in H4; elim H4; clear H4; intros;
unfold family_finite in H5; unfold domain_finite in H5;
unfold family_finite in |- *; unfold domain_finite in |- *;
elim H5; clear H5; intros l H5; exists l; intro; elim (H5 x);
intros; split; intro;
[ apply H6; simpl in |- *; simpl in H8; apply H8 | apply (H7 H8) ].
Qed.
Theorem Bolzano_Weierstrass :
forall (un:nat -> R) (X:R -> Prop),
compact X -> (forall n:nat, X (un n)) -> exists l : R, ValAdh un l.
Proof.
intros; cut (exists l : R, ValAdh_un un l).
intro; elim H1; intros; exists x; elim (ValAdh_un_prop un x); intros;
apply (H4 H2).
assert (H1 : exists z : R, X z).
exists (un 0%nat); apply H0.
set (D := fun x:R => exists n : nat, x = INR n).
set
(g :=
fun x:R =>
adherence (fun y:R => (exists p : nat, y = un p /\ x <= INR p) /\ D x)).
assert (H2 : forall x:R, (exists y : R, g x y) -> D x).
intros; elim H2; intros; unfold g in H3; unfold adherence in H3;
unfold point_adherent in H3.
assert (H4 : neighbourhood (disc x0 (mkposreal _ Rlt_0_1)) x0).
unfold neighbourhood in |- *; exists (mkposreal _ Rlt_0_1);
unfold included in |- *; trivial.
elim (H3 _ H4); intros; unfold intersection_domain in H5; decompose [and] H5;
assumption.
set (f0 := mkfamily D g H2).
assert (H3 := compact_P6 X H H1 f0).
elim (classic (exists l : R, ValAdh_un un l)); intro.
assumption.
cut (family_closed_set f0).
intro; cut (intersection_vide_in X f0).
intro; assert (H7 := H3 H5 H6).
elim H7; intros SF H8; unfold intersection_vide_finite_in in H8; elim H8;
clear H8; intros; unfold intersection_vide_in in H8;
elim (H8 0); intros _ H10; elim H10; unfold family_finite in H9;
unfold domain_finite in H9; elim H9; clear H9; intros l H9;
set (r := MaxRlist l); cut (D r).
intro; unfold D in H11; elim H11; intros; exists (un x);
unfold intersection_family in |- *; simpl in |- *;
unfold intersection_domain in |- *; intros; split.
unfold g in |- *; apply adherence_P1; split.
exists x; split;
[ reflexivity
| rewrite <- H12; unfold r in |- *; apply MaxRlist_P1; elim (H9 y); intros;
apply H14; simpl in |- *; apply H13 ].
elim H13; intros; assumption.
elim H13; intros; assumption.
elim (H9 r); intros.
simpl in H12; unfold intersection_domain in H12; cut (In r l).
intro; elim (H12 H13); intros; assumption.
unfold r in |- *; apply MaxRlist_P2;
cut (exists z : R, intersection_domain (ind f0) SF z).
intro; elim H13; intros; elim (H9 x); intros; simpl in H15;
assert (H17 := H15 H14); exists x; apply H17.
elim (classic (exists z : R, intersection_domain (ind f0) SF z)); intro.
assumption.
elim (H8 0); intros _ H14; elim H1; intros;
assert
(H16 :=
not_ex_all_not _ (fun y:R => intersection_family (subfamily f0 SF) y) H14);
assert
(H17 :=
not_ex_all_not _ (fun z:R => intersection_domain (ind f0) SF z) H13);
assert (H18 := H16 x); unfold intersection_family in H18;
simpl in H18;
assert
(H19 :=
not_all_ex_not _ (fun y:R => intersection_domain D SF y -> g y x /\ SF y)
H18); elim H19; intros; assert (H21 := imply_to_and _ _ H20);
elim (H17 x0); elim H21; intros; assumption.
unfold intersection_vide_in in |- *; intros; split.
intro; simpl in H6; unfold f0 in |- *; simpl in |- *; unfold g in |- *;
apply included_trans with (adherence X).
apply adherence_P4.
unfold included in |- *; intros; elim H7; intros; elim H8; intros; elim H10;
intros; rewrite H11; apply H0.
apply adherence_P2; apply compact_P2; assumption.
apply H4.
unfold family_closed_set in |- *; unfold f0 in |- *; simpl in |- *;
unfold g in |- *; intro; apply adherence_P3.
Qed.
(********************************************************)
(** * Proof of Heine's theorem *)
(********************************************************)
Definition uniform_continuity (f:R -> R) (X:R -> Prop) : Prop :=
forall eps:posreal,
exists delta : posreal,
(forall x y:R,
X x -> X y -> Rabs (x - y) < delta -> Rabs (f x - f y) < eps).
Lemma is_lub_u :
forall (E:R -> Prop) (x y:R), is_lub E x -> is_lub E y -> x = y.
Proof.
unfold is_lub in |- *; intros; elim H; elim H0; intros; apply Rle_antisym;
[ apply (H4 _ H1) | apply (H2 _ H3) ].
Qed.
Lemma domain_P1 :
forall X:R -> Prop,
~ (exists y : R, X y) \/
(exists y : R, X y /\ (forall x:R, X x -> x = y)) \/
(exists x : R, (exists y : R, X x /\ X y /\ x <> y)).
Proof.
intro; elim (classic (exists y : R, X y)); intro.
right; elim H; intros; elim (classic (exists y : R, X y /\ y <> x)); intro.
right; elim H1; intros; elim H2; intros; exists x; exists x0; intros.
split;
[ assumption
| split; [ assumption | apply (sym_not_eq (A:=R)); assumption ] ].
left; exists x; split.
assumption.
intros; case (Req_dec x0 x); intro.
assumption.
elim H1; exists x0; split; assumption.
left; assumption.
Qed.
Theorem Heine :
forall (f:R -> R) (X:R -> Prop),
compact X ->
(forall x:R, X x -> continuity_pt f x) -> uniform_continuity f X.
Proof.
intros f0 X H0 H; elim (domain_P1 X); intro Hyp.
(* X is empty *)
unfold uniform_continuity in |- *; intros; exists (mkposreal _ Rlt_0_1);
intros; elim Hyp; exists x; assumption.
elim Hyp; clear Hyp; intro Hyp.
(* X has only one element *)
unfold uniform_continuity in |- *; intros; exists (mkposreal _ Rlt_0_1);
intros; elim Hyp; clear Hyp; intros; elim H4; clear H4;
intros; assert (H6 := H5 _ H1); assert (H7 := H5 _ H2);
rewrite H6; rewrite H7; unfold Rminus in |- *; rewrite Rplus_opp_r;
rewrite Rabs_R0; apply (cond_pos eps).
(* X has at least two distinct elements *)
assert
(X_enc :
exists m : R, (exists M : R, (forall x:R, X x -> m <= x <= M) /\ m < M)).
assert (H1 := compact_P1 X H0); unfold bounded in H1; elim H1; intros;
elim H2; intros; exists x; exists x0; split.
apply H3.
elim Hyp; intros; elim H4; intros; decompose [and] H5;
assert (H10 := H3 _ H6); assert (H11 := H3 _ H8);
elim H10; intros; elim H11; intros; case (total_order_T x x0);
intro.
elim s; intro.
assumption.
rewrite b in H13; rewrite b in H7; elim H9; apply Rle_antisym;
apply Rle_trans with x0; assumption.
elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ (Rle_trans _ _ _ H13 H14) r)).
elim X_enc; clear X_enc; intros m X_enc; elim X_enc; clear X_enc;
intros M X_enc; elim X_enc; clear X_enc Hyp; intros X_enc Hyp;
unfold uniform_continuity in |- *; intro;
assert (H1 : forall t:posreal, 0 < t / 2).
intro; unfold Rdiv in |- *; apply Rmult_lt_0_compat;
[ apply (cond_pos t) | apply Rinv_0_lt_compat; prove_sup0 ].
set
(g :=
fun x y:R =>
X x /\
(exists del : posreal,
(forall z:R, Rabs (z - x) < del -> Rabs (f0 z - f0 x) < eps / 2) /\
is_lub
(fun zeta:R =>
0 < zeta <= M - m /\
(forall z:R, Rabs (z - x) < zeta -> Rabs (f0 z - f0 x) < eps / 2))
del /\ disc x (mkposreal (del / 2) (H1 del)) y)).
assert (H2 : forall x:R, (exists y : R, g x y) -> X x).
intros; elim H2; intros; unfold g in H3; elim H3; clear H3; intros H3 _;
apply H3.
set (f' := mkfamily X g H2); unfold compact in H0;
assert (H3 : covering_open_set X f').
unfold covering_open_set in |- *; split.
unfold covering in |- *; intros; exists x; simpl in |- *; unfold g in |- *;
split.
assumption.
assert (H4 := H _ H3); unfold continuity_pt in H4; unfold continue_in in H4;
unfold limit1_in in H4; unfold limit_in in H4; simpl in H4;
unfold R_dist in H4; elim (H4 (eps / 2) (H1 eps));
intros;
set
(E :=
fun zeta:R =>
0 < zeta <= M - m /\
(forall z:R, Rabs (z - x) < zeta -> Rabs (f0 z - f0 x) < eps / 2));
assert (H6 : bound E).
unfold bound in |- *; exists (M - m); unfold is_upper_bound in |- *;
unfold E in |- *; intros; elim H6; clear H6; intros H6 _;
elim H6; clear H6; intros _ H6; apply H6.
assert (H7 : exists x : R, E x).
elim H5; clear H5; intros; exists (Rmin x0 (M - m)); unfold E in |- *; intros;
split.
split.
unfold Rmin in |- *; case (Rle_dec x0 (M - m)); intro.
apply H5.
apply Rlt_Rminus; apply Hyp.
apply Rmin_r.
intros; case (Req_dec x z); intro.
rewrite H9; unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0;
apply (H1 eps).
apply H7; split.
unfold D_x, no_cond in |- *; split; [ trivial | assumption ].
apply Rlt_le_trans with (Rmin x0 (M - m)); [ apply H8 | apply Rmin_l ].
assert (H8 := completeness _ H6 H7); elim H8; clear H8; intros;
cut (0 < x1 <= M - m).
intro; elim H8; clear H8; intros; exists (mkposreal _ H8); split.
intros; cut (exists alp : R, Rabs (z - x) < alp <= x1 /\ E alp).
intros; elim H11; intros; elim H12; clear H12; intros; unfold E in H13;
elim H13; intros; apply H15.
elim H12; intros; assumption.
elim (classic (exists alp : R, Rabs (z - x) < alp <= x1 /\ E alp)); intro.
assumption.
assert
(H12 :=
not_ex_all_not _ (fun alp:R => Rabs (z - x) < alp <= x1 /\ E alp) H11);
unfold is_lub in p; elim p; intros; cut (is_upper_bound E (Rabs (z - x))).
intro; assert (H16 := H14 _ H15);
elim (Rlt_irrefl _ (Rlt_le_trans _ _ _ H10 H16)).
unfold is_upper_bound in |- *; intros; unfold is_upper_bound in H13;
assert (H16 := H13 _ H15); case (Rle_dec x2 (Rabs (z - x)));
intro.
assumption.
elim (H12 x2); split; [ split; [ auto with real | assumption ] | assumption ].
split.
apply p.
unfold disc in |- *; unfold Rminus in |- *; rewrite Rplus_opp_r;
rewrite Rabs_R0; simpl in |- *; unfold Rdiv in |- *;
apply Rmult_lt_0_compat; [ apply H8 | apply Rinv_0_lt_compat; prove_sup0 ].
elim H7; intros; unfold E in H8; elim H8; intros H9 _; elim H9; intros H10 _;
unfold is_lub in p; elim p; intros; unfold is_upper_bound in H12;
unfold is_upper_bound in H11; split.
apply Rlt_le_trans with x2; [ assumption | apply (H11 _ H8) ].
apply H12; intros; unfold E in H13; elim H13; intros; elim H14; intros;
assumption.
unfold family_open_set in |- *; intro; simpl in |- *; elim (classic (X x));
intro.
unfold g in |- *; unfold open_set in |- *; intros; elim H4; clear H4;
intros _ H4; elim H4; clear H4; intros; elim H4; clear H4;
intros; unfold neighbourhood in |- *; case (Req_dec x x0);
intro.
exists (mkposreal _ (H1 x1)); rewrite <- H6; unfold included in |- *; intros;
split.
assumption.
exists x1; split.
apply H4.
split.
elim H5; intros; apply H8.
apply H7.
set (d := x1 / 2 - Rabs (x0 - x)); assert (H7 : 0 < d).
unfold d in |- *; apply Rlt_Rminus; elim H5; clear H5; intros;
unfold disc in H7; apply H7.
exists (mkposreal _ H7); unfold included in |- *; intros; split.
assumption.
exists x1; split.
apply H4.
elim H5; intros; split.
assumption.
unfold disc in H8; simpl in H8; unfold disc in |- *; simpl in |- *;
unfold disc in H10; simpl in H10;
apply Rle_lt_trans with (Rabs (x2 - x0) + Rabs (x0 - x)).
replace (x2 - x) with (x2 - x0 + (x0 - x)); [ apply Rabs_triang | ring ].
replace (x1 / 2) with (d + Rabs (x0 - x)); [ idtac | unfold d in |- *; ring ].
do 2 rewrite <- (Rplus_comm (Rabs (x0 - x))); apply Rplus_lt_compat_l;
apply H8.
apply open_set_P6 with (fun _:R => False).
apply open_set_P4.
unfold eq_Dom in |- *; unfold included in |- *; intros; split.
intros; elim H4.
intros; unfold g in H4; elim H4; clear H4; intros H4 _; elim H3; apply H4.
elim (H0 _ H3); intros DF H4; unfold covering_finite in H4; elim H4; clear H4;
intros; unfold family_finite in H5; unfold domain_finite in H5;
unfold covering in H4; simpl in H4; simpl in H5; elim H5;
clear H5; intros l H5; unfold intersection_domain in H5;
cut
(forall x:R,
In x l ->
exists del : R,
0 < del /\
(forall z:R, Rabs (z - x) < del -> Rabs (f0 z - f0 x) < eps / 2) /\
included (g x) (fun z:R => Rabs (z - x) < del / 2)).
intros;
assert
(H7 :=
Rlist_P1 l
(fun x del:R =>
0 < del /\
(forall z:R, Rabs (z - x) < del -> Rabs (f0 z - f0 x) < eps / 2) /\
included (g x) (fun z:R => Rabs (z - x) < del / 2)) H6);
elim H7; clear H7; intros l' H7; elim H7; clear H7;
intros; set (D := MinRlist l'); cut (0 < D / 2).
intro; exists (mkposreal _ H9); intros; assert (H13 := H4 _ H10); elim H13;
clear H13; intros xi H13; assert (H14 : In xi l).
unfold g in H13; decompose [and] H13; elim (H5 xi); intros; apply H14; split;
assumption.
elim (pos_Rl_P2 l xi); intros H15 _; elim (H15 H14); intros i H16; elim H16;
intros; apply Rle_lt_trans with (Rabs (f0 x - f0 xi) + Rabs (f0 xi - f0 y)).
replace (f0 x - f0 y) with (f0 x - f0 xi + (f0 xi - f0 y));
[ apply Rabs_triang | ring ].
rewrite (double_var eps); apply Rplus_lt_compat.
assert (H19 := H8 i H17); elim H19; clear H19; intros; rewrite <- H18 in H20;
elim H20; clear H20; intros; apply H20; unfold included in H21;
apply Rlt_trans with (pos_Rl l' i / 2).
apply H21.
elim H13; clear H13; intros; assumption.
unfold Rdiv in |- *; apply Rmult_lt_reg_l with 2.
prove_sup0.
rewrite Rmult_comm; rewrite Rmult_assoc; rewrite <- Rinv_l_sym.
rewrite Rmult_1_r; pattern (pos_Rl l' i) at 1 in |- *; rewrite <- Rplus_0_r;
rewrite double; apply Rplus_lt_compat_l; apply H19.
discrR.
assert (H19 := H8 i H17); elim H19; clear H19; intros; rewrite <- H18 in H20;
elim H20; clear H20; intros; rewrite <- Rabs_Ropp;
rewrite Ropp_minus_distr; apply H20; unfold included in H21;
elim H13; intros; assert (H24 := H21 x H22);
apply Rle_lt_trans with (Rabs (y - x) + Rabs (x - xi)).
replace (y - xi) with (y - x + (x - xi)); [ apply Rabs_triang | ring ].
rewrite (double_var (pos_Rl l' i)); apply Rplus_lt_compat.
apply Rlt_le_trans with (D / 2).
rewrite <- Rabs_Ropp; rewrite Ropp_minus_distr; apply H12.
unfold Rdiv in |- *; do 2 rewrite <- (Rmult_comm (/ 2));
apply Rmult_le_compat_l.
left; apply Rinv_0_lt_compat; prove_sup0.
unfold D in |- *; apply MinRlist_P1; elim (pos_Rl_P2 l' (pos_Rl l' i));
intros; apply H26; exists i; split;
[ rewrite <- H7; assumption | reflexivity ].
assumption.
unfold Rdiv in |- *; apply Rmult_lt_0_compat;
[ unfold D in |- *; apply MinRlist_P2; intros; elim (pos_Rl_P2 l' y); intros;
elim (H10 H9); intros; elim H12; intros; rewrite H14;
rewrite <- H7 in H13; elim (H8 x H13); intros;
apply H15
| apply Rinv_0_lt_compat; prove_sup0 ].
intros; elim (H5 x); intros; elim (H8 H6); intros;
set
(E :=
fun zeta:R =>
0 < zeta <= M - m /\
(forall z:R, Rabs (z - x) < zeta -> Rabs (f0 z - f0 x) < eps / 2));
assert (H11 : bound E).
unfold bound in |- *; exists (M - m); unfold is_upper_bound in |- *;
unfold E in |- *; intros; elim H11; clear H11; intros H11 _;
elim H11; clear H11; intros _ H11; apply H11.
assert (H12 : exists x : R, E x).
assert (H13 := H _ H9); unfold continuity_pt in H13;
unfold continue_in in H13; unfold limit1_in in H13;
unfold limit_in in H13; simpl in H13; unfold R_dist in H13;
elim (H13 _ (H1 eps)); intros; elim H12; clear H12;
intros; exists (Rmin x0 (M - m)); unfold E in |- *;
intros; split.
split;
[ unfold Rmin in |- *; case (Rle_dec x0 (M - m)); intro;
[ apply H12 | apply Rlt_Rminus; apply Hyp ]
| apply Rmin_r ].
intros; case (Req_dec x z); intro.
rewrite H16; unfold Rminus in |- *; rewrite Rplus_opp_r; rewrite Rabs_R0;
apply (H1 eps).
apply H14; split;
[ unfold D_x, no_cond in |- *; split; [ trivial | assumption ]
| apply Rlt_le_trans with (Rmin x0 (M - m)); [ apply H15 | apply Rmin_l ] ].
assert (H13 := completeness _ H11 H12); elim H13; clear H13; intros;
cut (0 < x0 <= M - m).
intro; elim H13; clear H13; intros; exists x0; split.
assumption.
split.
intros; cut (exists alp : R, Rabs (z - x) < alp <= x0 /\ E alp).
intros; elim H16; intros; elim H17; clear H17; intros; unfold E in H18;
elim H18; intros; apply H20; elim H17; intros; assumption.
elim (classic (exists alp : R, Rabs (z - x) < alp <= x0 /\ E alp)); intro.
assumption.
assert
(H17 :=
not_ex_all_not _ (fun alp:R => Rabs (z - x) < alp <= x0 /\ E alp) H16);
unfold is_lub in p; elim p; intros; cut (is_upper_bound E (Rabs (z - x))).
intro; assert (H21 := H19 _ H20);
elim (Rlt_irrefl _ (Rlt_le_trans _ _ _ H15 H21)).
unfold is_upper_bound in |- *; intros; unfold is_upper_bound in H18;
assert (H21 := H18 _ H20); case (Rle_dec x1 (Rabs (z - x)));
intro.
assumption.
elim (H17 x1); split.
split; [ auto with real | assumption ].
assumption.
unfold included, g in |- *; intros; elim H15; intros; elim H17; intros;
decompose [and] H18; cut (x0 = x2).
intro; rewrite H20; apply H22.
unfold E in p; eapply is_lub_u.
apply p.
apply H21.
elim H12; intros; unfold E in H13; elim H13; intros H14 _; elim H14;
intros H15 _; unfold is_lub in p; elim p; intros;
unfold is_upper_bound in H16; unfold is_upper_bound in H17;
split.
apply Rlt_le_trans with x1; [ assumption | apply (H16 _ H13) ].
apply H17; intros; unfold E in H18; elim H18; intros; elim H19; intros;
assumption.
Qed.
|
module Main where
import qualified Criterion
import Criterion.Types
import qualified Data.ByteString.Lazy as BS
import qualified Data.Csv as Csv
import Data.Traversable ( for )
import qualified EffectZoo.Scenario.BigStack as BigStack
import qualified EffectZoo.Scenario.CountDown as CountDown
import qualified EffectZoo.Scenario.FileSizes as FileSizes
import qualified EffectZoo.Scenario.Reinterpretation
as Reinterpretation
import Statistics.Types
main :: IO ()
main = do
for
[ ("big-stack.csv" , BigStack.benchmarks)
, ("countdown.csv" , CountDown.benchmarks)
, ("file-sizes.csv" , FileSizes.benchmarks)
, ("reinterpretation.csv", Reinterpretation.benchmarks)
]
(\(csvFile, scenario) -> do
reports <- for
scenario
(\(implementation, scenario, benchmarkable) -> do
Report { reportAnalysis = SampleAnalysis { anMean = e@Estimate { estPoint = mean } } } <-
Criterion.benchmark' benchmarkable
let (meanL, meanU) = confidenceInterval e
return (implementation, scenario, mean, meanL, meanU)
)
BS.writeFile csvFile (Csv.encode reports)
)
return ()
|
(*
This file is generated by Cogent
*)
theory Random_seed_CorresSetup
imports "CogentCRefinement.Deep_Embedding_Auto"
"CogentCRefinement.Cogent_Corres"
"CogentCRefinement.Tidy"
"CogentCRefinement.Heap_Relation_Generation"
"CogentCRefinement.Type_Relation_Generation"
"CogentCRefinement.Dargent_Custom_Get_Set"
"Random_seed_ACInstall"
"Random_seed_TypeProof"
begin
(* C type and value relations *)
instantiation unit_t_C :: cogent_C_val
begin
definition type_rel_unit_t_C_def: "\<And> r. type_rel r (_ :: unit_t_C itself) \<equiv> r = RUnit"
definition val_rel_unit_t_C_def: "\<And> uv. val_rel uv (_ :: unit_t_C) \<equiv> uv = UUnit"
instance ..
end
instantiation bool_t_C :: cogent_C_val
begin
definition type_rel_bool_t_C_def: "\<And> typ. type_rel typ (_ :: bool_t_C itself) \<equiv> (typ = RPrim Bool)"
definition val_rel_bool_t_C_def:
"\<And> uv x. val_rel uv (x :: bool_t_C) \<equiv> (boolean_C x = 0 \<or> boolean_C x = 1) \<and>
uv = UPrim (LBool (boolean_C x \<noteq> 0))"
instance ..
end
context update_sem_init begin
lemmas corres_if = corres_if_base[where bool_val' = boolean_C,
OF _ _ val_rel_bool_t_C_def[THEN meta_eq_to_obj_eq, THEN iffD1]]
end
(* Put manual type and value relations below here *)
(* Put manual type and value relations above here *)
lemmas val_rel_simps[ValRelSimp] =
val_rel_word
val_rel_ptr_def
val_rel_unit_def
val_rel_unit_t_C_def
val_rel_bool_t_C_def
val_rel_fun_tag
(* Put manual value relation definitions below here *)
(* Put manual value relation definitions above here *)
lemmas type_rel_simps[TypeRelSimp] =
type_rel_word
type_rel_ptr_def
type_rel_unit_def
type_rel_unit_t_C_def
type_rel_bool_t_C_def
(* Put manual type relation definitions below here *)
(* Put manual type relation definitions above here *)
(* C heap type class *)
class cogent_C_heap = cogent_C_val +
fixes is_valid :: "lifted_globals \<Rightarrow> 'a ptr \<Rightarrow> bool"
fixes heap :: "lifted_globals \<Rightarrow> 'a ptr \<Rightarrow> 'a"
(* generate direct definitions of custom getter/setters (for custom layouts) by
inspecting their monadic definitions *)
setup \<open> generate_isa_getset_records_for_file "random_seed.c" @{locale random_seed} \<close>
local_setup \<open> local_setup_val_rel_type_rel_put_them_in_buckets "random_seed.c" [] \<close>
local_setup \<open> local_setup_instantiate_cogent_C_heaps_store_them_in_buckets "random_seed.c" \<close>
locale Random_seed = "random_seed" + update_sem_init
begin
(* The get/set lemmas that must be proven *)
ML \<open>val lems = mk_getset_lems "random_seed.c" @{context} \<close>
ML \<open>lems |> map (string_of_getset_lem @{context})|> map tracing\<close>
(* This proves the get/set lemmas *)
local_setup \<open>local_setup_getset_lemmas "random_seed.c" \<close>
(* Relation between program heaps *)
definition
heap_rel_ptr ::
"(funtyp, abstyp, ptrtyp) store \<Rightarrow> lifted_globals \<Rightarrow>
('a :: cogent_C_heap) ptr \<Rightarrow> bool"
where
"\<And> \<sigma> h p.
heap_rel_ptr \<sigma> h p \<equiv>
(\<forall> uv.
\<sigma> (ptr_val p) = Some uv \<longrightarrow>
type_rel (uval_repr uv) TYPE('a) \<longrightarrow>
is_valid h p \<and> val_rel uv (heap h p))"
lemma heap_rel_ptr_meta:
"heap_rel_ptr = heap_rel_meta is_valid heap"
by (simp add: heap_rel_ptr_def[abs_def] heap_rel_meta_def[abs_def])
local_setup \<open> local_setup_heap_rel "random_seed.c" [] [] \<close>
definition state_rel :: "((funtyp, abstyp, ptrtyp) store \<times> lifted_globals) set"
where
"state_rel = {(\<sigma>, h). heap_rel \<sigma> h}"
(* Proving correctness of getters *)
local_setup \<open> local_setup_getter_correctness "random_seed.c" \<close>
(* Generating the specialised take and put lemmas *)
local_setup \<open> local_setup_take_put_member_case_esac_specialised_lemmas "random_seed.c" \<close>
local_setup \<open> fold tidy_C_fun_def' Cogent_functions \<close>
end (* of locale *)
end
|
% -*- root: ../main.tex -*-
\chapter{Results\label{chap:results}}
\paragraph{Abstract}
This chapter describes the set of axioms needed to prove the target verification problem and the justifies the relevance of the axioms.
%
We will cover briefly the generated proofs and some complexity results.
%
Finally, we report a time analysis, comparing this \gls{ATP} to model checkers and the different inner steps of the methodology.
\section{Axioms}
We introduce now the set of relevant axioms needed to prove all the invariants.
%
There are some secondary axioms needed by \spass that have been omitted.
%
The omitted axioms refer:
%
\begin{itemize}
\item to the sorting (\spass is not multi-sorted as the theory we work with. It is necessary to define that an \addr is not an \elem, an \elem is not an \addr, etc)
\item to constants (\spass does not include arithmetic, so $0$,$1$,... must be defined as unique 0-ary functions specifying that $0\not\eq 1,0\not\eq 2$,...)
\item to the local and global variables of the program (\leap is quantifier free but \spass needs to quantify every variable)
\end{itemize}
%
The set of axioms has been divided in groups.
%
The division is as follows
\label{ax::fulllist}
\input{src/axioms}
The full list of axioms has been listed in appendix \ref{spass:syntax_file}.
%
We claim that there is no need for more axioms than the ones defined at \ref{ax::fulllist}.
%
The next section will present which axioms are needed for proving each invariants.
\section{Analysis of generated proofs}
\label{proof:Preserve}
\label{sec:axiomgraph}
\paragraph{Example}
Lets take \invDisjoint\footnote{Its full definition is at \ref{inv::full:disjoint}} as an example.
%
We aim to prove that \invDisjoint is an invariant. To do so, we need to prove its VCs valid.
%
There are only needed 3 axioms: the axiom which states that numbers are different and the 2 axioms which states $i$ and $j$ are threads.
%
With these 3 axiom, \spass can prove valid all the \spass problems associated with \invDisjoint.
To clarify the process described in \ref{ProcessDescription} we expose all the \spass problems generated to prove that \invDisjoint is an invariant.
%
There are 362 \spass problems. Half of them correspond to the \reducedProblem and the other half to the \smallToBig problem.
%
For each half, there are 181 \spass problems:
%
For \textbf{\instantiation} there is one problem.
%
For self-consecution there are 60 \spass problems. The program has 55 statements, so there is a \gls{VC} for each line except for \textit{while} and \textit{if} statements which have 2 \gls{VC} associated depending on the validity of the condition. As there are 3 while and 2 if, we have 60 \spass problems for each thread.
%
As \invDisjoint involves 2 threads, there are \textbf{120 self-consecution \spass problems}.
%
Finally for \textbf{Others consecution} there are \textbf{60} \spass problems.
\paragraph{Analysis}
Most of the transitions (\numTransitionsProvedWithPC in \numTotalTransitions) are proven without any relevant axiom.
%
Some of them do not even need any axiom.
%
\smallToBig problems usually do not need any axiom, because there are simple but big \gls{FOL} formulas.
Table \ref{table:analysisProofs} contains some global information about the proof of each invariant.
%
It is important to mention that every invariant has 2 problems of \instantiation.
\begin{table}[hbtp]
\centering
\begin{tabular}{c|cccc}
Invariant & Self-consecution & Others consecution & Total & Number of axioms used\\\hline
\input{src/tex/analysisTable.tex}
\end{tabular}
\label{table:analysisProofs}
\caption{Number of \spass problems by invariant.}
\end{table}
In terms of the number of axioms needed, it is interesting to see that \invLock is the most complicated, followed by \invNext.
%
The easiest is \invDisjoint, which only uses \textit{nums-are-different} (\ref{ax::nums_are_different}) and axioms related with sorts (there are 2 threads involved in the formula which are different from one another.)
\\
The differences on the number of other-consecution problem is caused by the splitting on complex \spass problems.
%
To prove \invOrder all other-consecution problems have been splat, but for \invLock and \invNext just 21 other consecution problems have been splat.
%
Despite that fact, \invOrder is not very complex in terms of total number of axioms needed.
Another interesting data to look at in order to study the difficult of each invariant is the number of axioms needed in each problem.
%
Figure \ref{fig:frequencyAxioms} shows the number of problems solved against the number of axioms needed.
%
The graphic illustrate the number of problems solved normalized by the total amount of problems that invariant involves.
%
As it was stated before, most of the problems can be proven without any axiom, or just with the axioms of sorts and numbers to reason about the \pc.
%
Looking to the figure, the difficulty of each axiom in terms of the axioms used in each problem is more precise:
%
\invOrder needs more axioms in general than the rest.
\begin{figure}[hbtp]
\centering
\includegraphics[scale=0.8]{graphics/frequencyAxioms.png}
\caption{Number of problems solved against number of axiom needed.}
\label{fig:frequencyAxioms}
\end{figure}
\subsection{Special Transitions}
Due to the limited space, we can not explore deeply the proof of the invariants.
%
However, some we offer a brief analysis of the complicated transitions for the most important invariant: \invPreserve. The complicated transitions are the ones modifying the heap: \textit{locks}, \textit{insertion} and \textit{removal}.
%
The transitions including \textit{locks} and \textit{unlocks} can be proven easily with the axioms, because a \fLock does not modify the content nor the pointer; thus, it can not break the list nor disorder the list.
%
For the other transitions some expert knowledge is needed, because \spass lacks information to finish the proof.
%
This limitation is that \spass does not know how to choose the axioms to use, leading into an unnecessary exploration of a branch of the proof.
%
\label{infty:time}
If \spass could know that, it would be much more efficient.
%
As a consequence, transitions 35 and 55 have been subdivided in to a number of smaller \spass problems, reducing manually in each case the number of axioms needed and leaving the ones which could be relevant.
%
\section{Time analysis}
\label{sec:timeanalysis}
\subsection{Proof generation}
All the times shown refer to the time \spass takes to prove the validity of each problem.
%
Previous parsing and creating the proper input to \spass has been ignored.
\subsection{Proof Checking}
One of the greatest consequences of this method is the possibility to refute the generated proofs and double check that they are valid.
%
We developed the solution such that for each \spass problem there are three files generated.
%
The \spass output (storing the information of which axioms have been used and the running time), the \spass proof in \spass format and the \spass proof in TPTP syntax (\cite{tptp}).
%
By generating a TPTP proof for each \spass problem we made possible to check these proofs with any other theorem prover as \citetool{vampire} or \citetool{issabelle}.
Another advantage of the generation of these files is the reduced amount of time needed to check the validity of the fine-grained-linked-list implementation.
%
There is no need to regenerate all the verification conditions and regenerate all the \spass files and let \spass run until it finds the proof for every problem.
%
One can just run \spass on the generated proofs and will save lot of time.
%
Lets see the amount of time needed to check the proofs instead of generate them.
\subsection{Comparing times}
In order to use formal verification in real environments, a time analysis is fundamental.
%
The more time it takes, the more useless formal verification is.
%
How much time does it takes to generate all the proofs for this linked-list implementation?
%
And more importantly, How much time does it takes to check the generated proofs?
In Table \ref{analysis::bigtimetable} one can find the summary of the timing according to four different activities. The first column refers to the time that \leap takes to prove the invariant (obtained from \cite{paperParametrizedInvariants}).
%
The second column, \textit{Full process}, refers to the time the whole process takes\footnote{The full process is described in \ref{ProcessDescription}}.
%
This is, generating the verification conditions, creating all the \spass problems and letting \spass work to solve each problem.
%
The third column, \textit{Sum of \spass time}, refers to the amount of time that \spass takes to solve all the problems of each invariant.
%
This column shows the real time necessary to generate the proofs, from the already generated files.
%
Finally, the last column shows very important information,
%
which is amount of time needed to check that the proofs are correct is less than every other method.
%
This method reduces significantly the time spent in checking the formal verification of a problem.
\begin{table}[hbtp]
\centering
\begin{tabular}{r|rrrr}
Invariant & Leap & Full process & Sum of \spass time & Check proofs \\\hline
\invPreserve & 12 min 85 sec & $\infty$ & 10 min 56.56 sec & 0 min 52.19 sec \\
\invOrder & 1 min 20 sec & 180 min 40.548 sec & 62 min 32.89 sec & 7 min 41.17 sec \\
\invLock & 0 min 50 sec & 39 min 28.321 sec & 13 min 34.00 sec & 1 min 53.94 sec \\
\invNext & 1 min 76 sec & 352 min 17.839 sec & 123 min 37.73 sec & 17 min 06.12 sec \\
\invRegion & 25 min 67 sec & 7 min 34.425 sec & 1 min 14.68 sec & 0 min 19.14 sec \\
\invDisjoint & 0 min 22 sec & 4 min 13.300 sec & 1 min 17.15 sec & 0 min 26.40 sec \\
%Total: & & & & \\
\end{tabular}
\caption{Compare of the times.}
\label{analysis::bigtimetable}
\end{table}
There are some very relevant issues with the measures of the \textit{Full process} time and the \textit{Sum of \spass time}.
\paragraph{About measuring the full process}
In order to improve performance, all \spass problems are first considered as if they were the simplest.
%
If it took \spass too much time to (according to a timeout) to find a proof for a problem, then the problem would be automatically divided.
%
This approach allows to prove simple problems very quickly, such as the majority of \invDisjoint transitions for example.
%
When a problem is not so simple (again, according to the timeout), then it is divided and some time has been wasted because the initial attempt to prove the problem is terminated.
%
The value of this timeout is not trivial to be set.
%
There are transitions which do not need any axioms.
%
This is caused because of VCs of the form $(\mathit{false} \to \mathit{something})$.
%
For these transitions, it is usual that \spass takes less than one second to prove them.
%
Thus, we could set the timeout to one second.
%
If a transition is taking more than one second, then it may need more axioms and or it should be divided.
%
But we may incur into dividing a problem which does not need to be divided.
%
Others consecution for transition 33 in \invLock takes 1 second and a half, but does not need to be divided because it is of the form $(false \to something)$.
%
A timeout of 1 second would make \gandalf to divided this transition, but a timeout of 2 seconds would cause a waste of 1 second in each not simple \spass problem.
%
The timeout had been setted to 100 seconds because it was preferable in order to generate less \spass problems, and consequently less proofs.
The problem explained before acquires more relevance in another context.
%
\spass does not have an expert knowledge about which axioms should be used first because they are relevant and which should not.
%
No arithmetic axiom is needed to prove \invRegion and \spass does not neither need any axiom about the order relation between elements.
%
There is a subset of axioms for each invariant.
%
Including unnecessary axioms may cause \spass to take more time searching for the proof in a branch where the proof cannot be found.
%
It may not cause any delay because it finds the proof without exploring all the branches.
%
We show an example of this reality.
%
Transition 11 of the \invPreserve takes 23 seconds to \spass when all the axioms are included but it takes 0.44 seconds when only used axioms are included.
%
This difference has been an important challenge, because when \spass could not find a proof it did not necessarily mean that the problem was unsatisfiable.
%
It could mean that too many unnecessary axiom had been included or that the problem needed to be divided.
%
Thus, the third column shows the real amount of time that \spass has needed to generate the proofs.
%
This time is not the lowest bound one could get, but as one can see, it is less than the whole process.
%
For the transition mentioned before, \spass takes 0.11 seconds to check that the proof is correct.
%
For \invPreserve there are two transitions whose proof were completed manually, as we explained in \ref{infty:time}. |
If data can be HACKED or STOLEN, STOP using REAL data and contact us today as we have the Encryption Solution more secure than any Encryption!
Our Team provides several MicroToken solutions that eliminate the vulnerability of storing and sending real data.
Each solution effectively removes the ability for intruders to discern any value from storage or transmission.
We provide solutions for transmitting commands between connected devices, storing and retrieving documents and data in any form, as well as secure payment services.
MicroToken Exchange (MTE) Encryption Technology solution for securing Data in MOTION.
- MTE secures data in motion by acting almost as an invisible shield or a translator between the sending device and the receiving device. Our MTE replaces your command or transmission data with a MicroToken just before the packet is sent. Once the packet has reached the receiver it is translated back into the original command or data. The Eclypses MTE is easy to implement and works with any communication protocol.
MicroToken Exchange (MTE) Encryption Technology solutions for securing Data at REST.
- MTE has several solutions for securing data at rest that can be accessed through a variety of ways. Eclypses secures your data by replacing any size file or data element with a MicroToken, ensuring that if there is ever a breach in your system that hackers will not be able to get any discernable value from what they access.
- Our Team's MicroToken solutions conform to several industry compliancy regulations and can remove the burden for your Agency, Company or your client's Agency or Company. |
open import Agda.Primitive
record Functor {a b} (F : Set a → Set b) : Set (lsuc a ⊔ b) where
field
fmap : ∀ {A B} → (A → B) → F A → F B
open Functor {{...}} public
module _ {a b} (F : Set a → Set b) where
record FunctorZero : Set (lsuc a ⊔ b) where
field
empty : ∀ {A} → F A
overlap {{super}} : Functor F
record Alternative : Set (lsuc a ⊔ b) where
infixl 3 _<|>_
field
_<|>_ : ∀ {A} → F A → F A → F A
overlap {{super}} : FunctorZero
open FunctorZero {{...}} public
open Alternative {{...}} public
record StateT {a} (S : Set a) (M : Set a → Set a) (A : Set a) : Set a where
no-eta-equality
constructor stateT
field runStateT : S → M A
open StateT public
module _ {a} {S : Set a} {M : Set a → Set a} where
instance
FunctorStateT : {{_ : Functor M}} → Functor {a = a} (StateT S M)
runStateT (fmap {{FunctorStateT}} f m) s = fmap f (runStateT m s)
FunctorZeroStateT : {{_ : FunctorZero M}} → FunctorZero {a = a} (StateT S M)
runStateT (empty {{FunctorZeroStateT}}) s = empty
AlternativeStateT : {{_ : Alternative M}} → Alternative {a = a} (StateT S M)
runStateT (_<|>_ {{AlternativeStateT}} x y) s = runStateT x s <|> runStateT y s
--- Example with some module parameter instantiations
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
data Vec (A : Set) : Nat → Set where
[] : Vec A 0
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
postulate
C₁ : Set → Set
record C₂ (A : Set) : Set where
field
f : A → A
overlap {{super}} : C₁ A
open C₂ {{...}}
postulate
T : (A : Set) → A → Set
module M (A : Set) (n : Nat) (xs : Vec A n) where
unpackT : Vec A n → Set
unpackT (x ∷ xs) = C₂ (T A x)
unpackT [] = ⊤
postulate instance C₁T : ∀ {x} {{C₁A : C₁ A}} → C₁ (T A x)
C₂T : {{C₂A : C₂ A}} (ys : Vec A n) → unpackT ys
C₂T [] = _
f {{C₂T (y ∷ ys)}} x = x
|
section \<open>Proper Iterators\<close>
theory Proper_Iterator
imports
SetIteratorOperations
Automatic_Refinement.Refine_Lib
begin
text \<open>
Proper iterators provide a way to obtain polymorphic iterators even
inside locale contexts.
For this purpose, an iterator that converts the set to a list is fixed
inside the locale, and polymorphic iterators are described by folding
over the generated list.
In order to ensure efficiency, it is shown that folding over the generated
list is equivalent to directly iterating over the set, and this equivalence
is set up as a code preprocessing rule.
\<close>
subsection \<open>Proper Iterators\<close>
text \<open>A proper iterator can be expressed as a fold over a list, where
the list does only depend on the set. In particular, it does not depend
on the type of the state. We express this by the following definition,
using two iterators with different types:\<close>
definition proper_it
:: "('x,'\<sigma>1) set_iterator \<Rightarrow> ('x,'\<sigma>2) set_iterator \<Rightarrow> bool"
where "proper_it it it' \<equiv> (\<exists>l. it=foldli l \<and> it'=foldli l)"
lemma proper_itI[intro?]:
fixes it :: "('x,'\<sigma>1) set_iterator"
and it' :: "('x,'\<sigma>2) set_iterator"
assumes "it=foldli l \<and> it'=foldli l"
shows "proper_it it it'"
using assms unfolding proper_it_def by auto
lemma proper_itE:
fixes it :: "('x,'\<sigma>1) set_iterator"
and it' :: "('x,'\<sigma>2) set_iterator"
assumes "proper_it it it'"
obtains l where "it=foldli l" and "it'=foldli l"
using assms unfolding proper_it_def by auto
lemma proper_it_parE:
fixes it :: "'a \<Rightarrow> ('x,'\<sigma>1) set_iterator"
and it' :: "'a \<Rightarrow> ('x,'\<sigma>2) set_iterator"
assumes "\<forall>x. proper_it (it x) (it' x)"
obtains f where "it = (\<lambda>x. foldli (f x))" and "it' = (\<lambda>x. foldli (f x))"
using assms unfolding proper_it_def
by metis
definition
proper_it'
where "proper_it' it it' \<equiv> \<forall>s. proper_it (it s) (it' s)"
lemma proper_it'I:
"\<lbrakk>\<And>s. proper_it (it s) (it' s)\<rbrakk> \<Longrightarrow> proper_it' it it'"
unfolding proper_it'_def by blast
lemma proper_it'D:
"proper_it' it it' \<Longrightarrow> proper_it (it s) (it' s)"
unfolding proper_it'_def by blast
subsubsection \<open>Properness Preservation\<close>
ML \<open>
structure Icf_Proper_Iterator = struct
structure icf_proper_iteratorI = Named_Thms
( val name = @{binding icf_proper_iteratorI_raw}
val description = "ICF (internal): Rules to show properness of iterators" )
val get = icf_proper_iteratorI.get
fun add_thm thm = icf_proper_iteratorI.add_thm thm
val add = Thm.declaration_attribute add_thm
fun del_thm thm = icf_proper_iteratorI.del_thm thm
val del = Thm.declaration_attribute del_thm
val setup = I
#> icf_proper_iteratorI.setup
#> Attrib.setup @{binding icf_proper_iteratorI}
(Attrib.add_del add del)
("ICF: Rules to show properness of iterators")
#> Global_Theory.add_thms_dynamic (@{binding icf_proper_iteratorI},
get o Context.proof_of
)
end
\<close>
setup \<open>Icf_Proper_Iterator.setup\<close>
lemma proper_iterator_trigger:
"proper_it it it' \<Longrightarrow> proper_it it it'"
"proper_it' itf itf' \<Longrightarrow> proper_it' itf itf'" .
declaration \<open>
Tagged_Solver.declare_solver @{thms proper_iterator_trigger}
@{binding proper_iterator} "Proper iterator solver"
(fn ctxt => REPEAT_ALL_NEW (resolve_tac ctxt (Icf_Proper_Iterator.get ctxt)))
\<close>
lemma pi_foldli[icf_proper_iteratorI]:
"proper_it (foldli l :: ('a,'\<sigma>) set_iterator) (foldli l)"
unfolding proper_it_def
by auto
lemma pi_foldri[icf_proper_iteratorI]:
"proper_it (foldri l :: ('a,'\<sigma>) set_iterator) (foldri l)"
unfolding proper_it_def foldri_def by auto
lemma pi'_foldli[icf_proper_iteratorI]:
"proper_it' (foldli o tsl) (foldli o tsl)"
apply (clarsimp simp add: proper_it'_def)
apply (tagged_solver)
done
lemma pi'_foldri[icf_proper_iteratorI]:
"proper_it' (foldri o tsl) (foldri o tsl)"
apply (clarsimp simp add: proper_it'_def)
apply (tagged_solver)
done
text \<open>Iterator combinators preserve properness\<close>
lemma pi_emp[icf_proper_iteratorI]:
"proper_it set_iterator_emp set_iterator_emp"
unfolding proper_it_def set_iterator_emp_def[abs_def]
by (auto intro!: ext exI[where x="[]"])
lemma pi_sng[icf_proper_iteratorI]:
"proper_it (set_iterator_sng x) (set_iterator_sng x)"
unfolding proper_it_def set_iterator_sng_def[abs_def]
by (auto intro!: ext exI[where x="[x]"])
lemma pi_union[icf_proper_iteratorI]:
assumes PA: "proper_it it_a it_a'"
assumes PB: "proper_it it_b it_b'"
shows "proper_it (set_iterator_union it_a it_b)
(set_iterator_union it_a' it_b')"
unfolding set_iterator_union_def
apply (rule proper_itE[OF PA])
apply (rule proper_itE[OF PB])
apply (rule_tac l="l@la" in proper_itI)
apply simp
apply (intro conjI ext)
apply (simp_all add: foldli_append)
done
lemma pi_product[icf_proper_iteratorI]:
fixes it_a :: "('a,'\<sigma>a) set_iterator"
fixes it_b :: "'a \<Rightarrow> ('b,'\<sigma>a) set_iterator"
assumes PA: "proper_it it_a it_a'"
and PB: "\<And>x. proper_it (it_b x) (it_b' x)"
shows "proper_it (set_iterator_product it_a it_b)
(set_iterator_product it_a' it_b')"
proof -
from PB have PB': "\<forall>x. proper_it (it_b x) (it_b' x)" ..
show ?thesis
unfolding proper_it_def
apply (rule proper_itE[OF PA])
apply (rule proper_it_parE[OF PB'])
apply (auto simp add: set_iterator_product_foldli_conv)
done
qed
lemma pi_image_filter[icf_proper_iteratorI]:
fixes it :: "('x,'\<sigma>1) set_iterator"
and it' :: "('x,'\<sigma>2) set_iterator"
and g :: "'x \<Rightarrow> 'y option"
assumes P: "proper_it it it'"
shows "proper_it (set_iterator_image_filter g it)
(set_iterator_image_filter g it')"
unfolding proper_it_def
apply (rule proper_itE[OF P])
apply (auto simp: set_iterator_image_filter_foldli_conv)
done
lemma pi_filter[icf_proper_iteratorI]:
assumes P: "proper_it it it'"
shows "proper_it (set_iterator_filter P it)
(set_iterator_filter P it')"
unfolding proper_it_def
apply (rule proper_itE[OF P])
by (auto simp: set_iterator_filter_foldli_conv)
lemma pi_image[icf_proper_iteratorI]:
assumes P: "proper_it it it'"
shows "proper_it (set_iterator_image g it)
(set_iterator_image g it')"
unfolding proper_it_def
apply (rule proper_itE[OF P])
by (auto simp: set_iterator_image_foldli_conv)
lemma pi_dom[icf_proper_iteratorI]:
assumes P: "proper_it it it'"
shows "proper_it (map_iterator_dom it)
(map_iterator_dom it')"
unfolding proper_it_def
apply (rule proper_itE[OF P])
by (auto simp: map_iterator_dom_foldli_conv)
lemma set_iterator_product_eq2:
assumes "\<forall>a\<in>set la. itb a = itb' a"
shows "set_iterator_product (foldli la) itb
= set_iterator_product (foldli la) itb'"
proof (intro ext)
fix c f \<sigma>
show "set_iterator_product (foldli la) itb c f \<sigma>
= set_iterator_product (foldli la) itb' c f \<sigma>"
using assms
unfolding set_iterator_product_def
apply (induct la arbitrary: \<sigma>)
apply (auto)
done
qed
subsubsection \<open>Optimizing Folds\<close>
text \<open>
Using an iterator to create a list. The optimizations will
match the pattern \<open>foldli (it_to_list it s)\<close>
\<close>
definition "it_to_list it s \<equiv> (it s) (\<lambda>_. True) (\<lambda>x l. l@[x]) []"
lemma map_it_to_list_genord_correct:
assumes A: "map_iterator_genord (it s) m (\<lambda>(k,_) (k',_). R k k')"
shows "map_of (it_to_list it s) = m
\<and> distinct (map fst (it_to_list it s))
\<and> sorted_wrt R ((map fst (it_to_list it s)))"
unfolding it_to_list_def
apply (rule map_iterator_genord_rule_insert_P[OF A, where I="
\<lambda>it l. map_of l = m |` it
\<and> distinct (map fst l)
\<and> sorted_wrt R ((map fst l))
"])
apply auto
apply (auto simp: restrict_map_def) []
apply (metis Some_eq_map_of_iff restrict_map_eq(2))
apply (auto simp add: sorted_wrt_append)
by (metis (lifting) restrict_map_eq(2) weak_map_of_SomeI)
lemma (in linorder) map_it_to_list_linord_correct:
assumes A: "map_iterator_linord (it s) m"
shows "map_of (it_to_list it s) = m
\<and> distinct (map fst (it_to_list it s))
\<and> sorted ((map fst (it_to_list it s)))"
using map_it_to_list_genord_correct[where it=it,
OF A[unfolded set_iterator_map_linord_def]]
by (simp add: sorted_sorted_wrt)
end
|
[STATEMENT]
lemma star_of_Suc_lessI: "\<And>N. star_of n < N \<Longrightarrow> star_of (Suc n) \<noteq> N \<Longrightarrow> star_of (Suc n) < N"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>N. \<lbrakk>hypnat_of_nat n < N; hypnat_of_nat (Suc n) \<noteq> N\<rbrakk> \<Longrightarrow> hypnat_of_nat (Suc n) < N
[PROOF STEP]
by transfer (rule Suc_lessI) |
(* Title: Complete Tests
Author: Walter Guttmann
Maintainer: Walter Guttmann <walter.guttmann at canterbury.ac.nz>
*)
section \<open>Complete Tests\<close>
theory Complete_Tests
imports Tests
begin
class complete_tests = tests + Sup + Inf +
assumes sup_test: "test_set A \<longrightarrow> Sup A = --Sup A"
assumes sup_upper: "test_set A \<and> x \<in> A \<longrightarrow> x \<le> Sup A"
assumes sup_least: "test_set A \<and> (\<forall>x\<in>A . x \<le> -y) \<longrightarrow> Sup A \<le> -y"
begin
lemma Sup_isotone:
"test_set B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> Sup A \<le> Sup B"
by (metis sup_least sup_test sup_upper test_set_closed subset_eq)
lemma mult_right_dist_sup:
assumes "test_set A"
shows "Sup A * -p = Sup { x * -p | x . x \<in> A }"
proof -
have 1: "test_set { x * -p | x . x \<in> A }"
by (simp add: assms mult_right_dist_test_set)
have 2: "Sup { x * -p | x . x \<in> A } \<le> Sup A * -p"
by (smt (verit, del_insts) assms mem_Collect_eq tests_dual.sub_sup_left_isotone sub_mult_closed sup_test sup_least sup_upper test_set_def)
have "\<forall>x\<in>A . x \<le> --(--Sup { x * -p | x . x \<in> A } \<squnion> --p)"
proof
fix x
assume 3: "x \<in> A"
hence "x * -p \<squnion> --p \<le> Sup { x * -p | x . x \<in> A } \<squnion> --p"
using 1 by (smt (verit, del_insts) assms mem_Collect_eq tests_dual.sub_inf_left_isotone sub_mult_closed sup_upper test_set_def sup_test)
thus "x \<le> --(--Sup { x * -p | x . x \<in> A } \<squnion> --p)"
using 1 3 by (smt (z3) assms tests_dual.inf_closed sub_comm test_set_def sup_test sub_mult_closed tests_dual.sba_dual.shunting_right tests_dual.sba_dual.sub_sup_left_isotone tests_dual.inf_absorb tests_dual.inf_less_eq_cases_3)
qed
hence "Sup A \<le> --(--Sup { x * -p | x . x \<in> A } \<squnion> --p)"
by (simp add: assms sup_least)
hence "Sup A * -p \<le> Sup { x * -p | x . x \<in> A }"
using 1 by (smt (z3) assms sup_test tests_dual.sba_dual.shunting tests_dual.sub_commutative tests_dual.sub_sup_closed tests_dual.sub_sup_demorgan)
thus ?thesis
using 1 2 by (smt (z3) assms sup_test tests_dual.sba_dual.sub_sup_closed tests_dual.antisymmetric tests_dual.inf_demorgan tests_dual.inf_idempotent)
qed
lemma mult_left_dist_sup:
assumes "test_set A"
shows "-p * Sup A = Sup { -p * x | x . x \<in> A }"
proof -
have 1: "Sup A * -p = Sup { x * -p | x . x \<in> A }"
by (simp add: assms mult_right_dist_sup)
have 2: "-p * Sup A = Sup A * -p"
by (metis assms sub_comm sup_test)
have "{ -p * x | x . x \<in> A } = { x * -p | x . x \<in> A }"
by (metis assms test_set_def tests_dual.sub_commutative)
thus ?thesis
using 1 2 by simp
qed
definition Sum :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a"
where "Sum f \<equiv> Sup { f n | n::nat . True }"
lemma Sum_test:
"test_seq t \<Longrightarrow> Sum t = --Sum t"
using Sum_def sup_test test_seq_test_set by auto
lemma Sum_upper:
"test_seq t \<Longrightarrow> t x \<le> Sum t"
using Sum_def sup_upper test_seq_test_set by auto
lemma Sum_least:
"test_seq t \<Longrightarrow> (\<forall>n . t n \<le> -p) \<Longrightarrow> Sum t \<le> -p"
using Sum_def sup_least test_seq_test_set by force
lemma mult_right_dist_Sum:
"test_seq t \<Longrightarrow> (\<forall>n . t n * -p \<le> -q) \<Longrightarrow> Sum t * -p \<le> -q"
by (smt (verit, del_insts) CollectD Sum_def sup_least sup_test test_seq_test_set test_set_def tests_dual.sba_dual.shunting_right tests_dual.sba_dual.sub_sup_closed)
lemma mult_left_dist_Sum:
"test_seq t \<Longrightarrow> (\<forall>n . -p * t n \<le> -q) \<Longrightarrow> -p * Sum t \<le> -q"
by (smt (verit, del_insts) Sum_def mem_Collect_eq mult_left_dist_sup sub_mult_closed sup_least test_seq_test_set test_set_def)
lemma pSum_below_Sum:
"test_seq t \<Longrightarrow> pSum t m \<le> Sum t"
using Sum_test Sum_upper nat_test_def pSum_below_sum test_seq_def mult_right_dist_Sum by auto
lemma pSum_sup:
assumes "test_seq t"
shows "pSum t m = Sup { t i | i . i \<in> {..<m} }"
proof -
have 1: "test_set { t i | i . i \<in> {..<m} }"
using assms test_seq_test_set test_set_def by auto
have "\<forall>y\<in>{ t i | i . i \<in> {..<m} } . y \<le> --pSum t m"
using assms pSum_test pSum_upper by force
hence 2: "Sup { t i | i . i \<in> {..<m} } \<le> --pSum t m"
using 1 by (simp add: sup_least)
have "pSum t m \<le> Sup { t i | i . i \<in> {..<m} }"
proof (induct m)
case 0
show ?case
by (smt (verit, ccfv_SIG) Collect_empty_eq empty_iff lessThan_0 pSum.simps(1) sup_test test_set_def tests_dual.top_greatest)
next
case (Suc n)
have 4: "test_set {t i |i. i \<in> {..<n}}"
using assms test_seq_def test_set_def by auto
have 5: "test_set {t i |i. i < Suc n}"
using assms test_seq_def test_set_def by force
hence 6: "Sup {t i |i. i < Suc n} = --Sup {t i |i. i < Suc n}"
using sup_test by auto
hence "\<forall>x\<in>{t i |i. i \<in> {..<n}} . x \<le> --Sup {t i |i. i < Suc n}"
using 5 less_Suc_eq sup_upper by fastforce
hence 7: "Sup {t i |i. i \<in> {..<n}} \<le> --Sup {t i |i. i < Suc n}"
using 4 by (simp add: sup_least)
have "t n \<in> {t i |i. i < Suc n}"
by auto
hence "t n \<le> Sup {t i |i. i < Suc n}"
using 5 by (simp add: sup_upper)
hence "pSum t n \<squnion> t n \<le> Sup {t i |i. i <Suc n}"
using Suc 4 6 7 by (smt assms tests_dual.greatest_lower_bound test_seq_def pSum_test tests_dual.sba_dual.transitive sup_test)
thus ?case
by simp
qed
thus ?thesis
using 1 2 by (smt assms tests_dual.antisymmetric sup_test pSum_test)
qed
definition Prod :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a"
where "Prod f \<equiv> Inf { f n | n::nat . True }"
lemma Sum_range:
"Sum f = Sup (range f)"
by (simp add: Sum_def image_def)
lemma Prod_range:
"Prod f = Inf (range f)"
by (simp add: Prod_def image_def)
end
end
|
lemma local_lipschitz_PairI: assumes f: "local_lipschitz A B (\<lambda>a b. f a b)" assumes g: "local_lipschitz A B (\<lambda>a b. g a b)" shows "local_lipschitz A B (\<lambda>a b. (f a b, g a b))" |
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
tfae_have 1 ↔ 2
[GOAL]
case tfae_1_iff_2
ι : Type u_1
I J : Box ι
x y : ι → ℝ
⊢ I ≤ J ↔ ↑I ⊆ ↑J
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
exact Iff.rfl
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
tfae_have 2 → 3
[GOAL]
case tfae_2_to_3
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
⊢ ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
[PROOFSTEP]
intro h
[GOAL]
case tfae_2_to_3
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
h : ↑I ⊆ ↑J
⊢ Icc I.lower I.upper ⊆ Icc J.lower J.upper
[PROOFSTEP]
simpa [coe_eq_pi, closure_pi_set, lower_ne_upper] using closure_mono h
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
tfae_2_to_3 : ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
tfae_have 3 ↔ 4
[GOAL]
case tfae_3_iff_4
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
tfae_2_to_3 : ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
⊢ Icc I.lower I.upper ⊆ Icc J.lower J.upper ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
tfae_2_to_3 : ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
tfae_3_iff_4 : Icc I.lower I.upper ⊆ Icc J.lower J.upper ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
exact Icc_subset_Icc_iff I.lower_le_upper
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
tfae_2_to_3 : ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
tfae_3_iff_4 : Icc I.lower I.upper ⊆ Icc J.lower J.upper ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
tfae_have 4 → 2
[GOAL]
case tfae_4_to_2
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
tfae_2_to_3 : ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
tfae_3_iff_4 : Icc I.lower I.upper ⊆ Icc J.lower J.upper ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper
⊢ J.lower ≤ I.lower ∧ I.upper ≤ J.upper → ↑I ⊆ ↑J
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
tfae_2_to_3 : ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
tfae_3_iff_4 : Icc I.lower I.upper ⊆ Icc J.lower J.upper ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper
tfae_4_to_2 : J.lower ≤ I.lower ∧ I.upper ≤ J.upper → ↑I ⊆ ↑J
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
exact fun h x hx i ↦ Ioc_subset_Ioc (h.1 i) (h.2 i) (hx i)
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
tfae_1_iff_2 : I ≤ J ↔ ↑I ⊆ ↑J
tfae_2_to_3 : ↑I ⊆ ↑J → Icc I.lower I.upper ⊆ Icc J.lower J.upper
tfae_3_iff_4 : Icc I.lower I.upper ⊆ Icc J.lower J.upper ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper
tfae_4_to_2 : J.lower ≤ I.lower ∧ I.upper ≤ J.upper → ↑I ⊆ ↑J
⊢ List.TFAE [I ≤ J, ↑I ⊆ ↑J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper]
[PROOFSTEP]
tfae_finish
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
⊢ Injective toSet
[PROOFSTEP]
rintro ⟨l₁, u₁, h₁⟩ ⟨l₂, u₂, h₂⟩ h
[GOAL]
case mk.mk
ι : Type u_1
I J : Box ι
x y l₁ u₁ : ι → ℝ
h₁ : ∀ (i : ι), l₁ i < u₁ i
l₂ u₂ : ι → ℝ
h₂ : ∀ (i : ι), l₂ i < u₂ i
h : ↑{ lower := l₁, upper := u₁, lower_lt_upper := h₁ } = ↑{ lower := l₂, upper := u₂, lower_lt_upper := h₂ }
⊢ { lower := l₁, upper := u₁, lower_lt_upper := h₁ } = { lower := l₂, upper := u₂, lower_lt_upper := h₂ }
[PROOFSTEP]
simp only [Subset.antisymm_iff, coe_subset_coe, le_iff_bounds] at h
[GOAL]
case mk.mk
ι : Type u_1
I J : Box ι
x y l₁ u₁ : ι → ℝ
h₁ : ∀ (i : ι), l₁ i < u₁ i
l₂ u₂ : ι → ℝ
h₂ : ∀ (i : ι), l₂ i < u₂ i
h : (l₂ ≤ l₁ ∧ u₁ ≤ u₂) ∧ l₁ ≤ l₂ ∧ u₂ ≤ u₁
⊢ { lower := l₁, upper := u₁, lower_lt_upper := h₁ } = { lower := l₂, upper := u₂, lower_lt_upper := h₂ }
[PROOFSTEP]
congr
[GOAL]
case mk.mk.e_lower
ι : Type u_1
I J : Box ι
x y l₁ u₁ : ι → ℝ
h₁ : ∀ (i : ι), l₁ i < u₁ i
l₂ u₂ : ι → ℝ
h₂ : ∀ (i : ι), l₂ i < u₂ i
h : (l₂ ≤ l₁ ∧ u₁ ≤ u₂) ∧ l₁ ≤ l₂ ∧ u₂ ≤ u₁
⊢ l₁ = l₂
case mk.mk.e_upper
ι : Type u_1
I J : Box ι
x y l₁ u₁ : ι → ℝ
h₁ : ∀ (i : ι), l₁ i < u₁ i
l₂ u₂ : ι → ℝ
h₂ : ∀ (i : ι), l₂ i < u₂ i
h : (l₂ ≤ l₁ ∧ u₁ ≤ u₂) ∧ l₁ ≤ l₂ ∧ u₂ ≤ u₁
⊢ u₁ = u₂
[PROOFSTEP]
exacts [le_antisymm h.2.1 h.1.1, le_antisymm h.1.2 h.2.2]
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
⊢ Option.isSome ⊥ = true ↔ Set.Nonempty ↑⊥
[PROOFSTEP]
erw [Option.isSome]
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
⊢ (match ⊥ with
| some val => true
| none => false) =
true ↔
Set.Nonempty ↑⊥
[PROOFSTEP]
simp
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
I : Box ι
⊢ Option.isSome ↑I = true ↔ Set.Nonempty ↑↑I
[PROOFSTEP]
erw [Option.isSome]
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
I : Box ι
⊢ (match ↑I with
| some val => true
| none => false) =
true ↔
Set.Nonempty ↑↑I
[PROOFSTEP]
simp [I.nonempty_coe]
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
I : WithBot (Box ι)
⊢ ⋃ (J : Box ι) (_ : ↑J = I), ↑J = ↑I
[PROOFSTEP]
induction I using WithBot.recBotCoe
[GOAL]
case bot
ι : Type u_1
I J : Box ι
x y : ι → ℝ
⊢ ⋃ (J : Box ι) (_ : ↑J = ⊥), ↑J = ↑⊥
[PROOFSTEP]
simp [WithBot.coe_eq_coe]
[GOAL]
case coe
ι : Type u_1
I J : Box ι
x y : ι → ℝ
a✝ : Box ι
⊢ ⋃ (J : Box ι) (_ : ↑J = ↑a✝), ↑J = ↑↑a✝
[PROOFSTEP]
simp [WithBot.coe_eq_coe]
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
I J : WithBot (Box ι)
⊢ ↑I ⊆ ↑J ↔ I ≤ J
[PROOFSTEP]
induction I using WithBot.recBotCoe
[GOAL]
case bot
ι : Type u_1
I J✝ : Box ι
x y : ι → ℝ
J : WithBot (Box ι)
⊢ ↑⊥ ⊆ ↑J ↔ ⊥ ≤ J
[PROOFSTEP]
simp
[GOAL]
case coe
ι : Type u_1
I J✝ : Box ι
x y : ι → ℝ
J : WithBot (Box ι)
a✝ : Box ι
⊢ ↑↑a✝ ⊆ ↑J ↔ ↑a✝ ≤ J
[PROOFSTEP]
induction J using WithBot.recBotCoe
[GOAL]
case coe.bot
ι : Type u_1
I J : Box ι
x y : ι → ℝ
a✝ : Box ι
⊢ ↑↑a✝ ⊆ ↑⊥ ↔ ↑a✝ ≤ ⊥
[PROOFSTEP]
simp [subset_empty_iff]
[GOAL]
case coe.coe
ι : Type u_1
I J : Box ι
x y : ι → ℝ
a✝¹ a✝ : Box ι
⊢ ↑↑a✝¹ ⊆ ↑↑a✝ ↔ ↑a✝¹ ≤ ↑a✝
[PROOFSTEP]
simp [le_def]
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
I J : WithBot (Box ι)
⊢ ↑I = ↑J ↔ I = J
[PROOFSTEP]
simp only [Subset.antisymm_iff, ← le_antisymm_iff, withBotCoe_subset_iff]
[GOAL]
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
⊢ mk' l u = ⊥ ↔ ∃ i, u i ≤ l i
[PROOFSTEP]
rw [mk']
[GOAL]
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
⊢ (if h : ∀ (i : ι), l i < u i then ↑{ lower := l, upper := u, lower_lt_upper := h } else ⊥) = ⊥ ↔ ∃ i, u i ≤ l i
[PROOFSTEP]
split_ifs with h
[GOAL]
case pos
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
h : ∀ (i : ι), l i < u i
⊢ ↑{ lower := l, upper := u, lower_lt_upper := h } = ⊥ ↔ ∃ i, u i ≤ l i
[PROOFSTEP]
simpa using h
[GOAL]
case neg
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
h : ¬∀ (i : ι), l i < u i
⊢ ⊥ = ⊥ ↔ ∃ i, u i ≤ l i
[PROOFSTEP]
simpa using h
[GOAL]
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
⊢ mk' l u = ↑I ↔ l = I.lower ∧ u = I.upper
[PROOFSTEP]
cases' I with lI uI hI
[GOAL]
case mk
ι : Type u_1
J : Box ι
x y l u lI uI : ι → ℝ
hI : ∀ (i : ι), lI i < uI i
⊢ mk' l u = ↑{ lower := lI, upper := uI, lower_lt_upper := hI } ↔
l = { lower := lI, upper := uI, lower_lt_upper := hI }.lower ∧
u = { lower := lI, upper := uI, lower_lt_upper := hI }.upper
[PROOFSTEP]
rw [mk']
[GOAL]
case mk
ι : Type u_1
J : Box ι
x y l u lI uI : ι → ℝ
hI : ∀ (i : ι), lI i < uI i
⊢ (if h : ∀ (i : ι), l i < u i then ↑{ lower := l, upper := u, lower_lt_upper := h } else ⊥) =
↑{ lower := lI, upper := uI, lower_lt_upper := hI } ↔
l = { lower := lI, upper := uI, lower_lt_upper := hI }.lower ∧
u = { lower := lI, upper := uI, lower_lt_upper := hI }.upper
[PROOFSTEP]
split_ifs with h
[GOAL]
case pos
ι : Type u_1
J : Box ι
x y l u lI uI : ι → ℝ
hI : ∀ (i : ι), lI i < uI i
h : ∀ (i : ι), l i < u i
⊢ ↑{ lower := l, upper := u, lower_lt_upper := h } = ↑{ lower := lI, upper := uI, lower_lt_upper := hI } ↔
l = { lower := lI, upper := uI, lower_lt_upper := hI }.lower ∧
u = { lower := lI, upper := uI, lower_lt_upper := hI }.upper
[PROOFSTEP]
simp [WithBot.coe_eq_coe]
[GOAL]
case neg
ι : Type u_1
J : Box ι
x y l u lI uI : ι → ℝ
hI : ∀ (i : ι), lI i < uI i
h : ¬∀ (i : ι), l i < u i
⊢ ⊥ = ↑{ lower := lI, upper := uI, lower_lt_upper := hI } ↔
l = { lower := lI, upper := uI, lower_lt_upper := hI }.lower ∧
u = { lower := lI, upper := uI, lower_lt_upper := hI }.upper
[PROOFSTEP]
suffices l = lI → u ≠ uI by simpa
[GOAL]
ι : Type u_1
J : Box ι
x y l u lI uI : ι → ℝ
hI : ∀ (i : ι), lI i < uI i
h : ¬∀ (i : ι), l i < u i
this : l = lI → u ≠ uI
⊢ ⊥ = ↑{ lower := lI, upper := uI, lower_lt_upper := hI } ↔
l = { lower := lI, upper := uI, lower_lt_upper := hI }.lower ∧
u = { lower := lI, upper := uI, lower_lt_upper := hI }.upper
[PROOFSTEP]
simpa
[GOAL]
case neg
ι : Type u_1
J : Box ι
x y l u lI uI : ι → ℝ
hI : ∀ (i : ι), lI i < uI i
h : ¬∀ (i : ι), l i < u i
⊢ l = lI → u ≠ uI
[PROOFSTEP]
rintro rfl rfl
[GOAL]
case neg
ι : Type u_1
J : Box ι
x y l u : ι → ℝ
h : ¬∀ (i : ι), l i < u i
hI : ∀ (i : ι), l i < u i
⊢ False
[PROOFSTEP]
exact h hI
[GOAL]
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
⊢ ↑(mk' l u) = Set.pi univ fun i => Ioc (l i) (u i)
[PROOFSTEP]
rw [mk']
[GOAL]
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
⊢ ↑(if h : ∀ (i : ι), l i < u i then ↑{ lower := l, upper := u, lower_lt_upper := h } else ⊥) =
Set.pi univ fun i => Ioc (l i) (u i)
[PROOFSTEP]
split_ifs with h
[GOAL]
case pos
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
h : ∀ (i : ι), l i < u i
⊢ ↑↑{ lower := l, upper := u, lower_lt_upper := h } = Set.pi univ fun i => Ioc (l i) (u i)
[PROOFSTEP]
exact coe_eq_pi _
[GOAL]
case neg
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
h : ¬∀ (i : ι), l i < u i
⊢ ↑⊥ = Set.pi univ fun i => Ioc (l i) (u i)
[PROOFSTEP]
rcases not_forall.mp h with ⟨i, hi⟩
[GOAL]
case neg.intro
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
h : ¬∀ (i : ι), l i < u i
i : ι
hi : ¬l i < u i
⊢ ↑⊥ = Set.pi univ fun i => Ioc (l i) (u i)
[PROOFSTEP]
rw [coe_bot, univ_pi_eq_empty]
[GOAL]
case neg.intro
ι : Type u_1
I J : Box ι
x y l u : ι → ℝ
h : ¬∀ (i : ι), l i < u i
i : ι
hi : ¬l i < u i
⊢ Ioc (l ?m.301759) (u ?m.301759) = ∅
ι : Type u_1 I J : Box ι x y l u : ι → ℝ h : ¬∀ (i : ι), l i < u i i : ι hi : ¬l i < u i ⊢ ι
[PROOFSTEP]
exact Ioc_eq_empty hi
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
I J : WithBot (Box ι)
⊢ ↑(I ⊓ J) = ↑I ∩ ↑J
[PROOFSTEP]
induction I using WithBot.recBotCoe
[GOAL]
case bot
ι : Type u_1
I J✝ : Box ι
x y : ι → ℝ
J : WithBot (Box ι)
⊢ ↑(⊥ ⊓ J) = ↑⊥ ∩ ↑J
[PROOFSTEP]
change ∅ = _
[GOAL]
case bot
ι : Type u_1
I J✝ : Box ι
x y : ι → ℝ
J : WithBot (Box ι)
⊢ ∅ = ↑⊥ ∩ ↑J
[PROOFSTEP]
simp
[GOAL]
case coe
ι : Type u_1
I J✝ : Box ι
x y : ι → ℝ
J : WithBot (Box ι)
a✝ : Box ι
⊢ ↑(↑a✝ ⊓ J) = ↑↑a✝ ∩ ↑J
[PROOFSTEP]
induction J using WithBot.recBotCoe
[GOAL]
case coe.bot
ι : Type u_1
I J : Box ι
x y : ι → ℝ
a✝ : Box ι
⊢ ↑(↑a✝ ⊓ ⊥) = ↑↑a✝ ∩ ↑⊥
[PROOFSTEP]
change ∅ = _
[GOAL]
case coe.bot
ι : Type u_1
I J : Box ι
x y : ι → ℝ
a✝ : Box ι
⊢ ∅ = ↑↑a✝ ∩ ↑⊥
[PROOFSTEP]
simp
[GOAL]
case coe.coe
ι : Type u_1
I J : Box ι
x y : ι → ℝ
a✝¹ a✝ : Box ι
⊢ ↑(↑a✝¹ ⊓ ↑a✝) = ↑↑a✝¹ ∩ ↑↑a✝
[PROOFSTEP]
change ((mk' _ _ : WithBot (Box ι)) : Set (ι → ℝ)) = _
[GOAL]
case coe.coe
ι : Type u_1
I J : Box ι
x y : ι → ℝ
a✝¹ a✝ : Box ι
⊢ ↑(mk' (fun i => (a✝¹.lower ⊔ a✝.lower) i) fun i => (a✝¹.upper ⊓ a✝.upper) i) = ↑↑a✝¹ ∩ ↑↑a✝
[PROOFSTEP]
simp only [coe_eq_pi, ← pi_inter_distrib, Ioc_inter_Ioc, Pi.sup_apply, Pi.inf_apply, coe_mk', coe_coe]
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
src✝¹ : SemilatticeSup (WithBot (Box ι)) := WithBot.semilatticeSup
src✝ : Inf (WithBot (Box ι)) := WithBot.inf
I J : WithBot (Box ι)
⊢ I ⊓ J ≤ I
[PROOFSTEP]
rw [← withBotCoe_subset_iff, coe_inf]
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
src✝¹ : SemilatticeSup (WithBot (Box ι)) := WithBot.semilatticeSup
src✝ : Inf (WithBot (Box ι)) := WithBot.inf
I J : WithBot (Box ι)
⊢ ↑I ∩ ↑J ⊆ ↑I
[PROOFSTEP]
exact inter_subset_left _ _
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
src✝¹ : SemilatticeSup (WithBot (Box ι)) := WithBot.semilatticeSup
src✝ : Inf (WithBot (Box ι)) := WithBot.inf
I J : WithBot (Box ι)
⊢ I ⊓ J ≤ J
[PROOFSTEP]
rw [← withBotCoe_subset_iff, coe_inf]
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
src✝¹ : SemilatticeSup (WithBot (Box ι)) := WithBot.semilatticeSup
src✝ : Inf (WithBot (Box ι)) := WithBot.inf
I J : WithBot (Box ι)
⊢ ↑I ∩ ↑J ⊆ ↑J
[PROOFSTEP]
exact inter_subset_right _ _
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
src✝¹ : SemilatticeSup (WithBot (Box ι)) := WithBot.semilatticeSup
src✝ : Inf (WithBot (Box ι)) := WithBot.inf
I J₁ J₂ : WithBot (Box ι)
h₁ : I ≤ J₁
h₂ : I ≤ J₂
⊢ I ≤ J₁ ⊓ J₂
[PROOFSTEP]
simp only [← withBotCoe_subset_iff, coe_inf] at *
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
src✝¹ : SemilatticeSup (WithBot (Box ι)) := WithBot.semilatticeSup
src✝ : Inf (WithBot (Box ι)) := WithBot.inf
I J₁ J₂ : WithBot (Box ι)
h₁ : ↑I ⊆ ↑J₁
h₂ : ↑I ⊆ ↑J₂
⊢ ↑I ⊆ ↑J₁ ∩ ↑J₂
[PROOFSTEP]
exact subset_inter h₁ h₂
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
I J : WithBot (Box ι)
⊢ Disjoint ↑I ↑J ↔ Disjoint I J
[PROOFSTEP]
simp only [disjoint_iff_inf_le, ← withBotCoe_subset_iff, coe_inf]
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
I J : WithBot (Box ι)
⊢ ↑I ⊓ ↑J ≤ ⊥ ↔ ↑I ∩ ↑J ⊆ ↑⊥
[PROOFSTEP]
rfl
[GOAL]
ι : Type u_1
I J : Box ι
x y : ι → ℝ
⊢ ¬Disjoint ↑I ↑J ↔ Set.Nonempty (↑I ∩ ↑J)
[PROOFSTEP]
rw [disjoint_coe, Set.not_disjoint_iff_nonempty_inter]
[GOAL]
ι : Type u_1
I✝ J : Box ι
x✝ y : ι → ℝ
n : ℕ
I : Box (Fin (n + 1))
i : Fin (n + 1)
x : ℝ
hx : x ∈ Ioc (lower I i) (upper I i)
⊢ MapsTo (Fin.insertNth i x) ↑(face I i) ↑I
[PROOFSTEP]
intro y hy
[GOAL]
ι : Type u_1
I✝ J : Box ι
x✝ y✝ : ι → ℝ
n : ℕ
I : Box (Fin (n + 1))
i : Fin (n + 1)
x : ℝ
hx : x ∈ Ioc (lower I i) (upper I i)
y : Fin n → ℝ
hy : y ∈ ↑(face I i)
⊢ Fin.insertNth i x y ∈ ↑I
[PROOFSTEP]
simp_rw [mem_coe, mem_def, i.forall_iff_succAbove, Fin.insertNth_apply_same, Fin.insertNth_apply_succAbove]
[GOAL]
ι : Type u_1
I✝ J : Box ι
x✝ y✝ : ι → ℝ
n : ℕ
I : Box (Fin (n + 1))
i : Fin (n + 1)
x : ℝ
hx : x ∈ Ioc (lower I i) (upper I i)
y : Fin n → ℝ
hy : y ∈ ↑(face I i)
⊢ x ∈ Ioc (lower I i) (upper I i) ∧ ∀ (j : Fin n), y j ∈ Ioc (lower I (Fin.succAbove i j)) (upper I (Fin.succAbove i j))
[PROOFSTEP]
exact ⟨hx, hy⟩
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
I : Box ι
⊢ ∃ J,
(∀ (n : ℕ), ↑Box.Icc (↑J n) ⊆ ↑Box.Ioo I) ∧
Tendsto (lower ∘ ↑J) atTop (𝓝 I.lower) ∧ Tendsto (upper ∘ ↑J) atTop (𝓝 I.upper)
[PROOFSTEP]
choose a b ha_anti hb_mono ha_mem hb_mem hab ha_tendsto hb_tendsto using fun i ↦
exists_seq_strictAnti_strictMono_tendsto (I.lower_lt_upper i)
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
I : Box ι
a b : ι → ℕ → ℝ
ha_anti : ∀ (i : ι), StrictAnti (a i)
hb_mono : ∀ (i : ι), StrictMono (b i)
ha_mem : ∀ (i : ι) (k : ℕ), a i k ∈ Ioo (lower I i) (upper I i)
hb_mem : ∀ (i : ι) (l : ℕ), b i l ∈ Ioo (lower I i) (upper I i)
hab : ∀ (i : ι) (k l : ℕ), a i k < b i l
ha_tendsto : ∀ (i : ι), Tendsto (a i) atTop (𝓝 (lower I i))
hb_tendsto : ∀ (i : ι), Tendsto (b i) atTop (𝓝 (upper I i))
⊢ ∃ J,
(∀ (n : ℕ), ↑Box.Icc (↑J n) ⊆ ↑Box.Ioo I) ∧
Tendsto (lower ∘ ↑J) atTop (𝓝 I.lower) ∧ Tendsto (upper ∘ ↑J) atTop (𝓝 I.upper)
[PROOFSTEP]
exact
⟨⟨fun k ↦ ⟨flip a k, flip b k, fun i ↦ hab _ _ _⟩, fun k l hkl ↦
le_iff_bounds.2 ⟨fun i ↦ (ha_anti i).antitone hkl, fun i ↦ (hb_mono i).monotone hkl⟩⟩,
fun n x hx i _ ↦ ⟨(ha_mem _ _).1.trans_le (hx.1 _), (hx.2 _).trans_lt (hb_mem _ _).2⟩, tendsto_pi_nhds.2 ha_tendsto,
tendsto_pi_nhds.2 hb_tendsto⟩
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
⊢ distortion I = distortion J
[PROOFSTEP]
simp only [distortion, nndist_pi_def, Real.nndist_eq', h, map_div₀]
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
⊢ (Finset.sup Finset.univ fun i =>
(Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b) / ↑Real.nnabs r) /
(↑Real.nnabs (upper J i - lower J i) / ↑Real.nnabs r)) =
Finset.sup Finset.univ fun i =>
(Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b)) / ↑Real.nnabs (upper J i - lower J i)
[PROOFSTEP]
congr 1 with i
[GOAL]
case e_f.h.a
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
i : ι
⊢ ↑((Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b) / ↑Real.nnabs r) /
(↑Real.nnabs (upper J i - lower J i) / ↑Real.nnabs r)) =
↑((Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b)) / ↑Real.nnabs (upper J i - lower J i))
[PROOFSTEP]
have : 0 < r := by
by_contra hr
have := div_nonpos_of_nonneg_of_nonpos (sub_nonneg.2 <| J.lower_le_upper i) (not_lt.1 hr)
rw [← h] at this
exact this.not_lt (sub_pos.2 <| I.lower_lt_upper i)
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
i : ι
⊢ 0 < r
[PROOFSTEP]
by_contra hr
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
i : ι
hr : ¬0 < r
⊢ False
[PROOFSTEP]
have := div_nonpos_of_nonneg_of_nonpos (sub_nonneg.2 <| J.lower_le_upper i) (not_lt.1 hr)
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
i : ι
hr : ¬0 < r
this : (upper J i - lower J i) / r ≤ 0
⊢ False
[PROOFSTEP]
rw [← h] at this
[GOAL]
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
i : ι
hr : ¬0 < r
this : upper I i - lower I i ≤ 0
⊢ False
[PROOFSTEP]
exact this.not_lt (sub_pos.2 <| I.lower_lt_upper i)
[GOAL]
case e_f.h.a
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
i : ι
this : 0 < r
⊢ ↑((Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b) / ↑Real.nnabs r) /
(↑Real.nnabs (upper J i - lower J i) / ↑Real.nnabs r)) =
↑((Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b)) / ↑Real.nnabs (upper J i - lower J i))
[PROOFSTEP]
have hn0 := (map_ne_zero Real.nnabs).2 this.ne'
[GOAL]
case e_f.h.a
ι : Type u_1
I✝ J✝ : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I J : Box ι
r : ℝ
h : ∀ (i : ι), upper I i - lower I i = (upper J i - lower J i) / r
i : ι
this : 0 < r
hn0 : ↑Real.nnabs r ≠ 0
⊢ ↑((Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b) / ↑Real.nnabs r) /
(↑Real.nnabs (upper J i - lower J i) / ↑Real.nnabs r)) =
↑((Finset.sup Finset.univ fun b => ↑Real.nnabs (upper J b - lower J b)) / ↑Real.nnabs (upper J i - lower J i))
[PROOFSTEP]
simp_rw [NNReal.finset_sup_div, div_div_div_cancel_right _ hn0]
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I : Box ι
i : ι
⊢ nndist I.lower I.upper / nndist (lower I i) (upper I i) * nndist (lower I i) (upper I i) ≤
distortion I * nndist (lower I i) (upper I i)
[PROOFSTEP]
apply mul_le_mul_right'
[GOAL]
case bc
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I : Box ι
i : ι
⊢ nndist I.lower I.upper / nndist (lower I i) (upper I i) ≤ distortion I
[PROOFSTEP]
apply Finset.le_sup (Finset.mem_univ i)
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I : Box ι
i : ι
⊢ dist I.lower I.upper ≤ ↑(distortion I) * (upper I i - lower I i)
[PROOFSTEP]
have A : I.lower i - I.upper i < 0 := sub_neg.2 (I.lower_lt_upper i)
[GOAL]
ι : Type u_1
I✝ J : Box ι
x y : ι → ℝ
inst✝ : Fintype ι
I : Box ι
i : ι
A : lower I i - upper I i < 0
⊢ dist I.lower I.upper ≤ ↑(distortion I) * (upper I i - lower I i)
[PROOFSTEP]
simpa only [← NNReal.coe_le_coe, ← dist_nndist, NNReal.coe_mul, Real.dist_eq, abs_of_neg A, neg_sub] using
I.nndist_le_distortion_mul i
[GOAL]
ι : Type u_1
I✝ J : Box ι
x✝ y✝ : ι → ℝ
inst✝ : Fintype ι
I : Box ι
i : ι
c : ℝ≥0
h : distortion I ≤ c
this : 0 ≤ ↑c * (upper I i - lower I i)
x : ι → ℝ
hx : x ∈ ↑Box.Icc I
y : ι → ℝ
hy : y ∈ ↑Box.Icc I
⊢ ↑(distortion I) * (upper I i - lower I i) ≤ ↑c * (upper I i - lower I i)
[PROOFSTEP]
gcongr
[GOAL]
case a0
ι : Type u_1
I✝ J : Box ι
x✝ y✝ : ι → ℝ
inst✝ : Fintype ι
I : Box ι
i : ι
c : ℝ≥0
h : distortion I ≤ c
this : 0 ≤ ↑c * (upper I i - lower I i)
x : ι → ℝ
hx : x ∈ ↑Box.Icc I
y : ι → ℝ
hy : y ∈ ↑Box.Icc I
⊢ 0 ≤ upper I i - lower I i
[PROOFSTEP]
exact sub_nonneg.2 (I.lower_le_upper i)
|
import data.real.irrational
import topology.basic
import algebra.order.floor
--OUTPUT 1
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
have h1 : ∀ i j : ℤ, i ≠ j → int.fract (α * ↑i) ≠ int.fract (α * ↑j), from by auto [int.fract_eq_iff, mul_eq_zero, hα_irrat],
have h2 : ∀ i j : ℤ, i ≠ j → int.fract (α * ↑i) ≠ int.fract (α * ↑j), from by auto [int.fract_eq_iff, mul_eq_zero, hα_irrat],
have h3 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h4 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h5 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h6 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h7 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h8 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h9 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h10 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h11 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h12 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h13 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h14 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h15 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h16 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h17 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h18 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h19 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h20 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h21 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h22 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h23 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h24 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h25 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h26 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h27 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h28 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h29 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h30 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h31 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h32 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h33 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h34 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h35 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h36 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h37 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h38 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h39 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h40 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h41 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h42 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one],
have h43 : ∀ i : ℤ, int.fract (α * ↑i)
end --Needs more than 2000 tokens!
--OUTPUT 2
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
have h1 : ∀ i j : ℤ, i ≠ j → (int.fract (α * ↑i)) ≠ (int.fract (α * ↑j)), from
begin
assume (i j : ℤ) (hij : i ≠ j),
have h1 : (int.fract (α * ↑i)) = (α * ↑i) - (int.nat_abs (α * ↑i)), from by auto [int.fract_def],
have h2 : (int.fract (α * ↑j)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [int.fract_def],
have h3 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h4 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h5 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h6 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h7 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h8 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h9 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h10 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h11 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h12 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h13 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h14 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h15 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h16 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h17 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h18 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h19 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h20 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h21 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h22 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h23 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h24 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h25 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h26 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h27 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h28 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h29 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h30 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h31 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h32 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h33 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h34 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h35 : (α * ↑i) - (int.nat_abs (α * ↑i)) = (α * ↑j) - (int.nat_abs (α * ↑j)), from by auto [h1, h2],
have h36 : (α * ↑i) - (int.nat_
end --Needs more than 2000 tokens!
--OUTPUT 3
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
have h1 : ∀ i j : ℤ, i ≠ j → int.fract (α * ↑i) ≠ int.fract (α * ↑j), from
begin
assume (i j : ℤ) (hij : i ≠ j),
have h1 : (α * ↑i) - int.floor (α * ↑i) = int.fract (α * ↑i), from by auto [int.fract_eq_iff_eq_floor],
have h2 : (α * ↑j) - int.floor (α * ↑j) = int.fract (α * ↑j), from by auto [int.fract_eq_iff_eq_floor],
have h3 : (α * ↑i) - int.floor (α * ↑i) = (α * ↑j) - int.floor (α * ↑j), from by auto [h1, h2],
have h4 : α = (int.floor (α * ↑i) - int.floor (α * ↑j)) / (i - j), from by auto [int.fract_eq_iff_eq_floor, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul_left_cancel, mul_comm, mul
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
assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),
have h1 : (A ⊆ S) ∧ (B ⊆ S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],
have h2 : (A ∩ B) ⊆ A, from by auto [set.inter_subset_left],
have h3 : (A ∩ B) ⊆ S, from by auto [set.subset.trans],
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
calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]
... = x*(x+y) + y*(x+y) : by auto [add_mul]
... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]
... = 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
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⁻¹],
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],
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`
Density of irrational orbit
The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval
`proof`
Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then
$$
i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor,
$$
which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence,
$$
S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}
$$
is an infinite subset of $\left[0,1\right]$.
By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$.
To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. Then by selecting $x \in S$ such that $\{x\}<\epsilon$ (which exists as $0$ is a limit point), and $N$ such that $N \cdot\{x\} \leq y<(N+1) \cdot\{x\}$, we get: $|y-\{N x\}|<\epsilon$.
QED
-/
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
FEW SHOT PROMPTS TO CODEX(END)-/
|
"""
exactShift!(hh,qq, iq, qrows, qcols, neq)
Compute the exact shiftrights and store them in qq.
"""
function exactShift!(hh::Array{Float64,2}, qq::Array{Float64,2}, iq::Int64, qRows::Int64, qCols::Int64, neq::Int64)
# total number of shifts
nexact = 0
# functions to seperate hh
left = 1:qCols
right = (qCols + 1):(qCols + neq)
# get right most columns of hh
zerorows = copy(hh[:, right]')
# compute absolute value
zerorows = abs.(zerorows)
# take the sum of the rows (aka 1st dimenison in julia)
zerorows = Compat.sum(zerorows; dims=1)
# anon function returns index of the rows who sum is 0
zerorows = LinearIndices(zerorows)[findall(row->(row == 0), zerorows)]
# continues until all zerorow indexes have been processed
while length(zerorows) != 0 && (iq <= qRows)
nz = size(zerorows, 1)
# insert only the indexes found with zerorows into qq
qq[(iq + 1):(iq + nz), :] = hh[zerorows, left]
# update by shifting right by $neq columns
hh[zerorows,:] = shiftRight!(hh[zerorows, :], neq)
# increment the variables the amount of zerorows found
iq = iq + nz
nexact = nexact + nz
# update zerorows as before but with our new hh matrix
zerorows = hh[:, right]'
zerorows = abs.(zerorows)
zerorows = Compat.sum(zerorows; dims=1)
zerorows = LinearIndices(zerorows)[findall(row->(row == 0), zerorows)]
end # while
return (hh, qq, iq, nexact)
end # exactShift
|
Are you thinking about using online assignment help platforms? If you answered yes, then you are definitely not alone. This service is increasing in popularity across the globe. It makes it easier for students to handle their school requirements. But the nature of the service remains shrouded in controversy. After all, teachers and professors give out assignments for a reason. They are meant to boost the skills of students both inside and outside the classroom. This begs the question: Do assignment help services benefit or hurt students?
It’s easy to see the benefits of hiring assignments experts to aid in your academic pursuits. They solve the problem of insufficient time to do homework’s, especially if you take on multiple part-time jobs after school hours. As you know, writing essays or completing complicated assignments can take up a boatload of time. Between gathering information and adding the final touches, your assignment can take several hours to finish.
The speed with which you can finish your assignments with the help of service providers like the guys at Do My Assignments is another huge benefit. Most companies accept expedited requests for an extra fee. It’s possible to get your paper or assignment in as little as 24 hours. While these aforementioned benefits are surely hard to resist, it’s worth noting that using assignment writing services offers more than meets the eye.
At first, it might not appear to make sense that hiring assignment help providers can improve your research skills. You don’t even need to research about anything. They will do everything for you, and this is where you can get tips from the experts.
By looking at the final output of the assignment expert, you could see how much it differs from the homework’s you have done yourself. It shouldn’t come as a surprise if these differences are very noticeable. You could tell that time and effort has been dedicated to producing such a well-researched assignment. Even the references and links can help you with your future requirements, as you would see how much more credible your work will look like if the links aren’t limited to Wikipedia.
The same applies to your presentation skills. The way the essay, research paper, or assignment is formatted can give you ideas on how to better structure your content. Notice how the ideas flow smoothly throughout, allowing you to get the point across even without the use of fancy words. You probably have a “go-to” format for your essays, but you’ll realize that it doesn’t always work.
It’s easy to dismiss assignment writing services as only for lazy students who do not care at all about learning. But it’s important to understand that the students can enjoy much more than its time-saving benefits. With the help of experts, you can pick up some tips on how to research about a topic, what credible sources to use, and how to present your ideas in a way that engages readers. All of these can prove beneficial for any student, even the ones who do remarkably well in class. |
The murmurous haunt of flies on summer eves . 50
|
{-# OPTIONS --without-K #-}
module Data.Tuple where
open import Data.Tuple.Base public
import Data.Product as P
Pair→× : ∀ {a b A B} → Pair {a} {b} A B → A P.× B
Pair→× (fst , snd) = fst P., snd
×→Pair : ∀ {a b A B} → P._×_ {a} {b} A B → Pair A B
×→Pair (fst P., snd) = fst , snd
|
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
⊢ CompleteLattice (Presieve X)
[PROOFSTEP]
dsimp [Presieve]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
⊢ CompleteLattice (⦃Y : C⦄ → Set (Y ⟶ X))
[PROOFSTEP]
infer_instance
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ f g : Y ⟶ X
⊢ singleton f g ↔ f = g
[PROOFSTEP]
constructor
[GOAL]
case mp
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ f g : Y ⟶ X
⊢ singleton f g → f = g
[PROOFSTEP]
rintro ⟨a, rfl⟩
[GOAL]
case mp.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ f : Y✝ ⟶ X
Y : C
⊢ f = f
[PROOFSTEP]
rfl
[GOAL]
case mpr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ f g : Y ⟶ X
⊢ f = g → singleton f g
[PROOFSTEP]
rintro rfl
[GOAL]
case mpr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ f : Y ⟶ X
⊢ singleton f f
[PROOFSTEP]
apply singleton.mk
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
inst✝ : HasPullbacks C
g : Z ⟶ X
⊢ pullbackArrows f (singleton g) = singleton pullback.snd
[PROOFSTEP]
funext W
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
inst✝ : HasPullbacks C
g : Z ⟶ X
W : C
⊢ pullbackArrows f (singleton g) = singleton pullback.snd
[PROOFSTEP]
ext h
[GOAL]
case h.h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
inst✝ : HasPullbacks C
g : Z ⟶ X
W : C
h : W ⟶ Y
⊢ h ∈ pullbackArrows f (singleton g) ↔ h ∈ singleton pullback.snd
[PROOFSTEP]
constructor
[GOAL]
case h.h.mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
inst✝ : HasPullbacks C
g : Z ⟶ X
W : C
h : W ⟶ Y
⊢ h ∈ pullbackArrows f (singleton g) → h ∈ singleton pullback.snd
[PROOFSTEP]
rintro ⟨W, _, _, _⟩
[GOAL]
case h.h.mp.mk.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝¹ Z : C
f : Y✝¹ ⟶ X
inst✝ : HasPullbacks C
g : Z ⟶ X
Y✝ Y : C
⊢ pullback.snd ∈ singleton pullback.snd
[PROOFSTEP]
exact singleton.mk
[GOAL]
case h.h.mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
inst✝ : HasPullbacks C
g : Z ⟶ X
W : C
h : W ⟶ Y
⊢ h ∈ singleton pullback.snd → h ∈ pullbackArrows f (singleton g)
[PROOFSTEP]
rintro ⟨_⟩
[GOAL]
case h.h.mpr.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
inst✝ : HasPullbacks C
g : Z ⟶ X
Y : C
⊢ pullback.snd ∈ pullbackArrows f (singleton g)
[PROOFSTEP]
exact pullbackArrows.mk Z g singleton.mk
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
⊢ (ofArrows (fun x => Y) fun x => f) = singleton f
[PROOFSTEP]
funext Y
[GOAL]
case h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
Y : C
⊢ (ofArrows (fun x => Y✝) fun x => f) = singleton f
[PROOFSTEP]
ext g
[GOAL]
case h.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
Y : C
g : Y ⟶ X
⊢ (g ∈ ofArrows (fun x => Y✝) fun x => f) ↔ g ∈ singleton f
[PROOFSTEP]
constructor
[GOAL]
case h.h.mp
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
Y : C
g : Y ⟶ X
⊢ (g ∈ ofArrows (fun x => Y✝) fun x => f) → g ∈ singleton f
[PROOFSTEP]
rintro ⟨_⟩
[GOAL]
case h.h.mp.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
Y : C
i✝ : PUnit
⊢ f ∈ singleton f
[PROOFSTEP]
apply singleton.mk
[GOAL]
case h.h.mpr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
Y : C
g : Y ⟶ X
⊢ g ∈ singleton f → g ∈ ofArrows (fun x => Y✝) fun x => f
[PROOFSTEP]
rintro ⟨_⟩
[GOAL]
case h.h.mpr.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
Y : C
⊢ f ∈ ofArrows (fun x => Y✝) fun x => f
[PROOFSTEP]
exact ofArrows.mk PUnit.unit
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f : Y ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
⊢ (ofArrows (fun i => pullback (g i) f) fun i => pullback.snd) = pullbackArrows f (ofArrows Z g)
[PROOFSTEP]
funext T
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f : Y ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
T : C
⊢ (ofArrows (fun i => pullback (g i) f) fun i => pullback.snd) = pullbackArrows f (ofArrows Z g)
[PROOFSTEP]
ext h
[GOAL]
case h.h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f : Y ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
T : C
h : T ⟶ Y
⊢ (h ∈ ofArrows (fun i => pullback (g i) f) fun i => pullback.snd) ↔ h ∈ pullbackArrows f (ofArrows Z g)
[PROOFSTEP]
constructor
[GOAL]
case h.h.mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f : Y ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
T : C
h : T ⟶ Y
⊢ (h ∈ ofArrows (fun i => pullback (g i) f) fun i => pullback.snd) → h ∈ pullbackArrows f (ofArrows Z g)
[PROOFSTEP]
rintro ⟨hk⟩
[GOAL]
case h.h.mp.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f : Y✝ ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
Y : C
hk : ι
⊢ pullback.snd ∈ pullbackArrows f (ofArrows Z g)
[PROOFSTEP]
exact pullbackArrows.mk _ _ (ofArrows.mk hk)
[GOAL]
case h.h.mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f : Y ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
T : C
h : T ⟶ Y
⊢ h ∈ pullbackArrows f (ofArrows Z g) → h ∈ ofArrows (fun i => pullback (g i) f) fun i => pullback.snd
[PROOFSTEP]
rintro ⟨W, k, hk₁⟩
[GOAL]
case h.h.mpr.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f : Y✝ ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
Y W : C
k : W ⟶ X
hk₁ : ofArrows Z g k
⊢ pullback.snd ∈ ofArrows (fun i => pullback (g i) f) fun i => pullback.snd
[PROOFSTEP]
cases' hk₁ with i hi
[GOAL]
case h.h.mpr.mk.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f : Y✝ ⟶ X
inst✝ : HasPullbacks C
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
Y : C
i : ι
⊢ pullback.snd ∈ ofArrows (fun i => pullback (g i) f) fun i => pullback.snd
[PROOFSTEP]
apply ofArrows.mk
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f : Y ⟶ X
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
j : ⦃Y : C⦄ → (f : Y ⟶ X) → ofArrows Z g f → Type u_2
W : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → j f H → C
k : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → (i : j f H) → W f H i ⟶ Y
⊢ (bind (ofArrows Z g) fun Y f H => ofArrows (W f H) (k f H)) =
ofArrows (fun i => W (g i.fst) (_ : ofArrows Z g (g i.fst)) i.snd) fun ij =>
k (g ij.fst) (_ : ofArrows Z g (g ij.fst)) ij.snd ≫ g ij.fst
[PROOFSTEP]
funext Y
[GOAL]
case h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f : Y✝ ⟶ X
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
j : ⦃Y : C⦄ → (f : Y ⟶ X) → ofArrows Z g f → Type u_2
W : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → j f H → C
k : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → (i : j f H) → W f H i ⟶ Y
Y : C
⊢ (bind (ofArrows Z g) fun Y f H => ofArrows (W f H) (k f H)) =
ofArrows (fun i => W (g i.fst) (_ : ofArrows Z g (g i.fst)) i.snd) fun ij =>
k (g ij.fst) (_ : ofArrows Z g (g ij.fst)) ij.snd ≫ g ij.fst
[PROOFSTEP]
ext f
[GOAL]
case h.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
j : ⦃Y : C⦄ → (f : Y ⟶ X) → ofArrows Z g f → Type u_2
W : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → j f H → C
k : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → (i : j f H) → W f H i ⟶ Y
Y : C
f : Y ⟶ X
⊢ (f ∈ bind (ofArrows Z g) fun Y f H => ofArrows (W f H) (k f H)) ↔
f ∈
ofArrows (fun i => W (g i.fst) (_ : ofArrows Z g (g i.fst)) i.snd) fun ij =>
k (g ij.fst) (_ : ofArrows Z g (g ij.fst)) ij.snd ≫ g ij.fst
[PROOFSTEP]
constructor
[GOAL]
case h.h.mp
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
j : ⦃Y : C⦄ → (f : Y ⟶ X) → ofArrows Z g f → Type u_2
W : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → j f H → C
k : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → (i : j f H) → W f H i ⟶ Y
Y : C
f : Y ⟶ X
⊢ (f ∈ bind (ofArrows Z g) fun Y f H => ofArrows (W f H) (k f H)) →
f ∈
ofArrows (fun i => W (g i.fst) (_ : ofArrows Z g (g i.fst)) i.snd) fun ij =>
k (g ij.fst) (_ : ofArrows Z g (g ij.fst)) ij.snd ≫ g ij.fst
[PROOFSTEP]
rintro ⟨_, _, _, ⟨i⟩, ⟨i'⟩, rfl⟩
[GOAL]
case h.h.mp.intro.intro.intro.intro.mk.intro.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝¹ Z✝ : C
f : Y✝¹ ⟶ X
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
j : ⦃Y : C⦄ → (f : Y ⟶ X) → ofArrows Z g f → Type u_2
W : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → j f H → C
k : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → (i : j f H) → W f H i ⟶ Y
Y✝ : C
i : ι
Y : C
i' : j (g i) (_ : ofArrows Z g (g i))
⊢ k (g i) (_ : ofArrows Z g (g i)) i' ≫ g i ∈
ofArrows (fun i => W (g i.fst) (_ : ofArrows Z g (g i.fst)) i.snd) fun ij =>
k (g ij.fst) (_ : ofArrows Z g (g ij.fst)) ij.snd ≫ g ij.fst
[PROOFSTEP]
exact ofArrows.mk (Sigma.mk _ _)
[GOAL]
case h.h.mpr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
j : ⦃Y : C⦄ → (f : Y ⟶ X) → ofArrows Z g f → Type u_2
W : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → j f H → C
k : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → (i : j f H) → W f H i ⟶ Y
Y : C
f : Y ⟶ X
⊢ (f ∈
ofArrows (fun i => W (g i.fst) (_ : ofArrows Z g (g i.fst)) i.snd) fun ij =>
k (g ij.fst) (_ : ofArrows Z g (g ij.fst)) ij.snd ≫ g ij.fst) →
f ∈ bind (ofArrows Z g) fun Y f H => ofArrows (W f H) (k f H)
[PROOFSTEP]
rintro ⟨i⟩
[GOAL]
case h.h.mpr.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f : Y✝ ⟶ X
ι : Type u_1
Z : ι → C
g : (i : ι) → Z i ⟶ X
j : ⦃Y : C⦄ → (f : Y ⟶ X) → ofArrows Z g f → Type u_2
W : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → j f H → C
k : ⦃Y : C⦄ → (f : Y ⟶ X) → (H : ofArrows Z g f) → (i : j f H) → W f H i ⟶ Y
Y : C
i : (i : ι) × j (g i) (_ : ofArrows Z g (g i))
⊢ k (g i.fst) (_ : ofArrows Z g (g i.fst)) i.snd ≫ g i.fst ∈ bind (ofArrows Z g) fun Y f H => ofArrows (W f H) (k f H)
[PROOFSTEP]
exact bind_comp _ (ofArrows.mk _) (ofArrows.mk _)
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F✝ : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
F : C ⥤ D
S : Presieve X
Y : D
f : Y ⟶ F.obj X
h : functorPushforward F S f
⊢ FunctorPushforwardStructure F S f
[PROOFSTEP]
choose Z f' g h₁ h using h
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F✝ : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
F : C ⥤ D
S : Presieve X
Y : D
f : Y ⟶ F.obj X
Z : C
f' : Z ⟶ X
g : Y ⟶ F.obj Z
h₁ : S f'
h : f = g ≫ F.map f'
⊢ FunctorPushforwardStructure F S f
[PROOFSTEP]
exact ⟨Z, f', g, h₁, h⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
⊢ functorPushforward (F ⋙ G) R = functorPushforward G (functorPushforward F R)
[PROOFSTEP]
funext x
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
x : E
⊢ functorPushforward (F ⋙ G) R = functorPushforward G (functorPushforward F R)
[PROOFSTEP]
ext f
[GOAL]
case h.h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
x : E
f : x ⟶ (F ⋙ G).obj X
⊢ f ∈ functorPushforward (F ⋙ G) R ↔ f ∈ functorPushforward G (functorPushforward F R)
[PROOFSTEP]
constructor
[GOAL]
case h.h.mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
x : E
f : x ⟶ (F ⋙ G).obj X
⊢ f ∈ functorPushforward (F ⋙ G) R → f ∈ functorPushforward G (functorPushforward F R)
[PROOFSTEP]
rintro ⟨X, f₁, g₁, h₁, rfl⟩
[GOAL]
case h.h.mp.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X✝
x : E
X : C
f₁ : X ⟶ X✝
g₁ : x ⟶ (F ⋙ G).obj X
h₁ : R f₁
⊢ g₁ ≫ (F ⋙ G).map f₁ ∈ functorPushforward G (functorPushforward F R)
[PROOFSTEP]
exact ⟨F.obj X, F.map f₁, g₁, ⟨X, f₁, 𝟙 _, h₁, by simp⟩, rfl⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X✝
x : E
X : C
f₁ : X ⟶ X✝
g₁ : x ⟶ (F ⋙ G).obj X
h₁ : R f₁
⊢ F.map f₁ = 𝟙 (F.obj X) ≫ F.map f₁
[PROOFSTEP]
simp
[GOAL]
case h.h.mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
x : E
f : x ⟶ (F ⋙ G).obj X
⊢ f ∈ functorPushforward G (functorPushforward F R) → f ∈ functorPushforward (F ⋙ G) R
[PROOFSTEP]
rintro ⟨X, f₁, g₁, ⟨X', f₂, g₂, h₁, rfl⟩, rfl⟩
[GOAL]
case h.h.mpr.intro.intro.intro.intro.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X✝
x : E
X : D
g₁ : x ⟶ G.obj X
X' : C
f₂ : X' ⟶ X✝
g₂ : X ⟶ F.obj X'
h₁ : R f₂
⊢ g₁ ≫ G.map (g₂ ≫ F.map f₂) ∈ functorPushforward (F ⋙ G) R
[PROOFSTEP]
exact ⟨X', f₂, g₁ ≫ G.map g₂, h₁, by simp⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X✝
x : E
X : D
g₁ : x ⟶ G.obj X
X' : C
f₂ : X' ⟶ X✝
g₂ : X ⟶ F.obj X'
h₁ : R f₂
⊢ g₁ ≫ G.map (g₂ ≫ F.map f₂) = (g₁ ≫ G.map g₂) ≫ (F ⋙ G).map f₂
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
f : Y ⟶ X
h : R f
⊢ F.map f = 𝟙 (F.obj Y) ≫ F.map f
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
⊢ ∀ {R S : Sieve X}, R.arrows = S.arrows → R = S
[PROOFSTEP]
rintro ⟨_, _⟩ ⟨_, _⟩ rfl
[GOAL]
case mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
arrows✝ : Presieve X
downward_closed✝¹ : ∀ {Y Z : C} {f : Y ⟶ X}, arrows✝ f → ∀ (g : Z ⟶ Y), arrows✝ (g ≫ f)
downward_closed✝ :
∀ {Y Z : C} {f : Y ⟶ X},
{ arrows := arrows✝, downward_closed := downward_closed✝¹ }.arrows f →
∀ (g : Z ⟶ Y), { arrows := arrows✝, downward_closed := downward_closed✝¹ }.arrows (g ≫ f)
⊢ { arrows := arrows✝, downward_closed := downward_closed✝¹ } =
{ arrows := { arrows := arrows✝, downward_closed := downward_closed✝¹ }.arrows,
downward_closed := downward_closed✝ }
[PROOFSTEP]
rfl
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
𝒮 : Set (Sieve X)
x✝² x✝¹ : C
f : x✝² ⟶ X
hf : (fun Y => {f | ∃ S, S ∈ 𝒮 ∧ S.arrows f}) x✝² f
x✝ : x✝¹ ⟶ x✝²
⊢ (fun Y => {f | ∃ S, S ∈ 𝒮 ∧ S.arrows f}) x✝¹ (x✝ ≫ f)
[PROOFSTEP]
obtain ⟨S, hS, hf⟩ := hf
[GOAL]
case intro.intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S✝ R : Sieve X
𝒮 : Set (Sieve X)
x✝² x✝¹ : C
f : x✝² ⟶ X
x✝ : x✝¹ ⟶ x✝²
S : Sieve X
hS : S ∈ 𝒮
hf : S.arrows f
⊢ setOf (fun f => ∃ S, S ∈ 𝒮 ∧ S.arrows f) (x✝ ≫ f)
[PROOFSTEP]
exact ⟨S, hS, S.downward_closed hf _⟩
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S✝ R✝ S R : Sieve X
⊢ ∀ {Y Z : C} {f : Y ⟶ X},
(fun Y f => S.arrows f ∨ R.arrows f) Y f → ∀ (g : Z ⟶ Y), (fun Y f => S.arrows f ∨ R.arrows f) Z (g ≫ f)
[PROOFSTEP]
rintro _ _ _ (h | h) g
[GOAL]
case inl
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S✝ R✝ S R : Sieve X
Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
h : S.arrows f✝
g : Z✝ ⟶ Y✝
⊢ S.arrows (g ≫ f✝) ∨ R.arrows (g ≫ f✝)
[PROOFSTEP]
simp [h]
[GOAL]
case inr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S✝ R✝ S R : Sieve X
Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
h : R.arrows f✝
g : Z✝ ⟶ Y✝
⊢ S.arrows (g ≫ f✝) ∨ R.arrows (g ≫ f✝)
[PROOFSTEP]
simp [h]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S✝ R✝ S R : Sieve X
⊢ ∀ {Y Z : C} {f : Y ⟶ X},
(fun Y f => S.arrows f ∧ R.arrows f) Y f → ∀ (g : Z ⟶ Y), (fun Y f => S.arrows f ∧ R.arrows f) Z (g ≫ f)
[PROOFSTEP]
rintro _ _ _ ⟨h₁, h₂⟩ g
[GOAL]
case intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S✝ R✝ S R : Sieve X
Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
h₁ : S.arrows f✝
h₂ : R.arrows f✝
g : Z✝ ⟶ Y✝
⊢ S.arrows (g ≫ f✝) ∧ R.arrows (g ≫ f✝)
[PROOFSTEP]
simp [h₁, h₂]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R x✝³ x✝² x✝¹ : Sieve X
h₁ : x✝³ ≤ x✝¹
h₂ : x✝² ≤ x✝¹
x✝ : C
f : x✝ ⟶ X
⊢ (x✝³ ⊔ x✝²).arrows f → x✝¹.arrows f
[PROOFSTEP]
rintro (hf | hf)
[GOAL]
case inl
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R x✝³ x✝² x✝¹ : Sieve X
h₁ : x✝³ ≤ x✝¹
h₂ : x✝² ≤ x✝¹
x✝ : C
f : x✝ ⟶ X
hf : x✝³.arrows f
⊢ x✝¹.arrows f
[PROOFSTEP]
exact h₁ _ hf
[GOAL]
case inr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R x✝³ x✝² x✝¹ : Sieve X
h₁ : x✝³ ≤ x✝¹
h₂ : x✝² ≤ x✝¹
x✝ : C
f : x✝ ⟶ X
hf : x✝².arrows f
⊢ x✝¹.arrows f
[PROOFSTEP]
exact h₂ _ hf
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S R : Sieve X
Ss : Set (Sieve X)
Y : C
f : Y ⟶ X
⊢ (sSup Ss).arrows f ↔ ∃ S x, S.arrows f
[PROOFSTEP]
simp [sSup, Sieve.sup, setOf]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
R : Presieve X
⊢ ∀ {Y Z : C} {f : Y ⟶ X},
(fun Z f => ∃ Y h g, R g ∧ h ≫ g = f) Y f → ∀ (g : Z ⟶ Y), (fun Z f => ∃ Y h g, R g ∧ h ≫ g = f) Z (g ≫ f)
[PROOFSTEP]
rintro Y Z _ ⟨W, g, f, hf, rfl⟩ h
[GOAL]
case intro.intro.intro.intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
R : Presieve X
Y Z W : C
g : Y ⟶ W
f : W ⟶ X
hf : R f
h : Z ⟶ Y
⊢ ∃ Y_1 h_1 g_1, R g_1 ∧ h_1 ≫ g_1 = h ≫ g ≫ f
[PROOFSTEP]
exact ⟨_, h ≫ g, _, hf, by simp⟩
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
R : Presieve X
Y Z W : C
g : Y ⟶ W
f : W ⟶ X
hf : R f
h : Z ⟶ Y
⊢ (h ≫ g) ≫ f = h ≫ g ≫ f
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S✝ R✝ : Sieve X
S : Presieve X
R : ⦃Y : C⦄ → ⦃f : Y ⟶ X⦄ → S f → Sieve Y
⊢ ∀ {Y Z : C} {f : Y ⟶ X},
Presieve.bind S (fun Y f h => (R h).arrows) f → ∀ (g : Z ⟶ Y), Presieve.bind S (fun Y f h => (R h).arrows) (g ≫ f)
[PROOFSTEP]
rintro Y Z f ⟨W, f, h, hh, hf, rfl⟩ g
[GOAL]
case intro.intro.intro.intro.intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S✝ R✝ : Sieve X
S : Presieve X
R : ⦃Y : C⦄ → ⦃f : Y ⟶ X⦄ → S f → Sieve Y
Y Z W : C
f : Y ⟶ W
h : W ⟶ X
hh : S h
hf : (R hh).arrows f
g : Z ⟶ Y
⊢ Presieve.bind S (fun Y f h => (R h).arrows) (g ≫ f ≫ h)
[PROOFSTEP]
exact ⟨_, g ≫ f, _, hh, by simp [hf]⟩
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S✝ R✝ : Sieve X
S : Presieve X
R : ⦃Y : C⦄ → ⦃f : Y ⟶ X⦄ → S f → Sieve Y
Y Z W : C
f : Y ⟶ W
h : W ⟶ X
hh : S h
hf : (R hh).arrows f
g : Z ⟶ Y
⊢ (fun Y f h => (R h).arrows) W h hh (g ≫ f) ∧ (g ≫ f) ≫ h = g ≫ f ≫ h
[PROOFSTEP]
simp [hf]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S✝ R✝ : Sieve X
R : Presieve X
S : Sieve X
ss : R ≤ S.arrows
Y : C
f : Y ⟶ X
⊢ (generate R).arrows f → S.arrows f
[PROOFSTEP]
rintro ⟨Z, f, g, hg, rfl⟩
[GOAL]
case intro.intro.intro.intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S✝ R✝ : Sieve X
R : Presieve X
S : Sieve X
ss : R ≤ S.arrows
Y Z : C
f : Y ⟶ Z
g : Z ⟶ X
hg : R g
⊢ S.arrows (f ≫ g)
[PROOFSTEP]
exact S.downward_closed (ss Z hg) f
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S R : Sieve X
h : S.arrows (𝟙 X)
Y : C
f : Y ⟶ X
x✝ : ⊤.arrows f
⊢ S.arrows f
[PROOFSTEP]
simpa using downward_closed _ h f
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
R : Presieve X
f : Y ⟶ X
inst✝ : IsSplitEpi f
hf : R f
⊢ generate R = ⊤
[PROOFSTEP]
rw [← id_mem_iff_eq_top]
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
R : Presieve X
f : Y ⟶ X
inst✝ : IsSplitEpi f
hf : R f
⊢ (generate R).arrows (𝟙 X)
[PROOFSTEP]
exact ⟨_, section_ f, f, hf, by simp⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
R : Presieve X
f : Y ⟶ X
inst✝ : IsSplitEpi f
hf : R f
⊢ section_ f ≫ f = 𝟙 X
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S✝ R : Sieve X
h : Y ⟶ X
S : Sieve X
Y✝ Z✝ : C
f✝ : Y✝ ⟶ Y
g : (fun Y_1 sl => S.arrows (sl ≫ h)) Y✝ f✝
⊢ ∀ (g : Z✝ ⟶ Y✝), (fun Y_1 sl => S.arrows (sl ≫ h)) Z✝ (g ≫ f✝)
[PROOFSTEP]
simp [g]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
⊢ pullback (𝟙 X) S = S
[PROOFSTEP]
simp [Sieve.ext_iff]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S✝ R : Sieve X
f : Y ⟶ X
g : Z ⟶ Y
S : Sieve X
⊢ pullback (g ≫ f) S = pullback g (pullback f S)
[PROOFSTEP]
simp [Sieve.ext_iff]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S✝ R✝ : Sieve X
f : Y ⟶ X
S R : Sieve X
⊢ pullback f (S ⊓ R) = pullback f S ⊓ pullback f R
[PROOFSTEP]
simp [Sieve.ext_iff]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
f : Y ⟶ X
⊢ S.arrows f ↔ pullback f S = ⊤
[PROOFSTEP]
rw [← id_mem_iff_eq_top, pullback_apply, id_comp]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝¹ : Y ⟶ X
S R✝ : Sieve X
f : Y ⟶ X
R : Sieve Y
Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
x✝ : (fun Z gf => ∃ g, g ≫ f = gf ∧ R.arrows g) Y✝ f✝
h : Z✝ ⟶ Y✝
j : Y✝ ⟶ Y
k : j ≫ f = f✝
z : R.arrows j
⊢ (h ≫ j) ≫ f = h ≫ f✝
[PROOFSTEP]
simp [k]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝¹ : Y ⟶ X
S R✝ : Sieve X
f : Y ⟶ X
R : Sieve Y
Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
x✝ : (fun Z gf => ∃ g, g ≫ f = gf ∧ R.arrows g) Y✝ f✝
h : Z✝ ⟶ Y✝
j : Y✝ ⟶ Y
k : j ≫ f = f✝
z : R.arrows j
⊢ R.arrows (h ≫ j)
[PROOFSTEP]
simp [z]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
f : Y ⟶ X
g : Z ⟶ Y
R : Sieve Z
W : C
h : W ⟶ X
x✝ : (pushforward (g ≫ f) R).arrows h
f₁ : W ⟶ Z
hq : f₁ ≫ g ≫ f = h
hf₁ : R.arrows f₁
⊢ (f₁ ≫ g) ≫ f = h
[PROOFSTEP]
simpa
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
f : Y ⟶ X
g : Z ⟶ Y
R : Sieve Z
W : C
h : W ⟶ X
x✝ : (pushforward f (pushforward g R)).arrows h
y : W ⟶ Y
hy : y ≫ f = h
z : W ⟶ Z
hR : z ≫ g = y
hz : R.arrows z
⊢ z ≫ g ≫ f = h ∧ R.arrows z
[PROOFSTEP]
rw [← Category.assoc, hR]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
f : Y ⟶ X
g : Z ⟶ Y
R : Sieve Z
W : C
h : W ⟶ X
x✝ : (pushforward f (pushforward g R)).arrows h
y : W ⟶ Y
hy : y ≫ f = h
z : W ⟶ Z
hR : z ≫ g = y
hz : R.arrows z
⊢ y ≫ f = h ∧ R.arrows z
[PROOFSTEP]
tauto
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S✝ R✝ : Sieve X
S : Presieve X
R : ⦃Y : C⦄ → ⦃f : Y ⟶ X⦄ → S f → Sieve Y
f : Y ⟶ X
h : S f
⊢ pushforward f (R h) ≤ bind S R
[PROOFSTEP]
rintro Z _ ⟨g, rfl, hg⟩
[GOAL]
case intro.intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f✝ : Y ⟶ X
S✝ R✝ : Sieve X
S : Presieve X
R : ⦃Y : C⦄ → ⦃f : Y ⟶ X⦄ → S f → Sieve Y
f : Y ⟶ X
h : S f
Z : C
g : Z ⟶ Y
hg : (R h).arrows g
⊢ (bind S R).arrows (g ≫ f)
[PROOFSTEP]
exact ⟨_, g, f, h, hg, rfl⟩
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S✝ R✝ : Sieve X
S : Presieve X
R : ⦃Y : C⦄ → ⦃f : Y ⟶ X⦄ → S f → Sieve Y
f : Y ⟶ X
h : S f
⊢ R h ≤ pullback f (bind S R)
[PROOFSTEP]
rw [← galoisConnection f]
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S✝ R✝ : Sieve X
S : Presieve X
R : ⦃Y : C⦄ → ⦃f : Y ⟶ X⦄ → S f → Sieve Y
f : Y ⟶ X
h : S f
⊢ pushforward f (R h) ≤ bind S R
[PROOFSTEP]
apply pushforward_le_bind_of_mem
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
f : Y ⟶ X
inst✝ : Mono f
⊢ GaloisCoinsertion (pushforward f) (pullback f)
[PROOFSTEP]
apply (galoisConnection f).toGaloisCoinsertion
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
f : Y ⟶ X
inst✝ : Mono f
⊢ ∀ (a : Sieve Y), pullback f (pushforward f a) ≤ a
[PROOFSTEP]
rintro S Z g ⟨g₁, hf, hg₁⟩
[GOAL]
case intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f✝ : Y ⟶ X
S✝ R : Sieve X
f : Y ⟶ X
inst✝ : Mono f
S : Sieve Y
Z : C
g g₁ : Z ⟶ Y
hf : g₁ ≫ f = g ≫ f
hg₁ : S.arrows g₁
⊢ S.arrows g
[PROOFSTEP]
rw [cancel_mono f] at hf
[GOAL]
case intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f✝ : Y ⟶ X
S✝ R : Sieve X
f : Y ⟶ X
inst✝ : Mono f
S : Sieve Y
Z : C
g g₁ : Z ⟶ Y
hf : g₁ = g
hg₁ : S.arrows g₁
⊢ S.arrows g
[PROOFSTEP]
rwa [← hf]
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
f : Y ⟶ X
inst✝ : IsSplitEpi f
⊢ GaloisInsertion (pushforward f) (pullback f)
[PROOFSTEP]
apply (galoisConnection f).toGaloisInsertion
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
f : Y ⟶ X
inst✝ : IsSplitEpi f
⊢ ∀ (b : Sieve X), b ≤ pushforward f (pullback f b)
[PROOFSTEP]
intro S Z g hg
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f✝ : Y ⟶ X
S✝ R : Sieve X
f : Y ⟶ X
inst✝ : IsSplitEpi f
S : Sieve X
Z : C
g : Z ⟶ X
hg : S.arrows g
⊢ (pushforward f (pullback f S)).arrows g
[PROOFSTEP]
refine' ⟨g ≫ section_ f, by simpa⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z✝ : C
f✝ : Y ⟶ X
S✝ R : Sieve X
f : Y ⟶ X
inst✝ : IsSplitEpi f
S : Sieve X
Z : C
g : Z ⟶ X
hg : S.arrows g
⊢ (g ≫ section_ f) ≫ f = g ∧ (pullback f S).arrows (g ≫ section_ f)
[PROOFSTEP]
simpa
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
⊢ generate (Presieve.pullbackArrows f R) = pullback f (generate R)
[PROOFSTEP]
ext W g
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W : C
g : W ⟶ Y
⊢ (generate (Presieve.pullbackArrows f R)).arrows g ↔ (pullback f (generate R)).arrows g
[PROOFSTEP]
constructor
[GOAL]
case h.mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W : C
g : W ⟶ Y
⊢ (generate (Presieve.pullbackArrows f R)).arrows g → (pullback f (generate R)).arrows g
[PROOFSTEP]
rintro ⟨_, h, k, hk, rfl⟩
[GOAL]
case h.mp.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W w✝ : C
h : W ⟶ w✝
k : w✝ ⟶ Y
hk : Presieve.pullbackArrows f R k
⊢ (pullback f (generate R)).arrows (h ≫ k)
[PROOFSTEP]
cases' hk with W g hg
[GOAL]
case h.mp.intro.intro.intro.intro.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W✝ W : C
g : W ⟶ X
hg : R g
h : W✝ ⟶ Limits.pullback g f
⊢ (pullback f (generate R)).arrows (h ≫ pullback.snd)
[PROOFSTEP]
change (Sieve.generate R).pullback f (h ≫ pullback.snd)
[GOAL]
case h.mp.intro.intro.intro.intro.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W✝ W : C
g : W ⟶ X
hg : R g
h : W✝ ⟶ Limits.pullback g f
⊢ (pullback f (generate R)).arrows (h ≫ pullback.snd)
[PROOFSTEP]
rw [Sieve.pullback_apply, assoc, ← pullback.condition, ← assoc]
[GOAL]
case h.mp.intro.intro.intro.intro.mk
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W✝ W : C
g : W ⟶ X
hg : R g
h : W✝ ⟶ Limits.pullback g f
⊢ (generate R).arrows ((h ≫ pullback.fst) ≫ g)
[PROOFSTEP]
exact Sieve.downward_closed _ (by exact Sieve.le_generate R W hg) (h ≫ pullback.fst)
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W✝ W : C
g : W ⟶ X
hg : R g
h : W✝ ⟶ Limits.pullback g f
⊢ (generate R).arrows g
[PROOFSTEP]
exact Sieve.le_generate R W hg
[GOAL]
case h.mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W : C
g : W ⟶ Y
⊢ (pullback f (generate R)).arrows g → (generate (Presieve.pullbackArrows f R)).arrows g
[PROOFSTEP]
rintro ⟨W, h, k, hk, comm⟩
[GOAL]
case h.mpr.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S R✝ : Sieve X✝
inst✝ : HasPullbacks C
X Y : C
f : Y ⟶ X
R : Presieve X
W✝ : C
g : W✝ ⟶ Y
W : C
h : W✝ ⟶ W
k : W ⟶ X
hk : R k
comm : h ≫ k = g ≫ f
⊢ (generate (Presieve.pullbackArrows f R)).arrows g
[PROOFSTEP]
exact ⟨_, _, _, Presieve.pullbackArrows.mk _ _ hk, pullback.lift_snd _ _ comm⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve (F.obj X)
⊢ ∀ {Y Z : C} {f : Y ⟶ X},
Presieve.functorPullback F R.arrows f → ∀ (g : Z ⟶ Y), Presieve.functorPullback F R.arrows (g ≫ f)
[PROOFSTEP]
intro _ _ f hf g
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve (F.obj X)
Y✝ Z✝ : C
f : Y✝ ⟶ X
hf : Presieve.functorPullback F R.arrows f
g : Z✝ ⟶ Y✝
⊢ Presieve.functorPullback F R.arrows (g ≫ f)
[PROOFSTEP]
unfold Presieve.functorPullback
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve (F.obj X)
Y✝ Z✝ : C
f : Y✝ ⟶ X
hf : Presieve.functorPullback F R.arrows f
g : Z✝ ⟶ Y✝
⊢ R.arrows (F.map (g ≫ f))
[PROOFSTEP]
rw [F.map_comp]
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve (F.obj X)
Y✝ Z✝ : C
f : Y✝ ⟶ X
hf : Presieve.functorPullback F R.arrows f
g : Z✝ ⟶ Y✝
⊢ R.arrows (F.map g ≫ F.map f)
[PROOFSTEP]
exact R.downward_closed hf (F.map g)
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
⊢ functorPullback (𝟭 C) R = R
[PROOFSTEP]
ext
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
Y✝ : C
f✝ : Y✝ ⟶ X
⊢ (functorPullback (𝟭 C) R).arrows f✝ ↔ R.arrows f✝
[PROOFSTEP]
rfl
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve ((F ⋙ G).obj X)
⊢ functorPullback (F ⋙ G) R = functorPullback F (functorPullback G R)
[PROOFSTEP]
ext
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve ((F ⋙ G).obj X)
Y✝ : C
f✝ : Y✝ ⟶ X
⊢ (functorPullback (F ⋙ G) R).arrows f✝ ↔ (functorPullback F (functorPullback G R)).arrows f✝
[PROOFSTEP]
rfl
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
⊢ Presieve.functorPushforward F (generate R).arrows = Presieve.functorPushforward F R
[PROOFSTEP]
funext Y
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
Y : D
⊢ Presieve.functorPushforward F (generate R).arrows = Presieve.functorPushforward F R
[PROOFSTEP]
ext f
[GOAL]
case h.h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
Y : D
f : Y ⟶ F.obj X
⊢ f ∈ Presieve.functorPushforward F (generate R).arrows ↔ f ∈ Presieve.functorPushforward F R
[PROOFSTEP]
constructor
[GOAL]
case h.h.mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
Y : D
f : Y ⟶ F.obj X
⊢ f ∈ Presieve.functorPushforward F (generate R).arrows → f ∈ Presieve.functorPushforward F R
[PROOFSTEP]
rintro ⟨X', g, f', ⟨X'', g', f'', h₁, rfl⟩, rfl⟩
[GOAL]
case h.h.mp.intro.intro.intro.intro.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
Y : D
X' : C
f' : Y ⟶ F.obj X'
X'' : C
g' : X' ⟶ X''
f'' : X'' ⟶ X
h₁ : R f''
⊢ f' ≫ F.map (g' ≫ f'') ∈ Presieve.functorPushforward F R
[PROOFSTEP]
exact ⟨X'', f'', f' ≫ F.map g', h₁, by simp⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f : Y✝ ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
Y : D
X' : C
f' : Y ⟶ F.obj X'
X'' : C
g' : X' ⟶ X''
f'' : X'' ⟶ X
h₁ : R f''
⊢ f' ≫ F.map (g' ≫ f'') = (f' ≫ F.map g') ≫ F.map f''
[PROOFSTEP]
simp
[GOAL]
case h.h.mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
Y : D
f : Y ⟶ F.obj X
⊢ f ∈ Presieve.functorPushforward F R → f ∈ Presieve.functorPushforward F (generate R).arrows
[PROOFSTEP]
rintro ⟨X', g, f', h₁, h₂⟩
[GOAL]
case h.h.mpr.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Presieve X
Y : D
f : Y ⟶ F.obj X
X' : C
g : X' ⟶ X
f' : Y ⟶ F.obj X'
h₁ : R g
h₂ : f = f' ≫ F.map g
⊢ f ∈ Presieve.functorPushforward F (generate R).arrows
[PROOFSTEP]
exact ⟨X', g, f', le_generate R _ h₁, h₂⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
⊢ ∀ {Y Z : D} {f : Y ⟶ F.obj X},
Presieve.functorPushforward F R.arrows f → ∀ (g : Z ⟶ Y), Presieve.functorPushforward F R.arrows (g ≫ f)
[PROOFSTEP]
intro _ _ f h g
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
Y✝ Z✝ : D
f : Y✝ ⟶ F.obj X
h : Presieve.functorPushforward F R.arrows f
g : Z✝ ⟶ Y✝
⊢ Presieve.functorPushforward F R.arrows (g ≫ f)
[PROOFSTEP]
obtain ⟨X, α, β, hα, rfl⟩ := h
[GOAL]
case intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
Y✝ Z✝ : D
g : Z✝ ⟶ Y✝
X : C
α : X ⟶ X✝
β : Y✝ ⟶ F.obj X
hα : R.arrows α
⊢ Presieve.functorPushforward F R.arrows (g ≫ β ≫ F.map α)
[PROOFSTEP]
exact ⟨X, α, g ≫ β, hα, by simp⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
Y✝ Z✝ : D
g : Z✝ ⟶ Y✝
X : C
α : X ⟶ X✝
β : Y✝ ⟶ F.obj X
hα : R.arrows α
⊢ g ≫ β ≫ F.map α = (g ≫ β) ≫ F.map α
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
⊢ functorPushforward (𝟭 C) R = R
[PROOFSTEP]
ext X f
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f✝ : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
X : C
f : X ⟶ (𝟭 C).obj X✝
⊢ (functorPushforward (𝟭 C) R).arrows f ↔ R.arrows f
[PROOFSTEP]
constructor
[GOAL]
case h.mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f✝ : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
X : C
f : X ⟶ (𝟭 C).obj X✝
⊢ (functorPushforward (𝟭 C) R).arrows f → R.arrows f
[PROOFSTEP]
intro hf
[GOAL]
case h.mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f✝ : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
X : C
f : X ⟶ (𝟭 C).obj X✝
hf : (functorPushforward (𝟭 C) R).arrows f
⊢ R.arrows f
[PROOFSTEP]
obtain ⟨X, g, h, hg, rfl⟩ := hf
[GOAL]
case h.mp.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝¹ Y Z : C
f : Y ⟶ X✝¹
S R✝ : Sieve X✝¹
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝¹
X✝ X : C
g : X ⟶ X✝¹
h : X✝ ⟶ (𝟭 C).obj X
hg : R.arrows g
⊢ R.arrows (h ≫ (𝟭 C).map g)
[PROOFSTEP]
exact R.downward_closed hg h
[GOAL]
case h.mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f✝ : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
X : C
f : X ⟶ (𝟭 C).obj X✝
⊢ R.arrows f → (functorPushforward (𝟭 C) R).arrows f
[PROOFSTEP]
intro hf
[GOAL]
case h.mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f✝ : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
X : C
f : X ⟶ (𝟭 C).obj X✝
hf : R.arrows f
⊢ (functorPushforward (𝟭 C) R).arrows f
[PROOFSTEP]
exact ⟨X, f, 𝟙 _, hf, by simp⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f✝ : Y ⟶ X✝
S R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X✝
X : C
f : X ⟶ (𝟭 C).obj X✝
hf : R.arrows f
⊢ f = 𝟙 X ≫ (𝟭 C).map f
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
⊢ functorPushforward (F ⋙ G) R = functorPushforward G (functorPushforward F R)
[PROOFSTEP]
ext
[GOAL]
case h
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
Y✝ : E
f✝ : Y✝ ⟶ (F ⋙ G).obj X
⊢ (functorPushforward (F ⋙ G) R).arrows f✝ ↔ (functorPushforward G (functorPushforward F R)).arrows f✝
[PROOFSTEP]
simp [R.arrows.functorPushforward_comp F G]
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X : C
⊢ GaloisConnection (functorPushforward F) (functorPullback F)
[PROOFSTEP]
intro R S
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S✝ R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X : C
R : Sieve X
S : Sieve (F.obj X)
⊢ functorPushforward F R ≤ S ↔ R ≤ functorPullback F S
[PROOFSTEP]
constructor
[GOAL]
case mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S✝ R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X : C
R : Sieve X
S : Sieve (F.obj X)
⊢ functorPushforward F R ≤ S → R ≤ functorPullback F S
[PROOFSTEP]
intro hle X f hf
[GOAL]
case mp
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝¹ Y Z : C
f✝ : Y ⟶ X✝¹
S✝ R✝ : Sieve X✝¹
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X✝ : C
R : Sieve X✝
S : Sieve (F.obj X✝)
hle : functorPushforward F R ≤ S
X : C
f : X ⟶ X✝
hf : R.arrows f
⊢ (functorPullback F S).arrows f
[PROOFSTEP]
apply hle
[GOAL]
case mp.a
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝¹ Y Z : C
f✝ : Y ⟶ X✝¹
S✝ R✝ : Sieve X✝¹
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X✝ : C
R : Sieve X✝
S : Sieve (F.obj X✝)
hle : functorPushforward F R ≤ S
X : C
f : X ⟶ X✝
hf : R.arrows f
⊢ (functorPushforward F R).arrows (F.map f)
[PROOFSTEP]
refine' ⟨X, f, 𝟙 _, hf, _⟩
[GOAL]
case mp.a
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝¹ Y Z : C
f✝ : Y ⟶ X✝¹
S✝ R✝ : Sieve X✝¹
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X✝ : C
R : Sieve X✝
S : Sieve (F.obj X✝)
hle : functorPushforward F R ≤ S
X : C
f : X ⟶ X✝
hf : R.arrows f
⊢ F.map f = 𝟙 (F.obj X) ≫ F.map f
[PROOFSTEP]
rw [id_comp]
[GOAL]
case mpr
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S✝ R✝ : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X : C
R : Sieve X
S : Sieve (F.obj X)
⊢ R ≤ functorPullback F S → functorPushforward F R ≤ S
[PROOFSTEP]
rintro hle Y f ⟨X, g, h, hg, rfl⟩
[GOAL]
case mpr.intro.intro.intro.intro
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝¹ Y✝ Z : C
f : Y✝ ⟶ X✝¹
S✝ R✝ : Sieve X✝¹
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X✝ : C
R : Sieve X✝
S : Sieve (F.obj X✝)
hle : R ≤ functorPullback F S
Y : D
X : C
g : X ⟶ X✝
h : Y ⟶ F.obj X
hg : R.arrows g
⊢ S.arrows (h ≫ F.map g)
[PROOFSTEP]
apply Sieve.downward_closed S
[GOAL]
case mpr.intro.intro.intro.intro.x
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X✝¹ Y✝ Z : C
f : Y✝ ⟶ X✝¹
S✝ R✝ : Sieve X✝¹
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
X✝ : C
R : Sieve X✝
S : Sieve (F.obj X✝)
hle : R ≤ functorPullback F S
Y : D
X : C
g : X ⟶ X✝
h : Y ⟶ F.obj X
hg : R.arrows g
⊢ S.arrows (F.map g)
[PROOFSTEP]
exact hle g hg
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F✝ : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
F : C ⥤ D
X : C
⊢ functorPushforward F ⊤ = ⊤
[PROOFSTEP]
refine' (generate_sieve _).symm.trans _
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F✝ : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
F : C ⥤ D
X : C
⊢ generate (functorPushforward F ⊤).arrows = ⊤
[PROOFSTEP]
apply generate_of_contains_isSplitEpi (𝟙 (F.obj X))
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F✝ : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
F : C ⥤ D
X : C
⊢ (functorPushforward F ⊤).arrows (𝟙 (F.obj X))
[PROOFSTEP]
refine' ⟨X, 𝟙 _, 𝟙 _, trivial, by simp⟩
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F✝ : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
F : C ⥤ D
X : C
⊢ 𝟙 (F.obj X) = 𝟙 (F.obj X) ≫ F.map (𝟙 X)
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝² : Category.{v₁, u₁} C
D : Type u₂
inst✝¹ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
E : Type u₃
inst✝ : Category.{v₃, u₃} E
G : D ⥤ E
R : Sieve X
V : C
f : V ⟶ X
h : R.arrows f
⊢ F.map f = 𝟙 (F.obj V) ≫ F.map f
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : EssSurj F
inst✝ : Full F
X : C
⊢ GaloisInsertion (functorPushforward F) (functorPullback F)
[PROOFSTEP]
apply (functor_galoisConnection F X).toGaloisInsertion
[GOAL]
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : EssSurj F
inst✝ : Full F
X : C
⊢ ∀ (b : Sieve (F.obj X)), b ≤ functorPushforward F (functorPullback F b)
[PROOFSTEP]
intro S Y f hf
[GOAL]
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S✝ R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : EssSurj F
inst✝ : Full F
X : C
S : Sieve (F.obj X)
Y : D
f : Y ⟶ F.obj X
hf : S.arrows f
⊢ (functorPushforward F (functorPullback F S)).arrows f
[PROOFSTEP]
refine' ⟨_, F.preimage ((F.objObjPreimageIso Y).hom ≫ f), (F.objObjPreimageIso Y).inv, _⟩
[GOAL]
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z : C
f✝ : Y✝ ⟶ X✝
S✝ R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : EssSurj F
inst✝ : Full F
X : C
S : Sieve (F.obj X)
Y : D
f : Y ⟶ F.obj X
hf : S.arrows f
⊢ (functorPullback F S).arrows (F.preimage ((Functor.objObjPreimageIso F Y).hom ≫ f)) ∧
f = (Functor.objObjPreimageIso F Y).inv ≫ F.map (F.preimage ((Functor.objObjPreimageIso F Y).hom ≫ f))
[PROOFSTEP]
simpa using S.downward_closed hf _
[GOAL]
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : Full F
inst✝ : Faithful F
X : C
⊢ GaloisCoinsertion (functorPushforward F) (functorPullback F)
[PROOFSTEP]
apply (functor_galoisConnection F X).toGaloisCoinsertion
[GOAL]
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y Z : C
f : Y ⟶ X✝
S R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : Full F
inst✝ : Faithful F
X : C
⊢ ∀ (a : Sieve X), functorPullback F (functorPushforward F a) ≤ a
[PROOFSTEP]
rintro S Y f ⟨Z, g, h, h₁, h₂⟩
[GOAL]
case intro.intro.intro.intro
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z✝ : C
f✝ : Y✝ ⟶ X✝
S✝ R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : Full F
inst✝ : Faithful F
X : C
S : Sieve X
Y : C
f : Y ⟶ X
Z : C
g : Z ⟶ X
h : F.obj Y ⟶ F.obj Z
h₁ : S.arrows g
h₂ : F.map f = h ≫ F.map g
⊢ S.arrows f
[PROOFSTEP]
rw [← F.image_preimage h, ← F.map_comp] at h₂
[GOAL]
case intro.intro.intro.intro
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z✝ : C
f✝ : Y✝ ⟶ X✝
S✝ R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : Full F
inst✝ : Faithful F
X : C
S : Sieve X
Y : C
f : Y ⟶ X
Z : C
g : Z ⟶ X
h : F.obj Y ⟶ F.obj Z
h₁ : S.arrows g
h₂ : F.map f = F.map (F.preimage h ≫ g)
⊢ S.arrows f
[PROOFSTEP]
rw [F.map_injective h₂]
[GOAL]
case intro.intro.intro.intro
C : Type u₁
inst✝⁴ : Category.{v₁, u₁} C
D : Type u₂
inst✝³ : Category.{v₂, u₂} D
F : C ⥤ D
X✝ Y✝ Z✝ : C
f✝ : Y✝ ⟶ X✝
S✝ R : Sieve X✝
E : Type u₃
inst✝² : Category.{v₃, u₃} E
G : D ⥤ E
inst✝¹ : Full F
inst✝ : Faithful F
X : C
S : Sieve X
Y : C
f : Y ⟶ X
Z : C
g : Z ⟶ X
h : F.obj Y ⟶ F.obj Z
h₁ : S.arrows g
h₂ : F.map f = F.map (F.preimage h ≫ g)
⊢ S.arrows (F.preimage h ≫ g)
[PROOFSTEP]
exact S.downward_closed h₁ _
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
Z✝ : Cᵒᵖ ⥤ Type v₁
f g : Z✝ ⟶ functor S
h : f ≫ functorInclusion S = g ≫ functorInclusion S
⊢ f = g
[PROOFSTEP]
ext Y y
[GOAL]
case w.h.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z : C
f✝ : Y✝ ⟶ X
S R : Sieve X
Z✝ : Cᵒᵖ ⥤ Type v₁
f g : Z✝ ⟶ functor S
h : f ≫ functorInclusion S = g ≫ functorInclusion S
Y : Cᵒᵖ
y : Z✝.obj Y
⊢ NatTrans.app f Y y = NatTrans.app g Y y
[PROOFSTEP]
simpa [Subtype.ext_iff_val] using congr_fun (NatTrans.congr_app h Y) y
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R✝ : Sieve X
R : Cᵒᵖ ⥤ Type v₁
f : R ⟶ yoneda.obj X
⊢ ∀ {Y Z : C} {f_1 : Y ⟶ X},
(fun Y g => ∃ t, NatTrans.app f (Opposite.op Y) t = g) Y f_1 →
∀ (g : Z ⟶ Y), (fun Y g => ∃ t, NatTrans.app f (Opposite.op Y) t = g) Z (g ≫ f_1)
[PROOFSTEP]
rintro Y Z _ ⟨t, rfl⟩ g
[GOAL]
case intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
R : Cᵒᵖ ⥤ Type v₁
f : R ⟶ yoneda.obj X
Y Z : C
t : R.obj (Opposite.op Y)
g : Z ⟶ Y
⊢ ∃ t_1, NatTrans.app f (Opposite.op Z) t_1 = g ≫ NatTrans.app f (Opposite.op Y) t
[PROOFSTEP]
refine' ⟨R.map g.op t, _⟩
[GOAL]
case intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
R : Cᵒᵖ ⥤ Type v₁
f : R ⟶ yoneda.obj X
Y Z : C
t : R.obj (Opposite.op Y)
g : Z ⟶ Y
⊢ NatTrans.app f (Opposite.op Z) (R.map g.op t) = g ≫ NatTrans.app f (Opposite.op Y) t
[PROOFSTEP]
rw [FunctorToTypes.naturality _ _ f]
[GOAL]
case intro
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y✝ Z✝ : C
f✝ : Y✝ ⟶ X
S R✝ : Sieve X
R : Cᵒᵖ ⥤ Type v₁
f : R ⟶ yoneda.obj X
Y Z : C
t : R.obj (Opposite.op Y)
g : Z ⟶ Y
⊢ (yoneda.obj X).map g.op (NatTrans.app f (Opposite.op Y) t) = g ≫ NatTrans.app f (Opposite.op Y) t
[PROOFSTEP]
simp
[GOAL]
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
⊢ sieveOfSubfunctor (functorInclusion S) = S
[PROOFSTEP]
ext
[GOAL]
case h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
Y✝ : C
f✝ : Y✝ ⟶ X
⊢ (sieveOfSubfunctor (functorInclusion S)).arrows f✝ ↔ S.arrows f✝
[PROOFSTEP]
simp only [functorInclusion_app, sieveOfSubfunctor_apply]
[GOAL]
case h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
Y✝ : C
f✝ : Y✝ ⟶ X
⊢ (∃ t, ↑t = f✝) ↔ S.arrows f✝
[PROOFSTEP]
constructor
[GOAL]
case h.mp
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
Y✝ : C
f✝ : Y✝ ⟶ X
⊢ (∃ t, ↑t = f✝) → S.arrows f✝
[PROOFSTEP]
rintro ⟨⟨f, hf⟩, rfl⟩
[GOAL]
case h.mp.intro.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f✝ : Y ⟶ X
S R : Sieve X
Y✝ : C
f : (Opposite.op Y✝).unop ⟶ X
hf : S.arrows f
⊢ S.arrows ↑{ val := f, property := hf }
[PROOFSTEP]
exact hf
[GOAL]
case h.mpr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
Y✝ : C
f✝ : Y✝ ⟶ X
⊢ S.arrows f✝ → ∃ t, ↑t = f✝
[PROOFSTEP]
intro hf
[GOAL]
case h.mpr
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
D : Type u₂
inst✝ : Category.{v₂, u₂} D
F : C ⥤ D
X Y Z : C
f : Y ⟶ X
S R : Sieve X
Y✝ : C
f✝ : Y✝ ⟶ X
hf : S.arrows f✝
⊢ ∃ t, ↑t = f✝
[PROOFSTEP]
exact ⟨⟨_, hf⟩, rfl⟩
|
# Taken from julia/base/util.jl
const _mem_units = ["byte", "KiB", "MiB", "GiB", "TiB", "PiB"]
const _cnt_units = ["", " k", " M", " G", " T", " P"]
function prettyprint_getunits(value, numunits, factor)
if value == 0 || value == 1
return (value, 1)
end
unit = ceil(Int, log(value) / log(factor))
unit = min(numunits, unit)
number = value/factor^(unit-1)
return number, unit
end
function format_bytes(bytes)
bytes, mb = prettyprint_getunits(bytes, length(_mem_units), Int64(1024))
if mb == 1
@sprintf("%d %s%s", bytes, _mem_units[mb], bytes==1 ? "" : "s")
else
@sprintf("%.3f %s", bytes, _mem_units[mb])
end
end
format_number(n::Int) = Formatting.format(n, commas=true)
format_observations(x::Array{T, 2}) where T <: Real = format_number(size(x, 2))
function log_experiment_info(experiment)
split = experiment[:split_strategy]
debug(LOGGER, "Experiment info: \n\tdata file: $(experiment[:data_file]),\n" *
"\tparams: adjust_K = $(experiment[:param][:adjust_K]), num_al_iterations = $(experiment[:param][:num_al_iterations])\n" *
"\tquery_strategy: $(experiment[:query_strategy][:type])\n" *
"\tmodel: $(experiment[:model][:type])\n" *
"\tinit_strategy: $(experiment[:model][:init_strategy])\n" *
"\tinitial_pools: $(countmap(experiment[:param][:initial_pools]))\n" *
"\tsplit_strategy: \n\t\ttrain: $(split.train_strat); \n\t\ttest: $(split.test_strat); \n\t\ttrain: $(split.query_strat)")
end
function Base.push!(logger::Logger, handler::Handler, name::String)
logger.handlers[name] = handler
end
|
function showsolution3(node,elem,u,expr,varargin)
%% SHOWSOLUTION3 plots the solution u on a tetrahedron mesh in 3-D.
%
% showsolution3(node,elem,u) displays the functoin u on a topological
% 2-dimensional mesh given by node and elem matrices. The function u
% could be piecewise constant or piecewise linear.
%
% showsolution3(node,elem,u,expr) displays the function u on the
% boundary of parts of the mesh specificed by the expression. For
% example, showsoluiton3(node,elem,'z==0') will show the function on the
% cross section of z=0.
%
% showsolution3(node,elem,u,viewangle) changes the display angle. The
% deault view angle on planar meshes is view(2) and view(3) for surface
% meshes.
%
% showsolution3(node,elem,u,expr,'param','value','param','value'...) allows
% additional patch param/value pairs to be used when displaying the
% mesh.
%
% Example:
% f = inline('x.^2 + y.^2 + z.^2');
% node = [-1,-1,-1; 1,-1,-1; 1,1,-1; -1,1,-1; -1,-1,1; 1,-1,1; 1,1,1; -1,1,1];
% elem = [1,2,3,7; 1,6,2,7; 1,5,6,7; 1,8,5,7; 1,4,8,7; 1,3,4,7];
% for k=1:4
% [node,elem] = uniformbisect3(node,elem);
% end
% u = f(node(:,1),node(:,2),node(:,3));
% subplot(1,2,1);
% showsolution3(node,elem,u);
% subplot(1,2,2);
% showsolution3(node,elem,u,'~(x>0 & y>0)',[139,16],'EdgeColor','k');
%
% See also showmesh, showsolution3.
%
% Copyright (C) Long Chen. See COPYRIGHT.txt for details.
if (nargin >= 4) && (any(expr))
x = node(:,1); y = node(:,2); z = node(:,3); %#ok<*NASGU>
incl = find(eval(expr));
elem = elem(any(ismember(elem,incl),2),:);
end
[bdNode, bdFace] = findboundary3(elem); %#ok<ASGLU>
if isempty(varargin)
showsolution(node,bdFace,u,'EdgeColor','k');
elseif (nargin == 5) && isnumeric(varargin{1})
showsolution(node,bdFace,u,'EdgeColor','k');
view(varargin{1});
else
showsolution(node,bdFace,u,varargin{1:end});
end |
%
% Introduction.tex
%
% History of LulzBot Printers
%
% Copyright (C) 2014, 2015 Aleph Objects, Inc.
%
% This document is licensed under the Creative Commons Attribution 4.0
% International Public License (CC BY-SA 4.0) by Aleph Objects, Inc.
%
\section{Free Software, Libre Innovation, Open Source Hardware}
\href{https://www.alephobjects.com/}{Aleph Objects, Inc.} is a
\href{https://www.fsf.org/}{Free Software},
Libre Innovation, and
\href{http://www.oshwa.org/}{Open Source Hardware}
company based in Loveland, Colorado, USA. Aleph Objects
manufactures the
\href{https://www.lulzbot.com/}{LulzBot} line of 3D printers, sold worldwide.
This document outlines the History of LulzBot Printers (HOLP).
HOPE and HELP. HOLP.
|
### Day 13 - Problem 2
## A Maze of Twisty Little Cubicles
## Author: Thanasis Georgiou
# Cell type
immutable Cell
x::Int
y::Int
weight::Int
end
# Equality check for cells
function Base.isequal(a::Cell, b::Cell)::Bool
return a.x == b.x && a.y == b.y
end
# Manhattan distance from cell to cell
function man_distance(a::Cell, b::Cell)::Int
return abs(a.x - b.x) + abs(a.y - b.y)
end
# Manhattan distance from coords to cell
function man_distance(x::Int, y::Int, b::Cell)::Int
return abs(x - b.x) + abs(y - b.y)
end
createHeuristicCell(x::Int, y::Int, target::Cell) = Cell(x, y, man_distance(x, y, target))
# -1 For wall, anything else is step count
floor = Array(Int, (50, 50))
# Create floor plan
for x = 0:49, y = 0:49
magic = x * x + 3 * x + 2 * x * y + y + y * y
magic += 1358
bitCount = count(bit -> bit == '1', bits(magic))
floor[x + 1, y + 1] = isodd(bitCount)? -1 : 0
end
# Find optimal path
target = Cell(31 + 1, 39 + 1, 0)
visited = Array(Cell, 0)
queue = Array(Cell, 0)
from = Dict{Cell, Cell}()
path = Array(Cell, 0)
# Add starting position to queue
push!(queue, createHeuristicCell(2, 2, target))
while length(queue) > 0
# Sort queue
sort!(queue, lt = (a, b) -> a.weight < b.weight)
# Grab most promising cell
cell = queue[1]
push!(visited, cell)
deleteat!(queue, 1)
steps = floor[cell.x, cell.y]
if (steps > 50)
continue
end
# Find neighbors
# For each neighbor check it's a wall. If not, create a cell, push to queue
# add to dictionary
neighbors = [
createHeuristicCell(cell.x + 1, cell.y, target),
createHeuristicCell(cell.x - 1, cell.y, target),
createHeuristicCell(cell.x, cell.y + 1, target),
createHeuristicCell(cell.x, cell.y - 1, target),
]
for neighbor in neighbors
if neighbor.x > 0 && neighbor.y > 0 && floor[neighbor.x, neighbor.y] == false
# Check if we have visited this before
visitedIndex = findfirst(x -> isequal(x, neighbor), visited)
if visitedIndex == 0
push!(queue, neighbor)
from[neighbor] = cell
floor[neighbor.x, neighbor.y] = steps + 1
else
oldCell = visited[visitedIndex]
if floor[oldCell.x, oldCell.y] > steps + 1
deleteat!(visited, visitedIndex)
from[neighbor] = cell
floor[neighbor.x, neighbor.y] = steps + 1
end
end
end
end
end
tileCount = count(x -> x > 0 && x <= 50, floor) + 1 # Plus one for starting position
println("Finished execution, reachable tiles: $tileCount")
for x = 1:40
for y = 1:45
if floor[x, y] > 0 && floor[x, y] <= 50
print("x")
elseif floor[x, y] == -1
print("█")
else
print(" ")
end
end
println()
end
|
import public Lightyear
import public Lightyear.Char
import public Lightyear.Strings
Name : Type
Name = String
showParen : String -> String
showParen x = "(" ++ x ++ ")"
data Tm
= Var Name -- x
| Lam Name Tm -- \x. t
| App Tm Tm -- t u
| Let Name Tm Tm -- let x = t in u
Show Tm where
show (Var str) = str
show (Lam x t) = showParen ("λ" ++ x ++ "." ++ show t)
show (App t u) = showParen ("" ++ show t ++ " " ++ show u)
show (Let str tm1 tm2) = showParen ("Let " ++ str ++ " = " ++ show tm1 ++ " in " ++ show tm2)
-- parsing
keyword : String -> Bool
keyword x = x == "λ" || x == "in" || x == "let"
pIdent' : Parser Name
pIdent' = do f <- satisfy (isAlphaNum)
i <- many (satisfy isAlphaNum)
pure (pack (f :: i)) <* spaces
pIdent : Parser Name
pIdent = do
str <- pIdent'
guard (not (keyword str))
pure str
pBind : Parser Name
pBind = pIdent <|> (token "_" *> pure "_")
mutual
pAtom : Parser Tm
pAtom = (Var <$> pIdent) <|> parens pTm -- what's `<$>` doing here?
pTm : Parser Tm
pTm = pLet <|>| pLam <|>| pSpine
pLam : Parser Tm
pLam = do
char 'λ' <|> char '\\'
xs <- some pBind
token "."
t <- pTm
pure (foldr Lam t xs)
pLet : Parser Tm
pLet = do
token "let"
x <- pBind
token "="
t <- pTm
token "in"
u <- pTm
pure $ Let x t u
pSpine : Parser Tm
pSpine = foldl1 App <$> some pAtom
-- evaluation
data Val
= VVar Name
| VApp Val Val
| VLam Name (Val -> Val)
Env : Type
Env = List (Name, Maybe Val)
fresh : Env -> Name -> Name
fresh env "_" = "_"
fresh env x = case lookup x env of
Nothing => x
(Just _) => fresh env (x ++ "'")
eval : Env -> Tm -> Val
eval env (Var x) = let findX = lookup x env in
(case findX of
Nothing => VVar x
(Just x') => (case x' of
Nothing => VVar x
(Just x'') => x''))
eval env (App t u) = let evalT = eval env t
evalU = eval env u
in
(case evalT of
(VLam _ f) => f evalU
_ => VApp evalT evalU)
eval env (Lam x t) = VLam x (\u => eval ((x, Just u)::env) t)
eval env (Let x t u) = let nextEnv = Just (eval env t) in
eval ((x, nextEnv)::env) u
quote : Env -> Val -> Tm
quote env (VVar x) = Var x
quote env (VApp t u) = App (quote env t) (quote env u)
quote env (VLam x t) = let freshX = fresh env x in
Lam freshX (quote ((x, Nothing)::env) (t (VVar x)))
nf : Env -> Tm -> Tm
nf env = let qe = quote env
ee = eval env in
qe . ee
test : Maybe Tm
test = let parsed = (Lightyear.Strings.parse (pTm) "let five = \\s z. s (s (s (s (s z)))) in let add = \\a b s z. a s (b s z) in let mul = \\a b s z. a (b s) z in let ten = add five five in let hundred = mul ten ten in let thousand = mul ten hundred in let tenthousand = mul ten thousand in tenthousand") in
(case parsed of
(Left l) => Nothing
(Right r) => Just (nf [] r))
test2 : Maybe Tm
test2 = let parsed = (Lightyear.Strings.parse (pTm) "let true = (\\x y. x) in let false = (\\x y. y) in let and = (\\x y. (x (y true false) false)) in let or = (\\x y. (x true (y true false))) in or false true") in
(case parsed of
(Left l) => Nothing
(Right r) => Just (nf [] r))
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Frédéric Dupuis
! This file was ported from Lean 3 source module algebra.star.module
! leanprover-community/mathlib commit 30413fc89f202a090a54d78e540963ed3de0056e
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Algebra.Star.SelfAdjoint
import Mathlib.Algebra.Module.Equiv
import Mathlib.LinearAlgebra.Prod
/-!
# The star operation, bundled as a star-linear equiv
We define `starLinearEquiv`, which is the star operation bundled as a star-linear map.
It is defined on a star algebra `A` over the base ring `R`.
This file also provides some lemmas that need `Algebra.Module.Basic` imported to prove.
## TODO
- Define `starLinearEquiv` for noncommutative `R`. We only the commutative case for now since,
in the noncommutative case, the ring hom needs to reverse the order of multiplication. This
requires a ring hom of type `R →+* Rᵐᵒᵖ`, which is very undesirable in the commutative case.
One way out would be to define a new typeclass `IsOp R S` and have an instance `IsOp R R`
for commutative `R`.
- Also note that such a definition involving `Rᵐᵒᵖ` or `is_op R S` would require adding
the appropriate `RingHomInvPair` instances to be able to define the semilinear
equivalence.
-/
section SmulLemmas
variable {R M : Type _}
@[simp]
theorem star_nat_cast_smul [Semiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ)
(x : M) : star ((n : R) • x) = (n : R) • star x :=
map_nat_cast_smul (starAddEquiv : M ≃+ M) R R n x
#align star_nat_cast_smul star_nat_cast_smul
@[simp]
theorem star_int_cast_smul [Ring R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℤ)
(x : M) : star ((n : R) • x) = (n : R) • star x :=
map_int_cast_smul (starAddEquiv : M ≃+ M) R R n x
#align star_int_cast_smul star_int_cast_smul
@[simp]
theorem star_inv_nat_cast_smul [DivisionSemiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M]
(n : ℕ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x :=
map_inv_nat_cast_smul (starAddEquiv : M ≃+ M) R R n x
#align star_inv_nat_cast_smul star_inv_nat_cast_smul
@[simp]
theorem star_inv_int_cast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M]
(n : ℤ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x :=
map_inv_int_cast_smul (starAddEquiv : M ≃+ M) R R n x
#align star_inv_int_cast_smul star_inv_int_cast_smul
@[simp]
theorem star_rat_cast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℚ)
(x : M) : star ((n : R) • x) = (n : R) • star x :=
map_rat_cast_smul (starAddEquiv : M ≃+ M) _ _ _ x
#align star_rat_cast_smul star_rat_cast_smul
@[simp]
theorem star_rat_smul {R : Type _} [AddCommGroup R] [StarAddMonoid R] [Module ℚ R] (x : R) (n : ℚ) :
star (n • x) = n • star x :=
map_rat_smul (starAddEquiv : R ≃+ R) _ _
#align star_rat_smul star_rat_smul
end SmulLemmas
section deinstance
-- porting note: this is lean#2074 at play
attribute [-instance] Ring.toNonUnitalRing
attribute [-instance] CommRing.toNonUnitalCommRing
/-- If `A` is a module over a commutative `R` with compatible actions,
then `star` is a semilinear equivalence. -/
@[simps]
def starLinearEquiv (R : Type _) {A : Type _} [CommRing R] [StarRing R] [Semiring A] [StarRing A]
[Module R A] [StarModule R A] : A ≃ₗ⋆[R] A :=
{ starAddEquiv with
toFun := star
map_smul' := star_smul }
#align star_linear_equiv starLinearEquiv
end deinstance
variable (R : Type _) (A : Type _) [Semiring R] [StarSemigroup R] [TrivialStar R] [AddCommGroup A]
[Module R A] [StarAddMonoid A] [StarModule R A]
/-- The self-adjoint elements of a star module, as a submodule. -/
def selfAdjoint.submodule : Submodule R A :=
{ selfAdjoint A with smul_mem' := fun _ _ => (IsSelfAdjoint.all _).smul }
#align self_adjoint.submodule selfAdjoint.submodule
/-- The skew-adjoint elements of a star module, as a submodule. -/
def skewAdjoint.submodule : Submodule R A :=
{ skewAdjoint A with smul_mem' := skewAdjoint.smul_mem }
#align skew_adjoint.submodule skewAdjoint.submodule
variable {A} [Invertible (2 : R)]
/-- The self-adjoint part of an element of a star module, as a linear map. -/
@[simps]
def selfAdjointPart : A →ₗ[R] selfAdjoint A
where
toFun x :=
⟨(⅟ 2 : R) • (x + star x), by
simp only [selfAdjoint.mem_iff, star_smul, add_comm, StarAddMonoid.star_add, star_inv',
star_bit0, star_one, star_star, star_invOf (2 : R), star_trivial]⟩
map_add' x y := by
ext
simp [add_add_add_comm]
map_smul' r x := by
ext
simp [← mul_smul, show ⅟ 2 * r = r * ⅟ 2 from Commute.invOf_left <| (2 : ℕ).cast_commute r]
#align self_adjoint_part selfAdjointPart
/-- The skew-adjoint part of an element of a star module, as a linear map. -/
@[simps]
def skewAdjointPart : A →ₗ[R] skewAdjoint A
where
toFun x :=
⟨(⅟ 2 : R) • (x - star x), by
simp only [skewAdjoint.mem_iff, star_smul, star_sub, star_star, star_trivial, ← smul_neg,
neg_sub]⟩
map_add' x y := by
ext
simp only [sub_add, ← smul_add, sub_sub_eq_add_sub, star_add, AddSubgroup.coe_mk,
AddSubgroup.coe_add]
map_smul' r x := by
ext
simp [← mul_smul, ← smul_sub,
show r * ⅟ 2 = ⅟ 2 * r from Commute.invOf_right <| (2 : ℕ).commute_cast r]
#align skew_adjoint_part skewAdjointPart
theorem StarModule.selfAdjointPart_add_skewAdjointPart (x : A) :
(selfAdjointPart R x : A) + skewAdjointPart R x = x := by
simp only [smul_sub, selfAdjointPart_apply_coe, smul_add, skewAdjointPart_apply_coe,
add_add_sub_cancel, inv_of_two_smul_add_inv_of_two_smul]
#align star_module.self_adjoint_part_add_skew_adjoint_part StarModule.selfAdjointPart_add_skewAdjointPart
variable (A)
/-- The decomposition of elements of a star module into their self- and skew-adjoint parts,
as a linear equivalence. -/
-- Porting note: This attribute causes a `timeout at 'whnf'`.
-- @[simps!]
def StarModule.decomposeProdAdjoint : A ≃ₗ[R] selfAdjoint A × skewAdjoint A := by
refine LinearEquiv.ofLinear ((selfAdjointPart R).prod (skewAdjointPart R))
(LinearMap.coprod ((selfAdjoint.submodule R A).subtype) (skewAdjoint.submodule R A).subtype)
?_ (LinearMap.ext <| StarModule.selfAdjointPart_add_skewAdjointPart R)
-- Porting note: The remaining proof at this point used to be `ext <;> simp`.
ext
· rw [LinearMap.id_coe, id.def]
rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.coprod_apply]
-- Porting note: It seems that in mathlib4 simp got a problem with defEq things.
-- It seems that in mathlib3 this was `submodule.coe_subtype`.
-- i.e. `rw [Submodule.coeSubtype]`
rename_i x
change ↑((LinearMap.prod (selfAdjointPart R) (skewAdjointPart R))
(Subtype.val x.fst + Subtype.val x.snd)).fst = (x.fst : A)
simp
· rw [LinearMap.id_coe, id.def]
rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.coprod_apply]
-- Porting note: See note above.
rename_i x
change ↑((LinearMap.prod (selfAdjointPart R) (skewAdjointPart R))
(Subtype.val x.fst + Subtype.val x.snd)).snd = (x.snd : A)
-- Porting note: With `set_option synthInstance.etaExperiment true` (lean4#2074) one needs the
-- 2 lines below (in particular `Pi.prod`).
-- With `etaExperiment false` they are uneccessary as `simp` would succeed without.
rw [LinearMap.prod_apply]
rw [Pi.prod]
simp
#align star_module.decompose_prod_adjoint StarModule.decomposeProdAdjoint
@[simp]
theorem algebraMap_star_comm {R A : Type _} [CommSemiring R] [StarRing R] [Semiring A]
[StarSemigroup A] [Algebra R A] [StarModule R A] (r : R) :
algebraMap R A (star r) = star (algebraMap R A r) := by
simp only [Algebra.algebraMap_eq_smul_one, star_smul, star_one]
#align algebra_map_star_comm algebraMap_star_comm
|
% AGENT CONTROL INPUT TRAJECTORIES
function [currentFigure,figureHandle] = GetFigure_inputs(SIM,objectIndex,DATA,currentFigure)
% Draws the seperations of all agents from each other, neglecting waypoint
% objects.
figureHandle = [];
% SANITY CHECK 1
if DATA.totalAgents == 0
warning('No agent data available.');
return
else
% LOGICALLY SELECT THE AGENTS FROM THE OBJECT INDEX
agentObjectIndex = objectIndex([SIM.OBJECTS.type] == OMAS_objectType.agent); % The agents themselves
end
iter = 0;
for ID1 = 1:SIM.totalAgents
% TRY TO GET THE REQUIRED PROPERTIES
try
testA = agentObjectIndex{ID1}.DATA.inputNames;
testB = agentObjectIndex{ID1}.DATA.inputs;
catch
iter = iter + 1;
end
end
% SANITY CHECK 2
if iter == SIM.totalAgents
warning('No agents have input timeseries stored in (agent).DATA.inputs. Use the "DATA.inputNames" and "DATA.inputs" fields if desired.');
return
end
% Declare title string for figure
figurePath = strcat(SIM.outputPath,'inputs');
% FIGURE META PROPERTIES
figureHandle = figure('Name','OpenMAS control inputs');
setappdata(figureHandle, 'SubplotDefaultAxesLocation', [0.1, 0.1, 0.85, 0.85]);
set(figureHandle,'Position', DATA.figureProperties.windowSettings); % [x y width height]
set(figureHandle,'Color',DATA.figureProperties.figureColor); % Background colour
plotCellA = 1; plotCellWidth = 4; % The width of each figure, the start of the plot
% FOR EACH AGENT'S PERSPECTIVE
for ID1 = 1:SIM.totalAgents
% GET EVALUATION OBJECT
evalAgent = agentObjectIndex{ID1};
% CHECK SKIP CONDITION
if isempty(evalAgent.DATA)
warning('[OUTPUT]\tProperty .DATA is empty for agent %s',evalAgent.name);
continue
end
% GET TH AGENT-LOCAL 'DATA' STRUCTURE
inputTrajectories = evalAgent.DATA.inputs;
inputCount = size(inputTrajectories,1);
% BUILD THE SUB-PLOT
plotCellB = double(ID1*plotCellWidth); % The end of the plot
plotLocation = subplot(double(DATA.totalAgents),plotCellWidth,[plotCellA plotCellB]);
set(plotLocation,...
'Color',DATA.figureProperties.axesColor,...
'GridLineStyle','--',...
'GridAlpha',0.25,...
'GridColor','k');
hold on;
% LEGEND LABELS
legendEntries = cell(inputCount,1);
numericLabelling = 1;
if isfield(evalAgent.DATA,'inputNames')
if length(evalAgent.DATA.inputNames) ~= inputCount
warning('Incorrect number of input labels for agent %s, reverting to numeric labelling',simName);
numericLabelling = 1;
else
% FETCH THE INPUT LABEL
for entry = 1:size(inputTrajectories,1)
legendEntries{entry} = evalAgent.DATA.inputNames{entry};
end
numericLabelling = 0;
end
end
if numericLabelling
% DEFAULT TO GENERIC NAMING
for entry = 1:size(inputTrajectories,1)
legendEntries{entry} = sprintf('Input %s',num2str(entry));
end
end
% PLOT THE SEPERATION DATA ON CURRENT FIGURE
plot(plotLocation,...
DATA.timeVector(:,1:SIM.TIME.endStep),...
inputTrajectories(:,1:SIM.TIME.endStep),...
'LineStyle','-',...
'LineWidth',DATA.figureProperties.lineWidth);
% Y-Label
ylabel(plotLocation,...
sprintf('Inputs \n [ID-%s]',num2str(evalAgent.objectID)),...
'Interpreter',DATA.figureProperties.interpreter,...
'fontname',DATA.figureProperties.fontName,...
'fontweight',DATA.figureProperties.fontWeight,...
'fontSize',DATA.figureProperties.axisFontSize,...
'FontSmoothing','On');
% Axes
set(plotLocation,...
'TickLabelInterpreter',DATA.figureProperties.interpreter,...
'fontname',DATA.figureProperties.fontName,...
'Fontweight',DATA.figureProperties.fontWeight,...
'FontSize',DATA.figureProperties.axisFontSize,...
'FontSmoothing','on',...
'Color',DATA.figureProperties.axesColor,...
'GridLineStyle','--',...
'GridAlpha',0.25,...
'GridColor','k');
% Legend
legend(legendEntries,...
'Location','eastoutside',...
'fontname',DATA.figureProperties.fontName,...
'Interpreter',DATA.figureProperties.interpreter);
grid on; box on; grid minor;
% Show the timestep difference in the figure
%plotLocation.XAxis.MinorTickValues = plotLocation.XAxis.Limits(1):SIM.TIME.dt:plotLocation.XAxis.Limits(2);
% ADD FIGURE TITLE TO FIRST PLOT HEADER
if plotCellA == 1
% Title
title(plotLocation,sprintf('Agent control trajectories over a period of %ss',num2str(SIM.TIME.endTime)),...
'Interpreter',DATA.figureProperties.interpreter,...
'fontname',DATA.figureProperties.fontName,...
'fontweight',DATA.figureProperties.fontWeight,...
'fontsize',DATA.figureProperties.titleFontSize); % Append title to first subplot
end
% Prevent overlap of x-label
if ID1 == DATA.totalAgents
% X-Label
xlabel(plotLocation,'t (s)',...
'Interpreter', DATA.figureProperties.interpreter,...
'fontname',DATA.figureProperties.fontName,...
'fontweight',DATA.figureProperties.fontWeight,...
'fontSize',DATA.figureProperties.axisFontSize,...
'FontSmoothing','On');
else
set(plotLocation,'XTickLabel',[]);
end
% Define the x-limits
xlim([SIM.TIME.startTime,SIM.TIME.endTime]); % Ensures plot alignment/sizing
plotCellA = plotCellA + plotCellWidth; % Move to next subplot location
end
hold off;
% SAVE THE OUTPUT FIGURE
savefig(figureHandle,figurePath);
% Publish as .pdf if requested
if DATA.figureProperties.publish
GetFigurePDF(figureHandle,figurePath);
end
% INCREMENT THE FIGURE INDEX
DATA.figureProperties.alignment = DATA.figureProperties.alignment + DATA.figureProperties.spacing;
currentFigure = currentFigure + 1;
end |
(* Title: A Definitional Encoding of TLA in Isabelle/HOL
Authors: Gudmund Grov <ggrov at inf.ed.ac.uk>
Stephan Merz <Stephan.Merz at loria.fr>
Year: 2011
Maintainer: Gudmund Grov <ggrov at inf.ed.ac.uk>
*)
section \<open>Lamport's Inc example\<close>
theory Inc
imports State
begin
text\<open>
This example illustrates use of the embedding by mechanising
the running example of Lamports original TLA paper \<^cite>\<open>"Lamport94"\<close>.
\<close>
datatype pcount = a | b | g
locale Firstprogram =
fixes x :: "state \<Rightarrow> nat"
and y :: "state \<Rightarrow> nat"
and init :: "temporal"
and m1 :: "temporal"
and m2 :: "temporal"
and phi :: "temporal"
and Live :: "temporal"
defines "init \<equiv> TEMP $x = # 0 \<and> $y = # 0"
and "m1 \<equiv> TEMP x` = Suc<$x> \<and> y` = $y"
and "m2 \<equiv> TEMP y` = Suc<$y> \<and> x` = $x"
and "Live \<equiv> TEMP WF(m1)_(x,y) \<and> WF(m2)_(x,y)"
and "phi \<equiv> TEMP (init \<and> \<box>[m1 \<or> m2]_(x,y) \<and> Live)"
assumes bvar: "basevars (x,y)"
lemma (in Firstprogram) "STUTINV phi"
by (auto simp: phi_def init_def m1_def m2_def Live_def stutinvs nstutinvs livestutinv)
lemma (in Firstprogram) enabled_m1: "\<turnstile> Enabled \<langle>m1\<rangle>_(x,y)"
proof (clarify)
fix s
show "s \<Turnstile> Enabled \<langle>m1\<rangle>_(x,y)"
by (rule base_enabled[OF bvar]) (auto simp: m1_def tla_defs)
qed
lemma (in Firstprogram) enabled_m2: "\<turnstile> Enabled \<langle>m2\<rangle>_(x,y)"
proof (clarify)
fix s
show "s \<Turnstile> Enabled \<langle>m2\<rangle>_(x,y)"
by (rule base_enabled[OF bvar]) (auto simp: m2_def tla_defs)
qed
locale Secondprogram = Firstprogram +
fixes sem :: "state \<Rightarrow> nat"
and pc1 :: "state \<Rightarrow> pcount"
and pc2 :: "state \<Rightarrow> pcount"
and vars
and initPsi :: "temporal"
and alpha1 :: "temporal"
and alpha2 :: "temporal"
and beta1 :: "temporal"
and beta2 :: "temporal"
and gamma1 :: "temporal"
and gamma2 :: "temporal"
and n1 :: "temporal"
and n2 :: "temporal"
and Live2 :: "temporal"
and psi :: "temporal"
and I :: "temporal"
defines "vars \<equiv> LIFT (x,y,sem,pc1,pc2)"
and "initPsi \<equiv> TEMP $pc1 = # a \<and> $pc2 = # a \<and> $x = # 0 \<and> $y = # 0 \<and> $sem = # 1"
and "alpha1 \<equiv> TEMP $pc1 =#a \<and> # 0 < $sem \<and> pc1$ = #b \<and> sem$ = $sem - # 1 \<and> Unchanged (x,y,pc2)"
and "alpha2 \<equiv> TEMP $pc2 =#a \<and> # 0 < $sem \<and> pc2` = #b \<and> sem$ = $sem - # 1 \<and> Unchanged (x,y,pc1)"
and "beta1 \<equiv> TEMP $pc1 =#b \<and> pc1` = #g \<and> x` = Suc<$x> \<and> Unchanged (y,sem,pc2)"
and "beta2 \<equiv> TEMP $pc2 =#b \<and> pc2` = #g \<and> y` = Suc<$y> \<and> Unchanged (x,sem,pc1)"
and "gamma1 \<equiv> TEMP $pc1 =#g \<and> pc1` = #a \<and> sem` = Suc<$sem> \<and> Unchanged (x,y,pc2)"
and "gamma2 \<equiv> TEMP $pc2 =#g \<and> pc2` = #a \<and> sem` = Suc<$sem> \<and> Unchanged (x,y,pc1)"
and "n1 \<equiv> TEMP (alpha1 \<or> beta1 \<or> gamma1)"
and "n2 \<equiv> TEMP (alpha2 \<or> beta2 \<or> gamma2)"
and "Live2 \<equiv> TEMP SF(n1)_vars \<and> SF(n2)_vars"
and "psi \<equiv> TEMP (initPsi \<and> \<box>[n1 \<or> n2]_vars \<and> Live2)"
and "I \<equiv> TEMP ($sem = # 1 \<and> $pc1 = #a \<and> $pc2 = # a)
\<or> ($sem = # 0 \<and> (($pc1 = #a \<and> $pc2 \<in> {#b , #g})
\<or> ($pc2 = #a \<and> $pc1 \<in> {#b , #g})))"
assumes bvar2: "basevars vars"
lemmas (in Secondprogram) Sact2_defs = n1_def n2_def alpha1_def beta1_def gamma1_def alpha2_def beta2_def gamma2_def
text \<open>
Proving invariants is the basis of every effort of system verification.
We show that \<open>I\<close> is an inductive invariant of specification \<open>psi\<close>.
\<close>
lemma (in Secondprogram) psiI: "\<turnstile> psi \<longrightarrow> \<box>I"
proof -
have init: "\<turnstile> initPsi \<longrightarrow> I" by (auto simp: initPsi_def I_def)
have "|~ I \<and> Unchanged vars \<longrightarrow> \<circle>I" by (auto simp: I_def vars_def tla_defs)
moreover
have "|~ I \<and> n1 \<longrightarrow> \<circle>I" by (auto simp: I_def Sact2_defs tla_defs)
moreover
have "|~ I \<and> n2 \<longrightarrow> \<circle>I" by (auto simp: I_def Sact2_defs tla_defs)
ultimately have step: "|~ I \<and> [n1 \<or> n2]_vars \<longrightarrow> \<circle>I" by (force simp: actrans_def)
from init step have goal: "\<turnstile> initPsi \<and> \<box>[n1 \<or> n2]_vars \<longrightarrow> \<box>I" by (rule invmono)
have "\<turnstile> initPsi \<and> \<box>[n1 \<or> n2]_vars \<and> Live2 ==> \<turnstile> initPsi \<and> \<box>[n1 \<or> n2]_vars"
by auto
with goal show ?thesis unfolding psi_def by auto
qed
text \<open>
Using this invariant we now prove step simulation, i.e. the safety part of
the refinement proof.
\<close>
theorem (in Secondprogram) step_simulation: "\<turnstile> psi \<longrightarrow> init \<and> \<box>[m1 \<or> m2]_(x,y)"
proof -
have "\<turnstile> initPsi \<and> \<box>I \<and> \<box>[n1 \<or> n2]_vars \<longrightarrow> init \<and> \<box>[m1 \<or> m2]_(x,y)"
proof (rule refinement1)
show "\<turnstile> initPsi \<longrightarrow> init" by (auto simp: initPsi_def init_def)
next
show "|~ I \<and> \<circle>I \<and> [n1 \<or> n2]_vars \<longrightarrow> [m1 \<or> m2]_(x,y)"
by (auto simp: I_def m1_def m2_def vars_def Sact2_defs tla_defs)
qed
with psiI show ?thesis unfolding psi_def by force
qed
text \<open>
Liveness proofs require computing the enabledness conditions of actions.
The first lemma below shows that all steps are visible, i.e. they change
at least one variable.
\<close>
lemma (in Secondprogram) n1_ch: "|~ \<langle>n1\<rangle>_vars = n1"
proof -
have "|~ n1 \<longrightarrow> \<langle>n1\<rangle>_vars" by (auto simp: Sact2_defs tla_defs vars_def)
thus ?thesis by (auto simp: angle_actrans_sem[int_rewrite])
qed
lemma (in Secondprogram) enab_alpha1: "\<turnstile> $pc1 = #a \<longrightarrow> # 0 < $sem \<longrightarrow> Enabled alpha1"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc1 (s 0) = a" and "0 < sem (s 0)"
thus "s \<Turnstile> Enabled alpha1"
by (intro base_enabled[OF bvar2]) (auto simp: Sact2_defs tla_defs vars_def)
qed
lemma (in Secondprogram) enab_beta1: "\<turnstile> $pc1 = #b \<longrightarrow> Enabled beta1"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc1 (s 0) = b"
thus "s \<Turnstile> Enabled beta1"
by (intro base_enabled[OF bvar2]) (auto simp: Sact2_defs tla_defs vars_def)
qed
lemma (in Secondprogram) enab_gamma1: "\<turnstile> $pc1 = #g \<longrightarrow> Enabled gamma1"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc1 (s 0) = g"
thus "s \<Turnstile> Enabled gamma1"
by (intro base_enabled[OF bvar2]) (auto simp: Sact2_defs tla_defs vars_def)
qed
lemma (in Secondprogram) enab_n1:
"\<turnstile> Enabled \<langle>n1\<rangle>_vars = ($pc1 = #a \<longrightarrow> # 0 < $sem)"
unfolding n1_ch[int_rewrite] proof (rule int_iffI)
show "\<turnstile> Enabled n1 \<longrightarrow> $pc1 = #a \<longrightarrow> # 0 < $sem"
by (auto elim!: enabledE simp: Sact2_defs tla_defs)
next
show "\<turnstile> ($pc1 = #a \<longrightarrow> # 0 < $sem) \<longrightarrow> Enabled n1"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc1 (s 0) = a \<longrightarrow> 0 < sem (s 0)"
thus "s \<Turnstile> Enabled n1"
using enab_alpha1[unlift_rule]
enab_beta1[unlift_rule]
enab_gamma1[unlift_rule]
by (cases "pc1 (s 0)") (force simp: n1_def Enabled_disj[int_rewrite] tla_defs)+
qed
qed
text \<open>
The analogous properties for the second process are obtained by copy and paste.
\<close>
lemma (in Secondprogram) n2_ch: "|~ \<langle>n2\<rangle>_vars = n2"
proof -
have "|~ n2 \<longrightarrow> \<langle>n2\<rangle>_vars" by (auto simp: Sact2_defs tla_defs vars_def)
thus ?thesis by (auto simp: angle_actrans_sem[int_rewrite])
qed
lemma (in Secondprogram) enab_alpha2: "\<turnstile> $pc2 = #a \<longrightarrow> # 0 < $sem \<longrightarrow> Enabled alpha2"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc2 (s 0) = a" and "0 < sem (s 0)"
thus "s \<Turnstile> Enabled alpha2"
by (intro base_enabled[OF bvar2]) (auto simp: Sact2_defs tla_defs vars_def)
qed
lemma (in Secondprogram) enab_beta2: "\<turnstile> $pc2 = #b \<longrightarrow> Enabled beta2"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc2 (s 0) = b"
thus "s \<Turnstile> Enabled beta2"
by (intro base_enabled[OF bvar2]) (auto simp: Sact2_defs tla_defs vars_def)
qed
lemma (in Secondprogram) enab_gamma2: "\<turnstile> $pc2 = #g \<longrightarrow> Enabled gamma2"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc2 (s 0) = g"
thus "s \<Turnstile> Enabled gamma2"
by (intro base_enabled[OF bvar2]) (auto simp: Sact2_defs tla_defs vars_def)
qed
lemma (in Secondprogram) enab_n2:
"\<turnstile> Enabled \<langle>n2\<rangle>_vars = ($pc2 = #a \<longrightarrow> # 0 < $sem)"
unfolding n2_ch[int_rewrite] proof (rule int_iffI)
show "\<turnstile> Enabled n2 \<longrightarrow> $pc2 = #a \<longrightarrow> # 0 < $sem"
by (auto elim!: enabledE simp: Sact2_defs tla_defs)
next
show "\<turnstile> ($pc2 = #a \<longrightarrow> # 0 < $sem) \<longrightarrow> Enabled n2"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc2 (s 0) = a \<longrightarrow> 0 < sem (s 0)"
thus "s \<Turnstile> Enabled n2"
using enab_alpha2[unlift_rule]
enab_beta2[unlift_rule]
enab_gamma2[unlift_rule]
by (cases "pc2 (s 0)") (force simp: n2_def Enabled_disj[int_rewrite] tla_defs)+
qed
qed
text \<open>
We use rule \<open>SF2\<close> to prove that \<open>psi\<close> implements strong fairness
for the abstract action \<open>m1\<close>. Since strong fairness implies weak fairness,
it follows that \<open>psi\<close> refines the liveness condition of \<open>phi\<close>.
\<close>
lemma (in Secondprogram) psi_fair_m1: "\<turnstile> psi \<longrightarrow> SF(m1)_(x,y)"
proof -
have "\<turnstile> \<box>[n1 \<or> n2]_vars \<and> SF(n1)_vars \<and> \<box>(I \<and> SF(n2)_vars) \<longrightarrow> SF(m1)_(x,y)"
proof (rule SF2)
txt \<open>
Rule \<open>SF2\<close> requires us to choose a helpful action (whose effect implies
\<open>\<langle>m1\<rangle>_(x,y)\<close>) and a persistent condition, which will eventually remain
true if the helpful action is never executed. In our case, the helpful action
is \<open>beta1\<close> and the persistent condition is \<open>pc1 = b\<close>.
\<close>
show "|~ \<langle>(n1 \<or> n2) \<and> beta1\<rangle>_vars \<longrightarrow> \<langle>m1\<rangle>_(x,y)"
by (auto simp: beta1_def m1_def vars_def tla_defs)
next
show "|~ $pc1 = #b \<and> \<circle>($pc1 = #b) \<and> \<langle>(n1 \<or> n2) \<and> n1\<rangle>_vars \<longrightarrow> beta1"
by (auto simp: n1_def alpha1_def beta1_def gamma1_def tla_defs)
next
show "\<turnstile> $pc1 = #b \<and> Enabled \<langle>m1\<rangle>_(x, y) \<longrightarrow> Enabled \<langle>n1\<rangle>_vars"
unfolding enab_n1[int_rewrite] by auto
next
txt \<open>
The difficult part of the proof is showing that the persistent condition
will eventually always be true if the helpful action is never executed.
We show that (1) whenever the condition becomes true it remains so and
(2) eventually the condition must be true.
\<close>
show "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars
\<and> SF(n1)_vars \<and> \<box>(I \<and> SF(n2)_vars) \<and> \<box>\<diamond>Enabled \<langle>m1\<rangle>_(x, y)
\<longrightarrow> \<diamond>\<box>($pc1 = #b)"
proof -
have "\<turnstile> \<box>\<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<longrightarrow> \<box>($pc1 = #b \<longrightarrow> \<box>($pc1 = #b))"
proof (rule STL4)
have "|~ $pc1 = #b \<and> [(n1 \<or> n2) \<and> \<not> beta1]_vars \<longrightarrow> \<circle>($pc1 = #b)"
by (auto simp: Sact2_defs vars_def tla_defs)
from this[THEN INV1]
show "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<longrightarrow> $pc1 = #b \<longrightarrow> \<box>($pc1 = #b)" by auto
qed
hence 1: "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<longrightarrow> \<diamond>($pc1 = #b) \<longrightarrow> \<diamond>\<box>($pc1 = #b)"
by (force intro: E31[unlift_rule])
have "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<and> SF(n1)_vars \<and> \<box>(I \<and> SF(n2)_vars)
\<longrightarrow> \<diamond>($pc1 = #b)"
proof -
txt \<open>
The plan of the proof is to show that from any state where \<open>pc1 = g\<close>
one eventually reaches \<open>pc1 = a\<close>, from where one eventually reaches
\<open>pc1 = b\<close>. The result follows by combining leadsto properties.
\<close>
let ?F = "LIFT (\<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<and> SF(n1)_vars \<and> \<box>(I \<and> SF(n2)_vars))"
txt \<open>
Showing that \<open>pc1 = g\<close> leads to \<open>pc1 = a\<close> is a simple
application of rule \<open>SF1\<close> because the first process completely
controls this transition.
\<close>
have ga: "\<turnstile> ?F \<longrightarrow> ($pc1 = #g \<leadsto> $pc1 = #a)"
proof (rule SF1)
show "|~ $pc1 = #g \<and> [(n1 \<or> n2) \<and> \<not> beta1]_vars \<longrightarrow> \<circle>($pc1 = #g) \<or> \<circle>($pc1 = #a)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc1 = #g \<and> \<langle>((n1 \<or> n2) \<and> \<not> beta1) \<and> n1\<rangle>_vars \<longrightarrow> \<circle>($pc1 = #a)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc1 = #g \<and> Unchanged vars \<longrightarrow> \<circle>($pc1 = #g)"
by (auto simp: vars_def tla_defs)
next
have "\<turnstile> $pc1 = #g \<longrightarrow> Enabled \<langle>n1\<rangle>_vars"
unfolding enab_n1[int_rewrite] by (auto simp: tla_defs)
hence "\<turnstile> \<box>($pc1 = #g) \<longrightarrow> Enabled \<langle>n1\<rangle>_vars"
by (rule lift_imp_trans[OF ax1])
hence "\<turnstile> \<box>($pc1 = #g) \<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
by (rule lift_imp_trans[OF _ E3])
thus "\<turnstile> \<box>($pc1 = #g) \<and> \<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<and> \<box>(I \<and> SF(n2)_vars)
\<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
by auto
qed
txt \<open>
The proof that \<open>pc1 = a\<close> leads to \<open>pc1 = b\<close> follows
the same basic schema. However, showing that \<open>n1\<close> is eventually
enabled requires reasoning about the second process, which must liberate
the critical section.
\<close>
have ab: "\<turnstile> ?F \<longrightarrow> ($pc1 = #a \<leadsto> $pc1 = #b)"
proof (rule SF1)
show "|~ $pc1 = #a \<and> [(n1 \<or> n2) \<and> \<not> beta1]_vars \<longrightarrow> \<circle>($pc1 = #a) \<or> \<circle>($pc1 = #b)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc1 = #a \<and> \<langle>((n1 \<or> n2) \<and> \<not> beta1) \<and> n1\<rangle>_vars \<longrightarrow> \<circle>($pc1 = #b)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc1 = #a \<and> Unchanged vars \<longrightarrow> \<circle>($pc1 = #a)"
by (auto simp: vars_def tla_defs)
next
txt \<open>We establish a suitable leadsto-chain.\<close>
let ?G = "LIFT \<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<and> SF(n2)_vars \<and> \<box>($pc1 = #a \<and> I)"
have "\<turnstile> ?G \<longrightarrow> \<diamond>($pc2 = #a \<and> $pc1 = #a \<and> I)"
proof -
txt \<open>Rule \<open>SF1\<close> takes us from \<open>pc2 = b\<close> to \<open>pc2 = g\<close>.\<close>
have bg2: "\<turnstile> ?G \<longrightarrow> ($pc2 = #b \<leadsto> $pc2 = #g)"
proof (rule SF1)
show "|~ $pc2 = #b \<and> [(n1 \<or> n2) \<and> \<not>beta1]_vars \<longrightarrow> \<circle>($pc2 = #b) \<or> \<circle>($pc2 = #g)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc2 = #b \<and> \<langle>((n1 \<or> n2) \<and> \<not>beta1) \<and> n2\<rangle>_vars \<longrightarrow> \<circle>($pc2 = #g)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc2 = #b \<and> Unchanged vars \<longrightarrow> \<circle>($pc2 = #b)"
by (auto simp: vars_def tla_defs)
next
have "\<turnstile> $pc2 = #b \<longrightarrow> Enabled \<langle>n2\<rangle>_vars"
unfolding enab_n2[int_rewrite] by (auto simp: tla_defs)
hence "\<turnstile> \<box>($pc2 = #b) \<longrightarrow> Enabled \<langle>n2\<rangle>_vars"
by (rule lift_imp_trans[OF ax1])
hence "\<turnstile> \<box>($pc2 = #b) \<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
by (rule lift_imp_trans[OF _ E3])
thus "\<turnstile> \<box>($pc2 = #b) \<and> \<box>[(n1 \<or> n2) \<and> \<not>beta1]_vars \<and> \<box>($pc1 = #a \<and> I)
\<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
by auto
qed
txt \<open>Similarly, \<open>pc2 = b\<close> leads to \<open>pc2 = g\<close>.\<close>
have ga2: "\<turnstile> ?G \<longrightarrow> ($pc2 = #g \<leadsto> $pc2 = #a)"
proof (rule SF1)
show "|~ $pc2 = #g \<and> [(n1 \<or> n2) \<and> \<not>beta1]_vars \<longrightarrow> \<circle>($pc2 = #g) \<or> \<circle>($pc2 = #a)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc2 = #g \<and> \<langle>((n1 \<or> n2) \<and> \<not>beta1) \<and> n2\<rangle>_vars \<longrightarrow> \<circle>($pc2 = #a)"
by (auto simp: n2_def alpha2_def beta2_def gamma2_def vars_def tla_defs)
next
show "|~ $pc2 = #g \<and> Unchanged vars \<longrightarrow> \<circle>($pc2 = #g)"
by (auto simp: vars_def tla_defs)
next
have "\<turnstile> $pc2 = #g \<longrightarrow> Enabled \<langle>n2\<rangle>_vars"
unfolding enab_n2[int_rewrite] by (auto simp: tla_defs)
hence "\<turnstile> \<box>($pc2 = #g) \<longrightarrow> Enabled \<langle>n2\<rangle>_vars"
by (rule lift_imp_trans[OF ax1])
hence "\<turnstile> \<box>($pc2 = #g) \<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
by (rule lift_imp_trans[OF _ E3])
thus "\<turnstile> \<box>($pc2 = #g) \<and> \<box>[(n1 \<or> n2) \<and> \<not>beta1]_vars \<and> \<box>($pc1 = #a \<and> I)
\<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
by auto
qed
with bg2 have "\<turnstile> ?G \<longrightarrow> ($pc2 = #b \<leadsto> $pc2 = #a)"
by (force elim: LT13[unlift_rule])
with ga2 have "\<turnstile> ?G \<longrightarrow> ($pc2 = #a \<or> $pc2 = #b \<or> $pc2 = #g) \<leadsto> ($pc2 = #a)"
unfolding LT17[int_rewrite] LT1[int_rewrite] by force
moreover
have "\<turnstile> $pc2 = #a \<or> $pc2 = #b \<or> $pc2 = #g"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc2 (s 0) \<noteq> a" and "pc2 (s 0) \<noteq> g"
thus "pc2 (s 0) = b" by (cases "pc2 (s 0)") auto
qed
hence "\<turnstile> (($pc2 = #a \<or> $pc2 = #b \<or> $pc2 = #g) \<leadsto> $pc2 = #a) \<longrightarrow> \<diamond>($pc2 = #a)"
by (rule fmp[OF _ LT4])
ultimately
have "\<turnstile> ?G \<longrightarrow> \<diamond>($pc2 = #a)" by force
thus ?thesis by (auto intro!: SE3[unlift_rule])
qed
moreover
have "\<turnstile> \<diamond>($pc2 = #a \<and> $pc1 = #a \<and> I) \<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
unfolding enab_n1[int_rewrite] by (rule STL4_eve) (auto simp: I_def tla_defs)
ultimately
show "\<turnstile> \<box>($pc1 = #a) \<and> \<box>[(n1 \<or> n2) \<and> \<not> beta1]_vars \<and> \<box>(I \<and> SF(n2)_vars)
\<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
by (force simp: STL5[int_rewrite])
qed
from ga ab have "\<turnstile> ?F \<longrightarrow> ($pc1 = #g \<leadsto> $pc1 = #b)"
by (force elim: LT13[unlift_rule])
with ab have "\<turnstile> ?F \<longrightarrow> (($pc1 = #a \<or> $pc1 = #b \<or> $pc1 = #g) \<leadsto> $pc1 = #b)"
unfolding LT17[int_rewrite] LT1[int_rewrite] by force
moreover
have "\<turnstile> $pc1 = #a \<or> $pc1 = #b \<or> $pc1 = #g"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc1 (s 0) \<noteq> a" and "pc1 (s 0) \<noteq> g"
thus "pc1 (s 0) = b" by (cases "pc1 (s 0)", auto)
qed
hence "\<turnstile> (($pc1 = #a \<or> $pc1 = #b \<or> $pc1 = #g) \<leadsto> $pc1 = #b) \<longrightarrow> \<diamond>($pc1 = #b)"
by (rule fmp[OF _ LT4])
ultimately show ?thesis by (rule lift_imp_trans)
qed
with 1 show ?thesis by force
qed
qed
with psiI show ?thesis unfolding psi_def Live2_def STL5[int_rewrite] by force
qed
text \<open>
In the same way we prove that \<open>psi\<close> implements strong fairness
for the abstract action \<open>m1\<close>. The proof is obtained by copy and paste
from the previous one.
\<close>
lemma (in Secondprogram) psi_fair_m2: "\<turnstile> psi \<longrightarrow> SF(m2)_(x,y)"
proof -
have "\<turnstile> \<box>[n1 \<or> n2]_vars \<and> SF(n2)_vars \<and> \<box>(I \<and> SF(n1)_vars) \<longrightarrow> SF(m2)_(x,y)"
proof (rule SF2)
txt \<open>
Rule \<open>SF2\<close> requires us to choose a helpful action (whose effect implies
\<open>\<langle>m2\<rangle>_(x,y)\<close>) and a persistent condition, which will eventually remain
true if the helpful action is never executed. In our case, the helpful action
is \<open>beta2\<close> and the persistent condition is \<open>pc2 = b\<close>.
\<close>
show "|~ \<langle>(n1 \<or> n2) \<and> beta2\<rangle>_vars \<longrightarrow> \<langle>m2\<rangle>_(x,y)"
by (auto simp: beta2_def m2_def vars_def tla_defs)
next
show "|~ $pc2 = #b \<and> \<circle>($pc2 = #b) \<and> \<langle>(n1 \<or> n2) \<and> n2\<rangle>_vars \<longrightarrow> beta2"
by (auto simp: n2_def alpha2_def beta2_def gamma2_def tla_defs)
next
show "\<turnstile> $pc2 = #b \<and> Enabled \<langle>m2\<rangle>_(x, y) \<longrightarrow> Enabled \<langle>n2\<rangle>_vars"
unfolding enab_n2[int_rewrite] by auto
next
txt \<open>
The difficult part of the proof is showing that the persistent condition
will eventually always be true if the helpful action is never executed.
We show that (1) whenever the condition becomes true it remains so and
(2) eventually the condition must be true.
\<close>
show "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars
\<and> SF(n2)_vars \<and> \<box>(I \<and> SF(n1)_vars) \<and> \<box>\<diamond>Enabled \<langle>m2\<rangle>_(x, y)
\<longrightarrow> \<diamond>\<box>($pc2 = #b)"
proof -
have "\<turnstile> \<box>\<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<longrightarrow> \<box>($pc2 = #b \<longrightarrow> \<box>($pc2 = #b))"
proof (rule STL4)
have "|~ $pc2 = #b \<and> [(n1 \<or> n2) \<and> \<not> beta2]_vars \<longrightarrow> \<circle>($pc2 = #b)"
by (auto simp: Sact2_defs vars_def tla_defs)
from this[THEN INV1]
show "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<longrightarrow> $pc2 = #b \<longrightarrow> \<box>($pc2 = #b)" by auto
qed
hence 1: "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<longrightarrow> \<diamond>($pc2 = #b) \<longrightarrow> \<diamond>\<box>($pc2 = #b)"
by (force intro: E31[unlift_rule])
have "\<turnstile> \<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<and> SF(n2)_vars \<and> \<box>(I \<and> SF(n1)_vars)
\<longrightarrow> \<diamond>($pc2 = #b)"
proof -
txt \<open>
The plan of the proof is to show that from any state where \<open>pc2 = g\<close>
one eventually reaches \<open>pc2 = a\<close>, from where one eventually reaches
\<open>pc2 = b\<close>. The result follows by combining leadsto properties.
\<close>
let ?F = "LIFT (\<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<and> SF(n2)_vars \<and> \<box>(I \<and> SF(n1)_vars))"
txt \<open>
Showing that \<open>pc2 = g\<close> leads to \<open>pc2 = a\<close> is a simple
application of rule \<open>SF1\<close> because the second process completely
controls this transition.
\<close>
have ga: "\<turnstile> ?F \<longrightarrow> ($pc2 = #g \<leadsto> $pc2 = #a)"
proof (rule SF1)
show "|~ $pc2 = #g \<and> [(n1 \<or> n2) \<and> \<not> beta2]_vars \<longrightarrow> \<circle>($pc2 = #g) \<or> \<circle>($pc2 = #a)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc2 = #g \<and> \<langle>((n1 \<or> n2) \<and> \<not> beta2) \<and> n2\<rangle>_vars \<longrightarrow> \<circle>($pc2 = #a)"
by (auto simp: n2_def alpha2_def beta2_def gamma2_def vars_def tla_defs)
next
show "|~ $pc2 = #g \<and> Unchanged vars \<longrightarrow> \<circle>($pc2 = #g)"
by (auto simp: vars_def tla_defs)
next
have "\<turnstile> $pc2 = #g \<longrightarrow> Enabled \<langle>n2\<rangle>_vars"
unfolding enab_n2[int_rewrite] by (auto simp: tla_defs)
hence "\<turnstile> \<box>($pc2 = #g) \<longrightarrow> Enabled \<langle>n2\<rangle>_vars"
by (rule lift_imp_trans[OF ax1])
hence "\<turnstile> \<box>($pc2 = #g) \<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
by (rule lift_imp_trans[OF _ E3])
thus "\<turnstile> \<box>($pc2 = #g) \<and> \<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<and> \<box>(I \<and> SF(n1)_vars)
\<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
by auto
qed
txt \<open>
The proof that \<open>pc2 = a\<close> leads to \<open>pc2 = b\<close> follows
the same basic schema. However, showing that \<open>n2\<close> is eventually
enabled requires reasoning about the second process, which must liberate
the critical section.
\<close>
have ab: "\<turnstile> ?F \<longrightarrow> ($pc2 = #a \<leadsto> $pc2 = #b)"
proof (rule SF1)
show "|~ $pc2 = #a \<and> [(n1 \<or> n2) \<and> \<not> beta2]_vars \<longrightarrow> \<circle>($pc2 = #a) \<or> \<circle>($pc2 = #b)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc2 = #a \<and> \<langle>((n1 \<or> n2) \<and> \<not> beta2) \<and> n2\<rangle>_vars \<longrightarrow> \<circle>($pc2 = #b)"
by (auto simp: n2_def alpha2_def beta2_def gamma2_def vars_def tla_defs)
next
show "|~ $pc2 = #a \<and> Unchanged vars \<longrightarrow> \<circle>($pc2 = #a)"
by (auto simp: vars_def tla_defs)
next
txt \<open>We establish a suitable leadsto-chain.\<close>
let ?G = "LIFT \<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<and> SF(n1)_vars \<and> \<box>($pc2 = #a \<and> I)"
have "\<turnstile> ?G \<longrightarrow> \<diamond>($pc1 = #a \<and> $pc2 = #a \<and> I)"
proof -
txt \<open>Rule \<open>SF1\<close> takes us from \<open>pc1 = b\<close> to \<open>pc1 = g\<close>.\<close>
have bg1: "\<turnstile> ?G \<longrightarrow> ($pc1 = #b \<leadsto> $pc1 = #g)"
proof (rule SF1)
show "|~ $pc1 = #b \<and> [(n1 \<or> n2) \<and> \<not>beta2]_vars \<longrightarrow> \<circle>($pc1 = #b) \<or> \<circle>($pc1 = #g)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc1 = #b \<and> \<langle>((n1 \<or> n2) \<and> \<not>beta2) \<and> n1\<rangle>_vars \<longrightarrow> \<circle>($pc1 = #g)"
by (auto simp: n1_def alpha1_def beta1_def gamma1_def vars_def tla_defs)
next
show "|~ $pc1 = #b \<and> Unchanged vars \<longrightarrow> \<circle>($pc1 = #b)"
by (auto simp: vars_def tla_defs)
next
have "\<turnstile> $pc1 = #b \<longrightarrow> Enabled \<langle>n1\<rangle>_vars"
unfolding enab_n1[int_rewrite] by (auto simp: tla_defs)
hence "\<turnstile> \<box>($pc1 = #b) \<longrightarrow> Enabled \<langle>n1\<rangle>_vars"
by (rule lift_imp_trans[OF ax1])
hence "\<turnstile> \<box>($pc1 = #b) \<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
by (rule lift_imp_trans[OF _ E3])
thus "\<turnstile> \<box>($pc1 = #b) \<and> \<box>[(n1 \<or> n2) \<and> \<not>beta2]_vars \<and> \<box>($pc2 = #a \<and> I)
\<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
by auto
qed
txt \<open>Similarly, \<open>pc1 = b\<close> leads to \<open>pc1 = g\<close>.\<close>
have ga1: "\<turnstile> ?G \<longrightarrow> ($pc1 = #g \<leadsto> $pc1 = #a)"
proof (rule SF1)
show "|~ $pc1 = #g \<and> [(n1 \<or> n2) \<and> \<not>beta2]_vars \<longrightarrow> \<circle>($pc1 = #g) \<or> \<circle>($pc1 = #a)"
by (auto simp: Sact2_defs vars_def tla_defs)
next
show "|~ $pc1 = #g \<and> \<langle>((n1 \<or> n2) \<and> \<not>beta2) \<and> n1\<rangle>_vars \<longrightarrow> \<circle>($pc1 = #a)"
by (auto simp: n1_def alpha1_def beta1_def gamma1_def vars_def tla_defs)
next
show "|~ $pc1 = #g \<and> Unchanged vars \<longrightarrow> \<circle>($pc1 = #g)"
by (auto simp: vars_def tla_defs)
next
have "\<turnstile> $pc1 = #g \<longrightarrow> Enabled \<langle>n1\<rangle>_vars"
unfolding enab_n1[int_rewrite] by (auto simp: tla_defs)
hence "\<turnstile> \<box>($pc1 = #g) \<longrightarrow> Enabled \<langle>n1\<rangle>_vars"
by (rule lift_imp_trans[OF ax1])
hence "\<turnstile> \<box>($pc1 = #g) \<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
by (rule lift_imp_trans[OF _ E3])
thus "\<turnstile> \<box>($pc1 = #g) \<and> \<box>[(n1 \<or> n2) \<and> \<not>beta2]_vars \<and> \<box>($pc2 = #a \<and> I)
\<longrightarrow> \<diamond>Enabled \<langle>n1\<rangle>_vars"
by auto
qed
with bg1 have "\<turnstile> ?G \<longrightarrow> ($pc1 = #b \<leadsto> $pc1 = #a)"
by (force elim: LT13[unlift_rule])
with ga1 have "\<turnstile> ?G \<longrightarrow> ($pc1 = #a \<or> $pc1 = #b \<or> $pc1 = #g) \<leadsto> ($pc1 = #a)"
unfolding LT17[int_rewrite] LT1[int_rewrite] by force
moreover
have "\<turnstile> $pc1 = #a \<or> $pc1 = #b \<or> $pc1 = #g"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc1 (s 0) \<noteq> a" and "pc1 (s 0) \<noteq> g"
thus "pc1 (s 0) = b" by (cases "pc1 (s 0)") auto
qed
hence "\<turnstile> (($pc1 = #a \<or> $pc1 = #b \<or> $pc1 = #g) \<leadsto> $pc1 = #a) \<longrightarrow> \<diamond>($pc1 = #a)"
by (rule fmp[OF _ LT4])
ultimately
have "\<turnstile> ?G \<longrightarrow> \<diamond>($pc1 = #a)" by force
thus ?thesis by (auto intro!: SE3[unlift_rule])
qed
moreover
have "\<turnstile> \<diamond>($pc1 = #a \<and> $pc2 = #a \<and> I) \<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
unfolding enab_n2[int_rewrite] by (rule STL4_eve) (auto simp: I_def tla_defs)
ultimately
show "\<turnstile> \<box>($pc2 = #a) \<and> \<box>[(n1 \<or> n2) \<and> \<not> beta2]_vars \<and> \<box>(I \<and> SF(n1)_vars)
\<longrightarrow> \<diamond>Enabled \<langle>n2\<rangle>_vars"
by (force simp: STL5[int_rewrite])
qed
from ga ab have "\<turnstile> ?F \<longrightarrow> ($pc2 = #g \<leadsto> $pc2 = #b)"
by (force elim: LT13[unlift_rule])
with ab have "\<turnstile> ?F \<longrightarrow> (($pc2 = #a \<or> $pc2 = #b \<or> $pc2 = #g) \<leadsto> $pc2 = #b)"
unfolding LT17[int_rewrite] LT1[int_rewrite] by force
moreover
have "\<turnstile> $pc2 = #a \<or> $pc2 = #b \<or> $pc2 = #g"
proof (clarsimp simp: tla_defs)
fix s :: "state seq"
assume "pc2 (s 0) \<noteq> a" and "pc2 (s 0) \<noteq> g"
thus "pc2 (s 0) = b" by (cases "pc2 (s 0)") auto
qed
hence "\<turnstile> (($pc2 = #a \<or> $pc2 = #b \<or> $pc2 = #g) \<leadsto> $pc2 = #b) \<longrightarrow> \<diamond>($pc2 = #b)"
by (rule fmp[OF _ LT4])
ultimately show ?thesis by (rule lift_imp_trans)
qed
with 1 show ?thesis by force
qed
qed
with psiI show ?thesis unfolding psi_def Live2_def STL5[int_rewrite] by force
qed
text \<open>
We can now prove the main theorem, which states that \<open>psi\<close>
implements \<open>phi\<close>.
\<close>
theorem (in Secondprogram) impl: "\<turnstile> psi \<longrightarrow> phi"
unfolding phi_def Live_def
by (auto dest: step_simulation[unlift_rule]
lift_imp_trans[OF psi_fair_m1 SF_imp_WF, unlift_rule]
lift_imp_trans[OF psi_fair_m2 SF_imp_WF, unlift_rule])
end
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Keeley Hoek, Scott Morrison
! This file was ported from Lean 3 source module tactic.simp_command
! leanprover-community/mathlib commit 8f6fd1b69096c6a587f745d354306c0d46396915
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Tactic.Core
/-!
## #simp
A user command to run the simplifier.
-/
namespace Tactic
/-- Strip all annotations of non local constants in the passed `expr`. (This is required in an
incantation later on in order to make the C++ simplifier happy.) -/
private unsafe def strip_annotations_from_all_non_local_consts {elab : Bool} (e : expr elab) :
expr elab :=
expr.unsafe_cast <|
e.unsafe_cast.replace fun e n =>
match e.is_annotation with
| some (_, expr.local_const _ _ _ _) => none
| some (_, _) => e.erase_annotations
| _ => none
#align tactic.strip_annotations_from_all_non_local_consts tactic.strip_annotations_from_all_non_local_consts
/-- `simp_arg_type.to_pexpr` retrieves the `pexpr` underlying the given `simp_arg_type`, if there is
one. -/
unsafe def simp_arg_type.to_pexpr : simp_arg_type → Option pexpr
| sat@(simp_arg_type.expr e) => e
| sat@(simp_arg_type.symm_expr e) => e
| sat => none
#align tactic.simp_arg_type.to_pexpr tactic.simp_arg_type.to_pexpr
/-- Incantation which prepares a `pexpr` in a `simp_arg_type` for use by the simplifier after
`expr.replace_subexprs` as been called to replace some of its local variables. -/
private unsafe def replace_subexprs_for_simp_arg (e : pexpr) (rules : List (expr × expr)) : pexpr :=
strip_annotations_from_all_non_local_consts <|
pexpr.of_expr <| e.unsafe_cast.replace_subexprs rules
#align tactic.replace_subexprs_for_simp_arg tactic.replace_subexprs_for_simp_arg
/-- `simp_arg_type.replace_subexprs` calls `expr.replace_subexprs` on the underlying `pexpr`, if
there is one, and then prepares the result for use by the simplifier. -/
unsafe def simp_arg_type.replace_subexprs : simp_arg_type → List (expr × expr) → simp_arg_type
| simp_arg_type.expr e, rules => simp_arg_type.expr <| replace_subexprs_for_simp_arg e rules
| simp_arg_type.symm_expr e, rules =>
simp_arg_type.symm_expr <| replace_subexprs_for_simp_arg e rules
| sat, rules => sat
#align tactic.simp_arg_type.replace_subexprs tactic.simp_arg_type.replace_subexprs
/- ./././Mathport/Syntax/Translate/Tactic/Mathlib/Core.lean:38:34: unsupported: setup_tactic_parser -/
-- Turn off the messages if the result is exactly `true` with this option.
initialize
registerTraceClass.1 `silence_simp_if_true
/-- The basic usage is `#simp e`, where `e` is an expression,
which will print the simplified form of `e`.
You can specify additional simp lemmas as usual for example using
`#simp [f, g] : e`, or `#simp with attr : e`.
(The colon is optional, but helpful for the parser.)
`#simp` understands local variables, so you can use them to
introduce parameters.
-/
@[user_command]
unsafe def simp_cmd (_ : parse <| tk "#simp") : lean.parser Unit := do
let no_dflt ← only_flag
let hs ← simp_arg_list
let attr_names ← with_ident_list
let o ← optional (tk ":")
let e ← types.texpr
let-- Retrieve the `pexpr`s parsed as part of the simp args, and collate them into a big list.
hs_es := List.join <| hs.map <| Option.toList ∘ simp_arg_type.to_pexpr
let/- Synthesize a `tactic_state` including local variables as hypotheses under which `expr.simp`
may be safely called with expected behaviour given the `variables` in the environment. -/
(ts, mappings)
← synthesize_tactic_state_with_variables_as_hyps (e :: hs_es)
let simp_result
←-- Enter the `tactic` monad, *critically* using the synthesized tactic state `ts`.
lean.parser.of_tactic
fun _ =>
(/- Resolve the local variables added by the parser to `e` (when it was parsed) against the local
hypotheses added to the `ts : tactic_state` which we are using. -/
do
let e ← to_expr e
let/- Replace the variables referenced in the passed `simp_arg_list` with the `expr`s corresponding
to the local hypotheses we created.
We would prefer to just elaborate the `pexpr`s encoded in the `simp_arg_list` against the
tactic state we have created (as we could with `e` above), but the simplifier expects
`pexpr`s and not `expr`s. Thus, we just modify the `pexpr`s now and let `simp` do the
elaboration when the time comes.
You might think that we could just examine each of these `pexpr`s, call `to_expr` on them,
and then call `to_pexpr` afterward and save the results over the original `pexprs`. Due to
how functions like `simp_lemmas.add_pexpr` are implemented in the core library, the `simp`
framework is not robust enough to handle this method. When pieces of expressions like
annotation macros are injected, the direct patten matches in the `simp_lemmas.*` codebase
fail, and the lemmas we want don't get added.
-/
hs := hs.map fun sat => sat.replace_subexprs mappings
-- Finally, call `expr.simp` with `e` and return the result.
Prod.fst <$>
e { } failed no_dflt attr_names hs)
ts
-- Trace the result.
when
(¬is_trace_enabled_for `silence_simp_if_true ∨ simp_result ≠ expr.const `true [])
(trace simp_result)
#align tactic.simp_cmd tactic.simp_cmd
add_tactic_doc
{ Name := "#simp"
category := DocCategory.cmd
declNames := [`tactic.simp_cmd]
tags := ["simplification"] }
end Tactic
|
State Before: θ : Angle
⊢ toReal (2 • θ) = 2 * toReal θ + 2 * π ↔ toReal θ ≤ -π / 2 State After: θ : Angle
⊢ toReal (2 • ↑(toReal θ)) = 2 * toReal θ + 2 * π ↔ toReal θ ≤ -π / 2 Tactic: nth_rw 1 [← coe_toReal θ] State Before: θ : Angle
⊢ toReal (2 • ↑(toReal θ)) = 2 * toReal θ + 2 * π ↔ toReal θ ≤ -π / 2 State After: θ : Angle
⊢ -3 * π < 2 * toReal θ ∧ 2 * toReal θ ≤ -π ↔ toReal θ ≤ -π / 2 Tactic: rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_add_two_pi_iff, Set.mem_Ioc] State Before: θ : Angle
⊢ -3 * π < 2 * toReal θ ∧ 2 * toReal θ ≤ -π ↔ toReal θ ≤ -π / 2 State After: no goals Tactic: refine'
⟨fun h => by linarith, fun h =>
⟨by linarith [pi_pos, neg_pi_lt_toReal θ], (le_div_iff' (zero_lt_two' ℝ)).1 h⟩⟩ State Before: θ : Angle
h : -3 * π < 2 * toReal θ ∧ 2 * toReal θ ≤ -π
⊢ toReal θ ≤ -π / 2 State After: no goals Tactic: linarith State Before: θ : Angle
h : toReal θ ≤ -π / 2
⊢ -3 * π < 2 * toReal θ State After: no goals Tactic: linarith [pi_pos, neg_pi_lt_toReal θ] |
% !TeX root = 00Book.tex
\subsection{August: Honey Crop and Varroa Treatment}
\subsubsection{Honey}
Taking off the honey before varroa treatment.
Canadian rhombus clearer board takes 2 days to clear of bees.
Drying the honey,
in the airing cupboard.
\subsubsection{Varroa Treatment}
No point in judging the number of varroa.
Just treat.
Apiguard or MAQS
On of before 12 kg to ensure that the temperature is h
\subsubsection{Feeding}
It is
generally considered that a honey bee colony requires about 20 – 30 kg of honey to
safely feed it through the winter.
Feed 14 kg per hive
which comes up to about 16 kg when stored in the hive.
A brood frame can carry about 2.2 kg of honey.
So the carrying capacity of 16 frames is about 35 kg.
The brood will take up space.
So for this reason you need at least 16 frames to go through winter.
A single brood is too small but a double brood is too much.
Brood and a half it about right but it is too compact
and you have a mix of frame sizes.
So a total of 42 kg of sugar is required for all three hives.
If you can get it at 50p per kg this is only £21,
so it is hardly worth bothering to heft the hives or weigh them.
Just feed it all or until they stop.
\subsubsection{Swarming}
If it happens it is too late, therefore:
\begin{description}
\item [Queen to one side] Split
\item [Queen excluder underneath] to prevent swarming (remove after a week)
\item [Unite] again don't try to produce a new queen.
\end{description}
|
Load(graph);
Import(graph);
conf := SparseDefaultConf;
opts := conf.getOpts(V(1));
opts.vec := true;
i := Ind(opts.symbol[1]);
front := var.fresh_t("frontier",TArray(TSemiring_Boolean(TInt), opts.symbol[1]));
fdataofs := FDataOfs(front, opts.symbol[1], 0);
md := MakeDiag(fdataofs);
eye := I(i);
sid := SUM(eye, md);
matmul := MatMul(opts.symbol[1],opts.symbol[1]);
spmv := matmul * sid;
spmv2 := Rewrite(spmv, RulesIDiag, opts);
push := Rewrite(spmv2, RulesMatMul, opts);
fdos := FDataOfs(front, opts.symbol[1], i);
rv := RowVec(fdos);
pull := IterVStack(i, opts.symbol[1], rv);
f := var.fresh_t("nnz", TInt);
push_pull := COND(lt(div(f, opts.symbol[1]), V(0.01)), PushBFSKernel(push), PullBFSKernel(pull));
rt := RandomRuleTree(last, opts);
srt := SumsRuleTree(rt, opts);
srt2 := Rewrite(Copy(srt), RulesSigSPMV2, opts);
push_pullfinal := Rewrite(Copy(srt2), RulesScatRow, opts);
cs := CodeSums(BFSKernel(last), opts);
PrintCode("dobfs", cs, opts); |
State Before: b o : Ordinal
hb : 1 < b
ho : o ≠ 0
hbo : b ≤ o
⊢ 0 < log b o State After: no goals Tactic: rwa [← succ_le_iff, succ_zero, ← opow_le_iff_le_log hb ho, opow_one] |
/-
Copyright © 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri, Yury Kudryashov
-/
import geometry.manifold.times_cont_mdiff_map
/-!
# Diffeomorphisms
This file implements diffeomorphisms.
## Definitions
* `diffeomorph I I' M M' n`: `n`-times continuously differentiable diffeomorphism between
`M` and `M'` with respect to I and I'; we do not introduce a separate definition for the case
`n = ∞`; we use notation instead.
* `diffeomorph.to_homeomorph`: reinterpret a diffeomorphism as a homeomorphism.
* `continuous_linear_equiv.to_diffeomorph`: reinterpret a continuous equivalence as
a diffeomorphism.
* `model_with_corners.trans_diffeomorph`: compose a given `model_with_corners` with a diffeomorphism
between the old and the new target spaces. Useful, e.g, to turn any finite dimensional manifold
into a manifold modelled on a Euclidean space.
* `diffeomorph.to_trans_diffeomorph`: the identity diffeomorphism between `M` with model `I` and `M`
with model `I.trans_diffeomorph e`.
## Notations
* `M ≃ₘ^n⟮I, I'⟯ M'` := `diffeomorph I J M N n`
* `M ≃ₘ⟮I, I'⟯ M'` := `diffeomorph I J M N ⊤`
* `E ≃ₘ^n[𝕜] E'` := `E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'`
* `E ≃ₘ[𝕜] E'` := `E ≃ₘ⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'`
## Implementation notes
This notion of diffeomorphism is needed although there is already a notion of structomorphism
because structomorphisms do not allow the model spaces `H` and `H'` of the two manifolds to be
different, i.e. for a structomorphism one has to impose `H = H'` which is often not the case in
practice.
## Keywords
diffeomorphism, manifold
-/
open_locale manifold topological_space
open function set
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{F : Type*} [normed_group F] [normed_space 𝕜 F]
{H : Type*} [topological_space H]
{H' : Type*} [topological_space H']
{G : Type*} [topological_space G]
{I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'}
{J : model_with_corners 𝕜 F G}
variables {M : Type*} [topological_space M] [charted_space H M]
{M' : Type*} [topological_space M'] [charted_space H' M']
{N : Type*} [topological_space N] [charted_space G N]
{n : with_top ℕ}
section defs
variables (I I' M M' n)
/--
`n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I'
-/
@[protect_proj, nolint has_inhabited_instance]
structure diffeomorph extends M ≃ M' :=
(times_cont_mdiff_to_fun : times_cont_mdiff I I' n to_equiv)
(times_cont_mdiff_inv_fun : times_cont_mdiff I' I n to_equiv.symm)
end defs
localized "notation M ` ≃ₘ^` n:1000 `⟮`:50 I `,` J `⟯ ` N := diffeomorph I J M N n" in manifold
localized "notation M ` ≃ₘ⟮` I `,` J `⟯ ` N := diffeomorph I J M N ⊤" in manifold
localized "notation E ` ≃ₘ^` n:1000 `[`:50 𝕜 `] ` E' :=
diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' n" in manifold
localized "notation E ` ≃ₘ[` 𝕜 `] ` E' :=
diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' ⊤" in manifold
namespace diffeomorph
instance : has_coe_to_fun (M ≃ₘ^n⟮I, I'⟯ M') := ⟨λ _, M → M', λe, e.to_equiv⟩
instance : has_coe (M ≃ₘ^n⟮I, I'⟯ M') C^n⟮I, M; I', M'⟯ := ⟨λ Φ, ⟨Φ, Φ.times_cont_mdiff_to_fun⟩⟩
@[continuity] protected lemma continuous (h : M ≃ₘ^n⟮I, I'⟯ M') : continuous h :=
h.times_cont_mdiff_to_fun.continuous
protected lemma times_cont_mdiff (h : M ≃ₘ^n⟮I, I'⟯ M') : times_cont_mdiff I I' n h :=
h.times_cont_mdiff_to_fun
protected lemma times_cont_mdiff_at (h : M ≃ₘ^n⟮I, I'⟯ M') {x} : times_cont_mdiff_at I I' n h x :=
h.times_cont_mdiff.times_cont_mdiff_at
protected lemma times_cont_mdiff_within_at (h : M ≃ₘ^n⟮I, I'⟯ M') {s x} :
times_cont_mdiff_within_at I I' n h s x :=
h.times_cont_mdiff_at.times_cont_mdiff_within_at
protected lemma times_cont_diff (h : E ≃ₘ^n[𝕜] E') : times_cont_diff 𝕜 n h :=
h.times_cont_mdiff.times_cont_diff
protected lemma smooth (h : M ≃ₘ⟮I, I'⟯ M') : smooth I I' h := h.times_cont_mdiff_to_fun
protected lemma mdifferentiable (h : M ≃ₘ^n⟮I, I'⟯ M') (hn : 1 ≤ n) : mdifferentiable I I' h :=
h.times_cont_mdiff.mdifferentiable hn
protected lemma mdifferentiable_on (h : M ≃ₘ^n⟮I, I'⟯ M') (s : set M) (hn : 1 ≤ n) :
mdifferentiable_on I I' h s :=
(h.mdifferentiable hn).mdifferentiable_on
@[simp] lemma coe_to_equiv (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑h.to_equiv = h := rfl
@[simp, norm_cast] lemma coe_coe (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑(h : C^n⟮I, M; I', M'⟯) = h := rfl
lemma to_equiv_injective : injective (diffeomorph.to_equiv : (M ≃ₘ^n⟮I, I'⟯ M') → (M ≃ M'))
| ⟨e, _, _⟩ ⟨e', _, _⟩ rfl := rfl
@[simp] lemma to_equiv_inj {h h' : M ≃ₘ^n⟮I, I'⟯ M'} : h.to_equiv = h'.to_equiv ↔ h = h' :=
to_equiv_injective.eq_iff
/-- Coercion to function `λ h : M ≃ₘ^n⟮I, I'⟯ M', (h : M → M')` is injective. -/
lemma coe_fn_injective : injective (λ (h : M ≃ₘ^n⟮I, I'⟯ M') (x : M), h x) :=
equiv.coe_fn_injective.comp to_equiv_injective
@[ext] lemma ext {h h' : M ≃ₘ^n⟮I, I'⟯ M'} (Heq : ∀ x, h x = h' x) : h = h' :=
coe_fn_injective $ funext Heq
section
variables (M I n)
/-- Identity map as a diffeomorphism. -/
protected def refl : M ≃ₘ^n⟮I, I⟯ M :=
{ times_cont_mdiff_to_fun := times_cont_mdiff_id,
times_cont_mdiff_inv_fun := times_cont_mdiff_id,
to_equiv := equiv.refl M }
@[simp] lemma refl_to_equiv : (diffeomorph.refl I M n).to_equiv = equiv.refl _ := rfl
@[simp] lemma coe_refl : ⇑(diffeomorph.refl I M n) = id := rfl
end
/-- Composition of two diffeomorphisms. -/
protected def trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) :
M ≃ₘ^n⟮I, J⟯ N :=
{ times_cont_mdiff_to_fun := h₂.times_cont_mdiff_to_fun.comp h₁.times_cont_mdiff_to_fun,
times_cont_mdiff_inv_fun := h₁.times_cont_mdiff_inv_fun.comp h₂.times_cont_mdiff_inv_fun,
to_equiv := h₁.to_equiv.trans h₂.to_equiv }
@[simp] lemma trans_refl (h : M ≃ₘ^n⟮I, I'⟯ M') : h.trans (diffeomorph.refl I' M' n) = h :=
ext $ λ _, rfl
@[simp] lemma refl_trans (h : M ≃ₘ^n⟮I, I'⟯ M') : (diffeomorph.refl I M n).trans h = h :=
ext $ λ _, rfl
@[simp] lemma coe_trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) :
⇑(h₁.trans h₂) = h₂ ∘ h₁ := rfl
/-- Inverse of a diffeomorphism. -/
protected def symm (h : M ≃ₘ^n⟮I, J⟯ N) : N ≃ₘ^n⟮J, I⟯ M :=
{ times_cont_mdiff_to_fun := h.times_cont_mdiff_inv_fun,
times_cont_mdiff_inv_fun := h.times_cont_mdiff_to_fun,
to_equiv := h.to_equiv.symm }
@[simp] lemma apply_symm_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : N) : h (h.symm x) = x :=
h.to_equiv.apply_symm_apply x
@[simp] lemma symm_apply_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : M) : h.symm (h x) = x :=
h.to_equiv.symm_apply_apply x
@[simp] lemma symm_refl : (diffeomorph.refl I M n).symm = diffeomorph.refl I M n :=
ext $ λ _, rfl
@[simp] lemma trans_symm (h : M ≃ₘ^n⟮I, J⟯ N) : h.trans h.symm = diffeomorph.refl I M n :=
ext h.symm_apply_apply
@[simp] lemma symm_trans (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.trans h = diffeomorph.refl J N n :=
ext h.apply_symm_apply
@[simp] lemma symm_trans' (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) :
(h₁.trans h₂).symm = h₂.symm.trans h₁.symm := rfl
@[simp] lemma symm_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.to_equiv = h.to_equiv.symm := rfl
@[simp, mfld_simps] lemma to_equiv_coe_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_equiv.symm = h.symm := rfl
lemma image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h '' s = h.symm ⁻¹' s :=
h.to_equiv.image_eq_preimage s
lemma symm_image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h.symm '' s = h ⁻¹' s :=
h.symm.image_eq_preimage s
@[simp, mfld_simps] lemma range_comp {α} (h : M ≃ₘ^n⟮I, J⟯ N) (f : α → M) :
range (h ∘ f) = h.symm ⁻¹' (range f) :=
by rw [range_comp, image_eq_preimage]
@[simp] lemma image_symm_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h '' (h.symm '' s) = s :=
h.to_equiv.image_symm_image s
@[simp] lemma symm_image_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h.symm '' (h '' s) = s :=
h.to_equiv.symm_image_image s
/-- A diffeomorphism is a homeomorphism. -/
def to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : M ≃ₜ N :=
⟨h.to_equiv, h.continuous, h.symm.continuous⟩
@[simp] lemma to_homeomorph_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) :
h.to_homeomorph.to_equiv = h.to_equiv :=
rfl
@[simp] lemma symm_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) :
h.symm.to_homeomorph = h.to_homeomorph.symm :=
rfl
@[simp] lemma coe_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_homeomorph = h := rfl
@[simp] lemma coe_to_homeomorph_symm (h : M ≃ₘ^n⟮I, J⟯ N) :
⇑h.to_homeomorph.symm = h.symm := rfl
@[simp] lemma times_cont_mdiff_within_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'}
{s x} (hm : m ≤ n) :
times_cont_mdiff_within_at I I' m (f ∘ h) s x ↔
times_cont_mdiff_within_at J I' m f (h.symm ⁻¹' s) (h x) :=
begin
split,
{ intro Hfh,
rw [← h.symm_apply_apply x] at Hfh,
simpa only [(∘), h.apply_symm_apply]
using Hfh.comp (h x) (h.symm.times_cont_mdiff_within_at.of_le hm) (maps_to_preimage _ _) },
{ rw ← h.image_eq_preimage,
exact λ hf, hf.comp x (h.times_cont_mdiff_within_at.of_le hm) (maps_to_image _ _) }
end
@[simp] lemma times_cont_mdiff_on_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'}
{s} (hm : m ≤ n) :
times_cont_mdiff_on I I' m (f ∘ h) s ↔ times_cont_mdiff_on J I' m f (h.symm ⁻¹' s) :=
h.to_equiv.forall_congr $ λ x, by simp only [hm, coe_to_equiv, symm_apply_apply,
times_cont_mdiff_within_at_comp_diffeomorph_iff, mem_preimage]
@[simp] lemma times_cont_mdiff_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {x}
(hm : m ≤ n) :
times_cont_mdiff_at I I' m (f ∘ h) x ↔ times_cont_mdiff_at J I' m f (h x) :=
h.times_cont_mdiff_within_at_comp_diffeomorph_iff hm
@[simp] lemma times_cont_mdiff_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'}
(hm : m ≤ n) :
times_cont_mdiff I I' m (f ∘ h) ↔ times_cont_mdiff J I' m f :=
h.to_equiv.forall_congr $ λ x, (h.times_cont_mdiff_at_comp_diffeomorph_iff hm)
@[simp] lemma times_cont_mdiff_within_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) {s x} :
times_cont_mdiff_within_at I' J m (h ∘ f) s x ↔ times_cont_mdiff_within_at I' I m f s x :=
⟨λ Hhf, by simpa only [(∘), h.symm_apply_apply]
using (h.symm.times_cont_mdiff_at.of_le hm).comp_times_cont_mdiff_within_at _ Hhf,
λ Hf, (h.times_cont_mdiff_at.of_le hm).comp_times_cont_mdiff_within_at _ Hf⟩
@[simp] lemma times_cont_mdiff_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) {x} :
times_cont_mdiff_at I' J m (h ∘ f) x ↔ times_cont_mdiff_at I' I m f x :=
h.times_cont_mdiff_within_at_diffeomorph_comp_iff hm
@[simp] lemma times_cont_mdiff_on_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) {s} :
times_cont_mdiff_on I' J m (h ∘ f) s ↔ times_cont_mdiff_on I' I m f s :=
forall_congr $ λ x, forall_congr $ λ hx, h.times_cont_mdiff_within_at_diffeomorph_comp_iff hm
@[simp] lemma times_cont_mdiff_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) :
times_cont_mdiff I' J m (h ∘ f) ↔ times_cont_mdiff I' I m f :=
forall_congr $ λ x, h.times_cont_mdiff_within_at_diffeomorph_comp_iff hm
lemma to_local_homeomorph_mdifferentiable (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) :
h.to_homeomorph.to_local_homeomorph.mdifferentiable I J :=
⟨h.mdifferentiable_on _ hn, h.symm.mdifferentiable_on _ hn⟩
variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners J N]
lemma unique_mdiff_on_image_aux (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n)
{s : set M} (hs : unique_mdiff_on I s) :
unique_mdiff_on J (h '' s) :=
begin
convert hs.unique_mdiff_on_preimage (h.to_local_homeomorph_mdifferentiable hn),
simp [h.image_eq_preimage]
end
@[simp] lemma unique_mdiff_on_image (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set M} :
unique_mdiff_on J (h '' s) ↔ unique_mdiff_on I s :=
⟨λ hs, h.symm_image_image s ▸ h.symm.unique_mdiff_on_image_aux hn hs,
h.unique_mdiff_on_image_aux hn⟩
@[simp] lemma unique_mdiff_on_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set N} :
unique_mdiff_on I (h ⁻¹' s) ↔ unique_mdiff_on J s :=
h.symm_image_eq_preimage s ▸ h.symm.unique_mdiff_on_image hn
@[simp] lemma unique_diff_on_image (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set E} :
unique_diff_on 𝕜 (h '' s) ↔ unique_diff_on 𝕜 s :=
by simp only [← unique_mdiff_on_iff_unique_diff_on, unique_mdiff_on_image, hn]
@[simp] lemma unique_diff_on_preimage (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set F} :
unique_diff_on 𝕜 (h ⁻¹' s) ↔ unique_diff_on 𝕜 s :=
h.symm_image_eq_preimage s ▸ h.symm.unique_diff_on_image hn
end diffeomorph
namespace continuous_linear_equiv
variable (e : E ≃L[𝕜] E')
/-- A continuous linear equivalence between normed spaces is a diffeomorphism. -/
def to_diffeomorph : E ≃ₘ[𝕜] E' :=
{ times_cont_mdiff_to_fun := e.times_cont_diff.times_cont_mdiff,
times_cont_mdiff_inv_fun := e.symm.times_cont_diff.times_cont_mdiff,
to_equiv := e.to_linear_equiv.to_equiv }
@[simp] lemma coe_to_diffeomorph : ⇑e.to_diffeomorph = e := rfl
@[simp] lemma symm_to_diffeomorph : e.symm.to_diffeomorph = e.to_diffeomorph.symm := rfl
@[simp] lemma coe_to_diffeomorph_symm : ⇑e.to_diffeomorph.symm = e.symm := rfl
end continuous_linear_equiv
namespace model_with_corners
variables (I) (e : E ≃ₘ[𝕜] E')
/-- Apply a diffeomorphism (e.g., a continuous linear equivalence) to the model vector space. -/
def trans_diffeomorph (I : model_with_corners 𝕜 E H) (e : E ≃ₘ[𝕜] E') :
model_with_corners 𝕜 E' H :=
{ to_local_equiv := I.to_local_equiv.trans e.to_equiv.to_local_equiv,
source_eq := by simp,
unique_diff' := by simp [range_comp e, I.unique_diff],
continuous_to_fun := e.continuous.comp I.continuous,
continuous_inv_fun := I.continuous_symm.comp e.symm.continuous }
@[simp, mfld_simps] lemma coe_trans_diffeomorph : ⇑(I.trans_diffeomorph e) = e ∘ I := rfl
@[simp, mfld_simps] lemma coe_trans_diffeomorph_symm :
⇑(I.trans_diffeomorph e).symm = I.symm ∘ e.symm := rfl
lemma trans_diffeomorph_range : range (I.trans_diffeomorph e) = e '' (range I) :=
range_comp e I
lemma coe_ext_chart_at_trans_diffeomorph (x : M) :
⇑(ext_chart_at (I.trans_diffeomorph e) x) = e ∘ ext_chart_at I x := rfl
lemma coe_ext_chart_at_trans_diffeomorph_symm (x : M) :
⇑(ext_chart_at (I.trans_diffeomorph e) x).symm = (ext_chart_at I x).symm ∘ e.symm := rfl
lemma ext_chart_at_trans_diffeomorph_target (x : M) :
(ext_chart_at (I.trans_diffeomorph e) x).target = e.symm ⁻¹' (ext_chart_at I x).target :=
by simp only [range_comp e, e.image_eq_preimage, preimage_preimage] with mfld_simps
end model_with_corners
namespace diffeomorph
variables (e : E ≃ₘ[𝕜] F)
instance smooth_manifold_with_corners_trans_diffeomorph [smooth_manifold_with_corners I M] :
smooth_manifold_with_corners (I.trans_diffeomorph e) M :=
begin
refine smooth_manifold_with_corners_of_times_cont_diff_on _ _ (λ e₁ e₂ h₁ h₂, _),
refine e.times_cont_diff.comp_times_cont_diff_on
(((times_cont_diff_groupoid ⊤ I).compatible h₁ h₂).1.comp
e.symm.times_cont_diff.times_cont_diff_on _),
mfld_set_tac
end
variables (I M)
/-- The identity diffeomorphism between a manifold with model `I` and the same manifold
with model `I.trans_diffeomorph e`. -/
def to_trans_diffeomorph (e : E ≃ₘ[𝕜] F) : M ≃ₘ⟮I, I.trans_diffeomorph e⟯ M :=
{ to_equiv := equiv.refl M,
times_cont_mdiff_to_fun := λ x,
begin
refine times_cont_mdiff_within_at_iff.2 ⟨continuous_within_at_id, _⟩,
refine e.times_cont_diff.times_cont_diff_within_at.congr' (λ y hy, _) _,
{ simp only [equiv.coe_refl, id, (∘), I.coe_ext_chart_at_trans_diffeomorph,
(ext_chart_at I x).right_inv hy.1] },
exact ⟨(ext_chart_at I x).map_source (mem_ext_chart_source I x), trivial,
by simp only with mfld_simps⟩
end,
times_cont_mdiff_inv_fun := λ x,
begin
refine times_cont_mdiff_within_at_iff.2 ⟨continuous_within_at_id, _⟩,
refine e.symm.times_cont_diff.times_cont_diff_within_at.congr' (λ y hy, _) _,
{ simp only [mem_inter_eq, I.ext_chart_at_trans_diffeomorph_target] at hy,
simp only [equiv.coe_refl, equiv.refl_symm, id, (∘),
I.coe_ext_chart_at_trans_diffeomorph_symm, (ext_chart_at I x).right_inv hy.1] },
exact ⟨(ext_chart_at _ x).map_source (mem_ext_chart_source _ x), trivial,
by simp only [e.symm_apply_apply, equiv.refl_symm, equiv.coe_refl] with mfld_simps⟩
end }
variables {I M}
@[simp] lemma times_cont_mdiff_within_at_trans_diffeomorph_right {f : M' → M} {x s} :
times_cont_mdiff_within_at I' (I.trans_diffeomorph e) n f s x ↔
times_cont_mdiff_within_at I' I n f s x :=
(to_trans_diffeomorph I M e).times_cont_mdiff_within_at_diffeomorph_comp_iff le_top
@[simp] lemma times_cont_mdiff_at_trans_diffeomorph_right {f : M' → M} {x} :
times_cont_mdiff_at I' (I.trans_diffeomorph e) n f x ↔ times_cont_mdiff_at I' I n f x :=
(to_trans_diffeomorph I M e).times_cont_mdiff_at_diffeomorph_comp_iff le_top
@[simp] lemma times_cont_mdiff_on_trans_diffeomorph_right {f : M' → M} {s} :
times_cont_mdiff_on I' (I.trans_diffeomorph e) n f s ↔ times_cont_mdiff_on I' I n f s :=
(to_trans_diffeomorph I M e).times_cont_mdiff_on_diffeomorph_comp_iff le_top
@[simp] lemma times_cont_mdiff_trans_diffeomorph_right {f : M' → M} :
times_cont_mdiff I' (I.trans_diffeomorph e) n f ↔ times_cont_mdiff I' I n f :=
(to_trans_diffeomorph I M e).times_cont_mdiff_diffeomorph_comp_iff le_top
@[simp] lemma smooth_trans_diffeomorph_right {f : M' → M} :
smooth I' (I.trans_diffeomorph e) f ↔ smooth I' I f :=
times_cont_mdiff_trans_diffeomorph_right e
@[simp] lemma times_cont_mdiff_within_at_trans_diffeomorph_left {f : M → M'} {x s} :
times_cont_mdiff_within_at (I.trans_diffeomorph e) I' n f s x ↔
times_cont_mdiff_within_at I I' n f s x :=
((to_trans_diffeomorph I M e).times_cont_mdiff_within_at_comp_diffeomorph_iff le_top).symm
@[simp] lemma times_cont_mdiff_at_trans_diffeomorph_left {f : M → M'} {x} :
times_cont_mdiff_at (I.trans_diffeomorph e) I' n f x ↔ times_cont_mdiff_at I I' n f x :=
((to_trans_diffeomorph I M e).times_cont_mdiff_at_comp_diffeomorph_iff le_top).symm
@[simp] lemma times_cont_mdiff_on_trans_diffeomorph_left {f : M → M'} {s} :
times_cont_mdiff_on (I.trans_diffeomorph e) I' n f s ↔ times_cont_mdiff_on I I' n f s :=
((to_trans_diffeomorph I M e).times_cont_mdiff_on_comp_diffeomorph_iff le_top).symm
@[simp] lemma times_cont_mdiff_trans_diffeomorph_left {f : M → M'} :
times_cont_mdiff (I.trans_diffeomorph e) I' n f ↔ times_cont_mdiff I I' n f :=
((to_trans_diffeomorph I M e).times_cont_mdiff_comp_diffeomorph_iff le_top).symm
@[simp] lemma smooth_trans_diffeomorph_left {f : M → M'} :
smooth (I.trans_diffeomorph e) I' f ↔ smooth I I' f :=
e.times_cont_mdiff_trans_diffeomorph_left
end diffeomorph
|
(* Contribution to the Coq Library V6.3 (July 1999) *)
(****************************************************************************)
(* This contribution was updated for Coq V5.10 by the COQ workgroup. *)
(* January 1995 *)
(****************************************************************************)
(* ps.v *)
(****************************************************************************)
Require Import Classical.
Require Import Ensembles.
Require Import Relations_1.
Require Import Relations_1_facts.
Require Import podefs.
Require Import podefs_1.
Section The_power_set_partial_order.
Variable U : Type.
Inductive Power_set (A : Ensemble U) : Ensemble (Ensemble U) :=
Definition_of_Power_set :
forall X : Ensemble U,
Included U X A -> In (Ensemble U) (Power_set A) X.
Hint Resolve Definition_of_Power_set.
(* Consider a set A, and its powerset P *)
Variable A : Ensemble U.
Theorem Empty_set_minimal :
forall X : Ensemble U, Included U (Empty_set U) X.
Proof.
red in |- *; intros X x H'; elim H'.
Qed.
Hint Resolve Empty_set_minimal.
Theorem Power_set_non_empty :
forall A : Ensemble U, Non_empty (Ensemble U) (Power_set A).
Proof.
intro A'; apply Non_empty_intro with (Empty_set U); auto.
Qed.
Hint Resolve Power_set_non_empty.
Theorem Inclusion_is_an_order : Order (Ensemble U) (Included U).
Proof.
auto 8.
Qed.
Hint Resolve Inclusion_is_an_order.
Theorem Inclusion_is_transitive : Transitive (Ensemble U) (Included U).
elim Inclusion_is_an_order; auto.
Qed.
Hint Resolve Inclusion_is_transitive.
Theorem Same_set_equivalence : Equivalence (Ensemble U) (Same_set U).
Proof.
generalize (Equiv_from_order (Ensemble U) (Included U)); intro H'; elim H';
auto.
Qed.
Theorem Same_set_reflexive : Reflexive (Ensemble U) (Same_set U).
Proof.
elim Same_set_equivalence; auto.
Qed.
Hint Resolve Same_set_reflexive.
Theorem Power_set_PO : PO (Ensemble U).
Proof.
apply Definition_of_PO with (Power_set A) (Included U); auto.
Defined.
Theorem Union_minimal :
forall a b X : Ensemble U,
Included U a X -> Included U b X -> Included U (Union U a b) X.
Proof.
intros a b X H' H'0; red in |- *; (intros x H'1; elim H'1); auto.
Qed.
Hint Resolve Union_minimal.
Theorem Intersection_maximal :
forall a b X : Ensemble U,
Included U X a -> Included U X b -> Included U X (Intersection U a b).
Proof.
auto.
Qed.
Theorem Union_increases_l :
forall a b : Ensemble U, Included U a (Union U a b).
Proof.
auto.
Qed.
Theorem Union_increases_r :
forall a b : Ensemble U, Included U b (Union U a b).
Proof.
auto.
Qed.
Theorem Intersection_decreases_l :
forall a b : Ensemble U, Included U (Intersection U a b) a.
Proof.
intros a b; red in |- *; auto.
intros x H'; elim H'; auto.
Qed.
Theorem Intersection_decreases_r :
forall a b : Ensemble U, Included U (Intersection U a b) b.
Proof.
intros a b; red in |- *; auto.
intros x H'; elim H'; auto.
Qed.
Hint Resolve Union_increases_l Union_increases_r Intersection_decreases_l
Intersection_decreases_r.
Theorem Empty_set_is_Bottom :
Bottom (Ensemble U) Power_set_PO (Empty_set U).
Proof.
apply Bottom_definition; simpl in |- *; auto.
Qed.
Hint Resolve Empty_set_is_Bottom.
Theorem Union_is_Lub :
forall a b : Ensemble U,
Included U a A ->
Included U b A ->
Lub (Ensemble U) Power_set_PO (Couple (Ensemble U) a b) (Union U a b).
Proof.
intros a b H' H'0.
apply Lub_definition; simpl in |- *.
apply Upper_Bound_definition; simpl in |- *.
auto.
intros y H'1; elim H'1; auto.
intros y H'1; elim H'1; simpl in |- *; auto.
Qed.
Theorem Intersection_is_Glb :
forall a b : Ensemble U,
Included U a A ->
Included U b A ->
Glb (Ensemble U) Power_set_PO (Couple (Ensemble U) a b)
(Intersection U a b).
Proof.
intros a b H' H'0.
apply Glb_definition.
apply Lower_Bound_definition; simpl in |- *.
apply Definition_of_Power_set; auto.
generalize Inclusion_is_transitive; intro IT; red in IT; apply IT with a;
auto.
intros y H'1; elim H'1; auto.
intros y H'1; elim H'1; simpl in |- *; auto.
Qed.
Theorem Empty_set_zero :
forall X : Ensemble U, Union U (Empty_set U) X = X.
Proof.
auto 10.
Qed.
Theorem Union_commutative :
forall A B : Ensemble U, Union U A B = Union U B A.
Proof.
auto.
Qed.
Theorem Union_associative :
forall A B C : Ensemble U,
Union U (Union U A B) C = Union U A (Union U B C).
Proof.
auto 20.
Qed.
Theorem Non_disjoint_union :
forall (X : Ensemble U) (x : U),
In U X x -> Union U (Singleton U x) X = X.
Proof.
intros X x H'; try assumption; auto 10.
apply Extensionality_Ensembles; unfold Same_set in |- *; split;
auto.
red in |- *; auto 10.
intros x0 H'0; elim H'0; auto 10.
intros x1 H'1; elim H'1; auto 10.
Qed.
Theorem Finite_plus_one_is_finite :
forall (X : Ensemble U) (x : U),
Finite U X -> Finite U (Union U (Singleton U x) X).
Proof.
intros X x H'.
generalize (classic (In U X x)); intro h; elim h;
[ intro H'0; clear h; try exact H'0 | clear h; intro H'0 ];
auto 10.
generalize (Non_disjoint_union X x); intro h; lapply h;
[ intro H'1; rewrite H'1; clear h | clear h ];
auto.
Qed.
Hint Resolve Finite_plus_one_is_finite.
Theorem Singleton_is_finite : forall x : U, Finite U (Singleton U x).
Proof.
intro x; generalize (Empty_set_zero (Singleton U x)); intro h;
rewrite <- h; clear h.
generalize (Union_commutative (Empty_set U) (Singleton U x)); intro h;
rewrite h; clear h; auto.
Qed.
Hint Resolve Singleton_is_finite.
Theorem Union_of_finite_is_finite :
forall X Y : Ensemble U,
Finite U X -> Finite U Y -> Finite U (Union U X Y).
Proof.
intros X Y H'; elim H'.
generalize (Empty_set_zero Y); intro h; rewrite h; clear h; auto.
clear A.
intros AA H'0 H'1 x H'2 H'3.
generalize (Union_associative (Singleton U x) AA Y); intro h; rewrite h;
clear h; auto.
Qed.
End The_power_set_partial_order.
Hint Resolve Empty_set_minimal.
Hint Resolve Power_set_non_empty.
Hint Resolve Inclusion_is_an_order.
Hint Resolve Inclusion_is_transitive.
Hint Resolve Same_set_reflexive.
Hint Resolve Union_minimal.
Hint Resolve Same_set_reflexive.
Hint Resolve Union_increases_l.
Hint Resolve Union_increases_r.
Hint Resolve Intersection_decreases_l.
Hint Resolve Intersection_decreases_r.
Hint Resolve Empty_set_is_Bottom.
Hint Resolve Empty_set_zero.
Hint Resolve Finite_plus_one_is_finite.
Hint Resolve Singleton_is_finite.
|
'''
Team 4: "SDRP Decisions"
Lee Jia Juinn, Kenji
Sung Yu Xin
Lim Wei Zhen
'''
import pandas as pd
import statsmodels.formula.api as smf
#LOAD DATA
df = pd.read_csv(r'https://tinyurl.com/SDRP-AI-SUBMISSION')
#df = df.iloc[0:33,1:63]
#Recalibration of Certain Data for categorical
df.Panelist[df.Panelist == 'Jim Lim'] = '1Jim Lim'
df.Country_of_Respondent[df.Country_of_Respondent == 'Singapore'] = '1Singapore'
df.Country_of_Complainant[df.Country_of_Complainant == 'Singapore'] = '1Singapore'
#Data Processing - Categorizing Variables which are categorical
df['Usage_of_Domain_name'] = df['Usage_of_Domain_name'].astype('category')
df['Panelist_Type'] = df['Panelist_Type'].astype('category')
df['Country_of_Respondent'] = df['Country_of_Respondent'].astype('category')
df['Country_of_Complainant'] = df['Country_of_Complainant'].astype('category')
df['Industry_Complainant'] = df['Industry_Complainant'].astype('category')
df['Industry_Registrant'] = df['Industry_Registrant'].astype('category')
df['Panelist'] = df['Panelist'].astype('category')
df['Year_of_Judgment'] = df['Year_of_Judgment'].astype('category')
print df['Country_of_Respondent']
#Creating the List of Data concerning Transfer of Domain Names (to be used in modelling below)
actual = df['Conclusion']
actual = actual.tolist()
#Creating the Function to Print: True and False Positives and Negatives, Accuracy, Precision, Recall, F1
#A GENERAL FUNCTION (to calculate Accuracy, Precision, Recall and F1)
'''
Let:
tp = N.o of True Positives
tn = N.o of True Negatives
fp = N.o of False Positives
fn = N.o of False Negatives
y_hat = predicted results
y = actual results
'''
def function(y_hat, y):
tp = 0
fp = 0
tn = 0
fn = 0
# To Count the Number of True Positives and True Negatives:
# Defensive Programming - to ward against errors
if len(y_hat) != len(y):
return None # If the length of both are different, there must have been an error somewhere.
else:
#Count number of true positives
for n in range(len(y)):
if y_hat[n] > 0.5 and y[n] == 1:
tp += 1
#Count number of false positives
for n in range(len(y)):
if y_hat[n] > 0.5 and y[n] == 0:
fp += 1
#Count number of true negatives:
for i in range(len(y)):
if y_hat[i] < 0.5 and y[i] == 0:
tn += 1
#Count number of false negatives:
for i in range(len(y)):
if y_hat[i] < 0.5 and y[i] == 1:
fn += 1
print "The number of true positives is " + str(tp)
print "The number of true negatives is " + str(tn)
print "The number of false positives is " + str(fp)
print "The number of false negatives is " + str(fn)
# Function to Calculate Accuracy
accuracy = float(tp + tn) / float(len(y_hat))
print "The accuracy is " + str(accuracy)
#Function to Calculate Precision
precision = float(tp) / float((tp+fp))
print "The precision is " + str(precision)
#Function to Calculate Recall
recall = float(tp) / float((tp+fn))
print "The recall is " + str(recall)
#Function to Calculate F1 Score
f1 = 2 * float(precision*recall) / float(precision + recall)
print "The F1 score is " + str(f1)
return " "
#Printing of the Summary of Variables
print "\n" + "SUMMARY"
print df.describe()
print "\n"+"SUMMARY OF ATTRIBUTES"
print "\n"+"LEGEND"
print "\n"+"1 = Yes / Present in Judgment"
print "\n"+"0 = No / Not mentioned in Judgment"
print "\n"+"-1 = No"
print "\n"+"General Attributes"
print "\n"+"Conclusion"
print df['Conclusion'].value_counts()
print "\n"+"Length of Cases (in Months)"
print df['Length_of_Cases_in_months'].value_counts()
print "\n"+"Year of Judgment"
print df['Year_of_Judgment'].value_counts()
print "\n"+"Country of Respondent"
print df['Country_of_Respondent'].value_counts()
print "\n"+"Country of Complainant"
print df['Country_of_Complainant'].value_counts()
print "\n"+"Industry of Complainant"
print df['Industry_Complainant'].value_counts()
print "\n"+"Industry of Respondent"
print df['Industry_Registrant'].value_counts()
print "\n"+"Panelist"
print df['Panelist'].value_counts()
print "\n"+"Panelist Type"
print df['Panelist_Type'].value_counts()
print "\n"+"Was there an Attempt to Settle"
print df['Attempts_to_settle'].value_counts()
print "\n"+"Number of Attempts to Settle"
print df['Number_of_settle_attempts'].value_counts()
print "\n"+"Was there Mediation Prior to this? "
print df['Mediation_prior'].value_counts()
print "\n"+"How many attempts were there to Mediate? "
print df['Mediaiton_Prior_attempts'].value_counts()
print "\n"+"Number of Singaporean cases cited?"
print df['No_Cited_SG_Cases'].value_counts()
print "\n"+"Number of SDRP cases cited?"
print df['No_Cited_SDRP_cases'].value_counts()
print "\n"+"Number of UK and EU cases cited?"
print df['No_Cited_UK_EU_cases'].value_counts()
print "\n"+"Number of US cases cited?"
print df['No_Cited_US_Cases'].value_counts()
print "\n"+"Number of WIPO/UDRP cases cited?"
print df['No_Cited_WIPO_UDRP_cases'].value_counts()
print "\n" + "SUMMARY: Element 1 - Identical / Confusing Similarity"
print "\n"+"Is the word a Made Up Word?"
print df['Made_up_word'].value_counts()
print "\n"+"Is the word an English Word?"
print df['English_word'].value_counts()
print "\n"+"Length of Word?"
print df['Length_of_word'].value_counts()
print "\n"+"Is the Domain a variation of the Complainant's mark or brand?"
print df['Domain_a_variation_of_mark_or_brand'].value_counts()
print "\n"+"Does the Complainant have an existing trade mark?"
print df['Existence_of_Trade_Mark'].value_counts()
print "\n"+"Is the Complainant's trademark registered in Singapore?"
print df['Trade_Mark_Registered_in_Singapore'].value_counts()
print "\n"+"Is the Trademark registered in other Countries?"
print df['Trade_Mark_Registered_in_other_Countries'].value_counts()
print "\n"+"Length the trademark has been registered in Singapore? (in years)"
print df['Length_of_Trade_Mark_SG'].value_counts()
print "\n"+"Is the mark a Well-Known Mark?"
print df['Well_Known_Mark'].value_counts()
print "\n"+"Is the Complainant a foreign brand?"
print df['Foreign_brand'].value_counts()
print "\n"+"Is the Complainant a well-known foreign brand?"
print df['Well_known_Foreign_Brand'].value_counts()
print "\n"+"Are the domain name and Complainant's mark identical or confusingly similar?"
print df['Identical_Confusing_Similarity'].value_counts()
print "\n"+"Are the domain name and Complainant's mark exactly identical?"
print df['Identical_Words'].value_counts()
print "\n"+"Are the domain name and Complainant's mark similar?"
print df['Similar_words'].value_counts()
print "\n"+"What is the % that the words are similar?"
print df['Percentage_of_Similarity_of_Words'].value_counts()
print "\n"+"Are the pronounciation of the words similar?"
print df['Pronounciation_Similarity'].value_counts()
print "\n" + "SUMMARY: Element 2 - Complainant showed Respondent has no legitimate interests in the domain name"
print "\n"+"Has the Complainant showed that the Registrant has no legitimate interests in the domain name?"
print df['Complainant_Showed_Registrant_No_Legitimate_Interests'].value_counts()
print "\n"+"Did the Complainant have prior ownership of the Domain name?"
print df['Complainant_Prior_ownership'].value_counts()
print "\n"+"Did the Respondent show bona fide registration / usage of the domain name?"
print df['Respondent_Showed_Bona_Fide'].value_counts()
print "\n"+"Did the Respondent show that they had used the domain name fairly?"
print df['Respondent_showed_fair_use'].value_counts()
print "\n"+"Did the Respondent show that they are commonly known to a section of the market?"
print df['Respondent_Showed_Commonly_Known'].value_counts()
print "\n"+"Has the Respondent been using the Domain Name?"
print df['Respondent_using_Domain_Name'].value_counts()
print "\n"+"How has the Respondent been using the Domain Name?"
print df['Usage_of_Domain_name'].value_counts()
print "\n"+"* NOTE - Legend" \
"\n" + "0 - Respondent did not use the domain name" \
"\n" + "1 - Respondent used the domain name for sale/rent/advertisements" \
"\n"+"2 - Respondent used the domain name to redirect to another site / their own site's business" \
"\n"+"3 - Respondent had legitimate usage of the domain name"
print "\n"+"Length of Usage of Domain Name?"
print df['Length_of_usage'].value_counts()
print "\n"+"Does the Respondent have localised goodwill attached to its domain name in Singapore?"
print df['Existence_of_localised_goodwill'].value_counts()
print "\n"+"Does the Respondent have localised goodwill attached to its domain name in Singapore?"
print df['Group_of_goodwill'].value_counts()
print "\n"+"Did the Complainant abandon the domain name?"
print df['Abandonment_by_Complainant'].value_counts()
print "\n" + "SUMMARY: Element 3 - Respondent Registered/Used Domain Name in Bad Faith"
print "\n"+"Is there evidence of Circumstances of registration for valuable consideration?"
print df['Evidence_of_Circumstances_of_registration_for_valuable_consideration'].value_counts()
print "\n"+"Is there evidence of registration to prevent Trademark owner usage?"
print df['Evidence_of_Registration_to_prevent_Trademark_owner_usage'].value_counts()
print "\n"+"Is there evidence of registration to disrupt business of Trademark proprietor?"
print df['Evidence_of_registration_to disrupt_business_of_trademark_proprietor'].value_counts()
print "\n"+"Is there evidence of registration to attract customers for commercial gain through likelihood of confusion?"
print df['Evidence_of_Attracting_customers_for_commercial_gain_through_likelihood_of_confusion'].value_counts()
print "\n"+"Is there evidence of bad faith on other grounds?"
print df['Evidence_of_bad_faith_on_other_grounds'].value_counts()
print "\n"+"Did the Respondent attempt to sell the domain name"
print df['Respondent_Attempt_to_sell'].value_counts()
print "\n"+"Did the Respondent respond to the Complainant?"
print df['Did_Respondent_Respond'].value_counts()
print "\n"+"No response from respondent "
print df['No_response_from_respondent'].value_counts()
print "\n"+"Was there a prior commercial relationship between the parties?"
print df['Prior_Commercial_relationship_between_parties'].value_counts()
#Descriptive Analysis
#Descriptive Statistics - Number of Cases over the Years
descriptiveData = df.groupby(['Year_of_Judgment']).size().reset_index(name = "Frequency")
print descriptiveData #While the histogram may be plotted by the Python code itself, it is an active choice to instead use the one inbuilt in KeyNote to plot it out using the data adduced here. The Data in the keynote incldues the settled cases, which is added on manually.
#Descriptive Statistics - Proportion of cases decided in favour of Complainant
descriptiveData = df.groupby(['Conclusion']).size().reset_index(name = "Frequency")
print descriptiveData
#Descriptive Statistics - Default Cases
descriptiveData = df.groupby(['No_response_from_respondent']).size().reset_index(name = "Frequency")
print descriptiveData
#Descriptive Statistics - Number of Precedents Cited by Years
descriptiveData = df.groupby(['Year_of_Judgment', 'No_Cited_SG_Cases']).size().reset_index(name = "Frequency")
print descriptiveData
descriptiveData = df.groupby(['Year_of_Judgment', 'No_Cited_SDRP_cases']).size().reset_index(name = "Frequency")
print descriptiveData
descriptiveData = df.groupby(['Year_of_Judgment', 'No_Cited_UK_EU_cases']).size().reset_index(name = "Frequency")
print descriptiveData
descriptiveData = df.groupby(['Year_of_Judgment', 'No_Cited_US_Cases']).size().reset_index(name = "Frequency")
print descriptiveData
descriptiveData = df.groupby(['Year_of_Judgment', 'No_Cited_WIPO_UDRP_cases']).size().reset_index(name = "Frequency")
print descriptiveData
#These data were then used to divide by the cases each year to obtain the Number of Precedents Cited Per Case
#MODELS
'''
In this section we seek to come up with linear and logistic models of our data.
We decided on the following naming systems:
sm stands for sub-model
gm stands for general-model
so the models would be named as such: e.g. sm1_linear means the linear sub-model for the first element
'''
#SUB-MODEL 1: IDENTICAL/CONFUSING SIMILARITY
print "SUB-MODEL 1: Identical / Confusing Similarity"
#Linear Model
print "SUB-MODEL 1: Identical / Confusing Similarity (LINEAR)"
sm1_linear = smf.ols(formula = 'Identical_Confusing_Similarity ~ Length_of_word + English_word+Trade_Mark_Registered_in_Singapore + Trade_Mark_Registered_in_other_Countries + Well_Known_Mark', data = df).fit()
print sm1_linear.summary()
predictedValue = sm1_linear.predict()
predictedValue = predictedValue.tolist()
print function(predictedValue,actual)
#Logit Model
print "SUB-MODEL 1: Identical / Confusing Similarity (LOGIT)"
sm1_log = smf.logit(formula = 'Conclusion ~ Length_of_word + English_word+Trade_Mark_Registered_in_Singapore + Well_Known_Mark', data = df).fit()
print sm1_log.summary()
predictedValue = sm1_log.predict()
predictedValue = predictedValue.tolist()
print function(predictedValue,actual)
#SUB-MODEL 2: Complainant has shown that Respondent has no Legitimate Interest
print "SUB-MODEL 2: Complainant has shown that Respondent has no Legitimate Interests"
#Linear Model
print "SUB-MODEL 2: Complainant has shown that Respondent has no Legitimate Interests (LINEAR)"
sm2_linear = smf.ols(formula = 'Complainant_Showed_Registrant_No_Legitimate_Interests ~ Respondent_Showed_Bona_Fide + Respondent_showed_fair_use + Usage_of_Domain_name', data = df).fit()
print sm2_linear.summary()
predictedValue = sm2_linear.predict()
predictedValue = predictedValue.tolist()
print function(predictedValue,actual)
#Logit Model
print "SUB-MODEL 2: Complainant has shown that Respondent has no Legitimate Interests (LOGIT)"
#Recalibrate data to make it binomial / only have 2 values instead of the original 3/4 values
'''
df['Complainant_Showed_Registrant_No_Legitimate_Interests'] = df["Complainant_Showed_Registrant_No_Legitimate_Interests"].map({-1:0, 0:0, 1:1})
df['Respondent_Showed_Bona_Fide'] = df["Respondent_Showed_Bona_Fide"].map({-1:0, 0:1, 1:1})
df['Respondent_showed_fair_use'] = df["Respondent_showed_fair_use"].map({-1:0, 0:1, 1:1})
df['Usage_of_Domain_name'] = df["Usage_of_Domain_name"].map({0:1, 1:0, 2:0, 3:1})
This mapping is no longer required given that the model was not helpful
#we tried the following logit model, which ran into errors. another model we tried also encountered a low pseudo R and very high P values that were close to 1. Thus we conclude that a logistic model is not appropriate for the data set for this second element of proving that the Complainant has no legitimate interests.
sm2_log = smf.logit(formula = 'Complainant_Showed_Registrant_No_Legitimate_Interests ~ Respondent_Showed_Bona_Fide + Respondent_showed_fair_use + Usage_of_Domain_name + Complainant_Prior_ownership', data = df).fit()
print sm2_log.summary()
predictedValue = sm2_log.predict(df)
predictedValue = predictedValue.tolist()
print function(predictedValue,actual)
'''
print "SUB-MODEL 3: Respondent registered or used the domain name in bad faith"
#Linear Model
print "SUB-MODEL 3: Respondent registered or used the domain name in bad faith (LINEAR)"
sm3_linear = smf.ols(formula='Conclusion ~ No_response_from_respondent+Evidence_of_Attracting_customers_for_commercial_gain_through_likelihood_of_confusion+Evidence_of_bad_faith_on_other_grounds+Respondent_Attempt_to_sell', data=df).fit()
predictedValue = sm3_linear.predict(df)
predictedValue = predictedValue.tolist()
print sm3_linear.summary()
print function(predictedValue,actual)
#Logit Model
print "SUB-MODEL 3: Respondent registered or used the domain name in bad faith (LOGIT)"
sm3_log = smf.ols(formula='Conclusion ~ No_response_from_respondent+Evidence_of_Attracting_customers_for_commercial_gain_through_likelihood_of_confusion+Evidence_of_bad_faith_on_other_grounds+Respondent_Attempt_to_sell', data=df).fit()
predictedValue = sm3_log.predict(df)
predictedValue = predictedValue.tolist()
print sm3_log.summary()
print function(predictedValue,actual)
print "GENERAL MODEL:"
#Model A: Conclusion ~ General Variables
#1 Panelists
gmA1_linear = smf.ols(formula='Conclusion ~ Panelist',data=df).fit()
print gmA1_linear.summary()
predictedValue = gmA1_linear.predict()
predictedValue = predictedValue.tolist()
print function(predictedValue,actual)
#2 Panelist Type
gmA2_linear = smf.ols(formula='Conclusion ~ Panelist_Type',data=df).fit()
print gmA2_linear.summary()
predictedValue = gmA2_linear.predict(df)
predictedValue = predictedValue.tolist()
print function(predictedValue,actual)
#Country of Complainant and Respondent
gmA3_linear = smf.ols(formula='Conclusion ~ Country_of_Respondent + Country_of_Complainant',data=df).fit()
print gmA3_linear.summary()
predictedValue = gmA3_linear.predict()
predictedValue = predictedValue.tolist()
print function(predictedValue,actual)
#General Variables: Attempts to Settle/Mediate
gmA4_linear = smf.ols(formula='Conclusion ~ Attempts_to_settle + Number_of_settle_attempts + Mediation_prior + Mediaiton_Prior_attempts', data=df).fit()
predictedValue = gmA4_linear.predict(df)
predictedValue = predictedValue.tolist()
print gmA4_linear.summary()
print function(predictedValue,actual)
#Log Model of Panelists + Attempts to Settle + Mediation Prior
''' Rationale: different panelists would afford different weight of the parties efforts to settle and mediate'''
gmA1_log = smf.logit(formula='Conclusion ~ Panelist_Type + Attempts_to_settle + Mediation_prior', data=df).fit()
predictedValue =gmA1_log.predict(df)
predictedValue = predictedValue.tolist()
print gmA1_log.summary()
print function(predictedValue, actual)
gmA1_linear = smf.ols(formula='Conclusion ~ Attempts_to_settle + Mediation_prior', data=df).fit()
predictedValue =gmA1_linear.predict(df)
predictedValue = predictedValue.tolist()
print gmA1_linear.summary()
print function(predictedValue, actual)
#Precedents
gmA5_linear = smf.ols(formula = 'Conclusion ~ Country_of_Respondent + Panelist_Type + No_response_from_respondent + No_Cited_WIPO_UDRP_cases + No_Cited_US_Cases + No_Cited_UK_EU_cases + No_Cited_SDRP_cases + No_Cited_SG_Cases', data = df).fit()
predictedValue =gmA5_linear.predict()
predictedValue =predictedValue.tolist()
print gmA5_linear.summary()
print function(predictedValue,actual)
#Model B: Conclusion ~ Attributes from Elements
#Without Dummy Variable
#Variable was phrased as "No response from respondent"
gmB1_linear = smf.ols(formula='Conclusion ~ Trade_Mark_Registered_in_Singapore+ No_response_from_respondent+Well_known_Foreign_Brand+Usage_of_Domain_name+Respondent_Showed_Bona_Fide+Evidence_of_Circumstances_of_registration_for_valuable_consideration+Evidence_of_Attracting_customers_for_commercial_gain_through_likelihood_of_confusion+Evidence_of_bad_faith_on_other_grounds+Respondent_Attempt_to_sell',data=df).fit()
predictedValue =gmB1_linear.predict(df)
predictedValue = predictedValue.tolist()
print gmB1_linear.summary()
print function(predictedValue,actual)
#Variable was phrased as: "Did respondent respond"
gmB2_linear = smf.ols(formula='Conclusion ~ Trade_Mark_Registered_in_Singapore + Did_Respondent_Respond+Well_known_Foreign_Brand+Usage_of_Domain_name+Respondent_Showed_Bona_Fide+Evidence_of_Circumstances_of_registration_for_valuable_consideration+Evidence_of_Attracting_customers_for_commercial_gain_through_likelihood_of_confusion+Evidence_of_bad_faith_on_other_grounds+Respondent_Attempt_to_sell', data=df).fit()
predictedValue =gmB2_linear.predict(df)
predictedValue = predictedValue.tolist()
print gmB2_linear.summary()
print function(predictedValue,actual)
#With Dummy Variables (we added Trade_Mark_Registered_in_Singapore as a control for Well_known_Foreign_Brand)
gmB3_linear = smf.ols(formula='Conclusion ~ No_response_from_respondent + Well_known_Foreign_Brand + Trade_Mark_Registered_in_Singapore + Percentage_of_Similarity_of_Words + Length_of_usage + Evidence_of_Circumstances_of_registration_for_valuable_consideration + Evidence_of_Attracting_customers_for_commercial_gain_through_likelihood_of_confusion + Evidence_of_bad_faith_on_other_grounds + Respondent_Attempt_to_sell',data=df).fit()
predictedValue = gmB3_linear.predict(df)
predictedValue = predictedValue.tolist()
print gmB3_linear.summary()
print function(predictedValue,actual)
#Model C: Conclusion ~ General Variables + Attributes from Elements
gmC1_linear = smf.ols(formula='Conclusion ~ Panelist_Type+Attempts_to_settle + Mediation_prior + No_response_from_respondent+Well_known_Foreign_Brand+Trade_Mark_Registered_in_Singapore+Usage_of_Domain_name+Respondent_Showed_Bona_Fide+Evidence_of_Circumstances_of_registration_for_valuable_consideration+Evidence_of_Attracting_customers_for_commercial_gain_through_likelihood_of_confusion+Evidence_of_bad_faith_on_other_grounds',data=df).fit()
predictedValue = gmC1_linear.predict(df)
predictedValue = predictedValue.tolist()
print gmC1_linear.summary()
print function(predictedValue,actual) |
🦀 = parse.(Int, split(read("input.txt", String), ","))
fuel1, fuel2 = typemax(Int), typemax(Int)
for loc in minimum(🦀):maximum(🦀)
fuel1 = min(fuel1, sum(x -> abs(x - loc), 🦀))
fuel2 = min(fuel2, sum(x -> sum(1:abs(x - loc)), 🦀))
end
@info "Part 1: minimum fuel usage = $fuel1"
@info "Part 2: minimum fuel usage = $fuel2"
|
Fey was born on May 18 , 1970 , in Upper Darby , Pennsylvania , a suburb of Philadelphia . Her mother , Zenobia " Jeanne " ( née <unk> ) , is a brokerage employee ; her father , Donald Henry Fey ( died 2015 , age 82 ) , was a university grant proposal writer . She has a brother , Peter , who is eight years older . Fey 's mother , who was born in Piraeus , Greece , is the daughter of Greek immigrants : <unk> <unk> , Fey 's maternal grandmother , left Petrina , Laconia , Greece on her own , arriving in the United States in February 1921 .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.