text
stringlengths 0
3.34M
|
---|
open classical
variables (Ξ± : Type) (p q : Ξ± β Prop)
variable a : Ξ±
variable r : Prop
example : (β x : Ξ±, r) β r := Ξ» β¨w, hrβ©, hr
example : r β (β x : Ξ±, r) := Ξ» hr, β¨a, hrβ©
example : (β x, p x β§ r) β (β x, p x) β§ r :=
β¨Ξ» β¨w, hpw, hrβ©, β¨β¨w, hpwβ©, hrβ©, Ξ» β¨β¨w, hpwβ©, hrβ©, β¨w, hpw, hrβ©β©
example : (β x, p x β¨ q x) β (β x, p x) β¨ (β x, q x) :=
β¨Ξ» β¨w, hpqwβ©,
hpqw.elim
(Ξ» hpw, or.inl β¨w, hpwβ©)
(Ξ» hqw, or.inr β¨w, hqwβ©),
Ξ» h,
h.elim
(Ξ» β¨w, hpwβ©, β¨w, or.inl hpwβ©)
(Ξ» β¨w, hqwβ©, β¨w, or.inr hqwβ©)β©
example : (β x, p x) β Β¬ (β x, Β¬ p x) :=
β¨Ξ» h β¨w, hnpwβ©, hnpw (h w),
Ξ» hnen x, by_contradiction (Ξ» hnpx, hnen β¨x, hnpxβ©)β©
example : (β x, p x) β Β¬ (β x, Β¬ p x) :=
β¨Ξ» β¨w, hpwβ© h, absurd hpw (h w),
Ξ» hnun, by_contradiction (Ξ» hne, hnun (Ξ» x hpx, hne β¨x, hpxβ©))β©
example : (Β¬ β x, p x) β (β x, Β¬ p x) :=
β¨Ξ» h x hpx, h β¨x, hpxβ©, Ξ» h β¨w, hpwβ©, h w hpwβ©
example : (Β¬ β x, p x) β (β x, Β¬ p x) :=
β¨Ξ» hnu,
by_contradiction
(assume hnen : Β¬ (β x, Β¬ p x),
suffices hu : β x, p x, from hnu hu,
assume x,
by_contradiction
(Ξ» hnpx, hnen β¨x, hnpxβ©)),
Ξ» β¨w, hnpwβ© hu, hnpw (hu w)β©
example : (β x, p x β r) β (β x, p x) β r :=
β¨Ξ» h β¨w, hpwβ©, h w hpw, Ξ» h x hpx, h β¨x, hpxβ©β©
example : (β x, p x β r) β (β x, p x) β r :=
β¨Ξ» β¨w, hpw2rβ© h, hpw2r (h w),
Ξ» h,
by_cases
(assume hu : β x, p x,
β¨a, Ξ» hpa, h huβ©)
(assume hnu : Β¬ β x, p x,
by_contradiction
(assume hne : Β¬ β x, p x β r,
have hu : β x, p x, from
assume x,
by_contradiction
(assume hnpx : Β¬ p x,
hne β¨x, Ξ» hpx, (hnpx hpx).elimβ©),
hnu hu))β©
example : (β x, r β p x) β (r β β x, p x) :=
β¨Ξ» β¨w, hr2pwβ© r, β¨w, hr2pw rβ©,
Ξ» h,
by_cases
(assume hr : r,
match h hr with
β¨w, hpwβ© := β¨w, Ξ» hr, hpwβ©
end)
(assume hnr : Β¬r,
β¨a, Ξ» hr, absurd hr hnrβ©)β©
|
\section{Computational Structure of a Region-Based DFA}
\FloatBarrier
\begin{flushright}
\textit{Scribed by Arpit Saxena}
\end{flushright}
\begin{enumerate}
\item {
Identify transfer function of each region (and sub-region)
\textbf{Bottom-up pass:}
\begin{enumerate}
\item Basic blocks transfer function derived from individual
statement's transfer functions
\item Loop body's transfer function from basic block's transfer
function
\item Loop's from loop body's, \ldots
\end{enumerate}
}
\item {
Compute the dataflow values at each program point by using the summary
transfer functions (for entire regions)
\textbf{Top-down analysis}: Descend down the region hierarchy
for internal points
}
\end{enumerate}
\begin{figure}[H]
\centering
\subfloat[\label{fig:m120:ex1:a}] {{
\tt
\begin{tikzpicture}[->,
node distance = 12mm,
start chain = going below,
box/.style = {draw,rounded corners,fill=white,
on chain,align=center},
unbox/.style = {on chain,align=center},
edge/.style = {midway}]
\coordinate[on chain] (begin);
\node[box] (b1) {
sum = 0\\
Q1 --- \\
i = 0 \\
P1 ---
};
\node[box] (b2) {
P2 --- \\
i < n
};
\node[unbox,below left=of b2] (b3) {exit};
\node[box,below=of b2] (b4) {sum += i \\ i++};
\path[]
(begin) edge (b1)
(b1) edge (b2)
(b2) edge node[edge, left] {F} (b3)
edge node[edge, right] {T} (b4);
\draw (b4.230) -| ++(0.6,-0.3) -| ([xshift=5mm]b2.east) |-
([yshift=3mm]b2.50) -- (b2.50);
\end{tikzpicture}
}}
\subfloat[\label{fig:m120:ex1:b}] {{
\tt
\begin{tikzpicture}[->,
node distance = 12mm,
start chain = going below,
box/.style = {draw,rounded corners,fill=white,
on chain,align=center},
unbox/.style = {on chain,align=center},
edge/.style = {midway}]
\coordinate[on chain] (begin);
\node[box](b1) {sum = 0 \\ i = 0};
\node[box](b2) {loop body \\ region};
\node[unbox](b3) {exit};
\path[]
(begin) edge (b1)
(b1) edge (b2)
(b2) edge (b3);
\draw (b2.230) -| ++(0.6,-0.3) -| ([xshift=5mm]b1.east) |-
([yshift=5mm]b1.50) -- (b1.50);
\end{tikzpicture}
}}
\subfloat[\label{fig:m120:ex1:c}] {{
\tt
\begin{tikzpicture}[->,
node distance = 12mm,
start chain = going below,
box/.style = {draw,rounded corners,fill=white,
on chain,align=center},
unbox/.style = {on chain,align=center},
edge/.style = {midway}]
\coordinate[on chain] (begin);
\node[box](b1) {sum = 0 \\ i = 0};
\node[box](b2) {loop region};
\node[unbox](b3) {exit};
\path[]
(begin) edge (b1)
(b1) edge (b2)
(b2) edge (b3);
\end{tikzpicture}
}}
\subfloat[\label{fig:m120:ex1:d}] {{
\tt
\begin{tikzpicture}[->,
node distance = 12mm,
start chain = going below,
box/.style = {draw,rounded corners,fill=white,
on chain,align=center},
unbox/.style = {on chain,align=center},
edge/.style = {midway}]
\coordinate[on chain] (begin);
\node[box](b1) {Procedure \\ Region};
\node[unbox](exit) {exit};
\path[]
(begin) edge (b1)
(b1) edge (exit);
\end{tikzpicture}
}}
\caption{A Region Hierarchy\\ Note that P1, P2, \ldots\ are program points}
\label{fig:m120:ex1}
\end{figure}
In figure \autoref{fig:m120:ex1:b}, the loop body's transfer function
would be:
{
\centering
\tt
f\textsubscript{b}(m) = m' \\
m'(i) = m(i) + 1 \\
m'(sum) = m(sum) + m(i) \\
}
Based on f\textsubscript{b}, we'll try to create a summary transfer
function for the entire loop.
In figure \autoref{fig:m120:ex1:c}, the loop's transfer function would be
{
\tt
\centering
m\textsuperscript{l} = f\textsubscript{l}(m) \\
m\textsuperscript{l}(i) = max(m(i), n) \\
m\textsuperscript{l}(sum) = m(sum) + $\sum_{j=m(i)}^{n-1} j$ \\
}
Note that if initially $i \geq n$, then the loop is not even entered, which
is the reason for having max in the second equation.
All iterations of the loop have been summarised as a single transfer function
f\textsubscript{l}, and it is a sophisticated symbolic analysis which may not
be possible for every loop. In that case, we have a fallback option of just
executing a basic DFA.
For figure \autoref{fig:m120:ex1:d}, we use the fact that we know at start of loop
region that \texttt{m(i) = 0, m(sum) = 0} and get the following transfer
function
{
\tt
\centering
m\textsuperscript{p} = f\textsubscript{p}(m) \\
m\textsuperscript{p}(i) = n \\
m\textsuperscript{p}(sum) = n * (n - 1) / 2 \\
}
Note that the transfer function doesn't need to be a closed form function. It
only needs to be a computable (terminating) function.
E.g.: Trivial solutions based on fixed point (terminating because the lattices
have finite height).
Suppose we wanted to compute value at P1 (refer to \autoref{fig:m120:ex1}).
In top-down fashion, we start from the procedure region. If we needed Q1,
then f\textsubscript{1} (which transfer function for the first basic block
in figure \autoref{fig:m120:ex1:c}) would only give summary of the basic block.
So, we'll apply transfer function of \texttt{sum = 0}.
In general, at every level of the hierarchy: Compute the DFA values on that level
of the hierarchy and we'll get boundary values of next-level regions. If we're
interested in an internal point of a region, we can use DFA value computed at
beginning of the region to get value internal to the region.
To compute value at P\textsubscript{2}:
\begin{itemize}
\item Run DFA on procedure region
\item Get value at beginning of loop region (P1). Note it's different
from P2 because the former is executed only once while the latter is entered
at every loop iteration.
\item Using P1, we find value at P1 at next level of the hierarchy.
\[Val[P_1] \wedge f_b(f_1(m_0)) \wedge f_b^2(f_1(m_0)) \wedge \ldots\]
\end{itemize}
|
# APS speed tests
import sys
import os
import pandas as pd
import numpy as np
import pytest
import pickle
from pathlib import Path
import multiprocessing
import pathos
import time
from sklearn.datasets import load_iris
import onnxruntime as rt
from pathlib import Path
from IVaps import estimate_aps_onnx, estimate_aps_user_defined
from IVaps.aps import _get_og_order
# First test that it works
def test_numba():
sklearn_logreg = str(Path(__file__).resolve().parents[0] / "test_models" / "logreg_iris.onnx")
iris = load_iris()
X, y = iris.data, iris.target
data = np.append(y[:,np.newaxis], X, axis = 1)
dt = pd.DataFrame(data, columns = ["y", "x1", "x2", "x3", "x4"])
data = dt.drop("y", axis = 1)
data = pd.concat([data]*100, ignore_index = True) # 150k rows
X_c = data.iloc[:,:3]
X_d = data.iloc[:,3]
# Insert NA into random rows
random_rows = np.random.choice(np.arange(X_c.shape[0]), size=100)
random_cols = np.random.choice(np.arange(X_c.shape[1]), size=100)
for i in range(len(random_rows)):
X_c.iloc[random_rows[i], random_cols[i]] = np.nan
# Set second continuous variable as mixed
L = {1:{3.0,4.0}}
t0 = time.time()
aps1 = estimate_aps_onnx_numba(X_c = X_c, X_d = X_d, S=100, delta=[0.1,0.5,0.8], onnx=sklearn_logreg, types=(np.float32,None), L = L, parallel=True)
t1 = time.time()
print("Numba runtime:", t1-t0)
aps2 = estimate_aps_onnx(X_c = X_c, X_d = X_d, S=100, delta=[0.1,0.5,0.8], onnx=sklearn_logreg, types=(np.float32,None), L = L, parallel=True)
t2 = time.time()
print("Original APS runtime:", t2-t1)
print(aps1)
print(aps2)
if __name__ == "__main__":
# Timeit
from timeit import Timer
sklearn_logreg = str(Path(__file__).resolve().parents[0] / "test_models" / "logreg_iris.onnx")
iris = load_iris()
X, y = iris.data, iris.target
data = np.append(y[:,np.newaxis], X, axis = 1)
dt = pd.DataFrame(data, columns = ["y", "x1", "x2", "x3", "x4"])
data = dt.drop("y", axis = 1)
# mult_vals = [1, 50, 100, 500, 1000, 2500, 5000]
# N = [150 * mult for mult in mult_vals]
# numba_time = []
# og_time = []
# for mult in mult_vals:
# tmp = pd.concat([data]*mult, ignore_index = True) # 150k rows
# X_c = tmp.iloc[:,:3]
# X_d = tmp.iloc[:,3]
#
# # Insert NA into random rows
# random_rows = np.random.choice(np.arange(X_c.shape[0]), size=100)
# random_cols = np.random.choice(np.arange(X_c.shape[1]), size=100)
# for i in range(len(random_rows)):
# X_c.iloc[random_rows[i], random_cols[i]] = np.nan
#
# # Set second continuous variable as mixed
# L = {1:{3.0,4.0}}
#
# # Time functions
# t = Timer(lambda: estimate_aps_onnx_numba(X_c = X_c, X_d = X_d, S=100, delta=[0.1,0.5,0.8],
# onnx=sklearn_logreg, types=(np.float32,None), L = L, parallel=True))
# numba_runtime = t.timeit(5)/300
# numba_time.append(numba_runtime)
# t = Timer(lambda: estimate_aps_onnx(X_c = X_c, X_d = X_d, S=100, delta=[0.1,0.5,0.8],
# onnx=sklearn_logreg, types=(np.float32,None), L = L, parallel=True))
# og_runtime = t.timeit(5)/300
# og_time.append(og_runtime)
#
# import matplotlib.pyplot as plt
# plt.plot(N, numba_time, color="red", label="Numba APS Performance")
# plt.plot(N, og_time, color="black", label="Original APS Performance")
# plt.legend()
# plt.title("Comparing APS Performance")
# plt.savefig("speed_test.png")
# plt.show()
# L = {1:{3.0,4.0}}
# X_c = data.iloc[:,:3]
# X_d = data.iloc[:,3]
# aps = estimate_aps_onnx(X_c = X_c, X_d = X_d, S=100, delta=[0.1,0.5,0.8], onnx=sklearn_logreg, types=(np.float32,None))
# print("APS ---------")
# print(aps)
# aps_p = estimate_aps_onnx(X_c = X_c, X_d = X_d, S=100, delta=[0.1,0.5,0.8], onnx=sklearn_logreg, types=(np.float32,None), parallel=True)
# print("APS parallel ---------")
# print(aps_p)
# aps_l = estimate_aps_onnx(X_c = X_c, X_d = X_d, S=100, delta=[0.1,0.5,0.8], onnx=sklearn_logreg, types=(np.float32,None), L = L, parallel=True)
# print("APS discrete vals ---------")
# print(aps_l)
|
module Sets.IterativeSet.Oper where
import Lvl
open import Data
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.Either as Either using (_β_)
open import Data.Tuple as Tuple using ()
open import Functional
open import Logic
open import Numeral.Natural
open import Relator.Equals using () renaming (_β‘_ to Id ; [β‘]-intro to intro)
open import Sets.IterativeSet
open import Syntax.Function
open import Type.Dependent
module _ where
private variable {β ββ ββ} : Lvl.Level
open Iset
-- The empty set, consisting of no elements.
-- Index is the empty type, which means that there are no objects pointing to elements in the set.
β
: Iset{β}
β
= set{Index = Empty} empty
-- The singleton set, consisting of one element.
-- Index is the unit type, which means that there are a single object pointing to a single element in the set.
singleton : Iset{β} β Iset{β}
singleton = set{Index = Unit} β const
-- The pair set, consisting of two elements.
-- Index is the boolean type, which means that there are two objects pointing to two elements in the set.
pair : Iset{β} β Iset{β} β Iset{β}
pair A B = set{Index = Lvl.Up(Bool)} ((if_then B else A) β Lvl.Up.obj)
-- The union operator.
-- Index(A βͺ B) is the either type of two indices, which means that both objects from the A and the B index point to elements in the set.
_βͺ_ : Iset{β} β Iset{β} β Iset{β}
A βͺ B = set{Index = Index(A) β Index(B)} (Either.map1 (elem(A)) (elem(B)))
_,_ : Iset{β} β Iset{β} β Iset{β}
A , B = pair (singleton A) (pair A B)
_β¨―_ : Iset{β} β Iset{β} β Iset{β}
A β¨― B = set{Index = Index(A) Tuple.β¨― Index(B)} \{(ia Tuple., ib) β (elem(A)(ia) , elem(B)(ib))}
-- The big union operator.
-- Index(β A) is the dependent sum type of an Index(A) and the index of the element this index points to.
β : Iset{β} β Iset{β}
β A = set{Index = Ξ£(Index(A)) (ia β¦ Index(elem(A)(ia)))} (\{(intro ia i) β elem(elem(A)(ia))(i)})
indexFilter : (A : Iset{β}) β (Index(A) β Stmt{β}) β Iset{β}
indexFilter A P = set{Index = Ξ£(Index(A)) P} (elem(A) β Ξ£.left)
filter : (A : Iset{β}) β (Iset{β} β Stmt{β}) β Iset{β}
filter{β} A P = indexFilter A (P β elem(A))
indexFilterBool : (A : Iset{β}) β (Index(A) β Bool) β Iset{β}
indexFilterBool A f = indexFilter A (Lvl.Up β IsTrue β f)
filterBool : (A : Iset{β}) β (Iset{β} β Bool) β Iset{β}
filterBool A f = indexFilterBool A (f β elem(A))
mapSet : (Iset{β} β Iset{β}) β (Iset{β} β Iset{β})
mapSet f(A) = set{Index = Index(A)} (f β elem(A))
-- The power set operator.
-- Index(β(A)) is a function type. An instance of such a function represents a subset, and essentially maps every element in A to a boolean which is interpreted as "in the subset of not".
-- Note: This only works properly in a classical setting. Trying to use indexFilter instead result in universe level problems.
β : Iset{β} β Iset{β}
β(A) = set{Index = Index(A) β Bool} (indexFilterBool A)
-- The set of ordinal numbers of the first order.
Ο : Iset{β}
Ο = set{Index = Lvl.Up β} (N β Lvl.Up.obj) where
N : β β Iset{β}
N(π) = β
N(π(n)) = N(n) βͺ singleton(N(n))
|
%
\notePage{0}{Title and list of authors changed}
%
\notePage{iii}{Prelude added.}
%
\replacementPage{iv}{fourteen}{twenty}
%
\deletionPage{vii}{
The Definition has evolved through a sequence of three previous versions,
circulated as Technical Reports. For those who have followed the
sequence, we should point out that the treatment of {\sl equality types}
and of {\sl admissibility} has been slightly modified in this publication
to meet the claim for principal signatures. The changes are mainly
in Sections~4.9, 5.5 and 5.13 and in the inference rules~19, 20,
29 and 65.}
%
\replacementPage{vii}{Some}{Many}
%
\replacementPage{vii}{have also become}{became}
%
\insertionPage{vii}{1990}
%
\replacementPage{vii}{will not be}{are not}
%
\replacementPage{vii}{So we are writing
a Commentary\cite{mt91} on the Definition which will assist people in reading it, and
which will serve as a bridge between the Definition and other texts.}
{We therefore wrote a
Commentary on the 1990
Definition to
assist people in reading it, and to
serve as a bridge between the Definition and other texts. Though in
part outdated by the present revision, the Commentary still fulfils its
purpose.}
%
\insertionPage{vii}{There exist several textbooks on programming
with Standard ML\cite{paulson96,mcp93,Ullman94,stansifer92}. The second
edition of Pauson's book\cite{paulson96} conforms with the present revision.}
%
\deletionPage{vii}{\begin{flushright} Edinburgh\\August 1989 \end{flushright}}
%
\replacementPage{1}{just}{part of}
%
\replacementPage{2}{all predefined identifiers.}{a
small set of predefined identifiers. A richer basis is defined
in a separate document\cite{mllib96}.}
%
\deletionPage{2}{
This theory, particularly the theory of types and signatures, will
benefit from a more pedagogic treatment in other publications; the
treatment here is
probably the minimum required to understand the meaning of the rules.}
%
\deletionPage{2}{In two cases, however, they are presented as ``claims'' rather than
theorems; these are the claim of principal environments in
Section~\ref{principal-env-sec}, and the claim of principal signatures
in Section~\ref{prinsig-sec}. We need further confirmation of our
detailed proofs of these claims, before asserting them as theorems.}
%
\replacementPage{3}{
An\index{6.2} {\sl integer constant}
is any non-empty sequence of digits, possibly preceded
by a negation symbol (\tttilde).
A {\sl real constant} is an integer constant,
possibly followed by a point ({\tt .}) and one or
more digits, possibly followed by an exponent symbol ~{\tt E}~ and an integer
constant; at least one of the optional parts must occur, hence no integer
constant is a real constant.}{
An\index{6.2} {\sl integer constant (in
decimal notation)} is an optional negation symbol (\tttilde)
followed by a non-empty sequence of decimal digits (\boxml{0}-\boxml{9}).
An {\sl integer constant (in
hexadecimal notation)} is an optional negation symbol
followed by \boxml{0x} followed by a non-empty sequence of
hexadecimal digits (\boxml{0}-\boxml{9}\boxml{a}-\boxml{f}\boxml{A}-\boxml{F},
where \boxml{A}-\boxml{F} are alternatives for \boxml{a}-\boxml{f},
respectively).
A {\sl word constant (in decimal notation)} is \boxml{0w} followed
by a non-empty sequence of decimal digits. A {\sl word constant
(in hexadecimal notation)} is \boxml{0wx} followed by a non-empty
sequence of hexadecimal digits.
A {\sl real constant} is an integer constant in decimal notation,
possibly followed by a point ({\tt .}) and one or
more decimal digits, possibly followed by an exponent symbol ~({\tt E} or {\tt e})~ and an integer
constant in decimal notation; at least one of the optional parts must occur, hence no integer
constant is a real constant.}
%
\replacementPage{3}{We assume an underlying alphabet of 256 characters
(numbered 0 to 255) such that the characters with numbers
0 to 127 coincide with the ASCII character set.
}{We assume an underlying alphabet of $N$ characters ($N \geq 256$), numbered
$0$ to $N-1$, which agrees with the ASCII character set on the characters
numbered 0 to 127. The interval $[0, N-1]$ is called the {\sl ordinal range} of
the alphabet.
%For use in string and character constants, we assume two underlying
%alphabets, of 8 bit and 16 bit characters, respectively. The {\sl ordinal
%ranges} of the two alphabets are $[0,255]$ and $[0,65535]$, respectively.
%In both cases, the characters with numbers 0 to 127 are assumed to coincide
%with the ASCII character set.
}
%
\notePage{3}{Inserted additional escape sequences in figure concerning
string constants and unicodes}
%
\insertionPage{4}{A {\sl character constant} is a sequence of the form
{\tt\#}$s$, where $s$ is a string constant denoting a string of size one character.
Libraries may provide multiple numeric types and multiple string types.
To each string type
corresponds an alphabet with ordinal range $[0, N-1]$
for some $N\geq 256$; each alphabet must agree with the ASCII character set on
the characters numbered 0 to 127. When multiple alphabets are supported,
all characters of a given string constant are interpreted over the same
alphabet. For each special constant, overloading
resolution is used for determining the type of the constant
(see Appendix~\ref{overload.sec}).
% All the escape sequences in a given string constant are interpreted
% over the same underlying alphabet (either 8-bit characters or 16-bit
% characters), and for each string constant this alphabet is determined
% by overloading resolution (see Appendix~\ref{overload.sec}).
% It is a compile-time error
% if the
%constant contains an escape sequence of the form $\uconst$ where
%$xxxx$ denotes an integer outside the ordinal range of the alphabet so
%determined. For example, within a sequence of 8-bit characters, the
%two leftmost hexadecimal digits of $\uconst$ must be {\tt 0} (zero).
}
%
\insertionPage{4}{word, character}
%
\replacementPage{4}{An
unmatched comment bracket should be
detected by the compiler.}{No space is allowed between
the two characters which make up
a comment bracket \ml{(*} or \ml{*)}. An unmatched
\boxml{(*} should be detected by the compiler.}
%
\notePage{4}{Figure 1 replaced by new figure (Var, Con and ExCon
merged into VId)}
%
\replacementPage{4}{$\var$}{$\vid$}
%
\replacementPage{4}{Var}{$\VId$}
%
\deletionPage{5}{The subclass $\ImpTyVar$ of
$\TyVar$, the {\sl imperative} type variables, consists of those which
start with one or two primes followed by an underbar. The complement
$\AppTyVar=\TyVar\setminus\ImpTyVar$\index{8.1} consists of the {\sl
applicative} type variables.
}
%
\replacementPage{5}{The other six classes ({\Var}, {\Con},
{\Exn}, {\TyCon}, {\Lab} and {\StrId}) are represented by identifiers
not starting with a prime.}{The other four classes ({\VId},
{\TyCon}, {\Lab} and {\StrId}) are represented by identifiers
not starting with a prime.}
%
\replacementPage{5}{six}{four}
%
\replacementPage{5}{
\item Elsewhere, $\id$ is an exception constructor if it occurs in
the scope of an exception binding which introduces it as such,
or a value constructor if it occurs in the
scope of a datatype binding which introduced it as such;
otherwise it is a value variable.}{
\item Elsewhere, $\id$ is a value identifier.}
%
\deletionPage{5}{
It follows from the last rule that no value declaration can make a
``hole'' in the scope of a value or exception constructor
by introducing the same identifier as a variable; this
is because, in the scope of the declaration which introduces $\id$ as a value
or exception constructor, any occurrence of $\id$ in a pattern
is interpreted as the
constructor and not as the binding occurrence of a new variable.}
%
\replacementPage{6}{$\var$, a
$\con$ or an $\exn$}{$\vid$}
%
\replacementPage{6}{directive.}{directive, and in these uses it is called an
{\sl infixed operator}.}
%
\replacementPage{6}{$\id$}{$\vid$}
%
\replacementPage{6}{``$\exp_1\ \id\ \exp_2$''}{``$\exp_1\ \vid\ \exp_2$''}
%
\replacementPage{6}{``$\pat_1\
\id\ \pat_2$''}{``$\pat_1\
\vid\ \pat_2$''}
%
\replacementPage{6}{$\id$}{$\vid$}
%
\replacementPage{6}{$\id$}{$\vid$}
%
\replacementPage{6}{$\id$}{$\vid$}
%
\replacementPage{6}{$\id$}{$\vid$}
%
\replacementPage{6}{\[ \longinfix \]
\[ \longinfixr \]
\[ \longnonfix \]}{\[ \newlonginfix \]
\[ \newlonginfixr \]
\[ \newlongnonfix \]}
%
\replacementPage{6}{$0$}{{\tt 0}}
%
\replacementPage{6}{~$\INFIX$~ and ~$\INFIXR$~ dictate left and right
associativity respectively; association is always to the left for different
operators of the same precedence.}{~$\INFIX$~ and ~$\INFIXR$~ dictate left and right
associativity respectively. In an expression of the form $\exp_1\, \vid_1\, \exp_2\, \vid_2\, \exp_3$, where
$\vid_1$ and $\vid_2$ are infixed operators with the same precedence,
either both must associate to the left or both must
associate to the right.
For example, suppose that {\tt <<} and {\tt >>} have equal precedence,
but associate to the left and right respectively; then
\medskip
\tabskip4cm
\halign to\hsize{\indent\hfil{\tt #}\tabskip1em&\hfil#\hfil\ &\ {\tt #}\hfil\cr
x << y << z&parses as&(x << y) << z\cr
x >> y >> z&parses as&x >> (y >> z)\cr
x << y >> z&is illegal\cr
x >> y << z&is illegal\cr}
\medskip}
%
\replacementPage{6}{infix}{infixed}
%
\replacementPage{7}{Figures~\ref{exp-syn}
and~\ref{pat-syn}.}{Figures~\ref{pat-syn} and~\ref{exp-syn}.}
%
\deletionPage{8}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
& & \opp\var & variable\cr
& & \opp\longcon & constant\cr
& & \opp\longexn & exception constant\cr}\end{minipage}}
%
\insertionPage{8}{$\opp\longvid$\qquad value identifier}
%
\insertionPage{8}{::=}
%
\deletionPage{8}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
& & \opp\conpat & value construction\cr
& & \opp\exconpat & exception construction\cr
& & \infpat & infixed value construction\cr
& & \infexpat & infixed exception construction\cr}\end{minipage}}
%
\insertionPage{8}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
& \opp\vidpat & constructed pattern\cr
& & \vidinfpat & infixed value construction\cr}\end{minipage}}
%
\replacementPage{8}{$\opp\layeredpat$}{$\opp\layeredvidpat$}
%
\deletionPage{10}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
& & \opp\longvar & value variable\cr
& & \opp\longcon & value constructor\cr
& & \opp\longexn & exception constructor\cr}\end{minipage}}
%
\insertionPage{10}{$\opp\longvid$\quad value identifier}
%
\replacementPage{10}{\infexp}{\vidinfexp}
%
\replacementPage{10}{\valdec}{\explicitvaldec}
%
\insertionPage{10}{$\datatyperepldecb$\qquad datatype replication}
%
\replacementPage{10}{\longinfix}{\newlonginfix}
%
\replacementPage{10}{\longinfixr}{\newlonginfixr}
%
\replacementPage{10}{\longnonfix}{\newlongnonfix}
%
\replacementPage{10}{$\opp\longconstrs$}{$\opp\longvidconstrs$}
%
\replacementPage{10}{\generativeexnbind}{\generativeexnvidbind}
%
\replacementPage{10}{\eqexnbind}{\eqexnvidbind}
%
\deletionPage{8}{No pattern may contain the same $\var$ twice. }
%
\insertionPage{8}{-expression}
%
\replacementPage{8}{constructors}{identifiers}
%
\insertionPage{8}{
For each $\dec$ of the form $\datatyperepldeca$,
the sequences $\tyvarseq$ and $\tyvarseq'$ must be equal and neither
may contain the same type variable twice.}
%
\insertionPage{9}{\item No $\datbind$ or $\exnbind$ may bind $\TRUE$, $\FALSE$, $\IT$,
$\NIL$, \boxml{::} or $\REF$.}
%
\replacementPage{11}{The derived forms for modules concern functors and appear in
Appendix~\ref{derived-forms-app}.}{The derived forms for modules appear in
Appendix~\ref{derived-forms-app}.}
%
\notePage{11}{Inserted new keywords {\tt where} and {\tt :>}}
%
\replacementPage{11}{syntax}{identifier}
%
\replacementPage{11}{generative}{basic}
%
\deletionPage{11}{A more liberal scheme (which is under consideration)
would allow fixity directives to appear also as specifications, so that
fixity may be dictated by a signature expression; furthermore, it would allow an ~$\OPEN$~
or ~$\INCLUDE$~ construction to restore the fixity which prevailed
in the structures being opened, or in the signatures being included.
This scheme is not adopted at present.}
%
\deletionPage{12}{SharEq \quad sharing equations}
%
\deletionPage{12}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
FunSigExp & functor signature expressions\cr
FunSpec & functor specifications\cr
FunDesc & functor descriptions\cr}\end{minipage}}
%
\deletionPage{11}{It should be noted that functor specifications (FunSpec) cannot
occur in programs;
neither can the associated functor descriptions (FunDesc)
and functor signature expressions (FunSigExp). The purpose of a $\funspec$
is to specify the static attributes (i.e. functor signature) of one
or more functors. This will be useful, in fact essential, for
separate compilation of functors. If, for example, a functor $g$
refers to another functor $f$ then --- in order to compile $g$ in
the absence of the declaration of $f$ --- at least the specification
of $f$ (i.e. its functor signature) must be available. At present there is no
special grammatical form for a separately compilable ``chunk'' of text
-- which we may like to call call a {\sl module} -- containing a $\fundec$
together with a $\funspec$ specifying its global references. However, below in
the semantics for Modules it is defined when a
declared functor matches a functor signature specified for it. This determines
exactly those functor environments (containing declared functors
such as $f$) into which the separately compiled ``chunk''
containing the declaration of $g$ may be loaded.}
%
\replacementPage{13}{generative}{basic}
%
\insertionPage{13}{$\transpconstraint$\quad transparent constraint}
%
\insertionPage{13}{ $ \opaqueconstraint$\quad opaque constraint}
%
\replacementPage{13}{$\strbindera$}{$\barestrbindera$}
%
\replacementPage{13}{generative}{basic}
%
\insertionPage{13}{$\wheretypesigexp$\quad type realisation}
%
\deletionPage{13}{single}
%
\deletionPage{13}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
& & \emptysigdec & empty\cr
& & \seqsigdec & sequential\cr}\end{minipage}}
%
\replacementPage{12}{, $\strdesc$ or $\fundesc$}{or $\strdesc$}
%
\replacementPage{12}{constructors}{identifiers}
%
\insertionPage{12}{
No ${\it tyvarseq}$ may contain the same ${\it tyvar}$ twice.}
%
\insertionPage{12}{
For each $\spec$ of the form $\datatypereplspeca$, the sequences
$\tyvarseq$ and $\tyvarseq'$ must be equal.}
%
\insertionPage{12}{
Any $\tyvar$ occurring on the right side of a $\datdesc$ of the form\linebreak
$\tyvarseq \;\tycon\;\boxml{=}$ $\cdots$ must occur
in the $\tyvarseq$; similarly, in signature expressions of the form $\sigexp\ \boxml{where type}\, \tyvarseq\,\longtycon\,$
$\boxml{=}\,\ty$, any $\tyvar$ occurring in $\ty$ must occur in $\tyvarseq$.}
%
\insertionPage{12}{\item No $\datdesc$ or $\exndesc$ may describe
$\TRUE$, $\FALSE$, $\IT$,
$\NIL$, \boxml{::} or $\REF$.}
%
\insertionPage{14}{$\datatypereplspecb$\qquad replication}
%
\deletionPage{14}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
& & \sharingspec & sharing\cr
& & \localspec & local\cr
& & \openspec & open ($n\geq 1$)\cr }\end{minipage}}
%
\replacementPage{14}{$\inclspec$\qquad include ($n\geq 1$)}{
$\singleinclspec$\qquad include}
%
\insertionPage{14}{$\newsharingspec$\qquad sharing \quad $(n\geq 2)$}
%
\replacementPage{14}{\valdescription}{\valviddescription}
%
\replacementPage{14}{\condescription}{\conviddescription}
%
\replacementPage{14}{\exndescription}{\exnviddescription}
%
\deletionPage{14}{\begin{minipage}{\textwidth}\halign{\indent#\hfil&#\hfil&#\hfil&#\hfil\cr
\shareq & ::= & \strshareq & structure sharing\cr
& & & \qquad ($n\geq 2$) \cr
& & \typshareq & type sharing \cr
& & & \qquad ($n\geq 2$) \cr
& & \multshareq & multiple\cr\noalign{\vspace{6pt}}
\noalign{\vspace{6pt}}}\end{minipage}}
%
\notePage{12}{Figure 8: Functor signature expressions and
functor specifications have been removed. Sequential and empty
functor declarations and signature declarations have been removed.
The grammar for $\topdec$ now allows sequencing (without semicolon)
of structure-level declarations, signature declarations and functor
declarations.}
%
\deletionPage{12}{
\subsection{Closure Restrictions}
\label{closure-restr-sec}
The\index{18.2} semantics presented in later sections requires no restriction on
reference to non-local identifiers. For example, it allows a signature
expression to refer to external signature identifiers and
(via ~$\SHARING$~ or ~$\OPEN$~) to external structure identifiers; it also
allows a functor to refer to external identifiers of any kind.
However, implementers who want to provide a simple facility for
separate compilation may want to impose the following restrictions
(ignoring references to identifiers bound in the initial basis
$\B_0$, which may occur anywhere):
%However, in the present version of the language,
%apart from references to identifiers bound in the initial basis $B_0$
%(which may occur anywhere), it is required that signatures only refer
%non-locally to signature identifiers and that functors only
%refer non-locally to functor and signature identifiers.
%These restrictions ease separate
%compilation; however, they may be relaxed in a future version of the language.
%
%More precisely, the restrictions are as follows (ignoring reference to
%identifiers bound in $B_0$):
\begin{enumerate}
\item In any signature binding ~$\sigid\ \mbox{{\tt =}}\ \sigexp$~,
the only non-local
references in $\sigexp$ are to signature identifiers.
\item In any functor description ~$\funid\ \longfunsigexpa$~,
the only non-local
references in $\sigexp$ and $\sigexp'$ are to signature identifiers,
except that $\sigexp'$ may refer to $\strid$ and its components.
\item In any functor binding ~$\funstrbinder$~, the only non-local
references in $\sigexp$, $\sigexp'$ and $\strexp$ are to functor and signature
identifiers,
except that both $\sigexp'$ and $\strexp$ may refer to $\strid$ and
its components.
\end{enumerate}
In the last two cases the final qualification allows, for example, sharing
constraints to be specified between functor argument and result.
(For a completely precise definition of these closure restrictions,
see the comments to rules \ref{single-sigdec-rule}
(page~\pageref{single-sigdec-rule}),
\ref{singfunspec-rule} (page~\pageref{singfunspec-rule})
and \ref{singfundec-rule} (page~\pageref{singfundec-rule})
in the static semantics of modules, Section~\ref{statmod-sec}.)
The\index{19.1}
significance of these restrictions is that they may ease separate
compilation; this may be seen as follows. If one takes a {\sl module}
to be a sequence of signature declarations, functor specifications
and functor declarations satisfying the above restrictions then the
elaboration of a module can be made to depend on the initial
static basis alone (in particular, it will not rely on
structures outside the module). Moreover, the elaboration
of a module cannot create new free structure or type names, so
name consistency (as defined in Section~\ref{consistency-sec},
page \pageref{consistency-sec}) is automatically preserved
across separately compiled modules. On the other hand,
imposing these restrictions may force the programmer to write
many more sharing equations than is needed if functors
and signature expressions can refer to free structures.
}
%
\replacementPage{15}{All semantic objects in the static semantics of the entire
language are built from identifiers and two further kinds of simple objects:
type constructor names and structure names.}{All semantic objects in
the static semantics of the entire
language are built from identifiers and two further kinds of simple objects:
type constructor names and identifier status descriptors.}
%
\deletionPage{15}{Structure names play an active role only in
the Modules semantics; they enter the Core semantics only because
they appear in structure environments, which (in turn) are needed in the Core
semantics only to determine the values of long identifiers.}
%
\replacementPage{15}{
\begin{displaymath}
\begin{array}{rclr}
\alpha\ {\rm or}\ \tyvar & \in & \TyVar & \mbox{type variables}\\
\t & \in & \TyNames & \mbox{type names}\\
\m & \in & \StrNames & \mbox{structure names}
\end{array}
\end{displaymath}}{\begin{displaymath}
\begin{array}{rcll}
\alpha\ {\rm or}\ \tyvar & \in & \TyVar & \mbox{type variables}\\
\t & \in & \TyNames & \mbox{type names}\\
\is & \in & \IdStatus = \{\isc,\ise,\isv\} & \mbox{identifier status descriptors}
\end{array}
\end{displaymath}}
%
\deletionPage{15}{Independently hereof, each $\alpha$ possesses a boolean attribute,
the {\sl imperative} attribute, which determines whether it is imperative,
i.e. whether it is a member of $\ImpTyVar$ (defined on page~\pageref{etyvar-lab})
or not.}
%
\replacementPage{15}{{\INT}, {\REAL}
or {\STRING}}{{\INT}, {\REAL}, {\WORD}, {\CHAR}
or {\STRING}}
%
\insertionPage{15}{(However, see Appendix~\ref{overload.sec}
concerning types of overloaded special constants.)}
%
\replacementPage{16}{\RecType}{\RowType}
%
\replacementPage{16}{\RecType}{\RowType}
%
\deletionPage{16}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&$#$\hfil&$#$\hfil\cr
\S\ {\rm or}\ (\m,\E)
& \in & \Str = \StrNames\times\Env \cr}\end{minipage}}
%
\replacementPage{16}{\CE}{\VE}
%
\replacementPage{16}{$\TyStr = \TypeFcn\times\ConEnv$}{$\TyStr = \TypeFcn\times\ValEnv$}
%
\replacementPage{16}{$\StrEnv = \finfun{\StrId}{\Str}$}{$\StrEnv = \finfun{\StrId}{\Env}$}
%
\deletionPage{16}{$\CE\quad \in\quad \ConEnv = \finfun{\Con}{\TypeScheme}$}
%
\replacementPage{16}{$\VarEnv = \finfun{(\Var\cup\Con\cup\Exn)}{\TypeScheme}$}{$\ValEnv = \finfun{\VId}{\TypeScheme\times\IdStatus}$}
%
\deletionPage{16}{$\EE \in \ExnEnv = \finfun{\Exn}{\Type}$}
%
\replacementPage{16}{$\longE{}$}{$\newlongE{}$}
%
\replacementPage{16}{$\Env = \StrEnv\times\TyEnv\times\VarEnv\times\ExnEnv$}{$\Env = \StrEnv\times\TyEnv\times\ValEnv$}
%
\deletionPage{16}{Moreover, $\imptyvars A$ and $\apptyvars A$ denote respectively the set
of imperative type variables and the set of applicative
type variables occurring free in $A$.}
%
\insertionPage{16}{\par Also note that a value environment maps
value identifiers to a pair of a type scheme and an identifier status.
If $\VE(\vid) = (\sigma,\is)$, we say that $\vid$ {\sl has status $\is$
in $\VE$}. An occurrence of a value identifier which is elaborated
in $\VE$ is referred to as a {\sl value variable}, a {\sl value constructor}
or an {\sl exception constructor}, depending on whether its status in $\VE$
is $\isv$, $\isc$ or $\ise$, respectively. }
%
\replacementPage{17}{variable-environment}{value-environment}
%
\replacementPage{17}{variable}{metavariable}
%
\replacementPage{17}{variable-environment}{value-environment}
%
\deletionPage{17}{ and ``$\of{\m}{\S}$'' means ``the structure name of $\S$''}
%
\replacementPage{17}{For instance $\C(\tycon)$ means
$(\of{\TE}{\C})\tycon$.
A particular case needs mention: $\C(\con)$ is taken to stand for
$(\of{\VE}{\C})\con$; similarly, $\C(\exn)$ is taken to stand for
$(\of{\VE}{\C})\exn$.
The type scheme of a value constructor is
held in $\VE$ as well as in $\TE$ (where it will be recorded within
a $\CE$); similarly, the type of an exception constructor is held in
$\VE$ as well as in $\EE$.
Thus the re-binding of a constructor of either kind is given proper
effect by accessing it in $\VE$, rather than in $\TE$ or in $\EE$.}{For
instance $\C(\tycon)$ means
$(\of{\TE}{\C})\tycon$ and $\C(\vid)$ means $(\of{\VE}{(\of{E}{\C})})(\vid)$.}
%
\replacementPage{17}{For instance if $\longcon = \strid_1.\cdots.\strid_k.\con$ then
$\E(\longcon)$ means
\[ (\of{\VE}
{(\of{\SE}
{\cdots(\of{\SE}
{(\of{\SE}{\E})\strid_1}
)\strid_2\cdots}
)\strid_k}
)\con.
\]
}{For instance if $\longvid = \strid_1.\cdots.\strid_k.\vid$ then
$\E(\longvid)$ means
\[ (\of{\VE}
{(\of{\SE}
{\cdots(\of{\SE}
{(\of{\SE}{\E})\strid_1}
)\strid_2\cdots}
)\strid_k}
)\vid.
\]
}
%
\replacementPage{17}{$(\emptymap,\emptymap,\VE,\emptymap)$.}{$(\emptymap,\emptymap,\VE)$.}
%
\replacementPage{17}{$\E+(\emptymap,\emptymap,\VE,\emptymap)$.}{$\E+(\emptymap,\emptymap,\VE)$.}
%
\deletionPage{17}{Similarly, the imperative attribute has no significance
in the bound variable of a type function.}
%
\deletionPage{18}{A type is {\sl imperative} if all type variables occurring in it are
imperative.}
%
\replacementPage{18}{if $\tau'=\tau\{\tauk/\alphak\}$ for some $\tauk$, where each member $\tau_i$
of $\tauk$ admits equality if $\alpha_i$ does,
%poly
and $\tau_i$ is imperative if $\alpha_i$ is imperative.}{if $\tau'=\tau\{\tauk/\alphak\}$ for some $\tauk$, where each member $\tau_i$
of $\tauk$ admits equality if $\alpha_i$ does.}
%
\deletionPage{18}{Similarly, the imperative attribute of a bound type variable of a
type scheme {\sl is} significant.}
%
\insertionPage{18}{Moreover, in a value declaration
{\tt val $\tyvarseq$ $\valbind$}, the sequence $\tyvarseq$ binds
type variables: a type variable occurs free in
{\tt val $\tyvarseq$ $\valbind$} iff it occurs free in $\valbind$
and is not in the sequence $\tyvarseq$.}
%
\deletionPage{18}{
In the modules, a description of a value, type, or datatype
may contain explicit type variables whose scope is that
description.}
%
\insertionPage{18}{explicit binding of type
variables at {\tt val} is optional, so}
%
\insertionPage{18}{free}
%
\replacementPage{18}{First, an occurrence of $\alpha$ in a value declaration $\valdec$ is said
to be {\sl unguarded} if the occurrence is not part of a smaller value
declaration within $\valbind$.}{First, a free occurrence of $\alpha$ in a value declaration
$\explicitvaldec$ is said
to be {\sl unguarded} if the occurrence is not part of a smaller value
declaration within $\valbind$.}
%
\replacementPage{18}{Then we say that $\alpha$ is {\sl scoped at}
a particular occurrence
$O$ of $\valdec$ in a program if}{Then we say that $\alpha$ is {\sl implicitly scoped at} a particular value declaration
{\tt val $\tyvarseq$ $\valbind$} in a program if}
%
\replacementPage{18}{occurrence $O$.}{given one.}
%
\deletionPage{18}{
Hence, associated with every occurrence of a value declaration there is
a set $\U$ of the explicit type variables that are implicitly
scoped at that
occurrence. One may think of each occurrence of $\VAL$ as being implicitly
decorated with such a set, for instance:
\vspace*{3mm}
\halign{\indent$#$&$#$&$#$\cr
\mbox{$\VAL_{\{\}}$ \ml{x = }}&\mbox{\ml{(}}&
\mbox{\ml{let $\VAL_{\{\mbox{\ml{'a}}\}}$ Id1:'a->'a = fn z=>z in Id1 Id1 end,}}\cr
& &\mbox{\ml{let $\VAL_{\{\mbox{\ml{'a}}\}}$ Id2:'a->'a = fn z=>z in Id2 Id2 end)}}\cr
\noalign{\vspace*{3mm}}
\mbox{$\VAL_{\{\mbox{\ml{'a}}\}}$ \ml{x = }}&\mbox{\ml{(}}&
\mbox{\ml{let $\VAL_{\{\}}$ Id:'a->'a = fn z=>z in Id Id end,}}\cr
& &\mbox{\ml{fn z=> z:'a)}}\cr}
}
%
\insertionPage{19}{Henceforth, we assume that for every
value declaration $\boxml{val}\,\tyvarseq\cdots$ occurring in the
program, every explicit type variable implicitly scoped at the {\tt val}
has been added to $\tyvarseq$. Thus for example, in the two declarations
\begin{tabbing}
\indent\=\tt val x = let val id:'a->'a = fn z=>z in id id end\\
\>\tt val x = (let val id:'a->'a = fn z=>z in id id end; fn z=>z:'a)
\end{tabbing}
the type variable \boxml{'a} is scoped differently; they become respectively
\begin{tabbing}
\indent\=\tt val x = let val 'a id:'a->'a = fn z=>z in id id end\\
\>\tt val 'a x = (let val id:'a->'a = fn z=>z in id id end; fn z=>z:'a)
\end{tabbing}
}
%
\replacementPage{19}{According}{Then, according}
%
\replacementPage{19}{\ml{Id}}{\ml{id}}
%
\replacementPage{19}{\ml{Id Id}}{\ml{id id}}
%
\deletionPage{19}{
\subsection{Non-expansive Expressions}
\label{expansive-sec}
In\index{23.4} order to treat polymorphic references and exceptions,
the set Exp of expressions is partitioned into two classes, the {\sl
expansive} and the {\sl non-expansive} expressions.
Any variable,
constructor and $\FN$ expression, possibly constrained by one or more
type expressions, is non-expansive; all other expressions are said to
be expansive. The idea is that the dynamic evaluation of a
non-expansive expression will neither generate an exception nor extend
the domain of the memory, while the evaluation of an expansive
expression might.}
%
\insertionPage{19}{
\subsection{Non-expansive Expressions}
\label{expansive-sec}
In\index{23.4} order to treat polymorphic references and exceptions,
the set Exp of expressions is partitioned into two classes, the {\sl
expansive} and the {\sl non-expansive} expressions.
An expression
is {\sl non-expansive in context $\C$} if, after replacing infixed forms
by their equivalent prefixed forms, and derived forms by their equivalent
forms, it can be generated by the following grammar from the
non-terminal $\nexp$:
\medskip
\halign{\indent\hfil$#$\ &\ $#$\hfil\ &\ $#$\hfil&\ #\hfil\cr
\nexp&::=&\scon\cr
&&\langle\OP\rangle\longvid\cr
&&\ttlbrace\langle\nexprow\rangle\ttrbrace\cr
&&\boxml{($\nexp$)}\cr
&&\boxml{$\conexp\;\nexp$}\cr
%&&\boxml{$\longvid\;\nexp$}\qquad\qquad\hbox{restrictions:}&$\longvid\neq\REF$ and\cr
%&&&$\of{\is}{\C(\longvid)}\in\{\isc,\ise\}$\cr
&&\nexp \boxml{:} \ty\cr
%&&\boxml{$\nexp$ handle $\match$}\cr
&&\boxml{fn $\match$}\cr%\cr
\nexprow&::=&\boxml{$\lab$ = $\nexp\langle$, $\nexprow\rangle$}\cr
\conexp&::=&\boxml{($\conexp\langle$:$\ty\rangle$)}\cr
&&\hbox{$\langle\OP\rangle\longvid$\hskip3cm Restriction:}&$\longvid\neq\REF$ and\cr
&&&$\of{\is}{\C(\longvid)}\in\{\isc,\ise\}$\cr}
\medskip
\noindent
All other expressions are said to be {\sl expansive (in $C$)}.
The idea is that the dynamic evaluation of a
non-expansive expression will neither generate an exception nor extend
the domain of the memory, while the evaluation of an expansive
expression might.
}
%
\replacementPage{19}{variable environment}{value
environment}
%
\replacementPage{19}{\[\cl{A}{\VE}=\{\id\mapsto\cl{A}{(\tau)}\ ;\ \VE(\id)=\tau\}\]}{\[\cl{A}{\VE}=\{\vid\mapsto(\cl{A}{(\tau)},\is)\ ;\ \VE(\vid)=(\tau,\is)\}\]}
%
\deletionPage{20}{with a similar definition for $\cl{A}{\CE}$.}
%
\replacementPage{20}{variable environment}{value environment}
%
\replacementPage{20}{Thus, for each $\var\in\Dom\VE$
there is a unique \mbox{\pat\ \ml{=} \exp}
in $\valbind$ which binds $\var$.}{Thus, for each $\vid\in\Dom\VE$
there is a unique \mbox{\pat\ \ml{=} \exp}
in $\valbind$ which binds $\vid$.}
%
\replacementPage{20}{$\VE(\var)=\tau$}{$\VE(\vid)=(\tau,\is)$}
%
\replacementPage{20}{$\cl{\C,\valbind}{\VE(\var)}=\longtych$}{$\cl{\C,\valbind}{\VE(\vid)}=(\longtych,\is)$}
%
\replacementPage{20}{\[\alphak=\cases{\TyVarFcn\tau\setminus\TyVarFcn\C,&if $\exp$
is non-expansive;\cr
\apptyvars\tau\setminus\TyVarFcn\C,&if $\exp$ is expansive.}
\]
}{
\[\alphak=\cases{\TyVarFcn\tau\setminus\TyVarFcn\C,&if $\exp$
is non-expansive in $\C$;\cr
(),&if $\exp$ is expansive in $\C$.}
\]}
%
\deletionPage{20}{Notice that the form of $\valbind$ does not affect the binding of
applicative type variables, only the binding of imperative
type variables.}
%
\replacementPage{20}{$(\theta,\CE)$}{$(\theta,\VE)$}
%
\replacementPage{20}{$(\theta,\CE)$}{$(\theta,\VE)$}
%
\replacementPage{20}{$\CE\neq\emptymap$}{$\VE\neq\emptymap$}
%
\insertionPage{20}{An object or assembly $A$ of semantic objects is {\sl well-formed} if every type structure
occurring in $A$ is well-formed.}
%
\replacementPage{20}{assumed}{required}
%
\replacementPage{20}{$(\t,\CE)$}{$(\t,\VE)$}
%
\replacementPage{20}{$\CE(\con)$}{$\VE(\vid)$}
%
\replacementPage{20}{$\forall\alphak.(\tau\rightarrow\alphak\t)$,}{$(\forall\alphak.(\tau\rightarrow\alphak\t), \is)$,}
%
\replacementPage{20}{$(\con,v)$}{$(\vid,v)$}
%
\replacementPage{20}{$(\t,\CE)$ }{$(\t,\VE)$ }
%
\replacementPage{20}{$\CE\neq\emptymap$}{$\VE\neq\emptymap$}
%
\replacementPage{20}{\[\TE=\{\tycon_i\mapsto(t_i,\CE_i)\ ;\ 1\leq i\leq k\},\]}{\[\TE=\{\tycon_i\mapsto(t_i,\VE_i)\ ;\ 1\leq i\leq k\},\]}
%
\replacementPage{20}{$\CE_i$}{$\VE_i$}
%
\replacementPage{20}{constructor}{value}
%
\replacementPage{20}{$\CE_i$}{$\VE_i$}
%
\replacementPage{21}{$\B=(\M,\T),\F,\G,\E$}{$\B=\T,\F,\G,\E$}
%
\replacementPage{21}{\begin{equation} % value variable
\label{varexp-rule}
\frac{\C(\longvar)\succ\tau}
{\C\ts\longvar\ra\tau}
\end{equation}}{\begin{equation} % value variable
\label{varexp-rule}
\frac{\C(\longvid) = (\sigma,\is)\qquad\sigma\succ\tau}
{\C\ts\longvid\ra\tau}
\end{equation}}
%
\deletionPage{21}{\begin{equation} % value constructor
\label{conexp-rule}
\frac{\C(\longcon)\succ\tau}
{\C\ts\longcon\ra\tau}
\end{equation}
\begin{equation} % exception constant
%\label{exconexp-rule}
\frac{\C(\longexn)=\tau}
{\C\ts\longexn\ra\tau}
\end{equation}}
%
\replacementPage{21}{\begin{equation} % local declaration
\label{let-rule}
\frac{\C\ts\dec\ra\E\qquad\C\oplus\E\ts\exp\ra\tau}
{\C\ts\letexp\ra\tau}\index{27.1}
\end{equation}}{\begin{equation} % local declaration
\label{let-rule}
\frac{\C\ts\dec\ra\E\qquad\C\oplus\E\ts\exp\ra\tau\qquad\TyNamesFcn\tau\subseteq\of{\T}{\C}}
{\C\ts\letexp\ra\tau}\index{27.1}
\end{equation}}
%
\replacementPage{22}{\item{(\ref{varexp-rule}),(\ref{conexp-rule})}
The instantiation of
type schemes allows different occurrences of a single $\longvar$
or $\longcon$ to assume different types.}{\item{(\ref{varexp-rule})}
The instantiation of
type schemes allows different occurrences of a single $\longvid$
to assume different types. Note that the identifier status is not
used in this rule.}
%
\insertionPage{22}{The side condition
prevents type names generated by $\dec$ from escaping outside the local declaration.}
%
\replacementPage{23}{
\begin{equation} % mrule
%\label{mrule-rule}
\frac{\C\ts\pat\ra(\VE,\tau)\qquad\C+\VE\ts\exp\ra\tau'}
{\C\ts\longmrule\ \ra\tau\rightarrow\tau'}
\end{equation}}{\begin{equation} % mrule
\label{mrule-rule}
\frac{\C\ts\pat\ra(\VE,\tau)\qquad\C+\VE\ts\exp\ra\tau'\qquad\TyNamesFcn\VE\subseteq\of{\T}{\C}}
{\C\ts\longmrule\ \ra\tau\rightarrow\tau'}
\end{equation}}
%
\replacementPage{23}{
\begin{equation} % value declaration
\label{valdec-rule}
\frac{\plusmap{\C}{\U}\ts\valbind\ra\VE\qquad
\VE'=\cl{\C,\valbind}{\VE}\qquad
\U\cap\TyVarFcn\VE'=\emptyset}
{\C\ts\valdecS\ra\VE'\ \In\ \Env}\index{28.2}
\end{equation}}{\begin{equation} % value declaration
\label{valdec-rule}
\frac{\begin{array}{l}
U = \TyVarsFcn (\tyvarseq)\\
\plusmap{\C}{\U}\ts\valbind\ra\VE\qquad
\VE'=\cl{\C,\valbind}{\VE}\qquad
\U\cap\TyVarFcn\VE'=\emptyset
\end{array}}
{\C\ts\boxml{val $\tyvarseq$ $\valbind$}\ra\VE'\ \In\ \Env}\index{28.2}
\end{equation}}
%
\replacementPage{23}{\CE}{\VE'}
%
\insertionPage{23}{\begin{equation} % datatype replication
\label{datatyperepldec-rule}
\frac{\C(\longtycon) = (\typefcn,\VE)\quad
\typefcn = \typefcnk\quad
\tyvarseq = \alphak\quad
\TE=\{\tycon\mapsto(\typefcn,\VE)\}
}
{\C\ts\datatyperepldec\ra(\VE,\TE)\ \In\ \Env}
\end{equation}}
%
\replacementPage{23}{\CE}{\VE'}
%
\replacementPage{23}{\begin{equation} % exception declaration
\label{exceptiondec-rule}
\frac{\C\ts\exnbind\ra\EE\quad\VE=\EE }
{\C\ts\exceptiondec\ra(\VE,\EE)\ \In\ \Env }
\end{equation}}{\begin{equation} % exception declaration
\label{exceptiondec-rule}
\frac{\C\ts\exnbind\ra\VE}
{\C\ts\exceptiondec\ra\VE\ \In\ \Env }
\end{equation}}
%
\replacementPage{24}{\begin{equation} % open declaration
%\label{open-dec-rule}
\frac{ \C(\longstrid_1)=(\m_1,\E_1)
\quad\cdots\quad
\C(\longstrid_n)=(\m_n,\E_n) }
{ \C\ts\openstrdec\ra \E_1 + \cdots + \E_n }
\end{equation}}{\begin{equation} % open declaration
%\label{open-dec-rule}
\frac{ \C(\longstrid_1)= \E_1
\quad\cdots\quad
\C(\longstrid_n)= \E_n }
{ \C\ts\openstrdec\ra \E_1 + \cdots + \E_n }
\end{equation}}
%
\replacementPage{24}{The closure of $\VE$ is exactly what allows variables to
be used polymorphically, via rule~\ref{varexp-rule}.}{The closure of $\VE$
allows value identifiers to
be used polymorphically, via rule~\ref{varexp-rule}.}
%
\replacementPage{24}{Moreover, $\U$ is the set of explicit type variables scoped at this particular
occurrence of $\valdec$, cf. Section~\ref{scope-sec},
page~\pageref{scope-def-lab}. The side-condition on $\U$
ensures that these explicit type variables are bound by the closure
operation.}{The side-condition on $\U$
ensures that the type variables in $\tyvarseq$ are bound
by the closure operation,
if they occur free in the range of $\VE$.}
%
\replacementPage{24}{On the other hand, no {\sl other} explicit type variable occurring
free in $\VE$ will become bound, since it must be in $\of{\U}{\C}$, and
is therefore excluded from closure by the definition of the closure operation
(Section~\ref{closure-sec}, page~\pageref{clos-def-lab})
since $\of{\U}{\C}\subseteq\TyVarFcn\C$.}{On the other hand,
if the phrase $\boxml{val}\,\tyvarseq\,\valbind$ occurs inside
some larger value binding $\boxml{val}\,\tyvarseq'\,\valbind'$
then no type variable $\alpha$ listed in $\tyvarseq'$ will become
bound by the $\cl{\C,\valbind}{\VE}$ operation; for $\alpha$ must
be in $\of{\U}{\C}$ and hence excluded from closure by the definition of the closure operation
(Section~\ref{closure-sec}, page~\pageref{clos-def-lab})
since $\of{\U}{\C}\subseteq\TyVarFcn\C$.}
%
\insertionPage{24}{\item{(\ref{datatyperepldec-rule})}
Note that no new type name is generated (i.e., datatype replication is
not generative).
By the syntactic restriction in Section~\ref{synres.sec} the two type
variable sequences in the conclusion must be equal.}
%
\replacementPage{24}{$\EE$}{$\VE$}
%
\replacementPage{24}{names}{constructors}
%
\deletionPage{24}{
Note that $\EE$ is also recorded in the {\VarEnv} component of
the resulting environment (see Section~\ref{stat-proj}, page~\pageref{stat-proj}).\index{29.0}}
%
\replacementPage{24}{
\begin{equation} % recursive value binding
\label{recvalbind-rule}
\frac{\C+\VE\ts\valbind\ra\VE}
{\C\ts\recvalbind\ra\VE}
\end{equation}}{\begin{equation} % recursive value binding
\label{recvalbind-rule}
\frac{\C+\VE\ts\valbind\ra\VE\qquad\TyNamesFcn\VE\subseteq\of{\T}{\C}}
{\C\ts\recvalbind\ra\VE}
\end{equation}}
%
\insertionPage{25}{Also note that $\C+\VE$ may overwrite
identifier status. For example, the program
{\tt datatype t = f; val rec f = fn x => x;}~~ is legal.}
%
\replacementPage{25}{\begin{equation} % datatype binding
\frac{\begin{array}{c}
\tyvarseq=\alphak\qquad\C,\alphakt\ts\constrs\ra\CE\\
\langle\C\ts\datbind\ra\VE,\TE\qquad
\forall(\t',\CE)\in\Ran\TE, \t\neq\t'\rangle
\end{array}
}
{\begin{array}{c}
\C\ts\longdatbind\ra\\
\qquad\qquad\qquad\cl{}{\CE}\langle +\ \VE\rangle,\
\{\tycon\mapsto(\t,\cl{}{\CE})\}\ \langle +\ \TE\rangle
\end{array}
}\index{30.1}
\end{equation}}{\begin{equation} % datatype binding
\frac{\begin{array}{c}
\tyvarseq=\alphak\qquad\C,\alphakt\ts\constrs\ra\VE\\
\langle\C\ts\datbind'\ra\VE',\TE'\qquad
\forall(\t',\VE'')\in\Ran\TE', \t\neq\t'\rangle
\end{array}
}
{\begin{array}{l}
\C\ts\newlongdatbind\ra\\
\qquad(\cl{}{\VE}\langle +\ \VE'\rangle,\
\{\tycon\mapsto(\t,\cl{}{\VE})\}\ \langle +\ \TE'\rangle
\end{array}
}\index{30.1}
\end{equation}}
%
\replacementPage{25}{The syntactic restrictions ensure $\Dom\VE\cap\Dom\CE = \emptyset$
and $\tycon\notin\Dom\TE$.}{The syntactic restrictions ensure $\Dom\VE\cap\Dom\VE' = \emptyset$
and $\tycon\notin\Dom\TE'$.}
%
\replacementPage{25}{\rulesec{Constructor Bindings}{\C,\tau\ts\constrs\ra\CE}}{\rulesec{Constructor Bindings}{\C,\tau\ts\constrs\ra\VE}}
%
\replacementPage{25}{\begin{equation} % data constructors
%\label{constrs-rule}
\frac{\langle\C\ts\ty\ra\tau'\rangle\qquad
\langle\langle\C,\tau\ts\constrs\ra\CE\rangle\rangle }
{\begin{array}{c}
\C,\tau\ts\longerconstrs\ra\\
\qquad\qquad\qquad\{\con\mapsto\tau\}\
\langle +\ \{\con\mapsto\tau'\to\tau\}\ \rangle\
\langle\langle +\ \CE\rangle\rangle
\end{array}
}\index{30.2}
\end{equation}}{\begin{equation} % data constructors
%\label{constrs-rule}
\frac{\langle\C\ts\ty\ra\tau'\rangle\qquad
\langle\langle\C,\tau\ts\constrs\ra\VE\rangle\rangle }
{\begin{array}{c}
\C,\tau\ts\longervidconstrs\ra\\
\qquad\qquad\qquad\{\vid\mapsto(\tau,\isc)\}\
\langle +\ \{\vid\mapsto(\tau'\to\tau,\isc)\}\ \rangle\
\langle\langle +\ \VE\rangle\rangle
\end{array}
}\index{30.2}
\end{equation}}
%
\replacementPage{25}{$\con\notin\Dom\CE$.}{$\vid\notin\Dom\VE$.}
%
\replacementPage{25}{
\rulesec{Exception Bindings}{\C\ts\exnbind\ra\EE}}{
\rulesec{Exception Bindings}{\C\ts\exnbind\ra\VE}}
%
\replacementPage{26}{\begin{equation} % exception binding
\label{exnbind1-rule}
\frac{\langle\C\ts\ty\ra\tau\quad\mbox{$\tau$ is imperative}\rangle\qquad
\langle\langle\C\ts\exnbind\ra\EE\rangle\rangle }
{\begin{array}{c}
\C\ts\longexnbinda\ra\\
\qquad\qquad\qquad\{\exn\mapsto\EXCN\}\
\langle +\ \{\exn\mapsto\tau\rightarrow\EXCN\}\ \rangle\
\langle\langle +\ \EE\rangle\rangle
\end{array}
}\index{30.3}
\end{equation}}{\begin{equation} % exception binding
\label{exnbind1-rule}
\frac{\langle\C\ts\ty\ra\tau\rangle\qquad
\langle\langle\C\ts\exnbind\ra\VE\rangle\rangle }
{\begin{array}{l}
\C\ts\longvidexnbinda\ra\\
\qquad\{\vid\mapsto(\EXCN,\ise)\}\
\langle +\ \{\vid\mapsto(\tau\rightarrow\EXCN,\ise)\}\ \rangle\
\langle\langle +\ \VE\rangle\rangle
\end{array}
}\index{30.3}
\end{equation}}
%
\replacementPage{26}{\begin{equation} % exception binding
\label{exnbind2-rule}
\frac{\C(\longexn)=\tau\qquad
\langle\C\ts\exnbind\ra\EE\rangle }
{\C\ts\longexnbindb\ra\{\exn\mapsto\tau\}\ \langle +\ \EE\rangle}
\end{equation}}{\begin{equation} % exception binding
\label{exnbind2-rule}
\frac{\C(\longvid)=(\tau,\ise)\qquad
\langle\C\ts\exnbind\ra\VE\rangle }
{\C\ts\longvidexnbindb\ra\{\vid\mapsto(\tau,\ise)\}\ \langle +\ \VE\rangle}
\end{equation}}
%
\replacementPage{26}{\item{(\ref{exnbind1-rule})} Notice that $\tau$ must not contain
any applicative type variables.}{\item{(\ref{exnbind1-rule})} Notice that $\tau$ may contain
type variables.}
%
\replacementPage{26}{
There is a unique $\EE$, for each $\C$ and $\exnbind$,
such that $\C\ts\exnbind\ra\EE$.}{For each $\C$ and $\exnbind$,
there is at most one $\VE$ satisfying $\C\ts\exnbind\ra\VE$.}
%
\replacementPage{26}{
\begin{equation} % variable pattern
\label{varpat-rule}
\frac{}
{\C\ts\var\ra (\{\var\mapsto\tau\},\tau) }
\end{equation}}{\begin{equation} % variable pattern
\label{varpat-rule}
\frac{\hbox{$\vid\notin\Dom(\C)$ or $\of{\is}{C(\vid)} = \isv$}}
{\C\ts\vid\ra (\{\vid\mapsto(\tau,\isv)\},\tau) }
\end{equation}}
%
\replacementPage{26}{
\begin{equation} % constant pattern
%\label{constpat-rule}
\frac{\C(\longcon)\succ\tauk\t }
{\C\ts\longcon\ra (\emptymap,\tauk\t)}
\end{equation}}{\begin{equation} % constant pattern
\label{constpat-rule}
\frac{\C(\longvid)=(\sigma,\is)\qquad\is\neq\isv\qquad\sigma\succ\tauk\t }
{\C\ts\longvid\ra (\emptymap,\tauk\t)}
\end{equation}}
%
\deletionPage{26}{
\begin{equation} % exception constant
%\label{exconapat-rule}
\frac{\C(\longexn)=\EXCN}
{\C\ts\longexn\ra (\emptymap,\EXCN)}
\end{equation}}
%
\replacementPage{26}{\item{(\ref{varpat-rule})}
Note that $\var$ can assume a type, not a general type scheme.}{\item{(\ref{varpat-rule}), (\ref{constpat-rule})} The context $\C$ determines which of these
two rules applies. In rule~\ref{varpat-rule}, note that
$\vid$ can assume a type, not a general type scheme.}
%
\replacementPage{27}{\begin{equation} % record component
\label{longlab-rule}
\frac{\C\ts\pat\ra(\VE,\tau)\qquad
\langle\C\ts\labpats\ra(\VE',\varrho)\qquad\lab\notin\Dom\varrho\rangle
}
{\C\ts\longlabpats\ra
(\VE\langle +\ \VE'\rangle,\
\{\lab\mapsto\tau\}\langle +\ \varrho\rangle) }
\end{equation}}{\begin{equation} % record component
\label{longlab-rule}
\frac{\begin{array}{c}\C\ts\pat\ra(\VE,\tau)\\
\langle\C\ts\labpats\ra(\VE',\varrho)\qquad\Dom\VE\cap\Dom\VE' = \emptyset\qquad\lab\notin\Dom\varrho\rangle
\end{array}
}
{\C\ts\longlabpats\ra
(\VE\langle +\ \VE'\rangle,\
\{\lab\mapsto\tau\}\langle +\ \varrho\rangle) }
\end{equation}}
%
\deletionPage{27}{\comment
\begin{description}
\item{(\ref{longlab-rule})}
By the syntactic restrictions, $\Dom\VE\cap\Dom\VE' = \emptyset$.
\end{description}}
%
\replacementPage{27}{
\begin{equation} % construction pattern
%\label{conpat-rule}
\frac{\C(\longcon)\succ\tau'\to\tau\qquad\C\ts\atpat\ra(\VE,\tau')}
{\C\ts\conpat\ra (\VE,\tau)}
\end{equation}}{\begin{equation} % construction pattern
%\label{conpat-rule}
\frac{\C(\longvid) = (\sigma, \is)\qquad\is\neq\isv\qquad \sigma\succ\tau'\to\tau\qquad\C\ts\atpat\ra(\VE,\tau')}
{\C\ts\vidpat\ra (\VE,\tau)}
\end{equation}}
%
\deletionPage{27}{
\begin{equation} % exception construction pattern
%\label{exconpat-rule}
\frac{\C(\longexn)=\tau\rightarrow\EXCN\qquad
\C\ts\atpat\ra(\VE,\tau)}
{\C\ts\exconpat\ra(\VE,\EXCN)}
\end{equation}}
%
\replacementPage{27}{
\begin{equation} % layered pattern
\label{layeredpat-rule}
\frac{\begin{array}{c}
\C\ts\var\ra(\VE,\tau)\qquad\langle\C\ts\ty\ra\tau\rangle\\
\C\ts\pat\ra(\VE',\tau)
\end{array}
}
{\C\ts\layeredpat\ra(\plusmap{\VE}{\VE'},\tau)}
\end{equation}}{\begin{equation} % layered pattern
\label{layeredpat-rule}
\frac{\begin{array}{c}
\hbox{$\vid\notin\Dom(\C)$ or $\of{\is}{C(\vid)} = \isv$}\\
\langle\C\ts\ty\ra\tau\rangle\qquad
\C\ts\pat\ra(\VE,\tau)\qquad \vid\notin\Dom\VE
\end{array}
}
{\C\ts\layeredvidpat\ra(\plusmap{\{\vid\mapsto(\tau,\isv)\}}{\VE},\tau)}
\end{equation}}
%
\deletionPage{27}{\comments
\begin{description}
\item{(\ref{layeredpat-rule})}
By the syntactic restrictions, $\Dom\VE\cap\Dom\VE' = \emptyset$.
\end{description}}
%
\replacementPage{27}{\CE}{\VE}
%
\replacementPage{28}{record}{row}
%
\deletionPage{28}{This restriction is necessary to ensure the
existence of principal type schemes.}
%
\insertionPage{28}{-value}
%
\replacementPage{28}{$\var\ \atpat_1\ \cdots\ \atpat_n\langle : \ty\rangle$\ \ml{=}\ $\exp$}{$\vid\ \atpat_1\ \cdots\ \atpat_n\langle : \ty\rangle$\ \ml{=}\ $\exp$}
%
\deletionPage{28}{
\subsection{Principal Environments}
\label{principal-env-sec}
The\index{33.15} notion of {\sl enrichment}, $\E\succ\E'$, between environments
$\E=(\SE,\TE,\VE,\EE)$ and $\E'=(\SE',\TE',\VE',\EE')$ is defined
in Section~\ref{enrichment-sec}. For the present section, $\E\succ\E'$
may be taken to mean $\SE=\SE'=\emptymap$, $\TE=\TE'$,
$\EE=\EE'$, $\Dom\VE=\Dom\VE'$ and, for each $\id\in\Dom\VE$,
$\VE(\id)\succ\VE'(\id)$.
Let\index{33.2} $\C$ be a context, and suppose that $\C\ts\dec\ra\E$
according to the preceding Inference Rules. Then $E$ is {\em principal}
(for $\dec$ in the context $\C$) if, for all $\E'$ for
which $\C\ts\dec\ra\E'$, we have $\E\succ\E'$. We claim that if
$\dec$ elaborates to any environment in $\C$ then it elaborates to
a principal environment in $\C$. Strictly, we must allow for the
possibility that type names and imperative
type variables
which do not occur in $\C$ are chosen
differently for $\E$ and $\E'$.
The stated claim is therefore made up to such variation.
}
%
\replacementPage{29}{
\begin{displaymath}
\begin{array}{rcl}
\M & \in & \StrNameSets = \Fin(\StrNames)\\
\N\ {\rm or}\ (\M,\T)
& \in & \NameSets = \StrNameSets\times\TyNameSets\\
\sig\ {\rm or}\ \longsig{}
& \in & \Sig = \NameSets\times\Str \\
\funsig\ {\rm or}\ \longfunsig{}
& \in & \FunSig = \NameSets\times
(\Str\times\Sig)\\
\G & \in & \SigEnv = \finfun{\SigId}{\Sig} \\
\F & \in & \FunEnv = \finfun{\FunId}{\FunSig} \\
\B\ {\rm or}\ \N,\F,\G,\E
& \in & \Basis = \NameSets\times
\FunEnv\times\SigEnv\times\Env\\
\end{array}
\end{displaymath}}{\begin{displaymath}
\begin{array}{rcl}
\sig\ {\rm or}\ \newlongsig{}
& \in & \Sig = \TyNameSets\times\Env \\
\funsig\ {\rm or}\ \newlongfunsig{}
& \in & \FunSig = \TyNameSets\times
(\Env\times\Sig)\\
\G & \in & \SigEnv = \finfun{\SigId}{\Sig} \\
\F & \in & \FunEnv = \finfun{\FunId}{\FunSig} \\
\B\ {\rm or}\ \T,\F,\G,\E
& \in & \Basis = \TyNameSets\times
\FunEnv\times\SigEnv\times\Env\\
\end{array}
\end{displaymath}}
%
\replacementPage{29}{
The prefix $(\N)$, in signatures and functor signatures, binds both type names
and structure names. We shall always consider a set $\N$ of names as
partitioned into a pair $(\M,\T)$ of sets of the two kinds of name.}{The
prefix $(\T)$, in signatures and functor signatures, binds type names.}
%
\deletionPage{29}{It is sometimes convenient to work with an arbitrary semantic object $A$, or
assembly $A$ of such objects.
As with the function $\TyNamesFcn$,
$\StrNamesFcn(A)$ and $\NamesFcn(A)$ denote respectively the set of structure names
and the set of names occurring free in $A$.}
%
\replacementPage{29}{Section~\ref{realisation-sec}}{Section~\ref{tyrea.sec}}
%
\deletionPage{29}{imperative, }
%
\deletionPage{29}{For any structure $\S=\longS{}$ we call $m$ the {\sl structure name} or
{\sl name} of $\S$; also, the {\sl proper substructures} of $\S$ are
the members of $\Ran\SE$ and their proper substructures. The
{\sl substructures} of
$\S$ are $\S$ itself and its proper substructures. The structures
{\sl occurring in}
an object or assembly $A$ are the structures and
substructures from which it is built.}
%
\replacementPage{29}{$\of{\N}{\B}$}{$\of{\T}{\B}$}
%
\deletionPage{29}{and
structure names }
%
\replacementPage{29}{$\B+(\NamesFcn\SE,\SE)$}{$\B+(\TyNamesFcn\SE,\SE)$}
%
\insertionPage{29}{
There is no separate kind of semantic object to represent structures:
structure expressions elaborate to environments, just as structure-level
declarations do. Thus, notions which are commonly associated with structures
(for example the notion of matching a structure against a signature) are defined
in terms of environments.}
%
\deletionPage{29}{
\subsection{Consistency}
\label{consistency-sec}
A\index{35.1} set of type structures is said to be {\sl consistent} if, for all
$(\theta_1,\CE_1)$ and $(\theta_2,\CE_2)$ in the set, if $\theta_1 = \theta_2$
then
\[\CE_1=\emptymap\ {\rm or}\
\CE_2=\emptymap\ {\rm or}\ \Dom\CE_1=\Dom\CE_2\]
A semantic object $A$ or assembly $A$ of objects is said to be
{\sl consistent} if (after changing bound names to make all nameset prefixes
in $A$ disjoint)
for all $\S_1$ and
$\S_2$ occurring in $A$ and for every $\longstrid$
and every $\longtycon$
\begin{enumerate}
\item If $\of{\m}{\S_1}=\of{\m}{\S_2}$, and both
$\S_1(\longstrid)$ and $\S_2(\longstrid)$ exist, then
\[ \of{\m}{\S_1(\longstrid)}\ =\ \of{\m}{\S_2(\longstrid)}\]
\item If $\of{\m}{\S_1}=\of{\m}{\S_2}$, and both
$\S_1(\longtycon)$ and $\S_2(\longtycon)$ exist, then
\[ \of{\theta}{\S_1(\longtycon)}\ =\ \of{\theta}{\S_2(\longtycon)}\]
\item The set of all type structures in $A$ is consistent
\end{enumerate}
As an example, a functor signature
$\longfunsig{}$ is
consistent if, assuming first that
$\N\cap\N'=\emptyset$,
the assembly $A=\{\S,\S'\}$ is consistent.
We may loosely say that two
structures $\S_1$ and $\S_2$
are consistent if
$\{\S_1,\S_2\}$ is consistent, but must remember that this is stronger than
the assertion that $\S_1$ is consistent and $\S_2$ is consistent.
Note that if $A$ is a consistent assembly and $A'\subset A$ then $A'$ is
also a consistent assembly.
}
%
\deletionPage{29}{
\subsection{Well-formedness}
A signature\index{35.2} $\longsig{}$ is {\sl well-formed}
if $\N\subseteq\NamesFcn\S$,
and also, whenever $(\m,\E)$ is a
substructure of $\S$ and $\m\notin\N$, then $\N\cap(\NamesFcn\E)=\emptyset$.
A functor signature $\longfunsig{}$ is {\sl well-formed} if
$\longsig{}$ and $(\N')\S'$ are well-formed, and also, whenever
$(\m',\E')$ is a substructure of $\S'$ and $\m'\notin\N\cup\N'$,
then $(\N\cup\N')\cap(\NamesFcn\E')=\emptyset$.
An object or assembly $A$ is {\sl well-formed} if every type environment,
signature and functor signature occurring in $A$ is well-formed.}
%
\deletionPage{29}{\subsection{Cycle-freedom}
An\index{35.3} object or assembly $A$ is {\sl cycle-free} if it contains no
cycle of structure names; that is, there is no sequence
\[\m_0,\cdots,\m_{k-1},\m_k=m_0\ \ (k>0)\]
of structure names such that, for each $i\ (0\leq i<k)$ some structure
with name $m_i$ occurring in $A$ has a proper substructure with name
$m_{i+1}$.
}
%
\deletionPage{29}{
\subsection{Admissibility}
\label{admis-sec}
An\index{36.1} object or assembly $A$ is {\sl admissible} if it is
consistent, well-formed and cycle-free.
Henceforth it is assumed
that
all objects mentioned are admissible.
We also require that
\begin{enumerate}
\item In every sentence $A\ts\phrase\ra A'$ inferred by the rules
given in Section~\ref{statmod-rules-sec}, the assembly $\{A,A'\}$ is
admissible.
\item In the special case of a sentence $\B\ts\sigexp\ra\S$,
we further require that the assembly consisting of all semantic
objects occurring in the entire inference of this sentence be
admissible. This is important for the definition of principal
signatures in Section~\ref{prinsig-sec}.
\end{enumerate}
In our semantic definition we have not undertaken to
indicate how admissibility should be checked in an implementation.
}
%
\replacementPage{29}{
A {\sl type realisation}\index{36.2} is a map
$\tyrea:\TyNames\to\TypeFcn$
such that
$\t$ and $\tyrea(\t)$ have the same arity, and
if $t$ admits equality then so does $\tyrea(\t)$.
The {\sl support} $\Supp\tyrea$ of a type realisation $\tyrea$ is the set of
type names $\t$ for which $\tyrea(\t)\ne\t$.}{A
{\sl (type) realisation}\index{36.2} is a map
$\rea:\TyNames\to\TypeFcn$
such that
$\t$ and $\rea(\t)$ have the same arity, and
if $t$ admits equality then so does $\rea(\t)$.
The {\sl support} $\Supp\rea$ of a type realisation $\rea$ is the set of
type names $\t$ for which $\rea(\t)\ne\t$.}
%
\deletionPage{29}{\subsection{Realisation}
\label{realisation-sec}
A {\sl realisation}\index{36.3} is a function $\rea$ of names,
partitioned into a type realisation $\tyrea:\TyNames\to\TypeFcn$
and a function $\strrea : \StrNames\to\StrNames$.
The {\sl support} $\Supp\rea$
of a realisation $\rea$ is the set of
names $\n$ for which $\rea(\n)\ne\n$.}
%
\replacementPage{29}{The {\sl yield}
$\Yield\rea$ of a realisation $\rea$ is the set of
names which occur in some $\rea(\n)$ for which $\n\in\Supp\rea$.}{The
{\sl yield} $\Yield\rea$ of a realisation $\rea$ is the set of
type names which occur in some $\rea(\t)$ for which $\t\in\Supp\rea$.}
%
\replacementPage{29}{$n$ by $\rea(\n)$}{$\t$ by $\rea(\t)$}
%
\replacementPage{30}{$\longsig{}$}{$\newlongsig{}$}
%
\replacementPage{30}{$(\N)$}{$(\T)$}
%
\replacementPage{30}{
\[\N\cap(\Supp\rea\cup\Yield\rea)=\emptyset\ .\]}{\[\T\cap(\Supp\rea\cup\Yield\rea)=\emptyset\ .\]}
%
\deletionPage{30}{
\subsection{Type Explication}
\label{type-explication-sec}
A\index{36.35} signature $(\N)\S$ is {\sl type-explicit\/} if,
whenever $\t\in\N$ and occurs free in $\S$, then some substructure of
$\S$ contains a type environment $\TE$ such that
$\TE(\tycon)=(\t,\CE)$ for some $\tycon$ and some $\CE$.}
%
\replacementPage{30}{
A\index{36.4} structure $\S_2$ {\sl is an instance of} a signature
$\sig_1=\longsig{1}$,
written $\siginst{\sig_1}{}{\S_2}$, if there exists a realisation
$\rea$
such that $\rea(\S_1)=\S_2$ and $\Supp\rea\subseteq\N_1$.}{An\index{36.4} environment $\E_2$ {\sl is an instance of} a signature
$\sig_1=\newlongsig{1}$,
written $\siginst{\sig_1}{}{\E_2}$, if there exists a realisation
$\rea$
such that $\rea(\E_1)=\E_2$ and $\Supp\rea\subseteq\T_1$.}
%
\deletionPage{30}{(Note that if $\sig_1$ is type-explicit then there is at most one
such $\rea$.)}
%
\deletionPage{30}{A signature
$\sig_2=\longsig{2}$ {\sl is an instance of}
$\sig_1 =\longsig{1}$,
written $\siginst{\sig_1}{}{\sig_2}$, if
$\siginst{\sig_1}{}{\S_2}$ and $\N_2\cap(\NamesFcn\sig_1)=\emptyset$.
It can be shown that $\siginst{\sig_1}{}{\sig_2}$ iff, for all $\S$,
whenever $\siginst{\sig_2}{}{\S}$ then $\siginst{\sig_1}{}{\S}$.}
%
\replacementPage{30}{
A\index{36.5} pair $(\S,(\N')\S')$ is called a {\sl functor instance}.
Given $\funsig=\longfunsig{1}$,
a functor instance $(\S_2,(\N_2')\S_2')$ is an {\sl instance} of
$\funsig$,
written $\funsiginst{\funsig}{}{(\S_2,(\N_2')\S_2')}$,
if there exists a realisation $\rea$
such that
$\rea(\S_1,(\N_1')\S_1')=(\S_2,(\N_2')\S_2')$ and
$\Supp\rea\subseteq\N_1$.}{
A\index{36.5} pair $(\E,(\T')\E')$ is called a {\sl functor instance}.
Given $\funsig=\newlongfunsig{1}$,
a functor instance $(\E_2,(\T_2')\E_2')$ is an {\sl instance} of
$\funsig$,
written $\funsiginst{\funsig}{}{(\E_2,(\T_2')\E_2')}$,
if there exists a realisation $\rea$
such that
$\rea(\E_1,(\T_1')\E_1')=(\E_2,(\T_2')\E_2')$ and
$\Supp\rea\subseteq\T_1$.}
%
\replacementPage{30}{a structure}{an environment}
%
\replacementPage{30}{structure}{environment}
%
\deletionPage{30}{structures, }
%
\replacementPage{30}{by mutual recursion}{recursively}
%
\deletionPage{30}{A structure $\S_1=(\m_1,\E_1)$
{\sl enriches} another structure
$\S_2=(\m_2,\E_2)$, written $\S_1\succ\S_2$, if
\begin{enumerate}
\item $\m_1=\m_2$
\item $\E_1\succ\E_2$
\end{enumerate}}
%
\replacementPage{30}{$\E_1=\longE{1}$}{$\E_1=\newlongE{1}$}
%
\replacementPage{30}{$\E_2=$ $\longE{2}$}{$\E_2=
( \SE_2,$\linebreak$\TE_2,\VE_2)$}
%
\replacementPage{30}{$\Dom\VE_1\supseteq\Dom\VE_2$, and $\VE_1(\id)\succ\VE_2(\id)$
for all $\id\in\Dom\VE_2$}{$\Dom\VE_1\supseteq\Dom\VE_2$, and $\VE_1(\vid)\succ\VE_2(\vid)$
for all $\vid\in\Dom\VE_2$,
where $(\sigma_1,\is_1)\succ(\sigma_2,\is_2)$ means $\sigma_1\succ\sigma_2$ and
$$\is_1 = \is_2\quad\hbox{or}\quad \is_2 = \isv$$}
%
\deletionPage{30}{
\item $\Dom\EE_1\supseteq\Dom\EE_2$, and $\EE_1(\exn)=\EE_2(\exn)$
for all $\exn\in\Dom\EE_2$}
%
\replacementPage{30}{\CE}{\VE}
%
\replacementPage{30}{\CE}{\VE}
%
\replacementPage{30}{\CE}{\VE}
%
\replacementPage{30}{\CE}{\VE}
%
\replacementPage{30}{\CE}{\VE}
%
\replacementPage{30}{\CE}{\VE}
%
\replacementPage{30}{\CE}{\VE}
%
\replacementPage{30}{
A\index{37.2} structure $\S$ {\sl matches} a signature $\sig_1$ if there exists
a structure $\S^-$ such that $\sig_1\geq\S^-\prec\S$. Thus matching
is a combination of instantiation and enrichment. There is at most
one such $\S^-$, given $\sig_1$ and $\S$.}{An\index{37.2} environment $\E$ {\sl matches} a signature $\sig_1$ if there exists
an environment $\E^-$ such that $\sig_1\geq\E^-\prec\E$. Thus matching
is a combination of instantiation and enrichment. There is at most
one such $\E^-$, given $\sig_1$ and $\E$.}
%
\deletionPage{30}{Moreover, writing $\sig_1=
\longsig{1}$, if $\sig_1\geq\S^-$ then there exists a realisation $\rea$
with $\Supp\rea\subseteq\N_1$ and $\rea(\S_1)=\S^-$.
We shall then say that $\S$ matches $\sig_1$ {\em via} $\rea$.
(Note that if $\sig_1$ is type-explicit
then $\rea$ is uniquely determined by $\sig_1$ and $\S$.)}
%
\deletionPage{30}{A\index{37.2.5} signature $\sig_2$ {\em matches} a signature $\sig_1$
if for all structures $\S$, if $\S$ matches $\sig_2$ then $\S$
matches $\sig_1$. It can be shown that $\sig_2=\longsig{2}$ matches
$\sig_1=\longsig{1}$ if and only if there exists a realisation
$\rea$ with $\Supp\rea\subseteq\N_1$ and $\rea(\S_1)\prec\S_2$
and $\N_2\cap\NamesFcn\sig_1=\emptyset$.}
%
\deletionPage{30}{\subsection{Principal Signatures}
\label{prinsig-sec}
The definitions in this section concern the elaboration of signature
expressions; more precisely they concern inferences of sentences of the
form $\B\ts\sigexp\ra\S$, where $\S$ is a structure and $\B$ is a basis.
Recall, from Section~\ref{admis-sec}, that the assembly of all semantic
objects in such an inference must be admissible.
For any basis $\B$ and any structure $\S$,
we say that $\B$ {\sl covers} $\S$
if for every substructure $(m,E)$ of $\S$ such that
$m\in\of{\N}{\B}$:
\begin{enumerate}
\item
For every structure identifier $\strid\in\Dom\E$,
$\B$ contains a substructure $(m,\E')$ with $m$
free and $\strid\in\Dom\E'$
\item
For every type constructor $\tycon\in\Dom\E$,
$\B$ contains a substructure $(m,\E')$ with $m$ free
and $\tycon\in\Dom\E'$
\end{enumerate}
(This condition is not a consequence of consistency of $\{\B,\S\}$;
informally, it states that if $\S$ shares a substructure with $\B$,
then $\S$ mentions no more components of the substructure than
$\B$ does.)
We\index{38.1} say that a signature
$\longsig{}$ is {\sl principal for $\sigexp$ in $\B$} if, choosing $\N$
so that $(\of{\N}{\B})\cap\N=\emptyset$,
\begin{enumerate}
\item $\B$ covers $\S$
\item $\B\vdash\sigexp\ra\S$
\item Whenever $\B\vdash\sigexp\ra\S'$, then $\sigord{\longsig{}}{}{\S'}$
\end{enumerate}
We claim that if $\sigexp$ elaborates in $\B$ to some structure covered
by $\B$, then it possesses a principal signature in $\B$.
Analogous to the definition given for type environments in
Section~\ref{typeenv-wf-sec}, we say that a semantic object $A$
{\sl respects equality} if every type environment occurring in
$A$ respects equality.
%
%
%Further, let $T$ be the set of type names
%$\t$ such that $(\t,\CE)$ occurs in $A$ for some
%$\CE\neq\emptymap$. Then $A$ is said to {\sl maximise equality}
%if (a) $A$ respects equality, and also (b) if any larger subset of
%$T$ were to admit equality (without any change in the equality
%attribute of any type names not in $T$) then $A$ would cease to
%respect equality.
%
\oldpagebreak
Now\index{38.5} let us assume that $\sigexp$ possesses a principal signature
$\sig_0=\longsig{0}$ in $B$. We wish to
define, in terms of $\sig_0$, another signature $\sig$ which provides more
information about the equality attributes of structures which will
match $\sig_0$. To this end, let $\T_0$ be the set of type names $\t\in\N_0$
which do not admit equality, and such that $(\t,\CE)$ occurs in $\S_0$
for some $\CE\neq\emptymap$. Then we say $\sig$ is
{\sl equality-principal for $\sigexp$ in $\B$} if
\begin{enumerate}
\item
$\sig$ respects equality
\item
$\sig$ is obtained from $\sig_0$ just by making as many
members of $\T_0$ admit equality as possible, subject to 1.~above
\end{enumerate}
It is easy to show that, if any such $\sig$ exists, it is determined
uniquely by $\sig_0$; moreover, $\sig$ exists if $\sig_0$ itself
respects equality.
\bigskip}
%
\replacementPage{31}{$\B=\N,\F,\G,\E$}{$\B=\T,\F,\G,\E$}
%
\replacementPage{31}{$\NamesFcn\F\ \cup\NamesFcn\G\cup\NamesFcn\E\subseteq\N$}{$\TyNamesFcn\F
\ \cup\TyNamesFcn\G\cup\TyNamesFcn\E\subseteq\T$}
%
\replacementPage{31}{
This is not
the case for bases in which signature expressions and specifications are
elaborated, but the following Theorem can be proved:}{
The following Theorem can be proved:}
%
\replacementPage{31}{
Moreover, if S$'$ is a sentence of the form
$\B''\ts\phrase\ra A$ occurring in a proof of S, where $\phrase$ is
either a structure expression or a structure-level declaration, then $\B''$
also satisfies the condition.}{
Moreover, if S$'$ is a sentence of the form
$\B''\ts\phrase\ra A$ occurring in a proof of S, where $\phrase$ is
any Modules phrase, then $\B''$ also satisfies the condition.}
%
\replacementPage{31}{Finally, if $\T,\U,\E\ts\phrase\ra A$ occurs
in a proof of S, where $\phrase$ is a phrase of the Core, then
$\TyNamesFcn\E\subseteq\T$.}{Finally, if $\T,\U,\E\ts\phrase\ra A$ occurs
in a proof of S, where $\phrase$ is a phrase of Modules or of the Core, then
$\TyNamesFcn\E\subseteq\T$.}
%
\replacementPage{31}{
\rulesec{Structure Expressions}{\B\ts\strexp\ra \S}}
{\rulesec{Structure Expressions}{\B\ts\strexp\ra \E}}
%
\replacementPage{31}{\begin{equation} % generative strexp
\label{generative-strexp-rule}
\frac{\B\ts\strdec\ra\E\qquad\m\notin(\of{\N}{\B})\cup\NamesFcn\E}
{\B\ts\encstrexp\ra(\m,\E)}\index{39.2}
\end{equation}}{\begin{equation} % generative strexp
\label{generative-strexp-rule}
\frac{\B\ts\strdec\ra\E}
{\B\ts\encstrexp\ra \E }\index{39.2}
\end{equation}}
%
\replacementPage{31}{
\begin{equation} % longstrid
%\label{longstrid-strexp-rule}
\frac{\B(\longstrid)=\S}
{\B\ts\longstrid\ra\S}
\end{equation}}{\begin{equation} % longstrid
%\label{longstrid-strexp-rule}
\frac{\B(\longstrid)=\E}
{\B\ts\longstrid\ra\E}
\end{equation}}
%
\insertionPage{31}{
\begin{equation}
\label{transparent-constraint-rule}
\frac{B\ts\strexp\ra\E\quad\B\ts\sigexp\ra\Sigma\quad\Sigma\geq\E'\prec\E}
{\B\ts\transpconstraint\ra\E'}
\end{equation}
}
%
\insertionPage{31}{
\begin{equation}
\label{opaque-constraint-rule}
\frac{\begin{array}{c}
B\ts\strexp\ra\E\quad\B\ts\sigexp\ra(\T')\E'\\
(\T')\E'\geq\E''\prec\E\quad \T' \cap(\of{\T}{\B}) = \emptyset
\end{array}}
{\B\ts\opaqueconstraint\ra\E'}
\end{equation}
}
%
\replacementPage{31}{
\begin{equation} % functor application
\label{functor-application-rule}
\frac{ \begin{array}{c}
\B\ts\strexp\ra\S\\
\funsiginst{\B(\funid)}{}{(\S'',(\N')\S')}\ ,
\ \S\succ\S''\\
(\of{\N}{\B})\cap\N'=\emptyset
\end{array}
}
{\B\ts\funappstr\ra\S'}
\end{equation}}{\begin{equation} % functor application
\label{functor-application-rule}
\frac{ \begin{array}{c}
\B\ts\strexp\ra\E\\
\funsiginst{\B(\funid)}{}{(\E'',(\T')\E')}\ ,
\ \E\succ\E''\\
(\TyNamesFcn \E\; \cup\; \of{\T}{\B})\cap\T'=\emptyset
\end{array}
}
{\B\ts\funappstr\ra\E'}
\end{equation}}
%
\replacementPage{31}{
\begin{equation} % let strexp
\label{letstrexp-rule}
\frac{\B\ts\strdec\ra\E\qquad\B\oplus\E\ts\strexp\ra\S}
{\B\ts\letstrexp\ra\S}
\end{equation}}{\begin{equation} % let strexp
\label{letstrexp-rule}
\frac{\B\ts\strdec\ra\E_1\qquad\B\oplus\E_1\ts\strexp\ra\E_2}
{\B\ts\letstrexp\ra\E_2}
\end{equation}}
%
\deletionPage{32}{
\item{(\ref{generative-strexp-rule})}
The side condition ensures that each generative structure
expression receives a new name. If the expression occurs in
a functor body the structure name will be bound by $(\N')$ in
rule~\ref{funbind-rule}; this will ensure that for each application of the
functor, by rule~\ref{functor-application-rule}, a new distinct name
will be chosen for the structure generated.}
%
\replacementPage{32}{$ (\of{\N}{\B})\cap\N'=\emptyset$}{$(\TyNamesFcn\E \cup \of{\T}{\B})\cap\T'=\emptyset$}
%
\replacementPage{32}{$(\N')S'$}{$(\T')E'$}
%
\replacementPage{32}{structures}{datatypes}
%
\replacementPage{32}{Let $\B(\funid)=(N)(\S_f,(N')\S_f')$.}{Let $\B(\funid)=(\T)(\E_f,(T')\E_f')$.}
%
\replacementPage{32}{Assuming that $(\N)\S_f$ is
type-explicit, the realisation $\rea$ for which
$\rea(\S_f,(N')\S_f')=(\S'',(\N')\S')$ is uniquely determined by $\S$,
since $\S\succ\S''$ can only hold if the type names and structure
names in $\S$ and $\S''$ agree. Recall that enrichment $\succ$ allows
more components and more polymorphism, while instantiation $\geq$ does
not.\par}{Let $\rea$ be a realisation such that\linebreak
$\rea(\E_f,(T')\E_f')=(\E'',(\T')\E')$.}
%
\replacementPage{32}{
Sharing between argument and result specified in the declaration of
the functor $\funid$ is represented by the occurrence of the same name
in both $\S_f$ and $\S_f'$, and this repeated occurrence is preserved
by $\rea$, yielding sharing between the argument structure $\S$ and
the result structure $\S'$ of this functor application.}{
Sharing between argument and result specified in the declaration of
the functor $\funid$ is represented by the occurrence of the same name
in both $\E_f$ and $\E_f'$, and this repeated occurrence is preserved
by $\rea$, yielding sharing between the argument structure $\E$ and
the result structure $\E'$ of this functor application.}
%
\deletionPage{32}{structure
and }
%
\replacementPage{32}{
\begin{equation} % core declaration
\label{dec-rule}
\frac{ \of{\C}{\B}\ts\dec\ra\E
\quad\E\ {\rm principal\ for\ \dec\ in\ } (\of{\C}{\B})
}
{ \B\ts\dec\ra\E }\index{40.2}
\end{equation}}{\begin{equation} % core declaration
\label{dec-rule}
\frac{ \of{\C}{\B}\ts\dec\ra\E
}
{ \B\ts\dec\ra\E }\index{40.2}
\end{equation}}
%
\deletionPage{32}{
\comments
\begin{description}
\item{(\ref{dec-rule})}
The side condition ensures that all type schemes in $\E$ are as
general as possible.
% and that no imperative type variables occur
%free in $\E$.
%from version 1:
% The side condition ensures that all type schemes in $\E$ are as
%general as possible and that all new type names in $\E$ admit
%equality, if possible.
\end{description}}
%
\replacementPage{32}{
\begin{equation} % structure binding
\label{structure-binding-rule}
\frac{ \begin{array}{cl}
\B\ts\strexp\ra\S\qquad\langle\B\ts\sigexp\ra\sig\ ,
\ \sig\geq\S'\prec\S\rangle\\
\langle\langle\plusmap{\B}{\TyNamesFcn\S}\ts
\strbind\ra\SE\rangle\rangle
\end{array}
}
{ \B\ts\strbinder\ra\{\strid\mapsto\S\langle'\rangle\}
\ \langle\langle +\ \SE\rangle\rangle }\index{41.1}
\end{equation}}{\begin{equation} % structure binding
\label{structure-binding-rule}
\frac{
\B\ts\strexp\ra\E\quad
\langle\plusmap{\B}{\TyNamesFcn\E}\ts
\strbind\ra\SE\rangle
}
{ \B\ts\barestrbindera\ra\{\strid\mapsto\E\}
\ \langle +\ \SE\rangle}\index{41.1}
\end{equation}}
%
\deletionPage{32}{
\comment If present, $\sigexp$ has the effect of restricting the
view which $\strid$ provides of $\S$ while retaining sharing of names.
The notation $\S\langle'\rangle$ means $\S'$, if the first option is present,
and $\S$ if not.}
%
\replacementPage{32}{
\rulesec{Signature Expressions}{\B\ts\sigexp\ra\S}
\begin{equation} % encapsulation sigexp
\label{encapsulating-sigexp-rule}
\frac{\B\ts\spec\ra\E }
{\B\ts\encsigexp\ra (\m,\E) }\index{41.2}
\end{equation}}{\rulesec{Signature Expressions}{\B\ts\sigexp\ra\E}
\begin{equation} % encapsulation sigexp
\label{encapsulating-sigexp-rule}
\frac{\B\ts\spec\ra\E }
{\B\ts\encsigexp\ra \E }\index{41.2}
\end{equation}}
%
\replacementPage{33}{\begin{equation} % signature identifier
\label{signature-identifier-rule}
\frac{ \sigord{\B(\sigid)}{}{\S} }
{ \B\ts\sigid\ra\S }
\end{equation}}{\begin{equation} % signature identifier
\label{signature-identifier-rule}
\frac{ \B(\sigid) = (\T)\E \quad \T\cap (\of{\T}{\B}) = \emptyset}
{ \B\ts\sigid\ra\E }
\end{equation}}
%
\insertionPage{33}{
\begin{equation}
\label{wheretype-rule}
\frac{
\begin{array}{c}
\B\ts\sigexp\ra \E\quad \tyvarseq = \alphak\quad \of{\C}{\B}\ts\ty\ra \tau\\
\E(\longtycon) = (\t, \VE)\quad t\notin(\of{\T}{\B})\cup\TyNamesFcn\tau\\
\rea = \{\t\mapsto \Lambda\alphak.\tau\}\quad
\hbox{$\Lambda\alphak.\tau$ admits equality, if $\t$ does\quad $\rea(\E)$ well-formed}
\end{array}
}
{\B\ts\wheretypesigexp\ra\rea(\E)}
\end{equation}}
%
\deletionPage{33}{
\item{(\ref{encapsulating-sigexp-rule})}
In contrast to rule~\ref{generative-strexp-rule}, $m$ is not here
required to be new.
The name $m$ may be chosen to achieve the sharing required
in rule~\ref{strshareq-rule}, or to achieve the enrichment side conditions
of rule~\ref{structure-binding-rule} or \ref{funbind-rule}.
The choice of $m$ must result in an admissible object.}
%
\replacementPage{33}{The instance $\S$ of $\B(\sigid)$ is not determined by this rule,
but -- as in rule~\ref{encapsulating-sigexp-rule} -- the instance
may be chosen to achieve sharing properties or enrichment
conditions.}{The bound names of $\B(\sigid)$ can always be renamed to satisfy $\T\cap(\of{\T}{\B}) = \emptyset$,
if necessary.}
%
\replacementPage{33}{\begin{equation} % any sigexp
\label{topmost-sigexp-rule}
\frac{\begin{array}{c}
\B\ts\sigexp\ra\S\quad\mbox{$(\N)\S$ equality-principal for $\sigexp$ in $\B$}\\
\mbox{$(\N)\S$ type-explicit}
\end{array}}
{\B\ts\sigexp\ra (\N)\S}\index{41.25}
\end{equation}}{\begin{equation} % any sigexp
\label{topmost-sigexp-rule}
\frac{
\B\ts\sigexp\ra\E\quad\T= \TyNamesFcn\E\setminus(\of{\T}{\B})
}
{\B\ts\sigexp\ra (\T)\E}\index{41.25}
\end{equation}}
%
\deletionPage{33}{a structure binding, }
%
\replacementPage{33}{, a
functor binding or a
functor signature}{, a signature constraint, or a
functor binding }
%
\replacementPage{33}{an equality-principal and type-explicit }{a }
%
\replacementPage{33}{\ref{structure-binding-rule}, }{
\ref{transparent-constraint-rule}, \ref{opaque-constraint-rule}, }
%
\deletionPage{33}{,
\ref{funsigexp-rule}}
%
\deletionPage{33}{By contrast, signature
expressions occurring in structure descriptions are elaborated to
structures using the liberal rules
\ref{encapsulating-sigexp-rule} and \ref{signature-identifier-rule},
see rule~\ref{strdesc-rule}, so that names can be chosen to achieve
sharing, when necessary.}
%
\deletionPage{33}{
\begin{equation} % empty signature declaration
%\label{empty-sigdec-rule}
\frac{}
{ \B\ts\emptysigdec\ra\emptymap }
\end{equation}
\begin{equation} % sequential signature declaration
\label{sequence-sigdec-rule}
\frac{ \B\ts\sigdec_1\ra\G_1 \qquad \plusmap{\B}{\G_1}\ts\sigdec_2\ra\G_2 }
{ \B\ts\seqsigdec\ra\plusmap{\G_1}{\G_2} }
\end{equation}}
%
\deletionPage{33}{\comments
\begin{description}
%
\item{(\ref{single-sigdec-rule})}
The first closure restriction of Section~\ref{closure-restr-sec}
can be enforced by replacing the $\B$ in the premise by $\B_0+\of{\G}{\B}$.
\item{(\ref{sequence-sigdec-rule})}
A signature declaration does not create any new structures
or types; hence the use of $+$ instead of $\oplus$.
\end{description}
}
%
\deletionPage{33}{\comment The condition that $\sig$ be equality-principal,
implicit in the first premise, ensures that the
signature found is as general as possible given the sharing
constraints present in $\sigexp$.}
%
\replacementPage{33}{
\begin{equation} % type specification
\label{typespec-rule}
\frac{ \of{\C}{\B}\ts\typdesc\ra\TE }
{ \B\ts\typespec\ra\TE\ \In\ \Env }
\end{equation}}{\begin{equation} % type specification
\label{typespec-rule}
\frac{
\of{\C}{\B}\ts\typdesc\ra\TE \quad
\forall(\t,\VE)\in\Ran\TE,\hbox{\ $t$ does not admit equality}
}
{ \B\ts\typespec\ra\TE\ \In\ \Env }
\end{equation}}
%
\replacementPage{34}{
\begin{equation} % eqtype specification
\label{eqtypspec-rule}
\frac{ \of{\C}{\B}\ts\typdesc\ra\TE \qquad
\forall(\theta,\CE)\in \Ran\TE,\ \theta {\rm\ admits\ equality} }
{ \B\ts\eqtypespec\ra\TE\ \In\ \Env }
\end{equation}}{\begin{equation} % eqtype specification
\label{eqtypspec-rule}
\frac{ \of{\C}{\B}\ts\typdesc\ra\TE \qquad
\forall(\t,\VE)\in \Ran\TE,\ \t {\rm\ admits\ equality} }
{ \B\ts\eqtypespec\ra\TE\ \In\ \Env }
\end{equation}}
%
\replacementPage{34}{
\begin{equation} % data specification
\label{datatypespec-rule}
\frac{ \plusmap{\of{\C}{\B}}{\TE}\ts\datdesc\ra\VE,\TE }
{ \B\ts\datatypespec\ra(\VE,\TE)\ \In\ \Env }
\end{equation}}{
\begin{equation} % data specification
\label{datatypespec-rule}
\frac{ \begin{array}{c}
\of{\C}{\B}\oplus\TE\ts\datdesc\ra\VE,\TE \quad
\forall(\t,\VE')\in\Ran\TE, \t\notin\of{\T}{\B}\\
\hbox{$\TE$ maximises equality}
\end{array}}
{ \B\ts\datatypespec\ra(\VE,\TE)\ \In\ \Env }
\end{equation}}
%
\insertionPage{34}{\begin{equation}
\label{datatypereplspec-rule}
\frac{ \B(\longtycon) = (\typefcn,\VE)\quad
\typefcn = \typefcnk\quad
\tyvarseq = \alphak\quad
\TE = \{\tycon\mapsto(\typefcn,\VE)\}
}
{\B\ts\datatypereplspec\ra (\VE,\TE)\ \In\ \Env}
\end{equation}}
%
\replacementPage{34}{
\begin{equation} % exception specification
\label{exceptionspec-rule}
\frac{ \of{\C}{\B}\ts\exndesc\ra\EE\quad\VE=\EE }
{ \B\ts\exceptionspec\ra(\VE,\EE)\ \In\ \Env }
\end{equation}}{\begin{equation} % exception specification
\label{exceptionspec-rule}
\frac{ \of{\C}{\B}\ts\exndesc\ra\VE }
{ \B\ts\exceptionspec\ra\VE\ \In\ \Env }
\end{equation}}
%
\deletionPage{34}{
\begin{equation} % sharing specification
%\label{sharingspec-rule}
\frac{ \B\ts\shareq\ra\emptymap }
{ \B\ts\sharingspec\ra\emptymap\ \In\ \Env }\index{42.3}
\end{equation}}
%
\deletionPage{34}{\begin{equation} % local specification
%\label{localspec-rule}
\frac{ \B\ts\spec_1\ra\E_1 \qquad \plusmap{\B}{\E_1}\ts\spec_2\ra\E_2 }
{ \B\ts\localspec\ra\E_2 }
\end{equation}}
%
\deletionPage{34}{\begin{equation} % open specification
%\label{openspec-rule}
\frac{ \B(\longstrid_1)=(\m_1,\E_1)\quad\cdots\quad
\B(\longstrid_n)=(\m_n,\E_n) }
{ \B\ts\openspec\ra\E_1 + \cdots +\E_n }
\end{equation}}
%
\replacementPage{34}{\begin{equation} % include signature specification
\label{inclspec-rule}
\frac{ \sigord{\B(\sigid_1)}{}{(\m_1,\E_1)} \quad\cdots\quad
\sigord{\B(\sigid_n)}{}{(\m_n,\E_n)} }
{ \B\ts\inclspec\ra\E_1 + \cdots +\E_n }
\end{equation}}{\begin{equation} % include signature specification
\label{inclspec-rule}
\frac{ \B\ts\sigexp\ra\E}
{ \B\ts\singleinclspec\ra\E }
\end{equation}}
%
\replacementPage{34}{
\begin{equation} % sequential specification
%\label{seqspec-rule}
\frac{ \B\ts\spec_1\ra\E_1 \qquad \plusmap{\B}{\E_1}\ts\spec_2\ra\E_2 }
{ \B\ts\seqspec\ra\plusmap{\E_1}{\E_2} }
\end{equation}}{\begin{equation} % sequential specification
\label{seqspec-rule}
\frac{ \B\ts\spec_1\ra\E_1 \qquad \B\oplus\E_1\ts\spec_2\ra\E_2\qquad\Dom(\E_1)\cap\Dom(\E_2) = \emptyset }
{ \B\ts\seqspec\ra\plusmap{\E_1}{\E_2} }
\end{equation}}
%
\insertionPage{34}{
\begin{equation}
\label{sharspec-rule}
\frac{\begin{array}{c}
\B\ts \spec \ra \E\quad \E(\longtycon_i) = (\t_i,\VE_i), \;i = 1..n\\
t\in\{\t_1,\ldots,\t_n\}\quad\hbox{$\t$ admits equality, if some $\t_i$ does}\\
\{\t_1,\ldots,\t_n\}\cap\of{\T}{\B} = \emptyset\quad
\rea = \{\t_1\mapsto\t,\ldots,\t_n\mapsto \t\}
\end{array}
}
{\B\ts \newsharingspec\ra \rea(\E)}
\end{equation}}
%
\replacementPage{35}{The type functions in $\TE$ may be chosen to achieve the sharing hypothesis
of rule~\ref{typshareq-rule} or the enrichment conditions of
rules~\ref{structure-binding-rule} and~\ref{funbind-rule}. In particular, the type
names in $\TE$ in rule~\ref{datatypespec-rule} need not be new.
Also, in rule~\ref{typespec-rule} the type functions in $\TE$ may admit
equality.}{The type
names in $\TE$ are new.}
%
\replacementPage{35}{$\EE$}{$\VE$}
%
\deletionPage{35}{\item{(\ref{inclspec-rule})}
The names $\m_i$ in the instances may be chosen to achieve sharing or
enrichment conditions.\index{43.0}}
%
\insertionPage{35}{\item{(\ref{seqspec-rule})}
Note that no sequential specification is allowed to specify the
same identifier twice.}
%
\replacementPage{35}{
\begin{equation} % value description
%\label{valdesc-rule}
\frac{ \C\ts\ty\ra\tau\qquad
\langle\C\ts\valdesc\ra\VE\rangle }
{ \C\ts\valdescription\ra\{\var\mapsto\tau\}
\ \langle +\ \VE\rangle }\index{43.1}
\end{equation}}{\begin{equation} % value description
%\label{valdesc-rule}
\frac{ \C\ts\ty\ra\tau\qquad
\langle\C\ts\valdesc\ra\VE\rangle }
{ \C\ts\valviddescription\ra\{\vid\mapsto(\tau,\isv)\}
\ \langle +\ \VE\rangle }\index{43.1}
\end{equation}}
%
\replacementPage{35}{
\begin{equation} % type description
\label{typdesc-rule}
\frac{ \tyvarseq = \alphak
\qquad\langle \C\ts\typdesc\ra\TE\rangle\qquad\arity\theta=k }
{ \C\ts\typdescription\ra\{\tycon\mapsto(\theta,\emptymap)\}
\ \langle +\ \TE\rangle }\index{43.2}
\end{equation}}{\begin{equation} % type description
\label{typdesc-rule}
\frac{ \begin{array}{c}
\tyvarseq = \alphak\quad\t\notin\of{\T}{\C}\quad\arity\t=k \\
\langle \C\ts\typdesc\ra\TE\qquad\t\notin\TyNamesFcn\TE\rangle
\end{array}}
{ \C\ts\typdescription\ra\{\tycon\mapsto(\t,\emptymap)\}
\ \langle +\ \TE\rangle }\index{43.2}
\end{equation}}
%
\deletionPage{35}{any $\theta$ of arity $k$ may be chosen but that}
%
\replacementPage{35}{constructor}{value}
%
\replacementPage{35}{For example, \mbox{\ml{datatype s=c type t sharing s=t}}\ }{For example, \mbox{\ml{datatype s=C type t}} \mbox{\ml{sharing type t=s}}\ }
%
\replacementPage{35}{\begin{equation} % datatype description
\label{datdesc-rule}
\frac{ \tyvarseq = \alphak\qquad\C,\alphakt\ts\condesc\ra\CE
\qquad\langle\C\ts\datdesc\ra\VE,\TE\rangle }
{ \begin{array}{cl}
\C\ts\datdescription\ra\\
\qquad\qquad\cl{}{\CE}\langle +\ \VE\rangle,\
\{\tycon\mapsto(t,\cl{}{\CE})\}\ \langle +\ \TE\rangle
\end{array}
}\index{43.3}
\end{equation}}{\begin{equation} % datatype description
\label{datdesc-rule}
\frac{ \begin{array}{c}
\tyvarseq = \alphak\qquad\C,\alphakt\ts\condesc\ra\VE
\quad\arity \t = k\\
\langle\C\ts\datdesc'\ra\VE',\TE'\qquad \forall(\t',\VE'')\in\Ran\TE',\,\t\neq\t'\rangle
\end{array}}
{ \begin{array}{l}
\C\ts\newdatdescription\ra\\
\qquad\cl{}{\VE} \langle +\ \VE'\rangle,\
\{\tycon\mapsto(t,\cl{}{\VE})\}\ \langle +\ \TE'\rangle
\end{array}
}\index{43.3}
\end{equation}}
%
\replacementPage{35}{\rulesec{Constructor Descriptions}{\C,\tau\ts\condesc\ra\CE}}{\rulesec{Constructor Descriptions}{\C,\tau\ts\condesc\ra\VE}}
%
\replacementPage{35}{\begin{equation} % constructor description
%\label{condesc-rule}
\frac{\langle\C\ts\ty\ra\tau'\rangle\qquad
\langle\langle\C,\tau\ts\condesc\ra\CE\rangle\rangle }
{\begin{array}{l}
\C,\tau\ts\longcondescription\ra\\
\qquad\{\con\mapsto\tau\}\
\langle +\ \{\con\mapsto\tau'\to\tau\}\ \rangle\
\langle\langle +\ \CE\rangle\rangle
\end{array}
}\index{43.35}
\end{equation}}{\begin{equation} % constructor description
%\label{condesc-rule}
\frac{\langle\C\ts\ty\ra\tau'\rangle\qquad
\langle\langle\C,\tau\ts\condesc\ra\VE\rangle\rangle }
{\begin{array}{l}
\C,\tau\ts\longconviddescription\ra\\
\qquad\{\vid\mapsto(\tau,\isc)\}\
\langle +\ \{\vid\mapsto(\tau'\to\tau,\isc)\}\ \rangle\
\langle\langle +\ \VE\rangle\rangle
\end{array}
}\index{43.35}
\end{equation}}
%
\replacementPage{35}{
\rulesec{Exception Descriptions}{\C\ts\exndesc\ra\EE}}{\rulesec{Exception
Descriptions}{\C\ts\exndesc\ra\VE}}
%
\replacementPage{35}{
\begin{equation} % exception description
\label{exndesc-rule}
\frac{ \langle\C\ts\ty\ra\tau\qquad\TyVarsFcn(\tau)=\emptyset\rangle\qquad
\langle\langle\C\ts\exndesc\ra\EE\rangle\rangle }
{ \begin{array}{l}
\C\ts\exndescriptiona\ra\\
\quad\quad\{\exn\mapsto\EXCN\}\ \langle +\ \{\exn\mapsto\tau\rightarrow\EXCN\}\rangle\ \langle\langle +\ \EE\rangle\rangle
\end{array}
}\index{43.4}
\end{equation}}{\begin{equation} % exception description
\label{exndesc-rule}
\frac{ \langle\C\ts\ty\ra\tau\qquad\TyVarsFcn(\tau)=\emptyset\rangle\qquad
\langle\langle\C\ts\exndesc\ra\VE\rangle\rangle }
{ \begin{array}{l}
\C\ts\exnviddescriptiona\ra\\
\quad\quad\{\vid\mapsto(\EXCN,\ise)\}\ \langle +\ \{\vid\mapsto(\tau\rightarrow\EXCN,\ise)\}\rangle\ \langle\langle +\ \VE\rangle\rangle
\end{array}
}\index{43.4}
\end{equation}}
%
\replacementPage{36}{
\begin{equation}
\label{strdesc-rule}
\frac{ \B\ts\sigexp\ra\S\qquad\langle\B\ts\strdesc\ra\SE\rangle }
{ \B\ts\strdescription\ra\{\strid\mapsto\S\}\ \langle +\ \SE\rangle }\index{43.5}
\end{equation}}{\begin{equation}
\label{strdesc-rule}
\frac{ \B\ts\sigexp\ra\E\qquad\langle\B + \TyNamesFcn\E\ts\strdesc\ra\SE\rangle }
{ \B\ts\strdescription\ra\{\strid\mapsto\E\}\ \langle +\ \SE\rangle }\index{43.5}
\end{equation}}
%
\deletionPage{36}{
\rulesec{Sharing Equations}{\B\ts\shareq\ra\emptymap}
\begin{equation} % structure sharing equation
\label{strshareq-rule}
\frac{ \of{\m}{\B(\longstrid_1)}=\cdots =\of{\m}{\B(\longstrid_n)} }
{ \B\ts\strshareq\ra\E,\emptymap }\index{44.1}
\end{equation}
\vspace{6pt}
\begin{equation} % type sharing equation
\label{typshareq-rule}
\frac{ \of{\typefcn}{\B(\longtycon_1)}=\cdots=\of{\typefcn}{\B(\longtycon_n)} }
{ \B\ts\typshareq\ra\emptymap }
\end{equation}
\vspace{6pt}
\begin{equation} % multiple sharing equation
%\label{multshareq-rule}
\frac{ \B\ts\shareq_1\ra\emptymap\qquad\B\ts\shareq_2\ra\emptymap }
{ \B\ts\multshareq\ra\emptymap }
\end{equation}
%
\comments
\begin{description}
\item{(\ref{strshareq-rule})}
By the definition of consistency the premise is weaker than\linebreak
$\B(\longstrid_1) = \cdots = \B(\longstrid_n)$.
Two different structures with the same name may be thought of
as representing different views. The requirement that $\B$ is
consistent forces different views to be consistent.
\end{description}
%
\oldpagebreak
\begin{description}
\item{(\ref{typshareq-rule})}
By\index{44.1.5}
the definition of consistency the premise is weaker than\linebreak
$\B(\longtycon_1) = \cdots = \B(\longtycon_n)$.
A type structure with empty constructor environment may have the
same type name as one with a non-empty constructor environment;
the former could arise from a type description, and the latter
from a datatype description.
However, the requirement that $\B$ is
consistent will prevent two type structures with constructor
environments which have different
non-empty domains from sharing the same type name.
\end{description}
}
%
\deletionPage{36}{
%
% Functor Specification rules
%
\rulesec{Functor Specifications}{\B\ts\funspec\ra\F}
\begin{equation} % single functor specification
\label{singfunspec-rule}
\frac{ \B\ts\fundesc\ra\F }
{ \B\ts\singfunspec\ra\F }\index{44.2}
\end{equation}
\vspace{6pt}
\begin{equation} % empty functor specification
%\label{emptyfunspec-rule}
\frac{}
{ \B\ts\emptyfunspec\ra\emptymap }
\end{equation}
\vspace{6pt}
\begin{equation} % sequential functor specification
%\label{seqfunspec-rule}
\frac{ \B\ts\funspec_1\ra\F_1\qquad
\B+\F_1\ts\funspec_2\ra\F_2 }
{ \B\ts\seqfunspec\ra\plusmap{\F_1}{\F_2} }
\end{equation}
\comments
\begin{description}
\item{(\ref{singfunspec-rule})}
The second closure restriction of Section~\ref{closure-restr-sec}
can be enforced by replacing the $\B$ in the premise by $\B_0+\of{\G}{\B}$.
\end{description}
\rulesec{Functor Descriptions}{\B\ts\fundesc\ra\F}
\begin{equation} % functor description
%\label{fundesc-rule}
\frac{ \B\ts\funsigexp\ra\funsig\qquad
\langle\B\ts\fundesc\ra\F\rangle}
{ \B\ts\longfundesc\ra\{\funid\mapsto\funsig\}
\langle +\ \F\rangle}\index{44.3}
\end{equation}
\rulesec{Functor Signature Expressions}{\B\ts\funsigexp\ra\funsig}
\begin{equation} % functor signature
\label{funsigexp-rule}
%version 1:
%\frac{
% \begin{array}{c}
% \B\ts\sigexp\ra\S\qquad\longsig{}{\rm\ principal\ in\ }\B\\
% \B\oplus\{\strid\mapsto\S\} \ts\sigexp'\ra\S'\\
% \N' = \NamesFcn\S'\setminus((\of{\N}{\B})\cup\N)
% \end{array}
% }
% {\B\ts\longfunsigexpa\ra(\N)(\S,(\N')\S')}\index{44.4}
%version2: \frac{\begin{array}{rl}
% \B\ts\sigexp\ra\S&\mbox{$(N)S$ principal in $\B$}\\
% \B\oplus\{\strid\mapsto\S\}\ts\sigexp'\ra\S'&
% \mbox{$(N')S'$ principal in $\B\oplus\{\strid\mapsto\S\}$}
% \end{array}}
% {\B\ts\longfunsigexpa\ra(N)(S,(N')S')}\index{44.4}
%\end{equation}
\frac{\B\ts\sigexp\ra(\N)\S\qquad
\B\oplus\{\strid\mapsto\S\}\ts\sigexp'\ra(\N')\S'}
{\B\ts\longfunsigexpa\ra(N)(S,(N')S')}\index{44.4}
\end{equation}
\comment
The signatures $(\N)\S$ and $(\N')\S'$ are equality-principal
and type-explicit, see rule~\ref{topmost-sigexp-rule}.
}
%
\deletionPage{36}{
\vspace{6pt}
\begin{equation} % empty functor declaration
%\label{emptyfundec-rule}
\frac{}
{ \B\ts\emptyfundec\ra\emptymap }
\end{equation}
\vspace{6pt}
\oldpagebreak
\begin{equation} % sequential functor declaration
%\label{seqfundec-rule}
\frac{ \B\ts\fundec_1\ra\F_1\qquad
\B+\F_1\ts\fundec_2\ra\F_2 }
{ \B\ts\seqfundec\ra\plusmap{\F_1}{\F_2} }\index{45.1.5}
\end{equation}}
%
\deletionPage{36}{\comments
\begin{description}
\item{(\ref{singfundec-rule})}
The third closure restriction of Section~\ref{closure-restr-sec}
can be enforced by replacing the $\B$ in the premise
by $\B_0+(\of{\G}{\B})+(\of{\F}{\B})$.
\end{description}}
%
\replacementPage{36}{\begin{equation} % functor binding
\label{funbind-rule}
\frac{
\begin{array}{c}
\B\ts\sigexp\ra(\N)\S\qquad
\B\oplus\{\strid\mapsto\S\} \ts\strexp\ra\S' \\
\langle
\B\oplus\{\strid\mapsto\S\} \ts\sigexp'\ra\sig',\ \sig'\geq\S''\prec\S'
\rangle\\
\N' = \NamesFcn\S'\setminus((\of{\N}{\B})\cup\N) \\
\langle\langle\B\ts\funbind\ra\F\rangle\rangle
\end{array}
}
{
\begin{array}{c}
\B\ts\funstrbinder\ \optfunbind\ra\\
\qquad\qquad \qquad
\{\funid\mapsto(\N)(\S,(\N')\S'\langle'\rangle)\}
\ \langle\langle +\ \F\rangle\rangle
\end{array}
}\index{45.2}
\end{equation}}{\begin{equation} % functor binding
\label{funbind-rule}
\frac{
\begin{array}{c}
\B\ts\sigexp\ra(\T)\E\qquad
\B\oplus\{\strid\mapsto\E\} \ts\strexp\ra\E'
\\
\T\cap(\of{\T}{\B}) = \emptyset\quad \T' = \TyNamesFcn\E'\setminus((\of{\T}{\B})\cup\T) \\
\langle\B\ts\funbind\ra\F\rangle
\end{array}
}
{
\begin{array}{c}
\B\ts\barefunstrbinder\ \langle\boxml{and \funbind}\rangle\ra\\
\qquad\qquad \qquad
\{\funid\mapsto(\T)(\E,(\T')\E')\}
\ \langle +\ \F\rangle
\end{array}
}\index{45.2}
\end{equation}
}
%
\deletionPage{36}{The requirement that $(\N)\S$ be equality-principal,
implicit in the first premise, forces $(\N)\S$ to be
as general as possible given the sharing constraints in $\sigexp$.
The requirement that $(\N)\S$ be type-explicit ensures that there is
at most one realisation via which an actual argument can match
$(\N)\S$.}
%
\deletionPage{36}{structure name $\m$ and}
%
\replacementPage{36}{$\S$ }{$\E$ }
%
\deletionPage{36}{$\m$ and }
%
\replacementPage{36}{The set $\N'$ is
chosen such that every name free
in $(\N)\S$ or $(\N)(\S,(\N')\S')$ is free in $\B$.}{The set $\T'$ is
chosen such that every name free
in $(\T)\E$ or $(\T)(\E,(\T')\E')$ is free in $\B$.}
%
\replacementPage{36}{\begin{equation} % structure-level declaration
\label{strdectopdec-rule}
\frac{\B\ts\strdec\ra\E \quad\imptyvars\E=\emptyset}
{\B\ts\strdec\ra
(\NamesFcn\E,\E)\ \In\ \Basis
}\index{45.3}
\end{equation}}{\begin{equation} % structure-level declaration
\label{strdectopdec-rule}
\frac{\begin{array}{c}
\B\ts\strdec\ra\E \quad \langle \B\oplus \E\ts \topdec\ra \B'\rangle\\
B'' = (\TyNamesFcn\E,\E)\In\ \Basis\; \langle + \B'\rangle\quad\TyVarFcn\B''=\emptyset
\end{array}}
{\B\ts\strdecintopdec\ra\B''}
\end{equation}}
%
\replacementPage{36}{\begin{equation} % signature declaration
%\label{sigdectopdec-rule}
\frac{\B\ts\sigdec\ra\G \quad\imptyvars\G=\emptyset}
{\B\ts\sigdec\ra
(\NamesFcn\G,\G)\ \In\ \Basis
}\index{46.0}
\end{equation}}{\begin{equation} % signature declaration
\frac{\begin{array}{c}
\B\ts\sigdec\ra \G\quad \langle\B\oplus\G\ts\topdec\ra\B'\rangle\\
\B'' = (\TyNamesFcn\G,G)\ \In\ \Basis\;\langle + \B'\rangle
\end{array}}
{\B\ts\sigdecintopdec\ra \B''
}\index{46.0}
\end{equation}}
%
\replacementPage{36}{\begin{equation} % functor declaration
\label{fundectopdec-rule}
\frac{\B\ts\fundec\ra\F \quad\imptyvars\F=\emptyset}
{\B\ts\fundec\ra
(\NamesFcn\F,\F)\ \In\ \Basis
}
\end{equation}}{\begin{equation} % functor declaration
\label{fundectopdec-rule}
\frac{\begin{array}{c}
\B\ts\fundec\ra\F\quad\langle\B\oplus\F\ts\topdec\ra\B'\rangle\\
B'' = (\TyNamesFcn\F,\F)\ \In\ \Basis\; \langle+\B'\rangle\quad \TyVarsFcn\B''=\emptyset
\end{array}}
{\B\ts\fundecintopdec\ra\B''}
\end{equation}}
%
\replacementPage{36}{
\begin{description}
\item{(\ref{strdectopdec-rule})--(\ref{fundectopdec-rule})} The side
conditions ensure that no free imperative
type variables enter the
basis.\index{46.01}
\end{description}}{
\begin{description}
\item{(\ref{strdectopdec-rule})--(\ref{fundectopdec-rule})}
No free type variables enter the basis: if $\B\ts\topdec\ra\B'$
then $\TyVarsFcn(\B') = \emptyset$.\index{46.01}
\end{description}}
%
\deletionPage{36}{\subsection{Functor Signature Matching}
\label{fun-sig-match-sec}
As\index{46} pointed out in Section~\ref{mod-gram-sec} on the
grammar for Modules, there is no phrase class whose elaboration
requires matching one functor signature to another functor signature.
But a precise definition of this matching is needed, since a
functor $g$ may only be separately compiled in the presence of
specification of any functor $f$ to which $g$ refers, and then a
real functor $f$ must match this specification.
In the case, then, that $f$ has been specified by a functor signature
\[\funsig_1\ =\ \longfunsig{1}\]
and that later $f$ is declared with functor signature
\[\funsig_2\ =\ \longfunsig{2}\]
the following matching rule will be employed:
A functor signature
$\funsig_2\ =\ \longfunsig{2}$ {\sl matches} another functor signature,
$\funsig_1\ =\ \longfunsig{1}$, if there exists a realisation $\rea$
such that
\begin{enumerate}
\item $\longsig{1}$ matches $\longsig{2}$ via $\rea$, and
\item $\rea((\N_2')\S_2')$ matches $(\N_1')\S_1'$.
\end{enumerate}
The first condition ensures that the real functor signature $\funsig_2$
for $f$ requires the argument $\strexp$ of any application $\f(\strexp)$
to have no more sharing, and no more richness, than was predicted by
the specified signature $\funsig_1$.
The second condition ensures that the real functor signature $\funsig_2$,
instantiated to $(\rea\S_2,\rea((\N_2')\S_2'))$, provides in the result of
the application $\f(\strexp)$
no less sharing, and no less richness, than was predicted by
the specified signature $\funsig_1$.
%We claim that any phrase -- e.g. the declaration of the functor $g$ above --
%which elaborates successfully in a basis $\B$ with $\B(f)=\funsig_1$ will
%also elaborate successfully in the basis $\B+\{f\mapsto\funsig_2\}$. This
%claim justifies our definition of functor matching.
% -- this claim is false because of open.
}
%
\replacementPage{37}{
Since\index{47.1} types are fully dealt with in the static semantics,
the dynamic semantics ignores them. The Core syntax is therefore
reduced by the following transformations, for the purpose of the dynamic
semantics:}{Since\index{47.1} types are mostly dealt with in the static semantics,
the Core syntax is
reduced by the following transformations,
for the purpose of the dynamic
semantics:}
%
\insertionPage{37}{constructor and}
%
\deletionPage{37}{
\item Any declaration of the form ``$\,\typedec\,$''
or ``$\datatypedec$'' is replaced by the empty declaration.}
%
\deletionPage{37}{\item A declaration of the form ``$\,\abstypedec\,$'' is replaced by ``$\dec\,$''.}
%
\deletionPage{37}{TypBind, DatBind, $\ConBind$, }
%
\insertionPage{37}{, word}
%
\insertionPage{37}{or character}
%
\deletionPage{37}{ASCII }
%
\replacementPage{37}{Exception constructors evaluate to exception names, unlike value constructors
which simply evaluate to themselves.}{Exception constructors evaluate to exception names.}
%
\replacementPage{37}{We generally omit the injection functions taking $\Con$,
$\Con\times\Val$ etc into $\Val$.}{We generally omit the injection functions taking $\VId$,
$\VId\times\Val$ etc into $\Val$.}
%
\replacementPage{38}{$\Val =\{\mbox{\tt :=}\}\cup\SVal\cup\BasVal\cup\Con$}{$\Val =\{\mbox{\tt :=}\}\cup\SVal\cup\BasVal\cup\VId$}
%
\replacementPage{38}{$\qquad\cup(\Con\times\Val)\cup\ExVal$}{$\qquad\cup(\VId\times\Val)\cup\ExVal$}
%
\replacementPage{38}{\Closure}{\FcnClosure}
%
\replacementPage{38}{$\Closure = \Match\times\Env\times\VarEnv$}{$\FcnClosure = \Match\times\Env\times\ValEnv$}
%
\insertionPage{38}{\TE,}
%
\deletionPage{38}{,\EE}
%
\replacementPage{38}{$\Env = \StrEnv\times\VarEnv\times\ExnEnv$}{$\Env = \StrEnv\times\TyEnv\times\ValEnv$}
%
\insertionPage{38}{$ \TE \in \TyEnv = \finfun{\TyCon}{\ValEnv}$}
%
\replacementPage{38}{$\VarEnv = \finfun{\Var}{\Val}$}{$\ValEnv = \finfun{\VId}{\Val\times\IdStatus}$}
%
\deletionPage{38}{$ \EE \in \ExnEnv = \finfun{\Exn}{\Exc}$}
%
\deletionPage{38}{
An important point is that structure names $\m$ have
no significance at all in the dynamic semantics; this explains why the
object class $\Str = \StrNames\times\Env$ is absent here -- for the dynamic
semantics the concepts {\sl structure} and {\sl environment} coincide.}
%
\deletionPage{38}{the }
%
\replacementPage{38}{identifiers}{value variables}
%
\replacementPage{38}{
These values are denoted by the identifiers to which they are bound in the
initial dynamic basis (see Appendix~\ref{init-dyn-bas-app}),
and are as follows:
{\tt
abs floor real sqrt sin cos arctan exp ln
size chr ord explode implode div mod
~ / * + - = <> < > <= >=
std\_in std\_out open\_in open\_out close\_in close\_out
input output lookahead end\_of\_stream
}
The meaning of basic values (almost all of which are functions) is
represented by the function
$\APPLY\ :\ \BasVal\times\Val\to\Val\cup\Pack $
which is detailed in Appendix~\ref{init-dyn-bas-app}.
}{In this document, we take $\BasVal$ to be the singleton set $\{\boxml{=}\}$;
however, libraries may define a larger set of basic values.
The meaning of basic values is
represented by a function
$ \APPLY\ :\ \BasVal\times\Val\to\Val\cup\Pack $
which satisfies that $\APPLY(\boxml{=}, \{1\mapsto v_1, 2\mapsto v_2\})$
is {\tt true} or {\tt false} according as the values $\V_1$ and $\V_2$ are, or are
not, identical values.
}
%
\replacementPage{39}{
A\index{49.2} subset $\BasExc\subset\Exc$ of the exception names are bound to predefined
exception constructors.
These names are denoted by the identifiers to which they are bound in the
initial dynamic basis (see Appendix~\ref{init-dyn-bas-app}),
and are as follows:}{A\index{49.2}
subset $\BasExc\subset\Exc$ of the exception names are bound to predefined
exception constructors in the initial dynamic basis
(see Appendix~\ref{init-dyn-bas-app}).
These names are denoted by the identifiers
to which they are bound in the
initial basis,
and are as follows:}
%
\replacementPage{39}{{\tt
Abs Ord Chr Div Mod Quot Prod
Neg Sum Diff Floor Sqrt Exp Ln
Io Match Bind Interrupt
}}{$$\boxml{ Match\ \ Bind}$$}
%
\replacementPage{39}{
The exceptions on the first two lines are raised by
corresponding basic functions, where \verb+~+ {\tt /} {\tt *}
{\tt +} {\tt -} correspond respectively to {\tt Neg} {\tt Quot}
{\tt Prod} {\tt Sum} {\tt Diff}. The details are given
in Appendix~\ref{init-dyn-bas-app}. The exception $(\mbox{{\tt Io}},s)$,
where $s$ is a string, is raised
by certain of the basic input/output functions,
as detailed in Appendix~\ref{init-dyn-bas-app}.
}{The}
%
\deletionPage{39}{
Finally, ~\ml{Interrupt}~
is raised by external intervention.}
%
\replacementPage{39}{\subsection{Closures}}{\subsection{Function Closures}}
%
\insertionPage{39}{function}
%
\insertionPage{39}{function}
%
\deletionPage{39}{function }
%
\replacementPage{39}{where\[ \Rec\ :\ \VarEnv\to\VarEnv \]is defined as follows:}{where\[ \Rec\ :\ \ValEnv\to\ValEnv \]is defined as follows:}
%
\replacementPage{39}{$\VE(\var)\notin\Closure$}{$\VE(\vid)\notin\FcnClosure\times\{\isv\}$}
%
\replacementPage{39}{If $\VE(\var)=(\match',\E',\VE')$
then $(\Rec\VE)(\var)=(\match',\E',\VE)$}{If $\VE(\vid)=((\match',\E',\VE'), \isv)$
then $(\Rec\VE)(\vid)=((\match',\E',\VE), \isv)$}
%
\replacementPage{39}{closure values}{function closures}
%
\insertionPage{40}{function}
%
\replacementPage{41}{\begin{equation} % value variable
\label{varexp-dyn-rule}
\frac{\E(\longvar)=\V}
{\E\ts\longvar\ra\V}\index{51.2}
\end{equation}
\oldpagebreak
\begin{equation} % value constructor
\label{conexp-dyn-rule}
\frac{\longcon=\strid_1.\cdots.\strid_k.\con}
{\E\ts\longcon\ra\con}\index{52.1}
\end{equation}
\begin{equation} % exception constant
\label{exconexp-dyn-rule}
\frac{\E(\longexn)=\e}
{\E\ts\longexn\ra\e}
\end{equation}}{\begin{equation} % value variable
\label{varexp-dyn-rule}
\frac{\E(\longvid)=(\V,\is)}
{\E\ts\longvid\ra\V}\index{51.2}
\end{equation}}
%
\deletionPage{41}{\item{(\ref{conexp-dyn-rule})}
Value constructors denote themselves.}
%
\insertionPage{41}{\item{(\ref{varexp-dyn-rule})}
As in the static semantics,
value identifiers are looked up in the environment and the
identifier status is not used.}
%
\deletionPage{41}{
\item{(\ref{exconexp-dyn-rule})}
Exception constructors are looked up in the exception environment
component of $\E$.}
%
\replacementPage{41}{\begin{equation} % constructor application
\label{conapp-dyn-rule}
\frac{\E\ts\exp\ra\con\qquad\con\neq\REF\qquad\E\ts\atexp\ra\V}
{\E\ts\appexp\ra(\con,\V)}
\end{equation}}{\begin{equation} % constructor application
\label{conapp-dyn-rule}
\frac{\E\ts\exp\ra\vid\qquad\vid\neq\REF\qquad\E\ts\atexp\ra\V}
{\E\ts\appexp\ra(\vid,\V)}
\end{equation}}
%
\replacementPage{42}{
\begin{equation} % basic function application
%\label{basapp-dyn-rule}
\frac{\E\ts\exp\ra b
\qquad\E\ts\atexp\ra\V\qquad\APPLY(b,\V)=\V'}
{\E\ts\appexp\ra\V'}\index{53.1}
\end{equation}}{
\begin{equation} % basic function application
%\label{basapp-dyn-rule}
\frac{\E\ts\exp\ra b
\qquad\E\ts\atexp\ra\V\qquad\APPLY(b,\V)=\V'/\p}
{\E\ts\appexp\ra\V'/\p}\index{53.1}
\end{equation}}
%
\deletionPage{42}{ (``garbage
collection'')}
%
\insertionPage{43}{function}
%
\replacementPage{43}{
\begin{equation} % match 3
%\label{match-dyn-rule}
\frac{\E,\V\ts\mrule\ra\FAIL\qquad\E,\V\ts\match\ra\V'/\FAIL}
{\E\ts\longmatcha\ra\V'/\FAIL}
\end{equation}}{\begin{equation} % match 3
%\label{match-dyn-rule}
\frac{\E,\V\ts\mrule\ra\FAIL\qquad\E,\V\ts\match\ra\V'/\FAIL}
{\E,\V\ts\longmatcha\ra\V'/\FAIL}
\end{equation}}
%
\replacementPage{43}{
\begin{equation} % value declaration
%\label{valdec-dyn-rule}
\frac{\E\ts\valbind\ra\VE}
{\E\ts\valdec\ra\VE\ \In\ \Env}\index{54.3}
\end{equation}}{\begin{equation} % value declaration
%\label{valdec-dyn-rule}
\frac{\E\ts\valbind\ra\VE}
{\E\ts\explicitvaldec\ra\VE\ \In\ \Env}\index{54.3}
\end{equation}}
%
\insertionPage{43}{\begin{equation}
\frac{\ts\typbind\ra\TE}
{\E\ts\typedec\ra\TE\ \In\ \Env}
\end{equation}}
%
\insertionPage{43}{
\begin{equation}
\frac{\ts\datbind\ra\VE,\TE}
{\E\ts\datatypedec\ra(\VE,\TE)\ \In\ \Env}
\end{equation}}
%
\insertionPage{43}{\begin{equation}
\frac{\E(\longtycon) = \VE}
{\begin{array}{r}
\E\ts\datatyperepldec\ra\qquad\qquad\\
(\VE,\{\tycon\mapsto\VE\})\ \In\ \Env
\end{array}}
\end{equation}}
%
\insertionPage{44}{
\begin{equation}
\frac{\ts\datbind\ra\VE\qquad \E+\VE\ts\dec\ra \E'}
{\E\ts\abstypedec \ra \E'}
\end{equation}}
%
\replacementPage{44}{
\begin{equation} % exception declaration
%\label{exceptiondec-dyn-rule}
\frac{\E\ts\exnbind\ra\EE }
{\E\ts\exceptiondec\ra\EE\ \In\ \Env }
\end{equation}}{\begin{equation} % exception declaration
%\label{exceptiondec-dyn-rule}
\frac{\E\ts\exnbind\ra\VE }
{\E\ts\exceptiondec\ra\VE\ \In\ \Env }
\end{equation}}
%
\replacementPage{44}{
\begin{equation} % open declaration
%\label{open-strdec-dyn-rule}
\frac{ \E(\longstrid_1)=\E_1
\quad\cdots\quad
\E(\longstrid_k)=\E_k }
{ \E\ts\openstrdec\ra \E_1 + \cdots + \E_k }
\end{equation}}{
\begin{equation} % open declaration
%\label{open-strdec-dyn-rule}
\frac{ \E(\longstrid_1)=\E_1
\quad\cdots\quad
\E(\longstrid_n)=\E_n }
{ \E\ts\openstrdec\ra \E_1 + \cdots + \E_n }
\end{equation}}
%
\insertionPage{44}{
\rulesec{Type Bindings}{\ts\typbind\ra\TE}
\begin{equation}
\frac{\langle\ts\typbind\ra\TE\rangle}
{\ts\longtypbind\ra\{\tycon\mapsto\emptymap\}\langle+\TE\rangle}
\end{equation}}
%
\insertionPage{44}{
\rulesec{Datatype Bindings}{\ts\datbind\ra\VE,\TE}
\begin{equation}
\frac{\ts\constrs\ra\VE\qquad\langle\ts\datbind'\ra\VE',\TE'\rangle}
{\ts\tyvarseq\;\tycon\boxml{=}\constrs\;\langle\boxml{and}\,\datbind'\rangle\ra\VE\langle+\VE'\rangle,\{\tycon\mapsto\VE\}\langle+\TE'\rangle}
\end{equation}
\rulesec{Constructor Bindings}{\ts\constrs\ra\VE}
\begin{equation}
\frac{\langle\ts\constrs\ra\VE\rangle}
{\ts\vid\langle\boxml{|}\,\constrs\rangle\ra
\{\vid\mapsto(\vid,\isc)\}\,\langle+\VE\rangle}
\end{equation}
}
%
\replacementPage{45}{
\rulesec{Exception Bindings}{\E\ts\exnbind\ra\EE/\p}}{\rulesec{Exception
Bindings}{\E\ts\exnbind\ra\VE}}
%
\replacementPage{45}{
\begin{equation} % exception binding 1
\label{exnbind-dyn-rule1}
\frac{\e\notin\of{\excs}{\s}\qquad\s'=\s+\{\e\}\qquad
\langle\s',\E\ts\exnbind\ra\EE,\s''\rangle }
{\s,\E\ts\longexnbindaa\ra\{\exn\mapsto\e\}\langle +\ \EE\rangle,\
\s'\langle'\rangle}\index{55.2}
\end{equation}}{\begin{equation} % exception binding 1
\label{exnbind-dyn-rule1}
\frac{\e\notin\of{\excs}{\s}\qquad\s'=\s+\{\e\}\qquad
\langle\s',\E\ts\exnbind\ra\VE,\s''\rangle }
{\s,\E\ts\longvidexnbindaa\ra\{\vid\mapsto(\e,\ise)\}\langle +\ \VE\rangle,\
\s'\langle'\rangle}\index{55.2}
\end{equation}}
%
\replacementPage{45}{
\begin{equation} % exception binding 2
%\label{exnbind-dyn-rule2}
\frac{\E(\longexn)=\e\qquad
\langle\E\ts\exnbind\ra\EE\rangle }
{\E\ts\longexnbindb\ra\{\exn\mapsto\e\}\langle +\ \EE\rangle}
\end{equation}}{\begin{equation} % exception binding 2
%\label{exnbind-dyn-rule2}
\frac{\E(\longvid)=(\e,\ise)\qquad
\langle\E\ts\exnbind\ra\VE\rangle }
{\E\ts\longvidexnbindb\ra\{\vid\mapsto(\e,\ise)\}\langle +\ \VE\rangle}
\end{equation}}
%
\replacementPage{45}{\begin{equation} % variable pattern
%\label{varpat-dyn-rule}
\frac{}
{\E,\V\ts\var\ra \{\var\mapsto\V\} }
\end{equation}}{\begin{equation} % variable pattern
%\label{varpat-dyn-rule}
\frac{\hbox{$\vid\notin\Dom(\E)$ or $\of{\is}{\E(\vid)} = \isv$}}
{\E,\V\ts\vid\ra \{\var\mapsto(\V,\isv)\} }
\end{equation}}
%
\deletionPage{45}{\begin{equation} % constant pattern
%\label{conapat-dyn-rule1}
\frac{\longcon=\strid_1.\cdots.\strid_k.\con\qquad\V=\con }
{\E,\V\ts\longcon\ra \emptymap}
\end{equation}
\begin{equation}
\label{conapat-dyn-rule2}
\frac{\longcon=\strid_1.\cdots.\strid_k.\con\qquad\V\neq\con}
{\E,\V\ts\longcon\ra\FAIL}
\end{equation}}
%
\replacementPage{45}{\begin{equation} % exception constant
%\label{exconapat-dyn-rule1}
\frac{\E(\longexn)=\V}
{\E,\V\ts\longexn\ra\emptymap}
\end{equation}}{\begin{equation} % exception constant
%\label{exconapat-dyn-rule1}
\frac{\E(\longvid)=(\V,\is)\qquad\is\neq\isv}
{\E,\V\ts\longvid\ra\emptymap}
\end{equation}}
%
\replacementPage{45}{\begin{equation}
\label{exconapat-dyn-rule2}
\frac{\E(\longexn)\neq\V}
{\E,\V\ts\longexn\ra\FAIL}\index{56.0}
\end{equation}}{\begin{equation}
\label{exconapat-dyn-rule2}
\frac{\E(\longvid)=(\V',\is)\qquad\is\neq\isv\qquad\V\neq\V'}
{\E,\V\ts\longvid\ra\FAIL}\index{56.0}
\end{equation}}
%
\deletionPage{46}{(\ref{conapat-dyn-rule2}),}
%
\deletionPage{46}{rule~\ref{conapat-dyn-rule2},}
%
\replacementPage{46}{\begin{equation} % construction pattern
%\label{conpat-dyn-rule1}
\frac{\begin{array}{c}
\longcon=\strid_1.\cdots.\strid_k.\con\neq\REF\qquad
\V=(\con,\V')\\
\E,\V'\ts\atpat\ra\VE/\fail
\end{array}}
{\E,\V\ts\conpat\ra \VE/\fail}
\end{equation}}{\begin{equation} % construction pattern
%\label{conpat-dyn-rule1}
\frac{\begin{array}{c}
\E(\longvid) = (\vid,\isc)\qquad\vid\neq\REF\qquad
\V=(\vid,\V')\\
\E,\V'\ts\atpat\ra\VE/\fail
\end{array}}
{\E,\V\ts\vidpat\ra \VE/\fail}
\end{equation}}
%
\replacementPage{46}{\begin{equation} % construction pattern
\label{conpat-dyn-rule2}
\frac{\longcon=\strid_1.\cdots.\strid_k.\con\neq\REF\qquad
\V\notin\{\con\}\times\Val}
{\E,\V\ts\conpat\ra \FAIL}
\end{equation}}{\begin{equation} % construction pattern
\label{conpat-dyn-rule2}
\frac{\E(\longvid) = (\vid,\isc)\qquad\vid\neq\REF\qquad
\V\notin\{\vid\}\times\Val}
{\E,\V\ts\vidpat\ra \FAIL}
\end{equation}}
%
\replacementPage{46}{\begin{equation} % exception construction
%\label{exconpat-dyn-rule1}
\frac{\begin{array}{c}
\E(\longexn)=\e\qquad\V=(\e,\V')\\
\E,\V'\ts\atpat\ra\VE/\FAIL
\end{array}
}
{\E,\V\ts\exconpat\ra\VE/\FAIL}
\end{equation}}{\begin{equation} % exception construction
%\label{exconpat-dyn-rule1}
\frac{\begin{array}{c}
\E(\longvid)=(\e,\ise)\qquad\V=(\e,\V')\\
\E,\V'\ts\atpat\ra\VE/\FAIL
\end{array}
}
{\E,\V\ts\vidpat\ra\VE/\FAIL}
\end{equation}}
%
\replacementPage{46}{\begin{equation}
\label{exconpat-dyn-rule2}
\frac{\E(\longexn)=\e\qquad\V\notin\{\e\}\times\Val}
{\E,\V\ts\exconpat\ra\FAIL}
\end{equation}}{\begin{equation}
\label{exconpat-dyn-rule2}
\frac{\E(\longvid)=(\e,\ise)\qquad\V\notin\{\e\}\times\Val}
{\E,\V\ts\vidpat\ra\FAIL}
\end{equation}}
%
\replacementPage{47}{\begin{equation} % layered pattern
%\label{layeredpat-dyn-rule}
\frac{\E,\V\ts\pat\ra\VE/\fail}
{\E,\V\ts\layeredpata\ra\{\var\mapsto\V\}+\VE/\fail}
\end{equation}}{\begin{equation} % layered pattern
%\label{layeredpat-dyn-rule}
\frac{\begin{array}{c}
\hbox{ $\vid\notin\Dom(\E)$ or $\of{\is}{\E(\vid)}=\isv$}\\
\E,\V\ts\pat\ra\VE/\fail
\end{array}}
{\E,\V\ts\layeredvidpata\ra\{\vid\mapsto(\V,\isv)\}+\VE/\fail}
\end{equation}}
%
\deletionPage{47}{rule~\ref{conapat-dyn-rule2},}
%
\replacementPage{48}{Unlike types,
it cannot ignore them completely; }{However,
they cannot be ignored completely; }
%
\insertionPage{48}{ and
imposing identifier status on value identifiers}
%
\replacementPage{48}{However, the types
and the sharing properties of structures and signatures are irrelevant to
dynamic evaluation; the syntax is therefore
reduced by the following transformations (in addition to those for the Core),
for the purpose of the dynamic semantics of Modules:}{The syntax is therefore
reduced by the following transformations (in addition to those for the Core),
for the purpose of the dynamic semantics of Modules:}
%
\insertionPage{48}{constructor and}
%
\deletionPage{48}{\item Any specification of the form ``$\typespec$'', ``$\eqtypespec$'',
``$\DATATYPE$\ $\datdesc$\,'' or
``$\sharingspec$'' is replaced by the empty specification.}
%
\deletionPage{48}{The Modules phrase classes TypDesc, DatDesc, ConDesc and SharEq
are omitted.}
%
\insertionPage{48}{Any qualification \boxml{sharing type $\cdots$} on
a specification or \boxml{where type $\cdots$} on a signature expression is omitted.}
%
\replacementPage{48}{$(\strid:\I,\strexp\langle:\I'\rangle,\B)$}{$(\strid:\I,\strexp,\B)$}
%
\replacementPage{48}{$(\StrExp\langle\times\Int\rangle)\times\Basis$}{$\StrExp\times\Basis$}
%
\replacementPage{48}{$(\IE,\vars,\exns)\ {\rm or}\ \I$}{$\I\ {\rm or}\ (\SI,\TI,\VI)$}
%
\replacementPage{48}{$\Int = \IntEnv\times\Fin(\Var)\times\Fin(\Exn)$}{$\Int = \StrInt\times\TyInt\times\ValInt$}
%
\replacementPage{48}{\IE}{\SI}
%
\replacementPage{48}{\IntEnv}{\StrInt}
%
\insertionPage{48}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&$#$\hfil&$#$\hfil\cr
\TI & \in & \TyInt = \finfun{\TyCon}{\ValInt}\cr
\VI & \in & \ValInt = \finfun{\VId}{\IdStatus}\cr}\end{minipage}}
%
\replacementPage{48}{\IE}{\I}
%
\replacementPage{48}{\IntEnv}{\Int}
%
\insertionPage{48}{
An {\sl interface} $\I\in\Int$ represents a ``view'' of a structure.
Specifications and signature expressions will evaluate to interfaces;
moreover, during the evaluation of a specification or signature expression,
structures (to which a specification or signature expression may
refer via datatype replicating specifications) are represented
only by their interfaces. To extract a value interface from
a dynamic value environment we define the operation $\Inter: \ValEnv \to\ValInt$
as follows:
\[\Inter(\VE) = \{\vid\mapsto\is\;;\;\VE(\vid) = (\V,\is)\}\]
In other words, $\Inter(\VE)$ is the value interface obtained from $\VE$ by
removing all values from $\VE$. We then extend $\Inter$ to a function
$\Inter:\Env\to\Int$ as follows:
\[ \Inter(\SE,\TE,\VE)\ =\ (\SI,\TI,\VI)\]
where $\VI$ = $\Inter(\VE)$ and
\begin{eqnarray*}
\SI & = & \{\strid\mapsto\Inter\E\;;\;\SE(\strid) = \E\}\\
\TI & = & \{\tycon\mapsto\Inter\VE'\;;\;\TE(\tycon) = \VE'\}
\end{eqnarray*}
An {\sl interface basis} $\IB=(\G,\I)$ is a value-free part of a basis, sufficient to
evaluate signature expressions and specifications.
The function $\Inter$ is extended to create an interface basis
from a basis $\B$ as follows:
\[ \Inter(\F,\G,\E)\ =\ (\G, \Inter\E) \]
}
%
\deletionPage{49}{
An {\sl interface} $\I\in\Int$ represents a ``view'' of a structure.
Specifications and signature expressions will evaluate to interfaces;
moreover, during the evaluation of a specification or signature expression,
structures (to which a specification or signature expression may
refer via ``$\OPEN$'') are represented only by their interfaces. To extract an
interface from a dynamic environment we define the operation
\[ \Inter\ :\ \Env\to\Int \]
as follows:
\[ \Inter(\SE,\VE,\EE)\ =\ (\IE,\Dom\VE,\Dom\EE)\]
where
\[ \IE\ =\ \{\strid\mapsto\Inter\E\ ;\ \SE(\strid)=\E\}\ .\]
An {\sl interface basis}\index{59.1} $\IB=(\G,\IE)$ is that part of a basis needed to
evaluate signature expressions and specifications.
The function $\Inter$ is extended to create an interface basis
from a basis $\B$ as follows:
\[ \Inter(\F,\G,\E)\ =\ (\G, \of{\IE}{(\Inter\E)}) \]}
%
\insertionPage{49}{
A further operation
\[ \downarrow\ :\ \Env\times\Int\to\Env\]
is required, to cut down an environment $\E$ to a given interface $\I$,
representing the effect of an explicit signature ascription. We first
define $\downarrow: \ValEnv\times\ValInt\to\ValEnv$ by
\[\VE\downarrow\VI = \{\vid\mapsto(\V,\is)\;;\;\VE(\vid) = (\V,\is')\ {\rm and}\ \VI(\vid) = \is\}\]
(Note that the identifier status is taken from $\VI$.)
We then define $\downarrow: \StrEnv \times \StrInt \to \StrEnv$,
$\downarrow: \TyEnv \times\TyInt\to\TyEnv$ and
$\downarrow: \Env\times\Int\to\Env$ simultaneously as follows:
\label{downarrowdef}
\begin{center}
$\SE\downarrow\SI = \{\strid\mapsto\E\downarrow\I\ ;\
\SE(\strid)=\E\ {\rm and}\ \SI(\strid)=\I\}$\\[6pt]
$ \TE\downarrow\TI = \{\tycon\mapsto \VE'\downarrow\VI'\ ;\
\TE(\tycon) = \VE'\ {\rm and}\ \TI(\tycon) = \VI'\}$ \\[6pt]
$
(\SE,\TE,\VE)\downarrow(\SI,\TE,\VI) =
(\SE\downarrow\SI, \TE\downarrow\TI, \VE\downarrow\VI) $
\end{center}}
%
\deletionPage{49}{
A further operation
\[ \downarrow\ :\ \Env\times\Int\to\Env\]
is required, to cut down an environment $\E$ to a given interface $\I$,
representing the effect of an explicit signature ascription. It is defined
as follows:
\[ (\SE,\VE,\EE)\downarrow(\IE,\vars,\exns)\ =\ (\SE',\VE',\EE') \]
where
\[ \SE'\ =\ \{\strid\mapsto\E\downarrow\I\ ;\
\SE(\strid)=\E\ {\rm and}\ \IE(\strid)=\I\} \]
and (taking $\downarrow$ now to mean restriction of a function domain)
\[\VE'=\VE\downarrow\vars,\ \EE'=\EE\downarrow\exns.\]
}
%
\replacementPage{49}{is also a projection of}{can
also be obtained from}
%
\replacementPage{49}{omitting structure names $\m$ and type environments
$\TE$,}{first replacing every type
structure $(\typefcn, \VE)$
in the range of every type environment $\TE$ by $\VE$}
%
\insertionPage{49}{then}
%
\replacementPage{49}{variable environment $\VE$ and each
exception environment $\EE$ by its domain.}{pair $(\sigma,\is)$ in the range
of every value environment $\VE$ by $\is$.}
%
\replacementPage{49}{ or an interface basis}{, a signature environment}
%
\insertionPage{50}{\begin{equation} % transparent signature constraint
\frac{\B\ts\strexp\ra\E\qquad\Inter\B\ts\sigexp\ra\I}
{\B\ts\transpconstraint\ra\E\downarrow\I}
\end{equation}
\begin{equation} % opaque signature constraint
\frac{\B\ts\strexp\ra\E\qquad\Inter\B\ts\sigexp\ra\I}
{\B\ts\opaqueconstraint\ra\E\downarrow\I}
\end{equation}}
%
\replacementPage{50}{\begin{equation} % functor application
\label{functor-application-dyn-rule}
\frac{ \begin{array}{c}
\B(\funid)=(\strid:\I,\strexp'\langle:\I'\rangle,\B')\\
\B\ts\strexp\ra\E\qquad
\B'+\{\strid\mapsto\E\downarrow\I\}\ts\strexp'\ra\E'\\
\end{array}
}
{\B\ts\funappstr\ra\E'\langle\downarrow\I'\rangle}
\end{equation}}{\begin{equation} % functor application
\label{functor-application-dyn-rule}
\frac{ \begin{array}{c}
\B(\funid)=(\strid:\I,\strexp',\B')\\
\B\ts\strexp\ra\E\qquad
\B'+\{\strid\mapsto\E\downarrow\I\}\ts\strexp'\ra\E'\\
\end{array}
}
{\B\ts\funappstr\ra\E'}
\end{equation}}
%
\replacementPage{51}{
\begin{equation} % structure binding
\frac{ \begin{array}{cl}
\B\ts\strexp\ra\E\qquad\langle\Inter\B\ts\sigexp\ra\I\rangle\\
\langle\langle\B\ts\strbind\ra\SE\rangle\rangle
\end{array}
}
{\begin{array}{c}
\B\ts\strbinder\ra\\
\qquad\qquad\qquad\{\strid\mapsto\E\langle\downarrow\I\rangle\}
\ \langle\langle +\ \SE\rangle\rangle
\end{array}
}\index{61.1}
\end{equation}
\comment As in the static semantics, when present, $\sigexp$ constrains the
``view'' of the structure. The restriction must be done in the
dynamic semantics to ensure that any dynamic opening of the structure
produces no more components than anticipated during the static
elaboration.}{\begin{equation} % structure binding
\frac{
\B\ts\strexp\ra\E\qquad
\langle\B\ts\strbind\ra\SE\rangle
}
{
\B\ts\barestrbindera\ra\{\strid\mapsto\E\}
\ \langle +\ \SE\rangle
}\index{61.1}
\end{equation}
}
%
\deletionPage{51}{
\begin{equation} % empty signature declaration
%\label{empty-sigdec-dyn-rule}
\frac{}
{ \IB\ts\emptysigdec\ra\emptymap }
\end{equation}
\begin{equation} % sequential signature declaration
%\label{sequence-sigdec-dyn-rule}
\frac{ \IB\ts\sigdec_1\ra\G_1 \qquad \plusmap{\IB}{\G_1}\ts\sigdec_2\ra\G_2 }
{ \IB\ts\seqsigdec\ra\plusmap{\G_1}{\G_2} }
\end{equation}
}
%
\replacementPage{51}{\begin{equation} % value specification
%\label{valspec-dyn-rule}
\frac{ \ts\valdesc\ra\vars }
{ \IB\ts\valspec\ra\vars\ \In\ \Int }\index{61.5}
\end{equation}}{\begin{equation} % value specification
%\label{valspec-dyn-rule}
\frac{ \ts\valdesc\ra\VI }
{ \IB\ts\valspec\ra\VI\ \In\ \Int }\index{61.5}
\end{equation}}
%
\insertionPage{51}{
\begin{equation}
\frac{\ts\typdesc\ra\TI}
{\IB\ts\typespec\ra\TI\ \In\ \Int}
\end{equation}
\begin{equation}
\frac{\ts\typdesc\ra\TI}
{\IB\ts\eqtypespec\ra\TI\ \In\ \Int}
\end{equation}}
%
\insertionPage{52}{
\begin{equation}
\frac{\ts\datdesc\ra\VI,\TI}
{\IB\ts\datatypespec\ra(\VI,\TI)\ \In\ \Int}
\end{equation}
}
%
\insertionPage{52}{
\begin{equation}
\frac{\IB(\longtycon) = \VI\qquad \TI = \{\tycon\mapsto\VI\}}
{\IB\ts\datatypereplspec\ra(\VI,\TI)\ \In\ \Int}
\end{equation}
}
%
\replacementPage{52}{
\begin{equation} % exception specification
%\label{exceptionspec-dyn-rule}
\frac{ \ts\exndesc\ra\exns}
{ \IB\ts\exceptionspec\ra\exns\ \In\ \Int }
\end{equation}}{\begin{equation} % exception specification
%\label{exceptionspec-dyn-rule}
\frac{ \ts\exndesc\ra\VI}
{ \IB\ts\exceptionspec\ra \VI\ \In\ \Int }
\end{equation}}
%
\replacementPage{52}{\begin{equation} % structure specification
\label{structurespec-dyn-rule}
\frac{ \IB\ts\strdesc\ra\IE }
{ \IB\ts\structurespec\ra\IE\ \In\ \Int }\index{62.1}
\end{equation}}{\begin{equation} % structure specification
\label{structurespec-dyn-rule}
\frac{ \IB\ts\strdesc\ra\SI }
{ \IB\ts\structurespec\ra\SI\ \In\ \Int }\index{62.1}
\end{equation}}
%
\deletionPage{52}{
\begin{equation} % local specification
\label{localspec-dyn-rule}
\frac{ \IB\ts\spec_1\ra\I_1 \qquad
\plusmap{\IB}{\of{\IE}{\I_1}}\ts\spec_2\ra\I_2 }
{ \IB\ts\localspec\ra\I_2 }
\end{equation}}
%
\deletionPage{52}{
\begin{equation} % open specification
%\label{openspec-dyn-rule}
\frac{ \IB(\longstrid_1)=\I_1\quad\cdots\quad
\IB(\longstrid_n)=\I_n }
{ \IB\ts\openspec\ra\I_1 + \cdots +\I_n }
\end{equation}}
%
\replacementPage{52}{
\begin{equation} % include signature specification
%\label{inclspec-dyn-rule}
\frac{ \IB(\sigid_1)=\I_1 \quad\cdots\quad
\IB(\sigid_n)=\I_n }
{ \IB\ts\inclspec\ra\I_1 + \cdots +\I_n }
\end{equation}}{\begin{equation} % include signature specification
%\label{inclspec-dyn-rule}
\frac{ \IB\ts\sigexp\ra\I}
{ \IB\ts\singleinclspec\ra\I}
\end{equation}}
%
\replacementPage{52}{\begin{equation} % sequential specification
\label{seqspec-dyn-rule}
\frac{ \IB\ts\spec_1\ra\I_1
\qquad \plusmap{\IB}{\of{\IE}{\I_1}}\ts\spec_2\ra\I_2 }
{ \IB\ts\seqspec\ra\plusmap{\I_1}{\I_2} }
\end{equation}}{\begin{equation} % sequential specification
\label{seqspec-dyn-rule}
\frac{ \IB\ts\spec_1\ra\I_1
\qquad \IB+\I_1\ts\spec_2\ra\I_2 }
{ \IB\ts\seqspec\ra\plusmap{\I_1}{\I_2} }
\end{equation}}
%
\deletionPage{52}{
\noindent\comments
\begin{description}
\item{(\ref{localspec-dyn-rule}),(\ref{seqspec-dyn-rule})}
Note that $\of{\vars}{\I_1}$ and $\of{\exns}{\I_1}$ are
not needed for the evaluation of $\spec_2$.
\end{description}}
%
\replacementPage{52}{\rulesec{Value Descriptions}{\ts\valdesc\ra\vars}}{\rulesec{Value Descriptions}{\ts\valdesc\ra\VI}}
%
\replacementPage{52}{\begin{equation} % value description
%\label{valdesc-dyn-rule}
\frac{ \langle\ts\valdesc\ra\vars\rangle }
{ \ts\var\ \langle\AND\ \valdesc\rangle\ra
\{\var\}\ \langle\cup\ \vars\rangle }\index{62.2}
\end{equation}}{\begin{equation} % value description
%\label{valdesc-dyn-rule}
\frac{ \langle\ts\valdesc\ra\VI\rangle }
{ \ts\vid\ \langle\AND\ \valdesc\rangle\ra
\{\vid\mapsto\isv\}\ \langle+\,\VI\rangle }\index{62.2}
\end{equation}}
%
\insertionPage{52}{
\rulesec{Type Descriptions}{\ts\typdesc\ra\TI}
\begin{equation}
\frac{\langle\ts\typdesc\ra\TI\rangle}
{\ts\typdescription\ra\{\tycon\mapsto\emptymap\}\langle+\TI\rangle}
\end{equation}
}
%
\insertionPage{52}{
\rulesec{Datatype Descriptions}{\ts\datdesc\ra\VI, \TI}
\begin{equation}
\frac{\ts\condesc\ra\VI\qquad\langle\ts\datdesc'\ra\VI',\TI'\rangle}
{\ts\datdescriptiona\ra\VI\,\langle+\,\VI'\rangle, \{\tycon\mapsto\VI\}\langle+\TI'\rangle}
\end{equation}
\rulesec{Constructor Descriptions}{\ts\condesc\ra\VI}
\begin{equation}
\frac{\langle\ts\condesc\ra\VI\rangle}
{\ts\shortconviddesc\ra\{\vid\mapsto\isc\}\,\langle+\VI\rangle}
\end{equation}
}
%
\replacementPage{53}{\rulesec{Exception Descriptions}{\ts\exndesc\ra\exns}}{\rulesec{Exception Descriptions}{\ts\exndesc\ra\VI}}
%
\replacementPage{53}{
\begin{equation} % exception description
%\label{exndesc-dyn-rule}
\frac{ \langle\ts\exndesc\ra\exns\rangle }
{ \ts\exn\ \langle\exndesc\rangle\ra\{\exn\}\ \langle\cup\ \exns\rangle }\index{62.3}
\end{equation}}{\begin{equation} % exception description
%\label{exndesc-dyn-rule}
\frac{ \langle\ts\exndesc\ra\VI\rangle }
{ \ts\vid\ \langle\boxml{and\ }\exndesc\rangle\ra\{\vid\mapsto\ise\}\ \langle+ \VI\rangle }\index{62.3}
\end{equation}}
%
\replacementPage{53}{\rulesec{Structure Descriptions}{\IB\ts\strdesc\ra\IE}}{\rulesec{Structure Descriptions}{\IB\ts\strdesc\ra\SI}}
%
\replacementPage{53}{\begin{equation}
%\label{strdesc-dyn-rule}
\frac{ \IB\ts\sigexp\ra\I\qquad\langle\IB\ts\strdesc\ra\IE\rangle }
{ \IB\ts\strdescription\ra\{\strid\mapsto\I\}\ \langle +\ \IE\rangle }\index{62.4}
\end{equation}}{\begin{equation}
%\label{strdesc-dyn-rule}
\frac{ \IB\ts\sigexp\ra\I\qquad\langle\IB\ts\strdesc\ra\SI\rangle }
{ \IB\ts\strdescription\ra\{\strid\mapsto\I\}\ \langle +\ \SI\rangle }\index{62.4}
\end{equation}}
%
\replacementPage{53}{
\begin{equation} % functor binding
%\label{funbind-dyn-rule}
\frac{
\begin{array}{c}
\Inter\B\ts\sigexp\ra\I\qquad
\langle\Inter\B+\{\strid\mapsto\I\} \ts\sigexp'\ra\I'\rangle \\
\langle\langle\B\ts\funbind\ra\F\rangle\rangle
\end{array}
}
{
\begin{array}{c}
\B\ts\funstrbinder\ \optfunbind\ra\\
\qquad\qquad \qquad
\{\funid\mapsto(\strid:\I,\strexp\langle:\I'\rangle,\B)\}
\ \langle\langle +\ \F\rangle\rangle
\end{array}
}\index{62.5}
\end{equation}}{\begin{equation} % functor binding
%\label{funbind-dyn-rule}
\frac{
\Inter\B\ts\sigexp\ra\I\qquad
\langle\IB\ts\funbind\ra\F\rangle
}
{
\begin{array}{c}
\IB\ts\barefunstrbinder\ \optfunbinda\ra\\
\qquad\qquad \qquad
\{\funid\mapsto(\strid:\I,\strexp,\B)\}
\ \langle +\ \F\rangle
\end{array}
}\index{62.5}
\end{equation}}
%
\deletionPage{53}{
\vspace{6pt}
\begin{equation} % empty functor declaration
%\label{emptyfundec-dyn-rule}
\frac{}
{ \B\ts\emptyfundec\ra\emptymap }
\end{equation}
\vspace{6pt}
\begin{equation} % sequential functor declaration
%\label{seqfundec-dyn-rule}
\frac{ \B\ts\fundec_1\ra\F_1\qquad
\B+\F_1\ts\fundec_2\ra\F_2 }
{ \B\ts\seqfundec\ra\plusmap{\F_1}{\F_2} }
\end{equation}}
%
\replacementPage{53}{
\begin{equation} % structure-level declaration
%\label{strdectopdec-dyn-rule}
\frac{\B\ts\strdec\ra\E}
{\B\ts\strdec\ra\E\ \In\ \Basis
}\index{63.2}
\end{equation}
\vspace{6pt}
\begin{equation} % signature declaration
%\label{sigdectopdec-dyn-rule}
\frac{\Inter\B\ts\sigdec\ra\G}
{\B\ts\sigdec\ra\G\ \In\ \Basis
}
\end{equation}
\vspace{6pt}
\begin{equation} % functor declaration
%\label{fundectopdec-dyn-rule}
\frac{\B\ts\fundec\ra\F}
{\B\ts\fundec\ra\F\ \In\ \Basis
}
\end{equation}}{\begin{equation} % structure-level declaration
%\label{strdectopdec-dyn-rule}
\frac{\B\ts\strdec\ra\E\quad\B' =\E\ \In\ \Basis\quad\langle \B+\B'\ts\topdec\ra\B''\rangle }
{\B\ts\strdecintopdec\ra\B'\langle'\rangle
}\index{63.2}
\end{equation}
\vspace{6pt}
\begin{equation} % signature declaration
%\label{sigdectopdec-dyn-rule}
\frac{\Inter\B\ts\sigdec\ra\G\quad B' = \G\ \In\ \Basis\quad
\langle \B + \B'\ts\topdec\ra\B''\rangle}
{\B\ts\sigdecintopdec\ra \B'\langle'\rangle
}
\end{equation}
\vspace{6pt}
\begin{equation} % functor declaration
%\label{fundectopdec-dyn-rule}
\frac{\B\ts\fundec\ra\F\quad \B' = \F\ \In\ \Basis\quad
\langle \B + \B'\ts\topdec\ra\B''\rangle}
{\B\ts\fundecintopdec\ra\B'\langle'\rangle
}
\end{equation}}
%
\deletionPage{54}{ or external intervention}
%
\deletionPage{55}{
\item Omit\index{65.5} the {\OPEN} declaration from the syntax class of
declarations $\dec$
\item Restrict the long identifier classes to identifiers, i.e.
omit qualified identifiers.}
%
\deletionPage{55}{
This means that several components of a basis, for example the
signature and functor environments, are irrelevant to the execution
of a core language program.}
%
\insertionPage{56}{\tyvarseq\ }
%
\insertionPage{56}{\tyvarseq\ }
%
\insertionPage{56}{\tyvarseq\ }
%
\insertionPage{56}{\tyvarseq\ }
%
\deletionPage{56}{
These forms are currently more experimental than the bare syntax of modules,
but we recommend implementers to include them so that they can be
tested in practice.
In the derived forms for functor bindings and functor signature expressions,
$\strid$ is a new structure identifier and
the form of $\sigexp'$ depends
on the form of $\sigexp$ as follows.
If $\sigexp$ is simply a signature identifier
$\sigid$, then $\sigexp'$ is also $\sigid$; otherwise $\sigexp$ must take
the form ~$\SIG\ \spec_1\ \END$~,
and then $\sigexp'$ is
$\mbox{\SIG\ \LOCAL\ \OPEN\ \strid\ \IN\ $\spec_1$\ \END\ \END}$.
%(where $\strid$ is new).
}
%
\insertionPage{56}{
Finally, Figure~\ref{spec-der-forms-fig} shows the derived forms for specifications.
The last derived form for specifications allows sharing between structure
identifiers as a shorthand for type sharing specifications.
%Standard ML no
%longer has a semantic notion of structure sharing;
%however, for compatability with Standard ML '90, a weaker form
%of structure sharing specification is provided.
The phrase
\[
\boxml{$\spec$ sharing $\longstrid_1$ = $\cdots$ = $\longstrid_k$}
\]
is a derived form whose equivalent form is
\pagebreak
%\medskip
\halign{\qquad\ignore{#}&#\hfil\cr
\boxml{$\spec$ sharing $\longstrid_1$ = $\cdots$} & \boxml{$\spec$}\cr
\boxml{\ \ \qquad\qquad\qquad\qquad\qquad = $\longstrid_k$} & \boxml{\ sharing type $\longtycon_{1}$ = $\longtycon_{1}'$}\cr
& \boxml{\ $\cdots$}\cr
& \boxml{\ sharing type $\longtycon_{m}$ = $\longtycon_{m}'$}\cr}
\medskip
\noindent
determined as follows.
First, note that $\spec$ specifies a set of
(possibly long) type constructors and structure identifiers, either
directly or via signature identifiers and $\INCLUDE$ specifications.
Then the equivalent form contains all type-sharing constraints
of the form
\[\boxml{sharing type $\longstrid_i.\longtycon$ = $\longstrid_j.longtycon$}\]
$(1\leq i<j\leq k)$, such that both sides of the equation are long type
constructors specified by $\spec$.
The meaning of the derived form does not depend on the order of the
type-sharing constraints in the equivalent form.
}
%
\replacementPage{57}{\begin{tabular}{|l|l|l}
\multicolumn{1}{c}{Derived Form} & \multicolumn{1}{c}{Equivalent Form} &
\multicolumn{1}{c}{}\\
\multicolumn{3}{c}{}\\
\multicolumn{2}{l}{{\bf Expressions} \exp}\\
%\multicolumn{2}{l}{EXPRESSIONS \exp}\\
\cline{1-2}
\ml{()} & \ml{\lttbrace\ \rttbrace} \\
\cline{1-2}
\ml{(}$\exp_1$ \ml{,} $\cdots$ \ml{,} $\exp_\n$\ml{)}
& \ml{\lttbrace 1=}$\exp_1$\ml{,}\ $\cdots$\ml{,}\
$\overline{n}$\ml{=}$\exp_\n$\ml{\rttbrace}
& $(\n\geq 2)$\\
\cline{1-2}
\ml{\#}\ \lab & \FN\ \ml{\lttbrace}\lab\ml{=}\var\ml{,...\rttbrace\ => }\var
& (\var\ new)\\
%\cline{1-2}
%\RAISE\ \longexn & \RAISE\ \longexn\ \WITH\ \ml{()} \\
\cline{1-2}
\CASE\ \exp\ \OF\ \match
& \ml{(}\FN\ \match\ml{)(}\exp\ml{)} \\
\cline{1-2}
\IF\ $\exp_1$\ \THEN\ $\exp_2$\ \ELSE\ $\exp_3$
& \CASE\ $\exp_1$\ \OF\ \TRUE\ \ml{=>}\ \exp$_2$\\
& \ \ \qquad\qquad\ml{|}\ \FALSE\ \ml{=>}\ \exp$_3$ \\
\cline{1-2}
\exp$_1$\ \ORELSE\ \exp$_2$
& \IF\ \exp$_1$\ \THEN\ \TRUE\ \ELSE\ \exp$_2$ \\
\cline{1-2}
\exp$_1$\ \ANDALSO\ \exp$_2$
& \IF\ \exp$_1$\ \THEN\ \exp$_2$\ \ELSE\ \FALSE \\
\cline{1-2}
\ml{(}$\exp_1$ \ml{;} $\cdots$ \ml{;} $\exp_\n$ \ml{;} \exp\ml{)}\
& \CASE\ \exp$_1$\ \OF\ \ml{(\_) =>}
& $(\n\geq 1)$ \\
& \qquad$\cdots$ \\
& \CASE\ \exp$_n$\ \OF\ \ml{(\_) =>}\ \exp \\
\cline{1-2}
\LET\ \dec\ \IN
& \LET\ \dec\ \IN & $(\n\geq 2)$ \\
\qquad$\exp_1$ \ml{;} $\cdots$ \ml{;} $\exp_\n$ \END
& \ \ \ml{(}$\exp_1$ \ml{;} $\cdots$ \ml{;} $\exp_\n$\ml{)}\
\END\\
\cline{1-2}
\WHILE\ \exp$_1$\ \DO\ \exp$_2$
& \LET\ \VAL\ \REC\ \var\ \ml{=}\ \FN\ \ml{() =>}
& (\var\ new)\\
& \ \ \IF\ \exp$_1$\ \THEN\
\ml{(}\exp$_2$\ml{;}\var\ml{())}\ \ELSE\ \ml{()} \\
& \ \ \IN\ \var\ml{()}\ \END\\
\cline{1-2}
\ml{[}$\exp_1$ \ml{,} $\cdots$ \ml{,} $\exp_\n$\ml{]}
& \exp$_1$\ \ml{::}\ $\cdots$\ \ml{::}\ \exp$_n$\
\ml{::}\ \NIL & $(n\geq 0)$ \\
\cline{1-2}
\multicolumn{3}{c}{}\\
\end{tabular}}{\begin{tabular}{|l|l|l}
\multicolumn{1}{c}{Derived Form} & \multicolumn{1}{c}{Equivalent Form} &
\multicolumn{1}{c}{}\\
\multicolumn{3}{c}{}\\
\multicolumn{2}{l}{{\bf Expressions} \exp}\\
%\multicolumn{2}{l}{EXPRESSIONS \exp}\\
\cline{1-2}
\ml{()} & \ml{\lttbrace\ \rttbrace} \\
\cline{1-2}
\ml{(}$\exp_1$ \ml{,} $\cdots$ \ml{,} $\exp_\n$\ml{)}
& \ml{\lttbrace 1=}$\exp_1$\ml{,}\ $\cdots$\ml{,}\
$\overline{n}$\ml{=}$\exp_\n$\ml{\rttbrace}
& $(\n\geq 2)$\\
\cline{1-2}
\ml{\#}\ \lab & \FN\ \ml{\lttbrace}\lab\ml{=}\vid\ml{,...\rttbrace\ => }\vid
& (\vid\ new)\\
%\cline{1-2}
%\RAISE\ \longexn & \RAISE\ \longexn\ \WITH\ \ml{()} \\
\cline{1-2}
\CASE\ \exp\ \OF\ \match
& \ml{(}\FN\ \match\ml{)(}\exp\ml{)} \\
\cline{1-2}
\IF\ $\exp_1$\ \THEN\ $\exp_2$\ \ELSE\ $\exp_3$
& \CASE\ $\exp_1$\ \OF\ \TRUE\ \ml{=>}\ \exp$_2$\\
& \ \ \qquad\qquad\ml{|}\ \FALSE\ \ml{=>}\ \exp$_3$ \\
\cline{1-2}
\exp$_1$\ \ORELSE\ \exp$_2$
& \IF\ \exp$_1$\ \THEN\ \TRUE\ \ELSE\ \exp$_2$ \\
\cline{1-2}
\exp$_1$\ \ANDALSO\ \exp$_2$
& \IF\ \exp$_1$\ \THEN\ \exp$_2$\ \ELSE\ \FALSE \\
\cline{1-2}
\ml{(}$\exp_1$ \ml{;} $\cdots$ \ml{;} $\exp_\n$ \ml{;} \exp\ml{)}\
& \CASE\ \exp$_1$\ \OF\ \ml{(\_) =>}
& $(\n\geq 1)$ \\
& \qquad$\cdots$ \\
& \CASE\ \exp$_n$\ \OF\ \ml{(\_) =>}\ \exp \\
\cline{1-2}
\LET\ \dec\ \IN
& \LET\ \dec\ \IN & $(\n\geq 2)$ \\
\qquad$\exp_1$ \ml{;} $\cdots$ \ml{;} $\exp_\n$ \END
& \ \ \ml{(}$\exp_1$ \ml{;} $\cdots$ \ml{;} $\exp_\n$\ml{)}\
\END\\
\cline{1-2}
\WHILE\ \exp$_1$\ \DO\ \exp$_2$
& \LET\ \VAL\ \REC\ \vid\ \ml{=}\ \FN\ \ml{() =>}
& (\vid\ new)\\
& \ \ \IF\ \exp$_1$\ \THEN\
\ml{(}\exp$_2$\ml{;}\vid\ml{())}\ \ELSE\ \ml{()} \\
& \ \ \IN\ \vid\ml{()}\ \END\\
\cline{1-2}
\ml{[}$\exp_1$ \ml{,} $\cdots$ \ml{,} $\exp_\n$\ml{]}
& \exp$_1$\ \ml{::}\ $\cdots$\ \ml{::}\ \exp$_n$\
\ml{::}\ \NIL & $(n\geq 0)$ \\
\cline{1-2}
\multicolumn{3}{c}{}\\
\end{tabular}}
%
\replacementPage{58}{
\id$\langle$\ml{:}\ty$\rangle
\ \langle\AS\ \pat\rangle
\ \langle$\ml{,} \labpats$\rangle$
}{\vid$\langle$\ml{:}\ty$\rangle
\ \langle\AS\ \pat\rangle
\ \langle$\ml{,} \labpats$\rangle$}
%
\replacementPage{58}{\id\ml{ = }\id$\langle$\ml{:}\ty$\rangle
\ \langle\AS\ \pat\rangle
\ \langle$\ml{,} \labpats$\rangle$}{\vid\ml{ = }\vid$\langle$\ml{:}\ty$\rangle
\ \langle\AS\ \pat\rangle
\ \langle$\ml{,} \labpats$\rangle$}
%
\replacementPage{58}{
\begin{tabular}{|l|l|}
\multicolumn{1}{c}{Derived Form} & \multicolumn{1}{c}{Equivalent Form}\\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Function-value Bindings} \fvalbind}\\
%\multicolumn{2}{l}{FUNCTION-VALUE BINDINGS \fvalbind}\\
\hline
& $\langle\OP\rangle$\var\ \ml{=} \FN\ \var$_1$\ml{=>} $\cdots$
\FN\ \var$_n$\ml{=>} \\
& \CASE\
\ml{(}\var$_1$\ml{,} $\cdots$ \ml{,} \var$_n$\ml{)} \OF \\
\ \ $\langle\OP\rangle\var\ \atpat_{11}\cdots\atpat_{1n}
\langle$\ml{:}\ty$\rangle$
\ml{=} \exp$_1$
& \ \ \ml{(}\atpat$_{11}$\ml{,}$\cdots$\ml{,}\atpat$_{1n}$
\ml{)=>}\exp$_1\langle$\ml{:}\ty$\rangle$\\
\ml{|}$\langle\OP\rangle\var\ \atpat_{21}\cdots\atpat_{2n}
\langle$\ml{:}\ty$\rangle$
\ml{=} \exp$_2$
& \ml{|(}\atpat$_{21}$\ml{,}$\cdots$\ml{,}\atpat$_{2n}$
\ml{)=>}\exp$_2\langle$\ml{:}\ty$\rangle$\\
\ml{|}\qquad$\cdots\qquad\cdots$
& \ml{|}\qquad$\cdots\qquad\cdots$\\
\ml{|}$\langle\OP\rangle\var\ \atpat_{m1}\cdots\atpat_{mn}
\langle$\ml{:}\ty$\rangle$
\ml{=} \exp$_m$
& \ml{|(}\atpat$_{m1}$\ml{,}$\cdots$\ml{,}\atpat$_{mn}$
\ml{)=>}\exp$_m\langle$\ml{:}\ty$\rangle$\\
\qquad\qquad\qquad$\langle\AND\ \fvalbind\rangle$
& \qquad\qquad\qquad$\langle\AND\ \fvalbind\rangle$\\
\hline
\multicolumn{2}{r}{($m,n\geq1$; $\var_1,\cdots,\var_n$ distinct and new)}\\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Declarations} \dec}\\
%\multicolumn{2}{l}{DECLARATIONS \dec}\\
\hline
\FUN\ \fvalbind
& \VAL\ \REC\ \fvalbind \\
\hline
\DATATYPE\ \datbind\ \WITHTYPE\ \typbind
& \DATATYPE\ \datbind$\/'$\ \ml{;}\ \TYPE\ \typbind \\
\hline
\ABSTYPE\ \datbind\ \WITHTYPE\ \typbind
& \ABSTYPE\ \datbind$\/'$ \\
\qquad\qquad\WITH\ \dec\ \END
& \qquad\WITH\ \TYPE\ \typbind\ \ml{;}\ \dec\ \END\\
\hline
\multicolumn{2}{r}{(see note in text concerning \datbind$\/'$)}\\
\multicolumn{2}{c}{}\\
\end{tabular}}{\begin{tabular}{|l|l|}
\multicolumn{1}{c}{Derived Form} & \multicolumn{1}{c}{Equivalent Form}\\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Function-value Bindings} \fvalbind}\\
%\multicolumn{2}{l}{FUNCTION-VALUE BINDINGS \fvalbind}\\
\hline
& $\langle\OP\rangle$\vid\ \ml{=} \FN\ \vid$_1$\ml{=>} $\cdots$
\FN\ \vid$_n$\ml{=>} \\
& \CASE\
\ml{(}\vid$_1$\ml{,} $\cdots$ \ml{,} \vid$_n$\ml{)} \OF \\
\ \ $\langle\OP\rangle\vid\ \atpat_{11}\cdots\atpat_{1n}
\langle$\ml{:}\ty$\rangle$
\ml{=} \exp$_1$
& \ \ \ml{(}\atpat$_{11}$\ml{,}$\cdots$\ml{,}\atpat$_{1n}$
\ml{)=>}\exp$_1\langle$\ml{:}\ty$\rangle$\\
\ml{|}$\langle\OP\rangle\vid\ \atpat_{21}\cdots\atpat_{2n}
\langle$\ml{:}\ty$\rangle$
\ml{=} \exp$_2$
& \ml{|(}\atpat$_{21}$\ml{,}$\cdots$\ml{,}\atpat$_{2n}$
\ml{)=>}\exp$_2\langle$\ml{:}\ty$\rangle$\\
\ml{|}\qquad$\cdots\qquad\cdots$
& \ml{|}\qquad$\cdots\qquad\cdots$\\
\ml{|}$\langle\OP\rangle\vid\ \atpat_{m1}\cdots\atpat_{mn}
\langle$\ml{:}\ty$\rangle$
\ml{=} \exp$_m$
& \ml{|(}\atpat$_{m1}$\ml{,}$\cdots$\ml{,}\atpat$_{mn}$
\ml{)=>}\exp$_m\langle$\ml{:}\ty$\rangle$\\
\qquad\qquad\qquad$\langle\AND\ \fvalbind\rangle$
& \qquad\qquad\qquad$\langle\AND\ \fvalbind\rangle$\\
\hline
\multicolumn{2}{r}{($m,n\geq1$; $\vid_1,\cdots,\vid_n$ distinct and new)}\\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Declarations} \dec}\\
%\multicolumn{2}{l}{DECLARATIONS \dec}\\
\hline
\FUN\ \tyvarseq\ \fvalbind
& \VAL\ \tyvarseq\ \REC\ \fvalbind \\
\hline
\DATATYPE\ \datbind\ \WITHTYPE\ \typbind
& \DATATYPE\ \datbind$\/'$\ \ml{;}\ \TYPE\ \typbind \\
\hline
\ABSTYPE\ \datbind\ \WITHTYPE\ \typbind
& \ABSTYPE\ \datbind$\/'$ \\
\qquad\qquad\WITH\ \dec\ \END
& \qquad\WITH\ \TYPE\ \typbind\ \ml{;}\ \dec\ \END\\
\hline
\multicolumn{2}{r}{(see note in text concerning \datbind$\/'$)}\\
\multicolumn{2}{c}{}\\
\end{tabular}}
%
\replacementPage{59}{
\begin{tabular}{|l|l|}
\multicolumn{1}{c}{Derived Form} & \multicolumn{1}{c}{Equivalent Form} \\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Structure Expressions} \strexp}\\
%\multicolumn{2}{l}{STRUCTURE EXPRESSIONS \strexp}\\
\cline{1-2}
\funappdec & \mbox{\funid\ \ml{(} \STRUCT\ \strdec\ \END\ \ml{)}}\\
\cline{1-2}
\multicolumn{2}{c}{}\\
%\multicolumn{2}{l}{FUNCTOR BINDINGS \funbind}\\
\multicolumn{2}{l}{{\bf Functor Bindings} \funbind}\\
\cline{1-2}
\mbox{\funid\ \ml{(}\ \spec\ \ml{)}\ $\langle$\ml{:}\ \sigexp$\rangle$\ \ml{=}}&
\mbox{\funid\ \ml{(}\ \strid\ \ml{:} \SIG\ \spec\ \END\ \ml{)}
$\langle$\ml{:}\ $\sigexp'\rangle$\ \ml{=}}\\
\mbox{\ \ \strexp\ $\langle$\AND\ \funbind$\rangle$} &
\mbox{\ \ \LET\ \OPEN\ \strid\ \IN\ \strexp\ \END\ $\langle$\AND\ \funbind$\rangle$} \\
\cline{1-2}
\multicolumn{2}{r}{($\strid$ new; see note in text concerning $\sigexp'$)}\\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Functor Signature Expressions} \funsigexp}\\
%\multicolumn{2}{l}{FUNCTOR SIGNATURES \funsigexp}\\
\cline{1-2}
\longfunsigexp & \mbox{\ml{(} \strid\ \ml{:}\ \SIG\ \spec\ \END\ \ml{)}
\ml{:}\ \sigexp$'$} \\
\cline{1-2}
\multicolumn{2}{r}{($\strid$ new; see note in text concerning $\sigexp'$)}\\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Top-level Declarations} \topdec}\\
\cline{1-2}
\exp & \VAL\ \ml{it =} \exp \\
\cline{1-2}
\multicolumn{2}{c}{}\\
\end{tabular}}{
\begin{tabular}{|l|l|}
\multicolumn{1}{c}{Derived Form} & \multicolumn{1}{c}{Equivalent Form} \\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Structure Bindings} \strbind}\\
\cline{1-2}
\derivedstrbinder & \equivalentstrbinder\\
\cline{1-2}
\derivedabststrbinder & \equivalentabststrbinder\\
\cline{1-2}
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Structure Expressions} \strexp}\\
\cline{1-2}
\funappdec & \mbox{\funid\ \ml{(} \STRUCT\ \strdec\ \END\ \ml{)}}\\
\cline{1-2}
\multicolumn{2}{c}{}\\
%\multicolumn{2}{l}{FUNCTOR BINDINGS \funbind}\\
\multicolumn{2}{l}{{\bf Functor Bindings} \funbind}\\
\cline{1-2}
\mbox{\funid\ \ml{(}\strid\ml{:}\sigexp\ml{)}\ml{:} $\sigexp'$ \ml{=}}&
\mbox{\funid\ \ml{(}\strid\ \ml{:} \sigexp\ml{)} \ \ml{=}}\\
\mbox{\ \ \strexp\ $\langle$\AND\ \funbind$\rangle$} &
\mbox{\ \ \strexp\ml{:}$\sigexp'$\ $\langle$\AND\ \funbind$\rangle$} \\
\cline{1-2}
\mbox{\funid\ \ml{(}\strid\ml{:}\sigexp\ml{)}\ABSTRACT $\sigexp'$ \ml{=}}&
\mbox{\funid\ \ml{(}\strid\ \ml{:} \sigexp\ml{)} \ \ml{=}}\\
\mbox{\ \ \strexp\ $\langle$\AND\ \funbind$\rangle$} &
\mbox{\ \ \strexp\ABSTRACT$\sigexp'$\ $\langle$\AND\ \funbind$\rangle$} \\
\cline{1-2}
\mbox{\funid\ \ml{(}\ \spec\ \ml{)}\ $\langle$\ml{:}\ \sigexp$\rangle$\ \ml{=}}&
\mbox{\funid\ \ml{(}\ $\strid_\nu$\ \ml{:} \SIG\ \spec\ \END\ \ml{)}
\ \ml{=}}\\
\mbox{\ \ \strexp\ $\langle$\AND\ \funbind$\rangle$} &
\mbox{\ \ \LET\ \OPEN\ $\strid_\nu$ \IN\ \strexp$\langle$\ml{:}\ $\sigexp\rangle$}\\
& \mbox{\ \ \END\ $\langle$\AND\ \funbind$\rangle$} \\
\cline{1-2}
\mbox{\funid\ \ml{(}\ \spec\ \ml{)}\ $\langle$\ABSTRACT\ \sigexp$\rangle$\ \ml{=}}&
\mbox{\funid\ \ml{(}\ $\strid_\nu$\ \ml{:} \SIG\ \spec\ \END\ \ml{)}
\ \ml{=}}\\
\mbox{\ \ \strexp\ $\langle$\AND\ \funbind$\rangle$} &
\mbox{\ \ \LET\ \OPEN\ $\strid_\nu$ \IN\ \strexp$\langle$\ABSTRACT $\sigexp\rangle$}\\
& \mbox{\ \ \END\ $\langle$\AND\ \funbind$\rangle$} \\
\cline{1-2}
\multicolumn{2}{r}{($\strid_\nu$ new)}\\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Programs} \program}\\
\cline{1-2}
$\exp\boxml{;}\langle\program\rangle$ & $\VAL\ \boxml{it =}\; \exp\boxml{;}\langle\program\rangle$\\
\cline{1-2}
\multicolumn{2}{c}{}\\
\end{tabular}}
%
\insertionPage{60}{
\begin{tabular}{|l|l|}
\multicolumn{1}{c}{Derived Form} & \multicolumn{1}{c}{Equivalent Form} \\
\multicolumn{2}{c}{}\\
\multicolumn{2}{l}{{\bf Specifications} \spec}\\
\cline{1-2}
$\TYPE\;\tyvarseq\;\tycon\,\boxml{=}\,\ty$ & \boxml{include}\\
&\boxml{\ sig $\TYPE\;\tyvarseq\;\tycon$}\\
&\boxml{\ end where type $\tyvarseq\;\tycon\,\boxml{=}\,\ty$} \\
\cline{1-2}
\boxml{type $\tyvarseq_1\;\tycon_1$ = $\ty_1$} & \boxml{type $\tyvarseq_1\;\tycon_1$ = $\ty_1$}\\
\boxml{ and $\cdots$} & \boxml{type $\cdots$}\\
\boxml{ $\cdots$} & \boxml{ $\cdots$}\\
\boxml{ and $\tyvarseq_n\;\tycon_n$ = $\ty_n$} & \boxml{type $\tyvarseq_n\;\tycon_n$ = $\ty_n$}\\
\cline{1-2}
$\inclspec$ ${}_{(n\geq2)}$ & $\INCLUDE\,\sigid_1; \cdots\, ; \INCLUDE \,sigid_n$\\
\cline{1-2}
\boxml{$\spec$ sharing $\longstrid_1$ = $\cdots$} & \boxml{$\spec$}\\
\boxml{\ \ \qquad\qquad\qquad\qquad\qquad = $\longstrid_k$} & \boxml{\ sharing type $\longtycon_{1}$ = }\\
& \boxml{\ \ \ \ \ \qquad\qquad\qquad\qquad $\longtycon_{1}'$}\\
& \boxml{\ $\cdots$}\\
& \boxml{\ sharing type $\longtycon_{m}$ = }\\
& \boxml{\ \ \ \ \ \qquad\qquad\qquad\qquad $\longtycon_{m}'$}\\
\cline{1-2}
\multicolumn{2}{r}{\vrule height14pt depth0pt width0pt(see note in text concerning $\longtycon_{1},\ldots,\longtycon_{m}'$)}\\
%\multicolumn{2}{r}{($n\geq 1$)}\\
\multicolumn{2}{c}{}\\
\end{tabular}}
%
\replacementPage{61}{Figure~\ref{functor-der-forms-fig}}{Figures~\ref{functor-der-forms-fig} and \ref{spec-der-forms-fig}}
%
\deletionPage{63}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&$#$\hfil&#\hfil\cr
& & \opp\longvar & value variable\cr
& & \opp\longcon & value constructor\cr
& & \opp\longexn & exception constructor\cr}\end{minipage}}
%
\insertionPage{63}{$\opp\longvid$\quad value identifier}
%
\replacementPage{63}{$\inexp_1$\ \id\ $\inexp_2$}{$\inexp_1$\ \vid\ $\inexp_2$}
%
\replacementPage{64}{\valdec}{\explicitvaldec}
%
\replacementPage{64}{\FUN\ \fvalbind}{\FUN\ \tyvarseq\ \fvalbind}
%
\insertionPage{64}{$\datatyperepldecb$\quad datatype replication}
%
\replacementPage{64}{\longinfix}{\newlonginfix}
%
\replacementPage{64}{\longinfixr}{\newlonginfixr}
%
\replacementPage{64}{\longnonfix}{\newlongnonfix}
%
\deletionPage{64}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&#\hfil&#\hfil\cr
\fvalbind& ::= & \ \ $\langle\OP\rangle\var\ \atpat_{11}\cdots\atpat_{1n}
\langle$\ml{:}\ty$\rangle$\ml{=}\exp$_1$ & $m,n\geq 1$\cr
& & \ml{|}$\langle\OP\rangle\var\ \atpat_{21}\cdots\atpat_{2n}
\langle$\ml{:}\ty$\rangle$\ml{=}\exp$_2$ & See also note
below\cr
& & \ml{|}\qquad$\cdots\qquad\cdots$ &\cr
& & \ml{|}$\langle\OP\rangle\var\ \atpat_{m1}\cdots\atpat_{mn}
\langle$\ml{:}\ty$\rangle$\ml{=}\exp$_m$ &\cr
& & \qquad\qquad\qquad$\langle\AND\ \fvalbind\rangle$ &\cr}\end{minipage}}
%
\insertionPage{64}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&#\hfil&#\hfil\cr
\fvalbind& ::= & \ \ $\langle\OP\rangle\vid\ \atpat_{11}\cdots\atpat_{1n}
\langle$\ml{:}\ty$\rangle$\ml{=}\exp$_1$ & $m,n\geq 1$\cr
& & \ml{|}$\langle\OP\rangle\vid\ \atpat_{21}\cdots\atpat_{2n}
\langle$\ml{:}\ty$\rangle$\ml{=}\exp$_2$ & See also note
below\cr
& & \ml{|}\qquad$\cdots\qquad\cdots$ &\cr
& & \ml{|}$\langle\OP\rangle\vid\ \atpat_{m1}\cdots\atpat_{mn}
\langle$\ml{:}\ty$\rangle$\ml{=}\exp$_m$ &\cr
& & \qquad\qquad\qquad$\langle\AND\ \fvalbind\rangle$ &\cr}\end{minipage}}
%
\replacementPage{64}{\opp\longconstrs}{\opp\longvidconstrs}
%
\replacementPage{64}{\generativeexnbind}{\generativeexnvidbind}
%
\replacementPage{64}{\eqexnbind}{\eqexnvidbind}
%
\replacementPage{64}{In the $\fvalbind$ form, if $\var$ has infix status then either
~\OP~ must be present, or $\var$ must be infixed. Thus, at the start of
any clause, ``~\OP\ \var\ \ml{(}\atpat\ml{,}\atpat$'$\ml{)} $\cdots$'' may be
written
``\ml{(}\atpat\ \var\ \atpat$'$\ml{)} $\cdots$''; the parentheses may also be
dropped if ``\ml{:}\ty'' or ``\ml{=}'' follows immediately.}{In the $\fvalbind$ form, if $\vid$ has infix status then either
~\OP~ must be present, or $\vid$ must be infixed. Thus, at the start of
any clause, ``~\OP\ \vid\ \ml{(}\atpat\ml{,}\atpat$'$\ml{)} $\cdots$'' may be
written
``\ml{(}\atpat\ \vid\ \atpat$'$\ml{)} $\cdots$''; the parentheses may also be
dropped if ``\ml{:}\ty'' or ``\ml{=}'' follows immediately.}
%
\deletionPage{65}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&$#$\hfil&$#$\hfil\cr
& & \opp\var & variable\cr
& & \opp\longcon & constant\cr
& & \opp\longexn & exception constant\cr}\end{minipage}}
%
\insertionPage{65}{$\opp\longvid$\quad value identifier}
%
\replacementPage{65}{\id}{\vid}
%
\deletionPage{65}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&$#$\hfil&#\hfil\cr
& & \opp\conpat & value construction\cr
& & \opp\exconpat & exception construction\cr
& & \infpat & infixed value construction\cr
& & \infexpat & infixed exception construction\cr
& & \typedpat & typed\cr
& & \opp\layeredpat & layered\cr}\end{minipage}}
%
\insertionPage{65}{\begin{minipage}{\textwidth}\halign{\indent$#$\hfil&$#$\hfil&$#$\hfil&#\hfil\cr
& & \opp\vidpat & constructed value\cr
& & \vidinfpat & constructed value (infix)\cr
& & \typedpat & typed\cr
& & \opp\layeredvidpat & layered\cr}\end{minipage}}
%
\insertionPage{65}{(R)}
%
\insertionPage{66}{
In this appendix (and the next) we define a minimal initial basis for
execution. Richer bases may be provided by libraries.}
%
\insertionPage{66}{
We\index{73.1} shall indicate components of the initial basis by the subscript 0.
The initial static basis is
$\B_0 = \T_0,\F_0,\G_0,\E_0$,
where $F_0 = \emptymap$, $\G_0 = \emptymap$ and
$$\T_0\ =\ \{\BOOL,\INT,\REAL,\STRING,\CHAR,\WORD,\LIST,\REF,\EXCN\}$$
The members of $\T_0$ are type names, not type constructors; for convenience
we have used type-constructor identifiers
to stand also for the type names which are bound to them in the initial
static type environment $\TE_0$. Of these type names,
~\LIST~ and ~\REF~
have arity 1, the rest have arity 0;
all except $\EXCN$ admit equality.
Finally, $\E_0 = (\SE_0,\TE_0,\VE_0)$, where $\SE_0 = \emptymap$,
while $\TE_0$ and $\VE_0$ are shown in Figures~\ref{stat-te} and \ref{stat-ve},
respectively.
}
%
\deletionPage{66}{
We\index{73.1} shall indicate components of the initial basis by the subscript 0.
The initial static basis is
\[ \B_0\ =\ (\M_0,\T_0),\F_0,\G_0,\E_0\]
where
\begin{itemize}
\item $\M_0\ =\ \emptyset$
\item $\T_0\ =\ \{\BOOL,\INT,\REAL,\STRING,\LIST,\REF,\EXCN,\INSTREAM,\OUTSTREAM\}$
\item $\F_0\ =\ \emptymap$
\item $\G_0\ =\ \emptymap$
\item $\E_0\ =\ \longE{0}$
\end{itemize}
The members of $\T_0$ are type names, not type constructors; for convenience
we have used type-constructor identifiers
to stand also for the type names which are bound to them in the initial
static type environment $\TE_0$. Of these type names,
~\LIST~ and ~\REF~
have arity 1, the rest have arity 0;
all except \EXCN, \INSTREAM~
and ~\OUTSTREAM~ admit equality.
The components of $\E_0$ are as follows:
\begin{itemize}
\item $\SE_0\ =\ \emptymap$
\item $\VE_0$ is shown in Figures~\ref{stat-ve} and \ref{stat-veio}.
Note that
$\Dom\VE_0$ contains those identifiers
({\tt true}, {\tt false}, {\tt nil},
\verb+::+, {\tt ref}) which are basic value constructors,
for reasons discussed in Section~\ref{stat-proj}.
$\VE_0$ also includes $\EE_0$, for the same reasons.
\item $\TE_0$ is shown in Figure~\ref{stat-te}. Note that the type
structures in $\TE_0$ contain the type schemes of all basic value
constructors.
\item $\Dom\EE_0\ =\ \BasExc$~, the set of basic exception names listed in
Section~\ref{bas-exc}.
In each case the associated type is ~\EXCN~, except that
~$\EE_0({\tt Io})=\STRING\rightarrow\EXCN$.
\end{itemize}
}
%
\deletionPage{66}{
\begin{figure}
\begin{center}
\begin{tabular}{|rl|}
\hline
$\var$ & $\mapsto\ \tych$\\
\hline
{\tt std\_in} & $\mapsto\ \INSTREAM$\\
{\tt open\_in} & $\mapsto\ \STRING\to\INSTREAM$\\
{\tt input} & $\mapsto\ \INSTREAM\ \ast\ \INT\to\STRING$\\
{\tt lookahead} & $\mapsto\ \INSTREAM\to\STRING$\\
{\tt close\_in} & $\mapsto\ \INSTREAM\to\UNIT$\\
{\tt end\_of\_stream}
& $\mapsto\ \INSTREAM\to\BOOL$\\
\multicolumn{2}{|c|}{}\\
{\tt std\_out} & $\mapsto\ \OUTSTREAM$\\
{\tt open\_out} & $\mapsto\ \STRING\to\OUTSTREAM$\\
{\tt output} & $\mapsto\ \OUTSTREAM\ \ast\ \STRING\to\UNIT$\\
{\tt close\_out} & $\mapsto\ \OUTSTREAM\to\UNIT$\\
\hline
\end{tabular}
\end{center}
\vspace{3pt}
\caption{Static $\VE_0$ (Input/Output)\index{75.1}}
\label{stat-veio}
\end{figure}}
%
\insertionPage{66}{
\begin{figure}[h]
\begin{center}
\begin{tabular}{|rll|}
\hline
$\tycon$ & $\mapsto\ (\ \typefcn$, & $\{\vid_1\mapsto(\tych_1,\is_1),\ldots,\vid_n\mapsto(\tych_n,\is_n)\}\ )\quad (n\geq0)$\\
\hline
\UNIT & $\mapsto\ (\ \Lambda().\{ \}$,
& $\emptymap\ )$ \\
\BOOL & $\mapsto\ (\ \BOOL$, & $\{\TRUE\mapsto(\BOOL,\isc),
\ \FALSE\mapsto(\BOOL,\isc)\}\ )$\\
\INT & $\mapsto\ (\ \INT$, & $\{\}\ )$\\
\WORD & $\mapsto\ (\ \WORD$, & $\{\}\ )$\\
\REAL & $\mapsto\ (\ \REAL$, & $\{\}\ )$\\
\STRING & $\mapsto\ (\ \STRING$, & $\{\}\ )$\\
%\UNISTRING & $\mapsto\ (\ \UNISTRING$, & $\{\}\ )$\\
\CHAR & $\mapsto\ (\ \CHAR$, & $\{\}\ )$\\
%\UNICHAR & $\mapsto\ (\ \UNICHAR$, & $\{\}\ )$\\
\LIST & $\mapsto\ (\ \LIST$, & $\{\NIL\mapsto(\forall\atyvar\ .\ \atyvar\ \LIST, \isc)$,\\
& & \ml{::}$\mapsto(\forall\atyvar\ .
\ \atyvar\ast\atyvar\ \LIST
\to\atyvar\ \LIST, \isc)\}\ )$\\
\REF & $\mapsto\ (\ \REF$, & $\{\REF\mapsto(\forall\ \atyvar\ .\
\atyvar\to\atyvar\ \REF,\isc)\}\ )$\\
\EXCN & $\mapsto\ (\ \EXCN$, & $\emptymap\ )$\\
\hline
\end{tabular}
\end{center}
\vskip-3mm
\caption{Static $\TE_0$\index{75.2}}
\vskip-3mm
\label{stat-te}
\end{figure}}
%
\notePage{66}{Figure (Static $VE_0$): many entries removed (now in library/basis)}
%
\insertionPage{66}{Inserted figure with caption: Static $\VE_0$\index{74}}
%
\insertionPage{67}
The initial dynamic basis is $\B_0 = \F_0,\G_0,\E_0$,
where $\F_0 = \emptymap$, $\G_0 = \emptymap$ and $\E_0 = (\SE_0, \TE_0,\VE_0)$,
where $\SE_0 = \emptymap$, $\TE_0$ is shown in Figure~\ref{dynTE0.fig}
%
\deletionPage{67}{
The initial dynamic basis is
\[ \B_0\ =\ \F_0,\G_0,\E_0\]
where
\begin{itemize}
\item $\F_0\ =\ \emptymap$
\item $\G_0\ =\ \emptymap$
\item $\E_0\ =\ \E_0'+\E_0''$
\end{itemize}
$\E_0'$ contains bindings of identifiers to the basic values BasVal and
basic exception names \BasExc; in fact
~$\E_0'\ =\ \SE_0',\VE_0',\EE_0'$~, where:
\begin{itemize}
\item $\SE_0'\ =\ \emptymap$
\item $\VE_0' = \{{\it id}\mapsto{\it id}\ ;\ {\it id}\in\hbox{BasVal}\}
+\{\hbox{\boxml{:=}}\mapsto\hbox{\boxml{:=}}\} +\EE_0'$\\
\vrule height0pt width3mm depth 0pt$+\;\{\boxml{true}\mapsto\boxml{true},\,\boxml{false}\mapsto\boxml{false},\,\boxml{nil}\mapsto\boxml{nil},\,
\hbox{\boxml{::}}\mapsto\hbox{\boxml{::}},\,
\hbox{\boxml{ref}}\mapsto\hbox{\boxml{ref}}\}$
\item $\EE_0'\ =\ \{\id\mapsto\id\ ;\ \id\in$ \BasExc$\}$
\end{itemize}
}
%
\deletionPage{67}{Note that $\VE_0'$ is the identity function on BasVal; this is because
we have chosen to denote these values by the names of variables
to which they are initially bound.
The semantics of these basic values (most of which are functions)
lies principally in their behaviour under APPLY, which we describe below.
On the other hand the semantics of \boxml{:=} is provided by a special
semantic rule, rule~\ref{assapp-dyn-rule}.
Similarly, $\EE_0'$ is the identity function on \BasExc, the set of
basic exception names, because we have also chosen
these names to be just those exception constructors to which they
are initially bound.
These exceptions are raised by APPLY as described below.
$\E_0''$ contains initial variable bindings which, unlike BasVal, are
definable in ML; it is the result of evaluating
the following declaration in the basis $\F_0,\G_0,\E_0'$. For convenience,
we have also included all basic infix directives in this declaration.
[omitted]
}
%
\insertionPage{67}{
\begin{figure}[h]
\begin{center}
\begin{tabular}{|rll|}
\hline
$\tycon$ & $\mapsto$ & $\{\vid_1\mapsto\V_1,\ldots,\vid_n\mapsto\V_n\}\quad (n\geq0)$\\
\hline
\UNIT & $\mapsto $ & $\emptymap$ \\
\BOOL & $\mapsto $ & $\{\TRUE\mapsto\TRUE
\ \FALSE\mapsto\FALSE\}$\\
\INT & $\mapsto $ & $\{\}$\\
\WORD & $\mapsto $ & $\{\}$\\
\REAL & $\mapsto $ & $\{\}$\\
\STRING & $\mapsto $ & $\{\}$\\
%\UNISTRING & $\mapsto $ & $\{\}$\\
\CHAR & $\mapsto $ & $\{\}$\\
%\UNICHAR & $\mapsto $ & $\{\}$\\
\LIST & $\mapsto $ & $\{\NIL\mapsto\NIL,\ml{::}\mapsto\ml{::}\}$\\
\REF & $\mapsto $ & $\{\REF\mapsto\REF\}$\\
\EXCN & $\mapsto $ & $\emptymap$\\
\hline
\end{tabular}
\end{center}
\caption{Dynamic $\TE_0$}
\label{dynTE0.fig}
\end{figure}}
%
\insertionPage{68}{
\section{Overloading}
\label{overload.sec}
Two forms of overloading are available:
\begin{itemize}
\item Certain special constants are overloaded. For example,
{\tt 0w5} may have type $\WORD$ or some other type, depending on
the surrounding program text;
\item Certain operators are overloaded. For example,
{\tt +} may have type $\INT\ast\INT\to\INT$ or
$\REAL\ast\REAL\to\REAL$, depending on
the surrounding program text;
\end{itemize}
Programmers cannot define their own overloaded constants or operators.
Although a formal treatment of overloading is outside the scope
of this document, we do give a complete list of the overloaded operators
and of types with overloaded special constants.
This list is consistent with the Basis Library\cite{mllib96}.
Every overloaded constant and value identifier has among its types a
{\em default type},
which is ascribed to it, when the surrounding text does not resolve the overloading.
For this purpose, the surrounding text is no larger than the smallest
enclosing structure-level declaration; an implementation may require
that a smaller context determines the type.
\subsection{Overloaded special constants}
Libraries may extend the set $\T_0$ of
Appendix~\ref{init-stat-bas-app} with additional type names. Thereafter, certain
subsets of $T_0$ have a special significance;
they are called {\sl overloading classes}
and they are:\medskip
\halign{\indent#\ \hfil&\ $#$\ &\ $#$\hfil\cr
\Int &\supseteq&\{\INT\}\cr
\Real &\supseteq&\{\REAL\}\cr
\Word &\supseteq&\{\WORD\}\cr
\String&\supseteq&\{\STRING\}\cr
\Char&\supseteq&\{\CHAR\}\cr
\WordInt&=&\Word\cup\INt\cr
\RealInt&=&\Real\cup\INt\cr
\Num&=&\Word\cup\Real\cup\INt\cr
\NumTxt&=&\Word\cup\Real\cup\INt\cup\String\cup\Char\cr}
\medskip
\noindent
Among these, the five first ($\Int$, $\Real$, $\Word$, $\String$ and $\Char$) are said to be
{\sl basic}; the remaining are said to be {\sl composite}.
The reason that the basic classes are specified using
$\supseteq$ rather than $=$ is that libraries may extend
each of the basic overloading
classes with further type names. Special constants are overloaded
within each of the basic overloading classes. However, the basic
overloading classes must be arranged so that every special constant can be
ascribed types from at most one of the basic overloading classes. For
example, to \boxml{0w5} may be ascribed type $\WORD$, or
some other member of $\Word$, depending on the surrounding text. If
the surrounding text does not determine the type of the constant, a
default type is used. The default types for the five sets are $\INT$,
$\REAL$, $\WORD$, $\STRING$ and $\CHAR$ respectively.
Once overloading resolution has determined the type of a special constant,
it is a compile-time error if the constant does not make sense or does not
denote a value within the machine representation chosen for the type.
For example, an escape sequence of the form $\uconst$ in a string constant
of 8-bit characters only makes sense if $xxxx$ denotes
a number in the range $[0, 255]$.
\subsection{Overloaded value identifiers}
Overloaded identifiers all have identifier status $\isv$. An
overloaded identifier may be re-bound with any status ($\isv$, $\isc$
and $\ise$) but then it is not overloaded within the scope of
the binding.
\begin{figure}
\begin{center}
\vskip-12pt
\begin{tabular}{|rl|rl|}
\multicolumn{2}{c}{NONFIX}& \multicolumn{2}{c}{INFIX}\\
\hline
$\var$ & $\mapsto\ \hbox{set of monotypes}$
& $\var$ & $\mapsto\ \hbox{set of monotypes}$\\
\hline
\boxml{abs} & $\mapsto \REALINT\to\REALINT$
& \multicolumn{2}{l|}{Precedence 7, left associative :} \\
\NEG & $\mapsto \REALINT\to\REALINT $ &
\boxml{div} & $\mapsto \WORDINT\ \ast\ \WORDINT
\to\WORDINT$\\
&
&
\boxml{mod} & $\mapsto \WORDINT\ \ast\ \WORDINT
\to\WORDINT$\\
& &
\boxml{*} &$\mapsto \NUM\ \ast\ \NUM
\to\NUM$\\
& &
\boxml{/} &$\mapsto \RREAL\ \ast\ \RREAL
\to\RREAL$\\
& &
\multicolumn{2}{l|}{Precedence 6, left associative :} \\
& &
\boxml{+} &$\mapsto \NUM\ \ast\ \NUM
\to\NUM$\\
& &
\boxml{-} &$\mapsto \NUM\ \ast\ \NUM\to\NUM$\\
&
& \multicolumn{2}{l|}{Precedence 4, left associative :}\\
& &
\boxml{<} & $\mapsto\NUMTEXT *\NUMTEXT \to \NUMTEXT$\\
& &
\boxml{>} & $\mapsto\NUMTEXT *\NUMTEXT \to \NUMTEXT$\\
& &
\boxml{<=} & $\mapsto\NUMTEXT *\NUMTEXT \to \NUMTEXT$\\
& &
\boxml{>=} & $\mapsto\NUMTEXT *\NUMTEXT \to \NUMTEXT$\\
\hline
\end{tabular}
\end{center}
\vskip-15pt
\caption{Overloaded identifiers}
\label{overload.fig}
\end{figure}
}
%
\notePage{70}{This appendix has been revised and extended in
several ways. A detailed list of changes is not available.}
%
\notePage{77}{This appendix is new!}
%
\notePage{94}{The Index has been revised; it is not accurate for
the version that has marginal notes.}
|
module UntypingPairs where
open import Relation.Binary.PropositionalEquality
open import Function using (id)
open import Data.Empty
open import Data.Unit
open import Relation.Nullary
open import Data.Nat
open import Data.Fin
open import Data.Vec
open import Data.Sum
open import Data.Product
open import Data.List
open import Data.Maybe
-- Rather tedious --- stuff grows quadratically. Get this to go
-- through and then see if we can generalize to codes for constructors
-- or something like that.
------------------------------------------------------------
-- Types
------------------------------------------------------------
-- A universe of types for STLC + natural numbers + pairs.
data Type : Set where
Nat : Type
_β_ : Type β Type β Type
_β_ : Type β Type β Type
infixr 80 _β_
infixr 90 _β_
-- The function type constructor is injective.
β-inj : β {Οβ Οβ Οβ Οβ} β (Οβ β Οβ β‘ Οβ β Οβ) β (Οβ β‘ Οβ) Γ (Οβ β‘ Οβ)
β-inj refl = refl , refl
β-inj : β {Οβ Οβ Οβ Οβ} β (Οβ β Οβ β‘ Οβ β Οβ) β (Οβ β‘ Οβ) Γ (Οβ β‘ Οβ)
β-inj refl = refl , refl
-- Equality of types is decidable.
_β‘?_ : (Οβ Οβ : Type) β (Οβ β‘ Οβ) β (Οβ β’ Οβ)
Nat β‘? Nat = injβ refl
Nat β‘? (_ β _) = injβ (Ξ» ())
Nat β‘? (_ β _) = injβ (Ξ» ())
(_ β _) β‘? Nat = injβ (Ξ» ())
(_ β _) β‘? (_ β _) = injβ (Ξ» ())
(_ β _) β‘? Nat = injβ (Ξ» ())
(_ β _) β‘? (_ β _) = injβ (Ξ» ())
(Οβ β Οβ) β‘? (Οβ β Οβ) with Οβ β‘? Οβ | Οβ β‘? Οβ
(Οβ β Οβ) β‘? (.Οβ β .Οβ) | injβ refl | injβ refl = injβ refl
(Οβ β Οβ) β‘? (Οβ β Οβ) | injβ Οββ’Οβ | _ = injβ (Ξ» eq β Οββ’Οβ (projβ (β-inj eq)))
(Οβ β Οβ) β‘? (Οβ β Οβ) | _ | injβ Οββ’Οβ = injβ (Ξ» eq β Οββ’Οβ (projβ (β-inj eq)))
(Οβ β Οβ) β‘? (Οβ β Οβ) with Οβ β‘? Οβ | Οβ β‘? Οβ
(Οβ β Οβ) β‘? (.Οβ β .Οβ) | injβ refl | injβ refl = injβ refl
(Οβ β Οβ) β‘? (Οβ β Οβ) | injβ Οββ’Οβ | _ = injβ (Ξ» x β Οββ’Οβ (projβ (β-inj x)))
(Οβ β Οβ) β‘? (Οβ β Οβ) | _ | injβ Οββ’Οβ = injβ (Ξ» eq β Οββ’Οβ (projβ (β-inj eq)))
β’-cong-β : β {Οβ Οβ Οβ Οβ} β (Οβ β Οβ β’ Οβ β Οβ) β (Οβ β’ Οβ) β (Οβ β’ Οβ)
β’-cong-β {Οβ} {Οβ} {Οβ} {Οβ} neq with Οβ β‘? Οβ | Οβ β‘? Οβ
β’-cong-β neq | injβ Οββ’Οβ | _ = injβ Οββ’Οβ
β’-cong-β neq | _ | injβ Οββ’Οβ = injβ Οββ’Οβ
β’-cong-β neq | injβ refl | injβ refl = β₯-elim (neq refl)
β’-cong-β : β {Οβ Οβ Οβ Οβ} β (Οβ β Οβ β’ Οβ β Οβ) β (Οβ β’ Οβ) β (Οβ β’ Οβ)
β’-cong-β {Οβ} {Οβ} {Οβ} {Οβ} neq with Οβ β‘? Οβ | Οβ β‘? Οβ
β’-cong-β neq | injβ Οββ’Οβ | _ = injβ Οββ’Οβ
β’-cong-β neq | _ | injβ Οββ’Οβ = injβ Οββ’Οβ
β’-cong-β neq | injβ refl | injβ refl = β₯-elim (neq refl)
-- A type of explicit evidence explaining *why* two types are unequal.
data _β_ : Type β Type β Set where
Natββ : β {Οβ Οβ} β Nat β (Οβ β Οβ)
Natββ : β {Οβ Οβ} β Nat β (Οβ β Οβ)
βββ : β {Οβ Οβ Οβ Οβ} β (Οβ β Οβ) β (Οβ β Οβ)
βΛ‘-β : β {Οβ Οβ Οβ Οβ} β Οβ β Οβ β (Οβ β Οβ) β (Οβ β Οβ)
βΚ³-β : β {Οβ Οβ Οβ Οβ} β Οβ β Οβ β (Οβ β Οβ) β (Οβ β Οβ)
βΛ‘-β : β {Οβ Οβ Οβ Οβ} β Οβ β Οβ β (Οβ β Οβ) β (Οβ β Οβ)
βΚ³-β : β {Οβ Οβ Οβ Οβ} β Οβ β Οβ β (Οβ β Οβ) β (Οβ β Οβ)
β-sym : β {Οβ Οβ} β Οβ β Οβ β Οβ β Οβ
-- Given such a proof we can show the types are unequal.
β-β’ : β {Οβ Οβ} β (Οβ β Οβ) β (Οβ β’ Οβ)
β-β’ Natββ = Ξ» ()
β-β’ Natββ = Ξ» ()
β-β’ βββ = Ξ» ()
β-β’ (βΛ‘-β ΟββΟβ) refl = β-β’ ΟββΟβ refl
β-β’ (βΚ³-β ΟββΟβ) refl = β-β’ ΟββΟβ refl
β-β’ (βΛ‘-β ΟββΟβ) refl = β-β’ ΟββΟβ refl
β-β’ (βΚ³-β ΟββΟβ) refl = β-β’ ΟββΟβ refl
β-β’ (β-sym ΟββΟβ) refl = β-β’ ΟββΟβ refl
-- Since our universe of types is closed, we can actually go the other
-- way too. That is, β’ is equivalent to β ; the point is that the
-- latter is more immediately informative (by pattern-matching etc.)
-- which can be used to produce error messages and so on.
--
-- Note, however, that there might be *multiple* terms of type Οβ β
-- Οβ: each corresponds to a different explanation of why the types
-- are not equal. We might actually care which one we have.
-- Round-tripping through (Οβ β’ Οβ) is not the identity.
β’-β : β {Οβ Οβ} β (Οβ β’ Οβ) β (Οβ β Οβ)
β’-β {Nat} {Nat} Οββ’Οβ with Οββ’Οβ refl
... | ()
β’-β {Nat} {Οβ β Οβ} _ = Natββ
β’-β {Nat} {Οβ β Οβ} _ = Natββ
β’-β {Οβ β Οβ} {Nat} _ = β-sym Natββ
β’-β {Οβ β Οβ} {Οβ β Οβ} _ = βββ
β’-β {Οβ β Οβ} {Nat} _ = β-sym Natββ
β’-β {Οβ β Οβ} {Οβ β Οβ} _ = β-sym βββ
β’-β {Οβ β Οβ} {Οβ β Οβ} ΟββΟββ’ΟββΟβ with β’-cong-β ΟββΟββ’ΟββΟβ
β’-β {Οβ β Οβ} {Οβ β Οβ} ΟββΟββ’ΟββΟβ | injβ Οββ’Οβ = βΛ‘-β (β’-β Οββ’Οβ)
β’-β {Οβ β Οβ} {Οβ β Οβ} ΟββΟββ’ΟββΟβ | injβ Οββ’Οβ = βΚ³-β (β’-β Οββ’Οβ)
β’-β {Οβ β Οβ} {Οβ β Οβ} ΟββΟββ’ΟββΟβ with β’-cong-β ΟββΟββ’ΟββΟβ
β’-β {Οβ β Οβ} {Οβ β Οβ} ΟββΟββ’ΟββΟβ | injβ Οββ’Οβ = βΛ‘-β (β’-β Οββ’Οβ)
β’-β {Οβ β Οβ} {Οβ β Οβ} ΟββΟββ’ΟββΟβ | injβ Οββ’Οβ = βΚ³-β (β’-β Οββ’Οβ)
-- Sometimes it's convenient to decide equality of types using β in place of β’.
_βΌ?_ : (Οβ Οβ : Type) β (Οβ β‘ Οβ) β (Οβ β Οβ)
Οβ βΌ? Οβ = Data.Sum.map id β’-β (Οβ β‘? Οβ)
-- Evidence that a type is not an arrow type.
data notβ_ : Type β Set where
notβNat : notβ Nat
notββ : β {Οβ Οβ} β notβ (Οβ β Οβ)
data notβ_ : Type β Set where
notβNat : notβ Nat
notββ : β {Οβ Οβ} β notβ (Οβ β Οβ)
β? : (Ο : Type) β (Ξ£[ Οβ β Type ] Ξ£[ Οβ β Type ] Ο β‘ Οβ β Οβ) β (notβ Ο)
β? Nat = injβ notβNat
β? (_ β _) = injβ notββ
β? (Οβ β Οβ) = injβ (Οβ , Οβ , refl)
------------------------------------------------------------
-- Expressions
------------------------------------------------------------
-- (Untyped) expressions of STLC + arithmetic + pairs.
data Expr (n : β) : Set where
lit : β β Expr n
_β_ : Expr n β Expr n β Expr n
β¨_,_β© : Expr n β Expr n β Expr n
Οβ : Expr n
Οβ : Expr n
var : Fin n β Expr n
Ζ : Type β Expr (suc n) β Expr n
_Β·_ : Expr n β Expr n β Expr n
Ctx : β β Set
Ctx n = Vec Type n
------------------------------------------------------------
-- Typing
------------------------------------------------------------
-- Typing derivations.
data _β’_βΆ_ : β {n} β Ctx n β Expr n β Type β Set where
lit : β {n} {Ξ : Ctx n} {m}
β Ξ β’ lit m βΆ Nat
_β_ : β {n} {Ξ : Ctx n} {tβ tβ}
β Ξ β’ tβ βΆ Nat
β Ξ β’ tβ βΆ Nat
β Ξ β’ (tβ β tβ) βΆ Nat
β¨_,_β© : β {n} {Ξ : Ctx n} {tβ tβ} {Οβ Οβ}
β Ξ β’ tβ βΆ Οβ
β Ξ β’ tβ βΆ Οβ
β Ξ β’ β¨ tβ , tβ β© βΆ Οβ β Οβ
Οβ : β {n} {Ξ : Ctx n} {Οβ Οβ}
β Ξ β’ Οβ βΆ (Οβ β Οβ) β Οβ
Οβ : β {n} {Ξ : Ctx n} {Οβ Οβ}
β Ξ β’ Οβ βΆ (Οβ β Οβ) β Οβ
var : β {n} {Ξ : Ctx n} {i}
β Ξ β’ var i βΆ lookup i Ξ
Ζ : β {n} {Ξ : Ctx n} {t} {Οβ Οβ}
β (Οβ β· Ξ) β’ t βΆ Οβ
β Ξ β’ Ζ Οβ t βΆ (Οβ β Οβ)
_Β·_ : β {n} {Ξ : Ctx n} {tβ tβ} {Οβ Οβ}
β Ξ β’ tβ βΆ Οβ β Οβ
β Ξ β’ tβ βΆ Οβ
β Ξ β’ tβ Β· tβ βΆ Οβ
-- Explicit, constructive evidence for the *untypability* of a term.
data _β¬_βΆ_ : β {n} β Ctx n β Expr n β Type β Set where
-- Explicitly build in uniqueness of typing as an axiom. t is not
-- typeable at type Οβ if t is typeable at some different type.
mismatch : β {n} {Ξ : Ctx n} {t} {Οβ Οβ}
β Ξ β’ t βΆ Οβ
β Οβ β Οβ
β Ξ β¬ t βΆ Οβ
-- There are three ways for a + term to fail to have a given type Ο:
-- either the left or right sides do not have type Nat, or the type
-- Ο itself is not Nat.
βΛ‘ : β {n} {Ξ : Ctx n} {tβ tβ} {Ο}
β Ξ β¬ tβ βΆ Nat
β Ξ β¬ (tβ β tβ) βΆ Ο
βΚ³ : β {n} {Ξ : Ctx n} {tβ tβ} {Ο}
β Ξ β¬ tβ βΆ Nat
β Ξ β¬ (tβ β tβ) βΆ Ο
ββNat : β {n} {Ξ : Ctx n} {tβ tβ} {Ο}
β Ο β Nat β Ξ β¬ (tβ β tβ) βΆ Ο
β¨β©-ty : β {n} {Ξ : Ctx n} {tβ tβ} {Ο}
β notβ Ο β Ξ β¬ β¨ tβ , tβ β© βΆ Ο
β¨β©Λ‘ : β {n} {Ξ : Ctx n} {tβ tβ} {Οβ Οβ}
β Ξ β¬ tβ βΆ Οβ
β Ξ β¬ β¨ tβ , tβ β© βΆ Οβ β Οβ
β¨β©Κ³ : β {n} {Ξ : Ctx n} {tβ tβ} {Οβ Οβ}
β Ξ β¬ tβ βΆ Οβ
β Ξ β¬ β¨ tβ , tβ β© βΆ Οβ β Οβ
Οβ-β : β {n} {Ξ : Ctx n} {Ο}
β notβ Ο
β Ξ β¬ Οβ βΆ Ο
Οβ-β : β {n} {Ξ : Ctx n} {Οβ Οβ}
β notβ Οβ
β Ξ β¬ Οβ βΆ Οβ β Οβ
Οβ-βΌ : β {n} {Ξ : Ctx n} {Οβ Οβ Οβ}
β Οβ β Οβ
β Ξ β¬ Οβ βΆ (Οβ β Οβ) β Οβ
Οβ-β : β {n} {Ξ : Ctx n} {Ο}
β notβ Ο
β Ξ β¬ Οβ βΆ Ο
Οβ-β : β {n} {Ξ : Ctx n} {Οβ Οβ}
β notβ Οβ
β Ξ β¬ Οβ βΆ Οβ β Οβ
Οβ-βΌ : β {n} {Ξ : Ctx n} {Οβ Οβ Οβ}
β Οβ β Οβ
β Ξ β¬ Οβ βΆ (Οβ β Οβ) β Οβ
-- Ζ-funty holds if Ο is not a function type at all, or if it is a
-- function type whose input type is not Οβ.
Ζ-funty : β {n} {Ξ : Ctx n} {t} {Οβ Ο}
β (β {Οβ} β Ο β Οβ β Οβ)
β Ξ β¬ Ζ Οβ t βΆ Ο
-- Otherwise, Ο is of the form (Οβ β Οβ) but the body t does not
-- have type Οβ. Note this could be either because t is not typable
-- at all, or because it has some type other than Οβ.
Ζ : β {n} {Ξ : Ctx n} {t} {Οβ Οβ}
β (Οβ β· Ξ) β¬ t βΆ Οβ
β Ξ β¬ Ζ Οβ t βΆ (Οβ β Οβ)
-- Had this Ζ-resty constructor, but it turns out we don't need it:
-- it is not used in inference or checking, and isn't needed to
-- prove equivalence of β¬ and Β¬ β’ . It handles *only* the case
-- where t is typable but has a type different than the output type
-- of the whole expression; but the Ζ constructor handles this case
-- as well as the case where t is not typeable at all.
-- Ζ-resty : β {n} {Ξ : Ctx n} {t} {Οβ Οβ Οβ}
-- β (Οβ β· Ξ) β’ t βΆ Οβ
-- β Οβ β Οβ
-- β Ξ β¬ Ζ Οβ t βΆ Οβ β Οβ
-- Finally, there are two cases when an application is not typeable.
-- Either the function does not have an appropriate function type,
-- or the argument does not have a type that matches the function's
-- input type.
Β·-fun : β {n} {Ξ : Ctx n} {tβ tβ} {Οβ}
β (β {Οβ} β Ξ β¬ tβ βΆ Οβ β Οβ)
β Ξ β¬ tβ Β· tβ βΆ Οβ
Β·-arg : β {n} {Ξ : Ctx n} {tβ tβ} {Οβ Οβ}
β Ξ β’ tβ βΆ Οβ β Οβ
β Ξ β¬ tβ βΆ Οβ
β Ξ β¬ tβ Β· tβ βΆ Οβ
-- ------------------------------------------------------------
-- -- Type inference and checking
-- ------------------------------------------------------------
-- -- Type inference for a term in a given context returns either a type
-- -- and a valid typing derivation, or a constructive proof that the
-- -- term has no type. Note that in this system, ALL terms can be
-- -- inferred. In a bidirectional system we would have to restrict this
-- -- to only take inferrable terms as inputs.
-- infer : β {n} β (Ξ : Ctx n) β (t : Expr n) β (β Ξ» Ο β Ξ β’ t βΆ Ο) β (β Ο β Ξ β¬ t βΆ Ο)
-- infer Ξ (lit n) = injβ (Nat , lit)
-- infer Ξ (tβ β tβ) with infer Ξ tβ | infer Ξ tβ
-- infer Ξ (tβ β tβ) | injβ (Nat , Ξβ’tββΆNat) | injβ (Nat , Ξβ’tββΆNat) = injβ (Nat , (Ξβ’tββΆNat β Ξβ’tββΆNat))
-- infer Ξ (tβ β tβ) | injβ (Οβ β Οβ , Ξβ’tββΆΟββΟβ) | injβ _ = injβ (Ξ» _ β βΛ‘ (mismatch Ξβ’tββΆΟββΟβ (β-sym Natββ)))
-- infer Ξ (tβ β tβ) | injβ _ | injβ (Οβ β Οβ , Ξβ’tββΆΟββΟβ) = injβ (Ξ» _ β βΚ³ (mismatch Ξβ’tββΆΟββΟβ (β-sym Natββ)))
-- infer Ξ (tβ β tβ) | injβ Ξβ¬tββΆ | _ = injβ (Ξ» _ β βΛ‘ (Ξβ¬tββΆ Nat))
-- infer Ξ (tβ β tβ) | _ | injβ Ξβ¬tββΆ = injβ (Ξ» _ β βΚ³ (Ξβ¬tββΆ Nat))
-- infer Ξ (var i) = injβ (lookup i Ξ , var)
-- infer Ξ (Ζ Οβ t) with infer (Οβ β· Ξ) t
-- infer Ξ (Ζ Οβ t) | injβ (Οβ , Οββ·Ξβ’tβΆΟβ) = injβ (Οβ β Οβ , Ζ Οββ·Ξβ’tβΆΟβ)
-- infer Ξ (Ζ Οβ t) | injβ Οββ·Ξβ¬tβΆ = injβ lemma
-- where
-- lemma : (Ο : Type) β Ξ β¬ Ζ Οβ t βΆ Ο
-- lemma Nat = Ζ-funty Natββ
-- lemma (Οββ² β Οβ) with Οββ² βΌ? Οβ
-- lemma (.Οβ β Οβ) | injβ refl = Ζ (Οββ·Ξβ¬tβΆ Οβ)
-- lemma (Οββ² β Οβ) | injβ Οββ²βΟβ = Ζ-funty (Ξ» {Οβ} β βΛ‘-β Οββ²βΟβ)
-- infer Ξ (tβ Β· tβ) with infer Ξ tβ | infer Ξ tβ
-- infer Ξ (tβ Β· tβ) | injβ (Nat , Ξβ’tββΆNat) | _ = injβ (Ξ» _ β Β·-fun (mismatch Ξβ’tββΆNat Natββ))
-- infer Ξ (tβ Β· tβ) | injβ (Οβ β Οβ , Ξβ’tββΆΟββΟβ) | injβ (Οββ² , Ξβ’tββΆΟββ²) with Οβ βΌ? Οββ²
-- infer Ξ (tβ Β· tβ) | injβ (Οβ β Οβ , Ξβ’tββΆΟββΟβ) | injβ (.Οβ , Ξβ’tββΆΟβ ) | injβ refl = injβ (Οβ , (Ξβ’tββΆΟββΟβ Β· Ξβ’tββΆΟβ))
-- infer Ξ (tβ Β· tβ) | injβ (Οβ β Οβ , Ξβ’tββΆΟββΟβ) | injβ (Οββ² , Ξβ’tββΆΟββ²) | injβ ΟββΟββ² = injβ lemma2
-- where
-- lemma2 : β Ο β Ξ β¬ tβ Β· tβ βΆ Ο
-- lemma2 Ο with Ο βΌ? Οβ
-- lemma2 Ο | injβ Οβ‘Οβ rewrite Οβ‘Οβ = Β·-arg Ξβ’tββΆΟββΟβ (mismatch Ξβ’tββΆΟββ² (β-sym ΟββΟββ²))
-- lemma2 Ο | injβ ΟβΟβ = Β·-fun (mismatch Ξβ’tββΆΟββΟβ (βΚ³-β (β-sym ΟβΟβ)))
-- infer Ξ (tβ Β· tβ) | injβ (Οβ β Οβ , Ξβ’tββΆΟββΟβ) | injβ Ξβ¬tβ = injβ lemma3
-- where
-- lemma3 : β Ο β Ξ β¬ tβ Β· tβ βΆ Ο
-- lemma3 Ο with Ο βΌ? Οβ
-- lemma3 Ο | injβ Οβ‘Οβ rewrite Οβ‘Οβ = Β·-arg Ξβ’tββΆΟββΟβ (Ξβ¬tβ Οβ)
-- lemma3 Ο | injβ ΟβΟβ = Β·-fun (mismatch Ξβ’tββΆΟββΟβ (βΚ³-β (β-sym ΟβΟβ)))
-- infer Ξ (tβ Β· tβ) | injβ Ξβ¬tββΆ | _ = injβ (Ξ» Οβ β Β·-fun (Ξ» {Οβ} β Ξβ¬tββΆ (Οβ β Οβ)))
-- -- Check whether a given term has a *given* type.
-- check : β {n} β (Ξ : Ctx n) β (t : Expr n) β (Ο : Type) β (Ξ β’ t βΆ Ο) β (Ξ β¬ t βΆ Ο)
-- check Ξ (lit _) (Ο β Οβ) = injβ (mismatch lit Natββ)
-- check Ξ (lit _) Nat = injβ lit
-- check Ξ (_ β _ ) (Ο β Οβ) = injβ (ββNat (β-sym Natββ))
-- check Ξ (tβ β tβ) Nat with check Ξ tβ Nat | check Ξ tβ Nat
-- check Ξ (tβ β tβ) Nat | injβ Ξβ’tββΆNat | injβ Ξβ’tββΆNat = injβ (Ξβ’tββΆNat β Ξβ’tββΆNat)
-- check Ξ (tβ β tβ) Nat | injβ Ξβ¬tββΆNat | _ = injβ (βΛ‘ Ξβ¬tββΆNat)
-- check Ξ (tβ β tβ) Nat | _ | injβ Ξβ¬tββΆNat = injβ (βΚ³ Ξβ¬tββΆNat)
-- check Ξ (var i) Ο with Ο βΌ? lookup i Ξ
-- check Ξ (var i) Ο | injβ Οβ‘iΞ rewrite Οβ‘iΞ = injβ var
-- check Ξ (var i) Ο | injβ ΟβiΞ = injβ (mismatch var (β-sym ΟβiΞ))
-- check Ξ (Ζ Οβ t) Nat = injβ (Ζ-funty Natββ)
-- check Ξ (Ζ Οβ t) (Ο β Οβ) with Ο βΌ? Οβ | check (Οβ β· Ξ) t Οβ
-- check Ξ (Ζ Οβ t) (Ο β Οβ) | injβ ΟβΟβ | _ = injβ (Ζ-funty (βΛ‘-β ΟβΟβ))
-- check Ξ (Ζ Οβ t) (.Οβ β Οβ) | injβ refl | injβ Οββ·Ξβ¬tβΆΟβ = injβ (Ζ Οββ·Ξβ¬tβΆΟβ)
-- check Ξ (Ζ Οβ t) (.Οβ β Οβ) | injβ refl | injβ Οββ·Ξβ’tβΆΟβ = injβ (Ζ Οββ·Ξβ’tβΆΟβ)
-- --- Note that in order to check an application we have to use type inference on tβ.
-- check Ξ (tβ Β· tβ) Ο with infer Ξ tβ
-- check Ξ (tβ Β· tβ) Ο | injβ Ξβ¬tββΆ = injβ (Β·-fun (Ξ» {Οβ} β Ξβ¬tββΆ (Οβ β Ο)))
-- check Ξ (tβ Β· tβ) Ο | injβ (Nat , Ξβ’tββΆΟβ) = injβ (Β·-fun (mismatch Ξβ’tββΆΟβ Natββ))
-- check Ξ (tβ Β· tβ) Ο | injβ (Οβ β Οβ , Ξβ’tββΆΟβ) with Ο βΌ? Οβ
-- check Ξ (tβ Β· tβ) Ο | injβ (Οβ β Οβ , Ξβ’tββΆΟβ) | injβ ΟβΟβ = injβ (Β·-fun (mismatch Ξβ’tββΆΟβ (βΚ³-β (β-sym ΟβΟβ))))
-- check Ξ (tβ Β· tβ) Ο | injβ (Οβ β Οβ , Ξβ’tββΆΟβ) | injβ Οβ‘Οβ rewrite Οβ‘Οβ with check Ξ tβ Οβ
-- check Ξ (tβ Β· tβ) Ο | injβ (Οβ β Οβ , Ξβ’tββΆΟβ) | injβ Οβ‘Οβ | injβ Ξβ¬tββΆΟβ = injβ (Β·-arg Ξβ’tββΆΟβ Ξβ¬tββΆΟβ)
-- check Ξ (tβ Β· tβ) Ο | injβ (Οβ β Οβ , Ξβ’tββΆΟβ) | injβ Οβ‘Οβ | injβ Ξβ’tββΆΟβ = injβ (Ξβ’tββΆΟβ Β· Ξβ’tββΆΟβ)
-- ------------------------------------------------------------
-- -- Correctness
-- ------------------------------------------------------------
-- -- The whole idea is that β¬ is a more explicit/constructive, yet
-- -- equivalent, way to represent the negation of β’ . We can actually
-- -- prove the equivalence.
-- -- First, straightforward induction on typing derivations shows that
-- -- we really do have unique types, as assumed by the 'mismatch'
-- -- constructor.
-- β’-unique : β {n} {Ξ : Ctx n} {t : Expr n} {Οβ Οβ : Type} β (Ξ β’ t βΆ Οβ) β (Ξ β’ t βΆ Οβ) β (Οβ β‘ Οβ)
-- β’-unique lit lit = refl
-- β’-unique (_ β _) (_ β _) = refl
-- β’-unique var var = refl
-- β’-unique (Ζ Ξβ’tβΆΟβ) (Ζ Ξβ’tβΆΟβ) rewrite β’-unique Ξβ’tβΆΟβ Ξβ’tβΆΟβ = refl
-- β’-unique (Ξβ’tβΆΟβ Β· _) (Ξβ’tβΆΟβ Β· _) = projβ (β-inj (β’-unique Ξβ’tβΆΟβ Ξβ’tβΆΟβ))
-- -- Now we can do one direction of the equivalence. This direction is
-- -- just induction over derivations, making use of uniqueness of
-- -- typing.
-- β¬-Β¬β’ : β {n} {Ξ : Ctx n} {t : Expr n} {Ο : Type} β (Ξ β¬ t βΆ Ο) β (Β¬ (Ξ β’ t βΆ Ο))
-- β¬-Β¬β’ (mismatch Ξβ’tβΆΟβ ΟββΟ) Ξβ’tβΆΟ = β-β’ ΟββΟ (β’-unique Ξβ’tβΆΟβ Ξβ’tβΆΟ)
-- β¬-Β¬β’ (βΛ‘ Ξβ¬tββΆN) (Ξβ’tββΆN β _ ) = β¬-Β¬β’ Ξβ¬tββΆN Ξβ’tββΆN
-- β¬-Β¬β’ (βΚ³ Ξβ¬tββΆN) (_ β Ξβ’tββΆN) = β¬-Β¬β’ Ξβ¬tββΆN Ξβ’tββΆN
-- β¬-Β¬β’ (ββNat ΟβN) (_ β _ ) = β-β’ ΟβN refl
-- β¬-Β¬β’ (Ζ-funty ΟβΟββ) (Ζ _) = β-β’ ΟβΟββ refl
-- β¬-Β¬β’ (Ζ Ξβ¬tβΆΟβ) (Ζ Ξβ’tβΆΟβ) = β¬-Β¬β’ Ξβ¬tβΆΟβ Ξβ’tβΆΟβ
-- β¬-Β¬β’ (Β·-fun Ξβ¬tβ) (Ξβ’tβ Β· _) = β¬-Β¬β’ Ξβ¬tβ Ξβ’tβ
-- β¬-Β¬β’ (Β·-arg Ξβ’tββΆΟββΟ Ξβ¬tββΆΟ) (Ξβ’tββΆΟββΟ Β· Ξβ’tβ)
-- rewrite projβ (β-inj (β’-unique Ξβ’tββΆΟββΟ Ξβ’tββΆΟββΟ)) = β¬-Β¬β’ Ξβ¬tββΆΟ Ξβ’tβ
-- -- The other direction follows straightforwardly from type checking.
-- Β¬β’-β¬ : β {n} {Ξ : Ctx n} {t : Expr n} {Ο : Type} β (Β¬ (Ξ β’ t βΆ Ο)) β (Ξ β¬ t βΆ Ο)
-- Β¬β’-β¬ {_} {Ξ} {t} {Ο} Β¬Ξβ’tβΆΟ with check Ξ t Ο
-- Β¬β’-β¬ Β¬Ξβ’tβΆΟ | injβ Ξβ’tβΆΟ = β₯-elim (Β¬Ξβ’tβΆΟ Ξβ’tβΆΟ)
-- Β¬β’-β¬ Β¬Ξβ’tβΆΟ | injβ Ξβ¬tβΆΟ = Ξβ¬tβΆΟ
-- ------------------------------------------------------------
-- -- Take 2
-- ------------------------------------------------------------
-- -- XXX these need to be dependent somehow? e.g. consider the Ζ case
-- -- below. If Ο is not an arrow type the whole thing fails; but if it
-- -- does, we need to know what Οβ and Οβ are in order to refer to them
-- -- in the rest of the conditions.
-- data many : List (Set Γ Set) β Set where
-- empty : many []
-- here : β {Tβ Tα΅£ Ts} β Tβ β many Ts β many ((Tβ , Tα΅£) β· Ts)
-- there : β {Tβ Tα΅£ Ts} β Tα΅£ β many Ts β many ((Tβ , Tα΅£) β· Ts)
-- data some : List (Set Γ Set) β Set where
-- here : β {Tβ Tα΅£ Ts} β Tβ β many Ts β some ((Tβ , Tα΅£) β· Ts)
-- there : β {Tβ Tα΅£ Ts} β Tα΅£ β some Ts β some ((Tβ , Tα΅£) β· Ts)
-- -- Unique untypability; gives *every* possible reason that something
-- -- is not typeable. There is no 'mismatch' constructor.
-- {-# NO_POSITIVITY_CHECK #-}
-- data _β¬β_βΆ_ : β {n} β Ctx n β Expr n β Type β Set where
-- lit : β {n} {Ξ : Ctx n} {m} {Ο} β Ο β Nat β Ξ β¬β lit m βΆ Ο
-- -- For tβ β tβ to be untypeable, at least one of three things must be wrong:
-- β : β {n} {Ξ : Ctx n} {tβ tβ Ο}
-- β some
-- ( (Ξ β¬β tβ βΆ Nat , Ξ β’ tβ βΆ Nat) -- Either tβ is well-typed or not
-- β· (Ξ β¬β tβ βΆ Nat , Ξ β’ tβ βΆ Nat) -- Either tβ is well-typed or not
-- β· ((Ο β Nat) , (Ο β‘ Nat)) -- Ο is Nat or not
-- β· []
-- )
-- β Ξ β¬β tβ β tβ βΆ Ο
-- var : β {n} {Ξ : Ctx n} {i Ο}
-- β Ο β lookup i Ξ
-- β Ξ β¬β var i βΆ Ο
-- -- Ζ Οβ t does not have type Ο if
-- -- - Ο is not an arrow type
-- -- Ζ : β {n} {Ξ : Ctx n} {t} {Οβ Οβ Ο}
-- -- β some
-- -- ( (Ο β
|
set.seed(1234)
ind <- sample(2, nrow(iris),replace=TRUE, prob=c(0.7,0.3))
trainData <- iris[ind==1,]
testData <- iris[ind==2,]
library(party)
myFormula <- iris$Species ~ iris$Sepal.Length + iris$Sepal.Width + iris$Petal.Length + iris$Petal.Width
iris_ctree <- ctree(myFormula, data=trainData)
testPred <- predict(iris_ctree, newdata = testData)
print(iris_ctree)
plot(iris_ctree,type="simple")
|
# MadNLP.jl.
# Created by Sungho Shin ([email protected])
mutable struct MonolevelPartition
g::Graph
nparts::Int
part::Vector{Int}
end
mutable struct MonolevelStruc
V::Vector{Int}
new_nbr::Vector{Int}
end
mutable struct BilevelPartition
g_lower::Graph
nparts_lower::Int
part_lower::Vector{Int}
V_lower::Vector{Vector{Int}}
g_upper::Graph
nparts_upper::Int
part_upper::Vector{Int}
end
mutable struct BilevelStruc
V_lower::Vector{Int}
V_upper::Vector{Int}
new_nbr_upper::Vector{Int}
end
mutable struct TwoStagePartition
nparts::Int
part::Vector{Int}
end
get_current_V(mls::MonolevelStruc) = mls.V
get_current_size(mls::MonolevelStruc) = length(mls.V)
get_full_size(mlp::MonolevelPartition) = nv(mlp.g)
function MonolevelPartition(csc::SparseMatrixCSC,part,nparts;max_size=0.)
g = Graph(csc)
isempty(part) && (part=partition(g,nparts,alg=:KWAY))
return MonolevelPartition(g,nparts,part)
end
function MonolevelStruc(mlp::MonolevelPartition,k;max_size=0.)
V = findall(mlp.part.==k)
new_nbr = expand!(V,mlp.g,max_size)
return MonolevelStruc(V,new_nbr)
end
function expand!(mls::MonolevelStruc,mlp::MonolevelPartition,max_size)
mls.new_nbr = expand!(mls.V,mlp.g,max_size,new_nbr=mls.new_nbr)
return
end
get_current_V(bls::BilevelStruc) = bls.V_lower
get_current_size(bls::BilevelStruc) = length(bls.V_upper)
get_full_size(blp::BilevelPartition) = blp.nparts_lower
function BilevelPartition(csc,part_lower,nparts_lower,part_upper,nparts_upper;max_size=0.)
g_lower = Graph(csc)
isempty(part_lower) && (part_lower= partition(g_lower,nparts_lower,alg=:KWAY))
V_lower = Vector{Vector{Int}}(undef,nparts_lower)
@blas_safe_threads for k=1:nparts_lower
V_lower[k] = findall(part_lower.==k)
end
g_upper = Graph(nparts_lower)
for e in edges(g_lower)
add_edge!(g_upper,part_lower[src(e)],part_lower[dst(e)])
end
isempty(part_upper) && (part_upper = partition(g_upper,nparts_upper,alg=:KWAY))
return BilevelPartition(g_lower,nparts_lower,part_lower,V_lower,g_upper,nparts_upper,part_upper)
end
function BilevelStruc(blp::BilevelPartition,k;max_size=0.)
V_upper = findall(blp.part_upper.==k)
new_nbr_upper = expand!(V_upper,blp.g_upper,max_size)
V_lower = vcat(blp.V_lower[V_upper]...)
return BilevelStruc(V_lower,V_upper,new_nbr_upper)
end
function TwoStagePartition(csc::SparseMatrixCSC,part,nparts)
if isempty(part) || findfirst(x->x==0.,part) == nothing
g = Graph(csc)
isempty(part) && (part = partition(g,nparts,alg=:KWAY))
mark_boundary!(g,part)
end
return TwoStagePartition(nparts,part)
end
Graph(csc::SparseMatrixCSC) = Graph(getelistcsc(csc.colptr,csc.rowval))
getelistcsc(colptr,rowval) = [Edge(i,Int(j)) for i=1:length(colptr)-1 for j in @view rowval[colptr[i]:colptr[i+1]-1]]
function expand!(bls::BilevelStruc,blp::BilevelPartition,max_size)
orig_size = length(bls.V_upper)
bls.new_nbr_upper = expand!(bls.V_upper,blp.g_upper,max_size,new_nbr=bls.new_nbr_upper)
bls.V_lower = vcat(blp.V_lower[bls.V_upper]...)
return
end
function expand!(V_om,g::Graph,max_size;
new_nbr=[])
if isempty(new_nbr)
new_nbr = Int[]
for v in V_om
append!(new_nbr,neighbors(g,v))
end
unique!(new_nbr)
setdiff!(new_nbr,V_om)
end
old_nbr = V_om
while (length(V_om) + length(new_nbr) < max_size) && length(V_om) < nv(g) && !isempty(new_nbr)
append!(V_om,new_nbr)
old_old_nbr = old_nbr
old_nbr=new_nbr
new_nbr = Int[]
for v in old_nbr
append!(new_nbr,neighbors(g,v))
end
unique!(new_nbr)
setdiff!(new_nbr,old_old_nbr)
setdiff!(new_nbr,old_nbr)
end
return new_nbr
end
function mark_boundary!(g,part)
for e in edges(g)
(part[src(e)]!=part[dst(e)] && part[src(e)]!= 0 && part[dst(e)] != 0) &&
(part[src(e)] = 0; part[dst(e)] = 0)
end
end
|
\chapter{GMAT System Framework}
\chapauthor{Darrel J. Conway}{Thinking Systems, Inc.}
The GMAT system consists of a high level framework, the GMAT Application, that manages system level
messages processed by GMAT. This framework contains a single instance of the core GMAT executive,
the Moderator, which manages the functionality of the system. The Moderator interacts with five
high level elements, shown in Figure 1, that function together to run the system.
The Interpreter subsystem consists of two separate components. The interpreter contains the current
mission script, used to generate the mission event sequence, and the interface to the GMAT user
interface. This latter interface takes the defined user actions and passes these actions to the
appropriate elements in the system -- for instance, when a user presses a ``Run Mission'' button on
the GMAT GUI, the command is passed to the user action interpreter, which then configures the
objects needed to run the current script and then starts the execution of the script. (Okay, that
sentence assumes a lot that I haven't talked about yet...)
The Environment subsystem contains configuration information for the system data files, external
programs (e.g. MATLAB), and a number of utility subsystems (Okay, I needed someplace to put these --
is this the best place?) used to perform common tasks. It acts as the repository for all of the
information needed for GMAT to talk to other elements running on a user's workstation, along with
the central location for information about the data files used by the system.
GMAT contains numerous classes that are used to perform spacecraft modeling. These classes are all
managed by a set of components that construct instances of the classes needed by a script; these
components are shown on Figure 1 as a set of object factories defined for the system. This
infrastructure provides the flexibility needed by the system to give users the ability to add custom
components to the system, and will be described in more detail later in this document. (This piece
is pretty core to the design I'm thinking about right now, so it needs to be examined closely to be
sure we get what we want in GMAT. Of course, that means it's also the hardest part to explain --
especially when I try to muddle through the way the system puts it together with the script
interpreter and the configurations!)
The GMAT Moderator includes a container used to manage lists of configured components used by the
system to perform mission analysis. GMAT maintains these lists as the core object structures
manipulated by the system to perform mission analysis. The Moderator has the following core lists
used in a mission timeline:
\begin{enumerate}
\item Solar System Configurations: A list of the celestial objects (star(s), planets, moons,
asteroids and comets that represent the playing field for mission analysis scenarios
\item Propagation Configurations: A list of configured propagation elements used to evolve the
modeled elements during analysis
\item Asset Configurations: A container for spacecraft, formations1 of spacecraft, and ground assets
\item Force Model Configurations: Collections of forces used to model perturbations acting on the
assets
\item Script Configurations: Either complete timelines or ``subscripts'', consisting of a sequence
of actions taken by the system to model all or a piece of an orbit problem
\item Mathematical Configurations: Elements used to perform custom calculations and for
communication with external programs like MATLAB
\end{enumerate}
GMAT runs are performed in the GMAT Sandbox. This portion of the system is the container for the
components of a run, linked together to perform the sequence of events in the mission timeline. When
a user tells GMAT to run the script, the system moderator uses the script interpreter to interpret
the contents of a script, and to place the corresponding script elements into the sandbox for use
during the run. The Moderator links each element placed into the sandbox to its neighboring
elements. Once the full script has been translated into the components in the sandbox, the
Moderator starts the run by calling the Run method on the sandbox.
The following sections describe each of these components more completely. These descriptions are
followed by several sample system configurations. The last section of this document provides
details of the classes used in this design.
|
[STATEMENT]
lemma hindered_conv_hindered_by: "hindered \<Gamma> \<longleftrightarrow> (\<exists>\<epsilon>>0. hindered_by \<Gamma> \<epsilon>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. hindered \<Gamma> = (\<exists>\<epsilon>>0. hindered_by \<Gamma> \<epsilon>)
[PROOF STEP]
by(blast intro: hindered_into_hindered_by hindered_by_into_hindered)
|
module PLRTree.Complete {A : Set} where
open import PLRTree {A}
open import PLRTree.Equality {A}
data _β_ : PLRTree β PLRTree β Set where
βlf : (x : A)
β node perfect x leaf leaf β leaf
βnd : {l r l' r' : PLRTree}
(x x' : A)
β l β r
β l' β r'
β l β l'
β node perfect x l r β node perfect x' l' r'
mutual
data _β_ : PLRTree β PLRTree β Set where
xβ : (x y z : A)
β node right x (node perfect y leaf leaf) leaf β node perfect z leaf leaf
lβ : {l r l' r' : PLRTree}
β (x x' : A)
β l β r
β l' β r'
β r β l'
β (node left x l r) β (node perfect x' l' r')
rβ : {l r l' r' : PLRTree}
β (x x' : A)
β l β r
β l' β r'
β l β l'
β (node right x l r) β (node perfect x' l' r')
data _β_ : PLRTree β PLRTree β Set where
βp : {l r : PLRTree}
β l β r
β l β r
βl : {l r l' r' : PLRTree}
β (x x' : A)
β l β r
β l' β r'
β l β r'
β (node perfect x l r) β (node left x' l' r')
βr : {l r l' r' : PLRTree}
β (x x' : A)
β l β r
β l' β r'
β l β l'
β (node perfect x l r) β (node right x' l' r')
data Complete : PLRTree β Set where
leaf : Complete leaf
perfect : {l r : PLRTree}
(x : A)
β Complete l
β Complete r
β l β r
β Complete (node perfect x l r)
left : {l r : PLRTree}
(x : A)
β Complete l
β Complete r
β l β r
β Complete (node left x l r)
right : {l r : PLRTree}
(x : A)
β Complete l
β Complete r
β l β r
β Complete (node right x l r)
|
= = = Voice Type = = =
|
/* -----------------------------------------------------------------------------
* Copyright 2021 Jonathan Haigh
* SPDX-License-Identifier: MIT
* ---------------------------------------------------------------------------*/
#ifndef SQ_INCLUDE_GUARD_parser_TokenView_h_
#define SQ_INCLUDE_GUARD_parser_TokenView_h_
#include "core/Token.h"
#include "core/typeutil.h"
#include <gsl/gsl>
#include <optional>
#include <range/v3/view/facade.hpp>
#include <string_view>
namespace sq::parser {
/**
* A ranges::view of the input query split into tokens.
*/
class TokenView : public ranges::view_facade<TokenView> {
public:
explicit TokenView(std::string_view str) noexcept;
TokenView() noexcept = default;
TokenView(const TokenView &) noexcept = default;
TokenView(TokenView &&) noexcept = default;
TokenView &operator=(const TokenView &) noexcept = default;
TokenView &operator=(TokenView &&) noexcept = default;
~TokenView() noexcept = default;
// required for ranges::view_facade
friend ranges::range_access;
SQ_ND const Token &read() const;
SQ_ND bool equal(ranges::default_sentinel_t other) const noexcept;
void next();
private:
gsl::index whitespace_length() const;
std::string_view str_;
gsl::index pos_ = 0;
mutable std::optional<Token> cache_ = std::nullopt;
};
} // namespace sq::parser
#endif // SQ_INCLUDE_GUARD_parser_TokenView_h_
|
import utilities
open list
open multiset
open set
open nat
set_option trace.simplify.rewrite true
variable {Ξ± : Type*}
variable r: Ξ± β Ξ± β Prop
variable x: Ξ±
variable xs: list Ξ±
/-
# Insertion sort
The two functions insort and isort from __Functional Algorithms, Verified!__ are defined in Lean
as ordered_insert and insertion_sort respectively and are reused.
## Functional Correctness
-/
lemma mset_insort [decidable_rel r] : (ordered_insert r x xs: multiset Ξ±) = {x} + βxs :=
begin
induction' xs,
{ refl },
{ simp,
split_ifs,
refl,
simp [β multiset.cons_coe, ih] }
end
lemma mset_isort [decidable_rel r] : (insertion_sort r xs: multiset Ξ±) = βxs :=
begin
induction' xs,
{ refl },
{ simp [mset_insort, ih],
refl }
end
lemma set_insort [decidable_rel r] : (ordered_insert r x xs).to_set = {x} βͺ xs.to_set :=
begin
simp [set.insert_def, β set_mset_mset, mset_insort, multiset.to_set],
end
lemma sorted_insort [decidable_rel r] [is_linear_order Ξ± r] : sorted' r (ordered_insert r x xs) = sorted' r xs :=
begin
-- By using fixing the trans and total_of functions work without writing the is_total and is_trans instances explicitly.
induction' xs fixing *,
{ simp [sorted'],
intros,
exact false.elim H },
{ simp only [ordered_insert],
split_ifs,
{ simp [sorted', list.to_set],
intros h1 h2,
apply and.intro h,
intros y h3,
have h4: y β xs.to_set β r hd y, from h1 y,
have h5: r hd y, from h4 h3,
exact trans h h5 },
{ simp [sorted', list.to_set, ih, set_insort],
intros h1 h2,
exact or.resolve_right (total_of r hd x) h } }
end
lemma sorted_isort [decidable_rel r] [is_linear_order Ξ± r]: sorted' r (insertion_sort r xs) :=
begin
induction' xs,
repeat { simp [sorted_insort, *] }
end
/-
## Time Complexity
We count the number of function calls.
-/
def T_insort [decidable_rel r] : Ξ± β list Ξ± β nat
| x [] := 1
| x (y::ys) := if r x y then 0 else T_insort x ys + 1
def T_isort [decidable_rel r] : list Ξ± β nat
| [] := 1
| (x::xs) := T_isort xs + T_insort r x (insertion_sort r xs) + 1
lemma T_insort_length [decidable_rel r]: T_insort r x xs <= xs.length + 1 :=
begin
induction' xs,
repeat { simp [T_insort] },
split_ifs,
repeat { simp *},
end
lemma length_insort [decidable_rel r] : (ordered_insert r x xs).length = xs.length + 1 :=
begin
induction' xs,
repeat { simp [ordered_insert] },
split_ifs,
repeat { simp *},
end
lemma length_isort [decidable_rel r] : (insertion_sort r xs).length = xs.length :=
begin
induction' xs,
repeat { simp [length_insort, *] }
end
/-
Lemma 2.1 from __Functional Algorithms, Verified!__
-/
lemma T_isort_length [decidable_rel r]: T_isort r xs <= (xs.length + 1) ^ 2 :=
begin
induction' xs fixing *,
repeat { simp [T_isort, T_insort_length, length_isort ]},
show T_isort r xs + T_insort r hd (insertion_sort r xs) + 1 β€ (xs.length + 1 + 1) ^ 2, by calc
T_isort r xs + T_insort r hd (insertion_sort r xs) + 1 β€ (xs.length + 1) ^ 2 + T_insort r hd (insertion_sort r xs) + 1 : by simp [ih]
... β€ (xs.length + 1) ^ 2 + ((insertion_sort r xs).length + 1) + 1 : by simp [T_insort_length]
... = (xs.length + 1) ^ 2 + (xs.length + 1) + 1 : by simp [length_isort]
... = xs.length ^2 + 2 * xs.length + xs.length + 3 : by ring
... β€ xs.length ^2 + 2 * xs.length + xs.length + xs.length + 3 : by simp
... β€ xs.length ^2 + 2 * xs.length + xs.length + xs.length + 4 : by simp
... = (xs.length + 1 + 1) ^ 2 : by ring,
end
|
(* Author: Bohua Zhan, with modifications by Tobias Nipkow *)
section \<open>Interval Trees\<close>
theory Interval_Tree
imports
"HOL-Data_Structures.Cmp"
"HOL-Data_Structures.List_Ins_Del"
"HOL-Data_Structures.Isin2"
"HOL-Data_Structures.Set_Specs"
begin
subsection \<open>Intervals\<close>
text \<open>The following definition of intervals uses the \<^bold>\<open>typedef\<close> command
to define the type of non-empty intervals as a subset of the type of pairs \<open>p\<close>
where @{prop "fst p \<le> snd p"}:\<close>
typedef (overloaded) 'a::linorder ivl =
"{p :: 'a \<times> 'a. fst p \<le> snd p}" by auto
text \<open>More precisely, @{typ "'a ivl"} is isomorphic with that subset via the function
@{const Rep_ivl}. Hence the basic interval properties are not immediate but
need simple proofs:\<close>
definition low :: "'a::linorder ivl \<Rightarrow> 'a" where
"low p = fst (Rep_ivl p)"
definition high :: "'a::linorder ivl \<Rightarrow> 'a" where
"high p = snd (Rep_ivl p)"
lemma ivl_is_interval: "low p \<le> high p"
by (metis Rep_ivl high_def low_def mem_Collect_eq)
lemma ivl_inj: "low p = low q \<Longrightarrow> high p = high q \<Longrightarrow> p = q"
by (metis Rep_ivl_inverse high_def low_def prod_eqI)
text \<open>Now we can forget how exactly intervals were defined.\<close>
instantiation ivl :: (linorder) linorder begin
definition ivl_less: "(x < y) = (low x < low y | (low x = low y \<and> high x < high y))"
definition ivl_less_eq: "(x \<le> y) = (low x < low y | (low x = low y \<and> high x \<le> high y))"
instance proof
fix x y z :: "'a ivl"
show a: "(x < y) = (x \<le> y \<and> \<not> y \<le> x)"
using ivl_less ivl_less_eq by force
show b: "x \<le> x"
by (simp add: ivl_less_eq)
show c: "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
using ivl_less_eq by fastforce
show d: "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
using ivl_less_eq a ivl_inj ivl_less by fastforce
show e: "x \<le> y \<or> y \<le> x"
by (meson ivl_less_eq leI not_less_iff_gr_or_eq)
qed end
definition overlap :: "('a::linorder) ivl \<Rightarrow> 'a ivl \<Rightarrow> bool" where
"overlap x y \<longleftrightarrow> (high x \<ge> low y \<and> high y \<ge> low x)"
definition has_overlap :: "('a::linorder) ivl set \<Rightarrow> 'a ivl \<Rightarrow> bool" where
"has_overlap S y \<longleftrightarrow> (\<exists>x\<in>S. overlap x y)"
subsection \<open>Interval Trees\<close>
type_synonym 'a ivl_tree = "('a ivl * 'a) tree"
fun max_hi :: "('a::order_bot) ivl_tree \<Rightarrow> 'a" where
"max_hi Leaf = bot" |
"max_hi (Node _ (_,m) _) = m"
definition max3 :: "('a::linorder) ivl \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" where
"max3 a m n = max (high a) (max m n)"
fun inv_max_hi :: "('a::{linorder,order_bot}) ivl_tree \<Rightarrow> bool" where
"inv_max_hi Leaf \<longleftrightarrow> True" |
"inv_max_hi (Node l (a, m) r) \<longleftrightarrow> (m = max3 a (max_hi l) (max_hi r) \<and> inv_max_hi l \<and> inv_max_hi r)"
lemma max_hi_is_max:
"inv_max_hi t \<Longrightarrow> a \<in> set_tree t \<Longrightarrow> high a \<le> max_hi t"
by (induct t, auto simp add: max3_def max_def)
lemma max_hi_exists:
"inv_max_hi t \<Longrightarrow> t \<noteq> Leaf \<Longrightarrow> \<exists>a\<in>set_tree t. high a = max_hi t"
proof (induction t rule: tree2_induct)
case Leaf
then show ?case by auto
next
case N: (Node l v m r)
then show ?case
proof (cases l rule: tree2_cases)
case Leaf
then show ?thesis
using N.prems(1) N.IH(2) by (cases r, auto simp add: max3_def max_def le_bot)
next
case Nl: Node
then show ?thesis
proof (cases r rule: tree2_cases)
case Leaf
then show ?thesis
using N.prems(1) N.IH(1) Nl by (auto simp add: max3_def max_def le_bot)
next
case Nr: Node
obtain p1 where p1: "p1 \<in> set_tree l" "high p1 = max_hi l"
using N.IH(1) N.prems(1) Nl by auto
obtain p2 where p2: "p2 \<in> set_tree r" "high p2 = max_hi r"
using N.IH(2) N.prems(1) Nr by auto
then show ?thesis
using p1 p2 N.prems(1) by (auto simp add: max3_def max_def)
qed
qed
qed
subsection \<open>Insertion and Deletion\<close>
definition node where
[simp]: "node l a r = Node l (a, max3 a (max_hi l) (max_hi r)) r"
fun insert :: "'a::{linorder,order_bot} ivl \<Rightarrow> 'a ivl_tree \<Rightarrow> 'a ivl_tree" where
"insert x Leaf = Node Leaf (x, high x) Leaf" |
"insert x (Node l (a, m) r) =
(case cmp x a of
EQ \<Rightarrow> Node l (a, m) r |
LT \<Rightarrow> node (insert x l) a r |
GT \<Rightarrow> node l a (insert x r))"
lemma inorder_insert:
"sorted (inorder t) \<Longrightarrow> inorder (insert x t) = ins_list x (inorder t)"
by (induct t rule: tree2_induct) (auto simp: ins_list_simps)
lemma inv_max_hi_insert:
"inv_max_hi t \<Longrightarrow> inv_max_hi (insert x t)"
by (induct t rule: tree2_induct) (auto simp add: max3_def)
fun split_min :: "'a::{linorder,order_bot} ivl_tree \<Rightarrow> 'a ivl \<times> 'a ivl_tree" where
"split_min (Node l (a, m) r) =
(if l = Leaf then (a, r)
else let (x,l') = split_min l in (x, node l' a r))"
fun delete :: "'a::{linorder,order_bot} ivl \<Rightarrow> 'a ivl_tree \<Rightarrow> 'a ivl_tree" where
"delete x Leaf = Leaf" |
"delete x (Node l (a, m) r) =
(case cmp x a of
LT \<Rightarrow> node (delete x l) a r |
GT \<Rightarrow> node l a (delete x r) |
EQ \<Rightarrow> if r = Leaf then l else
let (a', r') = split_min r in node l a' r')"
lemma split_minD:
"split_min t = (x,t') \<Longrightarrow> t \<noteq> Leaf \<Longrightarrow> x # inorder t' = inorder t"
by (induct t arbitrary: t' rule: split_min.induct)
(auto simp: sorted_lems split: prod.splits if_splits)
lemma inorder_delete:
"sorted (inorder t) \<Longrightarrow> inorder (delete x t) = del_list x (inorder t)"
by (induct t)
(auto simp: del_list_simps split_minD Let_def split: prod.splits)
lemma inv_max_hi_split_min:
"\<lbrakk> t \<noteq> Leaf; inv_max_hi t \<rbrakk> \<Longrightarrow> inv_max_hi (snd (split_min t))"
by (induct t) (auto split: prod.splits)
lemma inv_max_hi_delete:
"inv_max_hi t \<Longrightarrow> inv_max_hi (delete x t)"
apply (induct t)
apply simp
using inv_max_hi_split_min by (fastforce simp add: Let_def split: prod.splits)
subsection \<open>Search\<close>
text \<open>Does interval \<open>x\<close> overlap with any interval in the tree?\<close>
fun search :: "'a::{linorder,order_bot} ivl_tree \<Rightarrow> 'a ivl \<Rightarrow> bool" where
"search Leaf x = False" |
"search (Node l (a, m) r) x =
(if overlap x a then True
else if l \<noteq> Leaf \<and> max_hi l \<ge> low x then search l x
else search r x)"
lemma search_correct:
"inv_max_hi t \<Longrightarrow> sorted (inorder t) \<Longrightarrow> search t x = has_overlap (set_tree t) x"
proof (induction t rule: tree2_induct)
case Leaf
then show ?case by (auto simp add: has_overlap_def)
next
case (Node l a m r)
have search_l: "search l x = has_overlap (set_tree l) x"
using Node.IH(1) Node.prems by (auto simp: sorted_wrt_append)
have search_r: "search r x = has_overlap (set_tree r) x"
using Node.IH(2) Node.prems by (auto simp: sorted_wrt_append)
show ?case
proof (cases "overlap a x")
case True
thus ?thesis by (auto simp: overlap_def has_overlap_def)
next
case a_disjoint: False
then show ?thesis
proof cases
assume [simp]: "l = Leaf"
have search_eval: "search (Node l (a, m) r) x = search r x"
using a_disjoint overlap_def by auto
show ?thesis
unfolding search_eval search_r
by (auto simp add: has_overlap_def a_disjoint)
next
assume "l \<noteq> Leaf"
then show ?thesis
proof (cases "max_hi l \<ge> low x")
case max_hi_l_ge: True
have "inv_max_hi l"
using Node.prems(1) by auto
then obtain p where p: "p \<in> set_tree l" "high p = max_hi l"
using \<open>l \<noteq> Leaf\<close> max_hi_exists by auto
have search_eval: "search (Node l (a, m) r) x = search l x"
using a_disjoint \<open>l \<noteq> Leaf\<close> max_hi_l_ge by (auto simp: overlap_def)
show ?thesis
proof (cases "low p \<le> high x")
case True
have "overlap p x"
unfolding overlap_def using True p(2) max_hi_l_ge by auto
then show ?thesis
unfolding search_eval search_l
using p(1) by(auto simp: has_overlap_def overlap_def)
next
case False
have "\<not>overlap x rp" if asm: "rp \<in> set_tree r" for rp
proof -
have "low p \<le> low rp"
using asm p(1) Node(4) by(fastforce simp: sorted_wrt_append ivl_less)
then show ?thesis
using False by (auto simp: overlap_def)
qed
then show ?thesis
unfolding search_eval search_l
using a_disjoint by (auto simp: has_overlap_def overlap_def)
qed
next
case False
have search_eval: "search (Node l (a, m) r) x = search r x"
using a_disjoint False by (auto simp: overlap_def)
have "\<not>overlap x lp" if asm: "lp \<in> set_tree l" for lp
using asm False Node.prems(1) max_hi_is_max
by (fastforce simp: overlap_def)
then show ?thesis
unfolding search_eval search_r
using a_disjoint by (auto simp: has_overlap_def overlap_def)
qed
qed
qed
qed
definition empty :: "'a ivl_tree" where
"empty = Leaf"
subsection \<open>Specification\<close>
locale Interval_Set = Set +
fixes has_overlap :: "'t \<Rightarrow> 'a::linorder ivl \<Rightarrow> bool"
assumes set_overlap: "invar s \<Longrightarrow> has_overlap s x = Interval_Tree.has_overlap (set s) x"
fun invar :: "('a::{linorder,order_bot}) ivl_tree \<Rightarrow> bool" where
"invar t = (inv_max_hi t \<and> sorted(inorder t))"
interpretation S: Interval_Set
where empty = Leaf and insert = insert and delete = delete
and has_overlap = search and isin = isin and set = set_tree
and invar = invar
proof (standard, goal_cases)
case 1
then show ?case by auto
next
case 2
then show ?case by (simp add: isin_set_inorder)
next
case 3
then show ?case by(simp add: inorder_insert set_ins_list flip: set_inorder)
next
case 4
then show ?case by(simp add: inorder_delete set_del_list flip: set_inorder)
next
case 5
then show ?case by auto
next
case 6
then show ?case by (simp add: inorder_insert inv_max_hi_insert sorted_ins_list)
next
case 7
then show ?case by (simp add: inorder_delete inv_max_hi_delete sorted_del_list)
next
case 8
then show ?case by (simp add: search_correct)
qed
end
|
lemma norm_minus_commute: "norm (a - b) = norm (b - a)"
|
\section{Metric Spaces}
\setcounter{subsection}{6}
\subsection{Compact Metric Space}
\paragraph{27.}
\begin{proof}
If $\rho(F, K) > 0$, then clear that $F\cap K = \varnothing$. For the reverse
direction, consider the function $h(x) = \rho(x, F)= \inf_{y\in F}\rho(x,y)$.
Clear that for $x\in K$, $h(x) \le \rho(K, F)$.
First, we show that $h$ is continuous. Let $x$ be fixed. For every
$x\hp \in X$
\[
h(x) \le \rho(x, y) \le \rho(x, x\hp) + \rho(x\hp, y),
\quad\forall y\in F.
\]
Take infimum on the right hand side and we get
\[
h(x) \le \rho(x, x\hp) + h(x\hp)
\quad\Rightarrow\quad
h(x) - h(x\hp) \le \rho(x, x\hp).
\]
Similarly, we have $h(x\hp) - h(x) \le \rho(x, x\hp)$. Thus, $h$ is
continuous.
Since $K$ is compact and $h$ is continuous, $h$ attains its infimum $c$
at some point $x_0 \in K$. Assume, to obtain a contradiction, that $c = 0$.
Then, for every $\vep > 0$, there is a $y \in F$ s.t. $\rho(x_0, y) < \vep$.
Namely, $x_0$ is a cluster point of $F$. Since $F$ is closed, $x_0 \in F$,
which contradicts with $F\cap K=\varnothing$. Thus, $c > 0$ and therefore
$\rho(F, K) > 0$.
\end{proof}
\paragraph{28.}
\begin{proof}
$\,$\par
(a) Let $\vep > 0$ be fixed. Since $f$ is uniformly continuous, there exists
some $\delta > 0$ s.t. for every $x_1,x_2\in X$ with $\rho(x_1, x_2) <
\delta$, $\rho(f(x_1), f(x_2)) < \vep$. Let $B\subset X$ be a ball with
radius $\delta/2$. Then $f(B) \subset Y$ is contained by some ball of
radius $\vep$. Hence, we can cover $Y$ with finitely many balls of radius
$\vep$ as long as we can cover $X$ with finitely many balls of radius
$\delta / 2$ and this can be done since $X$ is totally bounded.
(b) Clear that $X = (0, 1)$ is totally bounded while $Y = (1, \infty)$ is
not. The function $1/x$ a continuous function that maps $X$ onto $Y$. Hence,
the result does not hold.
\end{proof}
\paragraph{29.}
\begin{proof}
$\,$\par
(a) First, by the definition of open cover and open sets, $\varphi(x) > 0$.
Meanwhile, since $X$ is compact, it is bounded and, therefore,
$\varphi(x) < \infty$.
(b) Let $x$ be fixed and $r$ be such that there exists some $O\in \mcal{U}$
with $B_{x, r}\subset O$. Let $s = r - \rho(x, y)$. If $s \le 0$, then
clear that $s \le \varphi(y)$. If $s > 0$, then we have $B_{y, s}
\subset B_{x, r} \subset O$. Hence, $s \le \varphi(y)$. Thus,
$r - \rho(x, y) \le \varphi(y)$. Take supremum on the left hand side and we
get $\varphi(x) - \rho(x, y) \le \varphi(y)$.
(c) It follows immediately from (b).
(d) Let $(x_n)$ be a sequence s.t. $\varphi(x_n) \to \vep$. Since $X$ is
sequentially compact, $(x_n)$ has a convergent subsequence. For the sake of
convenience, we assume the subsequence is $(x_n)$ itself. Suppose $x_n
\to x$. Since $\varphi$ is continuous, $\varphi(x) = \lim\varphi(x_n) =
\vep$. Thus, by (a), $\vep > 0$.
(e) Let $\delta$ be any positive number that is less than $\vep$. For every
$x$, since $\delta < \vep = \inf\varphi$, $\delta < \varphi(x)$ and,
therefore, $B_{x, \delta} \subset O$ for some $O \in \mcal{U}$.
\end{proof}
\subsection{Baire Category}
\paragraph{31.(a)}
\begin{proof}
Suppose that $F$ is nowhere dense. Since $F$ is closed, $F^c$ is dense.
Therefore, for every point $x\in F$, every neighborhood of $x$ contains a
point of $F^c$. Thus, $F$ contains to open set. For the reverse direction,
since $F$ contains no open set, every neighborhood of every $x\in X$ contains
a point in $F^c$, which implies that $F^c$ is dense.
\end{proof}
\paragraph{34.}
\begin{proof}
For the first part, it suffices to show that $\partial E$ is nowhere dense
for any set $E \subset X$. Since $\partial E$ is closed and contains no open
set, by 31.(a), it is nowhere dense.
For the second part, assume, to obtain a contradiction, that $F$ is not
nowhere dense. Then by 31.(a), it contains an nonempty open set $O$. By
32.(a), $O$ is also meager, which contradicts the Baire category theorem.
\end{proof}
\paragraph{35.}
\begin{proof}
Let $E$ be a subset set of the complete metric space $X$. If $E$ is residual,
then $E^c = \bigcup_n K_n$ where $K_n$ are nowhere dense sets. Hence,
\[
E = \bigcap K_n^c \supset \bigcap (\cl K_n)^c.
\]
Note that $(\cl K_n)^c$ is a $G_\delta$. Meanwhile, since each $(\cl K_n)^c$
is a dense open set and $X$ is complete, By the theorem of Baire,
$\bigcap (\cl K_n)^c$ is also dense. The proof of the reverse direction is
similar.
\end{proof}
\paragraph{39.}
\begin{proof}
Let $E_m$ has the same meaning as in the proof of Theorem 32. Let $O :=
\bigcup_m E_m^\circ$. By Prop. 31, $O$ is a dense residual open set. For
every $x\in O$, $x \in E_m^\circ$ for some $m$. Since $E_m^\circ$ is open,
there is a neighborhood $U$ of $x$ which is contained by $E_m^\circ$. Thus,
$\mcal{F}$ is uniformly bounded by $m$ in $U$.
\end{proof}
\setcounter{subsection}{9}
\subsection{The Ascoli-Arzel\'{a} Theorem}
\paragraph{47.}
\begin{proof}
Let $x$ be an arbitrary fixed point in $X$ and $(x_n)\subset X$ a sequence
that converges to $x$. Clear that $K = \{x\}\cup(x_n)$ is (sequently)
compact. Hence, $f_n$ converges to $f$ uniformly on $K$. Thus, $f$ is also
continuous on $K$ and therefore at $x$. Namely, $f$ is continuous.
\end{proof}
\paragraph{49.}
\begin{proof}
Let $x$ be an arbitrary point in $X$. For every $\vep > 0$, since $\mcal{F}$
is equicontinuous, there is an open neighborhood $O$ of $x$ s.t.
$\sigma(f(x), f(y)) < \vep$ for every $y\in O$ and $f\in\mcal{F}$. Now, for
every $f^+\in \mcal{F}^+$, suppose $f_n \to f$. We have
\[
\sigma(f^+(x), f^+(y))
= \sigma\left(\lim_n f_n(x), \lim_m f_m(y)\right)
= \lim_n\lim_m \sigma(f_n(x), f_m(y)) \le \vep,
\]
where the second equality comes from the continuity of $\sigma$ and the last
inequality comes from the equicontinuity of $\mcal{F}$.
\end{proof}
\paragraph{50.} I assume that the norm on $C[0, 1]$ is the sup norm.
\begin{proof}
Let $\mcal{F} := \{f\in C[0, 1]\mid \|f\|_\alpha \le 1 \}$. First, we show
that $\mcal{F}$ is equicontinuous. By the definition of $\|\cdot\|_\alpha$,
$f\in\mcal{F}$ only if it is bounded by $1$ and $|f(x) - f(y)| \le
|x - y|^\alpha$ for all $x, y \in [0, 1]$. For every $x\in X$ and $\vep > 0$,
consider the $\sqrt[\alpha]{\vep}$-ball $B$ centered at $x$. For every
$y \in B$, $|f(x) - f(y)| \le |x - y|^\alpha < \vep$. Hence, $\mcal{F}$ is
equicontinuous. Let $(f_n)$ be a sequence in $\mcal{F}$. Since $f_n$ is
bounded by $1$, by Corollary 41, $(f_n)$ contains a convergent subsequence.
Thus, $\mcal{F}$ is a (sequently) compact subset of $C[0, 1]$.
\end{proof}
|
What? No comments so far! Hard to believe since this is an all time classic (and quite possibly the best ever) music disk!
wow, one of the best musicdisks ever. tops "jesterday" a million times!
Not quite THAT good ("best ever").. But good.
use trsi.org instead of trsi.cc.
Yep, one of the best for sure, had a great overall feel to it, loading up the disk always felt like an experience, great music.
A bloody good musicdisk, possibly one of my favorites.
<3 <3 <3 this musicdisk! brings back the memories..
Always loved this one, still have the original floppies :) Very nice code by The Twins (greetings o/), what always annoyed me a bit is the fact that intro can't be skipped. Anyway, nice tunes by Virgill o/ and great graphics by Fade One as usual.
This must be the most romantic name for a music disk ever!
Which .mods by Virgill were featured on this one?
Great tunes, both "Vite and Plack" + "High Density".
But Fade1 should get the major cred for the graphics in this prod!
page created in 0.015546 seconds with 15 queries.
|
function [pyra, im_pyra] = deep_pyramid(im, cnn_model)
% [pyra, im_pyra] = deep_pyramid(im, cnn_model, cache_opts)
%
% im: a color image
% cnn_model: a handle to the model loaded into caffe
% AUTORIGHTS
% ---------------------------------------------------------
% Copyright (c) 2014, Ross Girshick
%
% This file is part of the DeepPyramid code and is available
% under the terms of the Simplified BSD License provided in
% LICENSE. Please retain this notice and LICENSE if you use
% this file (or any portion of it) in your project.
% ---------------------------------------------------------
[pyra, im_pyra] = feat_pyramid(im, cnn_model);
imsize = size(im);
pyra.imsize = imsize(1:2);
pyra.num_levels = cnn_model.pyra.num_levels;
pyra.stride = cnn_model.pyra.stride;
pyra.valid_levels = true(pyra.num_levels, 1);
pyra.padx = 0;
pyra.pady = 0;
% ------------------------------------------------------------------------
function [pyra, im_pyra] = feat_pyramid(im, cnn_model)
% ------------------------------------------------------------------------
% Compute a feature pyramid with caffe
if cnn_model.init_key ~= caffe('get_init_key')
error('You probably need to load the cnn model into caffe.');
end
% we're assuming the input height and width are the same
assert(cnn_model.pyra.dimx == cnn_model.pyra.dimy);
% compute output width and height
sz_w = (cnn_model.pyra.dimx - 1) / cnn_model.pyra.stride + 1;
sz_h = sz_w;
sz_l = cnn_model.pyra.num_levels;
sz_c = cnn_model.pyra.num_channels;
%th = tic;
[batch, scales, level_sizes] = image_pyramid(im, cnn_model);
%fprintf('prep: %.3fs\n', toc(th));
%th = tic;
feat = caffe('forward', {batch});
% standard song and dance of swapping width and height between caffe and matlab
feat = permute(reshape(feat{1}, [sz_w sz_h sz_c sz_l]), [2 1 3 4]);
%fprintf('fwd: %.3fs\n', toc(th));
pyra.feat = feat;
pyra.scales = scales;
pyra.level_sizes = level_sizes;
im_pyra = batch;
% ------------------------------------------------------------------------
function [batch, scales, level_sizes] = image_pyramid(im, cnn_model)
% ------------------------------------------------------------------------
% Construct an image pyramid that's ready for feeding directly into caffe
% forward
batch_width = cnn_model.pyra.dimx;
batch_height = cnn_model.pyra.dimy;
num_levels = cnn_model.pyra.num_levels;
stride = cnn_model.pyra.stride;
im = single(im);
% Convert to BGR
im = im(:,:,[3 2 1]);
% Subtract mean (mean of the image mean--one mean per channel)
im = bsxfun(@minus, im, cnn_model.mu);
% scale = base scale relative to input image
im_sz = size(im);
if im_sz(1) > im_sz(2)
height = batch_height;
width = NaN;
scale = height / im_sz(1);
else
height = NaN;
width = batch_width;
scale = width / im_sz(2);
end
im_orig = im;
batch = zeros(batch_width, batch_height, 3, num_levels, 'single');
alpha = cnn_model.pyra.scale_factor;
scales = scale*(alpha.^-(0:num_levels-1))';
level_sizes = zeros(num_levels, 2);
for i = 0:num_levels-1
if i == 0
im = imresize(im_orig, [height width], 'bilinear');
else
im = imresize(im_orig, scales(i+1), 'bilinear');
end
im_sz = size(im);
im_sz = im_sz(1:2);
level_sizes(i+1, :) = ceil((im_sz - 1) / stride + 1);
% Make width the fastest dimension (for caffe)
im = permute(im, [2 1 3]);
batch(1:im_sz(2), 1:im_sz(1), :, i+1) = im;
end
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
Require Import mathcomp.ssreflect.ssreflect.
From mathcomp
Require Import ssrfun ssrbool eqtype.
Require Import BinNat.
Require BinPos Ndec.
Require Export Ring.
(******************************************************************************)
(* A version of arithmetic on nat (natural numbers) that is better suited to *)
(* small scale reflection than the Coq Arith library. It contains an *)
(* extensive equational theory (including, e.g., the AGM inequality), as well *)
(* as support for the ring tactic, and congruence tactics. *)
(* The following operations and notations are provided: *)
(* *)
(* successor and predecessor *)
(* n.+1, n.+2, n.+3, n.+4 and n.-1, n.-2 *)
(* this frees the names "S" and "pred" *)
(* *)
(* basic arithmetic *)
(* m + n, m - n, m * n *)
(* Important: m - n denotes TRUNCATED subtraction: m - n = 0 if m <= n. *)
(* The definitions use the nosimpl tag to prevent undesirable computation *)
(* computation during simplification, but remain compatible with the ones *)
(* provided in the Coq.Init.Peano prelude. *)
(* For computation, a module NatTrec rebinds all arithmetic notations *)
(* to less convenient but also less inefficient tail-recursive functions; *)
(* the auxiliary functions used by these versions are flagged with %Nrec. *)
(* Also, there is support for input and output of large nat values. *)
(* Num 3 082 241 inputs the number 3082241 *)
(* [Num of n] outputs the value n *)
(* There are coercions num >-> BinNat.N >-> nat; ssrnat rebinds the scope *)
(* delimiter for BinNat.N to %num, as it uses the shorter %N for its own *)
(* notations (Peano notations are flagged with %coq_nat). *)
(* *)
(* doubling, halving, and parity *)
(* n.*2, n./2, odd n, uphalf n, with uphalf n = n.+1./2 *)
(* bool coerces to nat so we can write, e.g., n = odd n + n./2.*2. *)
(* *)
(* iteration *)
(* iter n f x0 == f ( .. (f x0)) *)
(* iteri n g x0 == g n.-1 (g ... (g 0 x0)) *)
(* iterop n op x x0 == op x (... op x x) (n x's) or x0 if n = 0 *)
(* *)
(* exponentiation, factorial *)
(* m ^ n, n`! *)
(* m ^ 1 is convertible to m, and m ^ 2 to m * m *)
(* *)
(* comparison *)
(* m <= n, m < n, m >= n, m > n, m == n, m <= n <= p, etc., *)
(* comparisons are BOOLEAN operators, and m == n is the generic eqType *)
(* operation. *)
(* Most compatibility lemmas are stated as boolean equalities; this keeps *)
(* the size of the library down. All the inequalities refer to the same *)
(* constant "leq"; in particular m < n is identical to m.+1 <= n. *)
(* *)
(* conditionally strict inequality `leqif' *)
(* m <= n ?= iff condition == (m <= n) and ((m == n) = condition) *)
(* This is actually a pair of boolean equalities, so rewriting with an *)
(* `leqif' lemma can affect several kinds of comparison. The transitivity *)
(* lemma for leqif aggregates the conditions, allowing for arguments of *)
(* the form ``m <= n <= p <= m, so equality holds throughout''. *)
(* *)
(* maximum and minimum *)
(* maxn m n, minn m n *)
(* Note that maxn m n = m + (m - n), due to the truncating subtraction. *)
(* Absolute difference (linear distance) between nats is defined in the int *)
(* library (in the int.IntDist sublibrary), with the syntax `|m - n|. The *)
(* '-' in this notation is the signed integer difference. *)
(* *)
(* countable choice *)
(* ex_minn : forall P : pred nat, (exists n, P n) -> nat *)
(* This returns the smallest n such that P n holds. *)
(* ex_maxn : forall (P : pred nat) m, *)
(* (exists n, P n) -> (forall n, P n -> n <= m) -> nat *)
(* This returns the largest n such that P n holds (given an explicit upper *)
(* bound). *)
(* *)
(* This file adds the following suffix conventions to those documented in *)
(* ssrbool.v and eqtype.v: *)
(* A (infix) -- conjunction, as in *)
(* ltn_neqAle : (m < n) = (m != n) && (m <= n). *)
(* B -- subtraction, as in subBn : (m - n) - p = m - (n + p). *)
(* D -- addition, as in mulnDl : (m + n) * p = m * p + n * p. *)
(* M -- multiplication, as in expnMn : (m * n) ^ p = m ^ p * n ^ p. *)
(* p (prefix) -- positive, as in *)
(* eqn_pmul2l : m > 0 -> (m * n1 == m * n2) = (n1 == n2). *)
(* P -- greater than 1, as in *)
(* ltn_Pmull : 1 < n -> 0 < m -> m < n * m. *)
(* S -- successor, as in addSn : n.+1 + m = (n + m).+1. *)
(* V (infix) -- disjunction, as in *)
(* leq_eqVlt : (m <= n) = (m == n) || (m < n). *)
(* X - exponentiation, as in lognX : logn p (m ^ n) = logn p m * n in *)
(* file prime.v (the suffix is not used in ths file). *)
(* Suffixes that abbreviate operations (D, B, M and X) are used to abbreviate *)
(* second-rank operations in equational lemma names that describe left-hand *)
(* sides (e.g., mulnDl); they are not used to abbreviate the main operation *)
(* of relational lemmas (e.g., leq_add2l). *)
(* For the asymmetrical exponentiation operator expn (m ^ n) a right suffix *)
(* indicates an operation on the exponent, e.g., expnM : m ^ (n1 * n2) = ...; *)
(* a trailing "n" is used to indicate the left operand, e.g., *)
(* expnMn : (m1 * m2) ^ n = ... The operands of other operators are selected *)
(* using the l/r suffixes. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(* Declare legacy Arith operators in new scope. *)
Delimit Scope coq_nat_scope with coq_nat.
Notation "m + n" := (plus m n) : coq_nat_scope.
Notation "m - n" := (minus m n) : coq_nat_scope.
Notation "m * n" := (mult m n) : coq_nat_scope.
Notation "m <= n" := (le m n) : coq_nat_scope.
Notation "m < n" := (lt m n) : coq_nat_scope.
Notation "m >= n" := (ge m n) : coq_nat_scope.
Notation "m > n" := (gt m n) : coq_nat_scope.
(* Rebind scope delimiters, reserving a scope for the "recursive", *)
(* i.e., unprotected version of operators. *)
Delimit Scope N_scope with num.
Delimit Scope nat_scope with N.
Delimit Scope nat_rec_scope with Nrec.
(* Postfix notation for the successor and predecessor functions. *)
(* SSreflect uses "pred" for the generic predicate type, and S as *)
(* a local bound variable. *)
Notation succn := Datatypes.S.
Notation predn := Peano.pred.
Notation "n .+1" := (succn n) (at level 2, left associativity,
format "n .+1") : nat_scope.
Notation "n .+2" := n.+1.+1 (at level 2, left associativity,
format "n .+2") : nat_scope.
Notation "n .+3" := n.+2.+1 (at level 2, left associativity,
format "n .+3") : nat_scope.
Notation "n .+4" := n.+2.+2 (at level 2, left associativity,
format "n .+4") : nat_scope.
Notation "n .-1" := (predn n) (at level 2, left associativity,
format "n .-1") : nat_scope.
Notation "n .-2" := n.-1.-1 (at level 2, left associativity,
format "n .-2") : nat_scope.
Lemma succnK : cancel succn predn. Proof. by []. Qed.
Lemma succn_inj : injective succn. Proof. by move=> n m []. Qed.
(* Predeclare postfix doubling/halving operators. *)
Reserved Notation "n .*2" (at level 2, format "n .*2").
Reserved Notation "n ./2" (at level 2, format "n ./2").
(* Canonical comparison and eqType for nat. *)
Fixpoint eqn m n {struct m} :=
match m, n with
| 0, 0 => true
| m'.+1, n'.+1 => eqn m' n'
| _, _ => false
end.
Lemma eqnP : Equality.axiom eqn.
Proof.
move=> n m; apply: (iffP idP) => [|<-]; last by elim n.
by elim: n m => [|n IHn] [|m] //= /IHn->.
Qed.
Canonical nat_eqMixin := EqMixin eqnP.
Canonical nat_eqType := Eval hnf in EqType nat nat_eqMixin.
Arguments eqn !m !n.
Arguments eqnP {x y}.
Lemma eqnE : eqn = eq_op. Proof. by []. Qed.
Lemma eqSS m n : (m.+1 == n.+1) = (m == n). Proof. by []. Qed.
Lemma nat_irrelevance (x y : nat) (E E' : x = y) : E = E'.
Proof. exact: eq_irrelevance. Qed.
(* Protected addition, with a more systematic set of lemmas. *)
Definition addn_rec := plus.
Notation "m + n" := (addn_rec m n) : nat_rec_scope.
Definition addn := nosimpl addn_rec.
Notation "m + n" := (addn m n) : nat_scope.
Lemma addnE : addn = addn_rec. Proof. by []. Qed.
Lemma plusE : plus = addn. Proof. by []. Qed.
Lemma add0n : left_id 0 addn. Proof. by []. Qed.
Lemma addSn m n : m.+1 + n = (m + n).+1. Proof. by []. Qed.
Lemma add1n n : 1 + n = n.+1. Proof. by []. Qed.
Lemma addn0 : right_id 0 addn. Proof. by move=> n; apply/eqP; elim: n. Qed.
Lemma addnS m n : m + n.+1 = (m + n).+1. Proof. by elim: m. Qed.
Lemma addSnnS m n : m.+1 + n = m + n.+1. Proof. by rewrite addnS. Qed.
Lemma addnCA : left_commutative addn.
Proof. by move=> m n p; elim: m => //= m; rewrite addnS => <-. Qed.
Lemma addnC : commutative addn.
Proof. by move=> m n; rewrite -{1}[n]addn0 addnCA addn0. Qed.
Lemma addn1 n : n + 1 = n.+1. Proof. by rewrite addnC. Qed.
Lemma addnA : associative addn.
Proof. by move=> m n p; rewrite (addnC n) addnCA addnC. Qed.
Lemma addnAC : right_commutative addn.
Proof. by move=> m n p; rewrite -!addnA (addnC n). Qed.
Lemma addnACA : interchange addn addn.
Proof. by move=> m n p q; rewrite -!addnA (addnCA n). Qed.
Lemma addn_eq0 m n : (m + n == 0) = (m == 0) && (n == 0).
Proof. by case: m; case: n. Qed.
Lemma eqn_add2l p m n : (p + m == p + n) = (m == n).
Proof. by elim: p. Qed.
Lemma eqn_add2r p m n : (m + p == n + p) = (m == n).
Proof. by rewrite -!(addnC p) eqn_add2l. Qed.
Lemma addnI : right_injective addn.
Proof. by move=> p m n Heq; apply: eqP; rewrite -(eqn_add2l p) Heq eqxx. Qed.
Lemma addIn : left_injective addn.
Proof. move=> p m n; rewrite -!(addnC p); apply addnI. Qed.
Lemma addn2 m : m + 2 = m.+2. Proof. by rewrite addnC. Qed.
Lemma add2n m : 2 + m = m.+2. Proof. by []. Qed.
Lemma addn3 m : m + 3 = m.+3. Proof. by rewrite addnC. Qed.
Lemma add3n m : 3 + m = m.+3. Proof. by []. Qed.
Lemma addn4 m : m + 4 = m.+4. Proof. by rewrite addnC. Qed.
Lemma add4n m : 4 + m = m.+4. Proof. by []. Qed.
(* Protected, structurally decreasing subtraction, and basic lemmas. *)
(* Further properties depend on ordering conditions. *)
Definition subn_rec := minus.
Notation "m - n" := (subn_rec m n) : nat_rec_scope.
Definition subn := nosimpl subn_rec.
Notation "m - n" := (subn m n) : nat_scope.
Lemma subnE : subn = subn_rec. Proof. by []. Qed.
Lemma minusE : minus = subn. Proof. by []. Qed.
Lemma sub0n : left_zero 0 subn. Proof. by []. Qed.
Lemma subn0 : right_id 0 subn. Proof. by case. Qed.
Lemma subnn : self_inverse 0 subn. Proof. by elim. Qed.
Lemma subSS n m : m.+1 - n.+1 = m - n. Proof. by []. Qed.
Lemma subn1 n : n - 1 = n.-1. Proof. by case: n => [|[]]. Qed.
Lemma subn2 n : (n - 2)%N = n.-2. Proof. by case: n => [|[|[]]]. Qed.
Lemma subnDl p m n : (p + m) - (p + n) = m - n.
Proof. by elim: p. Qed.
Lemma subnDr p m n : (m + p) - (n + p) = m - n.
Proof. by rewrite -!(addnC p) subnDl. Qed.
Lemma addKn n : cancel (addn n) (subn^~ n).
Proof. by move=> m; rewrite /= -{2}[n]addn0 subnDl subn0. Qed.
Lemma addnK n : cancel (addn^~ n) (subn^~ n).
Proof. by move=> m; rewrite /= (addnC m) addKn. Qed.
Lemma subSnn n : n.+1 - n = 1.
Proof. exact (addnK n 1). Qed.
Lemma subnDA m n p : n - (m + p) = (n - m) - p.
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma subnAC : right_commutative subn.
Proof. by move=> m n p; rewrite -!subnDA addnC. Qed.
Lemma subnS m n : m - n.+1 = (m - n).-1.
Proof. by rewrite -addn1 subnDA subn1. Qed.
Lemma subSKn m n : (m.+1 - n).-1 = m - n.
Proof. by rewrite -subnS. Qed.
(* Integer ordering, and its interaction with the other operations. *)
Definition leq m n := m - n == 0.
Notation "m <= n" := (leq m n) : nat_scope.
Notation "m < n" := (m.+1 <= n) : nat_scope.
Notation "m >= n" := (n <= m) (only parsing) : nat_scope.
Notation "m > n" := (n < m) (only parsing) : nat_scope.
(* For sorting, etc. *)
Definition geq := [rel m n | m >= n].
Definition ltn := [rel m n | m < n].
Definition gtn := [rel m n | m > n].
Notation "m <= n <= p" := ((m <= n) && (n <= p)) : nat_scope.
Notation "m < n <= p" := ((m < n) && (n <= p)) : nat_scope.
Notation "m <= n < p" := ((m <= n) && (n < p)) : nat_scope.
Notation "m < n < p" := ((m < n) && (n < p)) : nat_scope.
Lemma ltnS m n : (m < n.+1) = (m <= n). Proof. by []. Qed.
Lemma leq0n n : 0 <= n. Proof. by []. Qed.
Lemma ltn0Sn n : 0 < n.+1. Proof. by []. Qed.
Lemma ltn0 n : n < 0 = false. Proof. by []. Qed.
Lemma leqnn n : n <= n. Proof. by elim: n. Qed.
Hint Resolve leqnn : core.
Lemma ltnSn n : n < n.+1. Proof. by []. Qed.
Lemma eq_leq m n : m = n -> m <= n. Proof. by move->. Qed.
Lemma leqnSn n : n <= n.+1. Proof. by elim: n. Qed.
Hint Resolve leqnSn : core.
Lemma leq_pred n : n.-1 <= n. Proof. by case: n => /=. Qed.
Lemma leqSpred n : n <= n.-1.+1. Proof. by case: n => /=. Qed.
Lemma ltn_predK m n : m < n -> n.-1.+1 = n.
Proof. by case: n. Qed.
Lemma prednK n : 0 < n -> n.-1.+1 = n.
Proof. exact: ltn_predK. Qed.
Lemma leqNgt m n : (m <= n) = ~~ (n < m).
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma ltnNge m n : (m < n) = ~~ (n <= m).
Proof. by rewrite leqNgt. Qed.
Lemma ltnn n : n < n = false.
Proof. by rewrite ltnNge leqnn. Qed.
Lemma leqn0 n : (n <= 0) = (n == 0). Proof. by case: n. Qed.
Lemma lt0n n : (0 < n) = (n != 0). Proof. by case: n. Qed.
Lemma lt0n_neq0 n : 0 < n -> n != 0. Proof. by case: n. Qed.
Lemma eqn0Ngt n : (n == 0) = ~~ (n > 0). Proof. by case: n. Qed.
Lemma neq0_lt0n n : (n == 0) = false -> 0 < n. Proof. by case: n. Qed.
Hint Resolve lt0n_neq0 neq0_lt0n : core.
Lemma eqn_leq m n : (m == n) = (m <= n <= m).
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma anti_leq : antisymmetric leq.
Proof. by move=> m n; rewrite -eqn_leq => /eqP. Qed.
Lemma neq_ltn m n : (m != n) = (m < n) || (n < m).
Proof. by rewrite eqn_leq negb_and orbC -!ltnNge. Qed.
Lemma gtn_eqF m n : m < n -> n == m = false.
Proof. by rewrite eqn_leq (leqNgt n) => ->. Qed.
Lemma ltn_eqF m n : m < n -> m == n = false.
Proof. by move/gtn_eqF; rewrite eq_sym. Qed.
Lemma leq_eqVlt m n : (m <= n) = (m == n) || (m < n).
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma ltn_neqAle m n : (m < n) = (m != n) && (m <= n).
Proof. by rewrite ltnNge leq_eqVlt negb_or -leqNgt eq_sym. Qed.
Lemma leq_trans n m p : m <= n -> n <= p -> m <= p.
Proof. by elim: n m p => [|i IHn] [|m] [|p] //; apply: IHn m p. Qed.
Lemma leq_ltn_trans n m p : m <= n -> n < p -> m < p.
Proof. by move=> Hmn; apply: leq_trans. Qed.
Lemma ltnW m n : m < n -> m <= n.
Proof. exact: leq_trans. Qed.
Hint Resolve ltnW : core.
Lemma leqW m n : m <= n -> m <= n.+1.
Proof. by move=> le_mn; apply: ltnW. Qed.
Lemma ltn_trans n m p : m < n -> n < p -> m < p.
Proof. by move=> lt_mn /ltnW; apply: leq_trans. Qed.
Lemma leq_total m n : (m <= n) || (m >= n).
Proof. by rewrite -implyNb -ltnNge; apply/implyP; apply: ltnW. Qed.
(* Link to the legacy comparison predicates. *)
Lemma leP m n : reflect (m <= n)%coq_nat (m <= n).
Proof.
apply: (iffP idP); last by elim: n / => // n _ /leq_trans->.
elim: n => [|n IHn]; first by case: m.
by rewrite leq_eqVlt ltnS => /predU1P[<- // | /IHn]; right.
Qed.
Arguments leP {m n}.
Lemma le_irrelevance m n le_mn1 le_mn2 : le_mn1 = le_mn2 :> (m <= n)%coq_nat.
Proof.
elim: {n}n.+1 {-1}n (erefl n.+1) => // n IHn _ [<-] in le_mn1 le_mn2 *.
pose def_n2 := erefl n; transitivity (eq_ind _ _ le_mn2 _ def_n2) => //.
move def_n1: {1 4 5 7}n le_mn1 le_mn2 def_n2 => n1 le_mn1.
case: n1 / le_mn1 def_n1 => [|n1 le_mn1] def_n1 [|n2 le_mn2] def_n2.
- by rewrite [def_n2]eq_axiomK.
- by move/leP: (le_mn2); rewrite -{1}def_n2 ltnn.
- by move/leP: (le_mn1); rewrite {1}def_n2 ltnn.
case: def_n2 (def_n2) => ->{n2} def_n2 in le_mn2 *.
by rewrite [def_n2]eq_axiomK /=; congr le_S; apply: IHn.
Qed.
Lemma ltP m n : reflect (m < n)%coq_nat (m < n).
Proof. exact leP. Qed.
Arguments ltP {m n}.
Lemma lt_irrelevance m n lt_mn1 lt_mn2 : lt_mn1 = lt_mn2 :> (m < n)%coq_nat.
Proof. exact: (@le_irrelevance m.+1). Qed.
(* Comparison predicates. *)
Variant leq_xor_gtn m n : bool -> bool -> Set :=
| LeqNotGtn of m <= n : leq_xor_gtn m n true false
| GtnNotLeq of n < m : leq_xor_gtn m n false true.
Lemma leqP m n : leq_xor_gtn m n (m <= n) (n < m).
Proof.
by rewrite ltnNge; case le_mn: (m <= n); constructor; rewrite // ltnNge le_mn.
Qed.
Variant ltn_xor_geq m n : bool -> bool -> Set :=
| LtnNotGeq of m < n : ltn_xor_geq m n false true
| GeqNotLtn of n <= m : ltn_xor_geq m n true false.
Lemma ltnP m n : ltn_xor_geq m n (n <= m) (m < n).
Proof. by rewrite -(ltnS n); case: leqP; constructor. Qed.
Variant eqn0_xor_gt0 n : bool -> bool -> Set :=
| Eq0NotPos of n = 0 : eqn0_xor_gt0 n true false
| PosNotEq0 of n > 0 : eqn0_xor_gt0 n false true.
Lemma posnP n : eqn0_xor_gt0 n (n == 0) (0 < n).
Proof. by case: n; constructor. Qed.
Variant compare_nat m n :
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| CompareNatLt of m < n : compare_nat m n true false true false false false
| CompareNatGt of m > n : compare_nat m n false true false true false false
| CompareNatEq of m = n : compare_nat m n true true false false true true.
Lemma ltngtP m n : compare_nat m n (m <= n) (n <= m) (m < n)
(n < m) (n == m) (m == n).
Proof.
rewrite !ltn_neqAle [_ == m]eq_sym; case: ltnP => [mn|].
by rewrite ltnW // gtn_eqF //; constructor.
rewrite leq_eqVlt; case: ltnP; rewrite ?(orbT, orbF) => //= lt_nm eq_mn.
by rewrite ltn_eqF //; constructor.
by rewrite eq_mn; constructor; apply/eqP.
Qed.
(* Monotonicity lemmas *)
Lemma leq_add2l p m n : (p + m <= p + n) = (m <= n).
Proof. by elim: p. Qed.
Lemma ltn_add2l p m n : (p + m < p + n) = (m < n).
Proof. by rewrite -addnS; apply: leq_add2l. Qed.
Lemma leq_add2r p m n : (m + p <= n + p) = (m <= n).
Proof. by rewrite -!(addnC p); apply: leq_add2l. Qed.
Lemma ltn_add2r p m n : (m + p < n + p) = (m < n).
Proof. exact: leq_add2r p m.+1 n. Qed.
Lemma leq_add m1 m2 n1 n2 : m1 <= n1 -> m2 <= n2 -> m1 + m2 <= n1 + n2.
Proof.
by move=> le_mn1 le_mn2; rewrite (@leq_trans (m1 + n2)) ?leq_add2l ?leq_add2r.
Qed.
Lemma leq_addr m n : n <= n + m.
Proof. by rewrite -{1}[n]addn0 leq_add2l. Qed.
Lemma leq_addl m n : n <= m + n.
Proof. by rewrite addnC leq_addr. Qed.
Lemma ltn_addr m n p : m < n -> m < n + p.
Proof. by move/leq_trans=> -> //; apply: leq_addr. Qed.
Lemma ltn_addl m n p : m < n -> m < p + n.
Proof. by move/leq_trans=> -> //; apply: leq_addl. Qed.
Lemma addn_gt0 m n : (0 < m + n) = (0 < m) || (0 < n).
Proof. by rewrite !lt0n -negb_and addn_eq0. Qed.
Lemma subn_gt0 m n : (0 < n - m) = (m < n).
Proof. by elim: m n => [|m IHm] [|n] //; apply: IHm n. Qed.
Lemma subn_eq0 m n : (m - n == 0) = (m <= n).
Proof. by []. Qed.
Lemma leq_subLR m n p : (m - n <= p) = (m <= n + p).
Proof. by rewrite -subn_eq0 -subnDA. Qed.
Lemma leq_subr m n : n - m <= n.
Proof. by rewrite leq_subLR leq_addl. Qed.
Lemma subnKC m n : m <= n -> m + (n - m) = n.
Proof. by elim: m n => [|m IHm] [|n] // /(IHm n) {2}<-. Qed.
Lemma subnK m n : m <= n -> (n - m) + m = n.
Proof. by rewrite addnC; apply: subnKC. Qed.
Lemma addnBA m n p : p <= n -> m + (n - p) = m + n - p.
Proof. by move=> le_pn; rewrite -{2}(subnK le_pn) addnA addnK. Qed.
Lemma addnBAC m n p : n <= m -> m - n + p = m + p - n.
Proof. by move=> le_nm; rewrite addnC addnBA // addnC. Qed.
Lemma addnBCA m n p : p <= m -> p <= n -> m + (n - p) = n + (m - p).
Proof. by move=> le_pm le_pn; rewrite !addnBA // addnC. Qed.
Lemma addnABC m n p : p <= m -> p <= n -> m + (n - p) = m - p + n.
Proof. by move=> le_pm le_pn; rewrite addnBA // addnBAC. Qed.
Lemma subnBA m n p : p <= n -> m - (n - p) = m + p - n.
Proof. by move=> le_pn; rewrite -{2}(subnK le_pn) subnDr. Qed.
Lemma subKn m n : m <= n -> n - (n - m) = m.
Proof. by move/subnBA->; rewrite addKn. Qed.
Lemma subSn m n : m <= n -> n.+1 - m = (n - m).+1.
Proof. by rewrite -add1n => /addnBA <-. Qed.
Lemma subnSK m n : m < n -> (n - m.+1).+1 = n - m.
Proof. by move/subSn. Qed.
Lemma leq_sub2r p m n : m <= n -> m - p <= n - p.
Proof.
by move=> le_mn; rewrite leq_subLR (leq_trans le_mn) // -leq_subLR.
Qed.
Lemma leq_sub2l p m n : m <= n -> p - n <= p - m.
Proof.
rewrite -(leq_add2r (p - m)) leq_subLR.
by apply: leq_trans; rewrite -leq_subLR.
Qed.
Lemma leq_sub m1 m2 n1 n2 : m1 <= m2 -> n2 <= n1 -> m1 - n1 <= m2 - n2.
Proof. by move/(leq_sub2r n1)=> le_m12 /(leq_sub2l m2); apply: leq_trans. Qed.
Lemma ltn_sub2r p m n : p < n -> m < n -> m - p < n - p.
Proof. by move/subnSK <-; apply: (@leq_sub2r p.+1). Qed.
Lemma ltn_sub2l p m n : m < p -> m < n -> p - n < p - m.
Proof. by move/subnSK <-; apply: leq_sub2l. Qed.
Lemma ltn_subRL m n p : (n < p - m) = (m + n < p).
Proof. by rewrite !ltnNge leq_subLR. Qed.
(* Eliminating the idiom for structurally decreasing compare and subtract. *)
Lemma subn_if_gt T m n F (E : T) :
(if m.+1 - n is m'.+1 then F m' else E) = (if n <= m then F (m - n) else E).
Proof.
by case: leqP => [le_nm | /eqnP-> //]; rewrite -{1}(subnK le_nm) -addSn addnK.
Qed.
(* Max and min. *)
Definition maxn m n := if m < n then n else m.
Definition minn m n := if m < n then m else n.
Lemma max0n : left_id 0 maxn. Proof. by case. Qed.
Lemma maxn0 : right_id 0 maxn. Proof. by []. Qed.
Lemma maxnC : commutative maxn.
Proof. by move=> m n; rewrite /maxn; case ltngtP. Qed.
Lemma maxnE m n : maxn m n = m + (n - m).
Proof. by rewrite /maxn addnC; case: leqP => [/eqnP->|/ltnW/subnK]. Qed.
Lemma maxnAC : right_commutative maxn.
Proof. by move=> m n p; rewrite !maxnE -!addnA !subnDA -!maxnE maxnC. Qed.
Lemma maxnA : associative maxn.
Proof. by move=> m n p; rewrite !(maxnC m) maxnAC. Qed.
Lemma maxnCA : left_commutative maxn.
Proof. by move=> m n p; rewrite !maxnA (maxnC m). Qed.
Lemma maxnACA : interchange maxn maxn.
Proof. by move=> m n p q; rewrite -!maxnA (maxnCA n). Qed.
Lemma maxn_idPl {m n} : reflect (maxn m n = m) (m >= n).
Proof. by rewrite -subn_eq0 -(eqn_add2l m) addn0 -maxnE; apply: eqP. Qed.
Lemma maxn_idPr {m n} : reflect (maxn m n = n) (m <= n).
Proof. by rewrite maxnC; apply: maxn_idPl. Qed.
Lemma maxnn : idempotent maxn.
Proof. by move=> n; apply/maxn_idPl. Qed.
Lemma leq_max m n1 n2 : (m <= maxn n1 n2) = (m <= n1) || (m <= n2).
Proof.
without loss le_n21: n1 n2 / n2 <= n1.
by case/orP: (leq_total n2 n1) => le_n12; last rewrite maxnC orbC; apply.
by rewrite (maxn_idPl le_n21) orb_idr // => /leq_trans->.
Qed.
Lemma leq_maxl m n : m <= maxn m n. Proof. by rewrite leq_max leqnn. Qed.
Lemma leq_maxr m n : n <= maxn m n. Proof. by rewrite maxnC leq_maxl. Qed.
Lemma gtn_max m n1 n2 : (m > maxn n1 n2) = (m > n1) && (m > n2).
Proof. by rewrite !ltnNge leq_max negb_or. Qed.
Lemma geq_max m n1 n2 : (m >= maxn n1 n2) = (m >= n1) && (m >= n2).
Proof. by rewrite -ltnS gtn_max. Qed.
Lemma maxnSS m n : maxn m.+1 n.+1 = (maxn m n).+1.
Proof. by rewrite !maxnE. Qed.
Lemma addn_maxl : left_distributive addn maxn.
Proof. by move=> m1 m2 n; rewrite !maxnE subnDr addnAC. Qed.
Lemma addn_maxr : right_distributive addn maxn.
Proof. by move=> m n1 n2; rewrite !(addnC m) addn_maxl. Qed.
Lemma min0n : left_zero 0 minn. Proof. by case. Qed.
Lemma minn0 : right_zero 0 minn. Proof. by []. Qed.
Lemma minnC : commutative minn.
Proof. by move=> m n; rewrite /minn; case ltngtP. Qed.
Lemma addn_min_max m n : minn m n + maxn m n = m + n.
Proof. by rewrite /minn /maxn; case: ltngtP => // [_|->] //; apply: addnC. Qed.
Lemma minnE m n : minn m n = m - (m - n).
Proof. by rewrite -(subnDl n) -maxnE -addn_min_max addnK minnC. Qed.
Lemma minnAC : right_commutative minn.
Proof.
by move=> m n p; rewrite !minnE -subnDA subnAC -maxnE maxnC maxnE subnAC subnDA.
Qed.
Lemma minnA : associative minn.
Proof. by move=> m n p; rewrite minnC minnAC (minnC n). Qed.
Lemma minnCA : left_commutative minn.
Proof. by move=> m n p; rewrite !minnA (minnC n). Qed.
Lemma minnACA : interchange minn minn.
Proof. by move=> m n p q; rewrite -!minnA (minnCA n). Qed.
Lemma minn_idPl {m n} : reflect (minn m n = m) (m <= n).
Proof.
rewrite (sameP maxn_idPr eqP) -(eqn_add2l m) eq_sym -addn_min_max eqn_add2r.
exact: eqP.
Qed.
Lemma minn_idPr {m n} : reflect (minn m n = n) (m >= n).
Proof. by rewrite minnC; apply: minn_idPl. Qed.
Lemma minnn : idempotent minn.
Proof. by move=> n; apply/minn_idPl. Qed.
Lemma leq_min m n1 n2 : (m <= minn n1 n2) = (m <= n1) && (m <= n2).
Proof.
wlog le_n21: n1 n2 / n2 <= n1.
by case/orP: (leq_total n2 n1) => ?; last rewrite minnC andbC; auto.
by rewrite /minn ltnNge le_n21 /= andbC; case: leqP => // /leq_trans->.
Qed.
Lemma gtn_min m n1 n2 : (m > minn n1 n2) = (m > n1) || (m > n2).
Proof. by rewrite !ltnNge leq_min negb_and. Qed.
Lemma geq_min m n1 n2 : (m >= minn n1 n2) = (m >= n1) || (m >= n2).
Proof. by rewrite -ltnS gtn_min. Qed.
Lemma geq_minl m n : minn m n <= m. Proof. by rewrite geq_min leqnn. Qed.
Lemma geq_minr m n : minn m n <= n. Proof. by rewrite minnC geq_minl. Qed.
Lemma addn_minr : right_distributive addn minn.
Proof. by move=> m1 m2 n; rewrite !minnE subnDl addnBA ?leq_subr. Qed.
Lemma addn_minl : left_distributive addn minn.
Proof. by move=> m1 m2 n; rewrite -!(addnC n) addn_minr. Qed.
Lemma minnSS m n : minn m.+1 n.+1 = (minn m n).+1.
Proof. by rewrite -(addn_minr 1). Qed.
(* Quasi-cancellation (really, absorption) lemmas *)
Lemma maxnK m n : minn (maxn m n) m = m.
Proof. exact/minn_idPr/leq_maxl. Qed.
Lemma maxKn m n : minn n (maxn m n) = n.
Proof. exact/minn_idPl/leq_maxr. Qed.
Lemma minnK m n : maxn (minn m n) m = m.
Proof. exact/maxn_idPr/geq_minl. Qed.
Lemma minKn m n : maxn n (minn m n) = n.
Proof. exact/maxn_idPl/geq_minr. Qed.
(* Distributivity. *)
Lemma maxn_minl : left_distributive maxn minn.
Proof.
move=> m1 m2 n; wlog le_m21: m1 m2 / m2 <= m1.
move=> IH; case/orP: (leq_total m2 m1) => /IH //.
by rewrite minnC [in R in _ = R]minnC.
rewrite (minn_idPr le_m21); apply/esym/minn_idPr.
by rewrite geq_max leq_maxr leq_max le_m21.
Qed.
Lemma maxn_minr : right_distributive maxn minn.
Proof. by move=> m n1 n2; rewrite !(maxnC m) maxn_minl. Qed.
Lemma minn_maxl : left_distributive minn maxn.
Proof.
by move=> m1 m2 n; rewrite maxn_minr !maxn_minl -minnA maxnn (maxnC _ n) !maxnK.
Qed.
Lemma minn_maxr : right_distributive minn maxn.
Proof. by move=> m n1 n2; rewrite !(minnC m) minn_maxl. Qed.
(* Getting a concrete value from an abstract existence proof. *)
Section ExMinn.
Variable P : pred nat.
Hypothesis exP : exists n, P n.
Inductive acc_nat i : Prop := AccNat0 of P i | AccNatS of acc_nat i.+1.
Lemma find_ex_minn : {m | P m & forall n, P n -> n >= m}.
Proof.
have: forall n, P n -> n >= 0 by [].
have: acc_nat 0.
case exP => n; rewrite -(addn0 n); elim: n 0 => [|n IHn] j; first by left.
by rewrite addSnnS; right; apply: IHn.
move: 0; fix find_ex_minn 2 => m IHm m_lb; case Pm: (P m); first by exists m.
apply: find_ex_minn m.+1 _ _ => [|n Pn]; first by case: IHm; rewrite ?Pm.
by rewrite ltn_neqAle m_lb //; case: eqP Pm => // -> /idP[].
Qed.
Definition ex_minn := s2val find_ex_minn.
Inductive ex_minn_spec : nat -> Type :=
ExMinnSpec m of P m & (forall n, P n -> n >= m) : ex_minn_spec m.
Lemma ex_minnP : ex_minn_spec ex_minn.
Proof. by rewrite /ex_minn; case: find_ex_minn. Qed.
End ExMinn.
Section ExMaxn.
Variables (P : pred nat) (m : nat).
Hypotheses (exP : exists i, P i) (ubP : forall i, P i -> i <= m).
Lemma ex_maxn_subproof : exists i, P (m - i).
Proof. by case: exP => i Pi; exists (m - i); rewrite subKn ?ubP. Qed.
Definition ex_maxn := m - ex_minn ex_maxn_subproof.
Variant ex_maxn_spec : nat -> Type :=
ExMaxnSpec i of P i & (forall j, P j -> j <= i) : ex_maxn_spec i.
Lemma ex_maxnP : ex_maxn_spec ex_maxn.
Proof.
rewrite /ex_maxn; case: ex_minnP => i Pmi min_i; split=> // j Pj.
have le_i_mj: i <= m - j by rewrite min_i // subKn // ubP.
rewrite -subn_eq0 subnBA ?(leq_trans le_i_mj) ?leq_subr //.
by rewrite addnC -subnBA ?ubP.
Qed.
End ExMaxn.
Lemma eq_ex_minn P Q exP exQ : P =1 Q -> @ex_minn P exP = @ex_minn Q exQ.
Proof.
move=> eqPQ; case: ex_minnP => m1 Pm1 m1_lb; case: ex_minnP => m2 Pm2 m2_lb.
by apply/eqP; rewrite eqn_leq m1_lb (m2_lb, eqPQ) // -eqPQ.
Qed.
Lemma eq_ex_maxn (P Q : pred nat) m n exP ubP exQ ubQ :
P =1 Q -> @ex_maxn P m exP ubP = @ex_maxn Q n exQ ubQ.
Proof.
move=> eqPQ; case: ex_maxnP => i Pi max_i; case: ex_maxnP => j Pj max_j.
by apply/eqP; rewrite eqn_leq max_i ?eqPQ // max_j -?eqPQ.
Qed.
Section Iteration.
Variable T : Type.
Implicit Types m n : nat.
Implicit Types x y : T.
Definition iter n f x :=
let fix loop m := if m is i.+1 then f (loop i) else x in loop n.
Definition iteri n f x :=
let fix loop m := if m is i.+1 then f i (loop i) else x in loop n.
Definition iterop n op x :=
let f i y := if i is 0 then x else op x y in iteri n f.
Lemma iterSr n f x : iter n.+1 f x = iter n f (f x).
Proof. by elim: n => //= n <-. Qed.
Lemma iterS n f x : iter n.+1 f x = f (iter n f x). Proof. by []. Qed.
Lemma iter_add n m f x : iter (n + m) f x = iter n f (iter m f x).
Proof. by elim: n => //= n ->. Qed.
Lemma iteriS n f x : iteri n.+1 f x = f n (iteri n f x).
Proof. by []. Qed.
Lemma iteropS idx n op x : iterop n.+1 op x idx = iter n (op x) x.
Proof. by elim: n => //= n ->. Qed.
Lemma eq_iter f f' : f =1 f' -> forall n, iter n f =1 iter n f'.
Proof. by move=> eq_f n x; elim: n => //= n ->; rewrite eq_f. Qed.
Lemma eq_iteri f f' : f =2 f' -> forall n, iteri n f =1 iteri n f'.
Proof. by move=> eq_f n x; elim: n => //= n ->; rewrite eq_f. Qed.
Lemma eq_iterop n op op' : op =2 op' -> iterop n op =2 iterop n op'.
Proof. by move=> eq_op x; apply: eq_iteri; case. Qed.
End Iteration.
Lemma iter_succn m n : iter n succn m = m + n.
Proof. by elim: n => //= n ->. Qed.
Lemma iter_succn_0 n : iter n succn 0 = n.
Proof. exact: iter_succn. Qed.
Lemma iter_predn m n : iter n predn m = m - n.
Proof. by elim: n m => /= [|n IHn] m; rewrite ?subn0 // IHn subnS. Qed.
(* Multiplication. *)
Definition muln_rec := mult.
Notation "m * n" := (muln_rec m n) : nat_rec_scope.
Definition muln := nosimpl muln_rec.
Notation "m * n" := (muln m n) : nat_scope.
Lemma multE : mult = muln. Proof. by []. Qed.
Lemma mulnE : muln = muln_rec. Proof. by []. Qed.
Lemma mul0n : left_zero 0 muln. Proof. by []. Qed.
Lemma muln0 : right_zero 0 muln. Proof. by elim. Qed.
Lemma mul1n : left_id 1 muln. Proof. exact: addn0. Qed.
Lemma mulSn m n : m.+1 * n = n + m * n. Proof. by []. Qed.
Lemma mulSnr m n : m.+1 * n = m * n + n. Proof. exact: addnC. Qed.
Lemma mulnS m n : m * n.+1 = m + m * n.
Proof. by elim: m => // m; rewrite !mulSn !addSn addnCA => ->. Qed.
Lemma mulnSr m n : m * n.+1 = m * n + m.
Proof. by rewrite addnC mulnS. Qed.
Lemma iter_addn m n p : iter n (addn m) p = m * n + p.
Proof. by elim: n => /= [|n ->]; rewrite ?muln0 // mulnS addnA. Qed.
Lemma iter_addn_0 m n : iter n (addn m) 0 = m * n.
Proof. by rewrite iter_addn addn0. Qed.
Lemma muln1 : right_id 1 muln.
Proof. by move=> n; rewrite mulnSr muln0. Qed.
Lemma mulnC : commutative muln.
Proof.
by move=> m n; elim: m => [|m]; rewrite (muln0, mulnS) // mulSn => ->.
Qed.
Lemma mulnDl : left_distributive muln addn.
Proof. by move=> m1 m2 n; elim: m1 => //= m1 IHm; rewrite -addnA -IHm. Qed.
Lemma mulnDr : right_distributive muln addn.
Proof. by move=> m n1 n2; rewrite !(mulnC m) mulnDl. Qed.
Lemma mulnBl : left_distributive muln subn.
Proof.
move=> m n [|p]; first by rewrite !muln0.
by elim: m n => // [m IHm] [|n] //; rewrite mulSn subnDl -IHm.
Qed.
Lemma mulnBr : right_distributive muln subn.
Proof. by move=> m n p; rewrite !(mulnC m) mulnBl. Qed.
Lemma mulnA : associative muln.
Proof. by move=> m n p; elim: m => //= m; rewrite mulSn mulnDl => ->. Qed.
Lemma mulnCA : left_commutative muln.
Proof. by move=> m n1 n2; rewrite !mulnA (mulnC m). Qed.
Lemma mulnAC : right_commutative muln.
Proof. by move=> m n p; rewrite -!mulnA (mulnC n). Qed.
Lemma mulnACA : interchange muln muln.
Proof. by move=> m n p q; rewrite -!mulnA (mulnCA n). Qed.
Lemma muln_eq0 m n : (m * n == 0) = (m == 0) || (n == 0).
Proof. by case: m n => // m [|n] //=; rewrite muln0. Qed.
Lemma muln_eq1 m n : (m * n == 1) = (m == 1) && (n == 1).
Proof. by case: m n => [|[|m]] [|[|n]] //; rewrite muln0. Qed.
Lemma muln_gt0 m n : (0 < m * n) = (0 < m) && (0 < n).
Proof. by case: m n => // m [|n] //=; rewrite muln0. Qed.
Lemma leq_pmull m n : n > 0 -> m <= n * m.
Proof. by move/prednK <-; apply: leq_addr. Qed.
Lemma leq_pmulr m n : n > 0 -> m <= m * n.
Proof. by move/leq_pmull; rewrite mulnC. Qed.
Lemma leq_mul2l m n1 n2 : (m * n1 <= m * n2) = (m == 0) || (n1 <= n2).
Proof. by rewrite {1}/leq -mulnBr muln_eq0. Qed.
Lemma leq_mul2r m n1 n2 : (n1 * m <= n2 * m) = (m == 0) || (n1 <= n2).
Proof. by rewrite -!(mulnC m) leq_mul2l. Qed.
Lemma leq_mul m1 m2 n1 n2 : m1 <= n1 -> m2 <= n2 -> m1 * m2 <= n1 * n2.
Proof.
move=> le_mn1 le_mn2; apply (@leq_trans (m1 * n2)).
by rewrite leq_mul2l le_mn2 orbT.
by rewrite leq_mul2r le_mn1 orbT.
Qed.
Lemma eqn_mul2l m n1 n2 : (m * n1 == m * n2) = (m == 0) || (n1 == n2).
Proof. by rewrite eqn_leq !leq_mul2l -orb_andr -eqn_leq. Qed.
Lemma eqn_mul2r m n1 n2 : (n1 * m == n2 * m) = (m == 0) || (n1 == n2).
Proof. by rewrite eqn_leq !leq_mul2r -orb_andr -eqn_leq. Qed.
Lemma leq_pmul2l m n1 n2 : 0 < m -> (m * n1 <= m * n2) = (n1 <= n2).
Proof. by move/prednK=> <-; rewrite leq_mul2l. Qed.
Arguments leq_pmul2l [m n1 n2].
Lemma leq_pmul2r m n1 n2 : 0 < m -> (n1 * m <= n2 * m) = (n1 <= n2).
Proof. by move/prednK <-; rewrite leq_mul2r. Qed.
Arguments leq_pmul2r [m n1 n2].
Lemma eqn_pmul2l m n1 n2 : 0 < m -> (m * n1 == m * n2) = (n1 == n2).
Proof. by move/prednK <-; rewrite eqn_mul2l. Qed.
Arguments eqn_pmul2l [m n1 n2].
Lemma eqn_pmul2r m n1 n2 : 0 < m -> (n1 * m == n2 * m) = (n1 == n2).
Proof. by move/prednK <-; rewrite eqn_mul2r. Qed.
Arguments eqn_pmul2r [m n1 n2].
Lemma ltn_mul2l m n1 n2 : (m * n1 < m * n2) = (0 < m) && (n1 < n2).
Proof. by rewrite lt0n !ltnNge leq_mul2l negb_or. Qed.
Lemma ltn_mul2r m n1 n2 : (n1 * m < n2 * m) = (0 < m) && (n1 < n2).
Proof. by rewrite lt0n !ltnNge leq_mul2r negb_or. Qed.
Lemma ltn_pmul2l m n1 n2 : 0 < m -> (m * n1 < m * n2) = (n1 < n2).
Proof. by move/prednK <-; rewrite ltn_mul2l. Qed.
Arguments ltn_pmul2l [m n1 n2].
Lemma ltn_pmul2r m n1 n2 : 0 < m -> (n1 * m < n2 * m) = (n1 < n2).
Proof. by move/prednK <-; rewrite ltn_mul2r. Qed.
Arguments ltn_pmul2r [m n1 n2].
Lemma ltn_Pmull m n : 1 < n -> 0 < m -> m < n * m.
Proof. by move=> lt1n m_gt0; rewrite -{1}[m]mul1n ltn_pmul2r. Qed.
Lemma ltn_Pmulr m n : 1 < n -> 0 < m -> m < m * n.
Proof. by move=> lt1n m_gt0; rewrite mulnC ltn_Pmull. Qed.
Lemma ltn_mul m1 m2 n1 n2 : m1 < n1 -> m2 < n2 -> m1 * m2 < n1 * n2.
Proof.
move=> lt_mn1 lt_mn2; apply (@leq_ltn_trans (m1 * n2)).
by rewrite leq_mul2l orbC ltnW.
by rewrite ltn_pmul2r // (leq_trans _ lt_mn2).
Qed.
Lemma maxn_mulr : right_distributive muln maxn.
Proof. by case=> // m n1 n2; rewrite /maxn (fun_if (muln _)) ltn_pmul2l. Qed.
Lemma maxn_mull : left_distributive muln maxn.
Proof. by move=> m1 m2 n; rewrite -!(mulnC n) maxn_mulr. Qed.
Lemma minn_mulr : right_distributive muln minn.
Proof. by case=> // m n1 n2; rewrite /minn (fun_if (muln _)) ltn_pmul2l. Qed.
Lemma minn_mull : left_distributive muln minn.
Proof. by move=> m1 m2 n; rewrite -!(mulnC n) minn_mulr. Qed.
(* Exponentiation. *)
Definition expn_rec m n := iterop n muln m 1.
Notation "m ^ n" := (expn_rec m n) : nat_rec_scope.
Definition expn := nosimpl expn_rec.
Notation "m ^ n" := (expn m n) : nat_scope.
Lemma expnE : expn = expn_rec. Proof. by []. Qed.
Lemma expn0 m : m ^ 0 = 1. Proof. by []. Qed.
Lemma expn1 m : m ^ 1 = m. Proof. by []. Qed.
Lemma expnS m n : m ^ n.+1 = m * m ^ n. Proof. by case: n; rewrite ?muln1. Qed.
Lemma expnSr m n : m ^ n.+1 = m ^ n * m. Proof. by rewrite mulnC expnS. Qed.
Lemma iter_muln m n p : iter n (muln m) p = m ^ n * p.
Proof. by elim: n => /= [|n ->]; rewrite ?mul1n // expnS mulnA. Qed.
Lemma iter_muln_1 m n : iter n (muln m) 1 = m ^ n.
Proof. by rewrite iter_muln muln1. Qed.
Lemma exp0n n : 0 < n -> 0 ^ n = 0. Proof. by case: n => [|[]]. Qed.
Lemma exp1n n : 1 ^ n = 1.
Proof. by elim: n => // n; rewrite expnS mul1n. Qed.
Lemma expnD m n1 n2 : m ^ (n1 + n2) = m ^ n1 * m ^ n2.
Proof. by elim: n1 => [|n1 IHn]; rewrite !(mul1n, expnS) // IHn mulnA. Qed.
Lemma expnMn m1 m2 n : (m1 * m2) ^ n = m1 ^ n * m2 ^ n.
Proof. by elim: n => // n IHn; rewrite !expnS IHn -!mulnA (mulnCA m2). Qed.
Lemma expnM m n1 n2 : m ^ (n1 * n2) = (m ^ n1) ^ n2.
Proof.
elim: n1 => [|n1 IHn]; first by rewrite exp1n.
by rewrite expnD expnS expnMn IHn.
Qed.
Lemma expnAC m n1 n2 : (m ^ n1) ^ n2 = (m ^ n2) ^ n1.
Proof. by rewrite -!expnM mulnC. Qed.
Lemma expn_gt0 m n : (0 < m ^ n) = (0 < m) || (n == 0).
Proof.
by case: m => [|m]; elim: n => //= n IHn; rewrite expnS // addn_gt0 IHn.
Qed.
Lemma expn_eq0 m e : (m ^ e == 0) = (m == 0) && (e > 0).
Proof. by rewrite !eqn0Ngt expn_gt0 negb_or -lt0n. Qed.
Lemma ltn_expl m n : 1 < m -> n < m ^ n.
Proof.
move=> m_gt1; elim: n => //= n; rewrite -(leq_pmul2l (ltnW m_gt1)) expnS.
by apply: leq_trans; apply: ltn_Pmull.
Qed.
Lemma leq_exp2l m n1 n2 : 1 < m -> (m ^ n1 <= m ^ n2) = (n1 <= n2).
Proof.
move=> m_gt1; elim: n1 n2 => [|n1 IHn] [|n2] //; last 1 first.
- by rewrite !expnS leq_pmul2l ?IHn // ltnW.
- by rewrite expn_gt0 ltnW.
by rewrite leqNgt (leq_trans m_gt1) // expnS leq_pmulr // expn_gt0 ltnW.
Qed.
Lemma ltn_exp2l m n1 n2 : 1 < m -> (m ^ n1 < m ^ n2) = (n1 < n2).
Proof. by move=> m_gt1; rewrite !ltnNge leq_exp2l. Qed.
Lemma eqn_exp2l m n1 n2 : 1 < m -> (m ^ n1 == m ^ n2) = (n1 == n2).
Proof. by move=> m_gt1; rewrite !eqn_leq !leq_exp2l. Qed.
Lemma expnI m : 1 < m -> injective (expn m).
Proof. by move=> m_gt1 e1 e2 /eqP; rewrite eqn_exp2l // => /eqP. Qed.
Lemma leq_pexp2l m n1 n2 : 0 < m -> n1 <= n2 -> m ^ n1 <= m ^ n2.
Proof. by case: m => [|[|m]] // _; [rewrite !exp1n | rewrite leq_exp2l]. Qed.
Lemma ltn_pexp2l m n1 n2 : 0 < m -> m ^ n1 < m ^ n2 -> n1 < n2.
Proof. by case: m => [|[|m]] // _; [rewrite !exp1n | rewrite ltn_exp2l]. Qed.
Lemma ltn_exp2r m n e : e > 0 -> (m ^ e < n ^ e) = (m < n).
Proof.
move=> e_gt0; apply/idP/idP=> [|ltmn].
rewrite !ltnNge; apply: contra => lemn.
by elim: e {e_gt0} => // e IHe; rewrite !expnS leq_mul.
by elim: e e_gt0 => // [[|e] IHe] _; rewrite ?expn1 // ltn_mul // IHe.
Qed.
Lemma leq_exp2r m n e : e > 0 -> (m ^ e <= n ^ e) = (m <= n).
Proof. by move=> e_gt0; rewrite leqNgt ltn_exp2r // -leqNgt. Qed.
Lemma eqn_exp2r m n e : e > 0 -> (m ^ e == n ^ e) = (m == n).
Proof. by move=> e_gt0; rewrite !eqn_leq !leq_exp2r. Qed.
Lemma expIn e : e > 0 -> injective (expn^~ e).
Proof. by move=> e_gt1 m n /eqP; rewrite eqn_exp2r // => /eqP. Qed.
(* Factorial. *)
Fixpoint fact_rec n := if n is n'.+1 then n * fact_rec n' else 1.
Definition factorial := nosimpl fact_rec.
Notation "n `!" := (factorial n) (at level 2, format "n `!") : nat_scope.
Lemma factE : factorial = fact_rec. Proof. by []. Qed.
Lemma fact0 : 0`! = 1. Proof. by []. Qed.
Lemma factS n : (n.+1)`! = n.+1 * n`!. Proof. by []. Qed.
Lemma fact_gt0 n : n`! > 0.
Proof. by elim: n => //= n IHn; rewrite muln_gt0. Qed.
(* Parity and bits. *)
Coercion nat_of_bool (b : bool) := if b then 1 else 0.
Lemma leq_b1 (b : bool) : b <= 1. Proof. by case: b. Qed.
Lemma addn_negb (b : bool) : ~~ b + b = 1. Proof. by case: b. Qed.
Lemma eqb0 (b : bool) : (b == 0 :> nat) = ~~ b. Proof. by case: b. Qed.
Lemma eqb1 (b : bool) : (b == 1 :> nat) = b. Proof. by case: b. Qed.
Lemma lt0b (b : bool) : (b > 0) = b. Proof. by case: b. Qed.
Lemma sub1b (b : bool) : 1 - b = ~~ b. Proof. by case: b. Qed.
Lemma mulnb (b1 b2 : bool) : b1 * b2 = b1 && b2.
Proof. by case: b1; case: b2. Qed.
Lemma mulnbl (b : bool) n : b * n = (if b then n else 0).
Proof. by case: b; rewrite ?mul1n. Qed.
Lemma mulnbr (b : bool) n : n * b = (if b then n else 0).
Proof. by rewrite mulnC mulnbl. Qed.
Fixpoint odd n := if n is n'.+1 then ~~ odd n' else false.
Lemma oddb (b : bool) : odd b = b. Proof. by case: b. Qed.
Lemma odd_add m n : odd (m + n) = odd m (+) odd n.
Proof. by elim: m => [|m IHn] //=; rewrite -addTb IHn addbA addTb. Qed.
Lemma odd_sub m n : n <= m -> odd (m - n) = odd m (+) odd n.
Proof.
by move=> le_nm; apply: (@canRL bool) (addbK _) _; rewrite -odd_add subnK.
Qed.
Lemma odd_opp i m : odd m = false -> i <= m -> odd (m - i) = odd i.
Proof. by move=> oddm le_im; rewrite (odd_sub (le_im)) oddm. Qed.
Lemma odd_mul m n : odd (m * n) = odd m && odd n.
Proof. by elim: m => //= m IHm; rewrite odd_add -addTb andb_addl -IHm. Qed.
Lemma odd_exp m n : odd (m ^ n) = (n == 0) || odd m.
Proof. by elim: n => // n IHn; rewrite expnS odd_mul {}IHn orbC; case odd. Qed.
(* Doubling. *)
Fixpoint double_rec n := if n is n'.+1 then n'.*2%Nrec.+2 else 0
where "n .*2" := (double_rec n) : nat_rec_scope.
Definition double := nosimpl double_rec.
Notation "n .*2" := (double n) : nat_scope.
Lemma doubleE : double = double_rec. Proof. by []. Qed.
Lemma double0 : 0.*2 = 0. Proof. by []. Qed.
Lemma doubleS n : n.+1.*2 = n.*2.+2. Proof. by []. Qed.
Lemma addnn n : n + n = n.*2.
Proof. by apply: eqP; elim: n => // n IHn; rewrite addnS. Qed.
Lemma mul2n m : 2 * m = m.*2.
Proof. by rewrite mulSn mul1n addnn. Qed.
Lemma muln2 m : m * 2 = m.*2.
Proof. by rewrite mulnC mul2n. Qed.
Lemma doubleD m n : (m + n).*2 = m.*2 + n.*2.
Proof. by rewrite -!addnn -!addnA (addnCA n). Qed.
Lemma doubleB m n : (m - n).*2 = m.*2 - n.*2.
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma leq_double m n : (m.*2 <= n.*2) = (m <= n).
Proof. by rewrite /leq -doubleB; case (m - n). Qed.
Lemma ltn_double m n : (m.*2 < n.*2) = (m < n).
Proof. by rewrite 2!ltnNge leq_double. Qed.
Lemma ltn_Sdouble m n : (m.*2.+1 < n.*2) = (m < n).
Proof. by rewrite -doubleS leq_double. Qed.
Lemma leq_Sdouble m n : (m.*2 <= n.*2.+1) = (m <= n).
Proof. by rewrite leqNgt ltn_Sdouble -leqNgt. Qed.
Lemma odd_double n : odd n.*2 = false.
Proof. by rewrite -addnn odd_add addbb. Qed.
Lemma double_gt0 n : (0 < n.*2) = (0 < n).
Proof. by case: n. Qed.
Lemma double_eq0 n : (n.*2 == 0) = (n == 0).
Proof. by case: n. Qed.
Lemma doubleMl m n : (m * n).*2 = m.*2 * n.
Proof. by rewrite -!mul2n mulnA. Qed.
Lemma doubleMr m n : (m * n).*2 = m * n.*2.
Proof. by rewrite -!muln2 mulnA. Qed.
(* Halving. *)
Fixpoint half (n : nat) : nat := if n is n'.+1 then uphalf n' else n
with uphalf (n : nat) : nat := if n is n'.+1 then n'./2.+1 else n
where "n ./2" := (half n) : nat_scope.
Lemma doubleK : cancel double half.
Proof. by elim=> //= n ->. Qed.
Definition half_double := doubleK.
Definition double_inj := can_inj doubleK.
Lemma uphalf_double n : uphalf n.*2 = n.
Proof. by elim: n => //= n ->. Qed.
Lemma uphalf_half n : uphalf n = odd n + n./2.
Proof. by elim: n => //= n ->; rewrite addnA addn_negb. Qed.
Lemma odd_double_half n : odd n + n./2.*2 = n.
Proof.
by elim: n => //= n {3}<-; rewrite uphalf_half doubleD; case (odd n).
Qed.
Lemma half_bit_double n (b : bool) : (b + n.*2)./2 = n.
Proof. by case: b; rewrite /= (half_double, uphalf_double). Qed.
Lemma halfD m n : (m + n)./2 = (odd m && odd n) + (m./2 + n./2).
Proof.
rewrite -{1}[n]odd_double_half addnCA -{1}[m]odd_double_half -addnA -doubleD.
by do 2!case: odd; rewrite /= ?add0n ?half_double ?uphalf_double.
Qed.
Lemma half_leq m n : m <= n -> m./2 <= n./2.
Proof. by move/subnK <-; rewrite halfD addnA leq_addl. Qed.
Lemma half_gt0 n : (0 < n./2) = (1 < n).
Proof. by case: n => [|[]]. Qed.
Lemma odd_geq m n : odd n -> (m <= n) = (m./2.*2 <= n).
Proof.
move=> odd_n; rewrite -{1}[m]odd_double_half -[n]odd_double_half odd_n.
by case: (odd m); rewrite // leq_Sdouble ltnS leq_double.
Qed.
Lemma odd_ltn m n : odd n -> (n < m) = (n < m./2.*2).
Proof. by move=> odd_n; rewrite !ltnNge odd_geq. Qed.
Lemma odd_gt0 n : odd n -> n > 0. Proof. by case: n. Qed.
Lemma odd_gt2 n : odd n -> n > 1 -> n > 2.
Proof. by move=> odd_n n_gt1; rewrite odd_geq. Qed.
(* Squares and square identities. *)
Lemma mulnn m : m * m = m ^ 2.
Proof. by rewrite !expnS muln1. Qed.
Lemma sqrnD m n : (m + n) ^ 2 = m ^ 2 + n ^ 2 + 2 * (m * n).
Proof.
rewrite -!mulnn mul2n mulnDr !mulnDl (mulnC n) -!addnA.
by congr (_ + _); rewrite addnA addnn addnC.
Qed.
Lemma sqrn_sub m n : n <= m -> (m - n) ^ 2 = m ^ 2 + n ^ 2 - 2 * (m * n).
Proof.
move/subnK=> def_m; rewrite -{2}def_m sqrnD -addnA addnAC.
by rewrite -2!addnA addnn -mul2n -mulnDr -mulnDl def_m addnK.
Qed.
Lemma sqrnD_sub m n : n <= m -> (m + n) ^ 2 - 4 * (m * n) = (m - n) ^ 2.
Proof.
move=> le_nm; rewrite -[4]/(2 * 2) -mulnA mul2n -addnn subnDA.
by rewrite sqrnD addnK sqrn_sub.
Qed.
Lemma subn_sqr m n : m ^ 2 - n ^ 2 = (m - n) * (m + n).
Proof. by rewrite mulnBl !mulnDr addnC (mulnC m) subnDl !mulnn. Qed.
Lemma ltn_sqr m n : (m ^ 2 < n ^ 2) = (m < n).
Proof. by rewrite ltn_exp2r. Qed.
Lemma leq_sqr m n : (m ^ 2 <= n ^ 2) = (m <= n).
Proof. by rewrite leq_exp2r. Qed.
Lemma sqrn_gt0 n : (0 < n ^ 2) = (0 < n).
Proof. exact: (ltn_sqr 0). Qed.
Lemma eqn_sqr m n : (m ^ 2 == n ^ 2) = (m == n).
Proof. by rewrite eqn_exp2r. Qed.
Lemma sqrn_inj : injective (expn ^~ 2).
Proof. exact: expIn. Qed.
(* Almost strict inequality: an inequality that is strict unless some *)
(* specific condition holds, such as the Cauchy-Schwartz or the AGM *)
(* inequality (we only prove the order-2 AGM here; the general one *)
(* requires sequences). *)
(* We formalize the concept as a rewrite multirule, that can be used *)
(* both to rewrite the non-strict inequality to true, and the equality *)
(* to the specific condition (for strict inequalities use the ltn_neqAle *)
(* lemma); in addition, the conditional equality also coerces to a *)
(* non-strict one. *)
Definition leqif m n C := ((m <= n) * ((m == n) = C))%type.
Notation "m <= n ?= 'iff' C" := (leqif m n C) : nat_scope.
Coercion leq_of_leqif m n C (H : m <= n ?= iff C) := H.1 : m <= n.
Lemma leqifP m n C : reflect (m <= n ?= iff C) (if C then m == n else m < n).
Proof.
rewrite ltn_neqAle; apply: (iffP idP) => [|lte]; last by rewrite !lte; case C.
by case C => [/eqP-> | /andP[/negPf]]; split=> //; apply: eqxx.
Qed.
Lemma leqif_refl m C : reflect (m <= m ?= iff C) C.
Proof. by apply: (iffP idP) => [-> | <-] //; split; rewrite ?eqxx. Qed.
Lemma leqif_trans m1 m2 m3 C12 C23 :
m1 <= m2 ?= iff C12 -> m2 <= m3 ?= iff C23 -> m1 <= m3 ?= iff C12 && C23.
Proof.
move=> ltm12 ltm23; apply/leqifP; rewrite -ltm12.
case eqm12: (m1 == m2).
by rewrite (eqP eqm12) ltn_neqAle !ltm23 andbT; case C23.
by rewrite (@leq_trans m2) ?ltm23 // ltn_neqAle eqm12 ltm12.
Qed.
Lemma mono_leqif f : {mono f : m n / m <= n} ->
forall m n C, (f m <= f n ?= iff C) = (m <= n ?= iff C).
Proof. by move=> f_mono m n C; rewrite /leqif !eqn_leq !f_mono. Qed.
Lemma leqif_geq m n : m <= n -> m <= n ?= iff (m >= n).
Proof. by move=> lemn; split=> //; rewrite eqn_leq lemn. Qed.
Lemma leqif_eq m n : m <= n -> m <= n ?= iff (m == n).
Proof. by []. Qed.
Lemma geq_leqif a b C : a <= b ?= iff C -> (b <= a) = C.
Proof. by case=> le_ab; rewrite eqn_leq le_ab. Qed.
Lemma ltn_leqif a b C : a <= b ?= iff C -> (a < b) = ~~ C.
Proof. by move=> le_ab; rewrite ltnNge (geq_leqif le_ab). Qed.
Lemma leqif_add m1 n1 C1 m2 n2 C2 :
m1 <= n1 ?= iff C1 -> m2 <= n2 ?= iff C2 ->
m1 + m2 <= n1 + n2 ?= iff C1 && C2.
Proof.
rewrite -(mono_leqif (leq_add2r m2)) -(mono_leqif (leq_add2l n1) m2).
exact: leqif_trans.
Qed.
Lemma leqif_mul m1 n1 C1 m2 n2 C2 :
m1 <= n1 ?= iff C1 -> m2 <= n2 ?= iff C2 ->
m1 * m2 <= n1 * n2 ?= iff (n1 * n2 == 0) || (C1 && C2).
Proof.
case: n1 => [|n1] le1; first by case: m1 le1 => [|m1] [_ <-] //.
case: n2 m2 => [|n2] [|m2] /=; try by case=> // _ <-; rewrite !muln0 ?andbF.
have /leq_pmul2l-/mono_leqif<-: 0 < n1.+1 by [].
by apply: leqif_trans; have /leq_pmul2r-/mono_leqif->: 0 < m2.+1.
Qed.
Lemma nat_Cauchy m n : 2 * (m * n) <= m ^ 2 + n ^ 2 ?= iff (m == n).
Proof.
without loss le_nm: m n / n <= m.
by case: (leqP m n); auto; rewrite eq_sym addnC (mulnC m); auto.
apply/leqifP; case: ifP => [/eqP-> | ne_mn]; first by rewrite mulnn addnn mul2n.
by rewrite -subn_gt0 -sqrn_sub // sqrn_gt0 subn_gt0 ltn_neqAle eq_sym ne_mn.
Qed.
Lemma nat_AGM2 m n : 4 * (m * n) <= (m + n) ^ 2 ?= iff (m == n).
Proof.
rewrite -[4]/(2 * 2) -mulnA mul2n -addnn sqrnD; apply/leqifP.
by rewrite ltn_add2r eqn_add2r ltn_neqAle !nat_Cauchy; case: ifP => ->.
Qed.
(* Support for larger integers. The normal definitions of +, - and even *)
(* IO are unsuitable for Peano integers larger than 2000 or so because *)
(* they are not tail-recursive. We provide a workaround module, along *)
(* with a rewrite multirule to change the tailrec operators to the *)
(* normal ones. We handle IO via the NatBin module, but provide our *)
(* own (more efficient) conversion functions. *)
Module NatTrec.
(* Usage: *)
(* Import NatTrec. *)
(* in section definining functions, rebinds all *)
(* non-tail recursive operators. *)
(* rewrite !trecE. *)
(* in the correctness proof, restores operators *)
Fixpoint add m n := if m is m'.+1 then m' + n.+1 else n
where "n + m" := (add n m) : nat_scope.
Fixpoint add_mul m n s := if m is m'.+1 then add_mul m' n (n + s) else s.
Definition mul m n := if m is m'.+1 then add_mul m' n n else 0.
Notation "n * m" := (mul n m) : nat_scope.
Fixpoint mul_exp m n p := if n is n'.+1 then mul_exp m n' (m * p) else p.
Definition exp m n := if n is n'.+1 then mul_exp m n' m else 1.
Notation "n ^ m" := (exp n m) : nat_scope.
Local Notation oddn := odd.
Fixpoint odd n := if n is n'.+2 then odd n' else eqn n 1.
Local Notation doublen := double.
Definition double n := if n is n'.+1 then n' + n.+1 else 0.
Notation "n .*2" := (double n) : nat_scope.
Lemma addE : add =2 addn.
Proof. by elim=> //= n IHn m; rewrite IHn addSnnS. Qed.
Lemma doubleE : double =1 doublen.
Proof. by case=> // n; rewrite -addnn -addE. Qed.
Lemma add_mulE n m s : add_mul n m s = addn (muln n m) s.
Proof. by elim: n => //= n IHn in m s *; rewrite IHn addE addnCA addnA. Qed.
Lemma mulE : mul =2 muln.
Proof. by case=> //= n m; rewrite add_mulE addnC. Qed.
Lemma mul_expE m n p : mul_exp m n p = muln (expn m n) p.
Proof.
by elim: n => [|n IHn] in p *; rewrite ?mul1n //= expnS IHn mulE mulnCA mulnA.
Qed.
Lemma expE : exp =2 expn.
Proof. by move=> m [|n] //=; rewrite mul_expE expnS mulnC. Qed.
Lemma oddE : odd =1 oddn.
Proof.
move=> n; rewrite -{1}[n]odd_double_half addnC.
by elim: n./2 => //=; case (oddn n).
Qed.
Definition trecE := (addE, (doubleE, oddE), (mulE, add_mulE, (expE, mul_expE))).
End NatTrec.
Notation natTrecE := NatTrec.trecE.
Lemma eq_binP : Equality.axiom N.eqb.
Proof.
move=> p q; apply: (iffP idP) => [|<-]; last by case: p => //; elim.
by case: q; case: p => //; elim=> [p IHp|p IHp|] [q|q|] //=; case/IHp=> ->.
Qed.
Canonical bin_nat_eqMixin := EqMixin eq_binP.
Canonical bin_nat_eqType := Eval hnf in EqType N bin_nat_eqMixin.
Arguments N.eqb !n !m.
Section NumberInterpretation.
Import BinPos.
Section Trec.
Import NatTrec.
Fixpoint nat_of_pos p0 :=
match p0 with
| xO p => (nat_of_pos p).*2
| xI p => (nat_of_pos p).*2.+1
| xH => 1
end.
End Trec.
Local Coercion nat_of_pos : positive >-> nat.
Coercion nat_of_bin b := if b is Npos p then p : nat else 0.
Fixpoint pos_of_nat n0 m0 :=
match n0, m0 with
| n.+1, m.+2 => pos_of_nat n m
| n.+1, 1 => xO (pos_of_nat n n)
| n.+1, 0 => xI (pos_of_nat n n)
| 0, _ => xH
end.
Definition bin_of_nat n0 := if n0 is n.+1 then Npos (pos_of_nat n n) else 0%num.
Lemma bin_of_natK : cancel bin_of_nat nat_of_bin.
Proof.
have sub2nn n : n.*2 - n = n by rewrite -addnn addKn.
case=> //= n; rewrite -{3}[n]sub2nn.
by elim: n {2 4}n => // m IHm [|[|n]] //=; rewrite IHm // natTrecE sub2nn.
Qed.
Lemma nat_of_binK : cancel nat_of_bin bin_of_nat.
Proof.
case=> //=; elim=> //= p; case: (nat_of_pos p) => //= n [<-].
by rewrite natTrecE !addnS {2}addnn; elim: {1 3}n.
by rewrite natTrecE addnS /= addnS {2}addnn; elim: {1 3}n.
Qed.
Lemma nat_of_succ_gt0 p : Pos.succ p = p.+1 :> nat.
Proof. by elim: p => //= p ->; rewrite !natTrecE. Qed.
Lemma nat_of_addn_gt0 p q : (p + q)%positive = p + q :> nat.
Proof.
apply: @fst _ (Pplus_carry p q = (p + q).+1 :> nat) _.
elim: p q => [p IHp|p IHp|] [q|q|] //=; rewrite !natTrecE //;
by rewrite ?IHp ?nat_of_succ_gt0 ?(doubleS, doubleD, addn1, addnS).
Qed.
Lemma nat_of_add_bin b1 b2 : (b1 + b2)%num = b1 + b2 :> nat.
Proof. by case: b1 b2 => [|p] [|q] //=; apply: nat_of_addn_gt0. Qed.
Lemma nat_of_mul_bin b1 b2 : (b1 * b2)%num = b1 * b2 :> nat.
Proof.
case: b1 b2 => [|p] [|q] //=; elim: p => [p IHp|p IHp|] /=;
by rewrite ?(mul1n, nat_of_addn_gt0, mulSn) //= !natTrecE IHp doubleMl.
Qed.
Lemma nat_of_exp_bin n (b : N) : n ^ b = pow_N 1 muln n b.
Proof.
by case: b; last (elim=> //= p <-; rewrite natTrecE mulnn -expnM muln2 ?expnS).
Qed.
End NumberInterpretation.
(* Big(ger) nat IO; usage: *)
(* Num 1 072 399 *)
(* to create large numbers for test cases *)
(* Eval compute in [Num of some expression] *)
(* to display the resut of an expression that *)
(* returns a larger integer. *)
Record number : Type := Num {bin_of_number :> N}.
Definition extend_number (nn : number) m := Num (nn * 1000 + bin_of_nat m).
Coercion extend_number : number >-> Funclass.
Canonical number_subType := [newType for bin_of_number].
Definition number_eqMixin := Eval hnf in [eqMixin of number by <:].
Canonical number_eqType := Eval hnf in EqType number number_eqMixin.
Notation "[ 'Num' 'of' e ]" := (Num (bin_of_nat e))
(at level 0, format "[ 'Num' 'of' e ]") : nat_scope.
(* Interface to ring/ring_simplify tactics *)
Lemma nat_semi_ring : semi_ring_theory 0 1 addn muln (@eq _).
Proof. exact: mk_srt add0n addnC addnA mul1n mul0n mulnC mulnA mulnDl. Qed.
Lemma nat_semi_morph :
semi_morph 0 1 addn muln (@eq _) 0%num 1%num Nplus Nmult pred1 nat_of_bin.
Proof.
by move: nat_of_add_bin nat_of_mul_bin; split=> //= m n; move/eqP->.
Qed.
Lemma nat_power_theory : power_theory 1 muln (@eq _) nat_of_bin expn.
Proof. by split; apply: nat_of_exp_bin. Qed.
(* Interface to the ring tactic machinery. *)
Fixpoint pop_succn e := if e is e'.+1 then fun n => pop_succn e' n.+1 else id.
Ltac pop_succn e := eval lazy beta iota delta [pop_succn] in (pop_succn e 1).
Ltac nat_litteral e :=
match pop_succn e with
| ?n.+1 => constr: (bin_of_nat n)
| _ => NotConstant
end.
Ltac succn_to_add :=
match goal with
| |- context G [?e.+1] =>
let x := fresh "NatLit0" in
match pop_succn e with
| ?n.+1 => pose x := n.+1; let G' := context G [x] in change G'
| _ ?e' ?n => pose x := n; let G' := context G [x + e'] in change G'
end; succn_to_add; rewrite {}/x
| _ => idtac
end.
Add Ring nat_ring_ssr : nat_semi_ring (morphism nat_semi_morph,
constants [nat_litteral], preprocess [succn_to_add],
power_tac nat_power_theory [nat_litteral]).
(* A congruence tactic, similar to the boolean one, along with an .+1/+ *)
(* normalization tactic. *)
Ltac nat_norm :=
succn_to_add; rewrite ?add0n ?addn0 -?addnA ?(addSn, addnS, add0n, addn0).
Ltac nat_congr := first
[ apply: (congr1 succn _)
| apply: (congr1 predn _)
| apply: (congr1 (addn _) _)
| apply: (congr1 (subn _) _)
| apply: (congr1 (addn^~ _) _)
| match goal with |- (?X1 + ?X2 = ?X3) =>
symmetry;
rewrite -1?(addnC X1) -?(addnCA X1);
apply: (congr1 (addn X1) _);
symmetry
end ].
|
module Poker.Deck
import Control.ST
import Control.ST.Random
import Data.Fin
import Data.Vect
%access public export
%default total
elemSmallerThanBound : (n : Fin m) -> LT (finToNat n) m
elemSmallerThanBound FZ = LTESucc LTEZero
elemSmallerThanBound (FS x) = LTESucc (elemSmallerThanBound x)
data Suit = Spade | Heart | Diamond | Club
DecEq Suit where
decEq Spade Spade = Yes Refl
decEq Spade Heart = No $ \Refl impossible
decEq Spade Diamond = No $ \Refl impossible
decEq Spade Club = No $ \Refl impossible
decEq Heart Spade = No $ \Refl impossible
decEq Heart Heart = Yes Refl
decEq Heart Diamond = No $ \Refl impossible
decEq Heart Club = No $ \Refl impossible
decEq Diamond Spade = No $ \Refl impossible
decEq Diamond Heart = No $ \Refl impossible
decEq Diamond Diamond = Yes Refl
decEq Diamond Club = No $ \Refl impossible
decEq Club Spade = No $ \Refl impossible
decEq Club Heart = No $ \Refl impossible
decEq Club Diamond = No $ \Refl impossible
decEq Club Club = Yes Refl
Rank : Type
Rank = Fin 13
record Card where
constructor MkCard
suit : Suit
rank : Rank
enumFinHelp : (b : Nat) -> Vect a (Fin a) -> Vect (b + a) (Fin (b + a))
enumFinHelp Z xs = xs
enumFinHelp {a} (S k) xs =
let xs' = last :: map weaken xs
in rewrite plusSuccRightSucc k a in
enumFinHelp k xs'
enumFin : (n : Nat) -> Vect n (Fin n)
enumFin n =
rewrite sym (plusZeroRightNeutral n) in
enumFinHelp n []
outerBy : (a -> b -> c) -> Vect m a -> Vect n b -> Vect (m * n) c
outerBy {m} {n} f xs ys =
concat {m = m} {n = n} $ map (\x => map (f x) ys) xs
suits : Vect 4 Suit
suits = [Spade, Heart, Diamond, Club]
ranks : Vect 13 Rank
ranks = enumFin 13
ace : Rank
ace = the Rank last
newDeck : Vect 52 Card
newDeck =
let ss = suits
rs = ranks
in outerBy MkCard ss rs
data Cut : (m : Nat) -> Vect o t -> Type where
MkCut : (f : Vect m t) ->
(c : t) ->
(b : Vect n t) ->
Cut m (f ++ c :: b)
plusOnePlusSucc : (m : Nat) -> (i' : Nat) -> plus (plus m 1) i' = S (plus m i')
plusOnePlusSucc m i' = rewrite plusCommutative m 1 in Refl
cutHelp : (f : Vect m t ) ->
(b : Vect (S n) t ) ->
(i : Nat) ->
(lt : LT i (S n)) ->
Cut (m + i) (f ++ b)
cutHelp {m = m} {n = n} f (c :: b) Z lt =
rewrite plusZeroRightNeutral m in
MkCut f c b
cutHelp {m = m} {n = Z} f (c :: b) (S i') (LTESucc lt') = absurd lt'
cutHelp {m = m} {n = (S n')} f (c :: b) (S i') (LTESucc lt') =
let rec = cutHelp (f ++ [c]) b i' lt'
in rewrite vectAppendAssociative f [c] b in
rewrite sym $ plusSuccRightSucc m i' in
rewrite sym $ plusOnePlusSucc m i' in
rec
cut : (i : Nat) -> (xs : Vect n t) ->
{auto smaller : LT i n} ->
Cut i xs
cut {n = Z} i xs {smaller = smaller} = absurd smaller
cut {n = (S k)} i xs {smaller = smaller} = cutHelp [] xs i smaller
data Shuffle : Vect n t -> Type where
EmptyShuffle : (xs : Vect Z t) -> Shuffle xs
Deal : (c : t) -> Shuffle (f ++ b) -> Shuffle (f ++ c :: b)
mutual
shuffleHelp : (rnd : Var) -> (xs : Vect n t) ->
(i : Fin n) ->
ST m (Shuffle xs) [rnd ::: Random]
shuffleHelp {t} rnd xs i with (elemSmallerThanBound i)
shuffleHelp {t} rnd xs i | lt with (finToNat i)
shuffleHelp {t} rnd xs i | lt | i' with (cut i' xs)
shuffleHelp {t} rnd (f ++ c :: b) i | lt | i' | (MkCut f c b) = do
rest <- shuffle rnd $ assert_smaller (f ++ c :: b) (f ++ b)
pure (Deal {t = t} {f = f} {b = b} c rest)
shuffle : (rnd : Var) -> (xs : Vect n t) -> ST m (Shuffle xs) [rnd ::: Random]
shuffle {n = Z} rnd [] = pure (EmptyShuffle [])
shuffle {n = (S n')} rnd xs = do
i <- rndFin rnd n'
shuffleHelp rnd xs i
-- Local Variables:
-- idris-load-packages: ("contrib")
-- End:
|
function [imageCha, ssim_map, metrics] = algo_FCSA_proxA_3D( obj,input )
% 3D variant of FCSA
% based on Huang et al. paper on FCSA
%
% input:
% obj CS reconstruction object (holding all parameters)
% input struct containing recon parameters and image
%
% output:
% imageCha reconstructed channel individual image
% ssim_map structural similarity map
% metrics evaluation metrics
%
% (c) Marc Fischer, Thomas Kuestner, May 2015
% -------------------------------------------------------------------------
%%
timer_proxA = tic;
%% variables:
% internal flags
flag_wavetree = true;
flag_fast = true;
flag_extendImage = true;
% internal variables:
L = 1;
t_old = 1;
NLTV_struct.kernelratio = 3;
NLTV_struct.windowratio = 6;
NLTV_struct.nThreads = 1; % mind this option if used with -singleCompThread on BWCluster
itrNLTV = obj.iNINNER - 5;
% chambolle tv:
parsin.MAXITER=100; parsin.tv='iso'; % 'iso' or 'l1'
% from obj:
% maxitr = obj.maxitr;
maxitr = obj.iNINNER;
% n1 = obj.measPara.dim(1);
% n2 = obj.measPara.dim(2);
n1 = input.n1;
n2 = input.n2;
nSlices = input.nSlices;
% nSlices = obj.measPara.dim(3);
nCha = obj.measPara.dim(5);
lambdaWave = obj.lambda;
lambdaTV = obj.lambdaTV;
lambdaGroup = obj.lambdaGroup;
NLTV_struct.filterstrength = obj.lambdaNLTV_h; % 0.03 % converted from NLTV h = 0.01 %old: used: 3e-10
lambdaNLTV = obj.lambdaNLTV;
lambdaNLTV_h = obj.lambdaNLTV_h;
regularizerWeights = obj.regularizerWeights;
flagTV = obj.flagTV;
flagTV_iso = obj.flagTV_iso;
flagWave = obj.flagWave;
flagGroup = obj.flagGroup;
flagNLTV = obj.flagNLTV;
flagSBNLTV = obj.flagSBNLTV;
flagRealAndImag = obj.flagRealAndImag;
waveletStages = obj.trafo.waveletStages;
maxWavecells = waveletStages*7+1;
waveletFilterName_l1 = obj.trafo.waveletFilterName_l1;
waveletFilterName_l12 = obj.trafo.waveletFilterName_l12;
% from input:
b=input.b;
mask = input.mask;
G_prox = input.G_prox;
Gt_prox = input.Gt_prox;
groupnorm_index = input.groupnorm_index;
waveS_l1 = input.waveS_l1;
waveS_l12 = input.waveS_l12;
waveS_l12proxA = input.waveS_l12proxA;
proxA_extend_y = waveS_l12proxA(waveletStages+2,1) - waveS_l12(waveletStages+2,1);
proxA_extend_x = waveS_l12proxA(waveletStages+2,2) - waveS_l12(waveletStages+2,2);
z_proxA = cell(1,nCha);
% im_ref = input.im_ref;
% im_ref_full = zeros(n1,n2,nSlices);
% for j = 1:nCha
% im_ref_full = im_ref_full + abs(im_ref{1,j}).^2;
% end;
% im_ref_full = sqrt(im_ref_full);
clear input
% initialize cells/vectors
for j=1:nCha
FTb{1,j} = iFFT3D(b{1,j});
y{1,j} = real(FTb{1,j}); % needed for y_old
y{1,j+nCha} = imag(FTb{1,j});
end;
z = FTb; % starting point
x_wave = cell(1,2*nCha);
x_helper = x_wave;
x_wave_helper = x_wave;
x_tv = x_wave;
x_nltv = x_wave;
for j=1:2*nCha
x_nltv{1,j} = 0;
end;
x_g = x_wave;
x_g_helper = x_wave;
x_g_proxA = x_wave;
z_comp = x_wave;
%% MAD dependent lambdas:
flag_MAD = true;
if flag_MAD
x_wavedec_2D = cell(1,nCha);
x_wavedec_3D = cell(1,nCha);
threshold_2D = zeros(nCha,1); % one threshold value is enough (only for testing purposes)
threshold_3D = zeros(nCha,1); % one threshold value is enough (only for testing purposes)
if flagRealAndImag
for j=1:nCha
for l = 1:nSlices
x_wavedec_2D{1,j} = wavedec2(abs(z{1,j}),waveletStages,waveletFilterName_l12); % atm only based on l1-daubechie
x_wave_fine_scale_2D = size(x_wavedec_2D{1,j},2) - (3*waveS_l12(waveletStages+1,1)*waveS_l12(waveletStages+1,2));
threshold_2D(j) = mad(x_wavedec_2D{1,j}(x_wave_fine_scale_2D:end),1);
end;
x_wavedec_3D{1,j} = wavedec3(abs(z{1,j}),waveletStages,waveletFilterName_l1); % atm only based on l1-daubechie
x_wave_fine_scale_3D = zeros(0,0);
for k = (7*(x_wavedec_3D{1,j}.level-1)+2):maxWavecells
x_wave_fine_scale_3D = [x_wave_fine_scale_3D x_wavedec_3D{1,j}.dec{k}];
end;
[size1, size2, size3] = size(x_wave_fine_scale_3D);
threshold_3D(j) = mad(reshape(x_wave_fine_scale_3D,size1*size2*size3,1));
end;
else
for j=1:nCha
for l = 1:nSlices
x_wavedec_2D{1,j} = wavedec2(real(z{1,j}),waveletStages,waveletFilterName_l12); % atm only based on l1-daubechie
x_wavedec_2D{1,j+nCha} = wavedec2(imag(z{1,j}),waveletStages,waveletFilterName_l12); % atm only based on l1-daubechie
x_wave_fine_scale_2D_real = size(x_wavedec_2D{1,j},2) - (3*waveS_l12(waveletStages+1,1)*waveS_l12(waveletStages+1,2));
threshold_2D(j) = mad(x_wavedec_2D{1,j}(x_wave_fine_scale_2D_real:end),1);
x_wave_fine_scale_2D_imag = size(x_wavedec_2D{1,j},2) - (3*waveS_l12(waveletStages+1,1)*waveS_l12(waveletStages+1,2));
threshold_2D(j+nCha) = mad(x_wavedec_2D{1,j}(x_wave_fine_scale_2D_imag:end),1);
end;
x_wavedec_3D{1,j} = wavedec3(real(z{1,j}),waveletStages,waveletFilterName_l1); % atm only based on l1-daubechie
x_wavedec_3D{1,j} = wavedec3(imag(z{1,j}),waveletStages,waveletFilterName_l1); % atm only based on l1-daubechie
x_wave_fine_scale_3D_real = zeros(0,0);
x_wave_fine_scale_3D_imag = zeros(0,0);
for k = (7*(x_wavedec_3D{1,j}.level-1)+2):maxWavecells
x_wave_fine_scale_3D_real = [x_wave_fine_scale_3D_real x_wavedec_3D{1,j}.dec{k+2}];
x_wave_fine_scale_3D_imag = [x_wave_fine_scale_3D_imag x_wavedec_3D{1,j}.dec{k+2}];
end;
[size1, size2, size3] = size(x_wave_fine_scale_3D_real);
threshold_3D(j) = mad(reshape(x_wave_fine_scale_3D_real,size1*size2*size3,1));
threshold_3D(j+nCha) = mad(reshape(x_wave_fine_scale_3D_imag,size1*size2*size3,1));
end;
end;
clear x_wavedec
else
threshold_2D(1:nCha) = 1;
threshold_3D(1:nCha) = 1;
end;
if flagRealAndImag
threshold_group = 0;
for j = 1:nCha
threshold_wave(j) = lambdaWave * threshold_3D(j)/2 * 2/L;
threshold_TV(j) = lambdaTV * threshold_2D(j) * 2/L;
threshold_TV(j+nCha) = lambdaTV * threshold_2D(j) * 2/L;
threshold_group = threshold_group + lambdaGroup * threshold_2D(j) * 2/L;
threshold_NLTV(j) = lambdaNLTV; % * threshold(j) * 2/L;
threshold_NLTV(j+nCha) = lambdaNLTV;
threshold_NLTV_h(j) = lambdaNLTV_h; %*threshold(j); % adjust carefully or NLTV won't find a solution. lambdaNLTV_h should be < 0.01
threshold_NLTV_h(j+nCha) = lambdaNLTV_h;
end;
threshold_group = threshold_group /3;
else
threshold_group_real = 0;
threshold_group_imag = 0;
for j = 1:nCha
threshold_wave(j) = lambdaWave * threshold_3D(j) * 2/L;
threshold_wave(j+nCha) = lambdaWave * threshold_3D(j+nCha) * 2/L;
threshold_TV(j) = lambdaTV * threshold_2D(j) * 2/L;
threshold_TV(j+nCha) = lambdaTV * threshold_2D(j+nCha) * 2/L;
threshold_group_real = threshold_group_real + lambdaGroup * threshold_2D(j) * 2/L;
threshold_group_imag = threshold_group_imag + lambdaGroup * threshold_2D(j) * 2/L;
threshold_NLTV(j) = lambdaNLTV; % * threshold(j) * 2/L;
threshold_NLTV(j+nCha) = lambdaNLTV;
threshold_NLTV_h(j) = lambdaNLTV_h; %*threshold(j); % adjust carefully or NLTV won't find a solution. lambdaNLTV_h should be < 0.01
threshold_NLTV_h(j+nCha) = lambdaNLTV_h;
end;
threshold_group_real = threshold_group_real /3;
threshold_group_imag = threshold_group_imag /3;
end;
%% initialize metrics:
itr = 0;
metrics.xtime(itr+1)= 0;
% [metrics, ssim_map{1,1}] = get_metrics_itr( im_ref, im_ref_full, z, itr, maxitr, nCha, n1, n2, metrics, obj.K_1, obj.K_2, obj.W_size, obj.W_sigma, nSlices );
ssim_map = [];
%% recon
dispProgress('Proximal Average', 0, maxitr);
for itr = 1:maxitr % total iter counter
t_new = (1+sqrt(1+4*t_old^2))/2;
t_old = t_new;
y_old = y; % y_old = y for complex case
%% landweber step
for j = 1:nCha
x_helper{1,j} = iFFT3D(FFT3D_mask(z{1,j},mask)) -FTb{1,j} ;
z{1,j} = z{1,j} - x_helper{1,j}/L;
z_comp{1,j} = real(z{1,j});
z_comp{1,j+nCha} = imag(z{1,j});
end;
%% l1-Wavelet
if flagWave
for j = 1:2*nCha
x_wave_helper{1,j} = wavedec3(z_comp{1,j},waveletStages,waveletFilterName_l1);
end;
if flagRealAndImag
for j = 1:nCha
for k = 1:maxWavecells
dec_cell{j}{k} = x_wave_helper{1,j}.dec{k,1};
dec_cell{j+nCha}{k} = x_wave_helper{1,j+nCha}.dec{k,1};
[c1, c2, c3] = size(dec_cell{j}{k});
[dec_cell{j}{k}, dec_cell{j+nCha}{k}] = groupthresh_2vec(reshape(dec_cell{j}{k},c1*c2*c3,1,1),reshape(dec_cell{j+nCha}{k},c1*c2*c3,1,1),threshold_wave(j));
x_wave_helper{1,j}.dec{k,1} = reshape(dec_cell{j}{k},c1,c2,c3);
x_wave_helper{1,j+nCha}.dec{k,1} = reshape(dec_cell{j+nCha}{k},c1,c2,c3);
dec_cell{j}{k} = [];
dec_cell{j+nCha}{k} = [];
end;
end;
else
for j = 1:2*nCha
x_wave_helper{1,j} = softthresh_real(x_wave_helper{1,j},threshold_wave(j));
for k = 1:maxWavecells
dec_cell{j}{k} = x_wave_helper{1,j}.dec{k,1};
[c1, c2, c3] = size(dec_cell{j}{k});
dec_cell{j}{k} = softthresh_real(reshape(dec_cell{j}{k},c1*c2*c3,1,1),threshold_wave(j));
x_wave_helper{1,j}.dec{k,1} = reshape(dec_cell{j}{k},c1,c2,c3);
dec_cell{j}{k} = [];
end;
end;
end;
for j = 1:2*nCha
x_wave{1,j} = waverec3(x_wave_helper{1,j});
end;
end;
%% TV
if flagTV
if ~flagTV_iso
for j = 1:2*nCha
for i = 1:nSlices
x_tv{1,j}(:,:,i) = MTV_2D(z_comp{1,j}(:,:,i),threshold_TV(j),n1,n2);
end;
end;
else
for j = 1:2*nCha
for i = 1:nSlices
if (itr==1)
[x_tv{1,j}(:,:,i), P]=denoise_TV_One((z_comp{1,j}(:,:,i)), threshold_TV(j),-inf,inf,[],parsin);
else
[x_tv{1,j}(:,:,i), P]=denoise_TV_One((z_comp{1,j}(:,:,i)), threshold_TV(j),-inf,inf,P,parsin);
end;
end;
end;
end;
end;
%% NLTV
if flagNLTV
if itr >= itrNLTV
if flagSBNLTV
for j = 1:2*nCha
for i = 1:nSlices
x_nltv{1,j}(:,:,i) = SB_NLTVfunc_slim_rescale(z_comp{1,j}(:,:,i),n1,n2, threshold_NLTV(j), threshold_NLTV_h(j) );
end;
end;
else
for j = 1:2*nCha
for i = 1:nSlices
% if mod(itr,5) == 0 || itr == 1
x_nltv{1,j}(:,:,i) = NLMF(z_comp{1,j}(:,:,i),NLTV_struct);
x_nltv{1,j}(:,:,i) = (L.*z_comp{1,j}(:,:,i) + 2*threshold_NLTV(j)*x_nltv{1,j}(:,:,i))./(L+2*threshold_NLTV(j));
% end;
end;
end;
end;
end;
end;
%% l12-Wavelet
if flagGroup
for j = 1:2*nCha
for i = 1:nSlices
if flag_extendImage
z_proxA{1,j}(:,:,i) = extend_image(z_comp{1,j}(:,:,i), waveS_l12proxA, waveletStages, proxA_extend_y, proxA_extend_x);
x_g_helper{i}{1,j} = wavedec2(z_proxA{1,j}(:,:,i),waveletStages,waveletFilterName_l12);
else
x_g_helper{i}{1,j} = wavedec2(z_comp{1,j}(:,:,i),waveletStages,waveletFilterName_l12);
end;
if flag_wavetree
x_g_helper{i}{2,j} = (G_prox*x_g_helper{i}{1,j}')';
else
x_g_helper{i}{2,j} = zeros(1,size(x_g_helper{i}{1,j}(:,:,i),2));
end;
end;
end;
for i = 1:nSlices
if flagRealAndImag
x_g_helper{i}(1,:) = softthresh_proxA_cha(x_g_helper{i}(:,:),threshold_group,2*nCha,waveS_l12proxA,groupnorm_index);
else
x_g_helper{i}(1,1:nCha) = softthresh_proxA_cha(x_g_helper{i}(:,1:nCha),threshold_group_real,nCha,waveS_l12proxA,groupnorm_index);
x_g_helper{i}(1,nCha+1:2*nCha) = softthresh_proxA_cha(x_g_helper{i}(:,1:nCha),threshold_group_imag,nCha,waveS_l12proxA,groupnorm_index);
end;
end;
for j = 1:2*nCha
for i = 1:nSlices
x_g_proxA{1,j}(:,:,i) = waverec2(x_g_helper{i}{1,j},waveS_l12proxA,waveletFilterName_l12);
x_g{1,j}(:,:,i) = x_g_proxA{1,j}(1:end-proxA_extend_y,1:end-proxA_extend_x,i);
end;
end;
end;
%% add prox(.)
for j = 1:2*nCha
y{1,j} = zeros(n1,n2,nSlices);
if flagWave y{1,j} = y{1,j} + x_wave{1,j}.*regularizerWeights(1); end;
if flagTV y{1,j} = y{1,j} + x_tv{1,j}.*regularizerWeights(2); end;
if flagGroup y{1,j} = y{1,j} + x_g{1,j}.*regularizerWeights(3); end;
if flagNLTV y{1,j} = y{1,j} + x_nltv{1,j}.*regularizerWeights(4); end;
if itr < itrNLTV
y{1,j} = y{1,j}/(flagTV.*regularizerWeights(2) + flagWave.*regularizerWeights(1) + flagGroup.*regularizerWeights(3));
else
y{1,j} = y{1,j}/(flagTV.*regularizerWeights(2) + flagNLTV.*regularizerWeights(4) + flagWave.*regularizerWeights(1) + flagGroup.*regularizerWeights(3));
end;
if flag_fast
y{1,j}=y{1,j}+((t_old-1)/t_new).*(y{1,j}-y_old{1,j});
end;
end;
%% metrics of current itr:
% disp(itr);
dispProgress('Proximal Average', itr/maxitr);
metrics.xtime(itr+1)= toc(timer_proxA);
for j = 1:nCha
z{1,j} = y{1,j} + 1i*y{1,j+nCha};
end;
% [metrics, ssim_map{1,2}] = get_metrics_itr( im_ref, im_ref_full, z, itr, maxitr, nCha, n1, n2, metrics, obj.K_1, obj.K_2, obj.W_size, obj.W_sigma, nSlices );
end;
dispProgress('Proximal Average', 'Close');
imageCha = z;
for j = 1:nCha
imageCha{1,j} = turn_image( imageCha{1,j} );
end;
% for j = 1:nCha+1
% ssim_map{1,1}{1,j} = turn_image( ssim_map{1,1}{1,j} );
% ssim_map{1,2}{1,j} = turn_image( ssim_map{1,2}{1,j} );
% end;
end
|
/* roots/fdfsolver.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Reid Priedhorsky, Brian Gough
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_roots.h>
gsl_root_fdfsolver *
gsl_root_fdfsolver_alloc (const gsl_root_fdfsolver_type * T)
{
gsl_root_fdfsolver * s = (gsl_root_fdfsolver *) malloc (sizeof (gsl_root_fdfsolver));
if (s == 0)
{
GSL_ERROR_VAL ("failed to allocate space for root solver struct",
GSL_ENOMEM, 0);
};
s->state = malloc (T->size);
if (s->state == 0)
{
free (s); /* exception in constructor, avoid memory leak */
GSL_ERROR_VAL ("failed to allocate space for root solver state",
GSL_ENOMEM, 0);
};
s->type = T ;
s->fdf = NULL;
return s;
}
int
gsl_root_fdfsolver_set (gsl_root_fdfsolver * s, gsl_function_fdf * f, double root)
{
s->fdf = f;
s->root = root;
return (s->type->set) (s->state, s->fdf, &(s->root));
}
int
gsl_root_fdfsolver_iterate (gsl_root_fdfsolver * s)
{
return (s->type->iterate) (s->state, s->fdf, &(s->root));
}
void
gsl_root_fdfsolver_free (gsl_root_fdfsolver * s)
{
free (s->state);
free (s);
}
const char *
gsl_root_fdfsolver_name (const gsl_root_fdfsolver * s)
{
return s->type->name;
}
double
gsl_root_fdfsolver_root (const gsl_root_fdfsolver * s)
{
return s->root;
}
|
Human trafficking is definitely an important issue and still exists today even in the United States! We should be doing more to combat human trafficking, especially since human traffickers usually prey on those who are young and underprivileged.
Handling human rights abuses in war-torn countries is a major issue.
|
#clean
rm(list=ls())
# load lib
library(doParallel)
library(raster)
# load params
pars <- read.table("./pars/GenSA_rf_all_2_5y_rep1.txt",row.names=1)
# list landscape
clim_files <- list.files("data/futClimGrid/stmClim",full.names=TRUE)
# source res analytics function
source('./lib/resAnalytics.r')
source('./lib/convertStates.r')
# create output dir
system('mkdir -p ./data/futStatesGrid/probs')
system('mkdir -p ./data/futStatesGrid/stm100')
system('mkdir -p ./data/futStatesGrid/stm1000')
# open cluster
cl <- makeCluster(35)
registerDoParallel(cl)
###### PROBS
# foreach(i=1:length(clim_files),.packages=c('raster','rgdal'))%dopar%{
#
# ### READ
# climGrid <- read.csv(clim_files[i],header=TRUE,stringsAsFactors=FALSE)
# names(climGrid)[4:5] <- c("tp","pp")
#
# # set NA in order to solve
# climGrid$tp[which(climGrid$tp == -9999)] <- NA
# climGrid$pp[which(climGrid$pp == -9999)] <- NA
#
# #### SOLVE
# probsGrid <- solve_stm(climGrid_scale,pars)
# probsGrid <- data.frame(x=climGrid$x,y=climGrid$y,probsGrid,stringsAsFactors=FALSE)
#
# # get metadata
# filename <- strsplit(clim_files[i],"[/.]")[[1]][4]
#
# # write
# write.csv(probsGrid,file=paste0("./data/futStatesGrid/probs/",filename,".csv"),row.names=FALSE)
#
# }
###### STATES
probs_files <- list.files("./data/futStatesGrid/probs",full.names=TRUE,pattern="1985-2000")
#load raster ref
ref_rs100 <- readRDS("data/futClimGrid/rasterClim/res100/rcp85-ACCESS1_0-1985-2000.rda")
ref_rs1000 <- readRDS("data/futClimGrid/rasterClim/res1000/rcp85-ACCESS1_0-1985-2000.rda")
foreach(i=1:length(probs_files),.packages=c('raster','rgdal'))%dopar%{
probsGrid <- read.csv(probs_files[i])
states <- character(0)
for(r in 1:nrow(probsGrid)){
if(any(is.na(probsGrid[r,3:5]))){
states <- append(states,NA)
} else {
states <- append(states,names(which.max(probsGrid[r,3:5])))
}
}
stmGrid <- data.frame(coordinates(ref_rs1000),state=stateToId(states),stringsAsFactors=FALSE)
# turn into raster using clim rs
rs_stmGrid <- stmGrid
coordinates(rs_stmGrid) <- ~ x + y
gridded(rs_stmGrid) <- TRUE
rs_stmGrid <- raster(rs_stmGrid)
projection(rs_stmGrid) <- projection(ref_rs1000)
########## CREATE RES 1000
df_stmGrid_1000 <- as.data.frame(rs_stmGrid,xy=TRUE)
# turn coord into facteur
df_stmGrid_1000$x <- as.numeric(as.factor(df_stmGrid_1000$x)) - 1
df_stmGrid_1000$y <- as.numeric(as.factor(df_stmGrid_1000$y)) - 1
df_stmGrid_1000$state <- idToState(df_stmGrid_1000$state)
df_stmGrid_1000[is.na(df_stmGrid_1000$state),"state"] <- 0
########## CREATE RES 100
# reample using ref_rs100
rs_stmGrid_100 <- resample(rs_stmGrid,ref_rs100,method="ngb")
df_stmGrid_100 <- as.data.frame(rs_stmGrid_100,xy=TRUE)
# get metadata
filename <- strsplit(probs_files[i],"[/.]")[[1]][6]
filename <- paste(strsplit(filename,"[-]")[[1]][c(1,2,4)],collapse="-")
# turn coord into facteur
df_stmGrid_100$x <- as.numeric(as.factor(df_stmGrid_100$x)) - 1
df_stmGrid_100$y <- as.numeric(as.factor(df_stmGrid_100$y)) - 1
df_stmGrid_100$state <- idToState(df_stmGrid_100$state)
df_stmGrid_100[is.na(df_stmGrid_100$state),"state"] <- 0
# save for stm input
write.table(df_stmGrid_100,file=paste0("./data/futStatesGrid/stm100/",filename,".stm"),quote=FALSE,row.names=FALSE,col.names=FALSE,sep=",")
write.table(df_stmGrid_1000,file=paste0("./data/futStatesGrid/stm1000/",filename,".stm"),quote=FALSE,row.names=FALSE,col.names=FALSE,sep=",")
}
|
If $a \neq b$, then the open segment between $a$ and $b$ is uncountable.
|
\documentclass[11pt]{article}
%\usepackage{helvet} %%I personally hate this look, so I disabled it ;)
\renewcommand{\familydefault}{\sfdefault}
\usepackage{hyperref}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{xspace}
\usepackage{algorithmicx}
\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{setspace}
\usepackage{appendix}
\usepackage{xspace}
\usepackage{authblk}
\onehalfspacing
%\usepackage[notablist,nofiglist]{endfloat}
% Add Yield as a pseudocode command
\algnewcommand\algorithmicyield{\textbf{yield}}
\algnewcommand\Yield{\algorithmicyield{} }%
% Add Continue as a pseudocode command
\algnewcommand\algorithmiccontinue{\textbf{continue}}
\algnewcommand\Continue{\algorithmiccontinue{} }%
% Add Break as a pseudocode command
\algnewcommand\algorithmicbreak{\textbf{break}}
\algnewcommand\Break{\algorithmicbreak{} }%
% Non-useless comments
\algrenewcomment[1]{\(\triangleright\) #1}%
% Have a command for vocab words
\newcommand{\vocab}[1]{\textbf{#1}\xspace}
\newcommand{\vg}{{\tt vg}\xspace}
\newcommand{\gcsa}{{\tt GCSA2}\xspace}
\begin{document}
\title{Sequence variation aware references and read mapping with vg: the variation graph toolkit}
\author[1]{Erik Garrison}
\author[2]{Adam Novak}
\author[2]{Glenn Hickey}
\author[2]{Jordan Eizenga}
\author[1]{Jouni Siren}
\author[1]{Eric Dawson}
\author[1]{Will Jones}
\author[3]{Orion Buske}
\author[4]{Mike Lin}
\author[2]{Benedict Paten}
\author[1]{Richard Durbin}
\affil[1]{Wellcome Trust Sanger Institute, Wellcome Genome Campus, Hinxton, Cambridge, United Kingdom}
\affil[2]{UC Santa Cruz Genomics Institute, University of California, Santa Cruz, 1156 High St, Santa Cruz, CA, USA}
\affil[3]{University of Toronto, 686 Bay St, Room 12.9840
Toronto, ON, Canada}
\affil[4]{DNAnexus, Inc. 1975 W El Camino Real, Suite 101
Mountain View, CA, USA}
%\author{Erik Garrison 1, Adam Novak 2, Glenn Hickey 2, Jordan Eizenga 2, Jouni Siren 1, Eric Dawson 1, Will Jones 1, Orion Buske 3, Mike Lin 4, Benedict Paten 2, Richard Durbin 1}
\renewcommand\Authands{ and }
\maketitle
\begin{abstract}
Reference genomes provide a prior to guide our interpretation of DNA sequence data.
However, standard linear reference sequences have a fundamental limitation in that they only represent one version of each locus, whereas
in a population or species there is in general a distribution of related sequences at each locus.
Mapping sequence read data from new individuals to a single linear reference can introduce bias and other problems.
\emph{Variation graphs}, which are bidirectional DNA sequence graphs that capture genetic variation, describe general sequences of interest as walks within the graph.
Here we enable the practical use of variation graphs at human genome scale and allow the representation of alternate genomes in the reference system by building a toolkit of computational methods for the creation, manipulation, and utilization of these structures.
Using generalised compressed suffix array technology we provide an efficient approach to mapping reads onto our graphs.
Our approach generalizes fundamental aspects of resequencing analysis (assembly, alignment, variant calling, and genotyping) to operate on variation graphs.
\end{abstract}
\section{Introduction}
Where genomes are small and sequences from different individuals can be reliably isolated, we can understand variation by assembling whole genomes and then comparing them via whole-genome comparison approaches \cite{mummer} \cite{Paten:2011fva}.
In practice, complete de novo genome assemblies are not cheaply obtainable for large genomes such as \emph{Homo sapiens}, and we require prior information to interpret new sequence data in its correct genomic context.
The current paradigm is to align sequence reads to a single high quality reference genome sequence obtained from one (or a few) closely-related individuals.
While expedient, this approach biases our results towards a reference that may poorly represent alleles present in the sample we obtained our sequence reads from.
There is even likely to be sequence in the new sample that is not present in the reference {cite BGI pangenome paper}.
In principle we would like to align to a genome that is as similar to our sample as possible, ideally a ``personalized'' reference genome \cite{Yuan_2012}, which already incorporates sequence variants present in the individual.
Of course there is a chicken and egg problem in knowing what the variants are before aligning data from a sample, but most differences between any one genome and the reference are shared in the population, so if we can build a structure that contains known shared variation then that could potentially contain most of the correct personalised reference sequence for any individual from the population or species.
The natural computational structure for doing this is the sequence graph.
These have a long history of application to problems which require the representation of multiple genomes or ambiguities in the same structure.
For example, multiple sequence alignments have a natural representation as partially ordered sequence graphs \cite{lee2002POA}.
The variant call format (VCF) \cite{danecek2011}, which is a common data format for describing populations of genomes, does not explicitly define a graph model, but can be understood as defining a partially ordered graph similar to those used in multiple sequence alignment.
The total information available in a shotgun sequencing data set set can be compressed into a string graph, in which single-copy sequences are represented uniquely and repeated sequences unresolvable due to read lengths are collapsed into single entities \cite{myers2005, simpson2010}.
A similar structure which has good scaling properties when applied to the problem of genome assembly is the de Bruijn graph, which records the relationships between unique $k$-mers of a set of sequences with edges that link pairs of $k$-mers for which the suffix of one $k$-mer is the prefix of the next \cite{iqbal2012}.
To serve as a population variation aware reference system, we adopt a general sequence graph structure.
A similar approach has been introduced before for localised genomic regions \cite{prg2015}, but here we extend to a wider range of variation, and provide an implementation in a practical software environment for operating with them at the multi-gigabase scale: \vg.
We demonstrate the use of \vg by constructing a whole human genome graph incorporating all base-pair specific variation from the 1000 Genomes Project \cite{1000g2015} aligning short read sequencing data against it, and reporting genotypes.
\section{Methods}
\subsection{Model}
We define a variation graph to be a graph with embedded paths $G = ( N, E, P )$ comprised of
a set of nodes $N = n_1 \ldots n_M$,
a set of directed edges $E = e_1 \ldots e_L$,
and a set of paths $P = p_1 \ldots p_Q$ which describe the embedding of a set of sequences into the graph.
Each node $n_i$ represents a sequence $seq(n_i)$ which is built from an arbitrary alphabet ${ \cal A }$.
For DNA sequences, we use ${ \cal A } = \{ {\tt A, T, G, C, N} \}$, but in principle the model can be based in any alphabet.
Nodes may be traversed in either the forward ($+$) or reverse direction ($-$), with the sequence being reverse-complemented in the
$-$ direction.
We write $\overline{n_i}$ for the reverse-complement of node $n_i$, so that $seq(n_i) = revcomp(seq(\overline{n_i}))$, and note
that $\overline{\overline{n}} = n$. Below, where we refer to {\em node} in most places we mean an oriented node.
Edges represent links between nodes that can be followed in paths to represent longer sequences.
Edges can be identified with the ordered pairs of (oriented) nodes that they link, so we can write
$e_{i \rightarrow j} = ( n_i, n_j ) $. In fact this defines one strand of an edge. Edges also can be traversed in either forward or
reverse direction, with the reverse strand defined by $\overline{e_{i \rightarrow j}} = ( \overline{n_j}, \overline{n_i} )$.
We define paths as alignments to a walk through the graph. Explicitly, a path is a series of {\em mapping} operations, each
describing the segment of the path derived from a single node, $p = m_1, \ldots, m_{|p|}$. Each mapping $m$ can be written
as $( (n, o), e_i \ldots e_{|m|} )$, where $n$ is the node, $o$ is the zero-offset start position in the node sequence ($0 \le o < |n|$),
and each $e_i$ is an ``edit'' which copies or replaces a segment of the node sequence. In \vg we encode $e$ as $(f, t, s)$
where $f$ is a length in the node (``from length''), $t$ is a length in the derived sequence (``to length''), and $s$ is an optional
replacement literal sequence of length $t$. Edges traversed in a path are implicitly defined by the nodes of neighbouring mappings.
If all the edits are copies then we say that the path is {\em fully embedded} in the graph.
Figure \ref{fig:minimhc} provides a visual explanation of this model using a small fragment of an assembly of MHC haplotypes.
\begin{figure}[t]
\centering
\includegraphics[width=1.0\textwidth]{figures/minimhc}
\caption{\label{fig:minimhc}
A visualization of a fragment of the MHC variation graph.
The graph nodes and edges are written at bottom. The edges flow across the tops of the nodes, which indicates in this visualization that they are on the forward strand of the graph and not inverting.
Paths are described in a matrix above the graph.
The path name (shown at left) is hashed into a space of 8 colors and 766 Unicode characters (emoji) to provide stable and non-overlapping visual motifs for hundreds of paths.
These colored pictographs are used to annotate parts of the graph, in this case the edges are labeled with the paths that cross them.
Visualizations of this type are produced using {\tt vg view -dpn}.
}
\end{figure}
\subsection{Construction}
We can build a trivial graph with a single node and no edges from a linear reference sequence.
A more interesting graph may be generated by a series of align and edit operations.
We first describe our approach to alignment and editing, then summarise a number of interfaces to construct variation graphs using these operations from different types of input information.
\subsubsection{Alignment}
\emph{Alignment} is the process of finding an optimal path to the graph for a new DNA sequence such as a sequencing read.
Our approach to this is to find seed matches by an indexed search process, cluster them if there are multiple nearby seeds, and then perform local dynamic programming alignment of the read into a region of the graph around the seeds.
We discuss how we find seeds below in \ref{sec:GCSA2}.
When it comes to local dynamic programming, we must deal with the issue that \vg supports arbitrary sequence graphs, which may contain cycles representing repeats and inversions.
To avoid the complications introduced by cycles \cite{myers1989}, we transform the local graph region into a directed acyclic graph (DAG), on which we can perform
partial order alignment (POA) \cite{lee2002POA}, which generalizes standard pairwise sequence alignment by considering all possible inbound
positions in the graph in the recursion that derives the score for a new cell.
To transform the local graph into a DAG, we introduce {\tt VG::unfold} and {\tt VG::dagify}.
Unfold duplicates sections of the graph to materialise both the reverse-complement as well as the forward strand of nodes where this is necessary.
Dagify unrolls loops.
Both take a length parameter $k$ with the goal that all sequences up to length $k$ are represented in the resulting graph without cycles.
We keep track of the mappings through both these processes, so that we are able to translate alignments to the transformed graph back into the original one.
Further details are given in the Appendix.
To carry out the partial order alignment, we extended a SIMD-accelerated implementation \cite{zhao2013} of Farrar's striped Smith Waterman (SSW) algorithm \cite{farrar2007}, which we term ``graph striped Smith-Waterman'' \href{https://github.com/ekg/gssw}{GSSW}.
GSSW generalizes all aspects of SSW to operate over sequence DAGs, including affine gap penalties, retains its matrices for traceback, and is around six times faster than a non-SIMD based implementation of POA.
\subsubsection{Editing}
The operation $edit(G, P)$ extends the graph $G$ to include the sequences described by paths $P$, so that they become fully embedded.
If the nodes of the graph have single-base labels, then they are atomic and we only need to add edges and new nodes representing novel sequence.
We walk the mappings of the path through the graph.
We make no changes for matches.
%%%BENEDICT ASKS: Do you really always add novel sequence using single base nodes? Do you not need a compression step to collapse runs of single base nodes only connected to one another contiguously?
For substitutions, and insertions, we add the novel sequence from the path edit as new single base nodes in the graph.
For deletions we add edges between existing nodes in the graph.
To edit a non-atomic graph, where the node labels may be of arbitrary length, we first cut nodes in the paths where we need to add new sequence or edges.
We implement this editing method as \href{https://github.com/vgteam/vg/blob/fbcb6e62/src/vg.cpp#L4846-L4912}{{\tt VG::edit}}, which consumes a set of paths (possibly from alignments) and extends the graph.
\subsubsection{Progressive variation graph construction}
Given a set of alternate genome sequences or fragments of genomes, we can align each sequence in turn and edit the graph to include it.
The resulting graph contains all input sequences as embedded paths.
We implement this technique as the \href{https://github.com/vgteam/vg/blob/fbcb6e62/src/main.cpp#L674-L1248}{multiple sequence/graph aligner {\tt vg msga}}, and have applied it to assemble long sequences from the human MHC as described in section \ref{sec:MHC}.
\subsubsection{Construction from existing population variation data}
Population sequencing projects that have inferred variation from alignments to a linear reference sequence, such as the 1000 Genomes Project, typically generate a file of variants in VCF format.
First, we convert the variants in the VCF file into mappings to a graph made of only the reference sequence.
We then edit this graph using the mappings, incorporating the sequences given by the alleles in the VCF record into the graph.
We use this approach below in results section \ref{sec:1000g}.
\subsubsection{Construction from a \emph{de novo} assembly}
Almost all \emph{de novo} assembly algorithms build a sequence graph internally to represent ambiguity in the ways to connect together sequence reads.
They assemble a graph by overlapping reads or their $k$-mers, then generate contigs as non-branching regions of this graph after removing likely sequencing errors.
Provided that an assembler implements export of its graph structure, we can build a variation graph from this intermediate representation.
In \vg we support the \href{https://github.com/pmelsted/GFA-spec}{graphical fragment assembly (GFA) format}, which is a community standard for serialization of bidirectional sequence graphs from assemblers. There are some complexities in transitioning from an overlap graph formalism to the blunt-end-join model used in \vg, described further in the appendix.
\subsection{Compressed representation and indexing}
Our core implementation of variation graphs, \href{https://github.com/vgteam/vg/blob/fbcb6e62/src/vg.hpp#L196-L1146}{{\tt vg::VG}}, is optimized for efficient runtime for editing and transformation operations.
This requires that we must store a dynamic version of the graph, which we do using a hash structure that is optimized for run time and not memory overhead.
To load the entire human genome graph with common variation into main memory would require more than 300GB of RAM with this representation, but editing and alignment operations are local and do not require the whole graph to be available in memory at once.
The solution we have adopted is to also implement a succinct representation \footnote{Representations are termed ``succinct'' when they occupy only a small constant factor more space than that required to store a compressed version of their source data.} of a variation graph, called \href{https://github.com/vgteam/xg}{{\tt xg}}, that is static but allows efficient random access, using rank/select dictionaries and other data structures from the Succinct Data Structures Library (SDSL) \cite{sdsl2014}.
We then provide code to take subgraphs out of {\tt xg} and transform them into our mutable representation for alignment and editing. See the Appendix for details.
\subsection{Sequence query matching: (\gcsa)}
\label{sec:GCSA2}
In order to find seed matches for alignment to the graph, we introduce a second index that enables very rapid discovery of maximal exact substring matches.
Maximal exact matches (MEMs) are matches between a query and a reference system that cannot be extended in either direction along the query while still matching some sequence in the reference system.
Super-maximal exact matches (SMEMs) are MEMs that are not contained by any other MEM.
For linear sequences, the FM-index \cite{fmindex2000, fmindex2005} provides the required functionality in conjunction with the Burrows-Wheeler transform (BWT)\cite{burrowswheeler1994}, as implemented for example in {\tt bwa mem} \cite{li2013bwamem}.
As in {\tt bwa mem}, we use SMEMs to seed local alignment of reads, and to do this we use a generalisation of the BWT and FM-index to sequence graphs.
Several such generalizations have been developed in recent years.
The generalized compressed suffix array (GCSA) allows sequence queries in populations of genomes represented in a single multiple sequence alignment, but is limited to directed acyclic representations of these collections and requires heuristic optimization to build whole genome indexes \cite{siren2011indexing, siren2014indexing}.
The hierarchical graph FM index (HGFM) implemented in \href{https://github.com/infphilo/hisat2}{HISAT2} allows direct mapping of RNA sequencing reads against a transcriptome model including small sequence variants such as SNPs and indels \cite{kim2015hisat}.
In the HGFM, a global GFM represents the general population, while tens of thousands of local GFMs represent denser variation on a small scale.
Similarly to GCSA, HGFM requires the input graph be acyclic.
Recently, Siren has developed \href{https://github.com/jltsiren/gcsa2}{GCSA2}, which generalizes the GCSA/GFM model to use positionally-labeled de Bruijn graphs as input \cite{siren2016gcsa2}, including cyclic graphs, and provides a near complete generalization of the FM-index to arbitrary sequence graphs.
We implement global alignment in \vg by transforming the variation graph into a de Bruijn graph effectively with $k=128$ ,with positional labels that indicate where in the source graph a particular kmer starts and ends. \gcsa can then generate a GCSA from this labeled de Bruijn graph, which we use to find SMEMs for query sequences in time effectively proportional to the query length and independent of the graph size.
To build the $k=128$ de Bruijn graph efficiently, we initially generate kmers with $k=16$ labelled by their origin in the \vg graph. GCSA2 then undertakes three rounds of prefix doubling, wherein it uses the positional information in the input de Bruijn graph to double the order of the graph, to increase to $k=128$. In certain circumstances where there are repeated patterns of dense variants in the graph, the path complexity explodes exponentially, preventing practical enumeration of the de Bruijn graph. To avoid this, we
prune edges from the \vg graph which induce more than a small number of combinatorial bifurcations (typically 4) within the initial 16bp kmers, and remove any extremely short subgraphs that result from this destructive masking operation. This transformation preserves the coordinate system of the graph, allowing us to use it as the basis for seed generation against the unpruned graph.
\subsection{Global alignment and read set mapping}
Given a set of sequencing reads, we %TODO: I assume each read is mapped independently, but didn't want to fill in here
The first step is to derive the SMEMs for a query relative to our reference system.
SMEMs that are high-abundance may be filtered out by counting the number of occurrences in the graph using \href{https://github.com/jltsiren/gcsa2/releases/tag/v0.6}{\gcsa's $count$ function}, which uses techniques from document counting in compressed indexes to generalize the range counting that is possible in a compressed suffix array to GCSA.
This allows us to avoid SMEMs that have hundreds of thousands of hits in our index without extracting the specific hits from \gcsa.
We then cluster these SMEMs by exploiting an approximate distance metric on the graph.
If our node id space is locally ordered, then nodes with nearby ids are likely to lie close together in the graph.
We set a parameter to limit the distance at which we cluster, which is usually small (in the range of 5-10 when we have built our graph with a maximum node size of 32).
Now, for each cluster we extract the subgraph of the cluster and a small neighborhood around it from {\tt xg}, and locally align against it using unfolding, kDAGification, and GSSW alignment.
We sort the hits by their GSSW alignment score, and return either the top hit or all hits if multi-mapping results are desired.
Paired end reads may be handled using the approximate locality metric based on node ids.
Where one but not both fragments of a read pair map, we attempt to rescue the failed mate by aligning it in a window around the successful mapping.
For very long reads, where the local dynamic programming can become prohibitively expensive, we break the reads into ``bands'' of a fixed width $w$ with overlap between successive bands of $w/2$.
We then align these bands independently, trim the overlaps from the alignments, and concatenate the results.
This allows \vg to map reads of arbitrary length, and is used as a core component in the long read progressive assembler {\tt vg msga}.
\subsection{Storage and exchange of graph read alignments: GAM}
{introduce GAM}
\section{Results}
% TODO experiments
% 1) repeat yeast alignment score plot, this time using a 2d density plot to avoid overplotting issues and also with descriptive summary statistics: correlation in quality, mapping quality
% 2) scale this same experiment up to the human genome (use this to demonstrate scaling properties of the process)
% 3) simulation experiment: performance of alignment measured by exact match rate between alignments made at different levels of error and with/without variation in the reference system
% Figures:
% score correlation: array of 2D score/score plots
% simulation: truth exact match rate vs. read error rate vs. linear or graph
We have implemented \vg in C++11 under an open, distributed software development model, available from \href{https://github.com/vgteam/vg}{\tt https://github.com/vgteam/vg}. Further details are given in the appendix.
Here we briefly describe several results demonstrating the functionality of \vg.
All experiments were carried out on a dedicated compute node with 256 gigabytes of RAM and 32 2.4GHz AMD Opteron 6378 processors.
\subsection{The 1000 Genomes Project graph}
\label{sec:1000g}
The final phase of the 1000 Genomes Project has produced a data set describing the diploid genome sequences of 2504 humans \cite{1000g2015}.
We transformed the sequence DAG described by the project's released VCF and the GRCh37 reference into a variation graph in 15.5 hours using 32 threads, breaking the build into smaller pieces at particular parts of the reference and concatenating the resulting graphs.
The resulting graph, which we call 1000GP below, uses 4.76 GB when serialized to disk, and contains 3.181 Gbp of sequence, which is exactly equivalent to the length of the input reference plus the length of the novel alleles in the VCF file.
We indexed the 1000GP graph in two phases.
First, we built the {\tt xg} index using a single-threaded process in 1.5 hours, with the resulting index taking 31.6 GB both on disk and when loaded into RAM for use by \vg.
The initial kmer generation step of \gcsa indexing took approximately 24 hours of compute time, with the final indexing step taking 32.9 hours of wall clock time and 105.3 hours of CPU time.
This process required 100GB of RAM at peak, but reduces memory usage by implementing most operations using streaming disk-backed sorts.
As such, it required several terabytes of I/O during indexing.
The final GCSA2 index takes 35.9 GB space both on disk and in RAM.
Using these indexes, we aligned one million 150bp reads from an Illumina HiSeq X read set of NA12878 against the 1000GP graph.
This requires 60 seconds to load the indexes, 67G of RAM, and approximately 145 seconds to align the reads, with 99.36\% of reads being mapped, and resulting in a 160 MB
GAM file. This corresponds to approximately 24 hours of compute time on a single 32-processor server to map a 30x genome data set, resulting in an approximately 100 GB GAM file. XXX CHECK. IDEALLY ALIGN A WHOLE DATA SET.
%%BENEDICT: Yes, this really needs to be whole genome.
\subsection{An overlap assembly of the MHC}
\label{sec:MHC}
In many contexts we have finished genomes, but not an assembly graph or VCF file suitable for direct transformation into a variation graph.
To support the use of \vg in these contexts,
we developed a long read assembler \href{https://github.com/vgteam/vg/wiki/Long-read-assemblies-using-vg-msga}{\tt vg msga}.
This method takes a starting sequence or graph and progressively aligns new sequences to the graph, editing the graph to embed each new sequence as a path until all sequences have been included.
The process is deterministic and complete in that each new sequence will generate an alignment.
New sequences which do not map become new disjoint subgraphs, while homologs will be compressed against each other in the resulting graph.
We applied this method to the nine GRCh38 alternate haplotype sequences for the entire MHC, each between 4.6 and 5 megabases.
We begin with the primary reference sequence and add GI568335879, GI568335954, GI568335976, GI568335986, GI568335989, GI568335992, GI568335994, and GI568335997 in turn.
The process requires around an hour on our test machine, producing a graph that serializes to 18 MB on disk including the original sequences as paths, representing 10.8 Mbp of DNA in comparison with a total sequence length of 38.2 Mbp in the combined input sequences.
Figure \ref{fig:DRB1-3123} shows a rendering of a graph generated by {\tt vg msga} using the sequences of one of the MHC genes (DRB1-3123).
% actual counts: 38160773bp, 10802468bp
\begin{figure}[t]
\centering
\includegraphics[width=1.0\textwidth]{figures/DRB1-3123}
\caption{\label{fig:DRB1-3123}
A rendering of a portion of the MHC graph assembled by {\tt vg msga} around the DRB1-3123 gene.
Node labels have been omitted. The graph rendering required enhancement to make the structure clear at this zoom level, which results in the embossed effect.
}
\end{figure}
\section{Discussion and future plans}
%%BENEDICT: This is all good, but needs a little work to make it consistent with the other paper and to recognise the updates we have added to vg to find super/ultrabubbles and the work we've done with Mike Lin on whole genome. I also assume you're going to add in the yeast experiments, so this may change the discussion.
Presently \vg provides interfaces to the basic functions required for resequencing analysis using variation graph references.
We can construct, import, visualize, assemble, examine, modify, index, and query the graph and associated indexes using tools in \vg.
We can efficiently map new sequence reads to the reference using succinct indexes of the graph and its sequence space, and finally we can describe variation between a new sample and an arbitrary reference embedded as a path in the graph.
This framework provides the basis for future improvements and experimentation.
However, the project currently has a number of weak points which we would like to improve.
For one, the variant calling method is rudimentary and focused on determining variants against single nodes in the graph, which works for detecting SNPs and small indels.
We plan to implement a calling and genotyping approach based on superbubbles in the graph.
To do this we can employ recent work which develops a linear-time algorithm for the detection of superbubbles in the graph \cite{brankovic2016linear}.
After detecting superbubbles, we plan to apply haplotype-based variant calling approaches \cite{garrison2012haplotype} to the reads overlapping the superbubble.
This approach will be generic and handle all classes of variation, both small (SNPs and indels) and large (SVs).
Furthermore, we would like to utilize recent work generalizing the PBWT to graphs in the genotyping process.
This generalized system, gPBWT, provides the same efficient haplotype matching and counting queries possible in PBWT, but on a variation graph.
It should also be possible to apply this to reduce the complexity of the indexing process by generating a deBruijn graph for \gcsa that only contains kmers we have observed previously.
In anticipation of this, we have attempted a modification of the indexing process that only indexes the embedded paths in the graph, but have not completely debugged and tested it.
We would like to complete several experiments to validate the performance of the method in and end-to-end alignment and variant calling process.
First, we plan to complete a whole genome analysis of NA12878 and other individuals in the platinum genomes pedigree.
This is currently not possible as the calling method is localized to small regions of the graph, and we have not developed efficient techniques to extract reads overlapping a particular region.
Similarly, we plan to use sequencing data from the \href{http://www.ncbi.nlm.nih.gov/assembly/706168/}{CHM1 and CHM13} cell lines to construct a synthetic pseudodiploid.
The high quality of the \emph{de novo} assemblies for these cell lines (which are based on deep PacBio long-read sequencing) will allow us to evaluate the variation calling processes in a completely generic way within the graph itself.
We will use the calling process to generate a sample graph based on short reads and the 1000GP reference, then evaluate our results by threading the assembled contigs for CHM1 and CHM13 through the graph and counting the path divergences between them and our estimated sample graph.
In standard practice, we ignore the haplotype information in the VCF file and build the graph so as to allow all possible recombinations between successive variant loci.
This haplotype-agnostic approach has advantages of simplicity and ubiquity.
Even data providers with closed access policies often release information about the variants discovered in their cohorts, which provides a valuable resource when examining new individuals even if we do not have the complete haplotype information of the source genomes \cite{exac2015}.
However, there are valuable uses for the haplotypes, and storing this haplotype information efficiently is an area of active work among other collaborators on \vg are exploring generalizations of the positional Burrows Wheeler Transform (PBWT) \cite{durbin2014}.\footnote{Adam Novak, a collaborator on the \vg project, has implemented a generalization of the PBWT to graphs in xg. This generalization (gPBWT) is designed for efficient haplotype matching and frequency queries, but does not provide efficient positional queries.}
A large number of organisms lack complete reference genomes, or have such high rates of heterozygosity that generating linear versions of their genomes may be practically impossible.
We plan to apply \vg to these contexts by generating assembly graphs with other methods and then using these graphs as a reference for resequencing analysis.
This would allow whole genome resequencing analysis in previously-inaccessible contexts, such as in pooled sequencing of organisms without the aid of a finished reference sequence.
Validating these approaches will require the extension of methods for population structure and association analysis to the graph, which will be a difficult but essential step in the generalization of genomics from linear to graphical systems.
\bibliography{references}{}
\bibliographystyle{plain}
\newpage
\appendix
\section{Appendix}
We implement efficient local alignment to variation graphs by developing a SIMD-accelerated\footnote{Single input multiple data (SIMD) instructions allow vectorized mathematical operations in a single machine instruction, and can be used to greatly speed up algorithms which may be implemented in terms of operations on vectors.} string to graph alignment algorithm. We then enable alignment against completely generic graphs by a transformation process that projects a cyclic and bidirectional graph into an acyclic, unidirectional (single-stranded) graph which preserves the sequence space of the original graph up to a given length.
\subsubsection{Background}
As our sequence graphs are models of regular languages, they can be considered equivalent to regular expressions, so we understand this result to hold for variation graphs as well.
By transforming our graph from a cyclic to acyclic format, we produce a performant implementation of the limited case of alignment between strings and regular languages. However, we have not implemented the general case of alignment between regular languages, and know of no available software methods that implement it.
\subsubsection{SIMD-accelerated local alignment}
%%Commenting this out: We implement a
We interface with GSSW by \href{https://github.com/vgteam/vg/blob/fbcb6e62/src/vg.cpp#L6461-L6532}{transforming our graph into the internal graph used by GSSW}.
This graph is acyclic and only represents a single strand of the DNA.
In order to align against completely general, bidirectional sequence graphs (such as those with cycles and inversions), we can apply several transformations to the graph first to generate a DAG with the property that we can find any sequence up to a given length $k$ from our source graph in it.
These two operations are $unfold$, which expands the graph to include its reverse complement where accessible via an inversion, and $kDAGify$, which unrolls strongly connected components of the graph ``far enough'' that we are guaranteed to be able to find any sequence of length $k$ in the source graph in the unrolled one.
This allows us to align any sequence of up to length $k$ against a completely general variation graph.
Through these steps we retain a mapping from old node ids to new ones, which we will use to project alignments to the transformed graph back into our base coordinate space.
\subsubsection{Unfolding}
Every node has an implicit default orientation (see Graph Representation below) so that it is possible to determine edges that cause an inversion, i.e. those which connect between a forward and a reverse complement node orientation.
In \href{https://github.com/vgteam/vg/blob/fbcb6e62/src/vg.cpp#L8289-L8400}{{\tt VG::unfold}} we use a breadth first search starting at every inverting edge in the graph to explore the reverse complemented portions of the graph that we reach in some length $k$ from the inverting edge.
We then copy this subgraph, take its reverse complement, and replace the inverting edges connecting it to the forward strand of the graph with non-inverting ones.
If $k$ is greater than any length in our graph, then we will duplicate the entire reverse complement of the graph on the forward strand, effectively doubling the size of the graph if we have any inversions in it, as shown in figure \ref{fig:unfold}.
\begin{figure}[t]
\centering
\includegraphics[width=1.0\textwidth]{figures/unfold}
\caption{\label{fig:unfold}
Illustration of the unfolding process. The starting graph (A) has an inverting edge leading from the forward to reverse strand of node 2.
In (B) we unroll the graph with $k$ greater than the length of the graph, which materializes the implied reverse strand as sequence on the forward strand of new nodes.
}
\end{figure}
\subsubsection{kDAG-ification}
Variation graphs may have cycles.
These are useful as compact representations of copy number variable regions, and arise naturally in the process of genome assembly.
However, partial order alignment cannot handle these structures, and so we must convert them into an approximately equivalent acyclic graph in order to align with GSSW.
To do so, we unroll cyclic structures by copying their internal nodes an appropriate number of times to allow a given query length to align through the unrolled version of the component.
We first detect all strongly connected components by using a \href{https://github.com/vgteam/vg/blob/fbcb6e62/src/vg.cpp#L3508-L3552}{recursion-free implementation} of Tarjan's strongly connected components algorithm \cite{tarjan1972depth}.
Then, we copy each strongly connected component and its internal edges into a new graph.
We greedily break edges in this graph that introduce cycles.
Next we k-DAGify the component progressively copying the base component and for each edge between nodes in the component, connecting from the source node in the previous copy to the target node in the current copy.
We use dynamic programming to track the minimum distance back through the graph to a root node outside the component at each step.
When this reaches our target $k$, we stop unrolling, and add the expanded component back into the graph by reconnecting it with its original neighborhood.
For each copy of a node in the DAG-ified component we copy all of its inbound and outbound edges where the other end of the edge lies outside the strongly connected component.
The resulting graph is acyclic and supports queries up to length $k$ on the original graph provided the translation between the new graph and the source one.
Figure \ref{fig:kdagify} provides a visual description of the process.
\begin{figure}[t]
\centering
\includegraphics[width=1.0\textwidth]{figures/kdagify}
\caption{\label{fig:kdagify}
Illustration of the unrolling process. The starting graph (A) and a representation without sequences or sides to clarify the underlying structure (B).
In (C) we have unrolled one step ($k = 2$). In (D), $k = 4$, (E) $k = 10$, and (F) $k = 25$.
}
\end{figure}
\subsection{Succinct graph representation ({\tt xg})}
When using a variation graph as a reference system, we are unlikely to need to modify it.
As such we can compress it into a system that provides efficient access to important aspects of the graph.
Specifically, we care about the node and edge structure of the graph and queries that allow us to extract and seek to positions in embedded paths.
We would like to be able to query a part of the graph corresponding to a particular region of a chromosome in a reference path embedded in the graph.
Similarly, if we find an exact match on the graph using \gcsa, we would like to load that region of the graph into memory for efficient local alignment.
We implement a succinct representation of the graph in the \href{https://github.com/vgteam/xg}{{\tt xg}} library.
We do so using data structures from \href{https://github.com/simongog/sdsl-lite}{SDSL-lite}, which provides \href{https://en.wikipedia.org/wiki/Succinct_data_structure#Succinct_dictionaries}{rank/select dictionaries} that we use to navigate compressed vectors that record the labels and id space of the nodes, edges, and paths of the graph \cite{okanohara2007}.
Our model is summarized visually in Figure \ref{fig:xg}.
\subsubsection{Storing the nodes of the graph}
We first concatenate node labels to generate the node sequence vector $V_s = seq(n_1) + seq(n_2) + \ldots + seq(n_{|N|})$.
We store this as a compressed integer vector using the minimum required number of bits per base (which is typically 3 bits, as we need to represent ${\tt \{ A, T, G, C, N} \}$).
In a second bit vector $V_b : |V_b| = |V_s|$ (the node bit vector), we write 1 at the position corresponding to the first base in every node in $V_s$, and write a 0 for all internal bases.
We then store the node ids in the wavelet tree $V_i$ \cite{grossi2003high}, ordered by their appearance in $V_s$.
By building a rank/select dictionary from $V_b$, we can map from positions in the sequence vector to node ids, and from node ids to ranges in the sequence vector.
For example, we can look up the sequence of a particular node by its id in several steps.
We first query the node id wavelet tree to obtain the rank $n$ of a particular node by its id $i$: $n = rank_{i}(V_i, 1)$.
Then, $select_1(V_b, n)$ will return the position of the start of the $n$th node in the node sequence vector.
In reverse, we can use $rank_1(V_s, n)$ to map from positions in $V_s$ to node ranks, and then find the node id as $V_i[n]$.
Recording the node identifiers in $V_i$ allows us to work with non-contiguous node id spaces, but internally within {\tt xg}, we identify nodes by their rank in $V_s$ and $V_i$.
\subsubsection{A succinct bidirectional encoding of the edges of the graph}
Variation graphs which we are likely to use as a reference system tend to have few nodes with a high in or out degree.
We rely on this tendency to generate a bidirectional index of edges that is optimized for sparsely-connected graphs.
We store the edges of graph, $E$, using a pair of compressed integer vectors $F_e$ and $T_e$.
In each vector, we record information about the edges of each node in a single range of the vector.
We record the ranges of these vectors corresponding to particular nodes by marking bit vectors $F_b$ and $T_b$.
We record the edges in the forward direction in $F_e$.
For each $n_i \in N$ we write its own id into $F_e$.
Then for each edge from that node ($\forall j : e_{n_i \rightarrow j}$) we record the id of the node it goes to ($j$) in a block after the entry for $n_i$.
We record the position of the node blocks in $F_e$ in $F_b$ by marking the node entry with a 1, and leaving edge entries as 0.
$T_e$ and $T_b$ follow the same pattern, but instead of recording the edges from a node, we record the edges to it.
This bidirectional structure allows for fast traversal of the graph.
Note that $|F_e| = |T_e| = |N| + |E|$.
In other words, these vectors encode one entry for each node and edge in the graph.
We can exploit this property to provide a unique rank-based identifier for every node and edge in the entity space of the graph, which is useful for marking subgraphs with particular properties.
We use such a pattern to record which node strand each edge starts and ends on.
Four additional bit vectors mark whether an edge starts or ends on the forward or reverse strand: $|I_f| = |I_t| = |J_f| = |J_t| = |N| + |E|$.
We first mark all positions corresponding to the node block starts in $F_e$ as 0.
This padding ensures that we are working in the graph's entity space as described by $F_e$.
In $I_f$ we record if an edge in $F_e$ begins on the reverse strand (1) or not (0), and in $J_f$ we do the some for edges as described in $T_e$.
In $I_t$ we store if an edge in $F_e$ goes to the reverse strand (1) or not (0), while $J_t$ lets us do the some for edges as ordered in $T_e$.
In directed graphs these are typically sparse and easily compressible, but they are necessary to represent completely generic graphs.
\subsubsection{Compact path storage allowing positional queries}
In {\tt xg} we develop a compact representation of embedded paths that allows them to be used for $O(1)$ time positional queries.
For each path $p_j$ we store a bit vector $C_p^j$ with the same length as our forward edge vector $F_e$.
We mark 1 in this vector for each element in the graph which occurs in the path at its corresponding position in $F_e$, and a 0 otherwise.
We record the positions of the mappings ($m_1, \ldots, m_{|p_j|}$) of $p_j$ in an integer vector $M_p^j$, where we record the node ranks of the nodes the path traverses in $V_s$.
The strand of each mapping $m$ is marked in a bit vector $S_p^j$ of the same length as $M_p^j$.
We mark 0 if the mapping traverses the node's forward strand and 1 if it traverses the reverse.
Finally, we build a positional index of the path that allows us to determine what node strand of the path is at a given position.
We cache the start position of each node relative to the beginning of the path in $L_p^j : |L_p^j| = |M_p^j|$.
The bit vector $B_p^j$ has the same length as the sequence represented by the path.
For each position in the path where we begin a node, we mark a 1, and leave 0 otherwise.
We can now determine the node at a given position $x$ in the path as $M_p^j[rank_1(B_p^j, x)]$.
Furthermore, we can efficiently determine where in a particular path a node is using the $L_p^j$ vector.
This representation is not lightweight, and does not allow the storage of many paths because it requires $O(\sum_{\forall p \in P}{|p|})$ space.
However, it is an essential component of the index if we wish to query the graph based on the coordinate system of an existing linear reference sequence.
\begin{figure}[t]
\centering
\includegraphics[width=1.0\textwidth]{figures/xg}
\caption{\label{fig:xg}
A sketch of important components of the {\tt xg} graph index.
The source graph is at the top of the figure.
A single path is defined by the nodes and edges in black.
For simplicity we omit the edge type vectors and the traversal orientation vector as in this directed acyclic graph they would be marked as 0.
}
\end{figure}
\section{Implementation}
%%TODO: Make the following a complete sentence!
Dependencies on \href{}{xg}, \href{}{GCSA2}, and various libraries including \href{}{SDSL}.
Protobuf for serialisation onto disk.
\subsection{Software development and continuous integration testing}
All features of \vg are validated after every update to the source repository using \href{https://travis-ci.org/vgteam/vg}{continuous integration software validation approaches}.
As such, basic tests demonstrate the desired functionality for each feature, in some cases using a programmatic proof.
For example, we use kmer matching to verify that the kmer space of a graph is equivalent before and after unrolling and kDAGification.
As of this writing, we have implemented 228 tests validating the functionality of the system.
\end{document}
|
corollary Jordan_inside_outside: fixes c :: "real \<Rightarrow> complex" assumes "simple_path c" "pathfinish c = pathstart c" shows "inside(path_image c) \<noteq> {} \<and> open(inside(path_image c)) \<and> connected(inside(path_image c)) \<and> outside(path_image c) \<noteq> {} \<and> open(outside(path_image c)) \<and> connected(outside(path_image c)) \<and> bounded(inside(path_image c)) \<and> \<not> bounded(outside(path_image c)) \<and> inside(path_image c) \<inter> outside(path_image c) = {} \<and> inside(path_image c) \<union> outside(path_image c) = - path_image c \<and> frontier(inside(path_image c)) = path_image c \<and> frontier(outside(path_image c)) = path_image c"
|
Formal statement is: lemma metric_LIM_imp_LIM: fixes l :: "'a::metric_space" and m :: "'b::metric_space" assumes f: "f \<midarrow>a\<rightarrow> l" and le: "\<And>x. x \<noteq> a \<Longrightarrow> dist (g x) m \<le> dist (f x) l" shows "g \<midarrow>a\<rightarrow> m" Informal statement is: If $f$ converges to $l$ and $g$ is closer to $m$ than $f$ is to $l$, then $g$ converges to $m$.
|
(* SLOT, a formally verified model-checker
Copyright (C) 2019-2021 0k2
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*)
(** * Ensembles that can be deconstructed one element at a time
*)
From Coq Require Import
List
Lia.
Import ListNotations.
From SLOT Require Import
Foundations
Commutativity
Properties
Tactics.
From Hammer Require Import
Tactics.
Class Generator TE g :=
{ gen_step : g -> option (g * TE) -> Prop
}.
Open Scope slot_scope.
Notation "A '~~>' B & C" := (gen_step A (Some (B, C))) (at level 20) : slot_scope.
Notation "A '~~>x'" := (gen_step A None) (at level 20) : slot_scope.
Section GenEnsemble.
(** Generator as an ensemble *)
Context {TE G : Type} `{Generator TE G}.
Inductive GenEnsemble (g : G) : @TraceEnsemble TE :=
| gen_ens_nil :
g ~~>x ->
GenEnsemble g []
| gen_ens_cons : forall g' te t,
g ~~> g' & te ->
GenEnsemble g' t ->
GenEnsemble g (te :: t).
End GenEnsemble.
Section gen_commutativity.
Context {TE} Gen `{Generator (ProcessEvent TE) Gen}.
Definition different_processes {Evt} (te1 te2 : ProcessEvent Evt) :=
match te1, te2 with
pid1 @ _, pid2 @ _ => pid1 <> pid2
end.
Definition generator_events_commute :=
forall g g' g'' te1 te2,
different_processes te1 te2 ->
g ~~> g' & te1 ->
g' ~~> g'' & te2 ->
exists g_,
g ~~> g_ & te2 /\ g_ ~~> g'' & te1.
End gen_commutativity.
Section list_defn.
Context (A : Type).
Let G := list A.
Inductive ListGenStep : G -> option (G * A) -> Prop :=
| lgen_nil :
ListGenStep [] None
| lgen_cons : forall te t,
ListGenStep (te :: t) (Some (t, te)).
Global Instance listGenerator : Generator A G :=
{ gen_step := ListGenStep }.
Lemma list_gen_correct : forall l l',
GenEnsemble l l' ->
l = l'.
Proof.
intros.
induction H.
- now inversion H.
- subst. now inversion_clear H.
Qed.
End list_defn.
Section process.
Section defn.
Context {Request : Type} {Reply : Request -> Type}.
Let TE := IOp Request Reply.
Let t := @Program Request Reply.
Definition ThreadGenStep (gen : t) (next : option (t * TE)) : Prop :=
match gen with
| p_dead =>
next = None
| p_cont req cont =>
exists (ret : Reply req),
next = Some (cont ret, ret <~ req)
end.
Global Instance processGen : Generator TE t :=
{ gen_step := ThreadGenStep }.
End defn.
Section tests.
Let Req := bool.
Let Rep req :=
match req with
| true => nat
| false => bool
end.
Let my_prog : @Program Req Rep :=
do x <- true;
match x with
| 0 =>
done false
| _ =>
done true
end.
Goal forall t,
GenEnsemble my_prog t ->
exists x y z,
t = [0 <~ true; x <~ false] \/
t = [S y <~ true; z <~ true].
Proof.
intros. subst my_prog. simpl.
sauto.
Qed.
End tests.
End process.
Section singleton_process.
Context {Gen State Event} `{StateSpace State (ProcessEvent Event)} `{Generator Event Gen}.
Record SingletonProcess :=
singleton_process { _ : Gen }.
Inductive SingletonStep : SingletonProcess -> option (SingletonProcess * (ProcessEvent Event)) -> Prop :=
| wrs_nil : forall g,
g ~~>x ->
SingletonStep (singleton_process g) None
| wrp_cons : forall g g' evt,
g ~~> g' & evt ->
SingletonStep (singleton_process g) (Some (singleton_process g', 0 @ evt)).
Global Instance singletonGen : Generator (ProcessEvent Event) SingletonProcess :=
{ gen_step := SingletonStep }.
Lemma singleton_gen_comm :
generator_events_commute SingletonProcess.
Proof.
intros g g' g'' te1 te2 Hpids Hg Hg'.
exfalso.
inversion Hg; inversion Hg'; subst.
sauto.
Qed.
End singleton_process.
Hint Resolve singleton_gen_comm : slot.
Section parallel_defn.
Context {TE G__l G__r : Type} `{Generator TE G__l} `{Generator (ProcessEvent TE) G__r}.
Record Parallel :=
parallel
{ gp_l : G__l;
gp_r : G__r
}.
Inductive ParallelStep : Parallel -> option (Parallel * (ProcessEvent TE)) -> Prop :=
| g_left : forall te g__l g__l' g__r,
g__l ~~> g__l' & te ->
ParallelStep (parallel g__l g__r) (Some (parallel g__l' g__r, 0 @ te))
| g_right : forall te pid g__l g__r g__r',
g__r ~~> g__r' & (pid @ te) ->
ParallelStep (parallel g__l g__r) (Some (parallel g__l g__r', S pid @ te))
| g_nil : forall g__l g__r,
g__l ~~>x ->
g__r ~~>x ->
ParallelStep (parallel g__l g__r) None.
Global Instance genPairGen : Generator (ProcessEvent TE) Parallel :=
{ gen_step := ParallelStep }.
End parallel_defn.
Infix "<||>" := parallel (right associativity, at level 101) : slot_scope.
Notation "[| x |]" := (singleton_process x) : slot_scope.
Notation "[| x ; .. ; y ; z |]" := (parallel x (.. (parallel y (singleton_process z)) ..)) : slot_scope.
Section parallel_tests.
(* Check that all interleavings created by the ensemble are valid: *)
Goal forall t,
GenEnsemble [| [1; 2]; [3] |] t ->
t = [0 @ 1; 0 @ 2; 1 @ 3] \/
t = [0 @ 1; 1 @ 3; 0 @ 2] \/
t = [1 @ 3; 0 @ 1; 0 @ 2].
Proof.
intros. sauto.
Qed.
(* Check that it creates every interleaving: *)
Goal GenEnsemble [| [1; 2]; [3] |] [0 @ 1; 0 @ 2; 1 @ 3].
Proof.
constructor 2 with (g' := [| [2]; [3] |]).
- sauto.
- constructor 2 with (g' := [| []; [3] |]); sauto.
Qed.
Goal GenEnsemble [| [1; 2]; [3] |] [0 @ 1; 1 @ 3; 0 @ 2].
Proof.
constructor 2 with (g' := [| [2]; [3] |]).
- sauto.
- constructor 2 with (g' := [| [2] ; [] |] ); sauto.
Qed.
Goal GenEnsemble [| [1; 2] ; [3] |] [1 @ 3; 0 @ 1; 0 @ 2].
Proof.
constructor 2 with (g' := [| [1; 2] ; [] |]).
- sauto.
- constructor 2 with (g' := [| [2] ; [] |]); sauto.
Qed.
Goal forall t,
GenEnsemble [| [3] ; [1; 2] |] t ->
t = [1 @ 1; 1 @ 2; 0 @ 3] \/
t = [1 @ 1; 0 @ 3; 1 @ 2] \/
t = [0 @ 3; 1 @ 1; 1 @ 2].
Proof.
intros. sauto.
Qed.
(* Test interleavings of larger system *)
Goal forall t,
GenEnsemble [| [1; 2]; [3; 4] |] t ->
t = [0 @ 1; 0 @ 2; 1 @ 3; 1 @ 4] \/
t = [0 @ 1; 1 @ 3; 0 @ 2; 1 @ 4] \/
t = [0 @ 1; 1 @ 3; 1 @ 4; 0 @ 2] \/
t = [1 @ 3; 0 @ 1; 0 @ 2; 1 @ 4] \/
t = [1 @ 3; 0 @ 1; 1 @ 4; 0 @ 2] \/
t = [1 @ 3; 1 @ 4; 0 @ 1; 0 @ 2].
Proof.
intros. sauto.
Qed.
(* Test interleavings of a system with 3 processes *)
Goal forall t,
GenEnsemble [| [0]; [1]; [2] |] t ->
t = [0 @ 0; 1 @ 1; 2 @ 2] \/
t = [0 @ 0; 2 @ 2; 1 @ 1] \/
t = [1 @ 1; 0 @ 0; 2 @ 2] \/
t = [1 @ 1; 2 @ 2; 0 @ 0] \/
t = [2 @ 2; 1 @ 1; 0 @ 0] \/
t = [2 @ 2; 0 @ 0; 1 @ 1].
Proof.
intros. sauto.
Qed.
End parallel_tests.
From SLOT Require Import
Properties.
From Coq Require Import
Classical_Prop.
Section optimize.
Context {Gen State Event : Type}.
Let TE := (ProcessEvent Event).
Context `{Hssp : StateSpace State TE} `{Hgen : Generator TE Gen}.
Definition can_follow (te1 te2 : TE) : Prop :=
let (pid1, _) := te1 in
let (pid2, _) := te2 in
pid1 <= pid2 \/ not (events_commute te1 te2).
Inductive GenEnsembleOpt (g : Gen) : @TraceEnsemble TE :=
| og_ens_nil :
g ~~>x ->
GenEnsembleOpt g []
| og_ens_first : forall g' te,
g ~~> g' & te ->
g' ~~>x ->
GenEnsembleOpt g [te]
| og_ens_cons : forall g' te te' t,
g ~~> g' & te ->
can_follow te te' ->
GenEnsembleOpt g' (te' :: t) ->
GenEnsembleOpt g (te :: te' :: t).
Fixpoint gen_ens_opt_add g g' te te' t (Hte : g ~~> g' & te)
(Ht : GenEnsembleOpt g' (te' :: t))
(HG : generator_events_commute Gen)
(Hfoll : ~ can_follow te te') {struct Ht} :
exists t' : list TE, GenEnsembleOpt g (te' :: t') /\ Permutation events_commute (te :: te' :: t) (te' :: t').
Proof with auto with slot.
destruct te as [pid evt]. destruct te' as [pid' evt'].
firstorder. apply NNPP in H0. rename H0 into Hcomm.
assert (Hpids : pid <> pid') by lia.
inversion Ht; subst; clear Ht.
- exists [pid @ evt]. split.
+ specialize (HG g g' g'0 (pid @ evt) (pid' @ evt') Hpids).
destruct HG as [g_ [Hg_ Hg_']]...
constructor 3 with g_...
* left. lia.
* constructor 2 with g'0...
+ constructor 3...
- specialize (HG g g' g'0 (pid @ evt) (pid' @ evt') Hpids) as Hgen_comm.
destruct Hgen_comm as [g_ [Hg_ Hg_']]...
destruct (classic (can_follow (pid @ evt) te')) as [Hfoll' | Hfoll'].
+ exists (pid @ evt :: te' :: t0). split.
* constructor 3 with g_...
-- left. lia.
-- constructor 3 with g'0...
* constructor 3...
+ specialize (gen_ens_opt_add g_ g'0 (pid @ evt) te' t0) as IH. clear gen_ens_opt_add.
destruct IH as [t' [Ht' Hperm']]...
exists (te' :: t'). split.
* constructor 3 with g_...
* sauto.
Qed.
Fixpoint gen_ens_opt (g : Gen) (t : list TE) (Ht : GenEnsemble g t)
(HG : generator_events_commute Gen)
{struct Ht} :
exists t' : list TE, GenEnsembleOpt g t' /\ Permutation events_commute t t'.
Proof with auto with slot.
destruct Ht as [Hnil | g' te t Hte Ht].
- exists []. split; now constructor.
- apply gen_ens_opt in Ht. destruct Ht as [t' [Ht' Hperm]]; clear gen_ens_opt.
destruct t' as [ | te' t'].
+ exists [te].
apply perm_empty in Hperm; subst.
split.
* inversion Ht'. constructor 2 with g'...
* repeat constructor.
+ destruct (classic (can_follow te te')).
* exists (te :: te' :: t'). split.
-- constructor 3 with g'...
-- now constructor.
* eapply gen_ens_opt_add in Ht'; eauto.
destruct Ht' as [t'' [Ht'' Hperm'']].
exists (te' :: t''). split.
-- assumption.
-- apply perm_trans with (te :: te' :: t')...
+ assumption.
Qed.
Theorem optimize_gen_p g
(HG : generator_events_commute Gen) :
sufficient_replacement_p (GenEnsemble g) (GenEnsembleOpt g).
Proof.
intros t Ht.
now apply gen_ens_opt.
Qed.
Theorem optimize_gen (g : Gen) P Q (HG : generator_events_commute Gen) :
-{{ P }} GenEnsembleOpt g {{ Q }} ->
-{{ P }} GenEnsemble g {{ Q }}.
Proof.
now apply ht_sufficient_replacement, comm_perm_sufficient_replacement, optimize_gen_p.
Qed.
End optimize.
Section parallel_gen_comm.
Context {State Event} `{StateSpace State (ProcessEvent Event)} {G1 G2}
`{Generator Event G1}
`{Generator (ProcessEvent Event) G2}.
Lemma parallel_gen_comm :
generator_events_commute G2 ->
generator_events_commute (@Parallel G1 G2).
Proof.
intros HG2 g g' g'' te1 te2 Hpids Hg Hg'.
destruct te1 as [pid1 evt1]. set (te1 := pid1 @ evt1).
destruct te2 as [pid2 evt2]. set (te2 := pid2 @ evt2).
simpl in Hpids.
inversion Hg; inversion Hg'; subst.
- exfalso. lia.
- sauto.
- sauto.
- assert (Hpids' : different_processes (pid @ evt1) (pid0 @ evt2)).
{ simpl. lia. }
inversion H8; subst.
specialize (HG2 g__r g__r' g__r'0).
specialize (HG2 (pid @ evt1) (pid0 @ evt2) Hpids').
specialize (HG2 H4 H9).
sauto.
Qed.
Theorem parallel_processes_ht :
forall (P Q : State -> Prop) (g1 : G1) (g2 : G2),
generator_events_commute G2 ->
-{{ P }} GenEnsembleOpt (g1 <||> g2) {{ Q }} ->
-{{ P }} GenEnsemble (g1 <||> g2) {{ Q }}.
Proof.
intros *. intros HG2 Hht.
apply parallel_gen_comm in HG2.
specialize (optimize_gen (g1 <||> g2) P Q HG2 Hht) as Hopt.
assumption.
Qed.
End parallel_gen_comm.
Hint Unfold can_follow : slot.
Hint Resolve singleton_gen_comm : slot.
Hint Resolve parallel_gen_comm : slot.
|
function f = p01_f ( n, x )
%*****************************************************************************80
%
%% P01_F returns the integrand for problem 1.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 14 January 2012
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, integer N, the number of variables.
%
% Input, real X(N), the arguments.
%
% Output, real F(N), the values of the integrand.
%
f = 1.1 * ones ( n, 1 );
return
end
|
%
%%
\subsection{JConfiguration alias Config} %status = done GET(4/4) PUT(2/2) DELETE (1/1)
\label{subsec:Config}
%
%%
\subsubsection{Service eMail Tasks}
\textbf{Get all available email tasks}\\
\begin{tabular}{lll}
http & GET & \texttt{config/\{version\}/scenario/148/emailtask/}
\end{tabular}\\
\begin{flushleft}
\begin{lstlisting}
{
"ids":
[
448
]
}
\end{lstlisting}
\captionof{json}{Example output of get all available email tasks}
\end{flushleft}
\textbf{Get details for a specific email task}\\
\begin{tabular}{lll}
http & GET & \texttt{config/\{version\}/scenario/1/emailtask/448/?}
\end{tabular}\\
\begin{flushleft}
\begin{lstlisting}
{
"receiver":"[email protected]",
"subject":"Test",
"message":"Test Message"
}
\end{lstlisting}
\captionof{json}{Example output of get all available email tasks}
\end{flushleft}
\textbf{PUT changes for an email task}\\
\begin{tabular}{lll}
http & PUT & \texttt{config/\{version\}/emailtask/448/?}
\end{tabular}\\
\begin{flushleft}
\begin{lstlisting}
{
"receiver":"[email protected]",
"subject":"Test",
"message":"Test Message"
}
\end{lstlisting}
\captionof{json}{Example output of PUT request to change an email task}
\end{flushleft}
%
%%
\subsubsection{Scenarios}
\textbf{Delete an scenario}\\
\begin{tabular}{lll}
http & DELETE & \texttt{config/\{version\}/scenario/156/?}
\end{tabular}\\
%
%%
\subsubsection{Webservice Tasks}
\textbf{GET all webservice tasks}\\
\begin{tabular}{lll}
http & GET & \texttt{config/\{version\}/scenario/1/webservice?}
\end{tabular}\\
\begin{flushleft}
\begin{lstlisting}
{
"ids":[527]
}
\end{lstlisting}
\captionof{json}{Example output of get all webservice tasks for a specific scenario}
\end{flushleft}
\textbf{GET specific webservice task}\\
\begin{tabular}{lll}
http & GET & \texttt{config/\{version\}/scenario/1/webservice/253?}
\end{tabular}\\
\begin{flushleft}
\begin{lstlisting}
{
"body":"",
"link":"http://localhost:9998/interface/v2/scenario/156/instance",
"method":"POST",
"attributes":
[
{
"order":1,
"controlnode_id":527,
"key":"id",
"dataattribute_id":14
}
]
}
\end{lstlisting}
\captionof{json}{Example output of get specific webservice tasks for a specific scenario}
\end{flushleft}
\textbf{PUT specific webservice task}\\
\begin{tabular}{lll}
http & PUT & \texttt{config/\{version\}/webservice/253?}
\end{tabular}\\
\begin{flushleft}
\begin{lstlisting}
{
"method":"POST",
"link":"http://localhost:9998/interface/v2/scenario/156/instance",
"attributes":
[
{
"order":1,
"controlnode_id":527,
"key":"id",
"dataattribute_id":14
},
{
"order":2,
"controlnode_id":527,
"key":"link",
"dataattribute_id":15
}
]
}
\end{lstlisting}
\captionof{json}{Example output of get specific webservice tasks for a specific scenario}
\end{flushleft}
|
Formal statement is: lemma minus_left: "prod (- a) b = - prod a b" Informal statement is: The product of a negative number and a positive number is negative.
|
using Compose
using Colors
using DataFrames
using Random: shuffle!
const TernBack = RGB(253 / 255, 253 / 255, 241 / 255)
const TernPalette = distinguishable_colors(66, Color[TernBack, RGB(0, 0, 0), RGB(0 / 255, 168 / 255, 45 / 255)])[3:end]
const TernColorblind =
distinguishable_colors(66, Color[TernBack, RGB(0, 0, 0), colorant"DodgerBlue4"], transform = deuteranopic)[3:end]
"""
multiternary(data::DataFrame, cols::AbstractArray{Symbol}, clscol::Union{Symbol, Missing}=missing; palette=TernPalette, norm=1.0)
Uses Compose.jl to draw a simple multi-ternary diagram from the `data`, a `DataFrame`.
The columns are drawn in the order in `cols` and the vertices labeled with the names
of the columns.
"""
function multiternary(
data::DataFrame,
cols::AbstractArray,
clscol::Any = missing;
title = missing,
palette = TernPalette,
font = "Verdana",
fontsize = 5.0,
norm = 1.0,
withcount = true,
)
# Draw an individual ternary diagram for cola and colb in data
function ternary(data, cola, colb, v1, L, ΞΈ)
# Compute the intersection of the line (P1:P2) with (P3:P4)
function xy(P1, P2, P3, P4)
s =
(P1[2] * (P2[1] - P3[1]) + P2[2] * P3[1] - P2[1] * P3[2] + P1[1] * (P3[2] - P2[2])) /
(P2[2] * (P3[1] - P4[1]) + P1[2] * (P4[1] - P3[1]) + (P1[1] - P2[1]) * (P3[2] - P4[2]))
return (P3[1] + s * (P4[1] - P3[1]), P3[2] + s * (P4[2] - P3[2]))
end
# From a, b on [0,1] compute P1, P2, P3 and P4
function cc(a, b, va, vb, vc)
return xy(vb .+ a .* (va .- vb), vc .+ a .* (va .- vc), va .+ b .* (vb .- va), vc .+ b .* (vb .- vc))
end
v3 = (v1[1] + L * cos(ΞΈ - Ο / 6), v1[2] - L * sin(ΞΈ - Ο / 6))
v2 = (v1[1] + L * cos(ΞΈ + Ο / 6), v1[2] - L * sin(ΞΈ + Ο / 6))
# 0.1 increment lines
vx = [[v1 .+ f .* (v2 .- v1), v1 .+ f .* (v3 .- v1)] for f = 0.1:0.1:0.91]
append!(vx, [[v2 .+ f .* (v3 .- v2), v2 .+ f .* (v1 .- v2)] for f = 0.1:0.1:0.91])
append!(vx, [[v3 .+ f .* (v1 .- v3), v3 .+ f .* (v2 .- v3)] for f = 0.1:0.1:0.91])
# Data points
datapts, labels, range = [], [], ismissing(clscol) ? (1:1) : levels(data[:, clscol])
ilvl = 1
for lvl in range
f(row) = ismissing(clscol) || (row[clscol] == lvl)
pts = [cc(r[cola] / norm, r[colb] / norm, v3, v2, v1) for r in filter(f, eachrow(data))]
if length(pts) > 0
pa, pb, col = [pt[1] for pt in pts], [pt[2] for pt in pts], palette[ilvl]
push!(
datapts,
(
context(),
Compose.circle(pa, pb, [L * 0.003]),
Compose.stroke(col),
Compose.fill("transparent"),
Compose.clip([v3, v2, v1]),
),
)
if !ismissing(clscol)
push!(
labels,
(
context(),
Compose.text(0.02, 0.54 + ilvl * 0.03, withcount ? "$lvl - $(length(pts))" : "$lvl"),
Compose.fill(col),
Compose.font(font),
Compose.fontsize(0.8 * fontsize),
),
)
end
ilvl = (ilvl % length(palette)) + 1
end
end
shuffle!(datapts) # randomize datapoint order
if length(labels) > 15
last = labels[end]
labels = labels[1:12]
push!(
labels,
(last[1], Compose.text(0.02, 0.54 + 13 * 0.03, "β¦"), Compose.fill(colorant"black"), last[4], last[5]),
)
push!(
labels,
(last[1], Compose.text(0.02, 0.54 + 14 * 0.03, last[2].primitives[1].value), last[3], last[4], last[5]),
)
end
return (
context(),
(context(), datapts...),
(context(), Compose.polygon([v1, v2, v3]), Compose.stroke("black"), Compose.fill("transparent")),
(context(), Compose.line(vx), Compose.stroke("darkgray")),
(context(), Compose.polygon([v1, v2, v3]), Compose.stroke("transparent"), Compose.fill(TernBack)),
(context(), labels...),
)
end
# Label the ends of the axes
function label(v0, labels, L)
xl, yl, ll = Float64[], Float64[], String[]
function ss(l)
if startswith(l,"Element(")
try
parse(Element,l[9:end-1]).symbol
catch
titlecase(l)
end
else
titlecase(l)
end
end
for i in eachindex(labels)
ΞΈ = -Ο + Ο * i / 3
vv = v(v0, ΞΈ, L)
push!(xl, vv[1])
push!(yl, vv[2])
push!(ll, ss(labels[i]))
end
return (
context(),
Compose.text(xl, yl, ll, [hcenter], [vcenter]),
Compose.fill("black"),
Compose.font(font),
Compose.fontsize(fontsize),
)
end
v(v0, ΞΈ, off = 0.02) = (v0[1] + off * cos(ΞΈ), v0[2] - off * sin(ΞΈ))
center, ops, ncols = (0.5, 0.5), [], min(length(cols), 6)
for i = 2:ncols
sa, sb = cols[i-1], cols[i]
ΞΈ = -Ο / 2 + Ο / 3 * (i - 2)
append!(ops, ternary(data, sa, sb, v(center, ΞΈ), 0.42, ΞΈ))
end
if !ismissing(title)
append!(
ops,
(
context(),
Compose.text(0.5, 0.03, title, hcenter, vtop),
Compose.fill("black"),
Compose.font(font),
Compose.fontsize(1.3 * fontsize),
),
)
end
Compose.compose(context(0.05, 0.0, 0.9, 0.9), (context(), ops...), (context(), label(center, string.(cols[1:ncols]), 0.48)))
end
"""
multiternary(
zep::Zeppelin;
rows = missing,
omit = [ n"C", n"O" ],
palette = TernPalette,
fontsize = 12pt,
font = "Verdana",
)
Plot the elemental data in `zep` to a multi-ternary diagram.
"""
function multiternary(
zep::Zeppelin;
rows = missing,
omit = [ n"C", n"O" ],
palette = TernPalette,
fontsize = 12pt,
font = "Verdana",
)
# Determine which elements to plot...
zd = ismissing(rows) ? zep.data : zep.data[rows, :]
df=DataFrame(Elm=Symbol[], Mean=Float64[])
foreach(elm->push!(df, [ convert(Symbol,elm), mean(zd[:,convert(Symbol, elm)])]), filter(elm->!(elm in omit), zep.elms))
sort!(df, :Mean, rev=true)
elms = df[:,:Elm][1:min(size(df,1),6)]
multiternary(zd, elms, :CLASS, title=zep.header["DESCRIPTION"], palette=palette, norm=100.0, fontsize=fontsize, font=font)
end
|
Require Import Crypto.Specific.Framework.RawCurveParameters.
Require Import Crypto.Util.LetIn.
(***
Modulus : 2^251 - 9
Base: 64
***)
Definition curve : CurveParameters :=
{|
sz := 4%nat;
base := 64;
bitwidth := 64;
s := 2^251;
c := [(1, 9)];
carry_chains := None;
a24 := None;
coef_div_modulus := None;
goldilocks := None;
karatsuba := None;
montgomery := true;
freeze := Some false;
ladderstep := false;
mul_code := None;
square_code := None;
upper_bound_of_exponent_loose := None;
upper_bound_of_exponent_tight := None;
allowable_bit_widths := None;
freeze_extra_allowable_bit_widths := None;
modinv_fuel := None
|}.
Ltac extra_prove_mul_eq _ := idtac.
Ltac extra_prove_square_eq _ := idtac.
|
/-
Copyright (c) 2022 MarΓa InΓ©s de Frutos-FernΓ‘ndez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: MarΓa InΓ©s de Frutos-FernΓ‘ndez
-/
import basic
import mul_ring_norm_rat
import nonarchimedean
import function_field
--import number_theory.padics.padic_norm
--import order.filter.basic
--import analysis.special_functions.log.base
--import analysis.normed.ring.seminorm
--import data.nat.digits
--import ring_theory.power_series.basic
--import analysis.specific_limits.normed
--import topology.algebra.order.basic
open_locale big_operators
/-!
# Ostrowski's theorem for β
## References
* https://kconrad.math.uconn.edu/blurbs/gradnumthy/ostrowskinumbfield.pdf
## Tags
ring_norm, ostrowski
-/
noncomputable theory
section real
/-- The usual absolute value on β. -/
def mul_ring_norm.real : mul_ring_norm β :=
{ to_fun := Ξ» x : β, |x|,
map_zero' := by simp only [rat.cast_zero, abs_zero],
add_le' := norm_add_le,
neg' := norm_neg,
eq_zero_of_map_eq_zero' :=
by simp only [abs_eq_zero, rat.cast_eq_zero, imp_self, forall_const],
map_one' := by simp only [algebra_map.coe_one, abs_one],
map_mul' := by exact_mod_cast abs_mul,
}
@[simp] lemma mul_ring_norm_eq_abs (r : β) : mul_ring_norm.real r = |r| := rfl
end real
section padic
/-- The p-adic norm on β. -/
def mul_ring_norm.padic (p : β) [hp : fact (nat.prime p)] : mul_ring_norm β :=
{ to_fun := Ξ» x : β, (padic_norm p x: β),
map_zero' := by simp only [padic_norm.zero, rat.cast_zero],
add_le' := by norm_cast; exact padic_norm.triangle_ineq,
neg' := by simp only [padic_norm.neg, eq_self_iff_true, forall_const],
eq_zero_of_map_eq_zero' := by norm_cast; exact @padic_norm.zero_of_padic_norm_eq_zero p _,
map_one' := by exact_mod_cast padic_norm.one,
map_mul' := by simp only [padic_norm.mul, rat.cast_mul, eq_self_iff_true, forall_const],
}
@[simp] lemma mul_ring_norm_eq_padic_norm (p : β) [hp : fact (nat.prime p)] (r : β) :
mul_ring_norm.padic p r = padic_norm p r := rfl
lemma mul_ring_norm.padic_is_nonarchimedean (p : β) [hp : fact (nat.prime p)] :
is_nonarchimedean (@mul_ring_norm.padic p hp) :=
begin
simp only [is_nonarchimedean_def, mul_ring_norm_eq_padic_norm],
exact_mod_cast @padic_norm.nonarchimedean p _
end
end padic
variable {f : mul_ring_norm β}
section non_archimedean
-- Show that π is an ideal
-- Maybe this should be inserted into the final proof.
def π (harc : is_nonarchimedean f) : ideal β€ :=
{ carrier := {a : β€ | f a < 1},
add_mem' := Ξ» a b ha hb, by simp only [set.mem_set_of_eq, int.cast_add] at ha hb β’;
linarith [(harc a b), (max_lt ha hb)],
zero_mem' := by simp only [set.mem_set_of_eq, algebra_map.coe_zero, map_zero, zero_lt_one],
smul_mem' := Ξ» a b hb, by simp only [algebra.id.smul_eq_mul, set.mem_set_of_eq, int.cast_mul,
map_mul, mul_lt_of_le_of_lt_one' (int_norm_le_one a harc) hb (map_nonneg f b) zero_lt_one]}
--Maybe this should be inserted into the final proof.
lemma a_proper (harc : is_nonarchimedean f) : π harc β (β€ : ideal β€) :=
begin
rw ideal.ne_top_iff_one,
dsimp only [π, submodule.mem_mk, set.mem_set_of_eq, int.cast_one, not_lt],
simp only [algebra_map.coe_one, map_one, lt_self_iff_false, not_false_iff],
end
-- Show that it contains pZ
-- Maybe this should be inserted into the final proof.
lemma a_contains_prime_ideal (harc : is_nonarchimedean f) (h_nontriv : f β 1) :
β (p : β) [hp : fact (nat.prime p)], π harc β₯ ideal.span {p} :=
begin
obtain β¨p, hp, hboundβ© := ex_prime_norm_lt_one harc h_nontriv,
refine β¨p, hp, _β©,
{ apply ideal.span_le.mpr,
simp only [set.singleton_subset_iff, set_like.mem_coe],
exact hbound, }
end
-- Show that it's in fact equal to pZ (since pZ is a maximal ideal)
-- Maybe this should be inserted into the final proof.
lemma a_eq_prime_ideal (harc : is_nonarchimedean f) (h_nontriv : f β 1) :
β (p : β) [hp : fact (nat.prime p)], π harc = ideal.span {p} :=
by obtain β¨p, hp, hincβ© := a_contains_prime_ideal harc h_nontriv;
refine β¨p, hp, ((principal_ideal_ring.is_maximal_of_irreducible
(nat.prime_iff_prime_int.mp hp.1).irreducible).eq_of_le (a_proper harc) hinc).symmβ©
-- I will try to see whether there is a similar version of this (hopefully)
lemma mult_finite {a : β€} {p : β} (hp : nat.prime p) (ha : a β 0) :
multiplicity.finite (p : β€) a :=
by apply multiplicity.finite_int_iff.mpr;
simp only [ha, hp.ne_one, int.nat_abs_of_nat, ne.def, not_false_iff, and_self]
-- the equality at the end of the next lemma
lemma rearrange {p v : β} (m : β) (hp : p > 0) (hlogp : real.log p β 0) (hv : v > 0) :
v ^ m = (p ^ m)β»ΒΉ ^ (-real.log v / real.log p) :=
begin
have : p ^ m = p ^ (m : β) := by norm_cast,
rw [βreal.rpow_neg_one, this, β(real.rpow_mul (le_of_lt hp)),
β(real.rpow_mul (le_of_lt hp)), neg_div, mul_neg, mul_neg, mul_one, neg_mul, neg_neg,
mul_div, βreal.log_rpow hv, real.rpow_def_of_pos hp, mul_div_left_comm,
div_self hlogp, mul_one, real.exp_log],
{ norm_cast },
{ norm_cast,
exact pow_pos hv m }
end
-- f a = (f p)^m = ring_norm a
lemma int_val_eq (harc : is_nonarchimedean f) (h_nontriv : f β 1) :
β (p : β) [hp : fact (nat.prime p)] (s : β) [hs : s > 0],
β (a : β€), f a = (@mul_ring_norm.padic p hp a)^s :=
begin
obtain β¨p, hp, h_aeqβ© := a_eq_prime_ideal harc h_nontriv,
refine β¨p, hp, _β©,
cases hp,
have fpgt0 := @norm_pos_of_ne_zero f _ (nat.cast_ne_zero.mpr (ne_of_gt hp.pos)),
let s := (-real.log (f p : β) / real.log p),
have hs : s > 0,
{ refine div_pos _ (@real.log_pos p (by exact_mod_cast hp.one_lt)),
{ refine neg_pos.mpr ((real.log_neg_iff fpgt0).mpr _),
have p_mem_a : (p : β€) β ideal.span ({p} : set β€) := by rw ideal.mem_span_singleton,
rw βh_aeq at p_mem_a,
exact p_mem_a, } },
refine β¨s, hs, _β©,
intro a,
by_cases ha : a = 0,
{ simp_rw [ha, int.cast_zero, map_zero],
exact (real.zero_rpow (norm_num.ne_zero_of_pos s hs)).symm },
obtain β¨b, hapb, hndivβ© := multiplicity.exists_eq_pow_mul_and_not_dvd (mult_finite hp ha),
let m := (multiplicity (p : β€) a).get (mult_finite hp ha),
have : f a = (f p) ^ m,
{ rw hapb,
have hb : βb β π harc,
{ rw h_aeq,
intro hmem,
rw ideal.mem_span_singleton' at hmem,
obtain β¨k, hkβ© := hmem,
apply hndiv,
rw dvd_iff_exists_eq_mul_left,
refine β¨k, hk.symmβ© },
dsimp only [π] at hb,
simp only [int.cast_id, submodule.mem_mk, set.mem_set_of_eq, not_lt] at hb,
suffices h'' : f ((p : β) ^ m * (b : β)) = (f (p : β)) ^ m,
{ convert h'',
norm_cast },
rw [f_mul_eq, le_antisymm (int_norm_le_one b harc) hb, mul_one, mul_eq_pow] },
rw this,
simp only [mul_ring_norm_eq_padic_norm, ha, padic_norm.eq_zpow_of_nonzero, ne.def,
int.cast_eq_zero, not_false_iff, padic_val_rat.of_int, zpow_neg, zpow_coe_nat,
rat.cast_inv, rat.cast_pow, rat.cast_coe_nat],
unfold padic_val_int padic_val_nat,
simp [ha, hp.ne_one, int.nat_abs_pos_of_ne_zero ha, multiplicity.int.nat_abs p a],
have hppos : (p : β) > 0 := nat.cast_pos.mpr (hp.pos),
exact rearrange m hppos (norm_num.ne_zero_of_pos _ (@real.log_pos p (by exact_mod_cast hp.one_lt))) fpgt0,
end
lemma cast_pow_sub (r : β) (a b : β€) : r ^ (a - b) = r ^ ((a : β) - (b : β)) := by norm_cast
lemma cast_pow (r : β) (a : β) : r ^ a = r ^ (a : β) := by norm_cast
-- Extend this to β using div_eq
lemma rat_val_eq (harc : is_nonarchimedean f) (h_nontriv : f β 1) :
β (p : β) [hp : fact (nat.prime p)] (s : β) (hs : s > 0),
β (a : β), f a = (@mul_ring_norm.padic p hp a)^s :=
begin
obtain β¨p, hp, s, hs, h_intβ© := int_val_eq harc h_nontriv,
use [p, hp, s, hs],
intro a,
by_cases ha : a = 0,
{ rw [ha, map_zero, map_zero],
have hs' : s β 0 := norm_num.ne_zero_of_pos s hs,
exact (real.zero_rpow hs').symm },
have hcast : f (a.denom) = (@mul_ring_norm.padic p hp a.denom) ^ s := h_int a.denom,
rw [βrat.num_div_denom a, ring_norm.div_eq, h_int, hcast],
simp [ha],
unfold padic_val_rat,
rw [cast_pow_sub, real.rpow_sub],
unfold padic_norm,
simp [rat.num_ne_zero_of_ne_zero ha, rat.denom_ne_zero a],
rw [real.inv_rpow, real.inv_rpow],
simp only [inv_div_inv],
rw βreal.div_rpow,
repeat {
-- fact hp --> hp
cases hp,
rw cast_pow,
exact real.rpow_nonneg_of_nonneg (le_of_lt (nat.cast_pos.mpr hp.pos)) _
},
cases hp,
exact (nat.cast_pos.mpr hp.pos),
norm_cast,
exact rat.denom_ne_zero a,
end
-- Finish: hence f and padic are equivalent
lemma f_equiv_padic (harc : is_nonarchimedean f) (h_nontriv : f β 1) :
β (p : β) [hp : fact (nat.prime p)], mul_ring_norm.equiv f (@mul_ring_norm.padic p hp) :=
begin
obtain β¨p, hp, s, hs, hβ© := rat_val_eq harc h_nontriv,
use [p, hp, 1 / s],
refine β¨one_div_pos.mpr hs, _β©,
ext a,
rw [h, βreal.rpow_mul],
simp [norm_num.ne_zero_of_pos s hs],
unfold mul_ring_norm.padic,
simp only [map_nonneg]
end
end non_archimedean
section archimedean
-- This should be the same as `Sum_le`
lemma Sum_le' (n : β) (ΞΉ : finset.Iio n β β) :
f (β i : finset.Iio n, ΞΉ i) β€ β i : finset.Iio n, f (ΞΉ i) :=
begin
sorry
end
--First limit
lemma limit1 {N : β} (hN : 0 < N) : filter.tendsto (Ξ» n : β, N ^ (1 / (n : β))) filter.at_top (nhds 1) :=
begin
rw βreal.exp_log hN,
simp_rw [βreal.exp_mul],
refine real.tendsto_exp_nhds_0_nhds_1.comp _,
simp_rw [mul_one_div],
apply tendsto_const_div_at_top_nhds_0_nat
end
--Second limit
lemma limit2 (c : β) (hc : 0 < c) : filter.tendsto (Ξ» n : β, (1 + (n : β)*c)^(1 / (n : β))) filter.at_top (nhds 1) :=
begin
have cne0 : c β 0 := ne_of_gt hc,
have : (Ξ» n : β, (1+(n : β)*c)^(1 / (n : β))) = (Ξ» (x : β), x ^ (1 / ((1 / c) * x + (- 1) / c))) β (Ξ» y : β, 1 + c*y) β coe,
{ ext n, simp, rw mul_add, rw βmul_assoc, simp, rw div_eq_mul_inv, rw add_comm cβ»ΒΉ, rw add_assoc, rw [neg_mul, one_mul, add_right_neg, add_zero, inv_mul_cancel cne0, one_mul, mul_comm] },
rw this,
have : 1 / c β 0 := one_div_ne_zero cne0,
refine (tendsto_rpow_div_mul_add 1 (1 / c) (-1 / c) this.symm).comp _,
have : filter.tendsto (Ξ» y : β, 1 + c*y) filter.at_top filter.at_top,
{ apply filter.tendsto_at_top_add_const_left,
apply filter.tendsto.const_mul_at_top hc,
intros x hx,
exact hx },
exact this.comp tendsto_coe_nat_at_top_at_top
end
--Potentially useful
example {c : β} (hc : 0 < c) : filter.tendsto (Ξ» n : β, ((n : β))^(1 / (n : β))) filter.at_top (nhds 1) :=
begin
have hf : (Ξ» n : β, (n : β)^(1 / (n : β))) = Ξ» n : β, (((Ξ» x : β, x^(1 / x)) β coe) n),
{ ext, simp only [eq_self_iff_true] },
rw hf,
apply filter.tendsto.comp _ tendsto_coe_nat_at_top_at_top,
exact tendsto_rpow_div,
apply_instance,
end
lemma pow_mul_pow_le_max_pow {a b : β} {m n : β} (ha : 0 β€ a) (hb : 0 β€ b) : a^m * b^n β€ max a b ^ (m + n) :=
begin
rw pow_add,
apply mul_le_mul,
{ exact pow_le_pow_of_le_left ha (le_max_left a b) m },
{ exact pow_le_pow_of_le_left hb (le_max_right a b) n },
{ exact pow_nonneg hb n },
{ apply pow_nonneg,
rw le_max_iff,
left,
exact ha }
end
lemma inter_ineq {n : β} (x y : β) (hf : β m : β, f m β€ 1) :
f (x + y)^(n : β) β€ (n + 1 : β) * max (f x) (f y)^n :=
begin
norm_cast,
rw [βmul_eq_pow, add_pow],
apply le_trans (Sum_le f (n + 1)),
suffices goal_1 : β i in finset.range (n + 1), f ( x^i * y^(n - i) * (n.choose i) )
= β i in finset.range (n + 1), f (x ^ i) * f(y ^ (n - i)) * f (n.choose i),
{ rw goal_1,
clear goal_1,
calc β i in finset.range (n + 1), f (x ^ i) * f(y ^ (n - i)) * f (n.choose i)
β€ β i in finset.range (n + 1), f (x ^ i) * f (y ^ (n - i)) :
begin
apply finset.sum_le_sum,
intros i hi,
conv { to_rhs, rw βmul_one (f (x ^ i) * f (y ^ (n - i))) },
exact mul_le_mul_of_nonneg_left (hf _) (mul_nonneg (map_nonneg f _) (map_nonneg f _))
end
... β€ β i in finset.range (n + 1), max (f x) (f y) ^ n :
begin
apply finset.sum_le_sum,
intros i hi,
have : i + (n - i) = n,
{ rw add_comm,
apply nat.sub_add_cancel,
simp at hi,
linarith },
conv { to_rhs, rw βthis },
repeat { rw mul_eq_pow },
exact pow_mul_pow_le_max_pow (map_nonneg f x) (map_nonneg f y),
end
... = β(n + 1) * max (f x) (f y) ^ n : by simp, },
{ congr',
ext,
rw [f_mul_eq, f_mul_eq] }
end
lemma root_ineq {n : β} (x y : β) (hn : n β 0) (hf : β m : β, f m β€ 1) :
f (x + y) β€ (n + 1 : β) ^ (1 / (n : β)) * max (f x) (f y) :=
begin
refine le_of_pow_le_pow n _ (nat.pos_of_ne_zero hn) _,
{ apply mul_nonneg,
{ apply real.rpow_nonneg_of_nonneg,
norm_cast,
linarith },
{ rw le_max_iff,
left,
exact map_nonneg f x } },
{ rw mul_pow,
have : 0 β€ (n : β) + 1 := by { norm_cast, linarith },
nth_rewrite 1 [βreal.rpow_nat_cast],
rw [βreal.rpow_mul this, one_div],
have : (n : β) β 0 := by { norm_cast, exact hn },
rw [inv_mul_cancel this, real.rpow_one, βreal.rpow_nat_cast],
exact inter_ineq x y hf }
end
-- A norm is non-archimedean iff it's bounded on the naturals
lemma non_archimedean_iff_nat_norm_bound : (β n : β, f n β€ 1) β is_nonarchimedean f :=
begin
split,
{ intros H x y,
have lim : filter.tendsto (Ξ» n : β, (n + 1 : β) ^ (1 / (n : β)) * max (f x) (f y)) filter.at_top (nhds (max (f x) (f y))),
{ nth_rewrite 0 βone_mul (max (f x) (f y)),
apply filter.tendsto.mul_const (max (f x) (f y)),
suffices goal_1 : (Ξ» k : β, ((k : β) + 1) ^ (1 / (k : β))) = (Ξ» k : β, (1 + (k : β) * 1) ^ (1 / (k : β))),
{ rw goal_1,
clear goal_1,
exact limit2 1 (real.zero_lt_one) },
{ ext k,
simp,
rw add_comm } },
apply ge_of_tendsto lim _,
simp only [filter.eventually_at_top, ge_iff_le],
use 1,
intros b hb,
have : b β 0 := nat.one_le_iff_ne_zero.mp hb,
exact root_ineq x y this H },
{ intros hf n,
exact nat_norm_le_one n hf }
end
lemma aux1 {nβ : β} (hf : β n : β, 1 < f n) (dnβ : nβ = nat.find hf) : 1 < nβ :=
begin
have hnβ := nat.find_spec hf,
rw βdnβ at hnβ,
by_contra',
rw lt_iff_not_ge at hnβ,
interval_cases nβ,
{ apply hnβ,
simp only [nat.cast_zero, map_zero, ge_iff_le, zero_le_one] },
{ apply hnβ,
simp [f.map_one'] }
end
lemma list.map_with_index_append' {Ξ± M : Type*} [add_comm_monoid M]
(K L : list Ξ±) (f : β β Ξ± β M) :
(K ++ L).map_with_index f = K.map_with_index f ++ L.map_with_index (Ξ» i a, f (i + K.length) a) :=
begin
induction K with a J IH generalizing f,
{ simp },
{ simp [IH (Ξ» i, f (i+1)), add_assoc], }
end
-- This should be the same as `list.map_with_index_sum_to_finset_sum`
lemma list.map_with_index_sum_to_finset_sum' {Ξ² A : Type*} [add_comm_monoid A] {f : β β Ξ² β A}
{L : list Ξ²} [inhabited Ξ²] : (L.map_with_index f).sum = β i : finset.Iio L.length,
f i ((L.nth_le i (finset.mem_Iio.1 i.2))) :=
begin
sorry
end
lemma list.map_with_index_sum_to_finset_sum {Ξ² A : Type*} [add_comm_monoid A] {f : β β Ξ² β A}
{L : list Ξ²} [inhabited Ξ²] : (L.map_with_index f).sum = β i in finset.range L.length,
f i ((L.nth i).get_or_else default) :=
begin
apply list.reverse_rec_on L, -- the induction principle which works best
{ simp, },
{ intros M a IH,
simp [list.map_with_index_append, IH],
rw finset.sum_range_succ,
congr' 1,
{ apply finset.sum_congr rfl,
intros x hx,
congr' 2,
rw finset.mem_range at hx,
rw list.nth_append hx, },
{ simp, } },
end
-- This is lemma 1.1
lemma aux2 {nβ : β} {Ξ± : β} (hf : β n : β, 1 < f n)
(dnβ : nβ = nat.find hf) (dΞ± : Ξ± = real.log (f nβ) / real.log nβ) :
β n : β, f n β€ n ^ Ξ± :=
begin
have : f nβ = nβ ^ Ξ±,
{ rw [dΞ±, real.log_div_log],
apply eq.symm,
apply real.rpow_logb,
{ norm_cast,
exact lt_trans zero_lt_one (aux1 hf dnβ) },
{ apply ne_of_gt,
norm_cast,
exact aux1 hf dnβ },
{ have hnβ := nat.find_spec hf,
rw βdnβ at hnβ,
exact lt_trans zero_lt_one hnβ } },
have hΞ± : 0 < Ξ±,
{ rw dΞ±,
apply div_pos,
{ apply real.log_pos,
rw dnβ,
exact nat.find_spec hf },
{ apply real.log_pos,
norm_cast,
exact aux1 hf dnβ } },
let C : β := ((nβ : β) ^ Ξ±) / ((nβ : β) ^ Ξ± - 1),
have dc : C = ((nβ : β) ^ Ξ±) / ((nβ : β) ^ Ξ± - 1) := rfl,
have hC : 0 < C,
{ rw dc,
rw β this,
have hnβ := nat.find_spec hf,
rw βdnβ at hnβ,
apply div_pos; linarith, }, -- easy to do
suffices : β n : β, f n β€ C * ((n : β) ^ Ξ±),
{ intro n,
have limit' : filter.tendsto (Ξ» N : β, C ^ (1 / (N : β))) filter.at_top (nhds 1),
{ exact limit1 hC, }, --someone good at analysis
have limit'' : filter.tendsto
(Ξ» N : β, (C ^ (1 / (N : β))) * (n ^ Ξ±)) filter.at_top (nhds (n ^ Ξ±)),
{ have := filter.tendsto.mul_const (βn ^ Ξ±) limit',
simp at this,
simp,
exact this, }, --following from limit'
have stupid : (0 : β) β€ n := by norm_cast; exact zero_le n, -- very easy
have aux : β N : β, (f (n)) ^ (N : β) β€ C * ((n ^ Ξ±) ^ (N : β)),
{ intro N,
rw βreal.rpow_mul stupid,
nth_rewrite 1 mul_comm,
rw real.rpow_mul stupid,
norm_cast,
rw βmul_eq_pow,
specialize this (n ^ N),
norm_cast,
exact this, },
have aux1 : β N : β, 0 < N β f (n) β€ (C ^ (1 / (N : β))) * (n ^ Ξ±),
{ intros N hN,
refine le_of_pow_le_pow N _ hN _,
{ apply mul_nonneg,
{ apply le_of_lt,
exact real.rpow_pos_of_pos hC _, },
{ exact real.rpow_nonneg_of_nonneg stupid _, } },
{ rw mul_pow,
repeat {rw [βreal.rpow_nat_cast]},
rw [βreal.rpow_mul (le_of_lt hC), one_div],
have : (N : β) β 0,
{ norm_cast,
rw push_neg.not_eq,
exact ne_of_gt hN, },
rw [inv_mul_cancel this, real.rpow_one],
exact aux N, } }, --take nth root on both side
apply ge_of_tendsto limit'' _,
simp only [filter.eventually_at_top, ge_iff_le],
use 1,
intros b hb,
have : 0 < b := (by linarith),
exact aux1 b this, },
intro n,
by_cases n = 0,
{ subst h,
simp [hΞ±],
nlinarith [hC, real.zero_rpow_nonneg Ξ±] },
have length_lt_one : 0 β€ ((nβ.digits n).length : β) - 1, -- Not sure whether this is useful or not
{ norm_num,
sorry}, -- should be easy `digits_ne_nil_iff_ne_zero` might be useful
conv_lhs { rw βnat.of_digits_digits nβ n },
rw nat.of_digits_eq_sum_map_with_index,
rw list.map_with_index_sum_to_finset_sum',
simp only [nat.cast_sum, nat.cast_mul, nat.cast_pow],
apply le_trans (Sum_le' (nβ.digits n).length _),
have aux' : 2 β€ nβ := by linarith [aux1 hf dnβ],
suffices goal_1 : β i : finset.Iio (nβ.digits n).length,
f (((((nβ.digits n).nth_le i (finset.mem_Iio.1 i.2))) : β)
* (nβ : β) ^ (i : β)) = β i : finset.Iio (nβ.digits n).length,
f (((nβ.digits n).nth_le i (finset.mem_Iio.1 i.2)))
* (f nβ) ^ (i : β),
{ rw goal_1,
clear goal_1,
have coef_ineq : β i : finset.Iio (nβ.digits n).length,
f (((nβ.digits n).nth_le i (finset.mem_Iio.1 i.2))) β€ 1,
{ intro i,
have : ((nβ.digits n).nth_le i (finset.mem_Iio.1 i.2)) < nβ,
{ have aux'' : ((nβ.digits n).nth_le i (finset.mem_Iio.1 i.2)) β nβ.digits n,
{ exact (nat.digits nβ n).nth_le_mem βi (finset.mem_Iio.mp i.property) },
exact nat.digits_lt_base aux' aux'', },
apply le_of_not_gt,
subst dnβ,
rw gt_iff_lt,
exact nat.find_min hf this },
rw this,
have goal1 : β (i : (finset.Iio (nβ.digits n).length)),
f ((nβ.digits n).nth_le βi (finset.mem_Iio.1 i.2)) * (nβ ^ Ξ±) ^ (i : β) β€
β (i : (finset.Iio (nβ.digits n).length)), (nβ ^ Ξ±) ^ (i : β),
{sorry},
apply le_trans goal1,
clear goal1,
have goal2 : (β i : (finset.Iio (nβ.digits n).length), ((nβ : β) ^ Ξ±) ^ (i : β)) =
(((nβ : β) ^ (Ξ± * ((nβ.digits n).length - 1))) *
β i : (finset.Iio (nβ.digits n).length), ((nβ : β) ^ -Ξ±) ^ (i : β)),
{sorry},
rw goal2,
clear goal2,
have goal3_aux : β (i : (finset.Iio (nβ.digits n).length)),
((nβ : β) ^ -Ξ±) ^ (i : β) β€ β'i : β, (1 / ((nβ : β) ^ Ξ±)) ^ i,
{sorry},
have goal3_aux' : 0 β€ (nβ : β) ^ (Ξ± * (((nβ.digits n).length - 1))),
{sorry}, -- easy
have goal3 : ((nβ : β) ^ (Ξ± * (((nβ.digits n).length - 1))))
* (β (i : (finset.Iio (nβ.digits n).length)), ((nβ : β) ^ -Ξ±) ^ (i : β))
β€ ((nβ : β) ^ (Ξ± * (((nβ.digits n).length - 1)))) *
(β'i : β, (1 / ((nβ : β) ^ Ξ±)) ^ i),
{sorry}, -- easy here
apply le_trans goal3,
clear goal3_aux goal3_aux' goal3,
have goal4 : β'i : β, (1 / ((nβ : β) ^ Ξ±)) ^ i = C,
{sorry}, -- `tsum_geometric_of_abs_lt_1` is useful here.
rw goal4,
clear goal4,
rw mul_comm,
suffices : (nβ : β) ^ (Ξ± * (((nβ.digits n).length - 1))) β€ (n : β) ^ Ξ±,
{ nlinarith },
have goal : (nβ : β) ^ (((nβ.digits n).length : β) - 1) β€ (n : β),
{ have h' := nat.base_pow_length_digits_le nβ n aux' h,
have h'' : (nβ : β) ^ ((nβ.digits n).length : β) β€ (nβ : β) * (n : β),
{ norm_cast,
exact h' },
have aux'' : 0 < (nβ : β) := by norm_cast;linarith,
have stupid : (nβ : β) β 0 := by norm_cast;linarith,
have h''' : 0 β€ (nβ : β) ^ (-(1 : β)),
{ rw real.rpow_neg_one,
have stupid2 : 0 β€ (nβ : β)β»ΒΉ * nβ := by simp [inv_mul_cancel stupid],
exact nonneg_of_mul_nonneg_left stupid2 aux'' },
have h'''' := mul_le_mul_of_nonneg_left h'' h''',
rw βreal.rpow_add aux'' _ _ at h'''',
rw add_comm at h'''',
rw βmul_assoc at h'''',
apply le_trans h'''',
rw real.rpow_neg_one,
rw inv_mul_cancel stupid,
linarith },
have stupid : (0 : β) β€ nβ := sorry, -- easy
rw mul_comm,
rw real.rpow_mul stupid,
have stupid2 : 0 β€ (nβ : β) ^ (((nβ.digits n).length : β) - 1) := sorry, --easy
exact real.rpow_le_rpow stupid2 goal (le_of_lt hΞ±) },
{ congr',
ext,
rw [f_mul_eq, mul_eq_pow] }
end
-- This is lemma 1.2 (this looks hard btw)
lemma aux3 {nβ : β} {Ξ± : β} (hf : β n : β, 1 < f n)
(dnβ : nβ = nat.find hf) (dΞ± : Ξ± = real.log (f nβ) / real.log nβ) :
β n : β, (n ^ Ξ± : β) β€ f n :=
begin
have hΞ±β : 0 < Ξ±,
{ rw dΞ±,
apply div_pos,
{ apply real.log_pos,
rw dnβ,
exact nat.find_spec hf },
{ apply real.log_pos,
norm_cast,
exact aux1 hf dnβ } },
have hΞ± : 0 β€ Ξ± := by linarith,
have hnβ : 2 β€ nβ := by linarith [aux1 hf dnβ],
have : f nβ = nβ ^ Ξ± := sorry, -- same proof as above
let C : β := (1 - (1 - 1 / nβ) ^ Ξ±),
have hC : 0 β€ C,
{ dsimp only [C],
field_simp,
apply real.rpow_le_one _ _ hΞ±,
{ field_simp,
sorry},
{
sorry} },
suffices : β n : β, C * ((n : β) ^ Ξ±) β€ f n,
{sorry}, -- This should be almost the same as above
intros n,
by_cases hn : n = 0,
{ subst hn,
simp only [map_zero, algebra_map.coe_zero, map_zero],
rw real.zero_rpow,
{ rw mul_zero },
linarith },
have length_lt_one : 1 β€ (nβ.digits n).length,
{ by_contra goal,
simp only [not_le, nat.lt_one_iff] at goal,
rw [list.length_eq_zero, nat.digits_eq_nil_iff_eq_zero] at goal,
contradiction },
have hβ : f ((nβ : β) ^ ((nβ.digits n).length))
- f (((nβ : β) ^ ((nβ.digits n).length)) - n) β€ f n,
{ have goal := abs_sub_map_le_sub f ((nβ : β) ^ ((nβ.digits n).length)) (((nβ : β) ^ ((nβ.digits n).length)) - n),
simp only [map_pow, sub_sub_cancel] at goal,
apply le_trans _ goal,
rw map_pow,
exact le_abs_self _ },
apply le_trans' hβ,
rw [mul_eq_pow, this],
have h := aux2 hf dnβ dΞ±,
specialize h ((nβ ^ ((nβ.digits n).length)) - n),
have hnβ : n β€ nβ ^ (nβ.digits n).length := by linarith [@nat.lt_base_pow_length_digits nβ n hnβ],
have hβ : ((nβ : β) ^ Ξ±) ^ (nβ.digits n).length - ((nβ ^ (nβ.digits n).length - n) : β) ^ Ξ± β€
((nβ : β) ^ Ξ±) ^ (nβ.digits n).length - f ((nβ : β) ^ (nβ.digits n).length - (n : β)),
{ rw sub_le_sub_iff_left,
push_cast at h,
simp only [rat.cast_sub, rat.cast_pow, rat.cast_coe_nat],
exact h },
apply le_trans' hβ,
clear hβ,
simp only [rat.cast_sub, rat.cast_pow, rat.cast_coe_nat],
have hβ : ((nβ : β) ^ Ξ±) ^ (nβ.digits n).length - ((nβ : β) ^ (nβ.digits n).length - (nβ : β) ^ ((nβ.digits n).length - 1)) ^ Ξ± β€
((nβ : β) ^ Ξ±) ^ (nβ.digits n).length - ((nβ : β) ^ (nβ.digits n).length - (n : β)) ^ Ξ±,
{ rw sub_le_sub_iff_left,
apply real.rpow_le_rpow _ _ hΞ±,
{ field_simp,
norm_cast,
exact hnβ },
{ field_simp,
norm_cast,
rw β nat.pow_div length_lt_one,
{ simp only [pow_one],
exact nat.div_le_of_le_mul (nat.base_pow_length_digits_le nβ n hnβ hn) },
linarith } },
apply le_trans' hβ,
clear hβ,
have hβ : ((nβ : β) ^ Ξ±) ^ (nβ.digits n).length -
((nβ : β) ^ (nβ.digits n).length - (nβ : β) ^ ((nβ.digits n).length - 1)) ^ Ξ±
= (((nβ : β) ^ Ξ±) ^ (nβ.digits n).length) * (1 - (1 - 1 / nβ) ^ Ξ±),
{ rw mul_sub,
rw mul_one,
rw sub_right_inj,
repeat {rw βreal.rpow_nat_cast},
rw βreal.rpow_mul, -- This looks stupid here, as I am looking for (a ^ b) ^ c = (a ^ c) ^ b
{ nth_rewrite 1 mul_comm,
rw real.rpow_mul,
{ rw βreal.mul_rpow,
{ rw mul_sub,
rw mul_one,
rw nat.cast_sub length_lt_one,
rw real.rpow_sub,
{ ring_nf,
simp only [algebra_map.coe_one, real.rpow_one] },
norm_cast,
linarith [aux1 hf dnβ] },
{ norm_cast,
linarith [nat.one_le_pow ((nβ.digits n).length)
nβ (by linarith [aux1 hf dnβ])] },
{ simp only [sub_nonneg],
rw one_div_le,
{ simp only [div_self, ne.def, one_ne_zero, not_false_iff, nat.one_le_cast],
linarith [aux1 hf dnβ] },
{ norm_cast,
linarith [aux1 hf dnβ] },
{ linarith } } },
norm_cast,
exact nat.zero_le nβ },
norm_cast,
exact nat.zero_le nβ },
rw hβ,
clear hβ,
change (1 - (1 - 1 / (nβ : β)) ^ Ξ±) with C,
nth_rewrite 1 mul_comm,
apply mul_le_mul_of_nonneg_left _ hC,
suffices goal : (n : β )^ Ξ± β€ ((nβ : β) ^ (nβ.digits n).length) ^ Ξ±,
{ rw βreal.rpow_nat_cast at goal β’,
rw βreal.rpow_mul, -- This looks stupid here, as I am looking for (a ^ b) ^ c = (a ^ c) ^ b
{ rw mul_comm,
rw real.rpow_mul,
{ exact goal },
norm_cast,
exact nat.zero_le nβ },
norm_cast,
exact nat.zero_le nβ },
apply real.rpow_le_rpow,
{ norm_cast,
exact nat.zero_le n },
{ norm_cast,
linarith [@nat.lt_base_pow_length_digits _ n hnβ] },
{ exact hΞ± }
end
lemma archimedean_case (hf : Β¬ is_nonarchimedean f) : mul_ring_norm.equiv f mul_ring_norm.real :=
begin
rw βnon_archimedean_iff_nat_norm_bound at hf,
simp only [not_forall, not_le] at hf,
let nβ : β := nat.find hf,
have dnβ : nβ = nat.find hf := rfl,
let Ξ± : β := real.log (f nβ) / real.log nβ,
have hΞ± : Ξ± = real.log (f nβ) / real.log nβ := rfl,
have hβ : β (n : β), f (n : β) = (n : β) ^ Ξ±,
{ intro n,
linarith [aux3 hf dnβ hΞ± n, aux2 hf dnβ hΞ± n] },
have hβ : β (n : β), f (n : β) = |n| ^ Ξ±,
{ intro n,
rw nat.abs_cast n,
exact hβ n },
apply mul_ring_norm.equiv_symm _ _,
refine β¨Ξ±, _, _β©,
{ rw hΞ±,
apply div_pos,
{ apply real.log_pos,
exact nat.find_spec hf },
{ apply real.log_pos,
norm_cast,
exact aux1 hf dnβ } },
{ ext,
rw mul_ring_norm_eq_abs,
rw βrat.num_div_denom x,
norm_cast,
rw βrat.coe_int_div_eq_mk,
rw abs_div,
push_cast,
rw ring_norm.div_eq,
{ rw real.div_rpow,
{ congr,
{ cases x.num with b b,
{ simp only [int.of_nat_eq_coe, int.cast_coe_nat],
exact (hβ b).symm },
{ simp only [int.cast_neg_succ_of_nat, nat.cast_add, algebra_map.coe_one,
neg_add_rev],
rw βabs_neg,
rw βmap_neg_eq_map,
simp only [neg_add_rev, neg_neg],
norm_cast,
exact (hβ (b + 1)).symm } },
{ exact (hβ x.denom).symm } },
{ exact norm_nonneg ((x.num) : β) },
{ exact norm_nonneg ((x.denom) : β) } },
{ norm_cast,
exact rat.denom_ne_zero x } },
end
end archimedean
/-- Ostrowski's Theorem -/
theorem rat_ring_norm_p_adic_or_real (f : mul_ring_norm β) (hf_nontriv : f β 1) :
(mul_ring_norm.equiv f mul_ring_norm.real) β¨
β (p : β) [hp : fact (nat.prime p)], mul_ring_norm.equiv f (@mul_ring_norm.padic p hp) :=
begin
by_cases bdd : β z : β, f z β€ 1,
{ right, /- p-adic case -/
rw [non_archimedean_iff_nat_norm_bound] at bdd,
exact f_equiv_padic bdd hf_nontriv },
{ left,
rw non_archimedean_iff_nat_norm_bound at bdd,
exact archimedean_case bdd, /- Euclidean case -/ }
end
|
class category (C : Type) :=
( hom : C β C β Type )
( id : (X : C) β hom X X )
( comp : {X Y Z : C} β hom X Y β hom Y Z β hom X Z )
( id_comp {X Y : C} (f : hom X Y) : comp (id X) f = f )
( comp_id {X Y : C} (f : hom X Y) : comp f (id Y) = f )
( assoc {W X Y Z : C} (f : hom W X) (g : hom X Y) (h : hom Y Z) :
comp (comp f g) h = comp f (comp g h) )
notation " π " => category.id
infixr: 80 " β« " => category.comp
infixr: 10 " βΆ " => category.hom
variable (C : Type) [category C]
inductive prod_coprod : Type
| of_cat' : C β prod_coprod
| prod : prod_coprod β prod_coprod β prod_coprod
| coprod : prod_coprod β prod_coprod β prod_coprod
variable {C}
namespace prod_coprod
@[simp] def size : prod_coprod C β Nat
| of_cat' _ => 1
| prod X Y => size X + size Y + 1
| coprod X Y => size X + size Y + 1
inductive syn : (X Y : prod_coprod C) β Type
| of_cat {X Y : C} : (X βΆ Y) β syn (of_cat' X) (of_cat' Y)
| prod_mk {X Y Z : prod_coprod C} : syn X Y β syn X Z β syn X (Y.prod Z)
| fst {X Y : prod_coprod C} : syn (X.prod Y) X
| snd {X Y : prod_coprod C} : syn (X.prod Y) Y
| coprod_mk {X Y Z : prod_coprod C} : syn X Z β syn Y Z β syn (X.coprod Y) Z
| inl {X Y : prod_coprod C} : syn X (X.coprod Y)
| inr {X Y : prod_coprod C} : syn Y (X.coprod Y)
| id (X : prod_coprod C) : syn X X
| comp {X Y Z : prod_coprod C} : syn X Y β syn Y Z β syn X Z
namespace syn
inductive rel : {X Y : prod_coprod C} β syn X Y β syn X Y β Prop
| refl {X Y : prod_coprod C} (f : syn X Y) : rel f f
| symm {X Y : prod_coprod C} {f g : syn X Y} : rel f g β rel g f
| trans {X Y : prod_coprod C} {f g h : syn X Y} : rel f g β rel g h β rel f h
| comp_congr {X Y Z : prod_coprod C} {fβ fβ : syn X Y} {gβ gβ : syn Y Z} :
rel fβ fβ β rel gβ gβ β rel (fβ.comp gβ) (fβ.comp gβ)
| prod_mk_congr {X Y Z : prod_coprod C} {fβ fβ : syn X Y} {gβ gβ : syn X Z} :
rel fβ fβ β rel gβ gβ β rel (fβ.prod_mk gβ) (fβ.prod_mk gβ)
| coprod_mk_congr {X Y Z : prod_coprod C} {fβ fβ : syn X Z} {gβ gβ : syn Y Z} :
rel fβ fβ β rel gβ gβ β rel (fβ.coprod_mk gβ) (fβ.coprod_mk gβ)
| id_comp {X Y : prod_coprod C} (f : syn X Y) : rel ((syn.id X).comp f) f
| comp_id {X Y : prod_coprod C} (f : syn X Y) : rel (f.comp (syn.id Y)) f
| assoc {W X Y Z : prod_coprod C} (f : syn W X) (g : syn X Y) (h : syn Y Z) :
rel ((f.comp g).comp h) (f.comp (g.comp h))
| of_cat_id {X : C} : rel (syn.of_cat (π X)) (syn.id (of_cat' X))
| of_cat_comp {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z) :
rel (syn.of_cat (f β« g)) (syn.comp (syn.of_cat f) (syn.of_cat g))
| mk_fst_comp {X Y Z : prod_coprod C} (f : syn X Y) (g : syn X Z) :
rel (syn.comp (syn.prod_mk f g) syn.fst) f
| mk_snd_comp {X Y Z : prod_coprod C} (f : syn X Y) (g : syn X Z) :
rel (syn.comp (syn.prod_mk f g) syn.snd) g
| prod_eta {X Y Z : prod_coprod C} (f : syn X (Y.prod Z)) :
rel (syn.prod_mk (f.comp syn.fst) (f.comp syn.snd)) f
| inl_comp_mk {X Y Z : prod_coprod C} (f : syn X Z) (g : syn Y Z) :
rel (syn.comp syn.inl (syn.coprod_mk f g)) f
| inr_comp_mk {X Y Z : prod_coprod C} (f : syn X Z) (g : syn Y Z) :
rel (syn.comp syn.inr (syn.coprod_mk f g)) g
| coprod_eta {X Y Z : prod_coprod C} (f : syn (X.coprod Y) Z) :
rel (syn.coprod_mk (syn.inl.comp f) (syn.inr.comp f)) f
infixl:50 " β₯ " => rel
instance : Trans (@rel C _ X Y) (@rel C _ X Y) (@rel C _ X Y) where
trans := rel.trans
theorem rel_prod {X Y Z : prod_coprod C} {f g : syn X (Y.prod Z)}
(hβ : rel (f.comp syn.fst) (g.comp syn.fst))
(hβ : rel (f.comp syn.snd) (g.comp syn.snd)) :
rel f g :=
rel.trans (rel.symm (rel.prod_eta f)) (rel.trans (rel.prod_mk_congr hβ hβ) (rel.prod_eta g))
theorem rel_coprod {X Y Z : prod_coprod C} {f g : syn (X.coprod Y) Z}
(hβ : rel (syn.inl.comp f) (syn.inl.comp g))
(hβ : rel (syn.inr.comp f) (syn.inr.comp g)) :
rel f g :=
rel.trans (rel.symm (rel.coprod_eta f)) (rel.trans (rel.coprod_mk_congr hβ hβ) (rel.coprod_eta g))
end syn
inductive list_proj : (X Y : prod_coprod C) β Type -- Y is not prod
| empty {X : prod_coprod C} : list_proj X X
| fst_comp {X Y Z : prod_coprod C} (f : list_proj X Z) : list_proj (prod X Y) Z
| snd_comp {X Y Z : prod_coprod C} (f : list_proj Y Z) : list_proj (prod X Y) Z
inductive list_inj : (X Y : prod_coprod C) β Type -- X is not coprod
| empty {X : prod_coprod C} : list_inj X X
| comp_inl {X Y Z : prod_coprod C} (f : list_inj X Y) : list_inj X (coprod Y Z)
| comp_inr {X Y Z : prod_coprod C} (f : list_inj X Z) : list_inj X (coprod Y Z)
inductive norm_hom : prod_coprod C β prod_coprod C β Type
| prod_mk_of_cat {W : C} {X Y Z : prod_coprod C}
(f : norm_hom (of_cat' W) X) (g : norm_hom (of_cat' W) Y)
(h : list_inj (prod X Y) Z) :
norm_hom (of_cat' W) Z
| prod_mk_prod {V W X Y Z : prod_coprod C}
(f : norm_hom (prod V W) X) (g : norm_hom (prod V W) Y)
(h : list_inj (prod X Y) Z) :
norm_hom (prod V W) Z
| coprod_mk_of_cat {W X Y : prod_coprod C} {Z : C}
(f : list_proj W (coprod X Y))
(g : norm_hom X (of_cat' Z)) (h : norm_hom Y (of_cat' Z)) :
norm_hom W (of_cat' Z)
| coprod_mk_coprod {V W X Y Z : prod_coprod C}
(f : list_proj V (coprod W X))
(g : norm_hom W (coprod Y Z)) (h : norm_hom X (coprod Y Z)) :
norm_hom V (coprod Y Z)
| prod_mk_coprod {W X Y Z : prod_coprod C}
(f : norm_hom (coprod W X) Y) (g : norm_hom (coprod W X) Z) :
norm_hom (coprod W X) (prod Y Z)
| of_cat {W : prod_coprod C} {X Y : C} {Z : prod_coprod C}
(f : list_proj W (of_cat' X)) (g : X βΆ Y)
(h : list_inj (of_cat' Y) Z) : norm_hom W Z
namespace norm_hom
open list_inj list_proj
def prod_mk : {X Y Z : prod_coprod C} β (f : norm_hom X Y) β (g : norm_hom X Z) β
norm_hom X (prod Y Z)
| (of_cat' _), _, _, f, g => prod_mk_of_cat f g empty
| (coprod _ _), _, _, f, g => prod_mk_coprod f g
| (prod _ _), _ ,_, f, g => prod_mk_prod f g empty
def comp_fst : {X Y Z : prod_coprod C} β (f : norm_hom X (prod Y Z)) β norm_hom X Y
| _, _, _, (prod_mk_of_cat f _ list_inj.empty) => f
| _, _, _, (prod_mk_prod f _ list_inj.empty) => f
| _, _, _, (prod_mk_coprod f _) => f
@[simp] theorem comp_fst_prod_mk {X Y Z : prod_coprod C} (f : norm_hom X Y) (g : norm_hom X Z) :
comp_fst (prod_mk f g) = f :=
by cases X <;> simp [comp_fst, prod_mk]
def comp_snd : {X Y Z : prod_coprod C} β (f : norm_hom X (prod Y Z)) β norm_hom X Z
| _, _, _, (prod_mk_of_cat _ g list_inj.empty) => g
| _, _, _, (prod_mk_prod _ g list_inj.empty) => g
| _, _, _, (prod_mk_coprod _ g) => g
@[simp] theorem comp_snd_prod_mk {X Y Z : prod_coprod C} (f : norm_hom X Y) (g : norm_hom X Z) :
comp_snd (prod_mk f g) = g :=
by cases X <;> simp [comp_snd, prod_mk]
theorem prod_eta : {X Y Z : prod_coprod C} β (f : norm_hom X (prod Y Z)) β
prod_mk (comp_fst f) (comp_snd f) = f
| _, _, _, (prod_mk_of_cat _ _ list_inj.empty) => rfl
| _, _, _, (prod_mk_prod _ _ list_inj.empty) => rfl
| _, _, _, (prod_mk_coprod _ _) => rfl
theorem ext_prod {X Y Z : prod_coprod C} {f g : norm_hom X (prod Y Z)}
(hβ : f.comp_fst = g.comp_fst) (hβ : f.comp_snd = g.comp_snd) :
f = g :=
by rw [β prod_eta f, hβ, hβ, prod_eta]
def coprod_mk : {X Y Z : prod_coprod C} β (f : norm_hom X Z) β (g : norm_hom Y Z) β
norm_hom (coprod X Y) Z
| _, _, (of_cat' _), f, g => coprod_mk_of_cat empty f g
| _, _, (coprod _ _), f, g => coprod_mk_coprod empty f g
| _, _, (prod _ _), f, g => prod_mk_coprod
(coprod_mk (comp_fst f) (comp_fst g))
(coprod_mk (comp_snd f) (comp_snd g))
theorem coprod_mk_comp_fst {W X Y Z : prod_coprod C}
(f : norm_hom W (prod Y Z)) (g : norm_hom X (prod Y Z)) :
comp_fst (coprod_mk f g) = coprod_mk (comp_fst f) (comp_fst g) :=
by
cases Y <;>
simp [coprod_mk, comp_fst]
theorem coprod_mk_comp_snd {W X Y Z : prod_coprod C}
(f : norm_hom W (prod Y Z)) (g : norm_hom X (prod Y Z)) :
comp_snd (coprod_mk f g) = coprod_mk (comp_snd f) (comp_snd g) :=
by
intros
cases Y <;>
simp [coprod_mk, comp_snd]
def inl_comp : {X Y Z : prod_coprod C} β norm_hom (coprod X Y) Z β norm_hom X Z
| _, _, _, (coprod_mk_of_cat list_proj.empty g _) => g
| _, _, _, (coprod_mk_coprod list_proj.empty g _) => g
| _, _, _, prod_mk_coprod f g => prod_mk (inl_comp f) (inl_comp g)
def inr_comp : {X Y Z : prod_coprod C} β norm_hom (coprod X Y) Z β norm_hom Y Z
| _, _, _, (coprod_mk_of_cat list_proj.empty _ h) => h
| _, _, _, (coprod_mk_coprod list_proj.empty _ h) => h
| _, _, _, (prod_mk_coprod f g) => prod_mk (inr_comp f) (inr_comp g)
theorem inl_comp_comp_fst : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod W X) (prod Y Z)) β
inl_comp (comp_fst f) = comp_fst (inl_comp f)
| _, _, _, _, (prod_mk_coprod f g) => by
rw [inl_comp, comp_fst]
simp
theorem inr_comp_comp_fst : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod W X) (prod Y Z)) β
inr_comp (comp_fst f) = comp_fst (inr_comp f)
| _, _, _, _, (prod_mk_coprod f g) => by
rw [comp_fst, inr_comp]
simp
theorem inl_comp_comp_snd : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod W X) (prod Y Z)) β
inl_comp (comp_snd f) = comp_snd (inl_comp f)
| A, B, D, _, (prod_mk_coprod f g) => by
rw [comp_snd, inl_comp]
simp
theorem inr_comp_comp_snd : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod W X) (prod Y Z)) β
inr_comp (comp_snd f) = comp_snd (inr_comp f)
| _, _, _, _, (prod_mk_coprod f g) => by
rw [comp_snd, inr_comp]
simp
@[simp] theorem inl_comp_coprod_mk : {X Y Z : prod_coprod C} β (f : norm_hom X Z) β (g : norm_hom Y Z) β
inl_comp (coprod_mk f g) = f
| _, _, (of_cat' Z), _, _ => rfl
| _, _, (coprod Y Z), _, _ => rfl
| _, _, (prod Y Z), f, g =>
by rw [coprod_mk, inl_comp, inl_comp_coprod_mk, inl_comp_coprod_mk, prod_eta]
@[simp] theorem inr_comp_coprod_mk : {X Y Z : prod_coprod C} β (f : norm_hom X Z) β (g : norm_hom Y Z) β
inr_comp (coprod_mk f g) = g
| _, _, (of_cat' Z), _, _ => rfl
| _, _, (coprod Y Z), _, _ => rfl
| _, _, (prod Y Z), f, g =>
by rw [coprod_mk, inr_comp, inr_comp_coprod_mk, inr_comp_coprod_mk, prod_eta]
theorem coprod_eta : {X Y Z : prod_coprod C} β (f : norm_hom (coprod X Y) Z) β
coprod_mk (inl_comp f) (inr_comp f) = f
| _, _, _, (coprod_mk_of_cat list_proj.empty g h) => rfl
| _, _, _, (coprod_mk_coprod list_proj.empty g h) => rfl
| _, _, _, (prod_mk_coprod f g) =>
by simp [coprod_mk, inl_comp, inr_comp, coprod_eta f, coprod_eta g]
theorem ext_coprod {X Y Z : prod_coprod C} {f g : norm_hom (coprod X Y) Z}
(hβ : f.inl_comp = g.inl_comp) (hβ : f.inr_comp = g.inr_comp) :
f = g :=
by rw [β coprod_eta f, hβ, hβ, coprod_eta]
def prod_mk_l : {W X Y Z : prod_coprod C} β (f : norm_hom W X) β (g : norm_hom W Y) β
(h : list_inj (prod X Y) Z) β norm_hom W Z
| (of_cat' _), _, _, _, f, g, h => prod_mk_of_cat f g h
| (coprod _ _), _, _, _, f, g, h =>
coprod_mk
(prod_mk_l (inl_comp f) (inl_comp g) h)
(prod_mk_l (inr_comp f) (inr_comp g) h)
| (prod _ _), _, _, _, f, g, h => prod_mk_prod f g h
theorem coprod_mk_prod_mk_l {V W X Y Z : prod_coprod C}
(f : norm_hom V X) (g : norm_hom V Y)
(h : norm_hom W X) (i : norm_hom W Y)
(j : list_inj (prod X Y) Z) :
coprod_mk (prod_mk_l f g j) (prod_mk_l h i j) =
prod_mk_l (coprod_mk f h) (coprod_mk g i) j := by
cases X <;> cases Y <;> cases Z <;>
simp [coprod_mk, prod_mk_l, inl_comp, inr_comp, prod_eta]
def coprod_mk_l : {W X Y Z : prod_coprod C} β (f : list_proj W (coprod X Y)) β
(g : norm_hom X Z) β (h : norm_hom Y Z) β norm_hom W Z
| _, _, _, (of_cat' _), f, g, h => coprod_mk_of_cat f g h
| _, _, _, (prod _ _), f, g, h =>
prod_mk
(coprod_mk_l f (comp_fst g) (comp_fst h))
(coprod_mk_l f (comp_snd g) (comp_snd h))
| _, _, _, (coprod _ _), f, g, h => coprod_mk_coprod f g h
def fst_comp : {X Y Z : prod_coprod C} β
(f : norm_hom X Z) β norm_hom (prod X Y) Z
| _, _, _, (prod_mk_of_cat f g h) =>
prod_mk_l (fst_comp f) (fst_comp g) h
| _, _, _, (prod_mk_prod f g h) =>
prod_mk_l (fst_comp f) (fst_comp g) h
| _, _, _, (prod_mk_coprod f g) =>
prod_mk (fst_comp f) (fst_comp g)
| _, _, _, (coprod_mk_of_cat f g h) => coprod_mk_of_cat f.fst_comp g h
| _, _, _, (coprod_mk_coprod f g h) => coprod_mk_coprod f.fst_comp g h
| _, _, _, (of_cat f g h) => of_cat f.fst_comp g h
def snd_comp : {X Y Z : prod_coprod C} β
(f : norm_hom Y Z) β norm_hom (prod X Y) Z
| _, _, _, (prod_mk_of_cat f g h) =>
prod_mk_l (snd_comp f) (snd_comp g) h
| _, _, _, (prod_mk_prod f g h) =>
prod_mk_l (snd_comp f) (snd_comp g) h
| _, _, _, (prod_mk_coprod f g) =>
prod_mk (snd_comp f) (snd_comp g)
| _, _, _, (coprod_mk_of_cat f g h) => coprod_mk_of_cat f.snd_comp g h
| _, _, _, (coprod_mk_coprod f g h) => coprod_mk_coprod f.snd_comp g h
| _, _, _, (of_cat f g h) => of_cat f.snd_comp g h
theorem inl_comp_prod_mk_l : {V W X Y Z : prod_coprod C} β
(f : norm_hom (coprod V W) X) β (g : norm_hom (coprod V W) Y) β
(h : list_inj (prod X Y) Z) β
inl_comp (prod_mk_l f g h) = prod_mk_l (inl_comp f) (inl_comp g) h
| _, _, _, _, _, coprod_mk_of_cat list_proj.empty f g, coprod_mk_of_cat list_proj.empty h i, j => by
rw [inl_comp, inl_comp, prod_mk_l, inl_comp_coprod_mk, inl_comp, inl_comp]
| _, _, _, _, _, coprod_mk_of_cat list_proj.empty f g, coprod_mk_coprod list_proj.empty h i, j => by
rw [inl_comp, inl_comp, prod_mk_l, inl_comp_coprod_mk, inl_comp, inl_comp]
| _, _, _, _, _, coprod_mk_coprod list_proj.empty f g, coprod_mk_coprod list_proj.empty h i, j => by
rw [inl_comp, inl_comp, prod_mk_l, inl_comp_coprod_mk, inl_comp, inl_comp]
| _, _, _, _, _, coprod_mk_coprod list_proj.empty f g, coprod_mk_of_cat list_proj.empty h i, j => by
rw [inl_comp, inl_comp, prod_mk_l, inl_comp_coprod_mk, inl_comp, inl_comp]
| _, _, _, _, _, prod_mk_coprod f g, h, i => by
rw [inl_comp, prod_mk_l, inl_comp_coprod_mk, inl_comp]
| _, _, _, _, _, coprod_mk_coprod f g h, i, j => by
rw [prod_mk_l, inl_comp_coprod_mk]
| _, _, _, _, _, coprod_mk_of_cat f g h, i, j =>
by rw [prod_mk_l, inl_comp_coprod_mk]
theorem inr_comp_prod_mk_l : {V W X Y Z : prod_coprod C} β
(f : norm_hom (coprod V W) X) β (g : norm_hom (coprod V W) Y) β
(h : list_inj (prod X Y) Z) β
inr_comp (prod_mk_l f g h) = prod_mk_l (inr_comp f) (inr_comp g) h
| _, _, _, _, _, coprod_mk_of_cat list_proj.empty f g, coprod_mk_of_cat list_proj.empty h i, j => by
rw [inr_comp, inr_comp, prod_mk_l, inr_comp_coprod_mk, inr_comp, inr_comp]
| _, _, _, _, _, coprod_mk_of_cat list_proj.empty f g, coprod_mk_coprod list_proj.empty h i, j => by
rw [inr_comp, inr_comp, prod_mk_l, inr_comp_coprod_mk, inr_comp, inr_comp]
| _, _, _, _, _, coprod_mk_coprod list_proj.empty f g, coprod_mk_coprod list_proj.empty h i, j => by
rw [inr_comp, inr_comp, prod_mk_l, inr_comp_coprod_mk, inr_comp, inr_comp]
| _, _, _, _, _, coprod_mk_coprod list_proj.empty f g, coprod_mk_of_cat list_proj.empty h i, j => by
rw [inr_comp, inr_comp, prod_mk_l, inr_comp_coprod_mk, inr_comp, inr_comp]
| _, _, _, _, _, prod_mk_coprod f g, h, i => by
rw [inr_comp, prod_mk_l, inr_comp_coprod_mk, inr_comp]
| _, _, _, _, _, coprod_mk_coprod f g h, i, j => by
rw [prod_mk_l, inr_comp_coprod_mk]
| _, _, _, _, _, coprod_mk_of_cat f g h, i, j =>
by rw [prod_mk_l, inr_comp_coprod_mk]
theorem fst_comp_prod_mk_l : {V W X Y Z : prod_coprod C} β
(f : norm_hom W X) β (g : norm_hom W Y) β
(h : list_inj (prod X Y) Z) β
(fst_comp (prod_mk_l f g h) : norm_hom (prod W V) _) =
prod_mk_l f.fst_comp (fst_comp g) h
| _, of_cat' _, _, _, _, f, g, h => rfl
| _, coprod _ _, _, _, (of_cat' _), f, g, h => by
rw [prod_mk_l, prod_mk_l, coprod_mk, fst_comp, β inl_comp_prod_mk_l,
β inr_comp_prod_mk_l]
simp
| _, prod _ _, _, _, _, f, g, h => prod_mk_prod f g h
@[simp] def list_proj_comp : {X Y Z : prod_coprod C} β (f : list_proj X Y) β
(g : norm_hom Y Z) β norm_hom X Z
| _, _, _, list_proj.empty, g => g
| _, _, _, list_proj.fst_comp f, g => fst_comp (list_proj_comp f g)
| _, _, _, list_proj.snd_comp f, g => snd_comp (list_proj_comp f g)
@[simp] theorem list_proj_comp_coprod_mk_of_cat : {W X Y : prod_coprod C} β {Z : C} β
(f : list_proj W (coprod X Y)) β
(g : norm_hom X (of_cat' Z)) β (h : norm_hom Y (of_cat' Z)) β
list_proj_comp f (coprod_mk_of_cat empty g h) = coprod_mk_of_cat f g h
| _, _, _, _, list_proj.empty, _, _ => rfl
| _, _, _, _, (list_proj.fst_comp f), g, h =>
by rw [list_proj_comp, list_proj_comp_coprod_mk_of_cat, fst_comp]
| _, _, _, _, (list_proj.snd_comp f), g, h =>
by rw [list_proj_comp, list_proj_comp_coprod_mk_of_cat, snd_comp]
@[simp] theorem list_proj_comp_coprod_mk_coprod : {V W X Y Z : prod_coprod C} β
(f : list_proj V (coprod W X)) β
(g : norm_hom W (coprod Y Z)) β (h : norm_hom X (coprod Y Z)) β
list_proj_comp f (coprod_mk_coprod empty g h) = coprod_mk_coprod f g h
| _, _, _, _, _, list_proj.empty, _, _ => rfl
| _, _, _, _, _, (list_proj.fst_comp f), g, h =>
by rw [list_proj_comp, list_proj_comp_coprod_mk_coprod, fst_comp]
| _, _, _, _, _, (list_proj.snd_comp f), g, h =>
by rw [list_proj_comp, list_proj_comp_coprod_mk_coprod, snd_comp]
@[simp] theorem list_proj_comp_of_cat : {W : prod_coprod C} β {X Y : C} β {Z : prod_coprod C} β
(f : list_proj W (of_cat' X)) β (g : X βΆ Y) β
(h : list_inj (of_cat' Y) Z) β
list_proj_comp f (of_cat empty g h) = of_cat f g h
| _, _, _, _, list_proj.empty, _, _ => rfl
| _, _, _, _, (list_proj.fst_comp f), g, h =>
by rw [list_proj_comp, list_proj_comp_of_cat, fst_comp]
| _, _, _, _, (list_proj.snd_comp f), g, h =>
by rw [list_proj_comp, list_proj_comp_of_cat, snd_comp]
def comp_inl : {X Y Z : prod_coprod C} β
(f : norm_hom X Y) β norm_hom X (coprod Y Z)
| _, _, _, (coprod_mk_of_cat f g h) =>
coprod_mk_l f (comp_inl g) (comp_inl h)
| _, _, _, (coprod_mk_coprod f g h) =>
coprod_mk_l f (comp_inl g) (comp_inl h)
| _, _, _, (prod_mk_of_cat f g h) => prod_mk_of_cat f g h.comp_inl
| _, _, _, (prod_mk_prod f g h) => prod_mk_prod f g h.comp_inl
| _, _, _, (prod_mk_coprod f g) =>
prod_mk_l f g list_inj.empty.comp_inl
| _, _, _, (of_cat f g h) => of_cat f g h.comp_inl
def comp_inr : {X Y Z : prod_coprod C} β
(f : norm_hom X Z) β norm_hom X (coprod Y Z)
| _, _, _, (coprod_mk_of_cat f g h) =>
coprod_mk_l f (comp_inr g) (comp_inr h)
| _, _, _, (coprod_mk_coprod f g h) =>
coprod_mk_l f (comp_inr g) (comp_inr h)
| _, _, _, (prod_mk_of_cat f g h) => prod_mk_of_cat f g h.comp_inr
| _, _, _, (prod_mk_prod f g h) => prod_mk_prod f g h.comp_inr
| _, _, _, (prod_mk_coprod f g) =>
prod_mk_l f g list_inj.empty.comp_inr
| _, _, _, (of_cat f g h) => of_cat f g h.comp_inr
theorem inl_comp_comp_inl : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod W X) Y) β
(inl_comp (comp_inl f) : norm_hom W (coprod Y Z)) = comp_inl (inl_comp f)
| _, _, _, _, coprod_mk_of_cat list_proj.empty _ _ => rfl
| _, _, _, _, coprod_mk_coprod list_proj.empty _ _ => rfl
| W, _, _, _, prod_mk_coprod _ _ => by
rw [comp_inl, inl_comp, prod_mk_l, inl_comp_coprod_mk]
cases W <;> rfl
theorem inl_comp_comp_inr : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod W X) Z) β
(inl_comp (comp_inr f) : norm_hom W (coprod Y Z)) = comp_inr (inl_comp f)
| _, _, _, _, coprod_mk_of_cat list_proj.empty _ _ => rfl
| _, _, _, _, coprod_mk_coprod list_proj.empty _ _ => rfl
| W, _, _, _, prod_mk_coprod _ _ => by
rw [comp_inr, inl_comp, prod_mk_l, inl_comp_coprod_mk]
cases W <;> rfl
theorem inr_comp_comp_inl : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod X W) Y) β
(inr_comp (comp_inl f) : norm_hom W (coprod Y Z)) = comp_inl (inr_comp f)
| _, _, _, _, coprod_mk_of_cat list_proj.empty _ _ => rfl
| _, _, _, _, coprod_mk_coprod list_proj.empty _ _ => rfl
| W, _, _, _, prod_mk_coprod _ _ => by
rw [comp_inl, inr_comp, prod_mk_l, inr_comp_coprod_mk]
cases W <;> rfl
theorem inr_comp_comp_inr : {W X Y Z : prod_coprod C} β (f : norm_hom (coprod X W) Z) β
(inr_comp (comp_inr f) : norm_hom W (coprod Y Z)) = comp_inr (inr_comp f)
| _, _, _, _, coprod_mk_of_cat list_proj.empty _ _ => rfl
| _, _, _, _, coprod_mk_coprod list_proj.empty _ _ => rfl
| W, _, _, _, prod_mk_coprod _ _ => by
rw [comp_inr, inr_comp, prod_mk_l, inr_comp_coprod_mk]
cases W <;> rfl
theorem fst_comp_comp_inl : {W X Y Z : prod_coprod C} β (f : norm_hom W Y) β
(fst_comp (comp_inl f) : norm_hom (prod W X) (coprod Y Z)) = comp_inl (fst_comp f)
| _, _, _, _, coprod_mk_of_cat f g h => rfl
| _, _, _, _, coprod_mk_coprod f g h => rfl
| _, _, _, _, prod_mk_of_cat f g h => rfl
| _, _, _, _, prod_mk_prod f g h => rfl
| coprod A B, _, _, _, prod_mk_coprod f g => by
rw [comp_inl, fst_comp, prod_mk_l, prod_mk, comp_inl,
coprod_mk_prod_mk_l]
| _, _, _, _, of_cat f g h => rfl
protected def id : (X : prod_coprod C) β norm_hom X X
| (of_cat' X) => of_cat empty (π X) empty
| (prod X Y) => prod_mk (fst_comp (norm_hom.id X)) (snd_comp (norm_hom.id Y))
| (coprod X Y) => coprod_mk (comp_inl (norm_hom.id X)) (comp_inr (norm_hom.id Y))
@[simp] def comp_list_inj : {X Y Z : prod_coprod C} β (f : norm_hom X Y) β (g : list_inj Y Z) β
norm_hom X Z
| _, _, _, f, list_inj.empty => f
| _, _, _, f, list_inj.comp_inl g => comp_inl (comp_list_inj f g)
| _, _, _, f, list_inj.comp_inr g => comp_inr (comp_list_inj f g)
@[simp] theorem comp_list_inj_prod_mk_of_cat : {W : C} β {X Y Z : prod_coprod C} β
(f : norm_hom (of_cat' W) X) β (g : norm_hom (of_cat' W) Y) β
(h : list_inj (prod X Y) Z) β comp_list_inj (prod_mk_of_cat f g empty) h = prod_mk_of_cat f g h
| _, _, _, _, _, _, list_inj.empty => by simp [comp_list_inj]
| _, _, _, _, _, _, (list_inj.comp_inl h) =>
by rw [comp_list_inj, comp_list_inj_prod_mk_of_cat, comp_inl]
| _, _, _, _, _, _, (list_inj.comp_inr h) =>
by rw [comp_list_inj, comp_list_inj_prod_mk_of_cat, comp_inr]
@[simp] theorem comp_list_inj_prod_mk_prod : {V W X Y Z : prod_coprod C} β
(f : norm_hom (prod V W) X) β (g : norm_hom (prod V W) Y) β
(h : list_inj (prod X Y) Z) β
comp_list_inj (prod_mk_prod f g empty) h = prod_mk_prod f g h
| _, _, _, _, _, _, _, list_inj.empty => by simp
| _, _, _, _, _, _, _, (list_inj.comp_inl h) =>
by rw [comp_list_inj, comp_list_inj_prod_mk_prod, comp_inl]
| _, _, _, _, _, _, _, (list_inj.comp_inr h) =>
by rw [comp_list_inj, comp_list_inj_prod_mk_prod, comp_inr]
@[simp] theorem comp_list_inj_of_cat : {W : prod_coprod C} β {X Y : C} β {Z : prod_coprod C} β
(f : list_proj W (of_cat' X)) β (g : X βΆ Y) β
(h : list_inj (of_cat' Y) Z) β
comp_list_inj (of_cat f g empty) h = of_cat f g h
| _, _, _, _, _, _, list_inj.empty => rfl
| _, _, _, _, _, _, (list_inj.comp_inl h) =>
by rw [comp_list_inj, comp_list_inj_of_cat, comp_inl]
| _, _, _, _, _, _, (list_inj.comp_inr h) =>
by rw [comp_list_inj, comp_list_inj_of_cat, comp_inr]
def get_proj_of_cat : {X Y : prod_coprod C} β {Z : C} β
(f : norm_hom (prod X Y) (of_cat' Z)) β
norm_hom X (of_cat' Z) β norm_hom Y (of_cat' Z)
| _, _, _, (coprod_mk_of_cat (list_proj.fst_comp f) g h) =>
Sum.inl (coprod_mk_of_cat f g h)
| _, _, _, (coprod_mk_of_cat (list_proj.snd_comp f) g h) =>
Sum.inr (coprod_mk_of_cat f g h)
| _, _, _, (of_cat (list_proj.fst_comp f) g h) =>
Sum.inl (of_cat f g h)
| _, _, _, (of_cat (list_proj.snd_comp f) g h) =>
Sum.inr (of_cat f g h)
def get_inj_of_cat : {X : C} β {Y Z : prod_coprod C} β
(f : norm_hom (of_cat' X) (coprod Y Z)) β
norm_hom (of_cat' X) Y β norm_hom (of_cat' X) Z
| _, _, _, (prod_mk_of_cat f g (list_inj.comp_inl h)) =>
Sum.inl (prod_mk_of_cat f g h)
| _, _, _, (prod_mk_of_cat f g (list_inj.comp_inr h)) =>
Sum.inr (prod_mk_of_cat f g h)
| _, _, _, (of_cat f g (list_inj.comp_inl h)) =>
Sum.inl (of_cat f g h)
| _, _, _, (of_cat f g (list_inj.comp_inr h)) =>
Sum.inr (of_cat f g h)
end norm_hom
inductive norm_hom2 : (X Y : prod_coprod C) β Type
| of_cat {X Y : C} (f : X βΆ Y) : norm_hom2 (of_cat' X) (of_cat' Y)
| coprod_mk {X Y Z : prod_coprod C} (f : norm_hom2 X Z) (g : norm_hom2 Y Z) :
norm_hom2 (X.coprod Y) Z
| comp_inl {X Y Z : prod_coprod C} (f : norm_hom2 X Y) :
norm_hom2 X (coprod Y Z)
| comp_inr {X Y Z : prod_coprod C} (f : norm_hom2 X Z) :
norm_hom2 X (coprod Y Z)
| prod_mk {X Y Z : prod_coprod C} (f : norm_hom2 X Y) (g : norm_hom2 X Z) :
norm_hom2 X (prod Y Z)
| fst_comp {X Y Z : prod_coprod C} (f : norm_hom2 X Z) :
norm_hom2 (prod X Y) Z
| snd_comp {X Y Z : prod_coprod C} (f : norm_hom2 Y Z) :
norm_hom2 (prod X Y) Z
namespace norm_hom2
@[simp] def list_proj_comp : {X Y Z : prod_coprod C} β (f : list_proj X Y) β
(g : norm_hom2 Y Z) β norm_hom2 X Z
| _, _, _, list_proj.empty, g => g
| _, _, _, list_proj.fst_comp f, g => fst_comp (list_proj_comp f g)
| _, _, _, list_proj.snd_comp f, g => snd_comp (list_proj_comp f g)
@[simp] def comp_list_inj : {X Y Z : prod_coprod C} β (f : norm_hom2 X Y) β (g : list_inj Y Z) β
norm_hom2 X Z
| _, _, _, f, list_inj.empty => f
| _, _, _, f, list_inj.comp_inl g => comp_inl (comp_list_inj f g)
| _, _, _, f, list_inj.comp_inr g => comp_inr (comp_list_inj f g)
end norm_hom2
@[simp] def norm_hom.to_norm_hom2 : {X Y : prod_coprod C} β (f : norm_hom X Y) β norm_hom2 X Y
| _, _, (norm_hom.of_cat f g h) => (norm_hom2.list_proj_comp f (norm_hom2.of_cat g)).comp_list_inj h
| _, _, (norm_hom.prod_mk_of_cat f g h) =>
norm_hom2.comp_list_inj (norm_hom2.prod_mk (to_norm_hom2 f) (to_norm_hom2 g)) h
| _, _, (norm_hom.prod_mk_prod f g h) =>
norm_hom2.comp_list_inj (norm_hom2.prod_mk (to_norm_hom2 f) (to_norm_hom2 g)) h
| _, _, (norm_hom.prod_mk_coprod f g) =>
norm_hom2.prod_mk (to_norm_hom2 f) (to_norm_hom2 g)
| _, _, (norm_hom.coprod_mk_of_cat f g h) =>
norm_hom2.list_proj_comp f (norm_hom2.coprod_mk (to_norm_hom2 g) (to_norm_hom2 h))
| _, _, (norm_hom.coprod_mk_coprod f g h) =>
norm_hom2.list_proj_comp f (norm_hom2.coprod_mk (to_norm_hom2 g) (to_norm_hom2 h))
@[simp] def norm_hom2.to_norm_hom : {X Y : prod_coprod C} β (f : norm_hom2 X Y) β norm_hom X Y
| _, _, (norm_hom2.of_cat f) => norm_hom.of_cat list_proj.empty f list_inj.empty
| _, _, (norm_hom2.comp_inl f) => norm_hom.comp_inl (to_norm_hom f)
| _, _, (norm_hom2.comp_inr f) => norm_hom.comp_inr (to_norm_hom f)
| _, _, (norm_hom2.fst_comp f) => norm_hom.fst_comp (to_norm_hom f)
| _, _, (norm_hom2.snd_comp f) => norm_hom.snd_comp (to_norm_hom f)
| _, _, (norm_hom2.prod_mk f g) => norm_hom.prod_mk (to_norm_hom f) (to_norm_hom g)
| _, _, (norm_hom2.coprod_mk f g) => norm_hom.coprod_mk (to_norm_hom f) (to_norm_hom g)
@[simp] theorem to_norm_hom_list_proj_comp {X Y Z : prod_coprod C} (f : list_proj X Y) (g : norm_hom2 Y Z) :
(norm_hom2.list_proj_comp f g).to_norm_hom = g.to_norm_hom.list_proj_comp f :=
by induction f <;> simp [*]
@[simp] theorem to_norm_hom_comp_list_inj {X Y Z : prod_coprod C} (f : norm_hom2 X Y) (g : list_inj Y Z) :
(norm_hom2.comp_list_inj f g).to_norm_hom = f.to_norm_hom.comp_list_inj g :=
by induction g <;> simp [*]
def norm_hom2.size : {X Y : prod_coprod C} β norm_hom2 X Y β Nat
| _, _, (norm_hom2.of_cat _) => 0
| _, _, (norm_hom2.comp_inl f) => size f + 1
| _, _, (norm_hom2.comp_inr f) => size f + 1
| _, _, (norm_hom2.fst_comp f) => size f + 1
| _, _, (norm_hom2.snd_comp f) => size f + 1
| _, _, (norm_hom2.prod_mk f g) => size f + size g + 1
| _, _, (norm_hom2.coprod_mk f g) => size f + size g + 1
def norm_hom2.comp : {X Y Z : prod_coprod C} β
norm_hom2 X Y β norm_hom2 Y Z β norm_hom2 X Z
| _, _, _, fst_comp f, g => (comp f g).fst_comp
| _, _, _, snd_comp f, g => (comp f g).snd_comp
| _, _, _, coprod_mk f g, h => coprod_mk (comp f h) (comp g h)
| _, _, _, of_cat f, of_cat g => of_cat (f β« g)
| _, _, _, comp_inl f, coprod_mk g _ => comp f g
| _, _, _, comp_inr f, coprod_mk _ h => comp f h
| _, _, _, f, comp_inl g => (comp f g).comp_inl
| _, _, _, f, comp_inr g => (comp f g).comp_inr
| _, _, _, f, prod_mk g h => prod_mk (comp f g) (comp f h)
| _, _, _, prod_mk f _, fst_comp h => comp f h
| _, _, _, prod_mk _ g, snd_comp h => comp g h
termination_by comp X Y Z f g => (X.size, Y.size, Z.size)
theorem to_norm_hom_to_norm_hom2 {X Y : prod_coprod C} (f : norm_hom X Y) :
f.to_norm_hom2.to_norm_hom = f :=
by induction f <;> simp [norm_hom.to_norm_hom2, norm_hom2.to_norm_hom, *,
norm_hom.prod_mk, norm_hom.coprod_mk]
@[simp] theorem comp_fst_comp {W X Y Z : prod_coprod C} (f : norm_hom2 W Y)
(g : norm_hom2 Y Z) : (f.fst_comp.comp g : norm_hom2 (prod W X) Z).to_norm_hom =
(f.comp g).to_norm_hom.fst_comp := by
rw [norm_hom2.comp, norm_hom2.to_norm_hom]
@[simp] theorem comp_snd_comp {W X Y Z : prod_coprod C} (f : norm_hom2 X Y)
(g : norm_hom2 Y Z) : (f.snd_comp.comp g : norm_hom2 (prod W X) Z).to_norm_hom =
(f.comp g).to_norm_hom.snd_comp := by
rw [norm_hom2.comp, norm_hom2.to_norm_hom]
@[simp] theorem coprod_mk_comp {W X Y Z : prod_coprod C} (f : norm_hom2 W Y)
(g : norm_hom2 X Y) (h : norm_hom2 Y Z) :
((f.coprod_mk g).comp h).to_norm_hom = ((f.comp h).coprod_mk (g.comp h)).to_norm_hom := by
rw [norm_hom2.comp, norm_hom2.to_norm_hom]
@[simp] theorem comp_inl_comp_coprod_mk {W X Y Z : prod_coprod C} (f : norm_hom2 W X)
(g : norm_hom2 X Z) (h : norm_hom2 Y Z) :
(f.comp_inl.comp (g.coprod_mk h)).to_norm_hom = (f.comp g).to_norm_hom := by
rw [norm_hom2.comp]
@[simp] theorem comp_inr_comp_coprod_mk {W X Y Z : prod_coprod C} (f : norm_hom2 W Y)
(g : norm_hom2 X Z) (h : norm_hom2 Y Z) :
(f.comp_inr.comp (g.coprod_mk h)).to_norm_hom = (f.comp h).to_norm_hom := by
rw [norm_hom2.comp]
@[simp] theorem HEq_Iff_Eq {Ξ± : Sort _} {a b : Ξ±} : HEq a b β a = b := by
apply Iff.intro
intro h
cases h
rfl
intro h
cases h
exact HEq.refl _
@[simp] theorem comp_comp_inl {W X Y Z : prod_coprod C} (f : norm_hom2 W X)
(g : norm_hom2 X Y) : (f.comp g.comp_inl : norm_hom2 W (coprod Y Z)).to_norm_hom =
(f.comp g).to_norm_hom.comp_inl := by
induction f with
| of_cat f => rw [norm_hom2.comp, norm_hom2.to_norm_hom] <;> simp
| coprod_mk f h ihβ ihβ =>
rw [norm_hom2.comp, norm_hom2.to_norm_hom, ihβ, ihβ,
norm_hom2.comp, norm_hom2.to_norm_hom]
apply norm_hom.ext_coprod
rw [norm_hom.inl_comp_coprod_mk, norm_hom.inl_comp_comp_inl,
norm_hom.inl_comp_coprod_mk]
rw [norm_hom.inr_comp_coprod_mk, norm_hom.inr_comp_comp_inl,
norm_hom.inr_comp_coprod_mk]
| comp_inl f ih =>
rw [norm_hom2.comp, norm_hom2.to_norm_hom]
intros X Y f h
cases h
simp
intros X Y f h
cases h
simp
intros X Y f h
cases h
simp
intro h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
| comp_inr f ih =>
rw [norm_hom2.comp, norm_hom2.to_norm_hom]
intros X Y f h
cases h
simp
intros X Y f h
cases h
simp
intros X Y f h
cases h
simp
intro h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
| prod_mk f h =>
rw [norm_hom2.comp, norm_hom2.to_norm_hom]
intros X Y f h
cases h
simp
intros X Y f h
cases h
simp
intros X Y f h
cases h
simp
intro h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
intros h
cases h
simp
| fst_comp f ih =>
rw [norm_hom2.comp, norm_hom2.to_norm_hom, ih, norm_hom2.comp,
norm_hom2.to_norm_hom]
theorem norm_hom2.comp_assoc : {W X Y Z : prod_coprod C} β
(f : norm_hom2 W X) β (g : norm_hom2 X Y) β (h : norm_hom2 Y Z) β
((f.comp g).comp h).to_norm_hom =
(f.comp (g.comp h)).to_norm_hom
| _, _, _, _, fst_comp f, g, h => by
rw [comp, comp, comp, to_norm_hom, comp_assoc, to_norm_hom]
| _, _, _, _, snd_comp f, g, h => by
rw [comp, comp, comp, to_norm_hom, comp_assoc, to_norm_hom]
| _, _, _, _, coprod_mk f g, h, i => by
rw [comp, comp, comp, to_norm_hom, comp_assoc, to_norm_hom, comp_assoc]
| _, _, _, _, prod_mk f _, fst_comp h, i => by
rw [comp, comp, comp, comp_assoc]
| _, _, _, _, prod_mk f _, snd_comp h, i => by
rw [comp, comp, comp, comp_assoc]
| _, _, _, _, prod_mk _ _, prod_mk _ _, fst_comp _ => by
rw [comp, comp, comp, comp_assoc] <;>
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LaTeX Template: Project Titlepage Modified (v 0.1) by rcx
%
% Original Source: http://www.howtotex.com
% Date: November 2017
%
% This is a title page template which be used for articles & reports.
%
% This is the modified version of the original Latex template from
% aforementioned website.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[12pt]{report}
\usepackage[a4paper]{geometry}
\usepackage[myheadings]{fullpage}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx, wrapfig, subcaption, setspace, booktabs}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{fourier}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage[english]{babel}
\usepackage{sectsty}
\usepackage{url, lipsum}
\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\onehalfspacing{}
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}
%-------------------------------------------------------------------------------
% HEADER & FOOTER
%-------------------------------------------------------------------------------
\pagestyle{fancy}
\fancyhf{}
\setlength\headheight{15pt}
\fancyhead[L]{Student ID\@: 101006753}
\fancyhead[R]{Carleton University}
\fancyfoot[R]{Page \thepage\ of~\pageref{LastPage}}
%-------------------------------------------------------------------------------
% TITLE PAGE
%-------------------------------------------------------------------------------
\begin{document}
\title{ \HRule{0.5pt} \\
\LARGE \textbf{\uppercase{Proof on the Uniqueness of the Sicherman dice}}
\HRule{2pt} \\ [0.5cm]
\normalsize \today \vspace*{5\baselineskip}}
\date{}
\author{
Name: Robert Lech \\
Student ID\@: 101006753 \\
Carleton University \\
Department of Mathematics }
\maketitle
%-------------------------------------------------------------------------------
% Section title formatting
\sectionfont{\scshape}
%-------------------------------------------------------------------------------
%-------------------------------------------------------------------------------
% BODY
%-------------------------------------------------------------------------------
\section*{Introduction}
Often times, the jump from the abstract to the real-life application is what makes a proof so interesting. We
commonly use number theory and group theory to prove properties of encryption methods. We use the
representation theory of finite groups to infer structural information about molecules in chemistry. Lastly,
we note that problems in discrete probability rely heavily on techniques developed in combinatorics.
Generally, it's the ability to connect the real-world problems to questions in mathematics is what really
allows us to properly tackle them in systematic, and sometimes simple, ways. For the purposes of our paper, we
attempt to do exactly this to a well-known question in probability.
In this paper, we pose the problem, ``Suppose we have a pair of 1 to 6 dice. What other pair\@(s) of dice are
there that provide the same probability distribution?'' Suppose we had a die labelled, $1,2,2,3,3,4$ and
another labelled $1,3,4,5,6,8$. It's clear from Figure~\ref{fig:wikipedia_table} that there is 1 way for a
pair of dice to be rolled and produce a sum of 2, 2 ways to produce a sum of 3, and so on. Now, suppose we
have a different pair of dice. Therefore, we can conclude that both pairs of dice have the same probability
distribution when rolled. However, what's not as immediately clear is that this odd pair of dice (now called
the \textit{Sicherman dice}) is the only other pair of 6-sided dice, with positive labels, with this exact
probability distribution.
\begin{figure}[h]
\includegraphics[width=\linewidth]{images/wikipedia_table.png}
\caption{A table showing that the probability distribution of both dice are the same.}
\label{fig:wikipedia_table}
\end{figure}
We'll prove this by employing the Unique Factorization Theorem. After this, we'll then apply this to three
other scenarios: a scenario with two tetrahedral dice, a scenario with three cubic dice, and a scenario with
two octahedral dice. We then conclude by restating just how powerful and general this technique is.
%-------------------------------------------------------------------------------
% Background Information
%-------------------------------------------------------------------------------
\section*{Background Information}
In this section, we state all the algebraic definitions necessary. We start from the very beginning and work
our way forward. We let $G$ be a set together with a binary operation which assigns an ordered pair $(a,b)$ of
elements in $G$ to an element denoted $ab$. We say $G$ is a group under this operation if the following three
properties are satisfied: associativity, the existence of an identity element, and for each element, the
existence of an inverse of that element. Moreover, a group is \textit{Abelian} if the elements commute. We now
build upon this notion of a group by introducing our definition of a \textit{ring}. A \textit{ring} is a set
with two binary operations, addition (denoted by $(a+b)$) and multiplication (denoted $ab$) such that a ring
forms an Abelian group under addition and having an associative multiplication that is left and right
distributive over addition. When a ring contains an identity element under multiplication, we call it the
\textit{unity}. We take a step forward and define an \textit{integral domain} is a commutative ring with unity
and no \textit{zero-divisors}; that is, no non-zero elements $a,b$ such that $ab=0$. Lastly, we say that if a
non-zero element of a ring has a multiplicative inverse, we say that it is a \textit{unit}.
We now introduce our rings of interest. Let $R$ be a commutative ring. Then
$R[x]=\{ a_{n}x + \cdots + a_{0} | a_{i}\in R\}$ is called the \textit{ring of polynomials over $R$ in the
indeterminate $x$}. We're interested in $Z[x]$ under ordinary addition and multiplication, which is known to
be an integral domain since $Z$ is an integral domain. From this definition, we can define a particular type
of polynomial. Let $D$ be an integral domain. Let $f(x)\in D[x]$ be a non-zero or non-unit over $D[x]$. If for
every $f(x)=g(x)h(x)$, either $g(x)$ or $h(x)$ is unit, then $f(x)$ is \textit{irreducible}. Otherwise, it's
\textit{reducible}. With all these definitions in place, we introduce the final ingredient we'll need to prove
the uniqueness of the Sicherman dice. This is the \textit{Unique Factorization Theorem} which claims that
every polynomial in $Z[x]$ can be factored into the form
$b_{1}b_{2}\ldots b_{s}p_{1}(x)p_{2}(x)\ldots p_{m}(x)$ where $b_{i}$'s are irreducible polynomials of degree
$0$ and $p_{i}(x)$'s are irreducible polynomials of positive degree. Moreover, this factorization is unique
(which the only differences being that another factoring my have different signs in front of each polynomial).
With this all in place, we're ready to tackle our problem.
%-------------------------------------------------------------------------------
% THE PROBLEM
%-------------------------------------------------------------------------------
\section*{The Problem}
To begin the proof, we find a correspondence between summing dice and polynomials. We note that two dice
having a sum of 6 would imply the dice being rolled had values (5,1), (4,2), (3,3), (2,4), or (1,5). Now
suppose we look at $R(x)R(x)=(x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1})(x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1})$. We
observe that to pick the term $x^{6}$ in this product, we have to choose them in the following ways:
$x^{5}x^{1}$, $x^{4}x^{2}$, $x^{3}x^{3}$, $x^{2}x^{4}$, or $x^{1}x^{5}$. So there is a clear correspondence
here between the labels of dice whose sum is 6, and the pairs of terms whose products are six. This
correspondence is one to one (that is, any two dice with the same same should have the same correspondence).
Moreover, it's valid for all sums and dice -- including the Sicherman dice and any other potential dice (of
course, we'll show there aren't any others). We'll do this using a constructive argument, of sorts.
Suppose we have two sequences: $A=$ $a_{1}$, $a_{2}$, $a_{3}$, $a_{4}$, $a_{5}$, $a_{6}$ and $B=$ $b_{1}$,
$b_{2}$, $b_{3}$, $b_{4}$, $b_{5}$, $b_{6}$. Let these be the two sequences of positive integer labels for the
faces of pairs of cubes with the property that the probability of rolling any particular sum with these dice
(we'll call them \textit{weird dice}) is the same probability of rolling that sum with ordinary dice labelled
1 through 6. Therefore, as an example, we should also be able to choose 5 tuples $(a_{i_{1}}, b_{j_{1}})$,
$(a_{i_{2}}, b_{j_{2}})$, $(a_{i_{3}}, b_{j_{3}})$, $(a_{i_{4}}, b_{j_{4}})$, $(a_{i_{5}}, b_{j_{5}})$, such
that $a_{i_{s}} \in A$ and $b_{j_{t}} \in B$. Moreover, we should have that the product of two polynomials
$P(x)Q(x)=(x^{a_{6}}+x^{a_{5}}+x^{a_{4}}+x^{a_{3}}+x^{a_{2}}+x^{a_{1}})
(x^{b_{6}}+x^{b_{5}}+x^{b_{4}}+x^{b_{3}}+x^{b_{2}}+x^{b_{1}})$
should give us 5 pairs of terms who whose products is also $x^{6}$. Therefore, we can assume
$(R(x))^{2}=P(x)Q(x)$.
Therefore, now that we're done setting up the equation, we can focus on solving for the possible $a$'s and
$b$'s. We note from the Unique Factorization Theorem that our polynomial factors uniquely like so:
$x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1} = (x)(x+1)(x^{2}+x+1)(x^{2}-x+1)$ and so
$(x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1})^2 = (x)^{2}(x+1)^{2}(x^{2}+x+1)^{2}(x^{2}-x+1)^{2}$. However, this
implies $P(x)=(x)^{q}(x+1)^{r}(x^{2}+x+1)^{t}(x^{2}-x+1)^{u}$ where $0\leq q,r,t,u \leq 2$. The bounds are
there because the exponents can't possibly be negative, and $P(x)$ can't possibly introduce more of the same
irreducible polynomials then $(R(x))^2$ introduced.
We now restrict the possibilities for these four parameters by evaluating $P(0)$ and $P(1)$ in two ways.
Firstly, note $P(1)=1^{a_{6}}+1^{a_{5}}+1^{a_{4}}+1^{a_{3}}+1^{a_{2}}+1^{a_{1}}=6$. Moreover,
$P(1)=1^{q}2^{r}3^{t}1^{u}=2^{r}3^{t} \stackrel{!}{=} 6$. Therefore, $r=t=1$. So we have that
$P(x)=(x)^{q}(x+1)(x^{2}+x+1)(x^{2}-x+1)^{u}$. Now, we similarly note that
$P(0)=0^{a_{6}}+0^{a_{5}}+0^{a_{4}}+0^{a_{3}}+0^{a_{2}}+0^{a_{1}}=0$. Moreover,
$P(0)=0^{q}*1*1*1^{u} \stackrel{!}{=} 0$. This implies $q \neq 0$. Now, we'd like to show that $q$ cannot be
2. Suppose, for a contradiction, $q=2$ and $u=0$. Then
$P(x)=(x)^{2}(x+1)(x^{2}+x+1)=x^{5}+2x^{4}+2x^{3}+x^{2}$. That is, the first die should be labelled
$5,4,4,3,3,2$. This implies $Q(x)=(x+1)(x^{2}+x+1)(x^{2}-x+1)^{2}=x^{7}+x^{5}+x^{4}+x^{3}+x^{2}+x^{0}$ and so
the second die should be labelled $7,5,4,3,2,0$. However, we disallow labels of $0$ so this is not allowed.
This occurs similarly for when $u\in \{1,2\}$. Therefore, $q$ cannot be $2$, and so $q=1$. Therefore, we have
that $q=r=t=1$ and $u\in \{0,1,2\}$. So let's not consider the possibilities:
\begin{enumerate}
\item Suppose $u=0$. Then $P(x)=(x)(x+1)(x^{2}+x+1)=x^{4}+2x^{3}+2x^{2}+x^{1}$ and so the die labels are $4,3,3,2,2,1$ -- a Sicherman die.
\item Suppose $u=1$. Then $P(x)=(x)(x+1)(x^{2}+x+1)(x^{2}-x+1)=x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1}$ and so the die labels are $6,5,4,3,2,1$ -- an ordinary die.
\item Suppose $u=2$. Then $P(x)=(x)(x+1)(x^{2}+x+1)(x^{2}-x+1)^{2}=x^{8}+x^{6}+x^{5}+x^{4}+x^{3}+x^{1}$ and so the die labels are $8,6,5,4,3,1$ -- the other Sicherman die.
\end{enumerate}
Therefore, choose $P(x)$ such that $q=r=t=1$ and $u=0$ and $Q(x)$ such that $q=r=t=1$ and $u=2$. Then these
represent dice with the same probability distribution of an ordinary pair of dice. Moreover, this shows that
the Sicherman dice are the \textit{only} other pair of dice that have this property.
%-------------------------------------------------------------------------------
% ADDITIONAL APPLICATIONS
%-------------------------------------------------------------------------------
\section*{Additional Applications}
We can use this same approach to see what other `weird dice' we can create. We'll tackle this in three
different scenarios: a scenario with two tetrahedral dice, a scenario with three cubic dice, and a scenario
with two octahedral dice.
\subsection*{Weird Tetrahedral Dice}
We start with a pair of tetrahedrons labelled $1,2,3,4$. We'll use the same approach by denoting
$P(x)Q(x)=(x^{a_{4}}+x^{a_{3}}+x^{a_{2}}+x^{a_{1}})
(x^{b_{4}}+x^{b_{3}}+x^{b_{2}}+x^{b_{1}})=(x^{4}+x^{3}+x^{2}+x^{1})^{2}=(x)^{2}(x+1)^{2}(x^{2}+1)^{2}$.
Therefore, we need to solve for $P(x)=(x)^{q}(x+1)^{r}(x^{2}+1)^{s}$ for $q,r,s \in \{0,1,2\}$. We note that
$P(0)=0^{a_{4}}+0^{a_{3}}+0^{a_{2}}+0^{a_{1}}=0$ and $P(0)=(0)^{q}(1)^{r}(1)^{s} \stackrel{!}{=} 0$ which
implies $q \neq 0$. As with the case before, $q=2$ implies we must have a 0 label on the other die, which we
disallow. There, $q=1$. For the second case, we have $P(1)=1^{a_{4}}+1^{a_{3}}+1^{a_{2}}+1^{a_{1}}=4$ and
$P(1)=(1)^{1}(2)^{r}(2)^{s} \stackrel{!}{=} 4 \Rightarrow 2^{r+s}=2^{2} \Rightarrow r+s=2$. Therefore, have
that $s=2-r$ gives us 3 valid dice.
\begin{enumerate}
\item Suppose $r=0$. Then $P(x)=(x)(x+1)(x^{2}+1)=x^{3}+2x^{2}+x^{1}$ and so the die labels are $3,2,2,1$ -- one weird die.
\item Suppose $r=1$. Then $P(x)=(x)(x+1)(x^{2}+1)=x^{4}+x^{3}+x^{2}+x^{1}$ and so the die labels are $4,3,2,1$ -- an ordinary tetrahedral die.
\item Suppose $r=2$. Then $P(x)=(x)(x+1)(x^{2}+1)=x^{5}+2x^{3}+x^{1}$ and so the die labels are $5,3,3,1$ -- another weird die.
\end{enumerate}
Therefore, choose $P(x)$ such that $q=1$, $r=0$, and $s=2$ and $Q(x)$ such that $q=1$, $r=2$, and $s=0$. Then
these represent dice with labels $3,2,2,1$ and $5,3,3,1$ such that they have the same probability distribution
as that of an ordinary pair of tetrahedral dice. Moreover, this shows that the `weird dice' are the
\textit{only} other pair of tetrahedral dice that have this property.
\subsection*{Weird Triples of Cubic Dice}
We now tackle the question: are there combinations of 3 dice that have the same probability distribution as 3
cubes numbered $1,2,3,4,5,6$? The answer is yes and the approach is almost identical to what we did in the
previous section. We let
$\prod_{i=1}^{3} P_{i}=\prod_{i=1}^{3}(x^{a_{i,6}}+x^{a_{i,5}}+x^{a_{i,4}}+x^{a_{i,3}}+x^{a_{i,2}}+x^{a_{i,1}})=(x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1})^{3}=((x)(x+1)(x^{2}+x+1)(x^{2}-x+1))^{3}$.
Therefore, we're aiming to solve $P(x)=(x)^{q}(x+1)^{r}(x^{2}+x+1)^{t}(x^{2}-x+1)^{u}$ where
$0\leq q,r,t,u\leq 3$. However, for the exact same reasons as before, evaluating $P(1)$ tells us the $r,t=1$
and evaluating $P(0)$ tells us the $q \neq 0$. We note that setting $q=2,3$ demands at least one of our two
remaining dice have a 0 label, which we disallow. Therefore, $q=1$. What remains is our choice for $u$?
\begin{enumerate}
\item Suppose $u=0$. Then $P(x)=(x)(x+1)(x^{2}+x+1)=x^{4}+2x^{3}+2x^{2}+x^{1}$ and so the die labels are $4,3,3,2,2,1$ -- a Sicherman die.
\item Suppose $u=1$. Then $P(x)=(x)(x+1)(x^{2}+x+1)(x^{2}-x+1)=x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1}$ and so the die labels are $6,5,4,3,2,1$ -- an ordinary die.
\item Suppose $u=2$. Then $P(x)=(x)(x+1)(x^{2}+x+1)(x^{2}-x+1)^{2}=x^{8}+x^{6}+x^{5}+x^{4}+x^{3}+x^{1}$ and so the die labels are $8,6,5,4,3,1$ -- the other Sicherman die.
\item Suppose $u=3$. Then $P(x)=(x)(x+1)(x^{2}+x+1)(x^{2}-x+1)^{3}=x^{10}-x^{9}+2x^{8}+x^{6}+x^{5}+2x^{3}-x^{2}+x^{1}$. However, this is not of the form $x^{a_{1,6}}+x^{a_{1,5}}+x^{a_{1,4}}+x^{a_{1,3}}+x^{a_{1,2}}+x^{a_{1,1}}$ where $x^{a_{i,j}} \in \{1,2,\ldots\}$. Therefore, this case is impossible.
\end{enumerate}
Therefore, choose, this allows us to choose two triples of dice: either (a) a pair of Sicherman dice and 1 regular die, or (b) 3 regular dice.
\subsection*{Weird Octahedral Dice}
Lastly, we tackle the question: are there pairs of octahedral dice that have the same probability distribution
as octahedral dice numbered $1,2,3,4,5,6,7,8$? The answer is yes and the approach is almost identical to what
we did in the previous section -- with slightly more work. If we jump ahead, we have our
$R(x)=\sum_{i=1}^{8} x^{i}=(x)(x+1)(x^{2}+1)(x^{4}+1)$. Therefore, our $P(x)$ should be of the form
$(x)^{q}(x+1)^{r}(x^{2}+1)^{t}(x^{4}+1)^{u}$ such that $q,r,t,u \in \{0,1,2\}$. Our usual tricks tell us
$q=1$. However, evaluating $P(1)$ gives us $r+t+u=3$. Therefore, we have 7 choices for $r$, $t$, and $u$.
\begin{enumerate}
\item Suppose $r=0$, $t=1$, and $u=2$. Then $(x)^{1}(x+1)^{0}(x^{2}+1)^{1}(x^{4}+1)^{2}=x^{11}+x^{9}+2x^{7}+2x^{5}+x^{3}+x^{1}$ and so the die labels are $11,9,7,7,5,5,3,1$ -- a weird die
\item Suppose $r=0$, $t=2$, and $u=1$. Then $(x)^{1}(x+1)^{0}(x^{2}+1)^{2}(x^{4}+1)^{1}=x^{9}+2x^{7}+2x^{5}+2x^{3}+x^{1}$ and so the die labels are $9,7,7,5,5,3,3,1$ -- a weird die
\item Suppose $r=1$, $t=0$, and $u=2$. Then $(x)^{1}(x+1)^{1}(x^{2}+1)^{0}(x^{4}+1)^{2}=x^{10}+x^{9}+2x^{6}+2x^{5}+x^{2}+x^{1}$ and so the die labels are $10,9,6,6,5,5,2,1$ -- a weird die
\item Suppose $r=1$, $t=1$, and $u=1$. Then $(x)^{1}(x+1)^{1}(x^{2}+1)^{1}(x^{4}+1)^{1}=x^{8}+x^{7}+x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x^{1}$ and so the die labels are $8,7,6,5,4,3,2,1$ -- a regular die
\item Suppose $r=1$, $t=2$, and $u=0$. Then $(x)^{1}(x+1)^{1}(x^{2}+1)^{2}(x^{4}+1)^{0}=x^{6}+x^{5}+2x^{4}+2x^{3}+x^{2}+x^{1}$ and so the die labels are $6,5,4,4,3,3,2,1$ -- a weird die corresponding to the die mentioned in item 3
\item Suppose $r=2$, $t=0$, and $u=1$. Then $(x)^{1}(x+1)^{2}(x^{2}+1)^{0}(x^{4}+1)^{1}=x^{7}+2x^{6}+x^{5}+x^{3}+2x^{2}+x^{1}$ and so the die labels are $7,6,6,5,3,2,2,1$ -- a weird die corresponding to the die mentioned in item 2
\item Suppose $r=2$, $t=1$, and $u=0$. Then $(x)^{1}(x+1)^{2}(x^{2}+1)^{1}(x^{4}+1)^{0}=x^{5}+2x^{4}+2x^{3}+2x^{2}+x^{1}$ and so the die labels are $5,4,4,3,3,2,2,1$ -- a weird die corresponding to the die mentioned in item 1
\end{enumerate}
So our 4 pairs of octahedral dice are:
\begin{enumerate}
\item $(8,7,6,5,4,3,2,1)$ and $(8,7,6,5,4,3,2,1)$
\item $(9,7,7,5,5,3,3,1)$ and $(7,6,6,5,3,2,2,1)$
\item $(10,9,6,6,5,5,2,1)$ and $(6,5,4,4,3,3,2,1)$
\item $(11,9,7,7,5,5,3,1)$ and $(5,4,4,3,3,2,2,1)$
\end{enumerate}
%-------------------------------------------------------------------------------
% CONCLUSION
%-------------------------------------------------------------------------------
\section*{Conclusion}
We finish this project by recalling that the primary tool we used to successfully find, and prove the
uniqueness of, these dice was the Unique Factorization Theorem. That is, what makes this method/proof so
incredible is we used a completely abstract concept from ring theory, that inherently doesn't seem too
applicable to the real world, and applied it directly a real world question. Moreover, this method simply,
efficiently, and reliably solves the problem that would otherwise use an exponentially-growing, brute force
approach to prove. It's very general in that can be applied to dice with large number of size and dice with
varying numbers of faces. These are the reasons for why the method is so powerful. However, these aren't the
only reasons that make a method ``beautiful''.
Another more important facet, from a personal standpoint, that method needs for being beautiful is that it can
make math fun. This is a technique that can be introduced to high-schoolers to learn the importance of
higher-level math in the real world. I know I personally enjoyed applying it to other geometric shapes for
dice that I can create for myself some day, just for fun. This is why I think this proof is so beautiful.
%-------------------------------------------------------------------------------
% REFERENCES
%-------------------------------------------------------------------------------
\section*{References}
\addcontentsline{toc}{section}{References}
Gallian, J. A. (2010). 17. In \textit{Contemporary Abstract Algebra} (7th ed., pp. 314-319). Australia: Brooks/Cole.
\end{document}
|
# %% [markdown]
# # Creating NumPy Arrays
# %%
import numpy as np
# %% [markdown]
#
# Create the following NumPy arrays. Only use `np.array()` if you can find no
# other method to generate the array using methods discussed in the lecture:
# ```python
# array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# ```
# %%
# %% [markdown]
# ```python
# array([0. , 1.25, 2.5 , 3.75, 5. ])
# ```
# %%
# %% [markdown]
# ```python
# array([ 1, 3, 12, 92])
# ```
# %%
# %% [markdown]
# ```python
# array([[1, 2, 3, 4],
# [5, 6, 7, 8]])
# ```
# %%
# %% [markdown]
# ```python
# array([[[0, 2, 4, 6],
# [1, 3, 5, 7]],
#
# [[1, 2, 3, 4],
# [5, 6, 7, 8]],
#
# [[9, 8, 7, 6],
# [5, 4, 3, 2]]])
# ```
# %%
# %% [markdown]
# A $2\times 8$ Array containing uniformly distributed random numbers in $[0, 1)$.
# %%
# %% [markdown]
# ```python
# array([[1., 0., 0.],
# [0., 1., 0.],
# [0., 0., 1.]])
# ```
# %%
# %% [markdown]
# A vector with 5 elements containing normally distributed random numbers.
# %%
# %% [markdown]
# A $3 \times 4$ array containing normally distributed numbers with mean $5$ and standard deviation $0.5$.
# %%
# %% [markdown]
# Create the following NumPy arrays:
#
# ```python
# array([[ 0, 2, 4, 6],
# [ 8, 10, 12, 14],
# [16, 18, 20, 22],
# [24, 26, 28, 30],
# [32, 34, 36, 38]])
# ```
# %%
# %% [markdown]
#
# ```python
# array([[10, 19, 28, 37, 46, 55],
# [13, 22, 31, 40, 49, 58],
# [16, 25, 34, 43, 52, 61]])
# ```
# %%
# %% [markdown]
# # Extrema
#
# Create a vector with 100 random elements, uniformly distributed in $[10, 20)$.
#
# Compute the minimum and maximum value, as well as the indices of these values.
# %%
# %% [markdown]
# # Mean value
#
# Create a $6 \times 8$ array, containing normally distributed numbers with mean
# $2$ and standard deviation $1$.
# %%
# %% [markdown]
# Compute mean value and standard deviation of the complete array.
# %%
# %% [markdown]
# Compute the mean value and standard deviation for each row and column.
# %%
# %% [markdown]
# Compute the mean values of the whole array as well as of each row and column
# without using the method `mean()`.
#
# (*Hint:* The mean value is the sum of all relevant values divided by the
# number of relevant elements.)
# %%
|
{-# OPTIONS --cubical --safe #-}
module Data.List.Membership where
open import Data.List
open import Data.Fin
open import Data.Fin.Properties
open import Prelude
open import Relation.Nullary
open import Path.Reasoning
open import Data.List.Relation.Unary as Relation using (module Exists; module Congruence; β; β!)
import Data.Nat as β
import Data.Nat.Properties as β
open import Data.Maybe.Properties using (just-inj)
module _ {a} {A : Type a} {x : A} where
open Exists (_β‘ x)
using (push; pull; push!; pull!; here!; _β++_; _++β_)
renaming (β? to _β?_)
public
infixr 5 _β_ _β!_ _β_
_β_ : A β List A β Type _
x β xs = β (_β‘ x) xs
_β_ : {A : Type a} β A β List A β Type a
x β xs = Β¬ (x β xs)
_β!_ : A β List A β Type _
x β! xs = β! (_β‘ x) xs
cong-β : β (f : A β B) {x : A} xs β x β xs β f x β map f xs
cong-β f {x} = Congruence.cong-β (_β‘ x) (_β‘ (f x)) (cong f)
finβtabulate : β {n}
(f : Fin n β A)
(i : Fin n) β
f i β tabulate n f
finβtabulate {n = suc _} f f0 = f0 , refl
finβtabulate {n = suc _} f (fs i) =
push (finβtabulate (f β fs) i)
open import Function.Injective
at : β {xs : List A} (n : Fin (length xs)) β (xs ! n) β xs
at n = n , refl
module _ {a} {A : Set a} (_β_ : Discrete A) where
isSetβ¨Aβ© : isSet A
isSetβ¨Aβ© = DiscreteβisSet _β_
infixl 6 _\\_
_\\_ : List A β A β List A
xs \\ x = foldr f [] xs
where
f : A β List A β List A
f y xs with x β y
... | yes p = xs
... | no p = y β· xs
uniques : List A β List A
uniques = foldr f []
where
f : A β List A β List A
f x xs = x β· (xs \\ x)
xβxs\\x : β x xs β x β xs \\ x
xβxs\\x x (y β· xs) (n , xβxs) with x β y
xβxs\\x x (y β· xs) (n , xβxs) | yes p = xβxs\\x x xs (n , xβxs)
xβxs\\x x (y β· xs) (f0 , yβ‘x) | no Β¬p = Β¬p (sym yβ‘x)
xβxs\\x x (y β· xs) (fs n , xβxs) | no Β¬p = xβxs\\x x xs (n , xβxs)
xβ!xβ·xs\\x : β x xs β x β! x β· xs \\ x
xβ!xβ·xs\\x x xs = here! (refl , isSetβ¨Aβ© _ _ refl) (xβxs\\x x xs)
xβxsβxβxs\\y : β (x : A) y xs β x β xs β x β xs \\ y
xβxsβxβxs\\y x y (z β· xs) xβxs xβxs\\y with y β z
xβxsβxβxs\\y x y (z β· xs) xβxs xβxs\\y | yes p =
xβxsβxβxs\\y x y xs (xβxs β push) xβxs\\y
xβxsβxβxs\\y x y (z β· xs) xβxs (f0 , xβxs\\y) | no Β¬p =
xβxs (f0 , xβxs\\y)
xβxsβxβxs\\y x y (z β· xs) xβxs (fs n , xβxs\\y) | no Β¬p =
xβxsβxβxs\\y x y xs (xβxs β push) (n , xβxs\\y)
xβ!xsβxβ!xs\\y : β (x : A) y xs β y β’ x β x β! xs β x β! xs \\ y
xβ!xsβxβ!xs\\y x y (z β· xs) yβ’x xβ!xs with y β z
xβ!xsβxβ!xs\\y x y (z β· xs) yβ’x xβ!xs | yes p =
xβ!xsβxβ!xs\\y x y xs yβ’x (pull! (yβ’x β p ΝΎ_) xβ!xs)
xβ!xsβxβ!xs\\y x y (z β· xs) yβ’x ((f0 , xβxs) , uniq) | no Β¬p =
here! (xβxs , isSetβ¨Aβ© _ _ _) (xβxsβxβxs\\y x y xs (β.znots β cong FinToβ β cong fst β uniq β push))
xβ!xsβxβ!xs\\y x y (z β· xs) yβ’x ((fs n , xβxs) , uniq) | no Β¬p =
push! zβ’x (xβ!xsβxβ!xs\\y x y xs yβ’x (pull! zβ’x ((fs n , xβxs) , uniq)))
where zβ’x = β.snotz β cong FinToβ β cong fst β uniq β (f0 ,_)
βββ! : (x : A) (xs : List A) β x β xs β x β! uniques xs
βββ! x (y β· xs) (f0 , xβxs) =
subst (_β! (y β· uniques xs \\ y)) xβxs (xβ!xβ·xs\\x y (uniques xs))
βββ! x (y β· xs) (fs n , xβxs) with y β x
... | yes p = subst (_β! (y β· uniques xs \\ y)) p (xβ!xβ·xs\\x y (uniques xs))
... | no Β¬p = push! Β¬p (xβ!xsβxβ!xs\\y x y (uniques xs) Β¬p (βββ! x xs (n , xβxs)))
infixr 5 _βΒ²_
_βΒ²_ : A β List (List A) β Type _
x βΒ² xs = β (x β_) xs
βΒ²ββ : β {x : A} xs β x βΒ² xs β x β concat xs
βΒ²ββ = Relation.β-concat (_β‘ _)
|
################################################################################
# Roessler SRK for second order weak approx
struct DRI1ConstantCache{T,T2} <: StochasticDiffEqConstantCache
# hard-coded version
a021::T
a031::T
a032::T
a121::T
a131::T
#a132::T
#a221::T
#a231::T
#a232::T
b021::T
b031::T
#b032::T
b121::T
b131::T
#b132::T
b221::T
b222::T
b223::T
b231::T
b232::T
b233::T
Ξ±1::T
Ξ±2::T
Ξ±3::T
c02::T2
c03::T2
#c11::T2
c12::T2
c13::T2
#c21::T2
#c22::T2
#c23::T2
beta11::T
beta12::T
beta13::T
#beta21::T
beta22::T
beta23::T
beta31::T
beta32::T
beta33::T
#beta41::T
beta42::T
beta43::T
#quantile(Normal(),1/6)
NORMAL_ONESIX_QUANTILE::T
end
function DRI1ConstantCache(::Type{T}, ::Type{T2}) where {T,T2}
a021 = convert(T, 1//2)
a031 = convert(T, -1)
a032 = convert(T, 2)
a121 = convert(T, 342//491)
a131 = convert(T, 342//491)
b021 = convert(T, (6-sqrt(6))/10)
b031 = convert(T, (3+2*sqrt(6))/5)
b121 = convert(T, 3*sqrt(38//491))
b131 = convert(T, -3*sqrt(38/491))
b221 = convert(T, -214//513*sqrt(1105//991))
b222 = convert(T, -491//513*sqrt(221//4955))
b223 = convert(T, -491//513*sqrt(221//4955))
b231 = convert(T, 214//513*sqrt(1105//991))
b232 = convert(T, 491//513*sqrt(221//4955))
b233 = convert(T, 491//513*sqrt(221//4955))
Ξ±1 = convert(T, 1//6)
Ξ±2 = convert(T, 2//3)
Ξ±3 = convert(T, 1//6)
c02 = convert(T2, 1//2)
c03 = convert(T2, 1)
c12 = convert(T2, 342//491)
c13 = convert(T2, 342//491)
beta11 = convert(T, 193//684)
beta12 = convert(T, 491//1368)
beta13 = convert(T, 491//1368)
beta22 = convert(T, 1//6*sqrt(491//38))
beta23 = convert(T, -1//6*sqrt(491//38))
beta31 = convert(T, -4955//7072)
beta32 = convert(T, 4955//14144)
beta33 = convert(T, 4955//14144)
beta42 = convert(T, -1//8*sqrt(4955//221))
beta43 = convert(T, 1//8*sqrt(4955//221))
NORMAL_ONESIX_QUANTILE = convert(T, -0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::DRI1,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
DRI1ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RI1ConstantCache(T::Type, T2::Type)
a021 = convert(T, 2//3) # convert(T, 2//3)
a031 = convert(T, -1//3)
a032 = convert(T, 1)
a121 = convert(T, 1)
a131 = convert(T, 1)
b021 = convert(T, 1)
b031 = convert(T, 0)
b121 = convert(T, 1)
b131 = convert(T, -1)
b221 = convert(T, 1)
b222 = convert(T, 0)
b223 = convert(T, 0)
b231 = convert(T, -1)
b232 = convert(T, 0)
b233 = convert(T, 0)
Ξ±1 = convert(T, 1//4)
Ξ±2 = convert(T, 1//2)
Ξ±3 = convert(T, 1//4)
c02 = convert(T2, 2//3)
c03 = convert(T2, 2//3)
c12 = convert(T2, 1)
c13 = convert(T2, 1)
beta11 = convert(T, 1//2)
beta12 = convert(T, 1//4)
beta13 = convert(T, 1//4)
beta22 = convert(T, 1//2)
beta23 = convert(T, -1//2)
beta31 = convert(T, -1//2)
beta32 = convert(T, 1//4)
beta33 = convert(T, 1//4)
beta42 = convert(T, 1//2)
beta43 = convert(T, -1//2)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RI1,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RI1ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RI3ConstantCache(T::Type, T2::Type)
a021 = convert(T, 1)
a031 = convert(T, 1//4)
a032 = convert(T, 1//4)
a121 = convert(T, 1)
a131 = convert(T, 1)
b021 = convert(T, (3-2*sqrt(6))/5)
b031 = convert(T, (6+sqrt(6))/10)
b121 = convert(T, 1)
b131 = convert(T, -1)
b221 = convert(T, 1)
b222 = convert(T, 0)
b223 = convert(T, 0)
b231 = convert(T, -1)
b232 = convert(T, 0)
b233 = convert(T, 0)
Ξ±1 = convert(T, 1//6)
Ξ±2 = convert(T, 1//6)
Ξ±3 = convert(T, 2//3)
c02 = convert(T2, 1)
c03 = convert(T2, 1//2)
c12 = convert(T2, 1)
c13 = convert(T2, 1)
beta11 = convert(T, 1//2)
beta12 = convert(T, 1//4)
beta13 = convert(T, 1//4)
beta22 = convert(T, 1//2)
beta23 = convert(T, -1//2)
beta31 = convert(T, -1//2)
beta32 = convert(T, 1//4)
beta33 = convert(T, 1//4)
beta42 = convert(T, 1//2)
beta43 = convert(T, -1//2)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RI3,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RI3ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RI5ConstantCache(T::Type, T2::Type)
a021 = convert(T, 1)
a031 = convert(T, 25//144)
a032 = convert(T, 35//144)
a121 = convert(T, 1//4)
a131 = convert(T, 1//4)
b021 = convert(T, 1//3)
b031 = convert(T, -5//6)
b121 = convert(T, 1//2)
b131 = convert(T, -1//2)
b221 = convert(T, 1)
b222 = convert(T, 0)
b223 = convert(T, 0)
b231 = convert(T, -1)
b232 = convert(T, 0)
b233 = convert(T, 0)
Ξ±1 = convert(T, 1//10)
Ξ±2 = convert(T, 3//14)
Ξ±3 = convert(T, 24//35)
c02 = convert(T2, 1)
c03 = convert(T2, 5//12)
c12 = convert(T2, 1//4)
c13 = convert(T2, 1//4)
beta11 = convert(T, 1)
beta12 = convert(T, -1)
beta13 = convert(T, -1)
beta22 = convert(T, 1)
beta23 = convert(T, -1)
beta31 = convert(T, 1//2)
beta32 = convert(T, -1//4)
beta33 = convert(T, -1//4)
beta42 = convert(T, 1//2)
beta43 = convert(T, -1//2)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RI5,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RI5ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RI6ConstantCache(T::Type, T2::Type)
a021 = convert(T, 1)
a031 = convert(T, 0)
a032 = convert(T, 0)
a121 = convert(T, 1)
a131 = convert(T, 1)
b021 = convert(T, 1)
b031 = convert(T, 0)
b121 = convert(T, 1)
b131 = convert(T, -1)
b221 = convert(T, 1)
b222 = convert(T, 0)
b223 = convert(T, 0)
b231 = convert(T, -1)
b232 = convert(T, 0)
b233 = convert(T, 0)
Ξ±1 = convert(T, 1//2)
Ξ±2 = convert(T, 1//2)
Ξ±3 = convert(T, 0)
c02 = convert(T2, 1)
c03 = convert(T2, 0)
c12 = convert(T2, 1)
c13 = convert(T2, 1)
beta11 = convert(T, 1//2)
beta12 = convert(T, 1//4)
beta13 = convert(T, 1//4)
beta22 = convert(T, 1//2)
beta23 = convert(T, -1//2)
beta31 = convert(T, -1//2)
beta32 = convert(T, 1//4)
beta33 = convert(T, 1//4)
beta42 = convert(T, 1//2)
beta43 = convert(T, -1//2)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RI6,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RI6ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RDI2WMConstantCache(T::Type, T2::Type)
a021 = convert(T, 1)
a031 = convert(T, 0)
a032 = convert(T, 0)
a121 = convert(T, 2//3)
a131 = convert(T, 2//3)
b021 = convert(T, 1)
b031 = convert(T, 0)
b121 = convert(T, sqrt(2//3))
b131 = convert(T, -sqrt(2//3))
b221 = convert(T, sqrt(2))
b222 = convert(T, 0)
b223 = convert(T, 0)
b231 = convert(T, -sqrt(2))
b232 = convert(T, 0)
b233 = convert(T, 0)
Ξ±1 = convert(T, 1//2)
Ξ±2 = convert(T, 1//2)
Ξ±3 = convert(T, 0)
c02 = convert(T2, 1)
c03 = convert(T2, 0)
c12 = convert(T2, 2//3)
c13 = convert(T2, 2//3)
beta11 = convert(T, 1//4)
beta12 = convert(T, 3//8)
beta13 = convert(T, 3//8)
beta22 = convert(T, sqrt(6)/4)
beta23 = convert(T, -sqrt(6)/4)
beta31 = convert(T, -1//4)
beta32 = convert(T, 1//8)
beta33 = convert(T, 1//8)
beta42 = convert(T, sqrt(2)/4)
beta43 = convert(T, -sqrt(2)/4)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RDI2WM,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RDI2WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RDI3WMConstantCache(T::Type, T2::Type)
a021 = convert(T, 1//2)
a031 = convert(T, 0)
a032 = convert(T, 3//4)
a121 = convert(T, 2//3)
a131 = convert(T, 2//3)
b021 = convert(T, (9-2*sqrt(15))/14)
b031 = convert(T, (18+3*sqrt(15))/28)
b121 = convert(T, sqrt(2//3))
b131 = convert(T, -sqrt(2//3))
b221 = convert(T, sqrt(2))
b222 = convert(T, 0)
b223 = convert(T, 0)
b231 = convert(T, -sqrt(2))
b232 = convert(T, 0)
b233 = convert(T, 0)
Ξ±1 = convert(T, 2//9)
Ξ±2 = convert(T, 1//3)
Ξ±3 = convert(T, 4//9)
c02 = convert(T2, 1//2)
c03 = convert(T2, 3//4)
c12 = convert(T2, 2//3)
c13 = convert(T2, 2//3)
beta11 = convert(T, 1//4)
beta12 = convert(T, 3//8)
beta13 = convert(T, 3//8)
beta22 = convert(T, sqrt(6)/4)
beta23 = convert(T, -sqrt(6)/4)
beta31 = convert(T, -1//4)
beta32 = convert(T, 1//8)
beta33 = convert(T, 1//8)
beta42 = convert(T, sqrt(2)/4)
beta43 = convert(T, -sqrt(2)/4)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RDI3WM,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RDI3WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RDI4WMConstantCache(T::Type, T2::Type)
a021 = convert(T, 1//2)
a031 = convert(T, -1)
a032 = convert(T, 2)
a121 = convert(T, 2//3)
a131 = convert(T, 2//3)
b021 = convert(T, (6-sqrt(6))/10)
b031 = convert(T, (3+2*sqrt(6))/5)
b121 = convert(T, sqrt(2//3))
b131 = convert(T, -sqrt(2//3))
b221 = convert(T, sqrt(2))
b222 = convert(T, 0)
b223 = convert(T, 0)
b231 = convert(T, -sqrt(2))
b232 = convert(T, 0)
b233 = convert(T, 0)
Ξ±1 = convert(T, 1//6)
Ξ±2 = convert(T, 2//3)
Ξ±3 = convert(T, 1//6)
c02 = convert(T2, 1//2)
c03 = convert(T2, 1)
c12 = convert(T2, 2//3)
c13 = convert(T2, 2//3)
beta11 = convert(T, 1//4)
beta12 = convert(T, 3//8)
beta13 = convert(T, 3//8)
beta22 = convert(T, sqrt(6)/4)
beta23 = convert(T, -sqrt(6)/4)
beta31 = convert(T, -1//4)
beta32 = convert(T, 1//8)
beta33 = convert(T, 1//8)
beta42 = convert(T, sqrt(2)/4)
beta43 = convert(T, -sqrt(2)/4)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
DRI1ConstantCache(a021,a031,a032,a121,a131,b021,b031,b121,b131,b221,b222,b223,b231,b232,b233,Ξ±1,Ξ±2,Ξ±3,c02,c03,c12,c13,beta11,beta12,beta13,beta22,beta23,beta31,beta32,beta33,beta42,beta43,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RDI4WM,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RDI4WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
@cache struct DRI1Cache{uType,randType,MType1,tabType,rateNoiseType,rateType,possibleRateType} <: StochasticDiffEqMutableCache
u::uType
uprev::uType
_dW::randType
_dZ::randType
chi1::randType
Ihat2::MType1
tab::tabType
g1::rateNoiseType
g2::Vector{rateNoiseType}
g3::Vector{rateNoiseType}
k1::rateType
k2::rateType
k3::rateType
H02::uType
H03::uType
H12::Vector{uType}
H13::Vector{uType}
H22::Vector{uType}
H23::Vector{uType}
tmp1::possibleRateType
tmpg::rateNoiseType
end
function alg_cache(alg::DRI1,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = DRI1ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RI1,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RI1ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RI3,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RI3ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RI5,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RI5ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RI6,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RI6ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RDI2WM,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RDI2WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RDI3WM,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RDI3WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RDI4WM,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RDI4WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
DRI1Cache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,k1,k2,k3,H02,H03,H12,H13,H22,H23,tmp1,tmpg)
end
# Roessler SRK for first order weak approx
struct RDI1WMConstantCache{T,T2} <: StochasticDiffEqConstantCache
# hard-coded version
a021::T
#a121::T
#a221::T
b021::T
#b121::T
#b221::T
Ξ±1::T
Ξ±2::T
c02::T2
#c11::T2
#c12::T2
#c21::T2
#c22::T2
beta11::T
#beta12::T
#beta21::T
#beta22::T
#beta31::T
#beta32::T
#beta41::T
#beta42::T
#quantile(Normal(),1/6)
NORMAL_ONESIX_QUANTILE::T
end
function RDI1WMConstantCache(::Type{T}, ::Type{T2}) where {T,T2}
a021 = convert(T, 2//3)
b021 = convert(T, 2//3)
Ξ±1 = convert(T, 1//4)
Ξ±2 = convert(T, 3//4)
c02 = convert(T2, 2//3)
beta11 = convert(T, 1)
NORMAL_ONESIX_QUANTILE = convert(T, -0.9674215661017014)
RDI1WMConstantCache(a021,b021,Ξ±1,Ξ±2,c02,beta11,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RDI1WM,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RDI1WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
@cache struct RDI1WMCache{uType,randType,MType1,tabType,rateNoiseType,rateType,possibleRateType} <: StochasticDiffEqMutableCache
u::uType
uprev::uType
_dW::randType
_dZ::randType
chi1::randType
Ihat2::MType1
tab::tabType
g1::rateNoiseType
k1::rateType
k2::rateType
H02::uType
tmp1::possibleRateType
end
function alg_cache(alg::RDI1WM,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RDI1WMConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
k1 = zero(rate_prototype); k2 = zero(rate_prototype)
H02 = zero(u)
tmp1 = zero(rate_prototype)
RDI1WMCache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,k1,k2,H02,tmp1)
end
# Stratonovich sense
struct RSConstantCache{T,T2} <: StochasticDiffEqConstantCache
# hard-coded version
a021::T
a031::T
a032::T
a131::T
a141::T
b031::T
b032::T
b121::T
b131::T
b132::T
b141::T
b142::T
b143::T
b221::T
b231::T
b331::T
b332::T
b341::T
b342::T
Ξ±1::T
Ξ±2::T
Ξ±3::T
Ξ±4::T
c02::T2
c03::T2
c13::T2
c14::T2
beta11::T
beta12::T
beta13::T
beta14::T
beta22::T
beta23::T
#quantile(Normal(),1/6)
NORMAL_ONESIX_QUANTILE::T
end
function RS1ConstantCache(T::Type, T2::Type)
a021 = convert(T, 0)
a031 = convert(T, 1)
a032 = convert(T, 0)
a131 = convert(T, 1)
a141 = convert(T, 1)
b031 = convert(T, 1//4)
b032 = convert(T, 3//4)
b121 = convert(T, 2//3)
b131 = convert(T, 1//12)
b132 = convert(T, 1//4)
b141 = convert(T, -5//4)
b142 = convert(T, 1//4)
b143 = convert(T, 2)
b221 = convert(T, 1)
b231 = convert(T, -1)
b331 = convert(T, 1//4)
b332 = convert(T, 3//4)
b341 = convert(T, 1//4)
b342 = convert(T, 3//4)
Ξ±1 = convert(T, 0)
Ξ±2 = convert(T, 0)
Ξ±3 = convert(T, 1//2)
Ξ±4 = convert(T, 1//2)
c02 = convert(T2, 0)
c03 = convert(T2, 1)
c13 = convert(T2, 1)
c14 = convert(T2, 1)
beta11 = convert(T, 1//8)
beta12 = convert(T, 3//8)
beta13 = convert(T, 3//8)
beta14 = convert(T, 1//8)
beta22 = convert(T, -1//4)
beta23 = convert(T, 1//4)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
RSConstantCache(a021,a031,a032,a131,a141,b031,b032,b121,b131,b132,b141,b142,b143,b221,b231,b331,b332,b341,b342,Ξ±1,Ξ±2,Ξ±3,Ξ±4,c02,c03,c13,c14,beta11,beta12,beta13,beta14,beta22,beta23,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RS1,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RS1ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
function RS2ConstantCache(T::Type, T2::Type)
a021 = convert(T, 2//3)
a031 = convert(T, 1//6)
a032 = convert(T, 1//2)
a131 = convert(T, 1)
a141 = convert(T, 1)
b031 = convert(T, 1//4)
b032 = convert(T, 3//4)
b121 = convert(T, 2//3)
b131 = convert(T, 1//12)
b132 = convert(T, 1//4)
b141 = convert(T, -5//4)
b142 = convert(T, 1//4)
b143 = convert(T, 2)
b221 = convert(T, 1)
b231 = convert(T, -1)
b331 = convert(T, 1//4)
b332 = convert(T, 3//4)
b341 = convert(T, 1//4)
b342 = convert(T, 3//4)
Ξ±1 = convert(T, 1//4)
Ξ±2 = convert(T, 1//4)
Ξ±3 = convert(T, 1//2)
Ξ±4 = convert(T, 0)
c02 = convert(T2, 2//3)
c03 = convert(T2, 2//3)
c13 = convert(T2, 1)
c14 = convert(T2, 1)
beta11 = convert(T, 1//8)
beta12 = convert(T, 3//8)
beta13 = convert(T, 3//8)
beta14 = convert(T, 1//8)
beta22 = convert(T, -1//4)
beta23 = convert(T, 1//4)
NORMAL_ONESIX_QUANTILE = convert(T,-0.9674215661017014)
RSConstantCache(a021,a031,a032,a131,a141,b031,b032,b121,b131,b132,b141,b142,b143,b221,b231,b331,b332,b341,b342,Ξ±1,Ξ±2,Ξ±3,Ξ±4,c02,c03,c13,c14,beta11,beta12,beta13,beta14,beta22,beta23,NORMAL_ONESIX_QUANTILE)
end
function alg_cache(alg::RS2,prob,u,ΞW,ΞZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{false}})
RS2ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
end
@cache struct RSCache{uType,randType,MType1,tabType,rateNoiseType,rateType,possibleRateType} <: StochasticDiffEqMutableCache
u::uType
uprev::uType
_dW::randType
_dZ::randType
chi1::randType
Ihat2::MType1
tab::tabType
g1::rateNoiseType
g2::Vector{rateNoiseType}
g3::Vector{rateNoiseType}
g4::Vector{rateNoiseType}
k1::rateType
k2::rateType
k3::rateType
H02::uType
H03::uType
H12::Vector{uType}
H13::Vector{uType}
H14::Vector{uType}
H22::Vector{uType}
H23::Vector{uType}
tmp1::possibleRateType
tmpg::rateNoiseType
end
function alg_cache(alg::RS1,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RS1ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
g4 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H14 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H14,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
RSCache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,g4,k1,k2,k3,H02,H03,H12,H13,H14,H22,H23,tmp1,tmpg)
end
function alg_cache(alg::RS2,prob,u,ΞW,ΞZ,p,rate_prototype,
noise_rate_prototype,jump_rate_prototype,uEltypeNoUnits,
uBottomEltypeNoUnits,tTypeNoUnits,uprev,f,t,dt,::Type{Val{true}})
if typeof(ΞW) <: Union{SArray,Number}
_dW = copy(ΞW)
_dZ = copy(ΞW)
chi1 = copy(ΞW)
else
_dW = zero(ΞW)
_dZ = zero(ΞW)
chi1 = zero(ΞW)
end
m = length(ΞW)
Ihat2 = zeros(eltype(ΞW), m, m)
tab = RS2ConstantCache(real(uBottomEltypeNoUnits), real(tTypeNoUnits))
g1 = zero(noise_rate_prototype)
g2 = [zero(noise_rate_prototype) for k=1:m]
g3 = [zero(noise_rate_prototype) for k=1:m]
g4 = [zero(noise_rate_prototype) for k=1:m]
k1 = zero(rate_prototype); k2 = zero(rate_prototype); k3 = zero(rate_prototype)
H02 = zero(u)
H03 = zero(u)
H12 = Vector{typeof(u)}()
H13 = Vector{typeof(u)}()
H14 = Vector{typeof(u)}()
H22 = Vector{typeof(u)}()
H23 = Vector{typeof(u)}()
for k=1:m
push!(H12,zero(u))
push!(H13,zero(u))
push!(H14,zero(u))
push!(H22,zero(u))
push!(H23,zero(u))
end
tmp1 = zero(rate_prototype)
tmpg = zero(noise_rate_prototype)
RSCache(u,uprev,_dW,_dZ,chi1,Ihat2,tab,g1,g2,g3,g4,k1,k2,k3,H02,H03,H12,H13,H14,H22,H23,tmp1,tmpg)
end
|
[STATEMENT]
lemma member [iff]: \<open>member p z \<longleftrightarrow> p \<in> set z\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. member p z = (p \<in> set z)
[PROOF STEP]
by (induct z) simp_all
|
(* IsageoCoq2_R1
Highschool3.thy
Version 2.2.0 IsaGeoCoq2_R1, Port part of GeoCoq 3.4.0
(* GeoCoq : hilbert_to_tarski.v *)
Copyright (C) 2021-2023 Roland Coghetto roland.coghetto ( a t ) cafr-msa2p.be
License: LGPGL
History
Version 1.0.0: IsaGeoCoq
Port part of GeoCoq 3.4.0 (https://geocoq.github.io/GeoCoq/) in Isabelle/Hol (Isabelle2021)
Copyright (C) 2021 Roland Coghetto roland_coghetto (at) hotmail.com
License: LGPL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)
(*<*)
theory Tarski_Hilbert_Model
imports
Tarski_3D
Tarski_Euclidean
Tarski_Postulate_Parallels
Hilbert
Gupta
begin
(*>*)
section "Tarski - Hilbert Model"
context Hilbert_neutral_dimensionless
begin
definition (in Hilbert_neutral_dimensionless_pre) Bet :: "TPoint\<Rightarrow>TPoint\<Rightarrow>TPoint\<Rightarrow>bool"
where
"Bet A B C \<equiv> BetH A B C \<or> A = B \<or> B = C"
definition (in Hilbert_neutral_dimensionless_pre) Cong :: "TPoint\<Rightarrow>TPoint\<Rightarrow>TPoint\<Rightarrow>TPoint\<Rightarrow>bool"
where
"Cong A B C D \<equiv> (CongH A B C D \<and> A \<noteq> B \<and> C \<noteq> D) \<or> (A = B \<and> C = D)"
definition (in Hilbert_neutral_dimensionless) ParaP :: "TPoint\<Rightarrow>TPoint\<Rightarrow>TPoint\<Rightarrow>TPoint\<Rightarrow>bool"
where
"ParaP A B C D \<equiv> \<forall> l m.
IsL l \<and> IsL m \<and> IncidL A l \<and> IncidL B l \<and> IncidL C m \<and> IncidL D m
\<longrightarrow>
Para l m"
definition (in Hilbert_neutral_dimensionless_pre) is_line :: "TPoint \<Rightarrow> TPoint \<Rightarrow> 'b \<Rightarrow>bool"
where
"is_line A B l \<equiv> (IsL l \<and> A \<noteq> B \<and> IncidL A l \<and> IncidL B l)"
definition (in Hilbert_neutral_dimensionless_pre) cut' ::
"TPoint \<Rightarrow> TPoint \<Rightarrow> TPoint \<Rightarrow> TPoint \<Rightarrow> bool"
where
"cut' A B X Y \<equiv> X \<noteq> Y \<and> (\<forall> l. (IsL l \<and> IncidL X l \<and> IncidL Y l) \<longrightarrow> cut l A B)"
definition (in Hilbert_neutral_dimensionless_pre) Midpoint :: "TPoint \<Rightarrow> TPoint \<Rightarrow> TPoint\<Rightarrow>bool"
("_ Midpoint _ _" [99,99,99] 50)
where "M Midpoint A B \<equiv> Bet A M B \<and> Cong A M M B"
lemma betH_distincts:
assumes "BetH A B C"
shows "A \<noteq> B \<and> B \<noteq> C \<and> A \<noteq> C"
using assms between_comm between_diff between_only_one by blast
(** Hilbert's congruence is 'defined' only for non degenerated segments,
while Tarski's segment congruence allows the null segment. *)
lemma congH_perm:
assumes "A \<noteq> B"
shows "CongH A B B A"
proof -
obtain l where "IsL l" and "IncidL A l" and "IncidL B l"
using assms line_existence by fastforce
moreover
{
fix x
assume "IncidL x l" and
"outH A B x" and
"CongH A x A B"
hence "CongH A x B A"
by (simp add: cong_permr)
hence "CongH A B B A"
using \<open>CongH A x A B\<close> cong_pseudo_transitivity by blast
}
hence "\<forall> x. (IncidL x l \<and> outH A B x \<and> CongH A x A B) \<longrightarrow> CongH A B B A"
by blast
ultimately show ?thesis
using assms cong_existence by presburger
qed
lemma congH_refl:
assumes "A \<noteq> B"
shows "CongH A B A B"
by (simp add: assms congH_perm cong_permr)
lemma congH_sym:
assumes "A \<noteq> B" and
"CongH A B C D"
shows "CongH C D A B"
using assms(1) assms(2) congH_refl cong_pseudo_transitivity by blast
lemma colH_permut_231:
assumes "ColH A B C"
shows "ColH B C A"
using ColH_def assms by blast
lemma colH_permut_312:
assumes "ColH A B C"
shows "ColH C A B"
by (simp add: assms colH_permut_231)
lemma colH_permut_213:
assumes "ColH A B C"
shows "ColH B A C"
using ColH_def assms by auto
lemma colH_permut_132:
assumes "ColH A B C"
shows "ColH A C B"
using ColH_def assms by auto
lemma colH_permut_321:
assumes "ColH A B C"
shows "ColH C B A"
using ColH_def assms by auto
lemma other_point_exists:
fixes A::TPoint
shows "\<exists> B. A \<noteq> B"
by (metis lower_dim_2)
lemma colH_trivial111:
shows "ColH A A A"
using cong_4_existence same_side'_def by blast
lemma colH_trivial112:
shows "ColH A A B"
using colH_permut_231 cong_4_existence same_side'_def by blast
lemma colH_trivial122:
shows "ColH A B B"
by (simp add: colH_permut_312 colH_trivial112)
lemma colH_trivial121:
shows "ColH A B A"
by (simp add: colH_permut_312 colH_trivial122)
lemma colH_dec:
shows "ColH A B C \<or> \<not> ColH A B C"
by blast
lemma colH_trans:
assumes "X \<noteq> Y" and
"ColH X Y A" and
"ColH X Y B" and
"ColH X Y C"
shows "ColH A B C"
proof -
obtain l where "IsL l" and "IncidL X l" and "IncidL Y l" and "IncidL A l"
using ColH_def assms(2) by blast
obtain m where "IsL m" and "IncidL X m" and "IncidL Y m" and "IncidL B m"
using ColH_def assms(3) by blast
obtain n where "IsL n" and "IncidL X n" and "IncidL Y n" and "IncidL C n"
using ColH_def assms(4) by blast
have "EqL l m"
using line_uniqueness \<open>IncidL B m\<close> assms(1) \<open>IncidL X l\<close> \<open>IncidL Y l\<close>
\<open>IncidL X m\<close> \<open>IncidL Y m\<close> \<open>IsL m\<close> \<open>IsL l\<close> by blast
hence "IncidL B l"
using EqL_sym IncidL_morphism \<open>IncidL B m\<close> \<open>IsL l\<close> \<open>IsL m\<close> by blast
moreover have "IncidL C l"
by (meson IncidL_morphism \<open>IncidL C n\<close> \<open>IncidL X l\<close> \<open>IncidL X n\<close> \<open>IncidL Y l\<close>
\<open>IncidL Y n\<close> \<open>IsL l\<close> \<open>IsL n\<close> assms(1) line_uniqueness)
ultimately show ?thesis
using ColH_def \<open>IncidL A l\<close> \<open>IsL l\<close> by blast
qed
lemma bet_colH:
assumes "Bet A B C"
shows "ColH A B C"
using Bet_def assms between_col colH_trivial112 colH_trivial122 by blast
lemma ncolH_exists:
assumes "A \<noteq> B"
shows "\<exists> C. \<not> ColH A B C"
using assms colH_trans lower_dim_2 by blast
lemma ncolH_distincts:
assumes "\<not> ColH A B C"
shows "A \<noteq> B \<and> B \<noteq> C \<and> A \<noteq> C"
using assms colH_trivial112 colH_trivial121 colH_trivial122 by blast
lemma betH_expand:
assumes "BetH A B C"
shows "BetH A B C \<and> A \<noteq> B \<and> B \<noteq> C \<and> A \<noteq> C \<and> ColH A B C"
using assms betH_distincts between_col by presburger
lemma inter_uniquenessH:
assumes "A' \<noteq> B'" and
"\<not> ColH A B A'" and
"ColH A B X" and
"ColH A B Y" and
"ColH A' B' X" and
"ColH A' B' Y"
shows "X = Y"
proof -
have "A \<noteq> B"
using assms(2) colH_trivial112 by blast
thus ?thesis
by (metis (full_types) assms(1) assms(2) assms(3) assms(4) assms(5) assms(6)
colH_permut_231 colH_trans colH_trivial121)
qed
lemma inter_incid_uniquenessH:
assumes "\<not> IncidL P l" and
"IncidL P m" and
"IncidL X l" and
"IncidL Y l" and
"IncidL X m" and
"IncidL Y m"
shows "X = Y"
proof -
have "IsL l"
using Is_line assms(4) by blast
then obtain A B where "IncidL B l" and "IncidL A l" and "A \<noteq> B"
using two_points_on_line by blast
have "IsL m"
using Is_line assms(5) by blast
then obtain A' B' where "IncidL B' m" and "IncidL A' m" and "A' \<noteq> B'"
using two_points_on_line by blast
have "ColH A B X"
using ColH_def Is_line \<open>IncidL A l\<close> \<open>IncidL B l\<close> assms(3) by blast
have "ColH A B Y"
using ColH_def Is_line \<open>IncidL A l\<close> \<open>IncidL B l\<close> assms(4) by blast
have "ColH A' B' X"
using ColH_def Is_line \<open>IncidL A' m\<close> \<open>IncidL B' m\<close> assms(5) by blast
have "ColH A' B' Y"
using ColH_def Is_line \<open>IncidL A' m\<close> \<open>IncidL B' m\<close> assms(6) by blast
{
assume "ColH A B P"
then obtain l00 where "IsL l00" and "IncidL A l00" and "IncidL B l00" and "IncidL P l00"
using ColH_def by blast
hence "EqL l l00"
using \<open>A \<noteq> B\<close> \<open>IncidL A l\<close> \<open>IncidL B l\<close> \<open>IsL l\<close> line_uniqueness by blast
hence "IncidL P l"
using EqL_sym IncidL_morphism \<open>IncidL P l00\<close> \<open>IsL l00\<close> \<open>IsL l\<close> by blast
hence False
using assms(1) by blast
}
hence "\<not> ColH A B P"
by blast
{
assume "A' = P"
hence "X = Y"
using \<open>A' \<noteq> B'\<close> \<open>ColH A B X\<close> \<open>ColH A B Y\<close> \<open>ColH A' B' X\<close> \<open>ColH A' B' Y\<close> \<open>\<not> ColH A B P\<close>
inter_uniquenessH by blast
}
moreover
{
assume "A' \<noteq> P"
hence "X = Y"
using IncidL_morphism \<open>IsL l\<close> \<open>IsL m\<close> assms(1) assms(2) assms(3) assms(4) assms(5)
assms(6) line_uniqueness by blast
}
ultimately show ?thesis
by blast
qed
lemma between_only_one':
assumes "BetH A B C" (*and
"\<not> BetH B C A"*)
shows "\<not> BetH B A C"
using assms(1) between_comm between_only_one by blast
lemma betH_colH:
assumes "BetH A B C"
shows "ColH A B C \<and> A \<noteq> B \<and> B \<noteq> C \<and> A \<noteq> C"
using assms betH_expand by presburger
lemma cut_comm:
assumes "cut l A B"
shows "cut l B A"
using assms between_comm local.cut_def by blast
lemma line_on_plane':
assumes "A \<noteq> B" and
"IncidP A p" and
"IncidP B p" and
"ColH A B C"
shows "IncidP C p"
using ColH_def IncidLP_def Is_plane assms(1) assms(2) assms(3) assms(4) line_on_plane by blast
lemma inner_pasch_aux:
assumes "\<not> ColH B C P" and
"Bet A P C" and
"Bet B Q C"
shows "\<exists> X. Bet P X B \<and> Bet Q X A"
proof -
have "BetH A P C \<or> A = P \<or> P = C"
using Bet_def assms(2) by presburger
moreover
have "BetH B Q C \<or> B = Q \<or> Q = C"
using Bet_def assms(3) by blast
moreover
let ?t = "\<exists> X. Bet P X B \<and> Bet Q X A"
have "BetH A P C \<and> BetH B Q C \<longrightarrow> ?t"
proof -
{
assume "Q \<noteq> A" and
"BetH A P C" and "BetH B Q C"
obtain l where "IsL l" and "IncidL Q l" and "IncidL A l"
using \<open>Q \<noteq> A\<close> line_existence by blast
{
assume "P = A"
hence ?t
using Bet_def by blast
}
moreover
{
assume "P \<noteq> A"
{
assume "Q = C"
hence ?t
using \<open>BetH B Q C\<close> betH_distincts by auto
}
moreover
{
assume "Q \<noteq> C"
{
assume "IncidL P l"
have "ColH A P C"
using \<open>BetH A P C\<close> betH_colH by blast
have "ColH B Q C"
by (simp add: \<open>BetH B Q C\<close> between_col)
have "ColH A P Q"
using ColH_def \<open>IncidL A l\<close> \<open>IncidL P l\<close> \<open>IncidL Q l\<close> \<open>IsL l\<close> by blast
have "ColH P C Q"
by (meson ColH_def \<open>ColH A P C\<close> \<open>IncidL A l\<close> \<open>IncidL P l\<close> \<open>IncidL Q l\<close>
\<open>P \<noteq> A\<close> inter_incid_uniquenessH)
have "ColH B C P"
by (metis inter_uniquenessH \<open>ColH B Q C\<close> \<open>ColH P C Q\<close> \<open>Q \<noteq> C\<close>
colH_permut_321 colH_trivial122)
hence False
using assms(1) by blast
}
hence "\<not> IncidL P l"
by blast
{
assume "B = Q"
hence ?t
using Bet_def by blast
}
moreover
{
assume "B \<noteq> Q"
{
assume "A = C"
hence ?t
using \<open>BetH A P C\<close> between_diff by blast
}
moreover
{
assume "A \<noteq> C"
{
assume "IncidL B l"
have "ColH A B Q"
using ColH_def \<open>IncidL A l\<close> \<open>IncidL B l\<close> \<open>IncidL Q l\<close> \<open>IsL l\<close> by blast
have "ColH A B C"
using \<open>BetH B Q C\<close> \<open>ColH A B Q\<close> betH_colH colH_permut_231 colH_trans
colH_trivial121 by blast
have "ColH A P C"
by (simp add: \<open>BetH A P C\<close> betH_colH)
have "ColH B Q C"
by (simp add: \<open>BetH B Q C\<close> between_col)
have "ColH B C P"
by (meson ColH_def \<open>A \<noteq> C\<close> \<open>ColH A B C\<close> \<open>ColH A P C\<close> inter_incid_uniquenessH)
hence False
using assms(1) by blast
}
hence "\<not> IncidL B l"
by blast
{
assume "IncidL C l"
have "ColH A C Q"
using ColH_def \<open>IncidL A l\<close> \<open>IncidL C l\<close> \<open>IncidL Q l\<close> \<open>IsL l\<close> by blast
have "ColH B Q C"
using assms(3) bet_colH by auto
have "ColH A B C"
by (metis \<open>BetH B Q C\<close> \<open>ColH A C Q\<close> \<open>Q \<noteq> C\<close> betH_colH colH_permut_231
colH_trans colH_trivial121)
have "ColH B C P"
using inter_incid_uniquenessH ColH_def \<open>A \<noteq> C\<close> \<open>ColH A B C\<close> \<open>IncidL A l\<close>
\<open>IncidL C l\<close> \<open>\<not> IncidL B l\<close> by fastforce
hence False
by (simp add: assms(1))
}
have "cut l B C"
using \<open>BetH B Q C\<close> \<open>IncidL C l \<Longrightarrow> False\<close> \<open>IncidL Q l\<close> \<open>IsL l\<close> \<open>\<not> IncidL B l\<close>
local.cut_def by blast
obtain p where "IncidP B p" and "IncidP C p" and "IncidP P p"
using assms(1) plan_existence by blast
have "(\<not> ColH B C P \<and> IncidP B p \<and> IncidP C p \<and> IncidP P p \<and> IncidLP l p \<and>
\<not> IncidL P l \<and> cut l B C) \<longrightarrow> cut l B P \<or> cut l C P"
using pasch Is_plane \<open>IsL l\<close> by blast
moreover
have "\<not> ColH B C P"
by (simp add: assms(1))
moreover have "IncidP B p"
by (simp add: \<open>IncidP B p\<close>)
moreover have "IncidP C p"
by (simp add: \<open>IncidP C p\<close>)
moreover have "IncidP P p"
by (simp add: \<open>IncidP P p\<close>)
moreover have "IncidLP l p"
by (metis colH_permut_231 line_on_plane'
Hilbert_neutral_dimensionless.ncolH_distincts
Hilbert_neutral_dimensionless_axioms Is_plane \<open>IncidL A l\<close> \<open>IncidL Q l\<close>
\<open>IsL l\<close> \<open>Q \<noteq> A\<close> assms(2) assms(3) bet_colH calculation(2) calculation(3)
calculation(4) calculation(5) line_on_plane)
moreover have "\<not> IncidL P l"
by (simp add: \<open>\<not> IncidL P l\<close>)
moreover have "cut l B C"
by (simp add: \<open>local.cut l B C\<close>)
moreover
{
assume "cut l B P"
hence "\<not> IncidL B l"
using \<open>\<not> IncidL B l\<close> by auto
have "\<not> IncidL P l"
by (simp add: calculation(7))
obtain X where "IncidL X l" and "BetH B X P"
using \<open>local.cut l B P\<close> local.cut_def by blast
have "BetH P X B \<or> P = X \<or> X = B"
using \<open>BetH B X P\<close> between_comm by presburger
moreover have "BetH Q X A \<or> Q = X \<or> X = A"
proof (cases "A = X")
case True
thus ?thesis
by simp
next
case False
have "A \<noteq> Q"
using \<open>Q \<noteq> A\<close> by fastforce
have "P \<noteq> C"
using assms(1) colH_trivial122 by blast
have "A \<noteq> B"
using \<open>IncidL A l\<close> \<open>\<not> IncidL B l\<close> by auto
have "X \<noteq> Q"
using \<open>B \<noteq> Q\<close> \<open>BetH B X P\<close> assms(1) assms(3) bet_colH between_col
colH_trans colH_trivial121 by blast
have "ColH A X Q"
using ColH_def Is_line \<open>IncidL A l\<close> \<open>IncidL Q l\<close> \<open>IncidL X l\<close> by blast
{
assume "ColH A C Q"
obtain l00 where "IncidL A l00" and "IncidL C l00" and "IncidL Q l00"
using ColH_def \<open>ColH A C Q\<close> by blast
hence "IncidL C l"
using \<open>A \<noteq> Q\<close> \<open>IncidL A l\<close> \<open>IncidL Q l\<close> inter_incid_uniquenessH by blast
hence False
using \<open>IncidL C l \<Longrightarrow> False\<close> by auto
}
hence "\<not> ColH A C Q"
by blast
have "P \<noteq> B"
using assms(1) colH_trivial121 by fastforce
obtain m where "IsL m" and "IncidL P m" and "IncidL B m"
using \<open>P \<noteq> B\<close> line_existence by blast
have "\<not> IncidL Q m"
by (meson ColH_def \<open>B \<noteq> Q\<close> \<open>BetH B Q C\<close> \<open>IncidL B m\<close> \<open>IncidL P m\<close> assms(1)
between_col inter_incid_uniquenessH)
have "\<not> ColH A B P"
by (metis \<open>BetH A P C\<close> \<open>P \<noteq> A\<close> assms(1) betH_colH colH_permut_312
colH_trans colH_trivial122)
have "cut m A C"
using Hilbert_neutral_dimensionless_pre.ColH_def \<open>BetH A P C\<close>
\<open>IncidL B m\<close> \<open>IncidL P m\<close> \<open>IsL m\<close> \<open>\<not> ColH A B P\<close> assms(1)
local.cut_def by fastforce
obtain p where "IncidP A p" and "IncidP C p" and "IncidP Q p"
using \<open>\<not> ColH A C Q\<close> plan_existence by blast
have "(\<not> ColH A C Q \<and> IncidP A p \<and> IncidP C p \<and> IncidP Q p \<and>
IncidLP m p \<and> \<not> IncidL Q m \<and> cut m A C) \<longrightarrow> (cut m A Q \<or> cut m C Q)"
using pasch Is_plane \<open>IsL m\<close> by blast
moreover have "\<not> ColH A C Q \<and> IncidP A p \<and> IncidP C p \<and> IncidP Q p \<and>
IncidLP m p \<and> \<not> IncidL Q m \<and> cut m A C"
by (metis Is_plane \<open>A \<noteq> C\<close> \<open>BetH A P C\<close> \<open>BetH B Q C\<close> \<open>IncidL B m\<close>
\<open>IncidL P m\<close> \<open>IncidP A p\<close> \<open>IncidP C p\<close> \<open>IncidP Q p\<close>
\<open>IsL m\<close> \<open>P \<noteq> B\<close> \<open>Q \<noteq> C\<close>
\<open>\<not> ColH A C Q\<close> \<open>\<not> IncidL Q m\<close> \<open>local.cut m A C\<close> between_col between_comm
colH_permut_132 line_on_plane line_on_plane')
moreover {
assume "cut m A Q"
obtain Y where "IncidL Y m \<and> BetH A Y Q"
using \<open>local.cut m A Q\<close> local.cut_def by blast
have "ColH A Y Q"
by (simp add: \<open>IncidL Y m \<and> BetH A Y Q\<close> betH_colH)
then obtain l0 where "IncidL A l0" and "IncidL Y l0" and "IncidL Q l0"
using ColH_def by blast
have "EqL l0 l"
using Is_line \<open>A \<noteq> Q\<close> \<open>IncidL A l0\<close> \<open>IncidL A l\<close> \<open>IncidL Q l0\<close>
\<open>IncidL Q l\<close> line_uniqueness by presburger
hence "IncidL Y l"
using \<open>A \<noteq> Q\<close> \<open>IncidL A l0\<close> \<open>IncidL A l\<close> \<open>IncidL Q l0\<close> \<open>IncidL Q l\<close>
\<open>IncidL Y l0\<close> inter_incid_uniquenessH by blast
moreover
have "ColH B X P"
by (simp add: \<open>BetH B X P\<close> between_col)
then obtain m0 where "IncidL B m0" and "IncidL X m0" and "IncidL P m0"
using ColH_def by blast
have "EqL m0 m"
using Is_line \<open>IncidL B m0\<close> \<open>IncidL B m\<close> \<open>IncidL P m0\<close> \<open>IncidL P m\<close>
\<open>P \<noteq> B\<close> line_uniqueness by presburger
hence "IncidL X m"
using IncidL_morphism Is_line \<open>IncidL X m0\<close> \<open>IsL m\<close> by blast
ultimately
have "X = Y"
using \<open>IncidL B m\<close> \<open>IncidL X l\<close> \<open>IncidL Y m \<and> BetH A Y Q\<close>
\<open>\<not> IncidL B l\<close> inter_incid_uniquenessH by auto
hence ?thesis
using \<open>IncidL Y m \<and> BetH A Y Q\<close> between_comm by blast
}
moreover {
assume "cut m C Q"
then obtain I where "IncidL I m" and "BetH C I Q"
using local.cut_def by blast
have "ColH C I Q"
using \<open>BetH C I Q\<close> betH_colH by blast
obtain lo where "IncidL C lo" and "IncidL I lo" and "IncidL Q lo"
using ColH_def \<open>ColH C I Q\<close> by auto
{
assume "IncidL C m"
hence "ColH B C P"
using \<open>local.cut m A C\<close> local.cut_def by blast
hence False
by (simp add: assms(1))
}
have "IncidL B lo"
using ColH_def \<open>BetH B Q C\<close> \<open>IncidL C lo\<close> \<open>IncidL Q lo\<close> betH_colH
inter_incid_uniquenessH by blast
have "I = B"
using \<open>IncidL B lo\<close> \<open>IncidL B m\<close> \<open>IncidL I lo\<close> \<open>IncidL I m\<close>
\<open>IncidL Q lo\<close> \<open>\<not> IncidL Q m\<close> inter_incid_uniquenessH by blast
hence ?thesis
using \<open>BetH B Q C\<close> \<open>BetH C I Q\<close> between_only_one by blast
}
ultimately show ?thesis
by blast
qed
ultimately have ?t
using Bet_def by auto
}
moreover
{
assume "cut l C P"
then obtain I where "IncidL I l" and "BetH C I P"
using local.cut_def by blast
have "A = I"
proof -
obtain s where "IncidL A s" and "IncidL C s"
using \<open>A \<noteq> C\<close> line_existence by blast
{
assume "IncidL Q s"
have "A \<noteq> Q"
using \<open>Q \<noteq> A\<close> by blast
have "EqL l s"
using Is_line \<open>A \<noteq> Q\<close> \<open>IncidL A l\<close> \<open>IncidL A s\<close> \<open>IncidL Q l\<close>
\<open>IncidL Q s\<close> line_uniqueness by presburger
hence False
using \<open>A \<noteq> Q\<close> \<open>IncidL A l\<close> \<open>IncidL A s\<close> \<open>IncidL C l \<Longrightarrow> False\<close>
\<open>IncidL C s\<close> \<open>IncidL Q l\<close> \<open>IncidL Q s\<close> inter_incid_uniquenessH by blast
}
moreover
have "ColH C I P"
by (simp add: \<open>BetH C I P\<close> betH_colH)
have "ColH A P C"
by (simp add: \<open>BetH A P C\<close> betH_colH)
then obtain s0 where "IncidL A s0" and "IncidL P s0" and "IncidL C s0"
using ColH_def by blast
have "EqL s s0"
using Is_line \<open>A \<noteq> C\<close> \<open>IncidL A s0\<close> \<open>IncidL A s\<close> \<open>IncidL C s0\<close>
\<open>IncidL C s\<close> line_uniqueness by presburger
obtain s1 where "IsL s1" and "IncidL C s1" and "IncidL I s1" and "IncidL P s1"
using ColH_def \<open>ColH C I P\<close> by blast
have "EqL s s1"
by (metis EqL_trans Is_line \<open>BetH C I P\<close> \<open>EqL s s0\<close> \<open>IncidL C s0\<close>
\<open>IncidL C s1\<close> \<open>IncidL P s0\<close> \<open>IncidL P s1\<close> between_diff line_uniqueness)
hence "IncidL I s"
by (meson EqL_sym IncidL_morphism Is_line \<open>IncidL C s\<close> \<open>IncidL I s1\<close>)
ultimately show ?thesis
using \<open>IncidL A l\<close> \<open>IncidL A s\<close> \<open>IncidL I l\<close> \<open>IncidL Q l\<close>
inter_incid_uniquenessH by blast
qed
hence ?t
using \<open>BetH A P C\<close> \<open>BetH C I P\<close> between_only_one by blast
}
ultimately have ?t
by blast
}
ultimately have ?t
by blast
}
ultimately have ?t
by blast
}
ultimately have ?t
by blast
}
ultimately have ?t
by blast
}
moreover
{
assume "Q = A" and
"BetH A P C" and
"BetH B Q C"
have ?t
by (metis Bet_def \<open>BetH B Q C\<close> \<open>Q = A\<close> assms(1) assms(2) between_col
colH_trans ncolH_distincts)
}
ultimately show ?thesis
by blast
qed
moreover have "BetH A P C \<and> B = Q \<longrightarrow> ?t"
using Bet_def by blast
moreover have "BetH A P C \<and> Q = C \<longrightarrow> ?t"
by (meson Bet_def between_comm)
moreover have "A = P \<and> BetH B Q C \<longrightarrow> ?t"
using Bet_def by auto
moreover have "A = P \<and> B = Q \<longrightarrow> ?t"
using Bet_def by auto
moreover have "A = P \<and> Q = C \<longrightarrow> ?t"
using Bet_def by blast
moreover have "P = C \<and> BetH B Q C \<longrightarrow> ?t"
using assms(1) colH_trivial122 by blast
moreover have "P = C \<and> B = Q \<longrightarrow> ?t"
using assms(1) colH_trivial122 by blast
moreover have "P = C \<and> Q = C \<longrightarrow> ?t"
using assms(1) colH_trivial122 by blast
ultimately show ?thesis
by blast
qed
lemma betH_trans1:
assumes "BetH A B C" and
"BetH B C D"
shows "BetH A C D"
proof -
have "A \<noteq> B"
using assms(1) betH_distincts by blast
have "C \<noteq> B"
using assms(1) betH_distincts by blast
have "A \<noteq> C"
using assms(1) betH_expand by blast
have "D \<noteq> C"
using assms(2) betH_distincts by blast
have "D \<noteq> B"
using assms(2) between_diff by blast
obtain E where "\<not> ColH A C E"
using \<open>A \<noteq> C\<close> ncolH_exists by presburger
hence "C \<noteq> E"
by (simp add: ncolH_distincts)
obtain F where "BetH C E F"
using \<open>C \<noteq> E\<close> between_out by fastforce
have "E \<noteq> F"
using \<open>BetH C E F\<close> betH_distincts by blast
have "C \<noteq> F"
using \<open>BetH C E F\<close> between_diff by blast
have "ColH A B C"
using assms(1) betH_colH by auto
have "ColH B C D"
by (simp add: assms(2) betH_colH)
have "ColH C E F"
using \<open>BetH C E F\<close> between_col by auto
have "\<not> ColH F C B"
using ColH_def \<open>C \<noteq> B\<close> \<open>C \<noteq> F\<close> \<open>ColH A B C\<close> \<open>ColH C E F\<close> \<open>\<not> ColH A C E\<close>
inter_incid_uniquenessH by auto
have "\<exists> X. Bet B X F \<and> Bet E X A"
proof -
have "Bet A B C"
by (simp add: Bet_def assms(1))
moreover have "Bet F E C"
by (simp add: Bet_def \<open>BetH C E F\<close> between_comm)
ultimately show ?thesis
using \<open>\<not> ColH F C B\<close> inner_pasch_aux by auto
qed
then obtain G where "Bet B G F" and "Bet E G A"
by blast
{
assume "BetH B G F"
hence "ColH B G F"
by (simp add: \<open>Bet B G F\<close> bet_colH)
{
assume "BetH E G A"
hence "ColH E G A"
by (simp add: betH_colH)
{
assume "ColH D B G"
hence "ColH B D F"
by (metis betH_colH \<open>BetH B G F\<close> colH_permut_231 colH_trans colH_trivial121)
hence False
by (metis \<open>ColH B C D\<close> \<open>D \<noteq> B\<close> \<open>\<not> ColH F C B\<close> colH_permut_132
colH_trans colH_trivial121)
}
obtain m where "IncidL C m" and "IncidL E m"
using \<open>C \<noteq> E\<close> line_existence by blast
{
assume "cut m A G \<or> cut m B G"
moreover
{
assume "cut m A G"
then obtain E' where "IncidL E' m" and "BetH A E' G"
using local.cut_def by blast
have "E = E'"
proof -
have "C \<noteq> F"
by (simp add: \<open>C \<noteq> F\<close>)
moreover have "ColH A G E"
by (simp add: \<open>ColH E G A\<close> colH_permut_321)
moreover have "ColH A G E'"
using \<open>BetH A E' G\<close> between_col colH_permut_132 by blast
moreover have "ColH C F E"
by (simp add: \<open>ColH C E F\<close> colH_permut_132)
moreover have "\<not> ColH A G C"
by (metis betH_colH \<open>BetH A E' G\<close> \<open>\<not> ColH A C E\<close> calculation(2)
colH_trans colH_trivial121)
moreover have "ColH C F E'"
by (meson ColH_def \<open>C \<noteq> E\<close> \<open>IncidL C m\<close> \<open>IncidL E m\<close> \<open>IncidL E' m\<close>
calculation(4) inter_incid_uniquenessH)
ultimately show ?thesis
using inter_uniquenessH by blast
qed
have "\<not> Bet E G A"
using \<open>BetH A E' G\<close> \<open>BetH E G A\<close> \<open>E = E'\<close> between_only_one by blast
hence False
using \<open>Bet E G A\<close> \<open>\<not> Bet E G A\<close> by blast
}
moreover
{
assume "cut m B G"
obtain F' where "IncidL F' m" and "BetH B F' G"
using \<open>local.cut m B G\<close> local.cut_def by blast
have "ColH C E F'"
using ColH_def Is_line \<open>IncidL C m\<close> \<open>IncidL E m\<close> \<open>IncidL F' m\<close> by blast
have "B \<noteq> G"
using \<open>BetH B F' G\<close> between_diff by auto
have "\<not> ColH C E B"
using \<open>C \<noteq> E\<close> \<open>ColH C E F\<close> \<open>\<not> ColH F C B\<close> colH_trans colH_trivial121 by blast
hence "F = F'"
using inter_uniquenessH \<open>ColH C E F\<close> \<open>B \<noteq> G\<close> \<open>BetH B F' G\<close> \<open>ColH B G F\<close>
\<open>ColH C E F'\<close> between_col colH_permut_132 by blast
hence "\<not> BetH F G B"
using \<open>BetH B F' G\<close> between_only_one by blast
hence False
using \<open>BetH B G F\<close> between_comm by blast
}
ultimately have False
by blast
}
hence "\<not> (cut m A G \<or> cut m B G)"
by blast
have "\<not> ColH B D G"
using \<open>ColH D B G \<Longrightarrow> False\<close> colH_permut_213 by blast
{
assume "IncidL G m"
hence "ColH C E G"
using ColH_def Is_line \<open>IncidL C m\<close> \<open>IncidL E m\<close> by blast
hence "ColH A C E"
by (metis betH_colH \<open>BetH E G A\<close> colH_permut_231 colH_trans colH_trivial121)
hence False
by (simp add: \<open>\<not> ColH A C E\<close>)
}
hence "\<not> IncidL G m"
by blast
{
assume "IncidL D m"
have "ColH A C D"
by (meson ColH_def \<open>C \<noteq> B\<close> \<open>ColH A B C\<close> \<open>ColH B C D\<close> inter_incid_uniquenessH)
hence "ColH A C E"
by (meson ColH_def \<open>D \<noteq> C\<close> \<open>IncidL C m\<close> \<open>IncidL D m\<close> \<open>IncidL E m\<close>
inter_incid_uniquenessH)
hence False
by (simp add: \<open>\<not> ColH A C E\<close>)
}
hence "\<not> IncidL D m"
by blast
{
assume "IncidL B m"
hence "ColH A C E"
using ColH_def \<open>C \<noteq> B\<close> \<open>ColH B C D\<close> \<open>IncidL C m\<close> \<open>\<not> IncidL D m\<close>
inter_incid_uniquenessH by blast
hence False
by (simp add: \<open>\<not> ColH A C E\<close>)
}
hence "\<not> IncidL B m"
by blast
hence "cut m D B"
using Is_line \<open>IncidL C m\<close> \<open>\<not> IncidL D m\<close> assms(2) between_comm
local.cut_def by blast
obtain p where "IncidP B p" and "IncidP D p" and "IncidP G p"
using \<open>\<not> ColH B D G\<close> plan_existence by blast
have "(\<not> ColH B D G \<and> IncidP B p \<and> IncidP D p \<and> IncidP G p \<and>
IncidLP m p \<and> \<not> IncidL G m \<and> cut m B D) \<longrightarrow> (cut m B G \<or> cut m D G)"
using IncidLP_def pasch by blast
moreover have "\<not> ColH B D G \<and> IncidP B p \<and> IncidP D p \<and> IncidP G p \<and>
IncidLP m p \<and> \<not> IncidL G m \<and> cut m B D"
by (metis betH_colH Is_line Is_plane \<open>BetH B G F\<close> \<open>C \<noteq> E\<close> \<open>C \<noteq> F\<close> \<open>ColH B C D\<close>
\<open>ColH C E F\<close> \<open>D \<noteq> B\<close> \<open>IncidL C m\<close> \<open>IncidL E m\<close> \<open>IncidP B p\<close> \<open>IncidP D p\<close>
\<open>IncidP G p\<close> \<open>\<not> ColH B D G\<close> \<open>\<not> IncidL G m\<close> \<open>local.cut m D B\<close> colH_permut_312
cut_comm line_on_plane line_on_plane')
ultimately have "cut m B G \<or> cut m D G"
by blast
moreover
{
assume "cut m B G"
hence ?thesis
using \<open>\<not> (local.cut m A G \<or> local.cut m B G)\<close> by blast
}
moreover
{
assume "cut m D G"
obtain HX where "IncidL HX m" and "BetH D HX G"
using \<open>local.cut m D G\<close> local.cut_def by auto
{
assume "ColH G D A"
have "ColH A D B"
by (metis \<open>C \<noteq> B\<close> \<open>ColH A B C\<close> \<open>ColH B C D\<close> colH_permut_231 colH_trans
colH_trivial121)
hence False
by (metis \<open>ColH G D A\<close> \<open>\<not> ColH B D G\<close> assms(1) assms(2) between_comm
between_only_one' colH_permut_321 colH_trans colH_trivial122)
}
hence "\<not> ColH G D A"
by blast
{
assume "IncidL A m"
hence "ColH A C E"
using ColH_def \<open>A \<noteq> C\<close> \<open>ColH A B C\<close> \<open>IncidL C m\<close> \<open>\<not> IncidL B m\<close>
inter_incid_uniquenessH by blast
hence False
by (simp add: \<open>\<not> ColH A C E\<close>)
}
hence "\<not> IncidL A m"
by blast
have "cut m G D"
by (simp add: \<open>local.cut m D G\<close> cut_comm)
obtain p where "IncidP G p" and "IncidP D p" and "IncidP A p"
using \<open>\<not> ColH G D A\<close> plan_existence by blast
have "(\<not> ColH G D A \<and> IncidP G p \<and> IncidP D p \<and> IncidP A p \<and>
IncidLP m p \<and> \<not> IncidL A m \<and> cut m G D)\<longrightarrow> (cut m G A \<or> cut m D A)"
using pasch Is_line Is_plane \<open>IncidL HX m\<close> by blast
moreover
have "\<not> ColH G D A \<and> IncidP G p \<and> IncidP D p \<and> IncidP A p \<and>
IncidLP m p \<and> \<not> IncidL A m \<and> cut m G D"
proof -
have "\<not> ColH G D A \<and> IncidP G p \<and> IncidP D p \<and> IncidP A p"
using \<open>IncidP A p\<close> \<open>IncidP D p\<close> \<open>IncidP G p\<close> \<open>\<not> ColH G D A\<close> by blast
moreover
have "ColH B D C"
by (simp add: \<open>ColH B C D\<close> colH_permut_132)
have "ColH B A D"
by (metis \<open>C \<noteq> B\<close> \<open>ColH A B C\<close> \<open>ColH B C D\<close> colH_permut_231
colH_trans colH_trivial121)
hence "IncidP B p"
by (metis calculation colH_permut_231 colH_trivial122 line_on_plane')
hence "IncidP C p"
using \<open>A \<noteq> B\<close> \<open>ColH A B C\<close> \<open>IncidP A p\<close> line_on_plane' by blast
hence "IncidLP m p"
by (metis betH_colH Is_line Is_plane \<open>BetH E G A\<close> \<open>C \<noteq> E\<close> \<open>IncidL C m\<close>
\<open>IncidL E m\<close> \<open>IncidP A p\<close> \<open>IncidP G p\<close> colH_permut_321
line_on_plane line_on_plane')
moreover have "\<not> IncidL A m"
by (simp add: \<open>\<not> IncidL A m\<close>)
moreover have "cut m G D"
by (simp add: \<open>local.cut m G D\<close>)
ultimately show ?thesis
by blast
qed
ultimately have "cut m G A \<or> cut m D A"
by blast
moreover
{
assume "cut m G A"
hence ?thesis
using \<open>\<not> (local.cut m A G \<or> local.cut m B G)\<close> cut_comm by blast
}
moreover
{
assume "cut m D A"
then obtain I where "IncidL I m" and "BetH D I A"
using local.cut_def by blast
have "ColH D I A"
using \<open>BetH D I A\<close> between_col by fastforce
obtain l1 where "IsL l1" and "IncidL A l1" and "IncidL B l1" and "IncidL C l1"
using ColH_def \<open>ColH A B C\<close> by blast
obtain l2 where "IsL l2" and "IncidL B l2" and "IncidL C l2" and "IncidL D l2"
using ColH_def \<open>ColH B C D\<close> by blast
obtain l3 where "IsL l3" and "IncidL D l3" and "IncidL I l3" and "IncidL A l3"
using ColH_def \<open>ColH D I A\<close> by blast
have "A \<noteq> D"
using \<open>\<not> ColH G D A\<close> colH_trivial122 by blast
hence "BetH D C A"
by (metis \<open>BetH D I A\<close> \<open>C \<noteq> B\<close> \<open>IncidL A l1\<close> \<open>IncidL A l3\<close>
\<open>IncidL B l1\<close> \<open>IncidL B l2\<close> \<open>IncidL C l1\<close> \<open>IncidL C l2\<close> \<open>IncidL C m\<close>
\<open>IncidL D l2\<close> \<open>IncidL D l3\<close> \<open>IncidL I l3\<close> \<open>IncidL I m\<close> \<open>\<not> IncidL A m\<close>
inter_incid_uniquenessH)
hence "BetH A C D"
using between_comm by blast
}
ultimately have ?thesis
by blast
}
ultimately have ?thesis
by blast
}
moreover
{
assume "E = G"
hence ?thesis
using ColH_def \<open>BetH B G F\<close> \<open>ColH C E F\<close> \<open>E \<noteq> F\<close> \<open>\<not> ColH F C B\<close>
between_col inter_incid_uniquenessH by fastforce
}
moreover
{
assume "G = A"
hence ?thesis
by (metis \<open>A \<noteq> B\<close> \<open>BetH B G F\<close> \<open>ColH A B C\<close> \<open>\<not> ColH F C B\<close>
between_col inter_uniquenessH ncolH_distincts)
}
ultimately have ?thesis
using Bet_def \<open>Bet E G A\<close> by blast
}
moreover
{
assume "B = G"
hence ?thesis
using ColH_def \<open>A \<noteq> B\<close> \<open>Bet E G A\<close> \<open>ColH A B C\<close> \<open>\<not> ColH A C E\<close>
bet_colH inter_incid_uniquenessH by fastforce
}
moreover
{
assume "G = F"
hence False
by (metis \<open>Bet E G A\<close> \<open>ColH C E F\<close> \<open>E \<noteq> F\<close> \<open>G = F\<close> \<open>\<not> ColH A C E\<close>
bet_colH colH_permut_321 colH_trans colH_trivial122)
hence ?thesis
by blast
}
ultimately show ?thesis
using Bet_def \<open>Bet B G F\<close> by blast
qed
lemma betH_trans2:
assumes "BetH A B C" and
"BetH B C D"
shows "BetH A B D"
using assms(1) assms(2) betH_trans1 between_comm by blast
lemma betH_trans:
assumes "BetH A B C" and
"BetH B C D"
shows "BetH A B D \<and> BetH A C D"
using assms(1) assms(2) betH_trans1 betH_trans2 by blast
lemma not_cut3:
assumes "IncidP A p" and
"IncidP B p" and
"IncidP C p" and
"IncidLP l p" and
"\<not> IncidL A l" and
"\<not> ColH A B C" and
"\<not> cut l A B" and
"\<not> cut l A C"
shows "\<not> cut l B C"
by (meson colH_permut_312 cut_comm IncidLP_def assms(1) assms(2) assms(3)
assms(4) assms(5) assms(6) assms(7) assms(8) pasch)
lemma betH_trans0:
assumes "BetH A B C" and
"BetH A C D"
shows "BetH B C D \<and> BetH A B D"
proof -
have "A \<noteq> B"
using assms(1) betH_distincts by auto
have "A \<noteq> C"
using assms(1) between_diff by auto
have "A \<noteq> D"
using assms(2) between_diff by presburger
obtain G where "\<not> ColH A B G"
using \<open>A \<noteq> B\<close> ncolH_exists by presburger
have "B \<noteq> G"
using \<open>\<not> ColH A B G\<close> colH_trivial122 by blast
obtain F where "BetH B G F"
using \<open>B \<noteq> G\<close> between_out by blast
have "B \<noteq> F"
using \<open>BetH B G F\<close> between_diff by auto
{
assume "C = F"
have "ColH B F A"
using \<open>C = F\<close> assms(1) between_col colH_permut_231 by presburger
moreover have "ColH B F B"
by (simp add: colH_trivial121)
moreover have "ColH B F G"
using \<open>BetH B G F\<close> betH_expand colH_permut_132 by blast
ultimately have "ColH A B G"
using colH_trans \<open>B \<noteq> F\<close> by blast
hence ?thesis
by (simp add: \<open>\<not> ColH A B G\<close>)
}
moreover
{
assume "C \<noteq> F"
obtain l where "IncidL C l" and "IncidL F l"
using \<open>C \<noteq> F\<close> line_existence by blast
{
assume "cut l A B"
then obtain X where "IncidL X l" and "BetH A X B"
using local.cut_def by blast
hence "X = C"
proof -
have "\<not> ColH A B F"
by (meson ColH_def \<open>B \<noteq> F\<close> \<open>BetH B G F\<close> \<open>\<not> ColH A B G\<close>
between_col inter_incid_uniquenessH)
moreover have "ColH A B X"
by (simp add: \<open>BetH A X B\<close> between_col colH_permut_132)
moreover have "ColH A B C"
using assms(1) betH_colH by presburger
moreover have "ColH F C X"
using ColH_def Is_line \<open>IncidL C l\<close> \<open>IncidL F l\<close> \<open>IncidL X l\<close> by blast
moreover have "ColH F C C"
by (simp add: colH_trivial122)
ultimately show ?thesis
by (metis inter_uniquenessH)
qed
have False
using \<open>BetH A X B\<close> \<open>X = C\<close> assms(1) between_comm between_only_one by blast
}
hence "\<not> cut l A B"
by blast
{
assume "cut l B G"
obtain X where "IncidL X l" and "BetH B X G"
using \<open>local.cut l B G\<close> local.cut_def by blast
hence "ColH B X F"
by (meson \<open>BetH B G F\<close> \<open>B \<noteq> G\<close> between_col colH_permut_132
colH_trans colH_trivial121)
hence False
using ColH_def \<open>BetH B G F\<close> \<open>BetH B X G\<close> \<open>IncidL F l\<close> \<open>IncidL X l\<close>
\<open>local.cut l B G\<close> between_comm between_only_one inter_incid_uniquenessH
local.cut_def by blast
}
hence "\<not> cut l B G"
by blast
obtain p where "IncidP A p" and "IncidP B p" and "IncidP G p"
using \<open>\<not> ColH A B G\<close> plan_existence by blast
have "\<not> cut l A G"
proof -
have "IncidLP l p"
by (metis Hilbert_neutral_dimensionless.line_on_plane'
Hilbert_neutral_dimensionless_axioms Is_line Is_plane \<open>BetH B G F\<close> \<open>C \<noteq> F\<close>
\<open>IncidL C l\<close> \<open>IncidL F l\<close> \<open>IncidP A p\<close> \<open>IncidP B p\<close> \<open>IncidP G p\<close>
assms(1) betH_expand line_on_plane)
moreover
{
assume "IncidL B l"
have "ColH B C G"
by (meson ColH_def \<open>B \<noteq> F\<close> \<open>BetH B G F\<close> \<open>IncidL B l\<close> \<open>IncidL C l\<close>
\<open>IncidL F l\<close> between_col inter_incid_uniquenessH)
have "ColH B F C"
using ColH_def Is_line \<open>IncidL B l\<close> \<open>IncidL C l\<close> \<open>IncidL F l\<close> by blast
hence False
using betH_expand colH_permut_231 colH_trans colH_trivial121
\<open>ColH B C G\<close> \<open>\<not> ColH A B G\<close> assms(1) by fast
}
hence "\<not> IncidL B l"
by blast
moreover have "\<not> ColH B A G"
using \<open>\<not> ColH A B G\<close> colH_permut_213 by blast
moreover have "\<not> cut l B A"
using \<open>\<not> local.cut l A B\<close> cut_comm by blast
ultimately show ?thesis
using \<open>IncidP A p\<close> \<open>IncidP B p\<close> \<open>IncidP G p\<close> \<open>\<not> local.cut l B G\<close> not_cut3 by blast
qed
have "cut l A G \<or> cut l D G"
proof -
{
assume "ColH A D G"
have "ColH A C A"
by (simp add: colH_trivial121)
moreover have "ColH A C D"
by (simp add: assms(2) between_col)
moreover have "ColH A C B"
using assms(1) between_col colH_permut_132 by blast
ultimately have "ColH A D B"
using \<open>A \<noteq> C\<close> colH_trans by blast
hence False
using \<open>A \<noteq> D\<close> \<open>ColH A D G\<close> \<open>\<not> ColH A B G\<close> colH_trans colH_trivial121 by blast
}
hence "\<not> ColH A D G"
by blast
then obtain p where "IncidP A p" and "IncidP D p" and "IncidP G p"
using plan_existence by blast
show ?thesis
proof -
have "\<not> ColH A D G"
by (simp add: \<open>\<not> ColH A D G\<close>)
moreover have "IsP p"
using Is_plane \<open>IncidP D p\<close> by fastforce
moreover have "IsL l"
using Is_line \<open>IncidL C l\<close> by auto
moreover have "IncidP A p"
by (simp add: \<open>IncidP A p\<close>)
moreover have "IncidP D p"
by (simp add: \<open>IncidP D p\<close>)
moreover have "IncidP G p"
using \<open>IncidP G p\<close> by auto
moreover
have "IncidP C p"
by (metis \<open>A \<noteq> D\<close> assms(2) between_col calculation(4) calculation(5)
colH_permut_312 line_on_plane')
have "IncidP F p"
by (meson \<open>A \<noteq> C\<close> \<open>B \<noteq> G\<close> \<open>BetH B G F\<close> \<open>IncidP C p\<close> assms(1)
between_col calculation(4) calculation(6) colH_permut_132 line_on_plane')
hence "IncidLP l p"
using \<open>C \<noteq> F\<close> \<open>IncidL C l\<close> \<open>IncidL F l\<close> \<open>IncidP C p\<close> calculation(2)
calculation(3) line_on_plane by blast
moreover
{
assume "IncidL G l"
have "ColH G F C"
using ColH_def Is_line \<open>IncidL C l\<close> \<open>IncidL F l\<close> \<open>IncidL G l\<close> by blast
hence "ColH B C G"
using \<open>BetH B G F\<close> betH_colH colH_permut_231 colH_trans colH_trivial121 by blast
hence False
by (metis betH_expand colH_permut_231 colH_trans colH_trivial121
\<open>\<not> ColH A B G\<close> assms(1))
}
hence "\<not> IncidL G l"
by blast
moreover have "cut l A D"
proof -
{
assume "IncidL A l"
hence "ColH A C F"
using ColH_def Is_line \<open>IncidL C l\<close> \<open>IncidL F l\<close> by blast
have "ColH A B F"
using \<open>ColH A C F\<close> assms(1) betH_colH colH_permut_132 colH_trans
colH_trivial121 by blast
hence False
by (metis \<open>B \<noteq> F\<close> \<open>BetH B G F\<close> \<open>\<not> ColH A B G\<close> between_col
colH_permut_231 colH_trans colH_trivial121)
}
hence "\<not> IncidL A l"
by blast
moreover
{
assume "IncidL D l"
hence "ColH C D F"
using ColH_def \<open>IncidL C l\<close> \<open>IncidL F l\<close> \<open>IsL l\<close> by auto
hence "ColH A C F"
using assms(2) betH_colH colH_permut_231 colH_trans colH_trivial121 by blast
hence "ColH A B F"
by (metis assms(1) betH_colH colH_permut_312 colH_trans colH_trivial121)
hence False
by (metis \<open>B \<noteq> F\<close> \<open>BetH B G F\<close> \<open>\<not> ColH A B G\<close> between_col
colH_permut_231 colH_trans colH_trivial121)
}
hence "\<not> IncidL D l"
by blast
moreover have "IncidL C l"
by (simp add: \<open>IncidL C l\<close>)
moreover have "BetH A C D"
by (simp add: assms(2))
ultimately show ?thesis
using \<open>IsL l\<close> local.cut_def by blast
qed
ultimately show ?thesis
using pasch by blast
qed
qed
moreover
{
assume "cut l D G"
{
assume "ColH D G B"
have "ColH A B D"
by (meson \<open>A \<noteq> C\<close> assms(1) assms(2) between_col colH_permut_132
colH_trans colH_trivial121)
have "B \<noteq> D"
using \<open>\<not> local.cut l A G\<close> \<open>\<not> local.cut l B G\<close> calculation by auto
hence "ColH A B G"
by (meson ColH_def \<open>ColH A B D\<close> \<open>ColH D G B\<close> inter_incid_uniquenessH)
hence False
using \<open>\<not> ColH A B G\<close> by blast
}
hence "\<not> ColH D G B"
by blast
{
assume "IncidL B l"
hence "ColH B F C"
using ColH_def Is_line \<open>IncidL C l\<close> \<open>IncidL F l\<close> by blast
have "B \<noteq> C"
using assms(1) betH_distincts by presburger
hence "ColH A B G"
by (metis \<open>B \<noteq> F\<close> \<open>BetH B G F\<close> \<open>ColH B F C\<close> assms(1) between_col
colH_permut_231 colH_trans colH_trivial121)
hence False
by (simp add: \<open>\<not> ColH A B G\<close>)
}
hence "\<not> IncidL B l"
by blast
obtain p where "IncidP D p" and "IncidP G p" and "IncidP B p"
using \<open>\<not> ColH D G B\<close> plan_existence by blast
have "(\<not> ColH D G B \<and> IncidP D p \<and> IncidP G p \<and> IncidP B p \<and>
IncidLP l p \<and> \<not> IncidL B l \<and> cut l D G) \<longrightarrow> (cut l D B \<or> cut l G B)"
using Is_line Is_plane \<open>IncidL C l\<close> pasch by blast
moreover
have "(\<not> ColH D G B \<and> IncidP D p \<and> IncidP G p \<and> IncidP B p \<and>
IncidLP l p \<and> \<not> IncidL B l \<and> cut l D G)"
proof -
have "\<not> ColH D G B \<and> IncidP D p \<and> IncidP G p \<and> IncidP B p"
by (simp add: \<open>IncidP B p\<close> \<open>IncidP D p\<close> \<open>IncidP G p\<close> \<open>\<not> ColH D G B\<close>)
moreover have "IncidLP l p"
proof -
have "ColH B D C"
by (meson \<open>A \<noteq> C\<close> assms(1) assms(2) between_col colH_permut_132
colH_trans colH_trivial122)
hence "IncidP C p"
by (metis calculation colH_trivial121 line_on_plane')
moreover have "IncidP F p"
using \<open>BetH B G F\<close> \<open>IncidP B p\<close> \<open>IncidP G p\<close> betH_colH line_on_plane' by blast
ultimately show ?thesis
using Is_line Is_plane \<open>C \<noteq> F\<close> \<open>IncidL C l\<close> \<open>IncidL F l\<close> line_on_plane by blast
qed
moreover have "\<not> IncidL B l"
by (simp add: \<open>\<not> IncidL B l\<close>)
moreover have "cut l D G"
by (simp add: \<open>local.cut l D G\<close>)
ultimately show ?thesis
by blast
qed
ultimately have "cut l D B \<or> cut l G B"
using \<open>\<not> ColH D G B \<and> IncidP D p \<and> IncidP G p \<and> IncidP B p \<and>
IncidLP l p \<and> \<not> IncidL B l \<and> local.cut l D G \<longrightarrow> local.cut l D B \<or> local.cut l G B\<close>
by blast
moreover
{
assume "cut l D B"
then obtain C' where "IncidL C' l" and "BetH D C' B"
using local.cut_def by blast
have "ColH C C' F"
using ColH_def Is_line \<open>IncidL C l\<close> \<open>IncidL C' l\<close> \<open>IncidL F l\<close> by blast
have "\<not> ColH A B F"
by (metis \<open>BetH B G F\<close> \<open>\<not> ColH A B G\<close> betH_colH colH_permut_312
colH_trans colH_trivial122)
have "ColH B D A"
by (metis (full_types) \<open>A \<noteq> C\<close> assms(1) assms(2) between_col colH_trans
ncolH_distincts)
hence "ColH A B C'"
using ColH_def \<open>BetH D C' B\<close> betH_colH inter_incid_uniquenessH by fastforce
then have "C = C'" using inter_uniquenessH
by (metis (full_types) \<open>ColH C C' F\<close> \<open>\<not> ColH A B F\<close> assms(1)
betH_colH ncolH_distincts)
hence "BetH B C D \<and> BetH A B D"
using \<open>BetH D C' B\<close> assms(1) betH_trans between_comm by blast
}
moreover
{
assume "cut l G B"
hence "BetH B C D \<and> BetH A B D"
using \<open>\<not> local.cut l B G\<close> cut_comm by blast
}
ultimately have "BetH B C D \<and> BetH A B D"
by blast
}
ultimately have "BetH B C D \<and> BetH A B D"
using \<open>\<not> local.cut l A G\<close> by fastforce
}
ultimately show ?thesis
by blast
qed
lemma betH_outH2__betH:
assumes "BetH A B C" and
"outH B C C'" and
"outH B A A'"
shows "BetH A' B C'"
proof -
have "BetH B C C' \<or> BetH B C' C \<or> (B \<noteq> C \<and> C = C')"
using assms(2) outH_def by blast
moreover have "BetH B A A' \<or> BetH B A' A \<or> (B \<noteq> A \<and> A = A')"
using assms(3) outH_def by blast
moreover
{
assume "BetH B C C'"
hence "BetH A' B C"
using assms(1) betH_trans betH_trans0 between_comm calculation(2) by blast
}
moreover
{
assume "BetH B C' C"
hence "BetH A' B C"
using assms(1) betH_trans betH_trans0 between_comm calculation(2) by blast
}
moreover
{
assume "B \<noteq> C \<and> C = C'"
hence "BetH A' B C"
using assms(1) betH_trans betH_trans0 between_comm calculation(2) by blast
}
ultimately show ?thesis
by (meson betH_trans betH_trans0 between_comm)
qed
lemma cong_existence':
fixes A B::TPoint
assumes "A \<noteq> B" and
"IncidL M l"
shows "\<exists> A' B'. IncidL A' l \<and> IncidL B' l \<and> BetH A' M B' \<and> CongH M A' A B \<and> CongH M B' A B"
proof -
have "\<exists> P. IncidL P l \<and> M \<noteq> P"
by (metis Is_line assms(2) two_points_on_line)
then obtain P where "IncidL P l" and "M \<noteq> P"
by blast
obtain P' where "BetH P M P'"
using \<open>M \<noteq> P\<close> between_out by presburger
obtain A' where "IncidL A' l" and "outH M P A'" and "CongH M A' A B"
using Is_line \<open>IncidL P l\<close> \<open>M \<noteq> P\<close> assms(1) assms(2) cong_existence by blast
moreover
have "IncidL P' l"
using ColH_def \<open>BetH P M P'\<close> \<open>IncidL P l\<close> assms(2) betH_colH inter_incid_uniquenessH by blast
then obtain B' where "IncidL B' l" and "outH M P' B'" and "CongH M B' A B"
by (metis Is_line \<open>BetH P M P'\<close> assms(1) assms(2) betH_distincts cong_existence)
ultimately show ?thesis
using \<open>BetH P M P'\<close> betH_outH2__betH by blast
qed
lemma betH_to_bet:
assumes "BetH A B C"
shows "Bet A B C \<and> A \<noteq> B \<and> B \<noteq> C \<and> A \<noteq> C"
using Bet_def assms betH_distincts by presburger
lemma betH_line:
assumes "BetH A B C"
shows "\<exists> l. IncidL A l \<and> IncidL B l \<and> IncidL C l"
by (meson ColH_def assms betH_colH)
(****************** between_identity ************************)
lemma bet_identity:
assumes "Bet A B A"
shows "A = B"
using Bet_def assms between_diff by blast
(************************************************************)
lemma morph:
assumes "IsL l" and
"IsL m " and
"EqL l m"
shows "\<forall> A. IncidL A l \<longleftrightarrow> IncidL A m"
using EqL_sym IncidL_morphism assms(1) assms(2) assms(3) by blast
lemma point3_online_exists:
assumes "IncidL A l" and
"IncidL B l"
shows "\<exists> C. IncidL C l \<and> C \<noteq> A \<and> C \<noteq> B"
by (metis (full_types) assms(2) betH_distincts cong_existence' lower_dim_2)
lemma not_betH121:
shows "\<not> BetH A B A"
using between_diff by blast
(***************************** cong_identity ***********************)
lemma cong_identity:
assumes "Cong A B C C"
shows "A = B"
using Cong_def assms by presburger
(************************ cong_inner_transitivity ****************************)
lemma cong_inner_transitivity:
assumes "Cong A B C D" and
"Cong A B E F"
shows "Cong C D E F"
by (metis Cong_def assms(1) assms(2) cong_pseudo_transitivity)
lemma other_point_on_line:
assumes "IncidL A l"
shows "\<exists> B. A \<noteq> B \<and> IncidL B l"
by (metis Is_line assms two_points_on_line)
lemma bet_disjoint:
assumes "BetH A B C"
shows "disjoint A B B C"
proof -
{
assume "\<not> disjoint A B B C"
then obtain P where "BetH A P B" and "BetH B P C"
using disjoint_def by blast
have "BetH P B C \<and> BetH A P C"
using betH_trans0 \<open>BetH A P B\<close> assms by blast
hence False
using \<open>BetH B P C\<close> between_only_one' by blast
}
thus ?thesis
by blast
qed
lemma addition_betH:
assumes "BetH A B C" and
"BetH A' B' C'" and
"CongH A B A' B'" and
"CongH B C B' C'"
shows "CongH A C A' C'"
using addition assms(1) assms(2) assms(3) assms(4) bet_disjoint between_col by blast
lemma outH_trivial:
assumes "A \<noteq> B"
shows "outH A B B"
by (simp add: assms outH_def)
lemma same_side_refl:
assumes "IsL l" and (** ROLL ADD IsL l **)
"\<not> IncidL A l"
shows "same_side A A l"
proof -
obtain x x0 where "IncidL x0 l" and "IncidL x l" and "x \<noteq> x0"
using two_points_on_line assms(1) by blast
{
assume "A = x"
hence "same_side A A l"
using \<open>IncidL x l\<close> assms(2) by fastforce
}
moreover
{
assume "A \<noteq> x"
obtain x1 where "BetH A x x1"
by (metis \<open>IncidL x l\<close> assms(2) between_out)
have "\<not> IncidL x1 l"
using \<open>BetH A x x1\<close> \<open>IncidL x l\<close> assms(2) betH_expand betH_line
inter_incid_uniquenessH by blast
moreover have "\<exists> I. IncidL I l \<and> BetH A I x1"
using \<open>BetH A x x1\<close> \<open>IncidL x l\<close> by blast
ultimately have "same_side A A l"
using assms(1) assms(2) local.cut_def same_side_def by blast
}
ultimately show ?thesis
by blast
qed
lemma same_side_prime_refl:
assumes "\<not> ColH A B C"
shows "same_side' C C A B"
using ColH_def assms ncolH_distincts same_side'_def same_side_refl by presburger
lemma outH_expand:
assumes "outH A B C"
shows "outH A B C \<and> ColH A B C \<and> A \<noteq> C \<and> A \<noteq> B"
by (metis assms betH_colH colH_permut_132 colH_trivial122 outH_def)
lemma construction_uniqueness:
assumes "BetH A B D" and
"BetH A B E" and
"CongH B D B E"
shows "D = E"
proof -
have "A \<noteq> D"
using assms(1) between_diff by blast
have "A \<noteq> E"
using assms(2) not_betH121 by blast
have "ColH A B D"
by (simp add: assms(1) betH_colH)
have "ColH A B E"
using assms(2) betH_colH by fastforce
have "A \<noteq> B"
using assms(1) betH_distincts by auto
then obtain C where "\<not> ColH A B C"
using ncolH_exists by presburger
have "CongaH A C D A C E"
proof -
have"\<not> ColH A C D"
by (meson \<open>A \<noteq> D\<close> \<open>ColH A B D\<close> \<open>\<not> ColH A B C\<close> colH_permut_132
colH_trans colH_trivial121)
moreover have "\<not> ColH A C E"
by (metis \<open>A \<noteq> E\<close> \<open>ColH A B E\<close> \<open>\<not> ColH A B C\<close> colH_trivial121
colH_trivial122 inter_uniquenessH)
moreover have "CongH A C A C"
by (metis calculation(1) colH_trivial112 congH_refl)
moreover have "CongH A D A E"
by (metis addition_betH assms(1) assms(2) assms(3) congH_refl)
moreover have "CongaH C A D C A E"
proof-
have "CongaH C A B C A B"
by (meson \<open>\<not> ColH A B C\<close> colH_permut_231 conga_refl)
moreover have "outH A C C"
using \<open>\<not> ColH A C D\<close> ncolH_distincts outH_trivial by presburger
moreover have "outH A B D"
by (simp add: assms(1) outH_def)
moreover have "outH A B E"
by (simp add: assms(2) outH_def)
ultimately show ?thesis
using conga_out_conga by blast
qed
ultimately show ?thesis
using cong_5 by blast
qed
moreover have "\<not> ColH D C A"
by (metis ncolH_distincts \<open>A \<noteq> D\<close> \<open>ColH A B D\<close> \<open>\<not> ColH A B C\<close> inter_uniquenessH)
moreover hence "\<not> ColH A C D"
using colH_permut_321 by blast
moreover hence "\<not> ColH C A D"
using colH_permut_213 by blast
moreover have "same_side' D E C A"
proof -
obtain F where "BetH B A F"
using \<open>A \<noteq> B\<close> between_out by fastforce
obtain l where "IncidL C l" and "IncidL A l"
using ColH_def colH_trivial122 by blast
have "C \<noteq> A"
using calculation(2) colH_trivial122 by auto
moreover
have "\<forall> l. IsL l \<and> IncidL C l \<and> IncidL A l \<longrightarrow> same_side D E l"
proof -
{
fix l
assume "IsL l" and "IncidL C l" and "IncidL A l"
have "cut l D F"
proof -
{
assume "IncidL D l"
have "ColH A C D"
using ColH_def \<open>IncidL A l\<close> \<open>IncidL C l\<close> \<open>IncidL D l\<close> \<open>IsL l\<close> by blast
have False
using \<open>ColH A C D\<close> \<open>\<not> ColH A C D\<close> by auto
}
hence "\<not> IncidL D l"
by blast
moreover
{
assume "IncidL F l"
have "ColH A C F"
using ColH_def Is_line \<open>IncidL A l\<close> \<open>IncidL C l\<close> \<open>IncidL F l\<close> by blast
have False
using ColH_def \<open>BetH B A F\<close> \<open>IncidL A l\<close> \<open>IncidL C l\<close> \<open>IncidL F l\<close>
\<open>IsL l\<close> \<open>\<not> ColH A B C\<close> betH_distincts betH_line inter_incid_uniquenessH by blast
}
hence "\<not> IncidL F l"
by blast
moreover have "\<exists> I. IncidL I l \<and> BetH D I F"
using \<open>BetH B A F\<close> \<open>IncidL A l\<close> assms(1) betH_trans between_comm by blast
ultimately show ?thesis
by (simp add: \<open>IsL l\<close> local.cut_def)
qed
moreover have "cut l E F"
proof -
{
assume "IncidL E l"
have "ColH A C E"
using ColH_def \<open>IncidL A l\<close> \<open>IncidL C l\<close> \<open>IncidL E l\<close> \<open>IsL l\<close> by blast
hence False
using ColH_def \<open>A \<noteq> E\<close> \<open>\<not> ColH A B C\<close> assms(2) betH_line
inter_incid_uniquenessH by blast
}
hence "\<not> IncidL E l"
by blast
moreover
{
assume "IncidL F l"
have "ColH A C F"
using \<open>IncidL F l\<close> \<open>local.cut l D F\<close> local.cut_def by auto
hence False
using \<open>IncidL F l\<close> \<open>local.cut l D F\<close> local.cut_def by blast
}
hence "\<not> IncidL F l"
by blast
moreover have "\<exists> I. IncidL I l \<and> BetH E I F"
using \<open>BetH B A F\<close> \<open>IncidL A l\<close> assms(2) betH_trans between_comm by blast
ultimately show ?thesis
by (simp add: \<open>IsL l\<close> local.cut_def)
qed
ultimately have "same_side D E l"
using \<open>IsL l\<close> same_side_def by blast
}
thus ?thesis
by blast
qed
ultimately show ?thesis
using same_side'_def by auto
qed
ultimately have "outH C D E"
using same_side_prime_refl by (meson cong_4_uniqueness conga_refl)
thus ?thesis
using \<open>ColH A B D\<close> \<open>ColH A B E\<close> \<open>\<not> ColH A B C\<close> colH_trivial122
inter_uniquenessH outH_expand by blast
qed
lemma out_distinct:
assumes "outH A B C"
shows "A \<noteq> B \<and> A \<noteq> C"
using assms outH_expand by auto
lemma out_same_side:
assumes "IncidL A l" and
"\<not> IncidL B l" and
"outH A B C"
shows "same_side B C l"
proof -
have "A \<noteq> B"
using assms(1) assms(2) by blast
obtain P where "BetH B A P"
using \<open>A \<noteq> B\<close> between_out by presburger
{
assume "IncidL P l"
have "ColH B A P"
by (simp add: \<open>BetH B A P\<close> between_col)
obtain ll where "IncidL B ll" and "IncidL A ll" and "IncidL P ll"
using \<open>BetH B A P\<close> betH_line by blast
hence "EqL l ll"
by (metis Is_line \<open>BetH B A P\<close> \<open>IncidL P l\<close> assms(1) betH_distincts line_uniqueness)
hence False
using Is_line \<open>IncidL B ll\<close> \<open>IncidL P l\<close> assms(2) morph by blast
}
hence "\<not> IncidL P l"
by blast
have "cut l B P"
using assms(1) \<open>BetH B A P\<close> Is_line \<open>\<not> IncidL P l\<close> assms(2) local.cut_def by blast
moreover have "cut l C P"
proof -
have "\<not> IncidL C l"
using ColH_def assms(1) assms(2) assms(3) inter_incid_uniquenessH
outH_expand by blast
moreover have "BetH C A P"
by (metis betH_outH2__betH betH_to_bet outH_trivial \<open>BetH B A P\<close> assms(3))
ultimately show ?thesis
using assms(1) Is_line \<open>\<not> IncidL P l\<close> local.cut_def by blast
qed
ultimately show ?thesis
using Is_line assms(1) same_side_def by blast
qed
lemma between_one:
assumes "A \<noteq> B" and
"A \<noteq> C" and
"B \<noteq> C" and
"ColH A B C"
shows "BetH A B C \<or> BetH B C A \<or> BetH B A C"
proof -
obtain D where "\<not> ColH A C D"
using assms(2) ncolH_exists by presburger
have "B \<noteq> D"
using \<open>\<not> ColH A C D\<close> assms(4) colH_permut_132 by blast
obtain G where "BetH B D G"
using \<open>B \<noteq> D\<close> between_out by blast
have "A \<noteq> D"
using \<open>\<not> ColH A C D\<close> colH_trivial121 by force
then obtain lAD where "IsL lAD" and "IncidL A lAD" and "IncidL D lAD"
using line_existence by blast
have "C \<noteq> D"
using \<open>\<not> ColH A C D\<close> colH_trivial122 by blast
then obtain lCD where "IsL lCD" and "IncidL C lCD" and "IncidL D lCD"
using line_existence by blast
{
assume "ColH B G C"
hence False
by (metis \<open>BetH B D G\<close> \<open>\<not> ColH A C D\<close> assms(3) assms(4) between_col
colH_permut_312 colH_trans colH_trivial122 not_betH121)
}
hence "\<not> ColH B G C"
by blast
{
assume "ColH B G A"
hence False
by (meson colH_permut_312 colH_trans colH_trivial122 \<open>\<not> ColH B G C\<close>
assms(1) assms(4))
}
hence "\<not> ColH B G A"
by blast
have "\<not> IncidL C lAD"
using ColH_def \<open>IncidL A lAD\<close> \<open>IncidL D lAD\<close> \<open>IsL lAD\<close> \<open>\<not> ColH A C D\<close> by blast
have "\<not> IncidL A lCD"
using \<open>A \<noteq> D\<close> \<open>IncidL A lAD\<close> \<open>IncidL C lCD\<close> \<open>IncidL D lAD\<close> \<open>IncidL D lCD\<close>
\<open>\<not> IncidL C lAD\<close> inter_incid_uniquenessH by blast
{
assume "IncidL B lAD"
have "ColH A B D"
using ColH_def \<open>IncidL A lAD\<close> \<open>IncidL B lAD\<close> \<open>IncidL D lAD\<close> \<open>IsL lAD\<close> by blast
hence False
using \<open>\<not> ColH A C D\<close> assms(1) assms(4) colH_trans colH_trivial121 by blast
}
hence "\<not> IncidL B lAD"
by blast
{
assume "IncidL G lAD"
have "ColH A D G"
using ColH_def Is_line \<open>IncidL A lAD\<close> \<open>IncidL D lAD\<close> \<open>IncidL G lAD\<close> by blast
hence False
using betH_colH \<open>BetH B D G\<close> \<open>IncidL D lAD\<close> \<open>IncidL G lAD\<close> \<open>\<not> IncidL B lAD\<close>
betH_line inter_incid_uniquenessH by blast
}
hence "\<not> IncidL G lAD"
by blast
have "cut lAD B G"
using \<open>BetH B D G\<close> \<open>IncidL D lAD\<close> \<open>IsL lAD\<close> \<open>\<not> IncidL B lAD\<close> \<open>\<not> IncidL G lAD\<close>
local.cut_def by blast
{
assume "IncidL B lCD"
have "ColH B C D"
using ColH_def \<open>IncidL B lCD\<close> \<open>IncidL C lCD\<close> \<open>IncidL D lCD\<close> \<open>IsL lCD\<close> by blast
hence False
by (meson colH_permut_231 colH_trans colH_trivial122 \<open>\<not> ColH A C D\<close> assms(3) assms(4))
}
hence "\<not> IncidL B lCD"
by blast
{
assume "IncidL G lCD"
have "ColH C D G"
using ColH_def \<open>IncidL C lCD\<close> \<open>IncidL D lCD\<close> \<open>IncidL G lCD\<close> \<open>IsL lCD\<close> by blast
hence False
using betH_colH \<open>BetH B D G\<close> \<open>IncidL D lCD\<close> \<open>IncidL G lCD\<close> \<open>\<not> IncidL B lCD\<close>
betH_line inter_incid_uniquenessH by blast
}
hence "\<not> IncidL G lCD"
by blast
have "cut lCD B G"
using Is_line \<open>BetH B D G\<close> \<open>IncidL D lCD\<close> \<open>\<not> IncidL B lCD\<close>
\<open>\<not> IncidL G lCD\<close> local.cut_def by blast
obtain bgc where "IsP bgc" and "IncidP B bgc" and "IncidP G bgc" and "IncidP C bgc"
using \<open>\<not> ColH B G C\<close> plan_existence by blast
obtain bga where "IsP bga" and "IncidP B bga" and "IncidP G bga" and "IncidP A bga"
using \<open>\<not> ColH B G A\<close> plan_existence by blast
have "IncidLP lAD bgc"
by (metis (mono_tags, lifting) betH_colH line_on_plane \<open>A \<noteq> D\<close> \<open>BetH B D G\<close>
\<open>IncidL A lAD\<close> \<open>IncidL D lAD\<close> \<open>IncidP B bgc\<close> \<open>IncidP C bgc\<close> \<open>IncidP G bgc\<close>
\<open>IsL lAD\<close> \<open>IsP bgc\<close> assms(3) assms(4) colH_permut_312 line_on_plane')
have "IncidLP lCD bga"
by (metis (mono_tags, lifting) betH_colH line_on_plane \<open>BetH B D G\<close> \<open>C \<noteq> D\<close>
\<open>IncidL C lCD\<close> \<open>IncidL D lCD\<close> \<open>IncidP A bga\<close> \<open>IncidP B bga\<close> \<open>IncidP G bga\<close>
\<open>IsL lCD\<close> \<open>IsP bga\<close> assms(1) assms(4) colH_permut_312 line_on_plane')
show ?thesis
proof -
{
assume "cut lAD B C"
then obtain I where "IncidL I lAD" and "BetH B I C"
using local.cut_def by blast
have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
proof -
{
assume "cut lCD B A"
{
assume "A = I"
have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by (simp add: \<open>A = I\<close> \<open>BetH B I C\<close>)
}
moreover
{
assume "A \<noteq> I"
have "ColH A D I"
using ColH_def Is_line \<open>IncidL A lAD\<close> \<open>IncidL D lAD\<close> \<open>IncidL I lAD\<close> by blast
have "\<not> ColH B C D"
by (meson \<open>\<not> ColH A C D\<close> assms(3) assms(4) colH_permut_231
colH_trans colH_trivial122)
have "ColH B C I"
by (simp add: \<open>BetH B I C\<close> betH_colH colH_permut_132)
have "ColH B C A"
by (simp add: assms(4) colH_permut_231)
have "ColH D A I"
using \<open>ColH A D I\<close> colH_permut_213 by blast
have "ColH D A A"
by (simp add: colH_trivial122)
hence False using inter_uniquenessH
by (metis \<open>A \<noteq> I\<close> \<open>ColH B C A\<close> \<open>ColH B C I\<close> \<open>ColH D A I\<close> \<open>\<not> ColH B C D\<close>)
hence "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by blast
}
ultimately
have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by fastforce
}
moreover
{
assume "cut lCD G A"
{
assume "A = I"
have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by (simp add: \<open>A = I\<close> \<open>BetH B I C\<close>)
}
moreover
{
assume "A \<noteq> I"
have "ColH A D I"
using ColH_def Is_line \<open>IncidL A lAD\<close> \<open>IncidL D lAD\<close> \<open>IncidL I lAD\<close> by blast
have "D \<noteq> A"
using \<open>A \<noteq> D\<close> by blast
moreover have "\<not> ColH B C D"
by (meson \<open>\<not> ColH A C D\<close> assms(3) assms(4) colH_permut_231
colH_trans colH_trivial122)
moreover have "ColH B C I"
by (simp add: \<open>BetH B I C\<close> betH_colH colH_permut_132)
moreover have "ColH B C A"
by (simp add: assms(4) colH_permut_231)
moreover have "ColH D A I"
using \<open>ColH A D I\<close> colH_permut_213 by blast
moreover have "ColH D A A"
by (simp add: colH_trivial122)
hence False
by (metis \<open>A \<noteq> I\<close> calculation(2) calculation(3) calculation(4)
calculation(5) inter_uniquenessH)
hence "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by blast
}
ultimately have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by blast
}
ultimately show ?thesis
using \<open>IncidLP lCD bga\<close> \<open>IncidP A bga\<close> \<open>IncidP B bga\<close> \<open>IncidP G bga\<close>
\<open>IsL lCD\<close> \<open>IsP bga\<close> \<open>\<not> ColH B G A\<close> \<open>\<not> IncidL A lCD\<close>
\<open>local.cut lCD B G\<close> pasch by blast
qed
}
moreover
{
assume "cut lAD G C"
have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
proof -
{
assume "cut lCD B A"
then obtain I where "IncidL I lCD" and "BetH B I A"
using local.cut_def by blast
{
assume "C = I"
hence "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by (simp add: \<open>BetH B I A\<close>)
}
moreover
{
assume "C \<noteq> I"
have "ColH C D I"
using ColH_def Is_line \<open>IncidL C lCD\<close> \<open>IncidL D lCD\<close> \<open>IncidL I lCD\<close> by blast
have "D \<noteq> C"
using \<open>C \<noteq> D\<close> by blast
moreover have "\<not> ColH A B D"
using \<open>\<not> ColH A C D\<close> assms(1) assms(4) colH_trans colH_trivial121 by blast
moreover have "ColH A B I"
by (simp add: \<open>BetH B I A\<close> betH_colH colH_permut_312)
moreover have "ColH A B C"
by (simp add: assms(4))
moreover have "ColH D C I"
by (simp add: \<open>ColH C D I\<close> colH_permut_213)
moreover have "ColH D C C"
by (simp add: colH_trivial122)
ultimately have False
using \<open>C \<noteq> I\<close> inter_uniquenessH by blast
hence "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by blast
}
ultimately have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
by blast
}
moreover {
assume"cut lCD G A"
obtain E where "IncidL E lAD" and "BetH G E C"
using local.cut_def \<open>local.cut lAD G C\<close> by blast
obtain F where "IncidL F lCD" and "BetH G F A"
using \<open>local.cut lCD G A\<close> local.cut_def by blast
{
assume "ColH A G E"
hence "ColH A C D"
using \<open>BetH G E C\<close> \<open>\<not> ColH B G A\<close> assms(4) betH_colH
colH_permut_231 colH_trivial121 inter_uniquenessH by blast
hence False
using \<open>\<not> ColH A C D\<close> by auto
}
hence "\<not> ColH A G E"
by blast
have "C \<noteq> F"
using between_col \<open>BetH G E C\<close> \<open>BetH G F A\<close> \<open>\<not> ColH A G E\<close>
betH_trans0 colH_permut_312 by blast
obtain lCF where "IsL lCF" and "IncidL C lCF" and "IncidL F lCF"
using \<open>IncidL C lCD\<close> \<open>IncidL F lCD\<close> \<open>IsL lCD\<close> by blast
{
assume "IncidL E lCF"
hence False
by (metis (full_types) Hilbert_neutral_dimensionless.betH_expand
Hilbert_neutral_dimensionless_axioms \<open>BetH G E C\<close> \<open>C \<noteq> F\<close> \<open>IncidL C lCD\<close>
\<open>IncidL C lCF\<close> \<open>IncidL E lCF\<close> \<open>IncidL F lCD\<close> \<open>IncidL F lCF\<close>
\<open>\<not> IncidL G lCD\<close> betH_line inter_incid_uniquenessH)
}
hence "\<not> IncidL E lCF"
by blast
have "cut lCF A G"
by (metis IncidL_morphism Is_line \<open>BetH G F A\<close> \<open>C \<noteq> F\<close> \<open>IncidL C lCD\<close>
\<open>IncidL C lCF\<close> \<open>IncidL F lCD\<close> \<open>IncidL F lCF\<close> \<open>\<not> IncidL A lCD\<close>
\<open>\<not> IncidL G lCD\<close> between_comm line_uniqueness local.cut_def)
obtain p where "IncidP A p" and "IncidP G p" and "IncidP E p"
using IncidLP_def \<open>IncidL A lAD\<close> \<open>IncidL E lAD\<close> \<open>IncidLP lAD bgc\<close>
\<open>IncidP G bgc\<close> by blast
have "IncidP C p"
using \<open>BetH G E C\<close> \<open>IncidP E p\<close> \<open>IncidP G p\<close> betH_colH line_on_plane' by blast
moreover have "IncidP F p"
by (metis \<open>BetH G F A\<close> \<open>IncidP A p\<close> \<open>IncidP G p\<close> betH_colH
colH_permut_312 line_on_plane')
ultimately have "IncidLP lCF p"
using Is_plane \<open>C \<noteq> F\<close> \<open>IncidL C lCF\<close> \<open>IncidL F lCF\<close> \<open>IsL lCF\<close>
line_on_plane by blast
{
assume "cut lCF A E"
then obtain I where "IncidL I lCF" and "BetH A I E"
using local.cut_def by blast
have "I = D"
by (metis (full_types) Hilbert_neutral_dimensionless.betH_colH
Hilbert_neutral_dimensionless_axioms \<open>BetH A I E\<close> \<open>C \<noteq> F\<close> \<open>IncidL A lAD\<close>
\<open>IncidL C lCD\<close> \<open>IncidL C lCF\<close> \<open>IncidL D lAD\<close> \<open>IncidL D lCD\<close> \<open>IncidL E lAD\<close>
\<open>IncidL F lCD\<close> \<open>IncidL F lCF\<close> \<open>IncidL I lCF\<close> \<open>\<not> IncidL A lCD\<close>
betH_line inter_incid_uniquenessH)
{
assume "ColH A E C"
have "A \<noteq> E"
using \<open>BetH A I E\<close> not_betH121 by fastforce
have "ColH A D E"
using \<open>BetH A I E\<close> \<open>I = D\<close> between_col by auto
hence "ColH A C D"
by (meson Hilbert_neutral_dimensionless.colH_permut_132
colH_trans colH_trivial121 Hilbert_neutral_dimensionless_axioms
\<open>A \<noteq> E\<close> \<open>ColH A E C\<close>)
hence False
using \<open>\<not> ColH A C D\<close> by blast
}
hence "\<not> ColH A E C"
by blast
obtain lBD where "IncidL B lBD" and "IncidL D lBD"
using \<open>B \<noteq> D\<close> line_existence by blast
have "cut lBD A E"
by (metis betH_colH cut_def
Is_line \<open>BetH A I E\<close> \<open>I = D\<close> \<open>IncidL A lAD\<close> \<open>IncidL B lBD\<close> \<open>IncidL D lAD\<close>
\<open>IncidL D lBD\<close> \<open>IncidL E lAD\<close> \<open>\<not> IncidL B lAD\<close> inter_incid_uniquenessH)
have "IncidLP lBD p"
by (metis IncidLP_def Is_line \<open>B \<noteq> D\<close> \<open>I = D\<close> \<open>IncidL B lBD\<close> \<open>IncidL D lBD\<close>
\<open>IncidL I lCF\<close> \<open>IncidLP lCF p\<close> \<open>IncidP A p\<close> \<open>IncidP C p\<close> assms(2) assms(4)
colH_permut_312 line_on_plane line_on_plane')
{
assume "cut lBD A C"
then obtain I where "IncidL I lBD" and "BetH A I C"
using local.cut_def by blast
hence "ColH A I C"
using betH_colH by blast
hence "I = B"
proof -
have "D \<noteq> B"
using \<open>B \<noteq> D\<close> by auto
moreover have "\<not> ColH A C D"
by (simp add: \<open>\<not> ColH A C D\<close>)
moreover have "ColH A C I"
using \<open>ColH A I C\<close> colH_permut_132 by blast
moreover have "ColH A C B"
by (simp add: assms(4) colH_permut_132)
moreover have "ColH D B I"
using ColH_def Is_line \<open>IncidL B lBD\<close> \<open>IncidL D lBD\<close> \<open>IncidL I lBD\<close> by blast
moreover have "ColH D B B"
by (simp add: colH_trivial122)
ultimately show ?thesis
using inter_uniquenessH by blast
qed
hence "BetH A B C \<or> BetH B C A \<or> BetH B A C"
using \<open>BetH A I C\<close> by auto
}
moreover {
assume "cut lBD E C"
then obtain I where "IncidL I lBD" and "BetH E I C"
using local.cut_def by blast
hence "ColH E I C"
by (simp add: betH_colH)
hence "I = G"
proof -
have "C \<noteq> E"
using \<open>IncidL E lAD\<close> \<open>\<not> IncidL C lAD\<close> by auto
moreover have "\<not> ColH D B C"
by (metis \<open>BetH B D G\<close> \<open>\<not> ColH B G C\<close> betH_colH colH_permut_213
colH_trans colH_trivial122)
moreover have "ColH D B I"
using ColH_def Is_line \<open>IncidL B lBD\<close> \<open>IncidL D lBD\<close> \<open>IncidL I lBD\<close> by blast
moreover have "ColH D B G"
using \<open>BetH B D G\<close> between_col colH_permut_213 by blast
moreover have "ColH C E I"
using \<open>ColH E I C\<close> colH_permut_312 by blast
moreover have "ColH C E G"
by (simp add: \<open>BetH G E C\<close> between_col between_comm)
ultimately show ?thesis
using inter_uniquenessH by blast
qed
hence "BetH A B C \<or> BetH B C A \<or> BetH B A C"
using \<open>BetH E I C\<close> \<open>BetH G E C\<close> between_only_one' by blast
}
ultimately have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
using pasch inter_incid_uniquenessH Is_line Is_plane \<open>C \<noteq> D\<close> \<open>IncidL B lBD\<close>
\<open>IncidL C lCD\<close> \<open>IncidL D lBD\<close> \<open>IncidL D lCD\<close> \<open>IncidLP lBD p\<close> \<open>IncidP A p\<close>
\<open>IncidP C p\<close> \<open>IncidP E p\<close> \<open>\<not> ColH A E C\<close> \<open>\<not> IncidL B lCD\<close>
\<open>local.cut lBD A E\<close> by fastforce
}
moreover
{
assume "cut lCF G E"
then obtain I where "IncidL I lCF" and "BetH G I E"
using local.cut_def by blast
hence "ColH G I E"
using betH_expand by blast
have "I = C"
proof -
have "F \<noteq> C"
using \<open>C \<noteq> F\<close> by auto
moreover have "\<not> ColH G E F"
using \<open>BetH G F A\<close> \<open>\<not> ColH A G E\<close> betH_colH colH_permut_132
colH_trans colH_trivial121 by blast
moreover have "ColH G E I"
using \<open>ColH G I E\<close> colH_permut_132 by presburger
moreover have "ColH G E C"
by (simp add: \<open>BetH G E C\<close> betH_colH)
moreover have "ColH F C I"
using ColH_def Is_line \<open>IncidL C lCF\<close> \<open>IncidL F lCF\<close>
\<open>IncidL I lCF\<close> by blast
moreover have "ColH F C C"
by (simp add: colH_trivial122)
ultimately show ?thesis
using inter_uniquenessH by blast
qed
hence "BetH A B C \<or> BetH B C A \<or> BetH B A C"
using \<open>BetH G E C\<close> \<open>BetH G I E\<close> between_comm between_only_one by blast
}
ultimately have "BetH A B C \<or> BetH B C A \<or> BetH B A C"
using Is_plane \<open>IncidLP lCF p\<close> \<open>IncidP A p\<close> \<open>IncidP E p\<close> \<open>IncidP G p\<close>
\<open>IsL lCF\<close> \<open>\<not> ColH A G E\<close> \<open>\<not> IncidL E lCF\<close> \<open>local.cut lCF A G\<close>
pasch by blast
}
ultimately show ?thesis
using \<open>IncidLP lCD bga\<close> \<open>IncidP A bga\<close> \<open>IncidP B bga\<close> \<open>IncidP G bga\<close>
\<open>IsL lCD\<close> \<open>IsP bga\<close> \<open>\<not> ColH B G A\<close> \<open>\<not> IncidL A lCD\<close>
\<open>local.cut lCD B G\<close> pasch by blast
qed
}
ultimately show ?thesis
using pasch \<open>IsL lAD\<close> \<open>IsP bgc\<close> \<open>IncidLP lAD bgc\<close> \<open>IncidP B bgc\<close> \<open>IncidP C bgc\<close>
\<open>IncidP G bgc\<close> \<open>\<not> ColH B G C\<close> \<open>\<not> IncidL C lAD\<close> \<open>local.cut lAD B G\<close> by blast
qed
qed
lemma betH_dec:
(*assumes "A \<noteq> B" and
"B \<noteq> C" and
"A \<noteq> C" *)
shows "BetH A B C \<or> \<not> BetH A B C"
by blast
lemma cut2_not_cut:
assumes "\<not> ColH A B C" and
"cut l A B" and
"cut l A C"
shows "\<not> cut l B C"
proof -
have "\<not> IncidL A l"
using assms(2) local.cut_def by blast
have "\<not> IncidL B l"
using assms(2) local.cut_def by blast
have "\<not> IncidL C l"
using assms(3) local.cut_def by blast
obtain AB where "IncidL AB l" and "BetH A AB B"
using assms(2) local.cut_def by blast
hence "ColH A AB A"
using colH_trivial121 by blast
obtain AC where "IncidL AC l" and "BetH A AC C"
using assms(3) local.cut_def by blast
hence "ColH A AC C"
by (simp add: between_col)
{
assume "cut l B C"
then obtain BC where "IncidL BC l" and "BetH B BC C"
using local.cut_def by blast
hence "ColH B BC C"
by (simp add: between_col)
have "ColH AB AC BC"
using ColH_def Is_line \<open>IncidL AB l\<close> \<open>IncidL AC l\<close> \<open>IncidL BC l\<close> by blast
have "AB \<noteq> AC"
using colH_trans \<open>BetH A AB B\<close> \<open>ColH A AB A\<close> \<open>ColH A AC C\<close> assms(1)
betH_expand by blast
have "AB \<noteq> BC"
by (metis \<open>BetH A AB B\<close> \<open>ColH B BC C\<close> assms(1) betH_colH colH_trans ncolH_distincts)
have "BC \<noteq> AC"
by (metis \<open>BetH A AC C\<close> \<open>BetH B BC C\<close> assms(1) betH_colH between_comm
colH_trans ncolH_distincts)
have "BetH AB AC BC \<or> BetH AC BC AB \<or> BetH BC AB AC"
using \<open>AB \<noteq> AC\<close> \<open>AB \<noteq> BC\<close> \<open>BC \<noteq> AC\<close> \<open>ColH AB AC BC\<close> between_comm between_one by blast
moreover
{
assume "BetH AB AC BC"
then obtain m where "IncidL A m" and "IncidL C m"
using \<open>BetH A AC C\<close> betH_line by blast
have "\<not> ColH AB BC B"
using ColH_def \<open>AB \<noteq> BC\<close> \<open>IncidL AB l\<close> \<open>IncidL BC l\<close> \<open>\<not> IncidL B l\<close>
inter_incid_uniquenessH by blast
have "\<not> IncidL B m"
using Hilbert_neutral_dimensionless_pre.ColH_def Is_line \<open>IncidL A m\<close>
\<open>IncidL C m\<close> assms(1) by fastforce
have "cut m AB BC"
proof -
{
assume "IncidL AB m"
hence "ColH A B C"
using betH_colH \<open>BetH A AB B\<close> \<open>IncidL A m\<close> \<open>\<not> IncidL B m\<close> betH_line
inter_incid_uniquenessH by blast
hence ?thesis
by (simp add: assms(1))
}
moreover
{
assume "IncidL BC m"
hence "ColH A B C"
using betH_colH \<open>BetH B BC C\<close> \<open>IncidL C m\<close> \<open>\<not> IncidL B m\<close> betH_line
inter_incid_uniquenessH by blast
hence ?thesis
by (simp add: assms(1))
}
moreover have "IncidL AC m"
using betH_colH \<open>BetH A AC C\<close> \<open>IncidL A m\<close> \<open>IncidL C m\<close> betH_line
inter_incid_uniquenessH by blast
ultimately show ?thesis
using Is_line \<open>BetH AB AC BC\<close> local.cut_def by blast
qed
obtain p where "IncidP AB p" and "IncidP BC p" and "IncidP B p"
using \<open>\<not> ColH AB BC B\<close> plan_existence by blast
have "(\<not> ColH AB BC B \<and> IncidP AB p \<and> IncidP BC p \<and> IncidP B p \<and>
IncidLP m p \<and> \<not> IncidL B m \<and> cut m AB BC) \<longrightarrow> (cut m AB B \<or> cut m BC B)"
using pasch Is_line Is_plane \<open>IncidL C m\<close> by blast
moreover
have "(\<not> ColH AB BC B \<and> IncidP AB p \<and> IncidP BC p \<and> IncidP B p \<and>
IncidLP m p \<and> \<not> IncidL B m \<and> cut m AB BC)"
proof -
have "IncidLP m p \<and> \<not> IncidL B m \<and> cut m AB BC"
by (metis (full_types) Hilbert_neutral_dimensionless.betH_colH
Hilbert_neutral_dimensionless_axioms Is_line Is_plane \<open>AB \<noteq> BC\<close> \<open>BetH A AC C\<close>
\<open>BetH B BC C\<close> \<open>ColH AB AC BC\<close> \<open>IncidL A m\<close> \<open>IncidL C m\<close> \<open>IncidP AB p\<close>
\<open>IncidP B p\<close> \<open>IncidP BC p\<close> \<open>\<not> IncidL B m\<close> \<open>local.cut m AB BC\<close> betH_line
colH_permut_132 inter_incid_uniquenessH line_on_plane line_on_plane')
thus ?thesis
using \<open>IncidP AB p\<close> \<open>IncidP B p\<close> \<open>IncidP BC p\<close> \<open>\<not> ColH AB BC B\<close> by auto
qed
ultimately have "cut m AB B \<or> cut m BC B" by blast
moreover
{
assume "cut m AB B"
then obtain I where "IncidL I m" and "BetH AB I B"
using local.cut_def by blast
hence "ColH AB I B"
using between_col by blast
have "ColH A I C"
using ColH_def Is_line \<open>IncidL A m\<close> \<open>IncidL C m\<close> \<open>IncidL I m\<close> by blast
{
assume "A = I"
hence "\<not> BetH A AB B"
using \<open>A = I\<close> \<open>BetH AB I B\<close> between_only_one' by blast
hence False
using \<open>BetH A AB B\<close> by blast
}
hence "A \<noteq> I"
by blast
have "ColH A I A"
using colH_trivial121 by fastforce
have "ColH A I B"
by (meson \<open>BetH A AB B\<close> \<open>BetH AB I B\<close> betH_colH betH_trans0 between_comm)
hence "ColH A B C"
using colH_trans \<open>A \<noteq> I\<close> \<open>ColH A I A\<close> \<open>ColH A I C\<close> by blast
hence False
by (simp add: assms(1))
}
moreover
{
assume "cut m BC B"
then obtain C' where "IncidL C' m" and "BetH BC C' B"
using local.cut_def by blast
have "ColH BC C' B"
by (simp add: \<open>BetH BC C' B\<close> betH_colH)
have "B \<noteq> BC"
using \<open>IncidL BC l\<close> \<open>\<not> IncidL B l\<close> by auto
have "ColH B BC B"
using colH_trivial121 by auto
have "ColH B BC C'"
using \<open>ColH BC C' B\<close> colH_permut_312 by blast
have "ColH B C C'"
using \<open>ColH B BC C\<close> \<open>B \<noteq> BC\<close> \<open>ColH B BC B\<close> \<open>ColH B BC C'\<close>
\<open>ColH B BC C\<close> colH_trans by blast
have "C \<noteq> C'"
using \<open>BetH B BC C\<close> \<open>BetH BC C' B\<close> between_only_one by blast
have "ColH A B C"
using ColH_def \<open>C \<noteq> C'\<close> \<open>ColH B C C'\<close> \<open>IncidL C m\<close> \<open>IncidL C' m\<close>
\<open>\<not> IncidL B m\<close> inter_incid_uniquenessH by auto
hence False
by (simp add: assms(1))
}
ultimately have False
by blast
}
moreover
{
assume "BetH AC BC AB"
obtain m where "IncidL C m" and "IncidL B m"
using \<open>BetH B BC C\<close> betH_line by blast
have "\<not> ColH AB AC A"
using ColH_def \<open>AB \<noteq> AC\<close> \<open>IncidL AB l\<close> \<open>IncidL AC l\<close>
\<open>\<not> IncidL A l\<close> inter_incid_uniquenessH by blast
have "\<not> IncidL A m"
using ColH_def Is_line \<open>IncidL B m\<close> \<open>IncidL C m\<close> assms(1) by blast
have "\<not> IncidL AC m"
using betH_colH \<open>BetH A AC C\<close> \<open>IncidL C m\<close> \<open>\<not> IncidL A m\<close>
betH_line inter_incid_uniquenessH by blast
have "\<not> IncidL AB m"
using betH_colH \<open>BetH A AB B\<close> \<open>IncidL B m\<close> \<open>\<not> IncidL A m\<close>
betH_line inter_incid_uniquenessH by blast
have "IncidL BC m"
using betH_colH \<open>BetH B BC C\<close> \<open>IncidL B m\<close> \<open>IncidL C m\<close>
betH_line inter_incid_uniquenessH by blast
hence "cut m AC AB"
using Is_line \<open>BetH AC BC AB\<close> \<open>IncidL BC m\<close> \<open>\<not> IncidL AB m\<close>
\<open>\<not> IncidL AC m\<close> local.cut_def by blast
hence "cut m AB AC"
using cut_comm by blast
obtain p where "IncidP AB p" and "IncidP AC p" and "IncidP A p"
using \<open>\<not> ColH AB AC A\<close> plan_existence by blast
have "(\<not> ColH AB AC A \<and> IncidP AB p \<and> IncidP AC p \<and> IncidP A p \<and>
IncidLP m p \<and> \<not> IncidL A m \<and> cut m AB AC) \<longrightarrow> (cut m AB A \<or> cut m AC A)"
using Is_line Is_plane \<open>IncidL C m\<close> pasch by blast
moreover
have "\<not> ColH AB AC A \<and> IncidP AB p \<and> IncidP AC p \<and> IncidP A p \<and>
IncidLP m p \<and> \<not> IncidL A m \<and> cut m AB AC"
proof -
have "\<not> ColH AB AC A \<and> IncidP AB p \<and> IncidP AC p \<and> IncidP A p"
by (simp add: \<open>IncidP A p\<close> \<open>IncidP AB p\<close> \<open>IncidP AC p\<close> \<open>\<not> ColH AB AC A\<close>)
moreover have "IncidLP m p \<and> \<not> IncidL A m \<and> cut m AB AC"
by (metis (mono_tags, lifting) betH_colH line_on_plane Is_line Is_plane
\<open>AB \<noteq> AC\<close> \<open>BetH A AC C\<close> \<open>BetH B BC C\<close> \<open>ColH AB AC BC\<close> \<open>IncidL BC m\<close> \<open>IncidL C m\<close>
\<open>IncidP A p\<close> \<open>IncidP AB p\<close> \<open>IncidP AC p\<close> \<open>\<not> IncidL A m\<close> \<open>local.cut m AB AC\<close>
line_on_plane')
ultimately show ?thesis
by blast
qed
ultimately have "cut m AB A \<or> cut m AC A"
by blast
moreover {
assume "cut m AB A"
obtain B' where "IncidL B' m" and "BetH AB B' A"
using \<open>local.cut m AB A\<close> local.cut_def by blast
then have "ColH AB B' A"
using betH_colH by force
have "ColH A B B'"
using betH_expand \<open>BetH A AB B\<close> \<open>ColH A AB A\<close> \<open>ColH AB B' A\<close>
colH_permut_312 colH_trans by blast
hence False
using ColH_def \<open>BetH A AB B\<close> \<open>BetH AB B' A\<close> \<open>IncidL B m\<close> \<open>IncidL B' m\<close>
\<open>\<not> IncidL A m\<close> between_only_one inter_incid_uniquenessH by blast
}
moreover {
assume "cut m AC A"
then obtain I where "IncidL I m" and "BetH AC I A"
using local.cut_def by blast
hence "ColH AC I A"
by (simp add: betH_colH)
have "ColH C I A"
by (metis betH_colH \<open>BetH AC I A\<close> \<open>ColH A AC C\<close> colH_permut_312
colH_trans colH_trivial121)
hence "ColH A B C"
using ColH_def \<open>BetH A AC C\<close> \<open>BetH AC I A\<close> \<open>IncidL C m\<close> \<open>IncidL I m\<close>
\<open>\<not> IncidL A m\<close> between_only_one inter_incid_uniquenessH by blast
hence False
using assms(1) by fastforce
}
ultimately have False
by blast
}
moreover
{
assume "BetH BC AB AC"
obtain m where "IncidL A m" and "IncidL B m"
using \<open>BetH A AB B\<close> betH_line by blast
have "\<not> ColH BC A C"
by (metis \<open>ColH B BC C\<close> \<open>IncidL BC l\<close> \<open>\<not> IncidL C l\<close> assms(1)
colH_permut_213 colH_trans colH_trivial122)
have "\<not> IncidL C m"
using ColH_def Is_line \<open>IncidL A m\<close> \<open>IncidL B m\<close> assms(1) by blast
have "cut m BC AC"
by (metis (full_types) ncolH_distincts Is_line \<open>AB \<noteq> AC\<close> \<open>AB \<noteq> BC\<close>
\<open>BetH A AB B\<close> \<open>BetH BC AB AC\<close> \<open>IncidL A m\<close> \<open>IncidL AB l\<close> \<open>IncidL AC l\<close>
\<open>IncidL B m\<close> \<open>\<not> IncidL B l\<close> assms(1) betH_line inter_incid_uniquenessH
local.cut_def)
have "\<not> IncidL AC m"
using \<open>local.cut m BC AC\<close> local.cut_def by blast
obtain p where "IncidP BC p" and "IncidP AC p" and "IncidP C p"
by (metis (no_types, lifting) ncolH_distincts \<open>\<not> ColH BC A C\<close>
line_on_plane' plan_existence)
have "(\<not> ColH BC AC C \<and> IncidP BC p \<and> IncidP AC p \<and> IncidP C p \<and>
IncidLP m p \<and> \<not> IncidL C m \<and> cut m BC AC) \<longrightarrow> (cut m BC C \<or> cut m AC C)"
using Is_line Is_plane \<open>IncidL B m\<close> pasch by blast
moreover have "\<not> ColH BC AC C \<and> IncidP BC p \<and> IncidP AC p"
using ColH_def \<open>BC \<noteq> AC\<close> \<open>IncidL AC l\<close> \<open>IncidL BC l\<close> \<open>IncidP AC p\<close>
\<open>IncidP BC p\<close> \<open>\<not> IncidL C l\<close> inter_incid_uniquenessH by auto
moreover have "IncidP C p \<and> IncidLP m p \<and> \<not> IncidL C m \<and> cut m BC AC"
by (metis ncolH_distincts Is_line Is_plane \<open>ColH A AC C\<close> \<open>ColH B BC C\<close>
\<open>IncidL A m\<close> \<open>IncidL B m\<close> \<open>IncidP C p\<close> \<open>\<not> IncidL C m\<close> \<open>local.cut m BC AC\<close>
assms(1) calculation(2) colH_permut_321 line_on_plane line_on_plane')
moreover have "\<not> cut m BC C"
by (meson \<open>BetH B BC C\<close> \<open>IncidL B m\<close> betH_trans0 between_comm local.cut_def
outH_def out_same_side same_side_def)
moreover have "\<not> cut m AC C"
by (meson \<open>BetH A AC C\<close> \<open>IncidL A m\<close> betH_trans0 between_comm local.cut_def
outH_def out_same_side same_side_def)
ultimately have False
by blast
}
ultimately
have False
by blast
}
thus ?thesis
by blast
qed
lemma strong_pasch:
assumes "\<not> ColH A B C" and
"IncidP A p" and
"IncidP B p" and
"IncidP C p" and
"IncidLP l p" and
"\<not> IncidL C l" and
"cut l A B"
shows "(cut l A C \<and> \<not> cut l B C) \<or> (cut l B C \<and> \<not> cut l A C)"
by (meson cut2_not_cut IncidLP_def assms(1) assms(2) assms(3) assms(4)
assms(5) assms(6) assms(7) pasch)
lemma out2_out:
assumes "C \<noteq> D" and
"BetH A B C" and
"BetH A B D"
shows "BetH B C D \<or> BetH B D C"
proof -
have "A \<noteq> B"
using assms(2) betH_distincts by blast
have "ColH A B B"
by (simp add: colH_trivial122)
have "ColH A B C"
by (simp add: assms(2) between_col)
have "ColH A B D"
by (simp add: assms(3) betH_colH)
hence "ColH B C D"
using colH_trans \<open>A \<noteq> B\<close> \<open>ColH A B B\<close> \<open>ColH A B C\<close> by blast
{
assume "BetH C D B"
hence ?thesis
using between_comm by blast
}
moreover
{
assume "BetH C B D"
have "ColH A C D"
using \<open>A \<noteq> B\<close> \<open>ColH A B C\<close> \<open>ColH A B D\<close> colH_trans colH_trivial121 by blast
moreover have "BetH A C D \<longrightarrow> ?thesis"
using assms(2) betH_trans0 by blast
moreover have "BetH C D A \<longrightarrow> ?thesis"
using assms(3) betH_trans0 between_comm by blast
moreover have "BetH C A D \<longrightarrow> ?thesis"
using assms(2) assms(3) betH_trans0 between_comm between_only_one' by blast
ultimately have ?thesis
by (metis assms(1) assms(2) assms(3) betH_colH between_one)
}
ultimately show ?thesis
by (metis \<open>ColH B C D\<close> assms(1) assms(2) assms(3) betH_distincts between_one)
qed
lemma out2_out1:
assumes "C \<noteq> D" and
"BetH A B C" and
"BetH A B D"
shows "BetH A C D \<or> BetH A D C"
by (meson assms(1) assms(2) assms(3) betH_trans out2_out)
lemma betH2_out:
assumes "B \<noteq> C" and
"BetH A B D" and
"BetH A C D"
shows "BetH A B C \<or> BetH A C B"
proof -
have "A \<noteq> D"
using assms(2) between_diff by auto
moreover have "ColH A D A"
by (simp add: colH_trivial121)
moreover have "ColH A D B"
by (simp add: assms(2) betH_colH colH_permut_132)
moreover have "ColH A D C"
using assms(3) betH_colH colH_permut_132 by blast
ultimately have "ColH A B C"
using colH_trans by blast
moreover have "BetH B C A \<longrightarrow> ?thesis"
using between_comm by blast
moreover have "BetH C A B \<longrightarrow> ?thesis"
using assms(2) assms(3) betH_trans2 between_only_one' by blast
ultimately show ?thesis
by (metis assms(1) assms(2) assms(3) betH_colH between_comm between_one)
qed
lemma segment_construction:
shows "\<exists> E. Bet A B E \<and> Cong B E C D"
proof (cases "C = D")
case True
thus ?thesis
using Bet_def Cong_def by force
next
case False
hence "C \<noteq> D"
by blast
{
assume "A = B"
hence ?thesis
by (metis Bet_def Cong_def betH_distincts cong_existence' line_existence)
}
moreover
{
assume "A \<noteq> B"
obtain l where "IncidL A l" and "IncidL B l"
using \<open>A \<noteq> B\<close> line_existence by auto
obtain F where "\<exists> B'. IncidL F l \<and> IncidL B' l \<and> BetH F B B' \<and> CongH B F C D \<and> CongH B B' C D"
using False \<open>IncidL B l\<close> cong_existence' by presburger
then obtain F' where "IncidL F l" and "IncidL F' l" and "BetH F B F'" and
"CongH B F C D" and "CongH B F' C D"
by blast
hence "ColH A F F'"
using ColH_def Is_line \<open>IncidL A l\<close> by blast
have "A = F \<longrightarrow> ?thesis"
by (metis Bet_def Cong_def \<open>BetH F B F'\<close> \<open>CongH B F' C D\<close> betH_distincts)
moreover {
assume "A \<noteq> F"
have "A = F' \<longrightarrow> ?thesis"
by (metis Bet_def Cong_def \<open>BetH F B F'\<close> \<open>CongH B F C D\<close> betH_distincts between_comm)
moreover
{
assume "A \<noteq> F'"
have "ColH A F F'"
using \<open>ColH A F F'\<close> by blast
have "BetH A F F' \<longrightarrow> ?thesis"
by (metis Cong_def False \<open>BetH F B F'\<close> \<open>CongH B F' C D\<close> betH_to_bet
betH_trans0 between_comm)
moreover have "BetH F F' A \<longrightarrow> ?thesis"
by (metis Bet_def Cong_def False \<open>BetH F B F'\<close> \<open>CongH B F C D\<close>
betH_distincts betH_trans0 between_comm)
moreover have "BetH F' A F \<longrightarrow> ?thesis"
by (metis (full_types) Cong_def False \<open>A \<noteq> B\<close> \<open>BetH F B F'\<close> \<open>CongH B F C D\<close>
\<open>CongH B F' C D\<close> betH2_out betH_to_bet between_comm between_only_one out2_out)
ultimately have ?thesis
by (metis between_one \<open>A = F \<longrightarrow> (\<exists>E. Bet A B E \<and> Cong B E C D)\<close>
\<open>A = F' \<longrightarrow> (\<exists>E. Bet A B E \<and> Cong B E C D)\<close> \<open>BetH F B F'\<close> \<open>ColH A F F'\<close>
between_comm between_diff)
}
ultimately have ?thesis
by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
lemma lower_dim_e:
shows "\<exists> A B C. \<not> (Bet A B C \<or> Bet B C A \<or> Bet C A B)"
by (meson bet_colH colH_permut_312 lower_dim_2)
lemma outH_dec:
shows "outH A B C \<or> \<not> outH A B C"
by simp
lemma out_construction:
assumes "X \<noteq> Y" and
"A \<noteq> B"
shows "\<exists> C. CongH A C X Y \<and> outH A B C"
by (metis assms(1) assms(2) cong_existence line_existence)
lemma segment_constructionH:
assumes "A \<noteq> B" and
"C \<noteq> D"
shows "\<exists> E. BetH A B E \<and> CongH B E C D"
by (metis Bet_def Cong_def assms(1) assms(2) segment_construction)
lemma EqL_dec:
shows "EqL l m \<or> \<not> EqL l m"
by simp
lemma cut_exists:
assumes "IsL l" and (*ROLL ADD*)
"\<not> IncidL A l"
shows "\<exists> B. cut l A B"
using assms(1) assms(2) same_side_def same_side_refl by blast
lemma outH_col:
assumes "outH A B C"
shows "ColH A B C"
by (simp add: assms outH_expand)
lemma cut_distinct:
assumes "cut l A B"
shows "A \<noteq> B"
using assms local.cut_def not_betH121 by fastforce
lemma same_side_not_cut:
assumes "same_side A B l"
shows "\<not> cut l A B"
proof -
obtain P where "cut l A P" and "cut l B P"
using assms same_side_def by blast
{
assume "ColH P A B"
{
assume "cut l A B"
obtain M where "IncidL M l" and "BetH A M P"
using \<open>local.cut l A P\<close> local.cut_def by blast
obtain N where "IncidL N l" and "BetH B N P"
using \<open>local.cut l B P\<close> local.cut_def by blast
{
assume "M = N"
hence "BetH M A B \<or> BetH M B A"
using \<open>BetH A M P\<close> \<open>BetH B N P\<close> \<open>local.cut l A B\<close> between_comm
cut_distinct out2_out by blast
obtain Q where "IncidL Q l" and "BetH A Q B"
using \<open>local.cut l A B\<close> local.cut_def by blast
obtain R where "IncidL R l" and "BetH A R B"
using \<open>BetH A Q B\<close> \<open>IncidL Q l\<close> by blast
have "ColH A B M"
using \<open>BetH M A B \<or> BetH M B A\<close> betH_colH between_comm colH_permut_231 by blast
obtain m where "IncidL A m" and "IncidL B m"
using \<open>BetH A Q B\<close> betH_line by blast
obtain mm where "IncidL P mm" and "IncidL A mm" and "IncidL B mm"
using ColH_def \<open>ColH P A B\<close> by blast
have "EqL m mm"
by (metis Is_line \<open>IncidL A m\<close> \<open>IncidL A mm\<close> \<open>IncidL B m\<close> \<open>IncidL B mm\<close>
\<open>\<And>thesis. (\<And>R. \<lbrakk>IncidL R l; BetH A R B\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close>
betH_colH line_uniqueness)
obtain nn where "IncidL A nn" and "IncidL R nn" and "IncidL B nn"
using \<open>BetH A R B\<close> betH_line by blast
have "EqL m nn"
by (metis Is_line \<open>BetH A R B\<close> \<open>IncidL A m\<close> \<open>IncidL A nn\<close> \<open>IncidL B m\<close>
\<open>IncidL B nn\<close> line_uniqueness not_betH121)
obtain pp where "IncidL A pp" and "IncidL B pp" and "IncidL M pp"
using ColH_def \<open>ColH A B M\<close> by blast
have "EqL m pp"
by (metis Is_line \<open>BetH M A B \<or> BetH M B A\<close> \<open>IncidL A m\<close> \<open>IncidL A pp\<close>
\<open>IncidL B m\<close> \<open>IncidL B pp\<close> betH_distincts line_uniqueness)
have "R = M"
by (metis betH_colH \<open>IncidL A nn\<close> \<open>IncidL A pp\<close> \<open>IncidL B nn\<close>
\<open>IncidL B pp\<close> \<open>IncidL M l\<close> \<open>IncidL M pp\<close> \<open>IncidL R l\<close> \<open>IncidL R nn\<close>
\<open>local.cut l A B\<close> inter_incid_uniquenessH local.cut_def)
have "BetH M A B \<longrightarrow> False"
using \<open>BetH A R B\<close> \<open>R = M\<close> between_only_one' by blast
moreover have "BetH M B A \<longrightarrow> False"
using \<open>BetH A R B\<close> \<open>R = M\<close> between_only_one by blast
ultimately have False
using \<open>BetH M A B \<or> BetH M B A\<close> by blast
}
hence "M \<noteq> N"
by blast
have "A \<noteq> B"
using \<open>local.cut l A B\<close> cut_distinct by auto
obtain T where "IncidL T l" and "BetH A T B"
using \<open>local.cut l A B\<close> local.cut_def by blast
obtain m where "IncidL P m" and "IncidL A m" and "IncidL B m"
using ColH_def \<open>ColH P A B\<close> by blast
obtain mm where "IncidL A mm" and "IncidL M mm" and "IncidL P mm"
using \<open>BetH A M P\<close> betH_line by blast
obtain nn where "IncidL B nn" and "IncidL N nn" and "IncidL P nn"
using \<open>BetH B N P\<close> betH_line by blast
have "M = N" using inter_incid_uniquenessH
by (metis Hilbert_neutral_dimensionless_pre.cut_def \<open>BetH B N P\<close>
\<open>IncidL A m\<close> \<open>IncidL A mm\<close> \<open>IncidL B m\<close> \<open>IncidL M l\<close> \<open>IncidL M mm\<close>
\<open>IncidL N l\<close> \<open>IncidL P m\<close> \<open>IncidL P mm\<close>
\<open>\<And>thesis. (\<And>nn. \<lbrakk>IncidL B nn; IncidL N nn; IncidL P nn\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close>
\<open>local.cut l A P\<close> betH_expand)
hence False
by (simp add: \<open>M \<noteq> N\<close>)
}
hence "\<not> cut l A B"
by blast
}
moreover
{
assume "\<not> ColH P A B"
hence ?thesis
using \<open>local.cut l A P\<close> \<open>local.cut l B P\<close> cut2_not_cut cut_comm by blast
}
ultimately show ?thesis
by blast
qed
lemma IncidLP_morphism:
assumes
"IsL m" and
"IsP q" and
"IncidLP l p" and
"EqL l m" and
"EqP p q"
shows "IncidLP m q"
proof -
{
fix A
assume "IncidL A m"
have "IncidP A q"
by (metis Hilbert_neutral_dimensionless_pre.IncidLP_def IncidP_morphism
\<open>IncidL A m\<close> assms(1) assms(2) assms(3) assms(4) assms(5) morph)
}
thus ?thesis
using IncidLP_def assms(1) assms(2) by blast
qed
lemma same_side__plane:
assumes "same_side A B l"
shows "\<exists> p. IncidP A p \<and> IncidP B p \<and> IncidLP l p"
proof -
obtain P where "cut l A P" and "cut l B P"
using assms same_side_def by blast
then obtain X where "IncidL X l" and "BetH A X P"
using local.cut_def by blast
{
assume "ColH A B P"
obtain Y where "X \<noteq> Y" and "IncidL Y l"
using \<open>IncidL X l\<close> other_point_on_line by blast
{
assume "ColH X Y A"
obtain m where "IncidL X m" and "IncidL Y m" and "IncidL A m"
using ColH_def \<open>ColH X Y A\<close> by auto
hence "X = Y"
using inter_incid_uniquenessH \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>local.cut l A P\<close>
local.cut_def by blast
hence False
by (simp add: \<open>X \<noteq> Y\<close>)
}
hence "\<not> ColH X Y A"
by blast
obtain p where "IncidP X p" and "IncidP Y p" and "IncidP A p"
using \<open>ColH X Y A \<Longrightarrow> False\<close> plan_existence by blast
hence ?thesis
by (metis betH_colH Is_line Is_plane \<open>BetH A X P\<close> \<open>ColH A B P\<close>
\<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>X \<noteq> Y\<close> colH_permut_132 line_on_plane line_on_plane')
}
moreover
{
assume "\<not> ColH A B P"
obtain p where "IncidP A p" and "IncidP B p" and "IncidP P p"
using \<open>\<not> ColH A B P\<close> plan_existence by blast
obtain Y where "IncidL Y l" and "BetH B Y P"
using \<open>local.cut l B P\<close> local.cut_def by blast
have "IncidP X p"
by (metis ncolH_distincts \<open>BetH A X P\<close> \<open>IncidP A p\<close> \<open>IncidP P p\<close>
\<open>\<not> ColH A B P\<close> between_col colH_permut_132 line_on_plane')
moreover have "IncidP Y p"
using \<open>BetH B Y P\<close> \<open>IncidP B p\<close> \<open>IncidP P p\<close> betH_colH colH_permut_132
line_on_plane' by blast
ultimately have "IncidLP l p" using line_on_plane
by (metis Is_line Is_plane \<open>BetH A X P\<close> \<open>BetH B Y P\<close> \<open>IncidL X l\<close>
\<open>IncidL Y l\<close> \<open>\<not> ColH A B P\<close> between_col between_comm colH_permut_231
colH_trivial112 out2_out1)
hence ?thesis
using \<open>IncidP A p\<close> \<open>IncidP B p\<close> by blast
}
ultimately show ?thesis
by blast
qed
lemma same_side_prime__plane:
assumes "same_side' A B C D"
shows "\<exists> p. IncidP A p \<and> IncidP B p \<and> IncidP C p \<and> IncidP D p"
proof -
obtain l where "IsL l" and "IncidL C l" and "IncidL D l"
by (metis line_existence lower_dim_2)
obtain p where "IsP p" and "IncidP A p" and "IncidP B p" and "IncidLP l p"
by (meson Is_plane \<open>IncidL C l\<close> \<open>IncidL D l\<close> \<open>IsL l\<close> assms
same_side'_def same_side__plane)
thus ?thesis
using IncidLP_def \<open>IncidL C l\<close> \<open>IncidL D l\<close> by blast
qed
lemma cut_same_side_cut:
assumes "cut l P X" and
"same_side X Y l"
shows "cut l P Y"
proof -
have "\<not> cut l X Y"
by (simp add: assms(2) same_side_not_cut)
have "X = Y \<longrightarrow> ?thesis"
using assms(1) by fastforce
moreover {
assume "X \<noteq> Y"
obtain A where "IncidL A l" and "BetH P A X"
using assms(1) local.cut_def by blast
{
assume "ColH P X Y"
{
assume "IncidL Y l"
hence False
using \<open>IncidL Y l\<close> assms(2) local.cut_def same_side_def by force
}
hence "\<not> IncidL Y l"
by blast
have "IncidL A l"
by (simp add: \<open>IncidL A l\<close>)
moreover have "BetH P A Y"
proof -
have "BetH P X Y \<longrightarrow> BetH P A Y"
using \<open>BetH P A X\<close> betH_trans0 by blast
moreover have "BetH X Y P \<longrightarrow> BetH P A Y"
by (metis \<open>BetH P A X\<close> \<open>IncidL A l\<close> \<open>\<not> IncidL Y l\<close> \<open>\<not> local.cut l X Y\<close>
assms(1) betH2_out betH_trans0 between_comm local.cut_def)
moreover have "BetH X P Y \<longrightarrow> BetH P A Y"
by (meson \<open>\<not> IncidL Y l\<close> \<open>\<not> local.cut l X Y\<close> assms(1) betH_trans0
between_comm local.cut_def)
ultimately show ?thesis
by (metis betH_to_bet between_one cut_comm \<open>BetH P A X\<close> \<open>ColH P X Y\<close>
\<open>\<not> local.cut l X Y\<close> assms(1))
qed
ultimately have ?thesis
using \<open>\<not> IncidL Y l\<close> assms(1) local.cut_def by blast
}
moreover
{
assume "\<not> ColH P X Y"
{
assume "IncidL Y l"
obtain T where "cut l X T" and "cut l Y T"
using assms(2) same_side_def by blast
hence False
using \<open>IncidL Y l\<close> local.cut_def by blast
}
hence "\<not> IncidL Y l"
by blast
obtain p where "IncidP P p" and "IncidP X p" and "IncidP Y p"
using \<open>\<not> ColH P X Y\<close> plan_existence by blast
have "cut l X Y \<or> cut l P Y"
proof -
let ?A="X"
let ?B="P"
let ?C="Y"
have "\<not> ColH ?A ?B ?C"
using \<open>\<not> ColH P X Y\<close> colH_permut_213 by blast
moreover have "IsL l"
using assms(2) same_side_def by blast
moreover have "IsP p"
using Is_plane \<open>IncidP P p\<close> by blast
moreover have "IncidP ?A p"
by (simp add: \<open>IncidP X p\<close>)
moreover have "IncidP ?B p"
using \<open>IncidP P p\<close> by auto
moreover have "IncidP ?C p"
by (simp add: \<open>IncidP Y p\<close>)
moreover have "IncidLP l p"
proof -
{
fix A'
assume "IncidL A' l"
have "ColH P A X"
by (simp add: \<open>BetH P A X\<close> between_col)
obtain I where "IncidL I l" and "BetH P I X"
by (meson \<open>\<And>thesis. (\<And>A. \<lbrakk>IncidL A l; BetH P A X\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close>)
hence "ColH P I X"
using between_col by blast
have "I = A' \<longrightarrow> IncidP A' p"
by (metis betH_colH \<open>BetH P I X\<close> calculation(4) calculation(5)
colH_permut_132 line_on_plane')
moreover
obtain p' where "IsP p'" and "IncidP X p'" and "IncidP Y p'" and "IncidLP l p'"
using Is_plane assms(2) same_side__plane by blast
have "IncidP P p'"
using IncidLP_def \<open>BetH P A X\<close> \<open>ColH P A X\<close> \<open>IncidL A l\<close>
\<open>IncidLP l p'\<close> \<open>IncidP X p'\<close> betH_distincts colH_permut_231
line_on_plane' by blast
have "IncidP A' p'"
using IncidLP_def \<open>IncidL A' l\<close> \<open>IncidLP l p'\<close> by blast
have "IncidP A p'"
using IncidLP_def \<open>IncidL A l\<close> \<open>IncidLP l p'\<close> by blast
have "EqP p p'"
by (meson plane_uniqueness \<open>IncidP P p'\<close> \<open>IncidP P p\<close>
\<open>IncidP X p'\<close> \<open>IncidP X p\<close> \<open>IncidP Y p'\<close> \<open>IncidP Y p\<close> \<open>IsP p'\<close>
\<open>IsP p\<close> \<open>\<not> ColH P X Y\<close>)
hence "IncidP A' p"
by (meson EqP_sym IncidP_morphism \<open>IncidP A' p'\<close> \<open>IsP p'\<close> \<open>IsP p\<close>)
}
thus ?thesis
using IncidLP_def calculation(2) calculation(3) by blast
qed
moreover have "\<not> IncidL ?C l"
by (simp add: \<open>\<not> IncidL Y l\<close>)
moreover have "cut l ?A ?B"
by (simp add: assms(1) cut_comm)
ultimately
show ?thesis using pasch by blast
qed
have "IncidP A p"
using betH_colH \<open>BetH P A X\<close> \<open>IncidP P p\<close> \<open>IncidP X p\<close> colH_permut_132
line_on_plane' by blast
obtain q where "IncidP X q" and "IncidP Y q" and "IncidLP l q"
using assms(2) same_side__plane by blast
have "IncidP P q"
by (metis IncidLP_def \<open>IncidLP l q\<close> \<open>IncidP X q\<close>
\<open>\<And>thesis. (\<And>A. \<lbrakk>IncidL A l; BetH P A X\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close> betH_colH
between_comm line_on_plane')
have "EqP p q"
using Is_plane \<open>IncidP P p\<close> \<open>IncidP P q\<close> \<open>IncidP X p\<close> \<open>IncidP X q\<close>
\<open>IncidP Y p\<close> \<open>IncidP Y q\<close> \<open>\<not> ColH P X Y\<close> plane_uniqueness by presburger
hence "IncidLP l p"
by (meson EqL_refl EqP_sym IncidLP_morphism Is_line Is_plane
\<open>IncidL A l\<close> \<open>IncidLP l q\<close> \<open>IncidP P p\<close>)
have ?thesis
using \<open>\<not> local.cut l X Y\<close> \<open>local.cut l X Y \<or> local.cut l P Y\<close> by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
(** Theorem 11 of Hilbert: the angles at the base of an isosceles triangle are congruent *)
lemma isosceles_congaH:
assumes "\<not> ColH A B C" and
"CongH A B A C"
shows "CongaH A B C A C B"
by (metis assms(1) assms(2) colH_permut_213 colH_permut_312 colH_trivial112
congH_sym cong_5 conga_comm)
lemma cong_distincts:
assumes "A \<noteq> B" and
"Cong A B C D"
shows "C \<noteq> D"
using assms(1) assms(2) cong_identity by blast
lemma cong_sym:
assumes "Cong A B C D"
shows "Cong C D A B"
using Cong_def assms congH_sym by presburger
lemma cong_trans:
assumes "Cong A B C D" and
"Cong C D E F"
shows "Cong A B E F"
by (meson assms(1) assms(2) cong_inner_transitivity cong_sym)
lemma betH_not_congH:
assumes "BetH A B C"
shows "\<not> CongH A B A C"
by (metis assms betH_expand betH_trans between_comm between_out construction_uniqueness)
lemma congH_permlr:
assumes (*"A \<noteq> B" and*)
"C \<noteq> D" and
"CongH A B C D"
shows "CongH B A D C"
by (metis assms(2) assms(1) congH_sym cong_permr)
lemma congH_perms:
assumes "A \<noteq> B" and
"C \<noteq> D" and
"CongH A B C D"
shows "CongH B A C D \<and> CongH A B D C \<and> CongH C D A B \<and>
CongH D C A B \<and> CongH C D B A \<and> CongH D C B A \<and> CongH B A D C"
using assms(1) assms(2) assms(3) congH_sym cong_permr by presburger
lemma congH_perml:
assumes (*"A \<noteq> B" and*)
"C \<noteq> D" and
"CongH A B C D"
shows "CongH B A C D"
by (metis assms(2) assms(1) congH_perms)
lemma bet_cong3_bet:
assumes "A' \<noteq> B'" and
"B' \<noteq> C'" and
"A' \<noteq> C'" and
"BetH A B C" and
"ColH A' B' C'" and
"CongH A B A' B'" and
"CongH B C B' C'" and
"CongH A C A' C'"
shows "BetH A' B' C'"
proof -
{
assume "BetH B' C' A'"
obtain B'' where "BetH B C B''" and "CongH C B'' B C"
using assms(4) betH_to_bet segment_constructionH by blast
have "BetH A B B'' \<and> BetH A C B''"
using betH_trans \<open>BetH B C B''\<close> assms(4) by blast
hence "BetH A B B''"
by blast
have "BetH A C B''"
using \<open>BetH A B B'' \<and> BetH A C B''\<close> by blast
have "CongH A B'' A' B'"
proof -
have "ColH A C B''"
by (simp add: \<open>BetH A C B''\<close> between_col)
moreover have "disjoint A C C B''"
by (simp add: \<open>BetH A C B''\<close> bet_disjoint)
moreover have "disjoint A' C' C' B'"
by (simp add: \<open>BetH B' C' A'\<close> bet_disjoint between_comm)
moreover have "CongH C B'' C' B'"
by (metis betH_to_bet congH_sym \<open>BetH B C B''\<close> \<open>CongH C B'' B C\<close>
assms(7) cong_permr cong_pseudo_transitivity)
ultimately show ?thesis
using addition assms(5) assms(8) colH_permut_132 by blast
qed
have "CongH A B'' A B"
by (metis \<open>BetH A B B'' \<and> BetH A C B''\<close> \<open>CongH A B'' A' B'\<close> assms(6)
betH_colH congH_sym cong_pseudo_transitivity)
have "\<not> CongH A B A B''"
by (simp add: \<open>BetH A B B''\<close> betH_not_congH)
have "CongH A B A B''"
using \<open>BetH A B B''\<close> \<open>CongH A B'' A B\<close> betH_to_bet congH_sym by blast
hence False
by (simp add: \<open>\<not> CongH A B A B''\<close>)
hence ?thesis
by blast
}
moreover
{
assume "BetH C' A' B'"
obtain B'' where "BetH C A B''" and "CongH A B'' A B"
by (metis assms(4) betH_expand segment_constructionH)
have "CongH C B'' C' B'"
proof -
have "disjoint C A A B''"
using \<open>BetH C A B''\<close> bet_disjoint by force
moreover have "disjoint C' A' A' B'"
by (simp add: \<open>BetH C' A' B'\<close> bet_disjoint)
moreover have "CongH C A C' A'"
by (simp add: assms(3) assms(8) congH_permlr)
moreover have "CongH A B'' A' B'"
by (metis \<open>BetH C A B''\<close> \<open>CongH A B'' A B\<close> assms(6) betH_distincts
congH_sym cong_pseudo_transitivity)
ultimately show ?thesis
using \<open>BetH C A B''\<close> \<open>BetH C' A' B'\<close> addition_betH by blast
qed
have "BetH B A B'' \<and> BetH C B B''"
using betH_trans0 \<open>BetH C A B''\<close> assms(4) between_comm by blast
hence "BetH B A B''"
by blast
have "BetH C B B''"
using \<open>BetH B A B'' \<and> BetH C B B''\<close> by auto
have "\<not> CongH C B C B''"
by (simp add: \<open>BetH C B B''\<close> betH_not_congH)
hence ?thesis
by (metis betH_colH \<open>BetH C B B''\<close> \<open>CongH C B'' C' B'\<close> assms(2)
assms(7) congH_perms cong_pseudo_transitivity)
}
ultimately show ?thesis
using assms(1) assms(2) assms(3) assms(5) between_comm between_one by blast
qed
lemma betH_congH3_outH_betH:
assumes "BetH A B C" and
"outH A' B' C'" and
"CongH A C A' C'" and
"CongH A B A' B'"
shows "BetH A' B' C'"
proof -
{
assume "BetH A' C' B'"
obtain C'' where "BetH A' B' C''" and "CongH B' C'' B C"
using \<open>BetH A' C' B'\<close> assms(1) betH_distincts segment_constructionH by blast
hence "CongH A' C'' A C"
using addition_betH assms(1) assms(4) betH_distincts congH_sym by presburger
have "BetH C' B' C'' \<and> BetH A' C' C''"
using \<open>BetH A' B' C''\<close> \<open>BetH A' C' B'\<close> betH_trans0 by blast
hence "\<not> CongH A' C' A' C''"
by (simp add: betH_not_congH)
moreover
have "CongH A' C' A' C''"
by (metis betH_colH congH_sym \<open>BetH A' B' C''\<close> \<open>CongH A' C'' A C\<close>
assms(3) cong_pseudo_transitivity)
ultimately have ?thesis
by simp
}
moreover have "(A' \<noteq> B' \<and> B' \<noteq> C') \<longrightarrow> ?thesis"
using assms(2) calculation outH_def by auto
ultimately show ?thesis
by (metis betH_distincts assms(1) assms(2) assms(3) assms(4) betH_not_congH
congH_sym cong_pseudo_transitivity outH_def)
qed
lemma outH_sym:
assumes "A \<noteq> C" and
"outH A B C"
shows "outH A C B"
using assms(2) outH_def by fastforce
lemma soustraction_betH:
assumes "BetH A B C" and
"BetH A' B' C'" and
"CongH A B A' B'" and
"CongH A C A' C'"
shows "CongH B C B' C'"
proof -
obtain C1 where "BetH A' B' C1" and "CongH B' C1 B C"
using assms(1) assms(2) betH_to_bet segment_constructionH by blast
hence "CongH A C A' C1"
using addition_betH assms(1) assms(3) betH_distincts congH_sym by presburger
obtain X where "BetH B A X"
by (metis assms(1) between_out)
obtain X' where "BetH B' A' X'"
by (metis assms(2) between_out)
have "BetH X A C"
using \<open>BetH B A X\<close> assms(1) betH_trans between_comm by blast
have "BetH X' A' C1"
using \<open>BetH A' B' C1\<close> \<open>BetH B' A' X'\<close> betH_trans between_comm by blast
have "C' = C1"
by (meson \<open>BetH A' B' C1\<close> \<open>CongH A C A' C1\<close> assms(2) assms(4)
betH_not_congH cong_pseudo_transitivity out2_out1)
thus ?thesis
using \<open>BetH A' B' C1\<close> \<open>CongH B' C1 B C\<close> betH_colH congH_sym by blast
qed
lemma ncolH_expand:
assumes "\<not> ColH A B C"
shows "\<not> ColH A B C \<and> A \<noteq> B \<and> B \<noteq> C \<and> A \<noteq> C"
using assms colH_trivial112 colH_trivial121 colH_trivial122 by blast
lemma betH_outH__outH:
assumes "BetH A B C" and
"outH B C D"
shows "outH A C D"
by (metis betH_expand betH_outH2__betH betH_trans1
Hilbert_neutral_dimensionless_pre.outH_def assms(1) assms(2))
(** First case of congruence of triangles *)
lemma th12:
assumes "\<not> ColH A B C" and
"\<not> ColH A' B' C'" and
"CongH A B A' B'" and
"CongH A C A' C'" and
"CongaH B A C B' A' C'"
shows "CongaH A B C A' B' C' \<and> CongaH A C B A' C' B' \<and> CongH B C B' C'"
proof (intro conjI)
show "CongaH A B C A' B' C'"
by (simp add: assms(1) assms(2) assms(3) assms(4) assms(5) cong_5)
show "CongaH A C B A' C' B'"
by (meson assms(1) assms(2) assms(3) assms(4) assms(5) colH_permut_132
cong_5 conga_permlr)
obtain D' where "CongH B' D' B C" and "outH B' C' D'"
by (metis assms(1) assms(2) colH_trivial122 out_construction)
show "CongH B C B' C'"
proof (cases "B' = D'")
case True
thus ?thesis
using \<open>outH B' C' D'\<close> outH_expand by blast
next
case False
hence "B' \<noteq> D'"
by simp
have "\<not> ColH B A C"
using assms(1) colH_permut_213 by blast
moreover have "\<not> ColH B' A' D'"
using ColH_def \<open>outH B' C' D'\<close> assms(2) inter_incid_uniquenessH
outH_expand by fastforce
moreover have "CongH B A B' A'"
by (metis assms(3) calculation(2) congH_permlr ncolH_distincts)
moreover have "CongH B C B' D'"
by (simp add: False \<open>CongH B' D' B C\<close> congH_sym)
moreover have "CongaH A B C A' B' D'"
using \<open>CongaH A B C A' B' C'\<close> \<open>outH B' C' D'\<close> calculation(1) calculation(2)
conga_out_conga ncolH_expand outH_trivial by blast
ultimately have "CongaH B A C B' A' D'"
using cong_5 by blast
have "\<not> ColH C' A' B'"
using assms(2) colH_permut_231 by blast
moreover have "\<not> ColH B A C"
using \<open>\<not> ColH B A C\<close> by blast
moreover have "same_side' C' C' A' B'"
using assms(2) same_side_prime_refl by blast
moreover have "same_side' C' D' A' B'"
by (metis (no_types, lifting) ColH_def ncolH_distincts \<open>outH B' C' D'\<close>
assms(2) out_same_side same_side'_def)
ultimately have "outH A' C' D'"
using \<open>CongaH B A C B' A' D'\<close> assms(5) cong_4_uniqueness by presburger
have "C' = D'"
by (metis (full_types) colH_trivial121 outH_expand \<open>\<not> ColH C' A' B'\<close>
\<open>outH A' C' D'\<close> \<open>outH B' C' D'\<close> colH_permut_213 inter_uniquenessH)
thus ?thesis
by (simp add: \<open>CongH B C B' D'\<close>)
qed
qed
lemma th14:
assumes "\<not> ColH A B C" and
"\<not> ColH A' B' C'" and
"CongaH A B C A' B' C'" and
"BetH A B D" and
"BetH A' B' D'"
shows "CongaH C B D C' B' D'"
proof -
obtain A'' where "CongH B' A'' A B" and "outH B' A' A''"
by (metis assms(4) assms(5) betH_distincts out_construction)
obtain C'' where "CongH B' C'' B C" and "outH B' C' C''"
by (metis assms(1) assms(2) colH_trivial122 out_construction)
obtain D'' where "CongH B' D'' B D" and "outH B' D' D''"
using assms(4) assms(5) betH_expand out_construction by blast
have "CongaH B A C B' A'' C'' \<and> CongaH B C A B' C'' A'' \<and> CongH A C A'' C''"
proof (rule th12)
show "\<not> ColH B A C"
using assms(1) colH_permut_213 by blast
show "\<not> ColH B' A'' C''"
by (metis (mono_tags, opaque_lifting) \<open>outH B' A' A''\<close> \<open>outH B' C' C''\<close>
assms(2) colH_trans colH_trivial121 colH_trivial122 outH_expand)
show "CongH B A B' A''"
by (metis \<open>CongH B' A'' A B\<close> \<open>outH B' A' A''\<close> congH_perms congH_sym out_distinct)
show "CongH B C B' C''"
using \<open>CongH B' C'' B C\<close> \<open>outH B' C' C''\<close> congH_sym out_distinct by presburger
show "CongaH A B C A'' B' C''"
using \<open>\<not> ColH B A C\<close> \<open>outH B' A' A''\<close> \<open>outH B' C' C''\<close> assms(3)
conga_out_conga ncolH_distincts outH_trivial by blast
qed
have "BetH A'' B' D''"
using \<open>outH B' A' A''\<close> \<open>outH B' D' D''\<close> assms(5) betH_outH2__betH by blast
have "CongH A D A'' D''"
by (metis (full_types) \<open>BetH A'' B' D''\<close> \<open>CongH B' A'' A B\<close>
\<open>CongH B' D'' B D\<close> addition_betH assms(1) assms(4) colH_trivial112
congH_perml congH_sym not_betH121)
{
assume "ColH A C D"
have "A \<noteq> D"
using between_diff assms(4) by blast
moreover have "ColH A D A"
by (simp add: colH_trivial121)
moreover have "ColH A D B"
by (simp add: assms(4) between_col colH_permut_132)
moreover have "ColH A D C"
by (simp add: \<open>ColH A C D\<close> colH_permut_132)
hence False
using assms(1) calculation(1) calculation(2) calculation(3) colH_trans by blast
}
hence "\<not> ColH A C D"
by blast
{
assume "ColH A'' C'' D''"
have "ColH B' A' A'' \<and> B' \<noteq> A'' \<and> B' \<noteq> A'"
using \<open>outH B' A' A''\<close> outH_expand by blast
hence "ColH B' A' A''"
by simp
moreover have "B' \<noteq> A''"
using \<open>ColH B' A' A'' \<and> B' \<noteq> A'' \<and> B' \<noteq> A'\<close> by blast
moreover have "B' \<noteq> A'"
by (simp add: \<open>ColH B' A' A'' \<and> B' \<noteq> A'' \<and> B' \<noteq> A'\<close>)
moreover have "ColH B' C' C'' \<and> B' \<noteq> C'' \<and> B' \<noteq> C'"
using \<open>outH B' C' C''\<close> outH_expand by presburger
hence "ColH B' C' C''"
by simp
moreover have "B' \<noteq> C''"
using \<open>ColH B' C' C'' \<and> B' \<noteq> C'' \<and> B' \<noteq> C'\<close> by blast
have "B' \<noteq> C'"
using \<open>ColH B' C' C'' \<and> B' \<noteq> C'' \<and> B' \<noteq> C'\<close> by blast
moreover have "ColH B' D' D'' \<and> B' \<noteq> D'' \<and> B' \<noteq> D'"
using \<open>outH B' D' D''\<close> outH_expand by blast
hence "ColH B' D' D''"
by simp
moreover have "B' \<noteq> D''"
by (simp add: \<open>ColH B' D' D'' \<and> B' \<noteq> D'' \<and> B' \<noteq> D'\<close>)
moreover have "B' \<noteq> D'"
using \<open>ColH B' D' D'' \<and> B' \<noteq> D'' \<and> B' \<noteq> D'\<close> by blast
ultimately have "ColH A'' B' D''"
using \<open>BetH A'' B' D''\<close> between_col by blast
hence "ColH A'' D'' B'"
using colH_permut_132 by blast
have "A'' \<noteq> B'"
using \<open>B' \<noteq> A''\<close> by blast
have "ColH A'' B' A'"
by (simp add: \<open>ColH B' A' A''\<close> colH_permut_312)
have "ColH A'' B' B'"
by (simp add: colH_trivial122)
have "A'' \<noteq> D''"
using \<open>BetH A'' B' D''\<close> not_betH121 by auto
have "ColH A'' D'' A'"
using \<open>A'' \<noteq> B'\<close> \<open>ColH A'' B' A'\<close> \<open>ColH A'' B' D''\<close>
colH_trans colH_trivial121 by presburger
moreover have "ColH A'' D'' B'"
by (simp add: \<open>ColH A'' D'' B'\<close>)
moreover have "ColH A'' D'' C'"
proof -
have "ColH A'' C' D''"
by (metis \<open>ColH A'' C'' D''\<close> \<open>ColH B' C' C'' \<and> B' \<noteq> C'' \<and> B' \<noteq> C'\<close> calculation(2)
colH_permut_213 colH_trans colH_trivial121)
thus ?thesis
using colH_permut_132 by blast
qed
ultimately have "ColH A' B' C'"
using \<open>A'' \<noteq> D''\<close> colH_trans by blast
hence False
by (simp add: assms(2))
}
have "CongaH A C D A'' C'' D'' \<and> CongaH A D C A'' D'' C'' \<and> CongH C D C'' D''"
proof (rule th12)
show "\<not> ColH A C D"
using \<open>ColH A C D \<Longrightarrow> False\<close> by auto
show "\<not> ColH A'' C'' D''"
using \<open>ColH A'' C'' D'' \<Longrightarrow> False\<close> by auto
show "CongH A C A'' C''"
using \<open>CongaH B A C B' A'' C'' \<and> CongaH B C A B' C'' A'' \<and> CongH A C A'' C''\<close> by blast
show "CongH A D A'' D''"
by (simp add: \<open>CongH A D A'' D''\<close>)
have "CongaH C A B C'' A'' B'"
using \<open>CongaH B A C B' A'' C'' \<and> CongaH B C A B' C'' A'' \<and> CongH A C A'' C''\<close>
conga_permlr by presburger
moreover have "outH A C C"
by (metis assms(1) colH_trivial121 outH_trivial)
moreover have "outH A'' C'' C''"
by (metis \<open>\<not> ColH A'' C'' D''\<close> colH_trivial112 outH_trivial)
moreover have "outH A B D"
by (simp add: assms(4) outH_def)
moreover have "outH A'' B' D''"
using \<open>BetH A'' B' D''\<close> outH_def by auto
ultimately show "CongaH C A D C'' A'' D''"
using conga_out_conga by blast
qed
have "\<not> ColH D B C"
using assms(1) assms(4) betH_colH between_comm colH_trans colH_trivial122 by blast
moreover have "\<not> ColH D'' B' C''"
using \<open>BetH A'' B' D''\<close> \<open>ColH A'' C'' D'' \<Longrightarrow> False\<close> betH_colH between_comm
colH_trans colH_trivial121 by blast
moreover have "CongH D B D'' B'"
by (metis betH_distincts outH_expand \<open>CongH B' D'' B D\<close>
\<open>outH B' D' D''\<close> assms(4) congH_perms)
moreover have "CongH D C D'' C''"
by (metis \<open>CongaH A C D A'' C'' D'' \<and> CongaH A D C A'' D'' C'' \<and> CongH C D C'' D''\<close>
calculation(2) colH_trivial121 congH_permlr)
moreover have "CongaH B D C B' D'' C''"
proof -
have "CongaH A D C A'' D'' C''"
using \<open>CongaH A C D A'' C'' D'' \<and> CongaH A D C A'' D'' C'' \<and> CongH C D C'' D''\<close> by auto
moreover have "outH D A B"
using assms(4) between_comm outH_def by blast
moreover have "outH D C C"
by (metis \<open>\<not> ColH D B C\<close> colH_trivial121 outH_trivial)
moreover have "outH D'' A'' B'"
using between_comm \<open>BetH A'' B' D''\<close> outH_def by blast
moreover have "outH D'' C'' C''"
by (metis \<open>\<not> ColH D'' B' C''\<close> colH_trivial121 outH_trivial)
ultimately show ?thesis
using conga_out_conga by blast
qed
ultimately have "CongaH D B C D'' B' C''"
using th12 by blast
have "CongaH D B C D' B' C'"
proof -
have "outH B D D"
using assms(4) betH_distincts outH_trivial by blast
moreover have "outH B C C"
by (metis \<open>\<not> ColH A C D\<close> assms(4) between_col outH_trivial)
moreover have "outH B' D'' D'"
using \<open>BetH A'' B' D''\<close> \<open>outH B' D' D''\<close> betH_distincts outH_sym by presburger
moreover have "outH B' C'' C'"
using \<open>outH B' C' C''\<close> outH_sym out_distinct by blast
ultimately show ?thesis
using \<open>CongaH D B C D'' B' C''\<close> conga_out_conga by blast
qed
thus ?thesis
using conga_permlr by blast
qed
lemma congH_colH_betH:
assumes "A \<noteq> B" and
"A \<noteq> I" and
"B \<noteq> I" and
"CongH I A I B" and
"ColH I A B"
shows "BetH A I B"
proof -
have "BetH I A B \<longrightarrow> ?thesis"
using assms(4) betH_not_congH by blast
moreover have "BetH A B I \<longrightarrow> ?thesis"
by (metis assms(2) assms(4) betH_not_congH between_comm congH_sym)
ultimately show ?thesis
by (metis assms(1) assms(2) assms(3) assms(5) between_one)
qed
lemma plane_separation:
assumes "\<not> ColH A X Y" and
"\<not> ColH B X Y" and
"IncidP A p" and
"IncidP B p" and
"IncidP X p" and
"IncidP Y p"
shows "cut' A B X Y \<or> same_side' A B X Y"
proof -
obtain l where "IsL l" and "IncidL X l" and "IncidL Y l"
using ColH_def colH_trivial122 by blast
obtain C where "cut l A C"
using ColH_def \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(1) cut_exists by blast
have "A = B \<longrightarrow> ?thesis"
using assms(2) colH_permut_312 same_side_prime_refl by blast
moreover {
assume "A \<noteq> B"
have "A \<noteq> C"
using \<open>local.cut l A C\<close> cut_distinct by auto
{
assume "B = C"
obtain m where "IncidL X m \<and> IncidL Y m"
using \<open>IncidL X l\<close> \<open>IncidL Y l\<close> by auto
obtain I where "IncidL I l" and "BetH A I C"
using \<open>local.cut l A C\<close> local.cut_def by blast
have "\<not> IncidL A l"
using \<open>local.cut l A C\<close> local.cut_def by auto
have "\<not> IncidL C l"
using \<open>local.cut l A C\<close> local.cut_def by blast
have "cut l A C"
by (simp add: \<open>local.cut l A C\<close>)
hence "cut l A B"
by (simp add: \<open>B = C\<close>)
have "X \<noteq> Y"
using assms(1) colH_trivial122 by blast
moreover
{
fix k
assume "IsL k" and "IncidL X k" and "IncidL Y k"
hence "cut k A B"
by (metis inter_incid_uniquenessH \<open>B = C\<close> \<open>BetH A I C\<close> \<open>IncidL I l\<close>
\<open>IncidL X k\<close> \<open>IncidL X l\<close> \<open>IncidL Y k\<close> \<open>IncidL Y l\<close> \<open>IsL k\<close> \<open>\<not> IncidL A l\<close>
\<open>\<not> IncidL C l\<close> calculation local.cut_def)
}
ultimately have "cut' A B X Y"
using cut'_def by presburger
hence ?thesis
by blast
}
moreover
{
assume "B \<noteq> C"
hence ?thesis
proof (cases "ColH A C B")
case True
hence "ColH A C B"
by simp
obtain I where "IncidL I l" and "BetH A I C"
using \<open>local.cut l A C\<close> local.cut_def by blast
hence "ColH A I C"
using between_col by blast
have "ColH A I B"
by (meson True \<open>A \<noteq> C\<close> \<open>ColH A I C\<close> colH_permut_132 colH_trans colH_trivial121)
have "\<not> IncidL A l"
using \<open>local.cut l A C\<close> local.cut_def by auto
{
assume "BetH A I B"
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "EqL m l"
by (metis \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(2)
colH_trivial122 line_uniqueness)
hence "cut m A B"
using ColH_def \<open>BetH A I B\<close> \<open>IncidL I l\<close> \<open>IncidL X m\<close> \<open>IncidL Y m\<close>
\<open>IsL l\<close> \<open>IsL m\<close> \<open>\<not> IncidL A l\<close> assms(2) local.cut_def morph by auto
}
hence "cut' A B X Y"
using assms(1) colH_trivial122 cut'_def by auto
hence ?thesis
by blast
}
moreover {
assume "BetH I B A"
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "EqL m l"
by (metis \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(2)
colH_trivial122 line_uniqueness)
hence "same_side A B m"
by (metis inter_incid_uniquenessH ncolH_distincts out_same_side
outH_def \<open>BetH I B A\<close> \<open>IncidL I l\<close> \<open>IncidL X l\<close> \<open>IncidL X m\<close> \<open>IncidL Y l\<close>
\<open>IncidL Y m\<close> \<open>\<not> IncidL A l\<close> assms(2))
}
hence "same_side' A B X Y"
using assms(1) colH_trivial122 same_side'_def by auto
hence ?thesis
by blast
}
moreover {
assume "BetH I A B"
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "EqL m l"
by (metis \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(2)
colH_trivial122 line_uniqueness)
hence "same_side A B m"
by (metis inter_incid_uniquenessH ncolH_expand out_same_side
outH_def \<open>BetH I A B\<close> \<open>IncidL I l\<close> \<open>IncidL X l\<close> \<open>IncidL X m\<close> \<open>IncidL Y l\<close>
\<open>IncidL Y m\<close> \<open>\<not> IncidL A l\<close> assms(2))
}
hence "same_side' A B X Y"
using assms(1) colH_trivial122 same_side'_def by auto
hence ?thesis
by blast
}
ultimately show ?thesis
by (metis ColH_def Is_line \<open>A \<noteq> B\<close> \<open>BetH A I C\<close> \<open>ColH A I B\<close>
\<open>IncidL I l\<close> \<open>IncidL X l\<close> \<open>IncidL Y l\<close> assms(2) betH_colH between_one)
next
case False
have "IncidLP l p"
using ncolH_expand Is_plane \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close>
assms(2) assms(5) assms(6) line_on_plane by blast
obtain I where "IncidL I l" and "BetH A I C"
using \<open>local.cut l A C\<close> local.cut_def by blast
hence "ColH A I C"
by (simp add: between_col)
hence "IncidP I p"
using IncidLP_def \<open>IncidL I l\<close> \<open>IncidLP l p\<close> by blast
hence "IncidP C p"
using \<open>BetH A I C\<close> \<open>ColH A I C\<close> assms(3) betH_distincts line_on_plane' by blast
{
assume "cut l A B"
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "EqL m l"
by (metis \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(2)
colH_trivial122 line_uniqueness)
hence "cut m A B"
by (meson \<open>IsL m\<close> \<open>local.cut l A B\<close> local.cut_def morph)
}
hence ?thesis
using assms(1) colH_trivial122 cut'_def by force
}
moreover
{
assume "cut l C B"
have "X \<noteq> Y"
using assms(1) colH_trivial122 by blast
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "EqL m l"
by (metis \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(2)
colH_trivial122 line_uniqueness)
have "cut m A C"
by (meson \<open>EqL m l\<close> \<open>IsL m\<close> \<open>local.cut l A C\<close> local.cut_def morph)
moreover have "cut m B C"
by (metis \<open>EqL m l\<close> \<open>local.cut l C B\<close> calculation cut_comm local.cut_def morph)
ultimately have "same_side A B m"
using \<open>IsL m\<close> same_side_def by blast
}
hence "same_side' A B X Y"
using assms(1) colH_trivial122 same_side'_def by auto
hence ?thesis
by blast
}
moreover
have "\<not> IncidL B l"
using ColH_def \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(2) by blast
ultimately show ?thesis
using pasch False \<open>IncidLP l p\<close> \<open>IncidP C p\<close> \<open>local.cut l A C\<close>
assms(3) assms(4) strong_pasch by blast
qed
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
lemma same_side_comm:
assumes "same_side A B l"
shows "same_side B A l"
using assms same_side_def by blast
lemma same_side_not_incid:
assumes "same_side A B l"
shows "\<not> IncidL A l \<and> \<not> IncidL B l"
using assms local.cut_def same_side_def by auto
lemma out_same_side':
assumes "X \<noteq> Y" and
"IncidL X l" and
"IncidL Y l" and
"IncidL A l" and
"\<not> IncidL B l" and
"outH A B C"
shows "same_side' B C X Y"
proof -
have "same_side B C l"
using assms(4) assms(5) assms(6) out_same_side by blast
{
fix m
assume "IsL m" and
"IncidL X m" and
"IncidL Y m"
hence "EqL m l"
using Is_line assms(1) assms(2) assms(3) line_uniqueness by presburger
hence "same_side B C m"
by (meson Is_line \<open>IsL m\<close> assms(4) assms(5) assms(6) morph out_same_side)
}
thus ?thesis
by (simp add: assms(1) same_side'_def)
qed
lemma same_side_trans:
assumes "same_side A B l" and
"same_side B C l"
shows "same_side A C l"
by (meson assms(1) assms(2) cut_comm cut_same_side_cut same_side_def)
lemma colH_IncidL__IncidL:
assumes "A \<noteq> B" and
"IncidL A l" and
"IncidL B l" and
"ColH A B C"
shows "IncidL C l"
using ColH_def assms(1) assms(2) assms(3) assms(4) inter_incid_uniquenessH by blast
lemma IncidL_not_IncidL__not_colH:
assumes "A \<noteq> B" and
"IncidL A l" and
"IncidL B l" and
"\<not> IncidL C l"
shows "\<not> ColH A B C"
using assms(1) assms(2) assms(3) assms(4) colH_IncidL__IncidL by blast
lemma same_side_prime_not_colH:
assumes "same_side' A B C D"
shows "\<not> ColH A C D \<and> \<not> ColH B C D"
proof -
{
fix l
assume "IncidL C l" and
"IncidL D l"
have "same_side A B l"
using Is_line \<open>IncidL C l\<close> \<open>IncidL D l\<close> assms same_side'_def by auto
hence ?thesis
by (meson ColH_def assms same_side'_def same_side_not_incid)
}
thus ?thesis
by (metis assms line_existence same_side'_def)
qed
lemma OS2__TS:
assumes "same_side' Y Z PO X" and
"same_side' X Y PO Z"
shows "cut' X Z PO Y"
proof -
obtain Z' where "BetH Z PO Z'"
using assms(2) between_out same_side'_def by force
have "PO \<noteq> X"
using assms(1) same_side'_def by blast
have "PO \<noteq> Z"
using assms(2) same_side'_def by force
{
fix l
assume "IsL l" and
"IncidL PO l" and
"IncidL X l"
have "\<not> IncidL Y l"
using ColH_def \<open>IncidL PO l\<close> \<open>IncidL X l\<close> \<open>IsL l\<close> assms(1)
same_side_prime_not_colH by blast
moreover have "\<not> IncidL Z l"
using ColH_def \<open>IncidL PO l\<close> \<open>IncidL X l\<close> \<open>IsL l\<close> assms(1)
same_side_prime_not_colH by blast
ultimately have "cut l Z' Z"
by (metis IncidL_not_IncidL__not_colH Is_line \<open>BetH Z PO Z'\<close> \<open>IncidL PO l\<close>
betH_distincts between_col between_comm local.cut_def)
hence "cut l Y Z'"
by (meson \<open>IncidL PO l\<close> \<open>IncidL X l\<close> \<open>IsL l\<close> assms(1) cut_comm
cut_same_side_cut same_side'_def same_side_comm)
}
hence "cut' Y Z' PO X"
using \<open>PO \<noteq> X\<close> cut'_def by auto
{
fix l
assume "IsL l" and
"IncidL PO l" and
"IncidL Y l"
have "\<not> ColH Y PO Z"
using assms(2) same_side_prime_not_colH by blast
have "PO \<noteq> Y"
using \<open>\<not> ColH Y PO Z\<close> colH_trivial112 by auto
have "PO \<noteq> Z'"
using \<open>BetH Z PO Z'\<close> betH_distincts by auto
have "Z \<noteq> Z'"
using \<open>BetH Z PO Z'\<close> not_betH121 by auto
{
assume "IncidL Z' l"
hence "ColH PO Y Z'"
using ColH_def \<open>IncidL PO l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> by blast
moreover have "ColH Z PO Z'"
by (simp add: \<open>BetH Z PO Z'\<close> betH_colH)
ultimately have "ColH Y PO Z"
by (meson ColH_def \<open>PO \<noteq> Z'\<close> inter_incid_uniquenessH)
have False
using ColH_def \<open>BetH Z PO Z'\<close> \<open>IncidL PO l\<close> \<open>IncidL Y l\<close>
\<open>IncidL Z' l\<close> \<open>IsL l\<close> \<open>PO \<noteq> Z'\<close> \<open>\<not> ColH Y PO Z\<close> betH_line
inter_incid_uniquenessH by blast
}
hence "cut l Z Z'"
using ColH_def \<open>BetH Z PO Z'\<close> \<open>IncidL PO l\<close> \<open>IncidL Y l\<close>
\<open>IsL l\<close> \<open>\<not> ColH Y PO Z\<close> local.cut_def by blast
moreover
obtain m where "IsL m" and "IncidL PO m" and "IncidL X m"
using \<open>PO \<noteq> X\<close> line_existence by blast
have "cut m Y Z'"
using Is_line \<open>IncidL PO m\<close>
\<open>IncidL X m\<close> \<open>\<And>l. \<lbrakk>IsL l; IncidL PO l; IncidL X l\<rbrakk> \<Longrightarrow> local.cut l Y Z'\<close> by blast
have "\<not> IncidL Y m"
using \<open>local.cut m Y Z'\<close> local.cut_def by blast
have "\<not> IncidL Z' m"
using \<open>local.cut m Y Z'\<close> local.cut_def by auto
obtain X' where "IncidL X' m" and "BetH Y X' Z'"
using \<open>local.cut m Y Z'\<close> local.cut_def by blast
have "same_side Z' X' l"
using \<open>BetH Y X' Z'\<close> \<open>IncidL Y l\<close> \<open>IncidL Z' l \<Longrightarrow> False\<close> outH_def out_same_side by blast
moreover have "same_side X' X l"
proof -
have "ColH PO X X'"
using ColH_def Is_line \<open>IncidL PO m\<close> \<open>IncidL X m\<close> \<open>IncidL X' m\<close> by blast
have "\<not> ColH Y PO X"
using assms(1) same_side_prime_not_colH by presburger
have "outH PO X X'"
proof (cases "X = X'")
case True
thus ?thesis
using \<open>PO \<noteq> X\<close> outH_trivial by auto
next
case False
hence "X \<noteq> X'"
by simp
have "ColH Z PO Z'"
by (simp add: \<open>BetH Z PO Z'\<close> betH_colH)
have "ColH Y X' Z'"
by (simp add: \<open>BetH Y X' Z'\<close> betH_colH)
have "PO = X' \<longrightarrow> ?thesis"
using \<open>IncidL PO l\<close> calculation(2) same_side_not_incid by blast
moreover
{
assume "PO \<noteq> X'"
have "ColH PO X X'"
by (simp add: \<open>ColH PO X X'\<close>)
hence "BetH PO X X' \<or> BetH X X' PO \<or> BetH X PO X'"
using False \<open>PO \<noteq> X'\<close> \<open>PO \<noteq> X\<close> between_one by auto
moreover have "BetH PO X X' \<longrightarrow> ?thesis"
using outH_def by auto
moreover have "BetH X X' PO \<longrightarrow> ?thesis"
using between_comm outH_def by blast
moreover {
assume "BetH X PO X'"
obtain lo where "IsL lo" and "IncidL PO lo" and "IncidL Z lo"
using \<open>PO \<noteq> Z\<close> line_existence by blast
have "same_side X Y lo"
using \<open>IncidL PO lo\<close> \<open>IncidL Z lo\<close> \<open>IsL lo\<close> assms(2) same_side'_def by auto
have "cut lo X X'"
by (metis Is_line \<open>BetH X PO X'\<close> \<open>ColH PO X X'\<close> \<open>IncidL PO lo\<close>
\<open>PO \<noteq> X'\<close> \<open>same_side X Y lo\<close> colH_IncidL__IncidL colH_permut_312
local.cut_def same_side_not_incid)
moreover
have "\<not> IncidL X' lo"
using calculation local.cut_def by blast
moreover have "IncidL Z' lo"
by (metis \<open>ColH Z PO Z'\<close> \<open>IncidL PO lo\<close> \<open>IncidL Z lo\<close>
\<open>PO \<noteq> Z\<close> colH_IncidL__IncidL)
ultimately have "same_side X' Y lo"
by (meson \<open>BetH Y X' Z'\<close> between_comm outH_def out_same_side)
hence ?thesis
using \<open>local.cut lo X X'\<close> \<open>same_side X Y lo\<close> cut_same_side_cut
same_side_not_cut by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
thus ?thesis
by (meson \<open>IncidL PO l\<close> \<open>IncidL PO m\<close> \<open>IncidL X m\<close> \<open>IncidL Y l\<close>
\<open>PO \<noteq> X\<close> \<open>\<not> IncidL Y m\<close> inter_incid_uniquenessH out_same_side same_side_comm)
qed
ultimately have "same_side Z' X l"
using same_side_trans by blast
hence "cut l X Z"
using \<open>local.cut l Z Z'\<close> cut_comm cut_same_side_cut by blast
}
thus ?thesis
by (metis assms(2) colH_trivial112 cut'_def same_side_prime_not_colH)
qed
lemma th15_aux_1:
assumes "\<not> ColH H PO L" and
"\<not> ColH H' O' L'" and
"\<not> ColH K PO L" and
"\<not> ColH K' O' L'" and
"\<not> ColH H PO K" and
"\<not> ColH H' O' K'" and
"same_side' H K PO L" and
"same_side' H' K' O' L'" and
"cut' K L PO H" and
"CongaH H PO L H' O' L'" and
"CongaH K PO L K' O' L'"
shows "CongaH H PO K H' O' K'"
proof -
obtain K'' where "CongH O' K'' PO K" and "outH O' K' K''"
by (metis assms(3) assms(4) colH_trivial112 out_construction)
obtain L'' where "CongH O' L'' PO L" and "outH O' L' L''"
by (metis assms(3) assms(4) colH_trivial122 out_construction)
have "CongaH K PO L K'' O' L''"
using \<open>outH O' K' K''\<close> \<open>outH O' L' L''\<close> assms(1) assms(11) assms(5)
conga_out_conga ncolH_distincts outH_trivial by blast
have "PO \<noteq> H"
using assms(1) colH_trivial112 by blast
obtain l where "IsL l" and "IncidL PO l" and "IncidL H l"
using \<open>PO \<noteq> H\<close> line_existence by fastforce
hence "cut l K L"
using assms(9) cut'_def by auto
have "\<not> IncidL K l"
using \<open>local.cut l K L\<close> local.cut_def by blast
have "\<not> IncidL L l"
using \<open>local.cut l K L\<close> local.cut_def by auto
obtain I where "IncidL I l" and "BetH K I L"
using \<open>local.cut l K L\<close> local.cut_def by blast
have "PO \<noteq> I"
using \<open>BetH K I L\<close> assms(3) betH_colH by blast
have "H = I \<longrightarrow> outH PO I H"
using \<open>PO \<noteq> I\<close> outH_trivial by force
moreover {
assume "H \<noteq> I"
have "ColH PO I H"
using ColH_def Is_line \<open>IncidL H l\<close> \<open>IncidL I l\<close> \<open>IncidL PO l\<close> by blast
hence "BetH PO I H \<or> BetH I H PO \<or> BetH I PO H"
using between_one \<open>H \<noteq> I\<close> \<open>PO \<noteq> H\<close> \<open>PO \<noteq> I\<close> by blast
moreover have "BetH PO I H \<longrightarrow> outH PO I H"
by (simp add: outH_def)
moreover have "BetH I H PO \<longrightarrow> outH PO I H"
using between_comm outH_def by blast
moreover {
assume "BetH I PO H"
have "PO \<noteq> L"
using \<open>IncidL PO l\<close> \<open>\<not> IncidL L l\<close> by auto
obtain m where "IsL m" and "IncidL PO m" and "IncidL L m"
using ColH_def colH_trivial121 by blast
have "same_side H K m"
using \<open>IncidL L m\<close> \<open>IncidL PO m\<close> \<open>IsL m\<close> assms(7) same_side'_def by auto
have "cut m H I"
by (metis IncidL_not_IncidL__not_colH Is_line \<open>BetH I PO H\<close> \<open>ColH PO I H\<close>
\<open>IncidL PO m\<close> \<open>PO \<noteq> I\<close> \<open>same_side H K m\<close>
cut_comm local.cut_def same_side_not_incid)
moreover have "same_side I K m"
by (meson \<open>BetH K I L\<close> \<open>IncidL L m\<close> between_comm calculation local.cut_def
outH_def out_same_side)
ultimately have "cut m H K"
using cut_same_side_cut by blast
hence "outH PO I H"
using \<open>same_side H K m\<close> same_side_not_cut by auto
}
ultimately have "outH PO I H"
by blast
}
ultimately have "outH PO I H"
by blast
have "outH PO L L"
using assms(7) outH_trivial same_side'_def by force
obtain I' where "CongH O' I' PO I" and "outH O' H' I'"
by (metis \<open>PO \<noteq> I\<close> assms(2) colH_trivial112 out_construction)
hence "CongaH I PO L I' O' L''"
using \<open>PO \<noteq> H\<close> \<open>outH O' L' L''\<close> \<open>outH PO I H\<close> \<open>outH PO L L\<close> assms(10)
conga_out_conga outH_sym by blast
have "O' \<noteq> I'"
using \<open>outH O' H' I'\<close> out_distinct by auto
have "I' \<noteq> L''"
by (metis (mono_tags, opaque_lifting) \<open>O' \<noteq> I'\<close> \<open>outH O' H' I'\<close> \<open>outH O' L' L''\<close>
assms(2) colH_trans ncolH_expand outH_col)
hence "\<exists> I'. (O' \<noteq> I' \<and> I' \<noteq> L'' \<and> outH PO H I \<and> outH O' H' I' \<and>
ColH O' I' H' \<and> CongH O' I' PO I \<and> CongaH I PO L I' O' L'')"
using \<open>CongH O' I' PO I\<close> \<open>CongaH I PO L I' O' L''\<close> \<open>O' \<noteq> I'\<close> \<open>PO \<noteq> H\<close>
\<open>outH O' H' I'\<close> \<open>outH PO I H\<close> outH_col outH_sym by blast
then obtain I' where "O' \<noteq> I'" and "I' \<noteq> L''" and
"outH PO H I" and "outH O' H' I'" and
"ColH O' I' H'" and "CongH O' I' PO I" and "CongaH I PO L I' O' L''"
by blast
have "PO \<noteq> L"
using \<open>IncidL PO l\<close> \<open>\<not> IncidL L l\<close> by blast
have "O' \<noteq> L''"
using \<open>outH O' L' L''\<close> out_distinct by blast
have "ColH O' L' L''"
using \<open>outH O' L' L''\<close> outH_expand by blast
have "CongaH PO I L O' I' L'' \<and> CongaH PO L I O' L'' I' \<and> CongH I L I' L''"
proof -
have "\<not> ColH PO I L"
using \<open>IncidL I l\<close> \<open>IncidL PO l\<close> \<open>PO \<noteq> I\<close> \<open>\<not> IncidL L l\<close>
colH_IncidL__IncidL by blast
moreover
{
assume "ColH O' I' L''"
have False
by (metis \<open>ColH O' I' H'\<close> \<open>ColH O' I' L''\<close> \<open>ColH O' L' L''\<close> \<open>O' \<noteq> I'\<close> \<open>O' \<noteq> L''\<close>
assms(2) colH_permut_312 inter_uniquenessH ncolH_expand)
}
hence "\<not> ColH O' I' L''"
by blast
moreover have "CongH PO I O' I'"
using \<open>CongH O' I' PO I\<close> \<open>O' \<noteq> I'\<close> congH_sym by blast
moreover have "CongH PO L O' L''"
using \<open>CongH O' L'' PO L\<close> \<open>O' \<noteq> L''\<close> congH_sym by blast
moreover have "CongaH I PO L I' O' L''"
by (simp add: \<open>CongaH I PO L I' O' L''\<close>)
ultimately show ?thesis
using th12 by blast
qed
have "CongaH PO I L O' I' L''"
using \<open>CongaH PO I L O' I' L'' \<and> CongaH PO L I O' L'' I' \<and> CongH I L I' L''\<close> by auto
have "CongaH PO L I O' L'' I'"
using \<open>CongaH PO I L O' I' L'' \<and> CongaH PO L I O' L'' I' \<and> CongH I L I' L''\<close> by auto
have "CongH I L I' L''"
using \<open>CongaH PO I L O' I' L'' \<and> CongaH PO L I O' L'' I' \<and> CongH I L I' L''\<close> by blast
have "PO \<noteq> K"
using \<open>IncidL PO l\<close> \<open>\<not> IncidL K l\<close> by auto
have "PO \<noteq> L"
by (simp add: \<open>PO \<noteq> L\<close>)
have "ColH O' L' L''"
using \<open>ColH O' L' L''\<close> by blast
have "O' \<noteq> L'"
using \<open>outH O' L' L''\<close> outH_expand by presburger
have "CongaH PO K L O' K'' L'' \<and> CongaH PO L K O' L'' K'' \<and> CongH K L K'' L''"
proof -
have "\<not> ColH PO K L"
using assms(3) colH_permut_213 by blast
moreover
{
assume "ColH O' K'' L''"
have "O' \<noteq> K''"
using \<open>outH O' K' K''\<close> out_distinct by presburger
have "K'' \<noteq> L''"
by (metis \<open>ColH O' L' L''\<close> \<open>outH O' K' K''\<close> assms(4) colH_trans
ncolH_expand outH_expand)
have "O' \<noteq> K'"
using assms(6) colH_trivial122 by blast
have "K' \<noteq> L'"
using assms(4) ncolH_expand by presburger
have "ColH O' K' L'"
by (metis \<open>ColH O' K'' L''\<close> \<open>ColH O' L' L''\<close> \<open>O' \<noteq> K''\<close> \<open>O' \<noteq> L''\<close>
\<open>outH O' K' K''\<close> colH_trans ncolH_expand outH_col)
have False
using \<open>ColH O' K' L'\<close> assms(4) colH_permut_213 by blast
}
hence "\<not> ColH O' K'' L''"
by blast
moreover have "CongH PO K O' K''"
using \<open>CongH O' K'' PO K\<close> \<open>outH O' K' K''\<close> congH_sym out_distinct by presburger
moreover have "CongH PO L O' L''"
using \<open>CongH O' L'' PO L\<close> \<open>O' \<noteq> L''\<close> congH_sym by presburger
moreover have "CongaH K PO L K'' O' L''"
by (simp add: \<open>CongaH K PO L K'' O' L''\<close>)
ultimately show ?thesis
using th12 by blast
qed
have "CongaH PO K L O' K'' L''"
using \<open>CongaH PO K L O' K'' L'' \<and> CongaH PO L K O' L'' K'' \<and> CongH K L K'' L''\<close> by auto
have "CongaH PO L K O' L'' K''"
using \<open>CongaH PO K L O' K'' L'' \<and> CongaH PO L K O' L'' K'' \<and> CongH K L K'' L''\<close> by auto
have "CongH K L K'' L''"
using \<open>CongaH PO K L O' K'' L'' \<and> CongaH PO L K O' L'' K'' \<and> CongH K L K'' L''\<close> by auto
have "BetH K'' I' L''"
proof -
have "outH L PO PO"
using \<open>PO \<noteq> L\<close> outH_def by auto
have "outH L'' O' O'"
using \<open>O' \<noteq> L''\<close> outH_def by auto
have "outH L'' I' I'"
using \<open>I' \<noteq> L''\<close> outH_def by blast
have "outH L I K"
using \<open>BetH K I L\<close> between_comm outH_def by blast
hence "CongaH PO L K O' L'' I'"
using conga_out_conga \<open>CongaH PO L I O' L'' I'\<close> \<open>outH L PO PO\<close> \<open>outH L'' I' I'\<close>
\<open>outH L'' O' O'\<close> by blast
moreover
have "same_side' H' I' L'' O'"
proof -
obtain m where "IsL m" and "IncidL O' m" and "IncidL L'' m"
using \<open>O' \<noteq> L''\<close> line_existence by blast
have "L'' \<noteq> O'"
using \<open>O' \<noteq> L''\<close> by auto
moreover have "IncidL L'' m"
by (simp add: \<open>IncidL L'' m\<close>)
moreover have "IncidL O' m"
using \<open>IncidL O' m\<close> by auto
moreover
{
assume "IncidL H' m"
hence "ColH O' L'' H'"
using ColH_def \<open>IsL m\<close> calculation(2) calculation(3) by blast
hence False
by (metis \<open>ColH O' L' L''\<close> assms(2) calculation(1) colH_trans ncolH_distincts)
}
hence "\<not> IncidL H' m"
by blast
moreover have "outH O' H' I'"
using \<open>outH O' H' I'\<close> by blast
ultimately show ?thesis using out_same_side'
by blast
qed
moreover
have "L'' \<noteq> O'"
using \<open>O' \<noteq> L''\<close> by blast
moreover
have "\<forall> l. (IsL l \<and> IncidL L'' l \<and> IncidL O' l) \<longrightarrow> same_side H' K'' l"
proof -
{
fix l
assume "IsL l" and
"IncidL L'' l" and "IncidL O' l"
have "ColH O' L' L''"
by (simp add: \<open>ColH O' L' L''\<close>)
obtain lo where "IncidL O' lo" and "IncidL L' lo" and
"IncidL L'' lo" and "IncidL O' lo"
by (metis \<open>outH O' L' L''\<close> betH_line line_existence outH_def)
have "EqL l lo"
using Is_line \<open>IncidL L'' l\<close> \<open>IncidL L'' lo\<close> \<open>IncidL O' l\<close> \<open>IncidL O' lo\<close>
calculation(3) line_uniqueness by presburger
hence "same_side K' K'' lo"
using ColH_def Is_line \<open>IncidL L' lo\<close> \<open>IncidL O' lo\<close> \<open>outH O' K' K''\<close> assms(4)
out_same_side by blast
hence "same_side H' K' lo"
using Is_line \<open>IncidL L' lo\<close> \<open>IncidL O' lo\<close> assms(8) same_side'_def by force
hence "same_side H' K'' l" using same_side_trans
by (metis (no_types, lifting) ColH_def \<open>IncidL L' lo\<close> \<open>IncidL L'' l\<close>
\<open>IncidL L'' lo\<close> \<open>IncidL O' l\<close> \<open>IncidL O' lo\<close> \<open>IsL l\<close> \<open>outH O' K' K''\<close> assms(4)
assms(8) calculation(3) inter_incid_uniquenessH out_same_side same_side'_def)
}
thus ?thesis
by blast
qed
ultimately have "same_side' H' K'' L'' O'"
using same_side'_def by blast
thus ?thesis
by (metis \<open>BetH K I L\<close> \<open>CongaH PO L K O' L'' I'\<close> \<open>same_side' H' I' L'' O'\<close> assms(3)
\<open>CongaH PO I L O' I' L'' \<and> CongaH PO L I O' L'' I' \<and> CongH I L I' L''\<close>
\<open>CongaH PO K L O' K'' L'' \<and> CongaH PO L K O' L'' K'' \<and> CongH K L K'' L''\<close>
betH_congH3_outH_betH between_comm colH_permut_312 congH_permlr
cong_4_uniqueness out_distinct same_side_prime_not_colH)
qed
have "CongaH K PO I K'' O' I' \<and> CongaH K I PO K'' I' O' \<and> CongH PO I O' I'"
proof -
have "CongH I' K'' I K"
proof -
have "BetH L'' I' K''"
using \<open>BetH K'' I' L''\<close> between_comm by blast
moreover have "BetH L I K"
by (simp add: \<open>BetH K I L\<close> between_comm)
moreover have "CongH L'' I' L I"
using \<open>BetH K I L\<close> \<open>CongH I L I' L''\<close> \<open>I' \<noteq> L''\<close> betH_distincts
congH_perms by blast
moreover have "CongH L'' K'' L K"
by (metis \<open>CongH K L K'' L''\<close> assms(3) calculation(1) colH_trivial121
congH_perms not_betH121)
ultimately show ?thesis
using soustraction_betH by blast
qed
have "\<not> ColH K PO I"
by (metis IncidL_not_IncidL__not_colH \<open>IncidL I l\<close> \<open>IncidL PO l\<close> \<open>PO \<noteq> I\<close>
\<open>\<not> IncidL K l\<close> colH_permut_321)
moreover
{
assume "ColH K'' O' I'"
have "O' \<noteq> K''"
using \<open>outH O' K' K''\<close> out_distinct by blast
have "ColH O' K' K''"
using \<open>outH O' K' K''\<close> outH_expand by auto
hence "ColH K' O' L'"
by (metis colH_permut_231 colH_trans colH_trivial121 \<open>ColH K'' O' I'\<close>
\<open>ColH O' I' H'\<close> \<open>O' \<noteq> I'\<close> \<open>O' \<noteq> K''\<close> assms(6))
hence False
by (simp add: assms(4))
}
hence "\<not> ColH K'' O' I'"
by blast
moreover have "CongH K PO K'' O'"
using outH_expand \<open>CongH O' K'' PO K\<close> \<open>PO \<noteq> K\<close> \<open>outH O' K' K''\<close>
congH_perms by blast
moreover have "CongH K I K'' I'"
by (metis \<open>CongH I' K'' I K\<close> \<open>IncidL I l\<close> \<open>\<not> IncidL K l\<close> calculation(2)
colH_trivial121 congH_perms)
moreover have "CongaH PO K I O' K'' I'"
using \<open>BetH K I L\<close> \<open>BetH K'' I' L''\<close> \<open>CongaH PO K L O' K'' L''\<close> \<open>PO \<noteq> K\<close>
calculation(2) conga_out_conga ncolH_expand outH_def by blast
ultimately
show ?thesis using th12 by blast
qed
have "CongaH K PO I K'' O' I'"
using \<open>CongaH K PO I K'' O' I' \<and> CongaH K I PO K'' I' O' \<and> CongH PO I O' I'\<close> by blast
have "CongaH K I PO K'' I' O'"
using \<open>CongaH K PO I K'' O' I' \<and> CongaH K I PO K'' I' O' \<and> CongH PO I O' I'\<close> by auto
have "CongH PO I O' I'"
using \<open>CongH O' I' PO I\<close> \<open>O' \<noteq> I'\<close> congH_sym by auto
have "outH PO K K"
using \<open>PO \<noteq> K\<close> outH_def by force
moreover have "outH PO I H"
by (simp add: \<open>outH PO I H\<close>)
moreover have "outH O' K'' K'"
using \<open>outH O' K' K''\<close> outH_sym out_distinct by blast
moreover have "outH O' I' H'"
by (simp add: \<open>O' \<noteq> I'\<close> \<open>outH O' H' I'\<close> outH_sym)
ultimately show ?thesis
using \<open>CongaH K PO I K'' O' I'\<close> conga_out_conga conga_permlr by blast
qed
lemma th15_aux:
assumes "\<not> ColH H PO L" and
"\<not> ColH H' O' L'" and
"\<not> ColH K PO L" and
"\<not> ColH K' O' L'" and
"\<not> ColH H PO K" and
"\<not> ColH H' O' K'" and
"same_side' H K PO L" and
"same_side' H' K' O' L'" and
"CongaH H PO L H' O' L'" and
"CongaH K PO L K' O' L'"
shows "CongaH H PO K H' O' K'"
proof -
obtain p where "IsP p" and "IncidP H p" and "IncidP K p" and
"IncidP PO p" and "IncidP L p"
using Is_plane assms(7) same_side_prime__plane by blast
moreover have "cut' K L PO H \<longrightarrow> CongaH H PO K H' O' K'"
using assms(1) assms(10) assms(2) assms(3) assms(4) assms(5) assms(6)
assms(7) assms(8) assms(9) th15_aux_1 by auto
moreover {
assume "same_side' K L PO H"
moreover have "\<not> ColH K PO H"
using assms(5) colH_permut_321 by blast
moreover have "\<not> ColH K' O' H'"
using assms(6) colH_permut_321 by blast
moreover
have "PO \<noteq> L"
using assms(3) colH_trivial122 by blast
{
fix l
assume "IsL l" and "IncidL PO l" and "IncidL L l"
hence "same_side K H l"
by (metis assms(7) same_side'_def same_side_comm)
}
hence "same_side' K H PO L"
using \<open>PO \<noteq> L\<close> same_side'_def by auto
moreover have "O' \<noteq> L'"
using assms(4) colH_trivial122 by force
{
fix l
assume "IsL l" and "IncidL O' l" and "IncidL L' l"
hence "same_side K' H' l"
by (meson assms(8) same_side'_def same_side_comm)
}
hence "same_side' K' H' O' L'"
by (simp add: \<open>O' \<noteq> L'\<close> same_side'_def)
moreover have "cut' H L PO K"
by (simp add: OS2__TS assms(7) calculation(1))
ultimately have "CongaH H PO K H' O' K'"
using assms(1) assms(2) assms(3) assms(4) assms(9) assms(10)
conga_permlr th15_aux_1 by presburger
}
moreover have "\<not> ColH K PO H"
using assms(5) colH_permut_321 by blast
moreover have "\<not> ColH L PO H"
using assms(1) colH_permut_321 by blast
ultimately show ?thesis
using plane_separation by blast
qed
lemma th15:
assumes "\<not> ColH H PO L" and
"\<not> ColH H' O' L'" and
"\<not> ColH K PO L" and
"\<not> ColH K' O' L'" and
"\<not> ColH H PO K" and
"\<not> ColH H' O' K'" and
"(cut' H K PO L \<and> cut' H' K' O' L') \<or> (same_side' H K PO L \<and> same_side' H' K' O' L')" and
"CongaH H PO L H' O' L'" and
"CongaH K PO L K' O' L'"
shows "CongaH H PO K H' O' K'"
proof -
{
assume "same_side' H K PO L" and "same_side' H' K' O' L'"
hence ?thesis using th15_aux
using assms(1) assms(2) assms(3) assms(4) assms(5) assms(6)
assms(8) assms(9) by presburger
}
moreover
{
assume "cut' H K PO L" and
"cut' H' K' O' L'"
obtain SH where "BetH H PO SH"
by (metis assms(1) between_out colH_trivial112)
obtain SH' where "BetH H' O' SH'"
by (metis assms(2) between_out colH_trivial112)
have "CongaH SH PO L SH' O' L'"
using \<open>BetH H PO SH\<close> \<open>BetH H' O' SH'\<close> assms(1) assms(2) assms(8)
conga_permlr th14 by blast
have "H \<noteq> PO"
using assms(1) colH_trivial112 by force
have "PO \<noteq> SH"
using \<open>BetH H PO SH\<close> betH_distincts by blast
have "H \<noteq> SH"
using \<open>BetH H PO SH\<close> not_betH121 by auto
have "H' \<noteq> O'"
using assms(6) colH_trivial112 by force
have "H' \<noteq> SH'"
using \<open>BetH H' O' SH'\<close> not_betH121 by force
have "O' \<noteq> SH'"
using \<open>BetH H' O' SH'\<close> betH_distincts by blast
have "CongaH SH PO K SH' O' K'"
proof -
have "ColH H PO SH"
by (simp add: \<open>BetH H PO SH\<close> betH_colH)
have "ColH H' O' SH'"
by (simp add: \<open>BetH H' O' SH'\<close> betH_colH)
moreover have "\<not> ColH SH PO L"
by (metis \<open>ColH H PO SH\<close> \<open>PO \<noteq> SH\<close> assms(1) colH_trans ncolH_expand)
moreover have "\<not> ColH SH' O' L'"
by (metis \<open>ColH H' O' SH'\<close> \<open>O' \<noteq> SH'\<close> assms(2) colH_permut_321
colH_trans colH_trivial122)
moreover have "\<not> ColH SH PO K"
by (metis \<open>ColH H PO SH\<close> \<open>PO \<noteq> SH\<close> assms(5) colH_permut_321
colH_trans colH_trivial122)
moreover have "\<not> ColH SH' O' K'"
by (metis \<open>ColH H' O' SH'\<close> \<open>O' \<noteq> SH'\<close> assms(6) colH_permut_321
colH_trans colH_trivial122)
moreover
{
fix l
assume "IsL l" and "IncidL PO l" and "IncidL L l"
hence "cut l SH H"
by (meson ColH_def \<open>BetH H PO SH\<close> assms(1) between_comm
calculation(2) local.cut_def)
moreover
have "cut l H K"
using \<open>cut' H K PO L\<close> \<open>IncidL L l\<close> \<open>IncidL PO l\<close> \<open>IsL l\<close> cut'_def by auto
hence "cut l K H"
using cut_comm by blast
ultimately have "same_side SH K l"
using same_side_def \<open>IsL l\<close> by blast
}
moreover have "PO \<noteq> L"
using calculation(2) colH_trivial122 by blast
ultimately have "same_side' SH K PO L"
using same_side'_def by presburger
moreover
{
fix l
assume "IsL l" and "IncidL O' l" and "IncidL L' l"
hence "cut l SH' H'"
by (meson ColH_def \<open>BetH H' O' SH'\<close> \<open>\<not> ColH SH' O' L'\<close>
assms(2) between_comm local.cut_def)
moreover
have "cut l H' K'"
using \<open>cut' H' K' O' L'\<close> \<open>IncidL L' l\<close> \<open>IncidL O' l\<close> \<open>IsL l\<close> cut'_def by auto
hence "cut l K' H'"
using cut_comm by blast
ultimately have "same_side SH' K' l"
using same_side_def \<open>IsL l\<close> by blast
}
moreover have "O' \<noteq> L'"
using assms(2) colH_trivial122 by force
ultimately have "same_side' SH' K' O' L'"
using same_side'_def by presburger
thus ?thesis
using th15_aux \<open>CongaH SH PO L SH' O' L'\<close> \<open>\<not> ColH SH PO K\<close>
\<open>\<not> ColH SH' O' K'\<close> assms(9) same_side_prime_not_colH
\<open>same_side' SH K PO L\<close> by blast
qed
moreover have "\<not> ColH SH PO K"
using \<open>BetH H PO SH\<close> assms(5) betH_colH between_comm colH_trans colH_trivial122 by blast
moreover have "\<not> ColH SH' O' K'"
using \<open>BetH H' O' SH'\<close> assms(6) betH_colH between_comm colH_trans colH_trivial122 by blast
moreover have "BetH SH PO H"
by (simp add: \<open>BetH H PO SH\<close> between_comm)
moreover have "BetH SH' O' H'"
by (simp add: \<open>BetH H' O' SH'\<close> between_comm)
ultimately have ?thesis
using conga_permlr th14 by blast
}
ultimately show ?thesis
using assms(7) by fastforce
qed
lemma th17:
assumes "\<not> ColH X Y Z1" and
"\<not> ColH X Y Z2" and
"ColH X I Y" and
"BetH Z1 I Z2" and
"CongH X Z1 X Z2" and
"CongH Y Z1 Y Z2"
shows "CongaH X Y Z1 X Y Z2"
proof (cases "ColH Y Z1 Z2")
case True
hence "ColH Y Z1 Z2"
by simp
show ?thesis
proof (cases "ColH X Z1 Z2")
case True
hence "ColH X Z1 Z2"
by simp
have "ColH Z1 I Z2"
by (simp add: assms(4) betH_colH)
have "Z1 \<noteq> Z2"
using assms(4) not_betH121 by blast
hence "ColH X Y Z2"
by (metis True \<open>ColH Y Z1 Z2\<close> colH_permut_312 colH_trivial122 inter_uniquenessH)
thus ?thesis
using assms(2) by auto
next
case False
hence "\<not> ColH X Z1 Z2"
by simp
have "CongaH X Z1 Z2 X Z2 Z1"
by (simp add: False assms(5) isosceles_congaH)
have "\<not> ColH Z1 Y X"
using assms(1) colH_permut_321 by blast
moreover have "\<not> ColH Z2 Y X"
using assms(2) colH_permut_321 by blast
moreover have "CongH Z1 Y Z2 Y"
using assms(2) assms(6) congH_permlr ncolH_expand by blast
moreover have "CongH Z1 X Z2 X"
using False assms(5) congH_permlr ncolH_distincts by presburger
moreover
have "BetH Z1 Y Z2"
by (metis False True assms(1) assms(6) calculation(2) colH_trivial112
colH_trivial122 congH_colH_betH)
have "CongaH X Z1 Y X Z2 Y"
proof -
have "outH Z1 X X"
by (metis False colH_trivial112 outH_trivial)
moreover have "outH Z1 Z2 Y"
by (simp add: \<open>BetH Z1 Y Z2\<close> outH_def)
moreover have "outH Z2 X X"
by (metis False colH_trivial121 outH_trivial)
moreover have "outH Z2 Z1 Y"
using \<open>BetH Z1 Y Z2\<close> between_comm outH_def by blast
ultimately show ?thesis
using \<open>CongaH X Z1 Z2 X Z2 Z1\<close> conga_out_conga by blast
qed
hence "CongaH Y Z1 X Y Z2 X"
using conga_permlr by presburger
ultimately have "CongaH Z1 Y X Z2 Y X"
using cong_5 by blast
thus ?thesis
using conga_permlr by blast
qed
next
case False
hence "\<not> ColH Y Z1 Z2"
by simp
show ?thesis
proof (cases "ColH X Z1 Z2")
case True
hence "ColH X Z1 Z2"
by simp
have "CongaH Y Z1 Z2 Y Z2 Z1"
by (simp add: False assms(6) isosceles_congaH)
have "CongaH Z1 Y X Z2 Y X"
proof -
have "\<not> ColH Z1 Y X"
using assms(1) colH_permut_321 by blast
moreover have "\<not> ColH Z2 Y X"
using assms(2) colH_permut_321 by blast
moreover have "CongH Z1 Y Z2 Y"
by (metis False assms(6) colH_trivial121 congH_permlr)
moreover have "CongH Z1 X Z2 X"
using assms(2) assms(5) congH_permlr ncolH_expand by presburger
moreover
have "BetH Z1 X Z2"
by (metis False True assms(2) assms(5) calculation(1)
colH_trivial121 colH_trivial122 congH_colH_betH)
have "CongaH Y Z1 X Y Z2 X"
proof -
have "outH Z1 Y Y"
by (metis False colH_trivial112 outH_trivial)
moreover have "outH Z1 Z2 X"
by (simp add: \<open>BetH Z1 X Z2\<close> outH_def)
moreover have "outH Z2 Y Y"
using \<open>\<not> ColH Z2 Y X\<close> ncolH_expand outH_trivial by blast
moreover have "outH Z2 Z1 X"
using \<open>BetH Z1 X Z2\<close> between_comm outH_def by blast
ultimately show ?thesis
using \<open>CongaH Y Z1 Z2 Y Z2 Z1\<close> conga_out_conga by blast
qed
ultimately show ?thesis
using cong_5 by blast
qed
thus ?thesis
using conga_permlr by blast
next
case False
hence "\<not> ColH X Z1 Z2"
by simp
have "CongaH X Z1 Z2 X Z2 Z1"
by (simp add: False assms(5) isosceles_congaH)
have "CongaH Y Z1 Z2 Y Z2 Z1"
by (simp add: \<open>\<not> ColH Y Z1 Z2\<close> assms(6) isosceles_congaH)
have "CongaH X Z1 Y X Z2 Y"
proof -
have "\<not> ColH X Z1 Z2"
by (simp add: False)
moreover have "\<not> ColH X Z2 Z1"
using calculation colH_permut_132 by blast
moreover have "\<not> ColH Y Z1 Z2"
by (simp add: \<open>\<not> ColH Y Z1 Z2\<close>)
moreover have "\<not> ColH Y Z2 Z1"
using calculation(3) colH_permut_132 by blast
moreover have "\<not> ColH X Z1 Y"
using assms(1) colH_permut_132 by blast
moreover have "\<not> ColH X Z2 Y"
using assms(2) colH_permut_132 by blast
moreover
have "cut' X Y Z1 Z2 \<and> cut' X Y Z2 Z1 \<or> same_side' X Y Z1 Z2 \<and> same_side' X Y Z2 Z1"
proof -
obtain p where "IsP p" and "IncidP X p" and "IncidP Y p" and "IncidP Z1 p"
using assms(1) plan_existence by blast
hence "IncidP Z2 p"
by (metis betH_colH assms(2) assms(3) assms(4) colH_permut_312
line_on_plane' ncolH_distincts)
thus ?thesis
by (metis False \<open>IncidP X p\<close> \<open>IncidP Y p\<close> \<open>IncidP Z1 p\<close> calculation(2)
calculation(3) calculation(4) plane_separation same_side'_def)
qed
ultimately show ?thesis
by (simp add: \<open>CongaH Y Z1 Z2 Y Z2 Z1\<close> \<open>CongaH X Z1 Z2 X Z2 Z1\<close> th15)
qed
have "CongaH Z1 Y X Z2 Y X"
proof -
have "\<not> ColH Z1 Y X"
using assms(1) colH_permut_321 by blast
moreover have "\<not> ColH Z2 Y X"
using assms(2) colH_permut_321 by blast
moreover have "CongH Z1 Y Z2 Y"
by (metis \<open>\<not> ColH Y Z1 Z2\<close> assms(6) colH_trivial121 congH_permlr)
moreover have "CongH Z1 X Z2 X"
by (metis assms(5) calculation(2) colH_trivial121 congH_permlr)
moreover have "CongaH Y Z1 X Y Z2 X"
using \<open>CongaH X Z1 Y X Z2 Y\<close> conga_permlr by blast
ultimately show ?thesis
using cong_5 by blast
qed
thus ?thesis
using conga_permlr by blast
qed
qed
lemma congaH_existence_congH:
assumes "U \<noteq> V" and
"\<not> ColH P PO X" and
"\<not> ColH A B C"
shows "\<exists> Y. (CongaH A B C X PO Y \<and> same_side' P Y PO X \<and> CongH PO Y U V)"
proof -
have "A \<noteq> B"
using assms(3) colH_trivial112 by blast
have "C \<noteq> B"
using assms(3) colH_trivial122 by blast
have "PO \<noteq> X"
using assms(2) colH_trivial122 by blast
{
fix x
assume "CongaH A B C X PO x" and
"same_side' P x PO X"
obtain Yaux where "CongaH A B C X PO Yaux" and "same_side' P Yaux PO X"
using \<open>CongaH A B C X PO x\<close> \<open>same_side' P x PO X\<close> by blast
hence "\<not> ColH Yaux PO X"
using same_side_prime_not_colH by blast
{
assume "PO = Yaux"
hence "ColH Yaux PO X"
by (simp add: colH_trivial112)
hence False
by (simp add: \<open>\<not> ColH Yaux PO X\<close>)
}
{
fix Y
assume "CongH PO Y U V" and "outH PO Yaux Y"
have "CongaH A B C X PO Y"
proof -
have "CongaH A B C X PO Yaux"
using \<open>CongaH A B C X PO Yaux\<close> by blast
moreover have "outH B A A"
using \<open>A \<noteq> B\<close> outH_trivial by auto
moreover have "outH B C C"
using \<open>C \<noteq> B\<close> outH_trivial by presburger
moreover have "outH PO X X"
using \<open>PO \<noteq> X\<close> outH_trivial by blast
moreover have "outH PO Yaux Y"
using \<open>outH PO Yaux Y\<close> by auto
ultimately show ?thesis
using conga_out_conga by blast
qed
moreover have "same_side' P Y PO X"
using ColH_def \<open>\<not> ColH Yaux PO X\<close> \<open>outH PO Yaux Y\<close>
\<open>same_side' P Yaux PO X\<close> out_same_side same_side'_def same_side_trans by fastforce
ultimately have "\<exists> Y. CongaH A B C X PO Y \<and> same_side' P Y PO X \<and> CongH PO Y U V"
using \<open>CongH PO Y U V\<close> by auto
}
hence ?thesis
using \<open>PO = Yaux \<Longrightarrow> False\<close> assms(1) out_construction by blast
}
thus ?thesis
using assms(2) assms(3) cong_4_existence by blast
qed
lemma th18_aux:
assumes "\<not> ColH A B C" and
"\<not> ColH A' B' C'" and
"CongH A B A' B'" and
"CongH A C A' C'" and
"CongH B C B' C'"
shows "CongaH B A C B' A' C'"
proof -
have "A \<noteq> B"
using assms(1) colH_trivial112 by blast
moreover
have "C' \<noteq> B'"
using assms(2) colH_trivial122 by blast
have "A' \<noteq> C'"
using assms(2) colH_trivial121 by force
{
fix B0
assume "CongaH C A B C' A' B0" and "same_side' B' B0 A' C'" and "CongH A' B0 A B"
{
fix P
assume "BetH B' C' P"
{
fix B''
assume "CongaH C A B C' A' B''" and "same_side' P B'' A' C'" and "CongH A' B'' A B"
have "\<not> ColH A' C' B0"
using \<open>same_side' B' B0 A' C'\<close> colH_permut_312 same_side_prime_not_colH by blast
have "\<not> ColH A' C' B''"
using \<open>same_side' P B'' A' C'\<close> colH_permut_312 same_side_prime_not_colH by blast
have "CongH B C B0 C'"
by (metis \<open>CongH A' B0 A B\<close> \<open>CongaH C A B C' A' B0\<close>
\<open>same_side' B' B0 A' C'\<close> assms(1) assms(4) colH_permut_213 colH_trivial112
congH_sym conga_permlr same_side_prime_not_colH th12)
have "CongH B C B'' C'"
by (metis \<open>CongH A' B'' A B\<close> \<open>CongaH C A B C' A' B''\<close> \<open>\<not> ColH A' C' B''\<close>
assms(1) assms(4) colH_permut_132 congH_sym cong_permr ncolH_distincts th12)
have "A' \<noteq> B''"
using \<open>\<not> ColH A' C' B''\<close> colH_trivial121 by blast
have "A' \<noteq> B0"
using \<open>\<not> ColH A' C' B0\<close> colH_trivial121 by fastforce
have "CongH A' B'' A' B0"
by (meson \<open>A' \<noteq> B''\<close> \<open>A' \<noteq> B0\<close> \<open>CongH A' B'' A B\<close> \<open>CongH A' B0 A B\<close>
congH_sym cong_pseudo_transitivity)
have "CongH B'' C' B0 C'"
using \<open>CongH B C B'' C'\<close> \<open>CongH B C B0 C'\<close> cong_pseudo_transitivity by blast
have "CongH B'' C' B' C'"
using \<open>CongH B C B'' C'\<close> assms(5) cong_pseudo_transitivity by blast
obtain l where "IsL l" and "IncidL A' l" and "IncidL C' l"
using \<open>A' \<noteq> C'\<close> line_existence by blast
have "cut l B' P"
by (meson ColH_def Is_line \<open>BetH B' C' P\<close> \<open>IncidL A' l\<close> \<open>IncidL C' l\<close>
\<open>same_side' P B'' A' C'\<close> assms(2) local.cut_def same_side_prime_not_colH)
have "cut l B' B''"
using \<open>IncidL A' l\<close> \<open>IncidL C' l\<close> \<open>IsL l\<close> \<open>local.cut l B' P\<close>
\<open>same_side' P B'' A' C'\<close> cut_same_side_cut same_side'_def by blast
have "\<not> IncidL B' l"
using \<open>local.cut l B' P\<close> local.cut_def by blast
moreover have "\<not> IncidL B'' l"
using \<open>local.cut l B' B''\<close> local.cut_def by blast
moreover have "\<exists> I. IncidL I l \<and> BetH B' I B''"
using \<open>local.cut l B' B''\<close> local.cut_def by auto
ultimately obtain I' where "ColH A' I' C'" and "BetH B' I' B''"
using ColH_def Is_line \<open>IncidL A' l\<close> \<open>IncidL C' l\<close> by blast
have "cut l B'' B0"
by (meson \<open>IncidL A' l\<close> \<open>IncidL C' l\<close> \<open>IsL l\<close> \<open>local.cut l B' B''\<close>
\<open>same_side' B' B0 A' C'\<close> cut_comm cut_same_side_cut same_side'_def)
then obtain I where "ColH A' I C' \<and> BetH B0 I B''"
by (meson ColH_def \<open>IncidL A' l\<close> \<open>IncidL C' l\<close> cut_comm local.cut_def)
have "CongaH C' A' B'' C' A' B0"
proof -
have "\<not> ColH C' A' B''"
using \<open>\<not> ColH A' C' B''\<close> colH_permut_213 by blast
moreover have "\<not> ColH C' A' B0"
using \<open>\<not> ColH A' C' B0\<close> colH_permut_213 by blast
moreover have "ColH C' I A'"
using \<open>ColH A' I C' \<and> BetH B0 I B''\<close> colH_permut_321 by presburger
moreover have "BetH B'' I B0"
by (simp add: \<open>ColH A' I C' \<and> BetH B0 I B''\<close> between_comm)
moreover have "CongH C' B'' C' B0"
by (metis \<open>CongH B'' C' B0 C'\<close> calculation(2) colH_trivial121 congH_permlr)
ultimately show ?thesis
using th17 \<open>CongH A' B'' A' B0\<close> by blast
qed
moreover have "outH A' B0 B'"
proof -
have "\<not> ColH B' A' C'"
using assms(2) colH_permut_213 by blast
moreover have "\<not> ColH C' A' B''"
using \<open>\<not> ColH A' C' B''\<close> colH_permut_213 by blast
moreover have "CongaH C' A' B'' C' A' B'"
by (metis (full_types) \<open>A' \<noteq> B''\<close> \<open>BetH B' I' B''\<close> \<open>ColH A' I' C'\<close>
\<open>CongH A' B'' A B\<close> \<open>CongH B'' C' B' C'\<close> assms(3) between_comm calculation(1)
calculation(2) colH_permut_321 congH_permlr congH_sym
cong_pseudo_transitivity th17)
moreover have "same_side' B' B' A' C'"
using calculation(1) colH_permut_312 same_side_prime_refl by blast
ultimately show ?thesis
using \<open>CongaH C' A' B'' C' A' B0\<close> \<open>same_side' B' B0 A' C'\<close>
cong_4_uniqueness by blast
qed
ultimately have "CongaH B A C B' A' C'"
by (metis \<open>A \<noteq> B\<close> \<open>A' \<noteq> B0\<close> \<open>CongH A' B0 A B\<close> \<open>CongaH C A B C' A' B0\<close>
\<open>outH A' B0 B'\<close> assms(3) betH_not_congH congH_perms cong_pseudo_transitivity conga_permlr outH_def)
}
moreover have "\<not> ColH P A' C'"
by (metis betH_expand \<open>BetH B' C' P\<close> assms(2) colH_permut_312
colH_trans colH_trivial121)
moreover have "\<not> ColH C A B"
using assms(1) colH_permut_231 by blast
ultimately have "CongaH B A C B' A' C'"
using \<open>A \<noteq> B\<close> congaH_existence_congH by force
}
hence "CongaH B A C B' A' C'"
using \<open>C' \<noteq> B'\<close>between_out by presburger
}
moreover have "\<not> ColH B' A' C'"
using assms(2) colH_permut_213 by blast
moreover have "\<not> ColH C A B"
using assms(1) colH_permut_231 by blast
ultimately show ?thesis
using congaH_existence_congH by blast
qed
lemma th19:
assumes "\<not> ColH PO A B" and
"\<not> ColH O1 A1 B1" and
"\<not> ColH O2 A2 B2" and
"CongaH A PO B A1 O1 B1" and
"CongaH A PO B A2 O2 B2"
shows "CongaH A1 O1 B1 A2 O2 B2"
proof -
have "PO \<noteq> A"
using assms(1) colH_trivial112 by blast
have "PO \<noteq> B"
using assms(1) colH_trivial121 by blast
have "O1 \<noteq> A1"
using assms(2) colH_trivial112 by blast
have "O1 \<noteq> B1"
using assms(2) colH_trivial121 by blast
have "O2 \<noteq> A2"
using assms(3) colH_trivial112 by force
have "O2 \<noteq> B2"
using assms(3) colH_trivial121 by blast
{
fix A1'
assume "CongH O1 A1' PO A" and "outH O1 A1 A1'"
{
fix A2'
assume "CongH O2 A2' PO A" and "outH O2 A2 A2'"
{
fix B1'
assume "CongH O1 B1' PO B" and "outH O1 B1 B1'"
{
fix B2'
assume "CongH O2 B2' PO B" and "outH O2 B2 B2'"
have "O1 \<noteq> A1'"
using \<open>outH O1 A1 A1'\<close> outH_expand by blast
have "O2 \<noteq> A2'"
using \<open>outH O2 A2 A2'\<close> outH_expand by auto
have "O1 \<noteq> B1'"
using \<open>outH O1 B1 B1'\<close> out_distinct by auto
have "O2 \<noteq> B2'"
using \<open>outH O2 B2 B2'\<close> outH_expand by blast
{
assume "ColH O1 A1' B1'"
have "ColH O1 A1 A1'"
by (simp add: \<open>outH O1 A1 A1'\<close> outH_expand)
have "ColH O1 B1 B1'"
by (simp add: \<open>outH O1 B1 B1'\<close> outH_expand)
hence "ColH O1 A1 B1"
by (metis colH_trivial121 \<open>ColH O1 A1 A1'\<close> \<open>ColH O1 A1' B1'\<close>
\<open>ColH O1 B1 B1'\<close> \<open>O1 \<noteq> A1'\<close> \<open>O1 \<noteq> B1'\<close> colH_permut_231 inter_uniquenessH)
hence False
using assms(2) by blast
}
have "ColH O2 A2 A2'"
using \<open>outH O2 A2 A2'\<close> outH_expand by blast
have "ColH O2 B2 B2'"
by (simp add: \<open>outH O2 B2 B2'\<close> outH_expand)
hence "\<not> ColH O2 A2' B2'"
by (metis \<open>ColH O2 A2 A2'\<close> \<open>O2 \<noteq> A2'\<close> \<open>O2 \<noteq> B2'\<close> assms(3)
colH_permut_312 colH_trans colH_trivial122)
have "CongH A B A1' B1'"
proof -
have "CongH PO A O1 A1'"
using \<open>CongH O1 A1' PO A\<close> \<open>O1 \<noteq> A1'\<close> \<open>PO \<noteq> A\<close> congH_perms by blast
moreover have "CongH PO B O1 B1'"
by (simp add: \<open>CongH O1 B1' PO B\<close> \<open>O1 \<noteq> B1'\<close> congH_sym)
moreover have "CongaH A PO B A1' O1 B1'"
using \<open>PO \<noteq> A\<close> \<open>PO \<noteq> B\<close> \<open>outH O1 A1 A1'\<close> \<open>outH O1 B1 B1'\<close>
assms(4) conga_out_conga outH_trivial by blast
ultimately show ?thesis
using assms(1) th12 \<open>ColH O1 A1' B1' \<Longrightarrow> False\<close> by blast
qed
have "CongH A B A2' B2'"
proof -
have "CongH PO A O2 A2'"
using \<open>CongH O2 A2' PO A\<close> \<open>O2 \<noteq> A2'\<close> congH_sym by auto
moreover have "CongH PO B O2 B2'"
by (simp add: \<open>CongH O2 B2' PO B\<close> \<open>O2 \<noteq> B2'\<close> congH_sym)
moreover have "CongaH A PO B A2' O2 B2'"
using \<open>PO \<noteq> A\<close> \<open>PO \<noteq> B\<close> \<open>outH O2 A2 A2'\<close> \<open>outH O2 B2 B2'\<close>
assms(5) conga_out_conga outH_trivial by blast
ultimately show ?thesis
using assms(1) th12 \<open>\<not> ColH O2 A2' B2'\<close> by blast
qed
have "CongH A1' B1' A2' B2'"
using \<open>CongH A B A1' B1'\<close> \<open>CongH A B A2' B2'\<close> cong_pseudo_transitivity by blast
have "CongaH A1' O1 B1' A2' O2 B2'"
proof -
have "CongH O1 A1' O2 A2'"
by (meson \<open>CongH O1 A1' PO A\<close> \<open>CongH O2 A2' PO A\<close> \<open>O1 \<noteq> A1'\<close>
\<open>O2 \<noteq> A2'\<close> congH_sym cong_pseudo_transitivity)
moreover have "CongH O1 B1' O2 B2'"
by (meson \<open>CongH O1 B1' PO B\<close> \<open>CongH O2 B2' PO B\<close> \<open>O1 \<noteq> B1'\<close>
\<open>O2 \<noteq> B2'\<close> congH_sym cong_pseudo_transitivity)
ultimately show ?thesis
using th18_aux \<open>CongH A1' B1' A2' B2'\<close> \<open>ColH O1 A1' B1' \<Longrightarrow> False\<close>
\<open>\<not> ColH O2 A2' B2'\<close> by blast
qed
hence "CongaH A1 O1 B1 A2 O2 B2"
using \<open>O1 \<noteq> A1'\<close> \<open>O1 \<noteq> B1'\<close> \<open>O2 \<noteq> A2'\<close> \<open>O2 \<noteq> B2'\<close> \<open>outH O1 A1 A1'\<close>
\<open>outH O1 B1 B1'\<close> \<open>outH O2 A2 A2'\<close> \<open>outH O2 B2 B2'\<close> conga_out_conga outH_sym by blast
}
hence "CongaH A1 O1 B1 A2 O2 B2"
using \<open>O2 \<noteq> B2\<close> \<open>PO \<noteq> B\<close> out_construction by blast
}
hence "CongaH A1 O1 B1 A2 O2 B2"
using \<open>O1 \<noteq> B1\<close> \<open>PO \<noteq> B\<close> out_construction by blast
}
hence "CongaH A1 O1 B1 A2 O2 B2"
using \<open>O2 \<noteq> A2\<close> \<open>PO \<noteq> A\<close> out_construction by blast
}
thus ?thesis
using \<open>O1 \<noteq> A1\<close> \<open>PO \<noteq> A\<close> out_construction by force
qed
lemma congaH_sym:
assumes "\<not> ColH A B C" and
"\<not> ColH D E F" and
"CongaH A B C D E F"
shows "CongaH D E F A B C"
by (meson assms(1) assms(2) assms(3) colH_permut_213 conga_refl th19)
lemma congaH_commr:
assumes "\<not> ColH A B C" and
"\<not> ColH D E F" and
"CongaH A B C D E F"
shows "CongaH A B C F E D"
by (metis assms(1) assms(2) assms(3) colH_permut_213 colH_permut_312 conga_comm th19)
lemma cong_preserves_col:
assumes "BetH A B C" and
"CongH A B A' B'" and
"CongH B C B' C'" and
"CongH A C A' C'"
shows "ColH A' B' C'"
proof -
have "ColH A B C"
by (simp add: assms(1) betH_colH)
have "A \<noteq> B"
using assms(1) betH_distincts by blast
have "C \<noteq> B"
using assms(1) betH_distincts by blast
{
assume "\<not> ColH A' B' C'"
{
assume "A' = C'"
hence False
using \<open>\<not> ColH A' B' C'\<close> colH_trivial121 by blast
}
then obtain B'' where "CongH A' B'' A B" and "outH A' C' B''"
using \<open>A \<noteq> B\<close> out_construction by blast
hence "ColH A' C' B''"
using outH_expand by blast
have "A' \<noteq> B''"
using \<open>outH A' C' B''\<close> out_distinct by blast
have "outH A' B'' C'"
by (simp add: \<open>A' \<noteq> B''\<close> \<open>outH A' C' B''\<close> outH_sym)
hence "BetH A' B'' C'"
using \<open>A' \<noteq> B''\<close> \<open>CongH A' B'' A B\<close> assms(1) assms(4)
betH_congH3_outH_betH congH_sym by blast
have "A' \<noteq> B'"
using \<open>\<not> ColH A' B' C'\<close> colH_trivial112 by auto
obtain C'' where "BetH A' B' C''" and "CongH B' C'' B C"
using \<open>A' \<noteq> B'\<close> \<open>C \<noteq> B\<close> segment_constructionH by metis
hence "ColH A' B' C''"
using betH_colH by force
have "B' \<noteq> C''"
using \<open>BetH A' B' C''\<close> betH_distincts by blast
have "A' \<noteq> C''"
using \<open>BetH A' B' C''\<close> not_betH121 by blast
have "CongH B C B'' C'"
using \<open>A' \<noteq> B''\<close> \<open>BetH A' B'' C'\<close> \<open>CongH A' B'' A B\<close> assms(1) assms(4)
congH_sym soustraction_betH by presburger
have "CongH A' C'' A' C'"
by (meson \<open>B' \<noteq> C''\<close> \<open>BetH A' B' C''\<close> \<open>ColH A B C\<close> \<open>ColH A' B' C''\<close>
\<open>CongH B' C'' B C\<close> addition assms(1) assms(2) assms(4) bet_disjoint
congH_sym cong_pseudo_transitivity)
have "\<not> ColH A' C'' C'"
using \<open>A' \<noteq> C''\<close> \<open>ColH A' B' C''\<close> \<open>\<not> ColH A' B' C'\<close> colH_permut_132
colH_trans colH_trivial121 by blast
have "CongaH A' C'' C' A' C' C''"
by (simp add: \<open>CongH A' C'' A' C'\<close> \<open>\<not> ColH A' C'' C'\<close> isosceles_congaH)
have "\<not> ColH B' C'' C'"
by (meson \<open>B' \<noteq> C''\<close> \<open>ColH A' B' C''\<close> \<open>\<not> ColH A' B' C'\<close> colH_permut_231
colH_trans colH_trivial121)
have "CongaH B' C'' C' B' C' C''"
by (meson \<open>B' \<noteq> C''\<close> \<open>CongH B' C'' B C\<close> \<open>\<not> ColH B' C'' C'\<close> assms(3)
congH_sym cong_pseudo_transitivity isosceles_congaH)
have "CongaH A' C'' C' B' C'' C'"
using \<open>A' \<noteq> C''\<close> \<open>BetH A' B' C''\<close> \<open>ColH A' B' C''\<close> \<open>\<not> ColH A' B' C'\<close>
\<open>\<not> ColH A' C'' C'\<close> between_comm conga_out_conga conga_refl outH_def by blast
have "CongaH A' C' C'' B' C' C''"
by (metis th19 \<open>CongaH A' C'' C' A' C' C''\<close> \<open>CongaH A' C'' C' B' C'' C'\<close>
\<open>CongaH B' C'' C' B' C' C''\<close> \<open>\<not> ColH A' C'' C'\<close> \<open>\<not> ColH B' C'' C'\<close>
colH_permut_213 colH_permut_231)
have "outH C' A' B'"
proof -
have "\<not> ColH B' C' C''"
using \<open>\<not> ColH B' C'' C'\<close> colH_permut_132 by blast
moreover have "\<not> ColH A' C' C''"
using \<open>\<not> ColH A' C'' C'\<close> colH_permut_132 by blast
moreover have "CongaH A' C' C'' C'' C' A'"
by (simp add: calculation(2) conga_comm)
moreover have "CongaH A' C' C'' C'' C' B'"
using \<open>CongaH A' C' C'' B' C' C''\<close> calculation(1) calculation(2)
congaH_commr by blast
moreover have "same_side' B' A' C' C''"
by (metis ColH_def \<open>BetH A' B' C''\<close> between_comm calculation(1)
colH_trivial122 outH_def out_same_side')
moreover have "same_side' B' B' C' C''"
using calculation(1) colH_permut_312 same_side_prime_refl by blast
ultimately show ?thesis
using cong_4_uniqueness by blast
qed
hence False
using \<open>\<not> ColH A' B' C'\<close> colH_permut_231 outH_col by blast
}
thus ?thesis by blast
qed
lemma cong_preserves_col_stronger:
assumes "A \<noteq> B" and
"A \<noteq> C" and
"B \<noteq> C" and
"ColH A B C" and
"CongH A B A' B'" and
"CongH B C B' C'" and
"CongH A C A' C'"
shows "ColH A' B' C'"
by (metis ncolH_expand assms(1) assms(2) assms(3) assms(4) assms(5)
assms(6) assms(7) between_one colH_permut_213 colH_permut_312
congH_permlr cong_preserves_col)
lemma betH_congH2__False:
assumes "BetH A B C" and
"BetH A' C' B'" and
"CongH A B A' B'" and
"CongH A C A' C'"
shows "False"
proof -
have "ColH A B C"
using assms(1) betH_colH by auto
have "ColH A' C' B'"
by (simp add: assms(2) betH_colH)
have "A \<noteq> B"
using assms(1) betH_distincts by blast
have "C \<noteq> B"
using assms(1) betH_distincts by blast
have "A' \<noteq> B'"
using assms(2) not_betH121 by force
obtain C0 where "BetH A' B' C0" and "CongH B' C0 B C"
using \<open>A' \<noteq> B'\<close> \<open>C \<noteq> B\<close> segment_constructionH by metis
hence "CongH A' C0 A C"
using \<open>A \<noteq> B\<close> addition_betH assms(1) assms(3) congH_sym by blast
have "BetH A' C' C0"
using \<open>BetH A' B' C0\<close> assms(2) betH_trans0 by blast
moreover have "CongH A' C' A' C0"
by (metis \<open>BetH A' B' C0\<close> \<open>CongH A' C0 A C\<close> assms(4) betH_distincts
congH_sym cong_pseudo_transitivity)
ultimately show ?thesis
by (simp add: betH_not_congH)
qed
lemma cong_preserves_bet:
assumes "A' \<noteq> B'" and
"B' \<noteq> C'" and
"A'\<noteq>C'" and
"BetH A B C" and
"CongH A B A' B'" and
"CongH B C B' C'" and
"CongH A C A' C'"
shows "BetH A' B' C'"
by (meson assms(1) assms(2) assms(3) assms(4) assms(5) assms(6)
assms(7) bet_cong3_bet cong_preserves_col)
lemma axiom_five_segmentsH:
assumes "A \<noteq> D" and
"A' \<noteq> D'" and
"B \<noteq> D" and
"B' \<noteq> D'" and
"C \<noteq> D" and
"C' \<noteq> D'" and
"CongH A B A' B'" and
"CongH B C B' C'" and
"CongH A D A' D'" and
"CongH B D B' D'" and
"BetH A B C" and
"BetH A' B' C'" and
"A' \<noteq> D'"
shows "CongH C D C' D'"
proof -
have "ColH A B C"
by (simp add: assms(11) betH_colH)
have "ColH A' B' C'"
by (simp add: assms(12) betH_colH)
have "A \<noteq> B"
using assms(11) betH_distincts by blast
have "A \<noteq> C"
using assms(11) not_betH121 by blast
have "A' \<noteq> B'"
using assms(12) betH_distincts by auto
have "A' \<noteq> C'"
using assms(12) not_betH121 by blast
have "C' \<noteq> B'"
using assms(12) betH_distincts by blast
have "CongH A C A' C'"
using addition_betH assms(11) assms(12) assms(7) assms(8) by blast
{
assume "ColH A B D"
hence "BetH A B D \<or> BetH B D A \<or> BetH B A D"
by (simp add: \<open>A \<noteq> B\<close> assms(1) assms(3) between_one)
moreover
{
assume "BetH A B D"
hence "BetH A' B' D'"
using \<open>A' \<noteq> B'\<close> assms(10) assms(2) assms(4) assms(7) assms(9)
cong_preserves_bet by blast
hence "BetH A' D' C' \<or> BetH A' C' D'"
using assms(12) assms(6) out2_out1 by auto
moreover
{
assume "BetH A' D' C'"
hence "BetH A D C"
by (meson \<open>BetH A B D\<close> \<open>CongH A C A' C'\<close> assms(11) assms(5)
assms(9) betH_congH2__False out2_out1)
hence ?thesis
using \<open>BetH A' D' C'\<close> \<open>CongH A C A' C'\<close> assms(9) betH_colH
congH_permlr soustraction_betH by presburger
}
moreover
{
assume "BetH A' C' D'"
hence "BetH A C D"
by (meson \<open>BetH A B D\<close> \<open>CongH A C A' C'\<close> assms(11) assms(5)
assms(9) betH_congH2__False out2_out1)
hence ?thesis
using \<open>BetH A' C' D'\<close> \<open>CongH A C A' C'\<close> assms(9)
soustraction_betH by blast
}
ultimately have ?thesis
by blast
}
moreover
{
assume "BetH B D A"
hence "BetH B' D' A'"
by (metis \<open>A' \<noteq> B'\<close> assms(10) assms(2) assms(4) assms(7)
assms(9) congH_permlr cong_preserves_bet)
hence "BetH C D A"
using betH_trans0 \<open>BetH B D A\<close> assms(11) between_comm by blast
hence "BetH C' D' A'"
using betH_trans0 \<open>BetH B' D' A'\<close> assms(12) between_comm by blast
have "BetH A D C"
by (simp add: \<open>BetH C D A\<close> between_comm)
moreover have "BetH A' D' C'"
by (simp add: \<open>BetH C' D' A'\<close> between_comm)
ultimately have ?thesis
using \<open>CongH A C A' C'\<close> assms(9) betH_expand congH_permlr
soustraction_betH by presburger
}
moreover
{
assume "BetH B A D"
hence "BetH B' A' D'"
by (metis \<open>A' \<noteq> B'\<close> assms(10) assms(2) assms(4) assms(7) assms(9)
congH_permlr cong_preserves_bet)
have "BetH C' B' D'"
using \<open>BetH B' A' D'\<close> assms(12) betH_trans between_comm by blast
have "BetH C B D"
using \<open>BetH B A D\<close> assms(11) betH_trans between_comm by blast
moreover have "CongH C B C' B'"
using \<open>C' \<noteq> B'\<close> assms(8) congH_permlr by presburger
ultimately have ?thesis
using \<open>BetH C' B' D'\<close> assms(10) addition_betH by blast
}
ultimately have ?thesis
by blast
}
moreover
{
assume "\<not> ColH A B D"
hence "\<not> ColH A' B' D'"
using cong_preserves_col_stronger \<open>A \<noteq> B\<close> \<open>A' \<noteq> B'\<close> assms(1) assms(10)
assms(2) assms(3) assms(4) assms(7) assms(9) congH_sym by blast
hence "CongaH B A D B' A' D'"
using \<open>\<not> ColH A B D\<close> assms(10) assms(7) assms(9) th18_aux by blast
have "\<not> ColH A C D"
using \<open>A \<noteq> C\<close> \<open>ColH A B C\<close> \<open>\<not> ColH A B D\<close> colH_permut_132 colH_trans
colH_trivial121 by blast
moreover have "\<not> ColH A' C' D'"
using \<open>A' \<noteq> C'\<close> \<open>ColH A' B' C'\<close> \<open>\<not> ColH A' B' D'\<close> colH_permut_132
colH_trans colH_trivial121 by blast
moreover have "CongaH C A D C' A' D'"
using \<open>CongaH B A D B' A' D'\<close> assms(1) assms(11) assms(12) assms(2)
conga_out_conga outH_def by blast
ultimately have ?thesis
using \<open>CongH A C A' C'\<close> assms(9) th12 by blast
}
ultimately show ?thesis
by blast
qed
lemma five_segment:
assumes "Cong A B A' B'" and
"Cong B C B' C'" and
"Cong A D A' D'" and
"Cong B D B' D'" and
"Bet A B C" and
"Bet A' B' C'" and
"A \<noteq> B"
shows "Cong C D C' D'"
proof -
{
assume "BetH A B C"
{
assume "BetH A' B' C'"
have "ColH A B C"
using \<open>BetH A B C\<close> betH_colH by blast
have "ColH A' B' C'"
by (simp add: assms(6) bet_colH)
have "C \<noteq> B"
using \<open>BetH A B C\<close> betH_distincts by blast
have "A \<noteq> C"
using \<open>BetH A B C\<close> betH_distincts by blast
have "A' \<noteq> B'"
using \<open>BetH A' B' C'\<close> betH_distincts by blast
have "C' \<noteq> B'"
using \<open>BetH A' B' C'\<close> betH_distincts by blast
have "A' \<noteq> C'"
using \<open>BetH A' B' C'\<close> betH_distincts by blast
have "CongH A B A' B'"
using Cong_def \<open>A' \<noteq> B'\<close> assms(1) by presburger
have "CongH B C B' C'"
using Cong_def \<open>C \<noteq> B\<close> assms(2) by blast
have "CongH A D A' D' \<and> A \<noteq> D \<and> A' \<noteq> D' \<or> (A = D \<and> A' = D')"
using Cong_def assms(3) by force
moreover
have "CongH B D B' D' \<and> B \<noteq> D \<and> B'\<noteq> D' \<or> (B = D \<and> B' = D')"
using Cong_def assms(4) by presburger
{
assume "CongH A D A' D' \<and> A \<noteq> D \<and> A' \<noteq> D'"
hence "CongH A D A' D'"
by blast
have "A \<noteq> D"
by (simp add: \<open>CongH A D A' D' \<and> A \<noteq> D \<and> A' \<noteq> D'\<close>)
have "A' \<noteq> D'"
by (simp add: \<open>CongH A D A' D' \<and> A \<noteq> D \<and> A' \<noteq> D'\<close>)
{
assume "CongH B D B' D' \<and> B \<noteq> D \<and> B'\<noteq> D'"
hence "CongH B D B' D'"
by blast
have "B \<noteq> D"
by (simp add: \<open>CongH B D B' D' \<and> B \<noteq> D \<and> B' \<noteq> D'\<close>)
have "B'\<noteq> D'"
by (simp add: \<open>CongH B D B' D' \<and> B \<noteq> D \<and> B' \<noteq> D'\<close>)
{
assume "C = D"
have "CongH B' C' B' D'"
using \<open>C = D\<close> \<open>CongH B C B' C'\<close> \<open>CongH B D B' D' \<and> B \<noteq> D \<and> B' \<noteq> D'\<close>
cong_pseudo_transitivity by blast
hence "C' = D'"
using \<open>A' \<noteq> B'\<close> \<open>A' \<noteq> D'\<close> \<open>B' \<noteq> D'\<close> \<open>BetH A B C\<close> \<open>BetH A' B' C'\<close>
\<open>C = D\<close> \<open>CongH A B A' B'\<close> \<open>CongH A D A' D'\<close> \<open>CongH B D B' D'\<close>
cong_preserves_bet construction_uniqueness by blast
hence ?thesis
by (simp add: Cong_def \<open>C = D\<close>)
}
moreover
{
assume "C \<noteq> D"
{
assume "C' = D'"
hence "CongH B D B C"
by (metis \<open>B \<noteq> D\<close> \<open>C \<noteq> B\<close> \<open>CongH B C B' C'\<close> \<open>CongH B D B' D'\<close>
congH_sym cong_pseudo_transitivity)
have "BetH A B D"
using \<open>A \<noteq> D\<close> \<open>B \<noteq> D\<close> \<open>BetH A' B' C'\<close> \<open>C' = D'\<close> \<open>CongH A B A' B'\<close>
\<open>CongH A D A' D'\<close> \<open>CongH B D B' D'\<close> assms(7) congH_sym cong_preserves_bet by presburger
moreover have "CongH B C B D"
using \<open>B \<noteq> D\<close> \<open>CongH B D B C\<close> congH_sym by auto
ultimately have "C = D"
using construction_uniqueness \<open>BetH A B C\<close> by presburger
hence False
using \<open>C \<noteq> D\<close> by blast
}
hence "C' \<noteq> D'"
by blast
hence ?thesis
by (meson Cong_def \<open>BetH A B C\<close> \<open>BetH A' B' C'\<close> \<open>CongH A B A' B'\<close>
\<open>CongH A D A' D' \<and> A \<noteq> D \<and> A' \<noteq> D'\<close> \<open>CongH B C B' C'\<close>
\<open>CongH B D B' D' \<and> B \<noteq> D \<and> B' \<noteq> D'\<close> axiom_five_segmentsH calculation)
}
ultimately have ?thesis
by blast
}
moreover
{
assume "B = D \<and> B' = D'"
hence ?thesis
using Cong_def \<open>C \<noteq> B\<close> \<open>C' \<noteq> B'\<close> \<open>CongH B C B' C'\<close> congH_permlr by presburger
}
ultimately have ?thesis
using \<open>CongH B D B' D' \<and> B \<noteq> D \<and> B' \<noteq> D' \<or> B = D \<and> B' = D'\<close> by fastforce
}
moreover
{
assume "A = D \<and> A' = D'"
hence ?thesis
using Cong_def \<open>A \<noteq> C\<close> \<open>A' \<noteq> C'\<close> \<open>BetH A B C\<close> \<open>BetH A' B' C'\<close>
\<open>CongH A B A' B'\<close> \<open>CongH B C B' C'\<close> addition_betH congH_permlr by presburger
}
ultimately have ?thesis
by blast
}
moreover
{
assume "A' = B'"
hence ?thesis
using assms(1) assms(7) cong_identity by blast
}
moreover
{
assume "B' = C'"
hence ?thesis
using Cong_def \<open>BetH A B C\<close> assms(2) betH_to_bet by auto
}
ultimately have ?thesis
using Bet_def assms(6) by blast
}
moreover
{
assume "A = B"
hence ?thesis
using assms(7) by blast
}
moreover
{
assume "B = C"
hence ?thesis
using Cong_def assms(2) assms(4) by presburger
}
ultimately show ?thesis
using Bet_def assms(5) by blast
qed
lemma bet_comm:
assumes "Bet A B C"
shows "Bet C B A"
using Bet_def assms between_comm by presburger
lemma bet_trans:
assumes "Bet A B D" and
"Bet B C D"
shows "Bet A B C"
proof -
{
assume "BetH A B D"
hence ?thesis
using Bet_def assms(2) betH_trans0 between_comm by blast
}
moreover
{
assume "A = B \<or> B = D"
hence ?thesis
using Bet_def assms(2) bet_identity by blast
}
ultimately show ?thesis
using Bet_def assms(1) by blast
qed
lemma cong_transitivity:
assumes "Cong A B E F" and
"Cong C D E F"
shows "Cong A B C D"
using assms(1) assms(2) cong_sym cong_trans by blast
lemma cong_permT:
shows "Cong A B B A"
by (metis Cong_def congH_perm)
lemma pasch_general_case:
assumes "Bet A P C" and
"Bet B Q C" and
"A \<noteq> P" and
"P \<noteq> C" and
"B \<noteq> Q" and
"Q \<noteq> C" and
"\<not> (Bet A B C \<or> Bet B C A \<or> Bet C A B)"
shows "\<exists> x. Bet P x B \<and> Bet Q x A"
proof (cases "A = B")
case True
thus ?thesis
using Bet_def by auto
next
case False
{
assume "B = C"
hence ?thesis
using Bet_def assms(7) by presburger
}
moreover
{
assume "B \<noteq> C"
{
assume "A = C"
hence ?thesis
using Bet_def assms(7) by blast
}
moreover
{
assume "A \<noteq> C"
have "ColH A P C"
by (simp add: assms(1) bet_colH)
{
assume "ColH B C P"
hence "ColH A B C"
by (metis colH_permut_231 colH_trivial121 \<open>ColH A P C\<close> assms(4) inter_uniquenessH)
hence False
by (metis Bet_def assms(7) between_comm between_one)
}
hence "\<not> ColH B C P"
by blast
hence ?thesis
using assms(1) assms(2) inner_pasch_aux by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
lemma lower_dim_l:
shows "\<not> (Bet PP PQ PR \<or> Bet PQ PR PP \<or> Bet PR PP PQ)"
using bet_colH colH_permut_231 lower_dim_2 by blast
lemma ColH_bets:
assumes "ColH A B C"
shows "Bet A B C \<or> Bet B C A \<or> Bet C A B"
by (metis Bet_def assms bet_comm between_one)
interpretation Interp_Gupta_of_Tarski_neutral_dimensionless:
Gupta_neutral_dimensionless
where BetG = Bet and
CongG = Cong and
GPA = PP and
GPB = PQ and
GPC = PR
proof
show "\<forall>a b. Cong a b b a"
by (simp add: cong_permT)
show "\<forall>a b p q r s. Cong a b p q \<and> Cong a b r s \<longrightarrow> Cong p q r s"
using cong_inner_transitivity by blast
show "\<forall>a b c. Cong a b c c \<longrightarrow> a = b"
by (simp add: cong_identity)
show "\<forall>a b c q. \<exists>x. Bet q a x \<and> Cong a x b c"
by (simp add: segment_construction)
show "\<forall>a b c d a' b' c' d'. a \<noteq> b \<and> Bet a b c \<and> Bet a' b' c' \<and>
Cong a b a' b' \<and> Cong b c b' c' \<and> Cong a d a' d' \<and> Cong b d b' d' \<longrightarrow>
Cong c d c' d'"
using five_segment by blast
show "\<forall>a b c. Bet a b c \<longrightarrow> Bet c b a"
using bet_comm by blast
show "\<forall>a b c d. Bet a b d \<and> Bet b c d \<longrightarrow> Bet a b c"
using bet_trans by blast
show "\<forall>a b c p q. Bet a p c \<and> Bet b q c \<and> a \<noteq> p \<and> c \<noteq> p \<and> b \<noteq> q \<and>
c \<noteq> q \<and> \<not> (Bet a b c \<or> Bet b c a \<or> Bet c a b) \<longrightarrow>
(\<exists>x. Bet p x b \<and> Bet q x a)"
using pasch_general_case by auto
show "\<not> (Bet PP PQ PR \<or> Bet PQ PR PP \<or> Bet PR PP PQ)"
using lower_dim_l by blast
qed
interpretation H_to_T : Tarski_neutral_dimensionless
where Bet = Bet and
Cong = Cong and
TPA = PP and
TPB = PQ and
TPC = PR
proof
show "\<forall>a b. Cong a b b a"
by (simp add:
Interp_Gupta_of_Tarski_neutral_dimensionless.cong_pseudo_reflexivityG)
show "\<forall>a b p q r s. Cong a b p q \<and> Cong a b r s \<longrightarrow> Cong p q r s"
using cong_inner_transitivity by blast
show "\<forall>a b c. Cong a b c c \<longrightarrow> a = b"
by (simp add:
Interp_Gupta_of_Tarski_neutral_dimensionless.cong_identityG)
show "\<forall>a b c q. \<exists>x. Bet q a x \<and> Cong a x b c"
by (simp add:
Interp_Gupta_of_Tarski_neutral_dimensionless.segment_constructionG)
show "\<forall>a b c d a' b' c' d'. a \<noteq> b \<and> Bet a b c \<and> Bet a' b' c' \<and>
Cong a b a' b' \<and> Cong b c b' c' \<and> Cong a d a' d' \<and> Cong b d b' d' \<longrightarrow>
Cong c d c' d'"
using Interp_Gupta_of_Tarski_neutral_dimensionless.five_segmentG by blast
show "\<forall>a b. Bet a b a \<longrightarrow> a = b"
by (simp add: bet_identity)
show "\<forall>a b c p q. Bet a p c \<and> Bet b q c \<longrightarrow> (\<exists>x. Bet p x b \<and> Bet q x a)"
using Interp_Gupta_of_Tarski_neutral_dimensionless.inner_paschT by blast
show "\<not> Bet PP PQ PR \<and> \<not> Bet PQ PR PP \<and> \<not> Bet PR PP PQ"
using lower_dim_l by blast
qed
lemma MidH__Mid:
assumes "M Midpoint A B"
shows "H_to_T.Midpoint M A B"
proof -
have "Bet A M B"
using Midpoint_def assms by blast
moreover
have "Cong A M M B"
using Midpoint_def assms by blast
ultimately show ?thesis
using H_to_T.Midpoint_def by blast
qed
lemma Mid__MidH:
assumes "H_to_T.Midpoint M A B"
shows "M Midpoint A B"
proof -
have "Bet A M B"
using H_to_T.Midpoint_def assms by blast
moreover
have "Cong A M M B"
using H_to_T.Midpoint_def assms by blast
ultimately show ?thesis
by (simp add: Midpoint_def)
qed
lemma col_colh_1:
assumes "H_to_T.Col A B C"
shows "ColH A B C"
proof -
have "Bet A B C \<or> Bet B C A \<or> Bet C A B"
using assms H_to_T.Col_def by blast
thus ?thesis
using bet_colH colH_permut_312 by blast
qed
lemma col_colh_2:
assumes "ColH A B C"
shows "H_to_T.Col A B C"
proof -
have "Bet A B C \<or> Bet B C A \<or> Bet C A B"
by (simp add: ColH_bets assms)
thus ?thesis
using H_to_T.Col_def by presburger
qed
lemma col_colh:
shows "H_to_T.Col A B C \<longleftrightarrow> ColH A B C"
using col_colh_1 col_colh_2 by blast
lemma line_col:
assumes "IsL l" and (**AJOUT**)
"IncidL A l" and
"IncidL B l" and
"IncidL C l"
shows "H_to_T.Col A B C"
proof -
have "ColH A B C"
using ColH_def assms(1) assms(2) assms(3) assms(4) by blast
thus ?thesis
by (simp add: col_colh_2)
qed
lemma bet__beth:
assumes "A \<noteq> B" and
"B \<noteq> C" and
"Bet A B C"
shows "BetH A B C"
using Bet_def assms(1) assms(2) assms(3) by blast
lemma coplanar_plane0:
assumes "ColH A B X" and
"ColH C D X"
shows "\<exists> p. IncidP A p \<and> IncidP B p \<and> IncidP C p \<and> IncidP D p"
proof -
obtain l where "IsL l" and "IncidL A l" and "IncidL B l" and "IncidL X l"
using ColH_def assms(1) by blast
obtain m where "IsL m" and "IncidL C m" and "IncidL D m" and "IncidL X m"
using ColH_def assms(2) by blast
obtain Y where "X \<noteq> Y" and "IncidL Y l"
using \<open>IncidL X l\<close> other_point_on_line by blast
{
assume "EqL m l"
obtain Z where "\<not> ColH X Y Z"
using \<open>X \<noteq> Y\<close> ncolH_exists by blast
obtain p where "IsP p" and "IncidP X p" and "IncidP Y p" and "IncidP Z p"
using \<open>\<not> ColH X Y Z\<close> plan_existence by blast
hence "IncidLP l p"
using \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> \<open>X \<noteq> Y\<close> line_on_plane by blast
hence ?thesis
using IncidLP_def IncidL_morphism \<open>EqL m l\<close> \<open>IncidL A l\<close> \<open>IncidL B l\<close>
\<open>IncidL C m\<close> \<open>IncidL D m\<close> \<open>IsL m\<close> by blast
}
moreover
{
assume "\<not> EqL m l"
obtain Z where "X \<noteq> Z" and "IncidL Z m"
using \<open>IncidL X m\<close> other_point_on_line by blast
have "\<not> ColH X Y Z"
using IncidL_not_IncidL__not_colH \<open>IncidL X l\<close> \<open>IncidL X m\<close> \<open>IncidL Y l\<close>
\<open>IncidL Z m\<close> \<open>IsL l\<close> \<open>IsL m\<close> \<open>X \<noteq> Y\<close> \<open>X \<noteq> Z\<close> \<open>\<not> EqL m l\<close> line_uniqueness by blast
then obtain p where "IsP p" and "IncidP X p" and "IncidP Y p" and "IncidP Z p"
using plan_existence by blast
hence "IncidLP l p"
using \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> \<open>X \<noteq> Y\<close> line_on_plane by blast
moreover have "IncidLP m p"
using \<open>IncidL X m\<close> \<open>IncidL Z m\<close> \<open>IncidP X p\<close> \<open>IncidP Z p\<close> \<open>IsL m\<close>
\<open>IsP p\<close> \<open>X \<noteq> Z\<close> line_on_plane by blast
ultimately have ?thesis
using IncidLP_def \<open>IncidL A l\<close> \<open>IncidL B l\<close> \<open>IncidL C m\<close> \<open>IncidL D m\<close> by blast
}
ultimately show ?thesis
by blast
qed
lemma coplanar_plane1:
assumes "Bet A B X \<or> Bet B X A \<or> Bet X A B" and
"Bet C D X \<or> Bet D X C \<or> Bet X C D"
shows "\<exists> p. IsP p \<and> IncidP A p \<and> IncidP B p \<and> IncidP C p \<and> IncidP D p"
proof -
have "ColH A B X"
by (meson assms(1) bet_colH colH_permut_312)
moreover have "ColH C D X"
by (simp add: H_to_T.Col_def assms(2) col_colh_1)
ultimately show ?thesis
using Is_plane coplanar_plane0 by blast
qed
lemma coplanar_plane:
assumes "H_to_T.Coplanar A B C D"
shows "\<exists> p. IsP p \<and> IncidP A p \<and> IncidP B p \<and> IncidP C p \<and> IncidP D p"
proof -
obtain X where H1: "(H_to_T.Col A B X \<and> H_to_T.Col C D X) \<or>
(H_to_T.Col A C X \<and> H_to_T.Col B D X) \<or>
(H_to_T.Col A D X \<and> H_to_T.Col B C X)"
using H_to_T.Coplanar_def assms by auto
moreover have "(H_to_T.Col A B X \<and> H_to_T.Col C D X) \<longrightarrow> ?thesis"
using H_to_T.Col_def coplanar_plane1 by force
moreover {
assume "H_to_T.Col A C X" and
"H_to_T.Col B D X"
have "Bet A C X \<or> Bet C X A \<or> Bet X A C"
using H_to_T.Col_def \<open>H_to_T.Col A C X\<close> by presburger
moreover have "Bet B D X \<or> Bet D X B \<or> Bet X B D"
using H1 H_to_T.Col_def \<open>H_to_T.Col B D X\<close> by blast
ultimately have ?thesis
using coplanar_plane1 by blast
}
moreover {
assume "H_to_T.Col A D X" and
"H_to_T.Col B C X"
have "Bet A D X \<or> Bet D X A \<or> Bet X A D"
using H_to_T.Col_def \<open>H_to_T.Col A D X\<close> by auto
moreover have "Bet B C X \<or> Bet C X B \<or> Bet X B C"
using H_to_T.Col_def \<open>H_to_T.Col B C X\<close> by auto
ultimately have ?thesis
using coplanar_plane1 by blast
}
ultimately show ?thesis
by blast
qed
lemma plane_coplanar:
assumes "IncidP A p" and
"IncidP B p" and
"IncidP C p" and
"IncidP D p"
shows "H_to_T.Coplanar A B C D"
proof -
{
assume "ColH A B C"
hence "H_to_T.Col A B C"
using col_colh_2 by blast
hence ?thesis
using H_to_T.ncop__ncols by blast
}
moreover
{
assume "\<not> ColH A B C"
hence "A \<noteq> B"
by (simp add: ncolH_distincts)
obtain M where "M Midpoint A B"
using H_to_T.midpoint_existence Mid__MidH by blast
have "M \<noteq> A"
using Cong_def Hilbert_neutral_dimensionless_pre.Midpoint_def
\<open>A \<noteq> B\<close> \<open>M Midpoint A B\<close> by force
have "M \<noteq> B"
using Midpoint_def Interp_Gupta_of_Tarski_neutral_dimensionless.cong_identityG
\<open>A \<noteq> B\<close> \<open>M Midpoint A B\<close> by blast
have "ColH A B M"
using Midpoint_def \<open>M Midpoint A B\<close> bet_colH colH_permut_132 by blast
then obtain m where "IsL m" and "IncidL A m" and "IncidL B m" and "IncidL M m"
using ColH_def by blast
{
assume "D = M"
hence ?thesis
using H_to_T.ncop__ncols col_colh_2 \<open>ColH A B M\<close> by blast
}
moreover
{
assume "D \<noteq> M"
obtain l where "IsL l" and" IncidL D l" and "IncidL M l"
using \<open>D \<noteq> M\<close> line_existence by blast
{
assume "IncidL A l"
hence "EqL m l"
using \<open>IncidL A m\<close> \<open>IncidL M l\<close> \<open>IncidL M m\<close> \<open>IsL l\<close> \<open>IsL m\<close> \<open>M \<noteq> A\<close>
line_uniqueness by presburger
have "H_to_T.Col A B A \<and> H_to_T.Col C D A \<or> H_to_T.Col A C A \<and> H_to_T.Col B D A \<or>
H_to_T.Col A D A \<and> H_to_T.Col B C A"
by (meson ColH_def H_to_T.not_col_distincts IncidL_morphism Is_line
\<open>EqL m l\<close> \<open>IncidL A l\<close> \<open>IncidL B m\<close> \<open>IncidL D l\<close> col_colh_2)
hence ?thesis
using H_to_T.Coplanar_def by blast
}
moreover
{
assume "\<not> IncidL A l"
{
assume "IncidL B l"
hence "EqL l m"
using \<open>IncidL B m\<close> \<open>IncidL M l\<close> \<open>IncidL M m\<close> \<open>IsL l\<close> \<open>IsL m\<close>
\<open>M \<noteq> B\<close> line_uniqueness by blast
hence False
using \<open>IncidL A m\<close> \<open>IncidL B l\<close> \<open>IncidL B m\<close> \<open>IncidL M l\<close>
\<open>IncidL M m\<close> \<open>M \<noteq> B\<close> \<open>\<not> IncidL A l\<close> inter_incid_uniquenessH by blast
}
{
assume "IncidL C l"
hence "H_to_T.Col A B M \<and> H_to_T.Col C D M \<or> H_to_T.Col A C M \<and> H_to_T.Col B D M \<or>
H_to_T.Col A D M \<and> H_to_T.Col B C M"
using Hilbert_neutral_dimensionless_pre.ColH_def \<open>ColH A B M\<close>
\<open>IncidL D l\<close> \<open>IncidL M l\<close> \<open>IsL l\<close> col_colh by fastforce
hence ?thesis
using H_to_T.Coplanar_def by blast
}
moreover
{
assume "\<not> IncidL C l"
have "IncidP M p"
using \<open>A \<noteq> B\<close> \<open>ColH A B M\<close> assms(1) assms(2) line_on_plane' by blast
have
"\<not> ColH A B C \<and> IsL l \<and> IsP p \<and> IncidP A p \<and> IncidP B p \<and>
IncidP C p \<and> IncidLP l p \<and> \<not> IncidL C l \<and> (cut l A B)
\<longrightarrow>
(cut l A C) \<or> (cut l B C)"
using pasch by blast
moreover
{
assume "cut l A C"
then obtain I where "IncidL I l" and "BetH A I C"
using local.cut_def by blast
{
assume "H_to_T.Col I A B"
have "A \<noteq> I"
using \<open>IncidL I l\<close> \<open>\<not> IncidL A l\<close> by auto
moreover have "ColH A I A"
by (simp add: colH_trivial121)
moreover have "ColH A I C"
by (simp add: \<open>BetH A I C\<close> between_col)
ultimately have False
using \<open>\<not> ColH A B C\<close> colH_trans \<open>H_to_T.Col I A B\<close>
colH_permut_213 col_colh_1 by blast
}
hence "\<not> H_to_T.Col I A B"
by blast
moreover have "H_to_T.Coplanar I A B C"
using H_to_T.bet__coplanar H_to_T.ncoplanar_perm_7 \<open>BetH A I C\<close>
betH_to_bet by blast
moreover
have "H_to_T.Col I D M"
using ColH_def \<open>IncidL D l\<close> \<open>IncidL I l\<close> \<open>IncidL M l\<close> \<open>IsL l\<close> col_colh by auto
have "H_to_T.Col A B M"
using \<open>ColH A B M\<close> col_colh_2 by fastforce
hence "H_to_T.Col I A M \<and> H_to_T.Col B D M \<or> H_to_T.Col I B M \<and> H_to_T.Col A D M \<or>
H_to_T.Col I D M \<and> H_to_T.Col A B M"
using \<open>H_to_T.Col I D M\<close> by auto
hence "H_to_T.Coplanar I A B D"
using H_to_T.Coplanar_def by blast
ultimately have ?thesis
using H_to_T.coplanar_trans_1 by blast
}
moreover
{
assume "cut l B C"
then obtain I where "IncidL I l" and "BetH B I C"
using local.cut_def by blast
{
assume "H_to_T.Col I B A"
have "B \<noteq> I"
using \<open>IncidL B l \<Longrightarrow> False\<close> \<open>IncidL I l\<close> by fastforce
moreover have "ColH B I A"
using \<open>H_to_T.Col I B A\<close> colH_permut_213 col_colh by blast
moreover have "ColH B I B"
by (simp add: colH_trivial121)
ultimately have False
using \<open>BetH B I C\<close> \<open>\<not> ColH A B C\<close> between_col colH_trans by blast
}
hence "\<not> H_to_T.Col I B A"
by blast
moreover have "H_to_T.Coplanar I B A C"
using H_to_T.bet__coplanar H_to_T.ncoplanar_perm_7 \<open>BetH B I C\<close>
betH_to_bet by blast
moreover
have "H_to_T.Col I D M"
using ColH_def \<open>IncidL D l\<close> \<open>IncidL I l\<close> \<open>IncidL M l\<close> \<open>IsL l\<close> col_colh by auto
have "H_to_T.Col B A M"
by (metis Bet_def H_to_T.Col_def \<open>ColH A B M\<close> between_comm between_one)
hence "H_to_T.Col I B M \<and> H_to_T.Col A D M \<or> H_to_T.Col I A M \<and> H_to_T.Col B D M \<or>
H_to_T.Col I D M \<and> H_to_T.Col B A M"
using \<open>H_to_T.Col I D M\<close> by auto
hence "H_to_T.Coplanar I B A D"
using H_to_T.Coplanar_def by blast
ultimately have ?thesis
using H_to_T.coplanar_trans_1 H_to_T.ncoplanar_perm_6 by blast
}
ultimately have ?thesis
by (metis (mono_tags, lifting) Bet_def line_on_plane Is_plane Midpoint_def
\<open>ColH A B C \<Longrightarrow> H_to_T.Coplanar A B C D\<close> \<open>D = M \<Longrightarrow> H_to_T.Coplanar A B C D\<close>
\<open>IncidL B l \<Longrightarrow> False\<close> \<open>IncidL D l\<close> \<open>IncidL M l\<close> \<open>IncidP M p\<close> \<open>IsL l\<close>
\<open>M Midpoint A B\<close> \<open>\<not> IncidL A l\<close> \<open>\<not> IncidL C l\<close> assms(1) assms(2)
assms(3) assms(4) local.cut_def)
}
ultimately have ?thesis
by blast
}
ultimately have ?thesis
by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
lemma pars__para:
assumes "IncidL A l" and
"IncidL B l" and
"IncidL C m" and
"IncidL D m" and
"H_to_T.ParStrict A B C D"
shows "Para l m"
proof -
have "A \<noteq> B"
using H_to_T.par_strict_neq1 assms(5) by auto
have "C \<noteq> D"
using H_to_T.par_strict_distinct assms(5) by presburger
have "IsL l"
using Is_line assms(1) by blast
moreover have "IsL m"
using Is_line assms(4) by blast
moreover
{
fix X
assume "IncidL X l" and "IncidL X m"
hence "H_to_T.Col X A B"
using assms(1) assms(2) Is_line line_col by blast
moreover have "H_to_T.Col X C D"
using assms(1) assms(2) Is_line line_col \<open>IncidL X m\<close> assms(3) assms(4) by auto
ultimately have False
using H_to_T.par_not_col assms(5) by blast
}
moreover
obtain p where "IsP p" and "IncidP A p" and "IncidP B p" and "IncidP C p" and "IncidP D p"
using H_to_T.pars__coplanar assms(5) coplanar_plane by blast
have "\<exists> p. IncidLP l p \<and> IncidLP m p"
proof -
have "IncidLP l p"
using \<open>A \<noteq> B\<close> \<open>IncidP A p\<close> \<open>IncidP B p\<close> \<open>IsP p\<close> assms(1) assms(2)
calculation(1) line_on_plane by blast
moreover have "IncidLP m p"
using \<open>C \<noteq> D\<close> \<open>IncidP C p\<close> \<open>IncidP D p\<close> \<open>IsP p\<close> assms(3) assms(4)
line_on_plane \<open>IsL m\<close> by blast
ultimately show ?thesis
by blast
qed
ultimately show ?thesis
using Para_def by blast
qed
lemma par__or_eq_para:
assumes "IncidL A l" and
"IncidL B l" and
"IncidL C m" and
"IncidL D m" and
"H_to_T.Par A B C D"
shows "Para l m \<or> EqL l m"
proof -
{
assume "H_to_T.ParStrict A B C D"
hence ?thesis
using assms(1) assms(2) assms(3) assms(4) pars__para by blast
}
moreover
{
assume "A \<noteq> B" and
"C \<noteq> D" and
"H_to_T.Col A C D" and
"H_to_T.Col B C D"
hence ?thesis
by (meson IncidL_not_IncidL__not_colH Is_line assms(1) assms(2) assms(3)
assms(4) colH_permut_231 col_colh_1 line_uniqueness)
}
ultimately show ?thesis
using H_to_T.Par_def assms(5) by presburger
qed
lemma tarski_upper_dim:
assumes
plane_intersection_assms: "\<forall> A p q. IsP p \<and> IsP q \<and> IncidP A p \<and> IncidP A q
\<longrightarrow> (\<exists> B. IncidP B p \<and> IncidP B q \<and> A \<noteq> B)" and
lower_dim_3_assms: "\<not> (\<exists> p. IsP p \<and> IncidP HS1 p \<and> IncidP HS2 p \<and>
IncidP HS3 p \<and> IncidP HS4 p)" and
"P \<noteq> Q" and
"Q \<noteq> R" and
"P \<noteq> R" and
"Cong A P A Q" and
"Cong B P B Q" and
"Cong C P C Q" and
"Cong A P A R" and
"Cong B P B R" and
"Cong C P C R"
shows "Bet A B C \<or> Bet B C A \<or> Bet C A B"
proof -
have "H_to_T.upper_dim_3_axiom \<longrightarrow> ?thesis"
using H_to_T.upper_dim_3_axiom_def assms(10) assms(11) assms(3) assms(4)
assms(5) assms(6) assms(7) assms(8) assms(9) by blast
moreover
have "H_to_T.plane_intersection_axiom \<longrightarrow> H_to_T.upper_dim_3_axiom"
using H_to_T.upper_dim_3_equivalent_axioms by force
moreover
{
fix A B C D E F P
assume "H_to_T.Coplanar A B C P" and
"H_to_T.Coplanar D E F P"
obtain p where "IsP p" and "IncidP A p" and "IncidP B p" and "IncidP C p" and "IncidP P p"
using \<open>H_to_T.Coplanar A B C P\<close> coplanar_plane by blast
obtain q where "IsP q" and "IncidP D q" and "IncidP E q" and "IncidP F q" and "IncidP P q"
using \<open>H_to_T.Coplanar D E F P\<close> coplanar_plane by blast
obtain Q where "IncidP Q p" and "IncidP Q q" and "P \<noteq> Q"
using plane_intersection_assms Is_plane \<open>IncidP P p\<close> \<open>IncidP P q\<close> by blast
have "H_to_T.Coplanar A B C Q"
using \<open>IncidP A p\<close> \<open>IncidP B p\<close> \<open>IncidP C p\<close> \<open>IncidP Q p\<close> plane_coplanar by force
moreover have "H_to_T.Coplanar D E F Q"
using \<open>IncidP D q\<close> \<open>IncidP E q\<close> \<open>IncidP F q\<close> \<open>IncidP Q q\<close> plane_coplanar by force
ultimately have "\<exists> Q. H_to_T.Coplanar A B C Q \<and> H_to_T.Coplanar D E F Q \<and> P \<noteq> Q"
using \<open>P \<noteq> Q\<close> by blast
}
hence "H_to_T.plane_intersection_axiom"
using H_to_T.plane_intersection_axiom_def by force
ultimately show ?thesis
by simp
qed
lemma Col__ColH:
assumes "H_to_T.Col A B C"
shows "ColH A B C"
using assms col_colh by blast
lemma ColH__Col:
assumes "ColH A B C"
shows "H_to_T.Col A B C"
using assms ColH_bets col_colh by blast
lemma playfair_s_postulateH:
assumes euclid_uniqueness: "\<forall> l P m1 m2. IsL l \<and> IsL m1 \<and> IsL m2 \<and>
\<not> IncidL P l \<and> Para l m1 \<and> IncidL P m1 \<and> Para l m2 \<and> IncidL P m2 \<longrightarrow>
EqL m1 m2"
shows "H_to_T.playfair_s_postulate"
proof -
{
fix A1 A2 B1 B2 C1 C2 P
assume "H_to_T.Par A1 A2 B1 B2" and
"H_to_T.Col P B1 B2" and
"H_to_T.Par A1 A2 C1 C2" and
"H_to_T.Col P C1 C2"
have "A1 \<noteq> A2"
using H_to_T.par_distinct \<open>H_to_T.Par A1 A2 B1 B2\<close> by blast
then obtain l where "IsL l" and "IncidL A1 l" and "IncidL A2 l"
using line_existence by fastforce
have "B1 \<noteq> B2"
using H_to_T.par_distinct \<open>H_to_T.Par A1 A2 B1 B2\<close> by blast
then obtain m1 where "IsL m1" and "IncidL B1 m1" and "IncidL B2 m1"
using line_existence by fastforce
have "C1 \<noteq> C2"
using H_to_T.par_distinct \<open>H_to_T.Par A1 A2 C1 C2\<close> by blast
then obtain m2 where "IsL m2" and "IncidL C1 m2" and "IncidL C2 m2"
using line_existence by fastforce
{
assume "IncidL P l"
have "ColH A1 A2 P"
using ColH_def Is_line \<open>IncidL A1 l\<close> \<open>IncidL A2 l\<close> \<open>IncidL P l\<close> by blast
hence "H_to_T.Col A1 A2 P"
by (simp add: col_colh)
have "H_to_T.Col A1 B1 B2"
by (metis H_to_T.col3 H_to_T.not_col_distincts H_to_T.not_strict_par1
H_to_T.not_strict_par2 \<open>A1 \<noteq> A2\<close> \<open>H_to_T.Col A1 A2 P\<close> \<open>H_to_T.Col P B1 B2\<close>
\<open>H_to_T.Par A1 A2 B1 B2\<close>)
have "H_to_T.Col A2 B1 B2"
using H_to_T.Par_def H_to_T.not_col_permutation_2 H_to_T.par_strict_not_col_3
\<open>H_to_T.Col A1 B1 B2\<close> \<open>H_to_T.Par A1 A2 B1 B2\<close> by blast
have "H_to_T.ParStrict A1 A2 C1 C2 \<longrightarrow> H_to_T.Col C1 B1 B2 \<and> H_to_T.Col C2 B1 B2"
using H_to_T.Col_cases H_to_T.par_not_col \<open>H_to_T.Col A1 A2 P\<close>
\<open>H_to_T.Col P C1 C2\<close> by blast
moreover have "A1 \<noteq> A2 \<and> C1 \<noteq> C2 \<and> H_to_T.Col A1 C1 C2 \<and> H_to_T.Col A2 C1 C2
\<longrightarrow> H_to_T.Col C1 B1 B2 \<and> H_to_T.Col C2 B1 B2"
proof -
have "A1 \<noteq> A2 \<and> C1 \<noteq> C2 \<and> H_to_T.Col A1 C1 C2 \<and> H_to_T.Col A2 C1 C2
\<longrightarrow> H_to_T.Col C1 B1 B2"
by (meson H_to_T.col_permutation_1 H_to_T.l6_21 \<open>H_to_T.Col A1 B1 B2\<close>
\<open>H_to_T.Col A2 B1 B2\<close>)
moreover have "A1 \<noteq> A2 \<and> C1 \<noteq> C2 \<and> H_to_T.Col A1 C1 C2 \<and> H_to_T.Col A2 C1 C2
\<longrightarrow> H_to_T.Col C2 B1 B2"
using H_to_T.col_permutation_1 H_to_T.l6_21
by (metis H_to_T.col_permutation_1 H_to_T.colx \<open>H_to_T.Col A1 B1 B2\<close>
\<open>H_to_T.Col A2 B1 B2\<close> calculation)
ultimately show ?thesis
by blast
qed
ultimately have "H_to_T.Col C1 B1 B2 \<and> H_to_T.Col C2 B1 B2"
using H_to_T.Par_def \<open>H_to_T.Par A1 A2 C1 C2\<close> by force
}
moreover
{
assume "\<not> IncidL P l"
have "\<not> ColH A1 A2 P"
using IncidL_not_IncidL__not_colH \<open>A1 \<noteq> A2\<close> \<open>IncidL A1 l\<close> \<open>IncidL A2 l\<close>
\<open>\<not> IncidL P l\<close> by blast
hence "\<not> H_to_T.Col A1 A2 P"
using col_colh by blast
have "Para l m1"
proof -
have "H_to_T.ParStrict A1 A2 B1 B2"
using H_to_T.col_permutation_2 H_to_T.par_not_col_strict
\<open>H_to_T.Col P B1 B2\<close> \<open>H_to_T.Par A1 A2 B1 B2\<close> \<open>\<not> H_to_T.Col A1 A2 P\<close> by blast
moreover have "H_to_T.ParStrict A1 A2 B1 B2 \<longrightarrow> Para l m1"
using \<open>IncidL A1 l\<close> \<open>IncidL A2 l\<close> \<open>IncidL B1 m1\<close> \<open>IncidL B2 m1\<close> pars__para by blast
ultimately show ?thesis
by blast
qed
have "Para l m2"
proof -
have "H_to_T.ParStrict A1 A2 C1 C2"
using H_to_T.not_col_permutation_2 H_to_T.par_not_col_strict
\<open>H_to_T.Col P C1 C2\<close> \<open>H_to_T.Par A1 A2 C1 C2\<close> \<open>\<not> H_to_T.Col A1 A2 P\<close> by blast
moreover have "H_to_T.ParStrict A1 A2 C1 C2 \<longrightarrow> Para l m2"
using \<open>IncidL A1 l\<close> \<open>IncidL A2 l\<close> \<open>IncidL C1 m2\<close> \<open>IncidL C2 m2\<close> pars__para by auto
ultimately show ?thesis
by blast
qed
have "IncidL P m1"
using H_to_T.not_col_permutation_2 IncidL_not_IncidL__not_colH \<open>B1 \<noteq> B2\<close>
\<open>H_to_T.Col P B1 B2\<close> \<open>IncidL B1 m1\<close> \<open>IncidL B2 m1\<close> col_colh by blast
have "IncidL P m2"
using H_to_T.not_col_permutation_2 IncidL_not_IncidL__not_colH \<open>C1 \<noteq> C2\<close>
\<open>H_to_T.Col P C1 C2\<close> \<open>IncidL C1 m2\<close> \<open>IncidL C2 m2\<close> col_colh by blast
have "EqL m1 m2"
using \<open>IncidL P m1\<close> \<open>IncidL P m2\<close> \<open>IsL l\<close> \<open>IsL m1\<close> \<open>IsL m2\<close> \<open>Para l m1\<close>
\<open>Para l m2\<close> \<open>\<not> IncidL P l\<close> assms by blast
hence "H_to_T.Col C1 B1 B2 \<and> H_to_T.Col C2 B1 B2"
by (meson IncidL_morphism \<open>IncidL B1 m1\<close> \<open>IncidL B2 m1\<close> \<open>IncidL C1 m2\<close>
\<open>IncidL C2 m2\<close> \<open>IsL m1\<close> \<open>IsL m2\<close> line_col)
}
ultimately have "H_to_T.Col C1 B1 B2 \<and> H_to_T.Col C2 B1 B2"
by blast
}
thus ?thesis
using H_to_T.playfair_s_postulate_def by blast
qed
lemma tarski_s_euclid_aux:
assumes euclid_uniqueness: "\<forall> l P m1 m2. IsL l \<and> IsL m1 \<and> IsL m2 \<and>
\<not> IncidL P l \<and> Para l m1 \<and> IncidL P m1 \<and> Para l m2 \<and> IncidL P m2 \<longrightarrow>
EqL m1 m2"
shows "H_to_T.tarski_s_parallel_postulate"
proof -
have "H_to_T.playfair_s_postulate \<longrightarrow> H_to_T.tarski_s_parallel_postulate"
using H_to_T.InterAx5 H_to_T.Postulate01_def H_to_T.Postulate02_def by blast
moreover
have "H_to_T.playfair_s_postulate"
using playfair_s_postulateH assms(1) by blast
ultimately show ?thesis
by blast
qed
lemma tarski_s_euclid:
assumes euclid_uniqueness: "\<forall> l P m1 m2. IsL l \<and> IsL m1 \<and> IsL m2 \<and>
\<not> IncidL P l \<and> Para l m1 \<and> IncidL P m1 \<and> Para l m2 \<and> IncidL P m2 \<longrightarrow>
EqL m1 m2"
shows
"\<forall>A B C D T. Bet A D T \<and> Bet B D C \<and> A \<noteq> D \<longrightarrow> (\<exists>X Y. Bet A B X \<and> Bet A C Y \<and> Bet X T Y)"
using assms(1) tarski_s_euclid_aux H_to_T.tarski_s_parallel_postulate_def by blast
end
context Hilbert_neutral_2D
begin
lemma plane_separation_2D:
assumes "\<not> ColH A X Y" and
"\<not> ColH B X Y"
shows "cut' A B X Y \<or> same_side' A B X Y"
proof -
have "X \<noteq> Y"
using assms(2) colH_trivial122 by blast
obtain l where "IsL l" and "IncidL X l" and "IncidL Y l"
using \<open>X \<noteq> Y\<close> line_existence by blast
obtain C where "cut l A C"
using ColH_def \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> assms(1) cut_exists by blast
{
assume "A = B"
hence "same_side' A B X Y"
using assms(1) colH_permut_312 same_side_prime_refl by blast
hence ?thesis
by blast
}
moreover
{
assume "A \<noteq> B"
have "A \<noteq> C"
using \<open>local.cut l A C\<close> cut_distinct by blast
{
assume "B = C"
obtain m where "IsL m" and "IncidL X m" and "IncidL Y m"
using Is_line \<open>IncidL X l\<close> \<open>IncidL Y l\<close> by blast
obtain I where "IncidL I l" and "BetH A I C"
using \<open>local.cut l A C\<close> local.cut_def by blast
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "cut m A B"
by (metis ColH_def \<open>B = C\<close> \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>X \<noteq> Y\<close>
\<open>\<And>thesis. (\<And>I. \<lbrakk>IncidL I l; BetH A I C\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close> assms(1)
assms(2) inter_incid_uniquenessH local.cut_def)
}
hence "cut' A C X Y"
using \<open>X \<noteq> Y\<close> \<open>B = C\<close> cut'_def by auto
hence ?thesis
using \<open>B = C\<close> by blast
}
moreover
{
assume "B \<noteq> C"
{
assume "ColH A C B"
obtain I where "IncidL I l" and "BetH A I C"
using \<open>local.cut l A C\<close> local.cut_def by blast
hence "ColH A I C"
using betH_colH by blast
hence "ColH A I B"
by (meson colH_permut_132 colH_trans colH_trivial121 \<open>A \<noteq> C\<close> \<open>ColH A C B\<close>)
hence "BetH A I B \<or> BetH I B A \<or> BetH I A B"
using ColH_def \<open>A \<noteq> B\<close> \<open>BetH A I C\<close> \<open>IncidL I l\<close> \<open>IncidL X l\<close>
\<open>IncidL Y l\<close> \<open>IsL l\<close> assms(2) betH_colH between_one by blast
have "\<not> IncidL A l"
using \<open>local.cut l A C\<close> local.cut_def by auto
{
assume "BetH A I B"
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
have "\<not> IncidL B m"
using ColH_def \<open>IncidL X m\<close> \<open>IncidL Y m\<close> \<open>IsL m\<close> assms(2) by blast
moreover have "\<exists> I0. IncidL I0 m \<and> BetH A I0 B"
using \<open>BetH A I B\<close> \<open>IncidL I l\<close> \<open>IncidL X l\<close> \<open>IncidL X m\<close>
\<open>IncidL Y l\<close> \<open>IncidL Y m\<close> \<open>X \<noteq> Y\<close> inter_incid_uniquenessH by blast
ultimately have "cut m A B"
using \<open>IncidL X l\<close> \<open>IncidL X m\<close> \<open>IncidL Y l\<close> \<open>IncidL Y m\<close> \<open>IsL m\<close>
\<open>X \<noteq> Y\<close> \<open>\<not> IncidL A l\<close> inter_incid_uniquenessH local.cut_def by blast
}
hence "cut' A B X Y"
by (simp add: \<open>X \<noteq> Y\<close> cut'_def)
}
moreover have "BetH I B A \<longrightarrow> same_side' A B X Y"
using \<open>IncidL I l\<close> \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>X \<noteq> Y\<close> \<open>\<not> IncidL A l\<close>
outH_def out_same_side' by auto
moreover have "BetH I A B \<longrightarrow> same_side' A B X Y"
using \<open>IncidL I l\<close> \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>X \<noteq> Y\<close> \<open>\<not> IncidL A l\<close>
outH_def out_same_side' by auto
ultimately have ?thesis
using \<open>BetH A I B \<or> BetH I B A \<or> BetH I A B\<close> by fastforce
}
moreover
{
assume "\<not> ColH A C B"
have "\<not> IncidL B l"
using ColH_def Is_line \<open>IncidL X l\<close> \<open>IncidL Y l\<close> assms(2) by blast
moreover {
assume "cut l A B"
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "EqL m l"
using \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> \<open>IsL m\<close> \<open>X \<noteq> Y\<close>
line_uniqueness by blast
hence "cut m A B"
by (meson \<open>IsL m\<close> \<open>local.cut l A B\<close> local.cut_def morph)
}
hence "cut' A B X Y"
using \<open>X \<noteq> Y\<close> cut'_def by auto
}
{
assume "cut l C B"
{
fix m
assume "IsL m" and "IncidL X m" and "IncidL Y m"
hence "EqL m l"
using \<open>IncidL X l\<close> \<open>IncidL Y l\<close> \<open>IsL l\<close> \<open>X \<noteq> Y\<close> line_uniqueness by blast
have "cut m A C"
by (meson \<open>IncidL X l\<close> \<open>IncidL X m\<close> \<open>IncidL Y l\<close> \<open>IncidL Y m\<close>
\<open>IsL m\<close> \<open>X \<noteq> Y\<close> \<open>local.cut l A C\<close> inter_incid_uniquenessH local.cut_def)
moreover have "cut m B C"
by (meson \<open>EqL m l\<close> \<open>IsL m\<close> \<open>local.cut l C B\<close> cut_comm local.cut_def morph)
ultimately have "same_side A B m"
using \<open>IsL m\<close> same_side_def by blast
}
hence "same_side' A B X Y"
by (simp add: \<open>X \<noteq> Y\<close> same_side'_def)
have ?thesis
using \<open>IsL l\<close> \<open>\<not> ColH A C B\<close> \<open>local.cut l A C\<close> pasch_2D
\<open>same_side' A B X Y\<close> by blast
}
ultimately have ?thesis
using \<open>IsL l\<close> \<open>\<not> ColH A C B\<close> \<open>local.cut l A B \<Longrightarrow> cut' A B X Y\<close>
\<open>local.cut l A C\<close> pasch_2D by blast
}
ultimately have ?thesis
by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
lemma col_upper_dim:
assumes "ColH A P Q" and
"P \<noteq> Q" and
"A \<noteq> B" and
"A \<noteq> C" and
"B \<noteq> C" and
"A \<noteq> P" and
"A \<noteq> Q" and
"B \<noteq> P" and
"B \<noteq> Q" and
"C \<noteq> P" and
"C \<noteq> Q" and
"CongH A P A Q" and
"CongH B P B Q" and
"CongH C P C Q"
shows "Bet A B C \<or> Bet B C A \<or> Bet C A B"
proof -
{
assume "ColH B P Q"
hence "BetH P B Q"
using assms(13) assms(2) assms(8) assms(9) congH_colH_betH by auto
{
assume "BetH P A B"
hence "BetH Q B A"
using \<open>BetH P B Q\<close> betH_trans0 between_comm by blast
hence False
using \<open>BetH P A B\<close> assms(12) assms(13) assms(7) assms(9)
betH_congH2__False congH_permlr by blast
}
moreover
{
assume "BetH P B A"
hence "BetH Q A B"
by (metis assms(1) assms(12) assms(2) assms(6) assms(7)
betH_trans0 between_comm congH_colH_betH)
hence False
using \<open>BetH P B A\<close> assms(12) assms(13) assms(7) assms(9)
betH_congH2__False congH_permlr by blast
}
ultimately have False
by (metis \<open>BetH P B Q\<close> assms(1) assms(12) assms(2) assms(3)
assms(6) betH2_out congH_colH_betH)
}
hence "\<not> ColH B P Q"
by blast
{
assume "ColH C P Q"
hence "BetH P C Q"
using assms(10) assms(11) assms(14) assms(2) congH_colH_betH by force
{
assume "BetH P A C"
hence "BetH Q C A"
using \<open>BetH P C Q\<close> betH_trans0 between_comm by blast
hence False
using \<open>BetH P A C\<close> assms(11) assms(12) assms(14) assms(7)
betH_congH2__False congH_permlr by blast
}
moreover
{
assume "BetH P C A"
hence "BetH Q A C"
by (metis assms(1) assms(12) assms(2) assms(6) assms(7)
betH_trans0 between_comm congH_colH_betH)
hence False
using \<open>BetH P C A\<close> assms(10) assms(11) assms(12) assms(14)
assms(6) assms(7) betH_congH2__False congH_perms by blast
}
ultimately have False
by (metis congH_colH_betH \<open>BetH P C Q\<close> assms(1) assms(12) assms(2)
assms(4) assms(6) betH2_out)
}
hence "\<not> ColH C P Q"
by blast
{
assume "cut' B C P Q"
obtain l where "IsL l" and "IncidL P l" and "IncidL Q l"
using assms(2) line_existence by blast
have "cut l B C"
using \<open>IncidL P l\<close> \<open>IncidL Q l\<close> \<open>IsL l\<close> \<open>cut' B C P Q\<close> cut'_def by auto
obtain I where "IncidL I l" and "BetH B I C"
using \<open>local.cut l B C\<close> local.cut_def by blast
{
assume "P = I"
hence "ColH B Q C"
by (metis \<open>BetH B I C\<close> assms(11) assms(13) assms(14) assms(5)
congH_permlr congH_refl cong_preserves_col)
hence False
by (metis betH2_out \<open>BetH B I C\<close> \<open>P = I\<close> \<open>\<not> ColH B P Q\<close> assms(13)
assms(14) assms(2) assms(9) betH_colH bet_cong3_bet colH_permut_132
congH_permlr congH_refl)
}
hence "P \<noteq> I" by blast
{
assume "Q = I"
hence "ColH B P C"
by (metis \<open>BetH B I C\<close> assms(10) assms(11) assms(13) assms(14)
assms(5) assms(8) congH_perms congH_refl congH_sym cong_preserves_col)
hence False
by (metis Hilbert_neutral_dimensionless_pre.Bet_def \<open>BetH B I C\<close>
\<open>IncidL P l\<close> \<open>Q = I\<close> \<open>\<not> ColH B P Q\<close> \<open>local.cut l B C\<close> betH2_out bet_colH
between_one colH_permut_132 local.cut_def outH_def out_same_side same_side_not_cut)
}
hence "Q \<noteq> I"
by blast
have "ColH P Q I"
using ColH_def \<open>IncidL I l\<close> \<open>IncidL P l\<close> \<open>IncidL Q l\<close> \<open>IsL l\<close> by blast
have "CongaH I B P I B Q"
proof -
have "CongaH C B P C B Q"
proof -
have "\<not> ColH B C P"
by (metis (full_types) \<open>BetH B I C\<close> \<open>ColH B P Q \<Longrightarrow> False\<close>
\<open>ColH P Q I\<close> \<open>P = I \<Longrightarrow> False\<close> colH_permut_312 colH_trivial121
inter_uniquenessH outH_def outH_expand)
moreover have "\<not> ColH B C Q"
by (meson assms(10) assms(11) assms(13) assms(14) assms(5)
assms(8) assms(9) calculation congH_refl congH_sym cong_preserves_col_stronger)
moreover have "CongH B C B C"
by (simp add: assms(5) congH_refl)
moreover have "CongH B P B Q"
by (simp add: assms(13))
moreover have "CongH C P C Q"
by (simp add: assms(14))
ultimately show ?thesis
using th18_aux by blast
qed
moreover have "outH B C I"
by (simp add: \<open>BetH B I C\<close> outH_def)
moreover have "outH B P P"
by (simp add: assms(8) outH_def)
moreover have "outH B Q Q"
by (simp add: assms(9) outH_def)
ultimately show ?thesis
using conga_out_conga by blast
qed
have "CongH I P I Q"
proof -
have "\<not> ColH B I P"
by (metis \<open>ColH P Q I\<close> \<open>P = I \<Longrightarrow> False\<close> \<open>\<not> ColH B P Q\<close>
colH_permut_312 colH_trivial122 inter_uniquenessH)
moreover have "\<not> ColH B I Q"
using IncidL_not_IncidL__not_colH \<open>IncidL I l\<close> \<open>IncidL Q l\<close>
\<open>Q = I \<Longrightarrow> False\<close> \<open>local.cut l B C\<close> colH_permut_321 local.cut_def by blast
moreover have "CongH B I B I"
using \<open>BetH B I C\<close> betH_distincts congH_refl by auto
moreover have "CongH B P B Q"
by (simp add: assms(13))
moreover have "CongaH I B P I B Q"
by (simp add: \<open>CongaH I B P I B Q\<close>)
ultimately show ?thesis
using th12 by blast
qed
have "A = I \<longrightarrow> ?thesis"
using Bet_def \<open>BetH B I C\<close> between_comm by blast
moreover
{
assume "A \<noteq> I"
have "ColH I P Q"
by (simp add: \<open>ColH P Q I\<close> colH_permut_312)
hence "BetH P I Q"
by (simp add: \<open>CongH I P I Q\<close> \<open>P \<noteq> I\<close> \<open>Q \<noteq> I\<close> assms(2) congH_colH_betH)
{
assume "BetH P A I"
hence "BetH Q I A"
using \<open>BetH P I Q\<close> betH_trans0 between_comm by blast
hence False
by (metis \<open>BetH P A I\<close> \<open>CongH I P I Q\<close> \<open>Q \<noteq> I\<close> assms(12) assms(7)
betH_congH2__False congH_permlr)
}
moreover {
assume "BetH P I A"
hence "BetH Q A I"
by (metis assms(1) assms(12) assms(2) assms(6) assms(7) betH_trans0
between_comm congH_colH_betH)
hence False
by (metis \<open>BetH P I A\<close> \<open>CongH I P I Q\<close> \<open>Q = I \<Longrightarrow> False\<close> assms(12)
assms(7) betH_congH2__False congH_permlr)
}
ultimately have ?thesis
by (metis \<open>A = I \<longrightarrow> Bet A B C \<or> Bet B C A \<or> Bet C A B\<close> \<open>BetH P I Q\<close>
assms(1) assms(12) assms(2) assms(6) betH2_out congH_colH_betH)
}
ultimately have ?thesis
by blast
}
moreover
{
assume "same_side' B C P Q"
{
assume "ColH P B C"
have "ColH C P B"
by (simp add: \<open>ColH P B C\<close> colH_permut_312)
have "ColH B C Q"
by (metis colH_permut_312 \<open>ColH C P B\<close> assms(10) assms(13) assms(14)
assms(5) assms(8) congH_perm congH_perms cong_preserves_col_stronger)
have "BetH P B Q"
using ColH_def \<open>ColH B C Q\<close> \<open>ColH C P Q \<Longrightarrow> False\<close> \<open>ColH P B C\<close>
assms(5) colH_IncidL__IncidL by blast
have "BetH P C Q"
using \<open>BetH P B Q\<close> \<open>\<not> ColH B P Q\<close> between_col colH_permut_213 by blast
{
assume "BetH P B C"
hence "BetH Q C B"
using \<open>BetH P C Q\<close> betH_trans0 between_comm by blast
hence False
using \<open>BetH P B Q\<close> \<open>\<not> ColH B P Q\<close> betH_expand colH_permut_213 by blast
}
moreover
{
assume "BetH P C B"
hence "BetH B Q C"
using \<open>BetH P B Q\<close> \<open>\<not> ColH B P Q\<close> betH_expand colH_permut_213 by blast
hence False
using \<open>BetH P C Q\<close> \<open>ColH C P Q \<Longrightarrow> False\<close> betH_expand colH_permut_213 by blast
}
ultimately have False
using \<open>BetH P B Q\<close> \<open>BetH P C Q\<close> assms(5) betH2_out by blast
}
hence "\<not> ColH P B C"
by blast
{
assume "ColH Q B C"
hence "ColH B C P"
by (metis (full_types) \<open>\<not> ColH P B C\<close> assms(10) assms(11) assms(13)
assms(14) assms(5) assms(8) assms(9) between_one colH_permut_213 congH_perms
congH_refl cong_preserves_col)
hence False
using \<open>\<not> ColH P B C\<close> colH_permut_312 by blast
}
hence "\<not> ColH Q B C"
by blast
{
assume "cut' P Q B C"
obtain lBC where "IsL lBC" and "IncidL B lBC" and "IncidL C lBC"
using assms(5) line_existence by blast
{
assume "\<not> IncidL P lBC" and
"\<not> IncidL Q lBC" and
"\<exists> I. IncidL I lBC \<and> BetH P I Q"
then obtain I where "IncidL I lBC" and "BetH P I Q"
by blast
have "ColH B I C"
using ColH_def \<open>IncidL B lBC\<close> \<open>IncidL C lBC\<close> \<open>IncidL I lBC\<close> \<open>IsL lBC\<close> by auto
{
assume "BetH B I C"
obtain lPQ where "IncidL P lPQ" and "IncidL Q lPQ" and "\<not> cut lPQ B C"
by (metis \<open>same_side' B C P Q\<close> line_existence same_side'_def same_side_not_cut)
have "cut lPQ B C"
proof -
have "\<not> IncidL C lPQ"
using Hilbert_neutral_dimensionless_pre.ColH_def Is_line
\<open>ColH C P Q \<Longrightarrow> False\<close> \<open>IncidL P lPQ\<close> \<open>IncidL Q lPQ\<close> by fastforce
moreover have "IncidL I lPQ"
using \<open>BetH P I Q\<close> \<open>IncidL P lPQ\<close> \<open>IncidL Q lPQ\<close> assms(2) betH_line
inter_incid_uniquenessH by blast
ultimately show ?thesis
using \<open>BetH B I C\<close> Is_line \<open>ColH B I C\<close> betH_distincts
colH_IncidL__IncidL local.cut_def by blast
qed
hence "?thesis"
using \<open>\<not> local.cut lPQ B C\<close> by blast
}
moreover {
assume "BetH I C B"
have "CongaH P C I Q C I"
proof -
have "\<not> ColH B C P"
using \<open>\<not> ColH P B C\<close> colH_permut_312 by blast
moreover have "\<not> ColH B C Q"
using \<open>\<not> ColH Q B C\<close> colH_permut_312 by blast
moreover have "CongaH B C P B C Q"
using \<open>BetH P I Q\<close> \<open>ColH B I C\<close> assms(13) assms(14) calculation(1)
calculation(2) th17 by blast
moreover have "BetH B C I"
by (simp add: \<open>BetH I C B\<close> between_comm)
ultimately show ?thesis
using th14 by blast
qed
have "CongH I P I Q"
proof -
have "\<not> ColH C P I"
by (metis IncidL_not_IncidL__not_colH \<open>BetH P I Q\<close> \<open>IncidL C lBC\<close>
\<open>IncidL I lBC\<close> \<open>\<not> ColH C P Q\<close> \<open>\<not> IncidL P lBC\<close> betH_colH colH_permut_132 colH_permut_213)
moreover have "\<not> ColH C Q I"
using \<open>BetH I C B\<close> \<open>IncidL C lBC\<close> \<open>IncidL I lBC\<close> \<open>\<not> IncidL Q lBC\<close>
betH_distincts colH_IncidL__IncidL colH_permut_312 by blast
moreover have "CongH C P C Q"
by (simp add: assms(14))
moreover have "CongH C I C I"
by (metis \<open>BetH I C B\<close> betH_distincts congH_refl)
ultimately show ?thesis
using \<open>CongaH P C I Q C I\<close>
using congH_permlr ncolH_expand th12 by presburger
qed
have "A = I \<longrightarrow> ?thesis"
using Bet_def \<open>BetH I C B\<close> bet_comm by blast
moreover {
assume "A \<noteq> I"
have "ColH I P Q"
by (simp add: \<open>BetH P I Q\<close> betH_colH colH_permut_213)
{
assume "BetH P A I"
hence "BetH Q I A"
using \<open>BetH P I Q\<close> betH_trans0 between_comm by blast
hence False
by (metis betH_expand \<open>BetH P A I\<close> \<open>CongH I P I Q\<close> assms(12)
betH_congH2__False congH_perms)
}
moreover {
assume "BetH P I A"
hence "BetH Q A I"
by (metis assms(1) assms(12) assms(2) assms(6) assms(7) betH_trans0
between_comm congH_colH_betH)
hence False
by (metis \<open>BetH P I A\<close> \<open>CongH I P I Q\<close> assms(12) betH_congH2__False
betH_distincts congH_permlr)
}
ultimately have ?thesis
by (metis \<open>A = I \<longrightarrow> Bet A B C \<or> Bet B C A \<or> Bet C A B\<close> \<open>BetH P I Q\<close>
assms(1) assms(12) assms(2) assms(6) betH2_out congH_colH_betH)
}
ultimately have ?thesis
by blast
}
moreover {
assume "BetH I B C"
have "CongaH P B I Q B I"
proof -
have "\<not> ColH C B P"
using \<open>\<not> ColH P B C\<close> colH_permut_321 by blast
moreover have "\<not> ColH C B Q"
using \<open>\<not> ColH Q B C\<close> colH_permut_321 by blast
moreover have "CongaH C B P C B Q"
using colH_permut_321 \<open>BetH P I Q\<close> \<open>ColH B I C\<close> assms(13)
assms(14) calculation(1) calculation(2) th17 by blast
moreover have "BetH C B I"
by (simp add: \<open>BetH I B C\<close> between_comm)
ultimately show ?thesis
using th14 by blast
qed
have "CongH I P I Q"
proof -
have "\<not> ColH B P I"
using \<open>BetH I B C\<close> \<open>IncidL B lBC\<close> \<open>IncidL I lBC\<close> \<open>\<not> IncidL P lBC\<close>
betH_distincts colH_IncidL__IncidL colH_permut_312 by blast
moreover have "\<not> ColH B Q I"
using \<open>BetH I B C\<close> \<open>IncidL B lBC\<close> \<open>IncidL I lBC\<close> \<open>\<not> IncidL Q lBC\<close>
betH_distincts colH_IncidL__IncidL colH_permut_312 by blast
moreover have "CongH B P B Q"
using assms(13) by auto
moreover have "CongH B I B I"
by (metis \<open>BetH I B C\<close> betH_distincts congH_refl)
ultimately show ?thesis
using \<open>CongaH P B I Q B I\<close>
by (metis \<open>IncidL I lBC\<close> \<open>\<not> IncidL Q lBC\<close> congH_permlr th12)
qed
have "A = I \<longrightarrow> ?thesis"
using Bet_def \<open>BetH I B C\<close> by blast
moreover
{
assume "A \<noteq> I"
have "ColH I P Q"
using \<open>BetH P I Q\<close> betH_expand colH_permut_213 by blast
{
assume "BetH P A I"
hence "BetH Q I A"
using \<open>BetH P I Q\<close> betH_trans0 between_comm by blast
hence False
by (metis betH_expand \<open>BetH P A I\<close> \<open>CongH I P I Q\<close> assms(12)
betH_congH2__False congH_permlr)
}
moreover
{
assume "BetH P I A"
hence "BetH Q A I"
by (metis assms(1) assms(12) assms(2) assms(6) assms(7)
betH_trans0 between_comm congH_colH_betH)
hence False
by (metis betH_expand \<open>BetH P I A\<close> \<open>CongH I P I Q\<close> assms(12)
betH_congH2__False congH_perms)
}
ultimately have ?thesis
by (metis \<open>A = I \<longrightarrow> Bet A B C \<or> Bet B C A \<or> Bet C A B\<close>
\<open>BetH P I Q\<close> assms(1) assms(12) assms(2) assms(6) betH2_out congH_colH_betH)
}
ultimately have ?thesis
by blast
}
ultimately have ?thesis
by (metis \<open>BetH P I Q\<close> \<open>ColH B I C\<close> \<open>ColH B P Q \<Longrightarrow> False\<close>
\<open>ColH C P Q \<Longrightarrow> False\<close> assms(5) between_col between_one colH_permut_213)
}
hence ?thesis
using \<open>IncidL B lBC\<close> \<open>IncidL C lBC\<close> \<open>IsL lBC\<close> \<open>cut' P Q B C\<close> cut'_def
local.cut_def by auto
}
moreover
{
assume "same_side' P Q B C"
have "outH B P Q"
proof -
have "\<not> ColH P B C"
by (simp add: \<open>\<not> ColH P B C\<close>)
moreover have "\<not> ColH C B P"
using calculation colH_permut_321 by blast
moreover have "CongaH C B P C B P"
by (simp add: calculation(2) conga_refl)
moreover have "CongaH C B P C B Q"
by (metis \<open>\<not> ColH Q B C\<close> assms(13) assms(14) assms(5) calculation(2)
colH_permut_213 colH_permut_312 congH_refl th18_aux)
moreover have "same_side' P P B C"
using calculation(2) colH_permut_213 same_side_prime_refl by blast
ultimately show ?thesis
using \<open>same_side' P Q B C\<close> cong_4_uniqueness by blast
qed
hence ?thesis
using \<open>\<not> ColH B P Q\<close> outH_expand by blast
}
ultimately have ?thesis
using \<open>\<not> ColH P B C\<close> \<open>\<not> ColH Q B C\<close> plane_separation_2D by blast
}
ultimately show ?thesis
using \<open>\<not> ColH B P Q\<close> \<open>\<not> ColH C P Q\<close> plane_separation_2D by blast
qed
lemma TS_upper_dim:
assumes "cut' A B P Q" and
"P \<noteq> Q" and
"A \<noteq> B" and
"A \<noteq> C" and
"B \<noteq> C" and
"A \<noteq> P" and
"A \<noteq> Q" and
"B \<noteq> P" and
"B \<noteq> Q" and
"C \<noteq> P" and
"C \<noteq> Q" and
"CongH A P A Q" and
"CongH B P B Q" and
"CongH C P C Q"
shows "Bet A B C \<or> Bet B C A \<or> Bet C A B"
proof -
obtain l where "IsL l" and "IncidL P l" and "IncidL Q l"
using assms(2) line_existence by blast
have "cut l A B"
using \<open>IncidL P l\<close> \<open>IncidL Q l\<close> \<open>IsL l\<close> assms(1) cut'_def by auto
have "ColH A P Q \<longrightarrow> ?thesis"
by (simp add: assms(10) assms(11) assms(12) assms(13) assms(14) assms(2)
assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9) col_upper_dim)
moreover
{
assume "\<not> ColH A P Q"
have "ColH B P Q \<longrightarrow> ?thesis"
by (metis assms(10) assms(11) assms(12) assms(13) assms(14) assms(2)
assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9) col_upper_dim)
moreover
{
assume "\<not> ColH B P Q"
obtain I where "IncidL I l" and "BetH A I B"
using \<open>local.cut l A B\<close> local.cut_def by blast
have "ColH P Q I"
using ColH_def Is_line \<open>IncidL I l\<close> \<open>IncidL P l\<close> \<open>IncidL Q l\<close> by blast
{
assume "P = I"
hence "ColH A Q B"
by (metis \<open>BetH A I B\<close> assms(12) assms(13) assms(3) assms(9) congH_permlr
congH_refl cong_preserves_col)
hence False
by (metis colH_permut_312 colH_trans colH_trivial121 \<open>BetH A I B\<close>
\<open>P = I\<close> \<open>\<not> ColH B P Q\<close> assms(3) between_col)
}
hence "P \<noteq> I"
by blast
{
assume "Q = I"
hence "ColH A P B"
by (metis \<open>BetH A I B\<close> assms(12) assms(13) assms(3) assms(6) assms(8)
assms(9) congH_perms congH_refl congH_sym cong_preserves_col)
have "ColH A P I"
by (metis \<open>BetH A I B\<close> \<open>ColH A P B\<close> assms(3) colH_trans ncolH_expand
outH_col outH_def)
hence False
using \<open>Q = I\<close> \<open>\<not> ColH A P Q\<close> by blast
}
hence "Q \<noteq> I"
by blast
have "CongaH I A P I A Q"
proof -
have "CongaH B A P B A Q"
proof -
have "\<not> ColH A B P"
by (metis (full_types) \<open>BetH A I B\<close> \<open>ColH P Q I\<close> \<open>P = I \<Longrightarrow> False\<close>
\<open>\<not> ColH A P Q\<close> colH_permut_312 colH_trivial121 inter_uniquenessH
outH_def outH_expand)
moreover have "\<not> ColH A B Q"
by (meson assms(12) assms(13) assms(3) assms(6) assms(7) assms(8)
assms(9) calculation congH_refl congH_sym cong_preserves_col_stronger)
moreover have "CongH A B A B"
using assms(3) congH_refl by blast
moreover have "CongH A P A Q"
by (simp add: assms(12))
moreover have "CongH B P B Q"
using assms(13) by auto
ultimately show ?thesis
using th18_aux by blast
qed
moreover have "outH A B I"
by (simp add: \<open>BetH A I B\<close> outH_def)
moreover have "outH A P P"
by (simp add: assms(6) outH_def)
moreover have "outH A B I"
by (simp add: calculation(2))
moreover have "outH A Q Q"
by (simp add: assms(7) outH_def)
ultimately show ?thesis
using conga_out_conga by fastforce
qed
have "CongH I P I Q"
proof -
have "\<not> ColH A I P"
by (metis \<open>ColH P Q I\<close> \<open>P \<noteq> I\<close> \<open>\<not> ColH A P Q\<close> colH_permut_231
colH_trans colH_trivial122)
moreover have "\<not> ColH A I Q"
using ColH_def \<open>IncidL I l\<close> \<open>IncidL P l\<close> \<open>IncidL Q l\<close> \<open>Q = I \<Longrightarrow> False\<close>
calculation inter_incid_uniquenessH by auto
moreover have "CongH A I A I"
using \<open>BetH A I B\<close> betH_distincts congH_refl by presburger
ultimately show ?thesis
using \<open>CongaH I A P I A Q\<close> assms(12)
using th12 by blast
qed
have "ColH A B C"
proof -
have "C = I \<longrightarrow> ?thesis"
by (simp add: \<open>BetH A I B\<close> between_col colH_permut_132)
moreover
{
assume "C \<noteq> I"
have "ColH A C I"
by (metis colH_permut_231 \<open>BetH A I B\<close> \<open>C \<noteq> I\<close> \<open>ColH P Q I\<close>
\<open>CongH I P I Q\<close> \<open>P \<noteq> I\<close> \<open>Q \<noteq> I\<close> assms(10) assms(11) assms(12) assms(14)
assms(2) assms(4) assms(6) assms(7) betH_to_bet bet_colH col_upper_dim)
hence ?thesis
using ColH_def IncidL_not_IncidL__not_colH \<open>BetH A I B\<close> betH_colH by blast
}
ultimately show ?thesis
by blast
qed
have "BetH A B C \<longrightarrow> ?thesis"
by (simp add: ColH_bets \<open>ColH A B C\<close>)
moreover have "BetH B C A \<longrightarrow> ?thesis"
using ColH_bets \<open>ColH A B C\<close> by blast
moreover have "BetH B A C \<longrightarrow> ?thesis"
by (simp add: ColH_bets \<open>ColH A B C\<close>)
ultimately have ?thesis
using ColH_bets \<open>ColH A B C\<close> by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
lemma cut'_comm:
assumes "cut' A B X Y"
shows "cut' B A X Y"
by (metis assms cut'_def cut_comm)
lemma TS_upper_dim_bis:
assumes "BetH P I Q" and
"BetH I B A" and
"P \<noteq> Q" and
"A \<noteq> B" and
"A \<noteq> C" and
"B \<noteq> C" and
"A \<noteq> P" and
"A \<noteq> Q" and
"B \<noteq> P" and
"B \<noteq> Q" and
"C \<noteq> P" and
"C \<noteq> Q" and
"CongH A P A Q" and
"CongH B P B Q" and
"CongH C P C Q"
shows "Bet A B C \<or> Bet B C A \<or> Bet C A B"
proof -
have "ColH A P Q \<longrightarrow> ?thesis"
by (simp add: assms(10) assms(11) assms(12) assms(13) assms(14) assms(15)
assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9) col_upper_dim)
moreover
{
assume "\<not> ColH A P Q"
have "ColH B P Q \<longrightarrow> ?thesis"
by (metis assms(10) assms(11) assms(12) assms(13) assms(14) assms(15)
assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9) col_upper_dim)
moreover
{
assume "\<not> ColH B P Q"
have "CongaH P B I Q B I"
proof -
have "P \<noteq> I"
using assms(1) betH_expand by blast
have "Q \<noteq> I"
using assms(1) betH_colH by blast
{
assume "ColH A B P"
have "\<not> ColH P Q A"
using \<open>\<not> ColH A P Q\<close> colH_permut_312 by blast
moreover have "ColH P Q P"
by (simp add: colH_trivial121)
moreover have "ColH P Q I"
by (simp add: assms(1) betH_colH colH_permut_132)
moreover have "ColH A B I"
by (simp add: assms(2) betH_colH between_comm)
ultimately
have "P = I"
using assms(4) \<open>ColH A B P\<close> inter_uniquenessH by blast
hence False
by (simp add: \<open>P \<noteq> I\<close>)
}
hence "\<not> ColH A B P"
by blast
moreover
{
assume "ColH A B Q"
have "\<not> ColH Q P A"
using \<open>\<not> ColH A P Q\<close> colH_permut_321 by blast
moreover have "ColH Q P Q"
by (simp add: colH_trivial121)
moreover have "ColH Q P I"
using assms(1) betH_colH colH_permut_312 by blast
moreover have "ColH A B I"
using assms(2) between_col colH_permut_321 by blast
ultimately
have "Q = I"
using assms(4) \<open>ColH A B Q\<close> inter_uniquenessH by blast
hence False
by (simp add: \<open>Q \<noteq> I\<close>)
}
hence "\<not> ColH A B Q"
by blast
moreover have "CongaH A B P A B Q"
proof -
have "\<not> ColH B A P"
using calculation(1) colH_permut_213 by blast
moreover have "\<not> ColH B A Q"
using \<open>\<not> ColH A B Q\<close> colH_permut_213 by blast
moreover have "CongH B A B A"
using assms(4) congH_refl by auto
ultimately show ?thesis
using assms(13) assms(14) th18_aux by presburger
qed
ultimately show ?thesis
by (simp add: assms(2) between_comm th14)
qed
have "CongH I P I Q"
by (metis assms(1) assms(10) assms(13) assms(14) assms(2) assms(7)
assms(8) assms(9) axiom_five_segmentsH between_comm between_only_one congH_refl)
have "ColH A B C"
proof -
have "ColH A B I"
by (simp add: assms(2) between_col colH_permut_321)
have "C = I \<longrightarrow> ?thesis"
using \<open>ColH A B I\<close> by blast
moreover
{
assume "C \<noteq> I"
have "ColH I B A"
by (simp add: assms(2) betH_colH)
hence "ColH A C I"
by (metis (mono_tags, lifting) betH_to_bet bet_colH colH_permut_213
colH_permut_312 \<open>C \<noteq> I\<close> \<open>CongH I P I Q\<close> assms(1) assms(11) assms(12)
assms(13) assms(15) assms(2) assms(5) assms(7) assms(8) col_upper_dim)
have "ColH P I Q"
by (simp add: assms(1) betH_colH)
hence ?thesis
by (metis betH_distincts colH_permut_312 colH_trans colH_trivial121
\<open>ColH A C I\<close> \<open>ColH I B A\<close> assms(2))
}
ultimately show ?thesis
by blast
qed
have "BetH B A C \<longrightarrow> ?thesis"
using ColH_bets \<open>ColH A B C\<close> by blast
hence ?thesis
using ColH_bets \<open>ColH A B C\<close> by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis by blast
qed
lemma upper_dim:
assumes "P \<noteq> Q" and
"A \<noteq> B" and
"A \<noteq> C" and
"B \<noteq> C" and
"Cong A P A Q" and
"Cong B P B Q" and
"Cong C P C Q"
shows "Bet A B C \<or> Bet B C A \<or> Bet C A B"
proof -
have "C = P \<and> C = Q \<longrightarrow> ?thesis"
using assms(1) by blast
have "B = P \<and> B = Q \<longrightarrow> ?thesis"
using assms(1) by blast
have "A = P \<and> A = Q \<longrightarrow> ?thesis"
using assms(1) by blast
have "CongH A P A Q"
using Cong_def assms(1) assms(5) by auto
have "CongH B P B Q"
using Cong_def assms(1) assms(6) by blast
have "CongH C P C Q"
using Cong_def assms(1) assms(7) by blast
have "A \<noteq> P"
using Cong_def assms(1) assms(5) by presburger
have "A \<noteq> Q"
using Cong_def assms(1) assms(5) by presburger
have "B \<noteq> P"
using Cong_def assms(1) assms(6) by force
have "B \<noteq> Q"
using Cong_def assms(1) assms(6) by presburger
have "C \<noteq> P"
using Cong_def assms(1) assms(7) by presburger
have "C \<noteq> Q"
using Cong_def assms(1) assms(7) by presburger
have "ColH A P Q \<longrightarrow> ?thesis"
by (simp add: \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>C \<noteq> P\<close> \<open>C \<noteq> Q\<close>
\<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>CongH C P C Q\<close> assms(1) assms(2) assms(3)
assms(4) col_upper_dim)
moreover
{
assume "\<not> ColH A P Q"
have "ColH B P Q \<longrightarrow> ?thesis"
by (metis \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>C \<noteq> P\<close> \<open>C \<noteq> Q\<close>
\<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>CongH C P C Q\<close> assms(1) assms(2) assms(3)
assms(4) col_upper_dim)
moreover
{
assume "\<not> ColH B P Q"
have "ColH C P Q \<longrightarrow> ?thesis"
by (metis \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>C \<noteq> P\<close> \<open>C \<noteq> Q\<close>
\<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>CongH C P C Q\<close> assms(1) assms(2)
assms(3) assms(4) col_upper_dim)
moreover
{
assume "\<not> ColH C P Q"
have "cut' A B P Q \<longrightarrow> ?thesis"
by (simp add: TS_upper_dim \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>C \<noteq> P\<close>
\<open>C \<noteq> Q\<close> \<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>CongH C P C Q\<close> assms(1)
assms(2) assms(3) assms(4))
moreover
{
assume "same_side' A B P Q"
have "cut' A C P Q \<longrightarrow> ?thesis"
using TS_upper_dim \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>C \<noteq> P\<close> \<open>C \<noteq> Q\<close>
\<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>CongH C P C Q\<close> assms(1) assms(2) assms(3)
assms(4) bet_comm by blast
moreover
{
assume "same_side' A C P Q"
{
assume "ColH P A B"
hence "ColH B P A"
by (simp add: colH_permut_312)
have "ColH A B Q"
by (meson \<open>A \<noteq> P\<close> \<open>B \<noteq> P\<close> \<open>ColH B P A\<close> \<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close>
assms(2) colH_permut_312 congH_refl cong_preserves_col_stronger)
hence False
by (metis \<open>ColH B P A\<close> \<open>\<not> ColH A P Q\<close> assms(2) colH_trans ncolH_distincts)
}
hence "\<not> ColH P A B"
by blast
{
assume "ColH Q A B"
hence "ColH A B P"
by (meson \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>CongH A P A Q\<close>
\<open>CongH B P B Q\<close> assms(2) colH_permut_231 congH_refl congH_sym
cong_preserves_col_stronger)
hence False
using \<open>\<not> ColH P A B\<close> colH_permut_312 by blast
}
hence "\<not> ColH Q A B"
by blast
{
assume "same_side' P Q A B"
have "outH A P Q"
proof -
have "\<not> ColH P A B"
by (simp add: \<open>\<not> ColH P A B\<close>)
moreover have "\<not> ColH B A P"
using calculation colH_permut_321 by blast
moreover have "CongaH B A P B A P"
using calculation(2) conga_refl by blast
moreover have "CongaH B A P B A Q"
by (metis \<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>\<not> ColH Q A B\<close> assms(2)
calculation(2) colH_permut_213 colH_permut_312 congH_refl th18_aux)
moreover have "same_side' P P A B"
using calculation(1) colH_permut_312 same_side_prime_refl by blast
ultimately show ?thesis
using \<open>same_side' P Q A B\<close>
using cong_4_uniqueness by blast
qed
hence ?thesis
using \<open>\<not> ColH A P Q\<close> outH_expand by blast
}
moreover
{
assume "cut' P Q A B"
obtain lAB where "IsL lAB" and "IncidL A lAB" and "IncidL B lAB"
using assms(2) line_existence by blast
then obtain I where "IncidL I lAB" and "BetH P I Q"
using \<open>cut' P Q A B\<close> cut'_def local.cut_def by auto
hence "ColH A I B"
using ColH_def \<open>IncidL A lAB\<close> \<open>IncidL B lAB\<close> \<open>IsL lAB\<close> by auto
{
assume "BetH A I B"
obtain lPQ where "IsL lPQ" and "IncidL P lPQ" and "IncidL Q lPQ"
using assms(1) line_existence by blast
hence "\<not> cut lPQ A B"
using \<open>same_side' A B P Q\<close> same_side'_def same_side_not_cut by auto
have "cut lPQ A B"
proof -
have "\<not> IncidL B lPQ"
using Hilbert_neutral_dimensionless_pre.ColH_def \<open>IncidL P lPQ\<close>
\<open>IncidL Q lPQ\<close> \<open>IsL lPQ\<close> \<open>\<not> ColH B P Q\<close> by fastforce
moreover have "IncidL I lPQ"
using \<open>BetH P I Q\<close> \<open>IncidL P lPQ\<close> \<open>IncidL Q lPQ\<close> assms(1)
betH_line inter_incid_uniquenessH by blast
ultimately show ?thesis
using \<open>BetH A I B\<close>
using Is_line \<open>ColH A I B\<close> betH_distincts colH_IncidL__IncidL
local.cut_def by blast
qed
hence False
using \<open>\<not> local.cut lPQ A B\<close> by blast
hence ?thesis
by blast
}
moreover have "BetH I B A \<longrightarrow> ?thesis"
using TS_upper_dim_bis \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>BetH P I Q\<close>
\<open>C \<noteq> P\<close> \<open>C \<noteq> Q\<close> \<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>CongH C P C Q\<close>
assms(1) assms(2) assms(3) assms(4) by blast
moreover have "BetH I A B \<longrightarrow> ?thesis"
using TS_upper_dim_bis \<open>A \<noteq> P\<close> \<open>A \<noteq> Q\<close> \<open>B \<noteq> P\<close> \<open>B \<noteq> Q\<close> \<open>BetH P I Q\<close>
\<open>C \<noteq> P\<close> \<open>C \<noteq> Q\<close> \<open>CongH A P A Q\<close> \<open>CongH B P B Q\<close> \<open>CongH C P C Q\<close>
assms(1) assms(2) assms(3) assms(4) bet_comm by blast
ultimately have ?thesis
by (metis \<open>BetH P I Q\<close> \<open>ColH A I B\<close> \<open>\<not> ColH A P Q\<close> \<open>\<not> ColH B P Q\<close>
assms(2) betH_colH between_one colH_permut_213)
}
ultimately have ?thesis
using \<open>\<not> ColH P A B\<close> \<open>\<not> ColH Q A B\<close> plane_separation_2D by blast
}
ultimately have ?thesis
using \<open>\<not> ColH A P Q\<close> \<open>\<not> ColH C P Q\<close>
\<open>cut' A C P Q \<longrightarrow> Bet A B C \<or> Bet B C A \<or> Bet C A B\<close>
\<open>same_side' A C P Q \<Longrightarrow> Bet A B C \<or> Bet B C A \<or> Bet C A B\<close>
plane_separation_2D by blast
}
ultimately have ?thesis
using \<open>\<not> ColH A P Q\<close> \<open>\<not> ColH B P Q\<close> plane_separation_2D by blast
}
ultimately have ?thesis
by blast
}
ultimately have ?thesis
by blast
}
ultimately show ?thesis
by blast
qed
interpretation H2D_to_T2D : Tarski_2D
where Bet = Bet and
Cong = Cong and
TPA = PP and
TPB = PQ and
TPC = PR
proof
show "\<forall>a b. Cong a b b a"
by (simp add: cong_permT)
show "\<forall>a b p q r s. Cong a b p q \<and> Cong a b r s \<longrightarrow> Cong p q r s"
using cong_inner_transitivity by blast
show "\<forall>a b c. Cong a b c c \<longrightarrow> a = b"
by (simp add: cong_identity)
show "\<forall>a b c q. \<exists>x. Bet q a x \<and> Cong a x b c"
by (simp add: segment_construction)
show "\<forall>a b c d a' b' c' d'. a \<noteq> b \<and> Bet a b c \<and> Bet a' b' c' \<and>
Cong a b a' b' \<and> Cong b c b' c' \<and> Cong a d a' d' \<and> Cong b d b' d' \<longrightarrow>
Cong c d c' d'"
using five_segment by blast
show "\<forall>a b. Bet a b a \<longrightarrow> a = b"
by (simp add: bet_identity)
show "\<forall>a b c p q. Bet a p c \<and> Bet b q c \<longrightarrow> (\<exists>x. Bet p x b \<and> Bet q x a)"
proof -
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"Bet a b c \<or> Bet b c a \<or> Bet c a b"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
using Bet_def bet_comm bet_trans by metis
}
moreover
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"\<not> (Bet a b c \<or> Bet b c a \<or> Bet c a b)" and
"a = p \<or> p = c \<or> b = q \<or> q = c"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
by (metis Hilbert_neutral_dimensionless_pre.Bet_def bet_comm)
}
moreover
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"\<not> (Bet a b c \<or> Bet b c a \<or> Bet c a b)" and
"a \<noteq> p" and "p \<noteq> c" and "b \<noteq> q" and "q \<noteq> c"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
using pasch_general_case by blast
}
ultimately show ?thesis
by blast
qed
show "\<not> Bet PP PQ PR \<and> \<not> Bet PQ PR PP \<and> \<not> Bet PR PP PQ"
using lower_dim_l by blast
show "\<forall>a b c p q.
p \<noteq> q \<and> Cong a p a q \<and> Cong b p b q \<and> Cong c p c q \<longrightarrow>
Bet a b c \<or> Bet b c a \<or> Bet c a b"
by (metis Bet_def upper_dim)
qed
end
context Hilbert_neutral_3D
begin
interpretation H3D_to_T3D : Tarski_3D
where Bet = Bet and
Cong = Cong and
TPA = PP and
TPB = PQ and
TPC = PR and
TS1 = HS1 and TS2 = HS2 and TS3 = HS3 and TS4 = HS4
proof
show "\<forall>a b. Cong a b b a"
using cong_permT by blast
show "\<forall>a b p q r s. Cong a b p q \<and> Cong a b r s \<longrightarrow> Cong p q r s"
using cong_inner_transitivity by blast
show "\<forall>a b c. Cong a b c c \<longrightarrow> a = b"
by (simp add: cong_identity)
show "\<forall>a b c q. \<exists>x. Bet q a x \<and> Cong a x b c"
by (simp add: segment_construction)
show "\<forall>a b c d a' b' c' d'. a \<noteq> b \<and> Bet a b c \<and> Bet a' b' c' \<and>
Cong a b a' b' \<and> Cong b c b' c' \<and> Cong a d a' d' \<and> Cong b d b' d' \<longrightarrow>
Cong c d c' d'"
using five_segment by blast
show "\<forall>a b. Bet a b a \<longrightarrow> a = b"
using bet_identity by blast
show "\<forall>a b c p q. Bet a p c \<and> Bet b q c \<longrightarrow> (\<exists>x. Bet p x b \<and> Bet q x a)"
proof -
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"Bet a b c \<or> Bet b c a \<or> Bet c a b"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
using Bet_def bet_comm bet_trans by metis
}
moreover
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"\<not> (Bet a b c \<or> Bet b c a \<or> Bet c a b)" and
"a = p \<or> p = c \<or> b = q \<or> q = c"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
by (metis Hilbert_neutral_dimensionless_pre.Bet_def bet_comm)
}
moreover
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"\<not> (Bet a b c \<or> Bet b c a \<or> Bet c a b)" and
"a \<noteq> p" and "p \<noteq> c" and "b \<noteq> q" and "q \<noteq> c"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
using pasch_general_case by blast
}
ultimately show ?thesis
by blast
qed
show "\<not> Bet PP PQ PR \<and> \<not> Bet PQ PR PP \<and> \<not> Bet PR PP PQ"
using lower_dim_l by blast
show "\<nexists>X. (Bet HS1 HS2 X \<or> Bet HS2 X HS1 \<or> Bet X HS1 HS2) \<and>
(Bet HS3 HS4 X \<or> Bet HS4 X HS3 \<or> Bet X HS3 HS4) \<or>
(Bet HS1 HS3 X \<or> Bet HS3 X HS1 \<or> Bet X HS1 HS3) \<and>
(Bet HS2 HS4 X \<or> Bet HS4 X HS2 \<or> Bet X HS2 HS4) \<or>
(Bet HS1 HS4 X \<or> Bet HS4 X HS1 \<or> Bet X HS1 HS4) \<and>
(Bet HS2 HS3 X \<or> Bet HS3 X HS2 \<or> Bet X HS2 HS3)"
using coplanar_plane1 lower_dim_3 by blast
show "\<forall>A B C P Q R. P \<noteq> Q \<and> Q \<noteq> R \<and> P \<noteq> R \<and> Cong A P A Q \<and>
Cong B P B Q \<and> Cong C P C Q \<and> Cong A P A R \<and> Cong B P B R \<and> Cong C P C R \<longrightarrow>
Bet A B C \<or> Bet B C A \<or> Bet C A B"
using tarski_upper_dim plane_intersection lower_dim_3 by blast
qed
end
context Hilbert_euclidean
begin
interpretation Heucl_to_Teucl : Tarski_Euclidean
where Bet = Bet and
Cong = Cong and
TPA = PP and
TPB = PQ and
TPC = PR
proof
show "\<forall>a b. Cong a b b a"
using cong_permT by blast
show "\<forall>a b p q r s. Cong a b p q \<and> Cong a b r s \<longrightarrow> Cong p q r s"
using cong_inner_transitivity by blast
show "\<forall>a b c. Cong a b c c \<longrightarrow> a = b"
by (simp add: cong_identity)
show "\<forall>a b c q. \<exists>x. Bet q a x \<and> Cong a x b c"
by (simp add: segment_construction)
show "\<forall>a b c d a' b' c' d'. a \<noteq> b \<and> Bet a b c \<and> Bet a' b' c' \<and>
Cong a b a' b' \<and> Cong b c b' c' \<and> Cong a d a' d' \<and> Cong b d b' d' \<longrightarrow>
Cong c d c' d'"
using five_segment by blast
show "\<forall>a b. Bet a b a \<longrightarrow> a = b"
using bet_identity by blast
show "\<forall>a b c p q. Bet a p c \<and> Bet b q c \<longrightarrow> (\<exists>x. Bet p x b \<and> Bet q x a)"
proof -
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"Bet a b c \<or> Bet b c a \<or> Bet c a b"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
using Bet_def bet_comm bet_trans by metis
}
moreover
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"\<not> (Bet a b c \<or> Bet b c a \<or> Bet c a b)" and
"a = p \<or> p = c \<or> b = q \<or> q = c"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
by (metis Hilbert_neutral_dimensionless_pre.Bet_def bet_comm)
}
moreover
{
fix a b c p q
assume "Bet a p c" and "Bet b q c" and
"\<not> (Bet a b c \<or> Bet b c a \<or> Bet c a b)" and
"a \<noteq> p" and "p \<noteq> c" and "b \<noteq> q" and "q \<noteq> c"
hence "\<exists>x. Bet p x b \<and> Bet q x a"
using pasch_general_case by blast
}
ultimately show ?thesis
by blast
qed
show "\<not> Bet PP PQ PR \<and> \<not> Bet PQ PR PP \<and> \<not> Bet PR PP PQ"
using lower_dim_l by blast
show "\<forall>A B C D T. Bet A D T \<and> Bet B D C \<and> A \<noteq> D
\<longrightarrow> (\<exists>X Y. Bet A B X \<and> Bet A C Y \<and> Bet X T Y)"
using tarski_s_euclid euclid_uniqueness by blast
qed
end
end
|
3rd & U Cafe is a restaurant and cafes cafe. They serve all organic and fair trade coffee (from http://www.tonyscoffee.com/ Tonys Coffee and Teas) and have two 50inch flatscreen TVs.
The cafΓ© serves breakfast, lunch and dinner, including hamburgers, sandwiches deli sandwiches, and coffee. They also have a vegetarians vegetarianfriendly menu. The 3rd & U Cafe also serves beer and has a nice two for five dollars deal for beer that is all day long.
Still new in town, hopefully they will still be friendly to folks who just want to have some coffee and study spots study for a couple hours. They have free WiFi Hotspots wifi. The owners stated that there is seating for 68 people inside and 33 people outside.
The opening was delayed for months causing much speculation. There is a http://media.www.californiaaggie.com/media/storage/paper981/news/2007/08/23/CityNews/CafRoma.Location.To.Be.Taken.Over.By.New.3rd.U.Caf2935198.shtml California Aggie article dated Aug. 23 with some details (lets integrate the information into this page). A California Aggie http://media.www.californiaaggie.com/media/storage/paper981/news/2007/10/30/CityNews/Third.And.U.Cafeacute.To.Open.In.December3064225.shtml article dated October 30, 2007, says the cafe would open in December. There is another Aggie http://www.californiaaggie.com/news/2008/01/24/CityNews/Owners.Say.3rd.And.U.Cafeacute.Expected.To.Open.Next.Week3165562.shtml article that says that it would open before the end of January 2008. The Cafe opened March 14th, 2008.
The space they occupy was once inhabited by the late, great, Cafe Roma CafΓ© Roma. The CafΓ© Roma era inside stage was dismantled, as the managers have no plans to host live music. They do, however, hope to feature live DJs eventually.
Above this place sits the less than accommodating Roma Apartments.
On or just before November 3, 2011 their liquor license was suspended indefinitely. An article from the http://www.theaggie.org/2011/11/14/cafeisleftdryfollowingliquorlicensesuspension/ Aggie seems to suggest that it was suspended for failure to pay taxes.
As of 11/16/2011, the license was reinstated and alcohol is once again being served.
Specials
Beer is ALWAYS 2 pints for $5.25 (+tax), but there are other special deals as well!
Order a combo meal w/drink and receive endless fries, any day of the week! No sharing please :)
Happy Hour
3 PM 6:30 PM, Monday Friday.
Substantial happy hour food menu includes fries for $1.
ThursFri: 3 pints for $6.50 (+tax) After 8 PM!
Older comments can be found in the /Comment Archive comment archive.
20090113 12:30:11 nbsp geez some of you people are so picky. the food is relatively cheap and what ive had so far has all been pretty good. if you want a quiet place to study go to the library. if you dont like the atmosphere of a sports bar, then dont go. its really that simple. Users/fakeplastictrees
20090213 09:46:35 nbsp I really enjoyed the atmosphere around 1ish had soccer on one of their TVs, and their philly cheeses steak wasnt bad. Going there again later this week... Users/LizMelack
20090227 08:12:04 nbsp This place has the best location in Davis but poor execution. Why do places like Peets, Ciocolat, and Mishka overflow at all hours, while this place site empty? I think it needs a much warmer atmosphere (add a rug, replace the uncomfortable metal chairs), no TVs (this place is not a sports bar and the room is too small to not feel like the tvs are overwhelming) and more seating. Make some changes to make it more of a hangout place, run a really cheap lunch special and coffee special at night for a month or so to bring people in, and this place could really take offf. Users/jsg718
20090305 22:55:23 nbsp We ABSOLUTELY LOVE 3rd & U!! Friendly service and AMAZING food! Highly recommend the breakfast sandwiches, turkey club, pomadoro sandwich, happy hour menu, and basically everything! The food is reasonably priced too! Everything is wonderful about this place and we hope the word catches on! Users/millergirls
20090306 00:17:13 nbsp It looks like this place is doing much better since they got their alcohol license. At least...it did for a week or two. Ive noticed that it was both OPEN and FULL on many recent evenings, although it looks like everyone there is going for the alcohol, not the food. The past few nights, it does not seem to have remained open, so Im not sure when they are open and when they are not. But it is nice to see that they are at least staying open on some evenings now... Users/IDoNotExist
20090307 10:23:25 nbsp this place is great the food is good, the beer is cheap (2 for $5), and all of the employees are super nice. Users/leiris
20090308 08:45:52 nbsp jsg718 you clearly have no idea what youre talking about. I could list of so many reasons why youre wrong but this places success speaks for itself. Not only is it great that I can walk just two minutes off campus after a hard midterm to grab a cold beer, but I can grab two for five dollars (good beers too!). Also, the millergirls in the post above are right. Every food item taste amazingthey also have a great vegetarian menu. Above all else is the prices of this cafe however like MatthewPearson said on the first post: they do a great job of targeting student budgets. Everything is priced incredibly reasonably, and everyone who works there is very friendly. Thanks 3rd and U! Users/HanSolo
20090312 22:32:49 nbsp I was there last friday. My friends and I have been a fan in the past. We think for the amount of food for the price is the best in Davis...way better then the CoHo. We come now more than ever...ALL DAY/EVERYDAY BEER SPECIAL (2 BEERS FOR $5), need we say more. They have a good selection a beer...they are all 2 for $5. I came by after class last friday the place was packed and the food was fantastic. I thinkn the word is out about this place. I had the burger...juicy burger, toasted buns, great flavor...ONE OF THE BEST BURGERS I HAVE EVER HAD. Most of the students were taking advantage of the HAPPY HOUR food specials. A few guys sitting next to me got the hot wings...I thought they were going to die. They said that they were the BEST WINGS IN TOWN. It seems like with all the food and drink specials...this is the place to eat and hang out after class, before you go out for a night on the town. WE LOVE 3rd & U!!! Users/davisdan
20090318 19:50:42 nbsp As long as the beer stays cheap, 3rd & U is my favorite place in town! Users/BT
20090403 18:15:49 nbsp Life is meaningless without BEER and BURGERS and PLASMA SCREEN TVs! Who cares about studying? Who cares about aesthetics? Who cares about where the food comes from, or why its cheap? This place makes life MEANINGFUL! COME TO THIS PLACE IF YOU WANT MEANING IN YOUR LIFE!!! Users/ZacharyNorwood ZN
20090423 19:10:23 nbsp Ive read that there is a Happy Hour Specials Happy Hour in the comments here, which would be great to put in the main article. Can anyone recall between which hours it is happy hour? Users/RyanMikulovsky
20090729 11:49:21 nbsp One of the girls that works here is extremely unpleasant. Every time I go in, she is frowning and slouching about. God forbid she takes your ordershe makes it seem as though the customer is a constant inconvenience. Love the food, but she is a real downer. Users/desiree
20090825 15:11:21 nbsp I dont understand why a restaurant with an espresso machine, in a prime location next to campus doesnt want to make business off of the caffeine addicts that are the staff, students and faculty of U.C Davis. They dont seem to open at a consistent time in the morning and then dont have any morning bagels or muffins. If they really just want to be a lunch place then dont bother saying that you open at 8 in the morning when you arent consistently open at 8am. But for the location, it really is a shame. Users/Butterfly
Especially now that the CoHo just got downsized! Users/jsogul
20090918 16:54:38 nbsp First time here today for lunch. I never considered going here until I was having lunch with a friend who works near there. The service was great. Friendly and fast. I had a sandwhich and the bread was so fresh. I also like that they serve a whole grain bread instead of just wheat. I will be back for sure. Users/LokiAbbi
20090928 02:14:58 nbsp ZN,
I dont think your response to ct on this page is very fair. I think ct was commenting on exactly what you say that he failed to address: that the effects of βtrendsβ on our times are hard to determine without the kind of retrospective benefit we have with respect to βclassical cultureβ. Whether our era really devalues humanities or not obviously cannot be settled by quoting a number of articles. I think he was trying to address the fact that what is considered βhigh cultureβ and part of academic canon was once what was considered popular culture that you seem to believe is inherently inferior in value somehow. Like ct said, itβs not fair to compare the products of our current popular culture, which are still evolving, to βclassic cultureβ which is composed of works that have stood the test of time. If you look at classic cinema, like Hitchcock or Welles, a relatively modern phenomenon but having had enough time to filter out some gunk, it is easy to see their consistency in quality. Rather than thinking that there has been some sort of watering down of our culture, you might think that Manβs genius has simply found a different expression.
By the way, I dont think ct was trying to defend our current culture. Rather, I think he was trying to critique the way your argument was presented. By saying the βexpressionβ of your argument is hyperbolic, you are making it sound as though your argument is sound at heart, and only accentuated with strong words for an impact, when as a matter of fact, you are simply making sweeping generalizations and claims that are impossible to prove or defend. Whatβs more, you canβt draft βvaluesβ into a critique of modern culture the way you are using them now. No one would argue that philosophy or history are no longer important to our culture. In fact, I bet the good professors at the UC Davis Philosophy Department could get together and create a video game that convey these values to the audience, if they tried. Just because there has been a shift in the preferred cultural medium from print to visual, it does not necessarily mean there has been a drop in our cultureβs βcontentsβ, when you take into consideration that there has not yet been yet time enough to make the good works of our times βclassicsβ yet. I think it was along these lines that ct was making his case, and you have made no effort to answer the kind of questions raised here. You sound like a philosophy major, so I am surprised that you are deliberately distorting ctβs argument to make it easier to attack instead of addressing his critique fairly. Users/Kyonghwa
Hrm. Thanks for your input. You make some broad counterassertions and say Ive simply distorted cts arguments, rather than address them directly, and believe my response unfair. I find this ironic, since ct began with a number of oracular, demeaning remarks about what he thought I was arguing, rather than addressing my position directly (vis negative influence of bourgeoisindustrial, mercantile, utilitarianvalues on the local University scene, the values of the Academy, and so forth; the loss of Roma to a venue very different in style and demographic appeal, etc.). My position, not by intention, then digressed into other areas, after ct suggested I had no evidential support for my arguments; this got me into citing articles about the devaluation of the humanities and the rise of bourgeois values (and it is important to note that since I cited support for my position, things have only gotten worse; many other articles now reinforce my views, such as those from the Chronicle of higher education on the poor job market for humanities students). You say Iβm unfair, yet you seem to hold double standards for ct and yourself. E.g., you overlook the unfairness of cts argument that the value of Shakespeare is somehow lessened by bearbating nextdoor, which is patently fallacious and misleading for three reasons: (a) it doesnβt directly address my argument, which was centered around a hierarchy of value visavis the decadence of certain modes of culture or being, a hierarchy presupposing an objective framework for value, not a culturally relative framework; (b) the argument applies equally as much to support my position, at least when we help it out with the principle of charity, namely, that less valuable cultural modes can overrun and oppress the more valuable types (and to this I was charged with elitism, if I recall; but of course if I was an elitist, I wouldnt be putting effort into debating on a wiki); and (c) it can easily be shown fallacious by analogy, i.e., todays artistic productions are bad because we also have tobacco companies nearby (a red herring if I ever saw one). And there are other, equally fallacious arguments I will not address. And re: some of your input, which I appreciate on some levels, I would certainly tell philosophy professors at UCD that their own line of work is devalued, and many (if not most!) of them would agree. But theres irony to be found in your defensive examples as well: though I never made the claim that there was no significant value in contemporary or modern art, philosophy, etc., you implied as much by suggesting I overlooked valued contemporary and modern art (how is that not unfair?). You cite Welles and Hitchcock as counterexamples of an argument I never made, yet of course I would agree that some of their works are artistically valuable. But as I said, this was not my argument, and its offtopic, to boot. Another irony embedded within your offtopic defense, since you brought it up, is the profound influence of Shakespeare on Wells; and arguably, what has made many of Hitchcocks films so compelling is their critique of bourgeois values, such as complacency and fear of alternative values, as in The Birds, as well as the corruption of wealth in a number of his other films, such as Strangers on a Train. Anyway, no I was not a philosophy major, though of course I value philosophy very much. Cheers. ZN
20091229 16:12:13 nbsp I love coming here for lunch in between classes. I usually order a teriyaki burger, but with chicken instead of beef. Although this isnt on the menu, they never fail. It is my FAVORITE sandwich in Davis. The fries are good here too, always hot and fresh. Salads seem worth the money too, because they are very large and have nice toppings. I see a lot of people get beer here, cuz they have a 2 pints for $5 thing. The servers are always very sweet and helpful as well. Users/BrookeB
20100117 09:00:27 nbsp Probably has the tastiest sandwiches a reasonable walking distance from campus. Oddly enough theyre fresh made, hot, and about the same price as Sodexho branded sandwiches or Panini Time! But these are so much better and certainly more filling: eggplant sandwich, Chicken Pomidori, etc.. Users/RyanMikulovsky
20100318 18:21:41 nbsp I have to agree with the unusual opening and closing times. I went here to get a latte once before class around 10:00am and they werent open? Lunch is always really good. Sometimes the portions arent worth the price, ie. ill still be hungry after just a sandwich but i dont want to make it a $9 meal through to combo to be full. Anyways, I have tried almost everything here and cant complain about a single thing. The bacon avocado sandwich will always be my favorite, they make a good burger too, at a better price than burgers and brew. More breakfast options and consistent opening/closing times would make this place one of the best in Davis Users/cj2012aggie
20100610 00:17:19 nbsp Amazing place. Cheap, great panninis (even veggie option is good). Good beer for a great price. Cool owners. Cool people. Try it out! Users/DP2010
20100621 14:02:19 nbsp Maybe this isnt worth posting. If you think so, go ahead and delete it.
I came in asking about the World Cup, but I got a pretty weak response. I asked When are you showing World Cup games? and was told When theyre on. right.
Oh, we dont show the 7 oclock games, except this Wednesday. Well, I was wondering when I could see them because youre closer to me than the Grad, but they show them three times a day. Oh The Grad rolls eyes
...
So, I just got frustrated and decided Id just keep going to the Grad, even though I kind of hate that place. Isnt it simple enough to have your World Cup schedule nicely organized for potential customers to review? Again, probably not worth posting about this but then again, maybe some of us can put together a wiki page for the World Cup, so people will know where they can watch it. Users/drpottsiv
20100702 15:55:03 nbsp I LOVE 3rd & U! I go there all the time! Great food. Evidently the beer is really cheap (Im only 20) and the people that work there are so nice! Everyone always seems happy to be there! Eat outside or inside. Fast service. The bar facing the TVs are great for sports like now when the FIFA world cup is playing. I go on lunch dates with friends and with my mom every now and then. Never had a bad experience! Users/sportschik130
20100805 22:20:30 nbsp This place has a great patio and good 2/$5 beers all day so I keep coming back even though they are ridiculously understaffed, regardless of crowd or time of day. World cup, every seat taken, 2 people cooking and 2 people working the restaurant, 45 minutes to get your food. Average evening, a few tables taken, 1 person cooking and 1 person working the restaurant, 20 minutes to get a sandwich. When the 1 person is working the register, nobody is pouring beers or bringing out food and it just sits back there for awhile until they abandon the line to bring out some food. While being understaffed is not the fault of the employees, they often get orders wrong or mixed up. 2 eggplant paninis, never asked what bread we wanted, and one came out on focaccia and one came out on sliced wheat. ?
And whoever made the decision to rip down the CAFE sign and replace it with the new 3rd & U sign... made a very bad decision.
Users/SRB
20100910 21:35:44 nbsp they have big banners in and outside the store advertising 3 beers for $6 from 811pm, however the place closes around 9pm or earlier and they are not offering this deal. asked for it and the person working there said sorry were not doing that, the manager didnt want to take the sign down. they seem to close around 89pm so probably dont try going there without calling ahead if its after 8. they do have cheap beer when they are open two for $5 is solid. take down those ads until youre ready to put your money where your mouth is! Users/BenJohnson
20100912 13:12:45 nbsp I went here Friday around 6:30p for a friends birthday. We went hoping for yummy dinner and drinks. I was exhausted from working all day and needed a coffee. The counter girl told me, Oh, Im sorry, we stop serving coffee at a certain time. Really? The word Cafe is in your title. Needless to say I was really bummed. So, I ordered my dinner. I couldnt have coffee so I opted for soup. The counter girl told me, Oh, Im sorry, we dont serve soup in the summer. Really? Then take it OFF your menu. I ended up with my 3rd choice of vegetarian sandwich. It was dry and okay. When it was time for a copy of my receipt the machine ran out of paper. Rough day for 3rd and U Cafe. I didnt get anything I wanted. Users/EricaMacGregor
When this space was Cafe Roma, it may have been a tad scruffy and furnished with thrift store specials, but the student staffers had the focus right on: the customer comes first and is right. They were involved, could make decisions and would have made the situation right as far as serving coffee, making soup or keeping the cash register supplied with paper on their own initiative. 3rd and U sounds like a much more topdown oriented establishment managementwise with employees not able to take initiative on their own. Users/BrianOrr
20100916 21:32:16 nbsp I love this place! They have the best chicken tacos at happy hour, the best turkey deli sandwiches on Village Bakery ciabatta bread, tasty hot wings, great beer prices, huge salads AND AMAZING prices! Check it out! Users/Barley123
20101010 15:38:47 nbsp Fairly good, not exceptional. Good sandwiches, cheap prices, fast prices, and close enough to campus that you can go here for an hour lunch break and not worry about making it back for class on time. Users/JennyAdler
...cheap prices, fast prices..., I like that, sounds like the beginning of a country song. But what could fast prices be? Do they play fast and loose with your money before giving you your change? So fast and loose, you feel like they pulled a fast one on you? Ah, yes, life in the fast lane, where even the prices are fast these days in Davis. Oh, for the bygone days of Cafe Roma, where things werent so fast, and the stress was less, and the students working the counter friendly and always fast with a witty, sometimes priceless comment while taking all the time in the world to slowandeasily pass the time of day with you. Users/BrianOrr
20101112 19:08:31 nbsp if you want service and respect do not eat at 3rd and U. they are rude to their customers, do not take customer complaints seriously and disrespectful. I highly recommend staying away from this cafe. Users/MattMacFarlane
20110217 16:58:06 nbsp Wait... they raised the prices on the 2 for $5 beers? BOYCOTT! (Just kidding... I love this place. Even though its still a great deal, 2 for $5.25 plus tax just doesnt inspire the same excitement in me.) Users/jsogul
20110324 20:35:48 nbsp Walked in there and tried to order coffee, the employee completely ignored me until I left. Users/sundeimasu
20110401 22:45:53 nbsp NEVER AGAIN. I will start this by saying one of my buddies loves this place, knows all the workers, gets great service. He moved and so I havent been here in a while until yesterday. For starters, the beer selection is complete shit. When I arrived I had the choice of sudwerks pilsner (ok), newcastle (no thanks), some cider crap (who the hell stocks a bar with cider when you have such a limited selection of beer?), AND WAIT FOR IT... FOSTERS. The person who ordered fosters should be shot. I didnt even know they still made that beer. Who the hell goes to a bar and asks, do you guys carry fosters? NOBODY does this. Anyways, I guess it isnt that big of a deal, since I can drink sudwerks. Got the 2 for 5.25 special, not too shabby. Go back for my second beer and they are out of the pilsner. WTF. Selection went down to Newcastle, cider crap, and blue moon. I also wanted to order a chicken caesar salad but apparently they dont serve salad at 6:30pm. Terrible, terrible beer selection, terrible service, and constantly out of stuff or dont serve it at random times. The staff is completely unapologetic as well. The food is just okay, I have never had anything there I would consider good and the prices are not good, besides the 2 for 5.25 beers but I hope you enjoy the shitty selection. I will never go back here. Users/MMAC
20110404 20:15:49 nbsp Good food, good service, a large patio, and cheap beer. My favorite spot in the spring and summer time. Users/ALo
20110430 19:10:04 nbsp The first time I went here I found a twist tie in my burger. When I brought it to the attention of the person working the counter he said, thanks for letting us know and walked away. Ive been going back ever since hoping to find more crazy crap in my food. Bang up job guys. Users/JohnHammerhead
20110510 18:32:44 nbsp Every time I have eaten here the food has been more than just edible and exactly at the right price. And I know first hand how shitty customers can be when you work in the food industry. Despite my overall, personal pleasant experience with the staff, the food and the atmosphere of the cafe...I have noticed some very frazzled male workers who quite frankly arent professional at all. Cursing in front of a full cafe to your coworkers and especially customers (although I know sometimes quite frankly they totally deserve it) is really not appropriate. I like this place and I want it to do well, but some individuals employed at the cafe should practice restraint, breathe and relax a little. I was really taken aback by an employee yelling and cursing at another employee whom was cashiering a rather lengthy line of people. It was uncalled for and I left really disappointed for the first time in the behavior of an employee rather than a customer. Aside from that uncomfortable sight, the food is excellent and is the reason I will continue to come back to the cafe; so long as no one curses at me because they have no stress management skills. haha Users/kann
20110510 19:03:16 nbsp Pros:
Good fries. Garlic fries, buffalo fries, etc. Yum.
Nice location.
Cons:
Cheap prices for beer doesnt mean much if there are only four (usually crappy) choices.
They dont enforce the smoking law. Recently we were stuck next to a table of people on the patio who were chainsmoking the whole time we were there for at least an hour. Waiters passed by/served that table several times and clearly didnt mention anything. I didnt ask the manager to enforce it but that shouldnt really be my responsibility. Maybe next time I will.
Not sure why everybody is raving about the vegetarian menu. Your choices are either fries, an overpriced Boca burger, or a quesadilla. Users/MeggoWaffle
20110523 12:13:24 nbsp Tried to go to the breakfast buffet on Sunday around 10:45 or 11 and the restaurant was completely dark/closed/abandoned, you name it. This was pretty disappointing to us as we were planning on joining friends and enjoying a relaxing meal with mimosas and a hockey game. It seems if theyre going to be open or closed at will, they shouldnt keep posted hours and keep a sign up saying Please call for availability. Other than this disappointment, Ive had only positive experiences here. You certainly cant beat the beer prices. Users/B.Egan
20110606 20:44:49 nbsp Over all, I really like this place. But the last two times I have been there, they have gotten my order wrong. I cant eat mayonnaise and I ordered a sandwich without it, when I got the sandwich he set it down in front of me and told me it had no mayo, but when I opened it up, it looked like they had put mayo on there and just scraped it off when they realized it was wrongβand not even well..there was still some blobs of mayo on the bread! Not good enough, some people omit certain things for health reasons and it is frustrating that I have had to wait an extra long time to get my correct order while all of my friends are eating. Hopefully next time I come it will be better, as it has been in the past. Also, with the exception of a few, the workers lack customer service skills. I dont think I have ever been treated nicely/smiled at unless the owners wife is therewho is very accommodating and very sweet. Users/CourtneyMullarkey
I just got a facebook message from the owners who saw this, apologized, and offered to get me a free lunch. So nice of them, I really appreciate it.
20110816 16:31:23 nbsp I actually dont mind the food at all, considering the price. You get what you pay for. The owners are really nice.
But there are a lot of flies and its hot in the restaurant in the summer. Users/PaulV
20111002 11:33:14 nbsp I really really want to support this place. I really do. But I can honestly say I have never had a positive experience here yet. This morning was the last straw.
Apparently the breakfast buffet is no more and now they dont open until 11am? Not just the breakfast buffet has been aced, the entire breakfast menu is no longer served (even though its still listed on the menu). Which really is a common theme here weve found, what is on the menu isnt nessisarily what they are serving. They are constantly out of just about everything.
Eating here is like having a tea party with a toddler. The rules always change and you wont be told til you want it.
Now I will tell you, the owners are SAINTS! Thats why it pains me so much to see the place the way it is. I remember when they were the Marketplace Grill at Arden Fair. I was so sad whenthey closed. But when they opened in Davis I was overjoyed because they were back. Now the state of affiars here just depress me.
I want to love this place. But I just cant anymore. I just cant. Users/NatePitcairn
20111002 18:58:03 nbsp I ate here for the first time yesterday; Id visited for a beer once or twice before and wasnt impressed, but Im glad I gave it another shot. Lets get one thing clear off the bat: you dont come here for the service. The staff, aside from the busser who cleared some dishes for us, seemed extremely disinterested.
That said, the foods delicious. Great burgersI recommend the pastrami burger! The fries are above average as well. A large lunch and beers for two ran about $22quite good for the quality of the food. They also have some of the best buns in town for the burgers. Users/TomGarberson
20111105 12:11:36 nbsp I went there a week or two ago to get some drinks with my friends i had been there before mostly because of the drinks and we like to sit outside.. it doesnt hurt that theres a really hot guy that works during lunchtime and is always very nice to me and my friends (the tall guy with crazy blue eyes) the food is also pretty good, prices went up recently but whatever. The worst part about this place is that there can be a long wait during lunchtime and the staff is for the most part pretty rude, especially when its busy. i also get confused about when they are open.. it always seems to change. this place has potential but for whatever reason they dont take advantage of the location Users/roxygirl55
20111105 12:29:40 nbsp word on the street is that their alcohol license was suspended. The ABC license search does not show this though. Can anyone confirm or deny? Users/ChrisDietrich
20111111 14:28:45 nbsp Unfortunately their alcohol license is suspended indefinitely. So says the sign above the beer taps, and also posted on the door. Users/Zippypickle
20111116 19:32:22 nbsp The license was suspended per Alcohol License tax issues but as of this morning the license has been reinstated and the beers are flowing!! Users/IanN
20120113 12:49:49 nbsp residents of 3rd and u apartments beware, you WILL be blocked in if you forget to move your car out of one of their spots early in the morning! the owner doesnt take too kindly to it, as i experienced this morning. it was so odd, i woke up 5 minutes prior with a screaming hangover, just to have the gentleman tell me how smug and rude i was on the phone when i told him i needed the car blocking my girlfriends to move. i didnt know whos car it was, or why it was parked as such... i was told to park there and then to wake up early and move it. i suppose i should have chosen my words more carefully. i mean, the vendetta is clear, im certain it happens to him all the time. (residents parking in marked 3rd and u spots). i think i got the short end of the stick with this one. but hey, it all worked out. the food there is bomb. they need more beer choices though. Users/mynameisGIL
20120726 15:34:20 nbsp I eat here about once a week and am always satisfied. Customer service is fantastic, the owners refer to many customers by name and are always pleasant and up beat. The food is very reasonably price and good. Nothing too fancy or gourmet, but very satisfying. I strongly recommend it Users/mwalters
20121216 23:58:00 nbsp This is one of my favorite places in Davis. Cool beer garden, friendly staff, great happy hour and good beer food. Users/PrimaveraTime
20130207 17:30:18 nbsp I used to be really pleased to come here (the food is pretty good, Jalapeno burger is where it is atttt), and service is nice but pretty variable/slow. Id only recommend coming for happy hour. Once, during nonhappy hour, my partner ordered some french fries. It took over half an hour, and I think they literally just split up his order with someone elses since the fries were MUCH smaller in portion than I had ever gotten. if you get happy hour, you wont feel as irritated waiting half an hour since theyre $1 fries :)
Their happy food is good, too, and a great deal. The quesdillas are nicely crispy on the outside, but as for sliders, I recommend the Jalapeno again. Anyway, I dont mind studying here, since the Wifis decent and theres a lot of white noise. Users/HannahToru
20130630 20:51:34 nbsp This place is awesome, they have great food, fries are awesome, and very well priced, especially the 2 beers and food/side/beer combo (after 8pm?). They show sports so its nice to come sometimes to watch a game. Sometimes they are closed on the weekends, maybe when they are short staffed, so it helps to call first. Users/GarrettGallegos
20140611 17:40:13 nbsp While waiting in line to order last week I watched the cook handle raw chicken bare handed, then handtoss a salad, and prepare a burger all without a single hand washing. Though there was profuse wiping of hands on his disgustingly soiled tshirt. I ordered the two beer special. My friend ordered a burger and vomited heavily later in the evening. Owners were out of town according to the staff, otherwise I would have talked to them in person. Users/530PinTaxi
|
Formal statement is: lemma dist_triangle_eq: fixes x y z :: "'a::real_inner" shows "dist x z = dist x y + dist y z \<longleftrightarrow> norm (x - y) *\<^sub>R (y - z) = norm (y - z) *\<^sub>R (x - y)" Informal statement is: For any three points $x, y, z$ in a real inner product space, the following are equivalent: $\|x - z\| = \|x - y\| + \|y - z\|$ $\langle x - y, y - z \rangle = \|y - z\|^2$
|
struct DummyFilm <: GRAYTR.Film
resX::Int64
resY::Int64
end
DummyFilm() = DummyFilm(10,10)
@testset "Orthographic camera" begin
@testset "Orthographic function" begin
T = GRAYTR.orthographic(0.0, 1.0)
@test T.M β Matrix{Float64}(I, 4, 4)
@test T.MInv β Matrix{Float64}(I, 4, 4)
T = GRAYTR.orthographic(1.0, 3.0)
@test diag(T.M) β [1.0, 1.0, 0.5, 1.0]
@test T.M[:,4] β [0.0, 0.0, -0.5, 1.0]
end
@testset "Creations" begin
T = Transformation()
window = [-1.0, 1.0, -1.0, 1.0]
C = OrthographicCamera(T, window, 0.0, 0.0, DummyFilm())
sample = GRAYTR.CameraSample(5.0, 5.0, 0.5, 0.5)
weight, R = GRAYTR.generate_ray(C, sample)
@test R.origin β Point3(0.0, 0.0, 0.0)
@test R.direction β Vector3(0.0, 0.0, 1.0)
@test R.tmin == 0.0
@test R.tmax == Inf
@test R.depth == 1
end
@testset "Transformations" begin
T = Transformation()
window = [-1.0, 1.0, -1.0, 1.0]
C = OrthographicCamera(T, window, 0.0, 0.0, DummyFilm())
@test C.camera_to_world.M β Matrix{Float64}(I, 4, 4)
@test C.raster_to_camera(Point3(0)) β Point3(-1, -1, 0)
@test C.screen_to_camera(Point3(0)) β Point3(0)
end
end
|
!> Driver program for ballstab module, used to calculate ideal ballooning stability for a given (GS2) input file.
program ideal_ball
use ballstab, only: init_ballstab, finish_ballstab, run_stability_check, write_stability_ascii_2d
use job_manage, only: job_fork
use mp, only: init_mp, finish_mp, proc0, broadcast
use file_utils, only: init_file_utils, run_name
use theta_grid, only: finish_theta_grid
implicit none
logical :: list
character(len=500), target :: cbuff
!Setup mpi
call init_mp
!Setup files
if(proc0) call init_file_utils(list, name="gs")
call broadcast(list)
if(list) call job_fork
!Set run name
if(proc0) cbuff = trim(run_name)
call broadcast(cbuff)
if(.not.proc0) run_name => cbuff
!Initialise
call init_ballstab
!Run
if(proc0) then
call run_stability_check
call write_stability_ascii_2d
endif
!Finish
call finish_ballstab
call finish_theta_grid
call finish_mp
end program ideal_ball
|
function [A] = cm2A(cm)
% Convert length from centimeters to angstroms.
% Chad A. Greene 2012
A = cm*100000000;
|
# Homework 5
## Due Date: Tuesday, October 3rd at 11:59 PM
# Problem 1
We discussed documentation and testing in lecture and also briefly touched on code coverage. You must write tests for your code for your final project (and in life). There is a nice way to automate the testing process called continuous integration (CI).
This problem will walk you through the basics of CI and show you how to get up and running with some CI software.
### Continuous Integration
The idea behind continuous integration is to automate away the testing of your code.
We will be using it for our projects.
The basic workflow goes something like this:
1. You work on your part of the code in your own branch or fork
2. On every commit you make and push to GitHub, your code is automatically tested on a fresh machine on Travis CI. This ensures that there are no specific dependencies on the structure of your machine that your code needs to run and also ensures that your changes are sane
3. Now you submit a pull request to `master` in the main repo (the one you're hoping to contribute to). The repo manager creates a branch off `master`.
4. This branch is also set to run tests on Travis. If all tests pass, then the pull request is accepted and your code becomes part of master.
We use GitHub to integrate our roots library with Travis CI and Coveralls. Note that this is not the only workflow people use. Google git..github..workflow and feel free to choose another one for your group.
### Part 1: Create a repo
Create a public GitHub repo called `cs207test` and clone it to your local machine.
**Note:** No need to do this in Jupyter.
### Part 2: Create a roots library
Use the example from lecture 7 to create a file called `roots.py`, which contains the `quad_roots` and `linear_roots` functions (along with their documentation).
Also create a file called `test_roots.py`, which contains the tests from lecture.
All of these files should be in your newly created `cs207test` repo. **Don't push yet!!!**
### Part 3: Create an account on Travis CI and Start Building
#### Part A:
Create an account on Travis CI and set your `cs207test` repo up for continuous integration once this repo can be seen on Travis.
#### Part B:
Create an instruction to Travis to make sure that
1. python is installed
2. its python 3.5
3. pytest is installed
The file should be called `.travis.yml` and should have the contents:
```yml
language: python
python:
- "3.5"
before_install:
- pip install pytest pytest-cov
script:
- pytest
```
You should also create a configuration file called `setup.cfg`:
```cfg
[tool:pytest]
addopts = --doctest-modules --cov-report term-missing --cov roots
```
#### Part C:
Push the new changes to your `cs207test` repo.
At this point you should be able to see your build on Travis and if and how your tests pass.
### Part 4: Coveralls Integration
In class, we also discussed code coverage. Just like Travis CI runs tests automatically for you, Coveralls automatically checks your code coverage. One minor drawback of Coveralls is that it can only work with public GitHub accounts. However, this isn't too big of a problem since your projects will be public.
#### Part A:
Create an account on [`Coveralls`](https://coveralls.zendesk.com/hc/en-us), connect your GitHub, and turn Coveralls integration on.
#### Part B:
Update your the `.travis.yml` file as follows:
```yml
language: python
python:
- "3.5"
before_install:
- pip install pytest pytest-cov
- pip install coveralls
script:
- py.test
after_success:
- coveralls
```
Be sure to push the latest changes to your new repo.
### Part 5: Update README.md in repo
You can have your GitHub repo reflect the build status on Travis CI and the code coverage status from Coveralls. To do this, you should modify the `README.md` file in your repo to include some badges. Put the following at the top of your `README.md` file:
```
[](https://travis-ci.org/dsondak/cs207testing.svg?branch=master)
[](https://coveralls.io/github/dsondak/cs207testing?branch=master)
```
Of course, you need to make sure that the links are to your repo and not mine. You can find embed code on the Coveralls and Travis CI sites.
---
# Problem 2
Write a Python module for reaction rate coefficients. Your module should include functions for constant reaction rate coefficients, Arrhenius reaction rate coefficients, and modified Arrhenius reaction rate coefficients. Here are their mathematical forms:
\begin{align}
&k_{\textrm{const}} = k \tag{constant} \\
&k_{\textrm{arr}} = A \exp\left(-\frac{E}{RT}\right) \tag{Arrhenius} \\
&k_{\textrm{mod arr}} = A T^{b} \exp\left(-\frac{E}{RT}\right) \tag{Modified Arrhenius}
\end{align}
Test your functions with the following paramters: $A = 10^7$, $b=0.5$, $E=10^3$. Use $T=10^2$.
A few additional comments / suggestions:
* The Arrhenius prefactor $A$ is strictly positive
* The modified Arrhenius parameter $b$ must be real
* $R = 8.314$ is the ideal gas constant. It should never be changed (except to convert units)
* The temperature $T$ must be positive (assuming a Kelvin scale)
* You may assume that units are consistent
* Document each function!
* You might want to check for overflows and underflows
**Recall:** A Python module is a `.py` file which is not part of the main execution script. The module contains several functions which may be related to each other (like in this problem). Your module will be importable via the execution script. For example, suppose you have called your module `reaction_coeffs.py` and your execution script `kinetics.py`. Inside of `kinetics.py` you will write something like:
```python
import reaction_coeffs
# Some code to do some things
# :
# :
# :
# Time to use a reaction rate coefficient:
reaction_coeffs.const() # Need appropriate arguments, etc
# Continue on...
# :
# :
# :
```
Be sure to include your module in the same directory as your execution script.
---
# Problem 3
Write a function that returns the **progress rate** for a reaction of the following form:
\begin{align}
\nu_{A} A + \nu_{B} B \longrightarrow \nu_{C} C.
\end{align}
Order your concentration vector so that
\begin{align}
\mathbf{x} =
\begin{bmatrix}
\left[A\right] \\
\left[B\right] \\
\left[C\right]
\end{bmatrix}
\end{align}
Test your function with
\begin{align}
\nu_{i} =
\begin{bmatrix}
2.0 \\
1.0 \\
1.0
\end{bmatrix}
\qquad
\mathbf{x} =
\begin{bmatrix}
1.0 \\
2.0 \\
3.0
\end{bmatrix}
\qquad
k = 10.
\end{align}
You must document your function and write some tests in addition to the one suggested. You choose the additional tests, but you must have at least one doctest in addition to a suite of unit tests.
### Answer:
Answers to Problems 3-6 are saved as .py files in the cs207test repo created in Problems 1-2.
```python
import doctest
from typing import Iterable, List, Sequence
def progress_rate (x: Sequence[float], v: Sequence[float], k: float) -> float:
""" Calculates progress rate for single reaction represented by inputs.
Args:
x: Concentration vector.
v: Stoichiometric coefficients of reactants.
k: Forward reaction rate coefficient.
Notes:
Raises ValueError if sequences x and v are not the same length.
Returns:
Reaction progress rate.
Examples:
>>> progress_rate([1.0, 2.0, 3.0], [2.0, 1.0, 1.0], 10)
60.0
"""
if len(x) != len(v):
raise ValueError('x and v must be same length.')
result = 1
for i, x_i in enumerate(x):
result *= pow(x_i, v[i])
return k * result
```
```python
import unittest
class TestProgressRate(unittest.TestCase):
""" Tests progress_rate() function under various circumstances. """
def test_unequal_dim_args (self):
""" Ensures func raises ValueError with unequally-dimensioned args. """
x = [1.0, 2.0, 3.0]
v = [2.0, 1.0]
k = 10
try:
rate = progress_rate(x, v, k)
except Exception as e:
if not isinstance(e, ValueError):
self.fail('Expected ValueError but caught different exception.')
else:
pass
else:
self.fail('No exception raised even though args unequally-dimensioned.')
def test_x_not_seq (self):
""" Ensures that TypeError is raised when x is not a sequence. """
x = 1.0
v = [2.0, 1.0]
k = 10
try:
rate = progress_rate(x, v, k)
except Exception as e:
if not isinstance(e, TypeError):
self.fail('Expected TypeError but caught different exception.')
else:
pass
else:
self.fail('No exception raised even though x not sequence.')
```
---
# Problem 4
Write a function that returns the **progress rate** for a system of reactions of the following form:
\begin{align}
\nu_{11}^{\prime} A + \nu_{21}^{\prime} B \longrightarrow \nu_{31}^{\prime\prime} C \\
\nu_{12}^{\prime} A + \nu_{32}^{\prime} C \longrightarrow \nu_{22}^{\prime\prime} B + \nu_{32}^{\prime\prime} C
\end{align}
Note that $\nu_{ij}^{\prime}$ represents the stoichiometric coefficient of reactant $i$ in reaction $j$ and $\nu_{ij}^{\prime\prime}$ represents the stoichiometric coefficient of product $i$ in reaction $j$. Therefore, in this convention, I have ordered my vector of concentrations as
\begin{align}
\mathbf{x} =
\begin{bmatrix}
\left[A\right] \\
\left[B\right] \\
\left[C\right]
\end{bmatrix}.
\end{align}
Test your function with
\begin{align}
\nu_{ij}^{\prime} =
\begin{bmatrix}
1.0 & 2.0 \\
2.0 & 0.0 \\
0.0 & 2.0
\end{bmatrix}
\qquad
\nu_{ij}^{\prime\prime} =
\begin{bmatrix}
0.0 & 0.0 \\
0.0 & 1.0 \\
2.0 & 1.0
\end{bmatrix}
\qquad
\mathbf{x} =
\begin{bmatrix}
1.0 \\
2.0 \\
1.0
\end{bmatrix}
\qquad
k = 10.
\end{align}
You must document your function and write some tests in addition to the one suggested. You choose the additional tests, but you must have at least one doctest in addition to a suite of unit tests.
```python
def progress_rates (x: Sequence[float], v_react: Sequence[Sequence[float]],
k: float) -> List[float]:
""" Calculates progress rates for system of reactions.
Args:
x: Concentration vector.
v_react: Matrix of stoichiometric coefficients for reactants.
k: Forward reaction rate coefficient.
Notes:
v_react is an m-by-n matrix, where the number of rows (m) must equal the number
of species (i.e., length of concentration vector x) and the number of columns
must equal the number of reactions.
Returns:
List of progress rates for system of reactions.
Examples:
>>> progress_rates([1.0, 2.0, 1.0], [[1.0, 2.0], [2.0, 0.0], [0.0, 2.0]], 10)
[40.0, 10.0]
"""
# Test inputs
# Ensure all rows in v_react have same number of columns (corresponding to number
# of reactions).
M = len(v_react[0])
for row in v_react:
if len(row) != M:
raise ValueError('Not all rows in v_react share the same dimension.')
if len(x) != len(v_react):
raise ValueError('Length of x != number of rows in v_react.')
# Call progress_rate() on reaction formed from concentration vector x and the
# reactant coefficients in each column of v_react.
result = []
for j in range(0, M):
v = [row[j] for row in v_react]
rate = progress_rate(x, v, k)
result.append(rate)
return result
```
```python
class TestProgressRates(unittest.TestCase):
""" Tests progress_rates() function under various circumstances. """
def test_unequal_dim_args (self):
""" Ensures func raises ValueError when number of rows in stoichiometric
coefficient matrix is fewer than len(x).
"""
x = [1.0, 2.0, 1.0]
v = [[1.0, 2.0], [2.0, 0.0]]
k = 10
try:
rate = progress_rates(x, v, k)
except Exception as e:
if not isinstance(e, ValueError):
self.fail('Expected ValueError but different exception caught.')
else:
pass
else:
self.fail('No exception raised even though args unequally-dimensioned.')
def test_unequal_dim_v_cols (self):
""" Ensures func raises ValueError when not all of the rows within v share the
same dimension.
"""
x = [1.0, 2.0, 1.0]
# 3rd row has 1 fewer element than other 2 rows.
v = [[1.0, 2.0], [2.0, 0.0], [0.0]]
k = 10
try:
rate = progress_rates(x, v, k)
except Exception as e:
if not isinstance(e, ValueError):
self.fail('Expected ValueError but different exception caught.')
else:
pass
else:
self.fail(
'No exception raised even though not all rows within v share same '
'dimension.')
```
---
# Problem 5
Write a function that returns the **reaction rate** of a system of irreversible reactions of the form:
\begin{align}
\nu_{11}^{\prime} A + \nu_{21}^{\prime} B &\longrightarrow \nu_{31}^{\prime\prime} C \\
\nu_{32}^{\prime} C &\longrightarrow \nu_{12}^{\prime\prime} A + \nu_{22}^{\prime\prime} B
\end{align}
Once again $\nu_{ij}^{\prime}$ represents the stoichiometric coefficient of reactant $i$ in reaction $j$ and $\nu_{ij}^{\prime\prime}$ represents the stoichiometric coefficient of product $i$ in reaction $j$. In this convention, I have ordered my vector of concentrations as
\begin{align}
\mathbf{x} =
\begin{bmatrix}
\left[A\right] \\
\left[B\right] \\
\left[C\right]
\end{bmatrix}
\end{align}
Test your function with
\begin{align}
\nu_{ij}^{\prime} =
\begin{bmatrix}
1.0 & 0.0 \\
2.0 & 0.0 \\
0.0 & 2.0
\end{bmatrix}
\qquad
\nu_{ij}^{\prime\prime} =
\begin{bmatrix}
0.0 & 1.0 \\
0.0 & 2.0 \\
1.0 & 0.0
\end{bmatrix}
\qquad
\mathbf{x} =
\begin{bmatrix}
1.0 \\
2.0 \\
1.0
\end{bmatrix}
\qquad
k = 10.
\end{align}
You must document your function and write some tests in addition to the one suggested. You choose the additional tests, but you must have at least one doctest in addition to a suite of unit tests.
```python
import numpy as np
def reaction_rate (x: Sequence[float], v_react: Sequence[Sequence[float]],
v_prod: Sequence[Sequence[float]], k: float) -> Iterable:
""" Calculates reaction rates for species for a given system of reactions.
Args:
x: Concentration vector.
v_react: Matrix of stoichiometric coefficients for reactants.
v_prod: Matrix of stoichiometric coefficients for products.
k: Forward reaction rate coefficient.
Notes:
v_react is an m-by-n matrix, where the number of rows (m) must equal the number
of species (i.e., length of concentration vector x) and the number of columns
must equal the number of reactions.
v_react and v_prod must be of the same dimensions.
Returns:
List of reaction rates for species represented by concentration rates in x.
Examples:
>>> reaction_rate([1.0, 2.0, 1.0], [[1.0, 0.0], [2.0, 0.0], [0.0, 2.0]], [[0.0, 1.0], [0.0, 2.0], [1.0, 0.0]])
[-30.0, -60.0, 20.0]
"""
reaction_rates = progress_rates(x, v_react, k)
# Convert stoichiometric coefficients for reactants and products to np matrices to
# make matrix transformations simpler.
if not isinstance(v_react, np.matrix):
v_react = np.matrix(v_react)
if not isinstance(v_prod, np.matrix):
v_prod = np.matrix(v_prod)
if v_react.shape != v_prod.shape:
raise ValueError('Dimensions of v_react and v_prod not equal.')
v_ij = v_prod - v_react
result = v_ij.dot(reaction_rates)
# Convert 1D matrix to a simple list.
return np.array(result).flatten().tolist()
```
```python
class TestReactionRate(unittest.TestCase):
""" Tests reaction_rate() function under various circumstances. """
def test_unequal_dim_stoichiometric_coeff (self):
""" Ensures func raises ValueError when v_react and v_prod do not share the
same dimensions, both in terms of number of rows and columns.
"""
x = [1.0, 2.0, 1.0]
k = 10
# First test with v_react and v_prod having different number of rows.
v_react = [[1.0, 0.0], [2.0, 0.0], [0.0, 2.0]]
v_prod = [[0.0, 1.0], [0.0, 2.0]] # 1 row less than v_react
try:
rate = reaction_rate(x, v_react, v_prod, k)
except Exception as e:
if not isinstance(e, ValueError):
self.fail('Expected ValueError but different exception caught.')
else:
pass
else:
self.fail(
'No exception raised even though v_prod contains fewer rows than '
'v_react.')
# Next test with v_react and v_prod having same number of rows but one of their
# rows containing fewer elements than the rest.
v_react = [[1.0, 0.0], [2.0], [0.0, 2.0]] # 2nd row only contains 1 element
v_prod = [[0.0, 1.0], [0.0, 2.0], [1.0, 0.0]]
try:
rate = reaction_rate(x, v_react, v_prod, k)
except Exception as e:
if not isinstance(e, ValueError):
self.fail('Expected ValueError but different exception caught.')
else:
pass
else:
self.fail(
'No exception raised even though v_react contains fewer elements than '
'required in 2nd row.')
```
---
# Problem 6
Put parts 3, 4, and 5 in a module called `chemkin`.
Next, pretend you're a client who needs to compute the reaction rates at three different temperatures ($T = \left\{750, 1500, 2500\right\}$) of the following system of irreversible reactions:
\begin{align}
2H_{2} + O_{2} \longrightarrow 2OH + H_{2} \\
OH + HO_{2} \longrightarrow H_{2}O + O_{2} \\
H_{2}O + O_{2} \longrightarrow HO_{2} + OH
\end{align}
The client also happens to know that reaction 1 is a modified Arrhenius reaction with $A_{1} = 10^{8}$, $b_{1} = 0.5$, $E_{1} = 5\times 10^{4}$, reaction 2 has a constant reaction rate parameter $k = 10^{4}$, and reaction 3 is an Arrhenius reaction with $A_{3} = 10^{7}$ and $E_{3} = 10^{4}$.
You should write a script that imports your `chemkin` module and returns the reaction rates of the species at each temperature of interest.
You may assume that these are elementary reactions.
### Answer:
The order for the species I chose in my vectors/matrices is:
\begin{align}
\mathbf{x} =
\begin{bmatrix}
H_2 \\
O_2 \\
OH \\
HO_2 \\
H_2O
\end{bmatrix}
\end{align}
```python
"""
client.py
---------
Simulating client script that will use chemkin and reaction_coeffs in order to
calculate the reaction rates of species at various temperatures.
"""
import chemkin
import numpy as np
import reaction_coeffs
# Store params in lists so we can iterate through them simultaneously.
T = [750, 1500, 2500]
k1 = reaction_coeffs.modified_arrhenius(A=1E8, E=5 * 1E4, T=T[0], b=0.5)
k2 = 1E4
k3 = reaction_coeffs.arrhenius(A=1E7, E=1E4, T=T[2])
k = [k1, k2, k3]
v_react = [[2, 0, 0], [1, 0, 1], [0, 1, 0], [0, 1, 0], [0, 0, 1]]
v_prod = [[1, 0, 0], [0, 1, 0], [2, 0, 1], [0, 0, 1], [0, 1, 0]]
# Client must update concentration rates. Random numbers used here for demo.
x = np.random.randint(1, 5, size=len(v_react))
# Loop through temperatures and calculate reaction rate at each temperature and
# corresponding k value.
rates = []
for i, t in enumerate(T):
rate = chemkin.reaction_rate(x, v_react, v_prod, k[i])
rates.append(rate)
print('At T = {0}, species reaction rates = {1}'.format(t, rate))
```
---
# Problem 7
Get together with your project team, form a GitHub organization (with a descriptive team name), and give the teaching staff access. You can have has many repositories as you like within your organization. However, we will grade the repository called **`cs207-FinalProject`**.
Within the `cs207-FinalProject` repo, you must set up Travis CI and Coveralls. Make sure your `README.md` file includes badges indicating how many tests are passing and the coverage of your code.
```python
```
|
#' An LDA topicmodel, tokens and meta for State of the Union speeches
#'
#' @docType data
#' @keywords datasets
#' @name sotu
#' @usage data(sotu)
#' @format sotu: A LDA topicmodel from the topicmodels package, a dataframe containing tokens for State of the Union speeches and a dataframe containing the metadata.
NULL
|
If $f$ is a real-valued function such that $f(x) \to 0$ as $x \to -\infty$, and $n$ is an even positive integer, then $f(x)^n \to \infty$ as $x \to -\infty$.
|
#Simulate positions for n=8 sities
pos <- read.table("optimaltransport.ascii",header=F)
p = nrow(pos)
set.seed(345)
par(mfrow=c(1,1))
plot(pos)
dev.copy2pdf(file="../doc/example_trav_sale.pdf")
#Calculate pairwise distances between cities
d = as.matrix((dist(pos,diag=TRUE,upper=TRUE)))
#Convert to vector in order to access many components at a time
d = as.vector(d)
#Perform neighbor search, simulated annealing
#Random inizialization
#We implement the fact that the distribution must start and finish at home town
theta = c(1, sample(2:p,p-1), 1)
#Convert sequential pairs into index in the d-vector
ind = (theta[-p]-1)*p+theta[-1]
#Calculate total distance of order
V = sum(d[ind])
Vseq = V
Numit=50000
for(i in 1:Numit)
{
tau = 100/i
#tau = 1/log(i+1)
#tau <- (0.8 + i/Numit/10)*tau
#we never change the position of index=1 (home)
ind2 = sample(2:p,2,replace=F)
theta2 = theta
theta2[ind2[1]] = theta[ind2[2]]
theta2[ind2[2]] = theta[ind2[1]]
ind2 = (theta2[-p]-1)*p+theta2[-1]
V2 = sum(d[ind2])
prob = exp((V-V2)/tau)
u = runif(1)
if(u<prob)
{
theta = theta2
V = V2
}
Vseq = c(Vseq,V)
}
#par(mfrow=c(2,1),mar=c(0.5,1,0.5,1))
plot(pos)
lines(pos[theta,1],pos[theta,2])
points(pos[1,1],pos[1,2], type = 'o', col = 'red')
#dev.copy2pdf(file="../doc/example_trav_sale_SA.pdf")
plot.ts(Vseq)
show(min(Vseq))
|
module Common where
data PSet (A : Set) : Set where
β¦β¦ : PSet A
_::_ : A -> PSet A -> PSet A
data Pair (A : Set) : Set where
<_,_> : A -> A -> Pair A
data Bool : Set where
true : Bool
false : Bool
neg : Bool -> Bool
neg true = false
neg false = true
_&&_ : Bool -> Bool -> Bool
true && true = true
_ && _ = false
_||_ : Bool -> Bool -> Bool
false || false = false
_ || _ = true
-- data _β‘_ {a} {A : Set a} (x : A) : A β Set a where
-- instance refl : x β‘ x
-- data _β‘_ {a} {A : Set a} : A β A β Set where
-- refl : (a : A) β a β‘ a
-- sym : β x y β x β‘ y β y β‘ x
-- sym .a .a (refl a) = refl a
-- isEq : β x y -> x β‘ y -> Bool
-- isEq .a .a (refl a) = true
record Eq {a} (A : Set a) : Set a where
field
_==_ : A β A β Bool
open Eq {{...}} public
instance
eqPair : {A : Set} {{_ : Eq A}} β Eq (Pair A)
_==_ {{eqPair}} < xβ , xβ > < yβ , yβ > = (xβ == yβ) && (xβ == yβ)
|
\section{Finding eigenvalues}
\begin{outcome}
\begin{enumerate}
\item Find the characteristic polynomial, eigenvalues, and
eigenvectors of a matrix.
\item Find the eigenvalues of a triangular matrix.
\end{enumerate}
\end{outcome}
In the previous section, we saw how to find the eigenvectors
corresponding to a given eigenvalue $\eigenvar$, if $\eigenvar$ is already
known. But we have not yet seen how to find the eigenvalues of a
matrix. However, the calculations in
Examples~\ref{exa:find-eigenvectors-given-eigenvalue} and
{\ref{exa:basis-eigenspace}} suggest a way forward. We can see that
the following are equivalent:
\begin{enumerate}
\item $\eigenvar$ is an eigenvalue of $A$.
\item There exists a non-zero vector $\vect{v}$ such that
$A\vect{v}=\eigenvar\vect{v}$.
\item The homogeneous system of equations
$(A-\eigenvar I)\vect{v}=\vect{0}$ has a non-trivial solution.
\end{enumerate}
Indeed, the equivalence between 1 and 2 is just the definition of an
eigenvalue, and the equivalence between 2 and 3 is just algebra.
By Corollary~\ref{cor:determinant-homogeneous}, we know that the
system $(A-\eigenvar I)\vect{v}=\vect{0}$ has a non-trivial solution if
and only if $\det(A-\eigenvar I)=0$. Therefore, we have proved the
following theorem:
\begin{theorem}{Eigenvalues}{eigenvalues}
Let $A$ be a square matrix, and let $\eigenvar$ be a scalar. Then
$\eigenvar$ is an eigenvalue of $A$ if and only if
\begin{equation*}
\det(A-\eigenvar I)=0.
\end{equation*}
\end{theorem}
\begin{example}{Finding the eigenvalues}{finding-eigenvalues}
Find the eigenvalues of the matrix
\begin{equation*}
A = \begin{mymatrix}{rr}
-5 & 2 \\
-7 & 4 \\
\end{mymatrix}.
\end{equation*}
\end{example}
\begin{solution}
By Theorem~\ref{thm:eigenvalues}, a scalar $\eigenvar$ is an
eigenvalue of $A$ if and only if $\det(A-\eigenvar I)=0$. We calculate
the determinant:
\begin{eqnarray*}
\det(A-\eigenvar I)
&=&
\begin{absmatrix}{cc}
-5-\eigenvar & 2 \\
-7 & 4-\eigenvar \\
\end{absmatrix} \\
&=& (-5-\eigenvar)(4-\eigenvar) + 14 \\
&=& \eigenvar^2 + \eigenvar - 6.
\end{eqnarray*}
Therefore, $\eigenvar$ is an eigenvalue if and only if
$\eigenvar^2 + \eigenvar - 6 = 0$. We can find the roots of this
equation using the quadratic formula, or equivalently, by factoring
the left-hand side:
\begin{equation*}
\eigenvar^2 + \eigenvar - 6 = 0
\iff
(\eigenvar+3)(\eigenvar-2) = 0.
\end{equation*}
Therefore, the eigenvalues are $\eigenvar=-3$ and $\eigenvar=2$.
\end{solution}
\begin{example}{Finding the eigenvalues}{finding-eigenvalues2}
Find the eigenvalues of the matrix
\begin{equation*}
A=\begin{mymatrix}{rrr}
5 & -4 & 4 \\
2 & -1 & 2 \\
0 & 0 & 2 \\
\end{mymatrix}.
\end{equation*}
\end{example}
\begin{solution}
Once again, we calculate $\det(A-\eigenvar I)$:
\begin{eqnarray*}
\det(A-\eigenvar I)
&=&
\begin{absmatrix}{ccc}
5-\eigenvar & -4 & 4 \\
2 & -1-\eigenvar & 2 \\
0 & 0 & 2-\eigenvar \\
\end{absmatrix} \\
&=&
(5-\eigenvar)(-1-\eigenvar)(2-\eigenvar) - 2(-4)(2-\eigenvar) \\
&=& -\eigenvar^3 + 6\eigenvar^2 - 11\eigenvar + 6 \\
&=& (3-\eigenvar)(1-\eigenvar)(2-\eigenvar).
\end{eqnarray*}
The eigenvalues are the roots of this polynomial, i.e., the
solutions of the equation
$(\eigenvar-3)(\eigenvar-1)(2-\eigenvar)=0$. Therefore, the eigenvalues of
$A$ are $\eigenvar=1$, $\eigenvar=2$, and $\eigenvar=3$.
\end{solution}
\begin{example}{No real eigenvalue}{no-real-eigenvalue}
Find the eigenvalues of the matrix
\begin{equation*}
A=\begin{mymatrix}{rr}
0 & -1 \\
1 & 0 \\
\end{mymatrix}.
\end{equation*}
\end{example}
\begin{solution}
We have
\begin{equation*}
\det(A-\eigenvar I)
~=~
\begin{absmatrix}{cc}
-\eigenvar & -1 \\
1 & -\eigenvar \\
\end{absmatrix} \\
~=~
\eigenvar^2 + 1.
\end{equation*}
Since $\eigenvar^2+1 = 0$ does not have any solutions in the real
numbers, the matrix $A$ has no real eigenvalues. (However, if we
were working over the field of complex numbers rather than real
numbers, this matrix would have eigenvalues $\eigenvar=\pm i$).
\end{solution}
As the examples show, the quantity $\det(A-\eigenvar I)$ is always a
polynomial in the variable $\eigenvar$. A \textbf{polynomial}%
\index{polynomial} is an expression of the form
\begin{equation*}
p(\eigenvar) = a_n\eigenvar^n + a_{n-1}\eigenvar^{n-1} + \ldots + a_1\eigenvar + a_0,
\end{equation*}
where $a_0,\ldots,a_n$ are constants called the \textbf{coefficients}%
\index{coefficient!of a polynomial}%
\index{polynomial!coefficient} of the polynomial. The polynomial
$\det(A-\eigenvar I)$ has a special name:
\begin{definition}{Characteristic polynomial}{characteristic-polynomial}
Let $A$ be a square matrix. The expression
\begin{equation*}
p(\eigenvar) = \det(A-\eigenvar I)
\end{equation*}
is called the \textbf{characteristic polynomial}%
\index{characteristic polynomial}%
\index{polynomial!characteristic|see{characteristic polynomial}}%
\index{matrix!characteristic polynomial} of $A$.
\end{definition}
\begin{example}{Characteristic polynomial}{characteristic-polynomial}
Find the characteristic polynomial of the matrix
\begin{equation*}
A = \begin{mymatrix}{rrr}
3 & 0 & 2 \\
6 & 4 & 3 \\
-4 & 0 & -3 \\
\end{mymatrix}.
\end{equation*}
\end{example}
\begin{solution}
The characteristic polynomial is
\begin{eqnarray*}
\det(A-\eigenvar I) \\
&=&
\begin{absmatrix}{ccc}
3-\eigenvar & 0 & 2 \\
6 & 4-\eigenvar & 3 \\
-4 & 0 & -3-\eigenvar \\
\end{absmatrix} \\
&=&
(3-\eigenvar)\begin{absmatrix}{ccc}
4-\eigenvar & 3 \\
0 & -3-\eigenvar \\
\end{absmatrix}
+ 2 \begin{absmatrix}{ccc}
6 & 4-\eigenvar \\
-4 & 0 \\
\end{absmatrix} \\
&=& (3-\eigenvar)(4-\eigenvar)(-3-\eigenvar) + 8(4-\eigenvar) \\
&=& -\eigenvar^3 + 4\eigenvar^2 + \eigenvar - 4.
\end{eqnarray*}
\vspace{-8ex}\par
\end{solution}
It is time to summarize the method for finding the eigenvalues and
eigenvectors of a matrix.
\begin{procedure}{Finding eigenvalues and eigenvectors}{find-eigenvalues-vectors}
\index{eigenvalue!calculating}%
\index{eigenvector!calculating}%
\index{matrix!eigenvalue!calculating}%
\index{matrix!eigenvector!calculating}%
Let $A$ be an $n\times n$-matrix. To find the eigenvalues and
eigenvectors of $A$:
\begin{enumerate}
\item Calculate the characteristic polynomial $\det(A-\eigenvar I)$.
\item The eigenvalues are the roots of the characteristic polynomial.
\item For each eigenvalue $\eigenvar$, find a basis for the
eigenvectors by solving the homogeneous system
\begin{equation*}
(A-\eigenvar I)\vect{v} = \vect{0}.
\end{equation*}
\end{enumerate}
To double-check your work, make sure that $A\vect{v}=\eigenvar\vect{v}$
for each eigenvalue $\eigenvar$ and associated eigenvector $\vect{v}$.
\end{procedure}
\begin{example}{Finding eigenvalues and eigenvectors}{finding-eigenvalues-eigenvectors}
Find the eigenvalues and eigenvectors of the matrix
\begin{equation*}
A = \begin{mymatrix}{rrr}
3 & 0 & 2 \\
6 & 4 & 3 \\
-4 & 0 & -3 \\
\end{mymatrix}.
\end{equation*}
\end{example}
\begin{solution}
We already found the characteristic polynomial in
Example~\ref{exa:characteristic-polynomial}. It is
\begin{equation*}
p(\eigenvar)
= \det(A-\eigenvar I)
= -\eigenvar^3 + 4\eigenvar^2 + \eigenvar - 4.
\end{equation*}
Finding the roots%
\index{characteristic polynomial!root}%
\index{matrix!characteristic polynomial!root}%
\index{root!of a polynomial}%
\index{polynomial!root}
of a cubic polynomial can be a bit tricky, but
with some trial and error, we can find that $\eigenvar=1$ is a
root. We can therefore factor out $(\eigenvar-1)$:
\begin{equation*}
p(\eigenvar) = (\eigenvar-1)(-\eigenvar^2+3\eigenvar+4).
\end{equation*}
Then we can use the quadratic formula to find the remaining two
roots:
\begin{equation*}
\eigenvar = \frac{-3\pm\sqrt{9+16}}{-2},
\end{equation*}
which yields the two roots $\eigenvar=-1$ and $\eigenvar=4$. Therefore,
we have
\begin{equation*}
p(\eigenvar) = -(\eigenvar-1)(\eigenvar+1)(\eigenvar-4),
\end{equation*}
and the eigenvalues of $A$ are $\eigenvar=1$, $\eigenvar=-1$, and
$\eigenvar=4$. We now find the eigenvectors for each eigenvalue.
\begin{itemize}
\item {\bf{\underline{For $\eigenvar=1$:}}} We must solve
$(A-I)\/\vect{v}=\vect{0}$, i.e.,
\begin{equation*}
\begin{mymatrix}{rrr}
2 & 0 & 2 \\
6 & 3 & 3 \\
-4 & 0 & -4 \\
\end{mymatrix}\vect{v}=\vect{0}.
\end{equation*}
The basic solution is
\begin{equation*}
\vect{v}_1 = \begin{mymatrix}{r} -1 \\ 1 \\ 1 \end{mymatrix}.
\end{equation*}
\item {\bf{\underline{For $\eigenvar=-1$:}}} We must solve
$(A+I)\/\vect{v}=\vect{0}$, i.e.,
\begin{equation*}
\begin{mymatrix}{rrr}
4 & 0 & 2 \\
6 & 5 & 3 \\
-4 & 0 & -2 \\
\end{mymatrix}\vect{v}=\vect{0}.
\end{equation*}
The basic solution is
\begin{equation*}
\vect{v}_2 = \begin{mymatrix}{r} -1 \\ 0 \\ 2 \end{mymatrix}.
\end{equation*}
\item {\bf{\underline{For $\eigenvar=4$:}}} We must solve
$(A-4I)\vect{v}=\vect{0}$, i.e.,
\begin{equation*}
\begin{mymatrix}{rrr}
-1 & 0 & 2 \\
6 & 0 & 3 \\
-4 & 0 & -7 \\
\end{mymatrix}\vect{v}=\vect{0}.
\end{equation*}
The basic solution is
\begin{equation*}
\vect{v}_3 = \begin{mymatrix}{r} 0 \\ 1 \\ 0 \end{mymatrix}.
\end{equation*}
\end{itemize}
\end{solution}
\begin{example}{A zero eigenvalue}{zero-eigenvalue}
Let
\begin{equation*}
A=\begin{mymatrix}{rrr}
2 & 2 & -2 \\
1 & 3 & -1 \\
-1 & 1 & 1 \\
\end{mymatrix}.
\end{equation*}
Find the eigenvalues and eigenvectors of $A$.
\end{example}
\begin{solution}
To find the eigenvalues of $A$, we first compute the characteristic
polynomial.
\begin{equation*}
\det(A-\eigenvar I) =
\begin{absmatrix}{ccc}
2-\eigenvar & 2 & -2 \\
1 & 3-\eigenvar & -1 \\
-1 & 1 & 1-\eigenvar \\
\end{absmatrix}
= -\eigenvar^3+6 \eigenvar^2-8\eigenvar.
\end{equation*}
You can verify that the roots of this polynomial are
$\eigenvar_1 = 0$, $\eigenvar_2 = 2$, $\eigenvar_3 = 4$. Notice that
while eigenvectors can never equal $0$, it is possible to have an
eigenvalue equal to $0$. Now we will find the basic
eigenvectors.
\begin{itemize}
\item {\bf{\underline{For $\eigenvar_1 =0$:}}} We must solve the
equation $(A-0I)\vect{v} = \vect{0}$. This equation becomes
$A\vect{v}=\vect{0}$. We write the augmented matrix for this
system and reduce to {\ef}:
\begin{equation*}
\begin{mymatrix}{rrr|r}
2 & 2 & -2 & 0 \\
1 & 3 & -1 & 0 \\
-1 & 1 & 1 & 0 \\
\end{mymatrix}
\roweq\ldots\roweq
\begin{mymatrix}{rrr|r}
1 & 0 & -1 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\end{mymatrix}.
\end{equation*}
The basic solution is
\begin{equation*}
\vect{v}_1
=
\begin{mymatrix}{r} 1 \\ 0 \\ 1 \end{mymatrix}.
\end{equation*}
\item {\bf{\underline{For $\eigenvar_2=2$:}}} We solve the
equation $(A-2I)\vect{v} = \vect{0}$:
\begin{equation*}
\begin{mymatrix}{rrr|r}
0 & 2 & -2 & 0 \\
1 & 1 & -1 & 0 \\
-1 & 1 & -1 & 0 \\
\end{mymatrix}
\roweq\ldots\roweq
\begin{mymatrix}{rrr|r}
1 & 0 & 0 & 0 \\
0 & 1 & -1 & 0 \\
0 & 0 & 0 & 0 \\
\end{mymatrix}.
\end{equation*}
The basic solution is
\begin{equation*}
\vect{v}_2
=
\begin{mymatrix}{r} 0 \\ 1 \\ 1 \end{mymatrix}.
\end{equation*}
\item {\bf{\underline{For $\eigenvar_3=4$:}}} We solve the
equation $(A-4I)\vect{v} = \vect{0}$:
\begin{equation*}
\begin{mymatrix}{rrr|r}
-2 & 2 & -2 & 0 \\
1 & -1 & -1 & 0 \\
-1 & 1 & -3 & 0 \\
\end{mymatrix}
\roweq\ldots\roweq
\begin{mymatrix}{rrr|r}
1 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 0 \\
\end{mymatrix}.
\end{equation*}
The basic solution is
\begin{equation*}
\vect{v}_3
=
\begin{mymatrix}{r} 1 \\ 1 \\ 0 \end{mymatrix}.
\end{equation*}
\end{itemize}
Thus we have found the eigenvectors $\vect{v}_1$ for $\eigenvar_1$,
$\vect{v}_2$ for $\eigenvar_2$, and $\vect{v}_3$ for $\eigenvar_3$.
We can double-check our answers by checking the equation
$A\vect{v}=\eigenvar\vect{v}$ in each case:
\begin{eqnarray*}
A\vect{v}_1
&=&
\begin{mymatrix}{rrr}
2 & 2 & -2 \\
1 & 3 & -1 \\
-1 & 1 & 1 \\
\end{mymatrix}
\begin{mymatrix}{r} 1 \\ 0 \\ 1 \end{mymatrix}
=
\begin{mymatrix}{r} 0 \\ 0 \\ 0 \end{mymatrix}
= 0\vect{v}_1,
\\
A\vect{v}_2
&=&
\begin{mymatrix}{rrr}
2 & 2 & -2 \\
1 & 3 & -1 \\
-1 & 1 & 1 \\
\end{mymatrix}
\begin{mymatrix}{r} 0 \\ 1 \\ 1 \end{mymatrix}
=
\begin{mymatrix}{r} 0 \\ 2 \\ 2 \end{mymatrix}
= 2\vect{v}_2,
\\
A\vect{v}_3
&=&
\begin{mymatrix}{rrr}
2 & 2 & -2 \\
1 & 3 & -1 \\
-1 & 1 & 1 \\
\end{mymatrix}
\begin{mymatrix}{r} 1 \\ 1 \\ 0 \end{mymatrix}
=
\begin{mymatrix}{r} 4 \\ 4 \\ 0 \end{mymatrix}
= 4\vect{v}_3.
\end{eqnarray*}
Therefore, our eigenvectors and eigenvalues are correct.
\end{solution}
We conclude this section by considering the eigenvalues of a
triangular matrix. Recall from
Definition~\ref{def:triangular-matrices} that a matrix is
\textbf{upper triangular}%
\index{matrix!upper triangular!eigenvalues of}%
\index{matrix!triangular!eigenvalues of}%
\index{upper triangular matrix!eigenvalues}%
\index{triangular matrix!eigenvalues}%
\index{eigenvalue!of triangular matrix}
if all entries below the main diagonal are
zero, and \textbf{lower triangular}%
\index{matrix!lower triangular!eigenvalues of}%
\index{lower triangular matrix!eigenvalues}
if all entries above the main
diagonal are zero.
\begin{example}{Eigenvalues of a triangular matrix}{eigenvalues-triangular-matrix}
Find the eigenvalues of
\begin{equation*}
A=\begin{mymatrix}{rrr}
1 & 2 & 4 \\
0 & 4 & 7 \\
0 & 0 & 6 \\
\end{mymatrix}.
\end{equation*}
\end{example}
\begin{solution}
We calculate $\det(A - \eigenvar I) = 0$ as follows:
\begin{eqnarray*}
\det (A - \eigenvar I) =
\det \begin{mymatrix}{ccc}
1-\eigenvar & 2 & 4 \\
0 & 4-\eigenvar & 7 \\
0 & 0 & 6-\eigenvar \\
\end{mymatrix} = (1-\eigenvar)(4-\eigenvar)(6-\eigenvar).
\end{eqnarray*}
Solving the equation $(1-\eigenvar)(4-\eigenvar)(6-\eigenvar) = 0$
results in the eigenvalues $\eigenvar_1 = 1$, $\eigenvar_2 = 4$, and
$\eigenvar_3 = 6$. Thus the eigenvalues are the entries on the main
diagonal of $A$.
\end{solution}
Clearly, the same is true for any (upper or lower) triangular
matrix. We therefore have the following proposition:
\begin{proposition}{Eigenvalues of a triangular matrix}{eigenvalues-triangular-matrix}
Let $A$ be an upper or lower triangular matrix. Then the eigenvalues
of $A$ are the entries on the main diagonal.
\end{proposition}
|
\chapter{Evaluation}
\label{chap:evaluation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This chapter will elaborate on the experiments performed to evaluate the correctness of the implemented control system. The design for each experiment will be detailed, as well as explaining why these particular experiments were necessary. Results will then be shown for each experiment and any conclusions drawn.
A number of experiments were conducted to evaluate the correctness of the implemented robot control system. The robot control system was ran in its entirety on a high-end machine running Ubuntu Linux 12.04 LTS. Specifically, the machine has an \emph{Intel Core i7 3770K} clocked at \emph{4.5Ghz} paired with \emph{16GB} of memory. An attempt to run the control system on an \emph{Apple MacBook Pro} was made, which has an \emph{Intel Core i5 3239M} clocked at \emph{2.6Ghz} paired with \emph{8GB} of memory, but the machine could not achieve the performance necessary for good operation.
\begin{figure}[!h]
\centering
\includegraphics[width=12cm]{plan.png}
\caption{A diagram of the general layout of the test environment---not to any particular scale. Darkened shapes indicate large obstacles that the robot must detect and avoid. The robot was placed at the starting point at the beginning of each test. The end point indicates the target goal for the navigational tests along with an ideal path.}
\label{fig:eval_plan}
\end{figure}
Testing took place in a large environment as shown in \autoref{fig:eval_plan}. This environment contained a number of everyday obstacles with varying shapes, colours and textures. All tests were ran under ideal lighting conditions---i.e., full natural light---where possible. This ensured that the RGB-D camera provided the highest of quality images which would have a knock-on effect for the visual odometry and mapping subsystems.
\section{Hardware Interaction}
These experiments were created to test the correct function of the hardware interaction systems, specifically the RGB-D camera driver and the servo driver.
\subsection{RGB-D Camera Driver}
The RGB-D camera driver, provided by the \texttt{openni2\_driver} and \texttt{openni2\_launch} packages, was tested by observing output through \emph{rviz}. A \emph{rviz} configuration was made that would show both the colour and depth video feeds from the camera, taken from the \texttt{/camera/rgb/image} and \texttt{/camera/depth/image} topics. As this is a standard package, it was expected that it would function as intended without any issues.
That said, a peculiar fault was discovered in that the device would show itself to be disconnecting and reconnecting repeatedly while running. Throughout this, many USB timeout messages and similiar errors were shown in the Linux \emph{message buffer}---shown by \texttt{dmesg}. The cause of the issue turned out to be that, simply, the USB cable from the computer to the camera was too long. The USB specification states that devices running in USB 2.0 mode---which is the case for the \emph{Xtion}---may have a maximum cable length of $5$m \cite{usb_spec}. The cable had been extended to allow a larger movement distance but the resulting cable length was now $6.5$m long, as the \emph{Xtion} already had a $1.5$m cable attached.
Following this discovery, the cable was trimmed to $5$m and, as a result, the driver functioned correctly as intended.
\subsection{Servo Driver}
To test the servo driver for the system, which is implemented as a custom \texttt{servo\_controller} node, we ran the following experiments. Each experiment was implemented as a custom node would would then be ran alongside the driver nodes to execute the test. Correctness of results were determined by visual observation---i.e., looking to see if joints moved as intended.
\subsubsection{Rotation of a Single Servo}
This first experiment was designed to confirm correct behaviour when moving only one servo at a time. To elaborate further, we aimed to check the following:
\begin{description}[labelindent=\parindent]
\item[Hardware Communication] \hfill \\
If the servo controller was receiving any of the serial output sent by the \texttt{servo\_controller} node whatsoever, the on-board indication LED would flash with each message. This would have shown that the servo controller is receiving serial output as intended. No flashing LED would have indicated some general issue with the serial communication components.
\item[Topic Reception] \hfill \\
If the \texttt{servo\_controller} node was receiving \texttt{ServoCommand} messages sent on its \texttt{direct} topic, we expected some sort of change in system state in general---even if that involved the node crashing. No change would have indicated a problem with the topic subscriber within the node.
\item[Index, Angle \& Duration Conversion] \hfill \\
Should the formulae for converting from the units specified in the \texttt{ServoCommand} message to those specified by the servo controller's protocol be correct, we would have expected the specified servo to move the correct angle over the correct duration. Any deviation from this would have indicated some mathematical error in the formulae.
\end{description}
To implement this particular experiment, a \texttt{servo\_controller\_test\_single} node was created. This node requests four movements from each servo sequentially in a continuous loop at various angles and durations, pausing for one second between each. A listing of these movements is shown in \autoref{tab:servo_controller_eval}.
\begin{table}[!h]
\centering
\begin{tabular}{ c c c }
\toprule
\textbf{Movement} & \textbf{Angle} & \textbf{Duration} \\
\midrule
$1$ &
$90$\textdegree{} &
$1.00$s \\
$2$ &
$180$\textdegree{} &
$0.25$s \\
$3$ &
$0$\textdegree{} &
$0.50$s \\
$4$ &
$90$\textdegree{} &
$0.75$s \\
\bottomrule
\end{tabular}
\caption{A listing of movements made for each servo in the single servo rotation test. These movements are applied to each servo in a continuous loop with a one second delay between each movement.}
\label{tab:servo_controller_eval}
\end{table}
The \texttt{servo\_controller} node and \texttt{servo\_controller\_test\_single} node were launched and the robot observed. Prior to this, the robot was placed upon a pedestal to ensure that the limbs could rotate freely without unintentionally moving the robot. As expected, each servo rotated as intended to the correct angles and durations, thus showing the implementation was functional as required.
\subsubsection{Simultaneous Rotation of Multiple Servos}
The second experiment was designed to confirm correct behaviour in the case of multiple servos being moved simultaneously---i.e., where movement is requested for a number of servos such that the movement durations overlap. This was an essential requirement as no walk gaits would be possible without.
To implement this experiment, the \texttt{servo\_controller\_test\_single} node from the previous experiment was adapted to create a new \texttt{servo\_controller\_test\_multiple} node. This node performed the same set of movements but on all servos simultaneously rather than sequentially.
The \texttt{servo\_controller} node and \texttt{servo\_controller\_test\_double} node were launched and the robot observed, while the robot was placed on a pedestal as before. It was from this test that the necessity for a small delay between each serial communication was discovered. Without this delay, servos would either not rotate whatsoever or abort their requested rotation part-way through. During this, the indication LED on the servo controlled would also light up solidly, rather than flash as it does during normal operation. It was presumed that this meant there was some sort of communication error, perhaps as commands were being sent too quickly for the on-board microcontroller to process them. After adding an delay of $0.1$s, the problem immediately subsided. This was further reduced to a minimum delay of $0.003$s by trial-and-error, preventing any knock-on effects for commanding nodes. As mentioned in the implementation section for the \texttt{servo\_controller} node, no source code is available for the microcontroller software so no further diagnosis can be made.
Following this modification, the test ran as intended, thus showing the implementation was functional as required.
\section{Locomotion}
These experiments were created to evaluate that the systems designed to handle locomotion operated correctly. Specifically, we aimed to test the correct function of the limb controller, the limb calibration tool, and the walk controller.
\subsection{Limb Controller}
The limb controller, implemented as a custom \texttt{limb\_controller} node, was tested in a manner similar to the servo controller. The servo controller test nodes were adapted to send messages to the limb control topics, rather than the topic used to control the servos directly. Through running the same set of tests, the limb controller was shown to function correctly.
\subsection{Limb Calibration Tool}
The implementation of the limb calibration tool is fairly trivial and was used throughout the evaluation of the control system and as such, no particularly rigorous testing was performed. Testing was performed throughout the implementation process and the node was found to work as intended. Generally, the joint servos had to be re-calibrated during each session of operation, as the particular servos used are rather inaccurate. A number of realisations came about during its use.
In particular, it was found that achieving an accurate calibration through manual manipulation was essentially impossible. There are no markings on the robot with which the current angles of joints can be compared, so calibration was usually done by eye alone. Using a measuring implement, such as a protractor, was also infeasible as the physical geometry of the robot prevents such devices from aligning correctly with the servo axles. This issue could be alleviated by adding additional sensors on the robot---e.g., gyroscopes and accelerometers---such that calibration could be performed automatically or to, at the very least, give some notion of the stability of the robot.
Additionally, it was found that the servos would not rotate by small increments but only when it had reached a certain threshold away from its current position---e.g., if a servo is currently at $90$\textdegree{} then it will not rotate immediately until a rotation of $\pm2$\textdegree{} is requested whereupon it will ``snap'' into position. The particular threshold seemed to vary wildly depending on the particular servo \emph{and} its position. This ramifications of this were such that while a limb may seem calibrated, it could in fact be out of alignment by this threshold. This would only become apparent when larger rotations were made.
In general, both of these issues could be solved be utilising more accurate (and accordingly more expensive) servos---software can only correct for hardware problems up to a point.
\subsection{Tripod Gait Controller \& Gamepad Controller}
To test the tripod gait controller, implemented by the \texttt{walk\_controller} node, we conducted the following set of experiments. These would confirm that the implemented tripod gait cycle was correct and resulted in motions as intended. Specifically, we would test that the gait worked correctly for forward motions, angular motions and a combination of both motions. Manual control would be used throughout the test, given by the \texttt{gamepad\_controller}, providing confirmation that it too was functioning correctly. Tests would involve observing the robot visually as it moved around.
\subsubsection{Linear Motion}
The first test involved simply moving the robot back and forth in a straight line from its starting position. The left analogue stick on the controller was pushed upwards and downwards, signifying a forward and backwards movement. This was done for a few minutes to ensure there were no problems. As expected, the robot moved as intended without issue.
\subsubsection{Angular Motion}
The second test involved rotating the robot in place. The right analogue stick on the controller was pushed left and right, signifying anti-clockwise and clockwise rotations. Again, this was done for a number of minutes to ensure that there were no problems. As expected, the robot rotated as intended.
\subsubsection{Combined Linear and Angular Motion}
The third test involved supplying commands for both linear and angular motions simultaneously, such that the robot would move in a curved path. This was essentially a combination of the previous two tests. Both the left and right analogue sticks on the controller were moved in varying combinations of positions. The expected outcome was that the robot should push forward or backward while also turning to one side.
It was through this test that the necessity to apply some sort of equal ratio formula to the swing angles was found. Originally, both linear and angular movement angles were simply added together based on the requested velocities---i.e., $v_x \times \texttt{swing\_angle} + v_\theta \times \texttt{swing\_angle}$. This meant that both full linear and angular movements were requested, the resulting angles sent to the servos would be twice the specified maximum---i.e., $2 \times \texttt{swing\_angle}$. This was a rather nasty problem as it caused the legs of the robot to collide and get stuck inside one another.
The solution was to utilise ratios such that the maximum angle sent to the servos could only be \texttt{swing\_angle}, as described in great detail in the implementation section. After applying this correction, the robot could move around correctly as intended. However, while this correction prevents the legs from colliding with one another, the speed at which the robot moves is somewhat reduced. If both maximum linear and angular movements are requested, the robot will only move at half the maximum speed, as the ratio formula divides \texttt{swing\_angle} equally.
\section{Sensing}
These following experiments were created to evaluate that the sensing subsystems could interpret the world around the robot via the supplied camera input. Specifically, we test both the visual odometry and mapping components of the subsystem.
\subsection{Visual Odometry}
To test the visual odometry component, which was provided by the \texttt{visual\_odometry} node in the \texttt{ccny\_rgbd} package, we ran the following experiments. These experiments involved moving the robot in various ways while observing how accurately the visual odometery component matched these movements. Experiments would be ran with both manual movement of the robot---i.e., lifting it up along a path by hand---as well as with the implemented tripod gait. The \texttt{tf\_echo} tool from the \emph{tf} suite was used to get an exact readout of the interpreted position. Each experiment was ran ten times and the resulting positions averaged.
\subsubsection{Linear Motion}
The first experiment involved moving the robot forward by one meter while observing the position given by the visual odometery component. At the start of each test, the robot was placed at the starting position shown in \autoref{fig:eval_plan} and the control system reset. The robot would then be moved forward---either manually by hand or via the tripod gait---such that the robot had moved a meter relative to this starting position. Two points were placed both at the start and end positions such that the front two feet could be aligned with them. An ideal result would have been a resulting position of $(1$m, $0$m, $0$\textdegree{}$)$.
By manual movement, the visual odometery component gave an average position of $(0.924$m, $0.004$m, $0.471$\textdegree{}$)$. Notably, the system seemed to underestimate the $x$ component by an average of $0.076$m in this case, while the $y$ component and heading remained fairly accurate. A full listing of the results can be seen in \autoref{tab:eval_vo}.
By movement via the tripod gait, the visual odometery component gave an average position of $(0.952$m, $0.013$m, $0.191$\textdegree{}$)$. Similarly, the component seemed to underestimate the $x$ component by an average of $0.048$m while the heading remains reasonably accurate. The higher $y$ component drift in this case could be due to the roughness of the walk gait. Specifically, the camera does not glide forward exactly in a straight line as it does when being moved manually through the air. Each step causes the robot shake in general as it settles into position. Again, a full listing of the results can be seen in \autoref{tab:eval_vo}.
\subsubsection{Angular Motion}
The second experiment involved rotating the robot by $90$\textdegree{} in place. As before, the robot was placed at the starting position shown in \autoref{fig:eval_plan} and the control component reset at the start of each test. The robot would then be rotated clockwise by 90\textdegree{} on the spot either either manually by hand or via the tripod gait. An ideal result would have been a resulting position of $(0$m, $0$m, $90$\textdegree{}$)$.
By manual movement, the visual odometery component gave an average position of $(0.1$m, $0.004$m, $89.296$\textdegree{}$)$. By movement via the tripod gait, the visual odometery system gave an average position of $(0.172$m, $-0.018$m, $89.284$\textdegree{}$)$. A full listing of the results from both tests can be seen in \autoref{tab:eval_vo_rot}.
In both cases, there was a significant drift in the $x$ component---a drift of $0.1$m and $0.172$m for the manual and tripod gait movements respectively---while the $y$ and $\theta_z$ components remained fairly accurate. While observing the visual odometry output through \emph{RViz}, it seemed as though the robot was rotating around a pivot rather than in place as it should be. This was a particularly troubling outcome as it had the potential to disrupt both the mapping and navigation systems, but no further diagnosis could be done without delving into the complexities of the node's source code. It is possible that a more in-depth calibration of the camera lenses is necessary, as any warping of points caused by the lens may not be taken into account. A further evaluation into this particular aspect is definitely necessary.
\subsubsection{General Commentary}
As an additional issue, should the visual odometry component be unable to find sufficient features in the images it is currently receiving---e.g., some object is obstructing the camera--- then the output position will be essentially, undefined. While an actual position is output by the component in this case, it could essentially be considered completely random and therefore useless. Additionally, when the component is able to find sufficient features once more, the position does not reset to where it was previously. At this point, the whole control component must be restarted to resume normal operations.
In general, it is was not unexpected that the visual odometry component had some positional drift. The concept of odometry is such that it provides an estimate of the current position in space, rather than an exact position. Additional sensors---e.g., laser scanners, accelerometers, GPS, etc---would be very useful in this case. A multitude of filters can then be used to combine the information such that the robot can be localized in space much more accurately.
\subsection{Mapping}
To evaluate the mapping component, we ran the following set of experiments. These experiments would confirm that the mapping component could interpret the environment surrounding the robot correctly. Additionally, they would confirm that the map can update in real-time as the robot moved around the environment. A \emph{rviz} configuration was made to display both 2D and 3D maps generated by the \texttt{octomap\_server} node, allowing us to observe the results visually.
\subsubsection{Stationary Mapping}
The first experiment involved placing the robot on the starting position as shown in \autoref{fig:eval_plan}. The robot control system would then be started, and the map output shown in \emph{rviz} observed, checking the map for general accuracy versus the real environment. No movements---apart from putting the robot into a steady standing position---would be performed.
\begin{figure}[h]
\centering
\includegraphics[width=14cm]{eval_map1.jpg} \\
\vspace{2pt}
\includegraphics[width=8cm]{eval_rgbd3.jpg}
\includegraphics[width=8cm]{eval_rgbd4.jpg}
\caption{A display of the generated map a few seconds after the robot control system has started along with the direct colour (bottom left) and depth (bottom right) outputs from the RGB-D camera. The shape of the desk and wall directly in front of the robot, as seen in the colour image, can clearly be seen in the resulting map.}
\label{fig:eval_map_nobag}
\end{figure}
The resulting output along with raw imagery from the camera for this test as shown in \autoref{fig:eval_map_nobag}. While the map was generally accurate, there was some noise visible in the map output. It is possible that the mapping component could have erroneously detected some parts of the floor as obstacles. Regardless, they are so insignificant that the navigational systems would not have any issue with them. Thusly, this results of this experiment were deemed adequate.
\subsubsection{Stationary Mapping with an Obstacle}
The second experiment was performed in a manner similar to the previous experiment. At the start of the test, the robot was placed at the starting position and the control system started. The map output from the same \emph{rviz} configuration would then be observed. This time, however, after a few seconds an obstacle---in this case a backpack of similar height to the robot---would be placed $1$m in front of the robot. It was expected that the bag should then show up as an obstacle on the map. No movement would be performed, as before.
\begin{figure}[h]
\centering
\includegraphics[width=14cm]{eval_map2.jpg} \\
\vspace{2pt}
\includegraphics[width=8cm]{eval_rgbd1.jpg}
\includegraphics[width=8cm]{eval_rgbd2.jpg}
\caption{A display of the generated map after an obstacle has been placed in front of the robot---a backpack in this case---along with the direct RGB (bottom left) and depth (bottom right) outputs from the RGB-D camera. The resulting blocks from the bag can be seen on the map. Notably, the bag appears as a rather patchy grouping of blocks but would still be enough to trigger any avoidance routines from the navigation system.}
\label{fig:eval_map_bag}
\end{figure}
The resulting output after having placed the obstacle in front of the robot can be seen in \autoref{fig:eval_map_bag}. In this case, the surrounding environment was mapped quite accurately once again. The bag was also detected and mapped, however the resulting points were rather disjointed. The full shape of the obstacle was not mapped completely, even though it can be seen quite clearly in the raw imagery. Even though this was the case, the navigational system would have still been able to route around these points as the base footprint of the object can still be seen.
\subsubsection{Mapping During Walk Cycle}
The final experiment aimed to test the accuracy of the mapping component as the robot moved around the environment using the tripod gait. In particular, the robot would walk around the environment along the path as shown on \autoref{fig:eval_plan}, starting from the start position and ending at the end position. Manual control through the gamepad controller would be used for this test, rather than relying on the navigational system. The same \emph{rviz} configuration from previous tests would be used to visually observe the generated map for accuracy.
\begin{figure}[h]
\centering
\includegraphics[width=16cm]{eval_map3.jpg}
\caption{A display of the generated map after the robot has had a tour around the environment, as provided by RViz. It can be seen that the mapping system correctly generated a reasonable facsimile of the surrounding environment, however there is a large amount of distortion due to the drift from the visual locomotory system. Additionally, a rather large patch of the floor (bottom left, specifically) has been detected as an obstacle. As an aside, a strange effect results from the mirror that sits in the corner of the environment (top left, specifically).}
\label{fig:eval_map_room}
\end{figure}
The resulting map output for this test is shown in \autoref{fig:eval_map_room}. While the mapping component generated a reasonable facsimile of the surrounding environment, there were significant distortions due to the positional drift caused by the visual odometery system, particularly when the robot was rotating. Specifically, the detected walls of the environment should have been at right angles to each other but are shown to be somewhat askew. As the mapping component depends entirely on the visual odometry component for a positional fix, there is little that could have been done to solve this issue. An additional facility to localise the robot's position based on the map rather than relative motion may have been helpful in this case, as it would be able to correct for any drift.
\section{Navigation}
To test the navigation subsystem, the following set of experiments were performed. In particular, we looked to test the time taken and accuracy for the movements generated by this system when asked to reach a particular goal. To give a comparison, we would compare the results to that of those given from manual movements following an ``ideal'' path. This would require full integration and correct operations of all previously tested subsystems thus far, as the navigation subsystem relies on all of these subsystems for its own operation.
Specifically, two different sets of experiments were performed. One set would test autonomous navigation on a direct path with minimal rotation whereas the other would test a more complex path involving multiple turns.
\subsection{Direct Path}
The first set of experiments aimed to test the navigation system given a goal directly in front of the robots, such that no rotations were required. The target goal would be $3$m forward from the robot's starting position. At the start of each test, the control system would be reset. Once the system was ready, a goal would be set $3$m from the starting position with a forward heading using the target tool on \emph{rviz}. Time would be recorded and general accuracy observed. As a comparison, the time taken to move along the path manually using the gamepad controller would be recorded.
Dynamic obstacle avoidance would also be tested. An object---in this case a backpack as used in the previous examples---would be placed in front of the robot as it reached $1$m. How well the navigation system managed to move around this object would then be observed.
\subsubsection{Without Obstacle}
The first experiment in this set would evaluate accuracy and timing without any obstacles in the path of the robot. First, a number of manual movements were done as a control which gave a resulting average time of $36.164$s from start point to end point. Following this, tests using the navigation system were performed. These tests gave a resulting average time of $45.495$s from start point to end point, giving an average increase in time of $9.331$s. A full listing of results can be seen in \autoref{tab:eval_nav_dp_wo}.
The navigation subsystem spends a lot of time trying to keep the robot directly on its planned path---as one would expect---but this resulted in a number of unnecessary rotations, slowing down the overall movement. Additionally, some amount of processing time is needed for the system to compute a path. These are the most likely sources of this time increase. In general, however, the motions given by the system were reasonably accurate.
\subsubsection{With Obstacle}
The second experiment in this set would evaluate the accuracy and timing of the navigational system, but this time after an obstacle had been placed in front of the robot while it was walking. As before, a number of manual movements were performed for control---assuming that an ideal path was to curve around the obstacle. The manual movements gave an average time of $51.136$s. Following this, tests using the navigation system alone were performed. These autonomous tests gave a resulting average time of $1$m $5.677$s from start point to end point, giving an average increase in time of $14.541$s. A full listing of results can be seen in \autoref{tab:eval_nav_dp}.
\begin{figure}[h]
\centering
\includegraphics[width=14cm]{eval_nav.jpg}
\caption{A display of the planned path from the autonomous navigation system after an obstacle---in this case a backpack as before---has been placed in front of the robot. Prior to this image the planned path was directly ahead with no rotations. However, after the obstacle has been placed in front of the robot, the navigation system automatically recalculates the path such that it avoid the obstacles. The circular patterns on the ground plane indicate obstacle radii on the planner's avoidance costmap.}
\label{fig:eval_nav}
\end{figure}
An example of the path generated after the bag has been placed in front of the robot can be seen in \autoref{fig:eval_nav}. The causes of this time increase were similar to those mentioned in the previous test, but with the added rotational visual odometry drift. This rotational drift from the causes the navigation system to try and correct itself unnecessarily even though it is already in the correct position. Regardless, the robot was able to navigate around the bag successfully each time.
\subsection{Complex Path}
The second set of experiments aimed to test the navigation subsystem given a goal that would create a complex path. In these cases, the starting position and target end position would be those shown in \autoref{fig:eval_map_room}. This would show that the robot was capable of moving from one side of the room to the other. Two experiments would be performed: one where the robot had a chance to move around before hand such that the environment was already mapped, and the other where the control system had no knowledge of the environment before hand. As before, time would be recorded and general accuracy observed. A manually controlled walk would be done for time comparison.
\subsubsection{Known Environment}
The first experiment in this set would aim to prove the accuracy and efficiency of the navigation subsystem in a known environment. A number of manual tours around the ``ideal'' path would be performed before hand to get a control on timing as well as to provide a good mapping of the environment. After this, the robot would be placed at its starting position and commanded to navigate to the end position, as shown on \autoref{fig:eval_map_room}.
The manual movements from this experiment gave an average time of $2$m $5.649$s. For the autonomous navigation tests, the resulting average time was $2$m $30.561$s giving a difference of $24.912$s. This additional time is for the same reasons as explained in the previous tests. In one case, the test did not finish due to a cascading set of failures. Specifically, the navigation subsystem managed to propel the robot into a nearby obstacle whereupon the visual odometry system ceased to give a positional fix. This required a full restart of the control system and, thus, was counted as a ``did not finish'' result.
Generally, however, the test was successful. The visual odometry drift issue was still apparent overall but not enough to cause any significant problems.
\subsubsection{Unknown Environment}
The final experiment would aim to prove the accuracy and efficiency of the navigation system in an unknown environment. Unlike the previous test, no manual walking was performed to provide any mapping information. The control system would be started cleanly and then be expected to navigate from one side of the environment to the other. Manual timing information from the previous experiment would be used as a control---it did not make much sense for us to run the tests again when we ourselves already knew the environment. The navigation subsystem would have to detect and avoid obstacles to get to the end position as it moved the robot around.
Results from this test were varied. Out of the seven tests that completed successfully, the average time taken was $3$m $37.486$s giving a time difference from the control of $1$m $31.837$s. For those tests that did not complete successfully, similar issues as of those in the previous experiment occurred. Upon receiving the target goal, the navigation system immediately assumes it can get there directly as it has no information telling it otherwise. In these failure cases, the robot would get stuck facing the obstacle as the visual odometry system fails to detect any features from it due to being too close, causing a cascading failure of the mapping and navigational systems. In most cases, however, the robot was able to detect and adjust its path accordingly before it could get stuck.
Further tweaking of both the navigation and visual odometry systems is needed to improve upon these results.
|
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 2 14:28:44 2019
@author: aaussel
"""
#import matplotlib
#matplotlib.use('Agg')
from brian2 import *
start_scope()
from scipy import signal
from cells.RS_LIP import *
from cells.FS_LIP import *
from cells.SI_LIP import *
from cells.IB_soma_LIP import *
from cells.IB_axon_LIP import *
from cells.IB_apical_dendrite_LIP import *
from cells.IB_basal_dendrite_LIP import *
from LIP_superficial_layer import *
from LIP_beta1 import *
#from joblib import Parallel, delayed
#from joblib import parallel_backend
#import multiprocessing
import os
os.environ['MKL_NUM_THREADS'] = '1'
os.environ['OMP_NUM_THREADS'] = '1'
os.environ['MKL_DYNAMIC'] = 'FALSE'
import time
from itertools import *
##Custom
#input_beta2_IB=False
#input_beta2_RS=False
#input_beta2_FS_SI=False
#input_thalamus_gran=False
#thal_cond=8* msiemens * cm **-2
#kainate='low'
def make_full_network(syn_cond,J,thal,t_FS,theta_phase):
# print(syn_cond,J,thal,theta_phase)
NN=1 #multiplicative factor on the number of neurons
N_RS,N_FS,N_SI,N_IB= NN*80,NN*20,NN*20,NN*20 #Number of neurons of RE, TC, and HTC type
gSIdFSg,gFSgRSg,gRSgFSg,gRSgRSg,gFSgFSg,gRSgRSs,gRSgFSs,gFSgRSs=syn_cond
J_RSg,J_FSg=J
FLee=(0.05*mS/cm**2)/(0.4*uS/cm**2)*0.5
version = 'Alex'
runtime=3*second
kainate='low'
all_neurons, all_synapses, all_gap_junctions, all_monitors=create_Mark_Alex_network(kainate,version,Nf=NN)
V1,V2,V3,R1,R2,R3,I1,I2,I3,V4,R4,I4s,I4a,I4ad,I4bd=all_monitors
RS, FS, SI, IB_soma,IB_axon,IB_bd,IB_ad =all_neurons
if theta_phase=='bad':
input_beta2_IB=False
input_beta2_RS=False
input_beta2_FS_SI=True
input_thalamus_gran=True
gFS=0* msiemens * cm **-2
SI.ginp_SI=0* msiemens * cm **-2
thal_cond=2* msiemens * cm **-2
input_mixed=False
if theta_phase=='good':
input_beta2_IB=True
IB_bd.ginp_IB=500* msiemens * cm **-2
input_beta2_RS=False
input_beta2_FS_SI=False
input_thalamus_gran=True
thal_cond=thal
input_mixed=False
if theta_phase=='mixed':
input_mixed=True
IB_bd.ginp_IB=500* msiemens * cm **-2
input_beta2_IB=False
input_beta2_RS=False
input_beta2_RS=False
input_beta2_FS_SI=False
input_thalamus_gran=False
# print(input_mixed,input_beta2_IB,input_beta2_RS,input_beta2_FS_SI,input_thalamus_gran)
prefs.codegen.target = 'numpy'
defaultclock.dt = 0.01*ms
#Single column network
##Define neuron groups
E_gran=NeuronGroup(N_FS,eq_RS_LIP,threshold='V>-20*mvolt',refractory=3*ms,method='rk4')
E_gran.V = '-70*mvolt+10*rand()*mvolt'
E_gran.h = '0+0.05*rand()'
E_gran.m = '0+0.05*rand()'
E_gran.mAR = '0.035+0.025*rand()'
if kainate=='low':
# E_gran.J='1 * uA * cmeter ** -2' #article SI=25, code=1
E_gran.J=J_RSg
elif kainate=='high':
E_gran.J='-10 * uA * cmeter ** -2' #article SI=25, code=1
FS_gran=NeuronGroup(N_FS,eq_FS_LIP,threshold='V>-20*mvolt',refractory=3*ms,method='rk4')
FS_gran.V = '-110*mvolt+10*rand()*mvolt'
FS_gran.h = '0+0.05*rand()'
FS_gran.m = '0+0.05*rand()'
if kainate=='low':
# FS_gran.J='5 * uA * cmeter ** -2' #article=code=35
FS_gran.J=J_FSg
elif kainate=='high':
FS_gran.J='16 * uA * cmeter ** -2'
SI_deep=NeuronGroup(N_SI,eq_SI_LIP,threshold='V>-20*mvolt',refractory=3*ms,method='rk4')
SI_deep.V = '-100*mvolt+10*rand()*mvolt'
SI_deep.h = '0+0.05*rand()'
SI_deep.m = '0+0.05*rand()'
SI_deep.mAR = '0.02+0.04*rand()'
if version == 'Alex':
if kainate=='low':
SI_deep.J='35* uA * cmeter ** -2' #article SI=50, code=35, Mark = 45
elif kainate=='high':
SI_deep.J='30* uA * cmeter ** -2' #article SI=50, code=35, Mark = 45
elif version=='Mark':
if kainate=='low':
SI_deep.J='45* uA * cmeter ** -2' #article SI=50, code=35, Mark = 45
elif kainate=='high':
SI_deep.J='40* uA * cmeter ** -2' #article SI=50, code=35, Mark = 45
if theta_phase=='good' or theta_phase=='mixed':
SI_deep.ginp_SI=500* msiemens * cm **-2
##Synapses
eq_syn='''_post=s_i*g_i*(V_post-V_i) : amp * meter ** -2 (summed)
ds_i/dt=-s_i/taud_i+(1-s_i)/taur_i*0.5*(1+tanh(V_pre/10/mV)) : 1
g_i : siemens * meter**-2
V_i : volt
taud_i : second
taur_i : second
'''
def generate_syn(source,target,syntype,connection_pattern,g_i,taur_i,taud_i,V_i):
S=Synapses(source,target,model=syntype+eq_syn,method='exact')
if connection_pattern=='':
S.connect()
else :
S.connect(j=connection_pattern, skip_if_invalid=True)
S.g_i=g_i
S.taur_i=taur_i
S.taud_i=taud_i
S.V_i=V_i
return S
#From E (granular layer) cells
#S_EgranFS=generate_syn(E_gran,FS,'IsynEgran','',0.2*usiemens * cm **-2*FLee,0.125*ms,1*ms,0*mV)
#S_EgranFS=generate_syn(E_gran,FS,'IsynEgran','',0.1*msiemens * cm **-2,0.125*ms,1*ms,0*mV)
S_EgranFS=generate_syn(E_gran,FS,'IsynRS_LIP_gran','',gRSgFSs,0.125*ms,1*ms,0*mV)
#S_EgranEgran=generate_syn(E_gran,E_gran,'IsynEgran','',0.4*usiemens * cm **-2*FLee,0.125*ms,1*ms,0*mV)
S_EgranEgran=generate_syn(E_gran,E_gran,'IsynRS_LIP_gran','',gRSgRSg,0.125*ms,1*ms,0*mV)
#S_EgranFSgran=generate_syn(E_gran,FS_gran,'IsynEgran','',0.2*usiemens * cm **-2*FLee,0.125*ms,1*ms,0*mV)
S_EgranFSgran=generate_syn(E_gran,FS_gran,'IsynRS_LIP_gran','',gRSgFSg,0.125*ms,1*ms,0*mV)
#S_EgranRS=generate_syn(E_gran,RS,'IsynEgran','',0.2*usiemens * cm **-2*FLee,0.125*ms,1*ms,0*mV)
#S_EgranRS=generate_syn(E_gran,RS,'IsynEgran','',1*msiemens * cm **-2,0.125*ms,1*ms,0*mV)
S_EgranRS=generate_syn(E_gran,RS,'IsynRS_LIP_gran','',gRSgRSs,0.125*ms,1*ms,0*mV)
S_EgranIB=generate_syn(E_gran,IB_ad,'IsynRS_LIP_gran','',0.212*usiemens * cm **-2*FLee,0.125*ms,1*ms,0*mV)
#From FS (granular layer) cells
#S_FSgranEgran=generate_syn(FS_gran,E_gran,'IsynFSgran','',1* usiemens * cm **-2*FLee,0.25*ms,5*ms,-80*mV)
S_FSgranEgran=generate_syn(FS_gran,E_gran,'IsynFS_LIP_gran','',gFSgRSg,0.25*ms,t_FS,-80*mV)
S_FSgranFSgran=generate_syn(FS_gran,FS_gran,'IsynFS_LIP_gran','',gFSgFSg,0.25*ms,t_FS,-75*mV)
#S_FSgranRS=generate_syn(FS_gran,RS,'IsynFSgran','',0.02* usiemens * cm **-2*FLee,0.25*ms,5*ms,-80*mV)
S_FSgranRS=generate_syn(FS_gran,RS,'IsynFS_LIP_gran','',gFSgRSs,0.25*ms,5*ms,-80*mV)
#S_FSgranRS=generate_syn(FS_gran,RS,'IsynFSgran','',0* msiemens * cm **-2,0.25*ms,5*ms,-80*mV)
#From IB cells
#S_IBSIdeep=generate_syn(IB_axon,SI_deep,'IsynIB','',0.12* usiemens * cm **-2*FLee,0.125*ms,1*ms,0*mV)
# S_IBSIdeep=generate_syn(IB_axon,SI_deep,'IsynIB','',0.2* msiemens * cm **-2,0.125*ms,1*ms,0*mV)
S_IBSIdeep=generate_syn(IB_axon,SI_deep,'IsynIB_LIP','',0.01* msiemens * cm **-2,0.125*ms,1*ms,0*mV)
#From deep SI cells
S_SIdeepIB=generate_syn(SI_deep,IB_bd,'IsynSI_LIP_deep','',10* msiemens * cm **-2,0.25*ms,20*ms,-80*mV)
#S_SIdeepFSgran=generate_syn(SI_deep,FS_gran,'IsynSIdeep','',0.4* usiemens * cm **-2*FLee,0.25*ms,20*ms,-80*mV)
S_SIdeepFSgran=generate_syn(SI_deep,FS_gran,'IsynSI_LIP_deep','',gSIdFSg,0.25*ms,20*ms,-80*mV)
def generate_spike_timing(N,f,start_time,end_time=runtime):
list_time_and_i=[]
for i in range(N):
list_time=[(start_time,i)]
next_spike=list_time[-1][0]+(1+0.1*rand())/f
while next_spike<end_time:
list_time.append((next_spike,i))
next_spike=list_time[-1][0]+(1+0.1*rand())/f
list_time_and_i+=list_time
return array(list_time_and_i)
def generate_spike_timing_theta(N,f,start_time,end_time=runtime,f_theta=4*Hz):
list_time_and_i=[]
for i in range(N):
list_time=[(start_time,i)]
# next_spike=list_time[-1][0]+(1+0.1*rand())/f
next_spike=list_time[-1][0]+1/f
while next_spike<end_time:
if int(sin(2*pi*next_spike*f_theta)>0)==1:
list_time.append((next_spike,i))
next_spike=next_spike+1/f
list_time_and_i+=list_time
return array(list_time_and_i)
G_topdown,G_topdown2,G_topdown3,G_lateral,G_lateral2,Poisson_input,Poisson_input2=[None]*7
topdown_in,topdown_in2,topdown_in3,lateral_in,lateral_in2,bottomup_in,bottomup_in2=[None]*7
if input_beta2_IB:
# inputs_topdown=generate_spike_timing(N_IB,25*Hz,0*ms,end_time=3000*ms)
# G_topdown = SpikeGeneratorGroup(N_IB, inputs_topdown[:,1], inputs_topdown[:,0]*second)
# topdown_in=Synapses(G_topdown,IB_bd,on_pre='Vinp=Vhigh')
# topdown_in.connect(j='i')
inputs_topdown3=generate_spike_timing(N_SI,25*Hz,0*ms,end_time=3000*ms)
G_topdown3 = SpikeGeneratorGroup(N_SI, inputs_topdown3[:,1], inputs_topdown3[:,0]*second)
topdown_in3=Synapses(G_topdown3,SI_deep,on_pre='Vinp=Vhigh')
topdown_in3.connect(j='i')
if input_beta2_RS:
RS.ginp_RS_good=4* msiemens * cm **-2
RS.ginp_RS_bad=4* msiemens * cm **-2
inputs_topdown2=generate_spike_timing(N_RS,25*Hz,0*ms,end_time=3000*ms)
G_topdown2 = SpikeGeneratorGroup(N_RS, inputs_topdown2[:,1], inputs_topdown2[:,0]*second)
topdown_in2=Synapses(G_topdown2,RS,on_pre='Vinp=Vhigh')
topdown_in2.connect(j='i')
if input_beta2_FS_SI:
FS.ginp_FS_good=gFS
FS.ginp_FS_bad=gFS
inputs_lateral=generate_spike_timing(N_FS,25*Hz,0*ms,end_time=3000*ms)
G_lateral = SpikeGeneratorGroup(N_FS, inputs_lateral[:,1], inputs_lateral[:,0]*second)
lateral_in=Synapses(G_lateral,FS,on_pre='Vinp=Vhigh')
lateral_in.connect(j='i')
inputs_lateral2=generate_spike_timing(N_SI,25*Hz,0*ms,end_time=3000*ms)
G_lateral2 = SpikeGeneratorGroup(N_SI, inputs_lateral2[:,1], inputs_lateral2[:,0]*second)
lateral_in2=Synapses(G_lateral2,SI,on_pre='Vinp=Vhigh')
lateral_in2.connect(j='i')
if input_thalamus_gran:
E_gran.ginp_RS_good=thal_cond
FS_gran.ginp_FS_good=thal_cond
E_gran.ginp_RS_bad=thal_cond
FS_gran.ginp_FS_bad=thal_cond
# print(E_gran.ginp_RS_good,FS_gran.ginp_FS_good,E_gran.ginp_RS_bad,FS_gran.ginp_FS_bad)
# FS_gran.ginp_FS=thal_cond
inputs_mdpul=generate_spike_timing(N_FS,13*Hz,0*ms,end_time=3000*ms)
Poisson_input = SpikeGeneratorGroup(N_FS, inputs_mdpul[:,1], inputs_mdpul[:,0]*second)
# Poisson_input = PoissonGroup(N_FS,100*Hz)
bottomup_in = Synapses(Poisson_input,FS_gran, on_pre='Vinp=Vhigh')
bottomup_in.connect(j='i')
# E_gran.ginp_RS=thal_cond
Poisson_input2 = SpikeGeneratorGroup(N_FS, inputs_mdpul[:,1], inputs_mdpul[:,0]*second)
# Poisson_input2 = PoissonGroup(N_FS,100*Hz)
bottomup_in2 = Synapses(Poisson_input2,E_gran, on_pre='Vinp=Vhigh')
bottomup_in2.connect(j='i')
# print(bottomup_in,bottomup_in2)
if input_mixed:
E_gran.ginp_RS_good=5* msiemens * cm **-2
FS_gran.ginp_FS_good=5* msiemens * cm **-2
# E_gran.ginp_RS_bad=2* msiemens * cm **-2
# FS_gran.ginp_FS_bad=2* msiemens * cm **-2
E_gran.ginp_RS_bad=5* msiemens * cm **-2
FS_gran.ginp_FS_bad=5* msiemens * cm **-2
# FS_gran.ginp_FS='15* msiemens * cm **-2 * int(sin(2*pi*t*4*Hz)>0) + 2* msiemens * cm **-2 * int(sin(2*pi*t*4*Hz)<0)'
# inputs_mdpul=generate_spike_timing_theta(N_FS,13*Hz,0*ms,end_time=3000*ms)
t0=0*ms
t1=125*ms
inputs_mdpul=generate_spike_timing(N_SI,13*Hz,t0,end_time=t1)
while t0+250*ms<runtime:
t0,t1=t0+250*ms,t1+250*ms
inputs_mdpul=vstack((inputs_mdpul,generate_spike_timing(N_SI,13*Hz,t0,end_time=t1)))
Poisson_input = SpikeGeneratorGroup(N_FS, inputs_mdpul[:,1], inputs_mdpul[:,0]*second)
# Poisson_input = PoissonGroup(N_FS,100*Hz)
bottomup_in = Synapses(Poisson_input,FS_gran, on_pre='Vinp=Vhigh')
bottomup_in.connect(j='i')
# E_gran.ginp_RS='15* msiemens * cm **-2 * int(sin(2*pi*t*4*Hz)>0) + 2* msiemens * cm **-2 * int(sin(2*pi*t*4*Hz)<0)'
Poisson_input2 = SpikeGeneratorGroup(N_FS, inputs_mdpul[:,1], inputs_mdpul[:,0]*second)
# Poisson_input2 = PoissonGroup(N_FS,100*Hz)
bottomup_in2 = Synapses(Poisson_input2,E_gran, on_pre='Vinp=Vhigh')
bottomup_in2.connect(j='i')
inputs_topdown=generate_spike_timing_theta(N_IB,25*Hz,0*ms,end_time=5100*ms)
G_topdown = SpikeGeneratorGroup(N_IB, inputs_topdown[:,1], inputs_topdown[:,0]*second)
topdown_in=Synapses(G_topdown,IB_bd,on_pre='Vinp=Vhigh')
topdown_in.connect(j='i')
inputs_topdown3=generate_spike_timing_theta(N_SI,25*Hz,0*ms,end_time=5100*ms)
G_topdown3 = SpikeGeneratorGroup(N_SI, inputs_topdown3[:,1], inputs_topdown3[:,0]*second)
topdown_in3=Synapses(G_topdown3,SI_deep,on_pre='Vinp=Vhigh')
topdown_in3.connect(j='i')
# g_inputs=[G_topdown,G_topdown2,G_topdown3,G_lateral,G_lateral2,Poisson_input,Poisson_input2]
# g_inputs=[y for y in g_inputs if y]
# syn_inputs=[topdown_in,topdown_in2,topdown_in3,lateral_in,lateral_in2,bottomup_in,bottomup_in2]
# syn_inputs=[y for y in syn_inputs if y]
g_inputs=[G_topdown2,G_topdown3,G_lateral,G_lateral2,Poisson_input,Poisson_input2]
g_inputs=[y for y in g_inputs if y]
syn_inputs=[topdown_in2,topdown_in3,lateral_in,lateral_in2,bottomup_in,bottomup_in2]
syn_inputs=[y for y in syn_inputs if y]
#Define monitors and run network :
R5=SpikeMonitor(E_gran,record=True)
R6=SpikeMonitor(FS_gran,record=True)
R7=SpikeMonitor(SI_deep,record=True)
V5=StateMonitor(E_gran,'V',record=True)
V6=StateMonitor(FS_gran,'V',record=True)
V7=StateMonitor(SI_deep,'V',record=True)
inpmon=StateMonitor(E_gran,'Iinp1',record=True)
#graninpmon=StateMonitor(FS,'IsynEgran',record=[0])
inpIBmon=StateMonitor(IB_bd,'Iapp',record=[0])
all_neurons=all_neurons+(E_gran,FS_gran,SI_deep)+tuple(g_inputs)
all_synapses=all_synapses+(S_EgranFS,S_EgranEgran,S_EgranFSgran,S_EgranRS,S_EgranIB,S_FSgranEgran,S_FSgranFSgran,S_FSgranRS,S_IBSIdeep,S_SIdeepIB,S_SIdeepFSgran)+tuple(syn_inputs)
all_monitors=all_monitors+(R5,R6,R7,V5,V6,V7,inpmon,inpIBmon)
return all_neurons, all_synapses, all_gap_junctions, all_monitors
def run_one_simulation(simu,path,index_var):
# print(simu,len(simu))
start_scope()
close('all')
runtime=1*second
Vrev_inp=0*mV
taurinp=0.1*ms
taudinp=0.5*ms
tauinp=taudinp
Vhigh=0*mV
Vlow=-80*mV
ginp_IB=0* msiemens * cm **-2
ginp_SI=0* msiemens * cm **-2
ginp=0* msiemens * cm **-2
NN=1 #multiplicative factor on the number of neurons
N_RS,N_FS,N_SI,N_IB= NN*80,NN*20,NN*20,NN*20 #Number of neurons of RE, TC, and HTC type
syn_cond,J,thal,theta_phase,index=simu
print('Simulation '+str(index))
if theta_phase=='bad':
input_beta2_IB=False
input_beta2_RS=False
input_beta2_FS_SI=True
input_thalamus_gran=True
gFS=0* msiemens * cm **-2
ginp_SI=0* msiemens * cm **-2
ginpSIdeep=0* msiemens * cm **-2
thal_cond=2* msiemens * cm **-2
kainate='low'
input_mixed=False
if theta_phase=='good':
# input_beta2_IB=True
input_beta2_IB=False
ginp_IB=500* msiemens * cm **-2
ginpSIdeep=500* msiemens * cm **-2
input_beta2_RS=False
input_beta2_FS_SI=False
input_thalamus_gran=True
thal_cond=thal
kainate='low'
input_mixed=False
if theta_phase=='mixed':
input_mixed=True
ginp_IB=500* msiemens * cm **-2
ginpSIdeep=500* msiemens * cm **-2
input_beta2_IB=False
input_beta2_RS=False
input_beta2_RS=False
input_beta2_FS_SI=False
input_thalamus_gran=False
kainate='low'
net = Network(collect())
print('Network setup')
all_neurons, all_synapses, all_gap_junctions, all_monitors=make_full_network(syn_cond,J,thal,5*ms,theta_phase)
V1,V2,V3,R1,R2,R3,I1,I2,I3,V4,R4,I4s,I4a,I4ad,I4bd,R5,R6,R7,V5,V6,V7,inpmon,inpIBmon=all_monitors
net.add(all_neurons)
net.add(all_synapses)
net.add(all_gap_junctions)
net.add(all_monitors)
print('Compiling with cython')
prefs.codegen.target = 'cython' #cython=faster, numpy = default python
net.run(runtime,report='text',report_period=300*second)
figure()
plot(R1.t,R1.i+140,'r.',label='RS cells')
plot(R2.t,R2.i+120,'m.',label='FS cells')
plot(R3.t,R3.i+100,'y.',label='SI cells')
plot(R5.t,R5.i+70,'g.',label='Granular RS')
plot(R6.t,R6.i+50,'c.',label='Granular FS')
plot(R4.t,R4.i+20,'b.',label='IB cells')
plot(R7.t,R7.i,'k.',label='Deep SI')
xlim(0,runtime/second)
legend(loc='upper left')
figure()
plot(inpmon.t,inpmon.Iinp1[0])
min_t=int(50*ms*100000*Hz)
LFP_V_RS=1/N_RS*sum(V1.V,axis=0)[min_t:]
LFP_V_FS=1/N_FS*sum(V2.V,axis=0)[min_t:]
LFP_V_SI=1/N_SI*sum(V3.V,axis=0)[min_t:]
LFP_V_IB=1/N_IB*sum(V4.V,axis=0)[min_t:]
LFP_V_RSg=1/N_FS*sum(V5.V,axis=0)[min_t:]
LFP_V_FSg=1/N_FS*sum(V6.V,axis=0)[min_t:]
LFP_V_SId=1/N_SI*sum(V7.V,axis=0)[min_t:]
f,Spectrum_LFP_V_RS=signal.periodogram(LFP_V_RS, 100000,'flattop', scaling='spectrum')
f,Spectrum_LFP_V_FS=signal.periodogram(LFP_V_FS, 100000,'flattop', scaling='spectrum')
f,Spectrum_LFP_V_SI=signal.periodogram(LFP_V_SI, 100000,'flattop', scaling='spectrum')
f,Spectrum_LFP_V_IB=signal.periodogram(LFP_V_IB, 100000,'flattop', scaling='spectrum')
f,Spectrum_LFP_V_RSg=signal.periodogram(LFP_V_RSg, 100000,'flattop', scaling='spectrum')
f,Spectrum_LFP_V_FSg=signal.periodogram(LFP_V_FSg, 100000,'flattop', scaling='spectrum')
f,Spectrum_LFP_V_SId=signal.periodogram(LFP_V_SId, 100000,'flattop', scaling='spectrum')
figure(figsize=(10,8))
subplot(421)
plot(f,Spectrum_LFP_V_RS)
ylabel('Spectrum')
yticks([],[])
xlim(0,100)
title('RS cell')
subplot(422)
plot(f,Spectrum_LFP_V_FS)
yticks([],[])
xlim(0,100)
title('FS cell')
subplot(423)
plot(f,Spectrum_LFP_V_SI)
ylabel('Spectrum')
yticks([],[])
xlim(0,100)
title('SI cell')
subplot(425)
plot(f,Spectrum_LFP_V_RSg)
ylabel('Spectrum')
yticks([],[])
xlim(0,100)
title('gran RS cell')
subplot(426)
plot(f,Spectrum_LFP_V_FSg)
yticks([],[])
xlim(0,100)
title('gran FS cell')
subplot(427)
plot(f,Spectrum_LFP_V_IB)
xlabel('Frequency (Hz)')
ylabel('Spectrum')
yticks([],[])
xlim(0,100)
title('IB cell')
subplot(428)
plot(f,Spectrum_LFP_V_SId)
yticks([],[])
xlim(0,100)
xlabel('Frequency (Hz)')
title('deep SI cell')
tight_layout()
# min_t=int(50*ms*100000*Hz)
# LFP_V_RS=1/N_RS*sum(V1.V,axis=0)[min_t:]
# LFP_V_FS=1/N_FS*sum(V2.V,axis=0)[min_t:]
# LFP_V_SI=1/N_SI*sum(V3.V,axis=0)[min_t:]
# LFP_V_IB=1/N_IB*sum(V4.V,axis=0)[min_t:]
#
# f,Spectrum_LFP_V_RS=signal.periodogram(LFP_V_RS, 100000,'flattop', scaling='spectrum')
# f,Spectrum_LFP_V_FS=signal.periodogram(LFP_V_FS, 100000,'flattop', scaling='spectrum')
# f,Spectrum_LFP_V_SI=signal.periodogram(LFP_V_SI, 100000,'flattop', scaling='spectrum')
# f,Spectrum_LFP_V_IB=signal.periodogram(LFP_V_IB, 100000,'flattop', scaling='spectrum')
#
# figure()
# subplot(421)
# plot((V1.t/second)[min_t:],LFP_V_RS)
# ylabel('LFP')
# title('RS cell')
# subplot(423)
# plot((V1.t/second)[min_t:],LFP_V_FS)
# ylabel('LFP')
# title('FS cell')
# subplot(425)
# plot((V1.t/second)[min_t:],LFP_V_SI)
# ylabel('LFP')
# title('SI cell')
# subplot(427)
# plot((V1.t/second)[min_t:],LFP_V_IB)
# xlabel('Time (s)')
# ylabel('LFP')
# title('IB cell')
#
# subplot(422)
# plot(f,Spectrum_LFP_V_RS)
# ylabel('Spectrum')
# yticks([],[])
# xlim(0,100)
# title('RS cell')
# subplot(424)
# plot(f,Spectrum_LFP_V_FS)
# ylabel('Spectrum')
# yticks([],[])
# xlim(0,100)
# title('FS cell')
# subplot(426)
# plot(f,Spectrum_LFP_V_SI)
# ylabel('Spectrum')
# yticks([],[])
# xlim(0,100)
# title('SI cell')
# subplot(428)
# plot(f,Spectrum_LFP_V_IB)
# xlabel('Frequency (Hz)')
# ylabel('Spectrum')
# yticks([],[])
# xlim(0,100)
# title('IB cell')
##save figures
new_path=path+"/results_"+str(index)
os.mkdir(new_path)
for n in get_fignums():
current_fig=figure(n)
current_fig.savefig(new_path+'/figure'+str(n)+'.png')
if __name__=='__main__':
FLee=(0.05*mS/cm**2)/(0.4*uS/cm**2)*0.5
all_SIdFSg=[1*msiemens * cm **-2]
all_FSgRSg=[1* msiemens * cm **-2]
all_RSgFSg=[1*msiemens * cm **-2]
all_RSgRSg=[0.5*msiemens * cm **-2]
all_FSgFSg=[0.3* msiemens * cm **-2]
all_RSgRSs=[2*msiemens * cm **-2]
all_RSgFSs=[0.1*msiemens * cm **-2]
all_FSgRSs=[0.1* msiemens * cm **-2]
all_J_RSg=['15 * uA * cmeter ** -2'] #['20 * uA * cmeter ** -2']
all_J_FSg=['-5 * uA * cmeter ** -2']
all_thal=[10* msiemens * cm **-2]
all_theta=['mixed']
#FLee=(0.05*mS/cm**2)/(0.4*uS/cm**2)*0.5
#all_SIdFSg=[1*msiemens * cm **-2]
#all_FSgRSg=[1* msiemens * cm **-2]
#all_RSgFSg=[0.5*msiemens * cm **-2]
#all_RSgRSg=[0.3*msiemens * cm **-2]
#all_FSgFSg=[0.3* msiemens * cm **-2]
#all_RSgRSs=[0.25*msiemens * cm **-2]
#all_RSgFSs=[0.01*msiemens * cm **-2]
#all_FSgRSs=[0.01* msiemens * cm **-2]
#all_J_RSg=['30 * uA * cmeter ** -2']
#all_J_FSg=['30 * uA * cmeter ** -2']
#all_thal=[15* msiemens * cm **-2]
#all_theta=['good','bad']
all_syn_cond=list(product(all_SIdFSg,all_FSgRSg,all_RSgFSg,all_RSgRSg,all_FSgFSg,all_RSgRSs,all_RSgFSs,all_FSgRSs))
all_J=list(product(all_J_RSg,all_J_FSg))
path="./results_"+str(datetime.datetime.now())
os.mkdir(path)
all_sim=list(product(all_syn_cond,all_J,all_thal,all_theta))
index_var=[-1]
all_sim=[list(all_sim[i])+[i] for i in range(len(all_sim))]
#saving simulation parameters as a txt file
param_file=open(path+'/parameters.txt','w')
for simu in all_sim:
param_file.write(str(simu))
param_file.write('\n\n')
param_file.close()
#close('all')
#all_results=[]
#num_cores = multiprocessing.cpu_count()
#num_cores = 2
#with parallel_backend('multiprocessing'):
# Parallel(n_jobs=num_cores)(delayed(run_one_simulation)(simu,path,index_var) for simu in all_sim)
for simu in all_sim:
run_one_simulation(simu,path,index_var)
clear_cache('cython')
|
(* Title: SatSolverVerification/SatSolverVerification.thy
Author: Filip Maric
Maintainer: Filip Maric <filip at matf.bg.ac.yu>
*)
section\<open>Verification of DPLL based SAT solvers.\<close>
theory SatSolverVerification
imports CNF Trail
begin
text\<open>This theory contains a number of lemmas used in verification of
different SAT solvers. Although this file does not contain any
theorems significant on their own, it is an essential part of the SAT
solver correctness proof because it contains most of the technical
details used in the proofs that follow. These lemmas serve as a basis
for partial correctness proof for pseudo-code implementation of modern
SAT solvers described in \cite{JARrad}, in terms of Hoare logic.\<close>
(******************************************************************************)
subsection\<open>Literal Trail\<close>
(******************************************************************************)
text\<open>LiteralTrail is a Trail consisting of literals, where decision literals are marked.\<close>
type_synonym LiteralTrail = "Literal Trail"
abbreviation isDecision :: "('a \<times> bool) \<Rightarrow> bool"
where "isDecision l == marked l"
abbreviation lastDecision :: "LiteralTrail \<Rightarrow> Literal"
where "lastDecision M == Trail.lastMarked M"
abbreviation decisions :: "LiteralTrail \<Rightarrow> Literal list"
where "decisions M == Trail.markedElements M"
abbreviation decisionsTo :: "Literal \<Rightarrow> LiteralTrail \<Rightarrow> Literal list"
where "decisionsTo M l == Trail.markedElementsTo M l"
abbreviation prefixBeforeLastDecision :: "LiteralTrail \<Rightarrow> LiteralTrail"
where "prefixBeforeLastDecision M == Trail.prefixBeforeLastMarked M"
(*--------------------------------------------------------------------------*)
(* I N V A R I A N T S *)
(*--------------------------------------------------------------------------*)
(******************************************************************************)
subsection\<open>Invariants\<close>
(******************************************************************************)
text\<open>In this section a number of conditions will be formulated and
it will be shown that these conditions are invariant after applying
different DPLL-based transition rules.\<close>
definition
"InvariantConsistent (M::LiteralTrail) == consistent (elements M)"
definition
"InvariantUniq (M::LiteralTrail) == uniq (elements M)"
definition
"InvariantImpliedLiterals (F::Formula) (M::LiteralTrail) == \<forall> l. l el elements M \<longrightarrow> formulaEntailsLiteral (F @ val2form (decisionsTo l M)) l"
definition
"InvariantEquivalent (F0::Formula) (F::Formula) == equivalentFormulae F0 F"
definition
"InvariantVarsM (M::LiteralTrail) (F0::Formula) (Vbl::Variable set) == vars (elements M) \<subseteq> vars F0 \<union> Vbl"
definition
"InvariantVarsF (F::Formula) (F0::Formula) (Vbl::Variable set) == vars F \<subseteq> vars F0 \<union> Vbl"
text\<open>The following invariants are used in conflict analysis.\<close>
definition
"InvariantCFalse (conflictFlag::bool) (M::LiteralTrail) (C::Clause) == conflictFlag \<longrightarrow> clauseFalse C (elements M)"
definition
"InvariantCEntailed (conflictFlag::bool) (F::Formula) (C::Clause) == conflictFlag \<longrightarrow> formulaEntailsClause F C"
definition
"InvariantReasonClauses (F::Formula) (M::LiteralTrail) ==
\<forall> literal. literal el (elements M) \<and> \<not> literal el decisions M \<longrightarrow>
(\<exists> clause. formulaEntailsClause F clause \<and> isReason clause literal (elements M))"
(*----------------------------------------------------------------------*)
(* V E R I F I C A T I O N L E M M A S *)
(*----------------------------------------------------------------------*)
subsubsection\<open>Auxiliary lemmas\<close>
text\<open>This section contains some auxiliary lemmas that additionally
characterize some of invariants that have been defined.\<close>
(*------------------------- InvariantImpliedLiterals ---------------------*)
text\<open>Lemmas about @{term InvariantImpliedLiterals}.\<close>
lemma InvariantImpliedLiteralsWeakerVariant:
fixes M :: LiteralTrail and F :: Formula
assumes "\<forall> l. l el elements M \<longrightarrow> formulaEntailsLiteral (F @ val2form (decisionsTo l M)) l"
shows "\<forall> l. l el elements M \<longrightarrow> formulaEntailsLiteral (F @ val2form (decisions M)) l"
proof -
{
fix l :: Literal
assume "l el elements M"
with assms
have "formulaEntailsLiteral (F @ val2form (decisionsTo l M)) l"
by simp
have "isPrefix (decisionsTo l M) (decisions M)"
by (simp add: markedElementsToArePrefixOfMarkedElements)
then obtain s :: Valuation
where "(decisionsTo l M) @ s = (decisions M)"
using isPrefix_def [of "decisionsTo l M" "decisions M"]
by auto
hence "(decisions M) = (decisionsTo l M) @ s"
by (rule sym)
with \<open>formulaEntailsLiteral (F @ val2form (decisionsTo l M)) l\<close>
have "formulaEntailsLiteral (F @ val2form (decisions M)) l"
using formulaEntailsLiteralAppend [of "F @ val2form (decisionsTo l M)" "l" "val2form s"]
by (auto simp add:formulaEntailsLiteralAppend val2formAppend)
}
thus ?thesis
by simp
qed
lemma InvariantImpliedLiteralsAndElementsEntailLiteralThenDecisionsEntailLiteral:
fixes M :: LiteralTrail and F :: Formula and literal :: Literal
assumes "InvariantImpliedLiterals F M" and "formulaEntailsLiteral (F @ (val2form (elements M))) literal"
shows "formulaEntailsLiteral (F @ val2form (decisions M)) literal"
proof -
{
fix valuation :: Valuation
assume "model valuation (F @ val2form (decisions M))"
hence "formulaTrue F valuation" and "formulaTrue (val2form (decisions M)) valuation" and "consistent valuation"
by (auto simp add: formulaTrueAppend)
{
fix l :: Literal
assume "l el (elements M)"
from \<open>InvariantImpliedLiterals F M\<close>
have "\<forall> l. l el (elements M) \<longrightarrow> formulaEntailsLiteral (F @ val2form (decisions M)) l"
by (simp add: InvariantImpliedLiteralsWeakerVariant InvariantImpliedLiterals_def)
with \<open>l el (elements M)\<close>
have "formulaEntailsLiteral (F @ val2form (decisions M)) l"
by simp
with \<open>model valuation (F @ val2form (decisions M))\<close>
have "literalTrue l valuation"
by (simp add: formulaEntailsLiteral_def)
}
hence "formulaTrue (val2form (elements M)) valuation"
by (simp add: val2formFormulaTrue)
with \<open>formulaTrue F valuation\<close> \<open>consistent valuation\<close>
have "model valuation (F @ (val2form (elements M)))"
by (auto simp add:formulaTrueAppend)
with \<open>formulaEntailsLiteral (F @ (val2form (elements M))) literal\<close>
have "literalTrue literal valuation"
by (simp add: formulaEntailsLiteral_def)
}
thus ?thesis
by (simp add: formulaEntailsLiteral_def)
qed
lemma InvariantImpliedLiteralsAndFormulaFalseThenFormulaAndDecisionsAreNotSatisfiable:
fixes M :: LiteralTrail and F :: Formula
assumes "InvariantImpliedLiterals F M" and "formulaFalse F (elements M)"
shows "\<not> satisfiable (F @ val2form (decisions M))"
proof -
from \<open>formulaFalse F (elements M)\<close>
have "formulaFalse (F @ val2form (decisions M)) (elements M)"
by (simp add: formulaFalseAppend)
moreover
from \<open>InvariantImpliedLiterals F M\<close>
have "formulaEntailsValuation (F @ val2form (decisions M)) (elements M)"
unfolding formulaEntailsValuation_def
unfolding InvariantImpliedLiterals_def
using InvariantImpliedLiteralsWeakerVariant[of "M" "F"]
by simp
ultimately
show ?thesis
using formulaFalseInEntailedValuationIsUnsatisfiable [of "F @ val2form (decisions M)" "elements M"]
by simp
qed
lemma InvariantImpliedLiteralsHoldsForPrefix:
fixes M :: LiteralTrail and prefix :: LiteralTrail and F :: Formula
assumes "InvariantImpliedLiterals F M" and "isPrefix prefix M"
shows "InvariantImpliedLiterals F prefix"
proof -
{
fix l :: Literal
assume *: "l el elements prefix"
from * \<open>isPrefix prefix M\<close>
have "l el elements M"
unfolding isPrefix_def
by auto
from * and \<open>isPrefix prefix M\<close>
have "decisionsTo l prefix = decisionsTo l M"
using markedElementsToPrefixElement [of "prefix" "M" "l"]
by simp
from \<open>InvariantImpliedLiterals F M\<close> and \<open>l el elements M\<close>
have "formulaEntailsLiteral (F @ val2form (decisionsTo l M)) l"
by (simp add:InvariantImpliedLiterals_def)
with \<open>decisionsTo l prefix = decisionsTo l M\<close>
have "formulaEntailsLiteral (F @ val2form (decisionsTo l prefix)) l"
by simp
} thus ?thesis
by (auto simp add: InvariantImpliedLiterals_def)
qed
(*------------------------- InvariantReasonClauses ---------------------*)
text\<open>Lemmas about @{term InvariantReasonClauses}.\<close>
lemma InvariantReasonClausesHoldsForPrefix:
fixes F::Formula and M::LiteralTrail and p::LiteralTrail
assumes "InvariantReasonClauses F M" and "InvariantUniq M" and
"isPrefix p M"
shows "InvariantReasonClauses F p"
proof-
from \<open>InvariantReasonClauses F M\<close>
have *: "\<forall> literal. literal el elements M \<and> \<not> literal el decisions M \<longrightarrow>
(\<exists> clause. formulaEntailsClause F clause \<and> isReason clause literal (elements M))"
unfolding InvariantReasonClauses_def
by simp
from \<open>InvariantUniq M\<close>
have "uniq (elements M)"
unfolding InvariantUniq_def
by simp
{
fix literal::Literal
assume "literal el elements p" and "\<not> literal el decisions p"
from \<open>isPrefix p M\<close> \<open>literal el (elements p)\<close>
have "literal el (elements M)"
by (auto simp add: isPrefix_def)
moreover
from \<open>isPrefix p M\<close> \<open>literal el (elements p)\<close> \<open>\<not> literal el (decisions p)\<close> \<open>uniq (elements M)\<close>
have "\<not> literal el decisions M"
using markedElementsTrailMemPrefixAreMarkedElementsPrefix [of "M" "p" "literal"]
by auto
ultimately
obtain clause::Clause where
"formulaEntailsClause F clause" "isReason clause literal (elements M)"
using *
by auto
with \<open>literal el elements p\<close> \<open>\<not> literal el decisions p\<close> \<open>isPrefix p M\<close>
have "isReason clause literal (elements p)"
using isReasonHoldsInPrefix[of "literal" "elements p" "elements M" "clause"]
by (simp add:isPrefixElements)
with \<open>formulaEntailsClause F clause\<close>
have "\<exists> clause. formulaEntailsClause F clause \<and> isReason clause literal (elements p)"
by auto
}
thus ?thesis
unfolding InvariantReasonClauses_def
by auto
qed
lemma InvariantReasonClausesHoldsForPrefixElements:
fixes F::Formula and M::LiteralTrail and p::LiteralTrail
assumes "InvariantReasonClauses F p" and
"isPrefix p M" and
"literal el (elements p)" and "\<not> literal el decisions M"
shows "\<exists> clause. formulaEntailsClause F clause \<and> isReason clause literal (elements M)"
proof -
from \<open>isPrefix p M\<close> \<open>\<not> literal el (decisions M)\<close>
have "\<not> literal el (decisions p)"
using markedElementsPrefixAreMarkedElementsTrail[of "p" "M" "literal"]
by auto
from \<open>InvariantReasonClauses F p\<close> \<open>literal el (elements p)\<close> \<open>\<not> literal el (decisions p)\<close> obtain clause :: Clause
where "formulaEntailsClause F clause" "isReason clause literal (elements p)"
unfolding InvariantReasonClauses_def
by auto
with \<open>isPrefix p M\<close>
have "isReason clause literal (elements M)"
using isReasonAppend [of "clause" "literal" "elements p"]
by (auto simp add: isPrefix_def)
with \<open>formulaEntailsClause F clause\<close>
show ?thesis
by auto
qed
(*----------------------------------------------------------------------*)
(* V E R I F I C A T I O N L E M M A S *)
(*----------------------------------------------------------------------*)
subsubsection\<open>Transition rules preserve invariants\<close>
text\<open>In this section it will be proved that the different DPLL-based
transition rules preserves given invariants. Rules are implicitly given
in their most general form. Explicit definition of transition rules will be
done in theories that describe specific solvers.\<close>
(************************************************************************)
(* A P P L Y D E C I D E *)
(************************************************************************)
text\<open>$Decide$ transition rule.\<close>
lemma InvariantUniqAfterDecide:
fixes M :: LiteralTrail and literal :: Literal and M' :: LiteralTrail
assumes "InvariantUniq M" and
"var literal \<notin> vars (elements M)" and
"M' = M @ [(literal, True)]"
shows "InvariantUniq M'"
proof -
from \<open>InvariantUniq M\<close>
have "uniq (elements M)"
unfolding InvariantUniq_def
.
{
assume "\<not> uniq (elements M')"
with \<open>uniq (elements M)\<close> \<open>M' = M @ [(literal, True)]\<close>
have "literal el (elements M)"
using uniqButlastNotUniqListImpliesLastMemButlast [of "elements M'"]
by auto
hence "var literal \<in> vars (elements M)"
using valuationContainsItsLiteralsVariable [of "literal" "elements M"]
by simp
with \<open>var literal \<notin> vars (elements M)\<close>
have "False"
by simp
}
thus ?thesis
unfolding InvariantUniq_def
by auto
qed
lemma InvariantImpliedLiteralsAfterDecide:
fixes F :: Formula and M :: LiteralTrail and literal :: Literal and M' :: LiteralTrail
assumes "InvariantImpliedLiterals F M" and
"var literal \<notin> vars (elements M)" and
"M' = M @ [(literal, True)]"
shows "InvariantImpliedLiterals F M'"
proof -
{
fix l :: Literal
assume "l el elements M'"
have "formulaEntailsLiteral (F @ val2form (decisionsTo l M')) l"
proof (cases "l el elements M")
case True
with \<open>M' = M @ [(literal, True)]\<close>
have "decisionsTo l M' = decisionsTo l M"
by (simp add: markedElementsToAppend)
with \<open>InvariantImpliedLiterals F M\<close> \<open>l el elements M\<close>
show ?thesis
by (simp add: InvariantImpliedLiterals_def)
next
case False
with \<open>l el elements M'\<close> and \<open>M' = M @ [(literal, True)]\<close>
have "l = literal"
by (auto split: if_split_asm)
have "clauseEntailsLiteral [literal] literal"
by (simp add: clauseEntailsLiteral_def)
moreover
have "[literal] el (F @ val2form (decisions M) @ [[literal]])"
by simp
moreover
{
have "isDecision (last (M @ [(literal, True)]))"
by simp
moreover
from \<open>var literal \<notin> vars (elements M)\<close>
have "\<not> literal el (elements M)"
using valuationContainsItsLiteralsVariable[of "literal" "elements M"]
by auto
ultimately
have "decisionsTo literal (M @ [(literal, True)]) = ((decisions M) @ [literal])"
using lastTrailElementMarkedImpliesMarkedElementsToLastElementAreAllMarkedElements [of "M @ [(literal, True)]"]
by (simp add:markedElementsAppend)
}
ultimately
show ?thesis
using \<open>M' = M @ [(literal, True)]\<close> \<open>l = literal\<close>
clauseEntailsLiteralThenFormulaEntailsLiteral [of "[literal]" "F @ val2form (decisions M) @ [[literal]]" "literal"]
by (simp add:val2formAppend)
qed
}
thus ?thesis
by (simp add:InvariantImpliedLiterals_def)
qed
lemma InvariantVarsMAfterDecide:
fixes F :: Formula and F0 :: Formula and M :: LiteralTrail and literal :: Literal and M' :: LiteralTrail
assumes "InvariantVarsM M F0 Vbl" and
"var literal \<in> Vbl" and
"M' = M @ [(literal, True)]"
shows "InvariantVarsM M' F0 Vbl"
proof -
from \<open>InvariantVarsM M F0 Vbl\<close>
have "vars (elements M) \<subseteq> vars F0 \<union> Vbl"
by (simp only:InvariantVarsM_def)
from \<open>M' = M @ [(literal, True)]\<close>
have "vars (elements M') = vars (elements (M @ [(literal, True)]))"
by simp
also have "... = vars (elements M @ [literal])"
by simp
also have "... = vars (elements M) \<union> vars [literal]"
using varsAppendClauses [of "elements M" "[literal]"]
by simp
finally
show ?thesis
using \<open>vars (elements M) \<subseteq> (vars F0) \<union> Vbl\<close> \<open>var literal \<in> Vbl\<close>
unfolding InvariantVarsM_def
by auto
qed
lemma InvariantConsistentAfterDecide:
fixes M :: LiteralTrail and literal :: Literal and M' :: LiteralTrail
assumes "InvariantConsistent M" and
"var literal \<notin> vars (elements M)" and
"M' = M @ [(literal, True)]"
shows "InvariantConsistent M'"
proof -
from \<open>InvariantConsistent M\<close>
have "consistent (elements M)"
unfolding InvariantConsistent_def
.
{
assume "inconsistent (elements M')"
with \<open>M' = M @ [(literal, True)]\<close>
have "inconsistent (elements M) \<or> inconsistent [literal] \<or> (\<exists> l. literalTrue l (elements M) \<and> literalFalse l [literal])"
using inconsistentAppend [of "elements M" "[literal]"]
by simp
with \<open>consistent (elements M)\<close> obtain l :: Literal
where "literalTrue l (elements M)" and "literalFalse l [literal]"
by auto
hence "(opposite l) = literal"
by auto
hence "var literal = var l"
by auto
with \<open>literalTrue l (elements M)\<close>
have "var l \<in> vars (elements M)"
using valuationContainsItsLiteralsVariable [of "l" "elements M"]
by simp
with \<open>var literal = var l\<close> \<open>var literal \<notin> vars (elements M)\<close>
have "False"
by simp
}
thus ?thesis
unfolding InvariantConsistent_def
by auto
qed
lemma InvariantReasonClausesAfterDecide:
fixes F :: Formula and M :: LiteralTrail and M' :: LiteralTrail
assumes "InvariantReasonClauses F M" and "InvariantUniq M" and
"M' = M @ [(literal, True)]"
shows "InvariantReasonClauses F M'"
proof -
{
fix literal' :: Literal
assume "literal' el elements M'" and "\<not> literal' el decisions M'"
have "\<exists> clause. formulaEntailsClause F clause \<and> isReason clause literal' (elements M')"
proof (cases "literal' el elements M")
case True
with assms \<open>\<not> literal' el decisions M'\<close> obtain clause::Clause
where "formulaEntailsClause F clause \<and> isReason clause literal' (elements M')"
using InvariantReasonClausesHoldsForPrefixElements [of "F" "M" "M'" "literal'"]
by (auto simp add:isPrefix_def)
thus ?thesis
by auto
next
case False
with \<open>M' = M @ [(literal, True)]\<close> \<open>literal' el elements M'\<close>
have "literal = literal'"
by (simp split: if_split_asm)
with \<open>M' = M @ [(literal, True)]\<close>
have "literal' el decisions M'"
using markedElementIsMarkedTrue[of "literal" "M'"]
by simp
with \<open>\<not> literal' el decisions M'\<close>
have "False"
by simp
thus ?thesis
by simp
qed
}
thus ?thesis
unfolding InvariantReasonClauses_def
by auto
qed
lemma InvariantCFalseAfterDecide:
fixes conflictFlag::bool and M::LiteralTrail and C::Clause
assumes "InvariantCFalse conflictFlag M C" and "M' = M @ [(literal, True)]"
shows "InvariantCFalse conflictFlag M' C"
unfolding InvariantCFalse_def
proof
assume "conflictFlag"
show "clauseFalse C (elements M')"
proof -
from \<open>InvariantCFalse conflictFlag M C\<close>
have "conflictFlag \<longrightarrow> clauseFalse C (elements M)"
unfolding InvariantCFalse_def
.
with \<open>conflictFlag\<close>
have "clauseFalse C (elements M)"
by simp
with \<open>M' = M @ [(literal, True)]\<close>
show ?thesis
by (simp add:clauseFalseAppendValuation)
qed
qed
(************************************************************************)
(* A P P L Y U N I T P R O P A G A T E *)
(************************************************************************)
text\<open>$UnitPropagate$ transition rule.\<close>
lemma InvariantImpliedLiteralsHoldsForUnitLiteral:
fixes M :: LiteralTrail and F :: Formula and uClause :: Clause and uLiteral :: Literal
assumes "InvariantImpliedLiterals F M" and
"formulaEntailsClause F uClause" and "isUnitClause uClause uLiteral (elements M)" and
"M' = M @ [(uLiteral, False)]"
shows "formulaEntailsLiteral (F @ val2form (decisionsTo uLiteral M')) uLiteral"
proof-
have "decisionsTo uLiteral M' = decisions M"
proof -
from \<open>isUnitClause uClause uLiteral (elements M)\<close>
have "\<not> uLiteral el (elements M)"
by (simp add: isUnitClause_def)
with \<open>M' = M @ [(uLiteral, False)]\<close>
show ?thesis
using markedElementsToAppend[of "uLiteral" "M" "[(uLiteral, False)]"]
unfolding markedElementsTo_def
by simp
qed
moreover
from \<open>formulaEntailsClause F uClause\<close> \<open>isUnitClause uClause uLiteral (elements M)\<close>
have "formulaEntailsLiteral (F @ val2form (elements M)) uLiteral"
using unitLiteralIsEntailed [of "uClause" "uLiteral" "elements M" "F"]
by simp
with \<open>InvariantImpliedLiterals F M\<close>
have "formulaEntailsLiteral (F @ val2form (decisions M)) uLiteral"
by (simp add: InvariantImpliedLiteralsAndElementsEntailLiteralThenDecisionsEntailLiteral)
ultimately
show ?thesis
by simp
qed
lemma InvariantImpliedLiteralsAfterUnitPropagate:
fixes M :: LiteralTrail and F :: Formula and uClause :: Clause and uLiteral :: Literal
assumes "InvariantImpliedLiterals F M" and
"formulaEntailsClause F uClause" and "isUnitClause uClause uLiteral (elements M)" and
"M' = M @ [(uLiteral, False)]"
shows "InvariantImpliedLiterals F M'"
proof -
{
fix l :: Literal
assume "l el (elements M')"
have "formulaEntailsLiteral (F @ val2form (decisionsTo l M')) l"
proof (cases "l el elements M")
case True
with \<open>InvariantImpliedLiterals F M\<close>
have "formulaEntailsLiteral (F @ val2form (decisionsTo l M)) l"
by (simp add:InvariantImpliedLiterals_def)
moreover
from \<open>M' = M @ [(uLiteral, False)]\<close>
have "(isPrefix M M')"
by (simp add:isPrefix_def)
with True
have "decisionsTo l M' = decisionsTo l M"
by (simp add: markedElementsToPrefixElement)
ultimately
show ?thesis
by simp
next
case False
with \<open>l el (elements M')\<close> \<open>M' = M @ [(uLiteral, False)]\<close>
have "l = uLiteral"
by (auto split: if_split_asm)
moreover
from assms
have "formulaEntailsLiteral (F @ val2form (decisionsTo uLiteral M')) uLiteral"
using InvariantImpliedLiteralsHoldsForUnitLiteral [of "F" "M" "uClause" "uLiteral" "M'"]
by simp
ultimately
show ?thesis
by simp
qed
}
thus ?thesis
by (simp add:InvariantImpliedLiterals_def)
qed
lemma InvariantVarsMAfterUnitPropagate:
fixes F :: Formula and F0 :: Formula and M :: LiteralTrail and uClause :: Clause and uLiteral :: Literal and M' :: LiteralTrail
assumes "InvariantVarsM M F0 Vbl" and
"var uLiteral \<in> vars F0 \<union> Vbl" and
"M' = M @ [(uLiteral, False)]"
shows "InvariantVarsM M' F0 Vbl"
proof -
from \<open>InvariantVarsM M F0 Vbl\<close>
have "vars (elements M) \<subseteq> vars F0 \<union> Vbl"
unfolding InvariantVarsM_def
.
thus ?thesis
unfolding InvariantVarsM_def
using \<open>var uLiteral \<in> vars F0 \<union> Vbl\<close>
using \<open>M' = M @ [(uLiteral, False)]\<close>
varsAppendClauses [of "elements M" "[uLiteral]"]
by auto
qed
lemma InvariantConsistentAfterUnitPropagate:
fixes M :: LiteralTrail and F :: Formula and M' :: LiteralTrail and uClause :: Clause and uLiteral :: Literal
assumes "InvariantConsistent M" and
"isUnitClause uClause uLiteral (elements M)" and
"M' = M @ [(uLiteral, False)]"
shows "InvariantConsistent M'"
proof -
from \<open>InvariantConsistent M\<close>
have "consistent (elements M)"
unfolding InvariantConsistent_def
.
from \<open>isUnitClause uClause uLiteral (elements M)\<close>
have "\<not> literalFalse uLiteral (elements M)"
unfolding isUnitClause_def
by simp
{
assume "inconsistent (elements M')"
with \<open>M' = M @ [(uLiteral, False)]\<close>
have "inconsistent (elements M) \<or> inconsistent [unitLiteral] \<or> (\<exists> l. literalTrue l (elements M) \<and> literalFalse l [uLiteral])"
using inconsistentAppend [of "elements M" "[uLiteral]"]
by simp
with \<open>consistent (elements M)\<close> obtain literal::Literal
where "literalTrue literal (elements M)" and "literalFalse literal [uLiteral]"
by auto
hence "literal = opposite uLiteral"
by auto
with \<open>literalTrue literal (elements M)\<close> \<open>\<not> literalFalse uLiteral (elements M)\<close>
have False
by simp
} thus ?thesis
unfolding InvariantConsistent_def
by auto
qed
lemma InvariantUniqAfterUnitPropagate:
fixes M :: LiteralTrail and F :: Formula and M' :: LiteralTrail and uClause :: Clause and uLiteral :: Literal
assumes "InvariantUniq M" and
"isUnitClause uClause uLiteral (elements M)" and
"M' = M @ [(uLiteral, False)]"
shows "InvariantUniq M'"
proof-
from \<open>InvariantUniq M\<close>
have "uniq (elements M)"
unfolding InvariantUniq_def
.
moreover
from \<open>isUnitClause uClause uLiteral (elements M)\<close>
have "\<not> literalTrue uLiteral (elements M)"
unfolding isUnitClause_def
by simp
ultimately
show ?thesis
using \<open>M' = M @ [(uLiteral, False)]\<close> uniqAppendElement[of "elements M" "uLiteral"]
unfolding InvariantUniq_def
by simp
qed
lemma InvariantReasonClausesAfterUnitPropagate:
fixes M :: LiteralTrail and F :: Formula and M' :: LiteralTrail and uClause :: Clause and uLiteral :: Literal
assumes "InvariantReasonClauses F M" and
"formulaEntailsClause F uClause" and "isUnitClause uClause uLiteral (elements M)" and
"M' = M @ [(uLiteral, False)]"
shows "InvariantReasonClauses F M'"
proof -
from \<open>InvariantReasonClauses F M\<close>
have *: "(\<forall> literal. (literal el (elements M)) \<and> \<not> (literal el (decisions M)) \<longrightarrow>
(\<exists> clause. formulaEntailsClause F clause \<and> (isReason clause literal (elements M))))"
unfolding InvariantReasonClauses_def
by simp
{
fix literal::Literal
assume "literal el elements M'" "\<not> literal el decisions M'"
have "\<exists> clause. formulaEntailsClause F clause \<and> isReason clause literal (elements M')"
proof (cases "literal el elements M")
case True
with assms \<open>\<not> literal el decisions M'\<close> obtain clause::Clause
where "formulaEntailsClause F clause \<and> isReason clause literal (elements M')"
using InvariantReasonClausesHoldsForPrefixElements [of "F" "M" "M'" "literal"]
by (auto simp add:isPrefix_def)
thus ?thesis
by auto
next
case False
with \<open>literal el (elements M')\<close> \<open>M' = M @ [(uLiteral, False)]\<close>
have "literal = uLiteral"
by simp
with \<open>M' = M @ [(uLiteral, False)]\<close> \<open>isUnitClause uClause uLiteral (elements M)\<close> \<open>formulaEntailsClause F uClause\<close>
show ?thesis
using isUnitClauseIsReason [of "uClause" "uLiteral" "elements M"]
by auto
qed
} thus ?thesis
unfolding InvariantReasonClauses_def
by simp
qed
lemma InvariantCFalseAfterUnitPropagate:
fixes M :: LiteralTrail and F :: Formula and M' :: LiteralTrail and uClause :: Clause and uLiteral :: Literal
assumes "InvariantCFalse conflictFlag M C" and
"M' = M @ [(uLiteral, False)]"
shows "InvariantCFalse conflictFlag M' C"
proof-
from \<open>InvariantCFalse conflictFlag M C\<close>
have *: "conflictFlag \<longrightarrow> clauseFalse C (elements M)"
unfolding InvariantCFalse_def
.
{
assume "conflictFlag"
with \<open>M' = M @ [(uLiteral, False)]\<close> *
have "clauseFalse C (elements M')"
by (simp add:clauseFalseAppendValuation)
}
thus ?thesis
unfolding InvariantCFalse_def
by simp
qed
(************************************************************************)
(* A P P L Y B A C K T R A C K *)
(************************************************************************)
text\<open>$Backtrack$ transition rule.\<close>
lemma InvariantImpliedLiteralsAfterBacktrack:
fixes F::Formula and M::LiteralTrail
assumes "InvariantImpliedLiterals F M" and "InvariantUniq M" and "InvariantConsistent M" and
"decisions M \<noteq> []" and "formulaFalse F (elements M)"
"M' = (prefixBeforeLastDecision M) @ [(opposite (lastDecision M), False)]"
shows "InvariantImpliedLiterals F M'"
proof -
have "isPrefix (prefixBeforeLastDecision M) M"
by (simp add: isPrefixPrefixBeforeLastMarked)
{
fix l'::Literal
assume "l' el (elements M')"
let ?p = "(prefixBeforeLastDecision M)"
let ?l = "lastDecision M"
have "formulaEntailsLiteral (F @ val2form (decisionsTo l' M')) l'"
proof (cases "l' el (elements ?p)")
case True
with \<open>isPrefix ?p M\<close>
have "l' el (elements M)"
using prefixElementsAreTrailElements[of "?p" "M"]
by auto
with \<open>InvariantImpliedLiterals F M\<close>
have "formulaEntailsLiteral (F @ val2form (decisionsTo l' M)) l'"
unfolding InvariantImpliedLiterals_def
by simp
moreover
from \<open>M' = ?p @ [(opposite ?l, False)]\<close> True \<open>isPrefix ?p M\<close>
have "(decisionsTo l' M') = (decisionsTo l' M)"
using prefixToElementToPrefixElement[of "?p" "M" "l'"]
unfolding markedElementsTo_def
by (auto simp add: prefixToElementAppend)
ultimately
show ?thesis
by auto
next
case False
with \<open>l' el (elements M')\<close> and \<open>M' = ?p @ [(opposite ?l, False)]\<close>
have "?l = (opposite l')"
by (auto split: if_split_asm)
hence "l' = (opposite ?l)"
by simp
from \<open>InvariantUniq M\<close> and \<open>markedElements M \<noteq> []\<close>
have "(decisionsTo ?l M) = (decisions M)"
unfolding InvariantUniq_def
using markedElementsToLastMarkedAreAllMarkedElements
by auto
moreover
from \<open>decisions M \<noteq> []\<close>
have "?l el (elements M)"
by (simp add: lastMarkedIsMarkedElement markedElementsAreElements)
with \<open>InvariantConsistent M\<close>
have "\<not> (opposite ?l) el (elements M)"
unfolding InvariantConsistent_def
by (simp add: inconsistentCharacterization)
with \<open>isPrefix ?p M\<close>
have "\<not> (opposite ?l) el (elements ?p)"
using prefixElementsAreTrailElements[of "?p" "M"]
by auto
with \<open>M' = ?p @ [(opposite ?l, False)]\<close>
have "decisionsTo (opposite ?l) M' = decisions ?p"
using markedElementsToAppend [of "opposite ?l" "?p" "[(opposite ?l, False)]"]
unfolding markedElementsTo_def
by simp
moreover
from \<open>InvariantUniq M\<close> \<open>decisions M \<noteq> []\<close>
have "\<not> ?l el (elements ?p)"
unfolding InvariantUniq_def
using lastMarkedNotInPrefixBeforeLastMarked[of "M"]
by simp
hence "\<not> ?l el (decisions ?p)"
by (auto simp add: markedElementsAreElements)
hence "(removeAll ?l (decisions ?p)) = (decisions ?p)"
by (simp add: removeAll_id)
hence "(removeAll ?l ((decisions ?p) @ [?l])) = (decisions ?p)"
by simp
from \<open>decisions M \<noteq> []\<close> False \<open>l' = (opposite ?l)\<close>
have "(decisions ?p) @ [?l] = (decisions M)"
using markedElementsAreElementsBeforeLastDecisionAndLastDecision[of "M"]
by simp
with \<open>(removeAll ?l ((decisions ?p) @ [?l])) = (decisions ?p)\<close>
have "(decisions ?p) = (removeAll ?l (decisions M))"
by simp
moreover
from \<open>formulaFalse F (elements M)\<close> \<open>InvariantImpliedLiterals F M\<close>
have "\<not> satisfiable (F @ (val2form (decisions M)))"
using InvariantImpliedLiteralsAndFormulaFalseThenFormulaAndDecisionsAreNotSatisfiable[of "F" "M"]
by simp
from \<open>decisions M \<noteq> []\<close>
have "?l el (decisions M)"
unfolding lastMarked_def
by simp
hence "[?l] el val2form (decisions M)"
using val2FormEl[of "?l" "(decisions M)"]
by simp
with \<open>\<not> satisfiable (F @ (val2form (decisions M)))\<close>
have "formulaEntailsLiteral (removeAll [?l] (F @ val2form (decisions M))) (opposite ?l)"
using unsatisfiableFormulaWithSingleLiteralClause[of "F @ val2form (decisions M)" "lastDecision M"]
by auto
ultimately
show ?thesis
using \<open>l' = (opposite ?l)\<close>
using formulaEntailsLiteralRemoveAllAppend[of "[?l]" "F" "val2form (removeAll ?l (decisions M))" "opposite ?l"]
by (auto simp add: val2FormRemoveAll)
qed
}
thus ?thesis
unfolding InvariantImpliedLiterals_def
by auto
qed
lemma InvariantUniqAfterBacktrack:
fixes F::Formula and M::LiteralTrail
assumes "InvariantUniq M" and "InvariantConsistent M" and
"decisions M \<noteq> []" and
"M' = (prefixBeforeLastDecision M) @ [(opposite (lastDecision M), False)]"
shows "InvariantUniq M'"
proof-
from \<open>InvariantUniq M\<close>
have "uniq (elements (prefixBeforeLastDecision M))"
unfolding InvariantUniq_def
using isPrefixPrefixBeforeLastMarked[of "M"]
using isPrefixElements[of "prefixBeforeLastDecision M" "M"]
using uniqListImpliesUniqPrefix
by simp
moreover
from \<open>decisions M \<noteq> []\<close>
have "lastDecision M el (elements M)"
using lastMarkedIsMarkedElement[of "M"]
using markedElementsAreElements[of "lastDecision M" "M"]
by simp
with \<open>InvariantConsistent M\<close>
have "\<not> opposite (lastDecision M) el (elements M)"
unfolding InvariantConsistent_def
using inconsistentCharacterization
by simp
hence "\<not> opposite (lastDecision M) el (elements (prefixBeforeLastDecision M))"
using isPrefixPrefixBeforeLastMarked[of "M"]
using isPrefixElements[of "prefixBeforeLastDecision M" "M"]
using prefixIsSubset[of "elements (prefixBeforeLastDecision M)" "elements M"]
by auto
ultimately
show ?thesis
using
\<open>M' = (prefixBeforeLastDecision M) @ [(opposite (lastDecision M), False)]\<close>
uniqAppendElement[of "elements (prefixBeforeLastDecision M)" "opposite (lastDecision M)"]
unfolding InvariantUniq_def
by simp
qed
lemma InvariantVarsMAfterBacktrack:
fixes F::Formula and M::LiteralTrail
assumes "InvariantVarsM M F0 Vbl"
"decisions M \<noteq> []" and
"M' = (prefixBeforeLastDecision M) @ [(opposite (lastDecision M), False)]"
shows "InvariantVarsM M' F0 Vbl"
proof-
from \<open>decisions M \<noteq> []\<close>
have "lastDecision M el (elements M)"
using lastMarkedIsMarkedElement[of "M"]
using markedElementsAreElements[of "lastDecision M" "M"]
by simp
hence "var (lastDecision M) \<in> vars (elements M)"
using valuationContainsItsLiteralsVariable[of "lastDecision M" "elements M"]
by simp
moreover
have "vars (elements (prefixBeforeLastDecision M)) \<subseteq> vars (elements M)"
using isPrefixPrefixBeforeLastMarked[of "M"]
using isPrefixElements[of "prefixBeforeLastDecision M" "M"]
using varsPrefixValuation[of "elements (prefixBeforeLastDecision M)" "elements M"]
by auto
ultimately
show ?thesis
using assms
using varsAppendValuation[of "elements (prefixBeforeLastDecision M)" "[opposite (lastDecision M)]"]
unfolding InvariantVarsM_def
by auto
qed
(************************************************************************)
(* A P P L Y B A C K J U M P *)
(************************************************************************)
text\<open>$Backjump$ transition rule.\<close>
lemma InvariantImpliedLiteralsAfterBackjump:
fixes F::Formula and M::LiteralTrail and p::LiteralTrail and bClause::Clause and bLiteral::Literal
assumes "InvariantImpliedLiterals F M" and
"isPrefix p M" and "formulaEntailsClause F bClause" and "isUnitClause bClause bLiteral (elements p)" and
"M' = p @ [(bLiteral, False)]"
shows "InvariantImpliedLiterals F M'"
proof -
from \<open>InvariantImpliedLiterals F M\<close> \<open>isPrefix p M\<close>
have "InvariantImpliedLiterals F p"
using InvariantImpliedLiteralsHoldsForPrefix [of "F" "M" "p"]
by simp
with assms
show ?thesis
using InvariantImpliedLiteralsAfterUnitPropagate [of "F" "p" "bClause" "bLiteral" "M'"]
by simp
qed
lemma InvariantVarsMAfterBackjump:
fixes F::Formula and M::LiteralTrail and p::LiteralTrail and bClause::Clause and bLiteral::Literal
assumes "InvariantVarsM M F0 Vbl" and
"isPrefix p M" and "var bLiteral \<in> vars F0 \<union> Vbl" and
"M' = p @ [(bLiteral, False)]"
shows "InvariantVarsM M' F0 Vbl"
proof -
from \<open>InvariantVarsM M F0 Vbl\<close>
have "vars (elements M) \<subseteq> vars F0 \<union> Vbl"
unfolding InvariantVarsM_def
.
moreover
from \<open>isPrefix p M\<close>
have "vars (elements p) \<subseteq> vars (elements M)"
using varsPrefixValuation [of "elements p" "elements M"]
by (simp add: isPrefixElements)
ultimately
have "vars (elements p) \<subseteq> vars F0 \<union> Vbl"
by simp
with \<open>vars (elements p) \<subseteq> vars F0 \<union> Vbl\<close> assms
show ?thesis
using InvariantVarsMAfterUnitPropagate[of "p" "F0" "Vbl" "bLiteral" "M'"]
unfolding InvariantVarsM_def
by simp
qed
lemma InvariantConsistentAfterBackjump:
fixes F::Formula and M::LiteralTrail and p::LiteralTrail and bClause::Clause and bLiteral::Literal
assumes "InvariantConsistent M" and
"isPrefix p M" and "isUnitClause bClause bLiteral (elements p)" and
"M' = p @ [(bLiteral, False)]"
shows "InvariantConsistent M'"
proof-
from \<open>InvariantConsistent M\<close>
have "consistent (elements M)"
unfolding InvariantConsistent_def
.
with \<open>isPrefix p M\<close>
have "consistent (elements p)"
using consistentPrefix [of "elements p" "elements M"]
by (simp add: isPrefixElements)
with assms
show ?thesis
using InvariantConsistentAfterUnitPropagate [of "p" "bClause" "bLiteral" "M'"]
unfolding InvariantConsistent_def
by simp
qed
lemma InvariantUniqAfterBackjump:
fixes F::Formula and M::LiteralTrail and p::LiteralTrail and bClause::Clause and bLiteral::Literal
assumes "InvariantUniq M" and
"isPrefix p M" and "isUnitClause bClause bLiteral (elements p)" and
"M' = p @ [(bLiteral, False)]"
shows "InvariantUniq M'"
proof -
from \<open>InvariantUniq M\<close>
have "uniq (elements M)"
unfolding InvariantUniq_def
.
with \<open>isPrefix p M\<close>
have "uniq (elements p)"
using uniqElementsTrailImpliesUniqElementsPrefix [of "p" "M"]
by simp
with assms
show ?thesis
using InvariantUniqAfterUnitPropagate[of "p" "bClause" "bLiteral" "M'"]
unfolding InvariantUniq_def
by simp
qed
lemma InvariantReasonClausesAfterBackjump:
fixes F::Formula and M::LiteralTrail and p::LiteralTrail and bClause::Clause and bLiteral::Literal
assumes "InvariantReasonClauses F M" and "InvariantUniq M" and
"isPrefix p M" and "isUnitClause bClause bLiteral (elements p)" and "formulaEntailsClause F bClause" and
"M' = p @ [(bLiteral, False)]"
shows "InvariantReasonClauses F M'"
proof -
from \<open>InvariantReasonClauses F M\<close> \<open>InvariantUniq M\<close> \<open>isPrefix p M\<close>
have "InvariantReasonClauses F p"
by (rule InvariantReasonClausesHoldsForPrefix)
with assms
show ?thesis
using InvariantReasonClausesAfterUnitPropagate [of "F" "p" "bClause" "bLiteral" "M'"]
by simp
qed
(************************************************************************)
(* A P P L Y L E A R N *)
(************************************************************************)
text\<open>$Learn$ transition rule.\<close>
lemma InvariantImpliedLiteralsAfterLearn:
fixes F :: Formula and F' :: Formula and M :: LiteralTrail and C :: Clause
assumes "InvariantImpliedLiterals F M" and
"F' = F @ [C]"
shows "InvariantImpliedLiterals F' M"
proof -
from \<open>InvariantImpliedLiterals F M\<close>
have *: "\<forall> l. l el (elements M) \<longrightarrow> formulaEntailsLiteral (F @ val2form (decisionsTo l M)) l"
unfolding InvariantImpliedLiterals_def
.
{
fix literal :: Literal
assume "literal el (elements M)"
with *
have "formulaEntailsLiteral (F @ val2form (decisionsTo literal M)) literal"
by simp
hence "formulaEntailsLiteral (F @ [C] @ val2form (decisionsTo literal M)) literal"
proof-
have "\<forall> clause::Clause. clause el (F @ val2form (decisionsTo literal M)) \<longrightarrow> clause el (F @ [C] @ val2form (decisionsTo literal M))"
proof-
{
fix clause :: Clause
have "clause el (F @ val2form (decisionsTo literal M)) \<longrightarrow> clause el (F @ [C] @ val2form (decisionsTo literal M))"
proof
assume "clause el (F @ val2form (decisionsTo literal M))"
thus "clause el (F @ [C] @ val2form (decisionsTo literal M))"
by auto
qed
} thus ?thesis
by auto
qed
with \<open>formulaEntailsLiteral (F @ val2form (decisionsTo literal M)) literal\<close>
show ?thesis
by (rule formulaEntailsLiteralSubset)
qed
}
thus ?thesis
unfolding InvariantImpliedLiterals_def
using \<open>F' = F @ [C]\<close>
by auto
qed
lemma InvariantReasonClausesAfterLearn:
fixes F :: Formula and F' :: Formula and M :: LiteralTrail and C :: Clause
assumes "InvariantReasonClauses F M" and
"formulaEntailsClause F C" and
"F' = F @ [C]"
shows "InvariantReasonClauses F' M"
proof -
{
fix literal :: Literal
assume "literal el elements M \<and> \<not> literal el decisions M"
with \<open>InvariantReasonClauses F M\<close> obtain clause::Clause
where "formulaEntailsClause F clause" "isReason clause literal (elements M)"
unfolding InvariantReasonClauses_def
by auto
from \<open>formulaEntailsClause F clause\<close> \<open>F' = F @ [C]\<close>
have "formulaEntailsClause F' clause"
by (simp add:formulaEntailsClauseAppend)
with \<open>isReason clause literal (elements M)\<close>
have "\<exists> clause. formulaEntailsClause F' clause \<and> isReason clause literal (elements M)"
by auto
} thus ?thesis
unfolding InvariantReasonClauses_def
by simp
qed
lemma InvariantVarsFAfterLearn:
fixes F0 :: Formula and F :: Formula and F' :: Formula and C :: Clause
assumes "InvariantVarsF F F0 Vbl" and
"vars C \<subseteq> (vars F0) \<union> Vbl" and
"F' = F @ [C]"
shows "InvariantVarsF F' F0 Vbl"
using assms
using varsAppendFormulae[of "F" "[C]"]
unfolding InvariantVarsF_def
by auto
lemma InvariantEquivalentAfterLearn:
fixes F0 :: Formula and F :: Formula and F' :: Formula and C :: Clause
assumes "InvariantEquivalent F0 F" and
"formulaEntailsClause F C" and
"F' = F @ [C]"
shows "InvariantEquivalent F0 F'"
proof-
from \<open>InvariantEquivalent F0 F\<close>
have "equivalentFormulae F0 F"
unfolding InvariantEquivalent_def
.
with \<open>formulaEntailsClause F C\<close> \<open>F' = F @ [C]\<close>
have "equivalentFormulae F0 (F @ [C])"
using extendEquivalentFormulaWithEntailedClause [of "F0" "F" "C"]
by simp
thus ?thesis
unfolding InvariantEquivalent_def
using \<open>F' = F @ [C]\<close>
by simp
qed
lemma InvariantCEntailedAfterLearn:
fixes F0 :: Formula and F :: Formula and F' :: Formula and C :: Clause
assumes "InvariantCEntailed conflictFlag F C" and
"F' = F @ [C]"
shows "InvariantCEntailed conflictFlag F' C"
using assms
unfolding InvariantCEntailed_def
by (auto simp add:formulaEntailsClauseAppend)
(************************************************************************)
(* A P P L Y E X P L A I N *)
(************************************************************************)
text\<open>$Explain$ transition rule.\<close>
lemma InvariantCFalseAfterExplain:
fixes conflictFlag::bool and M::LiteralTrail and C::Clause and literal :: Literal
assumes "InvariantCFalse conflictFlag M C" and
"opposite literal el C" and "isReason reason literal (elements M)" and
"C' = resolve C reason (opposite literal)"
shows "InvariantCFalse conflictFlag M C'"
unfolding InvariantCFalse_def
proof
assume "conflictFlag"
with \<open>InvariantCFalse conflictFlag M C\<close>
have "clauseFalse C (elements M)"
unfolding InvariantCFalse_def
by simp
hence "clauseFalse (removeAll (opposite literal) C) (elements M)"
by (simp add: clauseFalseIffAllLiteralsAreFalse)
moreover
from \<open>isReason reason literal (elements M)\<close>
have "clauseFalse (removeAll literal reason) (elements M)"
unfolding isReason_def
by simp
ultimately
show "clauseFalse C' (elements M)"
using \<open>C' = resolve C reason (opposite literal)\<close>
resolveFalseClauses [of "opposite literal" "C" "elements M" "reason"]
by simp
qed
lemma InvariantCEntailedAfterExplain:
fixes conflictFlag::bool and M::LiteralTrail and C::Clause and literal :: Literal and reason :: Clause
assumes "InvariantCEntailed conflictFlag F C" and
"formulaEntailsClause F reason" and "C' = (resolve C reason (opposite l))"
shows "InvariantCEntailed conflictFlag F C'"
unfolding InvariantCEntailed_def
proof
assume "conflictFlag"
with \<open>InvariantCEntailed conflictFlag F C\<close>
have "formulaEntailsClause F C"
unfolding InvariantCEntailed_def
by simp
with \<open>formulaEntailsClause F reason\<close>
show "formulaEntailsClause F C'"
using \<open>C' = (resolve C reason (opposite l))\<close>
by (simp add:formulaEntailsResolvent)
qed
(************************************************************************)
(* A P P L Y C O N F L I C T *)
(************************************************************************)
text\<open>$Conflict$ transition rule.\<close>
lemma invariantCFalseAfterConflict:
fixes conflictFlag::bool and conflictFlag'::bool and M::LiteralTrail and F :: Formula and clause :: Clause and C' :: Clause
assumes "conflictFlag = False" and
"formulaFalse F (elements M)" and "clause el F" "clauseFalse clause (elements M)" and
"C' = clause" and "conflictFlag' = True"
shows "InvariantCFalse conflictFlag' M C'"
unfolding InvariantCFalse_def
proof
from \<open>conflictFlag' = True\<close>
show "clauseFalse C' (elements M)"
using \<open>clauseFalse clause (elements M)\<close> \<open>C' = clause\<close>
by simp
qed
lemma invariantCEntailedAfterConflict:
fixes conflictFlag::bool and conflictFlag'::bool and M::LiteralTrail and F :: Formula and clause :: Clause and C' :: Clause
assumes "conflictFlag = False" and
"formulaFalse F (elements M)" and "clause el F" and "clauseFalse clause (elements M)" and
"C' = clause" and "conflictFlag' = True"
shows "InvariantCEntailed conflictFlag' F C'"
unfolding InvariantCEntailed_def
proof
from \<open>conflictFlag' = True\<close>
show "formulaEntailsClause F C'"
using \<open>clause el F\<close> \<open>C' = clause\<close>
by (simp add:formulaEntailsItsClauses)
qed
(************************************************************************)
(* U N S A T R E P O R T *)
(************************************************************************)
text\<open>UNSAT report\<close>
lemma unsatReport:
fixes F :: Formula and M :: LiteralTrail and F0 :: Formula
assumes "InvariantImpliedLiterals F M" and "InvariantEquivalent F0 F" and
"decisions M = []" and "formulaFalse F (elements M)"
shows "\<not> satisfiable F0"
proof-
have "formulaEntailsValuation F (elements M)"
proof-
{
fix literal::Literal
assume "literal el (elements M)"
from \<open>decisions M = []\<close>
have "decisionsTo literal M = []"
by (simp add:markedElementsEmptyImpliesMarkedElementsToEmpty)
with \<open>literal el (elements M)\<close> \<open>InvariantImpliedLiterals F M\<close>
have "formulaEntailsLiteral F literal"
unfolding InvariantImpliedLiterals_def
by auto
}
thus ?thesis
unfolding formulaEntailsValuation_def
by simp
qed
with \<open>formulaFalse F (elements M)\<close>
have "\<not> satisfiable F"
by (simp add:formulaFalseInEntailedValuationIsUnsatisfiable)
with \<open>InvariantEquivalent F0 F\<close>
show ?thesis
unfolding InvariantEquivalent_def
by (simp add:satisfiableEquivalent)
qed
lemma unsatReportExtensiveExplain:
fixes F :: Formula and M :: LiteralTrail and F0 :: Formula and C :: Clause and conflictFlag :: bool
assumes "InvariantEquivalent F0 F" and "InvariantCEntailed conflictFlag F C" and
"conflictFlag" and "C = []"
shows "\<not> satisfiable F0"
proof-
from \<open>conflictFlag\<close> \<open>InvariantCEntailed conflictFlag F C\<close>
have "formulaEntailsClause F C"
unfolding InvariantCEntailed_def
by simp
with \<open>C=[]\<close>
have "\<not> satisfiable F"
by (simp add:formulaUnsatIffImpliesEmptyClause)
with \<open>InvariantEquivalent F0 F\<close>
show ?thesis
unfolding InvariantEquivalent_def
by (simp add:satisfiableEquivalent)
qed
(************************************************************************)
(* S A T R E P O R T *)
(************************************************************************)
text\<open>SAT Report\<close>
lemma satReport:
fixes F0 :: Formula and F :: Formula and M::LiteralTrail
assumes "vars F0 \<subseteq> Vbl" and "InvariantVarsF F F0 Vbl" and "InvariantConsistent M" and "InvariantEquivalent F0 F" and
"\<not> formulaFalse F (elements M)" and "vars (elements M) \<supseteq> Vbl"
shows "model (elements M) F0"
proof-
from \<open>InvariantConsistent M\<close>
have "consistent (elements M)"
unfolding InvariantConsistent_def
.
moreover
from \<open>InvariantVarsF F F0 Vbl\<close>
have "vars F \<subseteq> vars F0 \<union> Vbl"
unfolding InvariantVarsF_def
.
with \<open>vars F0 \<subseteq> Vbl\<close>
have "vars F \<subseteq> Vbl"
by auto
with \<open>vars (elements M) \<supseteq> Vbl\<close>
have "vars F \<subseteq> vars (elements M)"
by simp
hence "formulaTrue F (elements M) \<or> formulaFalse F (elements M)"
by (simp add:totalValuationForFormulaDefinesItsValue)
with \<open>\<not> formulaFalse F (elements M)\<close>
have "formulaTrue F (elements M)"
by simp
ultimately
have "model (elements M) F"
by simp
with \<open>InvariantEquivalent F0 F\<close>
show ?thesis
unfolding InvariantEquivalent_def
unfolding equivalentFormulae_def
by auto
qed
(******************************************************************************)
subsection\<open>Different characterizations of backjumping\<close>
(******************************************************************************)
text\<open>In this section, different characterization of applicability of
backjumping will be given.\<close>
text\<open>The clause satisfies the @{term "Unique Implication Point (UIP)"} condition
if the level of all its literals is stricly lower then the level of its last asserted literal\<close>
definition
"isUIP l c M ==
isLastAssertedLiteral (opposite l) (oppositeLiteralList c)(elements M) \<and>
(\<forall> l'. l' el c \<and> l' \<noteq> l \<longrightarrow> elementLevel (opposite l') M < elementLevel (opposite l) M)"
text\<open>@{term "Backjump level"} is a nonegative integer such that it is stricly
lower than the level of the last asserted literal of a clause, and greater or
equal then levels of all its other literals.\<close>
definition
"isBackjumpLevel level l c M ==
isLastAssertedLiteral (opposite l) (oppositeLiteralList c)(elements M) \<and>
0 \<le> level \<and> level < elementLevel (opposite l) M \<and>
(\<forall> l'. l' el c \<and> l' \<noteq> l \<longrightarrow> elementLevel (opposite l') M \<le> level)"
lemma lastAssertedLiteralHasHighestElementLevel:
fixes literal :: Literal and clause :: Clause and M :: LiteralTrail
assumes "isLastAssertedLiteral literal clause (elements M)" and "uniq (elements M)"
shows "\<forall> l'. l' el clause \<and> l' el elements M \<longrightarrow> elementLevel l' M <= elementLevel literal M"
proof -
{
fix l' :: Literal
assume "l' el clause" "l' el elements M"
hence "elementLevel l' M <= elementLevel literal M"
proof (cases "l' = literal")
case True
thus ?thesis
by simp
next
case False
from \<open>isLastAssertedLiteral literal clause (elements M)\<close>
have "literalTrue literal (elements M)"
"\<forall> l. l el clause \<and> l \<noteq> literal \<longrightarrow> \<not> precedes literal l (elements M)"
by (auto simp add:isLastAssertedLiteral_def)
with \<open>l' el clause\<close> False
have "\<not> precedes literal l' (elements M)"
by simp
with False \<open>l' el (elements M)\<close> \<open>literalTrue literal (elements M)\<close>
have "precedes l' literal (elements M)"
using precedesTotalOrder [of "l'" "elements M" "literal"]
by simp
with \<open>uniq (elements M)\<close>
show ?thesis
using elementLevelPrecedesLeq [of "l'" "literal" "M"]
by auto
qed
}
thus ?thesis
by simp
qed
text\<open>When backjump clause contains only a single literal, then the backjump level is 0.\<close>
(* additional assumption: (elementLevel l M) > 0 *)
lemma backjumpLevelZero:
fixes M :: LiteralTrail and C :: Clause and l :: Literal
assumes
"isLastAssertedLiteral (opposite l) (oppositeLiteralList C) (elements M)" and
"elementLevel (opposite l) M > 0" and
"set C = {l}"
shows
"isBackjumpLevel 0 l C M"
proof-
have "\<forall> l'. l' el C \<and> l' \<noteq> l \<longrightarrow> elementLevel (opposite l') M \<le> 0"
proof-
{
fix l'::Literal
assume "l' el C \<and> l' \<noteq> l"
hence "False"
using \<open>set C = {l}\<close>
by auto
} thus ?thesis
by auto
qed
with \<open>elementLevel (opposite l) M > 0\<close>
\<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList C) (elements M)\<close>
show ?thesis
unfolding isBackjumpLevel_def
by auto
qed
text\<open>When backjump clause contains more than one literal, then the level of the
second last asserted literal can be taken as a backjump level.\<close>
lemma backjumpLevelLastLast:
fixes M :: LiteralTrail and C :: Clause and l :: Literal
assumes
"isUIP l C M" and
"uniq (elements M)" and
"clauseFalse C (elements M)" and
"isLastAssertedLiteral (opposite ll) (removeAll (opposite l) (oppositeLiteralList C)) (elements M)"
shows
"isBackjumpLevel (elementLevel (opposite ll) M) l C M"
proof-
from \<open>isUIP l C M\<close>
have "isLastAssertedLiteral (opposite l) (oppositeLiteralList C) (elements M)"
unfolding isUIP_def
by simp
from \<open>isLastAssertedLiteral (opposite ll) (removeAll (opposite l) (oppositeLiteralList C)) (elements M)\<close>
have "literalTrue (opposite ll) (elements M)" "(opposite ll) el (removeAll (opposite l) (oppositeLiteralList C))"
unfolding isLastAssertedLiteral_def
by auto
have "\<forall> l'. l' el (oppositeLiteralList C) \<longrightarrow> literalTrue l' (elements M)"
proof-
{
fix l'::Literal
assume "l' el oppositeLiteralList C"
hence "opposite l' el C"
using literalElListIffOppositeLiteralElOppositeLiteralList[of "opposite l'" "C"]
by simp
with \<open>clauseFalse C (elements M)\<close>
have "literalTrue l' (elements M)"
by (auto simp add: clauseFalseIffAllLiteralsAreFalse)
}
thus ?thesis
by simp
qed
have "\<forall> l'. l' el C \<and> l' \<noteq> l \<longrightarrow>
elementLevel (opposite l') M <= elementLevel (opposite ll) M"
proof-
{
fix l' :: Literal
assume "l' el C \<and> l' \<noteq> l"
hence "(opposite l') el (oppositeLiteralList C)" "opposite l' \<noteq> opposite l"
using literalElListIffOppositeLiteralElOppositeLiteralList
by auto
hence "opposite l' el (removeAll (opposite l) (oppositeLiteralList C))"
by simp
from \<open>opposite l' el (oppositeLiteralList C)\<close>
\<open>\<forall> l'. l' el (oppositeLiteralList C) \<longrightarrow> literalTrue l' (elements M)\<close>
have "literalTrue (opposite l') (elements M)"
by simp
with \<open>opposite l' el (removeAll (opposite l) (oppositeLiteralList C))\<close>
\<open>isLastAssertedLiteral (opposite ll) (removeAll (opposite l) (oppositeLiteralList C)) (elements M)\<close>
\<open>uniq (elements M)\<close>
have "elementLevel (opposite l') M <= elementLevel (opposite ll) M"
using lastAssertedLiteralHasHighestElementLevel[of "opposite ll" "removeAll (opposite l) (oppositeLiteralList C)" "M"]
by auto
}
thus ?thesis
by simp
qed
moreover
from \<open>literalTrue (opposite ll) (elements M)\<close>
have "elementLevel (opposite ll) M \<ge> 0"
by simp
moreover
from \<open>(opposite ll) el (removeAll (opposite l) (oppositeLiteralList C))\<close>
have "ll el C" and "ll \<noteq> l"
using literalElListIffOppositeLiteralElOppositeLiteralList[of "ll" "C"]
by auto
from \<open>isUIP l C M\<close>
have "\<forall> l'. l' el C \<and> l' \<noteq> l \<longrightarrow> elementLevel (opposite l') M < elementLevel (opposite l) M"
unfolding isUIP_def
by simp
with \<open>ll el C\<close> \<open>ll \<noteq> l\<close>
have "elementLevel (opposite ll) M < elementLevel (opposite l) M"
by simp
ultimately
show ?thesis
using \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList C) (elements M)\<close>
unfolding isBackjumpLevel_def
by simp
qed
text\<open>if UIP is reached then there exists correct backjump level.\<close>
(* additional assumption: (elementLevel l M) > 0 *)
lemma isUIPExistsBackjumpLevel:
fixes M :: LiteralTrail and c :: Clause and l :: Literal
assumes
"clauseFalse c (elements M)" and
"isUIP l c M" and
"uniq (elements M)" and
"elementLevel (opposite l) M > 0"
shows
"\<exists> level. (isBackjumpLevel level l c M)"
proof-
from \<open>isUIP l c M\<close>
have "isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)"
unfolding isUIP_def
by simp
show ?thesis
proof (cases "set c = {l}")
case True
with \<open>elementLevel (opposite l) M > 0\<close> \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)\<close>
have "isBackjumpLevel 0 l c M"
using backjumpLevelZero[of "l" "c" "M"]
by auto
thus ?thesis
by auto
next
case False
have "\<exists> literal. isLastAssertedLiteral literal (removeAll (opposite l) (oppositeLiteralList c)) (elements M)"
proof-
let ?ll = "getLastAssertedLiteral (oppositeLiteralList (removeAll l c)) (elements M)"
from \<open>clauseFalse c (elements M)\<close>
have "clauseFalse (removeAll l c) (elements M)"
by (simp add:clauseFalseRemove)
moreover
have "removeAll l c \<noteq> []"
proof-
have "(set c) \<subseteq> {l} \<union> set (removeAll l c)"
by auto
from \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)\<close>
have "(opposite l) el oppositeLiteralList c"
unfolding isLastAssertedLiteral_def
by simp
hence "l el c"
using literalElListIffOppositeLiteralElOppositeLiteralList[of "l" "c"]
by simp
hence "l \<in> set c"
by simp
{
assume "\<not> ?thesis"
hence "set (removeAll l c) = {}"
by simp
with \<open>(set c) \<subseteq> {l} \<union> set (removeAll l c)\<close>
have "set c \<subseteq> {l}"
by simp
with \<open>l \<in> set c\<close>
have "set c = {l}"
by auto
with False
have "False"
by simp
}
thus ?thesis
by auto
qed
ultimately
have "isLastAssertedLiteral ?ll (oppositeLiteralList (removeAll l c)) (elements M)"
using \<open>uniq (elements M)\<close>
using getLastAssertedLiteralCharacterization [of "removeAll l c" "elements M"]
by simp
hence "isLastAssertedLiteral ?ll (removeAll (opposite l) (oppositeLiteralList c)) (elements M)"
using oppositeLiteralListRemove[of "l" "c"]
by simp
thus ?thesis
by auto
qed
then obtain ll::Literal where "isLastAssertedLiteral ll (removeAll (opposite l) (oppositeLiteralList c)) (elements M)"
by auto
with \<open>uniq (elements M)\<close> \<open>clauseFalse c (elements M)\<close> \<open>isUIP l c M\<close>
have "isBackjumpLevel (elementLevel ll M) l c M"
using backjumpLevelLastLast[of "l" "c" "M" "opposite ll"]
by auto
thus ?thesis
by auto
qed
qed
text\<open>Backjump level condition ensures that the backjump clause is
unit in the prefix to backjump level.\<close>
lemma isBackjumpLevelEnsuresIsUnitInPrefix:
fixes M :: LiteralTrail and conflictFlag :: bool and c :: Clause and l :: Literal
assumes "consistent (elements M)" and "uniq (elements M)" and
"clauseFalse c (elements M)" and "isBackjumpLevel level l c M"
shows "isUnitClause c l (elements (prefixToLevel level M))"
proof -
from \<open>isBackjumpLevel level l c M\<close>
have "isLastAssertedLiteral (opposite l) (oppositeLiteralList c)(elements M)"
"0 \<le> level" "level < elementLevel (opposite l) M" and
*: "\<forall> l'. l' el c \<and> l' \<noteq> l \<longrightarrow> elementLevel (opposite l') M \<le> level"
unfolding isBackjumpLevel_def
by auto
from \<open>isLastAssertedLiteral (opposite l)(oppositeLiteralList c) (elements M)\<close>
have "l el c" "literalTrue (opposite l) (elements M)"
using isLastAssertedCharacterization [of "opposite l" "c" "elements M"]
by auto
have "\<not> literalFalse l (elements (prefixToLevel level M))"
using \<open>level < elementLevel (opposite l) M\<close> \<open>0 <= level\<close> \<open>uniq (elements M)\<close>
by (simp add: literalNotInEarlierLevelsThanItsLevel)
moreover
have "\<not> literalTrue l (elements (prefixToLevel level M))"
proof -
from \<open>consistent (elements M)\<close> \<open>literalTrue (opposite l) (elements M)\<close>
have "\<not> literalFalse (opposite l) (elements M)"
by (auto simp add:inconsistentCharacterization)
thus ?thesis
using isPrefixPrefixToLevel[of "level" "M"]
prefixElementsAreTrailElements[of "prefixToLevel level M" "M"]
unfolding prefixToLevel_def
by auto
qed
moreover
have "\<forall> l'. l' el c \<and> l' \<noteq> l \<longrightarrow> literalFalse l' (elements (prefixToLevel level M))"
proof -
{
fix l' :: Literal
assume "l' el c" "l' \<noteq> l"
from \<open>l' el c\<close> \<open>clauseFalse c (elements M)\<close>
have "literalFalse l' (elements M)"
by (simp add:clauseFalseIffAllLiteralsAreFalse)
have "literalFalse l' (elements (prefixToLevel level M))"
proof -
from \<open>l' el c\<close> \<open>l' \<noteq> l\<close>
have "elementLevel (opposite l') M <= level"
using *
by auto
thus ?thesis
using \<open>literalFalse l' (elements M)\<close>
\<open>0 <= level\<close>
elementLevelLtLevelImpliesMemberPrefixToLevel[of "opposite l'" "M" "level"]
by simp
qed
} thus ?thesis
by auto
qed
ultimately
show ?thesis
using \<open>l el c\<close>
unfolding isUnitClause_def
by simp
qed
text\<open>Backjump level is minimal if there is no smaller level which
satisfies the backjump level condition. The following definition gives
operative characterization of this notion.\<close>
definition
"isMinimalBackjumpLevel level l c M ==
isBackjumpLevel level l c M \<and>
(if set c \<noteq> {l} then
(\<exists> ll. ll el c \<and> elementLevel (opposite ll) M = level)
else
level = 0
)"
lemma isMinimalBackjumpLevelCharacterization:
assumes
"isUIP l c M"
"clauseFalse c (elements M)"
"uniq (elements M)"
shows
"isMinimalBackjumpLevel level l c M =
(isBackjumpLevel level l c M \<and>
(\<forall> level'. level' < level \<longrightarrow> \<not> isBackjumpLevel level' l c M))" (is "?lhs = ?rhs")
proof
assume "?lhs"
show "?rhs"
proof (cases "set c = {l}")
case True
thus ?thesis
using \<open>?lhs\<close>
unfolding isMinimalBackjumpLevel_def
by auto
next
case False
with \<open>?lhs\<close>
obtain ll
where "ll el c" "elementLevel (opposite ll) M = level" "isBackjumpLevel level l c M"
unfolding isMinimalBackjumpLevel_def
by auto
have "l \<noteq> ll"
using \<open>isMinimalBackjumpLevel level l c M\<close>
using \<open>elementLevel (opposite ll) M = level\<close>
unfolding isMinimalBackjumpLevel_def
unfolding isBackjumpLevel_def
by auto
show ?thesis
using \<open>isBackjumpLevel level l c M\<close>
using \<open>elementLevel (opposite ll) M = level\<close>
using \<open>ll el c\<close> \<open>l \<noteq> ll\<close>
unfolding isBackjumpLevel_def
by force
qed
next
assume "?rhs"
show "?lhs"
proof (cases "set c = {l}")
case True
thus ?thesis
using \<open>?rhs\<close>
using backjumpLevelZero[of "l" "c" "M"]
unfolding isMinimalBackjumpLevel_def
unfolding isBackjumpLevel_def
by auto
next
case False
from \<open>?rhs\<close>
have "l el c"
unfolding isBackjumpLevel_def
using literalElListIffOppositeLiteralElOppositeLiteralList[of "l" "c"]
unfolding isLastAssertedLiteral_def
by simp
let ?oll = "getLastAssertedLiteral (removeAll (opposite l) (oppositeLiteralList c)) (elements M)"
have "clauseFalse (removeAll l c) (elements M)"
using \<open>clauseFalse c (elements M)\<close>
by (simp add: clauseFalseIffAllLiteralsAreFalse)
moreover
have "removeAll l c \<noteq> []"
proof-
{
assume "\<not> ?thesis"
hence "set (removeAll l c) = {}"
by simp
hence "set c \<subseteq> {l}"
by simp
hence False
using \<open>set c \<noteq> {l}\<close>
using \<open>l el c\<close>
by auto
} thus ?thesis
by auto
qed
ultimately
have "isLastAssertedLiteral ?oll (removeAll (opposite l) (oppositeLiteralList c)) (elements M)"
using \<open>uniq (elements M)\<close>
using getLastAssertedLiteralCharacterization[of "removeAll l c" "elements M"]
using oppositeLiteralListRemove[of "l" "c"]
by simp
hence "isBackjumpLevel (elementLevel ?oll M) l c M"
using assms
using backjumpLevelLastLast[of "l" "c" "M" "opposite ?oll"]
by auto
have "?oll el (removeAll (opposite l) (oppositeLiteralList c))"
using \<open>isLastAssertedLiteral ?oll (removeAll (opposite l) (oppositeLiteralList c)) (elements M)\<close>
unfolding isLastAssertedLiteral_def
by simp
hence "?oll el (oppositeLiteralList c)" "?oll \<noteq> opposite l"
by auto
hence "opposite ?oll el c"
using literalElListIffOppositeLiteralElOppositeLiteralList[of "?oll" "oppositeLiteralList c"]
by simp
from \<open>?oll \<noteq> opposite l\<close>
have "opposite ?oll \<noteq> l"
using oppositeSymmetry[of "?oll" "l"]
by simp
have "elementLevel ?oll M \<ge> level"
proof-
{
assume "elementLevel ?oll M < level"
hence "\<not> isBackjumpLevel (elementLevel ?oll M) l c M"
using \<open>?rhs\<close>
by simp
with \<open>isBackjumpLevel (elementLevel ?oll M) l c M\<close>
have False
by simp
} thus ?thesis
by force
qed
moreover
from \<open>?rhs\<close>
have "elementLevel ?oll M \<le> level"
using \<open>opposite ?oll el c\<close>
using \<open>opposite ?oll \<noteq> l\<close>
unfolding isBackjumpLevel_def
by auto
ultimately
have "elementLevel ?oll M = level"
by simp
show ?thesis
using \<open>opposite ?oll el c\<close>
using \<open>elementLevel ?oll M = level\<close>
using \<open>?rhs\<close>
using \<open>set c \<noteq> {l}\<close>
unfolding isMinimalBackjumpLevel_def
by (auto simp del: set_removeAll)
qed
qed
lemma isMinimalBackjumpLevelEnsuresIsNotUnitBeforePrefix:
fixes M :: LiteralTrail and conflictFlag :: bool and c :: Clause and l :: Literal
assumes "consistent (elements M)" and "uniq (elements M)" and
"clauseFalse c (elements M)" "isMinimalBackjumpLevel level l c M" and
"level' < level"
shows "\<not> (\<exists> l'. isUnitClause c l' (elements (prefixToLevel level' M)))"
proof-
from \<open>isMinimalBackjumpLevel level l c M\<close>
have "isUnitClause c l (elements (prefixToLevel level M))"
using assms
using isBackjumpLevelEnsuresIsUnitInPrefix[of "M" "c" "level" "l"]
unfolding isMinimalBackjumpLevel_def
by simp
hence "\<not> literalFalse l (elements (prefixToLevel level M))"
unfolding isUnitClause_def
by auto
hence "\<not> literalFalse l (elements M) \<or> elementLevel (opposite l) M > level"
using elementLevelLtLevelImpliesMemberPrefixToLevel[of "l" "M" "level"]
using elementLevelLtLevelImpliesMemberPrefixToLevel[of "opposite l" "M" "level"]
by (force)+
have "\<not> literalFalse l (elements (prefixToLevel level' M))"
proof (cases "\<not> literalFalse l (elements M)")
case True
thus ?thesis
using prefixIsSubset[of "elements (prefixToLevel level' M)" "elements M"]
using isPrefixPrefixToLevel[of "level'" "M"]
using isPrefixElements[of "prefixToLevel level' M" "M"]
by auto
next
case False
with \<open>\<not> literalFalse l (elements M) \<or> elementLevel (opposite l) M > level\<close>
have "level < elementLevel (opposite l) M"
by simp
thus ?thesis
using prefixToLevelElementsElementLevel[of "opposite l" "level'" "M"]
using \<open>level' < level\<close>
by auto
qed
show ?thesis
proof (cases "set c \<noteq> {l}")
case True
from \<open>isMinimalBackjumpLevel level l c M\<close>
obtain ll
where "ll el c" "elementLevel (opposite ll) M = level"
using \<open>set c \<noteq> {l}\<close>
unfolding isMinimalBackjumpLevel_def
by auto
hence "\<not> literalFalse ll (elements (prefixToLevel level' M))"
using literalNotInEarlierLevelsThanItsLevel[of "level'" "opposite ll" "M"]
using \<open>level' < level\<close>
by simp
have "l \<noteq> ll"
using \<open>isMinimalBackjumpLevel level l c M\<close>
using \<open>elementLevel (opposite ll) M = level\<close>
unfolding isMinimalBackjumpLevel_def
unfolding isBackjumpLevel_def
by auto
{
assume "\<not> ?thesis"
then obtain l'
where "isUnitClause c l' (elements (prefixToLevel level' M))"
by auto
have "False"
proof (cases "l = l'")
case True
thus ?thesis
using \<open>l \<noteq> ll\<close> \<open>ll el c\<close>
using \<open>\<not> literalFalse ll (elements (prefixToLevel level' M))\<close>
using \<open>isUnitClause c l' (elements (prefixToLevel level' M))\<close>
unfolding isUnitClause_def
by auto
next
case False
have "l el c"
using \<open>isMinimalBackjumpLevel level l c M\<close>
unfolding isMinimalBackjumpLevel_def
unfolding isBackjumpLevel_def
unfolding isLastAssertedLiteral_def
using literalElListIffOppositeLiteralElOppositeLiteralList[of "l" "c"]
by simp
thus ?thesis
using False
using \<open>\<not> literalFalse l (elements (prefixToLevel level' M))\<close>
using \<open>isUnitClause c l' (elements (prefixToLevel level' M))\<close>
unfolding isUnitClause_def
by auto
qed
} thus ?thesis
by auto
next
case False
with \<open>isMinimalBackjumpLevel level l c M\<close>
have "level = 0"
unfolding isMinimalBackjumpLevel_def
by simp
with \<open>level' < level\<close>
show ?thesis
by simp
qed
qed
text\<open>If all literals in a clause are decision literals, then UIP is reached.\<close>
lemma allDecisionsThenUIP:
fixes M :: LiteralTrail and c:: Clause
assumes "(uniq (elements M))" and
"\<forall> l'. l' el c \<longrightarrow> (opposite l') el (decisions M)"
"isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)"
shows "isUIP l c M"
proof-
from \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)\<close>
have "l el c" "(opposite l) el (elements M)"
and *: "\<forall>l'. l' el (oppositeLiteralList c) \<and> l' \<noteq> opposite l \<longrightarrow> \<not> precedes (opposite l) l' (elements M)"
unfolding isLastAssertedLiteral_def
using "literalElListIffOppositeLiteralElOppositeLiteralList"
by auto
with \<open>\<forall> l'. l' el c \<longrightarrow> (opposite l') el (decisions M)\<close>
have "(opposite l) el (decisions M)"
by simp
{
fix l' :: Literal
assume "l' el c" "l' \<noteq> l"
hence "opposite l' el (oppositeLiteralList c)" and "opposite l' \<noteq> opposite l"
using literalElListIffOppositeLiteralElOppositeLiteralList[of "l'" "c"]
by auto
with *
have "\<not> precedes (opposite l) (opposite l') (elements M)"
by simp
from \<open>l' el c\<close> \<open>\<forall> l. l el c \<longrightarrow> (opposite l) el (decisions M)\<close>
have "(opposite l') el (decisions M)"
by auto
hence "(opposite l') el (elements M)"
by (simp add:markedElementsAreElements)
from \<open>(opposite l) el (elements M)\<close> \<open>(opposite l') el (elements M)\<close> \<open>l' \<noteq> l\<close>
\<open>\<not> precedes (opposite l) (opposite l') (elements M)\<close>
have "precedes (opposite l') (opposite l) (elements M)"
using precedesTotalOrder [of "opposite l" "elements M" "opposite l'"]
by simp
with \<open>uniq (elements M)\<close>
have "elementLevel (opposite l') M <= elementLevel (opposite l) M"
by (auto simp add:elementLevelPrecedesLeq)
moreover
from \<open>uniq (elements M)\<close> \<open>(opposite l) el (decisions M)\<close> \<open>(opposite l') el (decisions M)\<close> \<open>l' \<noteq> l\<close>
have "elementLevel (opposite l) M \<noteq> elementLevel (opposite l') M"
using differentMarkedElementsHaveDifferentLevels[of "M" "opposite l" "opposite l'"]
by simp
ultimately
have "elementLevel (opposite l') M < elementLevel (opposite l) M"
by simp
}
thus ?thesis
using \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)\<close>
unfolding isUIP_def
by simp
qed
text\<open>If last asserted literal of a clause is a decision literal, then UIP is reached.\<close>
lemma lastDecisionThenUIP:
fixes M :: LiteralTrail and c:: Clause
assumes "(uniq (elements M))" and
"(opposite l) el (decisions M)"
"clauseFalse c (elements M)"
"isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)"
shows "isUIP l c M"
proof-
from \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)\<close>
have "l el c" "(opposite l) el (elements M)"
and *: "\<forall>l'. l' el (oppositeLiteralList c) \<and> l' \<noteq> opposite l \<longrightarrow> \<not> precedes (opposite l) l' (elements M)"
unfolding isLastAssertedLiteral_def
using "literalElListIffOppositeLiteralElOppositeLiteralList"
by auto
{
fix l' :: Literal
assume "l' el c" "l' \<noteq> l"
hence "opposite l' el (oppositeLiteralList c)" and "opposite l' \<noteq> opposite l"
using literalElListIffOppositeLiteralElOppositeLiteralList[of "l'" "c"]
by auto
with *
have "\<not> precedes (opposite l) (opposite l') (elements M)"
by simp
have "(opposite l') el (elements M)"
using \<open>l' el c\<close> \<open>clauseFalse c (elements M)\<close>
by (simp add: clauseFalseIffAllLiteralsAreFalse)
from \<open>(opposite l) el (elements M)\<close> \<open>(opposite l') el (elements M)\<close> \<open>l' \<noteq> l\<close>
\<open>\<not> precedes (opposite l) (opposite l') (elements M)\<close>
have "precedes (opposite l') (opposite l) (elements M)"
using precedesTotalOrder [of "opposite l" "elements M" "opposite l'"]
by simp
hence "elementLevel (opposite l') M < elementLevel (opposite l) M"
using elementLevelPrecedesMarkedElementLt[of "M" "opposite l'" "opposite l"]
using \<open>uniq (elements M)\<close>
using \<open>opposite l el (decisions M)\<close>
using \<open>l' \<noteq> l\<close>
by simp
}
thus ?thesis
using \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)\<close>
unfolding SatSolverVerification.isUIP_def
by simp
qed
text\<open>If all literals in a clause are decision literals, then there
exists a backjump level for that clause.\<close>
lemma allDecisionsThenExistsBackjumpLevel:
fixes M :: LiteralTrail and c:: Clause
assumes "(uniq (elements M))" and
"\<forall> l'. l' el c \<longrightarrow> (opposite l') el (decisions M)"
"isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)"
shows "\<exists> level. (isBackjumpLevel level l c M)"
proof-
from assms
have "isUIP l c M"
using allDecisionsThenUIP
by simp
moreover
from \<open>isLastAssertedLiteral (opposite l) (oppositeLiteralList c) (elements M)\<close>
have "l el c"
unfolding isLastAssertedLiteral_def
using literalElListIffOppositeLiteralElOppositeLiteralList
by simp
with \<open>\<forall> l'. l' el c \<longrightarrow> (opposite l') el (decisions M)\<close>
have "(opposite l) el (decisions M)"
by simp
hence "elementLevel (opposite l) M > 0"
using \<open>uniq (elements M)\<close>
elementLevelMarkedGeq1[of "M" "opposite l"]
by auto
moreover
have "clauseFalse c (elements M)"
proof-
{
fix l'::Literal
assume "l' el c"
with \<open>\<forall> l'. l' el c \<longrightarrow> (opposite l') el (decisions M)\<close>
have "(opposite l') el (decisions M)"
by simp
hence "literalFalse l' (elements M)"
using markedElementsAreElements
by simp
}
thus ?thesis
using clauseFalseIffAllLiteralsAreFalse
by simp
qed
ultimately
show ?thesis
using \<open>uniq (elements M)\<close>
using isUIPExistsBackjumpLevel
by simp
qed
text\<open>$Explain$ is applicable to each non-decision literal in a clause.\<close>
lemma explainApplicableToEachNonDecision:
fixes F :: Formula and M :: LiteralTrail and conflictFlag :: bool and C :: Clause and literal :: Literal
assumes "InvariantReasonClauses F M" and "InvariantCFalse conflictFlag M C" and
"conflictFlag = True" and "opposite literal el C" and "\<not> literal el (decisions M)"
shows "\<exists> clause. formulaEntailsClause F clause \<and> isReason clause literal (elements M)"
proof-
from \<open>conflictFlag = True\<close> \<open>InvariantCFalse conflictFlag M C\<close>
have "clauseFalse C (elements M)"
unfolding InvariantCFalse_def
by simp
with \<open>opposite literal el C\<close>
have "literalTrue literal (elements M)"
by (auto simp add:clauseFalseIffAllLiteralsAreFalse)
with \<open>\<not> literal el (decisions M)\<close> \<open>InvariantReasonClauses F M\<close>
show ?thesis
unfolding InvariantReasonClauses_def
by auto
qed
(**************************************************************************)
(* T E R M I N A T I O N *)
(**************************************************************************)
subsection\<open>Termination\<close>
text\<open>In this section different ordering relations will be defined. These
well-founded orderings will be the basic building blocks of termination
orderings that will prove the termination of the SAT solving procedures\<close>
text\<open>First we prove a simple lemma about acyclic orderings.\<close>
lemma transIrreflexiveOrderingIsAcyclic:
assumes "trans r" and "\<forall> x. (x, x) \<notin> r"
shows "acyclic r"
proof (rule acyclicI)
{
assume "\<exists> x. (x, x) \<in> r^+"
then obtain x where "(x, x) \<in> r^+"
by auto
moreover
from \<open>trans r\<close>
have "r^+ = r"
by (rule trancl_id)
ultimately
have "(x, x) \<in> r"
by simp
with \<open>\<forall> x. (x, x) \<notin> r\<close>
have False
by simp
}
thus "\<forall> x. (x, x) \<notin> r^+"
by auto
qed
(*-----------------------------------------------------------------------*)
subsubsection\<open>Trail ordering\<close>
(*-----------------------------------------------------------------------*)
text\<open>We define a lexicographic ordering of trails, based on the
number of literals on the different decision levels. It will be used
for transition rules that change the trail, i.e., for $Decide$,
$UnitPropagate$, $Backjump$ and $Backtrack$ transition rules.\<close>
definition
"decisionLess = {(l1::('a*bool), l2::('a*bool)). isDecision l1 \<and> \<not> isDecision l2}"
definition
"lexLess = {(M1::'a Trail, M2::'a Trail). (M2, M1) \<in> lexord decisionLess}"
text\<open>Following several lemmas will help prove that application of
some DPLL-based transition rules decreases the trail in the @{term
lexLess} ordering.\<close>
lemma lexLessBackjump:
assumes "p = prefixToLevel level a" and "level >= 0" and "level < currentLevel a"
shows "(p @ [(x, False)], a) \<in> lexLess"
proof-
from assms
have "\<exists> rest. prefixToLevel level a @ rest = a \<and> rest \<noteq> [] \<and> isDecision (hd rest)"
using isProperPrefixPrefixToLevel
by auto
with \<open>p = prefixToLevel level a\<close>
obtain rest
where "p @ rest = a \<and> rest \<noteq> [] \<and> isDecision (hd rest)"
by auto
thus ?thesis
unfolding lexLess_def
using lexord_append_left_rightI[of "hd rest" "(x, False)" "decisionLess" "p" "tl rest" "[]"]
unfolding decisionLess_def
by simp
qed
lemma lexLessBacktrack:
assumes "p = prefixBeforeLastDecision a" "decisions a \<noteq> []"
shows "(p @ [(x, False)], a) \<in> lexLess"
using assms
using prefixBeforeLastMarkedIsPrefixBeforeLastLevel[of "a"]
using lexLessBackjump[of "p" "currentLevel a - 1" "a"]
unfolding currentLevel_def
by auto
text\<open>The following several lemmas prover that @{term lexLess} is
acyclic. This property will play an important role in building a
well-founded ordering based on @{term lexLess}.\<close>
lemma transDecisionLess:
shows "trans decisionLess"
proof-
{
fix x::"('a*bool)" and y::"('a*bool)" and z::"('a*bool)"
assume "(x, y) \<in> decisionLess"
hence "\<not> isDecision y"
unfolding decisionLess_def
by simp
moreover
assume "(y, z) \<in> decisionLess"
hence "isDecision y"
unfolding decisionLess_def
by simp
ultimately
have False
by simp
hence "(x, z) \<in> decisionLess"
by simp
}
thus ?thesis
unfolding trans_def
by blast
qed
lemma translexLess:
shows "trans lexLess"
proof-
{
fix x :: "'a Trail" and y :: "'a Trail" and z :: "'a Trail"
assume "(x, y) \<in> lexLess" and "(y, z) \<in> lexLess"
hence "(x, z) \<in> lexLess"
using lexord_trans transDecisionLess
unfolding lexLess_def
by simp
}
thus ?thesis
unfolding trans_def
by blast
qed
lemma irreflexiveDecisionLess:
shows "(x, x) \<notin> decisionLess"
unfolding decisionLess_def
by simp
lemma irreflexiveLexLess:
shows "(x, x) \<notin> lexLess"
using lexord_irreflexive[of "decisionLess" "x"] irreflexiveDecisionLess
unfolding lexLess_def
by auto
lemma acyclicLexLess:
shows "acyclic lexLess"
proof (rule transIrreflexiveOrderingIsAcyclic)
show "trans lexLess"
using translexLess
.
show "\<forall> x. (x, x) \<notin> lexLess"
using irreflexiveLexLess
by auto
qed
text\<open>The @{term lexLess} ordering is not well-founded. In order to
get a well-founded ordering, we restrict the @{term lexLess}
ordering to cosistent and uniq trails with fixed variable set.\<close>
definition "lexLessRestricted (Vbl::Variable set) == {(M1, M2).
vars (elements M1) \<subseteq> Vbl \<and> consistent (elements M1) \<and> uniq (elements M1) \<and>
vars (elements M2) \<subseteq> Vbl \<and> consistent (elements M2) \<and> uniq (elements M2) \<and>
(M1, M2) \<in> lexLess}"
text\<open>First we show that the set of those trails is finite.\<close>
lemma finiteVarsClause:
fixes c :: Clause
shows "finite (vars c)"
by (induct c) auto
lemma finiteVarsFormula:
fixes F :: Formula
shows "finite (vars F)"
proof (induct F)
case (Cons c F)
thus ?case
using finiteVarsClause[of "c"]
by simp
qed simp
lemma finiteListDecompose:
shows "finite {(a, b). l = a @ b}"
proof (induct l)
case Nil
thus ?case
by simp
next
case (Cons x l')
thus ?case
proof-
let "?S l" = "{(a, b). l = a @ b}"
let "?S' x l'" = "{(a', b). a' = [] \<and> b = (x # l') \<or>
(\<exists> a. a' = x # a \<and> (a, b) \<in> (?S l'))}"
have "?S (x # l') = ?S' x l'"
proof
show "?S (x # l') \<subseteq> ?S' x l'"
proof
fix k
assume "k \<in> ?S (x # l')"
then obtain a and b
where "k = (a, b)" "x # l' = a @ b"
by auto
then obtain a' where "a' = x # a"
by auto
from \<open>k = (a, b)\<close> \<open>x # l' = a @ b\<close>
show "k \<in> ?S' x l'"
using SimpleLevi[of "a" "b" "x" "l'"]
by auto
qed
next
show "?S' x l' \<subseteq> ?S (x # l')"
proof
fix k
assume "k \<in> ?S' x l'"
then obtain a' and b where
"k = (a', b)" "a' = [] \<and> b = x # l' \<or> (\<exists> a . a' = x # a \<and> (a, b) \<in> ?S l')"
by auto
moreover
{
assume "a' = []" "b = x # l'"
with \<open>k = (a', b)\<close>
have "k \<in> ?S (x # l')"
by simp
}
moreover
{
assume "\<exists> a. a' = x # a \<and> (a, b) \<in> ?S l'"
then obtain a where
"a' = x # a \<and> (a, b) \<in> ?S l'"
by auto
with \<open>k = (a', b)\<close>
have "k \<in> ?S (x # l')"
by auto
}
ultimately
show "k \<in> ?S (x # l')"
by auto
qed
qed
moreover
have "?S' x l' =
{(a', b). a' = [] \<and> b = x # l'} \<union> {(a', b). \<exists> a. a' = x # a \<and> (a, b) \<in> ?S l'}"
by auto
moreover
have "finite {(a', b). \<exists> a. a' = x # a \<and> (a, b) \<in> ?S l'}"
proof-
let ?h = "\<lambda> (a, b). (x # a, b)"
have "{(a', b). \<exists> a. a' = x # a \<and> (a, b) \<in> ?S l'} = ?h ` {(a, b). l' = a @ b}"
by auto
thus ?thesis
using Cons(1)
by auto
qed
moreover
have "finite {(a', b). a' = [] \<and> b = x # l'}"
by auto
ultimately
show ?thesis
by auto
qed
qed
lemma finiteListDecomposeSet:
fixes L :: "'a list set"
assumes "finite L"
shows "finite {(a, b). \<exists> l. l \<in> L \<and> l = a @ b}"
proof-
have "{(a, b). \<exists> l. l \<in> L \<and> l = a @ b} = (\<Union> l \<in> L. {(a, b). l = a @ b})"
by auto
moreover
have "finite (\<Union> l \<in> L. {(a, b). l = a @ b})"
proof (rule finite_UN_I)
from \<open>finite L\<close>
show "finite L"
.
next
fix l
assume "l \<in> L"
show "finite {(a, b). l = a @ b}"
by (rule finiteListDecompose)
qed
ultimately
show ?thesis
by simp
qed
lemma finiteUniqAndConsistentTrailsWithGivenVariableSet:
fixes V :: "Variable set"
assumes "finite V"
shows "finite {(M::LiteralTrail). vars (elements M) = V \<and> uniq (elements M) \<and> consistent (elements M)}"
(is "finite (?trails V)")
using assms
proof induct
case empty
thus ?case
proof-
have "?trails {} = {M. M = []}" (is "?lhs = ?rhs")
proof
show "?lhs \<subseteq> ?rhs"
proof
fix M::LiteralTrail
assume "M \<in> ?lhs"
hence "M = []"
by (induct M) auto
thus "M \<in> ?rhs"
by simp
qed
next
show "?rhs \<subseteq> ?lhs"
proof
fix M::LiteralTrail
assume "M \<in> ?rhs"
hence "M = []"
by simp
thus "M \<in> ?lhs"
by (induct M) auto
qed
qed
moreover
have "finite {M. M = []}"
by auto
ultimately
show ?thesis
by auto
qed
next
case (insert v V')
thus ?case
proof-
let "?trails' V'" = "{(M::LiteralTrail). \<exists> M' l d M''.
M = M' @ [(l, d)] @ M'' \<and>
M' @ M'' \<in> (?trails V') \<and>
l \<in> {Pos v, Neg v} \<and>
d \<in> {True, False}}"
have "?trails (insert v V') = ?trails' V'"
(is "?lhs = ?rhs")
proof
show "?lhs \<subseteq> ?rhs"
proof
fix M::LiteralTrail
assume "M \<in> ?lhs"
hence "vars (elements M) = insert v V'" "uniq (elements M)" "consistent (elements M)"
by auto
hence "v \<in> vars (elements M)"
by simp
hence "\<exists> l. l el elements M \<and> var l = v"
by (induct M) auto
then obtain l where "l el elements M" "var l = v"
by auto
hence "\<exists> M' M'' d. M = M' @ [(l, d)] @ M''"
proof (induct M)
case (Cons m M1)
thus ?case
proof (cases "l = (element m)")
case True
then obtain d where "m = (l, d)"
using eitherMarkedOrNotMarkedElement[of "m"]
by auto
hence "m # M1 = [] @ [(l, d)] @ M1"
by simp
then obtain M' M'' d where "m # M1 = M' @ [(l, d)] @ M''"
..
thus ?thesis
by auto
next
case False
with \<open>l el elements (m # M1)\<close>
have "l el elements M1"
by simp
with Cons(1) \<open>var l = v\<close>
obtain M1' M'' d where "M1 = M1' @ [(l, d)] @ M''"
by auto
hence "m # M1 = (m # M1') @ [(l, d)] @ M''"
by simp
then obtain M' M'' d where "m # M1 = M' @ [(l, d)] @ M''"
..
thus ?thesis
by auto
qed
qed simp
then obtain M' M'' d where "M = M' @ [(l, d)] @ M''"
by auto
moreover
from \<open>var l = v\<close>
have "l : {Pos v, Neg v}"
by (cases l) auto
moreover
have *: "vars (elements (M' @ M'')) = vars (elements M') \<union> vars (elements M'')"
using varsAppendClauses[of "elements M'" "elements M''"]
by simp
from \<open>M = M' @ [(l, d)] @ M''\<close> \<open>var l = v\<close>
have **: "vars (elements M) = (vars (elements M')) \<union> {v} \<union> (vars (elements M''))"
using varsAppendClauses[of "elements M'" "elements ([(l, d)] @ M'')"]
using varsAppendClauses[of "elements [(l, d)]" "elements M''"]
by simp
have ***: "vars (elements M) = vars (elements (M' @ M'')) \<union> {v}"
using * **
by simp
have "M' @ M'' \<in> (?trails V')"
proof-
from \<open>uniq (elements M)\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "uniq (elements (M' @ M''))"
by (auto iff: uniqAppendIff)
moreover
have "consistent (elements (M' @ M''))"
proof-
{
assume "\<not> consistent (elements (M' @ M''))"
then obtain l' where "literalTrue l' (elements (M' @ M''))" "literalFalse l' (elements (M' @ M''))"
by (auto simp add:inconsistentCharacterization)
with \<open>M = M' @ [(l, d)] @ M''\<close>
have "literalTrue l' (elements M)" "literalFalse l' (elements M)"
by auto
hence "\<not> consistent (elements M)"
by (auto simp add: inconsistentCharacterization)
with \<open>consistent (elements M)\<close>
have False
by simp
}
thus ?thesis
by auto
qed
moreover
have "v \<notin> vars (elements (M' @ M''))"
proof-
{
assume "v \<in> vars (elements (M' @ M''))"
with *
have "v \<in> vars (elements M') \<or> v \<in> vars (elements M'')"
by simp
moreover
{
assume "v \<in> (vars (elements M'))"
hence "\<exists> l. var l = v \<and> l el elements M'"
by (induct M') auto
then obtain l' where "var l' = v" "l' el elements M'"
by auto
from \<open>var l = v\<close> \<open>var l' = v\<close>
have "l = l' \<or> opposite l = l'"
using literalsWithSameVariableAreEqualOrOpposite[of "l" "l'"]
by simp
moreover
{
assume "l = l'"
with \<open>l' el elements M'\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "\<not> uniq (elements M)"
by (auto iff: uniqAppendIff)
with \<open>uniq (elements M)\<close>
have False
by simp
}
moreover
{
assume "opposite l = l'"
have "\<not> consistent (elements M)"
proof-
from \<open>l' el elements M'\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "literalTrue l' (elements M)"
by simp
moreover
from \<open>l' el elements M'\<close> \<open>opposite l = l'\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "literalFalse l' (elements M)"
by simp
ultimately
show ?thesis
by (auto simp add: inconsistentCharacterization)
qed
with \<open>consistent (elements M)\<close>
have False
by simp
}
ultimately
have False
by auto
}
moreover
{
assume "v \<in> (vars (elements M''))"
hence "\<exists> l. var l = v \<and> l el elements M''"
by (induct M'') auto
then obtain l' where "var l' = v" "l' el (elements M'')"
by auto
from \<open>var l = v\<close> \<open>var l' = v\<close>
have "l = l' \<or> opposite l = l'"
using literalsWithSameVariableAreEqualOrOpposite[of "l" "l'"]
by simp
moreover
{
assume "l = l'"
with \<open>l' el elements M''\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "\<not> uniq (elements M)"
by (auto iff: uniqAppendIff)
with \<open>uniq (elements M)\<close>
have False
by simp
}
moreover
{
assume "opposite l = l'"
have "\<not> consistent (elements M)"
proof-
from \<open>l' el elements M''\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "literalTrue l' (elements M)"
by simp
moreover
from \<open>l' el elements M''\<close> \<open>opposite l = l'\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "literalFalse l' (elements M)"
by simp
ultimately
show ?thesis
by (auto simp add: inconsistentCharacterization)
qed
with \<open>consistent (elements M)\<close>
have False
by simp
}
ultimately
have False
by auto
}
ultimately
have False
by auto
}
thus ?thesis
by auto
qed
from
* ** ***
\<open>v \<notin> vars (elements (M' @ M''))\<close>
\<open>vars (elements M) = insert v V'\<close>
\<open>\<not> v \<in> V'\<close>
have "vars (elements (M' @ M'')) = V'"
by (auto simp del: vars_clause_def)
ultimately
show ?thesis
by simp
qed
ultimately
show "M \<in> ?rhs"
by auto
qed
next
show "?rhs \<subseteq> ?lhs"
proof
fix M :: LiteralTrail
assume "M \<in> ?rhs"
then obtain M' M'' l d where
"M = M' @ [(l, d)] @ M''"
"vars (elements (M' @ M'')) = V'"
"uniq (elements (M' @ M''))" "consistent (elements (M' @ M''))" "l \<in> {Pos v, Neg v}"
by auto
from \<open>l \<in> {Pos v, Neg v}\<close>
have "var l = v"
by auto
have *: "vars (elements (M' @ M'')) = vars (elements M') \<union> vars (elements M'')"
using varsAppendClauses[of "elements M'" "elements M''"]
by simp
from \<open>var l = v\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have **: "vars (elements M) = vars (elements M') \<union> {v} \<union> vars (elements M'')"
using varsAppendClauses[of "elements M'" "elements ([(l, d)] @ M'')"]
using varsAppendClauses[of "elements [(l, d)]" "elements M''"]
by simp
from * ** \<open>vars (elements (M' @ M'')) = V'\<close>
have "vars (elements M) = insert v V'"
by (auto simp del: vars_clause_def)
moreover
from *
\<open>var l = v\<close>
\<open>v \<notin> V'\<close>
\<open>vars (elements (M' @ M'')) = V'\<close>
have "var l \<notin> vars (elements M')" "var l \<notin> vars (elements M'')"
by auto
from \<open>var l \<notin> vars (elements M')\<close>
have "\<not> literalTrue l (elements M')" "\<not> literalFalse l (elements M')"
using valuationContainsItsLiteralsVariable[of "l" "elements M'"]
using valuationContainsItsLiteralsVariable[of "opposite l" "elements M'"]
by auto
from \<open>var l \<notin> vars (elements M'')\<close>
have "\<not> literalTrue l (elements M'')" "\<not> literalFalse l (elements M'')"
using valuationContainsItsLiteralsVariable[of "l" "elements M''"]
using valuationContainsItsLiteralsVariable[of "opposite l" "elements M''"]
by auto
have "uniq (elements M)"
using \<open>M = M' @ [(l, d)] @ M''\<close> \<open>uniq (elements (M' @ M''))\<close>
\<open>\<not> literalTrue l (elements M'')\<close> \<open>\<not> literalFalse l (elements M'')\<close>
\<open>\<not> literalTrue l (elements M')\<close> \<open>\<not> literalFalse l (elements M')\<close>
by (auto iff: uniqAppendIff)
moreover
have "consistent (elements M)"
proof-
{
assume "\<not> consistent (elements M)"
then obtain l' where "literalTrue l' (elements M)" "literalFalse l' (elements M)"
by (auto simp add: inconsistentCharacterization)
have False
proof (cases "l' = l")
case True
with \<open>literalFalse l' (elements M)\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "literalFalse l' (elements (M' @ M''))"
using oppositeIsDifferentFromLiteral[of "l"]
by (auto split: if_split_asm)
with \<open>\<not> literalFalse l (elements M')\<close> \<open>\<not> literalFalse l (elements M'')\<close> \<open>l' = l\<close>
show ?thesis
by auto
next
case False
with \<open>literalTrue l' (elements M)\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "literalTrue l' (elements (M' @ M''))"
by (auto split: if_split_asm)
with \<open>consistent (elements (M' @ M''))\<close>
have "\<not> literalFalse l' (elements (M' @ M''))"
by (auto simp add: inconsistentCharacterization)
with \<open>literalFalse l' (elements M)\<close> \<open>M = M' @ [(l, d)] @ M''\<close>
have "opposite l' = l"
by (auto split: if_split_asm)
with \<open>var l = v\<close>
have "var l' = v"
by auto
with \<open>literalTrue l' (elements (M' @ M''))\<close> \<open>vars (elements (M' @ M'')) = V'\<close>
have "v \<in> V'"
using valuationContainsItsLiteralsVariable[of "l'" "elements (M' @ M'')"]
by simp
with \<open>v \<notin> V'\<close>
show ?thesis
by simp
qed
}
thus ?thesis
by auto
qed
ultimately
show "M \<in> ?lhs"
by auto
qed
qed
moreover
let ?f = "\<lambda> ((M', M''), l, d). M' @ [(l, d)] @ M''"
let ?Mset = "{(M', M''). M' @ M'' \<in> ?trails V'}"
let ?lSet = "{Pos v, Neg v}"
let ?dSet = "{True, False}"
have "?trails' V' = ?f ` (?Mset \<times> ?lSet \<times> ?dSet)" (is "?lhs = ?rhs")
proof
show "?lhs \<subseteq> ?rhs"
proof
fix M :: LiteralTrail
assume "M \<in> ?lhs"
then obtain M' M'' l d
where P: "M = M' @ [(l, d)] @ M''" "M' @ M'' \<in> (?trails V')" "l \<in> {Pos v, Neg v}" "d \<in> {True, False}"
by auto
show "M \<in> ?rhs"
proof
from P
show "M = ?f ((M', M''), l, d)"
by simp
next
from P
show "((M', M''), l, d) \<in> ?Mset \<times> ?lSet \<times> ?dSet"
by auto
qed
qed
next
show "?rhs \<subseteq> ?lhs"
proof
fix M::LiteralTrail
assume "M \<in> ?rhs"
then obtain p l d where P: "M = ?f (p, l, d)" "p \<in> ?Mset" "l \<in> ?lSet" "d \<in> ?dSet"
by auto
from \<open>p \<in> ?Mset\<close>
obtain M' M'' where "M' @ M'' \<in> ?trails V'"
by auto
thus "M \<in> ?lhs"
using P
by auto
qed
qed
moreover
have "?Mset = {(M', M''). \<exists> l. l \<in> ?trails V' \<and> l = M' @ M''}"
by auto
hence "finite ?Mset"
using insert(3)
using finiteListDecomposeSet[of "?trails V'"]
by simp
ultimately
show ?thesis
by auto
qed
qed
lemma finiteUniqAndConsistentTrailsWithGivenVariableSuperset:
fixes V :: "Variable set"
assumes "finite V"
shows "finite {(M::LiteralTrail). vars (elements M) \<subseteq> V \<and> uniq (elements M) \<and> consistent (elements M)}" (is "finite (?trails V)")
proof-
have "{M. vars (elements M) \<subseteq> V \<and> uniq (elements M) \<and> consistent (elements M)} =
(\<Union> v \<in> Pow V.{M. vars (elements M) = v \<and> uniq (elements M) \<and> consistent (elements M)})"
by auto
moreover
have "finite (\<Union> v \<in> Pow V.{M. vars (elements M) = v \<and> uniq (elements M) \<and> consistent (elements M)})"
proof (rule finite_UN_I)
from \<open>finite V\<close>
show "finite (Pow V)"
by simp
next
fix v
assume "v \<in> Pow V"
with \<open>finite V\<close>
have "finite v"
by (auto simp add: finite_subset)
thus "finite {M. vars (elements M) = v \<and> uniq (elements M) \<and> consistent (elements M)}"
using finiteUniqAndConsistentTrailsWithGivenVariableSet[of "v"]
by simp
qed
ultimately
show ?thesis
by simp
qed
text\<open>Since the restricted ordering is acyclic and its domain is
finite, it has to be well-founded.\<close>
lemma wfLexLessRestricted:
assumes "finite Vbl"
shows "wf (lexLessRestricted Vbl)"
proof (rule finite_acyclic_wf)
show "finite (lexLessRestricted Vbl)"
proof-
let ?X = "{(M1, M2).
consistent (elements M1) \<and> uniq (elements M1) \<and> vars (elements M1) \<subseteq> Vbl \<and>
consistent (elements M2) \<and> uniq (elements M2) \<and> vars (elements M2) \<subseteq> Vbl}"
let ?Y = "{M. vars (elements M) \<subseteq> Vbl \<and> uniq (elements M) \<and> consistent (elements M)}"
have "?X = ?Y \<times> ?Y"
by auto
moreover
have "finite ?Y"
using finiteUniqAndConsistentTrailsWithGivenVariableSuperset[of "Vbl"]
\<open>finite Vbl\<close>
by auto
ultimately
have "finite ?X"
by simp
moreover
have "lexLessRestricted Vbl \<subseteq> ?X"
unfolding lexLessRestricted_def
by auto
ultimately
show ?thesis
by (simp add: finite_subset)
qed
next
show "acyclic (lexLessRestricted Vbl)"
proof-
{
assume "\<not> ?thesis"
then obtain x where "(x, x) \<in> (lexLessRestricted Vbl)^+"
unfolding acyclic_def
by auto
have "lexLessRestricted Vbl \<subseteq> lexLess"
unfolding lexLessRestricted_def
by auto
have "(lexLessRestricted Vbl)^+ \<subseteq> lexLess^+"
proof
fix a
assume "a \<in> (lexLessRestricted Vbl)^+"
with \<open>lexLessRestricted Vbl \<subseteq> lexLess\<close>
show "a \<in> lexLess^+"
using trancl_mono[of "a" "lexLessRestricted Vbl" "lexLess"]
by blast
qed
with \<open>(x, x) \<in> (lexLessRestricted Vbl)^+\<close>
have "(x, x) \<in> lexLess^+"
by auto
moreover
have "trans lexLess"
using translexLess
.
hence "lexLess^+ = lexLess"
by (rule trancl_id)
ultimately
have "(x, x) \<in> lexLess"
by auto
with irreflexiveLexLess[of "x"]
have False
by simp
}
thus ?thesis
by auto
qed
qed
text\<open>@{term lexLessRestricted} is also transitive.\<close>
lemma transLexLessRestricted:
shows "trans (lexLessRestricted Vbl)"
proof-
{
fix x::LiteralTrail and y::LiteralTrail and z::LiteralTrail
assume "(x, y) \<in> lexLessRestricted Vbl" "(y, z) \<in> lexLessRestricted Vbl"
hence "(x, z) \<in> lexLessRestricted Vbl"
unfolding lexLessRestricted_def
using translexLess
unfolding trans_def
by auto
}
thus ?thesis
unfolding trans_def
by blast
qed
(*-----------------------------------------------------------------------*)
subsubsection\<open>Conflict clause ordering\<close>
(*-----------------------------------------------------------------------*)
text\<open>The ordering of conflict clauses is the multiset ordering induced by the ordering of elements in the trail.
Since, resolution operator is defined so that it removes all occurrences of clashing literal, it is also neccessary
to remove duplicate literals before comparison.\<close>
definition
"multLess M = inv_image (mult (precedesOrder (elements M))) (\<lambda> x. mset (remdups (oppositeLiteralList x)))"
text\<open>The following lemma will help prove that application of the
$Explain$ DPLL transition rule decreases the conflict clause in the
@{term multLess} ordering.\<close>
lemma multLessResolve:
assumes
"opposite l el C" and
"isReason reason l (elements M)"
shows
"(resolve C reason (opposite l), C) \<in> multLess M"
proof-
let ?X = "mset (remdups (oppositeLiteralList C))"
let ?Y = "mset (remdups (oppositeLiteralList (resolve C reason (opposite l))))"
let ?ord = "precedesOrder (elements M)"
have "(?Y, ?X) \<in> (mult1 ?ord)"
proof-
let ?Z = "mset (remdups (oppositeLiteralList (removeAll (opposite l) C)))"
let ?W = "mset (remdups (oppositeLiteralList (removeAll l (list_diff reason C))))"
let ?a = "l"
from \<open>(opposite l) el C\<close>
have "?X = ?Z + {#?a#}"
using removeAll_multiset[of "remdups (oppositeLiteralList C)" "l"]
using oppositeLiteralListRemove[of "opposite l" "C"]
using literalElListIffOppositeLiteralElOppositeLiteralList[of "l" "oppositeLiteralList C"]
by auto
moreover
have "?Y = ?Z + ?W"
proof-
have "list_diff (oppositeLiteralList (removeAll l reason)) (oppositeLiteralList (removeAll (opposite l) C)) =
oppositeLiteralList (removeAll l (list_diff reason C))"
proof-
from \<open>isReason reason l (elements M)\<close>
have "opposite l \<notin> set (removeAll l reason)"
unfolding isReason_def
by auto
hence "list_diff (removeAll l reason) (removeAll (opposite l) C) = list_diff (removeAll l reason) C"
using listDiffRemoveAllNonMember[of "opposite l" "removeAll l reason" "C"]
by simp
thus ?thesis
unfolding oppositeLiteralList_def
using listDiffMap[of "opposite" "removeAll l reason" "removeAll (opposite l) C"]
by auto
qed
thus ?thesis
unfolding resolve_def
using remdupsAppendMultiSet[of "oppositeLiteralList (removeAll (opposite l) C)" "oppositeLiteralList (removeAll l reason)"]
unfolding oppositeLiteralList_def
by auto
qed
moreover
have "\<forall> b. b \<in># ?W \<longrightarrow> (b, ?a) \<in> ?ord"
proof-
{
fix b
assume "b \<in># ?W"
hence "opposite b \<in> set (removeAll l reason)"
proof-
from \<open>b \<in># ?W\<close>
have "b el remdups (oppositeLiteralList (removeAll l (list_diff reason C)))"
by simp
hence "opposite b el removeAll l (list_diff reason C)"
using literalElListIffOppositeLiteralElOppositeLiteralList[of "opposite b" "removeAll l (list_diff reason C)"]
by auto
hence "opposite b el list_diff (removeAll l reason) C"
by simp
thus ?thesis
using listDiffIff[of "opposite b" "removeAll l reason" "C"]
by simp
qed
with \<open>isReason reason l (elements M)\<close>
have "precedes b l (elements M)" "b \<noteq> l"
unfolding isReason_def
unfolding precedes_def
by auto
hence "(b, ?a) \<in> ?ord"
unfolding precedesOrder_def
by simp
}
thus ?thesis
by auto
qed
ultimately
have "\<exists> a M0 K. ?X = M0 + {#a#} \<and> ?Y = M0 + K \<and> (\<forall>b. b \<in># K \<longrightarrow> (b, a) \<in> ?ord)"
by blast
thus ?thesis
unfolding mult1_def
by auto
qed
hence "(?Y, ?X) \<in> (mult1 ?ord)\<^sup>+"
by simp
thus ?thesis
unfolding multLess_def
unfolding mult_def
unfolding inv_image_def
by auto
qed
lemma multLessListDiff:
assumes
"(a, b) \<in> multLess M"
shows
"(list_diff a x, b) \<in> multLess M"
proof-
let ?pOrd = "precedesOrder (elements M)"
let ?f = "\<lambda> l. remdups (map opposite l)"
have "trans ?pOrd"
using transPrecedesOrder[of "elements M"]
by simp
have "(mset (?f a), mset (?f b)) \<in> mult ?pOrd"
using assms
unfolding multLess_def
unfolding oppositeLiteralList_def
by simp
moreover
have "multiset_le (mset (list_diff (?f a) (?f x)))
(mset (?f a))
?pOrd"
using \<open>trans ?pOrd\<close>
using multisetLeListDiff[of "?pOrd" "?f a" "?f x"]
by simp
ultimately
have "(mset (list_diff (?f a) (?f x)), mset (?f b)) \<in> mult ?pOrd"
unfolding multiset_le_def
unfolding mult_def
by auto
thus ?thesis
unfolding multLess_def
unfolding oppositeLiteralList_def
by (simp add: listDiffMap remdupsListDiff)
qed
lemma multLessRemdups:
assumes
"(a, b) \<in> multLess M"
shows
"(remdups a, remdups b) \<in> multLess M \<and>
(remdups a, b) \<in> multLess M \<and>
(a, remdups b) \<in> multLess M"
proof-
{
fix l
have "remdups (map opposite l) = remdups (map opposite (remdups l))"
by (induct l) auto
}
thus ?thesis
using assms
unfolding multLess_def
unfolding oppositeLiteralList_def
by simp
qed
text\<open>Now we show that @{term multLess} is well-founded.\<close>
lemma wfMultLess:
shows "wf (multLess M)"
proof-
have "wf (precedesOrder (elements M))"
by (simp add: wellFoundedPrecedesOrder)
hence "wf (mult (precedesOrder (elements M)))"
by (simp add: wf_mult)
thus ?thesis
unfolding multLess_def
using wf_inv_image[of "(mult (precedesOrder (elements M)))"]
by auto
qed
(*-----------------------------------------------------------------------*)
subsubsection\<open>ConflictFlag ordering\<close>
(*-----------------------------------------------------------------------*)
text\<open>A trivial ordering on Booleans. It will be used for the
$Conflict$ transition rule.\<close>
definition
"boolLess = {(True, False)}"
text\<open>We show that it is well-founded\<close>
lemma wfBoolLess:
shows "wf boolLess"
proof (rule finite_acyclic_wf)
show "finite boolLess"
unfolding boolLess_def
by simp
next
have "boolLess^+ = boolLess"
using transBoolLess
by simp
thus "acyclic boolLess"
unfolding boolLess_def
unfolding acyclic_def
by auto
qed
(*-----------------------------------------------------------------------*)
subsubsection\<open>Formulae ordering\<close>
(*-----------------------------------------------------------------------*)
text\<open>A partial ordering of formulae, based on a membersip of a
single fixed clause. This ordering will be used for the $Learn$
transtion rule.\<close>
definition "learnLess (C::Clause) == {((F1::Formula), (F2::Formula)). C el F1 \<and> \<not> C el F2}"
text\<open>We show that it is well founded\<close>
lemma wfLearnLess:
fixes C::Clause
shows "wf (learnLess C)"
unfolding wf_eq_minimal
proof-
show "\<forall>Q F. F \<in> Q \<longrightarrow> (\<exists>Fmin\<in>Q. \<forall>F'. (F', Fmin) \<in> learnLess C \<longrightarrow> F' \<notin> Q)"
proof-
{
fix F::Formula and Q::"Formula set"
assume "F \<in> Q"
have "\<exists>Fmin\<in>Q. \<forall>F'. (F', Fmin) \<in> learnLess C \<longrightarrow> F' \<notin> Q"
proof (cases "\<exists> Fc \<in> Q. C el Fc")
case True
then obtain Fc where "Fc \<in> Q" "C el Fc"
by auto
have "\<forall>F'. (F', Fc) \<in> learnLess C \<longrightarrow> F' \<notin> Q"
proof
fix F'
show "(F', Fc) \<in> learnLess C \<longrightarrow> F' \<notin> Q"
proof
assume "(F', Fc) \<in> learnLess C"
hence "\<not> C el Fc"
unfolding learnLess_def
by auto
with \<open>C el Fc\<close> have False
by simp
thus "F' \<notin> Q"
by simp
qed
qed
with \<open>Fc \<in> Q\<close>
show ?thesis
by auto
next
case False
have "\<forall>F'. (F', F) \<in> learnLess C \<longrightarrow> F' \<notin> Q"
proof
fix F'
show "(F', F) \<in> learnLess C \<longrightarrow> F' \<notin> Q"
proof
assume "(F', F) \<in> learnLess C"
hence "C el F'"
unfolding learnLess_def
by simp
with False
show "F' \<notin> Q"
by auto
qed
qed
with \<open>F \<in> Q\<close>
show ?thesis
by auto
qed
}
thus ?thesis
by auto
qed
qed
(*-----------------------------------------------------------------------*)
subsubsection\<open>Properties of well-founded relations.\<close>
(*-----------------------------------------------------------------------*)
lemma wellFoundedEmbed:
fixes rel :: "('a \<times> 'a) set" and rel' :: "('a \<times> 'a) set"
assumes "\<forall> x y. (x, y) \<in> rel \<longrightarrow> (x, y) \<in> rel'" and "wf rel'"
shows "wf rel"
unfolding wf_eq_minimal
proof-
show "\<forall>Q x. x \<in> Q \<longrightarrow> (\<exists>zmin\<in>Q. \<forall>z. (z, zmin) \<in> rel \<longrightarrow> z \<notin> Q)"
proof-
{
fix x::"'a" and Q::"'a set"
assume "x \<in> Q"
have "\<exists>zmin\<in>Q. \<forall>z. (z, zmin) \<in> rel \<longrightarrow> z \<notin> Q"
proof-
from \<open>wf rel'\<close> \<open>x \<in> Q\<close>
obtain zmin::"'a"
where "zmin \<in> Q" and "\<forall>z. (z, zmin) \<in> rel' \<longrightarrow> z \<notin> Q"
unfolding wf_eq_minimal
by auto
{
fix z::"'a"
assume "(z, zmin) \<in> rel"
have "z \<notin> Q"
proof-
from \<open>\<forall> x y. (x, y) \<in> rel \<longrightarrow> (x, y) \<in> rel'\<close> \<open>(z, zmin) \<in> rel\<close>
have "(z, zmin) \<in> rel'"
by simp
with \<open>\<forall>z. (z, zmin) \<in> rel' \<longrightarrow> z \<notin> Q\<close>
show ?thesis
by simp
qed
}
with \<open>zmin \<in> Q\<close>
show ?thesis
by auto
qed
}
thus ?thesis
by auto
qed
qed
end
|
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒΉ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβ : Preorder ΞΉ
x : Ξ±
β’ x β notConvergentSeq f g n j β β k x_1, 1 / (βn + 1) < dist (f k x) (g x)
[PROOFSTEP]
simp_rw [notConvergentSeq, Set.mem_iUnion]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒΉ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβ : Preorder ΞΉ
x : Ξ±
β’ (β i i_1, x β {x | 1 / (βn + 1) < dist (f i x) (g x)}) β β k x_1, 1 / (βn + 1) < dist (f k x) (g x)
[PROOFSTEP]
rfl
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
β’ ββΞΌ (s β© β (j : ΞΉ), notConvergentSeq f g n j) = 0
[PROOFSTEP]
simp_rw [Metric.tendsto_atTop, ae_iff] at hfg
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
n : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
β’ ββΞΌ (s β© β (j : ΞΉ), notConvergentSeq f g n j) = 0
[PROOFSTEP]
rw [β nonpos_iff_eq_zero, β hfg]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
n : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
β’ ββΞΌ (s β© β (j : ΞΉ), notConvergentSeq f g n j) β€
ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)}
[PROOFSTEP]
refine' measure_mono fun x => _
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
n : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
x : Ξ±
β’ x β s β© β (j : ΞΉ), notConvergentSeq f g n j β
x β {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)}
[PROOFSTEP]
simp only [Set.mem_inter_iff, Set.mem_iInter, ge_iff_le, mem_notConvergentSeq_iff]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
n : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
x : Ξ±
β’ (x β s β§ β (i : ΞΉ), β k x_1, 1 / (βn + 1) < dist (f k x) (g x)) β
x β {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), N β€ n β dist (f n a) (g a) < Ξ΅)}
[PROOFSTEP]
push_neg
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
n : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
x : Ξ±
β’ (x β s β§ β (i : ΞΉ), β k x_1, 1 / (βn + 1) < dist (f k x) (g x)) β
x β {a | a β s β§ β Ξ΅, Ξ΅ > 0 β§ β (N : ΞΉ), β n, N β€ n β§ Ξ΅ β€ dist (f n a) (g a)}
[PROOFSTEP]
rintro β¨hmem, hxβ©
[GOAL]
case intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
n : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
x : Ξ±
hmem : x β s
hx : β (i : ΞΉ), β k x_1, 1 / (βn + 1) < dist (f k x) (g x)
β’ x β {a | a β s β§ β Ξ΅, Ξ΅ > 0 β§ β (N : ΞΉ), β n, N β€ n β§ Ξ΅ β€ dist (f n a) (g a)}
[PROOFSTEP]
refine' β¨hmem, 1 / (n + 1 : β), Nat.one_div_pos_of_nat, fun N => _β©
[GOAL]
case intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
n : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
x : Ξ±
hmem : x β s
hx : β (i : ΞΉ), β k x_1, 1 / (βn + 1) < dist (f k x) (g x)
N : ΞΉ
β’ β n_1, N β€ n_1 β§ 1 / (βn + 1) β€ dist (f n_1 x) (g x)
[PROOFSTEP]
obtain β¨n, hnβ, hnββ© := hx N
[GOAL]
case intro.intro.intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβΒΉ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Nonempty ΞΉ
nβ : β
hfg : ββΞΌ {a | Β¬(a β s β β (Ξ΅ : β), Ξ΅ > 0 β β N, β (n : ΞΉ), n β₯ N β dist (f n a) (g a) < Ξ΅)} = 0
x : Ξ±
hmem : x β s
hx : β (i : ΞΉ), β k x_1, 1 / (βnβ + 1) < dist (f k x) (g x)
N n : ΞΉ
hnβ : N β€ n
hnβ : 1 / (βnβ + 1) < dist (f n x) (g x)
β’ β n, N β€ n β§ 1 / (βnβ + 1) β€ dist (f n x) (g x)
[PROOFSTEP]
exact β¨n, hnβ, hnβ.leβ©
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Countable ΞΉ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
β’ Tendsto (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) atTop (π 0)
[PROOFSTEP]
cases' isEmpty_or_nonempty ΞΉ with h h
[GOAL]
case inl
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Countable ΞΉ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
h : IsEmpty ΞΉ
β’ Tendsto (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) atTop (π 0)
[PROOFSTEP]
have : (fun j => ΞΌ (s β© notConvergentSeq f g n j)) = fun j => 0 := by simp only [eq_iff_true_of_subsingleton]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Countable ΞΉ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
h : IsEmpty ΞΉ
β’ (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) = fun j => 0
[PROOFSTEP]
simp only [eq_iff_true_of_subsingleton]
[GOAL]
case inl
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Countable ΞΉ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
h : IsEmpty ΞΉ
this : (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) = fun j => 0
β’ Tendsto (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) atTop (π 0)
[PROOFSTEP]
rw [this]
[GOAL]
case inl
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Countable ΞΉ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
h : IsEmpty ΞΉ
this : (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) = fun j => 0
β’ Tendsto (fun j => 0) atTop (π 0)
[PROOFSTEP]
exact tendsto_const_nhds
[GOAL]
case inr
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Countable ΞΉ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
h : Nonempty ΞΉ
β’ Tendsto (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) atTop (π 0)
[PROOFSTEP]
rw [β measure_inter_notConvergentSeq_eq_zero hfg n, Set.inter_iInter]
[GOAL]
case inr
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ² : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒΉ : SemilatticeSup ΞΉ
instβ : Countable ΞΉ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
h : Nonempty ΞΉ
β’ Tendsto (fun j => ββΞΌ (s β© notConvergentSeq f g n j)) atTop
(π (ββΞΌ (β (i : ΞΉ), s β© notConvergentSeq (fun n x => f n x) (fun x => g x) n i)))
[PROOFSTEP]
refine'
tendsto_measure_iInter (fun n => hsm.inter <| notConvergentSeq_measurableSet hf hg)
(fun k l hkl => Set.inter_subset_inter_right _ <| notConvergentSeq_antitone hkl)
β¨h.some, (lt_of_le_of_lt (measure_mono <| Set.inter_subset_left _ _) (lt_top_iff_ne_top.2 hs)).neβ©
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
β’ β j, ββΞΌ (s β© notConvergentSeq f g n j) β€ ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n)
[PROOFSTEP]
have β¨N, hNβ© :=
(ENNReal.tendsto_atTop ENNReal.zero_ne_top).1 (measure_notConvergentSeq_tendsto_zero hf hg hsm hs hfg n)
(ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n))
(by
rw [gt_iff_lt, ENNReal.ofReal_pos]
exact mul_pos hΞ΅ (pow_pos (by norm_num) n))
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
β’ ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n) > 0
[PROOFSTEP]
rw [gt_iff_lt, ENNReal.ofReal_pos]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
β’ 0 < Ξ΅ * 2β»ΒΉ ^ n
[PROOFSTEP]
exact mul_pos hΞ΅ (pow_pos (by norm_num) n)
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
β’ 0 < 2β»ΒΉ
[PROOFSTEP]
norm_num
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
N : ΞΉ
hN :
β (n_1 : ΞΉ),
n_1 β₯ N β
ββΞΌ (s β© notConvergentSeq (fun n => f n) g n n_1) β
Icc (0 - ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n)) (0 + ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n))
β’ β j, ββΞΌ (s β© notConvergentSeq f g n j) β€ ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n)
[PROOFSTEP]
rw [zero_add] at hN
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
N : ΞΉ
hN :
β (n_1 : ΞΉ),
n_1 β₯ N β
ββΞΌ (s β© notConvergentSeq (fun n => f n) g n n_1) β
Icc (0 - ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n)) (ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n))
β’ β j, ββΞΌ (s β© notConvergentSeq f g n j) β€ ENNReal.ofReal (Ξ΅ * 2β»ΒΉ ^ n)
[PROOFSTEP]
exact β¨N, (hN N le_rfl).2β©
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ ββΞΌ (iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg) β€ ENNReal.ofReal Ξ΅
[PROOFSTEP]
refine'
le_trans (measure_iUnion_le _)
(le_trans (ENNReal.tsum_le_tsum <| notConvergentSeqLTIndex_spec (half_pos hΞ΅) hf hg hsm hs hfg) _)
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ β' (a : β), ENNReal.ofReal (Ξ΅ / 2 * 2β»ΒΉ ^ a) β€ ENNReal.ofReal Ξ΅
[PROOFSTEP]
simp_rw [ENNReal.ofReal_mul (half_pos hΞ΅).le]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ β' (a : β), ENNReal.ofReal (Ξ΅ / 2) * ENNReal.ofReal (2β»ΒΉ ^ a) β€ ENNReal.ofReal Ξ΅
[PROOFSTEP]
rw [ENNReal.tsum_mul_left, β ENNReal.ofReal_tsum_of_nonneg, inv_eq_one_div, tsum_geometric_two, β
ENNReal.ofReal_mul (half_pos hΞ΅).le, div_mul_cancel Ξ΅ two_ne_zero]
[GOAL]
case hf_nonneg
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ β (n : β), 0 β€ 2β»ΒΉ ^ n
[PROOFSTEP]
exact fun n => pow_nonneg (by norm_num) _
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
n : β
β’ 0 β€ 2β»ΒΉ
[PROOFSTEP]
norm_num
[GOAL]
case hf
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ Summable fun i => 2β»ΒΉ ^ i
[PROOFSTEP]
rw [inv_eq_one_div]
[GOAL]
case hf
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ Summable fun i => (1 / 2) ^ i
[PROOFSTEP]
exact summable_geometric_two
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg β s
[PROOFSTEP]
rw [iUnionNotConvergentSeq, β Set.inter_iUnion]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ s β© β (i : β), notConvergentSeq (fun n => f n) g i (notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg i) β s
[PROOFSTEP]
exact Set.inter_subset_left _ _
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ TendstoUniformlyOn f g atTop (s \ iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg)
[PROOFSTEP]
rw [Metric.tendstoUniformlyOn_iff]
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
β’ β (Ξ΅_1 : β),
Ξ΅_1 > 0 β
βαΆ (n : ΞΉ) in atTop, β (x : Ξ±), x β s \ iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg β dist (g x) (f n x) < Ξ΅_1
[PROOFSTEP]
intro Ξ΄ hΞ΄
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
β’ βαΆ (n : ΞΉ) in atTop, β (x : Ξ±), x β s \ iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg β dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
obtain β¨N, hNβ© := exists_nat_one_div_lt hΞ΄
[GOAL]
case intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
β’ βαΆ (n : ΞΉ) in atTop, β (x : Ξ±), x β s \ iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg β dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
rw [eventually_atTop]
[GOAL]
case intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
n : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
β’ β a, β (b : ΞΉ), b β₯ a β β (x : Ξ±), x β s \ iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg β dist (g x) (f b x) < Ξ΄
[PROOFSTEP]
refine' β¨Egorov.notConvergentSeqLTIndex (half_pos hΞ΅) hf hg hsm hs hfg N, fun n hn x hx => _β©
[GOAL]
case intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
n : ΞΉ
hn : n β₯ notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N
x : Ξ±
hx : x β s \ iUnionNotConvergentSeq hΞ΅ hf hg hsm hs hfg
β’ dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
simp only [Set.mem_diff, Egorov.iUnionNotConvergentSeq, not_exists, Set.mem_iUnion, Set.mem_inter_iff, not_and,
exists_and_left] at hx
[GOAL]
case intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
n : ΞΉ
hn : n β₯ notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N
x : Ξ±
hx :
x β s β§
(x β s β
β (x_1 : β),
Β¬x β notConvergentSeq (fun n => f n) g x_1 (notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg x_1))
β’ dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
obtain β¨hxs, hxβ© := hx
[GOAL]
case intro.intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
n : ΞΉ
hn : n β₯ notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N
x : Ξ±
hxs : x β s
hx :
x β s β
β (x_1 : β),
Β¬x β notConvergentSeq (fun n => f n) g x_1 (notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg x_1)
β’ dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
specialize hx hxs N
[GOAL]
case intro.intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
n : ΞΉ
hn : n β₯ notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N
x : Ξ±
hxs : x β s
hx : Β¬x β notConvergentSeq (fun n => f n) g N (notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N)
β’ dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
rw [Egorov.mem_notConvergentSeq_iff] at hx
[GOAL]
case intro.intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
n : ΞΉ
hn : n β₯ notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N
x : Ξ±
hxs : x β s
hx : Β¬β k x_1, 1 / (βN + 1) < dist (f k x) (g x)
β’ dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
push_neg at hx
[GOAL]
case intro.intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
n : ΞΉ
hn : n β₯ notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N
x : Ξ±
hxs : x β s
hx : β (k : ΞΉ), notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N β€ k β dist (f k x) (g x) β€ 1 / (βN + 1)
β’ dist (g x) (f n x) < Ξ΄
[PROOFSTEP]
rw [dist_comm]
[GOAL]
case intro.intro
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instβΒ³ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
nβ : β
i j : ΞΉ
s : Set Ξ±
Ξ΅ : β
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
instβΒ² : SemilatticeSup ΞΉ
instβΒΉ : Nonempty ΞΉ
instβ : Countable ΞΉ
hΞ΅ : 0 < Ξ΅
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hsm : MeasurableSet s
hs : ββΞΌ s β β€
hfg : βα΅ (x : Ξ±) βΞΌ, x β s β Tendsto (fun n => f n x) atTop (π (g x))
Ξ΄ : β
hΞ΄ : Ξ΄ > 0
N : β
hN : 1 / (βN + 1) < Ξ΄
n : ΞΉ
hn : n β₯ notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N
x : Ξ±
hxs : x β s
hx : β (k : ΞΉ), notConvergentSeqLTIndex (_ : 0 < Ξ΅ / 2) hf hg hsm hs hfg N β€ k β dist (f k x) (g x) β€ 1 / (βN + 1)
β’ dist (f n x) (g x) < Ξ΄
[PROOFSTEP]
exact lt_of_le_of_lt (hx n hn) hN
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instββ΅ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
instββ΄ : SemilatticeSup ΞΉ
instβΒ³ : Nonempty ΞΉ
instβΒ² : Countable ΞΉ
Ξ³ : Type u_4
instβΒΉ : TopologicalSpace Ξ³
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
s : Set Ξ±
instβ : IsFiniteMeasure ΞΌ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hfg : βα΅ (x : Ξ±) βΞΌ, Tendsto (fun n => f n x) atTop (π (g x))
Ξ΅ : β
hΞ΅ : 0 < Ξ΅
β’ β t, MeasurableSet t β§ ββΞΌ t β€ ENNReal.ofReal Ξ΅ β§ TendstoUniformlyOn f g atTop tαΆ
[PROOFSTEP]
have β¨t, _, ht, htendstoβ© :=
tendstoUniformlyOn_of_ae_tendsto hf hg MeasurableSet.univ (measure_ne_top ΞΌ Set.univ)
(by filter_upwards [hfg] with _ htendsto _ using htendsto) hΞ΅
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instββ΅ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
instββ΄ : SemilatticeSup ΞΉ
instβΒ³ : Nonempty ΞΉ
instβΒ² : Countable ΞΉ
Ξ³ : Type u_4
instβΒΉ : TopologicalSpace Ξ³
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
s : Set Ξ±
instβ : IsFiniteMeasure ΞΌ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hfg : βα΅ (x : Ξ±) βΞΌ, Tendsto (fun n => f n x) atTop (π (g x))
Ξ΅ : β
hΞ΅ : 0 < Ξ΅
β’ βα΅ (x : Ξ±) βΞΌ, x β univ β Tendsto (fun n => f n x) atTop (π (g x))
[PROOFSTEP]
filter_upwards [hfg] with _ htendsto _ using htendsto
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instββ΅ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
instββ΄ : SemilatticeSup ΞΉ
instβΒ³ : Nonempty ΞΉ
instβΒ² : Countable ΞΉ
Ξ³ : Type u_4
instβΒΉ : TopologicalSpace Ξ³
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
s : Set Ξ±
instβ : IsFiniteMeasure ΞΌ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hfg : βα΅ (x : Ξ±) βΞΌ, Tendsto (fun n => f n x) atTop (π (g x))
Ξ΅ : β
hΞ΅ : 0 < Ξ΅
t : Set Ξ±
wβ : t β univ
ht : MeasurableSet t
htendsto : ββΞΌ t β€ ENNReal.ofReal Ξ΅ β§ TendstoUniformlyOn (fun n => f n) g atTop (univ \ t)
β’ β t, MeasurableSet t β§ ββΞΌ t β€ ENNReal.ofReal Ξ΅ β§ TendstoUniformlyOn f g atTop tαΆ
[PROOFSTEP]
refine' β¨_, ht, _β©
[GOAL]
Ξ± : Type u_1
Ξ² : Type u_2
ΞΉ : Type u_3
m : MeasurableSpace Ξ±
instββ΅ : MetricSpace Ξ²
ΞΌ : Measure Ξ±
instββ΄ : SemilatticeSup ΞΉ
instβΒ³ : Nonempty ΞΉ
instβΒ² : Countable ΞΉ
Ξ³ : Type u_4
instβΒΉ : TopologicalSpace Ξ³
f : ΞΉ β Ξ± β Ξ²
g : Ξ± β Ξ²
s : Set Ξ±
instβ : IsFiniteMeasure ΞΌ
hf : β (n : ΞΉ), StronglyMeasurable (f n)
hg : StronglyMeasurable g
hfg : βα΅ (x : Ξ±) βΞΌ, Tendsto (fun n => f n x) atTop (π (g x))
Ξ΅ : β
hΞ΅ : 0 < Ξ΅
t : Set Ξ±
wβ : t β univ
ht : MeasurableSet t
htendsto : ββΞΌ t β€ ENNReal.ofReal Ξ΅ β§ TendstoUniformlyOn (fun n => f n) g atTop (univ \ t)
β’ ββΞΌ t β€ ENNReal.ofReal Ξ΅ β§ TendstoUniformlyOn f g atTop tαΆ
[PROOFSTEP]
rwa [Set.compl_eq_univ_diff]
|
C LAST UPDATE 21/02/94
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
SUBROUTINE STOREC
IMPLICIT NONE
C
C Purpose: Converts coordinates from standard to reciprocal space
C
C Calls 0:
C Called by: CTILT
C
C-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
C FIX include file:
C
INCLUDE 'FIXPAR.COM'
C
C Local variables:
C
INTEGER I
REAL CMU,CHI,TEMP,R,Z,D
C
C-----------------------------------------------------------------------
DO 10 I=1,NPTS
CMU = COS(ATAN2(SXY(1,I),SDD))
CHI = ATAN2(SXY(2,I),SQRT(SXY(1,I)**2+SDD**2))
TEMP = 1.0 - CMU*COS(CHI)
IF(TEMP.LT.0.0)TEMP = 0.0
D = SQRT(2.0*TEMP)/WAVE
Z = (SIN(TILT)*TEMP+COS(TILT)*SIN(CHI))/WAVE
R = D*D - Z*Z
IF(R.LT.0.0)R = 0.0
R = SQRT(R)
R = SIGN(R,SXY(1,I))
RZ(1,I) = R
RZ(2,I) = Z
10 CONTINUE
RETURN
C
END
|
(** Common definitions *)
From Coq Require Import Ensembles.
From RelationAlgebra Require Import prop monoid kat relalg kat_tac.
From Catincoq.lib Require Import proprel.
Definition partial_order {A} (R : relation A) := 1 β¦ R /\ R β
R β¦ R /\ R β RΒ° β¦ 1.
Definition strict_order {A} (R : relation A) := R β
R β¦ R /\ R β 1 β¦ 0.
Definition is_strict_order {A} (R : relation A) :=
relalg.is_irreflexive R /\
is_transitive R.
Lemma is_strict_order_spec {A} (R : relation A) : is_strict_order R <-> strict_order R.
Proof.
compute. firstorder.
Qed.
Definition is_irreflexive {X} (R : relation X) := R β 1 β¦ 0.
Definition irreflexive {A} (R : relation A) := cap R 1 β¦ bot.
Lemma is_irreflexive_spec1 {X} (R : relation X) : irreflexive R <-> is_irreflexive R.
Proof.
reflexivity.
Qed.
Lemma is_irreflexive_spec2 {X} (R : relation X) : relalg.is_irreflexive R <-> is_irreflexive R.
Proof.
compute. firstorder (subst; firstorder).
Qed.
Lemma is_irreflexive_spec3 {X} (R : relation X) : RelationClasses.Irreflexive R <-> is_irreflexive R.
Proof.
compute. firstorder (subst; firstorder).
Qed.
Definition acyclic {A} (R : relation A) := leq (cap (itr _ R) 1) bot.
Definition is_acyclic {X} (R : relation X) := R^+ β 1 β¦ 0.
Lemma is_acyclic_spec {X} (R : relation X) : acyclic R <-> is_acyclic R.
Proof.
split; intros A x y; specialize (A x y); rewrite A; compute; tauto.
Qed.
Definition total {A} (R : relation A) := !1 β¦ R β RΒ°.
(** TODO merge those two *)
Definition total_on {A} (E : set A) (R : relation A) := [E] β
!1 β
[E] β¦ R β RΒ°.
Definition linear_extension_on {A} (E : set A) (R : relation A) : set (relation A) :=
fun S => strict_order S /\ S β¦ [E] β
top β
[E] /\ total_on E S /\ [E] β
R β
[E] β¦ S.
Definition finite_set {A} (E : set A) :=
exists (l : list A), forall a, E a -> List.In a l.
Definition relational_image {A B} (R : A -> B -> Prop) : Ensemble A -> Ensemble B :=
fun x b => exists a, x a /\ R a b.
Definition functional_relation_domain {A B} (dom : Ensemble A) (R : A -> B -> Prop) :=
(forall a, dom a <-> exists b, R a b) /\
(forall a b b', R a b -> R a b' -> b = b').
Definition one_of_each {X} : Ensemble (Ensemble X) -> Ensemble (Ensemble X) :=
fun A b => exists f : Ensemble X -> X -> Prop,
(forall e fe, f e fe -> e fe) /\
functional_relation_domain A f /\
Same_set _ b (relational_image f A).
Definition subset_image {A B} (f : A -> B) (X : Ensemble A) : Ensemble B
:= fun y => exists x, X x /\ y = f x.
Definition union_of_relations {A} : Ensemble (relation A) -> relation A :=
fun Rs x y => exists R, Rs R /\ R x y.
Definition equivalence_classes {A} (R : relation A) : Ensemble (Ensemble A) :=
fun C => exists x, C x /\ forall y, R x y <-> C y.
|
[STATEMENT]
lemma ls_els_okE:
"\<And>ln. \<lbrakk> ls_els_ok ls t ln els; \<forall>l. lock_expr_locks_ok (ls $ l) t (ln $ l) (els l) \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>ln. \<lbrakk>ls_els_ok ls t ln els; \<forall>l. lock_expr_locks_ok (ls $ l) t (ln $ l) (els l) \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P
[PROOF STEP]
by(auto simp add: ls_els_ok_def)
|
-- The same name can not be exported more than once from a module.
module Issue154 where
module A where
postulate X : Set
module B where
postulate X : Set
open A public
|
| pc = 0xc002 | a = 0xf3 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc004 | a = 0xf3 | x = 0xfe | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc006 | a = 0xf3 | x = 0xfe | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x00ff] = 0xf3 |
| pc = 0xc008 | a = 0xf1 | x = 0xfe | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc00a | a = 0xf1 | x = 0xfe | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0000] = 0xf1 |
| pc = 0xc00c | a = 0xf2 | x = 0xfe | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc00e | a = 0xf2 | x = 0x02 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 |
| pc = 0xc010 | a = 0xf2 | x = 0x02 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0001] = 0xf2 |
| pc = 0xc012 | a = 0xf1 | x = 0x02 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0000] = 0xf1 |
| pc = 0xc014 | a = 0xf2 | x = 0x02 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0001] = 0xf2 |
| pc = 0xc016 | a = 0xf3 | x = 0x02 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x00ff] = 0xf3 |
| pc = 0xc018 | a = 0xf3 | x = 0xe3 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc01a | a = 0xf3 | x = 0xe3 | y = 0xfe | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc01c | a = 0xf3 | x = 0xe3 | y = 0xfe | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x00ff] = 0xe3 |
| pc = 0xc01e | a = 0xf3 | x = 0xe1 | y = 0xfe | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc020 | a = 0xf3 | x = 0xe1 | y = 0xfe | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0000] = 0xe1 |
| pc = 0xc022 | a = 0xf3 | x = 0xe2 | y = 0xfe | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc024 | a = 0xf3 | x = 0xe2 | y = 0x02 | sp = 0x01fd | p[NV-BDIZC] = 00110100 |
| pc = 0xc026 | a = 0xf3 | x = 0xe2 | y = 0x02 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0001] = 0xe2 |
| pc = 0xc028 | a = 0xe1 | x = 0xe2 | y = 0x02 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0000] = 0xe1 |
| pc = 0xc02a | a = 0xe2 | x = 0xe2 | y = 0x02 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0001] = 0xe2 |
| pc = 0xc02c | a = 0xe3 | x = 0xe2 | y = 0x02 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x00ff] = 0xe3 |
| pc = 0xc02e | a = 0xe3 | x = 0xe2 | y = 0xc3 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc030 | a = 0xe3 | x = 0xfe | y = 0xc3 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc032 | a = 0xe3 | x = 0xfe | y = 0xc3 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x00ff] = 0xc3 |
| pc = 0xc034 | a = 0xe3 | x = 0xfe | y = 0xc1 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc036 | a = 0xe3 | x = 0xfe | y = 0xc1 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0000] = 0xc1 |
| pc = 0xc038 | a = 0xe3 | x = 0xfe | y = 0xc2 | sp = 0x01fd | p[NV-BDIZC] = 10110100 |
| pc = 0xc03a | a = 0xe3 | x = 0x02 | y = 0xc2 | sp = 0x01fd | p[NV-BDIZC] = 00110100 |
| pc = 0xc03c | a = 0xe3 | x = 0x02 | y = 0xc2 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0001] = 0xc2 |
| pc = 0xc03e | a = 0xc1 | x = 0x02 | y = 0xc2 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0000] = 0xc1 |
| pc = 0xc040 | a = 0xc2 | x = 0x02 | y = 0xc2 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0001] = 0xc2 |
| pc = 0xc042 | a = 0xc3 | x = 0x02 | y = 0xc2 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x00ff] = 0xc3 |
|
Rescue efforts began in the immediate aftermath of the earthquake , with able @-@ bodied survivors extricating the living and the dead from the rubble of the many buildings that had collapsed . Treatment of the injured was hampered by the lack of hospital and morgue facilities : the Argentine military field hospital , which had been serving MINUSTAH , was the only one available until 13 January . Rescue work intensified only slightly with the arrival of doctors , police officers , military personnel and firefighters from various countries two days after the earthquake .
|
Abstract: Atmospheric water vapour is an important (natural) greenhouse gas, infuencing both directly and indirectly the global radiative balance of the Earth as well as heat and moisture fluxes at the surface. Since water vapour concentrations may change as a result of surface warming and other environmental/meteorological factors, there is a need to understand the long-term behaviour. Changes are small, so it is critical to use high quality data with well-defined uncertainties and biases, particularly for climate research. Hyper-spectral infrared (IR) sounders such as the Infrared Atmospheric Sounding Interferometer (IASI) and the Atmospheric Infrared Sounder (AIRS) allow for higher vertical resolution profile measurements of water vapour to be obtained compared to their predecessors. First results of global comparisons of AIRS profiles show that for tropospheric layers between 925-374 hPa biases are within +-10% and a significant dry bias of 20% in regions of the upper troposphere, consistent with recent comparisons to reanalysis. A consistent approach to the retrieval of temperature and water vapour profiles from all hyper-spectral IR sounders is outlined and an initial set of retrievals from IASI at global climate sites is performed. Results from the University of Leicester Water Vapour Processor (UoL-WVP) show errors of β1 K and Atmospheric water vapour is an important (natural) greenhouse gas, infuencing both directly and indirectly the global radiative balance of the Earth as well as heat and moisture fluxes at the surface. Since water vapour concentrations may change as a result of surface warming and other environmental/meteorological factors, there is a need to understand the long-term behaviour. Changes are small, so it is critical to use high quality data with well-defined uncertainties and biases, particularly for climate research. Hyper-spectral infrared (IR) sounders such as the Infrared Atmospheric Sounding Interferometer (IASI) and the Atmospheric Infrared Sounder (AIRS) allow for higher vertical resolution profile measurements of water vapour to be obtained compared to their predecessors. First results of global comparisons of AIRS profiles show that for tropospheric layers between 925-374 hPa biases are within +-10% and a significant dry bias of 20% in regions of the upper troposphere, consistent with recent comparisons to reanalysis. A consistent approach to the retrieval of temperature and water vapour profiles from all hyper-spectral IR sounders is outlined and an initial set of retrievals from IASI at global climate sites is performed. Results from the University of Leicester Water Vapour Processor (UoL-WVP) show errors of β1 K and β€20% within the troposphere for temperature and humidity respectfully. The significance of surface characterisation at a sub-pixel level is also demonstrated. Retrievals from IASI at selected climate sites for 2012 are inter-compared in a three-way analysis with high resolution radiosonde profiles and AIRS data. Results show that the mean standard deviation of observational error for IASI is 2.2% while AIRS is 3.6%. This thesis work represents a step forward in the use of AIRS and IASI data for climate research. However, proven long-term stability is needed for the water vapour data question to be answered. and humidity respectfully. The significance of surface characterisation at a sub-pixel level is also demonstrated. Retrievals from IASI at selected climate sites for 2012 are inter-compared in a three-way analysis with high resolution radiosonde profiles and AIRS data. Results show that the mean standard deviation of observational error for IASI is 2.2% while AIRS is 3.6%. This thesis work represents a step forward in the use of AIRS and IASI data for climate research. However, proven long-term stability is needed for the water vapour data question to be answered.
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Basic
namespace Lean.Meta
structure AuxLemmas where
idx : Nat := 1
lemmas : PHashMap Expr (Name Γ List Name) := {}
deriving Inhabited
builtin_initialize auxLemmasExt : EnvExtension AuxLemmas β registerEnvExtension (pure {})
/--
Helper method for creating auxiliary lemmas in the environment.
It uses a cache that maps `type` to declaration name. The cache is not stored in `.olean` files.
It is useful to make sure the same auxiliary lemma is not created over and over again in the same file.
This method is useful for tactics (e.g., `simp`) that may perform preprocessing steps to lemmas provided by
users. For example, `simp` preprocessor may convert a lemma into multiple ones.
-/
def mkAuxLemma (levelParams : List Name) (type : Expr) (value : Expr) : MetaM Name := do
let env β getEnv
let s := auxLemmasExt.getState env
let mkNewAuxLemma := do
let auxName := Name.mkNum (env.mainModule ++ `_auxLemma) s.idx
addDecl <| Declaration.thmDecl {
name := auxName
levelParams, type, value
}
modifyEnv fun env => auxLemmasExt.modifyState env fun β¨idx, lemmasβ© => β¨idx + 1, lemmas.insert type (auxName, levelParams)β©
return auxName
match s.lemmas.find? type with
| some (name, levelParams') => if levelParams == levelParams' then return name else mkNewAuxLemma
| none => mkNewAuxLemma
end Lean.Meta
|
#' R tools to manipulate ilo datasets code / label
#'
#' init ilo packages by loading codelist and cluster for parallel computation
#'
#' @param ... Specification for extenal update.
#' @section Specification:
#' others functions allow advanced manipulation.
#' \itemize{
#' \item \code{update}: update database for external users,
#' }
#' To learn more about ilo, start with the online vignettes:
#' \code{help_ilo()}
#'
#' @name init_ilo
#' @importFrom plyr llply mapvalues
#' @importFrom foreach foreach "%dopar%"
#' @importFrom doSNOW registerDoSNOW
#' @importFrom rappdirs user_data_dir
#' @importFrom openxlsx createWorkbook addWorksheet writeData saveWorkbook
#' @import dplyr
#' @importFrom tidyr expand unite
#' @importFrom stringr str_replace_all str_detect str_split_fixed fixed str_c str_split str_replace
#'
#'
#' @return ilo an R environment that contains cluster and codelist
#'
#' @examples
#' init_ilo()
#'
#' ilo
#' ilo %>% names
#' ilo$lastupdate
#' ilo$code %>% names
#' ilo$code$cl_country
#' @export
init_ilo <- function(...){
path_ilo <- ilo:::path_for_ilo()
TEST <- TRUE
cl_ilo = TRUE
init_time <- Sys.time()
update = FALSE
lang = 'en'
set <- list()
.dots = lazyeval::lazy_dots(...)
set$para <- .dots[!names(.dots)%in%'']
set$COL <- FALSE
set$FRQ <- FALSE
if(length(set$para)>0){
for (i in 1:length(names(set$para))){
if(tolower(names(set$para[i])) %in% 'collection'){set$COL <- TRUE}
if(tolower(names(set$para[i])) %in% 'freq'){set$FRQ <- TRUE}
eval(expression(assign(tolower(names(set$para[i])), eval( set$para[[i]]$expr, envir = set$para[[i]]$env))))
}
}
set$para <- .dots[names(.dots)%in%'']
set$UPDATE <- FALSE
if(length(set$para) > 0){
for (i in 1:length(set$para)){
test <- set$para[[i]]$expr %>% as.character %>% paste0(.,collapse = '')
if(tolower(test) %in% 'update'){
set$UPDATE <- TRUE
}
if(test %in% '-cl'){cl_ilo <- NULL}
}
}
test1 <- try( lazyLoad(paste0(path_ilo,'\\settings\\set'), refset <- new.env()), silent = T)
test2 <- try( lazyLoad(paste0(path_ilo,'\\settings\\cl'), refcl <- new.env()), silent = T)
if(!is.null(cl_ilo)){ # cluster registration
cl_ilo <- parallel::makeCluster(max(1, parallel::detectCores() - 1))
doSNOW::registerDoSNOW(cl_ilo)
}
# test2 <- try( lazyLoad(paste0(path_ilo,'\\settings\\cl'), refcl <- new.env()), silent = T)
e <- new.env()
assign('path', path_ilo, envir = e)
assign('cl', cl_ilo, envir = e)
assign('lang', lang, envir = e)
assign('code', refcl, envir = e)
Seg <- refset$segment %>%
{if(set$COL) rename(., col_ = collection) %>% filter(col_ %in% collection) %>% rename(collection = col_)else .} %>%
{if(set$FRQ) rename(., fre_ = freq) %>% filter(fre_ %in% freq) %>% rename(freq = fre_) else .}
assign('segment', Seg, envir = e); rm(Seg)
assign('lastupdate', refset$lastupdate, envir = e); rm(refset)
ilo <<- e
invisible(gc(reset = T))
final_time <- Sys.time()
return(paste0('Files ready, clusters created. Database available. ', round(final_time - init_time ,2)))
}
|
(* Author: Tobias Nipkow *)
section "AVL Tree with Balance Factors (1)"
theory AVL_Bal_Set
imports
Cmp
Isin2
begin
text \<open>This version detects height increase/decrease from above via the change in balance factors.\<close>
datatype bal = Lh | Bal | Rh
type_synonym 'a tree_bal = "('a * bal) tree"
text \<open>Invariant:\<close>
fun avl :: "'a tree_bal \<Rightarrow> bool" where
"avl Leaf = True" |
"avl (Node l (a,b) r) =
((case b of
Bal \<Rightarrow> height r = height l |
Lh \<Rightarrow> height l = height r + 1 |
Rh \<Rightarrow> height r = height l + 1)
\<and> avl l \<and> avl r)"
subsection \<open>Code\<close>
fun is_bal where
"is_bal (Node l (a,b) r) = (b = Bal)"
fun incr where
"incr t t' = (t = Leaf \<or> is_bal t \<and> \<not> is_bal t')"
fun rot2 where
"rot2 A a B c C = (case B of
(Node B\<^sub>1 (b, bb) B\<^sub>2) \<Rightarrow>
let b\<^sub>1 = if bb = Rh then Lh else Bal;
b\<^sub>2 = if bb = Lh then Rh else Bal
in Node (Node A (a,b\<^sub>1) B\<^sub>1) (b,Bal) (Node B\<^sub>2 (c,b\<^sub>2) C))"
fun balL :: "'a tree_bal \<Rightarrow> 'a \<Rightarrow> bal \<Rightarrow> 'a tree_bal \<Rightarrow> 'a tree_bal" where
"balL AB c bc C = (case bc of
Bal \<Rightarrow> Node AB (c,Lh) C |
Rh \<Rightarrow> Node AB (c,Bal) C |
Lh \<Rightarrow> (case AB of
Node A (a,Lh) B \<Rightarrow> Node A (a,Bal) (Node B (c,Bal) C) |
Node A (a,Bal) B \<Rightarrow> Node A (a,Rh) (Node B (c,Lh) C) |
Node A (a,Rh) B \<Rightarrow> rot2 A a B c C))"
fun balR :: "'a tree_bal \<Rightarrow> 'a \<Rightarrow> bal \<Rightarrow> 'a tree_bal \<Rightarrow> 'a tree_bal" where
"balR A a ba BC = (case ba of
Bal \<Rightarrow> Node A (a,Rh) BC |
Lh \<Rightarrow> Node A (a,Bal) BC |
Rh \<Rightarrow> (case BC of
Node B (c,Rh) C \<Rightarrow> Node (Node A (a,Bal) B) (c,Bal) C |
Node B (c,Bal) C \<Rightarrow> Node (Node A (a,Rh) B) (c,Lh) C |
Node B (c,Lh) C \<Rightarrow> rot2 A a B c C))"
fun insert :: "'a::linorder \<Rightarrow> 'a tree_bal \<Rightarrow> 'a tree_bal" where
"insert x Leaf = Node Leaf (x, Bal) Leaf" |
"insert x (Node l (a, b) r) = (case cmp x a of
EQ \<Rightarrow> Node l (a, b) r |
LT \<Rightarrow> let l' = insert x l in if incr l l' then balL l' a b r else Node l' (a,b) r |
GT \<Rightarrow> let r' = insert x r in if incr r r' then balR l a b r' else Node l (a,b) r')"
fun decr where
"decr t t' = (t \<noteq> Leaf \<and> (t' = Leaf \<or> \<not> is_bal t \<and> is_bal t'))"
fun split_max :: "'a tree_bal \<Rightarrow> 'a tree_bal * 'a" where
"split_max (Node l (a, ba) r) =
(if r = Leaf then (l,a)
else let (r',a') = split_max r;
t' = if decr r r' then balL l a ba r' else Node l (a,ba) r'
in (t', a'))"
fun delete :: "'a::linorder \<Rightarrow> 'a tree_bal \<Rightarrow> 'a tree_bal" where
"delete _ Leaf = Leaf" |
"delete x (Node l (a, ba) r) =
(case cmp x a of
EQ \<Rightarrow> if l = Leaf then r
else let (l', a') = split_max l in
if decr l l' then balR l' a' ba r else Node l' (a',ba) r |
LT \<Rightarrow> let l' = delete x l in if decr l l' then balR l' a ba r else Node l' (a,ba) r |
GT \<Rightarrow> let r' = delete x r in if decr r r' then balL l a ba r' else Node l (a,ba) r')"
subsection \<open>Proofs\<close>
lemmas split_max_induct = split_max.induct[case_names Node Leaf]
lemmas splits = if_splits tree.splits bal.splits
declare Let_def [simp]
subsubsection "Proofs about insertion"
lemma avl_insert: "avl t \<Longrightarrow>
avl(insert x t) \<and>
height(insert x t) = height t + (if incr t (insert x t) then 1 else 0)"
apply(induction x t rule: insert.induct)
apply(auto split!: splits)
done
text \<open>The following two auxiliary lemma merely simplify the proof of \<open>inorder_insert\<close>.\<close>
lemma [simp]: "avl t \<Longrightarrow> insert x t \<noteq> \<langle>l, (a, Rh), \<langle>\<rangle>\<rangle> \<and> insert x t \<noteq> \<langle>\<langle>\<rangle>, (a, Lh), r\<rangle>"
by(drule avl_insert[of _ x]) (auto split: splits)
theorem inorder_insert:
"\<lbrakk> avl t; sorted(inorder t) \<rbrakk> \<Longrightarrow> inorder(insert x t) = ins_list x (inorder t)"
apply(induction t)
apply (auto simp: ins_list_simps split!: splits)
done
subsubsection "Proofs about deletion"
lemma inorder_balR:
"\<lbrakk> ba = Rh \<longrightarrow> r \<noteq> Leaf; avl r \<rbrakk>
\<Longrightarrow> inorder (balR l a ba r) = inorder l @ a # inorder r"
by (auto split: splits)
lemma inorder_balL:
"\<lbrakk> ba = Lh \<longrightarrow> l \<noteq> Leaf; avl l \<rbrakk>
\<Longrightarrow> inorder (balL l a ba r) = inorder l @ a # inorder r"
by (auto split: splits)
lemma height_1_iff: "avl t \<Longrightarrow> height t = Suc 0 \<longleftrightarrow> (\<exists>x. t = Node Leaf (x,Bal) Leaf)"
by(cases t) (auto split: splits prod.splits)
lemma avl_split_max:
"\<lbrakk> split_max t = (t',a); avl t; t \<noteq> Leaf \<rbrakk> \<Longrightarrow>
avl t' \<and> height t = height t' + (if decr t t' then 1 else 0)"
apply(induction t arbitrary: t' a rule: split_max_induct)
apply(auto simp: max_absorb1 max_absorb2 height_1_iff split!: splits prod.splits)
done
lemma avl_delete: "avl t \<Longrightarrow>
avl (delete x t) \<and>
height t = height (delete x t) + (if decr t (delete x t) then 1 else 0)"
apply(induction x t rule: delete.induct)
apply(auto simp: max_absorb1 max_absorb2 height_1_iff dest: avl_split_max split!: splits prod.splits)
done
lemma inorder_split_maxD:
"\<lbrakk> split_max t = (t',a); t \<noteq> Leaf; avl t \<rbrakk> \<Longrightarrow>
inorder t' @ [a] = inorder t"
apply(induction t arbitrary: t' rule: split_max.induct)
apply(fastforce split!: splits prod.splits)
apply simp
done
lemma neq_Leaf_if_height_neq_0: "height t \<noteq> 0 \<Longrightarrow> t \<noteq> Leaf"
by auto
lemma split_max_Leaf: "\<lbrakk> t \<noteq> Leaf; avl t \<rbrakk> \<Longrightarrow> split_max t = (\<langle>\<rangle>, x) \<longleftrightarrow> t = Node Leaf (x,Bal) Leaf"
by(cases t) (auto split: splits prod.splits)
theorem inorder_delete:
"\<lbrakk> avl t; sorted(inorder t) \<rbrakk> \<Longrightarrow> inorder (delete x t) = del_list x (inorder t)"
apply(induction t rule: tree2_induct)
apply(auto simp: del_list_simps inorder_balR inorder_balL avl_delete inorder_split_maxD
split_max_Leaf neq_Leaf_if_height_neq_0
simp del: balL.simps balR.simps split!: splits prod.splits)
done
subsubsection \<open>Set Implementation\<close>
interpretation S: Set_by_Ordered
where empty = Leaf and isin = isin
and insert = insert
and delete = delete
and inorder = inorder and inv = avl
proof (standard, goal_cases)
case 1 show ?case by (simp)
next
case 2 thus ?case by(simp add: isin_set_inorder)
next
case 3 thus ?case by(simp add: inorder_insert)
next
case 4 thus ?case by(simp add: inorder_delete)
next
case 5 thus ?case by (simp)
next
case 6 thus ?case by (simp add: avl_insert)
next
case 7 thus ?case by (simp add: avl_delete)
qed
end
|
#' craze
#'
#' @description
#' High-level, R-like interface for fmlr. This gives a more
#' traditional, R-like interface around fmlr functions and methods. The
#' package name is a play on the German word 'fimmel'.
#'
#' @import fmlr
#' @import methods
#' @importFrom float is.float
#'
#' @docType package
#' @name craze-package
#' @author Drew Schmidt
#' @keywords package
NULL
|
\chapter{Reconstruction of physics objects}
\label{chapter:ReconstructionOfObjects}
This chapter describes the reconstruction of the main physics objects that are relevant for the analysis presented in this Thesis.
The identification, reconstruction and calibration of electrons, muons, jets and missing transverse energy is discussed in detail.
\section{Electrons}
\label{sec:ElectronReco}
In the following, the electron reconstruction and identification will be described.
The reconstruction step is used to define the electron candidates, while the identification selects electron samples with different purities.
\subsection{Electron reconstruction}
\label{subsec:ElectronReconstruction}
The electron reconstruction can be divided into central and forward.
In the central region, $|\eta|<2.47$, the electron reconstruction starts from energy deposits (clusters) in the electromagnetic calorimeter that are associated to reconstructed tracks of charged particles in the Inner Detector.
The reconstruction of the electron clusters is based on a fixed-size sliding window algorithm \cite{Lampl:2008zz}.
The tracks are extrapolated from their last measurement point in the inner detector to the second layer of the EM calorimeter and the coordinates from the impact point are then compared to those of the seed cluster.
The cluster matching is performed if at least one track is matched to the seed cluster.
In the case where several tracks are matched to the same cluster, tracks with silicon hits are preferred and the one with the smallest $\Delta R$ distance to the seed cluster is chosen.
The four-momentum of the central electrons is computed using the information from both the final cluster and the best track matched to the original seed cluster.
While the energy is given entirely by the cluster energy, the $\eta$ and the $\phi$ directions are taken from the corresponding track parameters at the vertex.
In the forward region, $2.5 < |\eta| < 4.9$, there are no tracking detectors. Therefore, the electron candidates are reconstructed only from energy deposits in the calorimeters. These clusters are built using a topological clustering algorithm, that will be explained in Section~\ref{sec:JetReco}.
\subsection{Electron identification}
\label{subsec:ElectronIdentification}
The electron identification aims to provide good separation between isolated electrons and jets faking electrons.
It consist of a cut-based selection on variables that use calorimeter, tracking and combined calorimeter and tracker information.
Three sets of reference selection criteria have been defined with increasing background rejection power: \textit{loose}, \textit{medium} and \textit{tight}, as described in Ref.~\cite{Aad:2011mk}.
The shower shape variables calculated in the second EM calorimeter layer and hadronic leakage variables are used in the loose selection.
These shower shape variables are binned in $\eta$ and $\met$, allowing a proper handling of correlations between variables and assuring the highest efficiency for a given jet rejection \cite{Aad:2014fxa}.
Cuts on the first EM calorimeter layer variables, track quality requirements and track-cluster matching are added in the medium selection.
Finally, in the tight selection, the track quality requirements are tightened.
For the analysis presented in this Thesis, only electrons following the \textit{medium} identification criteria are considered.
\subsection{Electron energy corrections}
\label{subsec:ElectronEnergyCorrections}
The reconstructed electron energy in data is tuned to reproduce the $Z$ mass peak central value according to the $Z$ mass world average by applying extra corrections as a function of $|\eta|$ \cite{Aad:2011mk}:
\begin{equation}
E_{\text{corrected}} = \frac{E}{1+\alpha},
\label{eq:ElectronEnergyCalibration}
\end{equation}
\noindent where $\alpha$ measures the residual miscalibration. The values of $\alpha$ are within $\pm 2 \%$ in the barrel region and within $\pm 5 \%$ in the forward regions.
The calibrated electron energy scale is further validated with electron candidates from $J/\psi\rightarrow ee$ events in data, and determined with a precision of 0.3--1.6\% in the central region over $|\eta|<2.47$, for different $|\eta|$ values \cite{Aad:2014nim}.
\section{Muons}
\label{sec:MuonReco}
This section presents the muon reconstruction and identification in ATLAS, which mainly relies on the information extracted from the Inner Detector and the Muon spectrometer.
\subsection{Track reconstruction}
\label{subsec:MuonTrackReconstruction}
The tracks of the muon candidates are reconstructed independently in the ID and the MS.
Hits in each station of the Muon Spectrometer are combined to build track segments up to $|\eta|<2.7$.
A similar approach is followed in the inner detector, where the pattern recognition uses space points from the pixel and SCT clusters to generate seeds, which are then extended into the TRT.
\subsection{Muon identification}
\label{subsec:MuonIdentification}
In ATLAS, the muon identification is performed according to several reconstruction criteria, which leads to different muon ``types''.
These types are defined based on the available information from the ID, the MS and different calorimeter sub-detector systems~\cite{Aad:2014rra}:
\begin{itemize}
\item{Stand-alone (SA):} The muon trajectory is only reconstructed in the muon spectrometer. The direction of flight and the impact parameter of the muon at the interaction point are determined by extrapolating the spectrometer track back to the beam line.
\item{Combined muon (CB):} The momentum of the stand-alone muon is combined with the momentum measured in the ID, which also provides information about the impact parameter of the muon trajectory with respect to the primary vertex.
\item{Segment tagged (ST):} A trajectory in the inner detector is identified as a muon if the trajectory extrapolated to the muon spectrometer can be associated with straight track segments in the precision muon chambers.
\item{Calorimeter tagged (CaloTag):} A trajectory in the ID is identified as a muon if the associated energy depositions in the calorimeters is compatible with the hypothesis of a minimum ionizing particle.
\end{itemize}
The analysis described in this Thesis uses combined muons and segment tagged muons, reconstructed with the \textit{staco} reconstruction chain, as described in Ref.~\cite{Hassani:2007cy}.
Combined muons are the highest purity muon candidates.
Tagged muons give additional efficiency, as they can recover muons which did not cross enough precision chambers to allow an independent momentum measurement in the Muon Spectrometer.
The reconstructed muon momentum in data is tuned to reproduce the $Z$ and $J/\Psi$ masses as it was done for electrons, and needs to be studied separately in the ID and the MS.
The dimuon invariant mass resolution of combined muons is found to vary between 2 and 3 GeV, as a function of $|\eta|$.
\section{Jets}
\label{sec:JetReco}
In hard interactions, quarks and gluons result in showers of collimated particles, called \textit{jets}.
A well-defined jet algorithm is needed in order to establish a correspondence between observables at partonic, hadronic and detector level.
Jets are reconstructed using the $\akt$ algorithm, described in the following.
\subsection{Jet finding algorithm}
\label{subsec:JetClusteringAlgorithm}
The $\akt$~\cite{Cacciari:2008gp} is a sequential recombination algorithm, and is the default jet finding algorithm in the LHC experiments.
It starts from an input list of four-vectors, which can be either particles from the $\pp$ interactions simulated in the MC with a lifetime longer than 10~ps (\emph{truth constituents}), reconstructed charged particle tracks associated with the reconstructed primary collision vertex (\emph{track constituents}), or energy depositions in the ATLAS calorimeters (\emph{calorimeter constituents}).
The jet reconstruction in ATLAS is summarized in Figure~\ref{fig:JetReconstructionOverview}.
\begin{figure}[!ht]
\begin{center}
\mbox{
\includegraphics[width=0.995\textwidth]{ObjectReconstruction/Figures/JetReconstructionOverview.eps}
}
\end{center}
\caption[Overview of the ATLAS jet reconstruction.]{Overview of the ATLAS jet reconstruction~\cite{Aad:2014bia}.}
\label{fig:JetReconstructionOverview}
\end{figure}
For all the input constituents, the $\akt$ algorithm computes the quantities:
\begin{subequations}
\begin{equation}
d_{ij} = \min\left( \frac{1}{k_{ti}^{2}}, \frac{1}{k_{tj}^{2}} \right) \frac{\Delta R_{ij}^{2}}{R^2}
\label{eq:AntiKt_dij}
\end{equation}
\begin{equation}
d_{iB} = \frac{1}{k_{ti}^{2}},
\label{eq:AntiKt_diB}
\end{equation}
\end{subequations}
\noindent where $\Delta R_{ij}^{2} = (\eta_i - \eta_j)^2 + (\phi_i - \phi_j)^2$, $R$ is a parameter of the algorithm that approximately controls the size of the jet and $k_{ti}$ is the transverse momentum of the constituent $i$.
Here, $d_{ij}$ is the ``distance'' between the constituents $i$ and $j$, while $d_{iB}$ is the distance between the constituent $i$ and the beam, introduced to separate constituents coming from the interactions from proton remnants.
The $\akt$ jet clustering algorithm proceeds by identifying the smallest of the distances.
If the smallest distance is a $d_{ij}$, it recombines the entities $i$ and $j$, while if the smallest distance is $d_{iB}$, the algorithm calls $i$ a jet and removes it from the list of entities.
The method used to recombine the different constituents is called \emph{recombination scheme}.
In ATLAS, the $E$-scheme is used, in which the four-momentum of the recombined object is defined by the vectorial sum of the four-momenta of its constituents.
After recombination, the distances are recalculated with the remaining objects, and the procedure repeated until no entities are left.
The $\akt$ algorithm defines jets with a well-defined conical shape, thus allowing robust pileup corrections.
Jets are defined with a minimum transverse momentum threshold $p_T^{\text{jet}}$, used as a scale to separate soft from hard interactions.
Figure \ref{fig:JetTopoClusterAntiKt} (left) illustrates the clustering of hard and soft particles into jets when the $\akt$ algorithm is applied.
\begin{figure}[!ht]
\begin{center}
\mbox{
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetAntiKt.eps}
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetClusterFormation.eps}
}
\end{center}
\caption[Illustration of the ``active'' catchment area of the $\akt$ algorithm (left). Topo-cluster formation in the three hadronic layers in the barrel and $\akt$ jet algorithm representation (right).]{
Illustration of the clustering of the jets with the $\akt$ algorithm~\protect\cite{Cacciari:2008gp} (left).
Grid representing calorimeter cells, showing topo-cluster formation in the three hadronic layers in the barrel (right).
}
\label{fig:JetTopoClusterAntiKt}
\end{figure}
\subsection{Cluster formation}
\label{subsec:JetClusterFormation}
The calorimeter constituents mentioned in the previous section are reconstructed with the topological clustering (topo-cluster) algorithm \cite{Lampl:2008zz}.
This algorithm, reconstructs 3-dimensional clusters, and is designed to follow the shower development of a single particle interacting with the calorimeter, taking advantage of the calorimeters fine granularity.
Figure \ref{fig:JetTopoClusterAntiKt} (right) shows a schema of a topological cluster formation.
Seed cells are built by selecting cells with a significant signal to noise ratio of $|S/N|\geq 4$.
The noise is defined as the expected RMS of the electronics noise for the current gain and conditions plus the contribution of pileup added in quadrature.
Neighboring cells in the 3 dimensions are then added to the cluster if their signal to noise ratio is $|S/N|\geq 2$.
Finally, cells with $|S/N|\geq 0$ in the perimeter are added to the cluster, to ensure that the tails of showers are not discarded, while the higher thresholds for seeds and neighbors effectively suppress both electronics and pile-up noise.
In case of particles leading to overlapping showers they can still be separated if they form local maxima in the calorimeter.
Topo-clusters are defined to be massless and represent three dimensional energy blobs in the calorimeter.
\subsection{Jet calibration}
\label{subsec:JetCalibration}
Topo-clusters are initially reconstructed at the EM scale, which correctly measures the energy in the calorimeter deposited by particles produced in an electromagnetic shower.
These clusters then need to be recalibrated to correctly measure the energy deposited by particles produced in an hadronic shower.
This is done with the local cell signal weighting (LCW).
LCW first classifies topo-clusters as either electromagnetic or hadronic based on the measured energy density and the longitudinal shower depth.
Then, energy corrections are derived according to this classification from single charged and neutral pion MC simulations.
Further dedicated corrections address effects of calorimeter non-compensation, signal losses due to noise threshold effects and energy loss in non instrumented regions of the detector close to the cluster.
Figure~\ref{fig:JetCalibrationFlow} shows an overview of the ATLAS calibration scheme for calorimeter jets, which restores the jet energy scale to that corresponding to particle-level jets before detector effects.
It consists of four steps, briefly discussed below:
\begin{figure}[!ht]
\begin{center}
\mbox{
\includegraphics[width=0.995\textwidth]{ObjectReconstruction/Figures/JetCalibrationFlow.eps}
}
\end{center}
\caption{Overview of the ATLAS jet calibration~\cite{Aad:2014bia}.}
\label{fig:JetCalibrationFlow}
\end{figure}
\begin{enumerate}
\item{\textbf{Pileup correction:}} The jets formed from topoclusters at the EM or LCW scale are first corrected to account for the energy offset due to pileup. This procedure is explained in detail in Section \ref{subsubsec:JetPileupCorrections}.
\item{\textbf{Origin correction:}} A correction to the calorimeter jet direction is applied to make that the jet points back to the primary event vertex instead of the center of the nominal ATLAS detector.
Thereafter, the kinematic observables of each topo-cluster are recalculated.
This correction improves the angular resolution and results in a small improvement in the jet $\pt$ response.
The energy of the jet remains unchanged.
\item{\textbf{Jet calibration based on MC simulation:}} The jet energy calibration is derived from simulation, by relating the reconstructed jet energy to the particle-level jet energy.
The jet energy calibration is discussed in detail in Section \ref{subsubsec:JetEnergyCalibration}.
\item{\textbf{Residual \emph{in-situ} corrections:}} This correction assesses the differences between the data and the MC simulations.
It is applied as the last step to the jets reconstructed in data, and is explained in detail in Section \ref{subsubsec:JetResidualCalibration}.
\end{enumerate}
\subsubsection{Pileup corrections}
\label{subsubsec:JetPileupCorrections}
The correction applied to jets to account for the energy offset introduced by the several interactions per bunch crossing in ATLAS is discussed below.
The mean number of inelastic $\pp$ interactions per bunch crossing, $\averageIntXing$, is related to the instantaneous luminosity, $\InstLumi$, by Equation~\ref{LumiDefinition}, which can be re-written as
\begin{equation}
\averageIntXing = \frac{\InstLumi \times \sigma_{\text{inel.}}}{n_b \times f_r}.
\label{eq:intPerXing}
\end{equation}
The instantaneous luminosity in 2012 reached values as high as $\unit[7.7\times10^{33}]{cm^{-2} s^{-1}}$, meaning that the average pileup activity in 2012 was $\averageIntXing \approx 20.7$.
The presence of these additional interactions per bunch crossing can effect the data-taking in two different ways:
\begin{itemize}
\item{\emph{In-time} pileup: } additional signals in the calorimeters can be produced due to the presence of additional interactions in the same bunch crossing as the triggered event.
\item{\emph{Out-of-time} pileup:} further signal modulation in the calorimeters from multiple interactions in surrounding bunch crossings.
\end{itemize}
In order to account for these effects, corrections of the jet transverse momentum that inherently accommodates jet-by-jet variations in pileup sensitivity as well as event-by-event fluctuations in pileup activity are applied according to Equation \ref{eq:JetPileupCorrection},
\begin{equation}
\pt^{\text{jet, corr}} = \pt^{\text{jet}} - \rho \cdot A - \text{Residuals}(N_{\text{PV}}-1, \averageIntXing, \pt)
\label{eq:JetPileupCorrection}
\end{equation}
\noindent where $\rho$ is the median $\pt$ density which provides a direct estimate of the global pileup activity in any event, and $A$ is the jet area, which provides an estimate of a jet's sensitivity to pileup. By the multiplication of these two quantities, an estimate of the effect of the in-time pileup on the jet is obtained.
However, Ref.~\cite{TheATLAScollaboration:2013pia} shows that the effects of pileup in the forward region are not well described by $\rho$.
After subtracting $\rho \cdot A$ from the jet $\pt$, an additional subtraction of a residual term is needed.
This residual term provides, as a function of the jet $\pt$, corrections for in-time and out-of-time pileup effects.
For this reason, the residual term is proportional to the number of reconstructed pileup vertices, $N_{\text{PV}}-1$, and to $\averageIntXing$, respectively.
Figure \ref{fig:JetPileupCorrection} shows the dependence of the reconstructed jet $\pt$ on in-time pileup (left) and out-of-time pileup (right) at various correction stages for different $|\eta|$.
\begin{figure}[!ht]
\begin{center}
\mbox{
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetPileupCorrNPV.eps}
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetPileupCorrMu.eps}
}
\end{center}
\caption[Dependence of the reconstructed jet $\pt$ on in-time pileup and out-of-time pileup at various correction stages.]{Dependence of the reconstructed jet $\pt$ on in-time pileup (left) and out-of-time pileup (right) at various correction stages~\protect\cite{TheATLAScollaboration:2013pia}.}
\label{fig:JetPileupCorrection}
\end{figure}
The fluctuations due to pileup effects in the energy of the jets with energies around the $\pt$ threshold or the reconstruction of jets coming from other pileup interactions, can increase the jet multiplicity of an event.
In order to reject these jets, information from the tracks associated to each jet is used.
The jet vertex fraction (JVF) is a variable aiming to identify the vertex from which a jet is originated.
A schematic representation of the JVF principle is shown in Figure \ref{fig:JetPileup} (left).
It is calculated as the ratio of the sum of transverse momentum of matched tracks that originate from a chosen PV to the sum of transverse momentum of all matched tracks in the jet, independently of their origin.
JVF is defined for each jet with respect to each PV, and therefore for a given jet $i$, its JVF with respect to the primary vertex $j$, PV$_j$, is given by:
\begin{equation}
\text{JVF}(\text{jet}_i, \text{PV}_j) = \frac{\sum_{k=1}^{N_\text{tracks}}{\pt(\text{track}_{k}^{\text{jet}_i}, \text{PV}_j) }}{ \sum_{n=1}^{N_\text{PV}}{\sum_{l=1}^{N_\text{tracks}}{\pt(\text{track}_{l}^{\text{jet}_i}, \text{PV}_n)} }}.
\label{eq:JetJVFDefinition}
\end{equation}
For the analysis presented in this thesis, the JVF will be defined with respect to the event hard-scatter vertex, which is selected as the primary vertex with the highest $\sum_{\text{tracks}}{(\pt^2)}$.
Figure \ref{fig:JetPileup} (right) shows the JVF distribution for hard-scatter jets and for pileup jets with $\pt^{\text{jet}}>\unit[20]{GeV}$ after the pileup subtraction, in order to illustrate the discriminating power of the JVF variable.
JVF values between 0 and 1 indicate the fraction of the $\pt$ of the associated tracks that come from the hard scattering.
If instead, no associated tracks are present, the JVF is set to -1.
\begin{figure}[!ht]
\begin{center}
\mbox{
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetJVFSchema.eps}
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetJVFDiscriminating.eps}
}
\end{center}
\caption[Schematic representation of the JVF principle, and JVF distribution for hard-scatter jets and for pileup jets after the pileup subtraction.]{Schematic representation of the JVF principle (left).
JVF distribution for hard-scatter jets and for pileup jets with $\pt^{\text{jet}}>\unit[20]{GeV}$ after the pileup subtraction~\protect\cite{TheATLAScollaboration:2013pia} (right).}
\label{fig:JetPileup}
\end{figure}
\subsubsection{Jet energy calibration}
\label{subsubsec:JetEnergyCalibration}
The jet energy calibration restores the reconstructed jet energy to the energy of the Monte Carlo particle-level jets (truth jets).
It corrects for detector effects due to the mis-measurement of the energy deposited by hadrons in the calorimeter, the energy lost in inactive regions of the detector or the energy deposits of particles inside the particle-level jet entering the detector that are not included in the reconstructed jet.
The jet energy calibration can be applied to jets formed from topo-clusters at EM or LCW scale, the resulting being referred as EM+JES or LCW+JES jets, respectively.
To derive this calibration, all the isolated calorimeter jets that have a matching isolated particle-level jet at $\Delta R=0.3$ are considered.
An isolated jet is defined as having no other jet with $\pt>\unit[7]{GeV}$ within $\Delta R = 2.5 R$, being $R$ the distance parameter of the jet algorithm~\cite{Aad:2011he}.
The derivation of the jet energy response correction proceeds in several steps:
\begin{itemize}
\item The jet energy response,
\begin{equation}
\mathfrak{R}_{\text{jet}}^{\text{EM(LCW)}} = \frac{E_{\text{jet}}^{\text{EM(LCW)}}}{E_{\text{jet}}^{\text{truth}}},
\label{eq:JetEnergyResponse}
\end{equation}
is computed for each pair of calorimeter and particle-level jets, measured in bins of truth jet energy, $E_{\text{jet}}^{\text{truth}}$ and calorimeter jet detector pseudorapidity\footnote{The detector $\eta$ is used instead of the origin corrected, used in physics analysis, because it more directly corresponds to a region of the calorimeter.}.
\item The averaged jet energy response, $\langle \mathfrak{R}_{\text{jet}}^{\text{EM(LCW)}} \rangle$, and the averaged reconstructed jet energy, $\langle E_{\text{jet}}^{\text{EM(LCW)}} \rangle$, are calculated for each $(E_{\text{jet}}^{\text{truth}}, $\eta$)$-bin.
These quantities are defined as the peak position of a Gaussian fit to the $\mathfrak{R}_{\text{jet}}^{\text{EM(LCW)}}$ and $E_{\text{jet}}^{\text{EM(LCW)}}$ distributions, respectively.
Figure \ref{fig:JetCalibrationResponse} (left) shows the averaged jet calibration response for the EM+JES scale, for various jet energies as a function of the jet $\eta$.
The values for the jet response vary between 0.85 and 0.55, increasing as the energy of the jet becomes larger and decreasing in the $\eta$ regions corresponding to the inactive regions of the calorimeters.
\item For each $\eta$ bin, the jet response calibration function, $\mathcal{F}_{\text{calib}}(E_{\text{jet}}^{\text{EM(LCW)}})$, is obtained by fitting the $(\langle E_{\text{jet}}^{\text{EM(LCW)}} \rangle, \langle \mathfrak{R}_{\text{jet}}^{\text{EM(LCW)}} \rangle)$ values corresponding to each $E_{\text{jet}}^{\text{truth}}$ bin.
The fitting function can be parametrized as:
\begin{equation}
\mathcal{F}_{\text{calib}}(E_{\text{jet}}^{\text{EM(LCW)}}) = \sum_{i=0}^{N_{\text{max}}}{a_i\left(\ln{E_{\text{jet}}^{\text{EM(LCW)}}}\right)^i},
\label{eq:JetResponseFunction}
\end{equation}
\noindent where $a_i$ are free parameters and $N_\text{max}$ is chosen between 1 and 6 depending on the goodness of the fit.
\end{itemize}
\begin{figure}[!ht]
\begin{center}
\mbox{
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetCalibrationResponse.eps}
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/JetCalibfig_EMJES_vs_pT_AntiKt6.eps}
}
\end{center}
\caption[Average energy of jets formed from topoclusters calibrated at EM scale, and average jet energy scale correction as a function of the calibrated jet transverse momentum.]{Left: average energy of jets formed from topoclusters calibrated at EM scale with respect to the particle-level jet energy ($E_{\text{jet}}^{\text{EM}}/E_{\text{jet}}^{\text{truth}}$) as a function of the jet pseudorapidity before applying the correction for the event vertex shown separately for various jet energies \protect\cite{Aad:2011he}.
Right: Average jet energy scale correction as a function of the calibrated jet transverse momentum for three representative $\eta^{\text{jet}}$-intervals obtained from the nominal MC simulation sample~\protect\cite{Aad:2011he}.
}
\label{fig:JetCalibrationResponse}
\end{figure}
The final jet energy scale correction that relates the measured calorimeter jet to the true jet energy is defined as $1/\mathcal{F}_{\text{calib}}(E_{\text{jet}}^{\text{EM(LCW)}})$, such that:
\begin{equation}
E_{\text{jet}}^{\text{EM+JES(LCW+JES)}} = \frac{E_{\text{jet}}^{\text{EM(LCW)}}}{\mathcal{F}_{\text{calib}}(E_{\text{jet}}^{\text{EM(LCW)}})|_{\eta}}.
\label{eq:JetJESCorrection}
\end{equation}
Figure \ref{fig:JetCalibrationResponse} (right) shows the jet energy scale correction as a function of the calibrated jet transverse momentum for three different $\eta$-intervals.
The values of the jet energy correction factors range from about 2.1 at low jet energies in the central region to less than 1.2 for high energy jets in the most forward region.
\subsubsection{Jet residual calibration}
\label{subsubsec:JetResidualCalibration}
In the jet residual calibration, the data-to-MC differences are assessed using \emph{in-situ} techniques, which exploit the transverse momentum balance between a jet and well-measured photons, $Z$ bosons or jets.
This calibration is only applied to data, since it aims to restore the energy of the jets reconstructed in data to that from the Monte Carlo simulation\footnote{The reconstructed jets from the MC simulations are calibrated with the EM+JES or the LCW+JES scheme, which restores the reconstructed jet energy to that of the particle-level jet in the simulation, as shown in Section~\ref{subsubsec:JetEnergyCalibration}.}.
The jet energy once the residual calibration has been applied, $E_{\text{jet}}^{\text{data, in-situ}}$, is found to be:
\begin{equation}
E_{\text{jet}}^{\text{data, in-situ}} = \frac{E_{\text{jet}}^{\text{data}}}{\mathcal{C}(\pt^{\text{jet}}, \eta)},
\label{eq:JetInSituCorrection}
\end{equation}
\noindent where $1 / \mathcal{C}(\pt^{\text{jet}}, \eta)$, the correction extracted from the jet in-situ calibrations, is defined as:
\begin{equation}
\mathcal{C}(\pt^{\text{jet}}, \eta) = \frac{\langle \pt^{\text{jet}} / \pt^{\text{ref}} \rangle_{\text{data}}}{\langle \pt^{\text{jet}} / \pt^{\text{ref}} \rangle_{\text{MC}}}\Bigg|_{\eta},
\label{eq:JetInSituCorrectionFactor}
\end{equation}
\noindent with $\langle \pt^{\text{jet}} / \pt^{\text{ref}} \rangle_{\text{data}}$ and $\langle \pt^{\text{jet}} / \pt^{\text{ref}} \rangle_{\text{MC}}$ being the ratio of the average jet response, measured in data and in the Monte Carlo simulation, respectively.
The residual jet calibration is computed following different strategies depending on whether the jet is contained in the central or in the forward regions of the detector.
In the central rapidity region, $|\eta_\text{det}|<1.2$, the jet energy can be calibrated as follows:
\begin{enumerate}
\item{\textbf{Jet energy calibration using $Z$-jet events: }}In events where one $Z$ boson is produced in association to only one jet, the jet recoils against the $Z$ boson ensuring approximate momentum balance between them in the transverse plane.
Ideally, the response of the jet in the calorimeters could be determined by using the $\pt$ of the $Z$ boson as the reference particle-level jet $\pt$.
However, uncertainties on the $Z$ boson decay products measurement, particles not included in the cone of the jet, additional parton radiation contributing to the recoil against the $Z$ boson or contributions from the underlying event prevent to use the measurement of $\langle\pt^{\text{jet}}/\pt^{\text{ref}}\rangle$ to estimate the jet response, but only to assess how well the MC simulation can reproduce the data.
Figure~\ref{fig:JetInSituMeasurements} (left) shows the mean $\pt$ balance measured in data and in a \pythia{} MC simulation, for EM+JES calibrated $\akt$ jets.
The $\pt$ balance, $\langle \pt^{\text{jet}} / \pt^{\text{ref}} \rangle$, ranges between 0.7 and 1 both in data and in the simulation, and it increases as the $\pt$ of the jet increases.
This figure also shows that the $\pt$ balance measured in the MC simulation is slightly higher compared to the measurement in data.
The advantage of the jet calibration using $Z$-jet events is the possibility of probing low-$\pt$ jets, which are difficult to reach with $\gamma$-jet events due to trigger thresholds and background contamination in that region.
\item{\textbf{Jet energy calibration using $\gamma$-jet events: }}The $\gamma$-jet events benefit from larger statistics for $\pt$ above 150~GeV compared to the $Z$-jet events.
Two in-situ techniques are used to probe the calorimeter response to jets recoiling the photons, for data and MC simulations.
On one hand, a technique based on the procedure used to determine the jet energy calibration using $Z$-jet events is followed, in which the highest $\pt$ jet is compared to the transverse momentum of the reference photon.
Alternatively, the missing transverse momentum projection fraction (MPF) technique \cite{Aad:2014bia} is used, in which the photon transverse momentum is balanced against the full hadronic recoil.
\item{\textbf{High-$\pt$ jet energy calibration: }}This technique is relevant for very high $\pt$ jets (at the TeV regime), where the calibrations extracted using the $Z$-jet and the $\gamma$-jet methods described above, are affected by statistical fluctuations.
Jets at very high $\pt$ are balanced against a recoil system of low $\pt$ jets, previously well calibrated using the $\gamma$-jet or the $Z$-jet balance.
\end{enumerate}
The final in-situ calibration obtained from the combination of these techniques is shown in Figure~\ref{fig:JetInSituMeasurements} (right), together with statistical uncertainties.
A general offset of about $-2\%$ is observed in the data-to-MC response ratios for jet transverse momenta below $\unit[100]{GeV}$.
The offset decreases to $-1\%$ at higher $\pt$ ($\pt \gtrsim \unit[200]{GeV}$).
\begin{figure}[!ht]
\begin{center}
\mbox{
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/Zjetfigures_balanceComparison_Jes_Akt4.pdf}
\includegraphics[width=0.495\textwidth]{ObjectReconstruction/Figures/responseRatioSmooth_TSpline2_EMJES_R4.pdf}
}
\end{center}
\caption[Mean $\pt$ balance obtained in the data and with the \pythia{} simulation, and ratio of the average jet response measured in data to that measured in MC simulations.]{Mean $\pt$ balance obtained in the data and with the \pythia{} simulation, for $\akt$ jets with $R=0.4$ calibrated with the EM+JES scheme (left)~\cite{Aad:2014bia}. Ratio of the average jet response $\langle \pt^{\text{jet}} / \pt^{\text{ref}} \rangle$ measured in data to that measured in MC simulations for jets within $|\eta|<1.2$ as a function of the jet transverse momentum, $\pt^{\text{jet}}$, shown separately for the three in-situ techniques, used in the combined calibration (right)~\cite{Aad:2014bia}.}
\label{fig:JetInSituMeasurements}
\end{figure}
In the forward rapidity region, $|\eta_\text{det}|>1.2$, the calibration can be performed by exploiting the transverse momentum balance in events with two jets at high transverse momentum.
A jet in the forward region can be balanced against a well-calibrated jet in the central region, and therefore, the whole detector response can be equalized as a function of $\eta^{\text{jet}}$.
In addition to this simple approach, the matrix method described in Ref.~\cite{ATLAS:2011jea} is used, in which the $\eta$-intercalibration is estimated from jets in all regions (not only the central one).
\section{Missing transverse energy}
\label{subsec:ETmissReco}
The missing transverse momentum, $\ptmiss$, is defined as the momentum imbalance in the plane transverse to the beam axis.
The vector momentum imbalance in the transverse plane is obtained from the negative vector sum of the momenta of all particles detected in a $\pp$ collision.
The $\ptmiss$ reconstruction includes contributions from energy deposits in the calorimeters and muons reconstructed in the muon spectrometer \cite{TheATLAScollaboration:2013oia}.
The two $\ptmiss$ components are calculated as:
\begin{equation}
p_{x(y)}^{\text{miss}} = p_{x(y)}^{\text{miss,calo}} + p_{x(y)}^{\text{miss},\mu}.
\label{eq:ETmissDef_All}
\end{equation}
The magnitude of this vector is the so-called missing transverse energy, $\met$.
The values of $\met$ and its azimutal coordinate $\phi^\text{miss}$ are defined as:
\begin{equation}
\begin{split}
\met = \sqrt{(p_{x}^{\text{miss}})^2 + (p_{y}^{\text{miss}})^2},\\
\phi^{\text{miss}} = \arctan{(p_{y}^{\text{miss}} / p_{x}^{\text{miss}})}.
\end{split}
\label{eq:ETmissDef_pol}
\end{equation}
The reconstruction of the calorimeter term of the $\ptmiss$ uses calorimeter cells calibrated according to the reconstructed high-$\pt$ physics object to which they are associated, in a chosen order: electrons, photons, hadronically decaying $\tau$-leptons, jets and muons.
Cells not associated with any such objects are also taken into account in the $\met$ calculation.
Once the cells are associated with objects as described above, the $\ptmiss$ calorimeter term is calculated as follows \cite{Aad:1379858} (the reason why the $p_{x(y)}^{\text{miss,calo},\mu}$ term is in between parenthesis will become clear below):
\begin{equation}
\begin{split}
p_{x(y)}^{\text{miss,calo}} = p_{x(y)}^{\text{miss},e} + p_{x(y)}^{\text{miss},\gamma} + p_{x(y)}^{\text{miss},\tau} + p_{x(y)}^{\text{miss,jets}} \\
p_{x(y)}^{\text{miss,softjets}} + (p_{x(y)}^{\text{miss,calo},\mu}) + p_{x(y)}^{\text{miss,CellOut}}.
\end{split}
\label{eq:ETmissDef_Calo}
\end{equation}
Each of the terms in the previous equation is computed from the negative sum of calibrated cell energies inside the corresponding object, according to the following expression:
\begin{equation}
\begin{split}
p_{x}^{\text{miss,term}} = \sum_{i=1}^{N_{\text{cell}}^{\text{term}}}{p_i \sin{\theta_i}\cos{\phi_i}} \\
p_{y}^{\text{miss,term}} = \sum_{i=1}^{N_{\text{cell}}^{\text{term}}}{p_i \sin{\theta_i}\sin{\phi_i}}
\end{split}
\label{eq:ETmissDef_Split}
\end{equation}
\noindent where $p_i$, $\theta_i$ and $\phi_i$ are the energy, the polar angle and the azimutal angle respectively, and all the summations are performed on cells in the range $|\eta|<4.5$.
The different terms in Equation \ref{eq:ETmissDef_Calo} are described in the following:
\begin{itemize}
\item{$p_{x(y)}^{\text{miss},e}$ }is reconstructed from cells in clusters associated to electrons passing the ``medium'' identification criteria with $\pt>\unit[10]{GeV}$.
\item{$p_{x(y)}^{\text{miss},\gamma}$ }is also reconstructed from cells in clusters, associated with photons passing the ``tight'' identification criteria \cite{ATLAS:2012ana} with $\pt>\unit[10]{GeV}$ at the EM scale.
\item{$p_{x(y)}^{\text{miss},\tau}$ }is reconstructed from cluster cells associated to LCW calibrated $\tau$-jets reconstructed with the ``tight'' identification criteria \cite{TheATLAScollaboration:2013wha}, with $\pt>\unit[10]{GeV}$.
\item{$p_{x(y)}^{\text{miss,jets}}$ }is computed from cells in clusters associated to LCW calibrated jets with $\pt>\unit[20]{GeV}$, reconstructed with the $\akt$ algorithm, and with the jet energy scale factor applied.
\item{$p_{x(y)}^{\text{miss,softjets}}$} is reconstructed from cells in clusters associated to LCW calibrated jets reconstructed with the $\akt$ algorithm (with $R=0.6$), with $\unit[7]{GeV}<\pt<\unit[20]{GeV}$.
\item{$p_{x(y)}^{\text{miss,calo},\mu}$} is the contribution originating from energy lost by muons in the calorimeter.
Its calibration will be discussed below.
\item{$p_{x(y)}^{\text{miss,CellOut}}$} is calculated from the cells in topoclusters with the LCW calibration and from reconstructed tracks with $\pt>\unit[400]{MeV}$ which are not included in the reconstructed objects.
The tracks are added to recover the contribution from low-$\pt$ particles which do not reach the calorimeter or do not have enough energy to seed a topocluster.
They are also used to improve the determination of the momentum in the topoclusters, since the calibration and resolution of the low $\pt$ tracks is better compared to that of the topoclusters.
\end{itemize}
On the other hand, the $\ptmiss$ muon term (see Equation \ref{eq:ETmissDef_All}) from the momentum of muon tracks reconstructed with $|\eta|<2.7$:
\begin{equation}
p_{x(y)}^{\text{miss},\mu} = - \sum_{\text{muons}}{p_{x(y)}}^{\mu},
\label{eq:ETmissDef_Mu}
\end{equation}
\noindent where the summation effects all the selected muons.
In the central region, $|\eta|<2.5$, combined muons (reconstructed muons in the MS with a matched track in the ID, see Section \ref{sec:MuonReco}) are considered.
Instead, since the region $2.5<|\eta|<2.7$ lays outside the fiducial volume of the ID, there is no matched track requirement and the MS $\pt$ alone is used.
The muon term is calculated differently for isolated and non-isolated muons, where non-isolated muons are defined to be those within a distance $\Delta R < 0.3$ of a reconstructed jet in the event.
For isolated muons, the $\pt$ is determined from the combined measurement in the ID and MS, accounting for the energy that the muon deposits in the calorimeter.
Therefore, $p_{x(y)}^{\text{miss,calo},\mu}$ is not added to the calorimeter contribution (this is the reason why it appears in between parenthesis in Equation \ref{eq:ETmissDef_Calo}).
Instead, for non-isolated muons, the term $p_{x(y)}^{\text{miss,calo},\mu}$ has to be considered.
The systematic uncertainty on each individual term of the $\met$ can be evaluated from the propagation of the uncertainties of the reconstructed objects that are used to build it.
Only the contribution to the $\met$ scale and resolution uncertainties coming from the ``soft terms'' (softjets and CellOut terms) needs to be estimated with dedicated studies \cite{TheATLAScollaboration:2013oia}.
The overall systematic uncertainty on the $\met$ scale is then calculated by combining the uncertainties on each term.
As it will be discussed in Section~\ref{sec:ObjectDefinition}, a slightly modified definition of the $\met$ is used\footnote{The $\met$ collection in the analysis presented is called ``\texttt{MET\_Egamma10NoTau}''.} in the analysis presented in this Thesis.
The $\tau$-lepton term, $p_{x(y)}^{\text{miss},\tau}$, is omitted because in the analysis presented, $\tau$-leptons are not identified as such, but considered as jets.
Furthermore, the muon terms, $p_{x(y)}^{\text{miss,calo},\mu}$ and $p_{x(y)}^{\text{miss},\mu}$, are also omitted.
The reason for not considering them is related to the precise estimation of the most important irreducible background in the analysis, $\znn$, which will be explained in Chapter~\ref{chapter:MonojetAnalysis}.
|
section\<open>The First Monotonicity Calculus\<close>
theory Mcalc
imports Mono
begin
context ProblemIk begin
subsection\<open>Naked variables\<close>
fun nvT where
"nvT (Var x) = {x}"
|
"nvT (Fn f Tl) = {}"
fun nvA where
"nvA (Eq T1 T2) = nvT T1 \<union> nvT T2"
|
"nvA (Pr p Tl) = {}"
fun nvL where
"nvL (Pos at) = nvA at"
|
"nvL (Neg at) = {}"
definition "nvC c \<equiv> \<Union> (set (map nvL c))"
definition "nvPB \<equiv> \<Union> c \<in> \<Phi>. nvC c"
lemma nvT_vars[simp]: "x \<in> nvT T \<Longrightarrow> x \<in> vars T"
by (induct T) (auto split: if_splits)
lemma nvA_varsA[simp]: "x \<in> nvA at \<Longrightarrow> x \<in> varsA at"
by (cases at, auto)
lemma nvL_varsL[simp]: "x \<in> nvL l \<Longrightarrow> x \<in> varsL l"
by (cases l, auto)
lemma nvC_varsC[simp]: "x \<in> nvC c \<Longrightarrow> x \<in> varsC c"
unfolding varsC_def nvC_def by(induct c, auto)
lemma nvPB_varsPB[simp]: "x \<in> nvPB \<Longrightarrow> x \<in> varsPB \<Phi>"
unfolding varsPB_def nvPB_def by auto
subsection\<open>The calculus\<close>
inductive mcalc (infix "\<turnstile>" 40) where
[simp]: "infTp \<sigma> \<Longrightarrow> \<sigma> \<turnstile> c"
|[simp]: "(\<forall> x \<in> nvC c. tpOfV x \<noteq> \<sigma>) \<Longrightarrow> \<sigma> \<turnstile> c"
lemma mcalc_iff: "\<sigma> \<turnstile> c \<longleftrightarrow> infTp \<sigma> \<or> (\<forall> x \<in> nvC c. tpOfV x \<noteq> \<sigma>)"
unfolding mcalc.simps by simp
end (* context ProblemIk *)
locale ProblemIkMcalc = ProblemIk wtFsym wtPsym arOf resOf parOf \<Phi> infTp
for wtFsym :: "'fsym \<Rightarrow> bool" and wtPsym :: "'psym \<Rightarrow> bool"
and arOf :: "'fsym \<Rightarrow> 'tp list"
and resOf and parOf and \<Phi> and infTp
+ assumes mcalc: "\<And> \<sigma> c. c \<in> \<Phi> \<Longrightarrow> \<sigma> \<turnstile> c"
locale ModelIkMcalc =
ModelIk wtFsym wtPsym arOf resOf parOf \<Phi> infTp intT intF intP +
ProblemIkMcalc wtFsym wtPsym arOf resOf parOf \<Phi> infTp
for wtFsym :: "'fsym \<Rightarrow> bool" and wtPsym :: "'psym \<Rightarrow> bool"
and arOf :: "'fsym \<Rightarrow> 'tp list"
and resOf and parOf and \<Phi> and infTp and intT and intF and intP
subsection\<open>Extension of a structure to an infinite structure
by adding indistinguishable elements\<close>
context ModelIkMcalc begin
text\<open>The projection from univ to a structure:\<close>
definition proj where "proj \<sigma> a \<equiv> if intT \<sigma> a then a else pickT \<sigma>"
lemma intT_proj[simp]: "intT \<sigma> (proj \<sigma> a)"
unfolding proj_def using pickT by auto
lemma proj_id[simp]: "intT \<sigma> a \<Longrightarrow> proj \<sigma> a = a"
unfolding proj_def by auto
lemma surj_proj:
assumes "intT \<sigma> a" shows "\<exists> b. proj \<sigma> b = a"
using assms by (intro exI[of _ a]) simp
definition "I_intT \<sigma> (a::univ) \<equiv> infTp \<sigma> \<longrightarrow> intT \<sigma> a"
definition "I_intF f al \<equiv> intF f (map2 proj (arOf f) al)"
definition "I_intP p al \<equiv> intP p (map2 proj (parOf p) al)"
lemma not_infTp_I_intT[simp]: "\<not> infTp \<sigma> \<Longrightarrow> I_intT \<sigma> a" unfolding I_intT_def by simp
lemma infTp_I_intT[simp]: "infTp \<sigma> \<Longrightarrow> I_intT \<sigma> a = intT \<sigma> a" unfolding I_intT_def by simp
lemma NE_I_intT: "NE (I_intT \<sigma>)"
using NE_intT by (cases "infTp \<sigma>", auto)
lemma I_intF:
assumes f: "wtFsym f" and al: "list_all2 I_intT (arOf f) al"
shows "I_intT (resOf f) (I_intF f al)"
unfolding I_intT_def I_intF_def apply safe apply(rule intF[OF f])
using al unfolding list_all2_length by auto
lemma Tstruct_I_intT: "Tstruct I_intT"
by standard (rule NE_I_intT)
lemma inf_I_intT: "infinite {a. I_intT \<sigma> a}"
by (cases "infTp \<sigma>", auto)
lemma InfStruct: "IInfStruct I_intT I_intF I_intP"
apply standard using NE_I_intT I_intF Tstruct_I_intT inf_I_intT by auto
end (* context ModelIkMcalc *)
sublocale ModelIkMcalc < InfStruct where
intT = I_intT and intF = I_intF and intP = I_intP
using InfStruct .
subsection\<open>The soundness of the calculus\<close>
text\<open>In what follows, ``Ik'' stands for the original
(augmented with infiniteness-knowledge)
and ``I'' for the infinite structure constructed from it
through the above sublocale statement.\<close>
context ModelIkMcalc begin
text\<open>The environment translation along the projection:\<close>
definition "transE \<xi> \<equiv> \<lambda> x. proj (tpOfV x) (\<xi> x)"
lemma wtE_transE[simp]: "I.wtE \<xi> \<Longrightarrow> Ik.wtE (transE \<xi>)"
unfolding Ik.wtE_def I.wtE_def transE_def by auto
abbreviation "Ik_intT \<equiv> intT"
abbreviation "Ik_intF \<equiv> intF"
abbreviation "Ik_intP \<equiv> intP"
lemma Ik_intT_int:
assumes wt: "Ik.wt T" and \<xi>: "I.wtE \<xi>"
and snv: "\<And> \<sigma>. infTp \<sigma> \<or> (\<forall> x \<in> nvT T. tpOfV x \<noteq> \<sigma>)"
shows "Ik_intT (tpOf T) (I.int \<xi> T)"
proof(cases "\<exists> x. T = Var x")
case True then obtain x where T: "T = Var x" by auto
show ?thesis proof(cases "infTp (tpOf T)")
case True thus ?thesis using T using wtE_transE[OF \<xi>]
by (metis I.wt_int I_intT_def \<xi> wt)
next
case False hence "\<forall> x \<in> nvT T. tpOfV x \<noteq> tpOf T" using snv by auto
hence "Ik.full (tpOf T)" using T by (cases T, simp_all)
thus ?thesis unfolding Ik.full_def by simp
qed
next
case False hence nonVar: "\<not> (\<exists> x. T = Var x)" by (cases T, auto)
thus ?thesis using nonVar wt apply(induct T, force)
unfolding I_intF_def tpOf.simps int.simps
apply(rule Ik.intF, simp) apply(rule listAll2_map2I) by auto
qed
lemma int_transE_proj:
assumes wt: "Ik.wt T"
shows "Ik.int (transE \<xi>) T = proj (tpOf T) (I.int \<xi> T)"
using wt proof (induct T)
case (Fn f Tl)
have 0: "Ik_intT (resOf f) (I_intF f (map (int \<xi>) Tl))" (is "Ik_intT ?\<sigma> ?a")
unfolding I_intF_def apply(rule Ik.intF)
using Fn unfolding list_all2_length list_all_iff by auto
have 1: "proj ?\<sigma> ?a = ?a" using proj_id[OF 0] .
show ?case
using [[unfold_abs_def = false]]
unfolding Ik.int.simps int.simps tpOf.simps 1
unfolding I_intF_def apply(rule arg_cong[of _ _ "intF f"])
proof (rule nth_equalityI)
have l[simp]: "length (arOf f) = length Tl" using Fn by simp
fix i assume "i < length (map (Ik.int (transE \<xi>)) Tl)"
hence i[simp]: "i < length Tl" by simp
have 0: "arOf f ! i = tpOf (Tl ! i)" using Fn by simp
have [simp]: "Ik.int (transE \<xi>) (Tl ! i) = proj (arOf f ! i) (I.int \<xi> (Tl ! i))"
unfolding 0 using Fn by (auto simp: list_all_length transE_def)
show "map (Ik.int (transE \<xi>)) Tl ! i =
map2 proj (arOf f) (map (I.int \<xi>) Tl) ! i"
using Fn unfolding list_all_length by simp
qed(use Fn in simp)
qed simp
lemma int_transE_snv[simp]:
assumes wt: "Ik.wt T" and \<xi>: "I.wtE \<xi>" and snv: "\<And> \<sigma>. infTp \<sigma> \<or> (\<forall> x \<in> nvT T. tpOfV x \<noteq> \<sigma>)"
shows "Ik.int (transE \<xi>) T = I.int \<xi> T"
unfolding int_transE_proj[OF wt] apply(rule proj_id)
using Ik_intT_int[OF wt \<xi> snv] .
lemma int_transE_Fn:
assumes wt: "list_all wt Tl" and f: "wtFsym f" and \<xi>: "I.wtE \<xi>"
and ar: "arOf f = map tpOf Tl"
shows "Ik.int (transE \<xi>) (Fn f Tl) = I.int \<xi> (Fn f Tl)"
apply(rule int_transE_snv) using assms by auto
lemma intP_transE[simp]:
assumes wt: "list_all wt Tl" and p: "wtPsym p" and ar: "parOf p = map tpOf Tl"
shows "Ik_intP p (map (Ik.int (transE \<xi>)) Tl) = I_intP p (map (I.int \<xi>) Tl)"
unfolding I_intP_def apply(rule arg_cong[of _ _ "Ik_intP p"])
apply(rule nth_equalityI) using assms
using int_transE_proj unfolding list_all_length by auto
lemma satA_snvA_transE[simp]:
assumes wtA: "Ik.wtA at" and \<xi>: "I.wtE \<xi>"
and pA: "\<And> \<sigma>. infTp \<sigma> \<or> (\<forall> x \<in> nvA at. tpOfV x \<noteq> \<sigma>)"
shows "Ik.satA (transE \<xi>) at \<longleftrightarrow> I.satA \<xi> at"
using assms apply (cases at, simp_all add: ball_Un) by (metis int_transE_snv)
(* The next contrapositive twist is crucial for proving satL_transE: *)
lemma satA_transE[simp]:
assumes wtA: "Ik.wtA at" and "I.satA \<xi> at"
shows "Ik.satA (transE \<xi>) at"
using assms apply(cases at) using int_transE_proj by auto
lemma satL_snvL_transE[simp]:
assumes wtL: "Ik.wtL l" and \<xi>: "I.wtE \<xi>"
and pL: "\<And> \<sigma>. infTp \<sigma> \<or> (\<forall> x \<in> nvL l. tpOfV x \<noteq> \<sigma>)" and "Ik.satL (transE \<xi>) l"
shows "I.satL \<xi> l"
using assms by (cases l) auto
lemma satC_snvC_transE[simp]:
assumes wtC: "Ik.wtC c" and \<xi>: "I.wtE \<xi>"
and pC: "\<And> \<sigma>. \<sigma> \<turnstile> c" and "Ik.satC (transE \<xi>) c"
shows "I.satC \<xi> c"
using assms unfolding Ik.mcalc_iff Ik.satC_def satC_def Ik.wtC_def nvC_def
unfolding list_all_iff list_ex_iff apply simp by (metis nth_mem satL_snvL_transE)
lemma satPB_snvPB_transE[simp]:
assumes \<xi>: "I.wtE \<xi>" shows "I.satPB \<xi> \<Phi>"
using Ik.wt_\<Phi> Ik.sat_\<Phi>[OF wtE_transE[OF \<xi>]]
using mcalc \<xi> unfolding Ik.satPB_def satPB_def Ik.wtPB_def nvPB_def by auto
lemma I_SAT: "I.SAT \<Phi>" unfolding I.SAT_def by auto
lemma InfModel: "IInfModel I_intT I_intF I_intP"
by standard (rule I_SAT)
end (* context ModelIkMcalc *)
sublocale ModelIkMcalc < inf?: InfModel where
intT = I_intT and intF = I_intF and intP = I_intP
using InfModel .
context ProblemIkMcalc begin
abbreviation "MModelIkMcalc \<equiv> ModelIkMcalc wtFsym wtPsym arOf resOf parOf \<Phi> infTp"
end (* context ProblemIkMcalc *)
text\<open>Final theorem in sublocale form: Any problem that passes the
monotonicity calculus is monotonic:\<close>
sublocale ProblemIkMcalc < MonotProblem
by standard (rule monot)
end
|
[STATEMENT]
lemma "rec_eval (Pr v va vb) [] = undefined"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. rec_eval (Pr v va vb) [] = undefined
[PROOF STEP]
by auto
|
From FourCerty Require Import Utility StackLang.
Import Utility StackLang.
Module StackLangRel.
Open Scope Z_scope.
Inductive do_cmp_R : ins_cmp -> Z -> Z -> bool -> Prop :=
| DC_Eq : forall i1 i2,
do_cmp_R C_Eq i1 i2 (i1 =? i2)
| DC_Ne : forall i1 i2,
do_cmp_R C_Ne i1 i2 (negb (i1 =? i2))
| DC_Lt : forall i1 i2,
do_cmp_R C_Lt i1 i2 (i1 <? i2)
| DC_Le : forall i1 i2,
do_cmp_R C_Le i1 i2 (i1 <=? i2)
| DC_Gt : forall i1 i2,
do_cmp_R C_Gt i1 i2 (i1 >? i2)
| DC_Ge : forall i1 i2,
do_cmp_R C_Ge i1 i2 (i1 >=? i2).
Inductive do_uop_R : ins_uop -> ins_val -> ins_val -> Prop :=
| DU_Add1 : forall i,
do_uop_R U_Add1 (V_Int i) (V_Int (i + 1))
| DU_Sub1 : forall i,
do_uop_R U_Sub1 (V_Int i) (V_Int (i - 1))
| DU_NotFalse : do_uop_R U_Not (V_Bool false) (V_Bool true)
| DU_NotTrue : do_uop_R U_Not (V_Bool true) (V_Bool false)
| DU_NotInt : forall i, do_uop_R U_Not (V_Int i) (V_Bool false).
Inductive do_bop_R : ins_bop -> ins_val -> ins_val -> ins_val -> Prop :=
| DB_Add : forall i1 i2,
do_bop_R B_Add (V_Int i1) (V_Int i2) (V_Int (i1 + i2))
| DB_Sub : forall i1 i2,
do_bop_R B_Sub (V_Int i1) (V_Int i2) (V_Int (i1 - i2))
| DB_And : forall b1 b2,
do_bop_R B_And (V_Bool b1) (V_Bool b2) (V_Bool (b1 && b2))
| DB_Or : forall b1 b2,
do_bop_R B_Or (V_Bool b1) (V_Bool b2) (V_Bool (b1 || b2)).
Inductive eval_tm_R : nat -> partial_map stk_fun -> stk_tm -> list ins_val -> list ins_val -> Prop :=
| E_End : forall f funs vs,
eval_tm_R f funs End vs vs
| E_InsCall : forall f f' funs inss' inss'' args rst fn n vs1 vs2 vs3,
f = S f' ->
args = firstn n vs1 ->
rst = skipn n vs1 ->
List.length args = n ->
Ok (Fun fn n inss'') = lookup funs fn ->
eval_tm_R f' funs inss'' args vs2 ->
eval_tm_R f funs inss' (vs2 ++ rst) vs3 ->
eval_tm_R f funs (Ins (Call fn n) inss') vs1 vs3
| E_InsPush : forall f funs v inss' vs1 vs2,
eval_tm_R f funs inss' (v :: vs1) vs2 ->
eval_tm_R f funs (Ins (Push v) inss') vs1 vs2
| E_InsPop : forall f funs inss' v rst vs,
eval_tm_R f funs inss' rst vs ->
eval_tm_R f funs (Ins Pop inss') (v :: rst) vs
| E_InsSwap : forall f funs inss' v1 v2 rst vs,
eval_tm_R f funs inss' (v2 :: v1 :: rst) vs ->
eval_tm_R f funs (Ins Swap inss') (v1 :: v2 :: rst) vs
| E_InsStkRef : forall f funs inss' n v vs1 vs2,
Some v = nth_error vs1 n ->
eval_tm_R f funs inss' (v :: vs1) vs2 ->
eval_tm_R f funs (Ins (StkRef n) inss') vs1 vs2
| E_InsUop : forall f funs inss' op v1 v2 rst vs,
do_uop_R op v1 v2 ->
eval_tm_R f funs inss' (v2 :: rst) vs ->
eval_tm_R f funs (Ins (Uop op) inss') (v1 :: rst) vs
| E_InsBop : forall f funs inss' op v1 v2 v3 rst vs,
do_bop_R op v1 v2 v3 ->
eval_tm_R f funs inss' (v3 :: rst) vs ->
eval_tm_R f funs (Ins (Bop op) inss') (v2 :: v1 :: rst) vs
| E_InsCmp : forall f funs inss' op i1 i2 b rst vs,
do_cmp_R op i1 i2 b ->
eval_tm_R f funs inss' ((V_Bool b) :: rst) vs ->
eval_tm_R f funs (Ins (Cmp op) inss') ((V_Int i2) :: (V_Int i1) :: rst) vs
| E_IfFalse : forall f funs thn els nxt rst vs1 vs2,
eval_tm_R f funs els rst vs1 ->
eval_tm_R f funs nxt vs1 vs2 ->
eval_tm_R f funs (If thn els nxt) ((V_Bool false) :: rst) vs2
| E_IfTrue : forall f funs thn els nxt v rst vs1 vs2,
eval_tm_R f funs thn rst vs1 ->
eval_tm_R f funs nxt vs1 vs2 ->
eval_tm_R f funs (If thn els nxt) (v :: rst) vs2.
Inductive extract_funs_R : list stk_fun -> partial_map stk_fun -> Prop :=
| EF_Nil : extract_funs_R [] empty
| EF_Cons : forall fs es l n ins,
extract_funs_R fs es ->
extract_funs_R ((Fun l n ins) :: fs) (update es l (Fun l n ins)).
Inductive eval_R : nat -> stk_prg -> list ins_val -> Prop :=
| E_Prg : forall f fs es inss v,
extract_funs_R fs es ->
eval_tm_R f es inss [] v ->
eval_R f (Prg fs inss) v.
End StackLangRel.
|
Enqueue := function(v, x)
Add(v[1], x);
end;
Dequeue := function(v)
local n, x;
n := Size(v[2]);
if n = 0 then
v[2] := Reversed(v[1]);
v[1] := [ ];
n := Size(v[2]);
if n = 0 then
return fail;
fi;
fi;
return Remove(v[2], n);
end;
# a new queue
v := [[], []];
Enqueue(v, 3);
Enqueue(v, 4);
Enqueue(v, 5);
Dequeue(v);
# 3
Enqueue(v, 6);
Dequeue(v);
# 4
Dequeue(v);
# 5
Dequeue(v);
# 6
Dequeue(v);
# fail
|
The episode features mash @-@ up covers of " It 's My Life " by Bon Jovi and " Confessions Part II " by Usher , and " Halo " by BeyoncΓ© Knowles and " Walking on Sunshine " by Katrina and the Waves . Both tracks were released as singles , available for digital download . " It 's My Life / Confessions Part II " charted at number 7 in Ireland , 14 in the UK , 22 in Australia , 25 in Canada and 30 in America , while " Halo / Walking on Sunshine " charted at number 4 in Ireland , 9 in the UK , 10 in Australia , 28 in Canada and 40 in America . Michele has revealed that she practiced talking " manically " for several days in order to convey the effects of pseudoephedrine on Rachel . In order to portray the character in her altered state , she questioned : " How manic is the right amount of manic ? What would Rachel be like on uppers ? What would she sound like ? " She deemed performing the mash @-@ up piece in that state " so much fun " .
|
If $f$ is uniformly continuous on $S$, then $cf$ is uniformly continuous on $S$.
|
# if PP_N_DIMS == 3
# define p4est_constants_mod p8est_constants_mod
# define P4EST_MAXLEVEL P8EST_MAXLEVEL
# endif
module quad_utils_mod
use constants_mod
use mesh_types_mod
use mesh_const_mod
use kernel_share_mod, only: nodes, weights
public
! real(dp) :: nodes(N_NODES), weights(N_NODES)
# if PP_N_DIMS == 2
real(dp) :: weightsD(N_NODES,N_NODES)
# elif PP_N_DIMS == 3
real(dp) :: weightsD(N_NODES,N_NODES,N_NODES)
# endif
contains
subroutine hook_init_510
! use interpol_mod, only: EquidistantNodesAndWeights
integer :: n1,n2,n3
!! The prefactor is necessary since the weights
!! are defined for the intervall: [-1,1]
! real(dp), parameter :: prefactor = 0.5**N_DIMS
! call EquidistantNodesAndWeights(N_NODES-1, nodes, weights)
# if PP_N_DIMS == 2
do n2 = 1,N_NODES; do n1 = 1,N_NODES;
weightsD(n1,n2) = weights(n1)*weights(n2)
end do; end do;
# elif PP_N_DIMS == 3
do n3 = 1,N_NODES; do n2 = 1,N_NODES; do n1 = 1,N_NODES;
weightsD(n1,n2,n3) = weights(n1)*weights(n2)*weights(n3)
end do; end do; end do;
# endif
end subroutine
pure function quad_get_center(quad) result(center)
type(quad_t), intent(in) :: quad
real(dp) :: verts(N_DIMS,MESH_CORNERS)
real(dp) :: center(N_DIMS)
verts = quad_get_vertices(quad)
# if PP_N_DIMS == 2
center = 0.5*(verts(:,NWF) + verts(:,SEF))
# elif PP_N_DIMS == 3
center = 0.5*(verts(:,NWF) + verts(:,SEB))
# endif
end function
# if PP_N_DIMS == 2
pure function quad_get_vertices(quad) result(verts)
use setup_config_mod
use p4est_interfaces_mod, only: p4est_qcoord_to_vertex
type(quad_t), intent(in) :: quad
real(dp) :: verts(N_DIMS,MESH_CORNERS)
real(dp), parameter :: upleft(N_DIMS) = (/xlim(1),ylim(1)/)
real(dp), parameter :: cublen(N_DIMS) = (/xlim(2)-xlim(1),ylim(2)-ylim(1)/)
real(dp) :: difvec(N_DIMS)
real(dp) :: coords(3)
difvec = 1.0_dp / 2**quad%level
call p4est_qcoord_to_vertex(quad%mesh%conn,0,quad%morton(1),quad%morton(2),coords)
verts(:,NWF) = upleft + cublen * (coords(1:2) + (/0.0_dp,0.0_dp/) * difvec)
verts(:,NEF) = upleft + cublen * (coords(1:2) + (/0.0_dp,1.0_dp/) * difvec)
verts(:,SWF) = upleft + cublen * (coords(1:2) + (/1.0_dp,0.0_dp/) * difvec)
verts(:,SEF) = upleft + cublen * (coords(1:2) + (/1.0_dp,1.0_dp/) * difvec)
end function
# elif PP_N_DIMS == 3
pure function quad_get_vertices(quad) result(verts)
use setup_config_mod, only: xlim,ylim,zlim
use p8est_interfaces_mod, only: p8est_qcoord_to_vertex
type(quad_t), intent(in) :: quad
real(dp) :: verts(N_DIMS,MESH_CORNERS)
real(dp), parameter :: upleft(N_DIMS) = (/xlim(1),ylim(1),zlim(1)/)
real(dp), parameter :: cublen(N_DIMS) = (/xlim(2)-xlim(1),ylim(2)-ylim(1),zlim(2)-zlim(1)/)
real(dp) :: difvec(N_DIMS)
real(dp) :: coords(3)
difvec = 1.0_dp / REAL(2**quad%level,dp)
call p8est_qcoord_to_vertex(quad%mesh%conn,0,quad%morton(1),quad%morton(2),quad%morton(3),coords)
verts(:,NWF) = upleft + cublen * (coords + (/0.0_dp,0.0_dp,0.0_dp/) * difvec)
verts(:,NEF) = upleft + cublen * (coords + (/0.0_dp,1.0_dp,0.0_dp/) * difvec)
verts(:,SWF) = upleft + cublen * (coords + (/1.0_dp,0.0_dp,0.0_dp/) * difvec)
verts(:,SEF) = upleft + cublen * (coords + (/1.0_dp,1.0_dp,0.0_dp/) * difvec)
verts(:,NWB) = upleft + cublen * (coords + (/0.0_dp,0.0_dp,1.0_dp/) * difvec)
verts(:,NEB) = upleft + cublen * (coords + (/0.0_dp,1.0_dp,1.0_dp/) * difvec)
verts(:,SWB) = upleft + cublen * (coords + (/1.0_dp,0.0_dp,1.0_dp/) * difvec)
verts(:,SEB) = upleft + cublen * (coords + (/1.0_dp,1.0_dp,1.0_dp/) * difvec)
end function
# endif
pure function quad_get_delta(quad) result(delta)
type(quad_t), intent(in) :: quad
real(dp) :: delta(N_DIMS)
real(dp) :: verts(N_DIMS,MESH_CORNERS)
verts = quad_get_vertices(quad)
delta(1) = abs(verts(1,SWF)-verts(1,NWF))
delta(2) = abs(verts(2,NEF)-verts(2,NWF))
# if PP_N_DIMS == 3
delta(3) = abs(verts(3,NEB)-verts(3,NWF))
# endif
end function
pure function quad_get_nodes(quad) result(ns)
type(quad_t), intent(in) :: quad
real(dp) :: ns(N_NODES)
ns = nodes
end function
pure function quad_get_weights(quad) result(ws)
type(quad_t), intent(in) :: quad
# if PP_N_DIMS == 2
real(dp) :: ws(N_NODES,N_NODES)
# elif PP_N_DIMS == 3
real(dp) :: ws(N_NODES,N_NODES,N_NODES)
# endif
ws = weightsD
end function
pure function quad_get_volumes(quad) result(volumes)
type(quad_t), intent(in) :: quad
# if PP_N_DIMS == 2
real(dp) :: volumes(N_NODES,N_NODES)
# elif PP_N_DIMS == 3
real(dp) :: volumes(N_NODES,N_NODES,N_NODES)
# endif
volumes = product(quad%delta)*weightsD
end function
pure function quad_get_coords(quad) result(coords)
type(quad_t), intent(in) :: quad
# if PP_N_DIMS == 2
real(dp) :: coords(N_NODES,N_NODES,N_DIMS)
# elif PP_N_DIMS == 3
real(dp) :: coords(N_NODES,N_NODES,N_NODES,N_DIMS)
# endif
real(dp) :: verts(N_DIMS,MESH_CORNERS),delta(N_DIMS)
integer :: n1,n2,n3
verts = quad_get_vertices(quad)
# if PP_N_DIMS == 2
delta = abs(verts(:,SEF)-verts(:,NWF))
do n2 = 1,N_NODES; do n1 = 1,N_NODES;
coords(n1,n2,1) = verts(1,NWF) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,n2,2) = verts(2,NWF) + (nodes(n2)+0.5_dp)*delta(2)
end do; end do;
# elif PP_N_DIMS == 3
delta = abs(verts(:,SEB)-verts(:,NWF))
do n3 = 1,N_NODES; do n2 = 1,N_NODES; do n1 = 1,N_NODES;
coords(n1,n2,n3,1) = verts(1,NWF) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,n2,n3,2) = verts(2,NWF) + (nodes(n2)+0.5_dp)*delta(2)
coords(n1,n2,n3,3) = verts(3,NWF) + (nodes(n3)+0.5_dp)*delta(3)
end do; end do; end do;
# endif
end function
pure function quad_get_face_coords(quad,faceid) result(coords)
type(quad_t), intent(in) :: quad
integer, intent(in) :: faceid
# if PP_N_DIMS == 2
real(dp) :: coords(N_NODES,N_DIMS)
# elif PP_N_DIMS == 3
real(dp) :: coords(N_NODES,N_NODES,N_DIMS)
# endif
real(dp) :: verts(N_DIMS,MESH_CORNERS),delta(N_DIMS)
integer :: n1,n2
verts = quad_get_vertices(quad)
# if PP_N_DIMS == 2
delta = abs(verts(:,SEF)-verts(:,NWF))
select case(faceid)
case(NOR)
do n1 = 1,N_NODES
coords(n1,1) = verts(1,NWF)
coords(n1,2) = verts(2,NWF) + (nodes(n1)+0.5_dp)*delta(2)
end do;
case(SOU)
do n1 = 1,N_NODES
coords(n1,1) = verts(1,SWF)
coords(n1,2) = verts(2,SWF) + (nodes(n1)+0.5_dp)*delta(2)
end do;
case(WES)
do n1 = 1,N_NODES
coords(n1,1) = verts(1,NWF) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,2) = verts(2,NWF)
end do;
case(EAS)
do n1 = 1,N_NODES
coords(n1,1) = verts(1,NWF) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,2) = verts(2,NEF)
end do;
end select
# elif PP_N_DIMS == 3
delta = abs(verts(:,SEB)-verts(:,NWF))
select case(faceid)
case(NOR)
do n2 = 1,N_NODES; do n1 = 1,N_NODES
coords(n1,n2,1) = verts(1,NWF)
coords(n1,n2,2) = verts(2,NWF) + (nodes(n1)+0.5_dp)*delta(2)
coords(n1,n2,3) = verts(3,NWF) + (nodes(n2)+0.5_dp)*delta(3)
end do; end do;
case(SOU)
do n2 = 1,N_NODES; do n1 = 1,N_NODES
coords(n1,n2,1) = verts(1,SWF)
coords(n1,n2,2) = verts(2,SWF) + (nodes(n1)+0.5_dp)*delta(2)
coords(n1,n2,3) = verts(3,SWF) + (nodes(n2)+0.5_dp)*delta(3)
end do; end do;
case(WES)
do n2 = 1,N_NODES; do n1 = 1,N_NODES
coords(n1,n2,1) = verts(1,NWF) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,n2,2) = verts(2,NWF)
coords(n1,n2,3) = verts(3,NWF) + (nodes(n2)+0.5_dp)*delta(3)
end do; end do;
case(EAS)
do n2 = 1,N_NODES; do n1 = 1,N_NODES
coords(n1,n2,1) = verts(1,NEF) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,n2,2) = verts(2,NEF)
coords(n1,n2,3) = verts(3,NEF) + (nodes(n2)+0.5_dp)*delta(3)
end do; end do;
case(FRO)
do n2 = 1,N_NODES; do n1 = 1,N_NODES
coords(n1,n2,1) = verts(1,NWF) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,n2,2) = verts(2,NWF) + (nodes(n2)+0.5_dp)*delta(2)
coords(n1,n2,3) = verts(3,NWF)
end do; end do;
case(BAC)
do n2 = 1,N_NODES; do n1 = 1,N_NODES
coords(n1,n2,1) = verts(1,NWB) + (nodes(n1)+0.5_dp)*delta(1)
coords(n1,n2,2) = verts(2,NWB) + (nodes(n2)+0.5_dp)*delta(2)
coords(n1,n2,3) = verts(3,NWB)
end do; end do;
end select
# endif
end function
!! ------------------------------------------------------------------------- !!
pure function quad_is_equal(a,b) result(yes)
type(quad_t), intent(in) :: a,b
logical :: yes
yes = (a%level == b%level) .and. all(a%morton == b%morton)
end function
!! ------------------------------------------------------------------------- !!
!! ------------------------------------------------------------------------- !!
pure function vert_get_dist(a,b) result(dist)
type(vert_t), intent(in) :: a,b
real(dp) :: dist
real(dp) :: v(N_DIMS)
v = vert_get_coords(b) - vert_get_coords(a)
dist = SQRT(SUM(v*v))
end function
pure function vert_get_coords(vert) result(coords)
use mesh_const_mod, only: map_to_opposite_vertid
type(vert_t), intent(in) :: vert
real(dp) :: coords(N_DIMS)
real(dp) :: verts(N_DIMS,MESH_CORNERS)
verts = quad_get_vertices(vert%mesh%quads(vert%iquads(vert%refquad)))
coords = verts(:,map_to_opposite_vertid(vert%refquad))
end function
pure function side_get_coords(side) result(coords)
type(side_t), intent(in) :: side
# if PP_N_DIMS == 2
real(dp) :: coords(N_NODES,N_DIMS)
# elif PP_N_DIMS == 3
real(dp) :: coords(N_NODES,N_NODES,N_DIMS)
# endif
coords = quad_get_face_coords(side%quads(1,side%inner)%p,side%faceid(side%inner))
end function
function quad_is_family(family) result(ok)
use mesh_const_mod, only: MESH_CHILDREN
use p4est_constants_mod, only: P4EST_MAXLEVEL
! use p4est_interfaces_mod, only: p4est_quadrant_is_family
type(quad_t), intent(in) :: family(MESH_CHILDREN)
logical :: ok
integer :: i
integer(kind=4) :: inc
ok = .false.
if (family(1)%level == 0) return
do i = 2,MESH_CHILDREN
if (family(1)%level /= family(i)%level) then
ok = .false.
return
end if
end do
!! #define P4EST_QUADRANT_LEN(l) ((p4est_qcoord_t) 1 << (P4EST_MAXLEVEL - (l)))
!inc = LSHIFT(1,P4EST_MAXLEVEL-family(1)%level)
inc = family(2)%morton(1) - family(1)%morton(1)
! write (*,*) 'first level!', inc, family(1)%morton(1), family(2)%morton(1), family(2)%morton(1) - family(1)%morton(1)
# if PP_N_DIMS == 2
!! ((q0->x + inc == q1->x && q0->y == q1->y) &&
!! (q0->x == q2->x && q0->y + inc == q2->y) &&
!! (q1->x == q3->x && q2->y == q3->y))
if (family(1)%morton(1) + inc == family(2)%morton(1) .and. family(1)%morton(2) == family(2)%morton(2)) then
if (family(1)%morton(1) == family(3)%morton(1) .and. family(1)%morton(2) + inc == family(3)%morton(2)) then
if (family(2)%morton(1) == family(4)%morton(1) .and. family(3)%morton(2) == family(4)%morton(2)) then
ok = .true.
end if; end if; end if
# elif PP_N_DIMS == 3
!! ((q0->x + inc == q1->x && q0->y == q1->y && q0->z == q1->z) &&
!! (q0->x == q2->x && q0->y + inc == q2->y && q0->z == q2->z) &&
!! (q1->x == q3->x && q2->y == q3->y && q0->z == q3->z) &&
!! (q0->x == q4->x && q0->y == q4->y && q0->z + inc == q4->z) &&
!! (q1->x == q5->x && q1->y == q5->y && q4->z == q5->z) &&
!! (q2->x == q6->x && q2->y == q6->y && q4->z == q6->z) &&
!! (q3->x == q7->x && q3->y == q7->y && q4->z == q7->z))
if (family(1)%morton(1) + inc == family(2)%morton(1) .and. family(1)%morton(2) == family(2)%morton(2) .and. family(1)%morton(3) == family(2)%morton(3)) then
!write (*,*) 'check 1'
if (family(1)%morton(1) == family(3)%morton(1) .and. family(1)%morton(2) + inc == family(3)%morton(2) .and. family(1)%morton(3) == family(3)%morton(3)) then
!write (*,*) 'check 2'
if (family(2)%morton(1) == family(4)%morton(1) .and. family(3)%morton(2) == family(4)%morton(2) .and. family(1)%morton(3) == family(4)%morton(3)) then
!write (*,*) 'check 3'
if (family(1)%morton(1) == family(5)%morton(1) .and. family(1)%morton(2) == family(5)%morton(2) .and. family(1)%morton(3) + inc == family(5)%morton(3)) then
!write (*,*) 'check 4'
if (family(2)%morton(1) == family(6)%morton(1) .and. family(2)%morton(2) == family(6)%morton(2) .and. family(5)%morton(3) == family(6)%morton(3)) then
!write (*,*) 'check 5'
if (family(3)%morton(1) == family(7)%morton(1) .and. family(3)%morton(2) == family(7)%morton(2) .and. family(5)%morton(3) == family(7)%morton(3)) then
!write (*,*) 'check 6'
if (family(4)%morton(1) == family(8)%morton(1) .and. family(4)%morton(2) == family(8)%morton(2) .and. family(5)%morton(3) == family(8)%morton(3)) then
!write (*,*) 'check 7'
ok = .true.
end if; end if; end if; end if; end if; end if; end if
# endif
end function
end module
|
From Undecidability.L Require Import L Tactics.LTactics LBool.
(*From Undecidability.L.Complexity Require Import Monotonic UpToC.*)
Class eqbClass X (eqb : X -> X -> bool): Type :=
_eqb_spec : forall (x y:X), reflect (x=y) (eqb x y).
Hint Mode eqbClass + -: typeclass_instances. (* treat argument as input and force evar-freeness*)
Definition eqb X eqb `{H:eqbClass (X:=X) eqb} := eqb.
Arguments eqb {_ _ _}: simpl never.
Lemma eqb_spec {X} {f : X -> X -> bool} {_:eqbClass f}:
forall (x y:X), reflect (x=y) (eqb x y).
Proof.
intros. eapply _eqb_spec.
Qed.
Instance eqbBool_inst : eqbClass Bool.eqb.
Proof.
intros ? ?. eapply iff_reflect. rewrite eqb_true_iff. reflexivity.
Qed.
Lemma dec_reflect_remove {P Y} (d:dec P) b (H:reflect P b) (y y' : Y):
(if d then y else y') = (if b then y else y').
Proof.
destruct H,d;easy.
Qed.
Lemma eqDec_remove {X Y eqb} {H:eqbClass (X:=X) eqb} x x' (d:dec (x=x')) (a b : Y):
(if d then a else b) = (if eqb x x' then a else b).
Proof.
apply dec_reflect_remove. eapply eqb_spec.
Qed.
Class eqbCompT X {R:encodable X} eqb {H:eqbClass (X:=X) eqb} :=
{ c__eqbComp :nat;
eqbTime x y:= min x y* c__eqbComp;
comp_eqb : computableTime' eqb (fun x _ =>(5,fun y _ => (eqbTime (size (enc x)) (size (enc y)),tt)))
}.
Arguments eqbCompT _ {_ _ _}.
Arguments c__eqbComp _ {_ _ _ _}.
Hint Mode eqbCompT + - - -: typeclass_instances.
Existing Instance comp_eqb.
Instance eqbComp_bool : eqbCompT bool.
Proof.
evar (c:nat). exists c. unfold Bool.eqb.
unfold enc;cbn.
extract.
solverec.
[c]:exact 3.
all:unfold c;try lia.
Qed.
Lemma eqbTime_le_l X {R : encodable X} (eqb : X -> X -> bool) {H : eqbClass eqb}
{H' : eqbCompT X} x n':
eqbTime (X:=X) x n' <= x * c__eqbComp X.
Proof.
unfold eqbTime. rewrite Nat.le_min_l. easy.
Qed.
Lemma eqbTime_le_r X (R : encodable X) (eqb : X -> X -> bool) (H : eqbClass eqb)
(eqbCompT : eqbCompT X) x n':
eqbTime (X:=X) n' x <= x * c__eqbComp X.
Proof.
unfold eqbTime. rewrite Nat.le_min_r. easy.
Qed.
(*
Lemma eqbTime_upToC X {R:encodable X} eqb {H:eqbClass (X:=X) eqb} {_:eqbCompT X}:
eqbTime (X:=X) <=c (fun (x y:nat) => min x y).
Proof.
unfold eqbTime. hnf.
exists (c__eqbComp X). unfold leHO;repeat intro; cbn;nia.
Qed.
*)
|
State Before: C : Type u
instβΒ² : Category C
D : Type u'
instβΒΉ : Category D
instβ : HasZeroMorphisms C
X : C
h : π X = 0
Y : C
f : X βΆ Y
β’ f = default State After: C : Type u
instβΒ² : Category C
D : Type u'
instβΒΉ : Category D
instβ : HasZeroMorphisms C
X : C
h : π X = 0
Y : C
f : X βΆ Y
β’ 0 = default Tactic: rw [β id_comp f, β id_comp (0: X βΆ Y), h, zero_comp, zero_comp] State Before: C : Type u
instβΒ² : Category C
D : Type u'
instβΒΉ : Category D
instβ : HasZeroMorphisms C
X : C
h : π X = 0
Y : C
f : X βΆ Y
β’ 0 = default State After: no goals Tactic: simp only State Before: C : Type u
instβΒ² : Category C
D : Type u'
instβΒΉ : Category D
instβ : HasZeroMorphisms C
X : C
h : π X = 0
Y : C
f : Y βΆ X
β’ f = default State After: C : Type u
instβΒ² : Category C
D : Type u'
instβΒΉ : Category D
instβ : HasZeroMorphisms C
X : C
h : π X = 0
Y : C
f : Y βΆ X
β’ 0 = default Tactic: rw [β comp_id f, β comp_id (0 : Y βΆ X), h, comp_zero, comp_zero] State Before: C : Type u
instβΒ² : Category C
D : Type u'
instβΒΉ : Category D
instβ : HasZeroMorphisms C
X : C
h : π X = 0
Y : C
f : Y βΆ X
β’ 0 = default State After: no goals Tactic: simp only
|
function [fboxes,cs] = transfer_friends(models, bboxes)
%transfer friends onto detections
error('deprecated function.. see VOCinit');
VOCinit;
% if isfield(models{i},'detect_add_flip') && models{i}.detect_add_flip == 1
% models{i}.gt_box = flip_box(models{i}.gt_box,[recs.size.height ...
% recs.size.width]);
% end
hasfriends = cellfun(@(x)size(x.friendbb,1),models);
hasfriends = find(hasfriends);
fboxes = cell(1,length(bboxes));
cs = cell(1,length(bboxes));
for i = 1:length(bboxes)
curb = bboxes{i};
goods = ismember(curb(:,6),hasfriends);
curb = curb(goods,:);
fboxes{i} = zeros(0,7);
cs{i} = cell(0,1);
for j = 1:size(curb,1)
exid = curb(j,6);
curg = models{exid}.gt_box;
others = models{exid}.friendbb;
if isfield(models{exid},'detect_add_flip') && models{exid}.detect_add_flip == 1
sizeI = models{exid}.sizeI;
%curg = flip_box(curg,sizeI);
others = flip_box(others,sizeI);
end
xform_cd = find_xform(curg, curb(j,:));
%news = others;
if isfield(models{exid},'detect_add_flip') && models{exid}.detect_add_flip == 1
others = flip_box(others,sizeI);
end
news = apply_xform(others,xform_cd);
%if isfield(models{exid},'detect_add_flip') && models{exid}.detect_add_flip == 1
% news = flip_box(news,sizeI);
%end
news(:,5) = j;
news(:,6) = curb(j,6);
news(:,7) = curb(j,end);
fboxes{i} = [fboxes{i}; news];
cs{i} = [cs{i} models{exid}.friendclass];
end
end
|
@testset "Symmetric" begin
let rng = MersenneTwister(123456), N = 100
for _ in 1:10
X, V, YΜ = randn.(Ref(rng), [N, N, N], [N, N, N])
@test check_errs(Symmetric, YΜ, X, V)
end
end
end
|
[GOAL]
π : Type u_1
A : Type u_2
instββ΄ : NontriviallyNormedField π
instβΒ³ : NormedRing A
instβΒ² : NormedAlgebra π A
instβΒΉ : CompleteSpace A
instβ : ProperSpace π
β’ CompactSpace β(characterSpace π A)
[PROOFSTEP]
rw [β isCompact_iff_compactSpace]
[GOAL]
π : Type u_1
A : Type u_2
instββ΄ : NontriviallyNormedField π
instβΒ³ : NormedRing A
instβΒ² : NormedAlgebra π A
instβΒΉ : CompleteSpace A
instβ : ProperSpace π
β’ IsCompact (characterSpace π A)
[PROOFSTEP]
have h : characterSpace π A β toNormedDual β»ΒΉ' Metric.closedBall 0 β(1 : A)β :=
by
intro Ο hΟ
rw [Set.mem_preimage, mem_closedBall_zero_iff]
exact (norm_le_norm_one β¨Ο, β¨hΟ.1, hΟ.2β©β© : _)
[GOAL]
π : Type u_1
A : Type u_2
instββ΄ : NontriviallyNormedField π
instβΒ³ : NormedRing A
instβΒ² : NormedAlgebra π A
instβΒΉ : CompleteSpace A
instβ : ProperSpace π
β’ characterSpace π A β βtoNormedDual β»ΒΉ' Metric.closedBall 0 β1β
[PROOFSTEP]
intro Ο hΟ
[GOAL]
π : Type u_1
A : Type u_2
instββ΄ : NontriviallyNormedField π
instβΒ³ : NormedRing A
instβΒ² : NormedAlgebra π A
instβΒΉ : CompleteSpace A
instβ : ProperSpace π
Ο : WeakDual π A
hΟ : Ο β characterSpace π A
β’ Ο β βtoNormedDual β»ΒΉ' Metric.closedBall 0 β1β
[PROOFSTEP]
rw [Set.mem_preimage, mem_closedBall_zero_iff]
[GOAL]
π : Type u_1
A : Type u_2
instββ΄ : NontriviallyNormedField π
instβΒ³ : NormedRing A
instβΒ² : NormedAlgebra π A
instβΒΉ : CompleteSpace A
instβ : ProperSpace π
Ο : WeakDual π A
hΟ : Ο β characterSpace π A
β’ ββtoNormedDual Οβ β€ β1β
[PROOFSTEP]
exact (norm_le_norm_one β¨Ο, β¨hΟ.1, hΟ.2β©β© : _)
[GOAL]
π : Type u_1
A : Type u_2
instββ΄ : NontriviallyNormedField π
instβΒ³ : NormedRing A
instβΒ² : NormedAlgebra π A
instβΒΉ : CompleteSpace A
instβ : ProperSpace π
h : characterSpace π A β βtoNormedDual β»ΒΉ' Metric.closedBall 0 β1β
β’ IsCompact (characterSpace π A)
[PROOFSTEP]
exact isCompact_of_isClosed_subset (isCompact_closedBall π 0 _) CharacterSpace.isClosed h
|
State Before: Ξ± : Type u_1
Ξ² : Type ?u.545966
m : MeasurableSpace Ξ±
M : Type u_2
instβΒ² : TopologicalSpace M
instβΒΉ : AddCommMonoid M
instβ : PartialOrder M
v w : VectorMeasure Ξ± M
β’ restrict v β
β€ restrict w β
State After: Ξ± : Type u_1
Ξ² : Type ?u.545966
m : MeasurableSpace Ξ±
M : Type u_2
instβΒ² : TopologicalSpace M
instβΒΉ : AddCommMonoid M
instβ : PartialOrder M
v w : VectorMeasure Ξ± M
j : Set Ξ±
aβ : MeasurableSet j
β’ β(restrict v β
) j β€ β(restrict w β
) j Tactic: intro j _ State Before: Ξ± : Type u_1
Ξ² : Type ?u.545966
m : MeasurableSpace Ξ±
M : Type u_2
instβΒ² : TopologicalSpace M
instβΒΉ : AddCommMonoid M
instβ : PartialOrder M
v w : VectorMeasure Ξ± M
j : Set Ξ±
aβ : MeasurableSet j
β’ β(restrict v β
) j β€ β(restrict w β
) j State After: no goals Tactic: rw [restrict_empty, restrict_empty]
|
State Before: Ξ± : Type u_1
l : Ordnode Ξ±
x : Ξ±
r : Ordnode Ξ±
β’ dual (node' l x r) = node' (dual r) x (dual l) State After: no goals Tactic: simp [node', add_comm]
|
fileID = fopen('rgd_cropped320/rgb_0000_annotationsCropped320.txt','r');
sizeA = [2 inf];
A = fscanf(fileID, '%f %f', sizeA)
imread('rgd_cropped320/rgd_0000Cropped320.png');
figure;
imshow(ans);
hold on;
[row col] = size(A);
for idx = 1:4:col
x = A(1, [idx:idx+3 idx]);
y = A(2, [idx:idx+3 idx]);
plot(x,y);
hold on
end
fclose(fileID);
|
lemma cis_mult: "cis a * cis b = cis (a + b)"
|
module arkaghosh.Odds
import Evens
import Intro
||| inductive type family IsOdd (Ques 1)
data IsOdd : Nat -> Type where
SZOdd : IsOdd (S Z)
SSOdd : (n : Nat) -> (IsOdd n) -> (IsOdd (S (S n)))
||| witness that 3 is odd (Ques 2)
threeOddProof : IsOdd 3
threeOddProof = SSOdd 1 SZOdd
||| witness that 2 is not odd (Ques 3)
total
twoNotOdd : (IsOdd 2) -> Void
twoNotOdd SZOdd impossible -- twoNotOdd will be total even without this line
twoNotOdd (SSOdd Z pf) impossible
||| Property 1 - If n is odd then (S n) is even (Ques 4)
total
prop1 : (n : Nat) -> (IsOdd n) -> (IsEven (S n))
prop1 (S Z) SZOdd = SSEven Z ZEven
prop1 (S (S n)) (SSOdd n pf) = SSEven (S n) (prop1 n pf)
||| Property 2 - If n is even then (S n) is odd (Ques 5)
total
prop2 : (n : Nat) -> (IsEven n) -> (IsOdd (S n))
prop2 Z ZEven = SZOdd
prop2 (S (S n)) (SSEven n pf) = SSOdd (S n) (prop2 n pf)
||| Property 3 - No number is both even and odd (Ques 7)
total
prop3 : (n : Nat) -> (IsOdd n) -> (IsEven n) -> Void
prop3 Z pf ZEven impossible
prop3 (S Z) SZOdd pf impossible
prop3 (S (S n)) (SSOdd n pf1) (SSEven n pf2) = prop3 n pf1 pf2
||| Property 4 - If n and m are odd, then (n + m) is even (Ques 8)
total
prop4 : (n : Nat) -> (m : Nat) -> (IsOdd n) -> (IsOdd m) -> (IsEven (add n m))
prop4 Z m pf1 pf2 impossible
prop4 (S Z) m pf1 pf2 = prop1 m pf2
prop4 (S (S n)) m (SSOdd n pf1) pf2 = SSEven (add n m) (prop4 n m pf1 pf2)
||| Property 5 - Every number n : Nat is either even or odd (Ques 6)
total
prop5 : (n : Nat) -> Either (IsEven n) (IsOdd n)
prop5 Z = Left ZEven
prop5 (S n) = f n (prop5 n)
where f : (m : Nat) -> (Either (IsEven m) (IsOdd m)) -> (Either (IsEven (S m)) (IsOdd (S m)))
f m (Left pf) = Right (prop2 m pf)
f m (Right pf) = Left (prop1 m pf)
||| Congruence : If n = m then f(n) = f(m)
total
congruence : (a : Type) -> (f : a -> a) -> (n : a) -> (m : a) -> (n = m) -> (f(n) = f(m))
congruence typ f n n Refl = Refl
||| Property 6 - if n is odd, then there exists m such that n = 2m + 1 (Ques 9)
total
prop6 : (n : Nat) -> (IsOdd n) -> ( k: Nat ** S(double k) = n )
prop6 (S Z) SZOdd = (Z ** Refl)
prop6 (S (S n)) (SSOdd n pf) = ( (S m) ** pf1)
where m : Nat
pf2 : S(double m) = n
m = fst(prop6 n pf)
pf2 = snd(prop6 n pf)
pf1 : S(double (S m)) = (S (S n))
pf1 = congruence Nat f (S(double m)) n pf2
where f : Nat -> Nat
f x = S( S x)
|
[GOAL]
R : Type u_1
instβ : CommRing R
r : R
β’ β(aeval (IsLocalization.Away.invSelf r)) (βC r * X - 1) = 0
[PROOFSTEP]
simp only [map_sub, map_mul, aeval_C, aeval_X, IsLocalization.Away.mul_invSelf, aeval_one, sub_self]
|
program TestSstWrite
use sst_test_data
use adios2
implicit none
integer(kind = 8), dimension(1)::shape_dims, start_dims, count_dims
integer(kind = 8), dimension(2)::shape_dims2, start_dims2, count_dims2
integer(kind = 8), dimension(2)::shape_dims3, start_dims3, count_dims3
integer(kind = 8), dimension(1)::shape_time, start_time, count_time
integer::inx, irank, isize, ierr, i, insteps, status
type(adios2_adios)::adios
type(adios2_io)::ioWrite, ioRead
type(adios2_variable), dimension(20)::variables
type(adios2_engine)::sstWriter;
!read handlers
character(len =:), allocatable::variable_name
integer::variable_type, ndims
integer(kind = 8), dimension(:), allocatable::shape_in
integer(kind = 8)::localtime
! No MPI
irank = 0;
isize = 1;
!Application variables
insteps = 10;
!Variable dimensions
shape_dims(1) = isize * nx
start_dims(1) = irank * nx
count_dims(1) = nx
shape_dims2 = (/ 2, isize *nx /)
start_dims2 = (/ 0, irank *nx /)
count_dims2 = (/ 2, nx /)
shape_dims3 = (/ isize *nx, 2 /)
start_dims3 = (/ irank *nx, 0 /)
count_dims3 = (/ nx, 2 /)
shape_time = (/ isize /)
start_time = (/ irank /)
count_time = (/ 1 /)
!Create adios handler passing the communicator, debug mode and error flag
call adios2_init_nompi(adios, adios2_debug_mode_on, ierr)
!!!!!!!!!!!!!!!!!!!!!!!!!WRITER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!Declare an IO process configuration inside adios
call adios2_declare_io(ioWrite, adios, "ioWrite", ierr)
call adios2_set_engine(ioWrite, "Sst", ierr)
!Defines a variable to be written
call adios2_define_variable(variables(12), ioWrite, "scalar_r64", &
adios2_type_dp, ierr)
call adios2_define_variable(variables(1), ioWrite, "i8", &
adios2_type_integer1, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(2), ioWrite, "i16", &
adios2_type_integer2, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(3), ioWrite, "i32", &
adios2_type_integer4, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(4), ioWrite, "i64", &
adios2_type_integer8, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(5), ioWrite, "r32", &
adios2_type_real, 1, &
shape_dims, start_dims, count_dims,&
adios2_constant_dims, ierr)
call adios2_define_variable(variables(6), ioWrite, "r64", &
adios2_type_dp, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(7), ioWrite, "r64_2d", &
adios2_type_dp, 2, &
shape_dims2, start_dims2, count_dims2, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(8), ioWrite, "r64_2d_rev", &
adios2_type_dp, 2, &
shape_dims3, start_dims3, count_dims3, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(9), ioWrite, "time", &
adios2_type_integer8, 1, &
shape_time, start_time, count_time, &
adios2_constant_dims, ierr)
call adios2_define_variable(variables(10), ioWrite, "c32", &
adios2_type_complex, 1, &
shape_dims, start_dims, count_dims,&
adios2_constant_dims, ierr)
call adios2_define_variable(variables(11), ioWrite, "c64", &
adios2_type_complex_dp, 1, &
shape_dims, start_dims, count_dims, &
adios2_constant_dims, ierr)
call adios2_open(sstWriter, ioWrite, "ADIOS2Sst", adios2_mode_write, ierr)
!Put array contents to bp buffer, based on var1 metadata
do i = 1, insteps
call GenerateTestData(i - 1, irank, isize)
call adios2_begin_step(sstWriter, adios2_step_mode_append, 0.0, status, &
ierr)
call adios2_put(sstWriter, variables(12), data_scalar_r64, ierr)
call adios2_put(sstWriter, variables(1), data_I8, ierr)
call adios2_put(sstWriter, variables(2), data_I16, ierr)
call adios2_put(sstWriter, variables(3), data_I32, ierr)
call adios2_put(sstWriter, variables(4), data_I64, ierr)
call adios2_put(sstWriter, variables(5), data_R32, ierr)
call adios2_put(sstWriter, variables(6), data_R64, ierr)
call adios2_put(sstWriter, variables(7), data_R64_2d, ierr)
call adios2_put(sstWriter, variables(8), data_R64_2d_rev, ierr)
localtime = 0 ! should be time(), but non-portable and value is unused
call adios2_put(sstWriter, variables(9), loc(localtime), ierr)
call adios2_put(sstWriter, variables(10), data_C32, ierr)
call adios2_put(sstWriter, variables(11), data_C64, ierr)
call adios2_end_step(sstWriter, ierr)
end do
!Closes engine1 and deallocates it, becomes unreachable
call adios2_close(sstWriter, ierr)
!Deallocates adios and calls its destructor
call adios2_finalize(adios, ierr)
end program TestSstWrite
|
[STATEMENT]
lemma rk_split_card:
"y \<notin> set xs \<Longrightarrow> distinct xs \<Longrightarrow> rk (xs @ y # zs) y = Some (card (set xs))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>y \<notin> set xs; distinct xs\<rbrakk> \<Longrightarrow> rk (xs @ y # zs) y = Some (card (set xs))
[PROOF STEP]
using rk_split
[PROOF STATE]
proof (prove)
using this:
?y \<notin> set ?xs \<Longrightarrow> rk (?xs @ ?y # ?zs) ?y = Some (length ?xs)
goal (1 subgoal):
1. \<lbrakk>y \<notin> set xs; distinct xs\<rbrakk> \<Longrightarrow> rk (xs @ y # zs) y = Some (card (set xs))
[PROOF STEP]
by (metis length_remdups_card_conv remdups_id_iff_distinct)
|
= = = City services = = =
|
import Base: haskey, getindex, setindex!, delete!
export RedBlackTree
###
#
# Red Black Tree
#
# Supported functionality
# - haskey
#
###
# TODO Can this be re-used somewhere?
# TODO Put this in tree.jl or try to get this out of DataStructures?
abstract Tree{K,V}
type RedBlackTreeNode{K,V} <: Tree{K,V}
key::K
value::V
left::Union(Nothing, Tree{K,V})
right::Union(Nothing, Tree{K,V})
end
type RedBlackTree{K,V} <: Tree{K,V}
root::Union(Nothing, RedBlackTreeNode{K,V})
red::Bool
#RedBlackTree() = new(EmptyTree{K,V}())
# Well, this is kind of weird.. is there a way to do this so that we don't have to this to avoid instantiating instances of EmptyTree?
# RedBlackTree(key::V, value::K) = new(RedBlackTreeNode{K,V}(key, value, EmptyTree{K,V}(), EmptyTree{K,V}()))
# Is this right?
RedBlackTree(key::V, value::K) = new(RedBlackTreeNode{K,V}(key, value, nothing, nothing))
end
_isred(tree::Nothing) = false
_isred(tree::RedBlackTree) = tree.red
haskey(tree::Nothing, key) = false
function haskey(tree::RedBlackTree, key)
rootkey = tree.root
if key == rootkey
return true
elseif key < rootkey
return haskey(tree.left, key)
else
return haskey(tree.right, key)
end
end
export RedBlackTree
|
Formal statement is: lemma distr_id2: "sets M = sets N \<Longrightarrow> distr N M (\<lambda>x. x) = N" Informal statement is: If two measures have the same sets, then the identity map is a measure isomorphism.
|
SUBROUTINE IFP1PC (I81,ICONT,POCARD,ORG,PORG)
C
C SUBROUTINE TO PERFORM FIRST-LEVEL CHECKING OF STRUCTURE PLOTTER
C CONTROL CARD FORMAT.
C
IMPLICIT INTEGER (A-Z)
EXTERNAL RSHIFT,COMPLF
LOGICAL FLAG(3),BIT64
INTEGER CASE(400),CTYPE(21),IDVPR(3),CAMERA(5),ORIGIN(11),
1 AXES(3),MAXES(3),CNTUR(20),SETPR(33),SETP2(12),
2 COORD(25),LBLPR(5),PLTPR(28),NAST(2),POCARD(1),
3 CORE(1),COREY(401)
CHARACTER UFM*23,UWM*25
COMMON /XMSSG / UFM,UWM
COMMON /SYSTEM/ ISYS,NOUT,NOGO,SKP(16),PLTOPT,SYS21,ILINK,
1 SKP63(63),INTRA
COMMON /XIFP1 / BLANK,BIT64
COMMON /ZZZZZZ/ COREX(1)
EQUIVALENCE (PROJ,CTYPE(11)), (DEFO,IDVPR( 1)),
1 (SYMM,PLTPR(13)), (ANTI,PLTPR(14)),
2 (MAGN,CNTUR(13)), (THRU,PLTPR(22)),
3 (POIN,LBLPR( 2)), (CORE(1),COREY(401)),
4 (COREX(1),COREY(1),CASE(1)), (HIDD,PLTPR(24))
DATA CTYPE / 4HPLOT, 4HORTH, 4HPERS, 4HSTER, 4HAXES, 4HVIEW,
1 4HMAXI, 4HCSCA, 4HFIND, 4HCONT, 4HPROJ, 4HOCUL,
2 4HCAME, 4HPAPE, 4HPEN , 4HPTIT, 4HSCAL, 4HORIG,
3 4HVANT, 4HSET , 4HREGI/
DATA CAMERA/ 4HFILM, 4HPAPE, 4HBOTH, 4HBLAN, 4HFRAM/
DATA AXES / 4HX , 4HY , 4HZ /
DATA MAXES / 4HMX , 4HMY , 4HMZ /
DATA CNTUR / 4HMAJP, 4HMINP, 4HMAXS, 4HXNOR, 4HYNOR, 4HZNOR,
1 4HXYSH, 4HXZSH, 4HYZSH, 4HXDIS, 4HYDIS, 4HZDIS,
2 4HMAGN, 4HNRM1, 4HNRM2, 4HSH12, 4HSH1Z, 4HSH2Z,
3 4HBDSH, 4HSTRA/
DATA SETPR / 4HINCL, 4HEXCL, 4HEXCE, 4HELEM, 4HGRID, 4HALL ,
1 4HAERO, 4HAXIF, 4HBAR , 4HCONE, 4HCONR, 4HHEXA,
2 4HFLUI, 4HIHEX, 4HPLOT, 4HQDME, 4HQDPL, 4HQUAD,
3 4HROD , 4HSHEA, 4HSLOT, 4HTETR, 4HTORD, 4HTRAP,
4 4HTRBS, 4HTRIA, 4HTRME, 4HTRPL, 4HTUBE, 4HTWIS,
5 4HVISC, 4HWEDG, 4HHBDY/
DATA SETP2 / 4HAX , 4HRG , 4H1 , 4H2 , 4H3 , 4H4 ,
1 4HD2 , 4HD3 , 4HD4 , 4HM , 4HM1 , 4HM2 /
DATA PLTPR / 4HSET , 4HSTAT, 4HMODA, 4HCMOD, 4HFREQ, 4HTRAN,
1 4HCONT, 4HRANG, 4HTIME, 4HPHAS, 4HMAGN, 4HORIG,
2 4HSYMM, 4HANTI, 4HPEN , 4HDENS, 4HSYMB, 4HLABE,
3 4HSHAP, 4HVECT, 4HOUTL, 4HTHRU, 4HMAXI, 4HHIDD,
4 4HSHRI, 4HNOFI, 4HFILL, 4HOFFS/
DATA IDVPR / 4HDEFO, 4HVELO, 4HACCE/
DATA COORD / 4HYX , 4HZX , 4HZY , 4HXY , 4HXZ , 4HYZ ,
1 4HX , 4HY , 4HZ ,
2 4HXYZ , 4HRXY , 4HRXZ , 4HRYZ , 4HR , 4HRN ,
3 4HXN , 4HYN , 4HZN , 4HXYN , 4HXZN , 4HYZN ,
4 4HXYZN, 4HRXYN, 4HRXZN, 4HRYZN /
DATA LBLPR / 4HGRID, 4HPOIN, 4HELEM, 4HBOTH, 4HEPID/
DATA TER / 4HTER /, PLAN / 4HPLAN/, SEPA / 4HSEPA/
DATA LAG / 4HLAG /, NAST / 4HSC , 4HCALC/,ILNK / 4HNS01/
C
C
C INITIALIZE
C
IF (INTRA.LE.1 .AND. ILINK.EQ.ILNK) GO TO 15
DO 5 I = 1,200
5 CORE(I)= POCARD(I)
15 ALLON = COMPLF(0)
EOR = RSHIFT(ALLON,1)
ISPLOT = 0
IWRD = I81
C
C BRANCH FOR CONTINUATION CARD
C SET PLOT FIND
IF (ICONT .NE. 0) GO TO (10, 2111, 2210, 1067), ICONT
C
IF (CORE(IWRD)) 9800,350,20
10 IF (CORE(IWRD) .LE. 0) GO TO 320
20 IF (CORE(IWRD) .EQ. EOR) GO TO 350
MODE = CORE(IWRD)
IWRD = IWRD + 1
C
C BRANCH FOR CARD TYPE
C
100 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
DO 300 I = 1,20
IF (IWORD .EQ. CTYPE(I))
1 GO TO (400, 500, 500, 500, 600, 700, 800, 900, 1000,
2 1100, 1200, 1300, 1400, 320, 320, 320, 1800, 1900,
3 2000, 2100), I
C
C 1 PLOT ORTH PERS STER AXES VIEW MAXI CSCA FIND
C 2 CONT PROJ OCUL CAME PAPE PEN PTIT SCAL ORIG
C 3 VANT SET
C
300 CONTINUE
GO TO 9802
320 IF (MODE .LE. 0) GO TO 330
IWRD = IWRD + 2
MODE = MODE - 1
GO TO 320
330 IF (CORE(IWRD)) 335,340,340
335 IF (CORE(IWRD) .EQ. -4) IWRD = IWRD + 1
IWRD = IWRD + 2
GO TO 330
340 IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 350
MODE = CORE(IWRD)
IWRD = IWRD + 1
GO TO 320
350 ICONT = 0
IF (CORE(IWRD) .EQ. 0) ICONT = 1
GO TO 9998
C
C BRANCH TO PLOT OR PLOTTER
C
400 IWORD = CORE(IWRD+1)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. TER) GO TO 410
ISPLOT = 1
GO TO 2200
C
C PLOTTER CARD
C
410 IWORD = CORE(IWRD+2)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD.EQ.NAST(1) .OR. IWORD.EQ.NAST(2)) GO TO 9804
GO TO 320
C
C PROJECTION CARD
C
500 IWRD = IWRD + 2
MODE = MODE - 1
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. PROJ) GO TO 510
ASSIGN 510 TO IRTN
IPRM = PROJ
GO TO 9806
510 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 330,330,100
C
C AXES CARD
C
600 IWRD = IWRD + 2
MODE = MODE - 1
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 600
DO 605 J = 1,3
605 FLAG(J) = .FALSE.
I = 0
GO TO 607
606 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
607 IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 610
DO 608 J = 1,3
IF (IWORD.EQ.AXES(J) .OR. IWORD.EQ.MAXES(J)) FLAG(J) = .TRUE.
608 CONTINUE
I = I + 1
610 IWRD = IWRD + 2
MODE = MODE - 1
IF (I .LT. 3) GO TO 606
C
ASSIGN 320 TO IRTN
IF (.NOT.FLAG(1) .OR. .NOT.FLAG(2) .OR. .NOT.FLAG(3)) GO TO 9810
620 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD.EQ.SYMM .OR. IWORD.EQ.ANTI) GO TO 630
IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 350
IF (CORE(IWRD).NE.ALLON .AND. IWORD.NE.BLANK) GO TO 100
IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 9812,9812,620
630 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 330,330,100
C
C VIEW COMMAND
C
700 NREAL = 3
NOPT = 0
GO TO 1310
C
C MAXIMUM DEFORMATION CARD
C
800 NREAL = 1
NOPT = 0
IWORD = CORE(IWRD+2)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. DEFO) GO TO 1310
ASSIGN 320 TO IRTN
IPRM = CORE(IWRD+2)
GO TO 9808
C
C CSCALE CARD
C
900 ASSIGN 320 TO IRTN
910 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 930,930,920
920 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 910
GO TO 9812
930 IF (CORE(IWRD)+1) 960,940,9816
940 WRITE (NOUT,950)
950 FORMAT (/5X,'REAL VALUE, NOT INTEGER, IS NOW USED FOR CSCALE')
GO TO 9816
C
960 NREAL = 1
NOPT = 0
GO TO 1700
C
C FIND COMMAND
C
1000 IWRD = IWRD + 2
MODE = MODE - 1
1005 IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 1080
ASSIGN 1070 TO IRTN
IF (MODE) 9812,9812,1006
1006 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1000
DO 1008 I = 17,21
ITYPE = I - 16
IF (IWORD .EQ. CTYPE(I))
1 GO TO (1020, 1030, 1040, 1030, 1050), ITYPE
C SCAL ORIG VANT SET REGI
C
1008 CONTINUE
IPRM = CORE(IWRD)
GO TO 9808
C
1020 NREAL = 1
1021 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE .LE. 0) GO TO 1061
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1021
GO TO 1005
C
1030 IPRM = CORE(IWRD)
ASSIGN 1005 TO IRTN
1031 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 1033,1033,1032
1032 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1031
GO TO 9814
1033 INTEG = 1
IF (CORE(IWRD) .EQ. EOR) GO TO 9814
IF (CORE(IWRD) .EQ. -1) INTEG = 0
IF (CORE(IWRD) .EQ. -4) IWRD = IWRD + 1
IF (ITYPE .NE. 2) GO TO 1034
FORG = CORE(IWRD+1)
ORG = ORG + 1
ORIGIN(ORG) = FORG
1034 IWRD = IWRD + 2
IF (PORG .GE. 0) GO TO 1066
PORG = 0
PORG1 = FORG
GO TO 1066
C
1040 IWRD = IWRD + 2
MODE = MODE - 1
ASSIGN 1070 TO IRTN
IF (MODE) 1041,1041,1042
1041 IPRM = POIN
GO TO 9806
1042 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. POIN) GO TO 1000
IPRM = CORE(IWRD)
GO TO 9808
C
1050 NREAL = 4
1060 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE .LE. 0) GO TO 1062
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1060
GO TO 9818
1061 IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 1080
1062 INTEG = 0
ASSIGN 1005 TO IRTN
DO 1065 I = 1,NREAL
IF (CORE(IWRD) .EQ. -1) INTEG = 1
IF (CORE(IWRD) .EQ. -4) IWRD = IWRD + 1
IWRD = IWRD + 2
1065 CONTINUE
1066 IF (INTEG) 1067,1067,9816
1067 IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 1080
MODE = CORE(IWRD)
IWRD = IWRD + 1
GO TO 1005
C
1070 IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 1080
IWRD = IWRD + 1
GO TO 1070
1080 ICONT = 0
IF (CORE(IWRD) .EQ. 0) ICONT = 4
GO TO 9998
C
C CONTOUR
C
1100 IWRD = IWRD + 2
MODE = MODE - 1
ASSIGN 320 TO IRTN
1105 IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 350
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1110
DO 1108 I = 1,20
IF (IWORD .EQ. CNTUR(I)) GO TO 320
1108 CONTINUE
IPRM = CORE(IWRD)
GO TO 9808
1110 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 9812,9812,1105
C
C PROJECTION PLANE SEPARATION
C
1200 IWRD = IWRD + 2
MODE = MODE - 1
ASSIGN 320 TO IRTN
IF (MODE) 1210,1210,1220
1210 IPRM = PLAN
GO TO 9806
1220 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .NE. PLAN) GO TO 1231
IWORD = CORE(IWRD+2)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. SEPA) GO TO 1240
1231 IPRM = CORE(IWRD)
GO TO 9808
1240 NREAL = 1
NOPT = 0
GO TO 1310
C
C OCULAR SEPARATION
C
1300 NREAL = 1
NOPT = 0
IWORD = CORE(IWRD+2)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. SEPA) GO TO 1310
ASSIGN 320 TO IRTN
IPRM = CORE(IWRD+2)
GO TO 9808
C
1310 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 1700,1700,1310
C
C CAMERA
C
1400 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE .LE. 0) GO TO 1420
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK ) GO TO 1400
IF (CORE(IWRD).EQ.EOR .OR. CORE(IWRD).EQ.0) GO TO 9820
DO 1410 I = 1,4
IF (IWORD .EQ. CAMERA(I)) GO TO 1415
1410 CONTINUE
IPRM = CORE(IWRD)
ASSIGN 320 TO IRTN
GO TO 9808
1415 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE .LE. 0) GO TO 1420
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1415
I = I + 1
IF (IWORD.EQ.CAMERA(4) .OR. IWORD.EQ.CAMERA(5)) GO TO 1415
ASSIGN 320 TO IRTN
IF (I-4) 100,9812,100
1420 IF (CORE(IWRD).EQ.EOR .OR. CORE(IWRD).EQ.0) IF (I-3) 350,350,9820
ASSIGN 320 TO IRTN
IF (CORE(IWRD)+1) 9816,1430,9816
1430 IWRD = IWRD + 2
GO TO 10
C
C TEST FOR REAL VALUES
C
1700 IRO = 0
NRO = NREAL
1710 INTEG = 0
ASSIGN 320 TO IRTN
DO 1720 I = 1,NRO
IF (CORE(IWRD).GE.0 .OR. CORE(IWRD).LT.-4) IF (IRO) 9818,9818,1712
1712 IF (CORE(IWRD) .EQ. -1) INTEG = 1
IF (CORE(IWRD) .EQ. -4) IWRD = IWRD + 1
IWRD = IWRD + 2
1720 CONTINUE
IF (INTEG .EQ. 0) GO TO 1730
ASSIGN 1730 TO IRTN
GO TO 9816
1730 IF (CORE(IWRD)) 1740,350,20
1740 IF (IRO.EQ.1 .OR. NOPT.EQ.0) GO TO 9812
IRO = 1
NRO = NOPT
GO TO 1710
C
C SCALE
C
1800 NREAL = 1
NOPT = 1
GO TO 1310
C
C ORIGIN
C
1900 NREAL = 3
NOPT = 0
1905 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 1907,1907,1906
1906 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1905
1907 IF (CORE(IWRD) .EQ. -1) GO TO 1910
IPRM = CTYPE(18)
ASSIGN 320 TO IRTN
GO TO 9814
1910 IF (CORE(IWRD) .EQ. -4) IWRD = IWRD + 1
IWRD = IWRD + 2
ASSIGN 320 TO IRTN
IF (CORE(IWRD) .EQ. EOR) GO TO 9818
IF (CORE(IWRD) .LT. 0) GO TO 1700
MODE = CORE(IWRD)
IWRD = IWRD + 1
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 1310
GO TO 9812
C
C VANTAGE POINT
C
2000 NREAL = 3
NOPT = 1
IWORD = CORE(IWRD+2)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. POIN) GO TO 1310
ASSIGN 320 TO IRTN
IPRM = CORE(IWRD+2)
GO TO 9808
C
C SET DEFINITION CARD
C
2100 NINT = 0
NTHRU= 0
2105 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2106,2106,2108
2106 IF (CORE(IWRD) .EQ. -1) GO TO 2110
ASSIGN 2107 TO IRTN
GO TO 9816
2107 IF (CORE(IWRD) .EQ. -4) IWRD = IWRD + 1
GO TO 2110
2108 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2105
IPRM = CTYPE(20)
ASSIGN 2120 TO IRTN
GO TO 9814
C
2110 IWRD = IWRD + 2
NREAL = 0
2111 IF (CORE(IWRD)) 2112,2113,2114
2112 NINT = NINT + 1
IF (CORE(IWRD).EQ.-1 .OR. NREAL.NE.0) GO TO 2110
ASSIGN 2110 TO IRTN
GO TO 9816
2113 ICONT = 2
NTHRU = 0
GO TO 9998
2114 IF (CORE(IWRD) .NE. EOR) GO TO 2115
ICONT = 0
GO TO 9998
2115 MODE = CORE(IWRD)
IWRD = IWRD + 1
2120 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).NE.ALLON .AND. IWORD.NE.BLANK) GO TO 2121
IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2111,2111,2120
2121 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .NE. THRU) GO TO 2130
NTHRU = NTHRU + 1
IF (CORE(IWRD-3).EQ.-1 .AND. CORE(IWRD+2).EQ.-1) GO TO 2122
ASSIGN 2123 TO IRTN
NREAL = 1
GO TO 9822
2122 IF (NTHRU .EQ. 1) GO TO 2123
IF (NINT.GE.2 .AND. CORE(IWRD-2).GT.CORE(IWRD-4)) GO TO 2123
ASSIGN 2123 TO IRTN
GO TO 9824
2123 NINT = 0
IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2111,2111,2130
2130 IF (CORE(IWRD) .EQ. 0) GO TO 2113
IF (CORE(IWRD) .EQ. EOR) GO TO 2114
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2135
DO 2132 I = 1,33
IF (IWORD .EQ. SETPR(I))
1 GO TO (2135, 2135, 2135, 2135, 2138, 2135, 2135, 2142, 2135,
2 2135, 2135, 2143, 2144, 2145, 2135, 2146, 2135, 2143,
3 2135, 2135, 2147, 2135, 2135, 2148, 2135, 2149, 2135,
4 2135, 2135, 2135, 2135, 2135, 2135), I
C
C 1 INCL EXCL EXCE ELEM GRID ALL AERO AXIF BAR
C 2 CONE CONR HEXA FLUI IHEX PLOT QDME QDPL QUAD
C 3 ROD SHEA SLOT TETR TORD TRAP TRBS TRIA TRME
C 4 TRPL TUBE TWIS VISCX WEDG HBDY
C
2132 CONTINUE
ASSIGN 2135 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
2135 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE .LE. 0) GO TO 2136
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2135
GO TO 2130
2136 NTHRU = 0
GO TO 2111
C
2138 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2139,2139,2140
2139 ASSIGN 2136 TO IRTN
IPRM = POIN
GO TO 9806
2140 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. POIN) GO TO 2135
ASSIGN 2130 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
C
2142 ISTT = 4
ISTB = 6
GO TO 2150
C
2143 ISTT = 3
ISTB = 6
GO TO 2150
C
2144 ISTT = 7
ISTB = 9
GO TO 2150
C
2145 ISTT = 3
ISTB = 5
GO TO 2150
C
2146 ISTT = 10
ISTB = 12
GO TO 2150
C
2147 ISTT = 5
ISTB = 6
GO TO 2150
C
2148 ISTT = 1
ISTB = 2
GO TO 2150
C
2149 ISTT = 1
ISTB = 5
C
2150 IWORD = CORE(IWRD+1)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
DO 2155 I = ISTT,ISTB
IF (IWORD .EQ. SETP2(I)) GO TO 2135
2155 CONTINUE
ASSIGN 2135 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
C
C PLOT COMMAND CARD
C
2200 IWRD = IWRD + 2
MODE = MODE - 1
2202 IF (CORE(IWRD).EQ.0 .OR. CORE(IWRD).EQ.EOR) GO TO 2215
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2207
DO 2205 I = 1,28
IF (IWORD .EQ. PLTPR(I))
1 GO TO (2208, 2220, 2220, 2220, 2230, 2230, 2207, 2250, 2250,
2 2260, 2207, 2208, 2280, 2280, 2208, 2208, 2208, 2290,
3 2207, 2281, 2207, 2248, 2240, 2207, 2245, 2207, 2207,
4 2208), I
C
C 1 SET STAT MODA CMOD FREQ TRAN CONT RANG TIME
C 2 PHAS MAGN ORIG SYMM ANTI PEN DENS SYMB LABE
C 3 SHAP VECT OUTL THRU MAXI HIDD SHRI NOFI FILL
C 4 OFFS
C
2205 CONTINUE
ASSIGN 2207 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
C
2207 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2210,2210,2202
C
2208 IPRM = CORE (IWRD)
ASSIGN 2202 TO IRTN
2209 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE .LE. 0) GO TO 2210
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2209
GO TO 9814
C
2210 IF (CORE(IWRD) .GE. 0) GO TO 2215
IF (I .NE. 12) GO TO 2214
PORG = CORE(IWRD+1)
IF (ORG .LE. 0) GO TO 9830
DO 2213 I = 1,ORG
IF (PORG .EQ. ORIGIN(I)) GO TO 2214
2213 CONTINUE
GO TO 9830
2214 IWRD = IWRD + 2
GO TO 2210
C
2215 IF (CORE(IWRD) .NE. 0) GO TO 2216
ICONT = 3
GO TO 9998
2216 IF (CORE(IWRD) .NE. EOR) GO TO 2217
ICONT = 0
GO TO 9998
2217 MODE = CORE(IWRD)
IWRD = IWRD + 1
GO TO 2202
C
2220 IPR1 = CORE(IWRD )
IPR2 = CORE(IWRD+1)
IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2222,2222,2223
2222 IPRM = DEFO
ASSIGN 2210 TO IRTN
GO TO 9806
2223 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
DO 2225 I = 1,3
C DEFO VELO ACCE
IF (IWORD .EQ. IDVPR(I)) GO TO (2207, 9826, 9826), I
2225 CONTINUE
ASSIGN 2207 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
C
2230 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2231,2231,2232
2231 ASSIGN 2210 TO IRTN
IPRM = DEFO
GO TO 9806
C
2232 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
DO 2235 I = 1,3
IF (IWORD .EQ. IDVPR(I)) GO TO 2207
2235 CONTINUE
ASSIGN 2207 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
C
2250 NREAL = 2
ASSIGN 2202 TO IRTN
2251 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE .LE. 0) GO TO 2252
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2251
GO TO 9818
2252 INTEG = 0
DO 2255 I = 1,NREAL
IF (CORE(IWRD) .GE. 0) GO TO 2257
IF (CORE(IWRD) .EQ. -1) INTEG = 1
IF (CORE(IWRD) .EQ. -4) IWRD = IWRD + 1
IWRD = IWRD + 2
2255 CONTINUE
IF (INTEG) 2210,2210,2256
2256 ASSIGN 2210 TO IRTN
GO TO 9816
2257 ASSIGN 2215 TO IRTN
GO TO 9818
C
2260 IWRD = IWRD + 2
MODE = MODE - 1
NREAL= 1
IF (MODE) 2261,2261,2262
2261 ASSIGN 2210 TO IRTN
IPRM = LAG
GO TO 9806
2262 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. LAG) GO TO 2251
ASSIGN 2251 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
C
2280 NCRD = 9
ICRD = 1
IVC = 0
GO TO 2282
2281 NCRD = 25
ICRD = 4
IVC = 1
2282 ASSIGN 2210 TO IRTN
IAX = 0
2283 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 9810,9810,2284
2284 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2283
DO 2285 I = ICRD,NCRD
IF (IWORD .EQ. COORD(I)) GO TO 2286
2285 CONTINUE
IF (IAX) 9810,9810,2202
2286 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2215,2215,2287
2287 IF (IVC) 2288,2288,2202
2288 IF (IAX) 2289,2289,2202
2289 IAX = 1
GO TO 2284
C
2290 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2210,2210,2291
2291 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (CORE(IWRD).EQ.ALLON .OR. IWORD.EQ.BLANK) GO TO 2290
DO 2292 I = 1,5
IF (IWORD .EQ. LBLPR(I)) GO TO (2290, 2207, 2207, 2207, 2207), I
C GRID POIN ELEM BOTH EPID
2292 CONTINUE
GO TO 2202
C
2240 IWRD = IWRD + 2
MODE = MODE - 1
IF (MODE) 2241,2241,2242
2241 ASSIGN 2210 TO IRTN
GO TO 9812
2242 IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. DEFO) GO TO 2243
ASSIGN 2243 TO IRTN
IPRM = CORE(IWRD)
GO TO 9808
2243 NREAL = 1
GO TO 2251
C
2245 IWRD = IWRD + 2
IWORD = CORE(IWRD)
IF (BIT64) CALL MVBITS (BLANK,0,32,IWORD,0)
IF (IWORD .EQ. HIDD) GO TO 2207
MODE = MODE - 1
IF (MODE) 2241,2210,2210
C
2248 IF (CORE(IWRD-3).EQ.-1 .AND. CORE(IWRD+2).EQ.-1) GO TO 2207
ASSIGN 2207 TO IRTN
GO TO 9822
C
C SET UP ERROR MESSAGE
C
9800 ASSIGN 9900 TO IERR
MSGNO = 348
GO TO 9890
9802 ASSIGN 9902 TO IERR
MSGNO = 349
GO TO 9890
9804 ASSIGN 9904 TO IERR
MSGNO = 350
GO TO 9895
9806 ASSIGN 9906 TO IERR
MSGNO = 351
GO TO 9890
9808 ASSIGN 9908 TO IERR
MSGNO = 351
GO TO 9890
9810 ASSIGN 9910 TO IERR
MSGNO = 352
GO TO 9890
9812 ASSIGN 9912 TO IERR
MSGNO = 353
GO TO 9890
9814 ASSIGN 9914 TO IERR
MSGNO = 354
GO TO 9895
9816 ASSIGN 9916 TO IERR
MSGNO = 355
GO TO 9890
9818 ASSIGN 9918 TO IERR
MSGNO = 356
GO TO 9890
9820 ASSIGN 9920 TO IERR
MSGNO = 357
GO TO 9895
9822 ASSIGN 9922 TO IERR
MSGNO = 358
GO TO 9890
9824 ASSIGN 9924 TO IERR
MSGNO = 359
GO TO 9890
9826 ASSIGN 9926 TO IERR
MSGNO = 360
GO TO 9890
9828 ASSIGN 9928 TO IERR
MSGNO = 361
GO TO 9895
9830 ASSIGN 9930 TO IERR
MSGNO = 362
GO TO 9895
C
9890 CALL PAGE2 (2)
WRITE (NOUT,9891) UFM,MSGNO
9891 FORMAT (A23,I4)
IF (PLTOPT .LE. 2) NOGO = 1
GO TO 9898
9895 CALL PAGE2 (2)
WRITE (NOUT,9896) UWM,MSGNO
9896 FORMAT (A25,I4)
C
9898 GO TO IERR, (9900,9902,9904,9906,9908,9910,9912,9914,9916,9918,
1 9920,9922,9924,9926,9928,9930)
C
9900 WRITE (NOUT,9901)
9901 FORMAT (5X,'FIRST CHARACTER ON CARD IS NUMERIC. INCORRECT FORMAT',
1 ' OR INCORRECT CONTINUATION ON PREVIOUS CARD')
GO TO 320
C
9902 WRITE (NOUT,9903) CORE(IWRD)
9903 FORMAT (5X,'PLOT COMMAND ',A4,' NOT RECOGNIZED. CHECK SPELLING ',
1 'AND FORMAT ON THIS CARD AND CONTINUATION ON PREVIOUS ONE')
GO TO 320
9904 WRITE (NOUT,9905)
9905 FORMAT (1H+,30X,' - ONLY NASTRAN GENERAL PURPOSE PLOTTER IS ',
1 'SUPPORTED')
GO TO 320
C
9906 WRITE (NOUT,9907) IPRM
9907 FORMAT (1H+,30X,' - KEYWORD ',A4,' NOT FOUND')
GO TO IRTN, (320,1070,2110,2136,2210,510)
C
9908 WRITE (NOUT,9909) IPRM
9909 FORMAT (1H+,30X,' - KEYWORD ',A4,' NOT RECOGNIZED')
GO TO IRTN, (320,1070,2130,2135,2202,2207,2243,2251)
C
9910 WRITE (NOUT,9911)
9911 FORMAT (1H+,30X,' - COORDINATE AXES INCORRECTLY DEFINED')
GO TO IRTN, (320,2210)
C
9912 WRITE (NOUT,9913)
9913 FORMAT (1H+,30X,' - INCORRECT FORMAT')
GO TO IRTN, (320,1070,2210)
C
9914 WRITE (NOUT,9915) IPRM
9915 FORMAT (1H+,30X,3H - ,A4,' IDENTIFICATION NUMBER NOT DEFINED')
GO TO IRTN, (320,1005,1910,2120,2202)
C
9916 WRITE (NOUT,9917)
9917 FORMAT (1H+,30X,' - DATA TYPE IS INCORRECT')
GO TO IRTN, (1005,1730,2107,2110,2210,320)
C
9918 WRITE (NOUT,9919)
9919 FORMAT (1H+,30X,' - ONE OR MORE REQUIRED REAL VALUES MISSING')
GO TO IRTN, (320,1005,2202,2215)
C
9920 WRITE (NOUT,9921)
9921 FORMAT (1H+,30X,' - CAMERA OPTION NOT SPECIFIED')
GO TO 320
C
9922 WRITE (NOUT,9923)
9923 FORMAT (1H+,30X,' - THRU MUST BE PRECEDED AND FOLLOWED BY INTEGER'
1, ' VALUES')
GO TO IRTN, (2123,2207)
C
9924 WRITE (NOUT,9925)
9925 FORMAT (1H+,30X,' - THRU RANGE OVERLAPS RANGE OF PREVIOUS THRU')
GO TO 2123
C
9926 WRITE (NOUT,9927) IPR1,IPR2
9927 FORMAT (1H+,30X,' - ONLY DEFORMATION VALID WITH ',2A4)
GO TO 2207
C
9928 WRITE (NOUT,9929) FORG,PORG
9929 FORMAT (1H+,30X,' - A NEW ORIGIN',I8,' WAS DEFINED IN A FIND ',
1 'CARD, BUT IT IS NOT USED BY THE IMMEDIATE PLOT CARD',
2 /5X,'(ORIGIN',I8,' WILL BE USED FOR THIS PLOT)',/)
GO TO 9999
C
9930 WRITE (NOUT,9931) PORG
9931 FORMAT (1H+,30X,' - ORIGIN',I8,' IS UNDEFINED')
GO TO 2207
C
9998 IF (ISPLOT.EQ.0 .OR. PORG.EQ.-1) RETURN
IF (PORG .EQ. 0) PORG = PORG1
IF (FORG.NE.0 .AND. FORG.NE.PORG) GO TO 9828
9999 FORG = 0
PORG = 0
RETURN
END
|
#include <algorithm>
#include <cstdio>
#include <boost/filesystem.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/format.hpp>
#include "include_base_utils.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "tx_pool.h"
#include "blockchain.h"
#include "blockchain_db/blockchain_db.h"
#include "cryptonote_basic/cryptonote_boost_serialization.h"
#include "cryptonote_config.h"
#include "cryptonote_basic/miner.h"
#include "hardforks/hardforks.h"
#include "misc_language.h"
#include "profile_tools.h"
#include "file_io_utils.h"
#include "int-util.h"
#include "common/threadpool.h"
#include "common/boost_serialization_helper.h"
#include "warnings.h"
#include "crypto/hash.h"
#include "cryptonote_core.h"
#include "ringct/rctSigs.h"
#include "common/perf_timer.h"
#include "common/notify.h"
#include "common/varint.h"
#include "common/pruning.h"
#include "time_helper.h"
#include "string_tools.h"
#include "crypto/rx-hash.h"
namespace cryptonote{
//-----------------------------------------------------------------------------------------------
static bool check_tx_inputs_keyimages_diff(const transaction& tx) const
{
std::unordered_set<crypto::key_image> ki;
for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
if(!ki.insert(tokey_in.k_image).second)
return false;
}
return true;
}
//-----------------------------------------------------------------------------------------------
static bool check_tx_inputs_ring_members_diff(const transaction& tx) const
{
for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
for (size_t n = 1; n < tokey_in.key_offsets.size(); ++n)
if (tokey_in.key_offsets[n] == 0)
return false;
}
return true;
}
//-----------------------------------------------------------------------------------------------
static bool check_tx_inputs_keyimages_domain(const transaction& tx) const
{
std::unordered_set<crypto::key_image> ki;
for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
if (!(rct::scalarmultKey(rct::ki2rct(tokey_in.k_image), rct::curveOrder()) == rct::identity()))
return false;
}
return true;
}
//-----------------------------------------------------------------------------------------------
bool check_tx_semantic(const transaction& tx)
{
if(!tx.vin.size())
{
MERROR_VER("tx with empty inputs, rejected for tx id= " << get_transaction_hash(tx));
return false;
}
if(!check_inputs_types_supported(tx))
{
MERROR_VER("unsupported input types for tx id= " << get_transaction_hash(tx));
return false;
}
if(!check_outs_valid(tx))
{
MERROR_VER("tx with invalid outputs, rejected for tx id= " << get_transaction_hash(tx));
return false;
}
//check if tx use different key images
if(!check_tx_inputs_keyimages_diff(tx))
{
MERROR_VER("tx uses a single key image more than once");
return false;
}
if (!check_tx_inputs_ring_members_diff(tx))
{
MERROR_VER("tx uses duplicate ring members");
return false;
}
if (!check_tx_inputs_keyimages_domain(tx))
{
MERROR_VER("tx uses key image not in the valid domain");
return false;
}
return true;
}
//------------------------------------------------------------------
bool check_tx_outputs(const transaction& tx, tx_verification_context &tvc) const
{
MTRACE("Blockchain::" << __func__);
// in a v2 tx, all outputs must have 0 amount
for (auto &o: tx.vout) {
if (o.amount != 0) {
tvc.m_invalid_output = true;
return false;
}
}
for (const auto &o: tx.vout) {
if (o.target.type() == typeid(txout_to_key)) {
const txout_to_key& out_to_key = boost::get<txout_to_key>(o.target);
if (!crypto::check_key(out_to_key.key)) {
tvc.m_invalid_output = true;
return false;
}
}
}
return true;
}
static bool check_fee( uint64_t fee) const
{
const uint64_t needed_fee= BASE_FEE;
if (fee < BASE_FEE) {
MERROR_VER("transaction fee is not enough: " << print_money(fee) << ", minimum fee: " << print_money(needed_fee));
return false;
}
return true;
}
static std::vector<rct::ctkey> fill_mix_ring(BlockchainDB&db, const txin_to_key& txin) const
{
MTRACE("Blockchain::" << __func__);
std::vector<rct::ctkey> decoys;
const auto oids = cryptonote::relative_output_offsets_to_absolute(tx_in_to_key.key_offsets);
const auto outputs=m_db->get_output_keys(oids);
const auto chain_height=db.get_chain_height();
for (const auto & out: outputs)
{
if (!is_tx_spendtime_unlocked(chain_height,out.unlock_time))
{
MERROR_VER("One of outputs for one of inputs has wrong tx.unlock_time = " << out.unlock_time);
return false;
}
decoys.push_back(rct::ctkey({rct::pk2rct(out.otk), out.commitment}));
}
// rct_signatures will be expanded after this
return decoys;
}
//------------------------------------------------------------------
// This function validates transaction inputs and their keys.
// FIXME: consider moving functionality specific to one input into
// check_tx_input() rather than here, and use this function simply
// to iterate the inputs as necessary (splitting the task
// using threads, etc.)
bool check_tx_inputs(BlockchainDB& db,transaction& tx, tx_verification_context &tvc) const
{
PERF_TIMER(check_tx_inputs);
MTRACE("Blockchain::" << __func__);
size_t sig_index = 0;
try{
// pruned txes are skipped, as they're only allowed in sync-pruned-blocks mode, which is within the builtin hashes
if (tx.pruned)
return true;
if(!check_fee(tx.rct_signatures.txnFee))
{
tvc.m_verifivation_failed = true;
tvc.m_fee_too_low = true;
return false;
}
const auto tx_prefix_hash = cryptonote::get_transaction_prefix_hash(tx);
// from hard fork 2, we require mixin at least 2 unless one output cannot mix with 2 others
// if one output cannot mix with 2 others, we accept at most 1 output that can mix
for (const auto& txin : tx.vin)
{
// non txin_to_key inputs will be rejected below
if (txin.type() == typeid(txin_to_key))
{
const txin_to_key& in_to_key = boost::get<txin_to_key>(txin);
size_t ring_mixin = in_to_key.key_offsets.size() - 1;
if (ring_mixin <2 || ring_mixin>10)
return false;
}
}
// from v7, sorted ins
{
const crypto::key_image *last_key_image = NULL;
for (size_t n = 0; n < tx.vin.size(); ++n)
{
const txin_v &txin = tx.vin[n];
if (txin.type() == typeid(txin_to_key))
{
const txin_to_key& in_to_key = boost::get<txin_to_key>(txin);
if (last_key_image && memcmp(&in_to_key.k_image, last_key_image, sizeof(*last_key_image)) >= 0)
{
MERROR_VER("transaction has unsorted inputs");
tvc.m_verifivation_failed = true;
return false;
}
last_key_image = &in_to_key.k_image;
}
}
}
std::vector<std::vector<rct::ctkey>> mix_rings(tx.vin.size());
for (const auto& txin : tx.vin)
{
const txin_to_key& in_to_key = boost::get<txin_to_key>(txin);
if(db.has_key_image(in_to_key.k_image))
{
MERROR_VER("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key.k_image));
tvc.m_double_spend = true;
return false;
}
// make sure that output being spent matches up correctly with the
// signature spending it.
auto & decoys = mix_rings[sig_index];
decoys=fill_mix_ring(db,in_to_key);
sig_index++;
}
// from version 2, check ringct signatures
// obviously, the original and simple rct APIs use a mixRing that's indexes
// in opposite orders, because it'd be too simple otherwise...
const rct::rctSig &rv = tx.rct_signatures;
switch (rv.type)
{
default: {
// we only accept no signatures for coinbase txes
throw_and_log("Null rct signature on non-coinbase tx");
}
case rct::RCTTypeCLSAG:
{
// message - hash of the transaction prefix
rv.message = rct::hash2rct(tx_prefix_hash);
rv.mixRing=mix_rings;
for (size_t n = 0; n < tx.vin.size(); ++n)
{
rv.p.CLSAGs[n].I = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
}
if (!rct::verRctNonSemanticsSimple(rv))
{
throw_and_log("Failed to check ringct signatures!");
}
break;
}
}
catch(std::exception &ex){
tvc.m_verifivation_failed = true;
return false;
}
return true;
}
}
|
Formal statement is: proposition analytic_continuation: assumes holf: "f holomorphic_on S" and "open S" and "connected S" and "U \<subseteq> S" and "\<xi> \<in> S" and "\<xi> islimpt U" and fU0 [simp]: "\<And>z. z \<in> U \<Longrightarrow> f z = 0" and "w \<in> S" shows "f w = 0" Informal statement is: If $f$ is a holomorphic function on an open connected set $S$, and $U$ is a subset of $S$ such that $f$ is zero on $U$ and $\xi$ is a limit point of $U$ in $S$, then $f$ is zero at $\xi$.
|
module nat where
open import product
open import bool
open import maybe
open import eq
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
data β : Set where
zero : β
suc : β β β
nat = β
----------------------------------------------------------------------
-- syntax
----------------------------------------------------------------------
infixl 10 _*_
infixl 9 _+_ _βΈ_
infixl 8 _<_ _=β_ _β€_ _>_ _β₯_
-- pragmas to get decimal notation:
{-# BUILTIN NATURAL β #-}
----------------------------------------------------------------------
-- operations
----------------------------------------------------------------------
---------------------------------------
-- basic arithmetic operations
---------------------------------------
_+_ : β β β β β
zero + n = n
suc m + n = suc (m + n)
{-# BUILTIN NATPLUS _+_ #-}
_*_ : β β β β β
zero * n = zero
suc m * n = n + (m * n)
{-# BUILTIN NATTIMES _*_ #-}
pred : β β β
pred 0 = 0
pred (suc n) = n
_βΈ_ : β β β β β
m βΈ zero = m
zero βΈ suc n = zero
suc m βΈ suc n = m βΈ n
-- see nat-division.agda for division function
{-# BUILTIN NATMINUS _βΈ_ #-}
square : β β β
square x = x * x
--------------------------------------------------
-- comparisons
--------------------------------------------------
_<_ : β β β β πΉ
0 < 0 = ff
0 < (suc y) = tt
(suc x) < (suc y) = x < y
(suc x) < 0 = ff
_=β_ : β β β β πΉ
0 =β 0 = tt
suc x =β suc y = x =β y
_ =β _ = ff
_β€_ : β β β β πΉ
x β€ y = (x < y) || x =β y
_>_ : β β β β πΉ
a > b = b < a
_β₯_ : β β β β πΉ
a β₯ b = b β€ a
min : β β β β β
min x y = if x < y then x else y
max : β β β β β
max x y = if x < y then y else x
data compare-t : Set where
compare-lt : compare-t
compare-eq : compare-t
compare-gt : compare-t
compare : β β β β compare-t
compare 0 0 = compare-eq
compare 0 (suc y) = compare-lt
compare (suc x) 0 = compare-gt
compare (suc x) (suc y) = compare x y
iszero : β β πΉ
iszero 0 = tt
iszero _ = ff
parity : β β πΉ
parity 0 = ff
parity (suc x) = ~ (parity x)
_pow_ : β β β β β
x pow 0 = 1
x pow (suc y) = x * (x pow y)
factorial : β β β
factorial 0 = 1
factorial (suc x) = (suc x) * (factorial x)
is-even : β β πΉ
is-odd : β β πΉ
is-even 0 = tt
is-even (suc x) = is-odd x
is-odd 0 = ff
is-odd (suc x) = is-even x
|
# Fourier Series: Straight Lines and Polygons
This notebook shows how to compute the Fourier series of straight lines and polygons.
### Content
1. [Prerequisites](#prerequisites)
2. [Representing Straight Lines](#representation)
1. Polygons
3. [Fourier Series of Straight Lines](#fourier_computation)
1. [Proof](#proof)
2. [Implementation](#implementation)
4. [Example](#example)
```python
%matplotlib inline
# Initial imports
import numpy as np
import matplotlib.pyplot as plt
```
```javascript
%%javascript
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
});
MathJax.Hub.Queue(
["resetEquationNumbers", MathJax.InputJax.TeX],
["PreProcess", MathJax.Hub],
["Reprocess", MathJax.Hub]
);
```
<IPython.core.display.Javascript object>
## Prerequisites <a id='prerequisites'></a>
This notebook shows how to compute the Fourier series of straight lines and polygones. For this, you should be familiar with:
- The general computation of [Fourier series of curves](Fourier-Series-of-Curves-Background.ipynb) and especially the case of piecewiese defines curves.
- Complex numbers, especially the representation of 2-dimensional points as complex numbers
- Computation of integrals of curves
## Representing Straight Lines <a id='representation'></a>
A straight line $g:[0,1]\to\mathbb{C}$ from point $p_0\in\mathbb{C}$ to point $p_1\in\mathbb{C}$ with $g(0)=p_0$ and $g(1) = p_1$ can be written as
$$
\begin{equation}
g(t) = (1-t)\cdot p_0 + t\cdot p_1 \label{eqn:straigt_line_01}
\end{equation}
$$
For the computation of the Fourier Series, we need a curve defined over the interval $[0,2\pi]$; for a polygon, which is a piecewise concatenation of straight lines, each piece $i$ would be defined over an interval $[t_i,t_{i+1}]$. For this reason, we generalize ($\ref{eqn:straigt_line_01}$) to a function $g:[a,b]\to\mathbb{C}$ with $g(a)=p_0$ and $g(b) = p_1$:
$$
\begin{align}
g(t) &= \frac{b-t}{b-a}\cdot p_0 + \frac{t-a}{b-a}\cdot p_1 \label{eqn:straigt_line_ab}\\
&= \frac{p_0b - p_1a}{b-a} + \frac{p_1-p_0}{b-a}t \label{eqn:straigt_line_by_t}
\end{align}
$$
### Polygons
Polygons are a sequence of straight lines, connecting corner points $p_0,\ldots,p_n$ with $p_n = p_0$ for closing the curve.
## Fourier Series of Straight Lines <a id='fourier_computation'></a>
As described in the [introduction of Fourier series of curves](Fourier-Series-of-Curves-Background.ipynb) we need to solve the integral $\int_a^b g(t)e^{-i\lambda t}dt$ for an arbitrary straight line $g$ and any choice of $a$, $b$ and $\lambda$ in order to compute the Fourier series of straight lines and polygons.
_Case 1:_ $\lambda=0$:
$$
\int_a^b g(t)e^{-i\lambda t}dt = \frac{1}{2}\left(p_1 + p_2)(b - a)\right)
$$
_Case 2:_ $\lambda\neq 0$:
$$
\int_a^b g(t)e^{-i\lambda t}dt = \frac{ie^{-i\lambda b}}{\lambda}p_2 - \frac{ie^{-i\lambda a}}{\lambda} p_1
+\frac{1}{\lambda^2}\frac{p_2-p_1}{b-a}\left(e^{-i\lambda b}-e^{-i\lambda a}\right)
$$
### Proof: <a id='proof'></a>
Using (\ref{eqn:straigt_line_by_t}), we can compute the integral as:
_Case 1:_ $\lambda=0$:
$$
\begin{align*}
\int_a^b g(t)e^{-i\lambda t}dt &= \int_a^b g(t)dt \\
&= \frac{p_1b - p_2a}{b-a}\left(b-a\right) + \frac{p_2-p_1}{b-a}\frac{1}{2}\left(b^2-a^2\right)\\
&= \left(p_1b - p_2a\right) + \frac{1}{2}\left(p_2-p_1\right)\left(a+b\right)\\
&= \frac{1}{2}\left(p_1b - p_2a + p_2b - p_1a\right)\\
&= \frac{1}{2}\left(p_1 + p_2\right)\left(b - a\right)
\end{align*}
$$
_Case 2:_ $\lambda\neq 0$:
$$
\begin{align*}
\int_a^b g(t)e^{-i\lambda t}dt &= \int_a^b \left(\frac{p_1b - p_2a}{b-a} + \frac{p_2-p_1}{b-a}t\right)e^{-i\lambda t}dt\\
&= \frac{p_1b - p_2a}{b-a} \int_a^b e^{-i\lambda t}dt + \frac{p_2-p_1}{b-a}\int_a^b te^{-i\lambda t}dt\\
&= \frac{p_1b - p_2a}{b-a} \left[\frac{e^{-i\lambda t}}{-i\lambda}\right]_{t=a}^b + \frac{p_2-p_1}{b-a}\left(\left[\frac{te^{-i\lambda t}}{-i\lambda}\right]_{t=a}^b-\int_a^b \frac{e^{-i\lambda t}}{-i\lambda}dt\right)\\
&= \frac{i}{\lambda}\frac{p_1b - p_2a}{b-a} \left(e^{-i\lambda b}-e^{-i\lambda a}\right) + \frac{i}{\lambda}\frac{p_2-p_1}{b-a}\left(be^{-i\lambda b}-ae^{-i\lambda a}\right) + \frac{1}{\lambda^2}\frac{p_2-p_1}{b-a}\left(e^{-i\lambda b}-e^{-i\lambda a}\right)\\
&=\\
&= \frac{e^{-i\lambda b}}{b-a} \frac{i}{\lambda}\left(p_1b - p_2a + p_2b - p_1b\right)-\frac{e^{-i\lambda a}}{b-a} \frac{i}{\lambda}\left(p_1b - p_2a + p_2a - p_1a\right) + \frac{1}{\lambda^2}\frac{p_2-p_1}{b-a}\left(e^{-i\lambda b}-e^{-i\lambda a}\right)\\
&= \frac{ie^{-i\lambda b}}{\lambda}p_2 - \frac{ie^{-i\lambda a}}{\lambda} p_1 +\frac{1}{\lambda^2}\frac{p_2-p_1}{b-a}\left(e^{-i\lambda b}-e^{-i\lambda a}\right)
\end{align*}
$$
### Implementation <a id='implementation'></a>
Beginning with a single staight line segment
```python
def transform_straight_line(p1, p2, l, a, b):
i = 1j # Just for shorter notations
l = np.asarray(l)
result = np.zeros(shape=l.shape, dtype=np.complex)
# Handle Case k != 0
l_ = l[l!=0]
result[l!=0] = i * np.exp(-i*l_*b) * p2 / l_ \
- i * np.exp(-i*l_*a) * p1 / l_ \
+ (p2 - p1) * (np.exp(-i*l_*b) - np.exp(-i*l_*a)) / (l_*l_*(b - a))
# Handle case k=0
result[l==0] = (p1 + p2) * (b - a) / 2
# Return results
return result
```
Extending this to closed sequences of lines. Here we scale the period so that the length $T=2\pi$.
_Note:_ There are different ways to determine the segment-borders $t_0,\ldots,t_m$. Here we use the length of the lines.
```python
def transform_polygon(p, n):
m = len(p) # Number of Segments (if we close the path)
# Close the curve: add the beginning point at the end
p = np.reshape(p, (-1))
p = p[list(range(m)) + [0]]
# Length of the segments
l = np.abs(p[1:] - p[:-1])
# Compute t_0 to t_m based on the lengths with t_0 = 0 and t_m = 2\pi
t = l.cumsum() / l.sum()
t = 2 * np.pi * np.concatenate([[0], t])
# get vector of k
k = np.arange(-n,n+1)
c = sum([transform_straight_line(p[i], p[i+1], k, t[i], t[i+1]) for i in range(m)])
return c, k
```
Get the fourier approximation as a function.
This will be used to plot the fourier approximation.
```python
def get_fourier_fct(c, k):
# Reshape the fourier coefficients row vectors
c = np.reshape(c, (1,-1))
k = np.reshape(k, (1,-1))
def fct(t):
# Reshape the input values into a column vector
t = np.reshape(t, (-1,1))
return np.sum(c * np.exp(1j * k * t), axis=1) / (2 * np.pi)
return fct
```
## Example: Triangle <a id='example'></a>
Works also with other polygons, just add or modify points.
```python
# Corner points of the triangle as complex numbers
p = [-1 -1j,
0.5 + 3j,
12
]
```
```python
N = 12
# Compute coefficients c_{-N} to c_N
c,k = transform_polygon(p, N)
# Get approximations (limited to different values n=1,...,N)
fcts = [get_fourier_fct(c[np.abs(k) <= n], k[np.abs(k) <= n]) for n in range(1,N+1)]
```
Plotting the results
```python
# plot closed curve of complex
def plotcc(p, *args, **kwargs):
# close curve
m = len(p)
p = np.reshape(p, (-1))
p = p[list(range(m)) + [0]] # Closing the curve
# Complex to real x and y vectors
x, y = np.real(p), np.imag(p)
plt.plot(x, y, *args, **kwargs)
```
```python
plt.figure(figsize=(30,20))
# Number of points
nT = 1000
t = 2 * np.pi * np.arange(0,1, 1/nT)
for n in range(1, N+1):
pf = fcts[n-1](t)
plt.subplot(3,4,n)
plotcc(p)
plotcc(pf)
plt.title(f"n={n}")
plt.show()
```
|
theory UnpairedLogic
imports
NewLogic
begin
fun unpairMsg :: "execmsg \<Rightarrow> kntrace"
where
"unpairMsg (Tup x y) =
[\<Delta> MkFst x y, \<star> x, \<Delta> MkSnd x y, \<star> y] @ unpairMsg x @ unpairMsg y"
| "unpairMsg m = []"
fun unpairTrace_raw :: "kntrace \<Rightarrow> kntrace"
where
"unpairTrace_raw [] = []"
| "unpairTrace_raw (\<Delta> e # t) = \<Delta> e # unpairTrace_raw t"
| "unpairTrace_raw (\<star> m # t) = \<star> m # unpairMsg m @ unpairTrace_raw t"
definition unpairTrace :: "kntrace \<Rightarrow> kntrace"
where "unpairTrace t = rev (remdups (rev (unpairTrace_raw t)))"
lemma distinct_unpairTrace [simp]: "distinct (unpairTrace t)"
by(simp add: unpairTrace_def)
lemma unpairTrace_raw_append [simp]:
"unpairTrace_raw (t@t') = unpairTrace_raw t @ unpairTrace_raw t'"
by(induct t rule: unpairTrace_raw.induct, auto)
lemma set_unpairTrace_raw_mono: "set t \<subseteq> set (unpairTrace_raw t)"
by(induct t rule: unpairTrace_raw.induct, auto)
lemmas set_unpairTrace_raw_monoD =
subsetD[OF set_unpairTrace_raw_mono, rule_format]
lemma set_unpairTrace_mono: "set t \<subseteq> set (unpairTrace t)"
by(simp add: unpairTrace_def set_unpairTrace_raw_mono)
lemmas set_unpairTrace_monoD =
subsetD[OF set_unpairTrace_mono, rule_format]
lemma listOrd_unpairTrace_raw:
"listOrd t x y \<Longrightarrow> listOrd (unpairTrace_raw t) x y"
apply(induct t rule: unpairTrace_raw.induct)
by(auto dest: set_unpairTrace_raw_monoD)
lemma in_unpair_conv_unpairMsg:
"x' \<in> unpair x \<Longrightarrow> \<star> x' \<in> set (\<star> x # unpairMsg x)"
by(induct x rule: unpairMsg.induct, auto)
lemma listOrd_unpairTrace_raw_unpair:
"listOrd t (\<star> x) y \<Longrightarrow>
\<forall> x' \<in> unpair x. listOrd (unpairTrace_raw t) (\<star> x') y"
apply(induct t rule: unpairTrace_raw.induct)
by(auto dest: set_unpairTrace_raw_monoD in_unpair_conv_unpairMsg)
lemma listOrd_rev [simp]: "listOrd (rev xs) x y = listOrd xs y x"
by(induct xs, auto)
lemma unpairTrace_Nil [iff]: "unpairTrace [] = []"
by(simp add: unpairTrace_def)
lemma remdups_Snoc:
"remdups (xs @ [x]) = [x' \<leftarrow> remdups xs. x' \<noteq> x] @ [x] "
by(induct xs rule: remdups.induct, auto)
lemma Event_in_set_unpairTrace_raw [simp]:
"(\<Delta> e \<in> set (unpairTrace_raw t)) = (\<Delta> e \<in> set t)"
apply(induct t rule: unpairTrace_raw.induct, auto)
oops
lemma unpairTrace_Cons_Event:
"unpairTrace (\<Delta> e # t) = \<Delta> e # [x\<leftarrow>unpairTrace t . x \<noteq> \<Delta> e]"
by(simp add: unpairTrace_def remdups_Snoc rev_filter)
lemma unpairTrace_idem [iff]:
"unpairTrace (unpairTrace t) = unpairTrace t"
apply(induct t rule: unpairTrace_raw.induct)
apply(simp)
apply(simp add: unpairTrace_Cons_Event)
oops
fun inp' :: "wt_subst \<Rightarrow> execevent \<Rightarrow> execmsg set"
where
"inp' s (MkStep tid (Send l msg)) = {}"
| "inp' s (MkStep tid (Recv l msg)) = {subst s (s2e msg tid)}"
| "inp' s (FromIK0 m) = {}"
| "inp' s (MkHash m) = {m}"
| "inp' s (MkTup x y) = {x, y}"
| "inp' s (MkFst x y) = {}"
| "inp' s (MkSnd x y) = {}"
| "inp' s (MkEncr m k) = {m, k}"
| "inp' s (MkDecr m k) = {Enc m k, inv k}"
fun fromMsg :: "wt_subst \<Rightarrow> kntrace \<Rightarrow> specmsg \<Rightarrow> tid \<Rightarrow> execmsg \<Rightarrow> bool"
where
"fromMsg s t (Enc msg key) tid m =
(
(subst s (s2e (Enc msg key) tid) = m) \<or>
(listOrd t (\<star> Enc (subst s (s2e msg tid)) (subst s (s2e key tid)))
(\<star> subst s (s2e msg tid))
\<and>
listOrd t (\<star> subst s (s2e (inv key) tid))
(\<star> subst s (s2e msg tid))
\<and>
fromMsg s t msg tid m
)
)"
| "fromMsg s t (Tup x y) tid m =
(
(subst s (s2e (Tup x y) tid) = m) \<or>
(listOrd t (\<star> Tup (subst s (s2e x tid)) (subst s (s2e y tid)))
(\<star> subst s (s2e x tid))
\<and>
fromMsg s t x tid m
) \<or>
(listOrd t (\<star> Tup (subst s (s2e x tid)) (subst s (s2e y tid)))
(\<star> subst s (s2e y tid))
\<and>
fromMsg s t y tid m
)
)"
| "fromMsg s t msg tid m = (subst s (s2e msg tid) = m)"
lemma Knows_before_inp'_unpaired:
"\<lbrakk>\<Delta> e \<in> set (unpairTrace t); m \<in> inp' s e\<rbrakk>
\<Longrightarrow> \<forall> m' \<in> unpair m. listOrd (unpairTrace t) (\<star> m') (\<Delta> e)"
oops
thm remdups_C
apply(auto)
lemma unpairTrace_reachable: "(unpairTrace t, r, s) \<in> reachable P"
apply(simp add: unpairTrace_def)
apply(insert reachable)
proof(induct rule: reachable.induct)
case init thus ?case
by(auto intro: reachable.intros)
next
case (create t r s tid R \<alpha>) thus ?case
apply(simp)
apply(drule reachable.create)
apply(simp+)
apply(simp_all)
case Nil thus ?case by simp next
case (Cons knev t) thus ?case
apply(case_tac knev)
apply(simp_all)
lemma listOrd_unpairTrace:
"listOrd t x y \<Longrightarrow> listOrd (unpairTrace t) x y"
apply(simp add: unpairTrace_def)
apply(induct t rule: unpairTrace_raw.induct)
by(auto dest: set_unpairTrace_raw_monoD)
lemma listOrd_unpairTrace_unpair:
"listOrd t (\<star> x) y \<Longrightarrow>
\<forall> x' \<in> unpair x. listOrd (unpairTrace_raw t) (\<star> x') y"
apply(induct t rule: unpairTrace_raw.induct)
by(auto dest: set_unpairTrace_raw_monoD in_unpair_conv_unpairMsg)
fun
fun appendNew :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
where
"appendNew as [] = as"
| "appendNew as (x#xs) =
appendNew (as @ (if x \<in> set as then [] else [x])) xs"
function (sequential) unpairTrace :: "kntrace \<Rightarrow> kntrace \<Rightarrow> kntrace"
where
"unpairTrace pre [] = pre"
| "unpairTrace pre (\<star> Tup x y # t) =
unpairTrace (appendNew pre [\<star> Tup x y])
(\<Delta> MkFst x y # \<star> x # \<Delta> MkSnd x y # \<star> y # t)"
| "unpairTrace pre (knev # t) = unpairTrace (appendNew pre [knev]) t"
by pat_completeness auto
termination
sorry
lemma set_unpairTrace_monoD_raw:
"x \<in> set pre \<Longrightarrow> x \<in> set (unpairTrace pre t)"
"x \<in> set t \<Longrightarrow> x \<in> set (unpairTrace pre t)"
apply(induct t arbitrary: x pre rule: unpairTrace.induct)
apply(simp_all)
apply(auto)
case 1 thus ?case by simp next
case (2 pre x y t x' pre') thus ?case
apply(auto)
thm prems apply(drule prems)
lemma set_unpairTrace_monoD:
"x \<in> set t \<Longrightarrow> x \<in> set (unpairTrace pre t)"
apply(induct t rule: unpairTrace.induct)
apply(simp_all)
apply(auto)
lemma listOrd_unpairTraceI:
"listOrd t x y \<Longrightarrow> listOrd (unpairTrace pre t) x y"
apply(induct t arbitrary: pre rule: unpairTrace.induct)
lemma unpairTrace_distinctI [intro!]:
"distinct pre \<Longrightarrow> distinct (unpairTrace pre t)"
apply(induct t arbitrary: pre rule: unpairTrace.induct)
apply(simp_all)
apply(safe)
apply(simp_all)
apply(auto)
lemma unpairMsg_distinct [intro!]:
"distinct t \<Longrightarrow> distinct (unpairMsg m t)"
a
lemma unpairMsg_Cons_Event [simp]:
"unpairMsg m (\<Delta> e # pre) = \<Delta> e # unpairMsg m pre"
by(induct m arbitrary: pre, auto)
lemma unpairTrace_Cons_Event [simp]:
"unpairTrace (\<Delta> e # pre) t = \<Delta> e # unpairTrace pre t"
by(induct t arbitrary: pre, simp, case_tac a, auto)
context reachable_state begin
lemma unpairTrace_distinct:
lemma unpairTrace_reachable: "(unpairTrace [] t, r, s) \<in> reachable P"
apply(insert reachable)
apply(induct rule: reachable.induct)
apply(simp_all)
case Nil thus ?case by simp next
case (Cons knev t) thus ?case
apply(case_tac knev)
apply(simp_all)
lemma
fun unpairMsg :: "execmsg \<Rightarrow> kntrace \<Rightarrow> kntrace"
where
"unpairMsg (Tup x y) t =
unpairMsg y (unpairMsg x (
t @
(if (\<star> x \<notin> set t \<and> \<Delta> MkFst x y \<notin> set t)
then [\<Delta> MkFst x y, \<star> x]
else []
) @
(if (\<star> y \<notin> set t \<and> \<Delta> MkSnd x y \<notin> set t)
then [\<Delta> MkSnd x y, \<star> y]
else []
)
))"
| "unpairMsg m t = t"
where
"unpairTrace [] = []"
"unpairTrace s [] = []"
| "unpairTrace s (MkStep tid (Send l msg) # es) =
MkStep tid (Send l msg) #
unpairMsg (subst s (spec2exec msg tid)) @
unpairTrace s es"
| "unpairTrace s (MkDecr m k # es) =
MkDecr m k #
unpairMsg m @
unpairTrace s es"
| "unpairTrace s (e # es) = e # unpairTrace s es"
thm reachable_eout_extend_wts
lemma unpairTrace_append [simp]:
"unpairTrace s (t@t') = unpairTrace s t @ unpairTrace s t'"
by(induct t rule: unpairTrace.induct, auto)
lemma extend_wts_assoc:
"extend_wts (extend_wts s s') s'' = extend_wts s (extend_wts s' s'')"
sorry
lemma reachable_unpairTrace_extend_wts [simp]:
"(t, r, s) \<in> reachable P
\<Longrightarrow> unpairTrace (extend_wts s s') t = unpairTrace s t"
apply(induct arbitrary: s' rule: reachable.induct)
apply(simp_all add: extend_wts_assoc extend_wts_conv_subst
reachable_Send_ground)
done
lemma knows_unpairTrace_subset:
"knows s t \<subseteq> knows s (unpairTrace s t)"
by(induct t rule: unpairTrace.induct, auto)
lemma reachable_append_unpairMsg:
"\<lbrakk> (t,r,s) \<in> reachable P; m \<in> knows s t \<rbrakk>
\<Longrightarrow> (t@unpairMsg m, r, s) \<in> reachable P"
proof(induct m arbitrary: t)
case (Tup x y) show ?case using prems(3-4)
apply(simp)
apply(subgoal_tac "t @ MkUnt x y # unpairMsg x @ unpairMsg y =
(t @ MkUnt x y # unpairMsg x) @ unpairMsg y")
apply(simp only:)
apply(rule prems(2))
apply(subgoal_tac "t @ MkUnt x y # unpairMsg x =
(t @ [MkUnt x y]) @ unpairMsg x")
apply(simp only:)
apply(rule prems(1))
apply(erule reachable.intros)
apply(simp_all (no_asm))
done
next
case Lit thus ?case by simp next
case Enc thus ?case by simp next
case Hash thus ?case by simp next
case SK thus ?case by simp next
case PK thus ?case by simp next
case K thus ?case by simp next
qed
lemma reachable_unpairTrace_reachable:
"(t,r,s) \<in> reachable P \<Longrightarrow>
(unpairTrace s t, r, s) \<in> reachable P"
proof(induct rule: reachable.induct)
case init thus ?case by(simp add: reachable.init)
case (create t r s tid R \<alpha>) thus ?case
apply(simp)
apply(rotate_tac 1)
apply(drule reachable.create)
apply(simp+)
apply(subgoal_tac
"(\<lambda>a. if a = tid then Some (newThread R) else r a) =
r(tid \<mapsto> newThread R)")
apply(simp)
apply(rule ext, simp)
done
next
case (recv t r s l msg tid \<alpha>) thus ?case
apply(simp)
apply(rule reachable.intros)
by(auto elim!: subsetD[OF knows_unpairTrace_subset])
next
case hash thus ?case
apply(simp)
apply(rule reachable.intros)
by(auto elim!: subsetD[OF knows_unpairTrace_subset])
next
case encr thus ?case
apply(simp)
apply(rule reachable.intros)
by(auto elim!: subsetD[OF knows_unpairTrace_subset])
next
case tuple thus ?case
apply(simp)
apply(rule reachable.intros)
by(auto elim!: subsetD[OF knows_unpairTrace_subset])
next
case untup thus ?case
apply(simp)
apply(rule reachable.intros)
by(auto elim!: subsetD[OF knows_unpairTrace_subset])
next
case (decr t r s m k) thus ?case
apply(simp add: reachable_append_unpairMsg)
apply(subgoal_tac "unpairTrace s t @ MkDecr m k # unpairMsg m =
(unpairTrace s t @ [MkDecr m k]) @ unpairMsg m")
apply(simp only:)
apply(rule reachable_append_unpairMsg)
apply(erule reachable.intros)
by(auto elim!: subsetD[OF knows_unpairTrace_subset])
next
case (send t r s l msg tid) thus ?case
apply(simp add: reachable_append_unpairMsg)
apply(subgoal_tac "unpairTrace s t @ MkStep tid (Send l msg) # unpairMsg (subst s (spec2exec msg tid)) =
(unpairTrace s t @ [MkStep tid (Send l msg)]) @ unpairMsg (subst s (spec2exec msg tid))")
apply(simp only:)
apply(rule reachable_append_unpairMsg)
apply(erule reachable.intros)
by(auto elim!: subsetD[OF knows_unpairTrace_subset])
qed
lemma unpairTrace_charn:
"\<lbrakk> m \<in> knows s t; m' \<in> unpair m \<rbrakk> \<Longrightarrow>
m' \<in> knows s (unpairTrace s t)"
apply(induct m)
apply(auto elim!: subsetD[OF knows_unpairTrace_subset])
apply(simp add: knows_conv_eout)
apply(erule disjE)
apply(force simp: IK0_def)
apply(clarsimp)
apply(case_tac x)
apply(case_tac rolestep)
apply(simp_all)
sorry
fun out :: "wt_subst \<Rightarrow> execevent \<Rightarrow> execmsg set"
where
"out s (MkStep tid (Send lbl msg)) =
unpair (subst s (spec2exec msg tid))"
| "out s (MkStep tid (Recv lbl msg)) = {}"
| "out s (MkTup x y) = unpair x \<union> unpair y"
| "out s (MkUnt x y) = unpair x \<union> unpair y"
| "out s (MkHash m) = {Hash m}"
| "out s (MkEncr m k) = {Enc m k}"
| "out s (MkDecr m k) = unpair m"
definition kn' :: "state \<Rightarrow> execmsg \<Rightarrow> bool"
where "kn' q m' = (case q of (t,r,s) \<Rightarrow>
\<forall> m \<in> unpair (subst s m').
m \<in> IK0 \<or> (\<exists> e \<in> set t. m \<in> out s e))"
lemma out_conv_eout:
"out s e = (\<Union> m \<in> eout s e. unpair m)"
by(induct e rule: out.induct, auto)
lemma kn'_conv_knows:
"kn' (t,r,s) m' =
(\<forall> m \<in> unpair m'. subst s m \<in> knows s (unpairTrace s t))"
apply(simp add: kn'_def)
apply(rule iffI)
apply(clarify)
apply(frule unpair_subst_distr)
apply(drule bspec)
apply(assumption)
apply(simp add: out_conv_eout knows_conv_eout)
apply(subgoal_tac "subst s m \<in> knows s t")
section{* Secrecy and Authentication Logic *}
subsection{* Abstract Events *}
datatype logicevent =
DoStep tid rolestep
| DoHash execmsg
| DoEncr execmsg execmsg
| DoDecr execmsg execmsg
fun substEv :: "wt_subst \<Rightarrow> logicevent \<Rightarrow> logicevent"
where
"substEv s (DoStep tid step) = DoStep tid step"
| "substEv s (DoHash m) = DoHash (subst s m)"
| "substEv s (DoEncr m k) = DoEncr (subst s m) (subst s k)"
| "substEv s (DoDecr m k) = DoDecr (subst s m) (subst s k)"
fun instEv :: "logicevent \<Rightarrow> execevent"
where
"instEv (DoStep tid step) = MkStep tid step"
| "instEv (DoHash m) = MkHash m"
| "instEv (DoEncr m k) = MkEncr m k"
| "instEv (DoDecr m k) = MkDecr m k"
fun out :: "wt_subst \<Rightarrow> execevent \<Rightarrow> execmsg set"
where
"out s (MkStep tid (Send lbl msg)) =
unpair (subst s (spec2exec msg tid))"
| "out s (MkStep tid (Recv lbl msg)) = {}"
| "out s (MkTup x y) = unpair x \<union> unpair y"
| "out s (MkUnt x y) = unpair x \<union> unpair y"
| "out s (MkHash m) = {Hash m}"
| "out s (MkEncr m k) = {Enc m k}"
| "out s (MkDecr m k) = unpair m"
subsection{* Predicates *}
definition kn :: "state \<Rightarrow> execmsg \<Rightarrow> bool"
where "kn q m' = (case q of (t,r,s) \<Rightarrow>
\<forall> m \<in> unpair (subst s m').
m \<in> IK0 \<or> (\<exists> e \<in> set t. m \<in> out s e))"
definition ev :: "state \<Rightarrow> logicevent \<Rightarrow> bool"
where "ev q e \<equiv> (case q of (t,r,s) \<Rightarrow>
instEv (substEv s e) \<in> set t)"
definition learn :: "state \<Rightarrow> logicevent \<Rightarrow> execmsg \<Rightarrow> bool"
where "learn q e m' \<equiv> (case q of (t,r,s) \<Rightarrow>
instEv (substEv s e) \<in> set t \<and>
(\<forall> m \<in> unpair (subst s m').
m \<in> IK0 \<or>
m \<in> out s (instEv (substEv s e)) \<or>
(\<exists> e'. (e',(instEv (substEv s e))) \<in> firstOccOrd t \<and>
m \<in> out s e')
) \<and>
(\<exists> m \<in> unpair (subst s m').
m \<notin> IK0 \<and>
m \<in> out s (instEv (substEv s e)) \<and>
(\<forall> e'. (e',instEv (substEv s e)) \<in> firstOccOrd t \<longrightarrow>
m \<notin> out s e'
)
)
)"
definition evbefore :: "state \<Rightarrow> logicevent \<Rightarrow> logicevent \<Rightarrow> bool"
where "evbefore q e1 e2 \<equiv> (case q of (t,r,s) \<Rightarrow>
(instEv (substEv s e1), instEv (substEv s e2))
\<in> firstOccOrd t)"
definition knbefore :: "state \<Rightarrow> execmsg \<Rightarrow> logicevent \<Rightarrow> bool"
where "knbefore q m' e \<equiv> (case q of (t,r,s) \<Rightarrow>
instEv (substEv s e) \<in> set t \<and>
(\<forall> m \<in> unpair (subst s m').
m \<in> IK0 \<or>
(\<exists> e'. (e',instEv (substEv s e)) \<in> firstOccOrd t \<and>
m \<in> out s e'
)
)
)"
definition runs :: "state \<Rightarrow> tid \<Rightarrow> role \<Rightarrow> bool"
where "runs q tid R \<equiv> (case q of (t,r,s) \<Rightarrow>
(case r tid of
Some (todo,done) \<Rightarrow> Rep_role R = rev done @ todo
| None \<Rightarrow> False))"
subsection{* Properties of Conversion Operators *}
lemma out_conv_eout:
"out s e = (\<Union> m \<in> eout s e. unpair m)"
by(induct e rule: out.induct, auto)
lemma reachable_instEv_substEv_extend_wts [simp]:
"\<lbrakk> (t,r,s) \<in> reachable P; instEv (substEv s e) \<in> set t \<rbrakk>
\<Longrightarrow> instEv (substEv (extend_wts s s') e) = instEv (substEv s e)"
apply(induct e rule: substEv.induct)
apply(auto simp: extend_wts_conv_subst
dest!: reachable_eventMsg_ground)
done
subsection{* Rules *}
subsubsection{* Simplification *}
lemma kn_simps [simp]:
"kn q (Tup x y) = (kn q x \<and> kn q y)"
"kn q (Lit (EConst c))"
"kn q (Lit (EHonest a))"
"kn q (Lit (EveNonce n))"
"kn q (SK (Lit Eve))"
"kn q (PK (Lit (EHonest a)))"
"kn q (K (Lit (EHonest a)) (Lit Eve))"
"kn q (K (Lit Eve) (Lit (EHonest a)))"
apply(cases q, simp add: add kn_def ball_Un)
by(cases q, simp add: IK0_def kn_def image_def)+
lemma knbefore_simps:
"knbefore q (Tup x y) e = (knbefore q x e \<and> knbefore q y e)"
"ev q e \<Longrightarrow> knbefore q (Lit (EConst c)) e"
"ev q e \<Longrightarrow> knbefore q (Lit (EHonest a)) e"
"ev q e \<Longrightarrow> knbefore q (Lit (EveNonce n)) e"
"ev q e \<Longrightarrow> knbefore q (SK (Lit Eve)) e"
"ev q e \<Longrightarrow> knbefore q (PK (Lit (EHonest a))) e"
"ev q e \<Longrightarrow> knbefore q (K (Lit (EHonest a)) (Lit Eve)) e"
"ev q e \<Longrightarrow> knbefore q (K (Lit Eve) (Lit (EHonest a))) e"
apply(cases q, simp add: knbefore_def, force)
by(cases q, simp add: IK0_def knbefore_def image_def ev_def)+
subsubsection{* Purely Logical *}
lemma evbeforeD1: "evbefore q e1 e2 \<Longrightarrow> ev q e1"
by(auto dest: in_set_firstOccOrd1 simp: evbefore_def ev_def)
lemma evbeforeD2: "evbefore q e1 e2 \<Longrightarrow> ev q e2"
by(auto dest: in_set_firstOccOrd2 simp: evbefore_def ev_def)
lemma knbeforeD1: "knbefore q m e \<Longrightarrow> kn q m"
by(auto dest!: in_set_firstOccOrd1 simp: knbefore_def kn_def)
lemma knbeforeD2: "knbefore q m e \<Longrightarrow> ev q e"
by(auto dest!: in_set_firstOccOrd2 simp: knbefore_def ev_def)
lemma learnD1: "learn q e m \<Longrightarrow> ev q e"
by(auto simp: learn_def ev_def)
lemma learnD2: "learn q e m \<Longrightarrow> kn q m"
by(auto dest!: in_set_firstOccOrd1 simp add: learn_def kn_def)
lemma ebefore_irr: "\<not>evbefore q e e"
by(auto simp: evbefore_def)
lemma ebefore_trans: "\<lbrakk> evbefore q e1 e2; evbefore q e2 e3 \<rbrakk> \<Longrightarrow> evbefore q e1 e3"
by(auto simp: evbefore_def intro: firstOccOrd_trans)
lemma learn_fun:
"\<lbrakk> learn q e1 m; learn q e2 m \<rbrakk>
\<Longrightarrow> instEv (substEv (sts q) e1) = instEv (substEv (sts q) e2)"
apply(clarsimp simp: learn_def)
apply(drule firstOccOrd_cases)
apply(assumption)
apply(erule disjE)
apply(simp)
apply(erule disjE)
apply(thin_tac "\<forall> x \<in> ?X. ?P x")
apply(drule_tac x=ma in bspec)
apply(force)
apply(simp)
apply(force)
apply(auto)
by(auto simp: learn_def dest: firstOccOrd_cases)
lemma learn_knbefore_evbefore:
"\<lbrakk> learn q e1 m; knbefore q m e2 \<rbrakk> \<Longrightarrow> evbefore q e1 e2"
apply(clarsimp simp: learn_def knbefore_def evbefore_def)
apply(drule_tac y="instEv (substEv ya e2)" in firstOccOrd_cases)
apply(drule in_set_firstOccOrd2, simp)
apply(safe)
apply(force)
apply(subgoal_tac "(e', instEv (substEv ya e1)) \<in> firstOccOrd xa")
apply(force)
apply(rule firstOccOrd_trans)
apply(auto)
done
lemma runs_fun: "\<lbrakk> runs q tid R1; runs q tid R2 \<rbrakk> \<Longrightarrow> R1 = R2"
by(auto simp: runs_def Rep_role_inject[symmetric] split: option.splits )
subsubsection{* Role Order *}
lemma evbefore_roleOrd:
"\<lbrakk> ev q (DoStep tid step); runs q tid R;
(prev, step) \<in> roleOrd R; q \<in> reachable P \<rbrakk>
\<Longrightarrow> evbefore q (DoStep tid prev) (DoStep tid step)"
apply(clarsimp simp: ev_def evbefore_def firstOccOrd_def runs_def
split: option.splits)
apply(rename_tac t r s todo "done")
apply(unfold roleOrd_def)
apply(rule reachable_roleOrd)
apply(assumption)
apply(assumption)
apply(auto dest: reachable_todo_notin_trace reachable_done_in_trace in_set_listOrd2)
done
subsubsection{* Inp'ut Messages *}
fun einp' :: "wt_subst \<Rightarrow> execevent \<Rightarrow> execmsg set"
where
"einp' s (MkStep tid (Send l m)) = {}"
| "einp' s (MkStep tid (Recv l m)) = {subst s (spec2exec m tid)}"
| "einp' s (MkHash m) = {m}"
| "einp' s (MkTup x y) = {x, y}"
| "einp' s (MkUnt x y) = {Tup x y}"
| "einp' s (MkEncr m k) = {m, k}"
| "einp' s (MkDecr m k) = {Enc m k, inv k}"
fun inp' :: "logicevent \<Rightarrow> execmsg set"
where
"inp' (DoStep tid (Send l m)) = {}"
| "inp' (DoStep tid (Recv l m)) = unpair (spec2exec m tid)"
| "inp' (DoHash m) = unpair m"
| "inp' (DoEncr m k) = unpair m \<union> unpair k"
| "inp' (DoDecr m k) = insert (Enc m k) (unpair (inv k))"
lemma einp'_ground_by_eventMsg_ground:
"\<lbrakk> m \<in> einp' s e; ground (eventMsg s e) \<rbrakk> \<Longrightarrow> ground m"
by(induct e rule: einp'.induct, auto)
lemma reachable_einp'_extend_wts [simp]:
"\<lbrakk> (t,r,s) \<in> reachable P; e \<in> set t \<rbrakk>
\<Longrightarrow> einp' (extend_wts s s') e = einp' s e"
apply(induct rule: einp'.induct)
apply(auto dest: reachable_eventMsg_ground
simp: extend_wts_conv_subst)
done
lemma reachable_knows_einp':
"\<lbrakk> (t,r,s) \<in> reachable P; e \<in> set t; m \<in> einp' s e \<rbrakk>
\<Longrightarrow> m \<in> knows s t"
thm reachable_knows_extend_wts
thm reachable_einp'_extend_wts
by(induct arbitrary: e rule: reachable.induct, auto)
lemma reachable_knows_before_einp':
"\<lbrakk> (t,r,s) \<in> reachable P; e \<in> set t; m \<in> einp' s e \<rbrakk>
\<Longrightarrow>
m \<in> IK0 \<or> (\<exists> e' \<in> set t. (e', e) \<in> firstOccOrd t \<and> m \<in> eout s e')"
apply(induct arbitrary: e m rule: reachable.induct)
apply(simp_all)
apply(erule disjE, simp)
apply(force intro!: firstOccOrd_appendI1)
apply((thin_tac "dom_wts ?x = ?X")?, (thin_tac "ran_wts ?x = ?X")?)
apply(case_tac "e \<in> set t")
apply(force intro!: firstOccOrd_appendI1)
apply(force simp: knows_conv_eout intro!: firstOccOrd_appendI2)
apply(case_tac "e \<in> set t")
apply(force intro!: firstOccOrd_appendI1)
apply(force simp: knows_conv_eout intro!: firstOccOrd_appendI2)
apply(case_tac "e \<in> set t")
apply(force intro!: firstOccOrd_appendI1)
apply(force simp: knows_conv_eout intro!: firstOccOrd_appendI2)
apply(case_tac "e \<in> set t")
apply(force intro!: firstOccOrd_appendI1)
apply(force simp: knows_conv_eout intro!: firstOccOrd_appendI2)
apply(case_tac "e \<in> set t")
apply(force intro!: firstOccOrd_appendI1)
apply(force simp: knows_conv_eout intro!: firstOccOrd_appendI2)
apply(case_tac "e \<in> set t")
apply(force intro!: firstOccOrd_appendI1)
apply(force simp: knows_conv_eout intro!: firstOccOrd_appendI2)
done
lemma Recv_knbefore:
"\<lbrakk> ev q (DoStep tid (Recv l msg));
m \<in> unpair (spec2exec msg tid);
q \<in> reachable P \<rbrakk>
\<Longrightarrow> knbefore q m (DoStep tid (Recv l msg))"
apply(cases q, rename_tac t r s)
apply(simp add: ev_def knbefore_def)
apply(drule reachable_knows_before_einp', assumption, simp)
apply(drule unpair_subst_distr)
apply(simp add: out_conv_eout knows_conv_eout)
apply(erule disjE)
apply(drule in_IK0_by_unpair, assumption, simp)
apply(force)
done
lemma Hash_knbefore:
"\<lbrakk> ev q (DoHash m'); m \<in> unpair m'; q \<in> reachable P \<rbrakk>
\<Longrightarrow> knbefore q m (DoHash m')"
apply(cases q, rename_tac t r s)
apply(simp add: ev_def knbefore_def)
apply(drule reachable_knows_before_einp', assumption, simp)
apply(drule unpair_subst_distr)
apply(simp add: out_conv_eout knows_conv_eout)
apply(erule disjE)
apply(drule in_IK0_by_unpair, assumption, simp)
apply(force)
done
lemma Encr_knbefore_msg:
"\<lbrakk> ev q (DoEncr m' k'); m \<in> unpair m'; q \<in> reachable P \<rbrakk>
\<Longrightarrow> knbefore q m (DoEncr m' k')"
apply(cases q, rename_tac t r s)
apply(simp add: ev_def knbefore_def)
apply(drule reachable_knows_before_einp', assumption)
apply(simp, rule disjI1, rule refl)
apply(drule unpair_subst_distr)
apply(simp add: out_conv_eout knows_conv_eout)
apply(erule disjE)
apply(drule in_IK0_by_unpair, assumption, simp)
apply(force)
done
lemma Encr_knbefore_key:
"\<lbrakk> ev q (DoEncr m' k'); m \<in> unpair k'; q \<in> reachable P \<rbrakk>
\<Longrightarrow> knbefore q m (DoEncr m' k')"
apply(cases q, rename_tac t r s)
apply(simp add: ev_def knbefore_def)
apply(drule reachable_knows_before_einp', assumption)
apply(simp, rule disjI2, rule refl)
apply(drule unpair_subst_distr)
apply(simp add: out_conv_eout knows_conv_eout)
apply(erule disjE)
apply(drule in_IK0_by_unpair, assumption, simp)
apply(force)
done
lemma Decr_knbefore_enc:
"\<lbrakk> ev q (DoDecr m k); q \<in> reachable P \<rbrakk>
\<Longrightarrow> knbefore q (Enc m k) (DoDecr m k)"
apply(cases q, rename_tac t r s)
apply(simp add: ev_def knbefore_def)
apply(drule reachable_knows_before_einp', assumption)
apply(simp, rule disjI1, rule refl)
apply(force simp: out_conv_eout knows_conv_eout)
done
lemma Decr_knbefore_key:
"\<lbrakk> ev q (DoDecr m' k'); m \<in> unpair (inv k'); q \<in> reachable P \<rbrakk>
\<Longrightarrow> knbefore q m (DoDecr m' k')"
apply(cases q, rename_tac t r s)
apply(simp add: ev_def knbefore_def)
apply(drule reachable_knows_before_einp', assumption)
apply(simp, rule disjI2, rule refl)
apply(drule unpair_subst_distr)
apply(simp add: out_conv_eout knows_conv_eout)
apply(erule disjE)
apply(drule in_IK0_by_unpair, assumption, simp)
apply(force)
done
lemmas Hash_kn = knbeforeD1[OF Hash_knbefore, rule_format]
subsubsection{* Decryption Chains *}
types chain = "(specmsg \<times> specmsg) list \<times> specmsg"
fun msgChains :: "specmsg \<Rightarrow> chain list"
where
"msgChains (Lit (SNonce n)) = [([], Lit (SNonce n))]"
| "msgChains (Lit (SVar (MVar n))) = [([], Lit (SVar (MVar n)))]"
| "msgChains (Lit _) = []"
| "msgChains (Tup x y) = msgChains x @ msgChains y"
| "msgChains (Enc m k) =
([], Enc m k) #
map (\<lambda> (encs,end). ((m,k)#encs,end)) (msgChains m)"
| "msgChains (Hash m) = [([], Hash m)]"
| "msgChains (K a b) = [([], K a b) ]"
| "msgChains (PK a) = [([], PK a) ]"
| "msgChains (SK a) = [([], SK a) ]"
fun chainStart :: "chain \<Rightarrow> specmsg"
where
"chainStart ([],start) = start"
| "chainStart ((m,k)#_,_) = Enc m k"
fun chainEnd :: "chain \<Rightarrow> specmsg"
where
"chainEnd (_,end) = end"
lemma chainEnd_in_parts:
"c \<in> set (msgChains msg) \<Longrightarrow> chainEnd c \<in> parts msg"
apply(induct msg arbitrary: c, case_tac lit)
apply(auto)
by(case_tac varid, auto)
(* if there are no long-term-keys in the parts of the message
then chain end is not part of it *)
lemma no_ltkeys_chainEnd:
"\<lbrakk> no_ltkeys msg; c \<in> set (msgChains msg) \<rbrakk> \<Longrightarrow>
K a b \<noteq> chainEnd c \<and> PK a \<noteq> chainEnd c \<and> SK a \<noteq> chainEnd c"
apply(induct msg arbitrary: c, case_tac lit)
apply(simp_all)
apply(case_tac varid)
by(simp+, force+)
fun chain :: "state \<Rightarrow> tid \<Rightarrow> chain \<Rightarrow> bool"
where
"chain q tid ([], _ ) = True"
| "chain q tid ([(m,k)], end) =
learn q (DoDecr (spec2exec m tid)
(spec2exec k tid))
(spec2exec end tid)"
| "chain q tid ((m,k)#(m',k')#encs, end) =
(learn q (DoDecr (spec2exec m tid)
(spec2exec k tid))
(spec2exec (Enc m' k') tid)
\<and> chain q tid ((m',k')#encs, end)
)"
lemma kn_rolemap_inv:
"kn (t, r', s) m \<Longrightarrow> kn (t, r, s) m"
by(simp add: kn_def)
(*
lemma reachable_kn_extend_wts [simp]:
"\<lbrakk> (t,r,s) \<in> reachable P \<rbrakk>
\<Longrightarrow> kn (t,r, extend_wts s s') m = kn (t,r,s) m"
apply(simp add: kn_def)
*)
lemma kn_substI: "kn q m \<Longrightarrow> kn q (subst (sts q) m)"
by(auto simp: kn_def)
lemma kn_substE:
"\<lbrakk> kn q (subst s m); subst (sts q) (subst s m) = subst (sts q) m \<rbrakk>
\<Longrightarrow> kn q m"
by(auto simp: kn_def)
thm extend_wts_conv_subst
lemma subst_subdomain:
"dom_wts s' \<subseteq> dom_wts s \<Longrightarrow> subst s' (subst s m) = subst s m"
apply(induct m rule: subst.induct, simp_all)
apply(case_tac "l \<in> dom_wts s")
apply(auto simp: dom_wts_def)
done
lemma substEv_subdomain:
"dom_wts s' \<subseteq> dom_wts s \<Longrightarrow> substEv s' (substEv s e) = substEv s e"
by(induct e rule: substEv.induct, auto intro!: subst_subdomain)
lemma reachable_kn_extend_wts [simp]:
"(t,r,s) \<in> reachable P \<Longrightarrow>
kn (t,r,extend_wts s s') m = kn (t,r,s) (subst (extend_wts s s') m)"
apply(subgoal_tac "subst s (subst (extend_wts s s') m) =
subst (extend_wts s s') m")
apply(auto simp: kn_def out_conv_eout
intro!: subst_subdomain)
done
lemma reachable_learn_extend_wts [simp]:
"(t,r',s) \<in> reachable P \<Longrightarrow>
learn (t,r,extend_wts s s') e m =
learn (t,r',s) (substEv (extend_wts s s') e) (subst (extend_wts s s') m)"
apply(subgoal_tac "subst s (subst (extend_wts s s') m) =
subst (extend_wts s s') m")
apply(subgoal_tac "substEv s (substEv (extend_wts s s') e) =
substEv (extend_wts s s') e")
apply(simp add: learn_def out_conv_eout)
apply(rule iffI)
apply(force dest: in_set_firstOccOrd1)
apply(force dest: in_set_firstOccOrd1)
apply(auto intro!: substEv_subdomain subst_subdomain)
done
lemma Rep_wt_subst_atomic: "\<exists> l'. Rep_wt_subst s l = Lit l'"
apply(insert Rep_wt_subst_welltyped[of s])
apply(simp add: welltyped_def)
apply(drule_tac x=l in spec, auto)
done
lemma Rep_wt_subst_noteq_simps [simp]:
"Rep_wt_subst s l \<noteq> Hash m"
"Rep_wt_subst s l \<noteq> Enc m k"
"Rep_wt_subst s l \<noteq> Tup x y"
"Rep_wt_subst s l \<noteq> PK a"
"Rep_wt_subst s l \<noteq> SK a"
"Rep_wt_subst s l \<noteq> K a b"
by(insert Rep_wt_subst_atomic[of s l], auto)
lemma kn_append_cases:
"kn (t@t', r, s) m \<Longrightarrow>
kn (t, r, s) m \<or>
(\<exists> e \<in> set t'. e \<notin> set t \<and> subst s m \<in> out s e)"
by(auto simp: kn_def)
lemma firstOccOrd_Nil [simp]: "firstOccOrd [] = {}"
by(simp add: firstOccOrd_def)
lemma firstOccOrd_Snoc1 [simp]:
"x \<in> set xs \<Longrightarrow> firstOccOrd (xs@[x]) = firstOccOrd xs"
by(induct xs rule: rev_induct, auto simp: firstOccOrd_def)
lemma firstOccOrd_Snoc2 [simp]:
"x \<notin> set xs \<Longrightarrow>
firstOccOrd (xs@[x]) = firstOccOrd xs \<union> { (y,x) | y. y \<in> set xs }"
by(induct xs rule: rev_induct, auto simp: firstOccOrd_def)
thm if_splits(1)
lemma firstOccOrd_splits:
"P (firstOccOrd (xs@[x])) =
((x \<in> set xs \<longrightarrow> P (firstOccOrd xs)) \<and>
(x \<notin> set xs \<longrightarrow> P (firstOccOrd xs \<union> { (y,x) | y. y \<in> set xs })))"
by(auto, case_tac "x \<in> set xs", auto)
lemma firstOccOrd_decomp:
"(e,e') \<in> firstOccOrd t
\<Longrightarrow> \<exists> xs ys zs. t = xs@e#ys@e'#zs \<and>
e \<notin> set xs \<and> e' \<notin> set xs \<and> e \<noteq> e' \<and> e' \<notin> set ys"
apply(induct t rule: rev_induct)
apply(auto split: firstOccOrd_splits)
apply(case_tac "x \<in> set xs")
apply(simp_all)
apply(force)
apply(erule disjE)
apply(force)
apply(clarsimp)
apply(drule split_list_first)
apply(clarsimp)
apply(auto)
done
lemma append_eq_append_before_first:
"\<lbrakk> vs @ y#ws = xs @ y#ys; y \<notin> set vs; y \<notin> set xs;
x \<in> set xs \<rbrakk>
\<Longrightarrow> x \<in> set vs"
apply(simp add: append_eq_append_conv2)
apply(auto)
apply(case_tac us)
apply(auto)
done
lemma firstOccOrd_appendD1:
"\<lbrakk> (e,e') \<in> firstOccOrd (t@t'); e' \<in> set t \<rbrakk> \<Longrightarrow> (e,e') \<in> firstOccOrd t"
apply(drule firstOccOrd_decomp)
apply(clarsimp)
apply(drule split_list_first)
apply(clarsimp)
apply(rule firstOccOrd_appendI2)
apply(simp_all)
apply(simp add: append_eq_append_conv2)
apply(auto)
apply(case_tac us, auto)
apply(case_tac us, auto)
done
lemma learn_appendI1:
"learn (t,r,s) e m \<Longrightarrow> learn (t@t', r', s) e m"
by(auto simp: learn_def dest: firstOccOrd_appendD1)
lemma learn_Snoc_MkTup [simp]:
"learn (t@[MkTup x y],r,s) = learn (t,r,s)"
apply(rule ext, rule ext, rename_tac e m, case_tac e)
by(auto simp: learn_def split: firstOccOrd_splits)
lemma learn_Snoc_MkUnt [simp]:
"learn (t@[MkUnt x y],r,s) = learn (t,r,s)"
apply(rule ext, rule ext, rename_tac e m, case_tac e)
by(auto simp: learn_def split: firstOccOrd_splits)
lemma runs_free_args:
"runs (t',r,s') = runs (t,r,s)"
by(rule ext,rule ext, simp add: runs_def)
(* TODO: Using Isar this lemma should be removed *)
lemma chain_Snoc_MkTup_aux [rule_format]:
"q = (t,r,s) \<longrightarrow>
chain (t@[MkTup x y],r,s) tid c = chain q tid c"
by(induct c rule: chain.induct, auto)
lemma chain_Snoc_MkTup [simp]:
"chain (t@[MkTup x y],r,s) = chain (t,r,s)"
by(rule ext, rule ext, auto intro!: chain_Snoc_MkTup_aux)
thm kn_def
lemma learn:
"\<lbrakk> (t,r,s) \<in> reachable P; kn (t,r,s) m' \<rbrakk> \<Longrightarrow>
subst s m' \<in> IK0 \<or>
(\<exists> m. m' = Hash m \<and> learn (t,r,s) (DoHash m) (Hash m)) \<or>
(\<exists> m k. m' = Enc m k \<and> learn (t,r,s) (DoEncr m k) (Enc m k)) \<or>
(\<exists> R \<in> P. \<exists> l msg. Send l msg \<in> roleEvs R \<and>
(\<exists> c \<in> set (msgChains msg). \<exists> tid.
runs (t,r,s) tid R \<and>
learn (t,r,s) (DoStep tid (Send l msg))
(spec2exec (chainStart c) tid) \<and>
chain (t,r,s) tid c \<and>
subst s m' = subst s (spec2exec (chainEnd c) tid)
)
)"
proof (induct arbitrary: m' rule: reachable.induct)
case init thus ?case by(simp add: kn_def)
next
case (tuple t r s x y) thus ?case
apply(simp)
apply(subst runs_free_args[where t=t and s=s])
next
case (hash t r s m) thus ?case
apply(insert kn_append_cases[OF prems(4)])
apply(erule disjE)
apply(drule prems(2))
apply(erule disjE)
apply(simp)
apply(erule disjE)
apply(rule disjI2, rule disjI1)
apply(simp add: learn_def)
apply(clarsimp)
apply(insert prems(1))
apply(rule disjI2, rule disjI1)
case (create t r s tid R \<alpha>) show ?case using prems(1,7)
apply(drule_tac r=r in kn_rolemap_inv)
apply(simp)
apply(drule prems(2))
apply(erule disjE)
apply(subst (asm) subst_subdomain)
apply(force)
apply(simp)
apply(erule disjE)
apply(rule disjI2,rule disjI1)
apply(clarsimp)
apply(cases m')
apply(simp_all)
apply(erule disjE)
apply(rule disjI2, rule disjI2, rule disjI1)
apply(cases m')
apply(simp_all)
apply(rule disjI2, rule disjI2, rule disjI2)
apply(clarsimp)
apply(case_tac "tida = tid")
apply(clarsimp)
apply(insert prems(3))
apply(force simp: runs_def dom_def split: option.splits)
apply(rule bexI)
apply(rule exI, rule exI, rule conjI)
apply(assumption)
apply(rule_tac x="(a,b)" in bexI)
apply(rule_tac x="tida" in exI)
apply(simp add: runs_def)
sorry
next
thm reachable_eout_extend_wts
apply(simp add: kn_def out_conv_eout)
sorry
lemma learn_Hash:
"\<lbrakk> q \<in> reachable P; kn q (Hash m) \<rbrakk> \<Longrightarrow>
learn q (DoHash m) (Hash m) \<or>
(\<exists> R \<in> P. \<exists> l msg. Send l msg \<in> roleEvs R \<and>
(\<exists> c \<in> set (msgChains msg). \<exists> tid.
runs q tid R \<and>
learn q (DoStep tid (Send l msg)) (spec2exec (chainStart c) tid) \<and>
chain q tid c \<and>
Hash (subst (sts q) m) = subst (sts q) (spec2exec (chainEnd c) tid)
)
)"
apply(drule learn, assumption)
by(auto simp: IK0_def)
lemma learn_SK:
"\<lbrakk> q \<in> reachable P; kn q (SK a) \<rbrakk> \<Longrightarrow>
subst (sts q) a = Lit Eve"
apply(drule learn, assumption)
apply(auto)
apply(force simp: IK0_def)
apply(case_tac b, case_tac lit)
apply(simp_all)
apply(insert Rep_wt_subst_welltyped[of "sts q"])
apply(simp add: welltyped_def)
apply(drule_tac x="EVar varid tid" in spec)
apply(force)
apply(simp add: roleEvs_def)
apply(drule Rep_role_Send_no_ltkeys)
apply(drule no_ltkeys_chainEnd)
apply(assumption)
apply(force)
done
|
Formal statement is: lemma fixes r :: ereal assumes "f holomorphic_on eball z0 r" shows conv_radius_fps_expansion: "fps_conv_radius (fps_expansion f z0) \<ge> r" and eval_fps_expansion: "\<And>z. z \<in> eball z0 r \<Longrightarrow> eval_fps (fps_expansion f z0) (z - z0) = f z" and eval_fps_expansion': "\<And>z. norm z < r \<Longrightarrow> eval_fps (fps_expansion f z0) z = f (z0 + z)" Informal statement is: Suppose $f$ is holomorphic on the ball $B(z_0, r)$. Then the radius of convergence of the power series expansion of $f$ at $z_0$ is at least $r$. Moreover, the power series expansion of $f$ at $z_0$ converges to $f$ on the ball $B(z_0, r)$.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.