text
stringlengths 0
3.34M
|
---|
import numpy as np
from scipy.optimize import linear_sum_assignment
from evaluater.graph_runner import GraphRunner
from tracker.track import Track, _NO_MATCH
from trainer.helpers import bbox_cross_overlap_iou_np
from vis_utils.vis_utils import draw_bounding_box_on_image
LSTM_INFO = (
"/Users/kanchana/Documents/current/FYP/fyp_2019/LSTM_Kanchana",
"exp02",
"model.ckpt-109169"
)
class Tracker:
"""
This is the multi-target tracker.
Parameter
----------
lstm_info : tuple
Info for loading trained LSTM model.
min_iou_distance : float
IoU threshold.
num_classes: int
Number of object classes
time_steps: int
Number of time steps
Attributes
----------
min_iou_distance : float
IoU matching threshold.
predictor : evaluater.graph_runner.GraphRunner
LSTM graph for predicting next track.
tracks : List[Track]
The list of active tracks at the current time step.
num_classes: int
Number of object classes
time_steps: int
Number of time steps
"""
def __init__(self, lstm_info=LSTM_INFO, min_iou_distance=0.5, num_classes=9, time_steps=10, max_no_hit=6):
self.predictor = GraphRunner(
base_path=lstm_info[0],
experiment=lstm_info[1],
checkpoint=lstm_info[2])
self.tracks = []
self.min_iou_distance = min_iou_distance
self.num_classes = num_classes
self.time_steps = time_steps
self._next_id = 1
self.max_no_hit = max_no_hit
def predict(self):
"""Obtain the next prediction from each track. Returns an array of shape (num_tracks, 4 + num_classes).
"""
out_array = []
if len(self.tracks) < 1:
return np.zeros(0, 4 + self.num_classes)
for track in self.tracks:
out_array.append(track.to_cwh())
out_array = np.array(out_array)
predictions = self.predictor.get_predictions(out_array)
return np.concatenate([predictions, out_array[:, -1, 4:]], axis=-1)
def update(self, detections, predictions):
"""Perform updates on tracks.
Parameters
----------
detections : np.array
Array of detections at the current time step of shape (count, 4 + num_classes).
predictions : np.array
Array of predictions at the current time step of shape (count, 4 + num_classes).
"""
num_detections = detections.shape[0]
num_predictions = predictions.shape[0]
unmatched_detections = set()
unmatched_tracks = set()
# Get matches.
iou_matrix = bbox_cross_overlap_iou_np(detections[:, :4], predictions[:, :4])
row_ind, col_ind = linear_sum_assignment(-iou_matrix)
# Find valid matches and update tracks
for det_idx, pred_idx in zip(row_ind, col_ind):
iou = iou_matrix[det_idx, pred_idx]
if iou > self.min_iou_distance:
self.tracks[pred_idx].update(detections[det_idx], predictions[pred_idx], iou)
else:
unmatched_tracks.add(pred_idx)
unmatched_detections.add(det_idx)
# find non-matches
for det_idx in range(num_detections):
if det_idx not in row_ind:
unmatched_detections.add(det_idx)
for pred_idx in range(num_predictions):
if pred_idx not in col_ind:
unmatched_tracks.add(pred_idx)
# update unmatched tracks
for pred_idx in unmatched_tracks:
prediction = predictions[pred_idx]
self.tracks[pred_idx].update(None, prediction, 0)
# initiate new tracks
for det_idx in unmatched_detections:
track = Track(start_pos=detections[det_idx], num_classes=self.num_classes, track_id=self._next_id,
iou_thresh=self.min_iou_distance, time_steps=self.time_steps)
self.tracks.append(track)
self._next_id += 1
# terminate older tracks
tracks_to_remove = []
for i in range(len(self.tracks)):
if self.tracks[i].time_since_match > self.max_no_hit:
tracks_to_remove.append(i)
for i in tracks_to_remove:
_ = self.tracks.pop(i)
def initiate_tracks(self, detections):
# initiate new tracks
for detection in detections:
track = Track(start_pos=detection, num_classes=self.num_classes, track_id=self._next_id,
iou_thresh=self.min_iou_distance, time_steps=self.time_steps)
self.tracks.append(track)
self._next_id += 1
def draw_tracks(self, image):
"""
Draws bounding boxes (for each track) on given image
Args:
image: PIL image instance
Returns:
None. Draws in-place.
"""
for track in self.tracks:
if track.state == _NO_MATCH:
continue
box = track.to_tlbr()[-1, :4] # ymin, xmin, ymax, xmax
assert box.shape == (4,), "invalid shape: {}".format(box.shape)
draw_bounding_box_on_image(image, box[0], box[1], box[2], box[3],
display_str_list=["{:02d}".format(track.track_id)])
|
If $f$ and $g$ are holomorphic functions on an open set $s$ containing $z$, and $g(z) \neq 0$, and $f(w) = g(w) (w - z)^n$ for all $w \in s$ with $w \neq z$, then the order of $f$ at $z$ is $n$. |
\chapter{Elliptic Curve Commitments}
\label{chpr:ec-commitments}
Elliptic curve cryptography is used in Bitcoin and in similar systems to secure the transactions.
We will give a brief overview of this cryptosystem, then we show how an elliptic curve point can be a commitment, finally we describe the consequent practical timestamping applications with Bitcoin.
\section{Elliptic Curve Public Key Cryptosystem}
We start with a general definition taken from \cite{Koblitz1987}\footnote{See Appendix \ref{app:A} for a more basic approach.},
\begin{mydef}
An elliptic curve $E_K$ defined over a field $K$ of characteristic $\neq 2, 3$ is the set of solutions $(x,y)\in K^2$ to the equation
\begin{equation}
\label{ec-eq}
y^2 = x^3 + ax + b, \quad a,b \in K
\end{equation}
together with a \textquotedblleft point at infinity\textquotedblright $\mathcal{O}$.
\end{mydef}
$\mathcal{O}$ is the projective closure of (\ref{ec-eq}) and may not be described in terms of two coordinates in $K$.
The points on $E_K$ form a group with identity element the point at infinity. The negative point $P \in E_K$ is the second point on $E_K$ having the same $x$-coordinate as $P$. Let $P_1=(x_1,y_1)$ and $P_2=(x_2,y_2)$ be two points on the curve, their sum $P_3=(x_3,y_3) = P_1 + P_2$ is given by:
\begin{equation}
x_3 = -x_1 -x_2 + \alpha^2, \quad
y_3 = -y_1 + \alpha(x_1 - x_3),
\end{equation}
where
\begin{equation}
\alpha = \begin{cases}
(y_2 - y_1)/(x_2 - x_1) & \textrm{if } P_1 \neq P_2, \\
(3x_1^2 + a)/(2y_1) & \textrm{if } P_1 = P_2.
\end{cases}
\end{equation}
This \textit{addition} operation for elliptic curve points has a geometric interpretation for $K = \mathbb{R}$, from which the above more general algebraic formulae can be derived.
Using these formulae, one can compute a multiple $mP$ of a given point $P$ in polynomial time by means of $O(\log m)$ doubling and additions, e.g. $11P = P + 2(P + 2(2P))$. This operation is called \textit{scalar multiplication}.
In cryptography most applications use finite fields, in particular a finite field contains $p^m$ elements with $p$ prime and $m \geq 1$. We will confine ourselves to the case $m=1$. So let $K=GF(p)=\mathbb{F}_p =\mathbb{Z}_p = \{0, 1, ..., p-1\}$, $K$ is a finite field, the points of $E_K$, together with the addition operation defined above, form a finite Abelian group. The elliptic curve becomes:
%cyclic or product of two cyclic groups
\begin{equation}
E_{\mathbb{F}_p}=\{(x,y)\in \mathbb{F}_p^2 \quad \textmd{s.t. }
y^2 = x^3 + ax + b \mod p, \quad a,b \in \mathbb{F}_p \} \cup \mathcal{O}
\end{equation}
Let $G \in E_{\mathbb{F}_p}$ be a conventional element of order $n$, called $generator$. The subgroup generated by $G$ is:
\begin{equation}
\langle G \rangle = \{xG|x \in \mathbb{Z}_n\} \subseteq E_{\mathbb{F}_p}
\end{equation}
Which is a cyclic group isomorphic to $\mathbb{Z}_n$; in particular, if $n$ is prime, then $\langle G \rangle = E_{\mathbb{F}_p}$.
Computing the isomorphism from $\mathbb{Z}_n$ to $\langle G \rangle$ is efficient, it takes $O(\log n)$ group operations; while the opposite isomorphism is much harder to compute, at moment, the best algorithm known takes approximately $\sqrt{n}$ operations. The latter procedure is called discrete logarithm and it stands at the base of the cryptosystem, more precisely:
\begin{mydef}
Elliptic Curve Discrete Logarithm Problem (ECDLP). Given an elliptic curve $E$ defined over $GF(q)$ and two points $P, Q \in E$, find an integer $x$ such that $Q = xP$ if such $x$ exists.
\end{mydef}
Elliptic curve cryptography is based on the premise that ECDLP is hard, actually it appears to be more intractable than DLP in finite fields.
The ECDLP difficulty enables a Diffie-Hellmann key exchange which precedes the ElGamal signature scheme, these techniques are at the foundations of the public key cryptosystem.
Fixed a point $P \in E_{\mathbb{F}_p}$, a \textit{public key} is a point $Q \in E_{\mathbb{F}_p}$ while its discrete logarithm $x$ w.r.t. $P$ ($xP=Q$) is the \textit{private key}.
Given $x$ is easy and fast to compute $Q$, while given $Q$ is infeasible to find $x$.
To classify different curves the Standard for Efficient Cryptography (SEC) proposed a set of parameter for elliptic curves over $\mathbb{F}_p$:
\begin{equation}
(p, a, b, G, n, h)
\end{equation}
\begin{itemize}
\item $p$ prime defines the finite field $\mathbb{F}_p$
\item $a, b \in \mathbb{F}_p$ define the curve $E_{\mathbb{F}_p}$
\item $G\in E_{\mathbb{F}_p}\backslash \{\mathcal{O}\}$ is a generator of the group
\item $n = |\langle G \rangle|$ is the order of the group (smallest $n>0$ s.t. $nG = \mathcal{O}$)
\item $h = |E_{\mathbb{F}_p}| / n$ is the cofactor
\end{itemize}
Note that if $n$ prime, then $\langle G \rangle = E_{\mathbb{F}_p}$, thus $n = |E_{\mathbb{F}_p}|$, $h=1$.
Bitcoin uses the curve named $secp256k1$ with parameters
\begin{verbatim}
p = 0x FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFE FFFFFC2F
a = 0
b = 7
G = (0x 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9
59F2815B 16F81798,
0x 483ADA77 26A3C465 5DA4FBFC 0E1108A8 FD17B448 A6855419
9C47D08F FB10D4B8)
n = 0x FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B
BFD25E8C D0364141
h = 1
\end{verbatim}
With this curve some calculation becomes more efficient, like computing the modular square root ($\sqrt{x}=x^{\lfloor\frac{p+1}{4}\rfloor}\textmd{ mod }p$, since $p= 3 \textmd{ mod }4$) and the modular inverse ($x^{-1}=x^{p-2}\textmd{ mod }p$, since $p$ prime).
Looking at the generator above one may think that to store an elliptic curve point is necessary to use 32 bytes for the $x$-coordinate and 32 bytes for the $y$-coordinate.
However it is not necessary to use all that space, infact it is possible to take advantage of the elliptic curve equation. Suppose $x \in \mathbb{F}_p$ is the $x$-coordinate of a point, then $y$ is given by $y^2 = x^3 + ax + b \quad \text{mod }p$, which, for $p$ prime, has exactly two solutions in $\mathbb{F}_p$, $y$ and $p-y$, one is odd and the other is even.
The solutions are easily computable thanks to the above formula.
Having consider this, to store an elliptic curve point $P$ one can store $P_x$ and the parity of $P_y$.
In Bitcoin the compressed encoding of a point $P$ is given by a byte for the parity of $P_y$ ($02$ if even, $03$ if odd) followed by the bytes representing $P_x$, for instance the generator $G$ is encoded as follows:
\begin{verbatim}
G = 02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9
59F2815B 16F81798
\end{verbatim}
\section{A New Commitment Operation}
Combining conveniently elliptic curve points and hash functions, it is possible to create new commitment operations.
A similar technique was used for the first time for deriving public keys in deterministic wallets \cite{Max11},
then the concept of embedding a value in an elliptic curve point was exploited \cite{journals/corr/abs-1212-3257, Sidechain},
later it was reformulated in a more refined way \cite{PoePR, PoeIs}
suitable for the integration in OpenTimestamps.
Let's analyse how this new commitment operations are structured.
\begin{myprop}
Let $E_{\mathbb{F}_p}$ be an elliptic curve defined on the finite field $\mathbb{F}_p$ with $p$ prime, $G \in E_{F_p}$ be the generator of the curve with order $n$ large prime. Let $h$ be a random oracle hash function, its input are somehow serialized in bits, its output are in $\{0,1\}^k$ and are interpreted as integers.
Let $C$ be defined as follows:
\begin{equation}
\begin{split}
C : \{0,1\}^* \times E_{\mathbb{F}_p} & \rightarrow E_{\mathbb{F}_p} \\
m, P & \mapsto h(P||m)G + P
\end{split}
\end{equation}
If $n$ is close to $2^k$, then $C$ is a commitment operation.
\end{myprop}
\begin{proof}
First we show a direct proof that works when $P$ (or $P'$) is fixed, then we show the general proof. Actually, in the former case, it is enough requiring $h$ to be second-preimage resistant, while, in the latter, a stronger assumption is needed.
\\
Let $m,P$ and $C(m,P)$ be fixed.
%Let $C(m,P)$ be a commitment to $m, P$.
$\forall P' \in E_{\mathbb{F}_p}$ fixed in advance, the problem is to find $m' \in \{0,1\}^*$ s.t. $C(m,P)=C(m',P')$ and $(m', P') \neq (m, P)$.
We want to show that such problem is infeasible.
$m'$ satisfies $h(m'||P')G + P'=C(m,P)$.
%The substitute value $m'$ needs to satisfy $h(m'||P')G + P'=C(m,P)$.
Let $x$ be such that $xG = C(m,P) - P'$, with $0\leq x<n$.
%so $x=h(P'||m')\textmd{ mod }n$. The problem to find a second preimage $m'$ of $x$.
Let $h_{P'}$ be defined as follows:
\begin{equation*}
\begin{split}
h_{P'}:\{0,1\}^* & \rightarrow \{0,1\}^k\\
m' & \mapsto h(m'||P')
\end{split}
\end{equation*}
Consider the elements in $\{0,1\}^{k}$ equivalent to $x$ modulo $n$, namely $I_x=\{h \in \{0,1\}^k \approx \mathbb{Z}_{2^k} | h=x\textmd{ mod }n\}$.
%Let $I_x=\{h \in \{0,1\}^k \approx \mathbb{Z}_{2^k} | h=x\textmd{ mod }n\}$ be the set of images of $h_{P'}$ suitable to find a second-preimage.
Note that:
\begin{equation*}
|I_x|=\begin{cases}
\lceil\frac{2^k}{n}\rceil & \textmd{if } x\geq n \\
\lfloor\frac{2^k}{n}\rfloor & \textmd{if } x< n
\end{cases}
\end{equation*}
The problem is finding $h_{p'}(m')\in I_x$.
Note that $h_{p'}$ is second-preimage resistant, since it is the composition of two functions with that property, $prepend(P')$ and $h$.
Finally, if $n \approx 2^k$, the elements in $I_x$ are few (eventually a single one), thus finding $m'$ is infeasible because $h_{P'}$ is second-preimage resistant.
%$I_x$ contains $\lceil\frac{2^k}{n}\rceil$ or $\lfloor\frac{2^k}{n}\rfloor$ elements.
%Hence to find a second-preimage one needs to find $m'$ s.t. $h_{P'}(m') \in I_x$. Note that $h_{P'}$ is second-preimage resistant, since it is the composition of two function with that property, $prepend(P')$ and $h$. Finally, if $n \approx 2^k$, the elements in $I_x$ are few (eventually a single one), thus finding $m'$ is unfeasible because $h_{P'}$ is second-preimage resistant.
\\
Now consider the case in which $P$ is not fixed.
We model the hash function $h$ as a random oracle $H$ with range $\{0,1\}^k\approx \mathbb{Z}_{2^k}$.
$H$ initially has an empty table.
When someone queries the oracle for a value $x \in \{0,1\}^*$,
the oracle samples uniformly a random value $H(x)$ in $\mathbb{Z}_{2^k}$ and associate it with $x$.
The oracle outputs $H(x)$ and annotate it on his table.
If someone calls again the oracle for $x$ he will answer with $H(x)$.
The oracle is queried by different entities for possibly different values.
Queries for new values result in a new line in the table.
Thus before querying $H$ for $x \in \{0,1\}^*$, we expect $H$ to output a uniform random value in $\mathbb{Z}_{2^k}$.
\\
Now suppose the discrete logarithm is broken, so anyone can run the map $x \mapsto xG$ both ways.
The map:
\begin{equation*}
\begin{split}
\tilde{C} : \{0,1\}^* \times E_{\mathbb{F}_p} & \rightarrow E_{\mathbb{F}_p} \\
m, P & \mapsto H(P||m)G + P
\end{split}
\end{equation*}
where $h$ is substituted by $H$.
If $P=xG$, it becomes:
\begin{equation*}
\begin{split}
\hat{C} : \{0,1\}^* \times \mathbb{Z}_n & \rightarrow \mathbb{Z}_n \\
m, x & \mapsto (H(xG||m) + x)\textmd{ mod }n
\end{split}
\end{equation*}
We show that $\hat{C}$ can be used as a random oracle.
$H$ is uniformly random and independent from its inputs,
moreover the offset $x$ cannot affect that.
Applying $\textmd{mod }n$ shrinks the range to $\mathbb{Z}_n$,
still $\hat{C}$ can be used as a random oracle.
Finally the output of $\hat{C}$, which is equivalent to $C$, is indistinguishable from the output of a random uniform distribution in $\mathbb{Z}_n$.
Since $n$ is close to $2^k$ finding a second-preimage to $C(m,P)$ is infeasible.
%Now consider the case in which $P$ is not fixed.
%Suppose we are able to find $x$ s.t. $P=xG$, the map $C$ can be seen as $m,x \mapsto x + h(xG||m)$ which is basically $m,x \mapsto x + \tilde{h}(x,m)$ for an opportune $\tilde{h}$.
%If such map is a random oracle then we are done, since random oracles are second preimage resistant.
%We assume $h$ is a random oracle, then also $\tilde{h}$ has the same feature, since it is independent from its input, moreover the offset $x$ does not affect the property.
%Hence we conclude that the map is a random oracle which gives second preimage resistance.
\end{proof}
The order $n$ has to be large so that $E_{\mathbb{F}_p}$ is rich enough to make the ECDLP intractable and to avoid shrinking the hash function codomain. Fixed $n$ the choice of $k$ should be made properly: if it is too low $h$ by itself will be too weak, if it is too high, $|I_x|$ will increase, weakening $C$. Hence a good compromise is choosing $n$ the closest possible to $2^k$.
The security of the commitment is given by the security of the hash function, and does not rely on the intractability of the ECDLP. Being able to compute the private key from the commitment is not enough to compute a second input committing to the same point, to do so it is necessary to able to find a second-preimage to an hash value.
With this commitment an elliptic curve point used for one purpose can be tweaked with $h(P||m)$ and, while still serving for the previous purpose, it can be a commitment to a value $m$. In fact suppose $x$ is the private key of $P$, $P=xG$, then $C(m,P)=(h(P||m)+x)G$. So the new private key is $(h(P||m)+x) \textmd{mod } n$ and, since $x$ is secret and $h(P||m)$ is a constant value, the resulting key is still secret.
So each time an elliptic curve point is written, we can encapsulate it in a commitment to an arbitrary value.
This technique may be extended to more general cases, but we will treat only the case of elliptic curves.
Several hash functions and elliptic curves can be used, considering we want to use Bitcoin as notary, we will focus an a particular case with $h=$ SHA256 and $E_{\mathbb{F}_p}=secp256k1$ since Bitcoin itself relies on the assumption that this hash function and this elliptic curve are not broken.
Moreover, the order of the curve $n$ is extremely close\footnote{Assuming that a generic output $x$ of SHA256 is indistinguishable from a sampling from an uniform distribution in $\mathbb{Z}_{2^{256}}$, then $\mathbb{P}(x\geq n)=1-\frac{n}{2^{256}}\approx 10^{-33}$. So the chance to choose $(P||m)$ leading to $|I_x|=2$ is almost zero.}
to the cardinality of the hash function codomain $2^{256}$. This commitment operation is called \verb|OpSecp256k1Commitment|.
Furthermore, to use this operation in as OpenTimestamp receipt, it has to be an unary operation, hence it will take as input $P||m$ and will return the $x$-coordinate of $C(m P)$ as output, both in bytes. More precisely it will operate as described in Algorithm \ref{alg:opsecp256k1}.
\begin{algorithm}
\caption{Commitment to a $secp256k1$ point using SHA256}
\label{alg:opsecp256k1}
\begin{algorithmic}[1]
\Procedure{OpSecp256k1Commitment}{$c$}\Comment{$c$ is $P||m$}
\State $P,m \gets$ \Call{decode}{$c$}\Comment{for bad $c$ return error}
\State $tweak \gets h(P||m)$\Comment{interpreted as an int}
\State $Q \gets tweak G + P$
\State \textbf{return} \Call{encode}{$Q_x$}\Comment{output in bytes}
\EndProcedure
\end{algorithmic}
\end{algorithm}
It can be used for several purposes, however, for this work, we focus only on timestamping.
\section{Timestamping Applications}
On the Bitcoin chain, elliptic curve points are used as public keys locking bitcoins or as part of the signature. The first case lead to the \textit{pay-to-contract} technique, the second to \textit{sign-to-contract}. We will analyse both uses and we will explain which one should be preferred.
These names owe their origin to the first application for which they were though: associate a \textit{contract} to an elliptic curve point.
The term contract may seem misleading, but it turns out to be useful dealing with \textit{sign-to-contract}, since it let us distinguish between the message signed and the contract committed.
\subsection{\textit{pay-to-contract}}
Public keys are elliptic curve points, here we show how they could commit to a value while still maintaining the secrecy of the private key.
We illustrate it through an example.
Alice needs to send Bob some bitcoins.
Bob has public key $P=xG$.
Bob wants to timestamp the message $m$.
Bob computes $Q=h(P||m)G+P$.
Bob tells Alice that his public key is $Q$.
Alice broadcasts a transaction sending bitcoins to $Q$, for instance she uses a P2PK publishing on the chain:
\begin{verbatim}
script pubkey:
<Q> OP_CHECKSIG
\end{verbatim}
Bob can spend the bitcoin locked in this script because he knows $P$, $m$ and $x$, so he can compute the private key corresponding to $Q$, that is $(h(P||m)+x) \textmd{ mod } n$.
To create the timestamp proof he has to decompose the transaction including $Q$ and create a proof that will look like:
\begin{verbatim}
prepend P
secp256k1commitment
prepend TX_p
append TX_a
sha256
...
sha256
verify BitcoinBlockHeaderAttestation(block)
\end{verbatim}
In the case of P2PKH, the committed public key is hashed as shown in the following real example, where \verb|b'Pay to contract!\n'| is timestamped:
\begin{Verbatim}[frame=single]
File sha256: 47257ff8c07f55a2e697ab9d89e47b471f60ab3f6883ed05
44561b2a39a26140
Timestamp:
prepend 02a1e5aafa5082d035c659143660b2526a4ba60d4ab5b2e603905
0eae9444d56ee
secp256k1commitment
prepend 02
sha256
ripemd160
prepend 01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1
bf933501a87986363464c000000006a47304402207724a6a96e91
a10821ee0c6db30a2f764ba8bd1dcdc82812fb958f6b91e97a4a0
22062db4df7205e6c97d9833f7ab0d597b7685e8320bb2031f57a
a6981cd2f626a40121030eb7a6c01ab07d3bfe598c295e9edfbeb
38e5d2df7320f16b4349fb89a975ab7fdffffff02e22000000000
00001976a914d8da7633fe644eb12617b2b1f0ba3f0461a2bc5e8
8ac10270000000000001976a914
append 88ac4ed90700
# Bitcoin transaction id
1b07d87e0f4e32d545932bf03e306d1532bc7d91f56e81dee81b7cd0b707a9
9d
sha256
sha256
prepend 9d12daa914a3d39cd25b36516383683aae3ac6f873b952bbab11cc
417650bb49
sha256
sha256
prepend 0123f36690131b2416d32a7e6c3c63110d9d77873911f71ad22740
b398a13874
sha256
sha256
append 9f45bbc92ac4ef65b5e5bfad479da46c400f6e7ab96217a20b4e08d
bfab47a45
sha256
sha256
prepend 949c83f6b502ec75c4647da6ed4e26d181de07b325eac75881de7b
b715a44c50
sha256
sha256
prepend 2ef8ff1aad05e891215698fe237546c73347967419f33d08baf0d9
71ab00004d
sha256
sha256
append 9bf69359a440f6a15a2a11adb1f257c96089ad27ef66e57a19056e3
3ecc1795b
sha256
sha256
prepend c1c9bb36792745df3967704dd5d15899bab47b0a9de35486eb339a
b4d00ff340
sha256
sha256
append c0b13e8aa4dc85a8256efb03272dea659e41fc67bc2f44add154111
c68f700be
sha256
sha256
append 1bf843d12afce2a7b02ebe1f083eb2c39a101a63474a622724f609a
3f08f8c7f
sha256
sha256
append a29eece3554c358e5df3901478c8670c71dbafe4e435cf660a18bb6
09d6d025d
sha256
sha256
append aa2c4696c3b75f73713345a7e4279805a9519fd067835769b41dcf7
88d6a7c96
sha256
sha256
prepend f7290a75923a0c54e87a50bbeff75f614437ed799347a46053a633
8dba42b5c7
sha256
sha256
verify BitcoinBlockHeaderAttestation(514394)
# Bitcoin block merkle root
be6859c5093de84a06e495b6621054616ce5bf7a38f24374a225d0da0c0de8
88
\end{Verbatim}
The raw transaction with the above TXID is
\begin{Verbatim}[commandchars=+\[\], frame=single]
01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1bf933501a
87986363464c000000006a47304402207724a6a96e91a10821ee0c6db30a2f
764ba8bd1dcdc82812fb958f6b91e97a4a022062db4df7205e6c97d9833f7a
b0d597b7685e8320bb2031f57aa6981cd2f626a40121030eb7a6c01ab07d3b
fe598c295e9edfbeb38e5d2df7320f16b4349fb89a975ab7fdffffff02e220
0000000000001976a914d8da7633fe644eb12617b2b1f0ba3f0461a2bc5e88
ac10270000000000001976a914+underline[57529515dc2e14701374eb65f0191b61ecfd]
+underline[d0e3]88ac4ed90700
\end{Verbatim}
Where the commitment to the data is underlined.
This technique is completely viable, but it has a relevant issue.
Almost all bitcoin wallets (software to manage private keys) use a deterministic derivation for creating new keys \cite{BIP32}. An initial value is generated at random using a cryptographically secure procedure, this value is called \textit{seed} and sometimes encoded as a list of words from a given dictionary. The keys are obtained from the seed using the specifications given by BIP32 and they are something like $h(seed||number)$. This procedure make possible to completely recover a wallet from the seed only, so if a user wants to use his wallet from another device he just need to remember the seed and all his private keys will be reconstructed.
Using pay-to-contract actually Bob goes outside of the BIP32 derivation. So if he looses $m$ or $P$ he won't be able to spend the bitcoin locked by $Q$. For this reason the use of \textit{pay-to-contract} for mere timestamping purposes should be limited.
In the case of a P2PKH, a timestamp made with \textit{pay-to-contract} reveals the public key which is the preimage of the receiving address.
The public key will be revealed anyway when the corresponding output will be spent, but, if it is still unspent, such disclosure may be an undesired feature.
In addition, when spending that UTXO, the public key is actually written in the chain, giving another anchoring point to create a different timestamp; this timestamp is just another path from the data to the chain, but it is not really useful since it cannot precede the other timestamp.
\subsection{\textit{sign-to-contract}}
The other place where elliptic curve points are published in the chain is the signature. Bitcoin uses the elliptic curve digital signature algorithm, ECDSA\footnote{\textit{sign-to-contract} works also with other signature schemes involving elliptic curves, like Schnorr signature.}, that works as detailed in Algorithm \ref{alg:ecdsa-sign}.
\begin{algorithm}
\caption{ECDSA signature}
\label{alg:ecdsa-sign}
\begin{algorithmic}[1]
\Procedure{ECDSAsig}{$x, m$}\Comment{$x$ private key signing}
\Statex \Comment{$m$ 32 bytes message to be signed}
\State $k \in_R \mathbb{Z}_n \backslash \{0\}$ \Comment{select $k$ at random in $\{1,..., n-1\}$}
\State $R \gets k G$
\State $r \gets R_x \textmd{ mod }n$\Comment{if $r=0$, fail}
\State $s \gets k^{-1}(m + rx) \textmd{ mod }n$\Comment{if $s=0$, fail}
\State \textbf{return} $(r,s)$
\EndProcedure
\end{algorithmic}
\end{algorithm}
The value $k$ is called nonce or \textit{ephemeral private key}, $R$ is called \textit{ephemeral public key}.
A signature is a couple of integers in $\{1,...,n-1\}$, the first one is the $x$-coordinate (mod $n$) of the ephemeral public key.
The idea of \textit{sign-to-contract}, exploited in Algorithm \ref{alg:ecdsa-s2c}, is to tweak $R$, so that the first part of the signature will be a commitment to (also) another message, the contract $c$.
\begin{algorithm}
\caption{ECDSA \textit{sign-to-contract} (s2c)}
\label{alg:ecdsa-s2c}
\begin{algorithmic}[1]
\Procedure{ECDSAs2c}{$x, m, c$}\Comment{$x$ private key signing}
\Statex \Comment{$m$ 32 bytes message to be signed}
\Statex \Comment{$c$ contract to commit}
\State $k \in_R \mathbb{Z}_n \backslash \{0\}$ \Comment{select $k$ at random in $\{1,..., n-1\}$}
\State $R \gets k G$
\State $tweak \gets h(R||c)$\Comment{interpreted as an int}
\State $e \gets (k + tweak) \textmd{ mod }n$ \Comment{if $e=0$, fail}
\State $Q \gets tweak G + R$
\State $q \gets Q_x \textmd{ mod }n$\Comment{if $q=0$, fail}
\Statex \Comment{if $q \neq Q_x$, commitment fail}
\State $s \gets e^{-1}(m + qx) \textmd{ mod }n$\Comment{if $s=0$, fail}
\State \textbf{return} $(q,s), R$\Comment{$R$ is needed to prove the commitment}
\EndProcedure
\end{algorithmic}
\end{algorithm}
Let's examine a real timestamp for the data \verb|b'Sign to contract\n'| made with the described technique.
\begin{Verbatim}[frame=single]
File sha256: dd60bcfecd023823efdcb8d8a5b04939111ef82dc1d674320
7e164e5aab08844
Timestamp:
append eb7e45e783d98504b2e64342b0bea3f5
sha256
prepend 0372a1fb359a24eab552e8c588f84b7e08144bbb10e87bfa6db649
8c7df730e867
secp256k1commitment
prepend 01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1b
f933501a87986363464c010000006a4730440220
append 022057db028ba602b467d09f67b6a6327d3219f2d9a264aae935873
146247a18008a0121027f4b59c84fbad07dec6cff8555214b1d3740
43bcdf47a35fbe08cf5a816b2a9ffdffffff02a6220000000000001
976a914c7a270de581a188f1decef735602cfd65a70607c88ac1027
0000000000001976a914ebc32f6f0a4d63da2d1a2f1f5cb762d0d89
824d488acf3d90700
# Bitcoin transaction id
3b6b0f10729cd0d90087e8c8c9261a2b41afa4e26508591700ddd1790b5087
05
sha256
sha256
append 8c6c3e7341ac6b64c17e4558a5279da1ccf5a0346abbcb1eed412db
103ff7cb5
sha256
sha256
prepend 8446d10571b0a6c63a0fb9538531d846148c9465eff456cccbaf91
1a967bc74c
sha256
sha256
prepend 66cdb8cf28763b45e195028566a0bd976afcf7ad072188e711e515
41f6867e43
sha256
sha256
prepend 465585e6b3ff7dfc8d753acce6e60c1ccd246975641dd4ad8b95c3
803244aca7
sha256
sha256
append 93bcaa3a00534081d6f2230412cde7e59a73acb0d98c809174f630d
e3b07b89d
sha256
sha256
append 0f1b327e68d8700e9c4074d8b4b82b0e28a5a7933f29f643cb27bd5
6bf668ec6
sha256
sha256
append d8738b3726def527296f47a70e0ba6841e35932e2ac8a0832c25393
ee320d4fc
sha256
sha256
append 73694be809a1f8d8a81f55e812c47d388747e1d99003d5b5427ca41
1a5fd4408
sha256
sha256
append 816fb904a9d0678198e84f060aecca9383320bebfec2d23783c922b
cdcb58af2
sha256
sha256
prepend f42214bc9a9c8e4b61a53e51c94ef9bbb2956202356054cd7a7677
858caae2de
sha256
sha256
prepend 1d71d75ef769c40aec08c7ccda1a64a82ee6e858efb5f8598f5199
a093b512d1
sha256
sha256
append 00b4475e869c96c8c297fce9ea8494f0b8f5c74d7b4e6208ba8fc84
d103f61d2
sha256
sha256
verify BitcoinBlockHeaderAttestation(514550)
# Bitcoin block merkle root
1d978e90baecf86c9b59ecad7d8e635da27aad41b39a1d4452c7654f9d5cd3
dd
\end{Verbatim}
The raw transaction with the above TXID is
\begin{Verbatim}[commandchars=+\[\], frame=single]
01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1bf933501a
87986363464c010000006a4730440220+underline[280686720849bfd72a3c7793a45610]
+underline[db2f0152422183bb1f7181ca003674aea5]022057db028ba602b467d09f67b6
a6327d3219f2d9a264aae935873146247a18008a0121027f4b59c84fbad07d
ec6cff8555214b1d374043bcdf47a35fbe08cf5a816b2a9ffdffffff02a622
0000000000001976a914c7a270de581a188f1decef735602cfd65a70607c88
ac10270000000000001976a914ebc32f6f0a4d63da2d1a2f1f5cb762d0d898
24d488acf3d90700
\end{Verbatim}
Where the commitment value is underlined.
Using \textit{sign-to-contract} every signature can include a commitment to a certain value. Contrary to \textit{pay-to-contract}, the loss of $c$ or $R$ leads to the impossibility of proving the commitment but not to a loss of funds. Indeed the signature published on the chain has already provided to its original purpose moving the coins to another owner. This makes \textit{sign-to-contract} a preferable commitment scheme.
In Algorithm \ref{alg:ecdsa-sign} and \ref{alg:ecdsa-s2c} the nonce $k$ is generated at random, however often computers are poor sources of randomness which may lead to security issues, namely exposing the nonce $k$ actually reveals the private key $x$.
To reduce this problem, it is a common practice to avoid the random generation, instead, it is performed a deterministic derivation of the type $k \gets h(x||m)$, the precise specification of $h$ is given by the RFC6979 standard \cite{rfc6979}. With this technique, in a signature, the private key is unique source of entropy used for security, indeed the message $m$ is public and the nonce $k$ is as secret as $x$, since, without $x$, it is not possible to guess $h(x||m)$.
Deterministic nonce and \textit{sign-to-contract} are completely independent techniques that can improve a signature scheme, it is possible to implement one without the other.
In addition, exposing two signature for the same message $m$, generated with the same private key $x$, but made using two different nonces $k_1, k_2$ reveals the private key.
This is a relevant issue when managing bitcoin, however signing with a deterministic nonce solves this problem.
With \textit{sign-to-contract}, considering a message $m$, private $x$, a deterministic nonce, but two contracts $c_1, c_2$, such issue, despite the deterministic derivation, arises again.
Thus is important take care of this chance during the implementation.
Using a deterministic nonce also, in some sense\footnote{To verify that the nonce is deterministic, it is necessary the knowledge of the private key, thus the verification cannot be performed by whoever. Moreover, in some cases, like bitcoin hardware wallets, extracting the secret key may be hard or unsafe.}, closes the subliminal channel in ECDSA signature.
The signer has some arbitrariness in choosing the nonce and could use it to transmit a certain message, as exploited in \cite{DBLP:journals/jsac/Simmons98}.
With \textit{sign-to-contract} the nonce is still deterministic, but is a function of $x,m$ and, in addition, $c$.
The technique could be seen as a particular use of the subliminal channel of ECDSA.
Consider the case where Alice wants to secretly communicate a simple message $c$ to Bob. Alice produces a signature which is a commitment via \textit{sign-to-contract} to a simple message $c$. Alice declares $P$ publicly. Bob knows that $c$ comes from a brute forceable set $S$. Bob sees the signature and tries all $c \in S$ until he finds the one which generated the commitment. As a result, Alice sent to Bob a message without anyone noticing the communication using the subliminal channel that ECDSA leaves open. |
h boast a panoramic ocean view and sun deck. Green lawns and lovely lakes surround the resortβs three-bedroom Villas, all of which boast a private swimming pool facing the ocean. The venueβs Condos, each with a panoramic ocean view and sundeck, have been elegantly designed in harmony with nature. For the ultimate luxury escape, our Penthouses are the best choice.
A sanctuary of exceptional luxury, each of the Cliffβs five breathtaking villas offers an exclusive haven of privacy with 470 sqm total area and private swimming pools overlooking the ocean. These very special villas offer a selection of unique and flexible holiday solutions for extended families, large groups of friends and special occasions such as corporate events and launches, weddings, birthday and anniversary celebrations.
Bed: 2 Kings + Twin. Maximum Capacity: 6 person. |
In 1172 , the new pope , Alexander III , further encouraged Henry to advance the integration of the Irish Church with Rome . Henry was authorised to impose a tithe of one penny per hearth as an annual contribution . This church levy , called Peter 's Pence , is extant in Ireland as a voluntary donation . In turn , Henry accepted the title of Lord of Ireland which Henry conferred on his younger son , John Lackland , in 1185 . This defined the Irish state as the Lordship of Ireland . When Henry 's successor died unexpectedly in 1199 , John inherited the crown of England and retained the Lordship of Ireland .
|
(* This Isabelle theory is produced using the TIP tool offered at the following website:
https://github.com/tip-org/tools
This file was originally provided as part of TIP benchmark at the following website:
https://github.com/tip-org/benchmarks
Yutaka Nagashima at CIIRC, CTU changed the TIP output theory file slightly
to make it compatible with Isabelle2017.*)
theory TIP_sort_HSortIsSort
imports "../../Test_Base"
begin
datatype 'a list = nil2 | cons2 "'a" "'a list"
datatype Heap = Node "Heap" "int" "Heap" | Nil
fun toHeap :: "int list => Heap list" where
"toHeap (nil2) = nil2"
| "toHeap (cons2 y z) = cons2 (Node Nil y Nil) (toHeap z)"
fun insert :: "int => int list => int list" where
"insert x (nil2) = cons2 x (nil2)"
| "insert x (cons2 z xs) =
(if x <= z then cons2 x (cons2 z xs) else cons2 z (insert x xs))"
fun isort :: "int list => int list" where
"isort (nil2) = nil2"
| "isort (cons2 y xs) = insert y (isort xs)"
fun hmerge :: "Heap => Heap => Heap" where
"hmerge (Node z x2 x3) (Node x4 x5 x6) =
(if x2 <= x5 then Node (hmerge x3 (Node x4 x5 x6)) x2 z else
Node (hmerge (Node z x2 x3) x6) x5 x4)"
| "hmerge (Node z x2 x3) (Nil) = Node z x2 x3"
| "hmerge (Nil) y = y"
fun hpairwise :: "Heap list => Heap list" where
"hpairwise (nil2) = nil2"
| "hpairwise (cons2 p (nil2)) = cons2 p (nil2)"
| "hpairwise (cons2 p (cons2 q qs)) =
cons2 (hmerge p q) (hpairwise qs)"
(*fun did not finish the proof*)
function hmerging :: "Heap list => Heap" where
"hmerging (nil2) = Nil"
| "hmerging (cons2 p (nil2)) = p"
| "hmerging (cons2 p (cons2 z x2)) =
hmerging (hpairwise (cons2 p (cons2 z x2)))"
by pat_completeness auto
fun toHeap2 :: "int list => Heap" where
"toHeap2 x = hmerging (toHeap x)"
(*fun did not finish the proof*)
function toList :: "Heap => int list" where
"toList (Node p y q) = cons2 y (toList (hmerge p q))"
| "toList (Nil) = nil2"
by pat_completeness auto
fun hsort :: "int list => int list" where
"hsort x = toList (toHeap2 x)"
theorem property0 :
"((hsort xs) = (isort xs))"
oops
end
|
#' Find the distance from the "from" location to a vector of "to" locations, given their latitude and longitude. Used by the earth.dist function.
#'
#' @param long1 the "from" longitude, in degrees
#' @param lat1 the "from" latitude, in degrees
#' @param long2 the vector of "to" longitudes, in degrees
#' @param lat2 the vector of "to latitudes, in degrees
#'
#' @return numeric scalar distance from the "from" location to the "to" locations.
deg.dist = function (long1, lat1, long2, lat2) {
rad <- pi/180
a1 <- lat1 * rad
a2 <- long1 * rad
b1 <- lat2 * rad
b2 <- long2 * rad
dlon <- b2 - a2
dlat <- b1 - a1
a <- (sin(dlat/2))^2 + cos(a1) * cos(b1) * (sin(dlon/2))^2
c <- 2 * atan2(sqrt(a), sqrt(1 - a))
R <- 40041.47/(2 * pi)
d <- R * c
return(d)
} |
import Categories.2-Category
import Categories.2-Functor
import Categories.Adjoint
import Categories.Adjoint.Construction.EilenbergMoore
import Categories.Adjoint.Construction.Kleisli
import Categories.Adjoint.Equivalence
import Categories.Adjoint.Instance.0-Truncation
import Categories.Adjoint.Instance.01-Truncation
import Categories.Adjoint.Instance.Core
import Categories.Adjoint.Instance.Discrete
import Categories.Adjoint.Instance.PosetCore
import Categories.Adjoint.Instance.StrictCore
import Categories.Adjoint.Mate
import Categories.Adjoint.Properties
import Categories.Adjoint.RAPL
import Categories.Bicategory
import Categories.Bicategory.Bigroupoid
import Categories.Bicategory.Construction.1-Category
import Categories.Bicategory.Instance.Cats
import Categories.Bicategory.Instance.EnrichedCats
import Categories.Category
import Categories.Category.BicartesianClosed
import Categories.Category.Cartesian
import Categories.Category.Cartesian.Properties
import Categories.Category.CartesianClosed
import Categories.Category.CartesianClosed.Canonical
import Categories.Category.CartesianClosed.Locally
import Categories.Category.CartesianClosed.Locally.Properties
import Categories.Category.Closed
import Categories.Category.Cocartesian
import Categories.Category.Cocomplete
import Categories.Category.Cocomplete.Finitely
import Categories.Category.Complete
import Categories.Category.Complete.Finitely
import Categories.Category.Construction.0-Groupoid
import Categories.Category.Construction.Arrow
import Categories.Category.Construction.Cocones
import Categories.Category.Construction.Comma
import Categories.Category.Construction.Cones
import Categories.Category.Construction.Coproduct
import Categories.Category.Construction.Core
import Categories.Category.Construction.EilenbergMoore
import Categories.Category.Construction.Elements
import Categories.Category.Construction.EnrichedFunctors
import Categories.Category.Construction.F-Algebras
import Categories.Category.Construction.Fin
import Categories.Category.Construction.Functors
import Categories.Category.Construction.Graphs
import Categories.Category.Construction.Grothendieck
import Categories.Category.Construction.Kleisli
import Categories.Category.Construction.Path
import Categories.Category.Construction.Presheaves
import Categories.Category.Construction.Properties.Comma
import Categories.Category.Construction.Pullbacks
import Categories.Category.Construction.Thin
import Categories.Category.Core
import Categories.Category.Discrete
import Categories.Category.Equivalence
import Categories.Category.Finite
import Categories.Category.Groupoid
import Categories.Category.Groupoid.Properties
import Categories.Category.Indiscrete
import Categories.Category.Instance.Cats
import Categories.Category.Instance.EmptySet
import Categories.Category.Instance.FamilyOfSets
import Categories.Category.Instance.Globe
import Categories.Category.Instance.Groupoids
import Categories.Category.Instance.One
import Categories.Category.Instance.PointedSets
import Categories.Category.Instance.Posets
import Categories.Category.Instance.Properties.Cats
import Categories.Category.Instance.Properties.Posets
import Categories.Category.Instance.Properties.Setoids
import Categories.Category.Instance.Setoids
import Categories.Category.Instance.Sets
import Categories.Category.Instance.Simplex
import Categories.Category.Instance.SimplicialSet
import Categories.Category.Instance.SingletonSet
import Categories.Category.Instance.Span
import Categories.Category.Instance.StrictCats
import Categories.Category.Instance.StrictGroupoids
import Categories.Category.Instance.Zero
import Categories.Category.Monoidal
import Categories.Category.Monoidal.Braided
import Categories.Category.Monoidal.Braided.Properties
import Categories.Category.Monoidal.Closed
import Categories.Category.Monoidal.Closed.IsClosed
import Categories.Category.Monoidal.Closed.IsClosed.Diagonal
import Categories.Category.Monoidal.Closed.IsClosed.Dinatural
import Categories.Category.Monoidal.Closed.IsClosed.Identity
import Categories.Category.Monoidal.Closed.IsClosed.L
import Categories.Category.Monoidal.Closed.IsClosed.Pentagon
import Categories.Category.Monoidal.Construction.Minus2
import Categories.Category.Monoidal.Core
import Categories.Category.Monoidal.Instance.Cats
import Categories.Category.Monoidal.Instance.One
import Categories.Category.Monoidal.Instance.Setoids
import Categories.Category.Monoidal.Instance.Sets
import Categories.Category.Monoidal.Instance.StrictCats
import Categories.Category.Monoidal.Properties
import Categories.Category.Monoidal.Reasoning
import Categories.Category.Monoidal.Symmetric
import Categories.Category.Monoidal.Traced
import Categories.Category.Monoidal.Utilities
import Categories.Category.Product
import Categories.Category.Product.Properties
import Categories.Category.RigCategory
import Categories.Category.SetoidDiscrete
import Categories.Category.Site
import Categories.Category.Slice
import Categories.Category.Slice.Properties
import Categories.Category.SubCategory
import Categories.Category.Topos
import Categories.Category.WithFamilies
import Categories.Comonad
import Categories.Diagram.Cocone
import Categories.Diagram.Cocone.Properties
import Categories.Diagram.Coend
import Categories.Diagram.Coequalizer
import Categories.Diagram.Coequalizer.Properties
import Categories.Diagram.Colimit
import Categories.Diagram.Colimit.DualProperties
import Categories.Diagram.Colimit.Lan
import Categories.Diagram.Colimit.Properties
import Categories.Diagram.Cone
import Categories.Diagram.Cone.Properties
import Categories.Diagram.Duality
import Categories.Diagram.End
import Categories.Diagram.End.Properties
import Categories.Diagram.Equalizer
import Categories.Diagram.Finite
import Categories.Diagram.Limit
import Categories.Diagram.Limit.Properties
import Categories.Diagram.Limit.Ran
import Categories.Diagram.Pullback
import Categories.Diagram.Pullback.Limit
import Categories.Diagram.Pullback.Properties
import Categories.Diagram.Pushout
import Categories.Diagram.Pushout.Properties
import Categories.Diagram.SubobjectClassifier
import Categories.Enriched.Category
import Categories.Enriched.Functor
import Categories.Enriched.NaturalTransformation
import Categories.Enriched.NaturalTransformation.NaturalIsomorphism
import Categories.Enriched.Over.One
import Categories.Functor
import Categories.Functor.Algebra
import Categories.Functor.Bifunctor
import Categories.Functor.Bifunctor.Properties
import Categories.Functor.Coalgebra
import Categories.Functor.Cocontinuous
import Categories.Functor.Construction.Constant
import Categories.Functor.Construction.Diagonal
import Categories.Functor.Construction.LiftSetoids
import Categories.Functor.Construction.Limit
import Categories.Functor.Construction.Zero
import Categories.Functor.Continuous
import Categories.Functor.Core
import Categories.Functor.Equivalence
import Categories.Functor.Fibration
import Categories.Functor.Groupoid
import Categories.Functor.Hom
import Categories.Functor.Instance.0-Truncation
import Categories.Functor.Instance.01-Truncation
import Categories.Functor.Instance.Core
import Categories.Functor.Instance.Discrete
import Categories.Functor.Instance.SetoidDiscrete
import Categories.Functor.Instance.StrictCore
import Categories.Functor.Monoidal
import Categories.Functor.Power
import Categories.Functor.Power.Functorial
import Categories.Functor.Power.NaturalTransformation
import Categories.Functor.Presheaf
import Categories.Functor.Profunctor
import Categories.Functor.Properties
import Categories.Functor.Representable
import Categories.Functor.Slice
import Categories.GlobularSet
import Categories.Kan
import Categories.Kan.Duality
import Categories.Minus2-Category
import Categories.Minus2-Category.Construction.Indiscrete
import Categories.Minus2-Category.Instance.One
import Categories.Minus2-Category.Properties
import Categories.Monad
import Categories.Monad.Duality
import Categories.Monad.Idempotent
import Categories.Monad.Strong
import Categories.Morphism
import Categories.Morphism.Cartesian
import Categories.Morphism.Duality
import Categories.Morphism.HeterogeneousIdentity
import Categories.Morphism.HeterogeneousIdentity.Properties
import Categories.Morphism.IsoEquiv
import Categories.Morphism.Isomorphism
import Categories.Morphism.Properties
import Categories.Morphism.Reasoning
import Categories.Morphism.Reasoning.Core
import Categories.Morphism.Reasoning.Iso
import Categories.Morphism.Universal
import Categories.NaturalTransformation
import Categories.NaturalTransformation.Core
import Categories.NaturalTransformation.Dinatural
import Categories.NaturalTransformation.Equivalence
import Categories.NaturalTransformation.Hom
import Categories.NaturalTransformation.NaturalIsomorphism
import Categories.NaturalTransformation.NaturalIsomorphism.Equivalence
import Categories.NaturalTransformation.NaturalIsomorphism.Functors
import Categories.NaturalTransformation.NaturalIsomorphism.Properties
import Categories.NaturalTransformation.Properties
import Categories.Object.Coproduct
import Categories.Object.Duality
import Categories.Object.Exponential
import Categories.Object.Initial
import Categories.Object.Product
import Categories.Object.Product.Construction
import Categories.Object.Product.Core
import Categories.Object.Product.Morphisms
import Categories.Object.Terminal
import Categories.Object.Zero
import Categories.Pseudofunctor
import Categories.Pseudofunctor.Instance.EnrichedUnderlying
import Categories.Utils.EqReasoning
import Categories.Utils.Product
import Categories.Yoneda
import Categories.Yoneda.Properties
import Relation.Binary.Construct.Symmetrize
|
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import topology.algebra.module
import linear_algebra.multilinear.basic
/-!
# Continuous multilinear maps
We define continuous multilinear maps as maps from `Ξ (i : ΞΉ), Mβ i` to `Mβ` which are multilinear
and continuous, by extending the space of multilinear maps with a continuity assumption.
Here, `Mβ i` and `Mβ` are modules over a ring `R`, and `ΞΉ` is an arbitrary type, and all these
spaces are also topological spaces.
## Main definitions
* `continuous_multilinear_map R Mβ Mβ` is the space of continuous multilinear maps from
`Ξ (i : ΞΉ), Mβ i` to `Mβ`. We show that it is an `R`-module.
## Implementation notes
We mostly follow the API of multilinear maps.
## Notation
We introduce the notation `M [Γn]βL[R] M'` for the space of continuous `n`-multilinear maps from
`M^n` to `M'`. This is a particular case of the general notion (where we allow varying dependent
types as the arguments of our continuous multilinear maps), but arguably the most important one,
especially when defining iterated derivatives.
-/
open function fin set
open_locale big_operators
universes u v w wβ wβ' wβ wβ wβ
variables {R : Type u} {ΞΉ : Type v} {n : β} {M : fin n.succ β Type w} {Mβ : ΞΉ β Type wβ}
{Mβ' : ΞΉ β Type wβ'} {Mβ : Type wβ} {Mβ : Type wβ} {Mβ : Type wβ} [decidable_eq ΞΉ]
/-- Continuous multilinear maps over the ring `R`, from `Ξ i, Mβ i` to `Mβ` where `Mβ i` and `Mβ`
are modules over `R` with a topological structure. In applications, there will be compatibility
conditions between the algebraic and the topological structures, but this is not needed for the
definition. -/
structure continuous_multilinear_map (R : Type u) {ΞΉ : Type v} (Mβ : ΞΉ β Type wβ) (Mβ : Type wβ)
[decidable_eq ΞΉ] [semiring R] [βi, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[βi, module R (Mβ i)] [module R Mβ] [βi, topological_space (Mβ i)] [topological_space Mβ]
extends multilinear_map R Mβ Mβ :=
(cont : continuous to_fun)
notation M `[Γ`:25 n `]βL[`:25 R `] ` M' := continuous_multilinear_map R (Ξ» (i : fin n), M) M'
namespace continuous_multilinear_map
section semiring
variables [semiring R]
[Ξ i, add_comm_monoid (M i)] [Ξ i, add_comm_monoid (Mβ i)] [Ξ i, add_comm_monoid (Mβ' i)]
[add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [Ξ i, module R (M i)]
[Ξ i, module R (Mβ i)] [Ξ i, module R (Mβ' i)] [module R Mβ]
[module R Mβ] [module R Mβ]
[Ξ i, topological_space (M i)] [Ξ i, topological_space (Mβ i)] [Ξ i, topological_space (Mβ' i)]
[topological_space Mβ] [topological_space Mβ] [topological_space Mβ]
(f f' : continuous_multilinear_map R Mβ Mβ)
instance : has_coe_to_fun (continuous_multilinear_map R Mβ Mβ) (Ξ» _, (Ξ i, Mβ i) β Mβ) :=
β¨Ξ» f, f.to_funβ©
@[continuity] lemma coe_continuous : continuous (f : (Ξ i, Mβ i) β Mβ) := f.cont
@[simp] lemma coe_coe : (f.to_multilinear_map : (Ξ i, Mβ i) β Mβ) = f := rfl
theorem to_multilinear_map_inj :
function.injective (continuous_multilinear_map.to_multilinear_map :
continuous_multilinear_map R Mβ Mβ β multilinear_map R Mβ Mβ)
| β¨f, hfβ© β¨g, hgβ© rfl := rfl
@[ext] theorem ext {f f' : continuous_multilinear_map R Mβ Mβ} (H : β x, f x = f' x) : f = f' :=
to_multilinear_map_inj $ multilinear_map.ext H
@[simp] lemma map_add (m : Ξ i, Mβ i) (i : ΞΉ) (x y : Mβ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.map_add' m i x y
@[simp] lemma map_smul (m : Ξ i, Mβ i) (i : ΞΉ) (c : R) (x : Mβ i) :
f (update m i (c β’ x)) = c β’ f (update m i x) :=
f.map_smul' m i c x
lemma map_coord_zero {m : Ξ i, Mβ i} (i : ΞΉ) (h : m i = 0) : f m = 0 :=
f.to_multilinear_map.map_coord_zero i h
@[simp] lemma map_zero [nonempty ΞΉ] : f 0 = 0 :=
f.to_multilinear_map.map_zero
instance : has_zero (continuous_multilinear_map R Mβ Mβ) :=
β¨{ cont := continuous_const, ..(0 : multilinear_map R Mβ Mβ) }β©
instance : inhabited (continuous_multilinear_map R Mβ Mβ) := β¨0β©
@[simp] lemma zero_apply (m : Ξ i, Mβ i) : (0 : continuous_multilinear_map R Mβ Mβ) m = 0 := rfl
section has_continuous_add
variable [has_continuous_add Mβ]
instance : has_add (continuous_multilinear_map R Mβ Mβ) :=
β¨Ξ» f f', β¨f.to_multilinear_map + f'.to_multilinear_map, f.cont.add f'.contβ©β©
@[simp] lemma add_apply (m : Ξ i, Mβ i) : (f + f') m = f m + f' m := rfl
@[simp] lemma to_multilinear_map_add (f g : continuous_multilinear_map R Mβ Mβ) :
(f + g).to_multilinear_map = f.to_multilinear_map + g.to_multilinear_map :=
rfl
instance add_comm_monoid : add_comm_monoid (continuous_multilinear_map R Mβ Mβ) :=
to_multilinear_map_inj.add_comm_monoid _ rfl (Ξ» _ _, rfl)
/-- Evaluation of a `continuous_multilinear_map` at a vector as an `add_monoid_hom`. -/
def apply_add_hom (m : Ξ i, Mβ i) : continuous_multilinear_map R Mβ Mβ β+ Mβ :=
β¨Ξ» f, f m, rfl, Ξ» _ _, rflβ©
@[simp] lemma sum_apply {Ξ± : Type*} (f : Ξ± β continuous_multilinear_map R Mβ Mβ)
(m : Ξ i, Mβ i) {s : finset Ξ±} : (β a in s, f a) m = β a in s, f a m :=
(apply_add_hom m).map_sum f s
end has_continuous_add
/-- If `f` is a continuous multilinear map, then `f.to_continuous_linear_map m i` is the continuous
linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the
`i`-th coordinate. -/
def to_continuous_linear_map (m : Ξ i, Mβ i) (i : ΞΉ) : Mβ i βL[R] Mβ :=
{ cont := f.cont.comp (continuous_const.update i continuous_id),
.. f.to_multilinear_map.to_linear_map m i }
/-- The cartesian product of two continuous multilinear maps, as a continuous multilinear map. -/
def prod (f : continuous_multilinear_map R Mβ Mβ) (g : continuous_multilinear_map R Mβ Mβ) :
continuous_multilinear_map R Mβ (Mβ Γ Mβ) :=
{ cont := f.cont.prod_mk g.cont,
.. f.to_multilinear_map.prod g.to_multilinear_map }
@[simp] lemma prod_apply
(f : continuous_multilinear_map R Mβ Mβ) (g : continuous_multilinear_map R Mβ Mβ) (m : Ξ i, Mβ i) :
(f.prod g) m = (f m, g m) := rfl
/-- Combine a family of continuous multilinear maps with the same domain and codomains `M' i` into a
continuous multilinear map taking values in the space of functions `Ξ i, M' i`. -/
def pi {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)] [Ξ i, topological_space (M' i)]
[Ξ i, module R (M' i)] (f : Ξ i, continuous_multilinear_map R Mβ (M' i)) :
continuous_multilinear_map R Mβ (Ξ i, M' i) :=
{ cont := continuous_pi $ Ξ» i, (f i).coe_continuous,
to_multilinear_map := multilinear_map.pi (Ξ» i, (f i).to_multilinear_map) }
@[simp] lemma coe_pi {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)]
[Ξ i, topological_space (M' i)] [Ξ i, module R (M' i)]
(f : Ξ i, continuous_multilinear_map R Mβ (M' i)) :
β(pi f) = Ξ» m j, f j m :=
rfl
lemma pi_apply {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)]
[Ξ i, topological_space (M' i)] [Ξ i, module R (M' i)]
(f : Ξ i, continuous_multilinear_map R Mβ (M' i)) (m : Ξ i, Mβ i) (j : ΞΉ') :
pi f m j = f j m :=
rfl
/-- If `g` is continuous multilinear and `f` is a collection of continuous linear maps,
then `g (fβ mβ, ..., fβ mβ)` is again a continuous multilinear map, that we call
`g.comp_continuous_linear_map f`. -/
def comp_continuous_linear_map
(g : continuous_multilinear_map R Mβ' Mβ) (f : Ξ i : ΞΉ, Mβ i βL[R] Mβ' i) :
continuous_multilinear_map R Mβ Mβ :=
{ cont := g.cont.comp $ continuous_pi $ Ξ»j, (f j).cont.comp $ continuous_apply _,
.. g.to_multilinear_map.comp_linear_map (Ξ» i, (f i).to_linear_map) }
@[simp] lemma comp_continuous_linear_map_apply (g : continuous_multilinear_map R Mβ' Mβ)
(f : Ξ i : ΞΉ, Mβ i βL[R] Mβ' i) (m : Ξ i, Mβ i) :
g.comp_continuous_linear_map f m = g (Ξ» i, f i $ m i) :=
rfl
/-- Composing a continuous multilinear map with a continuous linear map gives again a
continuous multilinear map. -/
def _root_.continuous_linear_map.comp_continuous_multilinear_map
(g : Mβ βL[R] Mβ) (f : continuous_multilinear_map R Mβ Mβ) :
continuous_multilinear_map R Mβ Mβ :=
{ cont := g.cont.comp f.cont,
.. g.to_linear_map.comp_multilinear_map f.to_multilinear_map }
@[simp] lemma _root_.continuous_linear_map.comp_continuous_multilinear_map_coe (g : Mβ βL[R] Mβ)
(f : continuous_multilinear_map R Mβ Mβ) :
((g.comp_continuous_multilinear_map f) : (Ξ i, Mβ i) β Mβ) =
(g : Mβ β Mβ) β (f : (Ξ i, Mβ i) β Mβ) :=
by { ext m, refl }
/-- `continuous_multilinear_map.pi` as an `equiv`. -/
@[simps]
def pi_equiv {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)]
[Ξ i, topological_space (M' i)] [Ξ i, module R (M' i)] :
(Ξ i, continuous_multilinear_map R Mβ (M' i)) β
continuous_multilinear_map R Mβ (Ξ i, M' i) :=
{ to_fun := continuous_multilinear_map.pi,
inv_fun := Ξ» f i, (continuous_linear_map.proj i : _ βL[R] M' i).comp_continuous_multilinear_map f,
left_inv := Ξ» f, by { ext, refl },
right_inv := Ξ» f, by { ext, refl } }
/-- In the specific case of continuous multilinear maps on spaces indexed by `fin (n+1)`, where one
can build an element of `Ξ (i : fin (n+1)), M i` using `cons`, one can express directly the
additivity of a multilinear map along the first variable. -/
lemma cons_add (f : continuous_multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.succ) (x y : M 0) :
f (cons (x+y) m) = f (cons x m) + f (cons y m) :=
f.to_multilinear_map.cons_add m x y
/-- In the specific case of continuous multilinear maps on spaces indexed by `fin (n+1)`, where one
can build an element of `Ξ (i : fin (n+1)), M i` using `cons`, one can express directly the
multiplicativity of a multilinear map along the first variable. -/
lemma cons_smul
(f : continuous_multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.succ) (c : R) (x : M 0) :
f (cons (c β’ x) m) = c β’ f (cons x m) :=
f.to_multilinear_map.cons_smul m c x
lemma map_piecewise_add (m m' : Ξ i, Mβ i) (t : finset ΞΉ) :
f (t.piecewise (m + m') m') = β s in t.powerset, f (s.piecewise m m') :=
f.to_multilinear_map.map_piecewise_add _ _ _
/-- Additivity of a continuous multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
lemma map_add_univ [fintype ΞΉ] (m m' : Ξ i, Mβ i) :
f (m + m') = β s : finset ΞΉ, f (s.piecewise m m') :=
f.to_multilinear_map.map_add_univ _ _
section apply_sum
open fintype finset
variables {Ξ± : ΞΉ β Type*} [fintype ΞΉ] (g : Ξ i, Ξ± i β Mβ i) (A : Ξ i, finset (Ξ± i))
/-- If `f` is continuous multilinear, then `f (Ξ£_{jβ β Aβ} gβ jβ, ..., Ξ£_{jβ β Aβ} gβ jβ)` is the
sum of `f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all functions with `r 1 β Aβ`, ...,
`r n β Aβ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
lemma map_sum_finset :
f (Ξ» i, β j in A i, g i j) = β r in pi_finset A, f (Ξ» i, g i (r i)) :=
f.to_multilinear_map.map_sum_finset _ _
/-- If `f` is continuous multilinear, then `f (Ξ£_{jβ} gβ jβ, ..., Ξ£_{jβ} gβ jβ)` is the sum of
`f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
lemma map_sum [β i, fintype (Ξ± i)] :
f (Ξ» i, β j, g i j) = β r : Ξ i, Ξ± i, f (Ξ» i, g i (r i)) :=
f.to_multilinear_map.map_sum _
end apply_sum
section restrict_scalar
variables (R) {A : Type*} [semiring A] [has_scalar R A] [Ξ (i : ΞΉ), module A (Mβ i)]
[module A Mβ] [β i, is_scalar_tower R A (Mβ i)] [is_scalar_tower R A Mβ]
/-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R`
and their actions on all involved modules agree with the action of `R` on `A`. -/
def restrict_scalars (f : continuous_multilinear_map A Mβ Mβ) :
continuous_multilinear_map R Mβ Mβ :=
{ to_multilinear_map := f.to_multilinear_map.restrict_scalars R,
cont := f.cont }
@[simp] lemma coe_restrict_scalars (f : continuous_multilinear_map A Mβ Mβ) :
β(f.restrict_scalars R) = f := rfl
end restrict_scalar
end semiring
section ring
variables [ring R] [βi, add_comm_group (Mβ i)] [add_comm_group Mβ]
[βi, module R (Mβ i)] [module R Mβ] [βi, topological_space (Mβ i)] [topological_space Mβ]
(f f' : continuous_multilinear_map R Mβ Mβ)
@[simp] lemma map_sub (m : Ξ i, Mβ i) (i : ΞΉ) (x y : Mβ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) :=
f.to_multilinear_map.map_sub _ _ _ _
section topological_add_group
variable [topological_add_group Mβ]
instance : has_neg (continuous_multilinear_map R Mβ Mβ) :=
β¨Ξ» f, {cont := f.cont.neg, ..(-f.to_multilinear_map)}β©
@[simp] lemma neg_apply (m : Ξ i, Mβ i) : (-f) m = - (f m) := rfl
instance : has_sub (continuous_multilinear_map R Mβ Mβ) :=
β¨Ξ» f g, { cont := f.cont.sub g.cont, .. (f.to_multilinear_map - g.to_multilinear_map) }β©
@[simp] lemma sub_apply (m : Ξ i, Mβ i) : (f - f') m = f m - f' m := rfl
instance : add_comm_group (continuous_multilinear_map R Mβ Mβ) :=
to_multilinear_map_inj.add_comm_group _ rfl (Ξ» _ _, rfl) (Ξ» _, rfl) (Ξ» _ _, rfl)
end topological_add_group
end ring
section comm_semiring
variables [comm_semiring R]
[βi, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[βi, module R (Mβ i)] [module R Mβ]
[βi, topological_space (Mβ i)] [topological_space Mβ]
(f : continuous_multilinear_map R Mβ Mβ)
lemma map_piecewise_smul (c : ΞΉ β R) (m : Ξ i, Mβ i) (s : finset ΞΉ) :
f (s.piecewise (Ξ» i, c i β’ m i) m) = (β i in s, c i) β’ f m :=
f.to_multilinear_map.map_piecewise_smul _ _ _
/-- Multiplicativity of a continuous multilinear map along all coordinates at the same time,
writing `f (Ξ» i, c i β’ m i)` as `(β i, c i) β’ f m`. -/
lemma map_smul_univ [fintype ΞΉ] (c : ΞΉ β R) (m : Ξ i, Mβ i) :
f (Ξ» i, c i β’ m i) = (β i, c i) β’ f m :=
f.to_multilinear_map.map_smul_univ _ _
variables {R' A : Type*} [comm_semiring R'] [semiring A] [algebra R' A]
[Ξ i, module A (Mβ i)] [module R' Mβ] [module A Mβ] [is_scalar_tower R' A Mβ]
[topological_space R'] [has_continuous_smul R' Mβ]
instance : has_scalar R' (continuous_multilinear_map A Mβ Mβ) :=
β¨Ξ» c f, { cont := continuous_const.smul f.cont, .. c β’ f.to_multilinear_map }β©
@[simp] lemma smul_apply (f : continuous_multilinear_map A Mβ Mβ) (c : R') (m : Ξ i, Mβ i) :
(c β’ f) m = c β’ f m := rfl
@[simp] lemma to_multilinear_map_smul (c : R') (f : continuous_multilinear_map A Mβ Mβ) :
(c β’ f).to_multilinear_map = c β’ f.to_multilinear_map :=
rfl
instance {R''} [comm_semiring R''] [has_scalar R' R''] [algebra R'' A]
[module R'' Mβ] [is_scalar_tower R'' A Mβ] [is_scalar_tower R' R'' Mβ]
[topological_space R''] [has_continuous_smul R'' Mβ]:
is_scalar_tower R' R'' (continuous_multilinear_map A Mβ Mβ) :=
β¨Ξ» cβ cβ f, ext $ Ξ» x, smul_assoc _ _ _β©
variable [has_continuous_add Mβ]
/-- The space of continuous multilinear maps over an algebra over `R` is a module over `R`, for the
pointwise addition and scalar multiplication. -/
instance : module R' (continuous_multilinear_map A Mβ Mβ) :=
{ one_smul := Ξ» f, ext $ Ξ» x, one_smul _ _,
mul_smul := Ξ» cβ cβ f, ext $ Ξ» x, mul_smul _ _ _,
smul_zero := Ξ» r, ext $ Ξ» x, smul_zero _,
smul_add := Ξ» r fβ fβ, ext $ Ξ» x, smul_add _ _ _,
add_smul := Ξ» rβ rβ f, ext $ Ξ» x, add_smul _ _ _,
zero_smul := Ξ» f, ext $ Ξ» x, zero_smul _ _ }
/-- Linear map version of the map `to_multilinear_map` associating to a continuous multilinear map
the corresponding multilinear map. -/
@[simps] def to_multilinear_map_linear :
(continuous_multilinear_map A Mβ Mβ) ββ[R'] (multilinear_map A Mβ Mβ) :=
{ to_fun := Ξ» f, f.to_multilinear_map,
map_add' := Ξ» f g, rfl,
map_smul' := Ξ» c f, rfl }
/-- `continuous_multilinear_map.pi` as a `linear_equiv`. -/
@[simps {simp_rhs := tt}]
def pi_linear_equiv {ΞΉ' : Type*} {M' : ΞΉ' β Type*}
[Ξ i, add_comm_monoid (M' i)] [Ξ i, topological_space (M' i)] [β i, has_continuous_add (M' i)]
[Ξ i, module R' (M' i)] [Ξ i, module A (M' i)] [β i, is_scalar_tower R' A (M' i)]
[Ξ i, has_continuous_smul R' (M' i)] :
-- typeclass search doesn't find this instance, presumably due to struggles converting
-- `Ξ i, module R (M' i)` to `Ξ i, has_scalar R (M' i)` in dependent arguments.
let inst : has_continuous_smul R' (Ξ i, M' i) := pi.has_continuous_smul in
(Ξ i, continuous_multilinear_map A Mβ (M' i)) ββ[R']
continuous_multilinear_map A Mβ (Ξ i, M' i) :=
{ map_add' := Ξ» x y, rfl,
map_smul' := Ξ» c x, rfl,
.. pi_equiv }
end comm_semiring
end continuous_multilinear_map
|
module globdata
! This module defines global parameters and variables for the mathinit and
! mathtool programs.
! David H Bailey 7 Mar 2012
! Parameter Default
! Name Value Explanation
! mxres 999 Size of result table, ie when one types "result[34]".
! nfuna 27 Number of predefined functions.
! nfunx 100 Maximum number of functions (including predefined).
! nfunz 75 nfunx - nfuna.
! ndigi 100 Initial precision level, in digits, not exceed ndigmx1.
! ndigmx1 1000 Maximum primary precision level, in digits (see note).
! ndigmx2 2000 Maximum secondary precision level, in digits (see note).
! nquadx 10 Maximum number of quadrature "levels".
! nquadz 18432 Size of quadrature table, in MP values (see note).
! ntmpx 100 Maximum number of temporary variables.
! nvara 7 Number of predefined constants (e, pi, etc).
! nvarb 9 Number of predefined arguments (arg1, arg2, etc).
! nvarc 7 Number of predefined variables (digits, epsilon, etc).
! nvarx 200 Maximum number of variables (including predefined).
! nvarz 76 nvarx - nvara - nvarb - nvarc.
! Variable
! Name Explanation
! ndebug Debug printout level: 0 = none; 3 = max.
! ndigits1 Primary working precision, in digits.
! ndigits2 Secondary precision, in digits.
! nef Output format: 1 = E format; 2 = F format.
! nef1 Width of output format.
! nef2 Digits after period in output format.
! nerror Error number (error has occurred if nonzero).
! nepsilon1 Primary epsilon variable (epsilon value = 10^(10-nepsilon)).
! nepsilon2 Secondary epsilon variable (epsilon2 value = 10^(10-nepsilon2).
! nfun Number of defined functions (including predefined).
! npslqb PSLQ bound (iterations are terminated when bound > 10^npslqb).
! npslql PSLQ level: 1, 2 or 3. PSLQ level 3 is not yet implemented.
! nquadl Quadrature level (at most nquadl levels are used).
! nquadt Quadrature type: 1 = Gaussian; 2 = erf; 3 = tanh-sinh.
! nvar Number of defined variables (including predefined).
! nwords1 Number of words of primary precision.
! nwords2 Number of words of secondary precision.
! Array
! Name Type Explanation
! narg integer Number of arguments for defined functions.
! fund char Function definitions.
! funn char Function names.
! varn char Variable names.
! quadn char Names of the three quadrature types.
! quadwk mp_real Quadrature weights.
! quadxk mp_real Quadrature abscissas.
! result mp_real Array of results, ie when one types "result[34]".
! var mp_real Variable values.
! If any change is made to this file, then at the least this file must be
! re-compiled, then all the mathtool files must be re-compiled and re-linked.
! If either ndigmx1, ndigmx2 or nquadx is changed, then in addition the
! mathinit.f program must be re-compiled and re-run. Additionally, if
! ndigmx1 or ndigmx2 is changed, make sure that neither exceeds mpipl in
! mp_mod.f. If either exceeds, then mpipl must be increased to at least this
! level and mp_mod.f must be re-compiled; then all mathtool files must be
! re-compiled, and the mathinit.f program must be re-compiled and re-run.
! Finally, if ndigmx1 exceeds 2000, then all instances of "2048" in this file,
! mathtool.f and quadsub.f must be changed to at least ndigmx1 + 40, and then
! all programs must be re-compiled and re-linked.
use mpmodule
implicit none
integer i, j
private i, j
integer mxres, ndebug, ndigi, ndigmx1, ndigmx2, ndigits1, ndigits2, nef, &
nef1, nef2, nepsilon1, nepsilon2, nerror, nfun, nfuna, nfunx, nfunz, &
npslqb, npslql, nquadl, nquadt, nquadx, nquadz, ntmpx, nvar, nvara, nvarb, &
nvarc, nvarx, nvarz, nwords1, nwords2
parameter (mxres = 999, nfuna = 30, nfunx = 100, nfunz = nfunx - nfuna, &
ndigi = 100, ndigmx1 = 1000, ndigmx2 = 2000, nquadx = 10, &
nquadz = 18 * 2 ** nquadx + 200, ntmpx = 100, nvara = 7, nvarb = 9, &
nvarc = 9, nvarx = 200, nvarz = nvarx - nvara - nvarb - nvarc)
integer narg(nfunx)
character*2048 fund(nfunx)
character*76 funhelp(4,nfuna)
character*16 funn(nfunx)
character*16 varn(nvarx)
character*16 quadn(3)
type (mp_real) quadwk(-1:nquadz), quadxk(-1:nquadz), result(mxres), var(nvarx)
data narg /1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 2, 2, 2, 1000, 1000, &
1, 1, 1, 4, 4, 1, 1, 1000, 1000, nfunz*0/
data fund /100 * ' '/
data funn /'Abs', 'Arccos', 'Arcsin', 'Arctan', 'Arctan2', 'Bessel', &
'Besselexp', 'Binomial', 'Cos', 'Erf', 'Exp', 'Factorial', 'Gamma', 'Int', &
'Integrate', 'Log', 'Max', 'Min', 'Mod', 'Polyroot', 'Pslq', 'Result', 'Sin', &
'Sqrt', 'Sum', 'Table', 'Tan', 'Zeta', 'Zetap', 'Zetaz', nfunz*' '/
data varn /'E', 'Log2', 'Log10', 'Pi', 'Catalan', 'Eulergamma', 'Infinity', &
'Arg1', 'Arg2', 'Arg3', 'Arg4', 'Arg5', 'Arg6', 'Arg7', 'Arg8', 'Arg9', &
'Debug', 'Digits', 'Digits2', 'Epsilon', 'Epsilon2', 'Pslqbound', &
'Pslqlevel', 'Quadlevel', 'Quadtype', nvarz*' '/
data quadn /'Gaussian', 'Error function', 'Tanh-Sinh'/
data ((funhelp(i,j), i = 1, 4), j = 1, 15) / &
'Abs[x] computes the absolute value of the x.', 3*' ', &
'Arccos[x] computes arccos of x, with result in [0,pi].', 3*' ',&
'Arcsin[x] computes arcsin of x, with result in [-pi/2,pi/2].', 3*' ', &
'Arctan[x] computes arctan of x, with result in [-pi/2,pi/2].', 3*' ',&
'Arctan2[y,x] computes arctangent of y/x, ie placing result in (-pi,pi]', &
'according to the coordinates (x,y). x or y may be 0 but not both.', 2*' ', &
'Bessel[x] computes BesselI[0,x].', 3*' ', &
'Besselexp[x] computes BesselI[0,x] / Exp[x].', 3*' ',&
'Binomial[m,n] computes the binomial coefficient of integers (m,n).', 3*' ', &
'Cos[x] computes the cosine of x.', 3*' ', &
'Erf[x] computes the error function of x.', 3*' ', &
'Exp[x] computes the exponential function of x.', 3*' ', &
'Factorial[n] computes the factorial of the integer n.', 3*' ', &
'Gamma[x] computes the Gamma function.', 3*' ', &
'Int[x] returns the integer part of x (closest to zero).', 3*' ', &
'Integrate[fun[x], {x, a, b}] computes the integral of function fun[x] (which', &
'may be an expression involving x), from x=a to x=b. Either a or b or both', &
'may be "infinity" or "-infinity". fun[x] may have a singularity at a or b,',&
'but not between. quadlevel (4-10) controls level; quadtype (1-3) is type.'/
data ((funhelp(i,j), i = 1, 4), j = 16, 22) / &
'Log[x] computes the natural logarithm of x.', 3*' ', &
'Max[x,y] returns the maximum of x and y.', 3*' ', &
'Min[x,y] returns the minimum of x and y.', 3*' ', &
'Mod[x,y] return x modulo y, i.e., x - floor(x/y).', 3*' ', &
'Polyroot[1,2,3,4,{-6}] finds the real root of polynomial 1+2x+3x^2+4x^3', &
'near -6. Polyroot[1, 2, 3, {-0.33, 0.47}] finds the complex root of', &
'1+2x+3x^2 near -0.33+0.47i. Starting value should be close to root,', &
'otherwise no root may be found. Some experimentation may be necessary.', &
'Pslq[x1,x2,...,xn] finds integers ai such that a1*x1+a2*x2+...+an*xn = 0,', &
'to within tolerance 10^epsilon. The xi may be expressions; n <= 50. The', &
'search is terminated when the relation bound exceeds 10^pslqbound. A two-', &
'level PSLQ (faster for large n) may be selected by typing "pslqlevel=2".', &
'Result[n] is used to recall the n-th result from the Toolkit.', 3*' '/
data ((funhelp(i,j), i = 1, 4), j = 23, nfuna) / &
'Sin[x] computes the sine of x.', 3*' ', &
'Sqrt[x] computes the square root of x.', 3*' ', &
'Sum[fun[n], {n,a,b}] computes the sum of the function fun[n] (which may be', &
'an expression involving n), from n=a to n=b (integer a and b). The', &
'parameter b may be "infinity". The function fun should rapidly go to 0;', &
'otherwise "infinite" summations may take an unreasonably long run time.', &
'Table[fun[n], {n,a,b}] generates the list (fun[a], fun[a+1], ..., fun[b]),', &
'where a and b are integers. No more than 50 entries may generated.', 2*' ', &
'Tan[x] computes the tangent of x.', 3*' ', &
'Zeta[n] computes the Riemann zeta function of positive integer n.', 3*' ', &
'Zetap[n1, n2, ..., nk] computes the multi-zeta function zetap for positive', &
'integers ni. See http://www.cecm.sfu.ca/projects/EZFace for definition.', &
2*' ', &
'Zetaz[n1, n2, ..., nk] computes the multi-zeta function zetaz for positive', &
'integers ni. See http://www.cecm.sfu.ca/projects/EZFace for definition.', &
2*' '/
end
|
Part 1: The operator had entered "YES" against "Information Sharing Consent", although I had answered "NO" in the written application form.
I demanded for "Consent for correction" to be raised (bearing enrollment number 2189/42026/01608) to correct this.
Part 2: Rs.110 was collected from me towards the enrollment. When I asked for the receipt, the operator said "No receipts will be given". |
module Examples.Type where
open import Agda.Builtin.Equality using (_β‘_; refl)
open import FFI.Data.String using (_++_)
open import Luau.Type using (nil; _βͺ_; _β©_; _β_)
open import Luau.Type.ToString using (typeToString)
ex1 : typeToString(nil) β‘ "nil"
ex1 = refl
ex2 : typeToString(nil β nil) β‘ "(nil) -> nil"
ex2 = refl
ex3 : typeToString(nil β (nil β nil)) β‘ "(nil) -> (nil) -> nil"
ex3 = refl
ex4 : typeToString(nil βͺ (nil β (nil β nil))) β‘ "((nil) -> (nil) -> nil)?"
ex4 = refl
ex5 : typeToString(nil β ((nil β nil) βͺ nil)) β‘ "(nil) -> ((nil) -> nil)?"
ex5 = refl
ex6 : typeToString((nil β nil) βͺ (nil β (nil β nil))) β‘ "((nil) -> nil | (nil) -> (nil) -> nil)"
ex6 = refl
ex7 : typeToString((nil β nil) βͺ ((nil β (nil β nil)) βͺ nil)) β‘ "((nil) -> nil | (nil) -> (nil) -> nil)?"
ex7 = refl
|
@testset "simple.jl" begin
# Load all required packages and define likelihood functions
β(x) = logpdf(Normal(x, 0.5), 1.0)
βvec(x) = logpdf(MvNormal(x, 0.25 * I), [1.0])
@everywhere begin
β(x) = logpdf(Normal(x, 0.5), 1.0)
βvec(x) = logpdf(MvNormal(x, 0.25 * I), [1.0])
end
@testset "Scalar model" begin
Random.seed!(1)
# model
prior = Normal(0, 1)
# true posterior
ΞΌ = 0.8
ΟΒ² = 0.2
# regular sampling
samples = sample(ESSModel(prior, β), ESS(), 2_000; progress=false)
@test samples isa Vector{Float64}
@test length(samples) == 2_000
@test mean(samples) β ΞΌ atol = 0.05
@test var(samples) β ΟΒ² atol = 0.05
# parallel sampling
for alg in (MCMCThreads(), MCMCDistributed(), MCMCSerial())
samples = sample(ESSModel(prior, β), ESS(), alg, 2_000, 5; progress=false)
@test samples isa Vector{Vector{Float64}}
@test length(samples) == 5
@test all(length(x) == 2_000 for x in samples)
@test mean(mean, samples) β ΞΌ atol = 0.05
@test mean(var, samples) β ΟΒ² atol = 0.05
# initial parameter
init_x = randn(5)
samples = sample(
ESSModel(prior, β), ESS(), alg, 10, 5; progress=false, init_params=init_x
)
@test map(first, samples) == init_x
end
# initial parameter
init_x = randn()
samples = sample(ESSModel(prior, β), ESS(), 10; progress=false, init_params=init_x)
@test first(samples) == init_x
end
@testset "Scalar model with nonzero mean" begin
Random.seed!(1)
# model
prior = Normal(0.5, 1)
# true posterior
ΞΌ = 0.9
ΟΒ² = 0.2
# regular sampling
samples = sample(ESSModel(prior, β), ESS(), 2_000; progress=false)
@test samples isa Vector{Float64}
@test length(samples) == 2_000
@test mean(samples) β ΞΌ atol = 0.05
@test var(samples) β ΟΒ² atol = 0.05
# parallel sampling
for alg in (MCMCThreads(), MCMCDistributed(), MCMCSerial())
samples = sample(ESSModel(prior, β), ESS(), alg, 2_000, 5; progress=false)
@test samples isa Vector{Vector{Float64}}
@test length(samples) == 5
@test all(length(x) == 2_000 for x in samples)
@test mean(mean, samples) β ΞΌ atol = 0.05
@test mean(var, samples) β ΟΒ² atol = 0.05
# initial parameter
init_x = randn(5)
samples = sample(
ESSModel(prior, β), ESS(), alg, 10, 5; progress=false, init_params=init_x
)
@test map(first, samples) == init_x
end
# initial parameter
init_x = randn()
samples = sample(ESSModel(prior, β), ESS(), 10; progress=false, init_params=init_x)
@test first(samples) == init_x
end
@testset "Scalar model (vectorized)" begin
Random.seed!(1)
# model
prior = MvNormal([0.0], I)
# true posterior
ΞΌ = [0.8]
ΟΒ² = [0.2]
# regular sampling
samples = sample(ESSModel(prior, βvec), ESS(), 2_000; progress=false)
@test samples isa Vector{Vector{Float64}}
@test length(samples) == 2_000
@test all(length(x) == 1 for x in samples)
@test mean(samples) β ΞΌ atol = 0.05
@test var(samples) β ΟΒ² atol = 0.05
# parallel sampling
for alg in (MCMCThreads(), MCMCDistributed(), MCMCSerial())
samples = sample(ESSModel(prior, βvec), ESS(), alg, 2_000, 5; progress=false)
@test samples isa Vector{Vector{Vector{Float64}}}
@test length(samples) == 5
@test all(length(x) == 2_000 for x in samples)
@test mean(mean, samples) β ΞΌ atol = 0.05
@test mean(var, samples) β ΟΒ² atol = 0.05
# initial parameter
init_x = [randn(1) for _ in 1:5]
samples = sample(
ESSModel(prior, βvec), ESS(), alg, 10, 5; progress=false, init_params=init_x
)
@test map(first, samples) == init_x
end
# initial parameter
init_x = randn(1)
samples = sample(
ESSModel(prior, βvec), ESS(), 10; progress=false, init_params=init_x
)
@test first(samples) == init_x
end
@testset "Scalar model with nonzero mean (vectorized)" begin
Random.seed!(1)
# model
prior = MvNormal([0.5], I)
# true posterior
ΞΌ = [0.9]
ΟΒ² = [0.2]
# regular sampling
samples = sample(ESSModel(prior, βvec), ESS(), 2_000; progress=false)
@test samples isa Vector{Vector{Float64}}
@test length(samples) == 2_000
@test all(length(x) == 1 for x in samples)
@test mean(samples) β ΞΌ atol = 0.05
@test var(samples) β ΟΒ² atol = 0.05
# parallel sampling
for alg in (MCMCThreads(), MCMCDistributed(), MCMCSerial())
samples = sample(ESSModel(prior, βvec), ESS(), alg, 2_000, 5; progress=false)
@test samples isa Vector{Vector{Vector{Float64}}}
@test length(samples) == 5
@test all(length(x) == 2_000 for x in samples)
@test mean(mean, samples) β ΞΌ atol = 0.05
@test mean(var, samples) β ΟΒ² atol = 0.05
# initial parameter
init_x = [randn(1) for _ in 1:5]
samples = sample(
ESSModel(prior, βvec), ESS(), alg, 10, 5; progress=false, init_params=init_x
)
@test map(first, samples) == init_x
end
# initial parameter
init_x = randn(1)
samples = sample(
ESSModel(prior, βvec), ESS(), 10; progress=false, init_params=init_x
)
@test first(samples) == init_x
end
end
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.discrete_category
import Mathlib.PostPort
universes v u
namespace Mathlib
/-!
# The empty category
Defines a category structure on `pempty`, and the unique functor `pempty β₯€ C` for any category `C`.
-/
namespace category_theory
namespace functor
/-- The canonical functor out of the empty category. -/
def empty (C : Type u) [category C] : discrete pempty β₯€ C := discrete.functor pempty.elim
/-- Any two functors out of the empty category are isomorphic. -/
def empty_ext {C : Type u} [category C] (F : discrete pempty β₯€ C) (G : discrete pempty β₯€ C) :
F β
G :=
discrete.nat_iso fun (x : discrete pempty) => pempty.elim x
/--
Any functor out of the empty category is isomorphic to the canonical functor from the empty
category.
-/
def unique_from_empty {C : Type u} [category C] (F : discrete pempty β₯€ C) : F β
empty C :=
empty_ext F (empty C)
/--
Any two functors out of the empty category are *equal*. You probably want to use
`empty_ext` instead of this.
-/
theorem empty_ext' {C : Type u} [category C] (F : discrete pempty β₯€ C) (G : discrete pempty β₯€ C) :
F = G :=
ext (fun (x : discrete pempty) => pempty.elim x)
fun (x _x : discrete pempty) (_x_1 : x βΆ _x) => pempty.elim x
end Mathlib |
function [au] = km2au(km)
% Convert length from kilometers to astronomical units.
% Chad A. Greene 2012
au = km*6.684587122671e-9; |
//
// Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
//
#include <testing/gunit.h>
#include <gmock/gmock.h>
#include <boost/scoped_ptr.hpp>
#include <boost/system/error_code.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/bind.hpp>
#include <base/logging.h>
#include <io/process_signal.h>
#include <io/event_manager.h>
using namespace process;
class SignalMock : public Signal {
public:
SignalMock(EventManager *evm, const Signal::SignalCallbackMap &smap,
const std::vector<Signal::SignalChildHandler> &chandlers,
bool always_handle_sigchild) :
Signal(evm, smap, chandlers, always_handle_sigchild) {
}
virtual ~SignalMock() {
}
MOCK_METHOD3(WaitPid, int(int pid, int *status, int options));
};
class ProcessSignalTest : public ::testing::Test {
public:
void HandleSignal(const boost::system::error_code &a_ec, int a_sig,
int e_sig) {
signal_handler_called_++;
ASSERT_EQ(boost::system::errc::success, a_ec);
EXPECT_EQ(a_sig, e_sig);
}
void HandleSigChild(const boost::system::error_code &a_ec, int a_sig,
pid_t a_pid, int a_status, int e_sig, pid_t e_pid, int e_status) {
sigchild_handler_called_++;
ASSERT_EQ(boost::system::errc::success, a_ec);
EXPECT_EQ(a_sig, e_sig);
EXPECT_EQ(a_pid, e_pid);
EXPECT_EQ(a_status, e_status);
}
protected:
ProcessSignalTest() {
}
~ProcessSignalTest() {
}
virtual void SetUp() {
}
virtual void TearDown() {
}
void SendSignal(int sig) {
boost::system::error_code ec;
psignal_->HandleSig(ec, sig);
}
int signal_handler_called_;
int sigchild_handler_called_;
EventManager evm_;
boost::scoped_ptr<SignalMock> psignal_;
};
using ::testing::DoAll;
using ::testing::SetArgPointee;
using ::testing::Return;
using ::testing::_;
TEST_F(ProcessSignalTest, Basic) {
signal_handler_called_ = 0;
Signal::SignalCallbackMap smap = boost::assign::map_list_of
(SIGHUP, std::vector<Signal::SignalHandler>(1,
boost::bind(&ProcessSignalTest::HandleSignal, this, _1, _2,
SIGHUP)))
(SIGTERM, std::vector<Signal::SignalHandler>(1,
boost::bind(&ProcessSignalTest::HandleSignal, this, _1, _2,
SIGTERM)));
std::vector<Signal::SignalChildHandler> chandler = boost::assign::list_of
(boost::bind(&ProcessSignalTest::HandleSigChild, this, _1, _2,
_3, _4, SIGCHLD, 333, 333));
psignal_.reset(new SignalMock(&evm_, smap, chandler, false));
EXPECT_CALL(*psignal_, WaitPid(_, _, _))
.Times(2)
.WillOnce(DoAll(SetArgPointee<1>(333), Return(333)))
.WillOnce(Return(-1));
// Now call the signals
SendSignal(SIGTERM);
SendSignal(SIGHUP);
SendSignal(SIGCHLD);
psignal_->Terminate();
psignal_.reset();
EXPECT_EQ(2, signal_handler_called_);
EXPECT_EQ(1, sigchild_handler_called_);
}
int main(int argc, char *argv[]) {
LoggingInit();
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
|
-- ------------------------------------------------------------ [ Position.idr ]
-- Module : Lightyear.Position
-- Description : Positioning in source files.
--
-- This code is distributed under the BSD 2-clause license.
-- See the file LICENSE in the root directory for its full text.
-- --------------------------------------------------------------------- [ EOH ]
module Lightyear.Position
import Data.Nat
import Data.Strings
%default total
-- %access export
||| Generic representation of a position.
public export
record Position where
constructor MkPos
fname : Maybe String
lineNo : Nat
colNo : Nat
export
defaultPos : Maybe String -> Position
defaultPos fname = MkPos fname 1 1
namespace Generic
||| Increment the position one character.
export
increment : (tabwidth : Nat)
-> (curr_pos : Position)
-> (character : Char)
-> Position
increment _ (MkPos f l _) '\n' = MkPos f (S l) 1
increment twidth (MkPos f l c) '\t' = MkPos f l (nextTab twidth)
where
nextTab : Nat -> Nat
nextTab Z = c
nextTab twidth@(S ptw) = (divNatNZ ((minus c 1) + twidth) twidth SIsNotZ) * twidth + 1
increment _ (MkPos f l c) _ = MkPos f l (S c)
||| Increment the position one character.
export
inc : Nat -> Position -> Char -> Position
inc = Generic.increment
||| Increment the position one character with a default tab width of eight.
export
increment : Position -> Char -> Position
increment = Generic.increment 8
||| Increment the position one character with a default tab width of eight.
export
inc : Position -> Char -> Position
inc = Generic.increment 8
-- [ NOTE ]
--
-- When comparing ASTs it would be nice to ignore positioning information.
Eq Position where
(==) _ _ = True
Ord Position where
compare _ _ = EQ
export
display : Position -> String
display (MkPos (Just fname) l c) = concat [show fname, ":", show l, ":", show c]
display (MkPos Nothing l c) = concat ["At ", show l, ":", show c]
-- --------------------------------------------------------------------- [ EOF ]
|
function [h, compUpAV, compUpVP, compUp] = lfmComputeH3AV(gamma1_p, gamma1_m, sigma2, t1, ...
t2, preFactor, mode)
% LFMCOMPUTEH3AV Helper function for computing part of the LFMAV kernel.
% FORMAT
% DESC computes a portion of the LFMAV kernel.
% ARG gamma1 : Gamma value for first system.
% ARG gamma2 : Gamma value for second system.
% ARG sigma2 : length scale of latent process.
% ARG t1 : first time input (number of time points x 1).
% ARG t2 : second time input (number of time points x 1).
% ARG preFactor : precomputed constants.
% ARG mode: indicates the correct derivative.
% RETURN h : result of this subcomponent of the kernel for the given values.
%
% COPYRIGHT : Mauricio Alvarez, 2010
% KERN
% Evaluation of h
if nargout>1
[compUpAV{1}, compUpVP{1}, compUp{1}] = lfmavComputeUpsilonMatrix(gamma1_p,sigma2, t1,t2, mode);
[compUpAV{2}, compUpVP{2}, compUp{2}] = lfmavComputeUpsilonMatrix(gamma1_m,sigma2, t1,t2, mode);
h = preFactor(1)*compUpAV{1} + preFactor(2)*compUpAV{2};
else
h = preFactor(1)*lfmavComputeUpsilonMatrix(gamma1_p,sigma2, t1,t2, mode) ...
+ preFactor(2)*lfmavComputeUpsilonMatrix(gamma1_m,sigma2, t1,t2, mode);
end
|
module System.Concurrency
import Data.IORef
%default total
-- At the moment this is pretty fundamentally tied to the Scheme RTS.
-- Given that different back ends will have entirely different threading
-- models, it might be unavoidable, but we might want to think about possible
-- primitives that back ends should support.
-- Thread mailboxes
%foreign "scheme:blodwen-set-thread-data"
prim__setThreadData : {a : Type} -> a -> PrimIO ()
%foreign "scheme:blodwen-get-thread-data"
prim__getThreadData : (a : Type) -> PrimIO a
export
setThreadData : HasIO io => {a : Type} -> a -> io ()
setThreadData val = primIO (prim__setThreadData val)
export
getThreadData : HasIO io => (a : Type) -> io a
getThreadData a = primIO (prim__getThreadData a)
-- Mutexes
export
data Mutex : Type where [external]
%foreign "scheme:blodwen-make-mutex"
prim__makeMutex : PrimIO Mutex
%foreign "scheme:blodwen-mutex-acquire"
prim__mutexAcquire : Mutex -> PrimIO ()
%foreign "scheme:blodwen-mutex-release"
prim__mutexRelease : Mutex -> PrimIO ()
||| Creates and returns a new mutex.
export
makeMutex : HasIO io => io Mutex
makeMutex = primIO prim__makeMutex
||| Acquires the mutex identified by `mutex`. The thread blocks until the mutex
||| has been acquired.
|||
||| Mutexes are recursive in Posix threads terminology, which means that the
||| calling thread can use mutex-acquire to (re)acquire a mutex it already has.
||| In this case, an equal number of mutex-release calls is necessary to release
||| the mutex.
export
mutexAcquire : HasIO io => Mutex -> io ()
mutexAcquire m = primIO (prim__mutexAcquire m)
||| Releases the mutex identified by `mutex`. Unpredictable behavior results if
||| the mutex is not owned by the calling thread.
export
mutexRelease : HasIO io => Mutex -> io ()
mutexRelease m = primIO (prim__mutexRelease m)
-- Condition variables
export
data Condition : Type where [external]
%foreign "scheme,racket:blodwen-make-cv"
"scheme,chez:blodwen-make-condition"
prim__makeCondition : PrimIO Condition
%foreign "scheme,racket:blodwen-cv-wait"
"scheme,chez:blodwen-condition-wait"
prim__conditionWait : Condition -> Mutex -> PrimIO ()
%foreign "scheme,chez:blodwen-condition-wait-timeout"
-- "scheme,racket:blodwen-cv-wait-timeout"
prim__conditionWaitTimeout : Condition -> Mutex -> Int -> PrimIO ()
%foreign "scheme,racket:blodwen-cv-signal"
"scheme,chez:blodwen-condition-signal"
prim__conditionSignal : Condition -> PrimIO ()
%foreign "scheme,racket:blodwen-cv-broadcast"
"scheme,chez:blodwen-condition-broadcast"
prim__conditionBroadcast : Condition -> PrimIO ()
||| Creates and returns a new condition variable.
export
makeCondition : HasIO io => io Condition
makeCondition = primIO prim__makeCondition
||| Waits up to the specified timeout for the condition identified by the
||| condition variable `cond`. The calling thread must have acquired the mutex
||| identified by `mutex` at the time `conditionWait` is called. The mutex is
||| released as a side effect of the call to `conditionWait`. When a thread is
||| later released from the condition variable by one of the procedures
||| described below, the mutex is reacquired and `conditionWait` returns.
export
conditionWait : HasIO io => Condition -> Mutex -> io ()
conditionWait cond mutex = primIO (prim__conditionWait cond mutex)
||| Variant of `conditionWait` with a timeout in microseconds.
||| When the timeout expires, the thread is released, `mutex` is reacquired, and
||| `conditionWaitTimeout` returns.
export
conditionWaitTimeout : HasIO io => Condition -> Mutex -> Int -> io ()
conditionWaitTimeout cond mutex timeout = primIO (prim__conditionWaitTimeout cond mutex timeout)
||| Releases one of the threads waiting for the condition identified by `cond`.
export
conditionSignal : HasIO io => Condition -> io ()
conditionSignal c = primIO (prim__conditionSignal c)
||| Releases all of the threads waiting for the condition identified by `cond`.
export
conditionBroadcast : HasIO io => Condition -> io ()
conditionBroadcast c = primIO (prim__conditionBroadcast c)
-- Semaphores
export
data Semaphore : Type where [external]
%foreign "scheme:blodwen-make-semaphore"
prim__makeSemaphore : Int -> PrimIO Semaphore
%foreign "scheme:blodwen-semaphore-post"
prim__semaphorePost : Semaphore -> PrimIO ()
%foreign "scheme:blodwen-semaphore-wait"
prim__semaphoreWait : Semaphore -> PrimIO ()
||| Creates and returns a new semaphore with the counter initially set to `init`.
export
makeSemaphore : HasIO io => Int -> io Semaphore
makeSemaphore init = primIO (prim__makeSemaphore init)
||| Increments the semaphore's internal counter.
export
semaphorePost : HasIO io => Semaphore -> io ()
semaphorePost sema = primIO (prim__semaphorePost sema)
||| Blocks until the internal counter for semaphore sema is non-zero. When the
||| counter is non-zero, it is decremented and `semaphoreWait` returns.
export
semaphoreWait : HasIO io => Semaphore -> io ()
semaphoreWait sema = primIO (prim__semaphoreWait sema)
-- Barriers
||| A barrier enables multiple threads to synchronize the beginning of some
||| computation.
export
data Barrier : Type where [external]
%foreign "scheme:blodwen-make-barrier"
prim__makeBarrier : Int -> PrimIO Barrier
%foreign "scheme:blodwen-barrier-wait"
prim__barrierWait : Barrier -> PrimIO ()
||| Creates a new barrier that can block a given number of threads.
export
makeBarrier : HasIO io => Int -> io Barrier
makeBarrier numThreads = primIO (prim__makeBarrier numThreads)
||| Blocks the current thread until all threads have rendezvoused here.
export
barrierWait : HasIO io => Barrier -> io ()
barrierWait barrier = primIO (prim__barrierWait barrier)
-- Channels
export
data Channel : Type -> Type where [external]
%foreign "scheme:blodwen-make-channel"
prim__makeChannel : PrimIO (Channel a)
%foreign "scheme:blodwen-channel-get"
prim__channelGet : Channel a -> PrimIO a
%foreign "scheme:blodwen-channel-put"
prim__channelPut : Channel a -> a -> PrimIO ()
||| Creates and returns a new channel. The channel can be used with channelGet
||| to receive a value through the channel. The channel can be used with
||| channelPut to send a value through the channel.
export
makeChannel : HasIO io => io (Channel a)
makeChannel = primIO prim__makeChannel
||| Blocks until a sender is ready to provide a value through `chan`. The result
||| is the sent value.
export
channelGet : HasIO io => Channel a -> io a
channelGet chan = primIO (prim__channelGet chan)
||| CAUTION: Different behaviour under chez and racket:
||| - Chez: Puts a value on the channel. If there already is a value, blocks
||| until that value has been received.
||| - Racket: Blocks until a receiver is ready to accept the value `val` through
||| `chan`.
export
channelPut : HasIO io => Channel a -> a -> io ()
channelPut chan val = primIO (prim__channelPut chan val)
|
A function $f$ is uniformly continuous on a set $S$ if and only if for every $\epsilon > 0$, there exists a $\delta > 0$ such that for all $x, x' \in S$, if $|x - x'| < \delta$, then $|f(x) - f(x')| < \epsilon$. |
[STATEMENT]
lemma invc_baldL: "\<lbrakk>invc2 l; invc r; color r = Black\<rbrakk> \<Longrightarrow> invc (baldL l a r)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>invc2 l; invc r; color r = Black\<rbrakk> \<Longrightarrow> invc (baldL l a r)
[PROOF STEP]
by (induct l a r rule: baldL.induct) (simp_all add: invc_baliR) |
#' Total human transcription factor peaks.
#'
#' A dataset containing all peak coordinates (chromosome number, peak start position, peak end position) for transcription factors from ENCODE.
#'
#' @docType data
#'
#' @usage data(txn_total)
#'
#' @format A data frame with 210065 rows and 3 variables:
#'
#' @keywords datasets
"txn_total" |
= John Cullen =
|
McLaren Automotive has announced its backing for the 2018 Telegraph UK STEM Awards that highlight science, technology, engineering and maths-based careers.
McLaren Automotive is supporting the automotive technology category to emphasise the importance of STEM careers. The Awards β now in their fifth year β are aimed at talented undergraduate level students and showcase the companyβs constant drive to hire the best talent needed to develop the next generation of world-beating sports cars and supercars.
For talented and ambitious students, the Awards provide a rare opportunity to present their bright ideas to some of the key decision-makers at one of the worldβs most exciting car companies.
To enter the McLaren Automotive-backed automotive technology category, McLarenβs judges have set students a challenge linked to the rise of connected cars.
While vehicles are becoming ever smarter and more connected, McLaren owners will always love the thrill of driving. Students will need to come up with ideas for how technology can be used in McLarenβs future luxury cars in a way that ensures they continue to engage customers in the entertainment of driving.
The winner of McLarenβs automotive technology category will go forward to compete to be crowned the overall UK STEM Awards winner, with a chance to receive a grand prize of Β£25,000 at the prestigious final to be held in London next summer.
Previous winners of the McLaren category impressed judges so much that they were offered permanent positions at the companyβs world-renowned global headquarters in Woking, Surrey.
Judging the McLaren category are Paul Arkesden, Head of Engineering for McLaren Special Operations (MSO) responsible for product development at McLarenβs bespoke operation; Simon Lacey, Head of Advance Engineering for McLaren Automotive, who creates and develops game-changing technology for future cars; and Dr Caroline Hargrove, Technical Director for McLaren Applied Technologies, McLaren Automotiveβs sister-company within the McLaren Group, that helped to develop the hybrid powertrain of the McLaren P1β’.
Full details of how to enter the McLaren Automotive category of the 2018 Telegraph UK STEM awards will be published in The Sunday Telegraph on October 1 and on the Telegraph website at www.telegraph.co.uk/STEMawards.
After the February 19, 2018, closing date for submissions , the trio of McLaren judges will shortlist up to five of the best entries based on what they feel are the most creative and innovative ideas that meet the challenge. Those who make it through Paul, Simon and Carolineβs expert scrutiny will then be invited to the McLaren Production Centre in Woking, Surrey, where the company designs, develops and hand-assembles its cars to present their ideas in person. After that they will get an exclusive, behind-the-scenes tour to see at first-hand the work of some of the companyβs 2,100 strong workforce.
McLarenβs involvement in the Awards is part of its long-term commitment to encourage the uptake of STEM subjects. That commitment includes a network of McLaren STEM Ambassadors who regularly visit schools, colleges and science fairs, as well as support for schemes that reach younger age-groups, such as the recent BBC Live Lesson on physical forces that was broadcast live from the McLaren Technology Centre to primary schools across the UK.
Mike Flewitt, Chief Executive Officer of McLaren Automotive said: βWeβre delighted to support the STEM Awards and for McLaren Automotive to back the automotive technology category. Our judges have set students a challenge that is both stretching and exciting but also one that is very relevant to a forward-thinking company like ours that is about creating the ultimate driving experience and enabling that through the clever deployment of technology,β . |
module Graphics.Rendering.Gl.Types
%access public export
GLenum : Type
GLenum = Int
GLbitfield : Type
GLbitfield = Int
GLboolean : Type
GLboolean = Int
GLbyte : Type
GLbyte = Char
GLubyte : Type
GLubyte = Char
GLshort : Type
GLshort = Int
GLushort : Type
GLushort = Int
GLint : Type
GLint = Int
GLuint : Type
GLuint = Int
GLsizei : Type
GLsizei = Int
GLchar : Type
GLchar = Char
GLdouble : Type
GLdouble = Double
GLclampd : Type
GLclampd = Double
-- only temporary
GLfloat : Type
GLfloat = Double
GLclampf : Type
GLclampf = Double
-- the pointer size of the data len*sizeof(whatever)
GLsizeiptr : Type
GLsizeiptr = Int
class GlEnum a where
toGlInt : a -> Int
|
\section{copy}
\index{copy}
\begin{shaded}
\begin{alltt}
/** copy
copy from input stream to output without delaying the stream. See elastic
for a more generic way to do this.
\end{alltt}
\end{shaded}
|
\chapter{Experiments and results} |
/* movstat/test_median.c
*
* Copyright (C) 2018 Patrick Alken
*
* 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_test.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_movstat.h>
#include <gsl/gsl_statistics.h>
/* compute filtered data by explicitely constructing window, sorting it and finding median */
int
slow_movmedian(const gsl_movstat_end_t etype, const gsl_vector * x, gsl_vector * y,
const int H, const int J)
{
const size_t n = x->size;
const int K = H + J + 1;
double *window = malloc(K * sizeof(double));
size_t i;
for (i = 0; i < n; ++i)
{
size_t wsize = gsl_movstat_fill(etype, x, i, H, J, window);
double yi = gsl_stats_median(window, 1, wsize);
gsl_vector_set(y, i, yi);
}
free(window);
return GSL_SUCCESS;
}
/* test root sequence */
static void
test_median_root(const double tol, const size_t n, const size_t K, const gsl_movstat_end_t etype)
{
gsl_movstat_workspace *w = gsl_movstat_alloc(K);
gsl_vector *x = gsl_vector_alloc(n);
gsl_vector *y = gsl_vector_alloc(n);
char buf[2048];
size_t i;
/* test a root sequence (square input): x = [zero one zero] */
gsl_vector_set_all(x, 0.0);
for (i = n / 3; i <= n / 2; ++i)
gsl_vector_set(x, i, 1.0);
/* compute y = median(x) and test y = x */
gsl_movstat_median(etype, x, y, w);
sprintf(buf, "n=%zu K=%zu endtype=%u SMF root sequence", n, K, etype);
compare_vectors(tol, y, x, buf);
gsl_vector_free(x);
gsl_vector_free(y);
gsl_movstat_free(w);
}
static double
func_median(const size_t n, double x[], void * params)
{
(void) params;
return gsl_stats_median(x, 1, n);
}
static void
test_median_proc(const double tol, const size_t n, const size_t H, const size_t J,
const gsl_movstat_end_t etype, gsl_rng *rng_p)
{
gsl_movstat_workspace *w;
gsl_vector *x = gsl_vector_alloc(n);
gsl_vector *y = gsl_vector_alloc(n);
gsl_vector *z = gsl_vector_alloc(n);
gsl_movstat_function F;
char buf[2048];
F.function = func_median;
F.params = NULL;
if (H == J)
w = gsl_movstat_alloc(2*H + 1);
else
w = gsl_movstat_alloc2(H, J);
/* test moving median with random input */
random_vector(x, rng_p);
/* y = median(x) with slow brute force algorithm */
slow_movmedian(etype, x, y, H, J);
/* z = median(x) */
gsl_movstat_median(etype, x, z, w);
/* test y = z */
sprintf(buf, "n=%zu H=%zu J=%zu endtype=%u median random", n, H, J, etype);
compare_vectors(tol, z, y, buf);
/* z = median(x) in-place */
gsl_vector_memcpy(z, x);
gsl_movstat_median(etype, z, z, w);
sprintf(buf, "n=%zu H=%zu J=%zu endtype=%u median random in-place", n, H, J, etype);
compare_vectors(tol, z, y, buf);
/* z = median(x) with user-defined function */
gsl_movstat_apply(etype, &F, x, z, w);
sprintf(buf, "n=%zu H=%zu J=%zu endtype=%u median user", n, H, J, etype);
compare_vectors(tol, z, y, buf);
gsl_vector_free(x);
gsl_vector_free(y);
gsl_vector_free(z);
gsl_movstat_free(w);
}
static void
test_median(gsl_rng * rng_p)
{
test_median_root(GSL_DBL_EPSILON, 1000, 3, GSL_MOVSTAT_END_PADZERO);
test_median_root(GSL_DBL_EPSILON, 200, 15, GSL_MOVSTAT_END_PADVALUE);
test_median_root(GSL_DBL_EPSILON, 100, 5, GSL_MOVSTAT_END_TRUNCATE);
test_median_proc(GSL_DBL_EPSILON, 1000, 0, 0, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 1000, 1, 1, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 100, 150, 150, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 8, 8, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 0, 5, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 5, 0, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 15, 10, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 10, 15, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 100, 150, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 150, 100, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 100, 100, GSL_MOVSTAT_END_PADZERO, rng_p);
test_median_proc(GSL_DBL_EPSILON, 1000, 0, 0, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 1000, 1, 1, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 100, 150, 150, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 8, 8, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 0, 5, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 5, 0, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 15, 10, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 10, 15, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 100, 150, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 150, 100, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 100, 100, GSL_MOVSTAT_END_PADVALUE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 1000, 0, 0, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 1000, 1, 1, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 100, 150, 150, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 8, 8, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 0, 5, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 5, 0, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 15, 10, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 5000, 10, 15, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 100, 150, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 150, 100, GSL_MOVSTAT_END_TRUNCATE, rng_p);
test_median_proc(GSL_DBL_EPSILON, 50, 100, 100, GSL_MOVSTAT_END_TRUNCATE, rng_p);
}
|
#redirect Stebbins Cold Canyon Reserve
|
theory RingBuffer_new_copy
imports Main HOL.List
begin
datatype PCW =
A1 | A2 | A3 | A4 | A5 | A6 | A7 | A8
| Enqueue | idleW | OOM | FinishedW | Write | BTS
datatype PCR =
Release | idleR | Read
datatype F = W | R | Q | B
datatype Pointer = Head | Tail
consts N :: nat (*size of buffer, input*)
consts n :: nat (*number of Arr\<^sub>W entries*)
definition "F1_set={W,B,Q,R}"
definition "W_pre_acquire_set={A1,A2,A3,A4,A5,A6,A7,A8,idleW,FinishedW,OOM,BTS}"
definition "W_post_acquire_set={Write,Enqueue}"
definition "R_pre_dequeue_set={idleR}"
definition "R_post_dequeue_set={Read, Release}"
lemmas sets [simp]= F1_set_def W_pre_acquire_set_def W_post_acquire_set_def
R_pre_dequeue_set_def R_post_dequeue_set_def
(*Recorded variables*)
record rb_state =
H :: nat
T :: nat
hW :: nat (*local copy of W*)
tW :: nat (*local copy of W*)
offset :: nat
q :: "(nat \<times> nat) list"
tempR :: "(nat \<times> nat)" (*local copy of word by R*)
data_index :: "(nat \<times> nat) \<Rightarrow> nat" (*state of the buffer contents*)
pcW :: PCW (*records program counter of W*)
pcR :: PCR (*records program counter of W*)
Data:: "nat \<Rightarrow> nat" (*returns a word Data_i*)
tR :: nat
numReads :: nat (* how many words the reader has read *)
numWrites :: nat (* how many words the writer has written *)
numEnqs :: nat (* how many words from Data the writer has enqueued *)
numDeqs :: nat (* how many words from Data the reader has retrieved *)
ownT :: F
ownD :: "nat \<Rightarrow> F" (* ownership of Data indices *)
ownB :: "nat \<Rightarrow> F" (* ownership of bytes in buffer *)
definition "con_assms s \<equiv> 0 < N \<and> 0<n \<and> N>n \<and> numEnqs s\<le>n \<and> (numDeqs s\<le>numEnqs s)
\<and> (\<forall>i.(i<n)\<longrightarrow>Data s i\<le>N \<and> Data s i>0 )"
definition push_H :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`H := _" [200])
where
"push_H v \<equiv> \<lambda>s. s \<lparr>H := v\<rparr>"
definition push_T :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`T := _" [200])
where
"push_T v \<equiv> \<lambda>s. s \<lparr>T := v\<rparr>"
definition write_data_index :: "nat \<times> nat \<Rightarrow> nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`B.write _ := _" [200]) where
"write_data_index a v \<equiv>
\<lambda>s. s \<lparr> data_index := \<lambda> x. if a = x then v else data_index s x \<rparr>"
definition change_writes :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`numWrites := _" [200])
where
"change_writes v \<equiv> \<lambda>s. s \<lparr>numWrites := v\<rparr>"
definition change_reads :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`numReads := _" [200])
where
"change_reads v \<equiv> \<lambda>s. s \<lparr>numReads := v\<rparr>"
definition push_offset :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`offset := _" [200])
where
"push_offset v \<equiv> \<lambda>s. s \<lparr>offset := v\<rparr>"
definition trans_ownT :: "F \<Rightarrow> F \<Rightarrow> rb_state \<Rightarrow> rb_state \<Rightarrow> rb_state" ("transownT [_ _ _]" [200]) where
"trans_ownT a b s \<equiv> if ownT s = a then (\<lambda>s. s \<lparr> ownT := b \<rparr>)
else (\<lambda>s. s \<lparr> ownT := ownT s\<rparr>)"
definition transfer_ownB :: "F \<Rightarrow> F \<Rightarrow> rb_state \<Rightarrow> rb_state" ("transownB [_ _]" [200]) where
"transfer_ownB a b \<equiv> (\<lambda>s. s \<lparr> ownB := \<lambda> i. if (ownB s i = a) then b else (ownB s) i\<rparr>)"
definition set_ownB :: "nat\<times>nat\<Rightarrow> F \<Rightarrow> rb_state \<Rightarrow> rb_state" ("setownB [_ _]" [200]) where
"set_ownB x a \<equiv> (\<lambda>s. s \<lparr> ownB := \<lambda> i. if ((i\<ge>fst(x)) \<and> (i<snd(x))) then a else (ownB s) i\<rparr>)"
definition transfer_ownD :: "nat\<Rightarrow> F \<Rightarrow> rb_state \<Rightarrow> rb_state" ("transownD [_ _]" [200]) where
"transfer_ownD x a \<equiv> (\<lambda>s. s \<lparr> ownD := \<lambda> i. if i=x then a else (ownD s) i\<rparr>)"
(*-----------------------*)
definition set_hW :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`hW := _" [200]) where
"set_hW v \<equiv> \<lambda>s. s \<lparr> hW := v\<rparr>"
definition set_tW :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`tW := _" [200]) where
"set_tW v \<equiv> \<lambda>s. s \<lparr> tW := v\<rparr>"
definition set_tR :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`tR := _" [200]) where
"set_tR v \<equiv> \<lambda>s. s \<lparr> tR := v\<rparr>"
definition set_tempR :: "(nat \<times> nat) \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`tempR := _" [200]) where
"set_tempR v \<equiv> \<lambda>s. s \<lparr> tempR := v\<rparr>"
definition update_numEnqs :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`numEnqs := _" [200]) where
"update_numEnqs v\<equiv> \<lambda>s. s \<lparr> numEnqs := v\<rparr>"
definition update_numDeqs :: "nat \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`numDeqs := _" [200]) where
"update_numDeqs v\<equiv> \<lambda>s. s \<lparr> numDeqs := v\<rparr>"
definition update_pcW :: "PCW \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`pcW := _" [200]) where
"update_pcW v \<equiv> \<lambda>s. s \<lparr> pcW := v\<rparr>"
definition update_pcR :: "PCR \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`pcR := _" [200]) where
"update_pcR v \<equiv> \<lambda>s. s \<lparr> pcR := v\<rparr>"
abbreviation update_b_err :: "rb_state \<Rightarrow> rb_state" ("ERROOM") where
"update_b_err \<equiv> \<lambda>s. s \<lparr> pcW := OOM \<rparr>"
abbreviation update_bts_err :: "rb_state \<Rightarrow> rb_state" ("ERRBTS") where
"update_bts_err \<equiv> \<lambda>s. s \<lparr> pcW := BTS \<rparr>"
definition update_q :: "(nat \<times> nat) list \<Rightarrow> rb_state \<Rightarrow> rb_state" ("`q := _" [200])
where
"update_q v \<equiv> \<lambda>s. s \<lparr>q := v\<rparr>"
lemmas functs [simp] = push_H_def push_T_def set_hW_def set_tW_def
update_numEnqs_def update_numDeqs_def
set_tempR_def
update_pcW_def update_pcR_def
transfer_ownB_def transfer_ownD_def trans_ownT_def
update_q_def
push_offset_def write_data_index_def
change_writes_def change_reads_def
set_tR_def set_ownB_def
(* Define the if statement "guards" *)
definition "off bo \<equiv> fst bo"
definition "len bo \<equiv> snd bo"
definition "grd1 s \<equiv> (tW s = hW s) \<and> (Data s (numEnqs s) \<le> N)"
definition "grd2 s \<equiv> (tW s > hW s) \<and> (Data s (numEnqs s) < (tW s - hW s))"
definition "grd3 s \<equiv> tW s < hW s"
definition "grd4 s \<equiv> Data s (numEnqs s) \<le> N - hW s"
definition "grd5 s \<equiv> Data s (numEnqs s) < tW s"
definition "no_space_for_word s \<equiv> (grd1 s \<longrightarrow> \<not>(Data s (numEnqs s) \<le> N))\<and>
(grd2 s \<longrightarrow> \<not>(Data s (numEnqs s) < (tW s - hW s)))\<and>
(grd3 s \<longrightarrow> \<not>(Data s (numEnqs s) \<le> N - hW s \<or> Data s (numEnqs s) < tW s))"
lemmas grd_simps [simp] = off_def len_def grd1_def grd2_def grd3_def grd4_def grd5_def no_space_for_word_def
(***********************************************************************)
(* Initial State *)
definition "init s \<equiv> (H s = 0) \<and> (T s = 0) \<and> (offset s = 0) \<and> q s = [] \<and> (hW s = 0) \<and> (tW s = 0) \<and> (tR s = 0)
\<and> numReads s = 0 \<and> numWrites s = 0 \<and> (numEnqs s = 0) \<and> (numDeqs s = 0)
\<and> ( pcW s = idleW)
\<and> ( pcR s = idleR)
\<and> (\<forall>l. (l<n) \<longrightarrow> ((Data s l > 0)\<and>(Data s l \<le> N)))
\<and> (\<forall>i. (i<n) \<longrightarrow> ownD s i = W)
\<and> (\<forall>i. (i\<le>N) \<longrightarrow> ownB s i = B)
\<and> (ownT s = Q)
\<and> (tempR s = (0,0))
\<and> (\<forall>i. (i\<le>N)\<longrightarrow>(\<forall>j.(j\<le>N)\<longrightarrow>data_index s (i,j) <n))"
(***********************************************************************)
(* State of the queue *)
(* What Q should look like *)
definition "end x \<equiv> fst x + snd x"
lemmas end_simp [simp] = end_def
definition "Q_boundness s \<equiv> (\<forall>x. (x \<in> set (q s)) \<longrightarrow> end x \<le> N)"
definition "Q_offsets_differ s \<equiv> (\<forall>i j.(i<length(q s)\<and> j<length(q s)\<and> i\<noteq>j)\<longrightarrow>(fst(q s!i)\<noteq>fst(q s!j)))"
definition "Q_gap_structure s \<equiv>
(\<forall>i. (i < length(q s) \<and> i > 0) \<longrightarrow>((end(q s!(i-1)) = fst(q s!i))\<or> (fst(q s!i) =0)))"
definition "Q_has_no_uroboros s \<equiv>
(\<forall>x. x \<in> set (butlast (q s)) \<longrightarrow> fst x \<noteq> end (last (q s)))"
definition "Q_has_no_overlaps s \<equiv>
(\<forall> x y. (fst(x) < fst(y) \<and> x \<in> set (q s) \<and> y \<in> set (q s)) \<longrightarrow> (end x \<le> fst y))"
definition "Q_basic_struct s \<equiv> Q_boundness s \<and> Q_gap_structure s \<and> Q_offsets_differ s
\<and> Q_has_no_overlaps s \<and> Q_has_no_uroboros s "
lemmas Q_basic_lemmas = Q_basic_struct_def Q_has_no_overlaps_def
Q_gap_structure_def Q_has_no_uroboros_def
Q_boundness_def Q_offsets_differ_def
(* Relating Q to other variables *)
definition "Q_holds_bytes s \<equiv> q s\<noteq>[]\<longrightarrow>(\<forall>i.(i\<in>set(q s))\<longrightarrow>(\<forall>j.(fst(i)\<le>j \<and> j<end(i))\<longrightarrow>ownB s j=Q))"
definition "Q_reflects_writes s \<equiv> (\<forall>i.(i<length(q s))\<longrightarrow>data_index s (q s!i) = ((numDeqs s) +i))"
definition "Q_elem_size s \<equiv> (\<forall>i.(i<length(q s))\<longrightarrow>snd(q s!i) =Data s ((numDeqs s) +i))"
definition "Q_reflects_ownD s \<equiv> (\<forall>i.(i<length(q s))\<longrightarrow>ownD s (i+(numDeqs s)) =B)"
definition "Q_structure s \<equiv>q s\<noteq>[]\<longrightarrow>(Q_basic_struct s \<and>
Q_holds_bytes s \<and> Q_reflects_writes s \<and> Q_elem_size s \<and>
Q_reflects_ownD s )"
lemmas Q_lemmas = Q_holds_bytes_def Q_reflects_writes_def Q_elem_size_def
Q_structure_def Q_basic_struct_def Q_reflects_ownD_def
(*have the idea of "can fit between T-N or not"*)
definition "pos_of_T_pre_deq s \<equiv>
(q s\<noteq>[] \<and> ((fst(hd (q s))\<ge>0 \<and> T s=fst(hd (q s)))
\<or> (fst(hd (q s)) =0 \<and>(tl(q s)\<noteq>[]\<longrightarrow>(\<forall>i.(i<length(tl(q s)))\<longrightarrow>T s>end(q s!i)))
\<and> T s>end(hd(q s)))))
\<or> (q s=[] \<and> pcW s\<notin>W_pre_acquire_set \<and> ((offset s\<ge>0\<and>T s=offset s) \<or> (T s>Data s (numEnqs s) \<and> offset s=0)))
\<or> (q s=[] \<and> pcW s\<in>W_pre_acquire_set \<and> T s=H s)"
definition "pos_of_T_post_deq s \<equiv>
(fst(tempR s)\<ge>0 \<and> T s=fst(tempR s))
\<or> (fst(tempR s)=0 \<and> (q s\<noteq>[]\<longrightarrow>T s>end(last(q s)))
\<and> T s>snd(tempR s))"
definition "Q_T_rel_idleR s \<equiv>
(T s=fst(hd(q s)))
\<or>(0 = fst(hd(q s)) \<and> (\<forall>i.(i<length(q s))\<longrightarrow>T s>end(q s!i)) \<and> T s\<noteq> 0)"
definition "Q_T_rel_nidleR s \<equiv>
(T s=fst(tempR s))
\<or>(0 = fst(tempR s) \<and> (q s\<noteq>[]\<longrightarrow>T s>end(last(q s))) \<and> T s>end(tempR s) \<and> T s\<noteq> 0)"
definition "pos_of_H_pre_acq s \<equiv>
((q s=[] \<and> pcR s\<in>R_pre_dequeue_set \<and> H s=T s)
\<or>(q s=[] \<and> pcR s\<in>R_post_dequeue_set \<and> H s=end(tempR s) \<and> H s\<noteq> T s)
\<or>(q s\<noteq>[] \<and> H s=end(last(q s)) \<and> H s\<noteq> T s))
\<and> (numEnqs s=0\<longrightarrow>H s=offset s)
\<and> (numEnqs s>0\<longrightarrow>H s=offset s+Data s(numEnqs s-1))"
definition "pos_of_H_post_acq s \<equiv> H s=offset s+Data s(numEnqs s)"
definition "Q_H_rel_idleR s \<equiv>
(fst(hd(q s))<end(last(q s))\<longrightarrow> H s\<ge>end(last(q s)) \<or> H s<fst(hd(q s)))
\<and>(fst(hd(q s))<end(last(q s))\<longrightarrow> H s\<ge>end(last(q s)) \<and> H s>fst(hd(q s)))"
definition "Q_H_rel_nidleR s \<equiv>
(fst(tempR s)<end(last(q s))\<longrightarrow> H s\<ge>end(last(q s)) \<or> H s<fst(tempR s))
\<and>(fst(tempR s)<end(last(q s))\<longrightarrow> H s\<ge>end(last(q s)) \<and> H s>fst(tempR s))"
(**********)
(* What tempR should look like *)
definition "tempR_boundness s \<equiv> end(tempR s)\<le>N"
definition "tempR_offsets_differ s \<equiv> q s\<noteq>[]\<longrightarrow>(\<forall> x.(x\<in>set(q s))\<longrightarrow>(fst(x) \<noteq> fst(tempR s)))"
definition "tempR_gap_structure s \<equiv> q s\<noteq>[]\<longrightarrow>(end(tempR s) =fst(hd(q s)) \<or> fst(hd(q s)) =0)"
definition "tempR_has_no_uroboros s \<equiv> q s\<noteq>[]\<longrightarrow>(fst(tempR s) \<noteq> end(last(q s)))"
definition "tempR_has_no_overlaps s \<equiv> q s\<noteq>[]\<longrightarrow>(\<forall> x. (x\<in>set(q s)) \<longrightarrow> ((end x < fst(tempR s))
\<or>(fst x \<ge> end(tempR s))))"
definition "tempR_basic_struct s \<equiv> tempR_boundness s \<and> tempR_gap_structure s \<and> tempR_offsets_differ s
\<and> tempR_has_no_overlaps s \<and> tempR_has_no_uroboros s "
lemmas tempR_basic_lemmas = tempR_basic_struct_def tempR_has_no_overlaps_def
tempR_gap_structure_def tempR_has_no_uroboros_def
tempR_boundness_def tempR_offsets_differ_def
(* Relating tempR to other variables *)
definition "tempR_holds_bytes s \<equiv> (\<forall>j.(fst(tempR s)\<le>j \<and> j<end(tempR s))\<longrightarrow>ownB s j=R)"
definition "tempR_reflects_writes s \<equiv> numDeqs s\<ge>1\<longrightarrow>((data_index s (tempR s) = ((numDeqs s) -1)))"
definition "tempR_elem_size s \<equiv> numDeqs s\<ge>1\<longrightarrow>((snd(tempR s) =Data s ((numDeqs s) -1)))"
definition "tempR_structure s \<equiv>(tempR_basic_struct s \<and>
tempR_holds_bytes s \<and> tempR_reflects_writes s \<and> tempR_elem_size s)"
lemmas tempR_lemmas = tempR_holds_bytes_def tempR_reflects_writes_def tempR_elem_size_def
tempR_structure_def tempR_basic_struct_def
lemma only_temp_starts_with_zero:
assumes "Q_structure s"
and "tempR_structure s"
and "fst(tempR s) =0"
shows "\<forall>i.(i<length(q s) \<and>i>0)\<longrightarrow>fst(q s!i) \<noteq>0"
using assms apply (simp add:Q_lemmas Q_basic_lemmas tempR_lemmas tempR_basic_lemmas)
by (metis Suc_diff_Suc Zero_not_Suc diff_0_eq_0 length_0_conv nth_mem prod.exhaust_sel)
lemma only_one_starts_with_zero:
assumes "Q_structure s"
and "fst(hd(q s)) =0"
shows "\<forall>i.(i<length(q s) \<and> i>0)\<longrightarrow>fst(q s!i) \<noteq>0"
using assms apply (simp add:Q_lemmas Q_basic_lemmas)
by (metis gr0I hd_conv_nth less_nat_zero_code list.size(3))
lemma sole_existence:
assumes "Q_structure s"
and "q s\<noteq>[]"
and "\<exists>x.(x\<in>set(q s) \<and> fst(x) =0)"
shows "\<exists>!x.(x\<in>set(q s) \<and> fst(x) =0)"
using assms apply(simp add:Q_lemmas Q_basic_lemmas)
by (metis fst_conv in_set_conv_nth)
lemma sole_existence_tempR_1:
assumes "Q_structure s"
and "q s\<noteq>[]"
and "tempR_structure s"
and "\<exists>x.(x\<in>set(q s) \<and> fst(x) =0)"
shows "\<exists>!x.(x\<in>set(q s) \<and> fst(x) =0)"
using assms apply (simp add:Q_lemmas Q_basic_lemmas)
by (metis assms(1) assms(4) sole_existence)
lemma sole_existence_tempR_2:
assumes "Q_structure s"
and "q s\<noteq>[]"
and "tempR_structure s"
and "fst(tempR s) =0"
shows "\<not>(\<exists>x.(x\<in>set(q s) \<and> fst(x) =0))"
using assms apply (simp add:Q_lemmas Q_basic_lemmas tempR_lemmas tempR_basic_lemmas)
by blast
(*T s\<noteq> fst(tempR s) peculiarities
pcR s = Read
\<and> (tR s\<noteq>fst(tempR s)\<longrightarrow>(fst(tempR s)=0))
\<and> (tR s\<noteq>fst(tempR s)\<longrightarrow>(\<forall>i.(i\<ge>tR s\<and> i<N)\<longrightarrow>ownB s i=Q))
\<and> ((tR s\<noteq>fst(tempR s)\<and>q s\<noteq>[])\<longrightarrow>(\<forall>i.(i\<in>set(q s))\<longrightarrow>end(i)<T s))
pcR s = Release
\<and> (tR s\<noteq>fst(tempR s)\<longrightarrow>(fst(tempR s)=0 \<and> tR s>end(tempR s)))
\<and> (tR s\<noteq>fst(tempR s)\<longrightarrow>(\<forall>i.(i\<ge>tR s \<and> i<N)\<longrightarrow>ownB s i=Q))
\<and> ((tR s\<noteq>fst(tempR s)\<and>q s\<noteq>[])\<longrightarrow>(\<forall>i.(i\<in>set(q s))\<longrightarrow>end(i)<T s))
*)
(*Writer Thread Behaviour*)
fun rbW_step :: "PCW \<Rightarrow> rb_state \<Rightarrow> rb_state" where
"rbW_step A1 s = ((`hW := (H s)) \<circ> (`tW := (T s)) \<circ> (`pcW := A2)) s "
| "rbW_step A2 s = (if grd1 s then ((`pcW := A3) \<circ> (transownT [Q W s]))
else if grd2 s then (`pcW := A4)
else if grd3 s then (`pcW := A5)
else (`pcW :=A8)) s"
| "rbW_step A3 s = ((`T := 0) \<circ> (`H := (Data s (numEnqs s))) \<circ> (`offset := 0) \<circ> (`pcW := Write)
\<circ> setownB [(0,(Data s (numEnqs s))) W]) s"
| "rbW_step A4 s = ((`H := ((hW s) + (Data s (numEnqs s)))) \<circ> (`offset := (hW s)) \<circ> (`pcW := Write)
\<circ> setownB [(hW s,hW s+Data s (numEnqs s)) W]) s"
| "rbW_step A5 s = (if grd4 s then (`pcW := A6)
else if grd5 s then (`pcW := A7)
else (`pcW := A8)) s"
| "rbW_step A6 s = (`H := ((hW s) + (Data s (numEnqs s))) \<circ> (`offset := (hW s)) \<circ> (`pcW := Write)
\<circ> setownB [(hW s,hW s+Data s (numEnqs s)) W]) s"
| "rbW_step A7 s = ((`H := (Data s (numEnqs s))) \<circ> (`offset := 0) \<circ> (`pcW := Write)
\<circ> (setownB [(hW s,N) W])
\<circ> (setownB [(0,Data s (numEnqs s)) W])) s"
| "rbW_step A8 s = (if ((Data s (numEnqs s))>N) then ERRBTS s
else (ERROOM \<circ> (`tW := (T s))) s)"
| "rbW_step Write s = s"
| "rbW_step Enqueue s = s"| "rbW_step idleW s = s" | "rbW_step FinishedW s = s"| "rbW_step BTS s = s"| "rbW_step OOM s = s"
definition "B_acquire s s' \<equiv> ((pcW s \<in> {idleW})
\<and> (Data s (numEnqs s)) > 0
\<and> s' = (`pcW := A1) s)"
definition "Q_enqueue s s' \<equiv> s' = (`q:=(append (q s) [(offset s,Data s (numEnqs s))])
\<circ> `pcW := idleW
\<circ> transownB [W Q]
\<circ> `numEnqs := (numEnqs s + 1)
\<circ> transownT [W Q s]) s"
definition "B_write s s' \<equiv> s' = ((`B.write ((offset s), (Data s (numEnqs s))):= (numEnqs s))
\<circ> (transownD [(numWrites s) B]) \<circ> `pcW := Enqueue \<circ> (`numWrites := ((numWrites s )+1))) s"
definition cW_step :: "PCW \<Rightarrow> rb_state \<Rightarrow> rb_state \<Rightarrow> bool" where
"cW_step pcw s s' \<equiv>
case pcw of
idleW \<Rightarrow> if ((numEnqs s) < n) then B_acquire s s'
else s' = (`pcW := FinishedW ) s
| Write \<Rightarrow> B_write s s'
| Enqueue \<Rightarrow> Q_enqueue s s'
| OOM \<Rightarrow> if tW s \<noteq> T s then s' = (`pcW := idleW ) s else s = s'
| FinishedW \<Rightarrow> s = s'
| BTS \<Rightarrow> s = s'
| _ \<Rightarrow> s' = rbW_step pcw s "
(*lemma
"(a \<and> b \<longrightarrow> c) = a \<and> (b \<longrightarrow> c)"
nitpick
*)
lemmas W_functs [simp] = B_acquire_def B_write_def Q_enqueue_def
(*---------Tailored assertions to Writer-------*)
definition "pre_acquire_inv s \<equiv> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq> W)
\<and> (T s=H s \<longrightarrow> (\<forall>i.(i\<ge>0 \<and> i\<le>N)\<longrightarrow>ownB s i=B) \<and> ownT s = Q \<and> q s= [] \<and> numDeqs s = numEnqs s)
\<and> (T s>H s \<longrightarrow> (\<forall>i.(i\<ge>H s \<and> i<T s)\<longrightarrow>ownB s i=B))
\<and> (T s<H s \<longrightarrow> (\<forall>i.((i\<ge>H s \<and> i\<le>N) \<or> i<T s)\<longrightarrow>ownB s i=B))
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s=0\<longrightarrow>q s=[])
\<and> (numEnqs s\<le>n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_A1_inv s \<equiv> (T s=H s\<longrightarrow>((\<forall>i.(i\<ge>0 \<and> i\<le>N)\<longrightarrow>ownB s i=B) \<and> ownT s =Q))
\<and> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (T s>H s \<longrightarrow> (\<forall>i.(i\<ge>H s \<and> i<T s)\<longrightarrow>ownB s i=B))
\<and> (T s<H s \<longrightarrow> (\<forall>i.((i\<ge>H s \<and> i\<le>N) \<or> i<T s)\<longrightarrow>ownB s i=B))
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_A2_inv s \<equiv> (tW s=hW s\<longrightarrow>((\<forall>i.(i\<ge>0 \<and> i\<le>N)\<longrightarrow>ownB s i=B) \<and> ownT s =Q))
\<and> (tW s>hW s \<longrightarrow> (\<forall>i.(i\<ge>hW s \<and> i<tW s)\<longrightarrow>ownB s i=B))
\<and> (tW s<hW s \<longrightarrow> (\<forall>i.((i\<ge>hW s \<and> i\<le>N) \<or> i<tW s)\<longrightarrow>ownB s i=B))
\<and> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_A3_inv s \<equiv> ((\<forall>i.(i\<ge>0 \<and> i\<le>N)\<longrightarrow>ownB s i=B) \<and> ownT s =Q)
\<and> (grd1 s)
\<and> (ownT s =W)
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_A4_inv s \<equiv> (\<forall>i.(i\<ge>hW s \<and> i<tW s)\<longrightarrow>ownB s i=B)
\<and> (grd2 s) \<and> (\<not>grd1 s)
\<and> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s) \<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s) "
definition "pre_A5_inv s \<equiv> (\<forall>i.((i\<ge>hW s \<and> i<N) \<or> i<tW s)\<longrightarrow>ownB s i=B)
\<and> (grd3 s) \<and> (\<not>grd1 s) \<and> (\<not>grd2 s)
\<and> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s \<and> numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_A6_inv s \<equiv> (\<forall>i.((i\<ge>hW s \<and> i<N) \<or> i<tW s)\<longrightarrow>ownB s i=B)
\<and> (grd4 s) \<and> (grd3 s) \<and> (\<not>grd1 s) \<and> (\<not>grd2 s)
\<and> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_A7_inv s \<equiv> (\<forall>i.((i\<ge>hW s \<and> i<N) \<or> i<tW s)\<longrightarrow>ownB s i=B)
\<and> (grd5 s) \<and> (grd3 s) \<and> (\<not>grd1 s) \<and> (\<not>grd2 s) \<and> (\<not>grd4 s)
\<and> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s) "
definition "pre_A8_inv s \<equiv> (\<forall>i.((i\<ge>hW s \<and> i<N) \<or> i<tW s)\<longrightarrow>ownB s i=B)
\<and> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s)
\<and> (no_space_for_word s) \<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_write_inv s \<equiv> (\<forall>i.(i\<ge>offset s \<and> i< ((offset s)+(Data s (numEnqs s))))\<longrightarrow>ownB s i=W)
\<and> ((tW s>hW s)\<longrightarrow>(\<forall>i.(i\<ge>((offset s)+(Data s (numEnqs s)))\<and>i<tW s)\<longrightarrow>ownB s i =B))
\<and> ((tW s<hW s \<and> offset s\<noteq>0)\<longrightarrow>(\<forall>i.((i\<ge>((offset s)+(Data s (numEnqs s))) \<and> i\<le>N)\<or>i<tW s)\<longrightarrow>ownB s i =B))
\<and> ((tW s<hW s \<and> offset s=0)\<longrightarrow>((\<forall>i.(i\<ge>((offset s)+(Data s (numEnqs s))) \<and> i<tW s)\<longrightarrow>ownB s i =B) \<and> (\<forall>i.(i\<ge>hW s \<and> i<N)\<longrightarrow>ownB s i=W)))
\<and> (tW s=hW s\<longrightarrow>ownT s=W)
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (H s>0)
\<and> (pos_of_H_post_acq s)
"
definition "pre_enqueue_inv s \<equiv> (\<forall>i.(i\<ge>offset s \<and> i< ((offset s)+(Data s (numEnqs s))))\<longrightarrow>ownB s i=W)
\<and> ((tW s>hW s)\<longrightarrow>(\<forall>i.(i\<ge>((offset s)+(Data s (numEnqs s)))\<and>i<tW s)\<longrightarrow>ownB s i =B))
\<and> ((tW s<hW s \<and> offset s\<noteq>0)\<longrightarrow>(\<forall>i.((i\<ge>((offset s)+(Data s (numEnqs s))) \<and> i\<le>N)\<or>i<tW s)\<longrightarrow>ownB s i =B))
\<and> ((tW s<hW s \<and> offset s=0)\<longrightarrow>((\<forall>i.(i\<ge>((offset s)+(Data s (numEnqs s))) \<and> i<tW s)\<longrightarrow>ownB s i =B) \<and> (\<forall>i.(i\<ge>hW s \<and> i<N)\<longrightarrow>ownB s i=W)))
\<and> (tW s=hW s\<longrightarrow>ownT s=W)
\<and> (numWrites s=numEnqs s +1)
\<and> (numEnqs s<n)
\<and> (pos_of_H_post_acq s)
"
definition "pre_OOM_inv s \<equiv> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (tW s>hW s \<longrightarrow> (\<forall>i.(i\<ge>tW s \<and> i<hW s)\<longrightarrow>ownB s i=B))
\<and> (tW s<hW s \<longrightarrow> (\<forall>i.((i\<ge>hW s \<and> i\<le>N) \<or> i<tW s)\<longrightarrow>ownB s i=B))
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_finished_inv s \<equiv> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s=n)
\<and> (pos_of_H_pre_acq s)
"
definition "pre_BTS_inv s \<equiv> (\<forall>j.(j\<ge>0\<and> j\<le>N)\<longrightarrow>ownB s j\<noteq>W)
\<and> (ownT s \<noteq>W)
\<and> (numWrites s=numEnqs s)
\<and> (numEnqs s<n)
\<and> (pos_of_H_pre_acq s)
"
lemmas writer_lemmas = pre_A1_inv_def pre_A2_inv_def pre_A3_inv_def pre_A4_inv_def
pre_A5_inv_def pre_A6_inv_def pre_A7_inv_def pre_A8_inv_def
pre_BTS_inv_def pre_OOM_inv_def pre_acquire_inv_def
pre_finished_inv_def pre_enqueue_inv_def pre_write_inv_def
(***********************************************************************)
(*Reader Thread Behaviour*)
definition "B_release s s' \<equiv> s' = (`T := (off(tempR s) +len(tempR s))
\<circ> (`pcR := idleR)
\<circ> (`tempR := (0,0))
\<circ> (transownB [R B])
\<circ> (if tR s\<noteq> fst(tempR s) then setownB [(tR s,N) B] else id)
\<circ> transownT [R Q s]) s"
definition "B_read s s' \<equiv> s' = (((transownD [(data_index s (tempR s)) R])
\<circ> (`pcR := Release))
\<circ> (`numReads := ((numReads s)+1))
\<circ> (`tR := (T s))) s"
definition "Q_dequeue s s' \<equiv> s' = ((`q:= (tl(q s)))
\<circ> (`pcR := Read)
\<circ> (`tempR := (hd(q s)))
\<circ> (transownT [Q R s])
\<circ> (`numDeqs :=(numDeqs s+1))
\<circ> (setownB [(off(hd(q s)),(end(hd(q s)))) R])) s"
definition cR_step :: "PCR \<Rightarrow> rb_state \<Rightarrow> rb_state \<Rightarrow> bool" where
"cR_step pcr s s' \<equiv>
case pcr of
idleR \<Rightarrow> if (q s=[]) then (s=s') else (Q_dequeue s s')
| Read \<Rightarrow> B_read s s'
| Release \<Rightarrow> B_release s s'"
lemmas R_functs [simp] = B_release_def B_read_def Q_dequeue_def
(*---------Tailored assertions to Reader-------*)
definition "pre_dequeue_inv s \<equiv> (tempR s = (0,0))
\<and> (q s\<noteq>[] \<longrightarrow> ownT s=Q)
\<and> (q s\<noteq>[]\<longrightarrow> (numReads s=data_index s (hd(q s))))
\<and> (numDeqs s \<le> n)
\<and> (numDeqs s \<ge> 0)
\<and> (numDeqs s = numReads s)
\<and> (numDeqs s \<le> numEnqs s)
\<and> (pcR s = idleR)
\<and> (q s\<noteq>[] \<longrightarrow> Q_T_rel_idleR s)
\<and> (\<forall>i.(i\<ge>0 \<and> i\<le>N)\<longrightarrow>ownB s i\<noteq>R)
"
definition "pre_Read_inv s \<equiv> (numReads s=data_index s (tempR s))
\<and> (numDeqs s \<le> n)
\<and> (numDeqs s \<ge> 0)
\<and> (numReads s+1=numDeqs s)
\<and> (numEnqs s\<ge>numDeqs s)
\<and> (numDeqs s\<ge>1)
\<and> (pcR s=Read)
\<and> (\<forall>i.((i<fst(tempR s)))\<longrightarrow>ownB s i\<noteq>R)
\<and> (\<forall>j.((j\<ge>end(tempR s)))\<longrightarrow>ownB s j\<noteq>R)
\<and> (ownT s = R)
\<and> (tempR_structure s)
\<and> (ownD s (numReads s) = B)
\<and> (q s\<noteq>[] \<longrightarrow> Q_T_rel_nidleR s)
"
definition "pre_Release_inv s \<equiv> (snd(tempR s) = Data s (numReads s -1))
\<and> (data_index s (tempR s) = numReads s -1)
\<and> (ownT s = R)
\<and> (numEnqs s\<ge>numDeqs s)
\<and> (numDeqs s\<le>n)
\<and> (numDeqs s\<ge>1)
\<and> (numDeqs s = numReads s)
\<and> (pcR s=Release)
\<and> (\<forall>i.((i<fst(tempR s)))\<longrightarrow>ownB s i\<noteq>R)
\<and> (\<forall>j.((j\<ge>end(tempR s)))\<longrightarrow>ownB s j\<noteq>R)
\<and> (tR s=T s)
\<and> (tempR_structure s)
\<and> (ownD s (numReads s -1) = R)
\<and> (q s\<noteq>[] \<longrightarrow> Q_T_rel_nidleR s)
"
lemmas reader_lemmas = pre_Release_inv_def pre_Read_inv_def pre_dequeue_inv_def
(***********************************************************************)
lemma "x\<longrightarrow> y = x \<and> \<not> y \<longrightarrow> False"
by simp
definition "inRange v \<equiv> 0 \<le> v \<and> v \<le> N"
definition "inRangeHT s \<equiv> inRange (H s) \<and> inRange (T s)"
definition "H0_T0 s \<equiv> H s = 0 \<longrightarrow> T s = 0"
definition "inRangeht s \<equiv> inRange (hW s) \<and> inRange (tW s)"
definition "basic_pointer_movement s \<equiv> inRangeHT s \<and> inRangeht s \<and> H0_T0 s "
lemmas basic_pointer_movement_lemmas [simp] = basic_pointer_movement_def inRangeHT_def inRangeht_def H0_T0_def inRange_def
definition "mainInv s \<equiv> \<forall> i. (i<numReads s \<longrightarrow> ownD s i=R) \<and> (numReads s \<le> i \<and> i < numWrites s \<longrightarrow> ownD s i = B) \<and> (numWrites s \<le> i \<and> i < n \<longrightarrow> ownD s i = W) "
definition "counter_bounds s \<equiv> numReads s \<le>n \<and> numWrites s\<le>n \<and> numEnqs s\<le>n \<and> numDeqs s \<le> n"
definition "counter_q_rel s \<equiv> (numEnqs s-numDeqs s=length(q s))\<and> numWrites s\<ge>numReads s"
(*new lemmas, take 2*)
definition "data_index_bouded s \<equiv> \<forall>i. (i\<le>N)\<longrightarrow>(\<forall>j.(j\<le>N)\<longrightarrow>data_index s (i,j)<n)"
lemmas invariant_lemmas [simp] = con_assms_def mainInv_def
counter_q_rel_def
counter_bounds_def data_index_bouded_def
(*------------------------ Invariant ------------------------------------*)
definition inv where
"inv s \<equiv> basic_pointer_movement s
\<and> mainInv s
\<and> counter_q_rel s
\<and> counter_bounds s
\<and> Q_structure s
\<and> data_index_bouded s
"
definition pre_W where
"pre_W pcw s \<equiv> (case pcw of
idleW \<Rightarrow> pre_acquire_inv s
| A1 \<Rightarrow> pre_A1_inv s
| A2 \<Rightarrow> pre_A2_inv s
| A3 \<Rightarrow> pre_A3_inv s
| A4 \<Rightarrow> pre_A4_inv s
| A5 \<Rightarrow> pre_A5_inv s
| A6 \<Rightarrow> pre_A6_inv s
| A7 \<Rightarrow> pre_A7_inv s
| A8 \<Rightarrow> pre_A8_inv s
| Write \<Rightarrow> pre_write_inv s
| OOM \<Rightarrow> pre_OOM_inv s
| BTS \<Rightarrow> pre_BTS_inv s
| Enqueue \<Rightarrow> pre_enqueue_inv s
| FinishedW \<Rightarrow> pre_finished_inv s)"
definition pre_R where
"pre_R pcr s \<equiv>
(case pcr of
idleR \<Rightarrow> pre_dequeue_inv s
| Read \<Rightarrow> pre_Read_inv s
| Release \<Rightarrow> pre_Release_inv s)"
lemmas inv_simps = inv_def cW_step_def cR_step_def init_def
lemma tail_preserves_struct:
"Q_gap_structure s \<Longrightarrow> fst (q s ! 0) = 0 \<Longrightarrow>\<forall> i . i<length (q s) \<longrightarrow> snd(q s ! i) > 0 \<Longrightarrow>
Q_offsets_differ s \<Longrightarrow> length(q s)>0 \<Longrightarrow>
\<forall> i . (i<length (q s) \<and> i>0)\<longrightarrow> fst(q s ! i) > fst (q s ! 0)"
apply(simp add:Q_gap_structure_def Q_offsets_differ_def)
by (metis gr_implies_not_zero not_gr_zero)
lemma local_pre_R:
assumes "con_assms s"
and "pcr = pcR s"
and "pre_R pcr s"
and "inv s"
and "cR_step pcr s s'"
shows "pre_R (pcR s') s'"
using assms apply(simp add:inv_def pre_R_def)
apply(case_tac "pcR s", simp_all add:cR_step_def)
apply(case_tac "tR s\<noteq>fst(tempR s)", simp_all)
apply(case_tac "ownT s = R", simp_all)
apply(simp add:pre_dequeue_inv_def)
apply(intro conjI impI)
apply(simp add:pre_Release_inv_def Q_structure_def Q_holds_bytes_def)
apply clarify apply(simp add:Q_T_rel_nidleR_def)
apply(simp add:tempR_structure_def tempR_basic_struct_def tempR_gap_structure_def tempR_offsets_differ_def)
apply clarify
apply (metis Nat.add_0_right Q_reflects_writes_def hd_conv_nth length_greater_0_conv)
using pre_Release_inv_def apply auto[1]
apply(simp add:Q_T_rel_idleR_def)
apply (metis (no_types, hide_lams) Q_T_rel_nidleR_def end_simp list.set_sel(1) pre_Release_inv_def tempR_basic_struct_def tempR_gap_structure_def tempR_offsets_differ_def tempR_structure_def)
apply (simp add: pre_Release_inv_def)
apply clarify
apply(intro conjI impI)
apply(simp add:pre_Release_inv_def pre_dequeue_inv_def Q_T_rel_idleR_def)
apply safe[1]
apply(simp add: Q_lemmas pre_dequeue_inv_def pre_Release_inv_def Q_T_rel_idleR_def Q_T_rel_nidleR_def)
apply (metis add_cancel_right_right hd_conv_nth length_greater_0_conv)
apply(simp add:tempR_lemmas tempR_gap_structure_def Q_T_rel_nidleR_def)
apply(simp add:tempR_lemmas tempR_gap_structure_def tempR_has_no_overlaps_def Q_T_rel_nidleR_def Q_lemmas Q_basic_lemmas)
apply(subgoal_tac "end(q s!i)<T s")
apply (metis end_simp trans_less_add1)
apply(subgoal_tac "T s =fst(tempR s)") prefer 2
apply presburger
defer
apply (metis gr0I prod.collapse)
apply(simp add:Q_lemmas)
apply (metis add.right_neutral hd_conv_nth length_greater_0_conv)
apply(simp add:Q_lemmas tempR_lemmas)
apply (metis end_simp plus_nat.add_0 tempR_gap_structure_def)
apply(simp add:Q_lemmas tempR_lemmas)
apply (metis end_simp list.set_sel(1) plus_nat.add_0 tempR_gap_structure_def tempR_offsets_differ_def)
apply (metis prod.collapse)
apply (metis pre_Release_inv_def)
apply clarify
apply(simp add:pre_dequeue_inv_def)
apply(subgoal_tac "pcR s'\<noteq>Release") prefer 2
apply(case_tac "q s=[]"; simp)
apply(case_tac "q s=[]"; simp)
apply (metis assms(1) con_assms_def less_eq_nat.simps(1) pre_dequeue_inv_def)
apply(simp add:pre_Read_inv_def)
apply(intro conjI impI)
apply (metis length_greater_0_conv less_Suc_eq_le less_trans_Suc zero_less_diff)
apply (metis Suc_leI length_greater_0_conv zero_less_diff)
apply (metis Q_T_rel_idleR_def le_trans less_or_eq_imp_le)
apply(simp add:Q_lemmas Q_basic_lemmas Q_T_rel_idleR_def)
defer
defer
apply clarify
apply(simp add:Q_lemmas Q_basic_lemmas Q_T_rel_idleR_def)
apply (metis length_greater_0_conv plus_nat.add_0)
apply(simp add:Q_lemmas Q_basic_lemmas Q_T_rel_idleR_def Q_T_rel_nidleR_def)
apply(case_tac "T s = fst (hd (q s))", simp)
apply clarify
apply(intro conjI impI)
sledgehammer
oops
lemma local_pre_W:
assumes "con_assms s"
and "pcw = pcW s"
and "pre_W pcw s"
and "inv s"
and "cW_step pcw s s'"
shows "pre_W (pcW s') s'"
sorry
lemma global_pre_W:
assumes "con_assms s"
and "pcr = pcR s"
and "pcw = pcW s"
and "pre_R pcr s"
and "pre_W pcw s"
and "inv s"
and "cR_step pcr s s'"
shows "pre_W (pcW s') s'"
sorry
lemma global_pre_R:
assumes "con_assms s"
and "pcr = pcR s"
and "pcw = pcW s"
and "pre_R pcr s"
and "pre_W pcw s"
and "inv s"
and "cW_step pcw s s'"
shows "pre_R (pcR s') s'"
sorry
lemma inv_holds_for_W:
assumes "con_assms s"
and "pcw = pcW s"
and "pre_W pcw s"
and "inv s"
and "cW_step pcw s s'"
shows "inv s'"
apply(simp add:inv_def Q_structure_def)
proof (intro conjI)
sorry
lemma inv_holds_for_R:
assumes "con_assms s"
and "pcr = pcR s"
and "pre_R pcr s"
and "inv s"
and "cR_step pcr s s'"
shows "inv s'"
apply(simp add:inv_def Q_structure_def)
proof (intro conjI)
(*
preP \<and> preQ preP \<and> inv
P P
preQ inv
preP \<and> preQ preQ \<and> inv
Q Q
preP inv
preP
p
postP
preQ
Q
postQ
*)
lemma inv_init:
assumes "init s"
and "con_assms s"
shows "inv \<and> preR \<and> preW"
using assms
apply simp_all
apply (simp_all add: inv_def Q_lemmas)
apply(intro conjI impI)
oops
(*(*
(*------------------------showing progress----------------------*)
(*
lemma tries_are_bounded:
assumes "con_assms s"
and "cW_step pcw s s'"
and "inv pcw pcr s"
shows "tries s'\<le>N"
using assms
apply (simp_all add:cW_step_def)
using less_le_trans apply auto[1]
apply (case_tac "pcw", simp_all)
using less_imp_le_nat apply blast
using less_imp_le_nat apply blast
using less_imp_le_nat apply blast
using less_imp_le_nat apply blast
using less_imp_le_nat apply blast
using less_imp_le_nat apply blast
using less_imp_le_nat apply blast
using less_imp_le_nat apply blast
apply(case_tac "numEnqs s < n", simp_all add:less_imp_le)
apply(case_tac "tW s \<noteq> T s", simp_all)
using Suc_leI apply blast
by (meson less_imp_le_nat)
lemma when_W_moves_prog_less:
assumes "con_assms s"
and "inv (pcW s) (pcR s) s"
and "cW_step (pcW s) s s'"
shows "lex_prog s s'"
proof -
from assms(1) have sp1: "numEnqs s \<le> n \<and> numDeqs s \<le> n"
using con_assms_def by auto
from assms show ?thesis
apply (simp_all add:cW_step_def inv_def progress_lemmas tries_left_def)
apply(case_tac "pcW s", simp_all)
apply(case_tac[!] "pcR s", simp_all)
apply (simp_all add: diff_less_mono2)
apply (case_tac[!] "tW s = T s", simp_all add:cW_step_def)
apply(case_tac[1-6] "numEnqs s < n", simp_all)
using diff_less_mono2 by auto
qed
lemma W_counter_implies_notown:
assumes "con_assms s"
and "mainInv s"
shows "\<forall>i.(i<numEnqs s)\<longrightarrow>ownD s i \<in> {R,B}"
using assms
apply (simp_all add:inv_def)
by (meson le_less_linear)
lemma least_prog_W_implies:
assumes "con_assms s"
and "inv (pcW s) pcr s"
and "cW_step (pcW s) s s'"
and "inv (pcW s') pcr s'"
and "lex_prog s s'"
shows "end_W_prog s'=True\<longrightarrow>end_W_prog s \<or> ((\<forall>i.(i<n)\<longrightarrow>ownD s' i\<noteq>W) \<and> (pcW s=idleW) \<and> numEnqs s=n)"
using assms W_counter_implies_notown
apply (simp_all add: end_W_prog_def progress_lemmas tries_left_def cW_step_def inv_def)
apply (case_tac "pcW s", simp_all)
apply(case_tac "numEnqs s < n", simp_all)
apply(case_tac "pcr", simp_all)
apply (metis F.distinct(1) F.distinct(5) le_less_linear)
apply (metis F.distinct(1) F.distinct(5) le_less_linear)
apply (metis F.distinct(1) F.distinct(5) le_less_linear)
by(case_tac "tW s \<noteq> T s", simp_all)
lemma when_R_moves_prog_less:
assumes "con_assms s"
and "inv (pcW s) (pcR s) s"
and "cR_step (pcR s) s s'"
shows "lex_prog s s'"
using assms apply (simp_all add:inv_def cR_step_def progress_lemmas)
apply(case_tac "pcR s", simp_all add:tries_left_def)
apply(case_tac[!] "pcW s", simp_all)
apply(case_tac[!] "q s=[]", simp_all add: Let_def)
apply clarify
oops
apply(case_tac " T s < fst (hd (q s)) + snd (hd (q s))", simp_all)
apply(case_tac " T s < fst (hd (q s)) + snd (hd (q s))", simp_all)
apply (metis (no_types, lifting) add_less_mono diff_less_mono2 diff_self_eq_0 length_greater_0_conv lessI less_le_trans mult_2 nat_add_left_cancel_less nat_less_le)
apply (metis (no_types, lifting) add_less_mono diff_less_mono2 diff_self_eq_0 length_greater_0_conv lessI less_le_trans mult_2 nat_add_left_cancel_less nat_less_le)
apply(case_tac " T s < fst (hd (q s)) + snd (hd (q s))", simp_all)
apply (metis diff_less_mono2 length_greater_0_conv lessI zero_less_diff)
apply (metis diff_less_mono2 diff_self_eq_0 le_eq_less_or_eq length_0_conv lessI)
sorry
lemma least_prog_R_implies:
assumes "con_assms s"
and "inv (pcW s) (pcR s) s"
and "cR_step (pcR s) s s'"
and "inv (pcW s) (pcR s) s'"
and "lex_prog s s'"
shows "end_R_prog s'=True\<longrightarrow>(end_R_prog s \<or> ((\<forall>i.(i<n)\<longrightarrow>ownD s' i=R) \<and> pcR s=Release))\<and>end_W_prog s"
using assms apply (simp_all add: end_R_prog_def end_W_prog_def tries_left_def cR_step_def inv_def)
apply(case_tac "pcR s", simp_all)
by(case_tac "q s=[]", simp_all add:Let_def)
lemma initial_progress:
assumes "cR_step (pcR s) s s' \<or> cW_step (pcW s) s s'"
and "inv (pcW s) (pcR s) s"
and "init s'"
and "con_assms s"
shows "lex_prog s s'\<longrightarrow>s=s'"
using assms apply(simp_all add:cR_step_def cW_step_def init_def progress_lemmas tries_left_def inv_def)
apply(case_tac "pcR s", simp_all)
apply(case_tac "pcW s", simp_all)
apply (metis add.commute add_less_mono diff_less less_le_trans less_nat_zero_code mult.commute mult_2_right nat_le_iff_add order_less_irrefl zero_less_iff_neq_zero)
apply (metis add.commute add_cancel_right_left add_cancel_right_right add_is_0 diff_less diff_zero le_iff_add length_0_conv length_greater_0_conv less_add_eq_less less_irrefl_nat less_le_trans mult.commute mult_2_right nat_diff_split zero_less_iff_neq_zero)
apply (metis (no_types, hide_lams) add.commute diff_less le_iff_add le_less_trans less_eq_nat.simps(1) less_le_trans mult.commute mult_2_right order_less_irrefl trans_less_add2)
apply (metis add.commute add_strict_mono diff_less le_iff_add less_le_trans less_nat_zero_code less_not_refl mult.commute mult_2_right zero_less_iff_neq_zero)
apply (metis add_is_0 diff_diff_cancel diff_le_self nat_0_less_mult_iff nat_less_le not_le zero_less_diff zero_less_numeral)
apply (metis add.commute diff_less le0 le_less_trans less_le_trans mult.commute mult_2_right nat_le_iff_add order_less_irrefl trans_less_add2)
apply (metis add.commute diff_less le_iff_add le_less_trans less_eq_nat.simps(1) less_le_trans less_not_refl mult.commute mult_2_right trans_less_add2)
apply (metis add.commute diff_less le0 le_less_trans less_le_trans less_not_refl mult.commute mult_2_right nat_le_iff_add trans_less_add1)
apply (metis add.commute add_cancel_right_right diff_less gr_implies_not0 le0 le_iff_add le_less_trans le_neq_implies_less less_add_eq_less less_le_trans mult.commute mult_2_right order_less_irrefl zero_le)
apply (metis add_is_0 diff_diff_cancel diff_self_eq_0 nat_0_less_mult_iff nat_less_le zero_less_diff zero_less_numeral)
apply (metis add.commute diff_less le_iff_add le_less_trans less_le_trans mult.commute mult_2_right order_less_irrefl trans_less_add2 zero_le)
apply (metis diff_add_zero diff_diff_cancel less_numeral_extra(3) mult_2)
apply (metis add.commute diff_less le_iff_add less_le_trans mult.commute mult_2_right order_less_irrefl)
apply (metis add.commute diff_less le_iff_add less_le_trans less_not_refl mult.commute mult_2_right)
apply (simp add: leD)
by (simp add: leD)
(*--------------------------------------------------------------*)
(*--------------lexicographical progress------------------------------*)
definition "ltpcW i j \<equiv>
(i \<noteq> j \<and>
(i=FinishedW)
\<or>(i \<in> {Enqueue, OOM, BTS} \<and> j\<noteq>FinishedW)
\<or> (i \<in> {A8, Write} \<and> j \<notin> {Enqueue, OOM, BTS, FinishedW})
\<or> (i \<in> {A6, A7} \<and> j \<in> {idleW, A1, A2, A3, A4, A5})
\<or> (i \<in> {A3, A4, A5} \<and> j \<in> {idleW, A1, A2})
\<or> (i = A2 \<and> j \<in> {idleW, A1})
\<or> (i = A1 \<and> j = idleW))
"
definition "ltpcR i j \<equiv>
i = idleR \<and> j =Release \<or> i=Release \<and> j=Read \<or> i=Read \<and> j=idleR"
definition "state_pv s \<equiv> (2*n - numEnqs s - numDeqs s)"
definition "tries_left s \<equiv> N-tries s"
definition "lex_prog s s' \<equiv> s = s' \<or>
(state_pv s' < state_pv s
\<or> (state_pv s' = state_pv s \<and> tries_left s' < tries_left s)
\<or> (state_pv s' = state_pv s \<and> tries_left s' = tries_left s \<and> ltpcR (pcR s') (pcR s))
\<or> (state_pv s' = state_pv s \<and> tries_left s' = tries_left s \<and> ltpcW (pcW s') (pcW s)))"
lemmas progress_lemmas = ltpcW_def ltpcR_def state_pv_def lex_prog_def
definition "end_W_prog s \<equiv> ((n-numEnqs s)=0) \<and> tries_left s=N \<and> pcW s=FinishedW"
definition "end_R_prog s \<equiv> end_W_prog s\<and> pcR s=idleR \<and> numDeqs s=numEnqs s"
definition "start_state_prog s\<equiv> state_pv s=2*n \<and> pcR s=idleR \<and> pcW s=idleW \<and> tries_left s=N"
*)
(*
\<and> right_to_addresses s
\<and> no_ownB s
\<and> H_T_ownB s
\<and> Buff_entries_transfer_numDeqs s*)*)*)
(*
definition "last_q s \<equiv> (q s!(length(q s)-1))"
definition "last_q_sum s \<equiv> fst(last_q s)+snd(last_q s)"
definition "tempR_sum s \<equiv> fst(tempR s)+snd(tempR s)"
definition "case_1 s \<equiv> (H s=T s \<and> pcR s=idleR \<and> pcW s\<in>W_pre_acquire_set \<and> q s=[]
\<and> (\<forall>j.(j\<ge>0\<and>j<N)\<longrightarrow>ownB s j=B))"
definition "case_2 s \<equiv> (H s>T s \<and> pcR s=idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and>j<N\<or>j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>hW s\<and>j<H s)\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.(j\<ge>T s\<and>j<last_q_sum s)\<longrightarrow>ownB s j=Q)
\<and>(last_q_sum s =hW s))"
definition "case_3 s \<equiv> (H s>T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.((j\<ge>H s\<and> j<N)\<or>(j\<ge>0\<and>j<T s))\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>hW s\<and> j<H s)\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.(j\<ge>tempR_sum s\<and> j<last_q_sum s)\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>T s\<and>j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>(last_q_sum s =hW s)
\<and>(tempR_sum s = fst(q s!0))
\<and>(T s=fst(tempR s)))"
definition "case_4 s \<equiv> (H s>T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_pre_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.((j\<ge>H s\<and>j<N)\<or>(j\<ge>0\<and>j<T s))\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>tempR_sum s\<and> j<last_q_sum s)\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>T s\<and>j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>(tempR_sum s = fst(q s!0))
\<and>(T s=fst(tempR s)))"
definition "case_5 s \<equiv> (H s<T s \<and> pcR s=idleR \<and> pcW s\<in>W_pre_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and>j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.((j\<ge>T s\<and> j<N)\<or>(j\<ge>0\<and>j<H s))\<longrightarrow>ownB s j=Q)
\<and> H s=last_q_sum s)"
definition "case_6 s \<equiv>(H s<T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_pre_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.((j\<ge>tempR_sum s \<and> j<N)\<or>(j\<ge>0 \<and> j<H s))\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>T s\<and> j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>(T s=fst(tempR s))
\<and>H s = last_q_sum s)"
definition "case_7 s \<equiv>(H s<T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_pre_acquire_set
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.((j\<ge>tempR_sum s\<and> j<H s)\<or>(j\<ge>T s\<and> j<N))\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>0 \<and> j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>fst(tempR s) =0
\<and>T s\<noteq>fst(tempR s)
\<and>(q s\<noteq>[]\<longrightarrow>fst(q s!0) = tempR_sum s \<and> H s=last_q_sum s)
\<and>(q s=[]\<longrightarrow>H s =tempR_sum s))"
definition "case_8 s \<equiv>(H s<T s \<and> pcR s=idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>hW s\<and>j<H s)\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.((j\<ge>T s\<and> j<N)\<or>(j\<ge>0\<and>j<last_q_sum s))\<longrightarrow>ownB s j=Q)
\<and>(hW s=last_q_sum s)
\<and>offset s=hW s)"
definition "case_9 s \<equiv>(H s<T s \<and> pcR s=idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.((j\<ge>hW s\<and>j<N)\<or>(j\<ge>0 \<and>j<H s))\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.(j\<ge>T s\<and> j<last_q_sum s)\<longrightarrow>ownB s j=Q)
\<and>offset s=0
\<and>last_q_sum s=hW s
\<and>T s=fst(q s!0))"
definition "case_10 s \<equiv>(H s<T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>hW s\<and>j<H s)\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.((j\<ge>0\<and>j<last_q_sum s)\<or>(j\<ge>tempR_sum s\<and>j<N))\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>T s\<and>j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>T s=fst(tempR s)
\<and>last_q_sum s=hW s)"
definition "case_11 s \<equiv>(H s<T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>hW s\<and>j<H s)\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.((j\<ge>tempR_sum s \<and>j<last_q_sum s)\<or>(j\<ge>T s\<and>j<N))\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>0 \<and>j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>fst(tempR s) =0
\<and>tempR_sum s=fst(q s!0)
\<and>last_q_sum s=hW s
\<and>T s\<noteq>fst(tempR s))"
definition "case_12 s \<equiv>(H s<T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s\<noteq>[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>hW s\<and>j<H s)\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.((j\<ge>tempR_sum s \<and>j<last_q_sum s)\<or>(j\<ge>T s\<and>j<N))\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>0 \<and>j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>fst(tempR s) =0
\<and>tempR_sum s=fst(q s!0)
\<and>last_q_sum s=hW s
\<and>T s\<noteq>fst(tempR s))"
definition "ownB_cases s \<equiv>
case_1 s
\<or>case_2 s
\<or>case_3 s
\<or>case_4 s
\<or>case_5 s
\<or>case_6 s
\<or>case_7 s
\<or>case_8 s
\<or>case_9 s
\<or>case_10 s
\<or>case_11 s
\<or>case_12 s"
definition "case_2_qempty s \<equiv>(H s>T s \<and> pcR s=idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s=[]
\<and>(\<forall>j.(j\<ge>H s\<and>j<N\<or>j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>T s\<and>j<H s)\<longrightarrow>ownB s j=W)
\<and> offset s=T s
\<and>(hW s\<noteq>tW s \<longrightarrow>offset s=hW s)
\<and>(hW s=tW s\<longrightarrow>offset s=0))"
definition "case_3_qempty s \<equiv>(H s>T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s=[]
\<and>(\<forall>j.((j\<ge>H s\<and> j<N)\<or>(j\<ge>0\<and>j<T s))\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>hW s\<and> j<H s)\<longrightarrow>ownB s j=W)
\<and>(\<forall>j.(j\<ge>T s\<and>j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>(tempR_sum s = hW s)
\<and>(T s=fst(tempR s)))"
definition "case_4_qempty s \<equiv>(H s>T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_pre_acquire_set \<and> q s=[]
\<and>(\<forall>j.((j\<ge>H s\<and>j<N)\<or>(j\<ge>0\<and>j<T s))\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>T s\<and>j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>H s=tempR_sum s
\<and>(T s=fst(tempR s)))"
definition "case_7_qempty s \<equiv>(H s<T s \<and> pcR s\<noteq>idleR \<and> pcW s\<in>W_pre_acquire_set \<and> q s=[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.(j\<ge>T s\<and>j<N)\<longrightarrow>ownB s j=Q)
\<and>(\<forall>j.(j\<ge>0\<and> j<tempR_sum s)\<longrightarrow>ownB s j=R)
\<and>(T s\<noteq>fst(tempR s))
\<and>H s=tempR_sum s)"
definition "case_9_qempty s \<equiv>(H s<T s \<and> pcR s=idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s=[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.((j\<ge>T s\<and>j<N)\<or>(j\<ge>0 \<and>j<H s))\<longrightarrow>ownB s j=W)
\<and>offset s=0
\<and>T s=hW s)"
definition "case_11_qempty s \<equiv>(H s<T s \<and> pcR s=idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s=[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.((j\<ge>T s\<and>j<N)\<or>(j\<ge>0 \<and>j<H s))\<longrightarrow>ownB s j=W)
\<and>offset s=0
\<and>T s=hW s)"
definition "case_12_qempty s \<equiv>(H s<T s \<and> pcR s=idleR \<and> pcW s\<in>W_post_acquire_set \<and> q s=[]
\<and>(\<forall>j.(j\<ge>H s\<and> j<T s)\<longrightarrow>ownB s j=B)
\<and>(\<forall>j.((j\<ge>T s\<and>j<N)\<or>(j\<ge>0 \<and>j<H s))\<longrightarrow>ownB s j=W)
\<and>offset s=0
\<and>T s=hW s)"
definition "ownB_cases_qempty s \<equiv>
case_2_qempty s
\<or>case_3_qempty s
\<or>case_4_qempty s
\<or>case_7_qempty s
\<or>case_9_qempty s
\<or>case_11_qempty s
\<or>case_12_qempty s"
definition "pre_acq_cases s \<equiv> case_1 s \<or> case_4 s \<or> case_5 s \<or> case_6 s \<or> case_7 s
\<or> case_4_qempty s \<or>case_7_qempty s"
lemmas pre_acq_case_lemmas = pre_acq_cases_def case_1_def case_4_def case_5_def case_6_def
case_7_def case_4_qempty_def case_7_qempty_def
definition "post_acq_cases s \<equiv> case_2 s \<or> case_3 s \<or> case_8 s \<or> case_9 s \<or> case_10 s
\<or> case_11 s \<or> case_12 s \<or> case_2_qempty s
\<or> case_3_qempty s \<or> case_9_qempty s \<or> case_11_qempty s
\<or> case_12_qempty s"
lemmas post_acq_case_lemmas = post_acq_cases_def case_2_def case_3_def case_8_def case_9_def
case_10_def case_11_def case_12_def case_2_qempty_def
case_3_qempty_def case_9_qempty_def case_11_qempty_def
case_12_qempty_def
definition "pre_deq_cases s \<equiv> case_1 s \<or>case_2 s \<or>case_5 s \<or>case_8 s \<or>case_9 s
\<or>case_2_qempty s \<or>case_9_qempty s \<or>case_11_qempty s \<or>case_12_qempty s"
lemmas pre_deq_case_lemmas = pre_deq_cases_def case_1_def case_2_def case_5_def case_8_def
case_9_def case_2_qempty_def case_9_qempty_def
case_11_qempty_def case_12_qempty_def
definition "post_deq_cases s \<equiv> case_3 s \<or>case_4 s \<or>case_6 s \<or>case_7 s \<or>case_10 s \<or>case_11 s \<or>case_12 s
\<or>case_3_qempty s \<or>case_4_qempty s \<or>case_7_qempty s"
lemmas post_deq_case_lemmas = post_deq_cases_def case_3_def case_4_def case_6_def case_7_def case_11_def
case_10_def case_12_def case_3_qempty_def
case_4_qempty_def case_7_qempty_def
definition "all_cases s \<equiv>ownB_cases_qempty s \<or> ownB_cases s"
lemmas all_cases_lemmas = all_cases_def last_q_def last_q_sum_def tempR_sum_def
ownB_cases_qempty_def ownB_cases_def case_1_def
case_1_def case_2_def case_3_def case_4_def
case_5_def case_6_def case_7_def case_8_def
case_9_def case_10_def case_11_def case_12_def
case_2_qempty_def case_3_qempty_def case_4_qempty_def
case_7_qempty_def case_9_qempty_def case_11_qempty_def
case_12_qempty_def
*) |
function distVal=GaussianSimilarity(mu1,Sigma1,mu2,Sigma2)
%%GAUSSIANSIMILARITY This is the normalized similarity measure used between
% two Gaussian distributions in the Appendix of [1]. It
% ranges from 0 (completely different) to 1 (same
% distribution).
%
%INPUTS: mu1 The xDimX1 mean of the first Gaussian distribution.
% Sigma1 The xDimXxDim covariance matrix of the first Gaussian
% distribution.
% mu2 The xDimX1 mean of the second Gaussian distribution.
% Sigma2 The xDimXxDim covariance matrix of the second Gaussian
% distribution.
%
%OUTPUTS: distVal The scalar distance between the two distributions.
%
%EXAMPLE:
%We show the similairty of identical distirbutions, extremely different
%distributions, and distributions that just differ a little bit.
% mu1=[12;3];
% mu2=[2000;8000];
% Sigma1=[10, 6;
% 6, 9];
% Sigma2=[8, -3;
% -3, 14];
% %Identical Distributions (Similarity is 1).
% GaussianSimilarity(mu1,Sigma1,mu1,Sigma1)
% %Distributions that are very different (Similarity is 0).
% GaussianSimilarity(mu1,Sigma1,mu2,Sigma2)
% %Distributions that only differ a little bit (Similarity is about
% %0.2163).
% GaussianSimilarity(mu1,Sigma1,mu1*0.5,Sigma1*0.5)
%
%REFERENCES:
%[1] F. Faubel, J. McDonough, and D. Klakow, "The split and merge unscented
% Gaussian mixture filter," IEEE Signal Processing Letters, vol. 16, no.
% 9, pp. 786-789, Sep. 2009.
%
%January 2021 David F. Crouse, Naval Research Laboratory, Washington D.C.
%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.
%Equation 16.
Sigma12Inv=inv(Sigma1)+inv(Sigma2);
%Equation 15.
mu12=Sigma12Inv\(Sigma1\mu1+Sigma2\mu2);
numDim=size(mu1,1);
z=zeros(numDim,1);
p1=GaussianD.PDF(z,mu1,Sigma1/2);
p2=GaussianD.PDF(z,mu2,Sigma2/2);
p12=GaussianD.PDFI(z,mu12,Sigma12Inv);
if(p1==0||p2==0||p12==0||p1*p2==0)
distVal=0;
else
distVal=sqrt(p1*p2)/p12;
end
end
%LICENSE:
%
%The source code is in the public domain and not licensed or under
%copyright. The information and software may be used freely by the public.
%As required by 17 U.S.C. 403, third parties producing copyrighted works
%consisting predominantly of the material produced by U.S. government
%agencies must provide notice with such work(s) identifying the U.S.
%Government material incorporated and stating that such material is not
%subject to copyright protection.
%
%Derived works shall not identify themselves in a manner that implies an
%endorsement by or an affiliation with the Naval Research Laboratory.
%
%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE
%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL
%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS
%OF RECIPIENT IN THE USE OF THE SOFTWARE.
|
\section{MPSoC Block Diagram}
\label{sec:embedded_platform:block_diagram}
Figure \ref{fig:hardware_overview} shows the most important hardware components for this project on the Ultra96-V2 board.
Communication and data transfer is handled by the interconnects, on the \acrlong{pl} side it is the AXI Interconnect \cite{mpsoc_memory}.
Recorded frames are stored in the \acrshort{ram} and retrieved when needed.
The Mali-400 MP2 is an OpenGL multi core \acrfull{gpu} distributed by ARM \cite{arm_mali}.
A \acrshort{gpu} is required to use the graphical interface.
The \acrshort{pl} contains the \acrshort{dpu} to run inference.
The application and the operating system run on the ARM processor.
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{graphics/hardware_overview.pdf}
\caption{Available hardware on the Ultra96-V2}
\label{fig:hardware_overview}
\end{figure}
|
# GraphHopper Directions API
#
# You use the GraphHopper Directions API to add route planning, navigation and route optimization to your software. E.g. the Routing API has turn instructions and elevation data and the Route Optimization API solves your logistic problems and supports various constraints like time window and capacity restrictions. Also it is possible to get all distances between all locations with our fast Matrix API.
#
# OpenAPI spec version: 1.0.0
#
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' GeocodingPoint Class
#'
#' @field lat
#' @field lng
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
GeocodingPoint <- R6::R6Class(
'GeocodingPoint',
public = list(
`lat` = NULL,
`lng` = NULL,
initialize = function(`lat`, `lng`){
if (!missing(`lat`)) {
stopifnot(is.numeric(`lat`), length(`lat`) == 1)
self$`lat` <- `lat`
}
if (!missing(`lng`)) {
stopifnot(is.numeric(`lng`), length(`lng`) == 1)
self$`lng` <- `lng`
}
},
toJSON = function() {
GeocodingPointObject <- list()
if (!is.null(self$`lat`)) {
GeocodingPointObject[['lat']] <- self$`lat`
}
if (!is.null(self$`lng`)) {
GeocodingPointObject[['lng']] <- self$`lng`
}
GeocodingPointObject
},
fromJSON = function(GeocodingPointJson) {
GeocodingPointObject <- jsonlite::fromJSON(GeocodingPointJson)
if (!is.null(GeocodingPointObject$`lat`)) {
self$`lat` <- GeocodingPointObject$`lat`
}
if (!is.null(GeocodingPointObject$`lng`)) {
self$`lng` <- GeocodingPointObject$`lng`
}
},
toJSONString = function() {
sprintf(
'{
"lat": %d,
"lng": %d
}',
self$`lat`,
self$`lng`
)
},
fromJSONString = function(GeocodingPointJson) {
GeocodingPointObject <- jsonlite::fromJSON(GeocodingPointJson)
self$`lat` <- GeocodingPointObject$`lat`
self$`lng` <- GeocodingPointObject$`lng`
}
)
)
|
lemma diameter_cbox: fixes a b::"'a::euclidean_space" shows "(\<forall>i \<in> Basis. a \<bullet> i \<le> b \<bullet> i) \<Longrightarrow> diameter (cbox a b) = dist a b" |
The complex conjugate of a real number times a complex number is the complex conjugate of the complex number times the real number. |
theory Exe2p9
imports Main
begin
fun itadd :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
"itadd 0 n = n" |
"itadd (Suc m) n = itadd m (Suc n)"
lemma "itadd m n = m + n"
apply(induction m arbitrary: n)
apply(auto)
done
end
|
#include <opencv2\opencv.hpp>
#include <iostream>
#include <fstream>
#include <sstream>
#include <boost\filesystem.hpp>
#include <iomanip>
#include <direct.h>
#include <ctime>
#include "exif.h"
namespace fs = ::boost::filesystem;
using namespace std;
using namespace cv;
/*
structure to map an image to its mean color
*/
struct ImageMean{
string name;
Vec3b mean;
};
/*
structure to hold application parameters
*/
struct Params{
string images_root;
string out_folder;
string index_filename = "index.txt";
Size pixelSize;
string input_image;
double resize_x;
double resize_y;
char pixelize;
char mosaicize;
unsigned skip_interval;
};
bool isInVector(const string& str, const vector<string>& vec){
for (string s : vec){
if (s == str)
return true;
}
return false;
}
/*
seeks recursively in root for all files having extension ext,
and builds the list ret
*/
void get_all(const fs::path& root, const vector<string>& extensions, vector<string>& ret)
{
if (!fs::exists(root) || !fs::is_directory(root)) return;
fs::recursive_directory_iterator it(root);
fs::recursive_directory_iterator endit;
while (it != endit)
{
if (fs::is_regular_file(*it) && isInVector(it->path().extension().string(), extensions))
ret.push_back(it->path().string());
++it;
}
}
/*
computes the mean color of an image
*/
Vec3b mean(const Mat3b& m){
unsigned long b = 0;
unsigned long g = 0;
unsigned long r = 0;
unsigned char *data = (unsigned char*)(m.data);
for (int r_c = 0; r_c < m.rows; ++r_c){
for (int c_c = 0; c_c < m.cols * 3; c_c = c_c + 3){
b += data[m.step * r_c + c_c];
g += data[m.step * r_c + c_c + 1];
r += data[m.step * r_c + c_c + 2];
}
}
unsigned nPix = m.rows*m.cols;
return Vec3b(b / nPix, g / nPix, r / nPix);
}
/*
self explanatory
*/
void printProgress(int percentage, unsigned elapsed, unsigned etl){
cout << "\rProgress:|";
char bar_length = 15;
char number_of_progress_chars = round(percentage * bar_length / 100);
for (unsigned j = 0; j < number_of_progress_chars; ++j) cout << "=";
cout << ">";
for (unsigned j = 0; j < bar_length - number_of_progress_chars; ++j) cout << " ";
cout << "| " << percentage << "%, Time elapsed: " << elapsed << " seconds, ETL: " << etl << " seconds.";
}
/*
extracts exif orientations from jpeg files.
useful if you have pictures taken with smartphones
*/
char extractEXIFOrientation(const string& img_name){
FILE *fp = fopen(img_name.c_str(), "rb");
if (!fp) {
//printf("Can't open file.\n");
}
fseek(fp, 0, SEEK_END);
unsigned long fsize = ftell(fp);
rewind(fp);
unsigned char *buf = new unsigned char[fsize];
if (fread(buf, 1, fsize, fp) != fsize) {
//printf("Can't read file.\n");
delete[] buf;
}
fclose(fp);
// Parse EXIF
easyexif::EXIFInfo result;
int code = result.parseFrom(buf, fsize);
delete[] buf;
if (code) {
//printf("Error parsing EXIF: code %d\n", code);
}
return result.Orientation;
}
/*
rotates an image clockwise
*/
void rotateClockwise(Mat& img){
transpose(img, img);
flip(img, img, 1);
}
/*
fixes image given its exif orientation
*/
void rectifyByOrientation(Mat3b& img, char orientation){
switch (orientation){
case 1: break; //fine
case 6: //rotate clockwise
rotateClockwise(img);
break;
case 3: //flip vertically
//ignorance is the law
rotateClockwise(img);
rotateClockwise(img);
break;
case 8: // rotate counterclockwise
//even more ignorance!!!!
rotateClockwise(img);
rotateClockwise(img);
rotateClockwise(img);
break;
default: break;
}
}
/*
precomputes all the small images ("pixels") that will form the mosaic.
Also stores in an index (index_filename) the mapping with the mean color.
*/
void
computePixelsAndIndex(const string& images_root, const string& out_folder, Size s, const string& index_filename){
cout << "Pixelizing images from " << images_root << ". This might take a while." << endl;
vector<string> images;
vector<string> extensions = { ".jpg", ".jpeg", ".JPG", ".JPEG" };
get_all(images_root, extensions, images);
fs::remove_all(out_folder);
fs::create_directory(out_folder);
ofstream out_index(out_folder + index_filename);
clock_t begin = clock();
for (unsigned i = 0; i < images.size(); ++i)
{
Mat3b img = imread(images[i]);
char orientation = extractEXIFOrientation(images[i]);
rectifyByOrientation(img, orientation);
Vec3b mean_color = mean(img);
Mat3b resized;
resize(img, resized, s);
ostringstream out_filename;
out_filename << out_folder << setfill('0') << setw(5) << i << ".png";
imwrite(out_filename.str(), resized);
out_index << out_filename.str() << "\t" << (int)mean_color[0] << " " << (int)mean_color[1] << " " << (int)mean_color[2] << endl;
//Measuring time for progress...
clock_t end = clock();
int percentage = round(double(i) * 100 / images.size());
unsigned elapsed = double(end - begin) / CLOCKS_PER_SEC;
unsigned etl = (double(elapsed) / i)*(images.size() - i);
printProgress(percentage, elapsed, etl);
}
out_index.close();
cout << endl << "Done." << endl;
}
/*
reads the precomputed mean colors from file
*/
void readIndexFile(const string& index_filename, vector<ImageMean>& index){
ifstream in(index_filename);
string line;
while (getline(in, line)){
stringstream ss(line);
ImageMean im;
unsigned r, g, b;
ss >> im.name >> b >> g >> r;
im.mean = Vec3b(b, g, r);
index.push_back(im);
}
}
/*
utility structure for sorting (by similarity)
*/
struct idxVal{
int idx;
double val;
bool operator<(idxVal conf){
if (val < conf.val)return true;
return false;
}
};
/*
returns the nearest image given the pixel color and the forbidden ones
*/
ImageMean nearestImage(const vector<ImageMean>& index, Vec3b color, vector<unsigned char>& forbidden){
vector<idxVal> ivals;
for (unsigned i = 0; i < index.size(); ++i){
Vec3b conf = index[i].mean;
idxVal ival;
ival.idx = i;
ival.val = norm(color, conf);
ivals.push_back(ival);
}
sort(ivals.begin(), ivals.end());
for (unsigned i = 0; i < ivals.size(); i++){
if (!forbidden[ivals[i].idx]){
forbidden[ivals[i].idx] = 1;
return index[ivals[i].idx];
}
}
ImageMean err;
return err;
}
/*
self explanatory
*/
void printUsage(){
cout << "Usage: Photomosaic <settings_file.ini>" << endl;
}
/*
reads the file holding parameters settings
*/
void readInitFile(const string& init_file, Params& params)
{
try{
ifstream in(init_file);
string line;
vector<string> strings;
while (getline(in, line)){
if (line[0] != '#') strings.push_back(line);
}
istringstream ss;
//dataset
params.images_root = strings[0];
//pixel_folder
params.out_folder = strings[1];
//pixel_size
ss = istringstream(strings[2]);
unsigned sx, sy;
ss >> sx >> sy;
params.pixelSize = Size(sx, sy);
//input image
params.input_image = strings[3];
//resize
ss = istringstream(strings[4]);
ss >> params.resize_x >> params.resize_y;
//pixelize
ss = istringstream(strings[5]);
params.pixelize = atoi(ss.str().c_str());
//mosaicize
ss = istringstream(strings[6]);
params.mosaicize = atoi(ss.str().c_str());
//skip_interval
ss = istringstream(strings[7]);
ss >> params.skip_interval;
}
catch (int e){
cout << "Something went wrong in the initialization file parsing... please check it." << endl;
exit(1);
}
}
/*
main function
*/
int main(int argc, char** argv){
if (argc != 2){
printUsage();
return 1;
}
string init_file = argv[1];
Params p;
readInitFile(init_file, p);
if (p.pixelize){
computePixelsAndIndex(p.images_root, p.out_folder, p.pixelSize, p.index_filename);
}
if (p.mosaicize){
cout << "Rendering mosaic for image " << p.input_image << "..." << endl;
vector<ImageMean> index;
readIndexFile(p.out_folder + p.index_filename, index);
Mat3b src = imread(p.input_image);
resize(src, src, Size(0, 0), p.resize_x, p.resize_y);
Mat3b output(src.rows*p.pixelSize.height, src.cols*p.pixelSize.width);
vector<unsigned char> forbidden(index.size());
clock_t begin = clock();
for (int i = 0; i < src.rows; ++i){
for (int j = 0; j < src.cols; ++j){
if (((i*src.cols + j) % p.skip_interval) == 0)
forbidden = vector<unsigned char>(index.size());
Vec3b color = src(i, j);
ImageMean best_match = nearestImage(index, color, forbidden);
Mat3b pixel = imread(best_match.name);
Rect bound(j*p.pixelSize.width, i*p.pixelSize.height, p.pixelSize.width, p.pixelSize.height);
pixel.copyTo(output.rowRange(i*p.pixelSize.height, i*p.pixelSize.height + p.pixelSize.height).colRange(j*p.pixelSize.width, j*p.pixelSize.width + p.pixelSize.width));
}
}
imwrite("output.png", output);
cout << endl << "Done. Mosaic image has been written to output.png" << endl;
}
} |
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ : R β+* S
xβ : S
f : R β+* S
x : S
β’ evalβ f x p = sum p fun e a => βf a * x ^ e
[PROOFSTEP]
rw [evalβ_def]
[GOAL]
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒ³ : Semiring Rβ
p q r : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
x : Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Semiring R
instβ : Semiring S
f g : R β+* S
s t : S
Ο Ο : R[X]
β’ f = g β s = t β Ο = Ο β evalβ f s Ο = evalβ g t Ο
[PROOFSTEP]
rintro rfl rfl rfl
[GOAL]
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒ³ : Semiring Rβ
p q r : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
x : Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Semiring R
instβ : Semiring S
f : R β+* S
s : S
Ο : R[X]
β’ evalβ f s Ο = evalβ f s Ο
[PROOFSTEP]
rfl
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f 0 p = βf (coeff p 0)
[PROOFSTEP]
simp (config := { contextual := true }) only [evalβ_eq_sum, zero_pow_eq, mul_ite, mul_zero, mul_one, sum,
Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff, RingHom.map_zero, imp_true_iff, eq_self_iff_true]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x 0 = 0
[PROOFSTEP]
simp [evalβ_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x (βC a) = βf a
[PROOFSTEP]
simp [evalβ_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x X = x
[PROOFSTEP]
simp [evalβ_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
r : R
β’ evalβ f x (β(monomial n) r) = βf r * x ^ n
[PROOFSTEP]
simp [evalβ_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
β’ evalβ f x (X ^ n) = x ^ n
[PROOFSTEP]
rw [X_pow_eq_monomial]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
β’ evalβ f x (β(monomial n) 1) = x ^ n
[PROOFSTEP]
convert evalβ_monomial f x (n := n) (r := 1)
[GOAL]
case h.e'_3
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
β’ x ^ n = βf 1 * x ^ n
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x (p + q) = evalβ f x p + evalβ f x q
[PROOFSTEP]
simp only [evalβ_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ (sum (p + q) fun e a => βf a * x ^ e) = (sum p fun e a => βf a * x ^ e) + sum q fun e a => βf a * x ^ e
[PROOFSTEP]
apply sum_add_index
[GOAL]
case hf
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ β (i : β), βf 0 * x ^ i = 0
[PROOFSTEP]
simp [add_mul]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ β (a : β) (bβ bβ : R), βf (bβ + bβ) * x ^ a = βf bβ * x ^ a + βf bβ * x ^ a
[PROOFSTEP]
simp [add_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x 1 = 1
[PROOFSTEP]
rw [β C_1, evalβ_C, f.map_one]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x (bit0 p) = bit0 (evalβ f x p)
[PROOFSTEP]
rw [bit0, evalβ_add, bit0]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x (bit1 p) = bit1 (evalβ f x p)
[PROOFSTEP]
rw [bit1, evalβ_add, evalβ_bit0, evalβ_one, bit1]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
xβ : S
g : R β+* S
p : R[X]
x : S
s : R
β’ evalβ g x (s β’ p) = βg s * evalβ g x p
[PROOFSTEP]
have A : p.natDegree < p.natDegree.succ := Nat.lt_succ_self _
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
xβ : S
g : R β+* S
p : R[X]
x : S
s : R
A : natDegree p < Nat.succ (natDegree p)
β’ evalβ g x (s β’ p) = βg s * evalβ g x p
[PROOFSTEP]
have B : (s β’ p).natDegree < p.natDegree.succ := (natDegree_smul_le _ _).trans_lt A
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
xβ : S
g : R β+* S
p : R[X]
x : S
s : R
A : natDegree p < Nat.succ (natDegree p)
B : natDegree (s β’ p) < Nat.succ (natDegree p)
β’ evalβ g x (s β’ p) = βg s * evalβ g x p
[PROOFSTEP]
rw [evalβ_eq_sum, evalβ_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
xβ : S
g : R β+* S
p : R[X]
x : S
s : R
A : natDegree p < Nat.succ (natDegree p)
B : natDegree (s β’ p) < Nat.succ (natDegree p)
β’ β a in range (Nat.succ (natDegree p)), βg (coeff (s β’ p) a) * x ^ a =
βg s * β a in range (Nat.succ (natDegree p)), βg (coeff p a) * x ^ a
[PROOFSTEP]
simp [mul_sum, mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
xβ : S
g : R β+* S
p : R[X]
x : S
s : R
A : natDegree p < Nat.succ (natDegree p)
B : natDegree (s β’ p) < Nat.succ (natDegree p)
β’ β (n : β), βg 0 * x ^ n = 0
[PROOFSTEP]
simp [mul_sum, mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
xβ : S
g : R β+* S
p : R[X]
x : S
s : R
A : natDegree p < Nat.succ (natDegree p)
B : natDegree (s β’ p) < Nat.succ (natDegree p)
β’ β (n : β), βg 0 * x ^ n = 0
[PROOFSTEP]
simp [mul_sum, mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
f : R β+* S
x : S
p q : R[X]
hp : evalβ C X p = p
hq : evalβ C X q = q
β’ evalβ C X (p + q) = p + q
[PROOFSTEP]
simp [hp, hq]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
xβ : S
n : β
x : R
β’ evalβ C X (β(monomial n) x) = β(monomial n) x
[PROOFSTEP]
rw [evalβ_monomial, β smul_X_eq_monomial, C_mul']
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
β’ evalβ f x βn = βn
[PROOFSTEP]
induction' n with n ih
[GOAL]
case zero
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x βNat.zero = βNat.zero
[PROOFSTEP]
simp only [evalβ_zero, Nat.cast_zero, Nat.zero_eq]
[GOAL]
case succ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
ih : evalβ f x βn = βn
β’ evalβ f x β(Nat.succ n) = β(Nat.succ n)
[PROOFSTEP]
rw [n.cast_succ, evalβ_add, ih, evalβ_one, n.cast_succ]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
xβ : S
instβ : Semiring T
p : T[X]
g : β β T β R[X]
x : S
β’ evalβ f x (sum p g) = sum p fun n a => evalβ f x (g n a)
[PROOFSTEP]
let T : R[X] β+ S :=
{ toFun := evalβ f x
map_zero' := evalβ_zero _ _
map_add' := fun p q => evalβ_add _ _ }
[GOAL]
R : Type u
S : Type v
Tβ : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
xβ : S
instβ : Semiring Tβ
p : Tβ[X]
g : β β Tβ β R[X]
x : S
T : R[X] β+ S :=
{ toZeroHom := { toFun := evalβ f x, map_zero' := (_ : evalβ f x 0 = 0) },
map_add' := (_ : β (p q : R[X]), evalβ f x (p + q) = evalβ f x p + evalβ f x q) }
β’ evalβ f x (sum p g) = sum p fun n a => evalβ f x (g n a)
[PROOFSTEP]
have A : β y, evalβ f x y = T y := fun y => rfl
[GOAL]
R : Type u
S : Type v
Tβ : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
xβ : S
instβ : Semiring Tβ
p : Tβ[X]
g : β β Tβ β R[X]
x : S
T : R[X] β+ S :=
{ toZeroHom := { toFun := evalβ f x, map_zero' := (_ : evalβ f x 0 = 0) },
map_add' := (_ : β (p q : R[X]), evalβ f x (p + q) = evalβ f x p + evalβ f x q) }
A : β (y : R[X]), evalβ f x y = βT y
β’ evalβ f x (sum p g) = sum p fun n a => evalβ f x (g n a)
[PROOFSTEP]
simp only [A]
[GOAL]
R : Type u
S : Type v
Tβ : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
xβ : S
instβ : Semiring Tβ
p : Tβ[X]
g : β β Tβ β R[X]
x : S
T : R[X] β+ S :=
{ toZeroHom := { toFun := evalβ f x, map_zero' := (_ : evalβ f x 0 = 0) },
map_add' := (_ : β (p q : R[X]), evalβ f x (p + q) = evalβ f x p + evalβ f x q) }
A : β (y : R[X]), evalβ f x y = βT y
β’ β{ toZeroHom := { toFun := evalβ f x, map_zero' := (_ : evalβ f x 0 = 0) },
map_add' := (_ : β (p q : R[X]), evalβ f x (p + q) = evalβ f x p + evalβ f x q) }
(sum p g) =
sum p fun n a =>
β{ toZeroHom := { toFun := evalβ f x, map_zero' := (_ : evalβ f x 0 = 0) },
map_add' := (_ : β (p q : R[X]), evalβ f x (p + q) = evalβ f x p + evalβ f x q) }
(g n a)
[PROOFSTEP]
rw [sum, T.map_sum, sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
fβ : R β+* S
xβ : S
instβ : Semiring T
f : R β+* S
x : S
p : AddMonoidAlgebra R β
β’ evalβ f x { toFinsupp := p } = β(liftNC βf β(β(powersHom S) x)) p
[PROOFSTEP]
simp only [evalβ_eq_sum, sum, toFinsupp_sum, support, coeff]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
fβ : R β+* S
xβ : S
instβ : Semiring T
f : R β+* S
x : S
p : AddMonoidAlgebra R β
β’ β x_1 in p.support, βf (βp x_1) * x ^ x_1 = β(liftNC βf β(β(powersHom S) x)) p
[PROOFSTEP]
rfl
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
hf : β (k : β), Commute (βf (coeff q k)) x
β’ evalβ f x (p * q) = evalβ f x p * evalβ f x q
[PROOFSTEP]
rcases p with β¨pβ©
[GOAL]
case ofFinsupp
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
hf : β (k : β), Commute (βf (coeff q k)) x
p : AddMonoidAlgebra R β
β’ evalβ f x ({ toFinsupp := p } * q) = evalβ f x { toFinsupp := p } * evalβ f x q
[PROOFSTEP]
rcases q with β¨qβ©
[GOAL]
case ofFinsupp.ofFinsupp
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
p q : AddMonoidAlgebra R β
hf : β (k : β), Commute (βf (coeff { toFinsupp := q } k)) x
β’ evalβ f x ({ toFinsupp := p } * { toFinsupp := q }) = evalβ f x { toFinsupp := p } * evalβ f x { toFinsupp := q }
[PROOFSTEP]
simp only [coeff] at hf
[GOAL]
case ofFinsupp.ofFinsupp
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
p q : AddMonoidAlgebra R β
hf : β (k : β), Commute (βf (βq k)) x
β’ evalβ f x ({ toFinsupp := p } * { toFinsupp := q }) = evalβ f x { toFinsupp := p } * evalβ f x { toFinsupp := q }
[PROOFSTEP]
simp only [β ofFinsupp_mul, evalβ_ofFinsupp]
[GOAL]
case ofFinsupp.ofFinsupp
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
p q : AddMonoidAlgebra R β
hf : β (k : β), Commute (βf (βq k)) x
β’ β(liftNC βf β(β(powersHom S) x)) (p * q) = β(liftNC βf β(β(powersHom S) x)) p * β(liftNC βf β(β(powersHom S) x)) q
[PROOFSTEP]
exact liftNC_mul _ _ p q fun {k n} _hn => (hf k).pow_right n
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
β’ evalβ f x (p * X) = evalβ f x p * x
[PROOFSTEP]
refine' _root_.trans (evalβ_mul_noncomm _ _ fun k => _) (by rw [evalβ_X])
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
β’ evalβ f x p * evalβ f x X = evalβ f x p * x
[PROOFSTEP]
rw [evalβ_X]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
k : β
β’ Commute (βf (coeff X k)) x
[PROOFSTEP]
rcases em (k = 1) with (rfl | hk)
[GOAL]
case inl
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
β’ Commute (βf (coeff X 1)) x
[PROOFSTEP]
simp
[GOAL]
case inr
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
k : β
hk : Β¬k = 1
β’ Commute (βf (coeff X k)) x
[PROOFSTEP]
simp [coeff_X_of_ne_one hk]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
β’ evalβ f x (X * p) = evalβ f x p * x
[PROOFSTEP]
rw [X_mul, evalβ_mul_X]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
h : Commute (βf a) x
β’ evalβ f x (p * βC a) = evalβ f x p * βf a
[PROOFSTEP]
rw [evalβ_mul_noncomm, evalβ_C]
[GOAL]
case hf
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
h : Commute (βf a) x
β’ β (k : β), Commute (βf (coeff (βC a) k)) x
[PROOFSTEP]
intro k
[GOAL]
case hf
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
h : Commute (βf a) x
k : β
β’ Commute (βf (coeff (βC a) k)) x
[PROOFSTEP]
by_cases hk : k = 0
[GOAL]
case pos
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
h : Commute (βf a) x
k : β
hk : k = 0
β’ Commute (βf (coeff (βC a) k)) x
[PROOFSTEP]
simp only [hk, h, coeff_C_zero, coeff_C_ne_zero]
[GOAL]
case neg
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
h : Commute (βf a) x
k : β
hk : Β¬k = 0
β’ Commute (βf (coeff (βC a) k)) x
[PROOFSTEP]
simp only [coeff_C_ne_zero hk, RingHom.map_zero, Commute.zero_left]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
ps : List R[X]
hf : β (p : R[X]), p β ps β β (k : β), Commute (βf (coeff p k)) x
β’ evalβ f x (List.prod ps) = List.prod (List.map (evalβ f x) ps)
[PROOFSTEP]
induction' ps using List.reverseRecOn with ps p ihp
[GOAL]
case H0
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
ps : List R[X]
hfβ : β (p : R[X]), p β ps β β (k : β), Commute (βf (coeff p k)) x
hf : β (p : R[X]), p β [] β β (k : β), Commute (βf (coeff p k)) x
β’ evalβ f x (List.prod []) = List.prod (List.map (evalβ f x) [])
[PROOFSTEP]
simp
[GOAL]
case H1
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
psβ : List R[X]
hfβ : β (p : R[X]), p β psβ β β (k : β), Commute (βf (coeff p k)) x
ps : List R[X]
p : R[X]
ihp :
(β (p : R[X]), p β ps β β (k : β), Commute (βf (coeff p k)) x) β
evalβ f x (List.prod ps) = List.prod (List.map (evalβ f x) ps)
hf : β (p_1 : R[X]), p_1 β ps ++ [p] β β (k : β), Commute (βf (coeff p_1 k)) x
β’ evalβ f x (List.prod (ps ++ [p])) = List.prod (List.map (evalβ f x) (ps ++ [p]))
[PROOFSTEP]
simp only [List.forall_mem_append, List.forall_mem_singleton] at hf
[GOAL]
case H1
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
x : S
instβ : Semiring T
psβ : List R[X]
hfβ : β (p : R[X]), p β psβ β β (k : β), Commute (βf (coeff p k)) x
ps : List R[X]
p : R[X]
ihp :
(β (p : R[X]), p β ps β β (k : β), Commute (βf (coeff p k)) x) β
evalβ f x (List.prod ps) = List.prod (List.map (evalβ f x) ps)
hf : (β (x_1 : R[X]), x_1 β ps β β (k : β), Commute (βf (coeff x_1 k)) x) β§ β (k : β), Commute (βf (coeff p k)) x
β’ evalβ f x (List.prod (ps ++ [p])) = List.prod (List.map (evalβ f x) (ps ++ [p]))
[PROOFSTEP]
simp [evalβ_mul_noncomm _ _ hf.2, ihp hf.1]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ (fun i => evalβ f x (β(monomial i) (coeff p i))) = fun i => βf (coeff p i) * x ^ i
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ : R β+* S
xβ : S
f : R β+* S
p : R[X]
n : β
hn : natDegree p < n
x : S
β’ evalβ f x p = β i in range n, βf (coeff p i) * x ^ i
[PROOFSTEP]
rw [evalβ_eq_sum, p.sum_over_range' _ _ hn]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ : R β+* S
xβ : S
f : R β+* S
p : R[X]
n : β
hn : natDegree p < n
x : S
β’ β (n : β), βf 0 * x ^ n = 0
[PROOFSTEP]
intro i
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ : R β+* S
xβ : S
f : R β+* S
p : R[X]
n : β
hn : natDegree p < n
x : S
i : β
β’ βf 0 * x ^ i = 0
[PROOFSTEP]
rw [f.map_zero, zero_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p qβ r : R[X]
instβ : CommSemiring S
f : R β+* S
x : S
q : R[X]
hp : evalβ f x p = 0
β’ evalβ f x (p * q) = 0
[PROOFSTEP]
rw [evalβ_mul f x]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p qβ r : R[X]
instβ : CommSemiring S
f : R β+* S
x : S
q : R[X]
hp : evalβ f x p = 0
β’ evalβ f x p * evalβ f x q = 0
[PROOFSTEP]
exact mul_eq_zero_of_left hp (q.evalβ f x)
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : CommSemiring S
f : R β+* S
x : S
p : R[X]
hq : evalβ f x q = 0
β’ evalβ f x (p * q) = 0
[PROOFSTEP]
rw [evalβ_mul f x]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : CommSemiring S
f : R β+* S
x : S
p : R[X]
hq : evalβ f x q = 0
β’ evalβ f x p * evalβ f x q = 0
[PROOFSTEP]
exact mul_eq_zero_of_right (p.evalβ f x) hq
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
β’ eval x p = sum p fun e a => a * x ^ e
[PROOFSTEP]
rw [eval, evalβ_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
β’ (sum p fun e a => β(RingHom.id R) a * x ^ e) = sum p fun e a => a * x ^ e
[PROOFSTEP]
rfl
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
xβ : R
p : R[X]
x : R
β’ eval x p = β i in range (natDegree p + 1), coeff p i * x ^ i
[PROOFSTEP]
rw [eval_eq_sum, sum_over_range]
[GOAL]
case h
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
xβ : R
p : R[X]
x : R
β’ β (n : β), 0 * x ^ n = 0
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβ : Semiring R
pβ q r : R[X]
xβ : R
p : R[X]
n : β
hn : natDegree p < n
x : R
β’ eval x p = β i in range n, coeff p i * x ^ i
[PROOFSTEP]
rw [eval_eq_sum, p.sum_over_range' _ _ hn]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβ : Semiring R
pβ q r : R[X]
xβ : R
p : R[X]
n : β
hn : natDegree p < n
x : R
β’ β (n : β), 0 * x ^ n = 0
[PROOFSTEP]
simp
[GOAL]
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q rβ : R[X]
x : R
S : Type u_1
instβ : Semiring S
f : R β+* S
r : R
β’ evalβ f (βf r) p = βf (eval r p)
[PROOFSTEP]
rw [evalβ_eq_sum, eval_eq_sum, sum, sum, f.map_sum]
[GOAL]
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q rβ : R[X]
x : R
S : Type u_1
instβ : Semiring S
f : R β+* S
r : R
β’ β n in support p, βf (coeff p n) * βf r ^ n = β x in support p, βf (coeff p x * r ^ x)
[PROOFSTEP]
simp only [f.map_mul, f.map_pow]
[GOAL]
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
S : Type u_1
instβ : Semiring S
f : R β+* S
β’ evalβ f 1 p = βf (eval 1 p)
[PROOFSTEP]
convert evalβ_at_apply (p := p) f 1
[GOAL]
case h.e'_2.h.e'_6
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
S : Type u_1
instβ : Semiring S
f : R β+* S
β’ 1 = βf 1
[PROOFSTEP]
simp
[GOAL]
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
S : Type u_1
instβ : Semiring S
f : R β+* S
n : β
β’ evalβ f (βn) p = βf (eval (βn) p)
[PROOFSTEP]
convert evalβ_at_apply (p := p) f n
[GOAL]
case h.e'_2.h.e'_6
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
S : Type u_1
instβ : Semiring S
f : R β+* S
n : β
β’ βn = βf βn
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβ : Semiring R
p q r : R[X]
x : R
n : β
β’ eval x βn = βn
[PROOFSTEP]
simp only [β C_eq_nat_cast, eval_C]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ³ : Semiring R
pβ q r : R[X]
xβ : R
instβΒ² : Monoid S
instβΒΉ : DistribMulAction S R
instβ : IsScalarTower S R R
s : S
p : R[X]
x : R
β’ eval x (s β’ p) = s β’ eval x p
[PROOFSTEP]
rw [β smul_one_smul R s p, eval, evalβ_smul, RingHom.id_apply, smul_one_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
β’ eval x (βC a * p) = a * eval x p
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q ph qh => simp only [mul_add, eval_add, ph, qh]
| h_monomial n b => simp only [mul_assoc, C_mul_monomial, eval_monomial]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
β’ eval x (βC a * p) = a * eval x p
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q ph qh => simp only [mul_add, eval_add, ph, qh]
| h_monomial n b => simp only [mul_assoc, C_mul_monomial, eval_monomial]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r : R[X]
x : R
p q : R[X]
ph : eval x (βC a * p) = a * eval x p
qh : eval x (βC a * q) = a * eval x q
β’ eval x (βC a * (p + q)) = a * eval x (p + q)
[PROOFSTEP]
| h_add p q ph qh => simp only [mul_add, eval_add, ph, qh]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r : R[X]
x : R
p q : R[X]
ph : eval x (βC a * p) = a * eval x p
qh : eval x (βC a * q) = a * eval x q
β’ eval x (βC a * (p + q)) = a * eval x (p + q)
[PROOFSTEP]
simp only [mul_add, eval_add, ph, qh]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m nβ : β
instβ : Semiring R
p q r : R[X]
x : R
n : β
b : R
β’ eval x (βC a * β(monomial n) b) = a * eval x (β(monomial n) b)
[PROOFSTEP]
| h_monomial n b => simp only [mul_assoc, C_mul_monomial, eval_monomial]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m nβ : β
instβ : Semiring R
p q r : R[X]
x : R
n : β
b : R
β’ eval x (βC a * β(monomial n) b) = a * eval x (β(monomial n) b)
[PROOFSTEP]
simp only [mul_assoc, C_mul_monomial, eval_monomial]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
β’ eval (1 + y) (β(monomial d) (βd + 1)) - eval y (β(monomial d) (βd + 1)) =
β x_1 in range (d + 1), β(Nat.choose (d + 1) x_1) * (βx_1 * y ^ (x_1 - 1))
[PROOFSTEP]
have cast_succ : (d + 1 : S) = ((d.succ : β) : S) := by simp only [Nat.cast_succ]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
β’ βd + 1 = β(Nat.succ d)
[PROOFSTEP]
simp only [Nat.cast_succ]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
β’ eval (1 + y) (β(monomial d) (βd + 1)) - eval y (β(monomial d) (βd + 1)) =
β x_1 in range (d + 1), β(Nat.choose (d + 1) x_1) * (βx_1 * y ^ (x_1 - 1))
[PROOFSTEP]
rw [cast_succ, eval_monomial, eval_monomial, add_comm, add_pow]
-- Porting note: `apply_congr` hadn't been ported yet, so `congr` & `ext` is used.
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
β’ β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m) - β(Nat.succ d) * y ^ d =
β x_1 in range (d + 1), β(Nat.choose (d + 1) x_1) * (βx_1 * y ^ (x_1 - 1))
[PROOFSTEP]
conv_lhs =>
congr
Β· congr
Β·skip
Β· congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m) - β(Nat.succ d) * y ^ d
[PROOFSTEP]
congr
Β· congr
Β·skip
Β· congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m) - β(Nat.succ d) * y ^ d
[PROOFSTEP]
congr
Β· congr
Β·skip
Β· congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m) - β(Nat.succ d) * y ^ d
[PROOFSTEP]
congr
[GOAL]
case a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
case a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * y ^ d
[PROOFSTEP]
Β· congr
Β·skip
Β· congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
congr
Β·skip
Β· congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
congr
Β·skip
Β· congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d) * β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
congr
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d)
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
Β·skip
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d)
[PROOFSTEP]
skip
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d)
[PROOFSTEP]
skip
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β(Nat.succ d)
[PROOFSTEP]
skip
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
Β· congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
congr
Β·skip
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| β m in range (d + 1), y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
congr
[GOAL]
case a.a.s
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| range (d + 1)
case a.a.f
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| fun m => y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
Β·skip
[GOAL]
case a.a.s
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| range (d + 1)
[PROOFSTEP]
skip
[GOAL]
case a.a.s
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| range (d + 1)
[PROOFSTEP]
skip
[GOAL]
case a.a.s
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| range (d + 1)
[PROOFSTEP]
skip
[GOAL]
case a.a.f
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| fun m => y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
Β· ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a.a.f
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| fun m => y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a.a.f
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| fun m => y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
ext
rw [one_pow, mul_one, mul_comm]
[GOAL]
case a.a.f
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
| fun m => y ^ m * 1 ^ (d - m) * β(Nat.choose d m)
[PROOFSTEP]
ext
[GOAL]
case a.a.f.h
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
xβ : β
| y ^ xβ * 1 ^ (d - xβ) * β(Nat.choose d xβ)
[PROOFSTEP]
rw [one_pow, mul_one, mul_comm]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
β’ β(Nat.succ d) * β x in range (d + 1), β(Nat.choose d x) * y ^ x - β(Nat.succ d) * y ^ d =
β x_1 in range (d + 1), β(Nat.choose (d + 1) x_1) * (βx_1 * y ^ (x_1 - 1))
[PROOFSTEP]
rw [sum_range_succ, mul_add, Nat.choose_self, Nat.cast_one, one_mul, add_sub_cancel, mul_sum, sum_range_succ',
Nat.cast_zero, zero_mul, mul_zero, add_zero]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
y : S
cast_succ : βd + 1 = β(Nat.succ d)
β’ β x in range d, β(Nat.succ d) * (β(Nat.choose d x) * y ^ x) =
β k in range d, β(Nat.choose (d + 1) (k + 1)) * (β(k + 1) * y ^ (k + 1 - 1))
[PROOFSTEP]
refine sum_congr rfl fun y _hy => ?_
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : CommRing S
d : β
yβ : S
cast_succ : βd + 1 = β(Nat.succ d)
y : β
_hy : y β range d
β’ β(Nat.succ d) * (β(Nat.choose d y) * yβ ^ y) = β(Nat.choose (d + 1) (y + 1)) * (β(y + 1) * yβ ^ (y + 1 - 1))
[PROOFSTEP]
rw [β mul_assoc, β mul_assoc, β Nat.cast_mul, Nat.succ_mul_choose_eq, Nat.cast_mul, Nat.add_sub_cancel]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβ : Semiring R
p q r : R[X]
x : R
n : β
β’ eval x (βn * p) = βn * eval x p
[PROOFSTEP]
rw [β C_eq_nat_cast, eval_C_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
β’ eval x (p * X) = eval x p * x
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q ph qh => simp only [add_mul, eval_add, ph, qh]
| h_monomial n a =>
simp only [β monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ', mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
β’ eval x (p * X) = eval x p * x
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q ph qh => simp only [add_mul, eval_add, ph, qh]
| h_monomial n a =>
simp only [β monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ', mul_assoc]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r : R[X]
x : R
p q : R[X]
ph : eval x (p * X) = eval x p * x
qh : eval x (q * X) = eval x q * x
β’ eval x ((p + q) * X) = eval x (p + q) * x
[PROOFSTEP]
| h_add p q ph qh => simp only [add_mul, eval_add, ph, qh]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r : R[X]
x : R
p q : R[X]
ph : eval x (p * X) = eval x p * x
qh : eval x (q * X) = eval x q * x
β’ eval x ((p + q) * X) = eval x (p + q) * x
[PROOFSTEP]
simp only [add_mul, eval_add, ph, qh]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m nβ : β
instβ : Semiring R
p q r : R[X]
x : R
n : β
a : R
β’ eval x (β(monomial n) a * X) = eval x (β(monomial n) a) * x
[PROOFSTEP]
| h_monomial n a =>
simp only [β monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ', mul_assoc]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m nβ : β
instβ : Semiring R
p q r : R[X]
x : R
n : β
a : R
β’ eval x (β(monomial n) a * X) = eval x (β(monomial n) a) * x
[PROOFSTEP]
simp only [β monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ', mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
k : β
β’ eval x (p * X ^ k) = eval x p * x ^ k
[PROOFSTEP]
induction' k with k ih
[GOAL]
case zero
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
β’ eval x (p * X ^ Nat.zero) = eval x p * x ^ Nat.zero
[PROOFSTEP]
simp
[GOAL]
case succ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
x : R
k : β
ih : eval x (p * X ^ k) = eval x p * x ^ k
β’ eval x (p * X ^ Nat.succ k) = eval x p * x ^ Nat.succ k
[PROOFSTEP]
simp [pow_succ', β mul_assoc, ih]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : DecidableEq R
β’ Decidable (IsRoot p a)
[PROOFSTEP]
unfold IsRoot
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
x : R
instβ : DecidableEq R
β’ Decidable (eval a p = 0)
[PROOFSTEP]
infer_instance
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
x : R
p : R[X]
β’ coeff p 0 = coeff p 0 * 0 ^ 0
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
x : R
p : R[X]
β’ coeff p 0 * 0 ^ 0 = eval 0 p
[PROOFSTEP]
symm
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
x : R
p : R[X]
β’ eval 0 p = coeff p 0 * 0 ^ 0
[PROOFSTEP]
rw [eval_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
x : R
p : R[X]
β’ (sum p fun e a => a * 0 ^ e) = coeff p 0 * 0 ^ 0
[PROOFSTEP]
exact Finset.sum_eq_single _ (fun b _ hb => by simp [zero_pow (Nat.pos_of_ne_zero hb)]) (by simp)
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m n : β
instβ : Semiring R
pβ q r : R[X]
x : R
p : R[X]
b : β
xβ : b β support p
hb : b β 0
β’ (fun e a => a * 0 ^ e) b (coeff p b) = 0
[PROOFSTEP]
simp [zero_pow (Nat.pos_of_ne_zero hb)]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
x : R
p : R[X]
β’ Β¬0 β support p β (fun e a => a * 0 ^ e) 0 (coeff p 0) = 0
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ q r : R[X]
x : R
p : R[X]
hp : coeff p 0 = 0
β’ IsRoot p 0
[PROOFSTEP]
rwa [coeff_zero_eq_eval_zero] at hp
[GOAL]
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
pβ qβ r : Rβ[X]
xβ : Rβ
R : Type u_1
instβ : CommSemiring R
p q : R[X]
x : R
h : IsRoot p x
hpq : p β£ q
β’ IsRoot q x
[PROOFSTEP]
rwa [IsRoot, eval, evalβ_eq_zero_of_dvd_of_evalβ_eq_zero _ _ hpq]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m n : β
instβ : Semiring R
p q rβ : R[X]
x r a : R
hr : r β 0
β’ Β¬IsRoot (βC r) a
[PROOFSTEP]
simpa using hr
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp p q = sum p fun e a => βC a * q ^ e
[PROOFSTEP]
rw [comp, evalβ_eq_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp p X = p
[PROOFSTEP]
simp only [comp, evalβ_def, C_mul_X_pow_eq_monomial]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ (sum p fun e a => β(monomial e) a) = p
[PROOFSTEP]
exact sum_monomial_eq _
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp p (βC a) = βC (eval a p)
[PROOFSTEP]
simp [comp, (C : R β+* _).map_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβ : Semiring R
p q r : R[X]
n : β
β’ comp (βn) p = βn
[PROOFSTEP]
rw [β C_eq_nat_cast, C_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp p 0 = βC (eval 0 p)
[PROOFSTEP]
rw [β C_0, comp_C]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp 0 p = 0
[PROOFSTEP]
rw [β C_0, C_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp p 1 = βC (eval 1 p)
[PROOFSTEP]
rw [β C_1, comp_C]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp 1 p = 1
[PROOFSTEP]
rw [β C_1, C_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (p * X) r = comp p r * r
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, add_mul, add_comp]
| h_monomial n b => simp only [pow_succ', mul_assoc, monomial_mul_X, monomial_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (p * X) r = comp p r * r
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, add_mul, add_comp]
| h_monomial n b => simp only [pow_succ', mul_assoc, monomial_mul_X, monomial_comp]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r p q : R[X]
hp : comp (p * X) r = comp p r * r
hq : comp (q * X) r = comp q r * r
β’ comp ((p + q) * X) r = comp (p + q) r * r
[PROOFSTEP]
| h_add p q hp hq => simp only [hp, hq, add_mul, add_comp]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r p q : R[X]
hp : comp (p * X) r = comp p r * r
hq : comp (q * X) r = comp q r * r
β’ comp ((p + q) * X) r = comp (p + q) r * r
[PROOFSTEP]
simp only [hp, hq, add_mul, add_comp]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m nβ : β
instβ : Semiring R
p q r : R[X]
n : β
b : R
β’ comp (β(monomial n) b * X) r = comp (β(monomial n) b) r * r
[PROOFSTEP]
| h_monomial n b => simp only [pow_succ', mul_assoc, monomial_mul_X, monomial_comp]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m nβ : β
instβ : Semiring R
p q r : R[X]
n : β
b : R
β’ comp (β(monomial n) b * X) r = comp (β(monomial n) b) r * r
[PROOFSTEP]
simp only [pow_succ', mul_assoc, monomial_mul_X, monomial_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
k : β
β’ comp (X ^ k) p = p ^ k
[PROOFSTEP]
induction' k with k ih
[GOAL]
case zero
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (X ^ Nat.zero) p = p ^ Nat.zero
[PROOFSTEP]
simp
[GOAL]
case succ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
k : β
ih : comp (X ^ k) p = p ^ k
β’ comp (X ^ Nat.succ k) p = p ^ Nat.succ k
[PROOFSTEP]
simp [pow_succ', mul_X_comp, ih]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
k : β
β’ comp (p * X ^ k) r = comp p r * r ^ k
[PROOFSTEP]
induction' k with k ih
[GOAL]
case zero
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (p * X ^ Nat.zero) r = comp p r * r ^ Nat.zero
[PROOFSTEP]
simp
[GOAL]
case succ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
k : β
ih : comp (p * X ^ k) r = comp p r * r ^ k
β’ comp (p * X ^ Nat.succ k) r = comp p r * r ^ Nat.succ k
[PROOFSTEP]
simp [ih, pow_succ', β mul_assoc, mul_X_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (βC a * p) r = βC a * comp p r
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp [hp, hq, mul_add]
| h_monomial n b => simp [mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (βC a * p) r = βC a * comp p r
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp [hp, hq, mul_add]
| h_monomial n b => simp [mul_assoc]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r p q : R[X]
hp : comp (βC a * p) r = βC a * comp p r
hq : comp (βC a * q) r = βC a * comp q r
β’ comp (βC a * (p + q)) r = βC a * comp (p + q) r
[PROOFSTEP]
| h_add p q hp hq => simp [hp, hq, mul_add]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
pβ qβ r p q : R[X]
hp : comp (βC a * p) r = βC a * comp p r
hq : comp (βC a * q) r = βC a * comp q r
β’ comp (βC a * (p + q)) r = βC a * comp (p + q) r
[PROOFSTEP]
simp [hp, hq, mul_add]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m nβ : β
instβ : Semiring R
p q r : R[X]
n : β
b : R
β’ comp (βC a * β(monomial n) b) r = βC a * comp (β(monomial n) b) r
[PROOFSTEP]
| h_monomial n b => simp [mul_assoc]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m nβ : β
instβ : Semiring R
p q r : R[X]
n : β
b : R
β’ comp (βC a * β(monomial n) b) r = βC a * comp (β(monomial n) b) r
[PROOFSTEP]
simp [mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβ : Semiring R
p q r : R[X]
n : β
β’ comp (βn * p) r = βn * comp p r
[PROOFSTEP]
rw [β C_eq_nat_cast, C_mul_comp, C_eq_nat_cast]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (bit0 p) q = bit0 (comp p q)
[PROOFSTEP]
simp only [bit0, add_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
β’ comp (bit1 p) q = bit1 (comp p q)
[PROOFSTEP]
simp only [bit1, add_comp, bit0_comp, one_comp]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ³ : Semiring R
pβ qβ r : R[X]
instβΒ² : Monoid S
instβΒΉ : DistribMulAction S R
instβ : IsScalarTower S R R
s : S
p q : R[X]
β’ comp (s β’ p) q = s β’ comp p q
[PROOFSTEP]
rw [β smul_one_smul R s p, comp, comp, evalβ_smul, β smul_eq_C_mul, smul_assoc, one_smul]
[GOAL]
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
p q r : Rβ[X]
R : Type u_1
instβ : CommSemiring R
Ο Ο Ο : R[X]
β’ comp (comp Ο Ο) Ο = comp Ο (comp Ο Ο)
[PROOFSTEP]
refine Polynomial.induction_on Ο ?_ ?_ ?_
[GOAL]
case refine_1
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
p q r : Rβ[X]
R : Type u_1
instβ : CommSemiring R
Ο Ο Ο : R[X]
β’ β (a : R), comp (comp (βC a) Ο) Ο = comp (βC a) (comp Ο Ο)
[PROOFSTEP]
intros
[GOAL]
case refine_1
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
p q r : Rβ[X]
R : Type u_1
instβ : CommSemiring R
Ο Ο Ο : R[X]
aβ : R
β’ comp (comp (βC aβ) Ο) Ο = comp (βC aβ) (comp Ο Ο)
[PROOFSTEP]
simp_all only [add_comp, mul_comp, C_comp, X_comp, pow_succ', β mul_assoc]
[GOAL]
case refine_2
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
p q r : Rβ[X]
R : Type u_1
instβ : CommSemiring R
Ο Ο Ο : R[X]
β’ β (p q : R[X]),
comp (comp p Ο) Ο = comp p (comp Ο Ο) β
comp (comp q Ο) Ο = comp q (comp Ο Ο) β comp (comp (p + q) Ο) Ο = comp (p + q) (comp Ο Ο)
[PROOFSTEP]
intros
[GOAL]
case refine_2
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
p q r : Rβ[X]
R : Type u_1
instβ : CommSemiring R
Ο Ο Ο pβ qβ : R[X]
aβΒΉ : comp (comp pβ Ο) Ο = comp pβ (comp Ο Ο)
aβ : comp (comp qβ Ο) Ο = comp qβ (comp Ο Ο)
β’ comp (comp (pβ + qβ) Ο) Ο = comp (pβ + qβ) (comp Ο Ο)
[PROOFSTEP]
simp_all only [add_comp, mul_comp, C_comp, X_comp, pow_succ', β mul_assoc]
[GOAL]
case refine_3
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
p q r : Rβ[X]
R : Type u_1
instβ : CommSemiring R
Ο Ο Ο : R[X]
β’ β (n : β) (a : R),
comp (comp (βC a * X ^ n) Ο) Ο = comp (βC a * X ^ n) (comp Ο Ο) β
comp (comp (βC a * X ^ (n + 1)) Ο) Ο = comp (βC a * X ^ (n + 1)) (comp Ο Ο)
[PROOFSTEP]
intros
[GOAL]
case refine_3
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒΉ : Semiring Rβ
p q r : Rβ[X]
R : Type u_1
instβ : CommSemiring R
Ο Ο Ο : R[X]
nβ : β
aβΒΉ : R
aβ : comp (comp (βC aβΒΉ * X ^ nβ) Ο) Ο = comp (βC aβΒΉ * X ^ nβ) (comp Ο Ο)
β’ comp (comp (βC aβΒΉ * X ^ (nβ + 1)) Ο) Ο = comp (βC aβΒΉ * X ^ (nβ + 1)) (comp Ο Ο)
[PROOFSTEP]
simp_all only [add_comp, mul_comp, C_comp, X_comp, pow_succ', β mul_assoc]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ coeff (comp p q) (natDegree p * natDegree q) = leadingCoeff p * leadingCoeff q ^ natDegree p
[PROOFSTEP]
rw [comp, evalβ_def, coeff_sum]
-- Porting note: `convert` β `refine`
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ (sum p fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) = leadingCoeff p * leadingCoeff q ^ natDegree p
[PROOFSTEP]
refine Eq.trans (Finset.sum_eq_single p.natDegree ?hβ ?hβ) ?hβ
[GOAL]
case hβ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ β (b : β),
b β support p β b β natDegree p β (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) b (coeff p b) = 0
case hβ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ Β¬natDegree p β support p β
(fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) = 0
case hβ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) =
leadingCoeff p * leadingCoeff q ^ natDegree p
[PROOFSTEP]
case hβ => simp only [coeff_natDegree, coeff_C_mul, coeff_pow_mul_natDegree]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) =
leadingCoeff p * leadingCoeff q ^ natDegree p
[PROOFSTEP]
case hβ => simp only [coeff_natDegree, coeff_C_mul, coeff_pow_mul_natDegree]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) =
leadingCoeff p * leadingCoeff q ^ natDegree p
[PROOFSTEP]
simp only [coeff_natDegree, coeff_C_mul, coeff_pow_mul_natDegree]
[GOAL]
case hβ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ β (b : β),
b β support p β b β natDegree p β (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) b (coeff p b) = 0
case hβ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ Β¬natDegree p β support p β
(fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) = 0
[PROOFSTEP]
case hβ =>
intro b hbs hbp
refine' coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt _)
rw [natDegree_C, zero_add]
refine' natDegree_pow_le.trans_lt ((mul_lt_mul_right (pos_iff_ne_zero.mpr hqd0)).mpr _)
exact lt_of_le_of_ne (le_natDegree_of_mem_supp _ hbs) hbp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ β (b : β),
b β support p β b β natDegree p β (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) b (coeff p b) = 0
[PROOFSTEP]
case hβ =>
intro b hbs hbp
refine' coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt _)
rw [natDegree_C, zero_add]
refine' natDegree_pow_le.trans_lt ((mul_lt_mul_right (pos_iff_ne_zero.mpr hqd0)).mpr _)
exact lt_of_le_of_ne (le_natDegree_of_mem_supp _ hbs) hbp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ β (b : β),
b β support p β b β natDegree p β (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) b (coeff p b) = 0
[PROOFSTEP]
intro b hbs hbp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
b : β
hbs : b β support p
hbp : b β natDegree p
β’ (fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) b (coeff p b) = 0
[PROOFSTEP]
refine' coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt _)
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
b : β
hbs : b β support p
hbp : b β natDegree p
β’ natDegree (βC (coeff p b)) + natDegree (q ^ b) < natDegree p * natDegree q
[PROOFSTEP]
rw [natDegree_C, zero_add]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
b : β
hbs : b β support p
hbp : b β natDegree p
β’ natDegree (q ^ b) < natDegree p * natDegree q
[PROOFSTEP]
refine' natDegree_pow_le.trans_lt ((mul_lt_mul_right (pos_iff_ne_zero.mpr hqd0)).mpr _)
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a bβ : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
b : β
hbs : b β support p
hbp : b β natDegree p
β’ b < natDegree p
[PROOFSTEP]
exact lt_of_le_of_ne (le_natDegree_of_mem_supp _ hbs) hbp
[GOAL]
case hβ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ Β¬natDegree p β support p β
(fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) = 0
[PROOFSTEP]
case hβ => simp (config := { contextual := true })
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ Β¬natDegree p β support p β
(fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) = 0
[PROOFSTEP]
case hβ => simp (config := { contextual := true })
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Semiring R
p q r : R[X]
hqd0 : natDegree q β 0
β’ Β¬natDegree p β support p β
(fun a b => coeff (βC b * q ^ a) (natDegree p * natDegree q)) (natDegree p) (coeff p (natDegree p)) = 0
[PROOFSTEP]
simp (config := { contextual := true })
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
a : R
β’ map f (β(monomial n) a) = β(monomial n) (βf a)
[PROOFSTEP]
dsimp only [map]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
a : R
β’ evalβ (RingHom.comp C f) X (β(monomial n) a) = β(monomial n) (βf a)
[PROOFSTEP]
rw [evalβ_monomial, β C_mul_X_pow_eq_monomial]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
a : R
β’ β(RingHom.comp C f) a * X ^ n = βC (βf a) * X ^ n
[PROOFSTEP]
rfl
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
β’ map f (p * q) = map f p * map f q
[PROOFSTEP]
rw [map, evalβ_mul_noncomm]
[GOAL]
case hf
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
β’ β (k : β), Commute (β(RingHom.comp C f) (coeff q k)) X
[PROOFSTEP]
exact fun k => (commute_X _).symm
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
f : R β+* S
r : R
β’ map f (r β’ p) = βf r β’ map f p
[PROOFSTEP]
rw [map, evalβ_smul, RingHom.comp_apply, C_mul']
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
n : β
instβ : Nat.AtLeastTwo n
β’ map f βn = βn
[PROOFSTEP]
rw [Polynomial.map_nat_cast]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
β’ coeff (map f p) n = βf (coeff p n)
[PROOFSTEP]
rw [map, evalβ_def, coeff_sum, sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
β’ β n_1 in support p, coeff (β(RingHom.comp C f) (coeff p n_1) * X ^ n_1) n = βf (coeff p n)
[PROOFSTEP]
conv_rhs => rw [β sum_C_mul_X_pow_eq p, coeff_sum, sum, map_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
| βf (coeff p n)
[PROOFSTEP]
rw [β sum_C_mul_X_pow_eq p, coeff_sum, sum, map_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
| βf (coeff p n)
[PROOFSTEP]
rw [β sum_C_mul_X_pow_eq p, coeff_sum, sum, map_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
| βf (coeff p n)
[PROOFSTEP]
rw [β sum_C_mul_X_pow_eq p, coeff_sum, sum, map_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n : β
β’ β n_1 in support p, coeff (β(RingHom.comp C f) (coeff p n_1) * X ^ n_1) n =
β x in support p, βf (coeff (βC (coeff p x) * X ^ x) n)
[PROOFSTEP]
refine'
Finset.sum_congr rfl fun x _hx =>
_
-- Porting note: Was `simp [Function.comp, coeff_C_mul_X_pow, f.map_mul]`.
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n x : β
_hx : x β support p
β’ coeff (β(RingHom.comp C f) (coeff p x) * X ^ x) n = βf (coeff (βC (coeff p x) * X ^ x) n)
[PROOFSTEP]
simp [Function.comp, coeff_C_mul_X_pow, -map_mul, -coeff_C_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n x : β
_hx : x β support p
β’ (if n = x then βf (coeff p x) else 0) = βf (if n = x then coeff p x else 0)
[PROOFSTEP]
split_ifs
[GOAL]
case pos
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n x : β
_hx : x β support p
hβ : n = x
β’ βf (coeff p x) = βf (coeff p x)
[PROOFSTEP]
simp [f.map_zero]
[GOAL]
case neg
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
n x : β
_hx : x β support p
hβ : Β¬n = x
β’ 0 = βf 0
[PROOFSTEP]
simp [f.map_zero]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
e : R β+* S
β’ RingHom.comp β(mapRingHom β(RingEquiv.symm e)) β(mapRingHom βe) = RingHom.id R[X]
[PROOFSTEP]
ext
[GOAL]
case hβ.a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
e : R β+* S
xβ : R
nβ : β
β’ coeff (β(RingHom.comp (RingHom.comp β(mapRingHom β(RingEquiv.symm e)) β(mapRingHom βe)) C) xβ) nβ =
coeff (β(RingHom.comp (RingHom.id R[X]) C) xβ) nβ
[PROOFSTEP]
simp
[GOAL]
case hβ.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
e : R β+* S
nβ : β
β’ coeff (β(RingHom.comp β(mapRingHom β(RingEquiv.symm e)) β(mapRingHom βe)) X) nβ = coeff (β(RingHom.id R[X]) X) nβ
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
e : R β+* S
β’ RingHom.comp β(mapRingHom βe) β(mapRingHom β(RingEquiv.symm e)) = RingHom.id S[X]
[PROOFSTEP]
ext
[GOAL]
case hβ.a.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
e : R β+* S
xβ : S
nβ : β
β’ coeff (β(RingHom.comp (RingHom.comp β(mapRingHom βe) β(mapRingHom β(RingEquiv.symm e))) C) xβ) nβ =
coeff (β(RingHom.comp (RingHom.id S[X]) C) xβ) nβ
[PROOFSTEP]
simp
[GOAL]
case hβ.a
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
e : R β+* S
nβ : β
β’ coeff (β(RingHom.comp β(mapRingHom βe) β(mapRingHom β(RingEquiv.symm e))) X) nβ = coeff (β(RingHom.id S[X]) X) nβ
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
pβ q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
instβ : Semiring T
g : S β+* T
p : R[X]
β’ β (n : β), coeff (map g (map f p)) n = coeff (map (RingHom.comp g f) p) n
[PROOFSTEP]
simp [coeff_map]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
β’ map (RingHom.id R) p = p
[PROOFSTEP]
simp [Polynomial.ext_iff, coeff_map]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x p = eval x (map f p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp [hp, hq]
| h_monomial n r => simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
x : S
β’ evalβ f x p = eval x (map f p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp [hp, hq]
| h_monomial n r => simp
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
f : R β+* S
x : S
p q : R[X]
hp : evalβ f x p = eval x (map f p)
hq : evalβ f x q = eval x (map f q)
β’ evalβ f x (p + q) = eval x (map f (p + q))
[PROOFSTEP]
| h_add p q hp hq => simp [hp, hq]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
f : R β+* S
x : S
p q : R[X]
hp : evalβ f x p = eval x (map f p)
hq : evalβ f x q = eval x (map f q)
β’ evalβ f x (p + q) = eval x (map f (p + q))
[PROOFSTEP]
simp [hp, hq]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
r : R
β’ evalβ f x (β(monomial n) r) = eval x (map f (β(monomial n) r))
[PROOFSTEP]
| h_monomial n r => simp
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
f : R β+* S
x : S
n : β
r : R
β’ evalβ f x (β(monomial n) r) = eval x (map f (β(monomial n) r))
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
mβ n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
f : R β+* S
hf : Function.Injective βf
p q : R[X]
h : map f p = map f q
m : β
β’ βf (coeff p m) = βf (coeff q m)
[PROOFSTEP]
rw [β coeff_map f, β coeff_map f, h]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβΒΉ qβ r : R[X]
instβ : Semiring S
f : R β+* S
hf : Function.Surjective βf
pβ p q : S[X]
hp : β a, map f a = p
hq : β a, map f a = q
p' : R[X]
hp' : map f p' = p
q' : R[X]
hq' : map f q' = q
β’ map f (p' + q') = p + q
[PROOFSTEP]
rw [Polynomial.map_add f, hp', hq']
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q rβ : R[X]
instβ : Semiring S
f : R β+* S
hf : Function.Surjective βf
p : S[X]
n : β
s : S
r : R
hr : βf r = s
β’ map f (β(monomial n) r) = β(monomial n) s
[PROOFSTEP]
rw [map_monomial f, hr]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : R[X]
β’ degree (map f p) β€ degree p
[PROOFSTEP]
refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
mβ n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : R[X]
m : β
hm : degree p < βm
β’ coeff (map f p) m = 0
[PROOFSTEP]
rw [degree_lt_iff_coeff_zero] at hm
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
mβ n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : R[X]
m : β
hm : β (m_1 : β), m β€ m_1 β coeff p m_1 = 0
β’ coeff (map f p) m = 0
[PROOFSTEP]
simp [hm m le_rfl]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
hp : Monic p
hfp : map f p = 0
x : R
β’ βf x = βf x * βf (leadingCoeff p)
[PROOFSTEP]
simp only [mul_one, hp.leadingCoeff, f.map_one]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
hp : Monic p
hfp : map f p = 0
x : R
β’ βf x * coeff (map f p) (natDegree p) = 0
[PROOFSTEP]
simp only [hfp, mul_zero, coeff_zero]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
f : R β+* S
hp : Monic p
h : β (x : R), βf x = 0
n : β
β’ coeff (map f p) n = coeff 0 n
[PROOFSTEP]
simp only [h, coeff_map, coeff_zero]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ f : R β+* S
hf : βf (leadingCoeff p) β 0
β’ degree p β€ degree (map f p)
[PROOFSTEP]
have hp0 : p β 0 := leadingCoeff_ne_zero.mp fun hp0 => hf (_root_.trans (congr_arg _ hp0) f.map_zero)
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ f : R β+* S
hf : βf (leadingCoeff p) β 0
hp0 : p β 0
β’ degree p β€ degree (map f p)
[PROOFSTEP]
rw [degree_eq_natDegree hp0]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ f : R β+* S
hf : βf (leadingCoeff p) β 0
hp0 : p β 0
β’ β(natDegree p) β€ degree (map f p)
[PROOFSTEP]
refine' le_degree_of_ne_zero _
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ f : R β+* S
hf : βf (leadingCoeff p) β 0
hp0 : p β 0
β’ coeff (map f p) (natDegree p) β 0
[PROOFSTEP]
rw [coeff_map]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ f : R β+* S
hf : βf (leadingCoeff p) β 0
hp0 : p β 0
β’ βf (coeff p (natDegree p)) β 0
[PROOFSTEP]
exact hf
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ f : R β+* S
hf : βf (leadingCoeff p) β 0
β’ leadingCoeff (map f p) = βf (leadingCoeff p)
[PROOFSTEP]
unfold leadingCoeff
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q r : R[X]
instβ : Semiring S
fβ f : R β+* S
hf : βf (leadingCoeff p) β 0
β’ coeff (map f p) (natDegree (map f p)) = βf (coeff p (natDegree p))
[PROOFSTEP]
rw [coeff_map, natDegree_map_of_leadingCoeff_ne_zero f hf]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
β’ p β RingHom.rangeS (mapRingHom f) β β (n : β), coeff p n β RingHom.rangeS f
[PROOFSTEP]
constructor
[GOAL]
case mp
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
β’ p β RingHom.rangeS (mapRingHom f) β β (n : β), coeff p n β RingHom.rangeS f
[PROOFSTEP]
rintro β¨p, rflβ© n
[GOAL]
case mp.intro
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : R[X]
n : β
β’ coeff (β(mapRingHom f) p) n β RingHom.rangeS f
[PROOFSTEP]
rw [coe_mapRingHom, coeff_map]
[GOAL]
case mp.intro
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : R[X]
n : β
β’ βf (coeff p n) β RingHom.rangeS f
[PROOFSTEP]
exact Set.mem_range_self _
[GOAL]
case mpr
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
β’ (β (n : β), coeff p n β RingHom.rangeS f) β p β RingHom.rangeS (mapRingHom f)
[PROOFSTEP]
intro h
[GOAL]
case mpr
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
h : β (n : β), coeff p n β RingHom.rangeS f
β’ p β RingHom.rangeS (mapRingHom f)
[PROOFSTEP]
rw [p.as_sum_range_C_mul_X_pow]
[GOAL]
case mpr
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
h : β (n : β), coeff p n β RingHom.rangeS f
β’ β i in range (natDegree p + 1), βC (coeff p i) * X ^ i β RingHom.rangeS (mapRingHom f)
[PROOFSTEP]
refine' (mapRingHom f).rangeS.sum_mem _
[GOAL]
case mpr
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
h : β (n : β), coeff p n β RingHom.rangeS f
β’ β (c : β), c β range (natDegree p + 1) β βC (coeff p c) * X ^ c β RingHom.rangeS (mapRingHom f)
[PROOFSTEP]
intro i _hi
[GOAL]
case mpr
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
h : β (n : β), coeff p n β RingHom.rangeS f
i : β
_hi : i β range (natDegree p + 1)
β’ βC (coeff p i) * X ^ i β RingHom.rangeS (mapRingHom f)
[PROOFSTEP]
rcases h i with β¨c, hcβ©
[GOAL]
case mpr.intro
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
h : β (n : β), coeff p n β RingHom.rangeS f
i : β
_hi : i β range (natDegree p + 1)
c : R
hc : βf c = coeff p i
β’ βC (coeff p i) * X ^ i β RingHom.rangeS (mapRingHom f)
[PROOFSTEP]
use C c * X ^ i
[GOAL]
case h
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
f : R β+* S
p : S[X]
h : β (n : β), coeff p n β RingHom.rangeS f
i : β
_hi : i β range (natDegree p + 1)
c : R
hc : βf c = coeff p i
β’ β(mapRingHom f) (βC c * X ^ i) = βC (coeff p i) * X ^ i
[PROOFSTEP]
rw [coe_mapRingHom, Polynomial.map_mul, map_C, hc, Polynomial.map_pow, map_X]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
f : R β+* S
instβ : Semiring T
g : S β+* T
x : T
β’ evalβ g x (map f p) = evalβ (RingHom.comp g f) x p
[PROOFSTEP]
rw [evalβ_eq_eval_map, evalβ_eq_eval_map, map_map]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
f : R β+* S
p q : R[X]
β’ β (a : R), map f (comp (βC a) q) = comp (map f (βC a)) (map f q)
[PROOFSTEP]
simp only [map_C, forall_const, C_comp, eq_self_iff_true]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
f : R β+* S
p q : R[X]
β’ β (p q_1 : R[X]),
map f (comp p q) = comp (map f p) (map f q) β
map f (comp q_1 q) = comp (map f q_1) (map f q) β map f (comp (p + q_1) q) = comp (map f (p + q_1)) (map f q)
[PROOFSTEP]
simp (config := { contextual := true }) only [Polynomial.map_add, add_comp, forall_const, imp_true_iff,
eq_self_iff_true]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
f : R β+* S
p q : R[X]
β’ β (n : β) (a : R),
map f (comp (βC a * X ^ n) q) = comp (map f (βC a * X ^ n)) (map f q) β
map f (comp (βC a * X ^ (n + 1)) q) = comp (map f (βC a * X ^ (n + 1))) (map f q)
[PROOFSTEP]
simp (config := { contextual := true }) only [pow_succ', β mul_assoc, comp, forall_const, evalβ_mul_X, imp_true_iff,
eq_self_iff_true, map_X, Polynomial.map_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ f : R β+* S
p : R[X]
β’ eval 0 (map f p) = βf (eval 0 p)
[PROOFSTEP]
simp [β coeff_zero_eq_eval_zero]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ f : R β+* S
p : R[X]
β’ eval 1 (map f p) = βf (eval 1 p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| h_monomial n r => simp only [one_pow, mul_one, eval_monomial, map_monomial]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ f : R β+* S
p : R[X]
β’ eval 1 (map f p) = βf (eval 1 p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| h_monomial n r => simp only [one_pow, mul_one, eval_monomial, map_monomial]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
fβ f : R β+* S
p q : R[X]
hp : eval 1 (map f p) = βf (eval 1 p)
hq : eval 1 (map f q) = βf (eval 1 q)
β’ eval 1 (map f (p + q)) = βf (eval 1 (p + q))
[PROOFSTEP]
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
fβ f : R β+* S
p q : R[X]
hp : eval 1 (map f p) = βf (eval 1 p)
hq : eval 1 (map f q) = βf (eval 1 q)
β’ eval 1 (map f (p + q)) = βf (eval 1 (p + q))
[PROOFSTEP]
simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
fβ f : R β+* S
n : β
r : R
β’ eval 1 (map f (β(monomial n) r)) = βf (eval 1 (β(monomial n) r))
[PROOFSTEP]
| h_monomial n r => simp only [one_pow, mul_one, eval_monomial, map_monomial]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
fβ f : R β+* S
n : β
r : R
β’ eval 1 (map f (β(monomial n) r)) = βf (eval 1 (β(monomial n) r))
[PROOFSTEP]
simp only [one_pow, mul_one, eval_monomial, map_monomial]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ f : R β+* S
p : R[X]
n : β
β’ eval (βn) (map f p) = βf (eval (βn) p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| h_monomial n r => simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ q r : R[X]
instβ : Semiring S
fβ f : R β+* S
p : R[X]
n : β
β’ eval (βn) (map f p) = βf (eval (βn) p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| h_monomial n r => simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
fβ f : R β+* S
n : β
p q : R[X]
hp : eval (βn) (map f p) = βf (eval (βn) p)
hq : eval (βn) (map f q) = βf (eval (βn) q)
β’ eval (βn) (map f (p + q)) = βf (eval (βn) (p + q))
[PROOFSTEP]
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβΒΉ : Semiring R
pβ qβ r : R[X]
instβ : Semiring S
fβ f : R β+* S
n : β
p q : R[X]
hp : eval (βn) (map f p) = βf (eval (βn) p)
hq : eval (βn) (map f q) = βf (eval (βn) q)
β’ eval (βn) (map f (p + q)) = βf (eval (βn) (p + q))
[PROOFSTEP]
simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβΒΉ : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
fβ f : R β+* S
nβ n : β
r : R
β’ eval (βnβ) (map f (β(monomial n) r)) = βf (eval (βnβ) (β(monomial n) r))
[PROOFSTEP]
| h_monomial n r => simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβΒΉ : β
instβΒΉ : Semiring R
p q rβ : R[X]
instβ : Semiring S
fβ f : R β+* S
nβ n : β
r : R
β’ eval (βnβ) (map f (β(monomial n) r)) = βf (eval (βnβ) (β(monomial n) r))
[PROOFSTEP]
simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul]
[GOAL]
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒ³ : Semiring Rβ
pβ q r : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Ring R
instβ : Ring S
f : R β+* S
p : R[X]
i : β€
β’ eval (βi) (map f p) = βf (eval (βi) p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| h_monomial n r => simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul]
[GOAL]
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒ³ : Semiring Rβ
pβ q r : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Ring R
instβ : Ring S
f : R β+* S
p : R[X]
i : β€
β’ eval (βi) (map f p) = βf (eval (βi) p)
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| h_monomial n r => simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul]
[GOAL]
case h_add
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒ³ : Semiring Rβ
pβ qβ r : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Ring R
instβ : Ring S
f : R β+* S
i : β€
p q : R[X]
hp : eval (βi) (map f p) = βf (eval (βi) p)
hq : eval (βi) (map f q) = βf (eval (βi) q)
β’ eval (βi) (map f (p + q)) = βf (eval (βi) (p + q))
[PROOFSTEP]
| h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
[GOAL]
case h_add
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒ³ : Semiring Rβ
pβ qβ r : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Ring R
instβ : Ring S
f : R β+* S
i : β€
p q : R[X]
hp : eval (βi) (map f p) = βf (eval (βi) p)
hq : eval (βi) (map f q) = βf (eval (βi) q)
β’ eval (βi) (map f (p + q)) = βf (eval (βi) (p + q))
[PROOFSTEP]
simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
[GOAL]
case h_monomial
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m nβ : β
instβΒ³ : Semiring Rβ
p q rβ : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Ring R
instβ : Ring S
f : R β+* S
i : β€
n : β
r : R
β’ eval (βi) (map f (β(monomial n) r)) = βf (eval (βi) (β(monomial n) r))
[PROOFSTEP]
| h_monomial n r => simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul]
[GOAL]
case h_monomial
Rβ : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m nβ : β
instβΒ³ : Semiring Rβ
p q rβ : Rβ[X]
instβΒ² : Semiring Sβ
fβ : Rβ β+* Sβ
R : Type u_1
S : Type u_2
instβΒΉ : Ring R
instβ : Ring S
f : R β+* S
i : β€
n : β
r : R
β’ eval (βi) (map f (β(monomial n) r)) = βf (eval (βi) (β(monomial n) r))
[PROOFSTEP]
simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒ² : Semiring R
p q r : R[X]
instβΒΉ : Semiring S
instβ : Semiring T
f : R β+* S
g : S β+* T
x : S
β’ βg (evalβ f x p) = evalβ (RingHom.comp g f) (βg x) p
[PROOFSTEP]
rw [β evalβ_map, evalβ_at_apply, eval_map]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q : R[X]
xβ : R
instβ : CommSemiring S
f : R β+* S
x : S
β’ evalβ f x (comp p q) = evalβ f (evalβ f x q) p
[PROOFSTEP]
rw [comp, p.as_sum_range]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q : R[X]
xβ : R
instβ : CommSemiring S
f : R β+* S
x : S
β’ evalβ f x (evalβ C q (β i in range (natDegree p + 1), β(monomial i) (coeff p i))) =
evalβ f (evalβ f x q) (β i in range (natDegree p + 1), β(monomial i) (coeff p i))
[PROOFSTEP]
simp [evalβ_finset_sum, evalβ_pow]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
k : β
t : S
β’ evalβ f t ((comp p)^[k] q) = (fun x => evalβ f x p)^[k] (evalβ f t q)
[PROOFSTEP]
induction' k with k IH
[GOAL]
case zero
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
t : S
β’ evalβ f t ((comp p)^[Nat.zero] q) = (fun x => evalβ f x p)^[Nat.zero] (evalβ f t q)
[PROOFSTEP]
simp
[GOAL]
case succ
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
t : S
k : β
IH : evalβ f t ((comp p)^[k] q) = (fun x => evalβ f x p)^[k] (evalβ f t q)
β’ evalβ f t ((comp p)^[Nat.succ k] q) = (fun x => evalβ f x p)^[Nat.succ k] (evalβ f t q)
[PROOFSTEP]
rw [Function.iterate_succ_apply', Function.iterate_succ_apply', evalβ_comp, IH]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : CommSemiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
β’ eval x (comp p q) = eval (eval x q) p
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add r s hr hs => simp [add_comp, hr, hs]
| h_monomial n a => simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : CommSemiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
β’ eval x (comp p q) = eval (eval x q) p
[PROOFSTEP]
induction p using Polynomial.induction_on' with
| h_add r s hr hs => simp [add_comp, hr, hs]
| h_monomial n a => simp
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : CommSemiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
r s : R[X]
hr : eval x (comp r q) = eval (eval x q) r
hs : eval x (comp s q) = eval (eval x q) s
β’ eval x (comp (r + s) q) = eval (eval x q) (r + s)
[PROOFSTEP]
| h_add r s hr hs => simp [add_comp, hr, hs]
[GOAL]
case h_add
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : CommSemiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
r s : R[X]
hr : eval x (comp r q) = eval (eval x q) r
hs : eval x (comp s q) = eval (eval x q) s
β’ eval x (comp (r + s) q) = eval (eval x q) (r + s)
[PROOFSTEP]
simp [add_comp, hr, hs]
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m nβ : β
instβΒΉ : CommSemiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
n : β
a : R
β’ eval x (comp (β(monomial n) a) q) = eval (eval x q) (β(monomial n) a)
[PROOFSTEP]
| h_monomial n a => simp
[GOAL]
case h_monomial
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
aβ b : R
m nβ : β
instβΒΉ : CommSemiring R
p q : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
n : β
a : R
β’ eval x (comp (β(monomial n) a) q) = eval (eval x q) (β(monomial n) a)
[PROOFSTEP]
simp
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : CommSemiring R
pβ qβ : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
p q : R[X]
H : IsRoot q a
β’ IsRoot (p * q) a
[PROOFSTEP]
rw [IsRoot, eval_mul, IsRoot.def.1 H, mul_zero]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : CommSemiring R
pβ qβ : R[X]
x : R
instβ : CommSemiring S
f : R β+* S
p q : R[X]
H : IsRoot p a
β’ IsRoot (p * q) a
[PROOFSTEP]
rw [IsRoot, eval_mul, IsRoot.def.1 H, zero_mul]
[GOAL]
Rβ : Type u
S : Type v
T : Type w
ΞΉβ : Type y
a b : Rβ
m n : β
instβΒ³ : CommSemiring Rβ
pβ q : Rβ[X]
xβ : Rβ
instβΒ² : CommSemiring S
f : Rβ β+* S
R : Type u_2
instβΒΉ : CommRing R
instβ : IsDomain R
ΞΉ : Type u_1
s : Finset ΞΉ
p : ΞΉ β R[X]
x : R
β’ IsRoot (β j in s, p j) x β β i, i β s β§ IsRoot (p i) x
[PROOFSTEP]
simp only [IsRoot, eval_prod, Finset.prod_eq_zero_iff]
[GOAL]
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m nβ : β
instβΒ² : CommSemiring Rβ
p q : Rβ[X]
xβ : Rβ
instβΒΉ : CommSemiring S
f : Rβ β+* S
R : Type u_1
instβ : CommSemiring R
n : β
x : R
β’ eval x (β i in range n, X ^ i) = β i in range n, x ^ i
[PROOFSTEP]
simp [eval_finset_sum]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
instβ : Semiring S
f : R β+* S
p : R[X]
β’ support (map f p) β support p
[PROOFSTEP]
intro x
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
instβ : Semiring S
f : R β+* S
p : R[X]
x : β
β’ x β support (map f p) β x β support p
[PROOFSTEP]
contrapose!
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
instβ : Semiring S
f : R β+* S
p : R[X]
x : β
β’ Β¬x β support p β Β¬x β support (map f p)
[PROOFSTEP]
simp (config := { contextual := true })
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Semiring R
instβ : Semiring S
p : R[X]
f : R β+* S
hf : Function.Injective βf
β’ support (map f p) = support p
[PROOFSTEP]
simp_rw [Finset.ext_iff, mem_support_iff, coeff_map, β map_zero f, hf.ne_iff, forall_const]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : CommSemiring R
instβ : CommSemiring S
fβ f : R β+* S
x : R
p : R[X]
h : IsRoot p x
β’ IsRoot (Polynomial.map f p) (βf x)
[PROOFSTEP]
rw [IsRoot, eval_map, evalβ_hom, h.eq_zero, f.map_zero]
[GOAL]
Rβ : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : Rβ
m n : β
instβΒ² : CommSemiring Rβ
instβΒΉ : CommSemiring S
fβ : Rβ β+* S
R : Type u_1
instβ : CommRing R
f : R β+* S
x : R
p : R[X]
h : IsRoot (Polynomial.map f p) (βf x)
hf : Function.Injective βf
β’ IsRoot p x
[PROOFSTEP]
rwa [IsRoot, β (injective_iff_map_eq_zero' f).mp hf, β evalβ_hom, β eval_map]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m nβ : β
instβ : Ring R
p q r : R[X]
n : β€
x : R
β’ eval x βn = βn
[PROOFSTEP]
simp only [β C_eq_int_cast, eval_C]
[GOAL]
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Ring R
p q r : R[X]
S : Type u_1
instβ : Ring S
f : R β+* S
x : S
β’ evalβ f x (-p) = -evalβ f x p
[PROOFSTEP]
rw [eq_neg_iff_add_eq_zero, β evalβ_add, add_left_neg, evalβ_zero]
[GOAL]
R : Type u
Sβ : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβΒΉ : Ring R
p q r : R[X]
S : Type u_1
instβ : Ring S
f : R β+* S
x : S
β’ evalβ f x (p - q) = evalβ f x p - evalβ f x q
[PROOFSTEP]
rw [sub_eq_add_neg, evalβ_add, evalβ_neg, sub_eq_add_neg]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Ring R
p q r : R[X]
β’ IsRoot (X - βC a) b β a = b
[PROOFSTEP]
rw [IsRoot.def, eval_sub, eval_X, eval_C, sub_eq_zero, eq_comm]
[GOAL]
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Ring R
p q r : R[X]
i : β€
β’ comp (βi) p = βi
[PROOFSTEP]
cases i
[GOAL]
case ofNat
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Ring R
p q r : R[X]
aβ : β
β’ comp (β(Int.ofNat aβ)) p = β(Int.ofNat aβ)
[PROOFSTEP]
simp
[GOAL]
case negSucc
R : Type u
S : Type v
T : Type w
ΞΉ : Type y
a b : R
m n : β
instβ : Ring R
p q r : R[X]
aβ : β
β’ comp (β(Int.negSucc aβ)) p = β(Int.negSucc aβ)
[PROOFSTEP]
simp
|
DAVIDSON, N.C., Jan. 10, 2019 /PRNewswire/ -- Rocus Networks, a managed cybersecurity service provider for business, announced today that it has entered the Palo Alto Networks NextWave Managed Security Service Provider (MSSP) Program.
"We created the MSSP program due to increased customer demand for managed security services and to provide a better way to connect businesses with service providers," said Karl Soderlund, Senior Vice President, Worldwide Channel Sales at Palo Alto Networks. "As part of our NextWave MSSP program, partners like Rocus Networks can continually and efficiently improve security effectiveness for our mutual customers, and accelerate the deployment of new security services."
"This program with Palo Alto Networks allows Rocus Networks to provide organizations, regardless of size, with best-in-class next-generation security technology without the need to hire dedicated security personnel," said Michael Viruso, Rocus Networks Chief Strategy Officer. "They get cloud-delivered, enterprise-level security that is easy to use and won't disrupt business operations."
The Palo Alto Networks NextWave MSSP Specialization empowers managed services partners with the most innovative technology in the industry, protection on registered deals and best-in-class training, all to provide our mutual customers with the technical expertise and services they require of their trusted security advisers.
To learn more about Rocus Networks, visit rocusnetworks.com. |
/-
Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import topology.metric_space.baire
import analysis.normed_space.operator_norm
/-!
# Banach open mapping theorem
This file contains the Banach open mapping theorem, i.e., the fact that a bijective
bounded linear map between Banach spaces has a bounded inverse.
-/
open function metric set filter finset
open_locale classical topological_space big_operators nnreal
variables {π : Type*} [nondiscrete_normed_field π]
{E : Type*} [normed_group E] [normed_space π E]
{F : Type*} [normed_group F] [normed_space π F]
(f : E βL[π] F)
include π
namespace continuous_linear_map
/-- A (possibly nonlinear) right inverse to a continuous linear map, which doesn't have to be
linear itself but which satisfies a bound `β₯inverse xβ₯ β€ C * β₯xβ₯`. A surjective continuous linear
map doesn't always have a continuous linear right inverse, but it always has a nonlinear inverse
in this sense, by Banach's open mapping theorem. -/
structure nonlinear_right_inverse :=
(to_fun : F β E)
(nnnorm : ββ₯0)
(bound' : β y, β₯to_fun yβ₯ β€ nnnorm * β₯yβ₯)
(right_inv' : β y, f (to_fun y) = y)
instance : has_coe_to_fun (nonlinear_right_inverse f) := β¨_, Ξ» fsymm, fsymm.to_funβ©
@[simp] lemma nonlinear_right_inverse.right_inv {f : E βL[π] F} (fsymm : nonlinear_right_inverse f)
(y : F) : f (fsymm y) = y :=
fsymm.right_inv' y
lemma nonlinear_right_inverse.bound {f : E βL[π] F} (fsymm : nonlinear_right_inverse f) (y : F) :
β₯fsymm yβ₯ β€ fsymm.nnnorm * β₯yβ₯ :=
fsymm.bound' y
end continuous_linear_map
/-- Given a continuous linear equivalence, the inverse is in particular an instance of
`nonlinear_right_inverse` (which turns out to be linear). -/
noncomputable def continuous_linear_equiv.to_nonlinear_right_inverse (f : E βL[π] F) :
continuous_linear_map.nonlinear_right_inverse (f : E βL[π] F) :=
{ to_fun := f.inv_fun,
nnnorm := nnnorm (f.symm : F βL[π] E),
bound' := Ξ» y, continuous_linear_map.le_op_norm (f.symm : F βL[π] E) _,
right_inv' := f.apply_symm_apply }
noncomputable instance (f : E βL[π] F) :
inhabited (continuous_linear_map.nonlinear_right_inverse (f : E βL[π] F)) :=
β¨f.to_nonlinear_right_inverseβ©
/-! ### Proof of the Banach open mapping theorem -/
variable [complete_space F]
/--
First step of the proof of the Banach open mapping theorem (using completeness of `F`):
by Baire's theorem, there exists a ball in `E` whose image closure has nonempty interior.
Rescaling everything, it follows that any `y β F` is arbitrarily well approached by
images of elements of norm at most `C * β₯yβ₯`.
For further use, we will only need such an element whose image
is within distance `β₯yβ₯/2` of `y`, to apply an iterative process. -/
lemma exists_approx_preimage_norm_le (surj : surjective f) :
βC β₯ 0, βy, βx, dist (f x) y β€ 1/2 * β₯yβ₯ β§ β₯xβ₯ β€ C * β₯yβ₯ :=
begin
have A : (βn:β, closure (f '' (ball 0 n))) = univ,
{ refine subset.antisymm (subset_univ _) (Ξ»y hy, _),
rcases surj y with β¨x, hxβ©,
rcases exists_nat_gt (β₯xβ₯) with β¨n, hnβ©,
refine mem_Union.2 β¨n, subset_closure _β©,
refine (mem_image _ _ _).2 β¨x, β¨_, hxβ©β©,
rwa [mem_ball, dist_eq_norm, sub_zero] },
have : β (n : β) x, x β interior (closure (f '' (ball 0 n))) :=
nonempty_interior_of_Union_of_closed (Ξ»n, is_closed_closure) A,
simp only [mem_interior_iff_mem_nhds, mem_nhds_iff] at this,
rcases this with β¨n, a, Ξ΅, β¨Ξ΅pos, Hβ©β©,
rcases normed_field.exists_one_lt_norm π with β¨c, hcβ©,
refine β¨(Ξ΅/2)β»ΒΉ * β₯cβ₯ * 2 * n, _, Ξ»y, _β©,
{ refine mul_nonneg (mul_nonneg (mul_nonneg _ (norm_nonneg _)) (by norm_num)) _,
exacts [inv_nonneg.2 (div_nonneg (le_of_lt Ξ΅pos) (by norm_num)), n.cast_nonneg] },
{ by_cases hy : y = 0,
{ use 0, simp [hy] },
{ rcases rescale_to_shell hc (half_pos Ξ΅pos) hy with β¨d, hd, ydlt, leyd, dinvβ©,
let Ξ΄ := β₯dβ₯ * β₯yβ₯/4,
have Ξ΄pos : 0 < Ξ΄ :=
div_pos (mul_pos (norm_pos_iff.2 hd) (norm_pos_iff.2 hy)) (by norm_num),
have : a + d β’ y β ball a Ξ΅,
by simp [dist_eq_norm, lt_of_le_of_lt ydlt.le (half_lt_self Ξ΅pos)],
rcases metric.mem_closure_iff.1 (H this) _ Ξ΄pos with β¨zβ, zβim, hββ©,
rcases (mem_image _ _ _).1 zβim with β¨xβ, hxβ, xzββ©,
rw β xzβ at hβ,
rw [mem_ball, dist_eq_norm, sub_zero] at hxβ,
have : a β ball a Ξ΅, by { simp, exact Ξ΅pos },
rcases metric.mem_closure_iff.1 (H this) _ Ξ΄pos with β¨zβ, zβim, hββ©,
rcases (mem_image _ _ _).1 zβim with β¨xβ, hxβ, xzββ©,
rw β xzβ at hβ,
rw [mem_ball, dist_eq_norm, sub_zero] at hxβ,
let x := xβ - xβ,
have I : β₯f x - d β’ yβ₯ β€ 2 * Ξ΄ := calc
β₯f x - d β’ yβ₯ = β₯f xβ - (a + d β’ y) - (f xβ - a)β₯ :
by { congr' 1, simp only [x, f.map_sub], abel }
... β€ β₯f xβ - (a + d β’ y)β₯ + β₯f xβ - aβ₯ :
norm_sub_le _ _
... β€ Ξ΄ + Ξ΄ : begin
apply add_le_add,
{ rw [β dist_eq_norm, dist_comm], exact le_of_lt hβ },
{ rw [β dist_eq_norm, dist_comm], exact le_of_lt hβ }
end
... = 2 * Ξ΄ : (two_mul _).symm,
have J : β₯f (dβ»ΒΉ β’ x) - yβ₯ β€ 1/2 * β₯yβ₯ := calc
β₯f (dβ»ΒΉ β’ x) - yβ₯ = β₯dβ»ΒΉ β’ f x - (dβ»ΒΉ * d) β’ yβ₯ :
by rwa [f.map_smul _, inv_mul_cancel, one_smul]
... = β₯dβ»ΒΉ β’ (f x - d β’ y)β₯ : by rw [mul_smul, smul_sub]
... = β₯dβ₯β»ΒΉ * β₯f x - d β’ yβ₯ : by rw [norm_smul, normed_field.norm_inv]
... β€ β₯dβ₯β»ΒΉ * (2 * Ξ΄) : begin
apply mul_le_mul_of_nonneg_left I,
rw inv_nonneg,
exact norm_nonneg _
end
... = (β₯dβ₯β»ΒΉ * β₯dβ₯) * β₯yβ₯ /2 : by { simp only [Ξ΄], ring }
... = β₯yβ₯/2 : by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hd] }
... = (1/2) * β₯yβ₯ : by ring,
rw β dist_eq_norm at J,
have K : β₯dβ»ΒΉ β’ xβ₯ β€ (Ξ΅ / 2)β»ΒΉ * β₯cβ₯ * 2 * βn * β₯yβ₯ := calc
β₯dβ»ΒΉ β’ xβ₯ = β₯dβ₯β»ΒΉ * β₯xβ - xββ₯ : by rw [norm_smul, normed_field.norm_inv]
... β€ ((Ξ΅ / 2)β»ΒΉ * β₯cβ₯ * β₯yβ₯) * (n + n) : begin
refine mul_le_mul dinv _ (norm_nonneg _) _,
{ exact le_trans (norm_sub_le _ _) (add_le_add (le_of_lt hxβ) (le_of_lt hxβ)) },
{ apply mul_nonneg (mul_nonneg _ (norm_nonneg _)) (norm_nonneg _),
exact inv_nonneg.2 (le_of_lt (half_pos Ξ΅pos)) }
end
... = (Ξ΅ / 2)β»ΒΉ * β₯cβ₯ * 2 * βn * β₯yβ₯ : by ring,
exact β¨dβ»ΒΉ β’ x, J, Kβ© } },
end
variable [complete_space E]
/-- The Banach open mapping theorem: if a bounded linear map between Banach spaces is onto, then
any point has a preimage with controlled norm. -/
theorem exists_preimage_norm_le (surj : surjective f) :
βC > 0, βy, βx, f x = y β§ β₯xβ₯ β€ C * β₯yβ₯ :=
begin
obtain β¨C, C0, hCβ© := exists_approx_preimage_norm_le f surj,
/- Second step of the proof: starting from `y`, we want an exact preimage of `y`. Let `g y` be
the approximate preimage of `y` given by the first step, and `h y = y - f(g y)` the part that
has no preimage yet. We will iterate this process, taking the approximate preimage of `h y`,
leaving only `h^2 y` without preimage yet, and so on. Let `u n` be the approximate preimage
of `h^n y`. Then `u` is a converging series, and by design the sum of the series is a
preimage of `y`. This uses completeness of `E`. -/
choose g hg using hC,
let h := Ξ»y, y - f (g y),
have hle : βy, β₯h yβ₯ β€ (1/2) * β₯yβ₯,
{ assume y,
rw [β dist_eq_norm, dist_comm],
exact (hg y).1 },
refine β¨2 * C + 1, by linarith, Ξ»y, _β©,
have hnle : βn:β, β₯(h^[n]) yβ₯ β€ (1/2)^n * β₯yβ₯,
{ assume n,
induction n with n IH,
{ simp only [one_div, nat.nat_zero_eq_zero, one_mul, iterate_zero_apply,
pow_zero] },
{ rw [iterate_succ'],
apply le_trans (hle _) _,
rw [pow_succ, mul_assoc],
apply mul_le_mul_of_nonneg_left IH,
norm_num } },
let u := Ξ»n, g((h^[n]) y),
have ule : βn, β₯u nβ₯ β€ (1/2)^n * (C * β₯yβ₯),
{ assume n,
apply le_trans (hg _).2 _,
calc C * β₯(h^[n]) yβ₯ β€ C * ((1/2)^n * β₯yβ₯) : mul_le_mul_of_nonneg_left (hnle n) C0
... = (1 / 2) ^ n * (C * β₯yβ₯) : by ring },
have sNu : summable (Ξ»n, β₯u nβ₯),
{ refine summable_of_nonneg_of_le (Ξ»n, norm_nonneg _) ule _,
exact summable.mul_right _ (summable_geometric_of_lt_1 (by norm_num) (by norm_num)) },
have su : summable u := summable_of_summable_norm sNu,
let x := tsum u,
have x_ineq : β₯xβ₯ β€ (2 * C + 1) * β₯yβ₯ := calc
β₯xβ₯ β€ β'n, β₯u nβ₯ : norm_tsum_le_tsum_norm sNu
... β€ β'n, (1/2)^n * (C * β₯yβ₯) :
tsum_le_tsum ule sNu (summable.mul_right _ summable_geometric_two)
... = (β'n, (1/2)^n) * (C * β₯yβ₯) : tsum_mul_right
... = 2 * C * β₯yβ₯ : by rw [tsum_geometric_two, mul_assoc]
... β€ 2 * C * β₯yβ₯ + β₯yβ₯ : le_add_of_nonneg_right (norm_nonneg y)
... = (2 * C + 1) * β₯yβ₯ : by ring,
have fsumeq : βn:β, f (β i in range n, u i) = y - (h^[n]) y,
{ assume n,
induction n with n IH,
{ simp [f.map_zero] },
{ rw [sum_range_succ, f.map_add, IH, iterate_succ', sub_add] } },
have : tendsto (Ξ»n, β i in range n, u i) at_top (π x) :=
su.has_sum.tendsto_sum_nat,
have Lβ : tendsto (Ξ»n, f (β i in range n, u i)) at_top (π (f x)) :=
(f.continuous.tendsto _).comp this,
simp only [fsumeq] at Lβ,
have Lβ : tendsto (Ξ»n, y - (h^[n]) y) at_top (π (y - 0)),
{ refine tendsto_const_nhds.sub _,
rw tendsto_iff_norm_tendsto_zero,
simp only [sub_zero],
refine squeeze_zero (Ξ»_, norm_nonneg _) hnle _,
rw [β zero_mul β₯yβ₯],
refine (tendsto_pow_at_top_nhds_0_of_lt_1 _ _).mul tendsto_const_nhds; norm_num },
have feq : f x = y - 0 := tendsto_nhds_unique Lβ Lβ,
rw sub_zero at feq,
exact β¨x, feq, x_ineqβ©
end
/-- The Banach open mapping theorem: a surjective bounded linear map between Banach spaces is
open. -/
theorem open_mapping (surj : surjective f) : is_open_map f :=
begin
assume s hs,
rcases exists_preimage_norm_le f surj with β¨C, Cpos, hCβ©,
refine is_open_iff.2 (Ξ»y yfs, _),
rcases mem_image_iff_bex.1 yfs with β¨x, xs, fxyβ©,
rcases is_open_iff.1 hs x xs with β¨Ξ΅, Ξ΅pos, hΞ΅β©,
refine β¨Ξ΅/C, div_pos Ξ΅pos Cpos, Ξ»z hz, _β©,
rcases hC (z-y) with β¨w, wim, wnormβ©,
have : f (x + w) = z, by { rw [f.map_add, wim, fxy, add_sub_cancel'_right] },
rw β this,
have : x + w β ball x Ξ΅ := calc
dist (x+w) x = β₯wβ₯ : by { rw dist_eq_norm, simp }
... β€ C * β₯z - yβ₯ : wnorm
... < C * (Ξ΅/C) : begin
apply mul_lt_mul_of_pos_left _ Cpos,
rwa [mem_ball, dist_eq_norm] at hz,
end
... = Ξ΅ : mul_div_cancel' _ (ne_of_gt Cpos),
exact set.mem_image_of_mem _ (hΞ΅ this)
end
/-! ### Applications of the Banach open mapping theorem -/
namespace continuous_linear_map
lemma exists_nonlinear_right_inverse_of_surjective (f : E βL[π] F) (hsurj : f.range = β€) :
β (fsymm : nonlinear_right_inverse f), 0 < fsymm.nnnorm :=
begin
choose C hC fsymm h using exists_preimage_norm_le _ (linear_map.range_eq_top.mp hsurj),
use { to_fun := fsymm,
nnnorm := β¨C, hC.lt.leβ©,
bound' := Ξ» y, (h y).2,
right_inv' := Ξ» y, (h y).1 },
exact hC
end
/-- A surjective continuous linear map between Banach spaces admits a (possibly nonlinear)
controlled right inverse. In general, it is not possible to ensure that such a right inverse
is linear (take for instance the map from `E` to `E/F` where `F` is a closed subspace of `E`
without a closed complement. Then it doesn't have a continuous linear right inverse.) -/
@[irreducible] noncomputable def nonlinear_right_inverse_of_surjective
(f : E βL[π] F) (hsurj : f.range = β€) : nonlinear_right_inverse f :=
classical.some (exists_nonlinear_right_inverse_of_surjective f hsurj)
lemma nonlinear_right_inverse_of_surjective_nnnorm_pos (f : E βL[π] F) (hsurj : f.range = β€) :
0 < (nonlinear_right_inverse_of_surjective f hsurj).nnnorm :=
begin
rw nonlinear_right_inverse_of_surjective,
exact classical.some_spec (exists_nonlinear_right_inverse_of_surjective f hsurj)
end
end continuous_linear_map
namespace linear_equiv
/-- If a bounded linear map is a bijection, then its inverse is also a bounded linear map. -/
@[continuity]
theorem continuous_symm (e : E ββ[π] F) (h : continuous e) :
continuous e.symm :=
begin
rw continuous_def,
intros s hs,
rw [β e.image_eq_preimage],
rw [β e.coe_coe] at h β’,
exact open_mapping β¨βe, hβ© e.surjective s hs
end
/-- Associating to a linear equivalence between Banach spaces a continuous linear equivalence when
the direct map is continuous, thanks to the Banach open mapping theorem that ensures that the
inverse map is also continuous. -/
def to_continuous_linear_equiv_of_continuous (e : E ββ[π] F) (h : continuous e) :
E βL[π] F :=
{ continuous_to_fun := h,
continuous_inv_fun := e.continuous_symm h,
..e }
@[simp] lemma coe_fn_to_continuous_linear_equiv_of_continuous (e : E ββ[π] F) (h : continuous e) :
β(e.to_continuous_linear_equiv_of_continuous h) = e := rfl
@[simp] lemma coe_fn_to_continuous_linear_equiv_of_continuous_symm (e : E ββ[π] F)
(h : continuous e) :
β(e.to_continuous_linear_equiv_of_continuous h).symm = e.symm := rfl
end linear_equiv
namespace continuous_linear_equiv
/-- Convert a bijective continuous linear map `f : E βL[π] F` between two Banach spaces
to a continuous linear equivalence. -/
noncomputable def of_bijective (f : E βL[π] F) (hinj : f.ker = β₯) (hsurj : f.range = β€) :
E βL[π] F :=
(linear_equiv.of_bijective βf hinj hsurj).to_continuous_linear_equiv_of_continuous f.continuous
@[simp] lemma coe_fn_of_bijective (f : E βL[π] F) (hinj : f.ker = β₯) (hsurj : f.range = β€) :
β(of_bijective f hinj hsurj) = f := rfl
@[simp] lemma of_bijective_symm_apply_apply (f : E βL[π] F) (hinj : f.ker = β₯)
(hsurj : f.range = β€) (x : E) :
(of_bijective f hinj hsurj).symm (f x) = x :=
(of_bijective f hinj hsurj).symm_apply_apply x
@[simp] lemma of_bijective_apply_symm_apply (f : E βL[π] F) (hinj : f.ker = β₯)
(hsurj : f.range = β€) (y : F) :
f ((of_bijective f hinj hsurj).symm y) = y :=
(of_bijective f hinj hsurj).apply_symm_apply y
end continuous_linear_equiv
namespace continuous_linear_map
/- TODO: remove the assumption `f.ker = β₯` in the next lemma, by using the map induced by `f` on
`E / f.ker`, once we have quotient normed spaces. -/
lemma closed_complemented_range_of_is_compl_of_ker_eq_bot (f : E βL[π] F) (G : submodule π F)
(h : is_compl f.range G) (hG : is_closed (G : set F)) (hker : f.ker = β₯) :
is_closed (f.range : set F) :=
begin
let g : (E Γ G) βL[π] F := f.coprod G.subtypeL,
have : (f.range : set F) = g '' ((β€ : submodule π E).prod (β₯ : submodule π G)),
by { ext x, simp [continuous_linear_map.mem_range] },
rw this,
haveI : complete_space G := complete_space_coe_iff_is_complete.2 hG.is_complete,
have grange : g.range = β€,
by simp only [range_coprod, h.sup_eq_top, submodule.range_subtypeL],
have gker : g.ker = β₯,
{ rw [ker_coprod_of_disjoint_range, hker],
{ simp only [submodule.ker_subtypeL, submodule.prod_bot] },
{ convert h.disjoint,
exact submodule.range_subtypeL _ } },
apply (continuous_linear_equiv.of_bijective g gker grange).to_homeomorph.is_closed_image.2,
exact is_closed_univ.prod is_closed_singleton,
end
end continuous_linear_map
|
State Before: Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
aβ bβ cβ d a b c : Ξ±
β’ a β b β c = a β c β (b β c) State After: no goals Tactic: rw [sup_sup_sup_comm, sup_idem] |
Formal statement is: lemma coprime_quot_of_fract: "coprime (fst (quot_of_fract x)) (snd (quot_of_fract x))" Informal statement is: The numerator and denominator of a fraction are coprime. |
import subgroup.lattice
/-!
Group homomorphisms
-/
-- We're always overwriting group theory here so we always work in
-- a namespace
namespace mygroup
/- homomorphisms of groups -/
/-- Bundled group homomorphisms -/
structure group_hom (G H : Type) [group G] [group H] :=
(to_fun : G β H)
(map_mul' : β x y, to_fun (x * y) = to_fun x * to_fun y)
-- notation
infixr ` β* `:25 := group_hom
-- coercion to a function
instance {G H : Type} [group G] [group H] :
has_coe_to_fun (G β* H) := β¨_, group_hom.to_funβ©
@[simp] lemma to_fun_eq_coe {G H : Type} [group G] [group H]
(f : G β* H) : f.to_fun = f := rfl
@[ext] lemma ext_hom {G H : Type} [group G] [group H] (Ο Ο : G β* H) :
Ο = Ο β Ο.to_fun = Ο.to_fun :=
begin
split, { cc },
{ intro h,
cases Ο with Ο1 Ο2,
cases Ο with Ο1 Ο2,
simp * at * }
end
@[ext] lemma ext {G H : Type} [group G] [group H] (Ο Ο : G β* H)
(h : β g : G, Ο g = Ο g) : Ο = Ο :=
begin
rw ext_hom,
ext g,
exact h g,
end
-- the identity homomorphism
def id_hom {G : Type} [group G] : G β* G := β¨id, Ξ» x y, rflβ©
/-- Group isomorphism as a bijective group homomorphism -/
structure group_iso (G H : Type) [group G] [group H] extends group_hom G H :=
(is_bijective : function.bijective to_fun)
notation G ` β
` H := group_iso G H
-- Coercion from `group_iso` to `group_hom`
instance {G H : Type} [group G] [group H] :
has_coe_t (G β
H) (G β* H) := β¨group_iso.to_group_homβ©
instance coe_iso_to_fun {G H : Type} [group G] [group H] :
has_coe_to_fun (G β
H) := β¨_, group_iso.to_group_homβ©
-- Should we define it this way or as an extension of equiv that preserves mul?
/- Alternative definition
structure group_equiv (G H : Type) [group G] [group H] extends G β H :=
(map_mul' : β x y : G, to_fun (x * y) = to_fun x * to_fun y)
notation G ` β
` H := group_equiv G H
-- Coercion from `group_equiv` to `group_hom`
instance {G H : Type} [group G] [group H] :
has_coe (G β
H) (G β* H) := β¨Ξ» f, β¨f.to_fun, f.map_mul'β©β© -/
open set mygroup.subgroup function
namespace group_hom
variables {G H K : Type} [group G] [group H] [group K]
/-- If f is a group homomorphism then f (a * b) = f a * f b. -/
@[simp]
lemma map_mul (f : G β* H) (a b : G) : f (a * b) = f a * f b :=
f.map_mul' a b
/-- The composition of two group homomorphisms form a group homomorphism -/
def map_comp (f : G β* H) (g : H β* K) : G β* K :=
{ to_fun := g β f,
map_mul' := Ξ» x y, by simp }
notation g ` β* ` f := map_comp f g
@[simp] lemma coe_map_comp (f : G β* H) (g : H β* K) : ((g β* f) : G β K) =
g β f := rfl
/-- A group is isomorphic to itself by the identity homomorphism -/
def iso_refl : G β
G :=
{ is_bijective := function.bijective_id, .. id_hom }
/-- The composition of two group isomorphisms form a group isomorphism -/
def iso_comp (f : G β
H) (g : H β
K) : G β
K :=
{ is_bijective := function.bijective.comp g.is_bijective f.is_bijective,
.. (g : group_hom H K) β* (f : group_hom G H) }
/-- An equiv between two groups that preserves multiplication forms an isomorphism -/
def iso_of_mul_equiv (f : G β* H) : G β
H :=
{ to_fun := f, map_mul' := f.map_mul',
is_bijective := equiv.bijective f.to_equiv }
/-- An isomorphism between two groups from an mul_equiv -/
noncomputable def mul_equiv_of_iso (f : G β
H) : G β* H :=
{ map_mul' := map_mul f, .. equiv.of_bijective _ f.is_bijective }
/-- If the group `G` is isomorphic to the group `H`, then `H` is isomorphic to `G`-/
noncomputable def iso_symm (f : G β
H) : H β
G :=
iso_of_mul_equiv $ mul_equiv.symm $ mul_equiv_of_iso f
def to_prod (H : subgroup G) (N : normal G) : H β* H β¨― N :=
{ to_fun := Ξ» h, β¨h.1, h.1, h.2, 1, subgroup.one_mem N, (group.mul_one _).symmβ©,
map_mul' := Ξ» β¨x, hxβ© β¨y, hyβ©, subtype.val_injective rfl }
@[simp] lemma to_prod_apply (H : subgroup G) (N : normal G) (h : H) :
to_prod H N h = β¨h.1, h.1, h.2, 1, subgroup.one_mem N, (group.mul_one _).symmβ© :=
rfl
@[simp] lemma to_prod_mul {H : subgroup G} {K : normal G} (x y : H) :
(to_prod H K x) * (to_prod H K y) = to_prod H K (x * y) := rfl
def to_prod' (H : subgroup G) (N : normal G) : N.to_subgroup β* H β¨― N :=
{ to_fun := Ξ» n, β¨n.1, 1, H.one_mem, n.1, n.2, (group.one_mul _).symmβ©,
map_mul' := Ξ» β¨x, hxβ© β¨y, hyβ©, subtype.val_injective rfl }
open_locale classical
/-
The type of group homs G β H is
denoted f : G β* H
and the underlying function of types is βf : G β H
TODO: can we switch those arrows off?
The axiom: if `f : G β* H` then `f.map_mul`
is the assertion that for all a, b β G
we have f(a) = f(b).
Our first job is to prove `f.map_one` and `f.map_inv`.
`f.map_one : f 1 = 1`
`f.map_inv {x : G} : f (xβ»ΒΉ) = f(x)β»ΒΉ`
-/
/-- If f is a group homomorphism then f 1 = 1. -/
@[simp] -- it's a good simp lemma
lemma map_one (f : G β* H) : f 1 = 1 :=
begin
have h : f 1 * f 1 = f 1,
rw βf.map_mul,
rw group.one_mul, -- annoying but stops cheating
-- TODO: can I kill one_mul somehow? I asked on Zulip
rw group.mul_left_eq_self at h, -- annoying
assumption
end
/-- If f is a group homomorphism then f(xβ»ΒΉ) = f(x)β»ΒΉ -/
@[simp] -- it's also a good simp lemma
lemma map_inv (f : G β* H) {x : G} : f (xβ»ΒΉ) = (f x)β»ΒΉ :=
begin
apply group.eq_inv_of_mul_eq_one,
rw βf.map_mul,
rw group.mul_left_inv,
rw f.map_one,
-- refl
end
-- Inclusion map as a homomorphism from a subgroup to the group
def πΎ (H : subgroup G) : H β* G :=
{ to_fun := Ξ» h, (h : G),
map_mul' := Ξ» _ _, rfl }
@[simp] lemma πΎ_def {H : subgroup G} {h} (hh : h β H) : πΎ H β¨h, hhβ© = h := rfl
-- The inclusion map is injective
lemma injective_πΎ {H : subgroup G} : injective $ πΎ H := Ξ» _ _ hxy, subtype.eq hxy
-- We prove the theorems here (only);
-- definitions need to go elsewhere
-- Rather than defining the kernel as the preimage of {1}, I think defining it
-- as a subgroup of the domain is better
/-- The kernel of a homomorphism `f : G β* H` is the normal subgroup of `G` whos
carrier is the preimage of `{1}`, i.e. `f β»ΒΉ' {1}` -/
def kernel (f : G β* H) : normal G :=
{ carrier := f β»ΒΉ' {1},
one_mem' := map_one _,
mul_mem' :=
begin
intros _ _ hx hy,
rw [mem_preimage, mem_singleton_iff] at *,
rw [map_mul f, hx, hy, group.mul_one]
end,
inv_mem' :=
begin
intros _ hx,
rw [mem_preimage, mem_singleton_iff] at *,
rw [map_inv f, hx, group.one_inv]
end,
conj_mem' :=
begin
intros _ hn _,
rw [mem_preimage, mem_singleton_iff] at *,
simp [hn],
end }
/-- The image of a homomorphism `f : G β* H` is the subgroup of `H` whose carrier
is the image of `univ : set G`, i.e. `f '' univ` -/
def image (f : G β* H) : subgroup H :=
{ carrier := range f,
one_mem' := β¨1, map_one _β©,
mul_mem' := Ξ» _ _ β¨x, hxββ© β¨y, hyββ©, β¨x * y, by rw [map_mul f x y, hxβ, hyβ]β©,
inv_mem' := Ξ» _ β¨x, hxββ©, β¨xβ»ΒΉ, by rw [βhxβ, map_inv]β© }
variables {f : G β* H}
lemma mem_kernel {g : G} : g β kernel f β f g = 1 :=
β¨Ξ» h, mem_singleton_iff.1 $ mem_preimage.1 h, Ξ» h, hβ©
lemma mem_kernel_of_eq {a b : G} (h : f a = f b) :
bβ»ΒΉ * a β kernel f :=
begin
rw [mem_kernel, map_mul, map_inv,
βgroup.mul_left_cancel_iff (f b)],
simp [βmul_assoc, h]
end
lemma one_mem_kernel (f : G β* H) : (1 : G) β kernel f := map_one f
lemma mem_image {h : H} : h β image f β β g, f g = h := iff.rfl
attribute [simp] mem_kernel mem_image
-- We will prove the classic results about injective homomorphisms that a
-- homomorphism is injective if and only if it have the trivial kernel
/-- A homomorphism `f` is injective iff. `f` has kernel `{1}` -/
theorem injective_iff_kernel_eq_one :
injective f β (kernel f : set G) = {1} :=
begin
split; intro hf,
{ show f β»ΒΉ' {1} = {1},
ext, split; intro hx,
{ apply @hf x 1,
rw map_one,
exact mem_singleton_iff.1 hx },
{ rw [mem_preimage, mem_singleton_iff, mem_singleton_iff.1 hx],
exact map_one _ } },
{ change f β»ΒΉ' {1} = {1} at hf,
by_contra h, push_neg at h,
rcases h with β¨x, y, heq, hneqβ©,
refine hneq (group.mul_right_cancel yβ»ΒΉ _ _ _),
have : x * yβ»ΒΉ β f β»ΒΉ' {1},
apply group.mul_right_cancel (f y),
rw [map_mul f, group.mul_assoc, map_inv, group.mul_left_inv,
group.one_mul, group.mul_one, heq],
rw [hf, mem_singleton_iff] at this,
rw [this, group.mul_right_inv] }
end
theorem injective_iff_kernel_eq_one' :
injective f β β a, f a = 1 β a = 1 :=
begin
rw injective_iff_kernel_eq_one,
simp_rw [βmem_kernel, set.ext_iff, mem_singleton_iff],
split,
{ intros h a ha,
rwa βh },
{ intros h a,
split, apply h,
rintro rfl,
apply one_mem }
end
/-- A homomorphism `f : G β* H` is surjective iff. the image of `f` is `H` -/
theorem surjective_iff_max_img :
surjective f β (image f : set H) = univ :=
begin
split; intro hf,
{ ext y, exact β¨Ξ» _, mem_univ _, Ξ» hy, hf yβ© },
{ intro y,
exact (show y β (image f : set H), by rw hf; exact mem_univ _) }
end
end group_hom
namespace subgroup
-- pushforward and pullback of subgroups
variables {G : Type} [group G] {H : Type} [group H]
/-- The image of a subgroup under a group homomorphism is a subgroup -/
def map (f : G β* H) (K : subgroup G) : subgroup H :=
{ carrier := f '' K,
one_mem' := by rw mem_image; exact β¨1, K.one_mem, f.map_oneβ©,
mul_mem' := by rintros _ _ β¨a, ha, rflβ© β¨b, hb, rflβ©;
exact β¨a * b, K.mul_mem ha hb, f.map_mul _ _β©,
inv_mem' := by rintros _ β¨a, ha, rflβ©; exact β¨aβ»ΒΉ, K.inv_mem ha, f.map_invβ© }
lemma mem_map (f : G β* H) (K : subgroup G) (a : H) :
a β K.map f β β g : G, g β K β§ f g = a := iff.rfl
/-- The preimage of a subgroup under a group homomorphism is a subgroup -/
def comap (f : G β* H) (K : subgroup H) : subgroup G :=
{ carrier := f β»ΒΉ' K,
one_mem' := show f 1 β K, by rw f.map_one; exact one_mem K,
mul_mem' := Ξ» x y hx hy, show f (x * y) β K,
by rw f.map_mul; exact mul_mem K hx hy,
inv_mem' := Ξ» x hx, show f xβ»ΒΉ β K, by rw f.map_inv; exact inv_mem K hx }
lemma mem_comap' (f : G β* H) (M : subgroup H) (g : G) :
g β M.comap f β f g β M := iff.rfl
def gc (f : G β* H) : galois_connection (map f) (comap f) :=
begin
rintros A B,
show f.to_fun '' A.carrier β B.carrier β A.carrier β f.to_fun β»ΒΉ' B.carrier,
finish
end
theorem closure_image (f : G β* H) (S : set G) :
closure (f '' S) = map f (closure S) :=
begin
apply lattice.le_antisymm,
{ rw [closure_le, le_eq_subset, image_subset_iff],
refine subset.trans (le_closure _) _,
change closure S β€ comap f (map f (closure S)),
apply galois_connection.le_u_l (gc f) },
{ refine galois_connection.l_le (gc f) _,
rw closure_le,
have h : S β f β»ΒΉ' ( f '' S),
intro x, finish,
refine set.subset.trans h _,
show f β»ΒΉ' _ β f β»ΒΉ' _,
mono, apply le_closure }
end
theorem closure_singleton (f : G β* H) (g : G) :
closure ({f g} : set H) = map f (closure ({g})) :=
by convert closure_image f ({g} : set G); finish
end subgroup
namespace normal
open group_hom mygroup.subgroup
variables {G H : Type} [group G] [group H]
/-- The preimage of a normal subgroup under a group homomorphism is normal -/
def comap (f : G β* H) (N : normal H) : normal G :=
{carrier := f β»ΒΉ' N,
one_mem' := by rw [mem_preimage, map_one]; exact N.one_mem',
mul_mem' := Ξ» _ _ hβ hβ, mem_preimage.2 (by rw map_mul; exact N.mul_mem' hβ hβ),
inv_mem' := Ξ» _ h, mem_preimage.2 (by rw map_inv; exact N.inv_mem' h),
conj_mem' :=
begin
intros n h t ,
rw [mem_preimage, map_mul, map_mul],
change _ β N, convert N.conj_mem (f n) h (f t),
apply f.map_inv
end }
@[simp] lemma mem_comap {f : G β* H} {N : normal H} (x) :
x β comap f N β f x β N :=
show x β f β»ΒΉ' N β f x β N, by exact mem_preimage
/-- The surjective image of a normal subgroup is normal -/
def nmap {f : G β* H} (hf : surjective f) (N : normal G) : normal H :=
{ carrier := f '' N,
one_mem' := β¨1, N.to_subgroup.one_mem, f.map_oneβ©,
mul_mem' := by rintros _ _ β¨a, ha, rflβ© β¨b, hb, rflβ©;
exact β¨a * b, N.to_subgroup.mul_mem ha hb, f.map_mul a bβ©,
inv_mem' := by rintros _ β¨a, ha, rflβ©;
exact β¨aβ»ΒΉ, N.to_subgroup.inv_mem ha, f.map_invβ©,
conj_mem' :=
begin
rintro _ β¨b, hb, rflβ© h,
rcases hf h with β¨g, rflβ©,
exact β¨g * b * gβ»ΒΉ, N.conj_mem b hb g, by simp [f.map_mul]β©
end }
@[simp] lemma mem_nmap {f : G β* H} (hf : surjective f) {N : normal G} (y) :
y β nmap hf N β β x β N, f x = y :=
show y β f '' N β _, by rw mem_image_iff_bex; refl
/-- Intersection of T and N is the pushforward to G of (the pullback to T of N)
along the natural map T β G -/
theorem subgroup_inf (N : normal G) (T : subgroup G) :
(T β N) = map (πΎ T) (comap (πΎ T) N) :=
begin
ext x, split,
{ exact Ξ» h, let β¨hxt, hxnβ© := mem_inf.1 h in
(mem_map _ _ _).1 β¨β¨x, hxtβ©, hxn, rflβ© },
{ rintro β¨β¨g, hgtβ©, ht1, rflβ©, exact mem_inf.2 β¨hgt, ht1β© }
end
end normal
end mygroup |
theory TopoS_Stateful_Policy
imports TopoS_Composition_Theory
begin
section\<open>Stateful Policy\<close>
text\<open>Details described in \<^cite>\<open>"diekmann2014esss"\<close>.\<close>
text\<open>Algorithm\<close>
term TopoS_Composition_Theory.generate_valid_topology
text\<open>generates a valid high-level topology. Now we discuss how to turn this into
a stateful policy.\<close>
text\<open>
Example:
SensorNode produces data and has no security level.
SensorSink has high security level
SensorNode -> SensorSink, but not the other way round.
Implementation: UDP in one direction
Alice is in internal protected subnet. Google can not arbitrarily access Alice.
Alice sends requests to google.
It is desirable that Alice gets the response back
Implementation: TCP and stateful packet filter that allows, once Alice establishes a connection, to get a response back via this connection.
Result:
IFS violations undesirable.
ACS violations may be okay under certain conditions.
\<close>
term all_security_requirements_fulfilled
text\<open>@{term "G = (V, E\<^sub>f\<^sub>i\<^sub>x, E\<^sub>s\<^sub>t\<^sub>a\<^sub>t\<^sub>e)"}\<close>
record 'v stateful_policy =
hosts :: "'v set" \<comment> \<open>nodes, vertices\<close>
flows_fix :: "('v \<times>'v) set" \<comment> \<open>edges in high-level policy\<close>
flows_state :: "('v \<times>'v) set" \<comment> \<open>edges that can have stateful flows, i.e. backflows\<close>
text\<open>All the possible ways packets can travel in a @{typ "'v stateful_policy"}.
They can either choose the fixed links;
Or use a stateful link, i.e. establish state.
Once state is established, packets can flow back via the established link.\<close>
definition all_flows :: "'v stateful_policy \<Rightarrow> ('v \<times> 'v) set" where
"all_flows \<T> \<equiv> flows_fix \<T> \<union> flows_state \<T> \<union> backflows (flows_state \<T>)"
definition stateful_policy_to_network_graph :: "'v stateful_policy \<Rightarrow> 'v graph" where
"stateful_policy_to_network_graph \<T> = \<lparr> nodes = hosts \<T>, edges = all_flows \<T> \<rparr>"
text\<open>@{typ "'v stateful_policy"} syntactically well-formed\<close>
locale wf_stateful_policy =
fixes \<T> :: "'v stateful_policy"
assumes E_wf: "fst ` (flows_fix \<T>) \<subseteq> (hosts \<T>)"
"snd ` (flows_fix \<T>) \<subseteq> (hosts \<T>)"
and E_state_fix: "flows_state \<T> \<subseteq> flows_fix \<T>"
and finite_Hosts: "finite (hosts \<T>)"
begin
lemma finite_fix: "finite (flows_fix \<T>)"
proof -
from finite_subset[OF E_wf(1) finite_Hosts] have 1: "finite (fst ` flows_fix \<T>)" .
from finite_subset[OF E_wf(2) finite_Hosts] have 2: "finite (snd ` flows_fix \<T>)" .
have s: "flows_fix \<T> \<subseteq> (fst ` flows_fix \<T> \<times> snd ` flows_fix \<T>)" by force
from finite_cartesian_product[OF 1 2] have "finite (fst ` flows_fix \<T> \<times> snd ` flows_fix \<T>)" .
from finite_subset[OF s this] show ?thesis .
qed
lemma finite_state: "finite (flows_state \<T>)"
using finite_subset[OF E_state_fix finite_fix] by assumption
lemma finite_backflows_state: "finite (backflows (flows_state \<T>))"
using [[simproc add: finite_Collect]] by(simp add: backflows_def finite_state)
lemma E_state_backflows_wf: "fst ` backflows (flows_state \<T>) \<subseteq> (hosts \<T>)"
"snd ` backflows (flows_state \<T>) \<subseteq> (hosts \<T>)"
by(auto simp add: backflows_def E_state_valid E_state_validD)
end
text\<open>Minimizing stateful flows such that only newly added backflows remain\<close>
definition filternew_flows_state :: "'v stateful_policy \<Rightarrow> ('v \<times> 'v) set" where
"filternew_flows_state \<T> \<equiv> {(s, r) \<in> flows_state \<T>. (r, s) \<notin> flows_fix \<T>}"
lemma filternew_subseteq_flows_state: "filternew_flows_state \<T> \<subseteq> flows_state \<T>"
by(auto simp add: filternew_flows_state_def)
\<comment> \<open>alternative definitions, all are equal\<close>
lemma filternew_flows_state_alt: "filternew_flows_state \<T> = flows_state \<T> - (backflows (flows_fix \<T>))"
apply(simp add: backflows_def filternew_flows_state_def)
apply(rule)
apply blast+
done
lemma stateful_policy_to_network_graph_filternew: "\<lbrakk> wf_stateful_policy \<T> \<rbrakk> \<Longrightarrow>
stateful_policy_to_network_graph \<T> =
stateful_policy_to_network_graph \<lparr>hosts = hosts \<T>, flows_fix = flows_fix \<T>, flows_state = filternew_flows_state \<T> \<rparr>"
apply(drule wf_stateful_policy.E_state_fix)
apply(simp add: stateful_policy_to_network_graph_def all_flows_def)
apply(rule Set.equalityI)
apply(simp add: filternew_flows_state_def backflows_def)
apply(rule, blast)+
apply(simp add: filternew_flows_state_def backflows_def)
apply fastforce
done
lemma backflows_filternew_disjunct_flows_fix:
"\<forall> b \<in> (backflows (filternew_flows_state \<T>)). b \<notin> flows_fix \<T>"
by(simp add: filternew_flows_state_def backflows_def)
text\<open>Given a high-level policy, we can construct a pretty large syntactically valid low level policy. However, the stateful policy will
almost certainly violate security requirements!\<close>
lemma "wf_graph G \<Longrightarrow> wf_stateful_policy \<lparr> hosts = nodes G, flows_fix = nodes G \<times> nodes G, flows_state = nodes G \<times> nodes G \<rparr>"
by(simp add: wf_stateful_policy_def wf_graph_def)
text\<open>@{const wf_stateful_policy} implies @{term wf_graph}\<close>
lemma wf_stateful_policy_is_wf_graph: "wf_stateful_policy \<T> \<Longrightarrow> wf_graph \<lparr>nodes = hosts \<T>, edges = all_flows \<T>\<rparr>"
apply(frule wf_stateful_policy.E_state_backflows_wf)
apply(frule wf_stateful_policy.E_state_backflows_wf(2))
apply(frule wf_stateful_policy.E_state_valid)
apply(frule wf_stateful_policy.E_state_valid(2))
apply(frule wf_stateful_policy.E_wf)
apply(frule wf_stateful_policy.E_wf(2))
apply(simp add: all_flows_def wf_graph_def wf_stateful_policy_def
wf_stateful_policy.finite_fix wf_stateful_policy.finite_state wf_stateful_policy.finite_backflows_state)
apply(rule conjI)
apply (metis image_Un sup.bounded_iff)+
done
(*we use the second way of writing it in the paper*)
lemma "(\<forall>F \<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<T> ). F \<subseteq> backflows (filternew_flows_state \<T>)) \<longleftrightarrow>
\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<T>)) \<subseteq> (backflows (flows_state \<T>)) - (flows_fix \<T>)"
by(simp add: filternew_flows_state_alt backflows_minus_backflows, blast)
text\<open>When is a stateful policy @{term "\<T>"} compliant with a high-level policy @{term "G"} and the security requirements @{term "M"}?\<close>
locale stateful_policy_compliance =
fixes \<T> :: "('v::vertex) stateful_policy"
fixes G :: "'v graph"
fixes M :: "('v) SecurityInvariant_configured list"
assumes
\<comment> \<open>the graph must be syntactically valid\<close>
wfG: "wf_graph G"
and
\<comment> \<open>security requirements must be valid\<close>
validReqs: "valid_reqs M"
and
\<comment> \<open>the high-level policy must be valid\<close>
high_level_policy_valid: "all_security_requirements_fulfilled M G"
and
\<comment> \<open>the stateful policy must be syntactically valid\<close>
stateful_policy_wf:
"wf_stateful_policy \<T>"
and
\<comment> \<open>the stateful policy must talk about the same nodes as the high-level policy\<close>
hosts_nodes:
"hosts \<T> = nodes G"
and
\<comment> \<open>only flows that are allowed in the high-level policy are allowed in the stateful policy\<close>
flows_edges:
"flows_fix \<T> \<subseteq> edges G"
and
\<comment> \<open>the low level policy must comply with the high-level policy\<close>
\<comment> \<open>all information flow strategy requirements must be fulfilled, i.e. no leaks!\<close>
compliant_stateful_IFS:
"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \<T>)"
and
\<comment> \<open>No Access Control side effects must occur\<close>
compliant_stateful_ACS:
"\<forall>F \<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<T> ). F \<subseteq> backflows (filternew_flows_state \<T>)"
begin
lemma compliant_stateful_ACS_no_side_effects_filternew_helper:
"\<forall> E \<subseteq> backflows (filternew_flows_state \<T>). \<forall> F \<in> get_offending_flows (get_ACS M) \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<union> E \<rparr>. F \<subseteq> E"
proof(rule, rule)
fix E
assume a1: "E \<subseteq> backflows (filternew_flows_state \<T>)"
from validReqs have valid_ReqsACS: "valid_reqs (get_ACS M)" by(simp add: get_ACS_def valid_reqs_def)
from compliant_stateful_ACS stateful_policy_to_network_graph_filternew[OF stateful_policy_wf] have compliant_stateful_ACS_only_state_violations_filternew:
"\<forall>F \<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<lparr>hosts = hosts \<T>, flows_fix = flows_fix \<T>, flows_state = filternew_flows_state \<T> \<rparr>). F \<subseteq> backflows (filternew_flows_state \<T>)" by simp
from wf_stateful_policy_is_wf_graph[OF stateful_policy_wf] have wfGfilternew:
"wf_graph \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> filternew_flows_state \<T> \<union> backflows (filternew_flows_state \<T>)\<rparr>"
apply(simp add: all_flows_def filternew_flows_state_alt backflows_minus_backflows)
by(auto simp add: wf_graph_def)
from wf_stateful_policy.E_state_fix[OF stateful_policy_wf] filternew_subseteq_flows_state have flows_fix_un_filternew_simp: "flows_fix \<T> \<union> filternew_flows_state \<T> = flows_fix \<T>" by blast
from compliant_stateful_ACS_only_state_violations_filternew have
"\<And>m. m \<in> set (get_ACS M) \<Longrightarrow>
\<Union>(c_offending_flows m \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> filternew_flows_state \<T> \<union> backflows (filternew_flows_state \<T>)\<rparr>) \<subseteq> backflows (filternew_flows_state \<T>)"
by(simp add: stateful_policy_to_network_graph_def all_flows_def get_offending_flows_def, blast)
\<comment> \<open>idea: use @{thm compliant_stateful_ACS} with the @{thm configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq}
lemma and substract @{term "backflows (filternew_flows_state \<T>) - E"}, on the right hand side @{term E} remains, as Graph's edges @{term "flows_fix \<T> \<union> E"} remains\<close>
from configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq[where X="backflows (filternew_flows_state \<T>)", OF _ wfGfilternew this]
\<open>valid_reqs (get_ACS M)\<close>
have
"\<And> m E. m \<in> set (get_ACS M) \<Longrightarrow>
\<forall>F\<in>c_offending_flows m \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> filternew_flows_state \<T> \<union> backflows (filternew_flows_state \<T>) - E\<rparr>. F \<subseteq> backflows (filternew_flows_state \<T>) - E"
by(auto simp add: all_flows_def valid_reqs_def)
from this flows_fix_un_filternew_simp have rule:
"\<And> m E. m \<in> set (get_ACS M) \<Longrightarrow>
\<forall>F\<in>c_offending_flows m \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> backflows (filternew_flows_state \<T>) - E\<rparr>. F \<subseteq> backflows (filternew_flows_state \<T>) - E"
by simp
from backflows_finite rev_finite_subset[OF wf_stateful_policy.finite_state[OF stateful_policy_wf] filternew_subseteq_flows_state] have
"finite (backflows (filternew_flows_state \<T>))" by blast
from a1 this have "finite E" by (metis rev_finite_subset)
from a1 obtain E' where E'_prop1: "backflows (filternew_flows_state \<T>) - E' = E" and E'_prop2: "E' = backflows (filternew_flows_state \<T>) - E" by blast
from E'_prop2 \<open>finite (backflows (filternew_flows_state \<T>))\<close> \<open>finite E\<close> have "finite E'" by blast
from Set.double_diff[where B="backflows (filternew_flows_state \<T>)" and C="backflows (filternew_flows_state \<T>)" and A="E", OF a1, simplified] have Ebackflowssimp:
"backflows (filternew_flows_state \<T>) - (backflows (filternew_flows_state \<T>) - E) = E" .
have "flows_fix \<T> \<union> backflows (filternew_flows_state \<T>) - (backflows (filternew_flows_state \<T>) - E) =
(flows_fix \<T> - (backflows (filternew_flows_state \<T>))) \<union> E"
apply(simp add: Set.Un_Diff)
apply(simp add: Ebackflowssimp)
by blast
also have "(flows_fix \<T> - (backflows (filternew_flows_state \<T>))) \<union> E = flows_fix \<T> \<union> E" using backflows_filternew_disjunct_flows_fix by blast
finally have flows_E_simp: "flows_fix \<T> \<union> backflows (filternew_flows_state \<T>) - (backflows (filternew_flows_state \<T>) - E) = flows_fix \<T> \<union> E" .
from rule[simplified E'_prop1 E'_prop2] have
"\<And>m. m \<in> set (get_ACS M) \<Longrightarrow>
\<forall>F\<in>c_offending_flows m \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> backflows (filternew_flows_state \<T>) - (backflows (filternew_flows_state \<T>) - E)\<rparr>.
F \<subseteq> backflows (filternew_flows_state \<T>) - (backflows (filternew_flows_state \<T>) - E)"
by(simp)
from this Ebackflowssimp flows_E_simp have
"\<And>m. m \<in> set (get_ACS M) \<Longrightarrow>
\<forall>F\<in>c_offending_flows m \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> E\<rparr>. F \<subseteq> E"
by simp
thus "\<forall>F\<in>get_offending_flows (get_ACS M) \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> E\<rparr>. F \<subseteq> E"
by(simp add: get_offending_flows_def)
qed
theorem compliant_stateful_ACS_no_side_effects:
"\<forall> E \<subseteq> backflows (flows_state \<T>). \<forall> F \<in> get_offending_flows(get_ACS M) \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<union> E \<rparr>. F \<subseteq> E"
proof -
from compliant_stateful_ACS stateful_policy_to_network_graph_filternew[OF stateful_policy_wf] have a1:
"\<forall>F \<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<lparr>hosts = hosts \<T>, flows_fix = flows_fix \<T>, flows_state = filternew_flows_state \<T> \<rparr>). F \<subseteq> backflows (filternew_flows_state \<T>)" by simp
have backflows_split: "backflows (filternew_flows_state \<T>) \<union> (backflows (flows_state \<T>) - backflows (filternew_flows_state \<T>)) = backflows (flows_state \<T>)"
by (metis Diff_subset Un_Diff_cancel Un_absorb1 backflows_minus_backflows filternew_flows_state_alt)
have
"\<forall>E\<subseteq>backflows (filternew_flows_state \<T>) \<union> (backflows (flows_state \<T>) - backflows (filternew_flows_state \<T>)).
\<forall>F\<in>get_offending_flows (get_ACS M) \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> E\<rparr>. F \<subseteq> E"
proof(rule allI, rule impI)
fix E
assume h1: "E \<subseteq> backflows (filternew_flows_state \<T>) \<union> (backflows (flows_state \<T>) - backflows (filternew_flows_state \<T>))"
have "\<exists> E1 E2. E1 \<subseteq> backflows (filternew_flows_state \<T>) \<and> E2 \<subseteq> (backflows (flows_state \<T>) - backflows (filternew_flows_state \<T>)) \<and> E1 \<union> E2 = E \<and> E1 \<inter> E2 = {}"
apply(rule_tac x="{e \<in> E. e \<in> backflows (filternew_flows_state \<T>)}" in exI)
apply(rule_tac x="{e \<in> E. e \<in>(backflows (flows_state \<T>) - backflows (filternew_flows_state \<T>))}" in exI)
apply(simp)
apply(rule)
apply blast
apply(rule)
apply blast
apply(rule)
using h1 apply blast
using backflows_filternew_disjunct_flows_fix by blast
from this obtain E1 E2 where E1_prop: "E1 \<subseteq> backflows (filternew_flows_state \<T>)" and E2_prop: "E2 \<subseteq> (backflows (flows_state \<T>) - backflows (filternew_flows_state \<T>))" and "E = E1 \<union> E2" and "E1 \<inter> E2 = {}" by blast
\<comment> \<open>the stateful flows are @{text "\<subseteq>"} fix flows. If substracting the new stateful flows, onyly the existing fix flows remain\<close>
from E2_prop filternew_flows_state_alt have "E2 \<subseteq> flows_fix \<T>" by (metis (opaque_lifting, no_types) Diff_subset_conv Un_Diff_cancel2 backflows_minus_backflows inf_sup_ord(3) order.trans)
\<comment> \<open>hence, E2 disappears\<close>
from Set.Un_absorb1[OF this] have E2_absorb: "flows_fix \<T> \<union> E2 = flows_fix \<T>" by blast
from \<open>E = E1 \<union> E2\<close> have E2E1eq: "E2 \<union> E1 = E" by blast
from \<open>E = E1 \<union> E2\<close> \<open>E1 \<inter> E2 = {}\<close> have "E1 \<subseteq> E" by simp
from compliant_stateful_ACS_no_side_effects_filternew_helper E1_prop have "\<forall>F\<in>get_offending_flows (get_ACS M) \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> E1 \<rparr>. F \<subseteq> E1" by simp
hence "\<forall>F\<in>get_offending_flows (get_ACS M) \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> E2 \<union> E1 \<rparr>. F \<subseteq> E1" using E2_absorb[symmetric] by simp
hence "\<forall>F\<in>get_offending_flows (get_ACS M) \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> E \<rparr>. F \<subseteq> E1" using E2E1eq by (metis Un_assoc)
from this \<open>E1 \<subseteq> E\<close> show "\<forall>F\<in>get_offending_flows (get_ACS M) \<lparr>nodes = hosts \<T>, edges = flows_fix \<T> \<union> E\<rparr>. F \<subseteq> E" by blast
qed
from this backflows_split show ?thesis by presburger
qed
corollary compliant_stateful_ACS_no_side_effects': "\<forall> E \<subseteq> backflows (flows_state \<T>). \<forall> F \<in> get_offending_flows(get_ACS M) \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<union> flows_state \<T> \<union> E \<rparr>. F \<subseteq> E"
using compliant_stateful_ACS_no_side_effects wf_stateful_policy.E_state_fix[OF stateful_policy_wf] by (metis Un_absorb2)
text\<open>The high level graph generated from the low level policy is a valid graph\<close>
lemma valid_stateful_policy: "wf_graph \<lparr>nodes = hosts \<T>, edges = all_flows \<T>\<rparr>"
by(rule wf_stateful_policy_is_wf_graph,fact stateful_policy_wf)
text\<open>The security requirements are definitely fulfilled if we consider only the fixed flows and the
normal direction of the stateful flows (i.e. no backflows).
I.e. considering no states, everything must be fulfilled\<close>
lemma compliant_stateful_ACS_static_valid: "all_security_requirements_fulfilled (get_ACS M) \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<rparr>"
proof -
from validReqs have valid_ReqsACS: "valid_reqs (get_ACS M)" by(simp add: get_ACS_def valid_reqs_def)
from wfG hosts_nodes[symmetric] have wfG': "wf_graph \<lparr> nodes = hosts \<T>, edges = edges G \<rparr>" by(case_tac G, simp)
from high_level_policy_valid have "all_security_requirements_fulfilled (get_ACS M) G"
by(simp add: get_ACS_def all_security_requirements_fulfilled_def)
from this hosts_nodes[symmetric] have "all_security_requirements_fulfilled (get_ACS M) \<lparr> nodes = hosts \<T>, edges = edges G \<rparr>"
by(case_tac G, simp)
from all_security_requirements_fulfilled_mono[OF valid_ReqsACS flows_edges wfG' this] show ?thesis .
qed
theorem compliant_stateful_ACS_static_valid':
"all_security_requirements_fulfilled M \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<union> flows_state \<T> \<rparr>"
proof -
from validReqs have valid_ReqsIFS: "valid_reqs (get_IFS M)" by(simp add: get_IFS_def valid_reqs_def)
\<comment> \<open>show that it holds for IFS, by monotonicity as it holds for more in IFS\<close>
from all_security_requirements_fulfilled_mono[OF valid_ReqsIFS _ valid_stateful_policy compliant_stateful_IFS[unfolded stateful_policy_to_network_graph_def]] have
goalIFS: "all_security_requirements_fulfilled (get_IFS M) \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<union> flows_state \<T> \<rparr>" by(simp add: all_flows_def)
from wf_stateful_policy.E_state_fix[OF stateful_policy_wf] have "flows_fix \<T> \<union> flows_state \<T> = flows_fix \<T>" by blast
from this compliant_stateful_ACS_static_valid have goalACS:
"all_security_requirements_fulfilled (get_ACS M) \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<union> flows_state \<T> \<rparr>" by simp
\<comment> \<open>ACS and IFS together form M, we know it holds for ACS\<close>
from goalACS goalIFS show ?thesis
apply(simp add: all_security_requirements_fulfilled_def get_IFS_def get_ACS_def)
by fastforce
qed
text\<open>The flows with state are a subset of the flows allowed by the policy\<close>
theorem flows_state_edges: "flows_state \<T> \<subseteq> edges G"
using wf_stateful_policy.E_state_fix[OF stateful_policy_wf] flows_edges by simp
text\<open>All offending flows are subsets of the reveres stateful flows\<close>
lemma compliant_stateful_ACS_only_state_violations:
"\<forall>F \<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<T>). F \<subseteq> backflows (flows_state \<T>)"
proof -
have "backflows (filternew_flows_state \<T>) \<subseteq> backflows (flows_state \<T>)" by (metis Diff_subset backflows_minus_backflows filternew_flows_state_alt)
from compliant_stateful_ACS this have
"\<forall> F \<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<T>). F \<subseteq> backflows (flows_state \<T>)"
by (metis subset_trans)
thus ?thesis .
qed
theorem compliant_stateful_ACS_only_state_violations': "\<forall>F \<in> get_offending_flows M (stateful_policy_to_network_graph \<T>). F \<subseteq> backflows (flows_state \<T>)"
proof -
from validReqs have valid_ReqsIFS: "valid_reqs (get_IFS M)" by(simp add: get_IFS_def valid_reqs_def)
have offending_split: "\<And>G. get_offending_flows M G = (get_offending_flows (get_IFS M) G \<union> get_offending_flows (get_ACS M) G)"
apply(simp add: get_offending_flows_def get_IFS_def get_ACS_def) by blast
show ?thesis
apply(subst offending_split)
using compliant_stateful_ACS_only_state_violations
all_security_requirements_fulfilled_imp_get_offending_empty[OF valid_ReqsIFS compliant_stateful_IFS]
by auto
qed
text \<open>All violations are backflows of valid flows\<close>
corollary compliant_stateful_ACS_only_state_violations_union: "\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \<T>)) \<subseteq> backflows (flows_state \<T>)"
using compliant_stateful_ACS_only_state_violations by fastforce
corollary compliant_stateful_ACS_only_state_violations_union': "\<Union>(get_offending_flows M (stateful_policy_to_network_graph \<T>)) \<subseteq> backflows (flows_state \<T>)"
using compliant_stateful_ACS_only_state_violations' by fastforce
text\<open>All individual flows cause no side effects, i.e. each backflow causes at most itself as violation, no other
side-effect violations are induced.\<close>
lemma compliant_stateful_ACS_no_state_singleflow_side_effect:
"\<forall> (v\<^sub>1, v\<^sub>2) \<in> backflows (flows_state \<T>).
\<Union>(get_offending_flows(get_ACS M) \<lparr> nodes = hosts \<T>, edges = flows_fix \<T> \<union> flows_state \<T> \<union> {(v\<^sub>1, v\<^sub>2)} \<rparr>) \<subseteq> {(v\<^sub>1, v\<^sub>2)}"
using compliant_stateful_ACS_no_side_effects' by blast
end
subsection\<open>Summarizing the important theorems\<close>
text\<open>No information flow security requirements are violated (including all added stateful flows)\<close>
thm stateful_policy_compliance.compliant_stateful_IFS
text\<open>There are not access control side effects when allowing stateful backflows.
I.e. for all possible subsets of the to-allow backflows, the violations they cause are only these backflows themselves\<close>
thm stateful_policy_compliance.compliant_stateful_ACS_no_side_effects'
text\<open>Also, considering all backflows individually, they cause no side effect, i.e. the only violation added is the backflow itself\<close>
thm stateful_policy_compliance.compliant_stateful_ACS_no_state_singleflow_side_effect
text\<open>In particular, all introduced offending flows for access control strategies are at most the stateful backflows\<close>
thm stateful_policy_compliance.compliant_stateful_ACS_only_state_violations_union
text\<open>Which implies: all introduced offending flows are at most the stateful backflows\<close>
thm stateful_policy_compliance.compliant_stateful_ACS_only_state_violations_union'
text\<open>Disregarding the backflows of stateful flows, all security requirements are fulfilled.\<close>
thm stateful_policy_compliance.compliant_stateful_ACS_static_valid'
end
|
# Turbine isentropic efficiency
A steam turbine performs with an isentropic efficiency of $\eta_t = 0.84$. The inlet conditions are 4 MPa and 650Β°C, with a mass flow rate of 100 kg/s, and the exit pressure is 10 kPa. Assume the turbine is adiabatic.
<figure>
<center>
<figcaption>Figure: Turbine</figcaption>
</center>
</figure>
**Problem:**
- Determine the power produced by the turbine
- Determine the rate of entropy generation
```python
import numpy as np
import cantera as ct
from pint import UnitRegistry
ureg = UnitRegistry()
Q_ = ureg.Quantity
```
We can start by specifying state 1 and the other known quantities:
```python
temp1 = Q_(650, 'degC')
pres1 = Q_(4, 'MPa')
state1 = ct.Water()
state1.TP = temp1.to('K').magnitude, pres1.to('Pa').magnitude
mass_flow_rate = Q_(100, 'kg/s')
efficiency = 0.84
pres2 = Q_(10, 'kPa')
```
To apply the isentropic efficiency, we'll need to separately consider the real turbine and an equivalent turbine operating in a reversible manner. They have the same initial conditions and mass flow rate.
For the reversible turbine, an entropy balance gives:
\begin{equation}
s_{s,2} = s_1
\end{equation}
and then with $P_2$ and $s_{s,2}$ we can fix state 2 for the reversible turbine:
```python
state2_rev = ct.Water()
state2_rev.SP = state1.s, pres2.to('Pa').magnitude
state2_rev()
```
water:
temperature 319.003 K
pressure 10000 Pa
density 0.07464 kg/m^3
mean mol. weight 18.016 amu
vapor fraction 0.912916
1 kg 1 kmol
----------- ------------
enthalpy -1.35945e+07 -2.449e+08 J
internal energy -1.37284e+07 -2.473e+08 J
entropy 11017.2 1.985e+05 J/K
Gibbs function -1.7109e+07 -3.082e+08 J
heat capacity c_p inf inf J/K
heat capacity c_v 100201 1.805e+06 J/K
Then, we can do an energy balance for the reversible turbine, which is also steady state and adiabatic:
\begin{equation}
\dot{m} h_1 = \dot{m} h_{s,2} + \dot{W}_{s,t}
\end{equation}
Then, recall that the isentropic efficiency is defined as
\begin{equation}
\eta_t = \frac{\dot{W}_t}{\dot{W}_{s,t}} \;,
\end{equation}
so we can obtain the actual turbine work using $\dot{W}_t = \eta_t \dot{W}_{s,t}$ :
```python
work_isentropic = mass_flow_rate * (
Q_(state1.h, 'J/kg') - Q_(state2_rev.h, 'J/kg')
)
work_actual = efficiency * work_isentropic
print(f'Actual turbine work: {work_actual.to(ureg.megawatt): .2f}')
```
Actual turbine work: 118.73 megawatt
Then, we can perform an energy balance on the actual turbine:
\begin{equation}
\dot{m} h_1 = \dot{m} h_2 + \dot{W}_t \;,
\end{equation}
which we can use with the exit pressure to fix state 2.
```python
enthalpy2 = Q_(state1.h, 'J/kg') - (work_actual / mass_flow_rate)
state2 = ct.Water()
state2.HP = enthalpy2.to('J/kg').magnitude, pres2.to('Pa').magnitude
state2()
```
water:
temperature 328.393 K
pressure 10000 Pa
density 0.0661646 kg/m^3
mean mol. weight 18.016 amu
vapor fraction 1
1 kg 1 kmol
----------- ------------
enthalpy -1.33683e+07 -2.408e+08 J
internal energy -1.35194e+07 -2.436e+08 J
entropy 11725.3 2.112e+05 J/K
Gibbs function -1.72188e+07 -3.102e+08 J
heat capacity c_p 1894.36 3.413e+04 J/K
heat capacity c_v 1423.02 2.564e+04 J/K
Finally, we can perform an entropy balance on the actual turbine:
\begin{equation}
\dot{m} s_1 + \dot{S}_{\text{gen}} = \dot{m} s_2 \;,
\end{equation}
which allows us to find the rate of entropy generation.
```python
entropy_gen = mass_flow_rate * (
Q_(state2.s, 'J/(kg K)') - Q_(state1.s, 'J/(kg K)')
)
print(f'rate of entropy generation: {entropy_gen.to("kW/K"): .2f}')
```
rate of entropy generation: 70.81 kilowatt / kelvin
```python
```
|
{-|
Module: Science.QuantumChemistry.NumericalTools.EigenValues
Description: Compute all the eigenvalues of the real symmetrical matrix
Copyright: @2016 Felipe Zapata
-}
module Science.QuantumChemistry.NumericalTools.EigenValues (
eigenSolve
) where
-- =============================> Standard and third party libraries <===============================
import Control.Arrow ((***))
import Data.Array.Repa as R
import Data.Vector.Storable (convert)
import qualified Data.Vector.Unboxed as U
import qualified Numeric.LinearAlgebra.Data as ND
import Numeric.LinearAlgebra.HMatrix (eigSH')
-- =================> Internal Modules <======================
import Science.QuantumChemistry.GlobalTypes (VecUnbox)
import Science.QuantumChemistry.NumericalTools.JacobiMethod (jacobiP)
import Science.QuantumChemistry.NumericalTools.VectorTools (sortEigenData)
-- | Compute all the eigenvalues and eigenvectors of symmetrical matrix.
eigenSolve :: Array U DIM2 Double -> (VecUnbox, Array U DIM2 Double)
eigenSolve arr = (vs, fromUnboxed (extent arr) mtx )
where (vs,mtx) = sortEigenData $ hv2VecUnbox *** hm2VecUnbox $ eigSH' $ repa2HM arr
vecUnbox2HV :: VecUnbox -> ND.Vector Double
vecUnbox2HV = convert
hv2VecUnbox :: ND.Vector Double -> VecUnbox
hv2VecUnbox = convert
repa2HM :: Array U DIM2 Double -> ND.Matrix Double
repa2HM arr = ND.reshape dim . convert . toUnboxed $ arr
where (Z :. dim :. _) = extent arr
hm2Repa :: ND.Matrix Double -> Array U DIM2 Double
hm2Repa mtx = fromUnboxed (ix2 dim dim) . convert . ND.flatten $ mtx
where dim = ND.rows mtx
hm2VecUnbox :: ND.Matrix Double -> VecUnbox
hm2VecUnbox = convert . ND.flatten
|
Michael Schumacher - a seven-time Formula One world champion is "not bedridden or living on tubes", it has been reported as new details about his recovery emerge.
It's nearly five years (December 29, 2013) since the 50 year old hit his head on a rock while skiing with his then 14-year-old son Mick in Meribel in the French Alps.
The multiple head injuries caused blood clots which were not entirely removed by doctors because of the extent of the injury.
He was placed into a medically induced coma to aid recovery from the accident, and he was gradually brought out of the coma in April of 2014.
Schumacher is believed to be receiving nursing and physiotherapy care at an estimated cost of more than Β£50,000 (Sh6.4m) a week.
According to The Daily Mail via German magazine Bravo, Schumacher is to be moved to a clinic in Dallas, Texas because he is claimed to be either intubated or bedridden.
Mark Weeks, the director, told the magazine: "We have a lot of experience with patients who are suffering this kind of trauma.
Schumacherβs family have always remained tight-lipped about the Germanβs condition leaving his fans in the dark about his health.
Currently Schumacher is being cared for by a team of medical experts at his luxury home in Gland near Lake Geneva in Switzerland. |
# functions to delete hybridization
# originally in functions.jl
# Claudia MArch 2015
# --------------------------------- delete hybridization -------------------------------
# function to identify inCycle (with priority queue)
# based on updateInCycle as it is the exact same code
# only without changing the incycle attribute
# only returning array of edges/nodes affected by the hybrid
# used when attempting to delete
# input: hybrid node around which we want to identify inCycle
# needs module "Base.Collections"
# returns tuple: nocycle, array of edges changed, array of nodes changed
# check: is this traversal much faster than a simple loop over
# all edges/nodes and check if incycle==hybrid.number?
function identifyInCycle(net::Network,node::Node)
node.hybrid || error("node $(node.number) is not hybrid, cannot identifyInCycle")
start = node;
hybedge = getHybridEdge(node);
last = getOtherNode(hybedge,node);
dist = 0;
queue = PriorityQueue();
path = Node[];
net.edges_changed = Edge[];
net.nodes_changed = Node[];
push!(net.edges_changed,hybedge);
push!(net.nodes_changed,node);
found = false;
net.visited = [false for i = 1:size(net.node,1)];
enqueue!(queue,node,dist);
while(!found)
if(isempty(queue))
return true, net.edges_changed, net.nodes_changed
else
curr = dequeue!(queue);
if(isEqual(curr,last))
found = true;
push!(path,curr);
else
if(!net.visited[getIndex(curr,net)])
net.visited[getIndex(curr,net)] = true;
if(isEqual(curr,start))
for e in curr.edge
if(!e.hybrid || e.isMajor)
other = getOtherNode(e,curr);
other.prev = curr;
dist = dist+1;
enqueue!(queue,other,dist);
end
end
else
for e in curr.edge
if(!e.hybrid || e.isMajor)
other = getOtherNode(e,curr);
if(!other.leaf && !net.visited[getIndex(other,net)])
other.prev = curr;
dist = dist+1;
enqueue!(queue,other,dist);
end
end
end
end
end
end
end
end # end while
curr = pop!(path);
while(!isEqual(curr, start))
if(curr.inCycle == start.number)
push!(net.nodes_changed, curr);
edge = getConnectingEdge(curr,curr.prev);
if(edge.inCycle == start.number)
push!(net.edges_changed, edge);
end
curr = curr.prev;
end
end
return false, net.edges_changed, net.nodes_changed
end
# aux function to traverse the network
# similar to traverseContainRoot but only
# identifying the edges that would be changed by a given
# hybridization
# warning: it does not go accross hybrid node/edge,
# nor tree node with minor hybrid edge
function traverseIdentifyRoot(node::Node, edge::Edge, edges_changed::Array{Edge,1})
if(!node.leaf && !node.hybrid)
for e in node.edge
if(!isEqual(edge,e) && e.isMajor && !e.hybrid)
other = getOtherNode(e,node);
push!(edges_changed, e);
if(!other.hybrid)
#if(!other.hasHybEdge)
traverseIdentifyRoot(other,e, edges_changed);
#else
# if(hybridEdges(other)[1].isMajor)
# traverseIdentifyRoot(other,e, edges_changed);
# end
#end
end
end
end
end
end
# function to identify containRoot
# depending on a hybrid node on the network
# input: hybrid node (can come from searchHybridNode)
# return array of edges affected by the hybrid node
function identifyContainRoot(net::HybridNetwork, node::Node)
node.hybrid || error("node $(node.number) is not hybrid, cannot identify containRoot")
net.edges_changed = Edge[];
for e in node.edge
if(!e.hybrid)
other = getOtherNode(e,node);
push!(net.edges_changed,e);
traverseIdentifyRoot(other,e, net.edges_changed);
end
end
return net.edges_changed
end
# function to undo the effect of a hybridization
# and then delete it
# input: network, hybrid node, random flag
# random = true, deletes one hybrid egde at random
# (minor with prob 1-gamma, major with prob gamma)
# random = false, deletes the minor edge always
# warning: it uses the gamma of the hybrid edges even if
# it is not identifiable like in bad diamond I (assumes undone by now)
# blacklist = true: add the edge as a bad choice to put a hybridization (not fully tested)
function deleteHybridizationUpdate!(net::HybridNetwork, hybrid::Node, random::Bool, blacklist::Bool)
global DEBUG
hybrid.hybrid || error("node $(hybrid.number) is not hybrid, so we cannot delete hybridization event around it")
DEBUG && println("MOVE: delete hybridization on hybrid node $(hybrid.number)")
nocycle, edgesInCycle, nodesInCycle = identifyInCycle(net,hybrid);
!nocycle || error("the hybrid node $(hybrid.number) does not create a cycle")
edgesRoot = identifyContainRoot(net,hybrid);
edges = hybridEdges(hybrid);
undoGammaz!(hybrid,net);
othermaj = getOtherNode(edges[1],hybrid)
edgesmaj = hybridEdges(othermaj)
DEBUG && println("edgesmaj[3] $(edgesmaj[3].number) is the one to check if containRoot=false already: $(edgesmaj[3].containRoot)")
if(edgesmaj[3].containRoot) #if containRoot=true, then we need to undo
push!(edgesRoot, edges[1]) ## add hybrid edges to edgesRoot to undo containRoot
push!(edgesRoot, edges[2])
undoContainRoot!(edgesRoot);
end
if(DEBUG)
edges[1].gamma >= 0.5 || println("strange major hybrid edge $(edges[1].number) with gamma $(edges[1].gamma) less than 0.5")
edges[1].gamma != 1.0 || println("strange major hybrid edge $(edges[1].number) with gamma $(edges[1].gamma) equal to 1.0")
end
limit = edges[1].gamma
if(random)
minor = rand() < limit ? false : true
else
minor = true;
end
deleteHybrid!(hybrid,net,minor, blacklist)
undoInCycle!(edgesInCycle, nodesInCycle); #moved after deleteHybrid to mantain who is incycle when deleteEdge and look for partition
undoPartition!(net,hybrid, edgesInCycle)
end
deleteHybridizationUpdate!(net::HybridNetwork, hybrid::Node) = deleteHybridizationUpdate!(net, hybrid, true, false)
# function to delete a hybridization event
# input: hybrid node and network
# minor: true (deletes minor edge), false (deletes major)
# warning: it is meant after undoing the effect of the
# hybridization in deleteHybridizationUpdate!
# by itself, it leaves things as is
# branch lengths of -1.0 are interpreted as missing.
function deleteHybrid!(node::Node,net::HybridNetwork,minor::Bool, blacklist::Bool)
node.hybrid || error("node $(node.number) has to be hybrid for deleteHybrid")
if(minor)
hybedge1,hybedge2,treeedge1 = hybridEdges(node);
other1 = getOtherNode(hybedge1,node);
other2 = getOtherNode(hybedge2,node);
other3 = getOtherNode(treeedge1,node);
if(hybedge1.number > treeedge1.number)
setLength!(treeedge1, addBL(treeedge1.length, hybedge1.length));
removeNode!(node,treeedge1);
setNode!(treeedge1,other1);
setEdge!(other1,treeedge1);
removeEdge!(other1, hybedge1);
deleteEdge!(net,hybedge1);
#treeedge1.containRoot = (!treeedge1.containRoot || !hybedge1.containRoot) ? false : true #causes problems if hybrid.CR=false
if(blacklist)
println("put in blacklist edge $(treeedge1.number)")
push!(net.blacklist, treeedge1.number)
end
else
makeEdgeTree!(hybedge1,node)
other1.hasHybEdge = false;
setLength!(hybedge1, addBL(hybedge1.length, treeedge1.length));
removeNode!(node,hybedge1);
setNode!(hybedge1,other3);
setEdge!(other3,hybedge1);
removeEdge!(other3,treeedge1);
deleteEdge!(net,treeedge1);
hybedge1.containRoot = (!treeedge1.containRoot || !hybedge1.containRoot) ? false : true
if(blacklist)
println("put in blacklist edge $(hybedge1.number)")
push!(net.blacklist, hybedge1.number)
end
end
hybindex = getIndex(true,[e.hybrid for e in other2.edge]);
if(hybindex == 1)
treeedge1 = other2.edge[2];
treeedge2 = other2.edge[3];
elseif(hybindex == 2)
treeedge1 = other2.edge[1];
treeedge2 = other2.edge[3];
elseif(hybindex == 3)
treeedge1 = other2.edge[1];
treeedge2 = other2.edge[2];
else
error("strange node has more than three edges")
end
treenode1 = getOtherNode(treeedge1,other2);
treenode2 = getOtherNode(treeedge2,other2);
if(abs(treeedge1.number) > abs(treeedge2.number))
setLength!(treeedge2, addBL(treeedge2.length, treeedge1.length));
removeNode!(other2,treeedge2);
setNode!(treeedge2,treenode1);
setEdge!(treenode1,treeedge2);
removeEdge!(treenode1,treeedge1);
deleteEdge!(net,treeedge1);
treeedge2.containRoot = (!treeedge1.containRoot || !treeedge2.containRoot) ? false : true
if(blacklist)
println("put in blacklist edge $(treeedge2.number)")
push!(net.blacklist, treeedge2.number)
end
else
setLength!(treeedge1, addBL(treeedge2.length, treeedge1.length));
removeNode!(other2,treeedge1);
setNode!(treeedge1,treenode2);
setEdge!(treenode2,treeedge1);
removeEdge!(treenode2,treeedge2);
deleteEdge!(net,treeedge2);
treeedge1.containRoot = (!treeedge1.containRoot || !treeedge2.containRoot) ? false : true
if(blacklist)
println("put in blacklist edge $(treeedge1.number)")
push!(net.blacklist, treeedge1.number)
end
end
#removeHybrid!(net,node);
deleteNode!(net,node);
deleteNode!(net,other2);
deleteEdge!(net,hybedge2);
else
hybedge1,hybedge2,treeedge1 = hybridEdges(node);
other1 = getOtherNode(hybedge1,node);
other2 = getOtherNode(hybedge2,node);
setLength!(treeedge1, addBL(treeedge1.length, hybedge2.length))
removeEdge!(other2,hybedge2)
removeNode!(node,treeedge1)
setEdge!(other2,treeedge1)
setNode!(treeedge1,other2)
#removeHybrid!(net,node)
deleteNode!(net,node)
deleteEdge!(net,hybedge1)
deleteEdge!(net,hybedge2)
removeEdge!(other1,hybedge1)
size(other1.edge,1) == 2 || error("strange node $(other1.number) had 4 edges")
if(abs(other1.edge[1].number) < abs(other1.edge[2].number))
edge = other1.edge[1]
otheredge = other1.edge[2]
else
edge = other1.edge[2]
otheredge = other1.edge[1]
end
setLength!(other1.edge[1], addBL(other1.edge[1].length, other1.edge[2].length))
other3 = getOtherNode(otheredge,other1);
removeNode!(other1,edge)
removeEdge!(other3,otheredge)
setEdge!(other3,edge)
setNode!(edge,other3)
deleteNode!(net,other1)
deleteEdge!(net,otheredge)
end
end
deleteHybrid!(node::Node,net::HybridNetwork,minor::Bool) = deleteHybrid!(node,net,minor, false)
"""
`deleteHybridEdge!(net::HybridNetwork,edge::Edge)`
Deletes a hybrid edge from a network. The network does not have to be of level 1,
and may contain some polytomies. Updates branch lengths, allowing for missing values.
Returns the network.
At each of the 2 junctions, the child edge is retained (i.e. the tree edge is retained,
below the hybrid node).
Warnings:
- does **not** update containRoot (could be implemented later)
- does **not** update attributes needed for snaq! (like containRoot, inCycle, edge.z, edge.y etc.)
- if the parent of edge is the root, the root will be moved to keep the network unrooted
with a root of degree two.
"""
function deleteHybridEdge!(net::HybridNetwork,edge::Edge)
edge.hybrid || error("edge $(edge.number) has to be hybrid for deleteHybridEdge!")
n1 = (edge.isChild1 ? edge.node[1] : edge.node[2]) # child of edge, to be deleted
n1.hybrid || error("child node $(n1.number) of hybrid edge $(edge.number) should be a hybrid.")
n2 = (edge.isChild1 ? edge.node[2] : edge.node[1]) # parent of edge, to be deleted too.
# next: keep hybrid node n1 if it has 4+ edges (2 parents and 2+ children).
# 2 or 1 edges should never occur.
if length(n1.edge) < 3
error("node $(n1.number) has $length(n1.edge) edges instead of 3+");
elseif length(n1.edge) == 3
pe = nothing # will be other parent (hybrid) edge of n1
ce = nothing # will be child edge of n1, to be merged with pe
for e in n1.edge
if (e.hybrid && e!=edge) pe = e; end
if !(e.hybrid) ce = e; end
end
pn = getOtherNode(pe,n1); # parent node of n1, other than n2
pn β’ n2 || error("k=2 cycle: 2 hybrid edges from node $(n2.number) to node $(n1.number)")
atRoot = (net.node[net.root] β‘ n1) # n1 should not be root, but if so, pn will be new root
# next: replace ce by pe+ce, remove n1 and pe from network.
ce.length = addBL(ce.length, pe.length)
removeNode!(n1,ce) # ce now has 1 single node cn
setNode!(ce,pn) # ce now has 2 nodes in this order: cn, pn
ce.isChild1 = true
setEdge!(pn,ce)
removeEdge!(pn,pe)
# if (pe.number<ce.number) ce.number = pe.number; end # bad to match edges between networks
deleteEdge!(net,pe,part=false) # decreases net.numEdges by 1
deleteNode!(net,n1) # decreases net.numHybrids by 1, numNodes too.
# warning: containRoot could be updated in ce and down the tree.
if (atRoot)
try
net.root = getIndex(pn,net)
catch e
if isa(e, ErrorException) error("node $(pn.number) not in net!"); end
end
end
else # n1 has 4+ edges (polytomy): keep n2 but detach it from 'edge'
removeEdge!(n1,edge) # does not update n1.hybrid at this time
warn("polytomy at node $(n1.number). Assuming only 2 hybrid parents, though.")
n1.hybrid = false
end
# next: keep n2 if it has 4+ edges. 2 or 1 edges should never occur.
# If root, would have no parent: treat network as unrooted and change the root.
if length(n2.edge) < 2
error("node $(n2.number) (parent of hybrid edge $(edge.number) to be deleted) has 1 edge only!")
elseif length(n2.edge) == 2 # if n2=root or degree-2 node
# remove n2 and both of its edges (including 'edge')
pe = (edge β‘ n2.edge[1] ? n2.edge[2] : n2.edge[1]) # <--edge-- n2 ---pe--- pn
pn = ( n2 β‘ pe.node[1] ? pe.node[2] : pe.node[1])
if net.node[net.root] β‘ n2 # if n2 was root, new root = pn
net.root = getIndex(pn, net)
end
# remove n2 and pe
removeEdge!(pn,pe)
deleteEdge!(net,pe,part=false)
deleteNode!(net,n2)
elseif length(n2.edge) == 3
oei = Int[] # n2's edges' indices, other than 'edge'.
for i=1:length(n2.edge)
if (n2.edge[i] != edge) push!(oei, i); end
end
length(oei)==2 || error("node $(n2.number) has 3 edges, but $(length(oei)) different from edge $(edge.number)")
ce = n2.edge[oei[1]] # ce will be kept
pe = n2.edge[oei[2]] # pe will be folded into new ce = pe+ce
switch = false
if getOtherNode(pe, n2).leaf
!getOtherNode(ce, n2).leaf ||
error("root $(n2.number) connected to 1 hybrid and 2 leaves: edges $(pe.number) and $(ce.number).")
switch = true
elseif (n2 β‘ ce.node[(ce.isChild1 ? 1 : 2)]) && (n2 β‘ pe.node[(pe.isChild1 ? 2 : 1)])
switch = true
end
if switch # to ensure correct direction isChild1 for new edges if the original was up-to-date
ce = n2.edge[oei[2]] # but no error if original isChild1 was outdated
pe = n2.edge[oei[1]] # and to ensure that pn can be the new root if needed.
end
atRoot = (net.node[net.root] β‘ n2) # if n2=root, new root will be 'pn' = other node of pe
# next: replace ce by pe+ce, remove n2 and pe from network.
pn = getOtherNode(pe,n2) # parent node of n2 if n2 not root. Otherwise, pn will be new root.
ce.length = addBL(ce.length, pe.length)
removeNode!(n2,ce) # ce now has 1 single node cn
setNode!(ce,pn) # ce now has 2 nodes in this order: cn, pn
ce.isChild1 = true
setEdge!(pn,ce)
removeEdge!(pn,pe)
# if (pe.number<ce.number) ce.number = pe.number; end # bad to match edges between networks
deleteEdge!(net,pe,part=false)
deleteNode!(net,n2)
if (atRoot)
try
net.root = getIndex(pn,net)
catch e
if isa(e, ErrorException) error("node $(pn.number) not in net!"); end
end
end
else # n2 has 4+ edges (polytomy): keep n2 but detach it from 'edge'
removeEdge!(n2,edge)
end
# finally: remove hybrid 'edge' from network
deleteEdge!(net,edge,part=false)
return net
end
# function to update net.partition after deleting a hybrid node
# needs a list of the edges in cycle
function undoPartition!(net::HybridNetwork, hybrid::Node, edgesInCycle::Vector{Edge})
global DEBUG
hybrid.hybrid || error("node $(hybrid.number) is not hybrid, and we need hybrid node inside deleteHybUpdate for undoPartition")
if(net.numHybrids == 0)
net.partition = Partition[]
else
cycles = Int[]
edges = Edge[]
N = length(net.partition)
i = 1
while(i <= N)
DEBUG && println("hybrid number is $(hybrid.number) and partition is $([e.number for e in net.partition[i].edges]), with cycle $(net.partition[i].cycle)")
if(in(hybrid.number,net.partition[i].cycle))
DEBUG && println("hybrid number matches with partition.cycle")
p = splice!(net.partition,i)
DEBUG && println("after splice, p partition has edges $([e.number for e in p.edges]) and cycle $(p.cycle)")
ind = getIndex(hybrid.number,p.cycle)
deleteat!(p.cycle,ind) #get rid of that hybrid number
cycles = vcat(cycles,p.cycle)
edges = vcat(edges,p.edges)
DEBUG && println("edges is $([e.number for e in edges]) and cycles is $(cycles)")
N = length(net.partition)
else
i += 1
end
end
for e in edgesInCycle
DEBUG && println("edge in cycle is $(e.number)")
if(isEdgeNumIn(e,net.edge)) #only include edge if still in net
DEBUG && println("edge is in net still")
push!(edges,e)
end
end
newPartition = Partition(unique(cycles),edges)
DEBUG && println("new partition with cycle $(newPartition.cycle), edges $([e.number for e in newPartition.edges])")
push!(net.partition,newPartition)
end
end
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.logic.embedding
import Mathlib.order.rel_classes
import Mathlib.data.set.intervals.basic
import Mathlib.PostPort
universes u_4 u_5 l u_1 u_2 u_3
namespace Mathlib
/-- A relation homomorphism with respect to a given pair of relations `r` and `s`
is a function `f : Ξ± β Ξ²` such that `r a b β s (f a) (f b)`. -/
structure rel_hom {Ξ± : Type u_4} {Ξ² : Type u_5} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) where
to_fun : Ξ± β Ξ²
map_rel' : β {a b : Ξ±}, r a b β s (to_fun a) (to_fun b)
infixl:25 " βr " => Mathlib.rel_hom
namespace rel_hom
protected instance has_coe_to_fun {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} : has_coe_to_fun (r βr s) :=
has_coe_to_fun.mk (fun (_x : r βr s) => Ξ± β Ξ²) fun (o : r βr s) => to_fun o
theorem map_rel {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (f : r βr s)
{a : Ξ±} {b : Ξ±} : r a b β s (coe_fn f a) (coe_fn f b) :=
map_rel' f
@[simp] theorem coe_fn_mk {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : Ξ± β Ξ²) (o : β {a b : Ξ±}, r a b β s (f a) (f b)) : β(mk f o) = f :=
rfl
@[simp] theorem coe_fn_to_fun {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) : to_fun f = βf :=
rfl
/-- The map `coe_fn : (r βr s) β (Ξ± β Ξ²)` is injective. We can't use `function.injective`
here but mimic its signature by using `β¦eβ eββ¦`. -/
theorem coe_fn_inj {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {eβ : r βr s}
{eβ : r βr s} : βeβ = βeβ β eβ = eβ :=
sorry
theorem ext {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {f : r βr s}
{g : r βr s} (h : β (x : Ξ±), coe_fn f x = coe_fn g x) : f = g :=
coe_fn_inj (funext h)
theorem ext_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {f : r βr s}
{g : r βr s} : f = g β β (x : Ξ±), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : Ξ±) => h βΈ rfl,
mpr := fun (h : β (x : Ξ±), coe_fn f x = coe_fn g x) => ext h }
/-- Identity map is a relation homomorphism. -/
protected def id {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) : r βr r := mk id sorry
/-- Composition of two relation homomorphisms is a relation homomorphism. -/
protected def comp {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop} (g : s βr t) (f : r βr s) : r βr t :=
mk (to_fun g β to_fun f) sorry
@[simp] theorem id_apply {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} (x : Ξ±) : coe_fn (rel_hom.id r) x = x :=
rfl
@[simp] theorem comp_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop} (g : s βr t) (f : r βr s) (a : Ξ±) :
coe_fn (rel_hom.comp g f) a = coe_fn g (coe_fn f a) :=
rfl
/-- A relation homomorphism is also a relation homomorphism between dual relations. -/
protected def swap {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) : function.swap r βr function.swap s :=
mk βf sorry
/-- A function is a relation homomorphism from the preimage relation of `s` to `s`. -/
def preimage {Ξ± : Type u_1} {Ξ² : Type u_2} (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) : f β»ΒΉ'o s βr s :=
mk f sorry
protected theorem is_irrefl {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) [is_irrefl Ξ² s] : is_irrefl Ξ± r :=
sorry
protected theorem is_asymm {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) [is_asymm Ξ² s] : is_asymm Ξ± r :=
sorry
protected theorem acc {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) (a : Ξ±) : acc s (coe_fn f a) β acc r a :=
sorry
protected theorem well_founded {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) (h : well_founded s) : well_founded r :=
well_founded.dcases_on h
fun (h : β (a : Ξ²), acc s a) =>
idRhs (well_founded r) (well_founded.intro fun (a : Ξ±) => rel_hom.acc f a (h (coe_fn f a)))
theorem map_inf {Ξ± : Type u_1} {Ξ² : Type u_2} [semilattice_inf Ξ±] [linear_order Ξ²]
(a : Less βr Less) (m : Ξ²) (n : Ξ²) : coe_fn a (m β n) = coe_fn a m β coe_fn a n :=
sorry
theorem map_sup {Ξ± : Type u_1} {Ξ² : Type u_2} [semilattice_sup Ξ±] [linear_order Ξ²] (a : gt βr gt)
(m : Ξ²) (n : Ξ²) : coe_fn a (m β n) = coe_fn a m β coe_fn a n :=
sorry
end rel_hom
/-- An increasing function is injective -/
theorem injective_of_increasing {Ξ± : Type u_1} {Ξ² : Type u_2} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop)
[is_trichotomous Ξ± r] [is_irrefl Ξ² s] (f : Ξ± β Ξ²) (hf : β {x y : Ξ±}, r x y β s (f x) (f y)) :
function.injective f :=
sorry
/-- An increasing function is injective -/
theorem rel_hom.injective_of_increasing {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} [is_trichotomous Ξ± r] [is_irrefl Ξ² s] (f : r βr s) : function.injective βf :=
injective_of_increasing r s βf fun (x y : Ξ±) => rel_hom.map_rel f
theorem surjective.well_founded_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {f : Ξ± β Ξ²} (hf : function.surjective f)
(o : β {a b : Ξ±}, r a b β s (f a) (f b)) : well_founded r β well_founded s :=
sorry
/-- A relation embedding with respect to a given pair of relations `r` and `s`
is an embedding `f : Ξ± βͺ Ξ²` such that `r a b β s (f a) (f b)`. -/
structure rel_embedding {Ξ± : Type u_4} {Ξ² : Type u_5} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop)
extends Ξ± βͺ Ξ² where
map_rel_iff' : β {a b : Ξ±}, s (coe_fn _to_embedding a) (coe_fn _to_embedding b) β r a b
infixl:25 " βͺr " => Mathlib.rel_embedding
/-- An order embedding is an embedding `f : Ξ± βͺ Ξ²` such that `a β€ b β (f a) β€ (f b)`.
This definition is an abbreviation of `rel_embedding (β€) (β€)`. -/
def order_embedding (Ξ± : Type u_1) (Ξ² : Type u_2) [HasLessEq Ξ±] [HasLessEq Ξ²] := LessEq βͺr LessEq
infixl:25 " βͺo " => Mathlib.order_embedding
/-- The induced relation on a subtype is an embedding under the natural inclusion. -/
def subtype.rel_embedding {X : Type u_1} (r : X β X β Prop) (p : X β Prop) :
subtype.val β»ΒΉ'o r βͺr r :=
rel_embedding.mk (function.embedding.subtype p) sorry
theorem preimage_equivalence {Ξ± : Sort u_1} {Ξ² : Sort u_2} (f : Ξ± β Ξ²) {s : Ξ² β Ξ² β Prop}
(hs : equivalence s) : equivalence (f β»ΒΉ'o s) :=
sorry
namespace rel_embedding
/-- A relation embedding is also a relation homomorphism -/
def to_rel_hom {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (f : r βͺr s) :
r βr s :=
rel_hom.mk (function.embedding.to_fun (to_embedding f)) sorry
-- see Note [function coercion]
protected instance rel_hom.has_coe {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} : has_coe (r βͺr s) (r βr s) :=
has_coe.mk to_rel_hom
protected instance has_coe_to_fun {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} : has_coe_to_fun (r βͺr s) :=
has_coe_to_fun.mk (fun (_x : r βͺr s) => Ξ± β Ξ²) fun (o : r βͺr s) => β(to_embedding o)
@[simp] theorem to_rel_hom_eq_coe {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) : to_rel_hom f = βf :=
rfl
@[simp] theorem coe_coe_fn {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) : ββf = βf :=
rfl
theorem injective {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (f : r βͺr s) :
function.injective βf :=
function.embedding.inj' (to_embedding f)
theorem map_rel_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (f : r βͺr s)
{a : Ξ±} {b : Ξ±} : s (coe_fn f a) (coe_fn f b) β r a b :=
map_rel_iff' f
@[simp] theorem coe_fn_mk {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : Ξ± βͺ Ξ²) (o : β {a b : Ξ±}, s (coe_fn f a) (coe_fn f b) β r a b) : β(mk f o) = βf :=
rfl
@[simp] theorem coe_fn_to_embedding {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) : β(to_embedding f) = βf :=
rfl
/-- The map `coe_fn : (r βͺr s) β (Ξ± β Ξ²)` is injective. We can't use `function.injective`
here but mimic its signature by using `β¦eβ eββ¦`. -/
theorem coe_fn_inj {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {eβ : r βͺr s}
{eβ : r βͺr s} : βeβ = βeβ β eβ = eβ :=
sorry
theorem ext {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {f : r βͺr s}
{g : r βͺr s} (h : β (x : Ξ±), coe_fn f x = coe_fn g x) : f = g :=
coe_fn_inj (funext h)
theorem ext_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {f : r βͺr s}
{g : r βͺr s} : f = g β β (x : Ξ±), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : Ξ±) => h βΈ rfl,
mpr := fun (h : β (x : Ξ±), coe_fn f x = coe_fn g x) => ext h }
/-- Identity map is a relation embedding. -/
protected def refl {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) : r βͺr r :=
mk (function.embedding.refl Ξ±) sorry
/-- Composition of two relation embeddings is a relation embedding. -/
protected def trans {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop} (f : r βͺr s) (g : s βͺr t) : r βͺr t :=
mk (function.embedding.trans (to_embedding f) (to_embedding g)) sorry
protected instance inhabited {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) : Inhabited (r βͺr r) :=
{ default := rel_embedding.refl r }
@[simp] theorem refl_apply {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} (x : Ξ±) :
coe_fn (rel_embedding.refl r) x = x :=
rfl
theorem trans_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop} (f : r βͺr s) (g : s βͺr t) (a : Ξ±) :
coe_fn (rel_embedding.trans f g) a = coe_fn g (coe_fn f a) :=
rfl
@[simp] theorem coe_trans {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop} (f : r βͺr s) (g : s βͺr t) :
β(rel_embedding.trans f g) = βg β βf :=
rfl
/-- A relation embedding is also a relation embedding between dual relations. -/
protected def swap {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) : function.swap r βͺr function.swap s :=
mk (to_embedding f) sorry
/-- If `f` is injective, then it is a relation embedding from the
preimage relation of `s` to `s`. -/
def preimage {Ξ± : Type u_1} {Ξ² : Type u_2} (f : Ξ± βͺ Ξ²) (s : Ξ² β Ξ² β Prop) : βf β»ΒΉ'o s βͺr s :=
mk f sorry
theorem eq_preimage {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) : r = βf β»ΒΉ'o s :=
funext fun (a : Ξ±) => funext fun (b : Ξ±) => propext (iff.symm (map_rel_iff f))
protected theorem is_irrefl {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_irrefl Ξ² s] : is_irrefl Ξ± r :=
is_irrefl.mk fun (a : Ξ±) => mt (iff.mpr (map_rel_iff f)) (irrefl (coe_fn f a))
protected theorem is_refl {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_refl Ξ² s] : is_refl Ξ± r :=
is_refl.mk fun (a : Ξ±) => iff.mp (map_rel_iff f) (refl (coe_fn f a))
protected theorem is_symm {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_symm Ξ² s] : is_symm Ξ± r :=
is_symm.mk fun (a b : Ξ±) => imp_imp_imp (iff.mpr (map_rel_iff f)) (iff.mp (map_rel_iff f)) symm
protected theorem is_asymm {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_asymm Ξ² s] : is_asymm Ξ± r :=
is_asymm.mk
fun (a b : Ξ±) (hβ : r a b) (hβ : r b a) =>
asymm (iff.mpr (map_rel_iff f) hβ) (iff.mpr (map_rel_iff f) hβ)
protected theorem is_antisymm {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_antisymm Ξ² s] : is_antisymm Ξ± r :=
sorry
protected theorem is_trans {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_trans Ξ² s] : is_trans Ξ± r :=
sorry
protected theorem is_total {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_total Ξ² s] : is_total Ξ± r :=
sorry
protected theorem is_preorder {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_preorder Ξ² s] : is_preorder Ξ± r :=
idRhs (is_preorder Ξ± r) is_preorder.mk
protected theorem is_partial_order {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) [is_partial_order Ξ² s] : is_partial_order Ξ± r :=
idRhs (is_partial_order Ξ± r) is_partial_order.mk
protected theorem is_linear_order {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) [is_linear_order Ξ² s] : is_linear_order Ξ± r :=
idRhs (is_linear_order Ξ± r) is_linear_order.mk
protected theorem is_strict_order {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) [is_strict_order Ξ² s] : is_strict_order Ξ± r :=
idRhs (is_strict_order Ξ± r) is_strict_order.mk
protected theorem is_trichotomous {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) [is_trichotomous Ξ² s] : is_trichotomous Ξ± r :=
sorry
protected theorem is_strict_total_order' {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) [is_strict_total_order' Ξ² s] : is_strict_total_order' Ξ± r :=
idRhs (is_strict_total_order' Ξ± r) is_strict_total_order'.mk
protected theorem acc {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) (a : Ξ±) : acc s (coe_fn f a) β acc r a :=
sorry
protected theorem well_founded {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) (h : well_founded s) : well_founded r :=
well_founded.dcases_on h
fun (h : β (a : Ξ²), acc s a) =>
idRhs (well_founded r)
(well_founded.intro fun (a : Ξ±) => rel_embedding.acc f a (h (coe_fn f a)))
protected theorem is_well_order {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βͺr s) [is_well_order Ξ² s] : is_well_order Ξ± r :=
idRhs (is_well_order Ξ± r) (is_well_order.mk (rel_embedding.well_founded f is_well_order.wf))
/-- It suffices to prove `f` is monotone between strict relations
to show it is a relation embedding. -/
def of_monotone {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
[is_trichotomous Ξ± r] [is_asymm Ξ² s] (f : Ξ± β Ξ²) (H : β (a b : Ξ±), r a b β s (f a) (f b)) :
r βͺr s :=
mk (function.embedding.mk f sorry) sorry
@[simp] theorem of_monotone_coe {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
[is_trichotomous Ξ± r] [is_asymm Ξ² s] (f : Ξ± β Ξ²) (H : β (a b : Ξ±), r a b β s (f a) (f b)) :
β(of_monotone f H) = f :=
rfl
/-- Embeddings of partial orders that preserve `<` also preserve `β€` -/
def order_embedding_of_lt_embedding {Ξ± : Type u_1} {Ξ² : Type u_2} [partial_order Ξ±]
[partial_order Ξ²] (f : Less βͺr Less) : Ξ± βͺo Ξ² :=
mk (to_embedding f) sorry
end rel_embedding
namespace order_embedding
/-- lt is preserved by order embeddings of preorders -/
def lt_embedding {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²) :
Less βͺr Less :=
rel_embedding.mk (rel_embedding.to_embedding f) sorry
@[simp] theorem lt_embedding_apply {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²]
(f : Ξ± βͺo Ξ²) (x : Ξ±) : coe_fn (lt_embedding f) x = coe_fn f x :=
rfl
@[simp] theorem le_iff_le {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²)
{a : Ξ±} {b : Ξ±} : coe_fn f a β€ coe_fn f b β a β€ b :=
rel_embedding.map_rel_iff f
@[simp] theorem lt_iff_lt {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²)
{a : Ξ±} {b : Ξ±} : coe_fn f a < coe_fn f b β a < b :=
rel_embedding.map_rel_iff (lt_embedding f)
@[simp] theorem eq_iff_eq {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²)
{a : Ξ±} {b : Ξ±} : coe_fn f a = coe_fn f b β a = b :=
function.injective.eq_iff (rel_embedding.injective f)
protected theorem monotone {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²) :
monotone βf :=
fun (x y : Ξ±) => iff.mpr (le_iff_le f)
protected theorem strict_mono {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²) :
strict_mono βf :=
fun (x y : Ξ±) => iff.mpr (lt_iff_lt f)
protected theorem acc {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²) (a : Ξ±) :
acc Less (coe_fn f a) β acc Less a :=
rel_embedding.acc (lt_embedding f) a
protected theorem well_founded {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²]
(f : Ξ± βͺo Ξ²) : well_founded Less β well_founded Less :=
rel_embedding.well_founded (lt_embedding f)
protected theorem is_well_order {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²)
[is_well_order Ξ² Less] : is_well_order Ξ± Less :=
rel_embedding.is_well_order (lt_embedding f)
/-- An order embedding is also an order embedding between dual orders. -/
protected def dual {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²) :
order_dual Ξ± βͺo order_dual Ξ² :=
rel_embedding.mk (rel_embedding.to_embedding f) sorry
/-- A sctrictly monotone map from a linear order is an order embedding. --/
def of_strict_mono {Ξ± : Type u_1} {Ξ² : Type u_2} [linear_order Ξ±] [preorder Ξ²] (f : Ξ± β Ξ²)
(h : strict_mono f) : Ξ± βͺo Ξ² :=
rel_embedding.mk (function.embedding.mk f (strict_mono.injective h)) sorry
@[simp] theorem coe_of_strict_mono {Ξ± : Type u_1} {Ξ² : Type u_2} [linear_order Ξ±] [preorder Ξ²]
{f : Ξ± β Ξ²} (h : strict_mono f) : β(of_strict_mono f h) = f :=
rfl
/-- Embedding of a subtype into the ambient type as an `order_embedding`. -/
def subtype {Ξ± : Type u_1} [preorder Ξ±] (p : Ξ± β Prop) : Subtype p βͺo Ξ± :=
rel_embedding.mk (function.embedding.subtype p) sorry
@[simp] theorem coe_subtype {Ξ± : Type u_1} [preorder Ξ±] (p : Ξ± β Prop) : β(subtype p) = coe := rfl
end order_embedding
/-- A relation isomorphism is an equivalence that is also a relation embedding. -/
structure rel_iso {Ξ± : Type u_4} {Ξ² : Type u_5} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) extends Ξ± β Ξ²
where
map_rel_iff' : β {a b : Ξ±}, s (coe_fn _to_equiv a) (coe_fn _to_equiv b) β r a b
infixl:25 " βr " => Mathlib.rel_iso
/-- An order isomorphism is an equivalence such that `a β€ b β (f a) β€ (f b)`.
This definition is an abbreviation of `rel_iso (β€) (β€)`. -/
def order_iso (Ξ± : Type u_1) (Ξ² : Type u_2) [HasLessEq Ξ±] [HasLessEq Ξ²] := LessEq βr LessEq
infixl:25 " βo " => Mathlib.order_iso
namespace rel_iso
/-- Convert an `rel_iso` to an `rel_embedding`. This function is also available as a coercion
but often it is easier to write `f.to_rel_embedding` than to write explicitly `r` and `s`
in the target type. -/
def to_rel_embedding {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) : r βͺr s :=
rel_embedding.mk (equiv.to_embedding (to_equiv f)) (map_rel_iff' f)
-- see Note [function coercion]
protected instance rel_embedding.has_coe {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} : has_coe (r βr s) (r βͺr s) :=
has_coe.mk to_rel_embedding
protected instance has_coe_to_fun {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} : has_coe_to_fun (r βr s) :=
has_coe_to_fun.mk (fun (_x : r βr s) => Ξ± β Ξ²) fun (f : r βr s) => βf
@[simp] theorem to_rel_embedding_eq_coe {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βr s) : to_rel_embedding f = βf :=
rfl
@[simp] theorem coe_coe_fn {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) : ββf = βf :=
rfl
theorem map_rel_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (f : r βr s)
{a : Ξ±} {b : Ξ±} : s (coe_fn f a) (coe_fn f b) β r a b :=
map_rel_iff' f
@[simp] theorem coe_fn_mk {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : Ξ± β Ξ²) (o : β {a b : Ξ±}, s (coe_fn f a) (coe_fn f b) β r a b) : β(mk f o) = βf :=
rfl
@[simp] theorem coe_fn_to_equiv {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) : β(to_equiv f) = βf :=
rfl
theorem injective_to_equiv {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} :
function.injective to_equiv :=
sorry
/-- The map `coe_fn : (r βr s) β (Ξ± β Ξ²)` is injective. Lean fails to parse
`function.injective (Ξ» e : r βr s, (e : Ξ± β Ξ²))`, so we use a trick to say the same. -/
theorem injective_coe_fn {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} :
function.injective fun (e : r βr s) (x : Ξ±) => coe_fn e x :=
function.injective.comp equiv.injective_coe_fn injective_to_equiv
theorem ext {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {f : r βr s}
{g : r βr s} (h : β (x : Ξ±), coe_fn f x = coe_fn g x) : f = g :=
injective_coe_fn (funext h)
theorem ext_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {f : r βr s}
{g : r βr s} : f = g β β (x : Ξ±), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : Ξ±) => h βΈ rfl,
mpr := fun (h : β (x : Ξ±), coe_fn f x = coe_fn g x) => ext h }
/-- Identity map is a relation isomorphism. -/
protected def refl {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) : r βr r := mk (equiv.refl Ξ±) sorry
/-- Inverse map of a relation isomorphism is a relation isomorphism. -/
protected def symm {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) : s βr r :=
mk (equiv.symm (to_equiv f)) sorry
/-- Composition of two relation isomorphisms is a relation isomorphism. -/
protected def trans {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop} (fβ : r βr s) (fβ : s βr t) : r βr t :=
mk (equiv.trans (to_equiv fβ) (to_equiv fβ)) sorry
protected instance inhabited {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) : Inhabited (r βr r) :=
{ default := rel_iso.refl r }
@[simp] theorem default_def {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) :
Inhabited.default = rel_iso.refl r :=
rfl
/-- a relation isomorphism is also a relation isomorphism between dual relations. -/
protected def swap {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) : function.swap r βr function.swap s :=
mk (to_equiv f) sorry
@[simp] theorem coe_fn_symm_mk {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : Ξ± β Ξ²) (o : β {a b : Ξ±}, s (coe_fn f a) (coe_fn f b) β r a b) :
β(rel_iso.symm (mk f o)) = β(equiv.symm f) :=
rfl
@[simp] theorem refl_apply {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} (x : Ξ±) :
coe_fn (rel_iso.refl r) x = x :=
rfl
@[simp] theorem trans_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop} (f : r βr s) (g : s βr t) (a : Ξ±) :
coe_fn (rel_iso.trans f g) a = coe_fn g (coe_fn f a) :=
rfl
@[simp] theorem apply_symm_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) (x : Ξ²) : coe_fn e (coe_fn (rel_iso.symm e) x) = x :=
equiv.apply_symm_apply (to_equiv e) x
@[simp] theorem symm_apply_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) (x : Ξ±) : coe_fn (rel_iso.symm e) (coe_fn e x) = x :=
equiv.symm_apply_apply (to_equiv e) x
theorem rel_symm_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) {x : Ξ±} {y : Ξ²} : r x (coe_fn (rel_iso.symm e) y) β s (coe_fn e x) y :=
sorry
theorem symm_apply_rel {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) {x : Ξ²} {y : Ξ±} : r (coe_fn (rel_iso.symm e) x) y β s x (coe_fn e y) :=
sorry
protected theorem bijective {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) : function.bijective βe :=
equiv.bijective (to_equiv e)
protected theorem injective {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) : function.injective βe :=
equiv.injective (to_equiv e)
protected theorem surjective {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) : function.surjective βe :=
equiv.surjective (to_equiv e)
@[simp] theorem range_eq {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(e : r βr s) : set.range βe = set.univ :=
function.surjective.range_eq (rel_iso.surjective e)
@[simp] theorem eq_iff_eq {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(f : r βr s) {a : Ξ±} {b : Ξ±} : coe_fn f a = coe_fn f b β a = b :=
function.injective.eq_iff (rel_iso.injective f)
/-- Any equivalence lifts to a relation isomorphism between `s` and its preimage. -/
protected def preimage {Ξ± : Type u_1} {Ξ² : Type u_2} (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) :
βf β»ΒΉ'o s βr s :=
mk f sorry
/-- A surjective relation embedding is a relation isomorphism. -/
def of_surjective {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (f : r βͺr s)
(H : function.surjective βf) : r βr s :=
mk (equiv.of_bijective βf sorry) sorry
@[simp] theorem of_surjective_coe {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (f : r βͺr s) (H : function.surjective βf) : β(of_surjective f H) = βf :=
rfl
/--
Given relation isomorphisms `rβ βr rβ` and `sβ βr sβ`, construct a relation isomorphism for the
lexicographic orders on the sum.
-/
def sum_lex_congr {Ξ±β : Type u_1} {Ξ±β : Type u_2} {Ξ²β : Type u_3} {Ξ²β : Type u_4}
{rβ : Ξ±β β Ξ±β β Prop} {rβ : Ξ±β β Ξ±β β Prop} {sβ : Ξ²β β Ξ²β β Prop} {sβ : Ξ²β β Ξ²β β Prop}
(eβ : rβ βr rβ) (eβ : sβ βr sβ) : sum.lex rβ sβ βr sum.lex rβ sβ :=
mk (equiv.sum_congr (to_equiv eβ) (to_equiv eβ)) sorry
/--
Given relation isomorphisms `rβ βr rβ` and `sβ βr sβ`, construct a relation isomorphism for the
lexicographic orders on the product.
-/
def prod_lex_congr {Ξ±β : Type u_1} {Ξ±β : Type u_2} {Ξ²β : Type u_3} {Ξ²β : Type u_4}
{rβ : Ξ±β β Ξ±β β Prop} {rβ : Ξ±β β Ξ±β β Prop} {sβ : Ξ²β β Ξ²β β Prop} {sβ : Ξ²β β Ξ²β β Prop}
(eβ : rβ βr rβ) (eβ : sβ βr sβ) : prod.lex rβ sβ βr prod.lex rβ sβ :=
mk (equiv.prod_congr (to_equiv eβ) (to_equiv eβ)) sorry
protected instance group {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} : group (r βr r) :=
group.mk (fun (fβ fβ : r βr r) => rel_iso.trans fβ fβ) sorry (rel_iso.refl r) sorry sorry
rel_iso.symm
(div_inv_monoid.div._default (fun (fβ fβ : r βr r) => rel_iso.trans fβ fβ) sorry
(rel_iso.refl r) sorry sorry rel_iso.symm)
sorry
@[simp] theorem coe_one {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} : β1 = id := rfl
@[simp] theorem coe_mul {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} (eβ : r βr r) (eβ : r βr r) :
β(eβ * eβ) = βeβ β βeβ :=
rfl
theorem mul_apply {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} (eβ : r βr r) (eβ : r βr r) (x : Ξ±) :
coe_fn (eβ * eβ) x = coe_fn eβ (coe_fn eβ x) :=
rfl
@[simp] theorem inv_apply_self {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} (e : r βr r) (x : Ξ±) :
coe_fn (eβ»ΒΉ) (coe_fn e x) = x :=
symm_apply_apply e x
@[simp] theorem apply_inv_self {Ξ± : Type u_1} {r : Ξ± β Ξ± β Prop} (e : r βr r) (x : Ξ±) :
coe_fn e (coe_fn (eβ»ΒΉ) x) = x :=
apply_symm_apply e x
end rel_iso
namespace order_iso
/-- Reinterpret an order isomorphism as an order embedding. -/
def to_order_embedding {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] (e : Ξ± βo Ξ²) :
Ξ± βͺo Ξ² :=
rel_iso.to_rel_embedding e
@[simp] theorem coe_to_order_embedding {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²]
(e : Ξ± βo Ξ²) : β(to_order_embedding e) = βe :=
rfl
protected theorem bijective {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] (e : Ξ± βo Ξ²) :
function.bijective βe :=
equiv.bijective (rel_iso.to_equiv e)
protected theorem injective {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] (e : Ξ± βo Ξ²) :
function.injective βe :=
equiv.injective (rel_iso.to_equiv e)
protected theorem surjective {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²]
(e : Ξ± βo Ξ²) : function.surjective βe :=
equiv.surjective (rel_iso.to_equiv e)
@[simp] theorem range_eq {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] (e : Ξ± βo Ξ²) :
set.range βe = set.univ :=
function.surjective.range_eq (order_iso.surjective e)
@[simp] theorem apply_eq_iff_eq {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²]
(e : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ±} : coe_fn e x = coe_fn e y β x = y :=
equiv.apply_eq_iff_eq (rel_iso.to_equiv e)
/-- Inverse of an order isomorphism. -/
def symm {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] (e : Ξ± βo Ξ²) : Ξ² βo Ξ± :=
rel_iso.symm e
@[simp] theorem apply_symm_apply {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²]
(e : Ξ± βo Ξ²) (x : Ξ²) : coe_fn e (coe_fn (symm e) x) = x :=
equiv.apply_symm_apply (rel_iso.to_equiv e) x
@[simp] theorem symm_apply_apply {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²]
(e : Ξ± βo Ξ²) (x : Ξ±) : coe_fn (symm e) (coe_fn e x) = x :=
equiv.symm_apply_apply (rel_iso.to_equiv e) x
theorem symm_apply_eq {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] (e : Ξ± βo Ξ²) {x : Ξ±}
{y : Ξ²} : coe_fn (symm e) y = x β y = coe_fn e x :=
equiv.symm_apply_eq (rel_iso.to_equiv e)
@[simp] theorem symm_symm {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] (e : Ξ± βo Ξ²) :
symm (symm e) = e :=
rel_iso.ext fun (x : Ξ±) => Eq.refl (coe_fn (symm (symm e)) x)
theorem symm_injective {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²] :
function.injective symm :=
sorry
@[simp] theorem to_equiv_symm {Ξ± : Type u_1} {Ξ² : Type u_2} [HasLessEq Ξ±] [HasLessEq Ξ²]
(e : Ξ± βo Ξ²) : equiv.symm (rel_iso.to_equiv e) = rel_iso.to_equiv (symm e) :=
rfl
/-- Composition of two order isomorphisms is an order isomorphism. -/
def trans {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} [HasLessEq Ξ±] [HasLessEq Ξ²] [HasLessEq Ξ³]
(e : Ξ± βo Ξ²) (e' : Ξ² βo Ξ³) : Ξ± βo Ξ³ :=
rel_iso.trans e e'
@[simp] theorem coe_trans {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} [HasLessEq Ξ±] [HasLessEq Ξ²]
[HasLessEq Ξ³] (e : Ξ± βo Ξ²) (e' : Ξ² βo Ξ³) : β(trans e e') = βe' β βe :=
rfl
theorem trans_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} [HasLessEq Ξ±] [HasLessEq Ξ²]
[HasLessEq Ξ³] (e : Ξ± βo Ξ²) (e' : Ξ² βo Ξ³) (x : Ξ±) :
coe_fn (trans e e') x = coe_fn e' (coe_fn e x) :=
rfl
protected theorem monotone {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²) :
monotone βe :=
order_embedding.monotone (to_order_embedding e)
protected theorem strict_mono {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²) :
strict_mono βe :=
order_embedding.strict_mono (to_order_embedding e)
@[simp] theorem le_iff_le {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
{x : Ξ±} {y : Ξ±} : coe_fn e x β€ coe_fn e y β x β€ y :=
rel_iso.map_rel_iff e
@[simp] theorem lt_iff_lt {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
{x : Ξ±} {y : Ξ±} : coe_fn e x < coe_fn e y β x < y :=
order_embedding.lt_iff_lt (to_order_embedding e)
@[simp] theorem preimage_Iic {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(b : Ξ²) : βe β»ΒΉ' set.Iic b = set.Iic (coe_fn (symm e) b) :=
sorry
@[simp] theorem preimage_Ici {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(b : Ξ²) : βe β»ΒΉ' set.Ici b = set.Ici (coe_fn (symm e) b) :=
sorry
@[simp] theorem preimage_Iio {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(b : Ξ²) : βe β»ΒΉ' set.Iio b = set.Iio (coe_fn (symm e) b) :=
sorry
@[simp] theorem preimage_Ioi {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(b : Ξ²) : βe β»ΒΉ' set.Ioi b = set.Ioi (coe_fn (symm e) b) :=
sorry
@[simp] theorem preimage_Icc {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(a : Ξ²) (b : Ξ²) : βe β»ΒΉ' set.Icc a b = set.Icc (coe_fn (symm e) a) (coe_fn (symm e) b) :=
sorry
@[simp] theorem preimage_Ico {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(a : Ξ²) (b : Ξ²) : βe β»ΒΉ' set.Ico a b = set.Ico (coe_fn (symm e) a) (coe_fn (symm e) b) :=
sorry
@[simp] theorem preimage_Ioc {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(a : Ξ²) (b : Ξ²) : βe β»ΒΉ' set.Ioc a b = set.Ioc (coe_fn (symm e) a) (coe_fn (symm e) b) :=
sorry
@[simp] theorem preimage_Ioo {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
(a : Ξ²) (b : Ξ²) : βe β»ΒΉ' set.Ioo a b = set.Ioo (coe_fn (symm e) a) (coe_fn (symm e) b) :=
sorry
/-- To show that `f : Ξ± β Ξ²`, `g : Ξ² β Ξ±` make up an order isomorphism of linear orders,
it suffices to prove `cmp a (g b) = cmp (f a) b`. --/
def of_cmp_eq_cmp {Ξ± : Type u_1} {Ξ² : Type u_2} [linear_order Ξ±] [linear_order Ξ²] (f : Ξ± β Ξ²)
(g : Ξ² β Ξ±) (h : β (a : Ξ±) (b : Ξ²), cmp a (g b) = cmp (f a) b) : Ξ± βo Ξ² :=
(fun (gf : β (a : Ξ±), a = g (f a)) => rel_iso.mk (equiv.mk f g sorry sorry) sorry) sorry
/-- Order isomorphism between two equal sets. -/
def set_congr {Ξ± : Type u_1} [preorder Ξ±] (s : set Ξ±) (t : set Ξ±) (h : s = t) : β₯s βo β₯t :=
rel_iso.mk (equiv.set_congr h) sorry
/-- Order isomorphism between `univ : set Ξ±` and `Ξ±`. -/
def set.univ {Ξ± : Type u_1} [preorder Ξ±] : β₯set.univ βo Ξ± := rel_iso.mk (equiv.set.univ Ξ±) sorry
end order_iso
/-- If a function `f` is strictly monotone on a set `s`, then it defines an order isomorphism
between `s` and its image. -/
protected def strict_mono_incr_on.order_iso {Ξ± : Type u_1} {Ξ² : Type u_2} [linear_order Ξ±]
[preorder Ξ²] (f : Ξ± β Ξ²) (s : set Ξ±) (hf : strict_mono_incr_on f s) : β₯s βo β₯(f '' s) :=
rel_iso.mk (set.bij_on.equiv f sorry) sorry
/-- A strictly monotone function from a linear order is an order isomorphism between its domain and
its range. -/
protected def strict_mono.order_iso {Ξ± : Type u_1} {Ξ² : Type u_2} [linear_order Ξ±] [preorder Ξ²]
(f : Ξ± β Ξ²) (h_mono : strict_mono f) : Ξ± βo β₯(set.range f) :=
rel_iso.mk (equiv.set.range f (strict_mono.injective h_mono)) sorry
/-- A strictly monotone surjective function from a linear order is an order isomorphism. -/
def strict_mono.order_iso_of_surjective {Ξ± : Type u_1} {Ξ² : Type u_2} [linear_order Ξ±] [preorder Ξ²]
(f : Ξ± β Ξ²) (h_mono : strict_mono f) (h_surj : function.surjective f) : Ξ± βo Ξ² :=
order_iso.trans (strict_mono.order_iso f h_mono)
(order_iso.trans
(order_iso.set_congr (set.range f) set.univ (function.surjective.range_eq h_surj))
order_iso.set.univ)
/-- `subrel r p` is the inherited relation on a subset. -/
def subrel {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) (p : set Ξ±) : β₯p β β₯p β Prop := coe β»ΒΉ'o r
@[simp] theorem subrel_val {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) (p : set Ξ±) {a : β₯p} {b : β₯p} :
subrel r p a b β r (subtype.val a) (subtype.val b) :=
iff.rfl
namespace subrel
/-- The relation embedding from the inherited relation on a subset. -/
protected def rel_embedding {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) (p : set Ξ±) : subrel r p βͺr r :=
rel_embedding.mk (function.embedding.subtype fun (x : Ξ±) => x β p) sorry
@[simp] theorem rel_embedding_apply {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) (p : set Ξ±) (a : β₯p) :
coe_fn (subrel.rel_embedding r p) a = subtype.val a :=
rfl
protected instance is_well_order {Ξ± : Type u_1} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] (p : set Ξ±) :
is_well_order (β₯p) (subrel r p) :=
rel_embedding.is_well_order (subrel.rel_embedding r p)
end subrel
/-- Restrict the codomain of a relation embedding. -/
def rel_embedding.cod_restrict {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
(p : set Ξ²) (f : r βͺr s) (H : β (a : Ξ±), coe_fn f a β p) : r βͺr subrel s p :=
rel_embedding.mk (function.embedding.cod_restrict p (rel_embedding.to_embedding f) H)
(rel_embedding.map_rel_iff' f)
@[simp] theorem rel_embedding.cod_restrict_apply {Ξ± : Type u_1} {Ξ² : Type u_2} {r : Ξ± β Ξ± β Prop}
{s : Ξ² β Ξ² β Prop} (p : set Ξ²) (f : r βͺr s) (H : β (a : Ξ±), coe_fn f a β p) (a : Ξ±) :
coe_fn (rel_embedding.cod_restrict p f H) a = { val := coe_fn f a, property := H a } :=
rfl
protected def order_iso.dual {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] [preorder Ξ²] (f : Ξ± βo Ξ²) :
order_dual Ξ± βo order_dual Ξ² :=
rel_iso.mk (rel_iso.to_equiv f) sorry
theorem order_iso.map_bot' {Ξ± : Type u_1} {Ξ² : Type u_2} [partial_order Ξ±] [partial_order Ξ²]
(f : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ²} (hx : β (x' : Ξ±), x β€ x') (hy : β (y' : Ξ²), y β€ y') :
coe_fn f x = y :=
sorry
theorem order_iso.map_bot {Ξ± : Type u_1} {Ξ² : Type u_2} [order_bot Ξ±] [order_bot Ξ²] (f : Ξ± βo Ξ²) :
coe_fn f β₯ = β₯ :=
order_iso.map_bot' f (fun (_x : Ξ±) => bot_le) fun (_x : Ξ²) => bot_le
theorem order_iso.map_top' {Ξ± : Type u_1} {Ξ² : Type u_2} [partial_order Ξ±] [partial_order Ξ²]
(f : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ²} (hx : β (x' : Ξ±), x' β€ x) (hy : β (y' : Ξ²), y' β€ y) :
coe_fn f x = y :=
order_iso.map_bot' (order_iso.dual f) hx hy
theorem order_iso.map_top {Ξ± : Type u_1} {Ξ² : Type u_2} [order_top Ξ±] [order_top Ξ²] (f : Ξ± βo Ξ²) :
coe_fn f β€ = β€ :=
order_iso.map_bot (order_iso.dual f)
theorem order_embedding.map_inf_le {Ξ± : Type u_1} {Ξ² : Type u_2} [semilattice_inf Ξ±]
[semilattice_inf Ξ²] (f : Ξ± βͺo Ξ²) (x : Ξ±) (y : Ξ±) : coe_fn f (x β y) β€ coe_fn f x β coe_fn f y :=
monotone.map_inf_le (order_embedding.monotone f) x y
theorem order_iso.map_inf {Ξ± : Type u_1} {Ξ² : Type u_2} [semilattice_inf Ξ±] [semilattice_inf Ξ²]
(f : Ξ± βo Ξ²) (x : Ξ±) (y : Ξ±) : coe_fn f (x β y) = coe_fn f x β coe_fn f y :=
sorry
theorem order_embedding.le_map_sup {Ξ± : Type u_1} {Ξ² : Type u_2} [semilattice_sup Ξ±]
[semilattice_sup Ξ²] (f : Ξ± βͺo Ξ²) (x : Ξ±) (y : Ξ±) : coe_fn f x β coe_fn f y β€ coe_fn f (x β y) :=
monotone.le_map_sup (order_embedding.monotone f) x y
theorem order_iso.map_sup {Ξ± : Type u_1} {Ξ² : Type u_2} [semilattice_sup Ξ±] [semilattice_sup Ξ²]
(f : Ξ± βo Ξ²) (x : Ξ±) (y : Ξ±) : coe_fn f (x β y) = coe_fn f x β coe_fn f y :=
order_iso.map_inf (order_iso.dual f) x y
end Mathlib |
# get_marker.r
#
# Copyright (c) 2020 VIB (Belgium) & Babraham Institute (United Kingdom)
#
# Software written by Carlos P. Roca, as research funded by the European Union.
#
# This software may be modified and distributed under the terms of the MIT
# license. See the LICENSE file for details.
# Writes a csv file with the common set of markers in a set of single-color
# controls, together with corrected names in case of presence of forbidden
# characters.
#
# Requires being called as a batch script, and assumes fixed values for the
# following two variables (see below):
# control.dir directory with the set of single-color controls
# control.def.file csv file defining the names and channels of the
# single-color controls
library( autospill )
# set parameters
asp <- get.autospill.param()
asp$marker.file.name
# read markers from controls
control.dir <- "./samples/"
control.def.file <- "./fcs_control.csv"
flow.set.marker.table <- read.marker( control.dir, control.def.file, asp )
flow.set.marker.table
# output session info
sessionInfo()
|
(**************************************************************)
(* Copyright *)
(* Jean-FranΓ§ois Monin [+] *)
(* Dominique Larchey-Wendling [*] *)
(* *)
(* [+] Affiliation VERIMAG - Univ. Grenoble-Alpes *)
(* [*] Affiliation LORIA -- CNRS *)
(**************************************************************)
(* This file is distributed under the terms of the *)
(* CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT *)
(**************************************************************)
(* List traversal from right to left *)
Require Import List Utf8.
Import ListNotations.
Require Import mark.
Reserved Notation "x '+:' y" (at level 59, left associativity, format "x +: y").
Fixpoint consr {A} (l : list A) (y : A) { struct l } : list A :=
match l with
| [] => [y]
| x :: l => x :: l +: y
end
where "x +: y" := (consr x y) : list_scope.
Inductive lr (A: Type) : Type :=
| Nilr : lr A
| Consr : list A β A β lr A
.
Arguments Nilr {A}.
Arguments Consr {A}.
Definition r2l {A} (r: lr A) : list A :=
match r with
| Nilr => []
| Consr u z => u +: z
end.
(* Simulating destruct from right to left *)
Fixpoint l2r {A} (l : list A) : lr A :=
match l with
| [] => Nilr
| x :: lr =>
match l2r lr with
| Nilr => Consr [] x
| Consr lg z => Consr (x :: lg) z
end
end.
(* Reflecting lists "constructed" with +:, using lr *)
Tactic Notation "reflect_lr_term" constr(t) :=
let changed :=
match t with
| context C [@nil ?t] => context C [@r2l t Nilr]
| context C [(?x +: ?y)] => context C [r2l (Consr x y)]
end in exact changed.
Tactic Notation "reflect_lr" :=
match goal with |- ?concl => change ltac:(reflect_lr_term concl) end.
Tactic Notation "reflect_lr" "in" hyp(H) :=
let t := type of H in change ltac:(reflect_lr_term t) in H.
(* The same at marked places *)
Tactic Notation "Mreflect_lr_term" constr(t) :=
let changed :=
match t with
| context C [MARQ (@nil) ?t] => context C [@r2l t Nilr]
| context C [MARQ (@consr) ?t ?x ?y] => context C [@r2l t (Consr x y)]
end in exact changed.
Tactic Notation "mreflect_lr" :=
match goal with |- ?concl => change ltac:(Mreflect_lr_term concl) end.
Tactic Notation "mreflect_lr" "in" hyp(H) :=
let t := type of H in change ltac:(Mreflect_lr_term t) in H.
Section sec_context.
Context {A: Type}.
Implicit Type l u v : list A.
Implicit Type x y z : A.
Implicit Type r : lr A.
(* -------------------------------------------------------------------------- *)
(* Easy key lemmas: r2l et l2r are inverse bijections *)
Lemma l2r_consr : β u z, l2r (u +: z) = Consr u z.
Proof .
intros u z; induction u as [ | x u Hu]; simpl; [ | rewrite Hu ]; reflexivity.
Qed.
Definition same_by_l2r_consr {P: lr A β Prop} {l u z} (E : l = u+:z) :
P (l2r l) -> P (Consr u z).
Proof. intros p; rewrite <-l2r_consr, <-E; exact p. Defined.
Lemma rlr_id : β r, l2r (r2l r) = r.
Proof. intros []; simpl; [reflexivity | apply l2r_consr]. Qed.
Corollary r2l_consr : β r u z, r2l r = u +: z β r = Consr u z.
Proof.
intros r u z e.
rewrite <- (rlr_id r), e; apply l2r_consr.
Qed.
(*Definition lrl l := r2l (l2r l).*)
Notation lrl := (Ξ» l, r2l (l2r l)).
Lemma lrl_id : β l, lrl l = l.
Proof.
induction l as [| x v Hv]; simpl.
- reflexivity.
- destruct (l2r v) as [| u z]; rewrite <- Hv; reflexivity.
Defined.
Ltac rewrite_lrl := cbv beta; rewrite lrl_id.
Corollary l2r_Nilr : β l, l2r l = Nilr β l = [].
Proof.
intros l e. reflect_lr. rewrite <- e. symmetry. apply lrl_id.
Qed.
Corollary l2r_Consr : β l u z, l2r l = Consr u z β l = u +: z.
Proof.
intros l u z e. reflect_lr. rewrite <- e. symmetry. apply lrl_id.
Qed.
(* Cast functions, in Prop and in Type *)
(* Using them constrain the use of eq_ind and eq_rect,
hence a clearer view of the underlying reasoning *)
Definition up_llP (P: list A β Prop) u : P u β P (lrl u).
Proof. rewrite_lrl; exact (fun p => p). Defined.
Definition up_llT (P: list A β Type) u : P u β P (lrl u).
Proof. rewrite_lrl; exact (fun p => p). Defined.
Definition down_llP (P: list A β Prop) u : P (lrl u) β P u.
Proof. rewrite_lrl; exact (fun p => p). Defined.
Definition down_llT (P: list A β Type) u : P (lrl u) β P u.
Proof. rewrite_lrl; exact (fun p => p). Defined.
End sec_context.
Notation lrl := (Ξ» l, r2l (l2r l)).
(* Adds in the goal a helper β r, R (r2l (l2r l)) r β R l r *)
Ltac gen_help l R := generalize (Ξ» y, down_llP (Ξ» x, R x y) l).
|
Formal statement is: lemma lebesgue_openin: "\<lbrakk>openin (top_of_set S) T; S \<in> sets lebesgue\<rbrakk> \<Longrightarrow> T \<in> sets lebesgue" Informal statement is: If $T$ is an open subset of a Lebesgue measurable set $S$, then $T$ is Lebesgue measurable. |
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.num.lemmas
import Mathlib.data.nat.prime
import Mathlib.tactic.ring
import Mathlib.PostPort
namespace Mathlib
/-!
# Primality for binary natural numbers
This file defines versions of `nat.min_fac` and `nat.prime` for `num` and `pos_num`. As with other
`num` definitions, they are not intended for general use (`nat` should be used instead of `num` in
most cases) but they can be used in contexts where kernel computation is required, such as proofs
by `rfl` and `dec_trivial`, as well as in `#reduce`.
The default decidable instance for `nat.prime` is optimized for VM evaluation, so it should be
preferred within `#eval` or in tactic execution, while for proofs the `norm_num` tactic can be used
to construct primality and non-primality proofs more efficiently than kernel computation.
Nevertheless, sometimes proof by computational reflection requires natural number computations, and
`num` implements algorithms directly on binary natural numbers for this purpose.
-/
namespace pos_num
/-- Auxiliary function for computing the smallest prime factor of a `pos_num`. Unlike
`nat.min_fac_aux`, we use a natural number `fuel` variable that is set to an upper bound on the
number of iterations. It is initialized to the number `n` we are determining primality for. Even
though this is exponential in the input (since it is a `nat`, not a `num`), it will get lazily
evaluated during kernel reduction, so we will only require about `sqrt n` unfoldings, for the
`sqrt n` iterations of the loop. -/
def min_fac_aux (n : pos_num) : β β pos_num β pos_num := sorry
theorem min_fac_aux_to_nat {fuel : β} {n : pos_num} {k : pos_num}
(h : nat.sqrt βn < fuel + β(bit1 k)) : β(min_fac_aux n fuel k) = nat.min_fac_aux βn β(bit1 k) :=
sorry
/-- Returns the smallest prime factor of `n β 1`. -/
def min_fac : pos_num β pos_num := sorry
@[simp] theorem min_fac_to_nat (n : pos_num) : β(min_fac n) = nat.min_fac βn := sorry
/-- Primality predicate for a `pos_num`. -/
@[simp] def prime (n : pos_num) := nat.prime βn
protected instance decidable_prime : decidable_pred prime := sorry
end pos_num
namespace num
/-- Returns the smallest prime factor of `n β 1`. -/
def min_fac : num β pos_num := sorry
@[simp] theorem min_fac_to_nat (n : num) : β(min_fac n) = nat.min_fac βn :=
num.cases_on n (idRhs (β(min_fac 0) = β(min_fac 0)) rfl)
fun (n : pos_num) => idRhs (β(pos_num.min_fac n) = nat.min_fac βn) (pos_num.min_fac_to_nat n)
/-- Primality predicate for a `num`. -/
@[simp] def prime (n : num) := nat.prime βn
protected instance decidable_prime : decidable_pred prime := sorry
end Mathlib |
using SeisCore
using Test
@testset "SeisCore.jl" begin
# Write your tests here.
end
|
Require Import Crypto.Arithmetic.PrimeFieldTheorems.
Require Import Crypto.Specific.solinas64_2e221m3_4limbs.Synthesis.
(* TODO : change this to field once field isomorphism happens *)
Definition carry :
{ carry : feBW_loose -> feBW_tight
| forall a, phiBW_tight (carry a) = (phiBW_loose a) }.
Proof.
Set Ltac Profiling.
Time synthesize_carry ().
Show Ltac Profile.
Time Defined.
Print Assumptions carry.
|
Set Implicit Arguments.
Require Import Metalib.Metatheory.
Require Import Program.Equality.
Require Export AlgoTyping.
Require Export Coq.micromega.Lia.
Module Fsub.
(*********************************************************)
(*********************************************************)
(********************** Definitions **********************)
(*********************************************************)
(*********************************************************)
Inductive typ : Set :=
| typ_nat : typ
| typ_top : typ
| typ_bvar : nat -> typ
| typ_fvar : var -> typ
| typ_arrow : typ -> typ -> typ
| typ_all : typ -> typ -> typ
.
Inductive exp : Set :=
| exp_bvar : nat -> exp
| exp_fvar : atom -> exp
| exp_abs : typ -> exp -> exp
| exp_app : exp -> exp -> exp
| exp_tabs : typ -> exp -> exp
| exp_tapp : exp -> typ -> exp
| exp_nat : exp
.
Coercion exp_bvar : nat >-> exp.
Coercion exp_fvar : atom >-> exp.
Fixpoint open_tt_rec (K : nat) (U : typ) (T : typ) {struct T} : typ :=
match T with
| typ_nat => typ_nat
| typ_top => typ_top
| typ_bvar J => if K === J then U else (typ_bvar J)
| typ_fvar X => typ_fvar X
| typ_arrow T1 T2 => typ_arrow (open_tt_rec K U T1) (open_tt_rec K U T2)
| typ_all T1 T2 => typ_all (open_tt_rec K U T1) (open_tt_rec (S K) U T2)
end.
Definition open_tt T U := open_tt_rec 0 U T.
Inductive type : typ -> Prop :=
| type_top :
type typ_top
| type_nat :
type typ_nat
| type_var : forall X,
type (typ_fvar X)
| type_arrow : forall T1 T2,
type T1 ->
type T2 ->
type (typ_arrow T1 T2)
| type_all : forall L T1 T2,
type T1 ->
(forall X, X `notin` L -> type (open_tt T2 (typ_fvar X))) ->
type (typ_all T1 T2)
.
Fixpoint subst_tt (Z : atom) (U : typ) (T : typ) {struct T} : typ :=
match T with
| typ_top => typ_top
| typ_nat => typ_nat
| typ_bvar J => typ_bvar J
| typ_fvar X => if X == Z then U else (typ_fvar X)
| typ_arrow T1 T2 => typ_arrow (subst_tt Z U T1) (subst_tt Z U T2)
| typ_all T1 T2 => typ_all (subst_tt Z U T1) (subst_tt Z U T2)
end.
Fixpoint fv_tt (T : typ) {struct T} : atoms :=
match T with
| typ_top => {}
| typ_nat => {}
| typ_bvar J => {}
| typ_fvar X => {{ X }}
| typ_arrow T1 T2 => (fv_tt T1) `union` (fv_tt T2)
| typ_all T1 T2 => (fv_tt T1) `union` (fv_tt T2)
end.
Inductive binding : Set :=
| bind_sub : typ -> binding
| bind_typ : typ -> binding.
Definition env := list (atom * binding).
Notation empty := (@nil (atom * binding)).
Coercion typ_bvar : nat >-> typ.
Coercion typ_fvar : atom >-> typ.
Inductive WF : env -> typ -> Prop :=
| WF_top : forall E, WF E typ_top
| WF_nat : forall E, WF E typ_nat
| WF_var: forall U E (X : atom),
binds X (bind_sub U) E ->
WF E (typ_fvar X)
| WF_arrow : forall E A B,
WF E A ->
WF E B ->
WF E (typ_arrow A B)
| WF_all : forall L E T1 T2,
WF E T1 ->
(forall X : atom, X `notin` L ->
WF (X ~ bind_sub T1 ++ E) (open_tt T2 X)) ->
WF E (typ_all T1 T2)
.
Fixpoint fl_tt (T : typ) {struct T} : atoms :=
match T with
| typ_top => {}
| typ_nat => {}
| typ_bvar J => {}
| typ_fvar X => {}
| typ_arrow T1 T2 => (fl_tt T1) `union` (fl_tt T2)
| typ_all T1 T2 => (fl_tt T1) \u (fl_tt T2)
end.
Fixpoint fv_env (E:env) : atoms :=
match E with
| nil => {}
| (x,bind_sub y)::E' => (fv_tt y) \u (fv_env E')
| (x,bind_typ y)::E' => (fv_tt y) \u (fv_env E')
end.
Fixpoint fl_env (E:env) : atoms :=
match E with
| nil => {}
| (x,bind_sub y)::E' => (fl_tt y) \u (fl_env E')
| (x,bind_typ y)::E' => (fl_tt y) \u (fl_env E')
end.
Inductive wf_env : env -> Prop :=
| wf_env_empty :
wf_env empty
| wf_env_sub : forall (E : env) (X : atom) (T : typ),
wf_env E ->
WF E T ->
X `notin` dom E ->
wf_env (X ~ bind_sub T ++ E)
| wf_env_typ : forall (E : env) (x : atom) (T : typ),
wf_env E ->
WF E T ->
x `notin` dom E ->
wf_env (x ~ bind_typ T ++ E).
Inductive sub : env -> typ -> typ -> Prop :=
| sa_nat: forall E,
wf_env E ->
sub E typ_nat typ_nat
| sa_fvar: forall E X,
wf_env E ->
WF E (typ_fvar X) ->
sub E (typ_fvar X) (typ_fvar X)
| sa_top : forall E A,
wf_env E ->
WF E A ->
sub E A typ_top
| sa_trans_tvar : forall U E T X,
binds X (bind_sub U) E ->
sub E U T ->
sub E (typ_fvar X) T
| sa_arrow: forall E A1 A2 B1 B2,
sub E B1 A1 ->
sub E A2 B2 ->
sub E (typ_arrow A1 A2) (typ_arrow B1 B2)
| sa_all : forall L E S T1 T2,
WF E S ->
(forall X : atom, X `notin` L ->
sub (X ~ bind_sub S ++ E) (open_tt T1 X) (open_tt T2 X)) ->
sub E (typ_all S T1) (typ_all S T2)
.
Definition subst_tb (Z : atom) (P : typ) (b : binding) : binding :=
match b with
| bind_sub T => bind_sub (subst_tt Z P T)
| bind_typ T => bind_typ (subst_tt Z P T)
end.
Fixpoint open_te_rec (K : nat) (U : typ) (e : exp) {struct e} : exp :=
match e with
| exp_nat => exp_nat
| exp_bvar i => exp_bvar i
| exp_fvar x => exp_fvar x
| exp_abs V e1 => exp_abs (open_tt_rec K U V) (open_te_rec K U e1)
| exp_app e1 e2 => exp_app (open_te_rec K U e1) (open_te_rec K U e2)
| exp_tabs V e1 => exp_tabs (open_tt_rec K U V) (open_te_rec (S K) U e1)
| exp_tapp e1 V => exp_tapp (open_te_rec K U e1) (open_tt_rec K U V)
end.
Fixpoint open_ee_rec (k : nat) (f : exp) (e : exp) {struct e} : exp :=
match e with
| exp_nat => exp_nat
| exp_bvar i => if k == i then f else (exp_bvar i)
| exp_fvar x => exp_fvar x
| exp_abs V e1 => exp_abs V (open_ee_rec (S k) f e1)
| exp_app e1 e2 => exp_app (open_ee_rec k f e1) (open_ee_rec k f e2)
| exp_tabs V e1 => exp_tabs V (open_ee_rec k f e1)
| exp_tapp e1 V => exp_tapp (open_ee_rec k f e1) V
end.
Definition open_te e U := open_te_rec 0 U e.
Definition open_ee e1 e2 := open_ee_rec 0 e2 e1.
Inductive expr : exp -> Prop :=
| expr_nat : expr exp_nat
| expr_var : forall x,
expr (exp_fvar x)
| expr_abs : forall L T e1,
type T ->
(forall x : atom, x `notin` L -> expr (open_ee e1 x)) ->
expr (exp_abs T e1)
| expr_app : forall e1 e2,
expr e1 ->
expr e2 ->
expr (exp_app e1 e2)
| expr_tabs : forall L T e1,
type T ->
(forall X : atom, X `notin` L -> expr (open_te e1 X)) ->
expr (exp_tabs T e1)
| expr_tapp : forall e1 V,
expr e1 ->
type V ->
expr (exp_tapp e1 V)
.
Definition body_e (e : exp) :=
exists L, forall x : atom, x `notin` L -> expr (open_ee e x).
Inductive typing : env -> exp -> typ -> Prop :=
| typing_nat: forall G,
wf_env G ->
typing G (exp_nat) (typ_nat)
| typing_var : forall E x T,
wf_env E ->
binds x (bind_typ T) E ->
typing E (exp_fvar x) T
| typing_abs : forall L E V e1 T1,
(forall x : atom, x `notin` L ->
typing (x ~ bind_typ V ++ E) (open_ee e1 x) T1) ->
typing E (exp_abs V e1) (typ_arrow V T1)
| typing_app : forall T1 E e1 e2 T2,
typing E e1 (typ_arrow T1 T2) ->
typing E e2 T1 ->
typing E (exp_app e1 e2) T2
| typing_tabs : forall L E V e1 T1,
(forall X : atom, X `notin` L ->
typing (X ~ bind_sub V ++ E) (open_te e1 X) (open_tt T1 X)) ->
typing E (exp_tabs V e1) (typ_all V T1)
| typing_tapp : forall T1 E e1 T T2,
typing E e1 (typ_all T1 T2) ->
sub E T T1 ->
typing E (exp_tapp e1 T) (open_tt T2 T)
| typing_sub : forall S E e T,
typing E e S ->
sub E S T ->
typing E e T
.
Inductive value : exp -> Prop :=
| value_abs : forall t1 T,
expr (exp_abs T t1) ->
value (exp_abs T t1)
| value_tabs : forall t1 T,
expr (exp_tabs T t1) ->
value (exp_tabs T t1)
| value_nat:
value exp_nat
.
Inductive step : exp -> exp -> Prop :=
| step_beta : forall (e1 e2:exp) T,
expr (exp_abs T e1) ->
value e2 ->
step (exp_app (exp_abs T e1) e2) (open_ee e1 e2)
| step_app1 : forall (e1 e2 e1':exp),
expr e2 ->
step e1 e1' ->
step (exp_app e1 e2) (exp_app e1' e2)
| step_app2 : forall v1 e2 e2',
value v1 ->
step e2 e2' ->
step (exp_app v1 e2) (exp_app v1 e2')
| step_tapp : forall e1 e1' V,
type V ->
step e1 e1' ->
step (exp_tapp e1 V) (exp_tapp e1' V)
| step_tabs : forall T1 e1 T2,
expr (exp_tabs T1 e1) ->
type T2 ->
step (exp_tapp (exp_tabs T1 e1) T2) (open_te e1 T2)
.
Hint Constructors type WF wf_env sub expr typing step value: core.
Fixpoint fv_te (e : exp) {struct e} : atoms :=
match e with
| exp_nat => {}
| exp_bvar i => {}
| exp_fvar x => {}
| exp_abs V e1 => (fv_tt V) `union` (fv_te e1)
| exp_app e1 e2 => (fv_te e1) `union` (fv_te e2)
| exp_tabs V e1 => (fv_tt V) `union` (fv_te e1)
| exp_tapp e1 V => (fv_tt V) `union` (fv_te e1)
end.
Fixpoint fv_ee (e : exp) {struct e} : atoms :=
match e with
| exp_nat => {}
| exp_bvar i => {}
| exp_fvar x => {{ x }}
| exp_abs V e1 => (fv_ee e1)
| exp_app e1 e2 => (fv_ee e1) `union` (fv_ee e2)
| exp_tabs V e1 => (fv_ee e1)
| exp_tapp e1 V => (fv_ee e1)
end.
Fixpoint subst_te (Z : atom) (U : typ) (e : exp) {struct e} : exp :=
match e with
| exp_nat => exp_nat
| exp_bvar i => exp_bvar i
| exp_fvar x => exp_fvar x
| exp_abs V e1 => exp_abs (subst_tt Z U V) (subst_te Z U e1)
| exp_app e1 e2 => exp_app (subst_te Z U e1) (subst_te Z U e2)
| exp_tabs V e1 => exp_tabs (subst_tt Z U V) (subst_te Z U e1)
| exp_tapp e1 V => exp_tapp (subst_te Z U e1) (subst_tt Z U V)
end.
Fixpoint subst_ee (z : atom) (u : exp) (e : exp) {struct e} : exp :=
match e with
| exp_nat => exp_nat
| exp_bvar i => exp_bvar i
| exp_fvar x => if x == z then u else e
| exp_abs V e1 => exp_abs V (subst_ee z u e1)
| exp_app e1 e2 => exp_app (subst_ee z u e1) (subst_ee z u e2)
| exp_tabs V e1 => exp_tabs V (subst_ee z u e1)
| exp_tapp e1 V => exp_tapp (subst_ee z u e1) V
end.
Definition equiv E A B := sub E A B /\ sub E B A.
Ltac gather_atoms ::=
let A := gather_atoms_with (fun x : atoms => x) in
let B := gather_atoms_with (fun x : atom => singleton x) in
let C := gather_atoms_with (fun x : list (var * typ) => dom x) in
let D := gather_atoms_with (fun x : typ => fl_tt x) in
let E := gather_atoms_with (fun x : typ => fv_tt x) in
let F := gather_atoms_with (fun x : env => dom x) in
let G := gather_atoms_with (fun x : env => fv_env x) in
let H := gather_atoms_with (fun x : env => fl_env x) in
let A1 := gather_atoms_with (fun x : exp => fv_te x) in
let A2 := gather_atoms_with (fun x : exp => fv_ee x) in
let A3 := gather_atoms_with (fun x : list (var * nat) => dom x) in
constr:(A \u B \u C \u D \u E \u F \u G \u H \u A1 \u A2 \u A3).
(*********************************************************)
(*********************************************************)
(******************** Infrastructures ********************)
(*********************************************************)
(*********************************************************)
Lemma uniq_from_wf_env : forall E,
wf_env E ->
uniq E.
Proof.
intros E H; induction H; auto.
Qed.
Lemma open_ee_rec_expr_aux : forall e j v u i,
i <> j ->
open_ee_rec j v e = open_ee_rec i u (open_ee_rec j v e) ->
e = open_ee_rec i u e.
Proof with congruence || eauto.
induction e; intros j v u i Neq H; simpl in *; inversion H; f_equal...
Case "exp_bvar".
destruct (j===n)... destruct (i===n)...
Qed.
Lemma open_ee_rec_type_aux : forall e j V u i,
open_te_rec j V e = open_ee_rec i u (open_te_rec j V e) ->
e = open_ee_rec i u e.
Proof.
induction e; intros j V u i H; simpl; inversion H; f_equal; eauto.
Qed.
Lemma open_ee_rec_expr : forall u e k,
expr e ->
e = open_ee_rec k u e.
Proof with auto.
intros u e k Hexpr. revert k.
induction Hexpr; intro k; simpl; f_equal; auto*;
try solve [
unfold open_ee in *;
pick fresh x;
eapply open_ee_rec_expr_aux with (j := 0) (v := exp_fvar x);
auto
| unfold open_te in *;
pick fresh X;
eapply open_ee_rec_type_aux with (j := 0) (V := typ_fvar X);
auto
].
Qed.
Lemma subst_ee_open_ee_rec : forall e1 e2 x u k,
expr u ->
subst_ee x u (open_ee_rec k e2 e1) =
open_ee_rec k (subst_ee x u e2) (subst_ee x u e1).
Proof with auto.
intros e1 e2 x u k WP. revert k.
induction e1; intros k; simpl; f_equal...
Case "exp_bvar".
destruct (k === n); subst...
Case "exp_fvar".
destruct (a == x); subst... apply open_ee_rec_expr...
Qed.
Lemma subst_ee_open_ee : forall e1 e2 x u,
expr u ->
subst_ee x u (open_ee e1 e2) =
open_ee (subst_ee x u e1) (subst_ee x u e2).
Proof with auto.
intros.
unfold open_ee.
apply subst_ee_open_ee_rec...
Qed.
Lemma subst_ee_open_ee_var : forall (x y:atom) u e,
y <> x ->
expr u ->
open_ee (subst_ee x u e) y = subst_ee x u (open_ee e y).
Proof with congruence || auto.
intros x y u e Neq Wu.
unfold open_ee.
rewrite subst_ee_open_ee_rec...
simpl.
destruct (y == x)...
Qed.
Ltac add_nil_fsub :=
match goal with
| [ |- WF ?E _ ] => rewrite_alist (nil ++ E)
| [ |- sub ?E _ _ ] => rewrite_alist (nil ++ E)
end.
Lemma subst_ee_intro_rec : forall x e u k,
x `notin` fv_ee e ->
open_ee_rec k u e = subst_ee x u (open_ee_rec k (exp_fvar x) e).
Proof with congruence || auto.
induction e; intros u k Fr; simpl in *; f_equal...
Case "exp_bvar".
destruct (k === n)... simpl. destruct (x == x)...
Case "exp_fvar".
destruct (a == x)... contradict Fr; fsetdec.
Qed.
Lemma subst_ee_intro : forall x e u,
x `notin` fv_ee e ->
open_ee e u = subst_ee x u (open_ee e x).
Proof with auto.
intros.
unfold open_ee.
apply subst_ee_intro_rec...
Qed.
Fixpoint close_tt_rec (K : nat) (Z : atom) (T : typ) {struct T} : typ :=
match T with
| typ_nat => typ_nat
| typ_top => typ_top
| typ_bvar J => typ_bvar J
| typ_fvar X => if X == Z then typ_bvar K else typ_fvar X
| typ_arrow T1 T2 => typ_arrow (close_tt_rec K Z T1) (close_tt_rec K Z T2)
| typ_all A B => typ_all (close_tt_rec K Z A)
(close_tt_rec (S K) Z B)
end.
Definition close_tt T X := close_tt_rec 0 X T.
Lemma close_open_reverse_rec: forall T X,
(X \notin fv_tt T) -> forall k, T = close_tt_rec k X (open_tt_rec k (typ_fvar X) T).
Proof with auto.
intros T.
induction T;intros;simpl in *;try solve [f_equal;auto]...
-
destruct (k==n)...
simpl...
destruct (X==X)...
destruct n0...
-
destruct (a==X)...
apply notin_singleton_1 in H...
destruct H...
Qed.
Lemma close_open_reverse: forall T X,
(X \notin fv_tt T) -> T = close_tt (open_tt T (typ_fvar X)) X.
Proof with auto.
intros.
apply close_open_reverse_rec...
Qed.
(* WFC typ n : type with < k binded variables *)
Inductive WFD : typ -> nat -> Prop :=
| WD_nat: forall k,
WFD typ_nat k
| WD_top: forall k,
WFD typ_top k
| WD_fvar: forall X k,
WFD (typ_fvar X) k
| WD_bvar: forall b k,
b < k ->
WFD (typ_bvar b) k
| WD_arrow: forall A B k,
WFD A k ->
WFD B k ->
WFD (typ_arrow A B) k
| WD_all: forall A B n,
WFD A n ->
WFD B (S n) ->
WFD (typ_all A B) n
.
Hint Constructors WFC WFD WFE: core.
Lemma close_wfd : forall A X,
WFD A 0 ->
WFD (close_tt A X) 1.
Proof with auto.
intros A.
unfold close_tt.
generalize 0.
induction A;intros;try solve [dependent destruction H;simpl in *;auto]...
-
simpl...
destruct (a==X)...
Qed.
Lemma close_type_wfd: forall A,
type A -> WFD A 0.
Proof with auto.
intros.
induction H;intros...
- (* WFD_all *)
constructor...
pick_fresh X.
specialize_x_and_L X L.
apply close_wfd with (X:=X) in H1.
rewrite <- close_open_reverse in H1...
Qed.
Lemma open_close_reverse_rec: forall T X X0,
(* (X \notin fv_tt T \u {{X0}}) -> *)
(* (X0 \notin fv_tt T) -> *)
forall k, WFD T k ->
subst_tt X X0 T = open_tt_rec k X0 (close_tt_rec k X T).
(* subst_tt X0 X T = close_tt_rec k X (open_tt_rec k (typ_fvar X0) T). *)
Proof with auto.
intros T.
induction T;intros;simpl in *;try solve [f_equal;auto]...
- inv H. destruct (k == n);try lia...
- destruct (a == X)... simpl. destruct (k == k); try lia...
- inv H. rewrite IHT1 with (k:=k)...
rewrite IHT2 with (k:=k)...
- inv H. rewrite IHT1 with (k:=k)...
rewrite IHT2 with (k:=S k)...
Qed.
Lemma open_close_reverse: forall T (X0 X:atom),
type T ->
(* (X \notin fv_tt T \u {{ X0 }}) -> *)
subst_tt X X0 T = open_tt (close_tt T X) X0.
Proof with auto.
intros. unfold open_tt, close_tt.
rewrite <- open_close_reverse_rec...
apply close_type_wfd...
Qed.
Lemma subst_tt_intro_rec : forall X T2 U k,
X `notin` fv_tt T2 ->
open_tt_rec k U T2 = subst_tt X U (open_tt_rec k (typ_fvar X) T2).
Proof with congruence || auto.
induction T2; intros U k Fr; simpl in *; f_equal...
Case "typ_bvar".
destruct (k === n)... simpl. destruct (X == X)...
Case "typ_fvar".
destruct (a == X)... contradict Fr; fsetdec.
Qed.
Lemma subst_tt_intro : forall X T2 U,
X `notin` fv_tt T2 ->
open_tt T2 U = subst_tt X U (open_tt T2 X).
Proof with auto.
intros.
unfold open_tt.
apply subst_tt_intro_rec...
Qed.
Lemma subst_te_intro_rec : forall X e U k,
X `notin` fv_te e ->
open_te_rec k U e = subst_te X U (open_te_rec k (typ_fvar X) e).
Proof.
induction e; intros U k Fr; simpl in *; f_equal;
auto using subst_tt_intro_rec.
Qed.
Lemma subst_te_intro : forall X e U,
X `notin` fv_te e ->
open_te e U = subst_te X U (open_te e X).
Proof with auto.
intros.
unfold open_te.
apply subst_te_intro_rec...
Qed.
Lemma open_tt_rec_type_aux : forall T j V i U,
i <> j ->
open_tt_rec j V T = open_tt_rec i U (open_tt_rec j V T) ->
T = open_tt_rec i U T.
Proof with congruence || eauto.
induction T; intros j V i U Neq H; simpl in *; inversion H; f_equal...
destruct (j === n)... destruct (i === n)...
Qed.
Lemma open_tt_rec_type : forall T U k,
type T ->
T = open_tt_rec k U T.
Proof with auto.
intros T U k Htyp. revert k.
induction Htyp; intros k; simpl; f_equal...
unfold open_tt in *.
pick fresh X.
apply open_tt_rec_type_aux with (j:=0) (V:=(typ_fvar X))...
Qed.
Lemma subst_tt_fresh : forall Z U T,
Z `notin` fv_tt T ->
T = subst_tt Z U T.
Proof with auto.
induction T; simpl; intro H; f_equal...
Case "typ_fvar".
destruct (a == Z)...
contradict H; fsetdec.
Qed.
Lemma subst_tt_open_tt_rec : forall T1 T2 X P k,
type P ->
subst_tt X P (open_tt_rec k T2 T1) =
open_tt_rec k (subst_tt X P T2) (subst_tt X P T1).
Proof with auto.
intros T1 T2 X P k WP. revert k.
induction T1; intros k; simpl; f_equal...
Case "typ_bvar".
destruct (k === n); subst...
Case "typ_fvar".
destruct (a == X); subst... apply open_tt_rec_type...
Qed.
Lemma subst_tt_open_tt : forall T1 T2 (X:atom) P,
type P ->
subst_tt X P (open_tt T1 T2) = open_tt (subst_tt X P T1) (subst_tt X P T2).
Proof with auto.
intros.
unfold open_tt.
apply subst_tt_open_tt_rec...
Qed.
Lemma subst_tt_open_tt_var : forall (X Y:atom) P T,
Y <> X ->
type P ->
open_tt (subst_tt X P T) Y = subst_tt X P (open_tt T Y).
Proof with congruence || auto.
intros X Y P T Neq Wu.
unfold open_tt.
rewrite subst_tt_open_tt_rec...
simpl.
destruct (Y == X)...
Qed.
Lemma subst_te_open_ee_rec : forall e1 e2 Z P k,
subst_te Z P (open_ee_rec k e2 e1) =
open_ee_rec k (subst_te Z P e2) (subst_te Z P e1).
Proof with auto.
induction e1; intros e2 Z P k; simpl; f_equal...
Case "exp_bvar".
destruct (k === n)...
Qed.
Lemma subst_te_open_ee : forall e1 e2 Z P,
subst_te Z P (open_ee e1 e2) = open_ee (subst_te Z P e1) (subst_te Z P e2).
Proof with auto.
intros.
unfold open_ee.
apply subst_te_open_ee_rec...
Qed.
Lemma subst_te_open_ee_var : forall Z (x:atom) P e,
open_ee (subst_te Z P e) x = subst_te Z P (open_ee e x).
Proof with auto.
intros.
rewrite subst_te_open_ee...
Qed.
Lemma open_te_rec_expr_aux : forall e j u i P ,
open_ee_rec j u e = open_te_rec i P (open_ee_rec j u e) ->
e = open_te_rec i P e.
Proof with congruence || eauto.
induction e; intros j u i P H; simpl in *; inversion H; f_equal...
Qed.
Lemma open_te_rec_type_aux : forall e j Q i P,
i <> j ->
open_te_rec j Q e = open_te_rec i P (open_te_rec j Q e) ->
e = open_te_rec i P e.
Proof.
induction e; intros j Q i P Neq Heq; simpl in *; inversion Heq;
f_equal; eauto using open_tt_rec_type_aux.
Qed.
Lemma open_te_rec_expr : forall e U k,
expr e ->
e = open_te_rec k U e.
Proof.
intros e U k WF. revert k.
induction WF; intros k; simpl; f_equal; auto using open_tt_rec_type;
try solve [
unfold open_ee in *;
pick fresh x;
eapply open_te_rec_expr_aux with (j := 0) (u := exp_fvar x);
auto
| unfold open_te in *;
pick fresh X;
eapply open_te_rec_type_aux with (j := 0) (Q := typ_fvar X);
auto
].
Qed.
Lemma subst_ee_open_te_rec : forall e P z u k,
expr u ->
subst_ee z u (open_te_rec k P e) = open_te_rec k P (subst_ee z u e).
Proof with auto.
induction e; intros P z u k H; simpl; f_equal...
Case "exp_fvar".
destruct (a == z)... apply open_te_rec_expr...
Qed.
Lemma subst_ee_open_te : forall e P z u,
expr u ->
subst_ee z u (open_te e P) = open_te (subst_ee z u e) P.
Proof with auto.
intros.
unfold open_te.
apply subst_ee_open_te_rec...
Qed.
Lemma subst_ee_open_te_var : forall z (X:atom) u e,
expr u ->
open_te (subst_ee z u e) X = subst_ee z u (open_te e X).
Proof with auto.
intros z X u e H.
rewrite subst_ee_open_te...
Qed.
Lemma subst_tt_type : forall Z P T,
type T ->
type P ->
type (subst_tt Z P T).
Proof with auto.
intros Z P T HT HP.
induction HT; simpl...
destruct (X == Z)...
pick fresh Y.
apply type_all with (L:=L \u {{Z}})...
intros.
rewrite subst_tt_open_tt_var...
Qed.
Lemma subst_tt_twice: forall (X Y:atom) T,
X \notin fv_tt T ->
T = subst_tt X Y (subst_tt Y X T).
Proof with auto.
induction T;intros;simpl in *;try f_equal...
+
destruct (a == Y);simpl...
destruct (X == X);simpl;try f_equal...
tauto.
destruct (a == X);simpl;try f_equal...
exfalso. simpl in H...
Qed.
Lemma subst_te_open_te_rec : forall e T X U k,
type U ->
subst_te X U (open_te_rec k T e) =
open_te_rec k (subst_tt X U T) (subst_te X U e).
Proof.
intros e T X U k WU. revert k.
induction e; intros k; simpl; f_equal; auto using subst_tt_open_tt_rec.
Qed.
Lemma subst_te_open_te : forall e T X U,
type U ->
subst_te X U (open_te e T) = open_te (subst_te X U e) (subst_tt X U T).
Proof with auto.
intros.
unfold open_te.
apply subst_te_open_te_rec...
Qed.
Lemma subst_te_open_te_var : forall (X Y:atom) U e,
Y <> X ->
type U ->
open_te (subst_te X U e) Y = subst_te X U (open_te e Y).
Proof with congruence || auto.
intros X Y U e Neq WU.
unfold open_te.
rewrite subst_te_open_te_rec...
simpl.
destruct (Y == X)...
Qed.
Lemma fv_open_tt_notin_inv: forall T S (X:atom),
X \notin fv_tt T ->
fv_tt (open_tt T X) [<=] add X S ->
fv_tt T [<=] S.
Proof with auto.
intro T.
unfold open_tt in *.
generalize 0.
induction T;intros;simpl in *;try solve [apply KeySetProperties.subset_empty]...
-
unfold "[<=]" in *.
intros...
apply AtomSetNotin.D.F.singleton_iff in H1...
subst.
assert (a0 `in` singleton a0) by auto.
specialize (H0 a0 H1)...
apply AtomSetImpl.add_3 in H0...
-
apply union_subset_7 in H0.
apply notin_union in H.
destruct_hypos.
apply KeySetProperties.union_subset_3...
apply IHT1 with (X:=X) (n:=n)...
apply IHT2 with (X:=X) (n:=n)...
-
apply union_subset_7 in H0.
apply notin_union in H.
destruct_hypos.
apply KeySetProperties.union_subset_3...
apply IHT1 with (X:=X) (n:=n)...
apply IHT2 with (X:=X) (n:=(Datatypes.S n))...
Qed.
Lemma open_tt_var_rev: forall A B (X:atom),
X \notin fv_tt A \u fv_tt B ->
open_tt A X = open_tt B X ->
A = B.
Proof with auto.
unfold open_tt.
generalize 0.
intros n A B.
generalize dependent n.
generalize dependent B.
induction A;induction B;intros;simpl in *;try solve [inversion H0|destruct (n0==n);subst;inversion H0]...
-
destruct (n1==n);destruct (n1==n0);subst...
inversion H0.
inversion H0.
-
destruct (n0==n);subst...
inversion H0.
rewrite <- H2 in H.
solve_notin_self X.
-
destruct (n0==n);subst...
inversion H0.
rewrite H2 in H.
solve_notin_self X.
-
inversion H0.
apply IHA1 in H2...
apply IHA2 in H3...
subst...
-
inversion H0.
apply IHA1 in H2...
apply IHA2 in H3...
subst...
Qed.
(*********************************************************)
(*********************************************************)
(******************** Regularity *************************)
(*********************************************************)
(*********************************************************)
Lemma wf_typ_strengthening : forall E F x U T,
WF (F ++ x ~ bind_typ U ++ E) T ->
WF (F ++ E) T.
Proof with eauto.
intros.
dependent induction H...
-
analyze_binds H...
-
apply WF_all with (L:=L);intros...
rewrite_env (((X~ bind_sub T1) ++ F) ++ E)...
apply H1 with (x0:=x) (U0:=U)...
Qed.
Lemma WF_weakening: forall E1 E2 T E,
WF (E1 ++ E2) T ->
WF (E1 ++ E ++ E2) T.
Proof with eauto.
intros.
generalize dependent E.
dependent induction H;intros...
-
apply WF_all with (L:=L)...
intros.
rewrite_alist (([(X, bind_sub T1)] ++ E1) ++ E ++ E2).
apply H1...
Qed.
Lemma wf_typ_from_binds_typ : forall x U E,
wf_env E ->
binds x (bind_typ U) E ->
WF E U.
Proof with auto.
induction 1; intros J; analyze_binds J...
-
apply IHwf_env in BindsTac...
add_nil_fsub.
apply WF_weakening...
-
inversion BindsTacVal;subst.
add_nil_fsub.
apply WF_weakening...
-
apply IHwf_env in BindsTac...
add_nil_fsub.
apply WF_weakening...
Qed.
Lemma WF_type: forall E T,
WF E T -> type T.
Proof with auto.
intros.
induction H...
apply type_all with (L:=L)...
Qed.
Lemma sub_regular : forall E A B,
sub E A B -> wf_env E /\ WF E A /\ WF E B.
Proof with auto.
intros.
induction H;destruct_hypos...
-
repeat split...
apply WF_var with (U:=U)...
-
pick fresh Z.
assert ( wf_env (Z ~ bind_sub S ++ E)).
specialize_x_and_L Z L.
destruct_hypos.
dependent destruction H1...
dependent destruction H2.
repeat split...
apply WF_all with (L:=L);intros...
eapply H1...
apply WF_all with (L:=L);intros...
eapply H1...
Qed.
Lemma binds_map_free: forall F X Y U P,
In (X, bind_sub U) F ->
X <> Y ->
In (X, bind_sub (subst_tt Y P U)) (map (subst_tb Y P) F).
Proof with auto.
induction F;intros...
apply in_inv in H.
destruct H...
-
destruct a.
inversion H;subst.
simpl...
-
simpl...
Qed.
Lemma subst_tb_wf : forall F Q E Z P T,
WF (F ++ Z ~ Q ++ E) T ->
WF E P ->
WF (map (subst_tb Z P) F ++ E) (subst_tt Z P T).
Proof with eauto.
intros.
generalize dependent P.
dependent induction H;intros;simpl in *...
-
destruct (X==Z);subst...
add_nil_fsub.
apply WF_weakening...
analyze_binds H...
apply WF_var with (U:=(subst_tt Z P U))...
unfold binds in *.
apply In_lemmaL.
apply binds_map_free...
-
apply WF_all with (L:=L \u {{Z}})...
intros.
rewrite subst_tt_open_tt_var...
rewrite_env (map (subst_tb Z P) (X ~ bind_sub T1 ++ F) ++ E).
apply H1 with (Q0:=Q)...
apply WF_type in H2...
Qed.
Lemma typing_regular : forall E e T,
typing E e T ->
wf_env E /\ expr e /\ WF E T.
Proof with auto.
intros.
induction H;destruct_hypos...
-
repeat split...
apply wf_typ_from_binds_typ with (x:=x)...
-
pick fresh Y.
assert (wf_env (Y ~ bind_typ V ++ E)).
specialize_x_and_L Y L...
destruct_hypos...
dependent destruction H1...
repeat split...
+
apply expr_abs with (L:=L)...
apply WF_type with (E:=E) ...
intros.
apply H0...
+
constructor...
specialize_x_and_L Y L...
destruct_hypos.
add_nil_fsub.
apply wf_typ_strengthening with (x:=Y) (U:=V)...
-
inv H6...
-
pick fresh Y.
assert (wf_env (Y ~ bind_sub V ++ E)).
specialize_x_and_L Y L...
destruct_hypos...
dependent destruction H1...
repeat split...
+
apply expr_tabs with (L:=L)...
apply WF_type with (E:=E) ...
intros.
apply H0...
+
apply WF_all with (L:=L)...
intros.
eapply H0...
-
inv H3...
repeat split...
+ constructor... apply WF_type with (E:=E).
apply sub_regular in H0. destruct_hypos...
+
pick fresh X.
rewrite subst_tt_intro with (X:=X)...
rewrite_env (map (subst_tb X T) nil ++ E).
apply subst_tb_wf with (Q:=bind_sub T1)...
apply H8...
apply sub_regular in H0. destruct_hypos...
-
repeat split...
apply sub_regular in H0. destruct_hypos...
Qed.
(*********************************************************)
(*********************************************************)
(******************** Reflexivity ************************)
(*********************************************************)
(*********************************************************)
Lemma Reflexivity: forall E A,
WF E A ->
wf_env E ->
sub E A A.
Proof with auto.
intros.
induction H...
-
constructor...
apply WF_var with (U:=U)...
-
apply sa_all with (L:=L \u dom E \u fv_env E \u fl_env E)...
Qed.
(*********************************************************)
(*********************************************************)
(*********** Context Strengthen/weakening ****************)
(*********************************************************)
(*********************************************************)
Lemma wf_env_strengthening : forall x T E F,
wf_env (F ++ x ~ bind_typ T ++ E) ->
wf_env (F ++ E).
Proof with eauto using wf_typ_strengthening.
induction F; intros Wf_env; inversion Wf_env; subst; simpl_env in *...
Qed.
Lemma Sub_typ_strengthening : forall E F x U A B,
sub (F ++ x ~ bind_typ U ++ E) A B ->
sub (F ++ E) A B.
Proof with eauto using wf_env_strengthening, wf_typ_strengthening.
intros.
dependent induction H...
-
apply sa_trans_tvar with (U:=U0)...
analyze_binds H...
-
apply sa_all with (L:=L);intros...
rewrite_env (((X~ bind_sub S) ++ F) ++ E)...
apply H1 with (x0:=x) (U0:=U)...
Qed.
Lemma Sub_weakening: forall E1 E2 A B E,
sub (E1 ++ E2) A B ->
wf_env (E1 ++ E ++ E2) ->
sub (E1 ++ E ++ E2) A B.
Proof with eauto using WF_weakening.
intros.
generalize dependent E.
dependent induction H;intros...
-
apply sa_all with (L:=L \u dom E1 \u dom E2 \u dom E \u fv_env (E1++E++E2) \u fl_env (E1++E++E2))...
intros.
rewrite_alist (([(X, bind_sub S)] ++ E1) ++ E ++ E2).
apply H1...
rewrite_alist ([(X, bind_sub S)] ++ E1 ++ E ++ E2)...
Qed.
Lemma binds_typ_replacing_subst_tb: forall E X Y T x,
binds x (bind_typ T) E ->
binds x (bind_typ (subst_tt X Y T)) ((map (subst_tb X Y) E)).
Proof.
intros. induction E.
- inv H.
- destruct H.
+ subst. left. reflexivity.
+ right. apply IHE. auto.
Qed.
Lemma binds_sub_replacing_subst_tb: forall E X Y T x,
binds x (bind_sub T) E ->
binds x (bind_sub (subst_tt X Y T)) ((map (subst_tb X Y) E)).
Proof.
intros. induction E.
- inv H.
- destruct H.
+ subst. left. reflexivity.
+ right. apply IHE. auto.
Qed.
Lemma wf_env_cons: forall E1 E2,
wf_env (E1++E2) ->
wf_env E2.
Proof with auto.
induction E1;intros...
destruct a...
dependent destruction H...
Qed.
Lemma WF_from_binds_typ : forall x U E,
wf_env E ->
binds x (bind_sub U) E ->
WF E U.
Proof with auto.
induction 1; intros J; analyze_binds J...
-
inversion BindsTacVal;subst.
add_nil_fsub.
apply WF_weakening...
-
add_nil_fsub.
apply WF_weakening...
-
add_nil_fsub.
apply WF_weakening...
Qed.
Lemma in_binds: forall x a U x0,
a `in` dom (x ++ (a, bind_sub U) :: x0).
Proof with auto.
induction x;intros...
simpl...
simpl...
destruct a...
Qed.
Lemma WF_imply_dom: forall E A,
WF E A ->
fv_tt A [<=] dom E.
Proof with auto.
intros.
induction H;simpl in *;try solve [apply KeySetProperties.subset_empty]...
-
unfold binds in H...
unfold "[<=]".
intros.
apply KeySetFacts.singleton_iff in H0.
subst.
apply in_split in H.
destruct_hypos.
rewrite H...
apply in_binds...
-
apply KeySetProperties.union_subset_3...
-
apply KeySetProperties.union_subset_3...
pick fresh X.
specialize_x_and_L X L.
apply fv_open_tt_notin_inv in H1...
Qed.
(*********************************************************)
(*********************************************************)
(******************** Replacing **************************)
(*********************************************************)
(*********************************************************)
Lemma binds_sub_replacing: forall E1 E2 U X Y x T,
binds x (bind_sub T) (E1++ X ~ bind_sub U ++E2) ->
X <> Y -> x <> X ->
wf_env ( E1 ++ X ~ bind_sub U ++ E2) ->
binds x (bind_sub (subst_tt X Y T)) (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++E2).
Proof with auto.
intros.
apply binds_app_iff in H. apply binds_app_iff.
destruct H.
- left. apply binds_sub_replacing_subst_tb...
- right. inv H. { inv H3... exfalso... }
apply wf_env_cons in H2. inv H2.
pose proof WF_from_binds_typ _ _ H7 H3.
apply WF_imply_dom in H4.
rewrite <- subst_tt_fresh...
Qed.
Lemma typing_replacing: forall E1 E2 e T U X Y,
typing (E1++ X ~ bind_typ U ++E2) e T ->
X <> Y ->
wf_env ( E1 ++ Y ~ bind_typ U ++ E2) ->
typing (E1 ++ Y ~ bind_typ U ++E2) (subst_ee X Y e) T.
Proof with auto.
intros.
generalize dependent Y.
dependent induction H;intros.
- constructor. auto.
- simpl. destruct (x == X)...
{ subst. apply typing_var...
assert (binds X (bind_typ U) (E1 ++ X ~ bind_typ U ++ E2))...
pose proof binds_unique _ _ _ _ _ H0 H3.
rewrite H4... apply uniq_from_wf_env... }
{ apply typing_var with (T:=T)... analyze_binds H0. }
- apply typing_abs with (L:=L \u {{ X }}
\u dom (E1 ++ Y ~ bind_typ U ++ E2) )...
intros.
specialize_x_and_L x L.
rewrite subst_ee_open_ee_var...
rewrite_env ((x~bind_typ V ++ E1) ++ Y ~ bind_typ U ++ E2).
apply H0...
rewrite_env (x~bind_typ V ++ (E1 ++ Y ~ bind_typ U ++ E2)).
constructor...
{ apply typing_regular in H. destruct_hypos.
inv H... rewrite_env (E1 ++ X ~ bind_typ U ++ E2) in H10.
apply wf_typ_strengthening in H10.
apply WF_weakening... }
- apply typing_app with (T1:=T1)...
- simpl. apply typing_tabs with (L:=L \u {{ X }}
\u dom (E1 ++ Y ~ bind_typ U ++ E2) ).
intros.
specialize_x_and_L X0 L.
rewrite subst_ee_open_te_var...
rewrite_env ((X0~bind_sub V ++ E1) ++ Y ~ bind_typ U ++ E2).
apply H0...
rewrite_env (X0~bind_sub V ++ (E1 ++ Y ~ bind_typ U ++ E2)).
constructor...
{ apply typing_regular in H. destruct_hypos.
inv H... rewrite_env (E1 ++ X ~ bind_typ U ++ E2) in H10.
apply wf_typ_strengthening in H10.
apply WF_weakening... }
- simpl. apply typing_tapp with (T1:=T1)...
apply IHtyping...
{ apply Sub_typ_strengthening in H0.
rewrite_env (E1 ++ Y ~ bind_typ U ++ E2).
apply Sub_weakening...
}
- apply typing_sub with (S:=S)...
{ apply Sub_typ_strengthening in H0.
rewrite_env (E1 ++ Y ~ bind_typ U ++ E2).
apply Sub_weakening...
}
Qed.
Lemma WF_replacing: forall E1 E2 T U (X Y:atom),
WF ( E1 ++ X ~ bind_sub U ++E2) T ->
Y <> X ->
WF (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++E2) (subst_tt X Y T).
Proof with auto.
intros.
dependent induction H;intros;simpl;try solve [rewrite_alist (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++ E2);constructor;auto]...
-
destruct (X0==X)...
{ subst. apply WF_var with (U:=U)... }
{ apply binds_app_iff in H. destruct H.
+ apply WF_var with (U:=(subst_tt X Y U0))...
apply binds_app_iff. left.
apply binds_map_free...
+ apply WF_var with (U:=U0)...
simpl. analyze_binds H. }
- apply WF_all with (L:= L \u {{X}});intros...
+ apply IHWF...
+ rewrite_alist ((map (subst_tb X Y) ((X0 ~ bind_sub T1) ++ E1)) ++ Y ~ bind_sub U ++ E2).
rewrite subst_tt_open_tt_var...
Qed.
Lemma maps_subst_tb_free: forall E X U,
X \notin fv_env E ->
map (subst_tb X U) E = E.
Proof with auto.
induction E;intros...
destruct a.
destruct b.
-
simpl in *.
f_equal...
f_equal...
f_equal...
rewrite <- subst_tt_fresh...
-
simpl in *.
f_equal...
f_equal...
f_equal...
rewrite <- subst_tt_fresh...
Qed.
Lemma fv_env_ls_dom: forall E,
wf_env E ->
fv_env E [<=] dom E.
Proof with auto.
induction E;intros;simpl in *...
-
apply AtomSetProperties.subset_empty...
-
destruct a.
destruct b.
+
dependent destruction H.
apply KeySetProperties.subset_add_2...
apply AtomSetProperties.union_subset_3...
apply WF_imply_dom...
+
dependent destruction H.
apply KeySetProperties.subset_add_2...
apply AtomSetProperties.union_subset_3...
apply WF_imply_dom...
Qed.
Lemma notin_from_wf_env: forall E1 X T E2,
wf_env (E1 ++ (X, bind_sub T) :: E2) ->
X \notin fv_tt T \u dom E2 \u dom E1 \u fv_env E2.
Proof with auto.
induction E1;intros...
-
dependent destruction H...
apply WF_imply_dom in H0...
apply fv_env_ls_dom in H...
-
dependent destruction H...
simpl in *...
apply IHE1 in H...
simpl in *...
apply IHE1 in H...
Qed.
Lemma binds_map_free_sub: forall E1 E2 X Y U S Q,
Y \notin {{X}} ->
wf_env (E1 ++ (Y, bind_sub Q) :: E2) ->
binds X (bind_sub U) (E1 ++ (Y, bind_sub Q) :: E2) ->
binds X (bind_sub (subst_tt Y S U)) (map (subst_tb Y S) E1 ++ E2).
Proof with auto.
intros.
analyze_binds H1...
-
unfold binds in *.
apply In_lemmaL.
apply binds_map_free...
-
unfold binds in *.
apply In_lemmaR.
rewrite <- maps_subst_tb_free with (X:=Y) (U:=S)...
apply binds_map_free...
apply notin_from_wf_env in H0...
Qed.
Lemma sub_replacing: forall E1 E2 A B U X Y,
sub (E1++ X ~ bind_sub U ++E2) A B ->
X <> Y ->
wf_env (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++ E2) ->
sub (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++E2) (subst_tt X Y A) (subst_tt X Y B).
Proof with auto.
intros.
generalize dependent Y.
dependent induction H;intros;simpl;try solve [rewrite_alist (map (subst_tb X Y) E1 ++ [(Y, bind_sub U)] ++ E2);constructor;auto;apply WF_replacing;auto]...
-
destruct (X0==X)...
constructor... apply WF_var with (U:=U)...
constructor...
dependent destruction H0.
apply binds_map_free_sub with (S:=Y) in H0...
apply WF_var with (U:=(subst_tt X Y U0))...
analyze_binds H0.
-
destruct (X0==X);subst...
+
apply sa_trans_tvar with (U:=subst_tt X Y U0)...
analyze_binds_uniq H...
apply uniq_from_wf_env...
{ apply sub_regular in H0. destruct_hypos... }
inversion BindsTacVal;subst.
apply sub_regular in H0. destruct_hypos...
apply notin_from_wf_env in H0.
rewrite <- subst_tt_fresh...
apply IHsub...
+
apply sa_trans_tvar with (U:=subst_tt X Y U0)...
analyze_binds H.
*
unfold binds in *.
apply In_lemmaL.
apply binds_map_free...
*
assert (Ht:=BindsTac0).
apply WF_from_binds_typ in Ht...
apply WF_imply_dom in Ht.
apply sub_regular in H0. destruct_hypos.
get_well_form.
apply notin_from_wf_env in H.
rewrite <- subst_tt_fresh...
apply notin_partial with (E2:=dom E2)...
apply wf_env_cons in H2.
apply wf_env_cons in H2...
*
apply IHsub...
-
apply sa_all with (L:=L \u {{X}} \u dom (map (subst_tb X Y) E1 ++ (Y, bind_sub U) :: E2));intros...
apply WF_replacing...
rewrite_env (map (subst_tb X Y) (X0~bind_sub S ++ E1) ++ (Y, bind_sub U) :: E2).
rewrite subst_tt_open_tt_var...
rewrite subst_tt_open_tt_var...
apply H1...
simpl...
constructor...
apply WF_replacing...
Qed.
Lemma typing_replacing2: forall E1 E2 e T U X Y,
typing (E1++ X ~ bind_sub U ++E2) e T ->
X <> Y ->
wf_env ( map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++ E2) ->
typing (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++E2) (subst_te X Y e) (subst_tt X Y T).
Proof with auto.
intros.
generalize dependent Y.
dependent induction H;intros.
- constructor. auto.
- destruct (x == X)...
{ subst. apply typing_var...
assert (binds X (bind_sub U) (E1 ++ X ~ bind_sub U ++ E2))...
pose proof binds_unique _ _ _ _ _ H0 H3.
apply uniq_from_wf_env in H.
specialize (H4 H). inv H4.
}
{ apply typing_var... apply binds_app_iff in H0. apply binds_app_iff.
destruct H0.
- left. apply binds_typ_replacing_subst_tb...
- right. destruct H0. { inv H0... }
apply wf_env_cons in H. inv H.
pose proof wf_typ_from_binds_typ _ _ H6 H0.
apply WF_imply_dom in H3.
rewrite <- subst_tt_fresh...
}
- simpl. apply typing_abs with (L:=L \u {{ X }} \u
dom (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++ E2)
)...
intros.
specialize_x_and_L x L.
rewrite subst_te_open_ee_var...
rewrite_env (map (subst_tb X Y) (x ~ bind_typ V ++ E1) ++ Y ~ bind_sub U ++ E2).
apply H0...
rewrite_env (x ~ bind_typ (subst_tt X Y V) ++ (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++ E2)).
constructor...
{ apply typing_regular in H. destruct_hypos.
inv H... rewrite_env (E1 ++ (X ~ bind_sub U) ++ E2) in H10.
apply WF_replacing... }
- simpl. apply typing_app with (T2:=subst_tt X Y T2) (T1:=subst_tt X Y T1)...
+ apply IHtyping1...
+ apply IHtyping2...
- simpl. apply typing_tabs with (L:=L \u {{ X }}
\u dom (E1 ++ Y ~ bind_typ U ++ E2) ).
intros.
specialize_x_and_L X0 L.
rewrite subst_te_open_te_var...
rewrite subst_tt_open_tt_var...
rewrite_env ( map (subst_tb X Y) (X0~bind_sub V ++ E1) ++ Y ~ bind_sub U ++ E2).
apply H0...
rewrite_env (X0~bind_sub (subst_tt X Y V) ++ (map (subst_tb X Y) E1 ++ Y ~ bind_sub U ++ E2)).
constructor...
{ apply typing_regular in H. destruct_hypos.
inv H... rewrite_env(E1 ++ (X ~ bind_sub U) ++ E2) in H10.
apply WF_replacing... }
- simpl. rewrite subst_tt_open_tt...
apply typing_tapp with (T2:=subst_tt X Y T2) (T1:=subst_tt X Y T1)...
+ apply IHtyping...
+ apply sub_replacing...
- apply typing_sub with (S:= subst_tt X Y S)...
apply sub_replacing...
Qed.
End Fsub. |
Short Sales in Newtown, CT - as of 10/22/10. Back in September 2008, we posted a blog titled "Short Sale - What is It?". We think this is useful information as we frequently explain what a short sale is to both buyers and sellers. Our intention is to update you every 2 months about the short sale activity in Newtown, CT.
The price range of the actively listed short sales in Newtown range from $159,000 to $875,000. As you can see, short sales in Newtown, CT have been selling, despite being difficult transactions.
If you would like a list of the short sales in Newtown, CT, just email us and we'll forward it to you ASAP.
If you would like to sell your home and feel it might be a short sale, please contact us. WE CAN HELP YOU. We are experienced with short sales and we are also SFR Certified. Anything you tell us will be held in the strictest confidence and will not be shared with anyone else. |
Wheeler has been termed " the most famous British archaeologist of the twentieth century " by archaeologists Gabriel Moshenska and Tim Schadla @-@ Hall . Highlighting his key role in encouraging interest in archaeology throughout British society , they stated that his " mastery of public archaeology was founded on his keen eye for value and a showman 's willingness to package and sell the past " . This was an issue about which Wheeler felt very strongly ; writing his obituary for the Biographical Memoirs of Fellows of the Royal Society , the English archaeologist Stuart Piggott noted that Wheeler placed " great importance to the archaeologist 's obligation to the public , on whose support the prosecution of his subject ultimately depended . "
|
Formal statement is: lemma filterlim_at_bot_at_right: fixes f :: "'a::linorder_topology \<Rightarrow> 'b::linorder" assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y" and bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)" and Q: "eventually Q (at_right a)" and bound: "\<And>b. Q b \<Longrightarrow> a < b" and P: "eventually P at_bot" shows "filterlim f at_bot (at_right a)" Informal statement is: If $f$ is a monotone function and $g$ is a bijection such that $f \circ g$ is the identity function, then $f$ is continuous at $a$ if and only if $g$ is continuous at $a$. |
||| OrdList are labelled list (key/value store) that embed a order relation on keys
||| to sort its elements.
module Flexidisc.OrdList.Type
%default total
%access public export
||| The OrdList consturctors are exported publicly as they need to be used at
||| the type level.
||| It's better not to use the constructor for something else that just pattern
||| matching, as they dont guarantee that the keys are ordered.
||| @k Type of the keys
||| @v Type of the values
||| @o The order relation used to compared keys
data OrdList : (k : Type) -> (o : Ord k) -> (v : Type) -> Type where
Nil : OrdList k o v
(::) : (k, v) -> OrdList k o v -> OrdList k o v
%name OrdList xs, ys, zs
keys : OrdList k o v -> List k
keys [] = []
keys (kv :: xs) = fst kv :: keys xs
implementation Functor (OrdList k o) where
map f [] = []
map f (kv :: xs) = map f kv :: map f xs
||| Insert an element in the list before the first element that is greater than
||| the given one., according to the order `o`
insert : (x : (k, v)) -> (xs : OrdList k o v) -> OrdList k o v
insert x []= [x]
insert (k, v) ((k', v') :: xs) with (k < k')
| False = (k',v') :: (insert (k, v) xs)
| True = (k,v) :: (k',v') :: xs
||| Merge two `OrdList`, preserving the order if the initial list are ordered.
merge : (xs, ys : OrdList k o v) -> OrdList k o v
merge [] ys = ys
merge xs [] = xs
merge ((k, v) :: hs) ((k', v') :: xs) with (k < k')
| False = (k', v') :: merge ((k, v) :: hs) xs
| True = (k , v) :: merge hs ((k', v') :: xs)
||| Sort a list.
toOrdList : (o : Ord k) => List (k, v) -> OrdList k o v
toOrdList = foldl (flip insert) Nil
||| Morphism to a list.
toList : OrdList k o v -> List (k, v)
toList [] = []
toList (x :: xs) = x :: toList xs
namespace properties
mapPreservesKeys : (xs : OrdList k o v) -> (f : v-> v') ->
keys xs = keys (map f xs)
mapPreservesKeys [] f = Refl
mapPreservesKeys ((a, b) :: xs) f = cong $ mapPreservesKeys xs f
|
/-
Copyright (c) 2021 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.special_linear_group
/-!
# The General Linear group $GL(n, R)$
This file defines the elements of the General Linear group `general_linear_group n R`,
consisting of all invertible `n` by `n` `R`-matrices.
## Main definitions
* `matrix.general_linear_group` is the type of matrices over R which are units in the matrix ring.
* `matrix.GL_pos` gives the subgroup of matrices with
positive determinant (over a linear ordered ring).
## Tags
matrix group, group, matrix inverse
-/
namespace matrix
universes u v
open_locale matrix
open linear_map
-- disable this instance so we do not accidentally use it in lemmas.
local attribute [-instance] special_linear_group.has_coe_to_fun
/-- `GL n R` is the group of `n` by `n` `R`-matrices with unit determinant.
Defined as a subtype of matrices-/
abbreviation general_linear_group (n : Type u) (R : Type v)
[decidable_eq n] [fintype n] [comm_ring R] : Type* := (matrix n n R)Λ£
notation `GL` := general_linear_group
namespace general_linear_group
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]
/-- The determinant of a unit matrix is itself a unit. -/
@[simps]
def det : GL n R β* RΛ£ :=
{ to_fun := Ξ» A,
{ val := (βA : matrix n n R).det,
inv := (β(Aβ»ΒΉ) : matrix n n R).det,
val_inv := by rw [βdet_mul, βmul_eq_mul, A.mul_inv, det_one],
inv_val := by rw [βdet_mul, βmul_eq_mul, A.inv_mul, det_one]},
map_one' := units.ext det_one,
map_mul' := Ξ» A B, units.ext $ det_mul _ _ }
/--The `GL n R` and `general_linear_group R n` groups are multiplicatively equivalent-/
def to_lin : (GL n R) β* (linear_map.general_linear_group R (n β R)) :=
units.map_equiv to_lin_alg_equiv'.to_mul_equiv
/--Given a matrix with invertible determinant we get an element of `GL n R`-/
def mk' (A : matrix n n R) (h : invertible (matrix.det A)) : GL n R :=
unit_of_det_invertible A
/--Given a matrix with unit determinant we get an element of `GL n R`-/
noncomputable def mk'' (A : matrix n n R) (h : is_unit (matrix.det A)) : GL n R :=
nonsing_inv_unit A h
/--Given a matrix with non-zero determinant over a field, we get an element of `GL n K`-/
def mk_of_det_ne_zero {K : Type*} [field K] (A : matrix n n K) (h : matrix.det A β 0) :
GL n K :=
mk' A (invertible_of_nonzero h)
lemma ext_iff (A B : GL n R) : A = B β (β i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :=
units.ext_iff.trans matrix.ext_iff.symm
/-- Not marked `@[ext]` as the `ext` tactic already solves this. -/
lemma ext β¦A B : GL n Rβ¦ (h : β i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :
A = B :=
units.ext $ matrix.ext h
section coe_lemmas
variables (A B : GL n R)
@[simp] lemma coe_mul : β(A * B) = (βA : matrix n n R) β¬ (βB : matrix n n R) := rfl
@[simp] lemma coe_one : β(1 : GL n R) = (1 : matrix n n R) := rfl
lemma coe_inv : β(Aβ»ΒΉ) = (βA : matrix n n R)β»ΒΉ :=
begin
letI := A.invertible,
exact inv_of_eq_nonsing_inv (βA : matrix n n R),
end
/-- An element of the matrix general linear group on `(n) [fintype n]` can be considered as an
element of the endomorphism general linear group on `n β R`. -/
def to_linear : general_linear_group n R β* linear_map.general_linear_group R (n β R) :=
units.map_equiv matrix.to_lin_alg_equiv'.to_ring_equiv.to_mul_equiv
-- Note that without the `@` and `βΉ_βΊ`, lean infers `Ξ» a b, _inst_1 a b` instead of `_inst_1` as the
-- decidability argument, which prevents `simp` from obtaining the instance by unification.
-- These `Ξ» a b, _inst a b` terms also appear in the type of `A`, but simp doesn't get confused by
-- them so for now we do not care.
@[simp] lemma coe_to_linear :
(@to_linear n βΉ_βΊ βΉ_βΊ _ _ A : (n β R) ββ[R] (n β R)) = matrix.mul_vec_lin A :=
rfl
@[simp] lemma to_linear_apply (v : n β R) :
(@to_linear n βΉ_βΊ βΉ_βΊ _ _ A) v = matrix.mul_vec_lin βA v :=
rfl
end coe_lemmas
end general_linear_group
namespace special_linear_group
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]
instance has_coe_to_general_linear_group : has_coe (special_linear_group n R) (GL n R) :=
β¨Ξ» A, β¨βA, β(Aβ»ΒΉ), congr_arg coe (mul_right_inv A), congr_arg coe (mul_left_inv A)β©β©
end special_linear_group
section
variables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]
section
variables (n R)
/-- This is the subgroup of `nxn` matrices with entries over a
linear ordered ring and positive determinant. -/
def GL_pos : subgroup (GL n R) :=
(units.pos_subgroup R).comap general_linear_group.det
end
@[simp] lemma mem_GL_pos (A : GL n R) : A β GL_pos n R β 0 < (A.det : R) := iff.rfl
end
section has_neg
variables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]
[fact (even (fintype.card n))]
/-- Formal operation of negation on general linear group on even cardinality `n` given by negating
each element. -/
instance : has_neg (GL_pos n R) :=
β¨Ξ» g, β¨-g, begin
rw [mem_GL_pos, general_linear_group.coe_det_apply, units.coe_neg, det_neg,
nat.neg_one_pow_of_even (fact.out (even (fintype.card n))), one_mul],
exact g.prop,
endβ©β©
instance : has_distrib_neg (GL_pos n R) :=
{ neg := has_neg.neg,
neg_neg := Ξ» x, subtype.ext $ neg_neg _,
neg_mul := Ξ» x y, subtype.ext $ neg_mul _ _,
mul_neg := Ξ» x y, subtype.ext $ mul_neg _ _ }
@[simp] lemma GL_pos.coe_neg (g : GL_pos n R) : β(- g) = - (βg : matrix n n R) :=
rfl
@[simp] lemma GL_pos.coe_neg_apply (g : GL_pos n R) (i j : n) :
(β(-g) : matrix n n R) i j = -((βg : matrix n n R) i j) :=
rfl
end has_neg
namespace special_linear_group
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [linear_ordered_comm_ring R]
/-- `special_linear_group n R` embeds into `GL_pos n R` -/
def to_GL_pos : special_linear_group n R β* GL_pos n R :=
{ to_fun := Ξ» A, β¨(A : GL n R), show 0 < (βA : matrix n n R).det, from A.prop.symm βΈ zero_lt_oneβ©,
map_one' := subtype.ext $ units.ext $ rfl,
map_mul' := Ξ» Aβ Aβ, subtype.ext $ units.ext $ rfl }
instance : has_coe (special_linear_group n R) (GL_pos n R) := β¨to_GL_posβ©
lemma coe_eq_to_GL_pos : (coe : special_linear_group n R β GL_pos n R) = to_GL_pos := rfl
lemma to_GL_pos_injective :
function.injective (to_GL_pos : special_linear_group n R β GL_pos n R) :=
(show function.injective ((coe : GL_pos n R β matrix n n R) β to_GL_pos),
from subtype.coe_injective).of_comp
end special_linear_group
section examples
/-- The matrix [a, b; -b, a] (inspired by multiplication by a complex number); it is an element of
$GL_2(R)$ if `a ^ 2 + b ^ 2` is nonzero. -/
@[simps coe {fully_applied := ff}]
def plane_conformal_matrix {R} [field R] (a b : R) (hab : a ^ 2 + b ^ 2 β 0) :
matrix.general_linear_group (fin 2) R :=
general_linear_group.mk_of_det_ne_zero ![![a, -b], ![b, a]]
(by simpa [det_fin_two, sq] using hab)
/- TODO: Add Iwasawa matrices `n_x=![![1,x],![0,1]]`, `a_t=![![exp(t/2),0],![0,exp(-t/2)]]` and
`k_ΞΈ==![![cos ΞΈ, sin ΞΈ],![-sin ΞΈ, cos ΞΈ]]`
-/
end examples
namespace general_linear_group
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]
-- this section should be last to ensure we do not use it in lemmas
section coe_fn_instance
/-- This instance is here for convenience, but is not the simp-normal form. -/
instance : has_coe_to_fun (GL n R) (Ξ» _, n β n β R) :=
{ coe := Ξ» A, A.val }
@[simp] lemma coe_fn_eq_coe (A : GL n R) : βA = (βA : matrix n n R) := rfl
end coe_fn_instance
end general_linear_group
end matrix
|
import data.serial
open serial serializer
structure point :=
(x y z : β)
instance : serial point :=
by mk_serializer (point.mk <$> ser_field point.x <*> ser_field point.y <*> ser_field point.z)
example : serial point :=
begin
apply of_serializer (point.mk <$> ser_field point.x <*> ser_field point.y <*> ser_field point.z),
intro w, cases w,
apply there_and_back_again_seq,
apply there_and_back_again_seq,
apply there_and_back_again_map,
{ simp },
{ refl },
{ simp },
{ refl },
{ simp },
end
@[derive serial]
inductive my_sum
| first : my_sum
| second : β β my_sum
| third (n : β) (xs : list β) : n β€ xs.length β my_sum
@[derive serial]
structure my_struct :=
(x : β)
(xs : list β)
(bounded : xs.length β€ x)
@[derive [serial, decidable_eq]]
inductive tree' (Ξ± : Type)
| leaf {} : tree'
| node2 : Ξ± β tree' β tree' β tree'
| node3 : Ξ± β tree' β tree' β tree' β tree'
open tree'
meta def tree'.repr {Ξ±} [has_repr Ξ±] : tree' Ξ± β string
| leaf := "leaf"
| (node2 x tβ tβ) := to_string $ format!"(node2 {repr x} {tree'.repr tβ} {tree'.repr tβ})"
| (node3 x tβ tβ tβ) := to_string $ format!"(node3 {repr x} {tree'.repr tβ} {tree'.repr tβ} {tree'.repr tβ})"
meta instance {Ξ±} [has_repr Ξ±] : has_repr (tree' Ξ±) := β¨ tree'.repr β©
def x := node2 2 (node3 77777777777777 leaf leaf (node2 1 leaf leaf)) leaf
#eval serialize x
-- [17, 1, 5, 2, 430029026, 72437, 0, 0, 1, 3, 0, 0, 0]
#eval deserialize (tree' β) [17, 1, 5, 2, 430029026, 72437, 0, 0, 1, 3, 0, 0, 0]
-- (some (node2 2 (node3 77777777777777 leaf leaf (node2 1 leaf leaf)) leaf))
#eval (deserialize _ (serialize x) = some x : bool)
-- tt
open medium
example (x : tree' β) : deserialize _ (serialize x) = some x :=
by { dsimp [serialize,deserialize],
rw [eval_eval,serial.correctness],
refl }
|
theory List_Demo
imports Main
begin
datatype 'a list = Nil | Cons "'a" "'a list"
term "Nil"
declare [[names_short]]
fun app :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
"app Nil ys = ys" |
"app (Cons x xs) ys = Cons x (app xs ys)"
fun rev :: "'a list \<Rightarrow> 'a list" where
"rev Nil = Nil" |
"rev (Cons x xs) = app (rev xs) (Cons x Nil)"
value "rev(Cons True (Cons False Nil))"
value "rev(Cons a (Cons b Nil))"
lemma app_Nil2[simp]: "app xs Nil = xs"
apply (induction xs)
apply auto
done
lemma app_assoc[simp]: "app (app xs ys) zs = app xs (app ys zs)"
apply (induction xs)
apply auto
done
lemma rev_app[simp]: "rev (app xs ys) = app (rev ys) (rev xs)"
apply (induction xs)
apply auto
done
theorem rev_rev[simp]: "rev (rev xs) = xs"
apply (induction xs)
apply auto
done
end
|
(** Calculation of an abstract machine for arithmetic expressions +
state + unbounded loops. *)
Require Import List.
Require Import ListIndex.
Require Import Tactics.
(** * Syntax *)
Inductive Expr : Set :=
| Val : nat -> Expr
| Add : Expr -> Expr -> Expr
| Get : Expr.
Inductive Stmt : Set :=
| Put : Expr -> Stmt
| Seqn : Stmt -> Stmt -> Stmt
| While : Expr -> Stmt -> Stmt.
(** * Semantics *)
Definition State := nat.
Reserved Notation "x β[ q ] y" (at level 80, no associativity).
Inductive eval : Expr -> State -> nat -> Prop :=
| eval_val q n : Val n β[q] n
| eval_add q x y m n : x β[q] n -> y β[q] m -> Add x y β[q] (n + m)
| eval_get q : Get β[q] q
where "x β[ q ] y" := (eval x q y).
Reserved Notation "x β[ q ] q'" (at level 80, no associativity).
Inductive run : Stmt -> State -> State -> Prop :=
| run_put x q v : x β[q] v -> Put x β[q] v
| run_seqn x1 x2 q1 q2 q3 : x1 β[q1] q2 -> x2 β[q2] q3 -> Seqn x1 x2 β[q1] q3
| run_while_exit x1 x2 q : x1 β[q] 0 -> While x1 x2 β[q] q
| run_while_cont v x1 x2 q1 q2 q3 : x1 β[q1] v -> v > 0 -> x2 β[q1] q2 -> While x1 x2 β[q2] q3
-> While x1 x2 β[q1] q3
where "x β[ q ] y" := (run x q y).
(** * Abstract machine *)
Inductive CONT : Set :=
| NEXT : Expr -> State -> CONT -> CONT
| ADD : nat -> CONT -> CONT
| PUT : CONT -> CONT
| SEQN : Stmt -> CONT -> CONT
| CHECK : Expr -> Stmt -> State -> CONT -> CONT
| WHILE : Expr -> Stmt -> CONT -> CONT
| HALT : CONT
.
Inductive Conf : Set :=
| eval'' : Expr -> State -> CONT -> Conf
| run'' : Stmt -> State -> CONT -> Conf
| exec : CONT -> nat -> Conf
| exec' : CONT -> State -> Conf
.
Notation "β¨ x , q , c β©" := (eval'' x q c).
Notation "β¨| x , q , c |β©" := (run'' x q c).
Notation "βͺ c , v β«" := (exec c v).
Notation "βͺ| c , q |β«" := (exec' c q).
Reserved Notation "x ==> y" (at level 80, no associativity).
Inductive AM : Conf -> Conf -> Prop :=
| am_val n q c : β¨Val n, q, cβ© ==> βͺc, nβ«
| am_add x y c q : β¨Add x y, q, cβ© ==> β¨x, q, NEXT y q cβ©
| am_get q c : β¨Get, q, c β© ==> βͺc, q β«
| am_put x q c : β¨|Put x, q, c|β© ==> β¨x, q, PUT cβ©
| am_seqn x1 x2 q1 c : β¨|Seqn x1 x2, q1, c|β© ==> β¨|x1, q1, SEQN x2 c|β©
| am_while x1 x2 q c : β¨|While x1 x2, q, c |β© ==> β¨x1, q, CHECK x1 x2 q cβ©
| am_NEXT y c n q : βͺNEXT y q c, nβ« ==> β¨y, q, ADD n cβ©
| am_ADD c n m : βͺADD n c, mβ« ==> βͺc, n+mβ«
| am_PUT c n : βͺPUT c, nβ« ==> βͺ|c, n|β«
| am_SEQN x2 c q2 : βͺ| SEQN x2 c, q2|β« ==> β¨|x2, q2, c |β©
| am_CHECK_0 c q x1 x2 : βͺCHECK x1 x2 q c, 0β« ==> βͺ|c, q|β«
| am_CHECK_S c q v x1 x2 : v > 0 -> βͺCHECK x1 x2 q c, vβ« ==> β¨|x2, q, WHILE x1 x2 c|β©
| am_WHILE x1 x2 c q2 : βͺ|WHILE x1 x2 c, q2 |β« ==> β¨|While x1 x2, q2, c|β©
where "x ==> y" := (AM x y).
(** * Calculation *)
(** Boilerplate to import calculation tactics *)
Module AM <: Preorder.
Definition Conf := Conf.
Definition VM := AM.
End AM.
Module AMCalc := Calculation AM.
Import AMCalc.
(** Specification of the abstract machine for expressions *)
Theorem specExpr x q v c : x β[q] v -> β¨x, q, cβ© =>> βͺc, vβ«.
(** Setup the induction proof *)
Proof.
intros.
generalize dependent c.
induction H;intros.
(** Calculation of the abstract machine *)
begin
βͺc, nβ«.
<== { apply am_val }
β¨Val n, q, cβ©.
[].
begin
βͺc, n + m β«.
<== { apply am_ADD }
βͺADD n c, m β«.
<<= { apply IHeval2 }
β¨y, q, ADD n cβ©.
<<= { apply am_NEXT }
βͺNEXT y q c , nβ«.
<<= { apply IHeval1 }
β¨x, q, NEXT y q cβ©.
<== {apply am_add}
β¨Add x y, q, cβ©.
[].
begin
βͺc, qβ«.
<== {apply am_get}
β¨Get, q, c β©.
[].
Qed.
Theorem specStmt x q q' c : x β[q] q' -> β¨| x, q, c|β© =>> βͺ|c, q'|β«.
(** Setup the induction proof *)
Proof.
intros.
generalize dependent c.
induction H;intros.
(** Calculation of the abstract machine *)
begin
βͺ|c, v|β«.
<<= { apply am_PUT }
βͺPUT c, vβ«.
<<= { apply specExpr }
β¨x, q, PUT cβ©.
<<= { apply am_put }
β¨|Put x, q, c|β©.
[].
begin
βͺ|c, q3 |β«.
<<= {apply IHrun2}
β¨|x2, q2, c |β©.
<== {apply am_SEQN}
βͺ| SEQN x2 c, q2|β«.
<<= {apply IHrun1}
β¨|x1, q1, SEQN x2 c |β©.
<== {apply am_seqn}
β¨|Seqn x1 x2, q1, c |β©.
[].
begin
βͺ|c, q|β«.
<== {apply am_CHECK_0}
βͺCHECK x1 x2 q c, 0β«.
<<= {apply specExpr}
β¨x1, q, CHECK x1 x2 q cβ©.
<== {apply am_while}
β¨|While x1 x2, q, c |β©.
[].
begin
βͺ|c, q3 |β«.
<<= {apply IHrun2}
β¨|While x1 x2, q2, c|β©.
<== {apply am_WHILE}
βͺ|WHILE x1 x2 c, q2|β«.
<<= {apply IHrun1}
β¨|x2, q1, WHILE x1 x2 c|β©.
<== {apply am_CHECK_S}
βͺCHECK x1 x2 q1 c, vβ«.
<<= {apply specExpr}
β¨x1, q1, CHECK x1 x2 q1 cβ©.
<== {apply am_while}
β¨|While x1 x2, q1, c |β©.
[].
Qed.
(** * Soundness *)
Lemma determ_am : determ AM.
Proof.
intros C c1 c2 V.
induction V; intro V'; inversion V'; subst; try congruence;
match goal with
| [H : 0>0 |- _] => inversion H
end.
Qed.
Definition terminates (p : Stmt) : Prop := exists r, p β[0] r.
Theorem sound x C : terminates x -> β¨|x, 0, HALT|β© =>>! C ->
exists r, C = βͺ|HALT, r|β« /\ x β[0] r.
Proof.
unfold terminates. intros. destruct H as [r T].
pose (specStmt x 0 r HALT) as H'. exists r. split. pose (determ_trc determ_am) as D.
unfold determ in D. eapply D. eassumption. split. eauto. intro. destruct H.
inversion H. assumption.
Qed.
|
!*****************************************************************************************
!>
! Refactored SLATEC/EISPACK routines for computing eigenvalues and eigenvectors.
module eispack_module
use kind_module, only: wp
implicit none
private
public :: compute_eigenvalues_and_eigenvectors
contains
!*****************************************************************************************
!*****************************************************************************************
!>
!***PURPOSE Balance a real general matrix and isolate eigenvalues
! whenever possible.
!***KEYWORDS EIGENVECTORS, EISPACK
!***AUTHOR Smith, B. T., et al.
!***DESCRIPTION
!
! This subroutine is a translation of the ALGOL procedure BALANCE,
! NUM. MATH. 13, 293-304(1969) by Parlett and Reinsch.
! HANDBOOK FOR AUTO. COMP., Vol.II-LINEAR ALGEBRA, 315-326(1971).
!
! This subroutine balances a REAL matrix and isolates
! eigenvalues whenever possible.
!
! On INPUT
!
! NM must be set to the row dimension of the two-dimensional
! array parameter, A, as declared in the calling program
! dimension statement. NM is an INTEGER variable.
!
! N is the order of the matrix A. N is an INTEGER variable.
! N must be less than or equal to NM.
!
! A contains the input matrix to be balanced. A is a
! two-dimensional REAL array, dimensioned A(NM,N).
!
! On OUTPUT
!
! A contains the balanced matrix.
!
! LOW and IGH are two INTEGER variables such that A(I,J)
! is equal to zero if
! (1) I is greater than J and
! (2) J=1,...,LOW-1 or I=IGH+1,...,N.
!
! SCALE contains information determining the permutations and
! scaling factors used. SCALE is a one-dimensional REAL array,
! dimensioned SCALE(N).
!
! Suppose that the principal submatrix in rows LOW through IGH
! has been balanced, that P(J) denotes the index interchanged
! with J during the permutation step, and that the elements
! of the diagonal matrix used are denoted by D(I,J). Then
! SCALE(J) = P(J), for J = 1,...,LOW-1
! = D(J,J), J = LOW,...,IGH
! = P(J) J = IGH+1,...,N.
! The order in which the interchanges are made is N to IGH+1,
! then 1 TO LOW-1.
!
! Note that 1 is returned for IGH if IGH is zero formally.
!
! The ALGOL procedure EXC contained in BALANCE appears in
! BALANC in line. (Note that the ALGOL roles of identifiers
! K,L have been reversed.)
!
! Questions and comments should be directed to B. S. Garbow,
! Applied Mathematics Division, ARGONNE NATIONAL LABORATORY
! ------------------------------------------------------------------
!
!***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
! Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
! system Routines - EISPACK Guide, Springer-Verlag,
! 1976.
!***REVISION HISTORY (YYMMDD)
! 760101 DATE WRITTEN
! 890831 Modified array declarations. (WRB)
! 890831 REVISION DATE from Version 3.2
! 891214 Prologue converted to Version 4.0 format. (BAB)
! 920501 Reformatted the REFERENCES section. (WRB)
subroutine balanc(Nm, n, a, Low, Igh, Scale)
implicit none
integer i, j, k, l, m, n, jj, Nm, Igh, Low, iexc, igo, igo1, igo2
real(wp) a(Nm, *), Scale(*)
real(wp) c, f, g, r, s, b2, radix
logical noconv
radix = 16
b2 = radix*radix
k = 1
l = n
igo = 1
igo1 = 0
igo2 = 1
! IN-LINE PROCEDURE FOR ROW AND
! COLUMN EXCHANGE
do while (igo2 == 1)
igo2 = 0
if (igo1 == 1) then
Scale(m) = j
if (j /= m) then
do i = 1, l
f = a(i, j)
a(i, j) = a(i, m)
a(i, m) = f
enddo
do i = k, n
f = a(j, i)
a(j, i) = a(m, i)
a(m, i) = f
enddo
endif
if (iexc == 2) then
! SEARCH FOR COLUMNS ISOLATING AN EIGENVALUE
! AND PUSH THEM LEFT
k = k + 1
igo = 0
else
! SEARCH FOR ROWS ISOLATING AN EIGENVALUE
! AND PUSH THEM DOWN
if (l == 1) then
Low = k
Igh = l
return
end if
l = l - 1
endif
end if
! FOR J=L STEP -1 UNTIL 1 DO --
igo1 = 1
if (igo == 1) then
do jj = 1, l
igo = 1
j = l + 1 - jj
do i = 1, l
if (i /= j) then
if (a(j, i) /= 0.0_wp) then
igo = 0
exit
end if
endif
enddo
if (igo == 0) cycle
m = l
iexc = 1
igo2 = 1
exit
enddo
if (igo2 == 1) cycle
end if
do j = k, l
igo = 1
do i = k, l
if (i /= j) then
if (a(i, j) /= 0.0_wp) then
igo = 0
exit
end if
endif
enddo
if (igo == 0) cycle
m = k
iexc = 2
igo2 = 1
exit
enddo
if (igo2 == 1) cycle
end do
! NOW BALANCE THE SUBMATRIX IN ROWS K TO L
do i = k, l
Scale(i) = 1.0_wp
enddo
! ITERATIVE LOOP FOR NORM REDUCTION
noconv = .true.
do while (noconv)
noconv = .false.
do i = k, l
c = 0.0_wp
r = 0.0_wp
do j = k, l
if (j /= i) then
c = c + abs(a(j, i))
r = r + abs(a(i, j))
endif
enddo
! GUARD AGAINST ZERO C OR R DUE TO UNDERFLOW
if (c /= 0.0_wp .and. r /= 0.0_wp) then
g = r/radix
f = 1.0_wp
s = c + r
do while (c < g)
f = f*radix
c = c*b2
end do
g = r*radix
do while (c >= g)
f = f/radix
c = c/b2
end do
! NOW BALANCE
if ((c + r)/f < 0.95_wp*s) then
g = 1.0_wp/f
Scale(i) = Scale(i)*f
noconv = .true.
do j = k, n
a(i, j) = a(i, j)*g
enddo
do j = 1, l
a(j, i) = a(j, i)*f
enddo
endif
endif
enddo
end do
Low = k
Igh = l
end subroutine balanc
!*****************************************************************************************
!>
!***PURPOSE Form the eigenvectors of a real general matrix from the
! eigenvectors of matrix output from BALANC.
!***KEYWORDS EIGENVECTORS, EISPACK
!***AUTHOR Smith, B. T., et al.
!***DESCRIPTION
!
! This subroutine is a translation of the ALGOL procedure BALBAK,
! NUM. MATH. 13, 293-304(1969) by Parlett and Reinsch.
! HANDBOOK FOR AUTO. COMP., Vol.II-LINEAR ALGEBRA, 315-326(1971).
!
! This subroutine forms the eigenvectors of a REAL GENERAL
! matrix by back transforming those of the corresponding
! balanced matrix determined by BALANC.
!
! On INPUT
!
! NM must be set to the row dimension of the two-dimensional
! array parameter, Z, as declared in the calling program
! dimension statement. NM is an INTEGER variable.
!
! N is the number of components of the vectors in matrix Z.
! N is an INTEGER variable. N must be less than or equal
! to NM.
!
! LOW and IGH are INTEGER variables determined by BALANC.
!
! SCALE contains information determining the permutations and
! scaling factors used by BALANC. SCALE is a one-dimensional
! REAL array, dimensioned SCALE(N).
!
! M is the number of columns of Z to be back transformed.
! M is an INTEGER variable.
!
! Z contains the real and imaginary parts of the eigen-
! vectors to be back transformed in its first M columns.
! Z is a two-dimensional REAL array, dimensioned Z(NM,M).
!
! On OUTPUT
!
! Z contains the real and imaginary parts of the
! transformed eigenvectors in its first M columns.
!
! Questions and comments should be directed to B. S. Garbow,
! Applied Mathematics Division, ARGONNE NATIONAL LABORATORY
! ------------------------------------------------------------------
!
!***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
! Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
! system Routines - EISPACK Guide, Springer-Verlag,
! 1976.
!***REVISION HISTORY (YYMMDD)
! 760101 DATE WRITTEN
! 890831 Modified array declarations. (WRB)
! 890831 REVISION DATE from Version 3.2
! 891214 Prologue converted to Version 4.0 format. (BAB)
! 920501 Reformatted the REFERENCES section. (WRB)
subroutine balbak(Nm, n, Low, Igh, Scale, m, z)
implicit none
integer i, j, k, m, n, ii, Nm, Igh, Low
real(wp) Scale(*), z(Nm, *)
real(wp) s
if (m /= 0) then
if (Igh /= Low) then
do i = Low, Igh
s = Scale(i)
! LEFT HAND EIGENVECTORS ARE BACK TRANSFORMED
! IF THE FOREGOING STATEMENT IS REPLACED BY
! S=1.0_wp/SCALE(I).
do j = 1, m
z(i, j) = z(i, j)*s
enddo
enddo
endif
! FOR I=LOW-1 STEP -1 UNTIL 1,
! IGH+1 STEP 1 UNTIL N DO --
do ii = 1, n
i = ii
if (i < Low .or. i > Igh) then
if (i < Low) i = Low - ii
k = Scale(i)
if (k /= i) then
do j = 1, m
s = z(i, j)
z(i, j) = z(k, j)
z(k, j) = s
enddo
endif
endif
enddo
endif
end subroutine balbak
!*****************************************************************************************
!>
!***PURPOSE Compute the complex quotient of two complex numbers.
!***AUTHOR (UNKNOWN)
!***DESCRIPTION
!
! Complex division, (CR,CI) = (AR,AI)/(BR,BI)
!
!***SEE ALSO EISDOC
!***REVISION HISTORY (YYMMDD)
! 811101 DATE WRITTEN
! 891214 Prologue converted to Version 4.0 format. (BAB)
! 900402 Added TYPE section. (WRB)
subroutine cdiv(Ar, Ai, Br, Bi, Cr, Ci)
implicit none
real(wp) Ar, Ai, Br, Bi, Cr, Ci
real(wp) s, ars, ais, brs, bis
s = abs(Br) + abs(Bi)
ars = Ar/s
ais = Ai/s
brs = Br/s
bis = Bi/s
s = brs**2 + bis**2
Cr = (ars*brs + ais*bis)/s
Ci = (ais*brs - ars*bis)/s
end subroutine cdiv
!*****************************************************************************************
!>
!***PURPOSE Reduce a real general matrix to upper Hessenberg form
! using stabilized elementary similarity transformations.
!***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
!***AUTHOR Smith, B. T., et al.
!***DESCRIPTION
!
! This subroutine is a translation of the ALGOL procedure ELMHES,
! NUM. MATH. 12, 349-368(1968) by Martin and Wilkinson.
! HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 339-358(1971).
!
! Given a REAL GENERAL matrix, this subroutine
! reduces a submatrix situated in rows and columns
! LOW through IGH to upper Hessenberg form by
! stabilized elementary similarity transformations.
!
! On INPUT
!
! NM must be set to the row dimension of the two-dimensional
! array parameter, A, as declared in the calling program
! dimension statement. NM is an INTEGER variable.
!
! N is the order of the matrix, A. N is an INTEGER variable.
! N must be less than or equal to NM.
!
! LOW and IGH are two INTEGER variables determined by the
! balancing subroutine BALANC. If BALANC has not been
! used, set LOW=1 and IGH equal to the order of the matrix, N.
!
! A contains the input matrix. A is a two-dimensional REAL
! array, dimensioned A(NM,N).
!
! On OUTPUT
!
! A contains the upper Hessenberg matrix. The multipliers which
! were used in the reduction are stored in the remaining
! triangle under the Hessenberg matrix.
!
! INTV contains information on the rows and columns interchanged
! in the reduction. Only elements LOW through IGH are used.
! INTV is a one-dimensional INTEGER array, dimensioned INTV(IGH).
!
! Questions and comments should be directed to B. S. Garbow,
! APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
! ------------------------------------------------------------------
!
!***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
! Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
! system Routines - EISPACK Guide, Springer-Verlag,
! 1976.
!***REVISION HISTORY (YYMMDD)
! 760101 DATE WRITTEN
! 890831 Modified array declarations. (WRB)
! 890831 REVISION DATE from Version 3.2
! 891214 Prologue converted to Version 4.0 format. (BAB)
! 920501 Reformatted the REFERENCES section. (WRB)
subroutine elmhes(Nm, n, Low, Igh, a, Intv)
implicit none
integer i, j, m, n, la, Nm, Igh, kp1, Low, mm1, mp1
real(wp) a(Nm, *)
real(wp) x, y
integer Intv(*)
la = Igh - 1
kp1 = Low + 1
if (la >= kp1) then
do m = kp1, la
mm1 = m - 1
x = 0.0_wp
i = m
do j = m, Igh
if (abs(a(j, mm1)) > abs(x)) then
x = a(j, mm1)
i = j
endif
enddo
Intv(m) = i
if (i /= m) then
! INTERCHANGE ROWS AND COLUMNS OF A
do j = mm1, n
y = a(i, j)
a(i, j) = a(m, j)
a(m, j) = y
enddo
do j = 1, Igh
y = a(j, i)
a(j, i) = a(j, m)
a(j, m) = y
enddo
endif
! END INTERCHANGE
if (x /= 0.0_wp) then
mp1 = m + 1
do i = mp1, Igh
y = a(i, mm1)
if (y /= 0.0_wp) then
y = y/x
a(i, mm1) = y
do j = m, n
a(i, j) = a(i, j) - y*a(m, j)
enddo
do j = 1, Igh
a(j, m) = a(j, m) + y*a(j, i)
enddo
endif
enddo
endif
enddo
endif
end subroutine elmhes
!*****************************************************************************************
!>
!***PURPOSE Accumulates the stabilized elementary similarity
! transformations used in the reduction of a real general
! matrix to upper Hessenberg form by ELMHES.
!***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
!***AUTHOR Smith, B. T., et al.
!***DESCRIPTION
!
! This subroutine is a translation of the ALGOL procedure ELMTRANS,
! NUM. MATH. 16, 181-204(1970) by Peters and Wilkinson.
! HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 372-395(1971).
!
! This subroutine accumulates the stabilized elementary
! similarity transformations used in the reduction of a
! REAL GENERAL matrix to upper Hessenberg form by ELMHES.
!
! On INPUT
!
! NM must be set to the row dimension of the two-dimensional
! array parameters, A and Z, as declared in the calling
! program dimension statement. NM is an INTEGER variable.
!
! N is the order of the matrix A. N is an INTEGER variable.
! N must be less than or equal to NM.
!
! LOW and IGH are two INTEGER variables determined by the
! balancing subroutine BALANC. If BALANC has not been
! used, set LOW=1 and IGH equal to the order of the matrix, N.
!
! A contains the multipliers which were used in the reduction
! by ELMHES in its lower triangle below the subdiagonal.
! A is a two-dimensional REAL array, dimensioned A(NM,IGH).
!
! INT contains information on the rows and columns interchanged
! in the reduction by ELMHES. Only elements LOW through IGH
! are used. INT is a one-dimensional INTEGER array,
! dimensioned INT(IGH).
!
! On OUTPUT
!
! Z contains the transformation matrix produced in the reduction
! by ELMHES. Z is a two-dimensional REAL array, dimensioned
! Z(NM,N).
!
! Questions and comments should be directed to B. S. Garbow,
! APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
! ------------------------------------------------------------------
!
!***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
! Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
! system Routines - EISPACK Guide, Springer-Verlag,
! 1976.
!***REVISION HISTORY (YYMMDD)
! 760101 DATE WRITTEN
! 890831 Modified array declarations. (WRB)
! 890831 REVISION DATE from Version 3.2
! 891214 Prologue converted to Version 4.0 format. (BAB)
! 920501 Reformatted the REFERENCES section. (WRB)
subroutine eltran(Nm, n, Low, Igh, a, Int, z)
implicit none
integer i, j, n, kl, mm, mp, Nm, Igh, Low, mp1
real(wp) a(Nm, *), z(Nm, *)
integer Int(*)
do i = 1, n
do j = 1, n
z(i, j) = 0.0_wp
enddo
z(i, i) = 1.0_wp
enddo
kl = Igh - Low - 1
if (kl >= 1) then
! for mp=igh-1 step -1 until low+1 do --
do mm = 1, kl
mp = Igh - mm
mp1 = mp + 1
do i = mp1, Igh
z(i, mp) = a(i, mp - 1)
enddo
i = Int(mp)
if (i /= mp) then
do j = mp, Igh
z(mp, j) = z(i, j)
z(i, j) = 0.0_wp
enddo
z(i, mp) = 1.0_wp
endif
enddo
endif
end subroutine eltran
!*****************************************************************************************
!>
!***PURPOSE Compute the eigenvalues of a real upper Hessenberg matrix
! using the QR method.
!***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
!***AUTHOR Smith, B. T., et al.
!***DESCRIPTION
!
! This subroutine is a translation of the ALGOL procedure HQR,
! NUM. MATH. 14, 219-231(1970) by Martin, Peters, and Wilkinson.
! HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 359-371(1971).
!
! This subroutine finds the eigenvalues of a REAL
! UPPER Hessenberg matrix by the QR method.
!
! On INPUT
!
! NM must be set to the row dimension of the two-dimensional
! array parameter, H, as declared in the calling program
! dimension statement. NM is an INTEGER variable.
!
! N is the order of the matrix H. N is an INTEGER variable.
! N must be less than or equal to NM.
!
! LOW and IGH are two INTEGER variables determined by the
! balancing subroutine BALANC. If BALANC has not been
! used, set LOW=1 and IGH equal to the order of the matrix, N.
!
! H contains the upper Hessenberg matrix. Information about
! the transformations used in the reduction to Hessenberg
! form by ELMHES or ORTHES, if performed, is stored
! in the remaining triangle under the Hessenberg matrix.
! H is a two-dimensional REAL array, dimensioned H(NM,N).
!
! On OUTPUT
!
! H has been destroyed. Therefore, it must be saved before
! calling HQR if subsequent calculation and back
! transformation of eigenvectors is to be performed.
!
! WR and WI contain the real and imaginary parts, respectively,
! of the eigenvalues. The eigenvalues are unordered except
! that complex conjugate pairs of values appear consecutively
! with the eigenvalue having the positive imaginary part first.
! If an error exit is made, the eigenvalues should be correct
! for indices IERR+1, IERR+2, ..., N. WR and WI are one-
! dimensional REAL arrays, dimensioned WR(N) and WI(N).
!
! IERR is an INTEGER flag set to
! Zero for normal return,
! J if the J-th eigenvalue has not been
! determined after a total of 30*N iterations.
! The eigenvalues should be correct for indices
! IERR+1, IERR+2, ..., N.
!
! Questions and comments should be directed to B. S. Garbow,
! APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
! ------------------------------------------------------------------
!
!***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
! Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
! system Routines - EISPACK Guide, Springer-Verlag,
! 1976.
!***REVISION HISTORY (YYMMDD)
! 760101 DATE WRITTEN
! 890531 Changed all specific intrinsics to generic. (WRB)
! 890831 Modified array declarations. (WRB)
! 890831 REVISION DATE from Version 3.2
! 891214 Prologue converted to Version 4.0 format. (BAB)
! 920501 Reformatted the REFERENCES section. (WRB)
subroutine hqr(Nm, n, Low, Igh, h, Wr, Wi, Ierr)
implicit none
integer i, j, k, l, m, n, en, ll, mm, na, Nm, Igh, &
itn, its, Low, mp2, enm2, Ierr, gt
real(wp) h(Nm, *), Wr(*), Wi(*)
real(wp) p, q, r, s, t, w, x, y, zz, norm, s1, s2
logical notlas
gt = 0
Ierr = 0
norm = 0.0_wp
k = 1
! STORE ROOTS ISOLATED BY BALANC
! AND COMPUTE MATRIX NORM
do i = 1, n
!
do j = k, n
norm = norm + abs(h(i, j))
enddo
!
k = i
if (i < Low .or. i > Igh) then
Wr(i) = h(i, i)
Wi(i) = 0.0_wp
endif
enddo
en = Igh
t = 0.0_wp
itn = 30*n
! SEARCH FOR NEXT EIGENVALUES
do while (en >= Low)
gt = 0
its = 0
na = en - 1
enm2 = na - 1
! LOOK FOR SINGLE SMALL SUB-DIAGONAL ELEMENT
! FOR L=EN STEP -1 UNTIL LOW DO --
do while (.true.)
do ll = Low, en
l = en + Low - ll
if (l == Low) exit
s = abs(h(l - 1, l - 1)) + abs(h(l, l))
if (s == 0.0_wp) s = norm
s2 = s + abs(h(l, l - 1))
if (s2 == s) exit
enddo
! FORM SHIFT
x = h(en, en)
if (l == en) then
! ONE ROOT FOUND
Wr(en) = x + t
Wi(en) = 0.0_wp
en = na
gt = 1
exit
else
y = h(na, na)
w = h(en, na)*h(na, en)
if (l == na) exit
if (itn == 0) then
! SET ERROR -- NO CONVERGENCE TO AN
! EIGENVALUE AFTER 30*N ITERATIONS
Ierr = en
return
else
if (its == 10 .or. its == 20) then
! FORM EXCEPTIONAL SHIFT
t = t + x
do i = Low, en
h(i, i) = h(i, i) - x
enddo
s = abs(h(en, na)) + abs(h(na, enm2))
x = 0.75_wp*s
y = x
w = -0.4375_wp*s*s
endif
its = its + 1
itn = itn - 1
!Β LOOK FOR TWO CONSECUTIVE SMALL
!Β SUB-DIAGONAL ELEMENTS.
!Β FOR M=EN-2 STEP -1 UNTIL L DO --
do mm = l, enm2
m = enm2 + l - mm
zz = h(m, m)
r = x - zz
s = y - zz
p = (r*s - w)/h(m + 1, m) + h(m, m + 1)
q = h(m + 1, m + 1) - zz - r - s
r = h(m + 2, m + 1)
s = abs(p) + abs(q) + abs(r)
p = p/s
q = q/s
r = r/s
if (m == l) exit
s1 = abs(p)*(abs(h(m - 1, m - 1)) + abs(zz) + abs(h(m + 1, m + 1)))
s2 = s1 + abs(h(m, m - 1))*(abs(q) + abs(r))
if (s2 == s1) exit
enddo
mp2 = m + 2
do i = mp2, en
h(i, i - 2) = 0.0_wp
if (i /= mp2) h(i, i - 3) = 0.0_wp
enddo
! DOUBLE QR STEP INVOLVING ROWS L TO EN AND
! COLUMNS M TO EN
do k = m, na
notlas = k /= na
if (k /= m) then
p = h(k, k - 1)
q = h(k + 1, k - 1)
r = 0.0_wp
if (notlas) r = h(k + 2, k - 1)
x = abs(p) + abs(q) + abs(r)
if (x == 0.0_wp) cycle
p = p/x
q = q/x
r = r/x
endif
s = sign(sqrt(p*p + q*q + r*r), p)
if (k == m) then
if (l /= m) h(k, k - 1) = -h(k, k - 1)
else
h(k, k - 1) = -s*x
endif
p = p + s
x = p/s
y = q/s
zz = r/s
q = q/p
r = r/p
! ROW MODIFICATION
do j = k, en
p = h(k, j) + q*h(k + 1, j)
if (notlas) then
p = p + r*h(k + 2, j)
h(k + 2, j) = h(k + 2, j) - p*zz
endif
h(k + 1, j) = h(k + 1, j) - p*y
h(k, j) = h(k, j) - p*x
enddo
j = min(en, k + 3)
! COLUMN MODIFICATION
do i = l, j
p = x*h(i, k) + y*h(i, k + 1)
if (notlas) then
p = p + zz*h(i, k + 2)
h(i, k + 2) = h(i, k + 2) - p*r
endif
h(i, k + 1) = h(i, k + 1) - p*q
h(i, k) = h(i, k) - p
enddo
enddo
endif
endif
enddo
! TWO ROOTS FOUND
if (gt == 0) then
p = (y - x)/2.0_wp
q = p*p + w
zz = sqrt(abs(q))
x = x + t
if (q < 0.0_wp) then
! COMPLEX PAIR
Wr(na) = x + p
Wr(en) = x + p
Wi(na) = zz
Wi(en) = -zz
else
! REAL PAIR
zz = p + sign(zz, p)
Wr(na) = x + zz
Wr(en) = Wr(na)
if (zz /= 0.0_wp) Wr(en) = x - w/zz
Wi(na) = 0.0_wp
Wi(en) = 0.0_wp
endif
en = enm2
end if
enddo
end subroutine hqr
!*****************************************************************************************
!>
!***PURPOSE Compute the eigenvalues and eigenvectors of a real upper
! Hessenberg matrix using QR method.
!***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
!***AUTHOR Smith, B. T., et al.
!***DESCRIPTION
!
! This subroutine is a translation of the ALGOL procedure HQR2,
! NUM. MATH. 16, 181-204(1970) by Peters and Wilkinson.
! HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 372-395(1971).
!
! This subroutine finds the eigenvalues and eigenvectors
! of a REAL UPPER Hessenberg matrix by the QR method. The
! eigenvectors of a REAL GENERAL matrix can also be found
! if ELMHES and ELTRAN or ORTHES and ORTRAN have
! been used to reduce this general matrix to Hessenberg form
! and to accumulate the similarity transformations.
!
! On INPUT
!
! NM must be set to the row dimension of the two-dimensional
! array parameters, H and Z, as declared in the calling
! program dimension statement. NM is an INTEGER variable.
!
! N is the order of the matrix H. N is an INTEGER variable.
! N must be less than or equal to NM.
!
! LOW and IGH are two INTEGER variables determined by the
! balancing subroutine BALANC. If BALANC has not been
! used, set LOW=1 and IGH equal to the order of the matrix, N.
!
! H contains the upper Hessenberg matrix. H is a two-dimensional
! REAL array, dimensioned H(NM,N).
!
! Z contains the transformation matrix produced by ELTRAN
! after the reduction by ELMHES, or by ORTRAN after the
! reduction by ORTHES, if performed. If the eigenvectors
! of the Hessenberg matrix are desired, Z must contain the
! identity matrix. Z is a two-dimensional REAL array,
! dimensioned Z(NM,M).
!
! On OUTPUT
!
! H has been destroyed.
!
! WR and WI contain the real and imaginary parts, respectively,
! of the eigenvalues. The eigenvalues are unordered except
! that complex conjugate pairs of values appear consecutively
! with the eigenvalue having the positive imaginary part first.
! If an error exit is made, the eigenvalues should be correct
! for indices IERR+1, IERR+2, ..., N. WR and WI are one-
! dimensional REAL arrays, dimensioned WR(N) and WI(N).
!
! Z contains the real and imaginary parts of the eigenvectors.
! If the J-th eigenvalue is real, the J-th column of Z
! contains its eigenvector. If the J-th eigenvalue is complex
! with positive imaginary part, the J-th and (J+1)-th
! columns of Z contain the real and imaginary parts of its
! eigenvector. The eigenvectors are unnormalized. If an
! error exit is made, none of the eigenvectors has been found.
!
! IERR is an INTEGER flag set to
! Zero for normal return,
! J if the J-th eigenvalue has not been
! determined after a total of 30*N iterations.
! The eigenvalues should be correct for indices
! IERR+1, IERR+2, ..., N, but no eigenvectors are
! computed.
!
! Calls CDIV for complex division.
!
! Questions and comments should be directed to B. S. Garbow,
! APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
! ------------------------------------------------------------------
!
!***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
! Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
! system Routines - EISPACK Guide, Springer-Verlag,
! 1976.
!***REVISION HISTORY (YYMMDD)
! 760101 DATE WRITTEN
! 890531 Changed all specific intrinsics to generic. (WRB)
! 890831 Modified array declarations. (WRB)
! 890831 REVISION DATE from Version 3.2
! 891214 Prologue converted to Version 4.0 format. (BAB)
! 920501 Reformatted the REFERENCES section. (WRB)
subroutine hqr2(Nm, n, Low, Igh, h, Wr, Wi, z, Ierr)
implicit none
integer i, j, k, l, m, n, en, ii, jj, ll, mm, na, Nm, &
nn, gt
integer Igh, itn, its, Low, mp2, enm2, Ierr
real(wp) h(Nm, *), Wr(*), Wi(*), z(Nm, *)
real(wp) p, q, r, s, t, w, x, y, ra, sa, vi, vr, zz, &
norm, s1, s2
logical notlas
gt = 0
Ierr = 0
norm = 0.0_wp
k = 1
! STORE ROOTS ISOLATED BY BALANC
! AND COMPUTE MATRIX NORM
do i = 1, n
do j = k, n
norm = norm + abs(h(i, j))
enddo
k = i
if (i < Low .or. i > Igh) then
Wr(i) = h(i, i)
Wi(i) = 0.0_wp
endif
enddo
en = Igh
t = 0.0_wp
itn = 30*n
! SEARCH FOR NEXT EIGENVALUES
do while (en >= Low)
gt = 0
its = 0
na = en - 1
enm2 = na - 1
! LOOK FOR SINGLE SMALL SUB-DIAGONAL ELEMENT
! FOR L=EN STEP -1 UNTIL LOW DO --
do while (.true.)
do ll = Low, en
l = en + Low - ll
if (l == Low) exit
s = abs(h(l - 1, l - 1)) + abs(h(l, l))
if (s == 0.0_wp) s = norm
s2 = s + abs(h(l, l - 1))
if (s2 == s) exit
enddo
! FORM SHIFT
x = h(en, en)
if (l == en) then
! ONE ROOT FOUND
h(en, en) = x + t
Wr(en) = h(en, en)
Wi(en) = 0.0_wp
en = na
gt = 1
exit
else
y = h(na, na)
w = h(en, na)*h(na, en)
if (l == na) exit
if (itn == 0) then
! SET ERROR -- NO CONVERGENCE TO AN
! EIGENVALUE AFTER 30*N ITERATIONS
Ierr = en
return
else
if (its == 10 .or. its == 20) then
! FORM EXCEPTIONAL SHIFT
t = t + x
do i = Low, en
h(i, i) = h(i, i) - x
enddo
s = abs(h(en, na)) + abs(h(na, enm2))
x = 0.75_wp*s
y = x
w = -0.4375_wp*s*s
endif
its = its + 1
itn = itn - 1
! LOOK FOR TWO CONSECUTIVE SMALL
! SUB-DIAGONAL ELEMENTS.
! FOR M=EN-2 STEP -1 UNTIL L DO --
do mm = l, enm2
m = enm2 + l - mm
zz = h(m, m)
r = x - zz
s = y - zz
p = (r*s - w)/h(m + 1, m) + h(m, m + 1)
q = h(m + 1, m + 1) - zz - r - s
r = h(m + 2, m + 1)
s = abs(p) + abs(q) + abs(r)
p = p/s
q = q/s
r = r/s
if (m == l) exit
s1 = abs(p)*(abs(h(m - 1, m - 1)) + abs(zz) + abs(h(m + 1, m + 1)))
s2 = s1 + abs(h(m, m - 1))*(abs(q) + abs(r))
if (s2 == s1) exit
enddo
mp2 = m + 2
do i = mp2, en
h(i, i - 2) = 0.0_wp
if (i /= mp2) h(i, i - 3) = 0.0_wp
enddo
! DOUBLE QR STEP INVOLVING ROWS L TO EN AND
! COLUMNS M TO EN
do k = m, na
notlas = k /= na
if (k /= m) then
p = h(k, k - 1)
q = h(k + 1, k - 1)
r = 0.0_wp
if (notlas) r = h(k + 2, k - 1)
x = abs(p) + abs(q) + abs(r)
if (x == 0.0_wp) cycle
p = p/x
q = q/x
r = r/x
endif
s = sign(sqrt(p*p + q*q + r*r), p)
if (k == m) then
if (l /= m) h(k, k - 1) = -h(k, k - 1)
else
h(k, k - 1) = -s*x
endif
p = p + s
x = p/s
y = q/s
zz = r/s
q = q/p
r = r/p
! ROW MODIFICATION
do j = k, n
p = h(k, j) + q*h(k + 1, j)
if (notlas) then
p = p + r*h(k + 2, j)
h(k + 2, j) = h(k + 2, j) - p*zz
endif
h(k + 1, j) = h(k + 1, j) - p*y
h(k, j) = h(k, j) - p*x
enddo
j = min(en, k + 3)
! COLUMN MODIFICATION
do i = 1, j
p = x*h(i, k) + y*h(i, k + 1)
if (notlas) then
p = p + zz*h(i, k + 2)
h(i, k + 2) = h(i, k + 2) - p*r
endif
h(i, k + 1) = h(i, k + 1) - p*q
h(i, k) = h(i, k) - p
enddo
! ACCUMULATE TRANSFORMATIONS
do i = Low, Igh
!
p = x*z(i, k) + y*z(i, k + 1)
if (notlas) then
p = p + zz*z(i, k + 2)
z(i, k + 2) = z(i, k + 2) - p*r
endif
z(i, k + 1) = z(i, k + 1) - p*q
z(i, k) = z(i, k) - p
!
enddo
enddo
endif
endif
enddo
if (gt == 1) cycle
! TWO ROOTS FOUND
p = (y - x)/2.0_wp
q = p*p + w
zz = sqrt(abs(q))
h(en, en) = x + t
x = h(en, en)
h(na, na) = y + t
if (q < 0.0_wp) then
! COMPLEX PAIR
Wr(na) = x + p
Wr(en) = x + p
Wi(na) = zz
Wi(en) = -zz
else
! REAL PAIR
zz = p + sign(zz, p)
Wr(na) = x + zz
Wr(en) = Wr(na)
if (zz /= 0.0_wp) Wr(en) = x - w/zz
Wi(na) = 0.0_wp
Wi(en) = 0.0_wp
x = h(en, na)
s = abs(x) + abs(zz)
p = x/s
q = zz/s
r = sqrt(p*p + q*q)
p = p/r
q = q/r
! ROW MODIFICATION
do j = na, n
zz = h(na, j)
h(na, j) = q*zz + p*h(en, j)
h(en, j) = q*h(en, j) - p*zz
enddo
! COLUMN MODIFICATION
do i = 1, en
zz = h(i, na)
h(i, na) = q*zz + p*h(i, en)
h(i, en) = q*h(i, en) - p*zz
enddo
! ACCUMULATE TRANSFORMATIONS
do i = Low, Igh
zz = z(i, na)
z(i, na) = q*zz + p*z(i, en)
z(i, en) = q*z(i, en) - p*zz
enddo
endif
en = enm2
enddo
! ALL ROOTS FOUND. BACKSUBSTITUTE TO FIND
! VECTORS OF UPPER TRIANGULAR FORM
if (norm /= 0.0_wp) then
! FOR EN=N STEP -1 UNTIL 1 DO --
do nn = 1, n
en = n + 1 - nn
p = Wr(en)
q = Wi(en)
na = en - 1
if (q < 0) then
! END COMPLEX VECTOR
! COMPLEX VECTOR
m = na
! LAST VECTOR COMPONENT CHOSEN IMAGINARY SO THAT
! EIGENVECTOR MATRIX IS TRIANGULAR
if (abs(h(en, na)) <= abs(h(na, en))) then
call cdiv(0.0_wp, -h(na, en), h(na, na) - p, q, h(na, na), h(na, en))
else
h(na, na) = q/h(en, na)
h(na, en) = -(h(en, en) - p)/h(en, na)
endif
h(en, na) = 0.0_wp
h(en, en) = 1.0_wp
enm2 = na - 1
if (enm2 /= 0) then
! FOR I=EN-2 STEP -1 UNTIL 1 DO --
do ii = 1, enm2
i = na - ii
w = h(i, i) - p
ra = 0.0_wp
sa = h(i, en)
!
do j = m, na
ra = ra + h(i, j)*h(j, na)
sa = sa + h(i, j)*h(j, en)
enddo
!
if (Wi(i) >= 0.0_wp) then
m = i
if (Wi(i) == 0.0_wp) then
call cdiv(-ra, -sa, w, q, h(i, na), h(i, en))
else
! SOLVE COMPLEX EQUATIONS
x = h(i, i + 1)
y = h(i + 1, i)
vr = (Wr(i) - p)*(Wr(i) - p) + Wi(i)*Wi(i) - q*q
vi = (Wr(i) - p)*2.0_wp*q
if (vr == 0.0_wp .and. vi == 0.0_wp) then
s1 = norm*(abs(w) + abs(q) + abs(x) + abs(y) + abs(zz))
vr = s1
do while (.true.)
vr = 0.5_wp*vr
if (s1 + vr <= s1) exit
enddo
vr = 2.0_wp*vr
endif
call cdiv(x*r - zz*ra + q*sa, x*s - zz*sa - q*ra, vr, vi, h(i, na), &
h(i, en))
if (abs(x) <= abs(zz) + abs(q)) then
call cdiv(-r - y*h(i, na), -s - y*h(i, en), zz, q, h(i + 1, na), &
h(i + 1, en))
else
h(i + 1, na) = (-ra - w*h(i, na) + q*h(i, en))/x
h(i + 1, en) = (-sa - w*h(i, en) - q*h(i, na))/x
endif
endif
else
zz = w
r = ra
s = sa
endif
enddo
endif
elseif (q == 0) then
! REAL VECTOR
m = en
h(en, en) = 1.0_wp
if (na /= 0) then
! FOR I=EN-1 STEP -1 UNTIL 1 DO --
do ii = 1, na
i = en - ii
w = h(i, i) - p
r = h(i, en)
if (m <= na) then
do j = m, na
r = r + h(i, j)*h(j, en)
enddo
endif
if (Wi(i) >= 0.0_wp) then
! END REAL VECTOR
m = i
if (Wi(i) == 0.0_wp) then
t = w
if (t == 0.0_wp) then
t = norm
do while (.true.)
t = 0.5_wp*t
if (norm + t <= norm) exit
enddo
t = 2.0_wp*t
endif
h(i, en) = -r/t
else
! SOLVE REAL EQUATIONS
x = h(i, i + 1)
y = h(i + 1, i)
q = (Wr(i) - p)*(Wr(i) - p) + Wi(i)*Wi(i)
t = (x*s - zz*r)/q
h(i, en) = t
if (abs(x) <= abs(zz)) then
h(i + 1, en) = (-s - y*t)/zz
else
h(i + 1, en) = (-r - w*t)/x
endif
endif
else
zz = w
s = r
endif
enddo
endif
endif
enddo
! END BACK SUBSTITUTION.
! VECTORS OF ISOLATED ROOTS
do i = 1, n
if (i < Low .or. i > Igh) then
do j = i, n
z(i, j) = h(i, j)
enddo
endif
enddo
! MULTIPLY BY TRANSFORMATION MATRIX TO GIVE
! VECTORS OF ORIGINAL FULL MATRIX.
! FOR J=N STEP -1 UNTIL LOW DO --
do jj = Low, n
j = n + Low - jj
m = min(j, Igh)
do i = Low, Igh
zz = 0.0_wp
do k = Low, m
zz = zz + z(i, k)*h(k, j)
enddo
z(i, j) = zz
enddo
enddo
endif
end subroutine hqr2
!*****************************************************************************************
!>
! Compute the eigenvalues and, optionally, the eigenvectors
! of a real general matrix.
!
! This subroutine calls the recommended sequence of
! subroutines from the eigensystem subroutine package (EISPACK)
! To find the eigenvalues and eigenvectors (if desired)
! of a REAL GENERAL matrix.
!
!### References
! * B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
! Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
! system Routines - EISPACK Guide, Springer-Verlag,
! 1976.
!
!### Author
! * Smith, B. T., et al.
!
!### History (YYMMDD)
! * 760101 DATE WRITTEN
! * 890831 Modified array declarations. (WRB)
! * 890831 REVISION DATE from Version 3.2
! * 891214 Prologue converted to Version 4.0 format. (BAB)
! * 920501 Reformatted the REFERENCES section. (WRB)
! * 921103 Corrected description of IV1. (DWL, FNF and WRB)
! * Jacob Williams, refactored into modern Fortran (3/25/2018)
subroutine rg(Nm, n, a, Wr, Wi, Matz, z, Iv1, Fv1, Ierr)
implicit none
integer,intent(in) :: n !! the order of the matrix A.
!! N must be less than or equal to NM.
integer,intent(in) :: Nm !! must be set to the row dimension of the two-dimensional
!! array parameters, A and Z, as declared in the calling
!! program dimension statement.
integer,intent(in) :: Matz !! an INTEGER variable set equal to zero if only
!! eigenvalues are desired. Otherwise, it is set to any
!! non-zero integer for both eigenvalues and eigenvectors.
real(wp),intent(inout) :: a(Nm, *) !! contains the real general matrix.
!! dimensioned A(NM,N).
!! Note: A is destroyed on output.
integer,intent(out) :: Ierr !! an INTEGER flag set to:
!!
!! * Zero -- for normal return,
!! * 10*N -- if N is greater than NM,
!! * J -- if the J-th eigenvalue has not been
!! determined after a total of 30 iterations.
!! The eigenvalues should be correct for indices
!! IERR+1, IERR+2, ..., N, but no eigenvectors are
!! computed.
real(wp),intent(out) :: Wr(*) !! real part of the eigenvalues. The eigenvalues are unordered except
!! that complex conjugate pairs of eigenvalues appear consecutively
!! with the eigenvalue having the positive imaginary part
!! first. If an error exit is made, the eigenvalues should be
!! correct for indices IERR+1, IERR+2, ..., N. WR and WI are
!! one-dimensional REAL arrays, dimensioned WR(N) and WI(N).
real(wp),intent(out) :: Wi(*) !! imaginary part of the eigenvalues.
real(wp),intent(out) :: z(Nm, *) !! contains the real and imaginary parts of the eigenvectors
!! if MATZ is not zero. If the J-th eigenvalue is real, the
!! J-th column of Z contains its eigenvector. If the J-th
!! eigenvalue is complex with positive imaginary part, the
!! J-th and (J+1)-th columns of Z contain the real and
!! imaginary parts of its eigenvector. The conjugate of this
!! vector is the eigenvector for the conjugate eigenvalue.
!! Z is a two-dimensional REAL array, dimensioned Z(NM,N).
real(wp),intent(inout) :: Fv1(*) !! one-dimensional temporary storage arrays of dimension N.
integer,intent(inout) :: Iv1(*) !! one-dimensional temporary storage arrays of dimension N.
integer :: is1
integer :: is2
if (n <= Nm) then
call balanc(Nm, n, a, is1, is2, Fv1)
call elmhes(Nm, n, is1, is2, a, Iv1)
if (Matz /= 0) then
! find both eigenvalues and eigenvectors
call eltran(Nm, n, is1, is2, a, Iv1, z)
call hqr2(Nm, n, is1, is2, a, Wr, Wi, z, Ierr)
if (Ierr == 0) call balbak(Nm, n, is1, is2, Fv1, n, z)
else
! find eigenvalues only
call hqr(Nm, n, is1, is2, a, Wr, Wi, Ierr)
endif
else
Ierr = 10*n
endif
end subroutine rg
!*****************************************************************************************
!*****************************************************************************************
!>
! Compute the eigenvalues and, optionally, the eigenvectors
! of a real general matrix.
!
!### See also
! * See [[rg]] for more details. This routine is just a wrapper to that one.
!
!### Author
! * Jacob Williams, 3/25/2018
subroutine compute_eigenvalues_and_eigenvectors(n, a, w, z, ierr)
use numbers_module
implicit none
integer,intent(in) :: n !! the order of the matrix `a`
real(wp),dimension(n,n),intent(in) :: a !! contains the real general matrix
real(wp),dimension(n,2),intent(out) :: w !! real and imaginary parts of the eigenvalues
real(wp),dimension(n,n),intent(out) :: z !! real and imaginary parts of the eigenvectors
integer,intent(out) :: ierr !! output flag from [[rg]]
integer,parameter :: matz = 1 !! tells [[rg]] to compute eigenvalues and eigenvectors
integer :: i !! counter
real(wp),dimension(n,n) :: a_tmp !! copy of [[a]] matrix
real(wp),dimension(n) :: fv1 !! work array for [[rg]]
integer,dimension(n) :: iv1 !! work array for [[rg]]
real(wp),dimension(n) :: wr !! real part of the eigenvalues
real(wp),dimension(n) :: wi !! imaginary part of the eigenvalues
! temp arrays:
a_tmp = a
wr = zero
wi = zero
! call the general routine:
call rg(n, n, a_tmp, wr, wi, matz, z, iv1, fv1, ierr)
! pack outputs:
do i=1,n
w(i,1) = wr(i)
w(i,2) = wi(i)
end do
end subroutine compute_eigenvalues_and_eigenvectors
!*****************************************************************************************
!*****************************************************************************************
end module eispack_module
!*****************************************************************************************
|
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degbm : β {a b : A}, degb (a + b) β€ degb a + degb b
f g : AddMonoidAlgebra R A
β’ Finset.sup (f * g).support degb β€ Finset.sup f.support degb + Finset.sup g.support degb
[PROOFSTEP]
refine' (Finset.sup_mono <| support_mul _ _).trans _
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degbm : β {a b : A}, degb (a + b) β€ degb a + degb b
f g : AddMonoidAlgebra R A
β’ Finset.sup (Finset.biUnion f.support fun aβ => Finset.biUnion g.support fun aβ => {aβ + aβ}) degb β€
Finset.sup f.support degb + Finset.sup g.support degb
[PROOFSTEP]
simp_rw [Finset.sup_biUnion, Finset.sup_singleton]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degbm : β {a b : A}, degb (a + b) β€ degb a + degb b
f g : AddMonoidAlgebra R A
β’ (Finset.sup f.support fun x => Finset.sup g.support fun x_1 => degb (x + x_1)) β€
Finset.sup f.support degb + Finset.sup g.support degb
[PROOFSTEP]
refine' Finset.sup_le fun fd fds => Finset.sup_le fun gd gds => degbm.trans <| add_le_add _ _
[GOAL]
case refine'_1
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degbm : β {a b : A}, degb (a + b) β€ degb a + degb b
f g : AddMonoidAlgebra R A
fd : A
fds : fd β f.support
gd : A
gds : gd β g.support
β’ degb fd β€ Finset.sup f.support degb
[PROOFSTEP]
exact Finset.le_sup βΉ_βΊ
[GOAL]
case refine'_2
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degbm : β {a b : A}, degb (a + b) β€ degb a + degb b
f g : AddMonoidAlgebra R A
fd : A
fds : fd β f.support
gd : A
gds : gd β g.support
β’ degb gd β€ Finset.sup g.support degb
[PROOFSTEP]
exact Finset.le_sup βΉ_βΊ
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degt : A β T
degtm : β {a b : A}, degt a + degt b β€ degt (a + b)
f g : AddMonoidAlgebra R A
β’ Finset.inf f.support degt + Finset.inf g.support degt β€ Finset.inf (f * g).support degt
[PROOFSTEP]
refine' OrderDual.ofDual_le_ofDual.mpr <| sup_support_mul_le (_) f g
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degt : A β T
degtm : β {a b : A}, degt a + degt b β€ degt (a + b)
f g : AddMonoidAlgebra R A
β’ β {a b : A}, degt (a + b) β€ degt a + degt b
[PROOFSTEP]
intros a b
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : Add A
instββ΅ : Add B
instββ΄ : Add T
instβΒ³ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degt : A β T
degtm : β {a b : A}, degt a + degt b β€ degt (a + b)
f g : AddMonoidAlgebra R A
a b : A
β’ degt (a + b) β€ degt a + degt b
[PROOFSTEP]
exact OrderDual.ofDual_le_ofDual.mp degtm
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
β’ Finset.sup (List.prod []).support degb β€ List.sum (List.map (fun f => Finset.sup f.support degb) [])
[PROOFSTEP]
rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
β’ β (b : A), b β 1.support β degb b β€ 0
[PROOFSTEP]
exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
a : A
ha : a β 1.support
β’ degb a β€ 0
[PROOFSTEP]
rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
f : AddMonoidAlgebra R A
fs : List (AddMonoidAlgebra R A)
β’ Finset.sup (List.prod (f :: fs)).support degb β€ List.sum (List.map (fun f => Finset.sup f.support degb) (f :: fs))
[PROOFSTEP]
rw [List.prod_cons, List.map_cons, List.sum_cons]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
f : AddMonoidAlgebra R A
fs : List (AddMonoidAlgebra R A)
β’ Finset.sup (f * List.prod fs).support degb β€
Finset.sup f.support degb + List.sum (List.map (fun f => Finset.sup f.support degb) fs)
[PROOFSTEP]
exact
(sup_support_mul_le (@fun a b => degbm a b) _ _).trans (add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _)
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
l : List (AddMonoidAlgebra R A)
β’ List.sum (List.map (fun f => Finset.inf f.support degt) l) β€ Finset.inf (List.prod l).support degt
[PROOFSTEP]
refine' OrderDual.ofDual_le_ofDual.mpr _
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
l : List (AddMonoidAlgebra R A)
β’ Quot.lift (fun l => List.foldr (fun x x_1 => x β x_1) β€ l)
(_ :
β (_lβ _lβ : List T),
Setoid.r _lβ _lβ β List.foldr (fun x x_1 => x β x_1) β€ _lβ = List.foldr (fun x x_1 => x β x_1) β€ _lβ)
(Multiset.map degt (List.prod l).support.val) β€
List.foldl (fun x x_1 => x + x_1) 0 (List.map (fun f => Finset.inf f.support degt) l)
[PROOFSTEP]
refine' sup_support_list_prod_le _ _ l
[GOAL]
case refine'_1
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
l : List (AddMonoidAlgebra R A)
β’ degt 0 β€ 0
[PROOFSTEP]
refine' (OrderDual.ofDual_le_ofDual.mp _)
[GOAL]
case refine'_1
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
l : List (AddMonoidAlgebra R A)
β’ βOrderDual.ofDual 0 β€ βOrderDual.ofDual (degt 0)
[PROOFSTEP]
exact degt0
[GOAL]
case refine'_2
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
l : List (AddMonoidAlgebra R A)
β’ β (a b : A), degt (a + b) β€ degt a + degt b
[PROOFSTEP]
refine' (fun a b => OrderDual.ofDual_le_ofDual.mp _)
[GOAL]
case refine'_2
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
l : List (AddMonoidAlgebra R A)
a b : A
β’ βOrderDual.ofDual (degt a + degt b) β€ βOrderDual.ofDual (degt (a + b))
[PROOFSTEP]
exact degtm a b
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
n : β
f : AddMonoidAlgebra R A
β’ Finset.sup (f ^ n).support degb β€ n β’ Finset.sup f.support degb
[PROOFSTEP]
rw [β List.prod_replicate, β List.sum_replicate]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
n : β
f : AddMonoidAlgebra R A
β’ Finset.sup (List.prod (List.replicate n f)).support degb β€ List.sum (List.replicate n (Finset.sup f.support degb))
[PROOFSTEP]
refine' (sup_support_list_prod_le degb0 degbm _).trans_eq _
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
n : β
f : AddMonoidAlgebra R A
β’ List.sum (List.map (fun f => Finset.sup f.support degb) (List.replicate n f)) =
List.sum (List.replicate n (Finset.sup f.support degb))
[PROOFSTEP]
rw [List.map_replicate]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
n : β
f : AddMonoidAlgebra R A
β’ n β’ Finset.inf f.support degt β€ Finset.inf (f ^ n).support degt
[PROOFSTEP]
refine'
OrderDual.ofDual_le_ofDual.mpr <|
sup_support_pow_le (OrderDual.ofDual_le_ofDual.mp _) (fun a b => OrderDual.ofDual_le_ofDual.mp _) n f
[GOAL]
case refine'_1
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
n : β
f : AddMonoidAlgebra R A
β’ βOrderDual.ofDual (degt 0) β€ βOrderDual.ofDual 0
case refine'_2
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
n : β
f : AddMonoidAlgebra R A
a b : A
β’ βOrderDual.ofDual (degt (a + b)) β€ βOrderDual.ofDual (degt a + degt b)
[PROOFSTEP]
exact degt0
[GOAL]
case refine'_2
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : Semiring R
instββΆ : AddMonoid A
instββ΅ : AddMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
n : β
f : AddMonoidAlgebra R A
a b : A
β’ βOrderDual.ofDual (degt (a + b)) β€ βOrderDual.ofDual (degt a + degt b)
[PROOFSTEP]
exact degtm _ _
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
m : Multiset (AddMonoidAlgebra R A)
β’ Finset.sup (Multiset.prod m).support degb β€ Multiset.sum (Multiset.map (fun f => Finset.sup f.support degb) m)
[PROOFSTEP]
induction m using Quot.inductionOn
[GOAL]
case h
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
aβ : List (AddMonoidAlgebra R A)
β’ Finset.sup (Multiset.prod (Quot.mk Setoid.r aβ)).support degb β€
Multiset.sum (Multiset.map (fun f => Finset.sup f.support degb) (Quot.mk Setoid.r aβ))
[PROOFSTEP]
rw [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_sum, Multiset.coe_prod]
[GOAL]
case h
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degb0 : degb 0 β€ 0
degbm : β (a b : A), degb (a + b) β€ degb a + degb b
aβ : List (AddMonoidAlgebra R A)
β’ Finset.sup (List.prod aβ).support degb β€ List.sum (List.map (fun f => Finset.sup f.support degb) aβ)
[PROOFSTEP]
exact sup_support_list_prod_le degb0 degbm _
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
m : Multiset (AddMonoidAlgebra R A)
β’ Multiset.sum (Multiset.map (fun f => Finset.inf f.support degt) m) β€ Finset.inf (Multiset.prod m).support degt
[PROOFSTEP]
refine'
OrderDual.ofDual_le_ofDual.mpr <|
sup_support_multiset_prod_le (OrderDual.ofDual_le_ofDual.mp _) (fun a b => OrderDual.ofDual_le_ofDual.mp (_)) m
[GOAL]
case refine'_1
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
m : Multiset (AddMonoidAlgebra R A)
β’ βOrderDual.ofDual (degt 0) β€ βOrderDual.ofDual 0
case refine'_2
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
m : Multiset (AddMonoidAlgebra R A)
a b : A
β’ βOrderDual.ofDual (degt (a + b)) β€ βOrderDual.ofDual (degt a + degt b)
[PROOFSTEP]
exact degt0
[GOAL]
case refine'_2
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
m : Multiset (AddMonoidAlgebra R A)
a b : A
β’ βOrderDual.ofDual (degt (a + b)) β€ βOrderDual.ofDual (degt a + degt b)
[PROOFSTEP]
exact degtm _ _
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
s : Finset ΞΉ
f : ΞΉ β AddMonoidAlgebra R A
β’ β i in s, Finset.inf (f i).support degt =
Multiset.sum (Multiset.map (fun f => Finset.inf f.support degt) (Multiset.map (fun i => f i) s.val))
[PROOFSTEP]
rw [Multiset.map_map]
[GOAL]
R : Type u_1
A : Type u_2
T : Type u_3
B : Type u_4
ΞΉ : Type u_5
instβΒΉΒΉ : SemilatticeSup B
instβΒΉβ° : OrderBot B
instββΉ : SemilatticeInf T
instββΈ : OrderTop T
instββ· : CommSemiring R
instββΆ : AddCommMonoid A
instββ΅ : AddCommMonoid B
instββ΄ : CovariantClass B B (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ³ : CovariantClass B B (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβΒ² : AddCommMonoid T
instβΒΉ : CovariantClass T T (fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
instβ : CovariantClass T T (Function.swap fun x x_1 => x + x_1) fun x x_1 => x β€ x_1
degb : A β B
degt : A β T
degt0 : 0 β€ degt 0
degtm : β (a b : A), degt a + degt b β€ degt (a + b)
s : Finset ΞΉ
f : ΞΉ β AddMonoidAlgebra R A
β’ β i in s, Finset.inf (f i).support degt =
Multiset.sum (Multiset.map ((fun f => Finset.inf f.support degt) β fun i => f i) s.val)
[PROOFSTEP]
rfl
|
If a sequence is Cauchy, then its range is bounded. |
State Before: b c : Prop
Ξ± : Sort u_1
xβ : Decidable b
instβ : Decidable c
x : b β Ξ±
u : c β Ξ±
y : Β¬b β Ξ±
v : Β¬c β Ξ±
hβ : b = c
hβ : β (h : c), x (_ : b) = u h
hβ : β (h : Β¬c), y (_ : Β¬b) = v h
β’ dite b x y = dite c u v State After: no goals Tactic: cases Decidable.em c with
| inl h => rw [dif_pos h]; subst b; rw [dif_pos h]; exact hβ h
| inr h => rw [dif_neg h]; subst b; rw [dif_neg h]; exact hβ h State Before: case inl
b c : Prop
Ξ± : Sort u_1
xβ : Decidable b
instβ : Decidable c
x : b β Ξ±
u : c β Ξ±
y : Β¬b β Ξ±
v : Β¬c β Ξ±
hβ : b = c
hβ : β (h : c), x (_ : b) = u h
hβ : β (h : Β¬c), y (_ : Β¬b) = v h
h : c
β’ dite b x y = dite c u v State After: case inl
b c : Prop
Ξ± : Sort u_1
xβ : Decidable b
instβ : Decidable c
x : b β Ξ±
u : c β Ξ±
y : Β¬b β Ξ±
v : Β¬c β Ξ±
hβ : b = c
hβ : β (h : c), x (_ : b) = u h
hβ : β (h : Β¬c), y (_ : Β¬b) = v h
h : c
β’ dite b x y = u h Tactic: rw [dif_pos h] State Before: case inl
b c : Prop
Ξ± : Sort u_1
xβ : Decidable b
instβ : Decidable c
x : b β Ξ±
u : c β Ξ±
y : Β¬b β Ξ±
v : Β¬c β Ξ±
hβ : b = c
hβ : β (h : c), x (_ : b) = u h
hβ : β (h : Β¬c), y (_ : Β¬b) = v h
h : c
β’ dite b x y = u h State After: case inl
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ dite c x y = u h Tactic: subst b State Before: case inl
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ dite c x y = u h State After: case inl
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ x h = u h Tactic: rw [dif_pos h] State Before: case inl
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ x h = u h State After: no goals Tactic: exact hβ h State Before: case inr
b c : Prop
Ξ± : Sort u_1
xβ : Decidable b
instβ : Decidable c
x : b β Ξ±
u : c β Ξ±
y : Β¬b β Ξ±
v : Β¬c β Ξ±
hβ : b = c
hβ : β (h : c), x (_ : b) = u h
hβ : β (h : Β¬c), y (_ : Β¬b) = v h
h : Β¬c
β’ dite b x y = dite c u v State After: case inr
b c : Prop
Ξ± : Sort u_1
xβ : Decidable b
instβ : Decidable c
x : b β Ξ±
u : c β Ξ±
y : Β¬b β Ξ±
v : Β¬c β Ξ±
hβ : b = c
hβ : β (h : c), x (_ : b) = u h
hβ : β (h : Β¬c), y (_ : Β¬b) = v h
h : Β¬c
β’ dite b x y = v h Tactic: rw [dif_neg h] State Before: case inr
b c : Prop
Ξ± : Sort u_1
xβ : Decidable b
instβ : Decidable c
x : b β Ξ±
u : c β Ξ±
y : Β¬b β Ξ±
v : Β¬c β Ξ±
hβ : b = c
hβ : β (h : c), x (_ : b) = u h
hβ : β (h : Β¬c), y (_ : Β¬b) = v h
h : Β¬c
β’ dite b x y = v h State After: case inr
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : Β¬c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ dite c x y = v h Tactic: subst b State Before: case inr
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : Β¬c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ dite c x y = v h State After: case inr
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : Β¬c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ y h = v h Tactic: rw [dif_neg h] State Before: case inr
c : Prop
Ξ± : Sort u_1
instβ : Decidable c
u : c β Ξ±
v : Β¬c β Ξ±
h : Β¬c
xβ : Decidable c
x : c β Ξ±
y : Β¬c β Ξ±
hβ : β (h : c), x (_ : c) = u h
hβ : β (h : Β¬c), y (_ : Β¬c) = v h
β’ y h = v h State After: no goals Tactic: exact hβ h |
[STATEMENT]
lemma cancel_scalar: "\<lbrakk> a \<noteq> 0; u \<in> V; v \<in> V; a \<cdot> u = a \<cdot> v \<rbrakk> \<Longrightarrow> u = v"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>a \<noteq> (0::'f); u \<in> V; v \<in> V; a \<cdot> u = a \<cdot> v\<rbrakk> \<Longrightarrow> u = v
[PROOF STEP]
using smult_assoc[of "1/a" a u]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>(1::'f) / a \<in> UNIV; a \<in> UNIV; u \<in> V\<rbrakk> \<Longrightarrow> ((1::'f) / a) \<cdot> a \<cdot> u = ((1::'f) / a * a) \<cdot> u
goal (1 subgoal):
1. \<lbrakk>a \<noteq> (0::'f); u \<in> V; v \<in> V; a \<cdot> u = a \<cdot> v\<rbrakk> \<Longrightarrow> u = v
[PROOF STEP]
by simp |
If $f$ is Lebesgue integrable on $E$, then so is $-f$. |
[STATEMENT]
lemma eeqExcPID2_RDD:
"eeqExcPID2 paps paps1 \<Longrightarrow>
titlePaper (paps PID) = titlePaper (paps1 PID) \<and>
abstractPaper (paps PID) = abstractPaper (paps1 PID) \<and>
contentPaper (paps PID) = contentPaper (paps1 PID) \<and>
reviewsPaper (paps PID) = reviewsPaper (paps1 PID) \<and>
disPaper (paps PID) = disPaper (paps1 PID) \<and>
hd (decsPaper (paps PID)) = hd (decsPaper (paps PID))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. eeqExcPID2 paps paps1 \<Longrightarrow> titlePaper (paps PID) = titlePaper (paps1 PID) \<and> abstractPaper (paps PID) = abstractPaper (paps1 PID) \<and> contentPaper (paps PID) = contentPaper (paps1 PID) \<and> reviewsPaper (paps PID) = reviewsPaper (paps1 PID) \<and> disPaper (paps PID) = disPaper (paps1 PID) \<and> hd (decsPaper (paps PID)) = hd (decsPaper (paps PID))
[PROOF STEP]
using eeqExcPID2_def
[PROOF STATE]
proof (prove)
using this:
eeqExcPID2 ?paps ?paps1.0 \<equiv> \<forall>pid. if pid = PID then eqExcD2 (?paps pid) (?paps1.0 pid) else ?paps pid = ?paps1.0 pid
goal (1 subgoal):
1. eeqExcPID2 paps paps1 \<Longrightarrow> titlePaper (paps PID) = titlePaper (paps1 PID) \<and> abstractPaper (paps PID) = abstractPaper (paps1 PID) \<and> contentPaper (paps PID) = contentPaper (paps1 PID) \<and> reviewsPaper (paps PID) = reviewsPaper (paps1 PID) \<and> disPaper (paps PID) = disPaper (paps1 PID) \<and> hd (decsPaper (paps PID)) = hd (decsPaper (paps PID))
[PROOF STEP]
unfolding eqExcD2
[PROOF STATE]
proof (prove)
using this:
eeqExcPID2 ?paps ?paps1.0 \<equiv> \<forall>pid. if pid = PID then titlePaper (?paps pid) = titlePaper (?paps1.0 pid) \<and> abstractPaper (?paps pid) = abstractPaper (?paps1.0 pid) \<and> contentPaper (?paps pid) = contentPaper (?paps1.0 pid) \<and> reviewsPaper (?paps pid) = reviewsPaper (?paps1.0 pid) \<and> disPaper (?paps pid) = disPaper (?paps1.0 pid) \<and> hd (decsPaper (?paps pid)) = hd (decsPaper (?paps1.0 pid)) else ?paps pid = ?paps1.0 pid
goal (1 subgoal):
1. eeqExcPID2 paps paps1 \<Longrightarrow> titlePaper (paps PID) = titlePaper (paps1 PID) \<and> abstractPaper (paps PID) = abstractPaper (paps1 PID) \<and> contentPaper (paps PID) = contentPaper (paps1 PID) \<and> reviewsPaper (paps PID) = reviewsPaper (paps1 PID) \<and> disPaper (paps PID) = disPaper (paps1 PID) \<and> hd (decsPaper (paps PID)) = hd (decsPaper (paps PID))
[PROOF STEP]
by auto |
[STATEMENT]
lemma ordLeq3_finite_infinite:
assumes A: "finite A" and B: "infinite B" shows "ordLeq3 (card_of A) (card_of B)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ordLeq3 (card_of A) (card_of B)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. ordLeq3 (card_of A) (card_of B)
[PROOF STEP]
have \<open>ordLeq3 (card_of A) (card_of B) \<or> ordLeq3 (card_of B) (card_of A)\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ordLeq3 (card_of A) (card_of B) \<or> ordLeq3 (card_of B) (card_of A)
[PROOF STEP]
by (intro ordLeq_total card_of_Well_order)
[PROOF STATE]
proof (state)
this:
ordLeq3 (card_of A) (card_of B) \<or> ordLeq3 (card_of B) (card_of A)
goal (1 subgoal):
1. ordLeq3 (card_of A) (card_of B)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
ordLeq3 (card_of A) (card_of B) \<or> ordLeq3 (card_of B) (card_of A)
goal (1 subgoal):
1. ordLeq3 (card_of A) (card_of B)
[PROOF STEP]
have "\<not> ordLeq3 (card_of B) (card_of A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (card_of B, card_of A) \<notin> ordLeq
[PROOF STEP]
using B A card_of_ordLeq_finite[of B A]
[PROOF STATE]
proof (prove)
using this:
infinite B
finite A
\<lbrakk>ordLeq3 (card_of B) (card_of A); finite A\<rbrakk> \<Longrightarrow> finite B
goal (1 subgoal):
1. (card_of B, card_of A) \<notin> ordLeq
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(card_of B, card_of A) \<notin> ordLeq
goal (1 subgoal):
1. ordLeq3 (card_of A) (card_of B)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
ordLeq3 (card_of A) (card_of B) \<or> ordLeq3 (card_of B) (card_of A)
(card_of B, card_of A) \<notin> ordLeq
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
ordLeq3 (card_of A) (card_of B) \<or> ordLeq3 (card_of B) (card_of A)
(card_of B, card_of A) \<notin> ordLeq
goal (1 subgoal):
1. ordLeq3 (card_of A) (card_of B)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ordLeq3 (card_of A) (card_of B)
goal:
No subgoals!
[PROOF STEP]
qed |
/-
Copyright (c) 2022 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import for_mathlib.algebraic_topology.homotopical_algebra.homotopies
import for_mathlib.algebraic_topology.homotopical_algebra.fibrant
import category_theory.full_subcategory
import for_mathlib.category_theory.quotient_misc
import for_mathlib.category_theory.localization.predicate
noncomputable theory
open algebraic_topology
open category_theory
open category_theory.limits
open category_theory.category
namespace algebraic_topology
namespace model_category
variables (C : Type*) [category C] [model_category C]
@[nolint has_nonempty_instance]
structure cofibrant_object :=
(obj : C)
[cof : is_cofibrant obj]
namespace cofibrant_object
instance (X : cofibrant_object C) : is_cofibrant X.obj := X.cof
instance : category (cofibrant_object C) := induced_category.category (Ξ» X, X.obj)
@[simps, derive full, derive faithful]
def forget : cofibrant_object C β₯€ C := induced_functor _
variable {C}
@[simp]
def weq : morphism_property (cofibrant_object C) := Ξ» X Y f, model_category.weq ((forget C).map f)
def right_homotopy : hom_rel (cofibrant_object C) := Ξ» A X fβ fβ,
β (P : path_object X.obj), nonempty (right_homotopy P.pre fβ fβ)
namespace right_homotopy
lemma mk {A X : cofibrant_object C} {fβ fβ : A βΆ X} (P : path_object X.obj)
(H : model_category.right_homotopy P.pre fβ fβ) : right_homotopy fβ fβ :=
β¨P, nonempty.intro Hβ©
lemma symm {A X : cofibrant_object C} {fβ fβ : A βΆ X} (H : right_homotopy fβ fβ) :
right_homotopy fβ fβ :=
right_homotopy.mk H.some.symm H.some_spec.some.symm
lemma comp_left {A B X : cofibrant_object C} {gβ gβ : B βΆ X} (H : right_homotopy gβ gβ)
(f : A βΆ B) : right_homotopy (f β« gβ) (f β« gβ) :=
right_homotopy.mk H.some (H.some_spec.some.comp_left f)
lemma comp_right {A X Y : cofibrant_object C} {fβ fβ : A βΆ X} (H : right_homotopy fβ fβ)
(g : X βΆ Y) : right_homotopy (fβ β« g) (fβ β« g) :=
begin
cases H with P hP,
rcases hP.some.with_cof_Ο_of_right_homotopy with β¨P', H', hP'β©,
haveI : cofibration P'.Ο := hP',
let Q := path_object.some Y.1,
suffices H'' : model_category.right_homotopy Q.pre (P'.dβ β« g) (P'.dβ β« g),
{ exact mk Q { h := H'.h β« H''.h, }, },
apply right_homotopy.extension P'.Ο,
simp only [pre_path_object.dβΟ_assoc, pre_path_object.dβΟ_assoc],
apply right_homotopy.refl,
end
inductive trans_closure β¦A X : cofibrant_object Cβ¦ : (A βΆ X) β (A βΆ X) β Prop
| mk {fβ fβ : A βΆ X} (H : right_homotopy fβ fβ) : trans_closure fβ fβ
| trans {fβ fβ fβ : A βΆ X} (Hββ : trans_closure fβ fβ) (Hββ : trans_closure fβ fβ) :
trans_closure fβ fβ
namespace trans_closure
lemma is_equiv (A X : cofibrant_object C) :
is_equiv (A βΆ X) (Ξ» fβ fβ, trans_closure fβ fβ) :=
{ refl := Ξ» f, trans_closure.mk (right_homotopy.mk
(path_object.some X.1) (right_homotopy.refl _ f)),
trans := Ξ» fβ fβ fβ Hββ Hββ, trans_closure.trans Hββ Hββ,
symm := Ξ» fβ fβ H, begin
induction H with fβ fβ Hββ fβ fβ fβ Hββ Hββ Hββ Hββ,
{ exact trans_closure.mk Hββ.symm, },
{ exact trans_closure.trans Hββ Hββ, },
end, }
lemma comp_left {A B X : cofibrant_object C} {gβ gβ : B βΆ X} (H : trans_closure gβ gβ)
(f : A βΆ B) : trans_closure (f β« gβ) (f β« gβ) :=
begin
induction H with fβ fβ Hββ fβ fβ fβ Hββ Hββ Hββ' Hββ',
{ exact mk (Hββ.comp_left f), },
{ exact trans Hββ' Hββ', }
end
lemma comp_right {A X Y : cofibrant_object C} {fβ fβ : A βΆ X} (H : trans_closure fβ fβ)
(g : X βΆ Y) : trans_closure (fβ β« g) (fβ β« g) :=
begin
induction H with fβ fβ Hββ fβ fβ fβ Hββ Hββ Hββ' Hββ',
{ exact mk (Hββ.comp_right g), },
{ exact trans Hββ' Hββ', },
end
end trans_closure
end right_homotopy
variable (C)
@[simp]
def homotopy_relation : hom_rel (cofibrant_object C) := right_homotopy.trans_closure
instance : congruence (homotopy_relation C) :=
{ is_equiv := right_homotopy.trans_closure.is_equiv,
comp_left := Ξ» A B X f gβ gβ H, H.comp_left f,
comp_right := Ξ» A X Y fβ fβ g H, H.comp_right g, }
@[nolint has_nonempty_instance]
def homotopy_category := quotient (right_homotopy.trans_closure : hom_rel (cofibrant_object C))
instance : congruence (right_homotopy.trans_closure : hom_rel (cofibrant_object C)) :=
{ is_equiv := right_homotopy.trans_closure.is_equiv,
comp_left := Ξ» A B X f gβ gβ H, H.comp_left f,
comp_right := Ξ» A X Y fβ fβ g H, H.comp_right g, }
instance : category (homotopy_category C) := quotient.category _
variable {C}
def homotopy_category.Q : cofibrant_object C β₯€ homotopy_category C := quotient.functor _
namespace homotopy_category
@[simp]
lemma Q_map {X Y : cofibrant_object C} (f : X βΆ Y) :
Q.map f = (quotient.functor _).map f := rfl
lemma Q_map_surjective (X Y : cofibrant_object C) :
function.surjective (@category_theory.functor.map _ _ _ _ Q X Y) :=
by apply quotient.functor_map_surjective
lemma Q_map_eq_iff {X Y : cofibrant_object C} [hY : is_fibrant Y.obj]
(Cyl : cylinder X.obj) (fβ fβ : X βΆ Y) :
(Q.map fβ = Q.map fβ) β nonempty (left_homotopy Cyl.pre fβ fβ) :=
begin
split,
{ intro h,
simp only [Q_map, quotient.functor_map_eq_iff] at h,
induction h with fβ fβ H fβ fβ fβ Hββ Hββ H H',
{ exact nonempty.intro (H.some_spec.some.to_left_homotopy Cyl), },
{ exact nonempty.intro ((H.some.trans H'.some).change_cylinder Cyl), }, },
{ intro h,
apply category_theory.quotient.sound,
refine right_homotopy.trans_closure.mk
(right_homotopy.mk (path_object.some Y.obj) (h.some.to_right_homotopy _)), },
end
lemma Q_map_eq_iff' {X Y : cofibrant_object C} [is_fibrant Y.obj]
(P : path_object Y.obj) (fβ fβ : X βΆ Y) :
(Q.map fβ = Q.map fβ) β nonempty (model_category.right_homotopy P.pre fβ fβ) :=
begin
rw Q_map_eq_iff (cylinder.some X.obj) fβ fβ,
split,
{ exact Ξ» h, nonempty.intro (h.some.to_right_homotopy _), },
{ exact Ξ» h, nonempty.intro (h.some.to_left_homotopy _), },
end
def weq : morphism_property (cofibrant_object.homotopy_category C) :=
Ξ» X Y f, β (g : X.as.obj βΆ Y.as.obj) (hg : model_category.weq g), f = Q.map g
lemma weq_Q_map_iff {X Y : cofibrant_object C} (f : X βΆ Y) :
weq (Q.map f) β cofibrant_object.weq f :=
begin
refine β¨Ξ» hf, _, Ξ» hf, β¨f, hf, rflβ©β©,
rcases hf with β¨g : X βΆ Y, hg, Hβ©,
dsimp only [Q] at H,
rw quotient.functor_map_eq_iff at H,
induction H with fβ fβ H fβ fβ fβ Hββ Hββ hβ hβ,
{ rcases H with β¨P, Hβ©,
let f'β : X.obj βΆ Y.obj := fβ,
let f'β : X.obj βΆ Y.obj := fβ,
change model_category.weq f'β,
change model_category.weq f'β at hg,
let h : model_category.right_homotopy P.pre f'β f'β := H.some,
rw β h.hβ,
rw β h.hβ at hg,
exact CM2.of_comp _ _ (CM2.of_comp_right _ _ weak_eq.property hg) weak_eq.property, },
{ exact hβ (hβ hg), },
end
end homotopy_category
end cofibrant_object
variable (C)
@[derive category]
def Hocof' := (cofibrant_object.weq : morphism_property (cofibrant_object C)).localization
variable {C}
def Lcof' : cofibrant_object C β₯€ Hocof' C :=
(cofibrant_object.weq : morphism_property (cofibrant_object C)).Q
instance Lcof'_is_localization :
(Lcof' : cofibrant_object C β₯€ Hocof' C).is_localization cofibrant_object.weq :=
by { dsimp [Lcof'], apply_instance, }
end model_category
end algebraic_topology
|
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Q.MonteCarlo where
import Control.Monad.State
import Data.RVar
import Q.Stochastic.Discretize
import Q.Stochastic.Process
import Control.Monad
import Q.ContingentClaim
import Data.Random
import Q.Time
import Data.Time
import Statistics.Distribution (cumulative)
import Statistics.Distribution.Normal (standard)
import Q.ContingentClaim.Options
import Q.Types
type Path b = [(Time, b)]
-- |Summary type class aggregates all priced values of paths
class (PathPricer p) => Summary m p | m->p where
-- | Updates summary with given priced pathes
sSummarize :: m -> [p] -> m
-- | Defines a metric, i.e. calculate distance between 2 summaries
sNorm :: m -> m -> Double
-- | Path generator is a stochastic path generator
class PathGenerator m where
pgMkNew :: m->IO m
pgGenerate :: Integer -> m -> Path b
-- | Path pricer provides a price for given path
class PathPricer m where
ppPrice :: m -> Path b -> m
type MonteCarlo s a = StateT [(Time, s)] RVar a
-- | Generate a single trajectory stopping at each provided time.
trajectory :: forall a b d. (StochasticProcess a b, Discretize d b) =>
d -- ^ Discretization scheme
-> a -- ^ The stochastic process
-> b -- ^ \(S(0)\)
-> [Time] -- ^ Stopping points \(\{t_i\}_i^n \) where \(t_i > 0\)
-> [RVar b] -- ^ \(dW\)s. One for each stopping point.
-> RVar [b] -- ^ \(S(0) \cup \{S(t_i)\}_i^n \)
trajectory disc p s0 times dws = reverse <$> evalStateT (onePath times dws) initState' where
initState' :: [(Time, b)]
initState' = [(0, s0)]
onePath :: [Time] -> [RVar b] -> MonteCarlo b [b]
onePath [] _ = do
s <- get
return $ map snd s
onePath (t1:tn) (dw1:dws) = do
s <- get
let t0 = head s
b <- lift $ pEvolve p disc t0 t1 dw1
put $ (t1, b) : s
onePath tn dws
-- | Generate multiple trajectories. See 'trajectory'
trajectories:: forall a b d. (StochasticProcess a b, Discretize d b) =>
Int -- ^Num of trajectories
-> d -- ^Discretization scheme
-> a -- ^The stochastic process
-> b -- ^\(S(0)\)
-> [Time] -- ^Stopping points \(\{t_i\}_i^n \) where \(t_i > 0\)
-> [RVar b] -- ^\(dW\)s. One for each stopping point.
-> RVar [[b]] -- ^\(S(0) \cup \{S(t_i)\}_i^n \)
trajectories n disc p initState times dws = replicateM n $ trajectory disc p initState times dws
observationTimes :: ContingentClaim a -> [Day]
observationTimes = undefined
class Model a b | a -> b where
discountFactor :: a -> YearFrac -> YearFrac -> RVar Rate
evolve :: a -> YearFrac -> StateT (YearFrac, b) RVar Double
|
#ifndef WEBRTC_PUB_HPP
#define WEBRTC_PUB_HPP
#include <boost/asio.hpp>
#include <string>
#include <stdint.h>
#include <stddef.h>
void init_single_udp_server(boost::asio::io_context& io_context, const std::string& candidate_ip, uint16_t port);
void dtls_init(const std::string& key_file, const std::string& cert_file);
void init_webrtc_stream_manager_callback();
#endif |
[STATEMENT]
lemma rem_condless_valid_7:
fixes s P as as2
assumes "(list_all P as \<and> list_all P as2)"
shows "list_all P (rem_condless_act s as2 as)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. list_all P (rem_condless_act s as2 as)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
list_all P as \<and> list_all P as2
goal (1 subgoal):
1. list_all P (rem_condless_act s as2 as)
[PROOF STEP]
by (induction as arbitrary: P s as2) auto |
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
#include <boost/exception/exception.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception_ptr.hpp>
#include "keto/common/MetaInfo.hpp"
#include "keto/common/Log.hpp"
#include "keto/common/Exception.hpp"
#include "keto/common/StringCodec.hpp"
#include "keto/environment/EnvironmentManager.hpp"
#include "keto/environment/Constants.hpp"
#include "keto/ssl/RootCertificate.hpp"
#include "keto/cli/Constants.hpp"
#include "keto/session/HttpSession.hpp"
#include "keto/chain_common/TransactionBuilder.hpp"
#include "keto/chain_common/SignedTransactionBuilder.hpp"
#include "keto/chain_common/ActionBuilder.hpp"
#include "keto/transaction_common/TransactionMessageHelper.hpp"
#include "keto/account_utils/AccountGenerator.hpp"
namespace ketoEnv = keto::environment;
namespace ketoCommon = keto::common;
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
boost::program_options::options_description generateOptionDescriptions() {
boost::program_options::options_description optionDescripion;
optionDescripion.add_options()
("help,h", "Print this help message and exit.")
("version,v", "Print version information.")
("accgen,A", "Generate an account.")
("account_key,K", po::value<std::string>(),"Private key file.")
("transgen,T", "Generate a transaction.")
("sessiongen,S", "Generate a new session ID.")
("action,a", po::value<std::string>(),"Action Hash or Name.")
("parent,p", po::value<std::string>(),"Parent Transaction.")
("source,s", po::value<std::string>(),"Source Account Hash.")
("target,t",po::value<std::string>(), "Target Account Hash.")
("value,V", po::value<long>(), "Value of the transaction.");
return optionDescripion;
}
std::shared_ptr<keto::chain_common::TransactionBuilder> buildTransaction(
const std::string& contractHash, const std::string& parentHash,
const std::string& accountHash, const std::string& targetHash,
const long value) {
std::shared_ptr<keto::chain_common::ActionBuilder> actionPtr =
keto::chain_common::ActionBuilder::createAction();
actionPtr->setContract(
keto::asn1::HashHelper(contractHash,
keto::common::HEX)).setParent(
keto::asn1::HashHelper(parentHash,
keto::common::HEX));
long longValue = value;
std::shared_ptr<keto::chain_common::TransactionBuilder> transactionPtr =
keto::chain_common::TransactionBuilder::createTransaction();
transactionPtr->setParent(
keto::asn1::HashHelper(parentHash,
keto::common::HEX)).setSourceAccount(
keto::asn1::HashHelper(accountHash,
keto::common::HEX)).setTargetAccount(
keto::asn1::HashHelper(targetHash,
keto::common::HEX)).setValue(keto::asn1::NumberHelper(longValue)).addAction(actionPtr);
return transactionPtr;
}
int generateTransaction(std::shared_ptr<ketoEnv::Config> config,
boost::program_options::options_description optionDescription) {
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::KETOD_SERVER)) {
std::cerr << "Please configure the ketod server host information [" <<
keto::cli::Constants::KETOD_SERVER << "]" << std::endl;
return -1;
}
std::string host = config->getVariablesMap()[keto::cli::Constants::KETOD_SERVER].as<std::string>();
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::KETOD_PORT)) {
std::cerr << "Please configure the ketod server port information [" <<
keto::cli::Constants::KETOD_PORT << "]" << std::endl;
return -1;
}
std::string port = config->getVariablesMap()[keto::cli::Constants::KETOD_PORT].as<std::string>();
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::PRIVATE_KEY)) {
std::cerr << "Please configure the private key [" <<
keto::cli::Constants::PRIVATE_KEY << "]" << std::endl;
return -1;
}
std::string privateKey = config->getVariablesMap()[keto::cli::Constants::PRIVATE_KEY].as<std::string>();
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::PUBLIC_KEY)) {
std::cerr << "Please configure the public key [" <<
keto::cli::Constants::PUBLIC_KEY << "]" << std::endl;
return -1;
}
std::string publicKey = config->getVariablesMap()[keto::cli::Constants::PUBLIC_KEY].as<std::string>();
// read in the keys
keto::crypto::KeyLoader keyLoader(privateKey, publicKey);
// retrieve the action hash
if (!config->getVariablesMap().count(keto::cli::Constants::ACTION)) {
std::cerr << "Please provide the action name or hash [" <<
keto::cli::Constants::ACTION << "]" << std::endl;
std::cout << optionDescription << std::endl;
return -1;
}
std::string action = config->getVariablesMap()[keto::cli::Constants::ACTION].as<std::string>();
if (config->getVariablesMap().count(action)) {
action = config->getVariablesMap()[action].as<std::string>();
}
// retrieve the parent hash
if (!config->getVariablesMap().count(keto::cli::Constants::PARENT)) {
std::cerr << "Please provide the parent hash [" <<
keto::cli::Constants::PARENT << "]" << std::endl;
std::cout << optionDescription << std::endl;
return -1;
}
std::string parentHash = config->getVariablesMap()[keto::cli::Constants::PARENT].as<std::string>();
// retrieve source account hash
if (!config->getVariablesMap().count(keto::cli::Constants::SOURCE_ACCOUNT)) {
std::cerr << "Please provide the source account [" <<
keto::cli::Constants::SOURCE_ACCOUNT << "]" << std::endl;
std::cout << optionDescription << std::endl;
return -1;
}
std::string sourceAccount = config->getVariablesMap()[keto::cli::Constants::SOURCE_ACCOUNT].as<std::string>();
// retrieve target account hash
if (!config->getVariablesMap().count(keto::cli::Constants::TARGET_ACCOUNT)) {
std::cerr << "Please provide the target account [" <<
keto::cli::Constants::TARGET_ACCOUNT << "]" << std::endl;
std::cout << optionDescription << std::endl;
return -1;
}
std::string targetAccount = config->getVariablesMap()[keto::cli::Constants::TARGET_ACCOUNT].as<std::string>();
// retrieve transaction value
if (!config->getVariablesMap().count(keto::cli::Constants::VALUE)) {
std::cerr << "Please provide the value [" <<
keto::cli::Constants::VALUE << "]" << std::endl;
std::cout << optionDescription << std::endl;
return -1;
}
long value = config->getVariablesMap()[keto::cli::Constants::VALUE].as<long>();
std::shared_ptr<keto::chain_common::TransactionBuilder> transactionPtr = buildTransaction(
action, parentHash,sourceAccount, targetAccount,value);
keto::asn1::PrivateKeyHelper privateKeyHelper;
privateKeyHelper.setKey(
Botan::PKCS8::BER_encode( *keyLoader.getPrivateKey() ));
std::shared_ptr<keto::chain_common::SignedTransactionBuilder> signedTransBuild =
keto::chain_common::SignedTransactionBuilder::createTransaction(
privateKeyHelper);
signedTransBuild->setTransaction(transactionPtr);
signedTransBuild->sign();
keto::transaction_common::TransactionMessageHelperPtr transactionMessageHelperPtr(
new keto::transaction_common::TransactionMessageHelper(
*signedTransBuild,keto::asn1::HashHelper(sourceAccount,
keto::common::HEX),keto::asn1::HashHelper(targetAccount,
keto::common::HEX)));
// The io_context is required for all I/O
boost::asio::io_context ioc;
// The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client};
// This holds the root certificate used for verification
keto::ssl::load_root_certificates(ctx);
keto::session::HttpSession session(ioc,ctx,
privateKey,publicKey);
std::string result=
session.setHost(host).setPort(port).handShake().makeRequest(
transactionMessageHelperPtr);
// Write the message to standard out
std::cout << result << std::endl;
return 0;
}
int generateSession(std::shared_ptr<ketoEnv::Config> config) {
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::KETOD_SERVER)) {
std::cerr << "Please configure the ketod server host information [" <<
keto::cli::Constants::KETOD_SERVER << "]" << std::endl;
return -1;
}
std::string host = config->getVariablesMap()[keto::cli::Constants::KETOD_SERVER].as<std::string>();
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::KETOD_PORT)) {
std::cerr << "Please configure the ketod server port information [" <<
keto::cli::Constants::KETOD_PORT << "]" << std::endl;
return -1;
}
std::string port = config->getVariablesMap()[keto::cli::Constants::KETOD_PORT].as<std::string>();
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::PRIVATE_KEY)) {
std::cerr << "Please configure the private key [" <<
keto::cli::Constants::PRIVATE_KEY << "]" << std::endl;
return -1;
}
std::string privateKey = config->getVariablesMap()[keto::cli::Constants::PRIVATE_KEY].as<std::string>();
// retrieve the host information from the configuration file
if (!config->getVariablesMap().count(keto::cli::Constants::PUBLIC_KEY)) {
std::cerr << "Please configure the public key [" <<
keto::cli::Constants::PUBLIC_KEY << "]" << std::endl;
return -1;
}
std::string publicKey = config->getVariablesMap()[keto::cli::Constants::PUBLIC_KEY].as<std::string>();
// read in the keys
keto::crypto::KeyLoader keyLoader(privateKey, publicKey);
// The io_context is required for all I/O
boost::asio::io_context ioc;
// The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client};
// This holds the root certificate used for verification
keto::ssl::load_root_certificates(ctx);
keto::session::HttpSession session(ioc,ctx,
privateKey,publicKey);
std::string result=
session.setHost(host).setPort(port).handShake().getSessionId();
// Write the message to standard out
std::cout << "Session id : " << result << std::endl;
return 0;
}
int generateAccount(std::shared_ptr<ketoEnv::Config> config,
boost::program_options::options_description optionDescription) {
if (config->getVariablesMap().count(keto::cli::Constants::KETO_ACCOUNT_KEY)) {
std::string keyPath = config->getVariablesMap()[keto::cli::Constants::KETO_ACCOUNT_KEY].as<std::string>();
std::cout << ((const std::string)keto::account_utils::AccountGenerator(keyPath)) << std::endl;
} else {
std::cout << ((const std::string)keto::account_utils::AccountGenerator()) << std::endl;
}
return 0;
}
/**
* The CLI main file
*
* @param argc
* @param argv
* @return
*/
int main(int argc, char** argv)
{
try {
boost::program_options::options_description optionDescription =
generateOptionDescriptions();
std::shared_ptr<ketoEnv::EnvironmentManager> manager =
keto::environment::EnvironmentManager::init(
keto::environment::Constants::KETO_CLI_CONFIG_FILE,
optionDescription,argc,argv);
std::shared_ptr<ketoEnv::Config> config = manager->getConfig();
if (config->getVariablesMap().count(ketoEnv::Constants::KETO_VERSION)) {
std::cout << ketoCommon::MetaInfo::VERSION << std::endl;
return 0;
}
if (config->getVariablesMap().count(ketoEnv::Constants::KETO_HELP)) {
std::cout << optionDescription << std::endl;
return 0;
}
if (config->getVariablesMap().count(keto::cli::Constants::KETO_TRANSACTION_GEN))
{
return generateTransaction(config,optionDescription);
} else if (config->getVariablesMap().count(keto::cli::Constants::KETO_ACCOUNT_GEN)) {
return generateAccount(config,optionDescription);
} else if (config->getVariablesMap().count(keto::cli::Constants::KETO_SESSION_GEN)) {
return generateSession(config);
}
KETO_LOG_INFO << "CLI Executed";
} catch (keto::common::Exception& ex) {
KETO_LOG_ERROR << "Failed to start because : " << ex.what();
KETO_LOG_ERROR << "Cause: " << boost::diagnostic_information(ex,true);
return -1;
} catch (boost::exception& ex) {
KETO_LOG_ERROR << "Failed to start because : " << boost::diagnostic_information(ex,true);
return -1;
} catch (std::exception& ex) {
KETO_LOG_ERROR << "Failed to start because : " << ex.what();
return -1;
} catch (...) {
KETO_LOG_ERROR << "Failed to start unknown error.";
return -1;
}
}
|
function oeprint1(mu, oev)
% print six classical orbital elements
% and orbital period in minutes
% input
% mu = gravitational constant (km**3/sec**2)
% oev(1) = semimajor axis (kilometers)
% oev(2) = orbital eccentricity (non-dimensional)
% (0 <= eccentricity < 1)
% oev(3) = orbital inclination (radians)
% (0 <= inclination <= pi)
% oev(4) = argument of perigee (radians)
% (0 <= argument of perigee <= 2 pi)
% oev(5) = right ascension of ascending node (radians)
% (0 <= raan <= 2 pi)
% oev(6) = true anomaly (radians)
% (0 <= true anomaly <= 2 pi)
% Orbital Mechanics with Matlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rtd = 180 / pi;
% unload orbital elements array
sma = oev(1);
ecc = oev(2);
inc = oev(3);
argper = oev(4);
raan = oev(5);
tanom = oev(6);
arglat = mod(tanom + argper, 2.0 * pi);
if (sma > 0.0)
period = 2.0d0 * pi * sma * sqrt(sma / mu);
else
period = 99999.9;
end
% print orbital elements
fprintf ('\n sma (km) eccentricity inclination (deg) argper (deg)');
fprintf ('\n %+16.14e %+16.14e %+16.14e %+16.14e \n', sma, ecc, inc * rtd, argper * rtd);
fprintf ('\n raan (deg) true anomaly (deg) arglat (deg) period (min)');
fprintf ('\n %+16.14e %+16.14e %+16.14e %+16.14e \n', raan * rtd, tanom * rtd, arglat * rtd, period / 60);
|
(* Title: HOL/Auth/n_mutualExFsm_lemma_inv__3_on_rules.thy
Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
*)
header{*The n_mutualExFsm Protocol Case Study*}
theory n_mutualExFsm_lemma_inv__3_on_rules imports n_mutualExFsm_lemma_on_inv__3
begin
section{*All lemmas on causal relation between inv__3*}
lemma lemma_inv__3_on_rules:
assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv0 p__Inv1. p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv0~=p__Inv1\<and>f=inv__3 p__Inv0 p__Inv1)"
shows "invHoldForRule s f r (invariants N)"
proof -
have c1: "(\<exists> i. i\<le>N\<and>r=n_fsm i)"
apply (cut_tac b1, auto) done
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_fsm i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_fsmVsinv__3) done
}
ultimately show "invHoldForRule s f r (invariants N)"
by satx
qed
end
|
module Control.Monad.Writer
import public Control.Monad.Writer.Interface as Control.Monad.Writer
import public Control.Monad.Writer.CPS as Control.Monad.Writer
|
[STATEMENT]
lemma closed_segment_eq_real_ivl:
fixes a b::real
shows "closed_segment a b = (if a \<le> b then {a .. b} else {b .. a})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. closed_segment a b = (if a \<le> b then {a..b} else {b..a})
[PROOF STEP]
using closed_segment_eq_real_ivl1[of a b] closed_segment_eq_real_ivl1[of b a]
[PROOF STATE]
proof (prove)
using this:
a \<le> b \<Longrightarrow> closed_segment a b = {a..b}
b \<le> a \<Longrightarrow> closed_segment b a = {b..a}
goal (1 subgoal):
1. closed_segment a b = (if a \<le> b then {a..b} else {b..a})
[PROOF STEP]
by (auto simp: closed_segment_commute) |
[STATEMENT]
lemma one_inf_conv:
"1 \<sqinter> x = 1 \<sqinter> x\<^sup>T"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (1::'a) \<sqinter> x = (1::'a) \<sqinter> x\<^sup>T
[PROOF STEP]
by (metis conv_dist_inf coreflexive_symmetric inf.cobounded1 symmetric_one_closed) |
open import Agda.Builtin.Nat
data Fin : Nat β Set where
zero : {n : Nat} β Fin (suc n)
suc : {n : Nat} β Fin n β Fin (suc n)
f : Fin 1 β Nat
f zero = 0
|
proposition connected_open_polynomial_connected: fixes S :: "'a::euclidean_space set" assumes S: "open S" "connected S" and "x \<in> S" "y \<in> S" shows "\<exists>g. polynomial_function g \<and> path_image g \<subseteq> S \<and> pathstart g = x \<and> pathfinish g = y" |
-- In this file we consider the special of localising at a single
-- element f : R (or rather the set of powers of f). This is also
-- known as inverting f.
-- We then prove that localising first at an element f and at an element
-- g (or rather the image g/1) is the same as localising at the product fΒ·g
-- This fact has an important application in algebraic geometry where it's
-- used to define the structure sheaf of a commutative ring.
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Localisation.InvertingElements where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as β₯
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+β_ ; _Β·_ to _Β·β_
; +-comm to +β-comm ; +-assoc to +β-assoc
; Β·-assoc to Β·β-assoc ; Β·-comm to Β·β-comm)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Vec
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
private
variable
β β' : Level
A : Type β
module _(R' : CommRing β) where
open isMultClosedSubset
private R = fst R'
open CommRingStr (snd R')
open Exponentiation R'
[_βΏ|nβ₯0] : R β β R
[ f βΏ|nβ₯0] g = (β[ n β β ] g β‘ f ^ n) , isPropPropTrunc
-- Ξ£[ n β β ] (s β‘ f ^ n) Γ (β m β s β‘ f ^ m β n β€ m) maybe better, this isProp:
-- (n,sβ‘fβΏ,p) (m,sβ‘fα΅,q) then nβ€m by p and mβ€n by q => nβ‘m
powersFormMultClosedSubset : (f : R) β isMultClosedSubset R' [ f βΏ|nβ₯0]
powersFormMultClosedSubset f .containsOne = PT.β£ zero , refl β£
powersFormMultClosedSubset f .multClosed =
PT.map2 Ξ» (m , p) (n , q) β (m +β n) , (Ξ» i β (p i) Β· (q i)) β Β·-of-^-is-^-of-+ f m n
R[1/_] : R β Type β
R[1/ f ] = Loc.Sβ»ΒΉR R' [ f βΏ|nβ₯0] (powersFormMultClosedSubset f)
R[1/_]AsCommRing : R β CommRing β
R[1/ f ]AsCommRing = Loc.Sβ»ΒΉRAsCommRing R' [ f βΏ|nβ₯0] (powersFormMultClosedSubset f)
-- A useful lemma: (gβΏ/1)β‘(g/1)βΏ in R[1/f]
^-respects-/1 : {f g : R} (n : β) β [ (g ^ n) , 1r , PT.β£ 0 , (Ξ» _ β 1r) β£ ] β‘
Exponentiation._^_ R[1/ f ]AsCommRing [ g , 1r , powersFormMultClosedSubset _ .containsOne ] n
^-respects-/1 zero = refl
^-respects-/1 {f} {g} (suc n) = eq/ _ _ ( (1r , powersFormMultClosedSubset f .containsOne)
, cong (1r Β· (g Β· (g ^ n)) Β·_) (Β·Lid 1r))
β cong (CommRingStr._Β·_ (R[1/ f ]AsCommRing .snd)
[ g , 1r , powersFormMultClosedSubset f .containsOne ]) (^-respects-/1 n)
-- A slight improvement for eliminating into propositions
InvElPropElim : {f : R} {P : R[1/ f ] β Type β'}
β (β x β isProp (P x))
β (β (r : R) (n : β) β P [ r , (f ^ n) , PT.β£ n , refl β£ ]) -- β r n β P (r/fβΏ)
----------------------------------------------------------
β (β x β P x)
InvElPropElim {f = f} {P = P} PisProp base = elimProp (Ξ» _ β PisProp _) []-case
where
S[f] = Loc.S R' [ f βΏ|nβ₯0] (powersFormMultClosedSubset f)
[]-case : (a : R Γ S[f]) β P [ a ]
[]-case (r , s , sβS[f]) = PT.rec (PisProp _) Ξ£helper sβS[f]
where
Ξ£helper : Ξ£[ n β β ] s β‘ f ^ n β P [ r , s , sβS[f] ]
Ξ£helper (n , p) = subst P (cong [_] (β‘-Γ refl (Ξ£β‘Prop (Ξ» _ β isPropPropTrunc) (sym p)))) (base r n)
-- For predicates over the set of powers
powersPropElim : {f : R} {P : R β Type β'}
β (β x β isProp (P x))
β (β n β P (f ^ n))
------------------------------
β β s β s β [ f βΏ|nβ₯0] β P s
powersPropElim {f = f} {P = P} PisProp base s =
PT.rec (PisProp s) Ξ» (n , p) β subst P (sym p) (base n)
module DoubleLoc (R' : CommRing β) (f g : (fst R')) where
open isMultClosedSubset
open CommRingStr (snd R')
open CommRingTheory R'
open Exponentiation R'
open RingTheory (CommRingβRing R')
open CommRingStr (snd (R[1/_]AsCommRing R' f)) renaming ( _Β·_ to _Β·αΆ _ ; 1r to 1αΆ
; _+_ to _+αΆ _ ; 0r to 0αΆ
; Β·Lid to Β·αΆ -lid ; Β·Rid to Β·αΆ -rid
; Β·Assoc to Β·αΆ -assoc ; Β·-comm to Β·αΆ -comm)
open IsRingHom
private
R = fst R'
R[1/f] = R[1/_] R' f
R[1/f]AsCommRing = R[1/_]AsCommRing R' f
R[1/fg] = R[1/_] R' (f Β· g)
R[1/fg]AsCommRing = R[1/_]AsCommRing R' (f Β· g)
R[1/f][1/g] = R[1/_] (R[1/_]AsCommRing R' f)
[ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
R[1/f][1/g]AsCommRing = R[1/_]AsCommRing (R[1/_]AsCommRing R' f)
[ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
R[1/f][1/g]Λ£ = R[1/f][1/g]AsCommRing Λ£
_/1/1 : R β R[1/f][1/g]
r /1/1 = [ [ r , 1r , PT.β£ 0 , refl β£ ] , 1αΆ , PT.β£ 0 , refl β£ ]
/1/1AsCommRingHom : CommRingHom R' R[1/f][1/g]AsCommRing
fst /1/1AsCommRingHom = _/1/1
snd /1/1AsCommRingHom = makeIsRingHom refl lem+ lemΒ·
where
lem+ : _
lem+ r r' =
cong [_]
(β‘-Γ
(cong [_]
(β‘-Γ
(congβ _+_
(sym (Β·Rid _) β (Ξ» i β (Β·Rid r (~ i)) Β· (Β·Rid 1r (~ i))))
(sym (Β·Rid _) β (Ξ» i β (Β·Rid r' (~ i)) Β· (Β·Rid 1r (~ i)))))
(Ξ£β‘Prop (Ξ» _ β isPropPropTrunc)
(sym (Β·Lid _) β (Ξ» i β (Β·Lid 1r (~ i)) Β· (Β·Lid 1r (~ i)))))))
(Ξ£β‘Prop (Ξ» _ β isPropPropTrunc) (sym (Β·αΆ -lid 1αΆ ))))
lemΒ· : _
lemΒ· r r' =
cong [_]
(β‘-Γ
(cong [_] (β‘-Γ refl (Ξ£β‘Prop (Ξ» _ β isPropPropTrunc) (sym (Β·Lid _)))))
(Ξ£β‘Prop (Ξ» _ β isPropPropTrunc) (sym (Β·αΆ -lid 1αΆ ))))
-- this will give us a map R[1/fg] β R[1/f][1/g] by the universal property of localisation
fβΏgβΏ/1/1βR[1/f][1/g]Λ£ : (s : R) β s β ([_βΏ|nβ₯0] R' (f Β· g)) β s /1/1 β R[1/f][1/g]Λ£
fβΏgβΏ/1/1βR[1/f][1/g]Λ£ = powersPropElim R' (Ξ» s β R[1/f][1/g]Λ£ (s /1/1) .snd) βcase
where
βcase : (n : β) β ((f Β· g) ^ n) /1/1 β R[1/f][1/g]Λ£
βcase n = [ [ 1r , (f ^ n) , PT.β£ n , refl β£ ]
, [ (g ^ n) , 1r , PT.β£ 0 , refl β£ ] --denominator
, PT.β£ n , ^-respects-/1 _ n β£ ]
, eq/ _ _ ((1αΆ , powersFormMultClosedSubset _ _ .containsOne)
, eq/ _ _ ((1r , powersFormMultClosedSubset _ _ .containsOne) , path))
where
eq1 : β x β 1r Β· (1r Β· (x Β· 1r) Β· 1r) Β· (1r Β· 1r Β· (1r Β· 1r)) β‘ x
eq1 = solve R'
eq2 : β x y β x Β· y β‘ 1r Β· (1r Β· 1r Β· (1r Β· y)) Β· (1r Β· (1r Β· x) Β· 1r)
eq2 = solve R'
path : 1r Β· (1r Β· ((f Β· g) ^ n Β· 1r) Β· 1r) Β· (1r Β· 1r Β· (1r Β· 1r))
β‘ 1r Β· (1r Β· 1r Β· (1r Β· g ^ n)) Β· (1r Β· (1r Β· f ^ n) Β· 1r)
path = 1r Β· (1r Β· ((f Β· g) ^ n Β· 1r) Β· 1r) Β· (1r Β· 1r Β· (1r Β· 1r)) β‘β¨ eq1 ((f Β· g) ^ n) β©
(f Β· g) ^ n β‘β¨ ^-ldist-Β· _ _ _ β©
f ^ n Β· g ^ n β‘β¨ eq2 (f ^ n) (g ^ n) β©
1r Β· (1r Β· 1r Β· (1r Β· g ^ n)) Β· (1r Β· (1r Β· f ^ n) Β· 1r) β
-- the main result: localising at one element and then at another is
-- the same as localising at the product.
-- takes forever to compute without experimental lossy unification
R[1/fg]β‘R[1/f][1/g] : R[1/fg]AsCommRing β‘ R[1/f][1/g]AsCommRing
R[1/fg]β‘R[1/f][1/g] = Sβ»ΒΉRChar R' ([_βΏ|nβ₯0] R' (f Β· g))
(powersFormMultClosedSubset R' (f Β· g)) _ /1/1AsCommRingHom pathtoR[1/fg]
where
open PathToSβ»ΒΉR
pathtoR[1/fg] : PathToSβ»ΒΉR R' ([_βΏ|nβ₯0] R' (f Β· g)) (powersFormMultClosedSubset R' (f Β· g))
R[1/f][1/g]AsCommRing /1/1AsCommRingHom
ΟSβAΛ£ pathtoR[1/fg] = fβΏgβΏ/1/1βR[1/f][1/g]Λ£
kerΟβannS pathtoR[1/fg] r p = toGoal helperR[1/f]
where
open RingTheory (CommRingβRing R[1/f]AsCommRing) renaming ( 0RightAnnihilates to 0αΆ RightAnnihilates
; 0LeftAnnihilates to 0αΆ -leftNullifies)
open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^αΆ _)
hiding (Β·-of-^-is-^-of-+ ; ^-ldist-Β·)
S[f] = Loc.S R' ([_βΏ|nβ₯0] R' f) (powersFormMultClosedSubset R' f)
S[fg] = Loc.S R' ([_βΏ|nβ₯0] R' (f Β· g)) (powersFormMultClosedSubset R' (f Β· g))
g/1 : R[1/_] R' f
g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
S[g/1] = Loc.S R[1/f]AsCommRing
([_βΏ|nβ₯0] R[1/f]AsCommRing g/1)
(powersFormMultClosedSubset R[1/f]AsCommRing g/1)
r/1 : R[1/_] R' f
r/1 = [ r , 1r , powersFormMultClosedSubset R' f .containsOne ]
-- this is the crucial step, modulo truncation we can take p to be generated
-- by the quotienting relation of localisation. Note that we wouldn't be able
-- to prove our goal if kerΟβannS was formulated with a Ξ£ instead of a β
β₯r/1,1/1β0/1,1/1β₯ : β[ u β S[g/1] ] fst u Β·αΆ r/1 Β·αΆ 1αΆ β‘ fst u Β·αΆ 0αΆ Β·αΆ 1αΆ
β₯r/1,1/1β0/1,1/1β₯ = Iso.fun (SQ.isEquivRelβTruncIso (Loc.locIsEquivRel _ _ _) _ _) p
helperR[1/f] : β[ n β β ] [ g ^ n Β· r , 1r , PT.β£ 0 , refl β£ ] β‘ 0αΆ
helperR[1/f] = PT.rec isPropPropTrunc
(uncurry (uncurry (powersPropElim R[1/f]AsCommRing
(Ξ» _ β isPropΞ (Ξ» _ β isPropPropTrunc)) baseCase)))
β₯r/1,1/1β0/1,1/1β₯
where
baseCase : β n β g/1 ^αΆ n Β·αΆ r/1 Β·αΆ 1αΆ β‘ g/1 ^αΆ n Β·αΆ 0αΆ Β·αΆ 1αΆ
β β[ n β β ] [ g ^ n Β· r , 1r , PT.β£ 0 , refl β£ ] β‘ 0αΆ
baseCase n q = PT.β£ n , path β£
where
path : [ g ^ n Β· r , 1r , PT.β£ 0 , refl β£ ] β‘ 0αΆ
path = [ g ^ n Β· r , 1r , PT.β£ 0 , refl β£ ]
β‘β¨ cong [_] (β‘-Γ refl (Ξ£β‘Prop (Ξ» _ β isPropPropTrunc) (sym (Β·Rid _)))) β©
[ g ^ n , 1r , PT.β£ 0 , refl β£ ] Β·αΆ r/1
β‘β¨ cong (_Β·αΆ r/1) (^-respects-/1 _ n) β©
g/1 ^αΆ n Β·αΆ r/1
β‘β¨ sym (Β·αΆ -rid _) β©
g/1 ^αΆ n Β·αΆ r/1 Β·αΆ 1αΆ
β‘β¨ q β©
g/1 ^αΆ n Β·αΆ 0αΆ Β·αΆ 1αΆ
β‘β¨ cong (_Β·αΆ 1αΆ ) (0αΆ RightAnnihilates _) β 0αΆ -leftNullifies 1αΆ β©
0αΆ β
toGoal : β[ n β β ] [ g ^ n Β· r , 1r , PT.β£ 0 , refl β£ ] β‘ 0αΆ
β β[ u β S[fg] ] fst u Β· r β‘ 0r
toGoal = PT.rec isPropPropTrunc Ξ£helper
where
Ξ£helper : Ξ£[ n β β ] [ g ^ n Β· r , 1r , PT.β£ 0 , refl β£ ] β‘ 0αΆ
β β[ u β S[fg] ] fst u Β· r β‘ 0r
Ξ£helper (n , q) = PT.map Ξ£helper2 helperR
where
-- now, repeat the above strategy with q
β₯gβΏrβ0β₯ : β[ u β S[f] ] fst u Β· (g ^ n Β· r) Β· 1r β‘ fst u Β· 0r Β· 1r
β₯gβΏrβ0β₯ = Iso.fun (SQ.isEquivRelβTruncIso (Loc.locIsEquivRel _ _ _) _ _) q
helperR : β[ m β β ] f ^ m Β· g ^ n Β· r β‘ 0r
helperR = PT.rec isPropPropTrunc
(uncurry (uncurry (powersPropElim R'
(Ξ» _ β isPropΞ (Ξ» _ β isPropPropTrunc)) baseCase)))
β₯gβΏrβ0β₯
where
baseCase : (m : β) β f ^ m Β· (g ^ n Β· r) Β· 1r β‘ f ^ m Β· 0r Β· 1r
β β[ m β β ] f ^ m Β· g ^ n Β· r β‘ 0r
baseCase m q' = PT.β£ m , path β£
where
path : f ^ m Β· g ^ n Β· r β‘ 0r
path = (Ξ» i β Β·Rid (Β·Assoc (f ^ m) (g ^ n) r (~ i)) (~ i))
ββ q' ββ (Ξ» i β Β·Rid (0RightAnnihilates (f ^ m) i) i)
Ξ£helper2 : Ξ£[ m β β ] f ^ m Β· g ^ n Β· r β‘ 0r
β Ξ£[ u β S[fg] ] fst u Β· r β‘ 0r
Ξ£helper2 (m , q') = (((f Β· g) ^ l) , PT.β£ l , refl β£) , path
where
l = max m n
path : (f Β· g) ^ l Β· r β‘ 0r
path = (f Β· g) ^ l Β· r
β‘β¨ cong (_Β· r) (^-ldist-Β· _ _ _) β©
f ^ l Β· g ^ l Β· r
β‘β¨ congβ (Ξ» x y β f ^ x Β· g ^ y Β· r) (sym (β€-βΈ-+-cancel {m = m} left-β€-max))
(sym (β€-βΈ-+-cancel {m = n} right-β€-max)) β©
f ^ (l βΈ m +β m) Β· g ^ (l βΈ n +β n) Β· r
β‘β¨ congβ (Ξ» x y β x Β· y Β· r) (sym (Β·-of-^-is-^-of-+ _ _ _))
(sym (Β·-of-^-is-^-of-+ _ _ _)) β©
f ^ (l βΈ m) Β· f ^ m Β· (g ^ (l βΈ n) Β· g ^ n) Β· r
β‘β¨ cong (_Β· r) (Β·-commAssocSwap _ _ _ _) β©
f ^ (l βΈ m) Β· g ^ (l βΈ n) Β· (f ^ m Β· g ^ n) Β· r
β‘β¨ sym (Β·Assoc _ _ _) β©
f ^ (l βΈ m) Β· g ^ (l βΈ n) Β· (f ^ m Β· g ^ n Β· r)
β‘β¨ cong (f ^ (l βΈ m) Β· g ^ (l βΈ n) Β·_) q' β©
f ^ (l βΈ m) Β· g ^ (l βΈ n) Β· 0r
β‘β¨ 0RightAnnihilates _ β©
0r β
surΟ pathtoR[1/fg] = InvElPropElim _ (Ξ» _ β isPropPropTrunc) toGoal
where
open Exponentiation R[1/f]AsCommRing renaming (_^_ to _^αΆ _)
hiding (Β·-of-^-is-^-of-+ ; ^-ldist-Β·)
open CommRingStr (snd R[1/f][1/g]AsCommRing) renaming (_Β·_ to _Β·R[1/f][1/g]_)
hiding (1r ; Β·Lid ; Β·Rid ; Β·Assoc)
open Units R[1/f][1/g]AsCommRing
g/1 : R[1/_] R' f
g/1 = [ g , 1r , powersFormMultClosedSubset R' f .containsOne ]
S[fg] = Loc.S R' ([_βΏ|nβ₯0] R' (f Β· g)) (powersFormMultClosedSubset R' (f Β· g))
baseCase : (r : R) (m n : β) β β[ x β R Γ S[fg] ] (x .fst /1/1)
β‘ [ [ r , f ^ m , PT.β£ m , refl β£ ]
, [ g ^ n , 1r , PT.β£ 0 , refl β£ ] , PT.β£ n , ^-respects-/1 _ n β£ ]
Β·R[1/f][1/g] (x .snd .fst /1/1)
baseCase r m n = PT.β£ ((r Β· f ^ (l βΈ m) Β· g ^ (l βΈ n)) -- x .fst
, (f Β· g) ^ l , PT.β£ l , refl β£) -- x .snd
, eq/ _ _ ((1αΆ , PT.β£ 0 , refl β£) , eq/ _ _ ((1r , PT.β£ 0 , refl β£) , path)) β£
-- reduce equality of double fractions into equality in R
where
eq1 : β r flm gln gn fm
β 1r Β· (1r Β· (r Β· flm Β· gln) Β· (gn Β· 1r)) Β· (1r Β· (fm Β· 1r) Β· 1r)
β‘ r Β· flm Β· (gln Β· gn) Β· fm
eq1 = solve R'
eq2 : β r flm gl fm β r Β· flm Β· gl Β· fm β‘ r Β· (flm Β· fm ) Β· gl
eq2 = solve R'
eq3 : β r fgl β r Β· fgl β‘ 1r Β· (1r Β· (r Β· fgl) Β· 1r) Β· (1r Β· 1r Β· (1r Β· 1r))
eq3 = solve R'
l = max m n
path : 1r Β· (1r Β· (r Β· f ^ (l βΈ m) Β· g ^ (l βΈ n)) Β· (g ^ n Β· 1r)) Β· (1r Β· (f ^ m Β· 1r) Β· 1r)
β‘ 1r Β· (1r Β· (r Β· (f Β· g) ^ l) Β· 1r) Β· (1r Β· 1r Β· (1r Β· 1r))
path = 1r Β· (1r Β· (r Β· f ^ (l βΈ m) Β· g ^ (l βΈ n)) Β· (g ^ n Β· 1r)) Β· (1r Β· (f ^ m Β· 1r) Β· 1r)
β‘β¨ eq1 r (f ^ (l βΈ m)) (g ^ (l βΈ n)) (g ^ n) (f ^ m) β©
r Β· f ^ (l βΈ m) Β· (g ^ (l βΈ n) Β· g ^ n) Β· f ^ m
β‘β¨ cong (Ξ» x β r Β· f ^ (l βΈ m) Β· x Β· f ^ m) (Β·-of-^-is-^-of-+ _ _ _) β©
r Β· f ^ (l βΈ m) Β· g ^ (l βΈ n +β n) Β· f ^ m
β‘β¨ cong (Ξ» x β r Β· f ^ (l βΈ m) Β· g ^ x Β· f ^ m) (β€-βΈ-+-cancel right-β€-max) β©
r Β· f ^ (l βΈ m) Β· g ^ l Β· f ^ m
β‘β¨ eq2 r (f ^ (l βΈ m)) (g ^ l) (f ^ m) β©
r Β· (f ^ (l βΈ m) Β· f ^ m) Β· g ^ l
β‘β¨ cong (Ξ» x β r Β· x Β· g ^ l) (Β·-of-^-is-^-of-+ _ _ _) β©
r Β· f ^ (l βΈ m +β m) Β· g ^ l
β‘β¨ cong (Ξ» x β r Β· f ^ x Β· g ^ l) (β€-βΈ-+-cancel left-β€-max) β©
r Β· f ^ l Β· g ^ l
β‘β¨ sym (Β·Assoc _ _ _) β©
r Β· (f ^ l Β· g ^ l)
β‘β¨ cong (r Β·_) (sym (^-ldist-Β· _ _ _)) β©
r Β· (f Β· g) ^ l
β‘β¨ eq3 r ((f Β· g) ^ l) β©
1r Β· (1r Β· (r Β· (f Β· g) ^ l) Β· 1r) Β· (1r Β· 1r Β· (1r Β· 1r)) β
base-^αΆ -helper : (r : R) (m n : β) β β[ x β R Γ S[fg] ] (x .fst /1/1)
β‘ [ [ r , f ^ m , PT.β£ m , refl β£ ]
, g/1 ^αΆ n , PT.β£ n , refl β£ ] Β·R[1/f][1/g] (x .snd .fst /1/1)
base-^αΆ -helper r m n = subst (Ξ» y β β[ x β R Γ S[fg] ] (x .fst /1/1)
β‘ [ [ r , f ^ m , PT.β£ m , refl β£ ] , y ] Β·R[1/f][1/g] (x .snd .fst /1/1))
(Ξ£β‘Prop (Ξ» _ β isPropPropTrunc) (^-respects-/1 _ n)) (baseCase r m n)
indStep : (r : R[1/_] R' f) (n : β) β β[ x β R Γ S[fg] ]
(x .fst /1/1) β‘ [ r , g/1 ^αΆ n , PT.β£ n , refl β£ ] Β·R[1/f][1/g] (x .snd .fst /1/1)
indStep = InvElPropElim _ (Ξ» _ β isPropΞ Ξ» _ β isPropPropTrunc) base-^αΆ -helper
toGoal : (r : R[1/_] R' f) (n : β) β β[ x β R Γ S[fg] ]
(x .fst /1/1) Β·R[1/f][1/g]
((x .snd .fst /1/1) β»ΒΉ) β¦ ΟSβAΛ£ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) β¦
β‘ [ r , g/1 ^αΆ n , PT.β£ n , refl β£ ]
toGoal r n = PT.map Ξ£helper (indStep r n)
where
Ξ£helper : Ξ£[ x β R Γ S[fg] ]
(x .fst /1/1) β‘ [ r , g/1 ^αΆ n , PT.β£ n , refl β£ ] Β·R[1/f][1/g] (x .snd .fst /1/1)
β Ξ£[ x β R Γ S[fg] ]
(x .fst /1/1) Β·R[1/f][1/g] ((x .snd .fst /1/1) β»ΒΉ)
β¦ ΟSβAΛ£ pathtoR[1/fg] (x .snd .fst) (x .snd .snd) β¦
β‘ [ r , g/1 ^αΆ n , PT.β£ n , refl β£ ]
Ξ£helper ((r' , s , sβS[fg]) , p) = (r' , s , sβS[fg])
, β»ΒΉ-eq-elim β¦ ΟSβAΛ£ pathtoR[1/fg] s sβS[fg] β¦ p
-- In this module we construct the map R[1/fg]βR[1/f][1/g] directly
-- and show that it is equal (although not judgementally) to the map induced
-- by the universal property of localisation, i.e. transporting along the path
-- constructed above. Given that this is the easier direction, we can see that
-- it is pretty cumbersome to prove R[1/fg]β‘R[1/f][1/g] directly,
-- which illustrates the usefulness of Sβ»ΒΉRChar quite well.
private
module check where
Ο : R[1/fg] β R[1/f][1/g]
Ο = SQ.rec squash/ Ο Οcoh
where
S[fg] = Loc.S R' ([_βΏ|nβ₯0] R' (f Β· g)) (powersFormMultClosedSubset R' (f Β· g))
curriedΟΞ£ : (r s : R) β Ξ£[ n β β ] s β‘ (f Β· g) ^ n β R[1/f][1/g]
curriedΟΞ£ r s (n , sβ‘fg^n) = [ [ r , (f ^ n) , PT.β£ n , refl β£ ]
, [ (g ^ n) , 1r , PT.β£ 0 , refl β£ ] --denominator
, PT.β£ n , ^-respects-/1 R' n β£ ]
curriedΟ : (r s : R) β β[ n β β ] s β‘ (f Β· g) ^ n β R[1/f][1/g]
curriedΟ r s = elimβSet (Ξ» _ β squash/) (curriedΟΞ£ r s) coh
where
coh : (x y : Ξ£[ n β β ] s β‘ (f Β· g) ^ n) β curriedΟΞ£ r s x β‘ curriedΟΞ£ r s y
coh (n , sβ‘fg^n) (m , sβ‘fg^m) = eq/ _ _ ((1αΆ , PT.β£ 0 , refl β£) ,
eq/ _ _ ( (1r , powersFormMultClosedSubset R' f .containsOne)
, path))
where
eq1 : β r gm fm β 1r Β· (1r Β· r Β· gm) Β· (1r Β· fm Β· 1r) β‘ r Β· (gm Β· fm)
eq1 = solve R'
path : 1r Β· (1r Β· r Β· (g ^ m)) Β· (1r Β· (f ^ m) Β· 1r)
β‘ 1r Β· (1r Β· r Β· (g ^ n)) Β· (1r Β· (f ^ n) Β· 1r)
path = 1r Β· (1r Β· r Β· (g ^ m)) Β· (1r Β· (f ^ m) Β· 1r)
β‘β¨ eq1 r (g ^ m) (f ^ m) β©
r Β· (g ^ m Β· f ^ m)
β‘β¨ cong (r Β·_) (sym (^-ldist-Β· g f m)) β©
r Β· ((g Β· f) ^ m)
β‘β¨ cong (Ξ» x β r Β· (x ^ m)) (Β·-comm _ _) β©
r Β· ((f Β· g) ^ m)
β‘β¨ cong (r Β·_) ((sym sβ‘fg^m) β sβ‘fg^n) β©
r Β· ((f Β· g) ^ n)
β‘β¨ cong (Ξ» x β r Β· (x ^ n)) (Β·-comm _ _) β©
r Β· ((g Β· f) ^ n)
β‘β¨ cong (r Β·_) (^-ldist-Β· g f n) β©
r Β· (g ^ n Β· f ^ n)
β‘β¨ sym (eq1 r (g ^ n) (f ^ n)) β©
1r Β· (1r Β· r Β· (g ^ n)) Β· (1r Β· (f ^ n) Β· 1r) β
Ο : R Γ S[fg] β R[1/f][1/g]
Ο = uncurry2 curriedΟ -- Ξ» (r / (fg)βΏ) β ((r / fβΏ) / gβΏ)
curriedΟcohΞ£ : (r s r' s' u : R) β (p : u Β· r Β· s' β‘ u Β· r' Β· s)
β (Ξ± : Ξ£[ n β β ] s β‘ (f Β· g) ^ n)
β (Ξ² : Ξ£[ m β β ] s' β‘ (f Β· g) ^ m)
β (Ξ³ : Ξ£[ l β β ] u β‘ (f Β· g) ^ l)
β Ο (r , s , PT.β£ Ξ± β£) β‘ Ο (r' , s' , PT.β£ Ξ² β£)
curriedΟcohΞ£ r s r' s' u p (n , sβ‘fgβΏ) (m , s'β‘fgα΅) (l , uβ‘fgΛ‘) =
eq/ _ _ ( ( [ (g ^ l) , 1r , powersFormMultClosedSubset R' f .containsOne ]
, PT.β£ l , ^-respects-/1 R' l β£)
, eq/ _ _ ((f ^ l , PT.β£ l , refl β£) , path))
where
eq1 : β fl gl r gm fm
β fl Β· (gl Β· r Β· gm) Β· (1r Β· fm Β· 1r) β‘ fl Β· gl Β· r Β· (gm Β· fm)
eq1 = solve R'
path : f ^ l Β· (g ^ l Β· transp (Ξ» i β R) i0 r Β· transp (Ξ» i β R) i0 (g ^ m))
Β· (1r Β· transp (Ξ» i β R) i0 (f ^ m) Β· transp (Ξ» i β R) i0 1r)
β‘ f ^ l Β· (g ^ l Β· transp (Ξ» i β R) i0 r' Β· transp (Ξ» i β R) i0 (g ^ n))
Β· (1r Β· transp (Ξ» i β R) i0 (f ^ n) Β· transp (Ξ» i β R) i0 1r)
path = f ^ l Β· (g ^ l Β· transp (Ξ» i β R) i0 r Β· transp (Ξ» i β R) i0 (g ^ m))
Β· (1r Β· transp (Ξ» i β R) i0 (f ^ m) Β· transp (Ξ» i β R) i0 1r)
β‘β¨ (Ξ» i β f ^ l Β· (g ^ l Β· transportRefl r i Β· transportRefl (g ^ m) i)
Β· (1r Β· transportRefl (f ^ m) i Β· transportRefl 1r i)) β©
f ^ l Β· (g ^ l Β· r Β· g ^ m) Β· (1r Β· f ^ m Β· 1r)
β‘β¨ eq1 (f ^ l) (g ^ l) r (g ^ m) (f ^ m) β©
f ^ l Β· g ^ l Β· r Β· (g ^ m Β· f ^ m)
β‘β¨ (Ξ» i β ^-ldist-Β· f g l (~ i) Β· r Β· ^-ldist-Β· g f m (~ i)) β©
(f Β· g) ^ l Β· r Β· (g Β· f) ^ m
β‘β¨ cong (Ξ» x β (f Β· g) ^ l Β· r Β· x ^ m) (Β·-comm _ _) β©
(f Β· g) ^ l Β· r Β· (f Β· g) ^ m
β‘β¨ (Ξ» i β uβ‘fgΛ‘ (~ i) Β· r Β· s'β‘fgα΅ (~ i)) β©
u Β· r Β· s'
β‘β¨ p β©
u Β· r' Β· s
β‘β¨ (Ξ» i β uβ‘fgΛ‘ i Β· r' Β· sβ‘fgβΏ i) β©
(f Β· g) ^ l Β· r' Β· (f Β· g) ^ n
β‘β¨ cong (Ξ» x β (f Β· g) ^ l Β· r' Β· x ^ n) (Β·-comm _ _) β©
(f Β· g) ^ l Β· r' Β· (g Β· f) ^ n
β‘β¨ (Ξ» i β ^-ldist-Β· f g l i Β· r' Β· ^-ldist-Β· g f n i) β©
f ^ l Β· g ^ l Β· r' Β· (g ^ n Β· f ^ n)
β‘β¨ sym (eq1 (f ^ l) (g ^ l) r' (g ^ n) (f ^ n)) β©
f ^ l Β· (g ^ l Β· r' Β· g ^ n) Β· (1r Β· f ^ n Β· 1r)
β‘β¨ (Ξ» i β f ^ l Β· (g ^ l Β· transportRefl r' (~ i) Β· transportRefl (g ^ n) (~ i))
Β· (1r Β· transportRefl (f ^ n) (~ i) Β· transportRefl 1r (~ i))) β©
f ^ l Β· (g ^ l Β· transp (Ξ» i β R) i0 r' Β· transp (Ξ» i β R) i0 (g ^ n))
Β· (1r Β· transp (Ξ» i β R) i0 (f ^ n) Β· transp (Ξ» i β R) i0 1r) β
curriedΟcoh : (r s r' s' u : R) β (p : u Β· r Β· s' β‘ u Β· r' Β· s)
β (Ξ± : β[ n β β ] s β‘ (f Β· g) ^ n)
β (Ξ² : β[ m β β ] s' β‘ (f Β· g) ^ m)
β (Ξ³ : β[ l β β ] u β‘ (f Β· g) ^ l)
β Ο (r , s , Ξ±) β‘ Ο (r' , s' , Ξ²)
curriedΟcoh r s r' s' u p = PT.elim (Ξ» _ β isPropΞ 2 (Ξ» _ _ β squash/ _ _))
Ξ» Ξ± β PT.elim (Ξ» _ β isPropΞ (Ξ» _ β squash/ _ _))
Ξ» Ξ² β PT.rec (squash/ _ _)
Ξ» Ξ³ β curriedΟcohΞ£ r s r' s' u p Ξ± Ξ² Ξ³
Οcoh : (a b : R Γ S[fg])
β Loc._β_ R' ([_βΏ|nβ₯0] R' (f Β· g)) (powersFormMultClosedSubset R' (f Β· g)) a b
β Ο a β‘ Ο b
Οcoh (r , s , Ξ±) (r' , s' , Ξ²) ((u , Ξ³) , p) = curriedΟcoh r s r' s' u p Ξ± Ξ² Ξ³
-- the map induced by the universal property
open Sβ»ΒΉRUniversalProp R' ([_βΏ|nβ₯0] R' (f Β· g)) (powersFormMultClosedSubset R' (f Β· g))
Ο : R[1/fg] β R[1/f][1/g]
Ο = Sβ»ΒΉRHasUniversalProp R[1/f][1/g]AsCommRing /1/1AsCommRingHom fβΏgβΏ/1/1βR[1/f][1/g]Λ£ .fst .fst .fst
-- the sanity check:
-- both maps send a fraction r/(fg)βΏ to a double fraction,
-- where numerator and denominator are almost the same fraction respectively.
-- unfortunately the proofs that the denominators are powers are quite different for
-- the two maps, but of course we can ignore them.
-- The definition of Ο introduces a lot of (1r Β·_). Perhaps most surprisingly,
-- we have to give the path eq1 for the equality of the numerator of the numerator.
Οβ‘Ο : β r β Ο r β‘ Ο r
Οβ‘Ο = InvElPropElim _ (Ξ» _ β squash/ _ _) βcase
where
βcase : (r : R) (n : β)
β Ο [ r , (f Β· g) ^ n , PT.β£ n , refl β£ ] β‘ Ο [ r , (f Β· g) ^ n , PT.β£ n , refl β£ ]
βcase r n = cong [_] (Ξ£PathP --look into the components of the double-fractions
( cong [_] (Ξ£PathP (eq1 , Ξ£β‘Prop (Ξ» x β S'[f] x .snd) (sym (Β·Lid _))))
, Ξ£β‘Prop (Ξ» x β S'[f][g] x .snd) --ignore proof that denominator is power of g/1
( cong [_] (Ξ£PathP (sym (Β·Lid _) , Ξ£β‘Prop (Ξ» x β S'[f] x .snd) (sym (Β·Lid _)))))))
where
S'[f] = ([_βΏ|nβ₯0] R' f)
S'[f][g] = ([_βΏ|nβ₯0] R[1/f]AsCommRing [ g , 1r , powersFormMultClosedSubset R' f .containsOne ])
eq1 : transp (Ξ» i β fst R') i0 r β‘ r Β· transp (Ξ» i β fst R') i0 1r
eq1 = transportRefl r ββ sym (Β·Rid r) ββ cong (r Β·_) (sym (transportRefl 1r))
|
/-
Copyright (c) 2022 George Peter Banyard, YaΓ«l Dillies, Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: George Peter Banyard, YaΓ«l Dillies, Kyle Miller
-/
import combinatorics.simple_graph.connectivity
/-!
# Graph products
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the box product of graphs and other product constructions. The box product of `G`
and `H` is the graph on the product of the vertices such that `x` and `y` are related iff they agree
on one component and the other one is related via either `G` or `H`. For example, the box product of
two edges is a square.
## Main declarations
* `simple_graph.box_prod`: The box product.
## Notation
* `G β‘ H`: The box product of `G` and `H`.
## TODO
Define all other graph products!
-/
variables {Ξ± Ξ² Ξ³ : Type*}
namespace simple_graph
variables {G : simple_graph Ξ±} {H : simple_graph Ξ²} {I : simple_graph Ξ³} {a aβ aβ : Ξ±} {b bβ bβ : Ξ²}
{x y : Ξ± Γ Ξ²}
/-- Box product of simple graphs. It relates `(aβ, b)` and `(aβ, b)` if `G` relates `aβ` and `aβ`,
and `(a, bβ)` and `(a, bβ)` if `H` relates `bβ` and `bβ`. -/
def box_prod (G : simple_graph Ξ±) (H : simple_graph Ξ²) : simple_graph (Ξ± Γ Ξ²) :=
{ adj := Ξ» x y, G.adj x.1 y.1 β§ x.2 = y.2 β¨ H.adj x.2 y.2 β§ x.1 = y.1,
symm := Ξ» x y, by simp [and_comm, or_comm, eq_comm, adj_comm],
loopless := Ξ» x, by simp }
infix ` β‘ `:70 := box_prod
@[simp] lemma box_prod_adj :
(G β‘ H).adj x y β G.adj x.1 y.1 β§ x.2 = y.2 β¨ H.adj x.2 y.2 β§ x.1 = y.1 := iff.rfl
@[simp] lemma box_prod_adj_left : (G β‘ H).adj (aβ, b) (aβ, b) β G.adj aβ aβ :=
by rw [box_prod_adj, and_iff_left rfl, or_iff_left (Ξ» h : H.adj b b β§ _, h.1.ne rfl)]
@[simp] lemma box_prod_adj_right : (G β‘ H).adj (a, bβ) (a, bβ) β H.adj bβ bβ :=
by rw [box_prod_adj, and_iff_left rfl, or_iff_right (Ξ» h : G.adj a a β§ _, h.1.ne rfl)]
lemma box_prod_neighbor_set (x : Ξ± Γ Ξ²) :
(G β‘ H).neighbor_set x = ((G.neighbor_set x.1) ΓΛ’ {x.2}) βͺ ({x.1} ΓΛ’ (H.neighbor_set x.2)) :=
begin
ext β¨a',b'β©,
simp only [mem_neighbor_set, set.mem_union, box_prod_adj, set.mem_prod, set.mem_singleton_iff],
simp only [eq_comm, and_comm],
end
variables (G H I)
/-- The box product is commutative up to isomorphism. `equiv.prod_comm` as a graph isomorphism. -/
@[simps] def box_prod_comm : G β‘ H βg H β‘ G := β¨equiv.prod_comm _ _, Ξ» x y, or_comm _ _β©
/-- The box product is associative up to isomorphism. `equiv.prod_assoc` as a graph isomorphism. -/
@[simps] def box_prod_assoc : (G β‘ H) β‘ I βg G β‘ (H β‘ I) :=
β¨equiv.prod_assoc _ _ _, Ξ» x y, by simp only [box_prod_adj, equiv.prod_assoc_apply,
or_and_distrib_right, or_assoc, prod.ext_iff, and_assoc, @and.comm (x.1.1 = _)]β©
/-- The embedding of `G` into `G β‘ H` given by `b`. -/
@[simps] def box_prod_left (b : Ξ²) : G βͺg G β‘ H :=
{ to_fun := Ξ» a, (a , b),
inj' := Ξ» aβ aβ, congr_arg prod.fst,
map_rel_iff' := Ξ» aβ aβ, box_prod_adj_left }
/-- The embedding of `H` into `G β‘ H` given by `a`. -/
@[simps] def box_prod_right (a : Ξ±) : H βͺg G β‘ H :=
{ to_fun := prod.mk a,
inj' := Ξ» bβ bβ, congr_arg prod.snd,
map_rel_iff' := Ξ» bβ bβ, box_prod_adj_right }
namespace walk
variables {G}
/-- Turn a walk on `G` into a walk on `G β‘ H`. -/
protected def box_prod_left (b : Ξ²) : G.walk aβ aβ β (G β‘ H).walk (aβ, b) (aβ, b) :=
walk.map (G.box_prod_left H b).to_hom
variables (G) {H}
/-- Turn a walk on `H` into a walk on `G β‘ H`. -/
protected def box_prod_right (a : Ξ±) : H.walk bβ bβ β (G β‘ H).walk (a, bβ) (a, bβ) :=
walk.map (G.box_prod_right H a).to_hom
variables {G}
/-- Project a walk on `G β‘ H` to a walk on `G` by discarding the moves in the direction of `H`. -/
def of_box_prod_left [decidable_eq Ξ²] [decidable_rel G.adj] :
Ξ {x y : Ξ± Γ Ξ²}, (G β‘ H).walk x y β G.walk x.1 y.1
| _ _ nil := nil
| x z (cons h w) := or.by_cases h (Ξ» hG, w.of_box_prod_left.cons hG.1)
(Ξ» hH, show G.walk x.1 z.1, by rw hH.2; exact w.of_box_prod_left)
/-- Project a walk on `G β‘ H` to a walk on `H` by discarding the moves in the direction of `G`. -/
def of_box_prod_right [decidable_eq Ξ±] [decidable_rel H.adj] :
Ξ {x y : Ξ± Γ Ξ²}, (G β‘ H).walk x y β H.walk x.2 y.2
| _ _ nil := nil
| x z (cons h w) := (or.symm h).by_cases (Ξ» hH, w.of_box_prod_right.cons hH.1)
(Ξ» hG, show H.walk x.2 z.2, by rw hG.2; exact w.of_box_prod_right)
@[simp] lemma of_box_prod_left_box_prod_left [decidable_eq Ξ²] [decidable_rel G.adj] :
β {aβ aβ : Ξ±} (w : G.walk aβ aβ), (w.box_prod_left H b).of_box_prod_left = w
| _ _ nil := rfl
| _ _ (cons' x y z h w) := begin
rw [walk.box_prod_left, map_cons, of_box_prod_left, or.by_cases, dif_pos, βwalk.box_prod_left,
of_box_prod_left_box_prod_left],
exacts [rfl, β¨h, rflβ©],
end
@[simp]
end walk
variables {G H}
protected lemma preconnected.box_prod (hG : G.preconnected) (hH : H.preconnected) :
(G β‘ H).preconnected :=
begin
rintro x y,
obtain β¨wββ© := hG x.1 y.1,
obtain β¨wββ© := hH x.2 y.2,
rw [β@prod.mk.eta _ _ x, β@prod.mk.eta _ _ y],
exact β¨(wβ.box_prod_left _ _).append (wβ.box_prod_right _ _)β©,
end
protected lemma preconnected.of_box_prod_left [nonempty Ξ²] (h : (G β‘ H).preconnected) :
G.preconnected :=
begin
classical,
rintro aβ aβ,
obtain β¨wβ© := h (aβ, classical.arbitrary _) (aβ, classical.arbitrary _),
exact β¨w.of_box_prod_leftβ©,
end
protected lemma preconnected.of_box_prod_right [nonempty Ξ±] (h : (G β‘ H).preconnected) :
H.preconnected :=
begin
classical,
rintro bβ bβ,
obtain β¨wβ© := h (classical.arbitrary _, bβ) (classical.arbitrary _, bβ),
exact β¨w.of_box_prod_rightβ©,
end
protected lemma connected.box_prod (hG : G.connected) (hH : H.connected) : (G β‘ H).connected :=
by { haveI := hG.nonempty, haveI := hH.nonempty, exact β¨hG.preconnected.box_prod hH.preconnectedβ© }
protected lemma connected.of_box_prod_left (h : (G β‘ H).connected) : G.connected :=
by { haveI := (nonempty_prod.1 h.nonempty).1, haveI := (nonempty_prod.1 h.nonempty).2,
exact β¨h.preconnected.of_box_prod_leftβ© }
protected lemma connected.of_box_prod_right (h : (G β‘ H).connected) : H.connected :=
by { haveI := (nonempty_prod.1 h.nonempty).1, haveI := (nonempty_prod.1 h.nonempty).2,
exact β¨h.preconnected.of_box_prod_rightβ© }
@[simp] lemma box_prod_connected : (G β‘ H).connected β G.connected β§ H.connected :=
β¨Ξ» h, β¨h.of_box_prod_left, h.of_box_prod_rightβ©, Ξ» h, h.1.box_prod h.2β©
instance box_prod_fintype_neighbor_set (x : Ξ± Γ Ξ²)
[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)] :
fintype ((G β‘ H).neighbor_set x) :=
fintype.of_equiv
((G.neighbor_finset x.1 ΓΛ’ {x.2}).disj_union ({x.1} ΓΛ’ H.neighbor_finset x.2)
$ finset.disjoint_product.mpr $ or.inl $ neighbor_finset_disjoint_singleton _ _)
((equiv.refl _).subtype_equiv $ Ξ» y, begin
simp_rw [finset.mem_disj_union, finset.mem_product, finset.mem_singleton,
mem_neighbor_finset, mem_neighbor_set, equiv.refl_apply, box_prod_adj],
simp only [eq_comm, and_comm],
end)
lemma box_prod_neighbor_finset (x : Ξ± Γ Ξ²)
[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)] [fintype ((G β‘ H).neighbor_set x)] :
(G β‘ H).neighbor_finset x =
(G.neighbor_finset x.1 ΓΛ’ {x.2}).disj_union ({x.1} ΓΛ’ H.neighbor_finset x.2)
(finset.disjoint_product.mpr $ or.inl $ neighbor_finset_disjoint_singleton _ _) :=
begin
-- swap out the fintype instance for the canonical one
letI : fintype ((G β‘ H).neighbor_set x) := simple_graph.box_prod_fintype_neighbor_set _,
refine eq.trans _ finset.attach_map_val,
convert (finset.map_map _ (function.embedding.subtype _) finset.univ),
end
lemma box_prod_degree (x : Ξ± Γ Ξ²)
[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)] [fintype ((G β‘ H).neighbor_set x)] :
(G β‘ H).degree x = G.degree x.1 + H.degree x.2 :=
begin
rw [degree, degree, degree, box_prod_neighbor_finset, finset.card_disj_union],
simp_rw [finset.card_product, finset.card_singleton, mul_one, one_mul],
end
end simple_graph
|
[STATEMENT]
lemma word_and_le_plus_one:
"a > 0 \<Longrightarrow> (x :: 'a :: len word) AND (a - 1) < a"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. 0 < a \<Longrightarrow> x AND a - 1 < a
[PROOF STEP]
by (simp add: gt0_iff_gem1 word_and_less') |
(* generated by Ott 0.31, locally-nameless lngen from: ../spec/rules.ott ../spec/reduction.ott *)
Require Import Metalib.Metatheory.
(** syntax *)
Definition typevar : Set := var.
Definition termvar : Set := var.
Definition label : Set := nat.
Definition int : Set := nat.
Inductive typ : Set := (*r types *)
| t_tvar_b (_:nat) (*r type variable *)
| t_tvar_f (X:typevar) (*r type variable *)
| t_int : typ (*r int *)
| t_top : typ (*r top type *)
| t_bot : typ (*r bottom type *)
| t_forall (A:typ) (B:typ) (*r universal type *)
| t_arrow (A:typ) (B:typ) (*r function type *)
| t_and (A:typ) (B:typ) (*r intersection *)
| t_rcd (l:label) (A:typ) (*r record *).
Inductive exp : Set := (*r expressions *)
| e_var_b (_:nat) (*r variable *)
| e_var_f (x:termvar) (*r variable *)
| e_top : exp (*r top *)
| e_lit (i:int) (*r lit *)
| e_abs (A:typ) (e:exp) (*r abstraction with argument annotation *)
| e_fixpoint (A:typ) (e:exp) (*r fixpoint *)
| e_app (e1:exp) (e2:exp) (*r applications *)
| e_merge (e1:exp) (e2:exp) (*r merge *)
| e_anno (e:exp) (A:typ) (*r annotation *)
| e_rcd (l:label) (e:exp) (*r record *)
| e_proj (e:exp) (l:label) (*r projection *)
| e_tabs (e:exp) (*r type abstractions *)
| e_tapp (e:exp) (A:typ) (*r type applications *).
Definition tctx : Set := list ( atom * typ ).
Inductive dirflag : Set := (*r checking direction *)
| Inf : dirflag
| Chk : dirflag.
Inductive arg : Set := (*r arguments (expression or projection label or type) *)
| arg_exp (v:exp)
| arg_la (l:label)
| arg_typ (A:typ).
Definition ctx : Set := list ( atom * typ ).
Inductive inla : Set := (*r index or label *)
| inla_arrow : inla
| inla_forall : inla
| inla_label (l:label).
(* EXPERIMENTAL *)
(** auxiliary functions on the new list types *)
(** library functions *)
(** subrules *)
(** arities *)
(** opening up abstractions *)
Fixpoint open_typ_wrt_typ_rec (k:nat) (A5:typ) (A_6:typ) {struct A_6}: typ :=
match A_6 with
| (t_tvar_b nat) =>
match lt_eq_lt_dec nat k with
| inleft (left _) => t_tvar_b nat
| inleft (right _) => A5
| inright _ => t_tvar_b (nat - 1)
end
| (t_tvar_f X) => t_tvar_f X
| t_int => t_int
| t_top => t_top
| t_bot => t_bot
| (t_forall A B) => t_forall (open_typ_wrt_typ_rec k A5 A) (open_typ_wrt_typ_rec (S k) A5 B)
| (t_arrow A B) => t_arrow (open_typ_wrt_typ_rec k A5 A) (open_typ_wrt_typ_rec k A5 B)
| (t_and A B) => t_and (open_typ_wrt_typ_rec k A5 A) (open_typ_wrt_typ_rec k A5 B)
| (t_rcd l A) => t_rcd l (open_typ_wrt_typ_rec k A5 A)
end.
Fixpoint open_exp_wrt_typ_rec (k:nat) (A5:typ) (e_5:exp) {struct e_5}: exp :=
match e_5 with
| (e_var_b nat) => e_var_b nat
| (e_var_f x) => e_var_f x
| e_top => e_top
| (e_lit i) => e_lit i
| (e_abs A e) => e_abs (open_typ_wrt_typ_rec k A5 A) (open_exp_wrt_typ_rec k A5 e)
| (e_fixpoint A e) => e_fixpoint (open_typ_wrt_typ_rec k A5 A) (open_exp_wrt_typ_rec k A5 e)
| (e_app e1 e2) => e_app (open_exp_wrt_typ_rec k A5 e1) (open_exp_wrt_typ_rec k A5 e2)
| (e_merge e1 e2) => e_merge (open_exp_wrt_typ_rec k A5 e1) (open_exp_wrt_typ_rec k A5 e2)
| (e_anno e A) => e_anno (open_exp_wrt_typ_rec k A5 e) (open_typ_wrt_typ_rec k A5 A)
| (e_rcd l e) => e_rcd l (open_exp_wrt_typ_rec k A5 e)
| (e_proj e l) => e_proj (open_exp_wrt_typ_rec k A5 e) l
| (e_tabs e) => e_tabs (open_exp_wrt_typ_rec (S k) A5 e)
| (e_tapp e A) => e_tapp (open_exp_wrt_typ_rec k A5 e) (open_typ_wrt_typ_rec k A5 A)
end.
Fixpoint open_exp_wrt_exp_rec (k:nat) (e_5:exp) (e__6:exp) {struct e__6}: exp :=
match e__6 with
| (e_var_b nat) =>
match lt_eq_lt_dec nat k with
| inleft (left _) => e_var_b nat
| inleft (right _) => e_5
| inright _ => e_var_b (nat - 1)
end
| (e_var_f x) => e_var_f x
| e_top => e_top
| (e_lit i) => e_lit i
| (e_abs A e) => e_abs A (open_exp_wrt_exp_rec (S k) e_5 e)
| (e_fixpoint A e) => e_fixpoint A (open_exp_wrt_exp_rec (S k) e_5 e)
| (e_app e1 e2) => e_app (open_exp_wrt_exp_rec k e_5 e1) (open_exp_wrt_exp_rec k e_5 e2)
| (e_merge e1 e2) => e_merge (open_exp_wrt_exp_rec k e_5 e1) (open_exp_wrt_exp_rec k e_5 e2)
| (e_anno e A) => e_anno (open_exp_wrt_exp_rec k e_5 e) A
| (e_rcd l e) => e_rcd l (open_exp_wrt_exp_rec k e_5 e)
| (e_proj e l) => e_proj (open_exp_wrt_exp_rec k e_5 e) l
| (e_tabs e) => e_tabs (open_exp_wrt_exp_rec k e_5 e)
| (e_tapp e A) => e_tapp (open_exp_wrt_exp_rec k e_5 e) A
end.
Definition open_arg_wrt_typ_rec (k:nat) (A5:typ) (arg5:arg) : arg :=
match arg5 with
| (arg_exp v) => arg_exp (open_exp_wrt_typ_rec k A5 v)
| (arg_la l) => arg_la l
| (arg_typ A) => arg_typ (open_typ_wrt_typ_rec k A5 A)
end.
Definition open_arg_wrt_exp_rec (k:nat) (e5:exp) (arg5:arg) : arg :=
match arg5 with
| (arg_exp v) => arg_exp (open_exp_wrt_exp_rec k e5 v)
| (arg_la l) => arg_la l
| (arg_typ A) => arg_typ A
end.
Definition open_arg_wrt_typ A5 arg5 := open_arg_wrt_typ_rec 0 arg5 A5.
Definition open_exp_wrt_exp e_5 e__6 := open_exp_wrt_exp_rec 0 e__6 e_5.
Definition open_arg_wrt_exp e5 arg5 := open_arg_wrt_exp_rec 0 arg5 e5.
Definition open_exp_wrt_typ A5 e_5 := open_exp_wrt_typ_rec 0 e_5 A5.
Definition open_typ_wrt_typ A5 A_6 := open_typ_wrt_typ_rec 0 A_6 A5.
(** terms are locally-closed pre-terms *)
(** definitions *)
(* defns LC_typ *)
Inductive lc_typ : typ -> Prop := (* defn lc_typ *)
| lc_t_tvar_f : forall (X:typevar),
(lc_typ (t_tvar_f X))
| lc_t_int :
(lc_typ t_int)
| lc_t_top :
(lc_typ t_top)
| lc_t_bot :
(lc_typ t_bot)
| lc_t_forall : forall (A B:typ),
(lc_typ A) ->
( forall X , lc_typ ( open_typ_wrt_typ B (t_tvar_f X) ) ) ->
(lc_typ (t_forall A B))
| lc_t_arrow : forall (A B:typ),
(lc_typ A) ->
(lc_typ B) ->
(lc_typ (t_arrow A B))
| lc_t_and : forall (A B:typ),
(lc_typ A) ->
(lc_typ B) ->
(lc_typ (t_and A B))
| lc_t_rcd : forall (l:label) (A:typ),
(lc_typ A) ->
(lc_typ (t_rcd l A)).
(* defns LC_exp *)
Inductive lc_exp : exp -> Prop := (* defn lc_exp *)
| lc_e_var_f : forall (x:termvar),
(lc_exp (e_var_f x))
| lc_e_top :
(lc_exp e_top)
| lc_e_lit : forall (i:int),
(lc_exp (e_lit i))
| lc_e_abs : forall (A:typ) (e:exp),
(lc_typ A) ->
( forall x , lc_exp ( open_exp_wrt_exp e (e_var_f x) ) ) ->
(lc_exp (e_abs A e))
| lc_e_fixpoint : forall (A:typ) (e:exp),
(lc_typ A) ->
( forall x , lc_exp ( open_exp_wrt_exp e (e_var_f x) ) ) ->
(lc_exp (e_fixpoint A e))
| lc_e_app : forall (e1 e2:exp),
(lc_exp e1) ->
(lc_exp e2) ->
(lc_exp (e_app e1 e2))
| lc_e_merge : forall (e1 e2:exp),
(lc_exp e1) ->
(lc_exp e2) ->
(lc_exp (e_merge e1 e2))
| lc_e_anno : forall (e:exp) (A:typ),
(lc_exp e) ->
(lc_typ A) ->
(lc_exp (e_anno e A))
| lc_e_rcd : forall (l:label) (e:exp),
(lc_exp e) ->
(lc_exp (e_rcd l e))
| lc_e_proj : forall (e:exp) (l:label),
(lc_exp e) ->
(lc_exp (e_proj e l))
| lc_e_tabs : forall (e:exp),
( forall X , lc_exp ( open_exp_wrt_typ e (t_tvar_f X) ) ) ->
(lc_exp (e_tabs e))
| lc_e_tapp : forall (e:exp) (A:typ),
(lc_exp e) ->
(lc_typ A) ->
(lc_exp (e_tapp e A)).
(* defns LC_arg *)
Inductive lc_arg : arg -> Prop := (* defn lc_arg *)
| lc_arg_exp : forall (v:exp),
(lc_exp v) ->
(lc_arg (arg_exp v))
| lc_arg_la : forall (l:label),
(lc_arg (arg_la l))
| lc_arg_typ : forall (A:typ),
(lc_typ A) ->
(lc_arg (arg_typ A)).
(** free variables *)
Fixpoint typefv_typ (A5:typ) : vars :=
match A5 with
| (t_tvar_b nat) => {}
| (t_tvar_f X) => {{X}}
| t_int => {}
| t_top => {}
| t_bot => {}
| (t_forall A B) => (typefv_typ A) \u (typefv_typ B)
| (t_arrow A B) => (typefv_typ A) \u (typefv_typ B)
| (t_and A B) => (typefv_typ A) \u (typefv_typ B)
| (t_rcd l A) => (typefv_typ A)
end.
Fixpoint termfv_exp (e_5:exp) : vars :=
match e_5 with
| (e_var_b nat) => {}
| (e_var_f x) => {{x}}
| e_top => {}
| (e_lit i) => {}
| (e_abs A e) => (termfv_exp e)
| (e_fixpoint A e) => (termfv_exp e)
| (e_app e1 e2) => (termfv_exp e1) \u (termfv_exp e2)
| (e_merge e1 e2) => (termfv_exp e1) \u (termfv_exp e2)
| (e_anno e A) => (termfv_exp e)
| (e_rcd l e) => (termfv_exp e)
| (e_proj e l) => (termfv_exp e)
| (e_tabs e) => (termfv_exp e)
| (e_tapp e A) => (termfv_exp e)
end.
Fixpoint typefv_exp (e_5:exp) : vars :=
match e_5 with
| (e_var_b nat) => {}
| (e_var_f x) => {}
| e_top => {}
| (e_lit i) => {}
| (e_abs A e) => (typefv_typ A) \u (typefv_exp e)
| (e_fixpoint A e) => (typefv_typ A) \u (typefv_exp e)
| (e_app e1 e2) => (typefv_exp e1) \u (typefv_exp e2)
| (e_merge e1 e2) => (typefv_exp e1) \u (typefv_exp e2)
| (e_anno e A) => (typefv_exp e) \u (typefv_typ A)
| (e_rcd l e) => (typefv_exp e)
| (e_proj e l) => (typefv_exp e)
| (e_tabs e) => (typefv_exp e)
| (e_tapp e A) => (typefv_exp e) \u (typefv_typ A)
end.
Definition termfv_arg (arg5:arg) : vars :=
match arg5 with
| (arg_exp v) => (termfv_exp v)
| (arg_la l) => {}
| (arg_typ A) => {}
end.
Definition typefv_arg (arg5:arg) : vars :=
match arg5 with
| (arg_exp v) => (typefv_exp v)
| (arg_la l) => {}
| (arg_typ A) => (typefv_typ A)
end.
(** substitutions *)
Fixpoint typsubst_typ (A5:typ) (X5:typevar) (A_6:typ) {struct A_6} : typ :=
match A_6 with
| (t_tvar_b nat) => t_tvar_b nat
| (t_tvar_f X) => (if eq_var X X5 then A5 else (t_tvar_f X))
| t_int => t_int
| t_top => t_top
| t_bot => t_bot
| (t_forall A B) => t_forall (typsubst_typ A5 X5 A) (typsubst_typ A5 X5 B)
| (t_arrow A B) => t_arrow (typsubst_typ A5 X5 A) (typsubst_typ A5 X5 B)
| (t_and A B) => t_and (typsubst_typ A5 X5 A) (typsubst_typ A5 X5 B)
| (t_rcd l A) => t_rcd l (typsubst_typ A5 X5 A)
end.
Fixpoint typsubst_exp (A5:typ) (X5:typevar) (e_5:exp) {struct e_5} : exp :=
match e_5 with
| (e_var_b nat) => e_var_b nat
| (e_var_f x) => e_var_f x
| e_top => e_top
| (e_lit i) => e_lit i
| (e_abs A e) => e_abs (typsubst_typ A5 X5 A) (typsubst_exp A5 X5 e)
| (e_fixpoint A e) => e_fixpoint (typsubst_typ A5 X5 A) (typsubst_exp A5 X5 e)
| (e_app e1 e2) => e_app (typsubst_exp A5 X5 e1) (typsubst_exp A5 X5 e2)
| (e_merge e1 e2) => e_merge (typsubst_exp A5 X5 e1) (typsubst_exp A5 X5 e2)
| (e_anno e A) => e_anno (typsubst_exp A5 X5 e) (typsubst_typ A5 X5 A)
| (e_rcd l e) => e_rcd l (typsubst_exp A5 X5 e)
| (e_proj e l) => e_proj (typsubst_exp A5 X5 e) l
| (e_tabs e) => e_tabs (typsubst_exp A5 X5 e)
| (e_tapp e A) => e_tapp (typsubst_exp A5 X5 e) (typsubst_typ A5 X5 A)
end.
Fixpoint subst_exp (e_5:exp) (x5:termvar) (e__6:exp) {struct e__6} : exp :=
match e__6 with
| (e_var_b nat) => e_var_b nat
| (e_var_f x) => (if eq_var x x5 then e_5 else (e_var_f x))
| e_top => e_top
| (e_lit i) => e_lit i
| (e_abs A e) => e_abs A (subst_exp e_5 x5 e)
| (e_fixpoint A e) => e_fixpoint A (subst_exp e_5 x5 e)
| (e_app e1 e2) => e_app (subst_exp e_5 x5 e1) (subst_exp e_5 x5 e2)
| (e_merge e1 e2) => e_merge (subst_exp e_5 x5 e1) (subst_exp e_5 x5 e2)
| (e_anno e A) => e_anno (subst_exp e_5 x5 e) A
| (e_rcd l e) => e_rcd l (subst_exp e_5 x5 e)
| (e_proj e l) => e_proj (subst_exp e_5 x5 e) l
| (e_tabs e) => e_tabs (subst_exp e_5 x5 e)
| (e_tapp e A) => e_tapp (subst_exp e_5 x5 e) A
end.
Definition typsubst_arg (A5:typ) (X5:typevar) (arg5:arg) : arg :=
match arg5 with
| (arg_exp v) => arg_exp (typsubst_exp A5 X5 v)
| (arg_la l) => arg_la l
| (arg_typ A) => arg_typ (typsubst_typ A5 X5 A)
end.
Definition subst_arg (e5:exp) (x5:termvar) (arg5:arg) : arg :=
match arg5 with
| (arg_exp v) => arg_exp (subst_exp e5 x5 v)
| (arg_la l) => arg_la l
| (arg_typ A) => arg_typ A
end.
(** definitions *)
(* defns TypeWellformedness *)
Inductive TWell : tctx -> typ -> Prop := (* defn TWell *)
| TW_top : forall (D:tctx),
TWell D t_top
| TW_bot : forall (D:tctx),
TWell D t_bot
| TW_int : forall (D:tctx),
TWell D t_int
| TW_var : forall (D:tctx) (X:typevar) (A:typ),
binds X A D ->
TWell D (t_tvar_f X)
| TW_rcd : forall (D:tctx) (l:label) (A:typ),
TWell D A ->
TWell D (t_rcd l A)
| TW_arrow : forall (D:tctx) (A B:typ),
TWell D A ->
TWell D B ->
TWell D (t_arrow A B)
| TW_and : forall (D:tctx) (A B:typ),
TWell D A ->
TWell D B ->
TWell D (t_and A B)
| TW_all : forall (L:vars) (D:tctx) (A B:typ),
TWell D A ->
( forall X , X \notin L -> TWell (cons ( X , A ) D ) ( open_typ_wrt_typ B (t_tvar_f X) ) ) ->
TWell D (t_forall A B).
(* defns TermContextWellformedness *)
Inductive CWell : tctx -> ctx -> Prop := (* defn CWell *)
| CW_empty : forall (D:tctx),
CWell D nil
| CW_cons : forall (D:tctx) (G:ctx) (x:termvar) (A:typ),
CWell D G ->
TWell D A ->
CWell D (cons ( x , A ) G ) .
(* defns TypeContextWellformedness *)
Inductive TCWell : tctx -> Prop := (* defn TCWell *)
| TCW_empty :
TCWell nil
| TCW_cons : forall (D:tctx) (X:typevar) (A:typ),
TCWell D ->
TWell D A ->
uniq (cons ( X , A ) D ) ->
TCWell (cons ( X , A ) D ) .
(* defns BotLikeType *)
Inductive botLike : typ -> Prop := (* defn botLike *)
| BL_bot :
botLike t_bot
| BL_andl : forall (A B:typ),
lc_typ B ->
botLike A ->
botLike (t_and A B)
| BL_andr : forall (A B:typ),
lc_typ A ->
botLike B ->
botLike (t_and A B).
(* defns TopLikeType *)
Inductive topLike : tctx -> typ -> Prop := (* defn topLike *)
| TL_top : forall (D:tctx),
TCWell D ->
topLike D t_top
| TL_and : forall (D:tctx) (A B:typ),
topLike D A ->
topLike D B ->
topLike D (t_and A B)
| TL_arrow : forall (D:tctx) (A B:typ),
TWell D A ->
topLike D B ->
topLike D (t_arrow A B)
| TL_rcd : forall (D:tctx) (l:label) (B:typ),
topLike D B ->
topLike D (t_rcd l B)
| TL_all : forall (L:vars) (D:tctx) (A B:typ),
( forall X , X \notin L -> topLike (cons ( X , A ) D ) ( open_typ_wrt_typ B (t_tvar_f X) ) ) ->
topLike D (t_forall A B)
| TL_var : forall (D:tctx) (X:typevar) (A:typ),
TCWell D ->
binds X A D ->
botLike A ->
topLike D (t_tvar_f X).
(* defns NotTopLikeType *)
Inductive notTopLike : tctx -> typ -> Prop := (* defn notTopLike *)
| NTL : forall (D:tctx) (A:typ),
TCWell D ->
TWell D A ->
not ( topLike D A ) ->
notTopLike D A.
(* defns OrdinaryType *)
Inductive ord : typ -> Prop := (* defn ord *)
| O_var : forall (X:typevar),
ord (t_tvar_f X)
| O_top :
ord t_top
| O_bot :
ord t_bot
| O_int :
ord t_int
| O_arrow : forall (A B:typ),
lc_typ A ->
ord B ->
ord (t_arrow A B)
| O_all : forall (L:vars) (A B:typ),
lc_typ A ->
( forall X , X \notin L -> ord ( open_typ_wrt_typ B (t_tvar_f X) ) ) ->
ord (t_forall A B)
| O_rcd : forall (l:label) (B:typ),
ord B ->
ord (t_rcd l B).
(* defns SplitType *)
Inductive spl : typ -> typ -> typ -> Prop := (* defn spl *)
| Sp_arrow : forall (A B C1 C2:typ),
lc_typ A ->
spl B C1 C2 ->
spl (t_arrow A B) (t_arrow A C1) (t_arrow A C2)
| Sp_all : forall (L:vars) (A B C1 C2:typ),
lc_typ A ->
( forall X , X \notin L -> spl ( open_typ_wrt_typ B (t_tvar_f X) ) ( open_typ_wrt_typ C1 (t_tvar_f X) ) ( open_typ_wrt_typ C2 (t_tvar_f X) ) ) ->
spl (t_forall A B) (t_forall A C1) (t_forall A C2)
| Sp_rcd : forall (l:label) (B C1 C2:typ),
spl B C1 C2 ->
spl (t_rcd l B) (t_rcd l C1) (t_rcd l C2)
| Sp_and : forall (A B:typ),
lc_typ A ->
lc_typ B ->
spl (t_and A B) A B.
(* defns DeclarativeSubtyping *)
Inductive sub : tctx -> typ -> typ -> Prop := (* defn sub *)
| DS_refl : forall (D:tctx) (A:typ),
TCWell D ->
TWell D A ->
sub D A A
| DS_trans : forall (D:tctx) (A C B:typ),
sub D A B ->
sub D B C ->
sub D A C
| DS_top : forall (D:tctx) (A:typ),
TCWell D ->
TWell D A ->
sub D A t_top
| DS_bot : forall (D:tctx) (A:typ),
TCWell D ->
TWell D A ->
sub D t_bot A
| DS_and : forall (D:tctx) (A B C:typ),
sub D A B ->
sub D A C ->
sub D A (t_and B C)
| DS_andl : forall (D:tctx) (A B:typ),
TCWell D ->
TWell D (t_and A B) ->
sub D (t_and A B) A
| DS_andr : forall (D:tctx) (A B:typ),
TCWell D ->
TWell D (t_and A B) ->
sub D (t_and A B) B
| DS_arr : forall (D:tctx) (A1 B1 A2 B2:typ),
sub D A2 A1 ->
sub D B1 B2 ->
sub D (t_arrow A1 B1) (t_arrow A2 B2)
| DS_distArrow : forall (D:tctx) (A B C:typ),
TCWell D ->
TWell D (t_arrow A (t_and B C)) ->
sub D (t_and (t_arrow A B) (t_arrow A C) ) (t_arrow A (t_and B C))
| DS_topArrow : forall (D:tctx),
TCWell D ->
sub D t_top (t_arrow t_top t_top)
| DS_rcd : forall (D:tctx) (l:label) (A B:typ),
sub D A B ->
sub D (t_rcd l A) (t_rcd l B)
| DS_distRcd : forall (D:tctx) (l:label) (A B:typ),
TCWell D ->
TWell D (t_rcd l (t_and A B)) ->
sub D (t_and (t_rcd l A) (t_rcd l B)) (t_rcd l (t_and A B))
| DS_topRcd : forall (D:tctx) (l:label),
TCWell D ->
sub D t_top (t_rcd l t_top)
| DS_all : forall (L:vars) (D:tctx) (A1 B1 A2 B2:typ),
sub D A2 A1 ->
( forall X , X \notin L -> sub (cons ( X , A2 ) D ) ( open_typ_wrt_typ B1 (t_tvar_f X) ) ( open_typ_wrt_typ B2 (t_tvar_f X) ) ) ->
sub D (t_forall A1 B1) (t_forall A2 B2)
| DS_distAll : forall (D:tctx) (A B1 B2:typ),
TCWell D ->
TWell D (t_forall A (t_and B1 B2) ) ->
sub D (t_and (t_forall A B1) (t_forall A B2) ) (t_forall A (t_and B1 B2) )
| DS_topAll : forall (D:tctx),
TCWell D ->
sub D t_top (t_forall t_top t_top)
| DS_topVar : forall (D:tctx) (X:typevar) (A:typ),
binds X A D ->
sub D A t_bot ->
sub D t_top (t_tvar_f X).
(* defns AlgorithmicSubtyping *)
Inductive algo_sub : tctx -> typ -> typ -> Prop := (* defn algo_sub *)
| S_var : forall (D:tctx) (X:typevar),
TCWell D ->
TWell D (t_tvar_f X) ->
algo_sub D (t_tvar_f X) (t_tvar_f X)
| S_int : forall (D:tctx),
TCWell D ->
algo_sub D t_int t_int
| S_top : forall (D:tctx) (A B:typ),
TWell D A ->
ord B ->
topLike D B ->
algo_sub D A B
| S_bot : forall (D:tctx) (A:typ),
TCWell D ->
TWell D A ->
ord A ->
algo_sub D t_bot A
| S_andl : forall (D:tctx) (A B C:typ),
TWell D B ->
ord C ->
algo_sub D A C ->
algo_sub D (t_and A B) C
| S_andr : forall (D:tctx) (A B C:typ),
TWell D A ->
ord C ->
algo_sub D B C ->
algo_sub D (t_and A B) C
| S_arrow : forall (D:tctx) (A1 B1 A2 B2:typ),
ord B2 ->
algo_sub D A2 A1 ->
algo_sub D B1 B2 ->
algo_sub D (t_arrow A1 B1) (t_arrow A2 B2)
| S_all : forall (L:vars) (D:tctx) (A1 A2 B1 B2:typ),
( forall X , X \notin L -> ord ( open_typ_wrt_typ B2 (t_tvar_f X) ) ) ->
algo_sub D B1 A1 ->
( forall X , X \notin L -> algo_sub (cons ( X , B1 ) D ) ( open_typ_wrt_typ A2 (t_tvar_f X) ) ( open_typ_wrt_typ B2 (t_tvar_f X) ) ) ->
algo_sub D (t_forall A1 A2) (t_forall B1 B2)
| S_rcd : forall (D:tctx) (l:label) (A B:typ),
ord B ->
algo_sub D A B ->
algo_sub D (t_rcd l A) (t_rcd l B)
| S_and : forall (D:tctx) (A B B1 B2:typ),
spl B B1 B2 ->
algo_sub D A B1 ->
algo_sub D A B2 ->
algo_sub D A B.
(* defns ModularSubtyping *)
Inductive msub : tctx -> typ -> typ -> Prop := (* defn msub *)
| MS_refl : forall (D:tctx) (A:typ),
TCWell D ->
TWell D A ->
msub D A A
| MS_top : forall (D:tctx) (A B:typ),
TWell D A ->
topLike D B ->
msub D A B
| MS_bot : forall (D:tctx) (A:typ),
TCWell D ->
TWell D A ->
msub D t_bot A
| MS_andl : forall (D:tctx) (A B C:typ),
TWell D B ->
msub D A C ->
msub D (t_and A B) C
| MS_andr : forall (D:tctx) (A B C:typ),
TWell D A ->
msub D B C ->
msub D (t_and A B) C
| MS_arrow : forall (D:tctx) (A1 B1 A2 B2:typ),
msub D A2 A1 ->
msub D B1 B2 ->
msub D (t_arrow A1 B1) (t_arrow A2 B2)
| MS_rcd : forall (D:tctx) (l:label) (A B:typ),
msub D A B ->
msub D (t_rcd l A) (t_rcd l B)
| MS_and : forall (D:tctx) (A B B1 B2:typ),
spl B B1 B2 ->
msub D A B1 ->
msub D A B2 ->
msub D A B
| MS_all : forall (L:vars) (D:tctx) (A1 A2 B1 B2:typ),
msub D B1 A1 ->
( forall X , X \notin L -> msub (cons ( X , B1 ) D ) ( open_typ_wrt_typ A2 (t_tvar_f X) ) ( open_typ_wrt_typ B2 (t_tvar_f X) ) ) ->
msub D (t_forall A1 A2) (t_forall B1 B2).
(* defns DisjointnessAxiom *)
Inductive disjoint_axiom : typ -> typ -> Prop := (* defn disjoint_axiom *)
| Dax_intArrow : forall (A1 A2:typ),
lc_typ A1 ->
lc_typ A2 ->
disjoint_axiom t_int (t_arrow A1 A2)
| Dax_intRcd : forall (l:label) (A:typ),
lc_typ A ->
disjoint_axiom t_int (t_rcd l A)
| Dax_intAll : forall (A B:typ),
lc_typ A ->
lc_typ (t_forall A B) ->
disjoint_axiom t_int (t_forall A B)
| Dax_arrowRcd : forall (A1 A2:typ) (l:label) (A:typ),
lc_typ A1 ->
lc_typ A2 ->
lc_typ A ->
disjoint_axiom (t_arrow A1 A2) (t_rcd l A)
| Dax_arrowAll : forall (A1 A2 A B:typ),
lc_typ A1 ->
lc_typ A2 ->
lc_typ A ->
lc_typ (t_forall A B) ->
disjoint_axiom (t_arrow A1 A2) (t_forall A B)
| Dax_rcdAll : forall (l:label) (C A B:typ),
lc_typ C ->
lc_typ A ->
lc_typ (t_forall A B) ->
disjoint_axiom (t_rcd l C) (t_forall A B)
| Dax_arrowInt : forall (A1 A2:typ),
lc_typ A1 ->
lc_typ A2 ->
disjoint_axiom (t_arrow A1 A2) t_int
| Dax_rcdInt : forall (l:label) (A:typ),
lc_typ A ->
disjoint_axiom (t_rcd l A) t_int
| Dax_allInt : forall (A B:typ),
lc_typ A ->
lc_typ (t_forall A B) ->
disjoint_axiom (t_forall A B) t_int
| Dax_rcdArrow : forall (l:label) (A A1 A2:typ),
lc_typ A ->
lc_typ A1 ->
lc_typ A2 ->
disjoint_axiom (t_rcd l A) (t_arrow A1 A2)
| Dax_allArrow : forall (A B A1 A2:typ),
lc_typ A ->
lc_typ (t_forall A B) ->
lc_typ A1 ->
lc_typ A2 ->
disjoint_axiom (t_forall A B) (t_arrow A1 A2)
| Dax_allRcd : forall (A B:typ) (l:label) (C:typ),
lc_typ A ->
lc_typ (t_forall A B) ->
lc_typ C ->
disjoint_axiom (t_forall A B) (t_rcd l C)
| Dax_rcdNeq : forall (l1:label) (A:typ) (l2:label) (B:typ),
lc_typ A ->
lc_typ B ->
l1 <> l2 ->
disjoint_axiom (t_rcd l1 A) (t_rcd l2 B).
(* defns TypeDisjointness *)
Inductive disjoint : tctx -> typ -> typ -> Prop := (* defn disjoint *)
| D_ax : forall (D:tctx) (A B:typ),
TCWell D ->
TWell D A ->
TWell D B ->
disjoint_axiom A B ->
disjoint D A B
| D_topl : forall (D:tctx) (A B:typ),
TWell D B ->
topLike D A ->
disjoint D A B
| D_topr : forall (D:tctx) (A B:typ),
TWell D A ->
topLike D B ->
disjoint D A B
| D_arrow : forall (D:tctx) (A1 A2 B1 B2:typ),
TWell D (t_arrow A1 A2) ->
TWell D (t_arrow B1 B2) ->
disjoint D A2 B2 ->
disjoint D (t_arrow A1 A2) (t_arrow B1 B2)
| D_rcdEq : forall (D:tctx) (l:label) (A B:typ),
disjoint D A B ->
disjoint D (t_rcd l A) (t_rcd l B)
| D_all : forall (L:vars) (D:tctx) (A1 B1 A2 B2:typ),
TWell D A1 ->
TWell D A2 ->
( forall X , X \notin L -> disjoint (cons ( X , (t_and A1 A2) ) D ) ( open_typ_wrt_typ B1 (t_tvar_f X) ) ( open_typ_wrt_typ B2 (t_tvar_f X) ) ) ->
disjoint D (t_forall A1 B1) (t_forall A2 B2)
| D_varl : forall (D:tctx) (X:typevar) (B A:typ),
binds X A D ->
algo_sub D A B ->
disjoint D (t_tvar_f X) B
| D_varr : forall (D:tctx) (B:typ) (X:typevar) (A:typ),
binds X A D ->
algo_sub D A B ->
disjoint D B (t_tvar_f X)
| D_andl : forall (D:tctx) (A B A1 A2:typ),
spl A A1 A2 ->
disjoint D A1 B ->
disjoint D A2 B ->
disjoint D A B
| D_andr : forall (D:tctx) (A B B1 B2:typ),
spl B B1 B2 ->
disjoint D A B1 ->
disjoint D A B2 ->
disjoint D A B.
(* defns IsomorphicSubtyping *)
Inductive subsub : typ -> typ -> Prop := (* defn subsub *)
| IS_refl : forall (A:typ),
lc_typ A ->
subsub A A
| IS_and : forall (A1 A2 B B1 B2:typ),
spl B B1 B2 ->
subsub A1 B1 ->
subsub A2 B2 ->
subsub (t_and A1 A2) B.
(* defns DuplicatedType *)
Inductive DuplicatedType : typ -> typ -> Prop := (* defn DuplicatedType *)
| DT_refl : forall (A:typ),
lc_typ A ->
DuplicatedType A A
| DT_copy : forall (A B C:typ),
DuplicatedType A C ->
DuplicatedType B C ->
DuplicatedType (t_and A B) C
| DT_and : forall (A' B' A B:typ),
DuplicatedType A' A ->
DuplicatedType B' B ->
DuplicatedType (t_and A' B') (t_and A B).
(* defns ApplicativeDistribution *)
Inductive appDist : typ -> typ -> Prop := (* defn appDist *)
| AD_andArrow : forall (A1 A2 B1 B2 C1 C2:typ),
appDist A1 (t_arrow B1 C1) ->
appDist A2 (t_arrow B2 C2) ->
appDist (t_and A1 A2) (t_arrow (t_and B1 B2) (t_and C1 C2))
| AD_andRcd : forall (A1 A2:typ) (l:label) (B1 B2:typ),
appDist A1 (t_rcd l B1) ->
appDist A2 (t_rcd l B2) ->
appDist (t_and A1 A2) (t_rcd l (t_and B1 B2))
| AD_andAll : forall (A1 A2 B1 B2 C1 C2:typ),
appDist A1 (t_forall B1 C1) ->
appDist A2 (t_forall B2 C2) ->
appDist (t_and A1 A2) (t_forall (t_and B1 B2) (t_and C1 C2) )
| AD_refl : forall (A:typ),
lc_typ A ->
appDist A A.
(* defns Values *)
Inductive value : exp -> Prop := (* defn value *)
| V_unit :
value e_top
| V_lit : forall (i:int),
value (e_lit i)
| V_abs : forall (A:typ) (e:exp) (B:typ),
lc_typ A ->
lc_exp (e_abs A e) ->
lc_typ B ->
value (e_anno ( (e_abs A e) ) B)
| V_bareAbs : forall (A:typ) (e:exp),
lc_typ A ->
lc_exp (e_abs A e) ->
value ( (e_abs A e) )
| V_tabs : forall (e:exp) (B:typ),
lc_exp (e_tabs e) ->
lc_typ B ->
value (e_anno ( (e_tabs e) ) B)
| V_bareTabs : forall (e:exp),
lc_exp (e_tabs e) ->
value ( (e_tabs e) )
| V_rcd : forall (l:label) (e:exp) (B:typ),
lc_exp e ->
lc_typ B ->
value (e_anno (e_rcd l e) B)
| V_bareRcd : forall (l:label) (e:exp),
lc_exp e ->
value (e_rcd l e)
| V_merge : forall (v1 v2:exp),
value v1 ->
value v2 ->
value (e_merge v1 v2).
(* defns Casting *)
Inductive casting : exp -> typ -> exp -> Prop := (* defn casting *)
| Cast_int : forall (i:int),
casting (e_lit i) t_int (e_lit i)
| Cast_top : forall (v:exp),
lc_exp v ->
casting v t_top e_top
| Cast_topArrow : forall (v:exp) (A1 A2:typ),
lc_exp v ->
ord (t_arrow A1 A2) ->
topLike nil (t_arrow A1 A2) ->
casting v (t_arrow A1 A2) (e_anno ( (e_abs t_top e_top) ) (t_arrow A1 A2))
| Cast_topAll : forall (v:exp) (A1 A2:typ),
lc_exp v ->
ord (t_forall A1 A2) ->
topLike nil (t_forall A1 A2) ->
casting v (t_forall A1 A2) (e_anno ( (e_tabs e_top) ) (t_forall A1 A2))
| Cast_topRcd : forall (v:exp) (l:label) (A:typ),
lc_exp v ->
ord (t_rcd l A) ->
topLike nil (t_rcd l A) ->
casting v (t_rcd l A) (e_anno (e_rcd l e_top) (t_rcd l A))
| Cast_anno : forall (e:exp) (A B:typ),
lc_exp e ->
ord B ->
notTopLike nil B ->
algo_sub nil A B ->
casting (e_anno e A) B (e_anno e B)
| Cast_mergel : forall (v1 v2:exp) (A:typ) (v1':exp),
lc_exp v2 ->
ord A ->
casting v1 A v1' ->
casting (e_merge v1 v2) A v1'
| Cast_merger : forall (v1 v2:exp) (A:typ) (v2':exp),
lc_exp v1 ->
ord A ->
casting v2 A v2' ->
casting (e_merge v1 v2) A v2'
| Cast_and : forall (v:exp) (A:typ) (v1 v2:exp) (B C:typ),
spl A B C ->
casting v B v1 ->
casting v C v2 ->
casting v A (e_merge v1 v2).
(* defns ExpressionWrapping *)
Inductive wrapping : exp -> typ -> exp -> Prop := (* defn wrapping *)
| EW_top : forall (e:exp),
lc_exp e ->
wrapping e t_top e_top
| EW_topArrow : forall (e:exp) (A1 A2:typ),
lc_exp e ->
ord (t_arrow A1 A2) ->
topLike nil (t_arrow A1 A2) ->
wrapping e (t_arrow A1 A2) (e_anno ( (e_abs t_top e_top) ) (t_arrow A1 A2))
| EW_topAll : forall (e:exp) (A1 A2:typ),
lc_exp e ->
ord (t_forall A1 A2) ->
topLike nil (t_forall A1 A2) ->
wrapping e (t_forall A1 A2) (e_anno ( (e_tabs e_top) ) (t_forall A1 A2))
| EW_topRcd : forall (e:exp) (l:label) (A:typ),
lc_exp e ->
ord (t_rcd l A) ->
topLike nil (t_rcd l A) ->
wrapping e (t_rcd l A) (e_anno (e_rcd l e_top) (t_rcd l A))
| EW_anno : forall (e:exp) (A:typ),
lc_exp e ->
ord A ->
notTopLike nil A ->
wrapping e A (e_anno e A)
| EW_and : forall (e:exp) (A:typ) (e1 e2:exp) (B C:typ),
spl A B C ->
wrapping e B e1 ->
wrapping e C e2 ->
wrapping e A (e_merge e1 e2).
(* defns ParallelApplication *)
Inductive papp : exp -> arg -> exp -> Prop := (* defn papp *)
| PApp_abs : forall (A:typ) (e1:exp) (B:typ) (e2 e2':exp) (C2 C1:typ),
lc_exp (e_abs A e1) ->
appDist B (t_arrow C1 C2) ->
wrapping e2 A e2' ->
papp (e_anno ( (e_abs A e1) ) B) (arg_exp e2) (e_anno ( (open_exp_wrt_exp e1 e2' ) ) C2)
| PApp_tabs : forall (e:exp) (A C B2 B1:typ),
lc_exp (e_tabs e) ->
lc_typ C ->
appDist A (t_forall B1 B2) ->
papp (e_anno ( (e_tabs e) ) A) (arg_typ C) (e_anno ( (open_exp_wrt_typ e C ) ) (open_typ_wrt_typ B2 C ) )
| PApp_proj : forall (l:label) (e:exp) (A B:typ),
lc_exp e ->
appDist A (t_rcd l B) ->
papp (e_anno (e_rcd l e) A) (arg_la l) (e_anno e B)
| PApp_merge : forall (v1 v2:exp) (arg5:arg) (e1 e2:exp),
papp v1 arg5 e1 ->
papp v2 arg5 e2 ->
papp (e_merge v1 v2) arg5 (e_merge e1 e2).
(* defns PreValues *)
Inductive prevalue : exp -> Prop := (* defn prevalue *)
| PV_int : forall (i:int),
prevalue (e_lit i)
| PV_top :
prevalue e_top
| PV_anno : forall (e:exp) (A:typ),
lc_exp e ->
lc_typ A ->
prevalue (e_anno e A)
| PV_merge : forall (u1 u2:exp),
prevalue u1 ->
prevalue u2 ->
prevalue (e_merge u1 u2).
(* defns PrincipalType *)
Inductive pType : exp -> typ -> Prop := (* defn pType *)
| PT_top :
pType e_top t_top
| PT_int : forall (i:int),
pType (e_lit i) t_int
| PT_anno : forall (e:exp) (A:typ),
lc_exp e ->
lc_typ A ->
pType ( (e_anno e A) ) A
| PT_merge : forall (u1 u2:exp) (A B:typ),
pType u1 A ->
pType u2 B ->
pType ( (e_merge u1 u2) ) (t_and A B) .
(* defns Consistent *)
Inductive consistent : exp -> exp -> Prop := (* defn consistent *)
| C_lit : forall (i:int),
consistent (e_lit i) (e_lit i)
| C_anno : forall (e:exp) (A B:typ),
lc_typ A ->
lc_exp e ->
lc_typ B ->
consistent (e_anno e A) (e_anno e B)
| C_disjoint : forall (u1 u2:exp) (A B:typ),
pType u1 A ->
pType u2 B ->
disjoint nil A B ->
prevalue u1 ->
prevalue u2 ->
consistent u1 u2
| C_mergel : forall (u1 u2 u:exp),
consistent u1 u ->
consistent u2 u ->
consistent (e_merge u1 u2) u
| C_merger : forall (u u1 u2:exp),
consistent u u1 ->
consistent u u2 ->
consistent u (e_merge u1 u2).
(* defns BidirectionalTyping *)
Inductive Typing : tctx -> ctx -> exp -> dirflag -> typ -> Prop := (* defn Typing *)
| Typ_top : forall (D:tctx) (G:ctx),
TCWell D ->
CWell D G ->
uniq G ->
Typing D G e_top Inf t_top
| Typ_lit : forall (D:tctx) (G:ctx) (i:int),
TCWell D ->
CWell D G ->
uniq G ->
Typing D G (e_lit i) Inf t_int
| Typ_var : forall (D:tctx) (G:ctx) (x:termvar) (A:typ),
TCWell D ->
CWell D G ->
binds x A G ->
uniq G ->
Typing D G (e_var_f x) Inf A
| Typ_abs : forall (L:vars) (D:tctx) (G:ctx) (A:typ) (e:exp) (B1 B2:typ),
algo_sub D B1 A ->
( forall x , x \notin L -> Typing D (cons ( x , A ) G ) ( open_exp_wrt_exp e (e_var_f x) ) Chk B2 ) ->
Typing D G (e_abs A e) Chk (t_arrow B1 B2)
| Typ_app : forall (D:tctx) (G:ctx) (e1 e2:exp) (C A B:typ),
Typing D G e1 Inf A ->
appDist A (t_arrow B C) ->
Typing D G e2 Chk B ->
Typing D G (e_app e1 e2) Inf C
| Typ_tabs : forall (L:vars) (D:tctx) (G:ctx) (e:exp) (A B:typ),
CWell D G ->
( forall X , X \notin L -> Typing (cons ( X , A ) D ) G ( open_exp_wrt_typ e (t_tvar_f X) ) Chk ( open_typ_wrt_typ B (t_tvar_f X) ) ) ->
Typing D G (e_tabs e) Chk (t_forall A B)
| Typ_tapp : forall (D:tctx) (G:ctx) (e:exp) (A C2 B C1:typ),
Typing D G e Inf B ->
appDist B (t_forall C1 C2) ->
disjoint D A C1 ->
Typing D G (e_tapp e A) Inf (open_typ_wrt_typ C2 A )
| Typ_proj : forall (D:tctx) (G:ctx) (e:exp) (l:label) (C A:typ),
Typing D G e Inf A ->
appDist A (t_rcd l C) ->
Typing D G (e_proj e l) Inf C
| Typ_rcd : forall (D:tctx) (G:ctx) (l:label) (e:exp) (A:typ),
Typing D G e Chk A ->
Typing D G (e_rcd l e) Chk (t_rcd l A)
| Typ_merge : forall (D:tctx) (G:ctx) (e1 e2:exp) (A B:typ),
Typing D G e1 Inf A ->
Typing D G e2 Inf B ->
disjoint D A B ->
Typing D G (e_merge e1 e2) Inf (t_and A B)
| Typ_inter : forall (D:tctx) (G:ctx) (e:exp) (A B:typ),
Typing D G e Chk A ->
Typing D G e Chk B ->
Typing D G e Chk (t_and A B)
| Typ_anno : forall (D:tctx) (G:ctx) (e:exp) (A:typ),
Typing D G e Chk A ->
Typing D G ( (e_anno e A) ) Inf A
| Typ_fix : forall (L:vars) (D:tctx) (G:ctx) (A:typ) (e:exp),
( forall x , x \notin L -> Typing D (cons ( x , A ) G ) ( open_exp_wrt_exp e (e_var_f x) ) Chk A ) ->
Typing D G (e_fixpoint A e) Inf A
| Typ_mergev : forall (D:tctx) (G:ctx) (u1 u2:exp) (A B:typ),
TCWell D ->
CWell D G ->
uniq G ->
Typing nil nil u1 Inf A ->
Typing nil nil u2 Inf B ->
consistent u1 u2 ->
Typing D G (e_merge u1 u2) Inf (t_and A B)
| Typ_sub : forall (D:tctx) (G:ctx) (e:exp) (B A:typ),
Typing D G e Inf A ->
algo_sub D A B ->
Typing D G e Chk B.
(* defns Reduction *)
Inductive step : exp -> exp -> Prop := (* defn step *)
| Step_papp : forall (v e e':exp),
value v ->
papp v (arg_exp e) e' ->
step (e_app v e) e'
| Step_pproj : forall (v:exp) (l:label) (e:exp),
value v ->
papp v (arg_la l) e ->
step (e_proj v l) e
| Step_ptapp : forall (v:exp) (A:typ) (e:exp),
value v ->
papp v (arg_typ A) e ->
step (e_tapp v A) e
| Step_annov : forall (v:exp) (A:typ) (v':exp),
value v ->
prevalue v ->
casting v A v' ->
step (e_anno v A) v'
| Step_appl : forall (e1 e2 e1':exp),
lc_exp e2 ->
step e1 e1' ->
step (e_app e1 e2) (e_app e1' e2)
| Step_merge : forall (e1 e2 e1' e2':exp),
step e1 e1' ->
step e2 e2' ->
step (e_merge e1 e2) (e_merge e1' e2')
| Step_mergel : forall (e1 v2 e1':exp),
value v2 ->
step e1 e1' ->
step (e_merge e1 v2) (e_merge e1' v2)
| Step_merger : forall (v1 e2 e2':exp),
value v1 ->
step e2 e2' ->
step (e_merge v1 e2) (e_merge v1 e2')
| Step_anno : forall (e:exp) (A:typ) (e':exp),
lc_typ A ->
step e e' ->
step (e_anno e A) (e_anno e' A)
| Step_fix : forall (A:typ) (e:exp),
lc_exp (e_fixpoint A e) ->
lc_typ A ->
step (e_fixpoint A e) (e_anno (open_exp_wrt_exp e (e_fixpoint A e) ) A)
| Step_proj : forall (e:exp) (l:label) (e':exp),
step e e' ->
step (e_proj e l) (e_proj e' l)
| Step_tapp : forall (e:exp) (A:typ) (e':exp),
lc_typ A ->
step e e' ->
step (e_tapp e A) (e_tapp e' A).
(** infrastructure *)
Hint Constructors TWell CWell TCWell botLike topLike notTopLike ord spl sub algo_sub msub disjoint_axiom disjoint subsub DuplicatedType appDist value casting wrapping papp prevalue pType consistent Typing step lc_typ lc_exp lc_arg : core.
|
/-
First steps towards proving the second isomorphism theorem for groups.
We relate the join of two subgroups with the closure of their pointwise product.
Author: AdriΓ‘n DoΓ±a Mateo
These were contributed to mathlib in
[#6165](https://github.com/leanprover-community/mathlib/pull/6165/).
An apostrophe was added at the end of the names to avoid clashes.
-/
import algebra.pointwise
import group_theory.subgroup
-- These lemmas were added to src/algebra/pointwise.lean.
namespace submonoid
variables {M : Type*} [monoid M]
@[to_additive]
lemma closure_mul_le' (S T : set M) : closure (S * T) β€ closure S β closure T :=
Inf_le $ Ξ» x β¨s, t, hs, ht, hxβ©, hx βΈ (closure S β closure T).mul_mem
(set_like.le_def.mp le_sup_left $ subset_closure hs)
(set_like.le_def.mp le_sup_right $ subset_closure ht)
@[to_additive]
lemma sup_eq_closure' (H K : submonoid M) : H β K = closure (H * K) :=
le_antisymm
(sup_le
(Ξ» h hh, subset_closure β¨h, 1, hh, K.one_mem, mul_one hβ©)
(Ξ» k hk, subset_closure β¨1, k, H.one_mem, hk, one_mul kβ©))
(by conv_rhs { rw [β closure_eq H, β closure_eq K] }; apply closure_mul_le)
end submonoid
-- These lemmas were added to src/group_theory/subgroup.lean.
section pointwise
namespace subgroup
variables {G : Type*} [group G]
@[to_additive]
lemma closure_mul_le' (S T : set G) : closure (S * T) β€ closure S β closure T :=
Inf_le $ Ξ» x β¨s, t, hs, ht, hxβ©, hx βΈ (closure S β closure T).mul_mem
(set_like.le_def.mp le_sup_left $ subset_closure hs)
(set_like.le_def.mp le_sup_right $ subset_closure ht)
@[to_additive]
lemma sup_eq_closure' (H K : subgroup G) : H β K = closure (H * K) :=
le_antisymm
(sup_le
(Ξ» h hh, subset_closure β¨h, 1, hh, K.one_mem, mul_one hβ©)
(Ξ» k hk, subset_closure β¨1, k, H.one_mem, hk, one_mul kβ©))
(by conv_rhs { rw [β closure_eq H, β closure_eq K] }; apply closure_mul_le)
@[to_additive]
private def mul_normal_aux (H N : subgroup G) [hN : N.normal] : subgroup G :=
{ carrier := (H : set G) * N,
one_mem' := β¨1, 1, H.one_mem, N.one_mem, by rw mul_oneβ©,
mul_mem' := Ξ» a b β¨h, n, hh, hn, haβ© β¨h', n', hh', hn', hbβ©,
β¨h * h', h'β»ΒΉ * n * h' * n',
H.mul_mem hh hh', N.mul_mem (by simpa using hN.conj_mem _ hn h'β»ΒΉ) hn',
by simp [β ha, β hb, mul_assoc]β©,
inv_mem' := Ξ» x β¨h, n, hh, hn, hxβ©,
β¨hβ»ΒΉ, h * nβ»ΒΉ * hβ»ΒΉ, H.inv_mem hh, hN.conj_mem _ (N.inv_mem hn) h,
by rw [mul_assoc h, inv_mul_cancel_left, β hx, mul_inv_rev]β© }
/-- The carrier of `H β N` is just `βH * βN` (pointwise set product) when `N` is normal. -/
@[to_additive "The carrier of `H β N` is just `βH + βN` (pointwise set addition)
when `N` is normal."]
lemma mul_normal' (H N : subgroup G) [N.normal] : (β(H β N) : set G) = H * N :=
set.subset.antisymm
(show H β N β€ mul_normal_aux H N,
by { rw sup_eq_closure, apply Inf_le _, dsimp, refl })
((sup_eq_closure H N).symm βΈ subset_closure)
@[to_additive]
private def normal_mul_aux (N H : subgroup G) [hN : N.normal] : subgroup G :=
{ carrier := (N : set G) * H,
one_mem' := β¨1, 1, N.one_mem, H.one_mem, by rw mul_oneβ©,
mul_mem' := Ξ» a b β¨n, h, hn, hh, haβ© β¨n', h', hn', hh', hbβ©,
β¨n * (h * n' * hβ»ΒΉ), h * h',
N.mul_mem hn (hN.conj_mem _ hn' _), H.mul_mem hh hh',
by simp [β ha, β hb, mul_assoc]β©,
inv_mem' := Ξ» x β¨n, h, hn, hh, hxβ©,
β¨hβ»ΒΉ * nβ»ΒΉ * h, hβ»ΒΉ,
by simpa using hN.conj_mem _ (N.inv_mem hn) hβ»ΒΉ, H.inv_mem hh,
by rw [mul_inv_cancel_right, β mul_inv_rev, hx]β© }
/-- The carrier of `N β H` is just `βN * βH` (pointwise set product) when `N` is normal. -/
@[to_additive "The carrier of `N β H` is just `βN + βH` (pointwise set addition)
when `N` is normal."]
lemma normal_mul' (N H : subgroup G) [N.normal] : (β(N β H) : set G) = N * H :=
set.subset.antisymm
(show N β H β€ normal_mul_aux N H,
by { rw sup_eq_closure, apply Inf_le _, dsimp, refl })
((sup_eq_closure N H).symm βΈ subset_closure)
end subgroup
end pointwise |
4 ) , which features both Sb ( III ) and Sb ( V ) . Unlike oxides of phosphorus and arsenic , these various oxides are amphoteric , do not form well @-@ defined <unk> and react with acids to form antimony salts .
|
If $f$ is analytic on $S$, then its derivative $f'$ is analytic on $S$. |
module Issue784.RefAPI where
open import Issue784.Values public hiding (seq)
open import Issue784.Context -- that should be private
open import Issue784.Transformer public
open import Data.List public using (List; []; _β·_; [_])
open import Data.Nat
open import Relation.Binary.PropositionalEquality.TrustMe
private
postulate
_seq_ : β {a b} {A : Set a} {B : Set b} β A β B β B
nativeRef : (A : Set) β Set
-- create new reference and initialize it with passed value
nativeNew-β : β β nativeRef β
-- increment value in place
nativeInc-β : nativeRef β β Unit
nativeGet-β : nativeRef β β β
nativeFree-β : nativeRef β β Unit
data Exact {β} {A : Set β} : A β Set β where
exact : β a β Exact a
getExact : β {β} {A : Set β} {a : A} β Exact a β A
getExact (exact a) = a
β‘-exact : β {β} {A : Set β} {a : A} (e : Exact a) β getExact e β‘ a
β‘-exact (exact a) = refl
Ref-β : β β Set
Ref-β a = Ξ£[ native β nativeRef β ] nativeGet-β native β‘ a
private
-- making these private to avoid further using
-- which may lead to inconsistency
proofNew-β : β a β Ref-β a
proofNew-β a = nativeNew-β a , trustMe
proofInc-β : β {a} β Ref-β a β Ref-β (suc a)
proofInc-β (r , _) = (nativeInc-β r) seq (r , trustMe)
proofGet-β : β {a} β Ref-β a β Exact a
proofGet-β (r , p) = β‘-elimβ² Exact p (exact $ nativeGet-β r)
proofFree-β : {a : β} β Ref-β a β Unit
proofFree-β (r , _) = nativeFree-β r
new-β : β a n β Transformer! [] [(n , Unique (Ref-β a))]
new-β a n ctx nr-v []βv nr-vβͺn = context w , (β‘ββ $ β‘-trans pβ pβ) where
v = Context.get ctx
w = v βͺ [(n , Unique (Ref-β a) , unique (proofNew-β a))]
pβ : types (v βͺ [(n , Unique (Ref-β a) , _)]) β‘ types v βͺ [(n , Unique (Ref-β a))]
pβ = t-xβͺy v [(n , Unique (Ref-β a) , _)]
pβ : types v βͺ [(n , Unique (Ref-β a))] β‘ types v ββ [] βͺ [(n , Unique (Ref-β a))]
pβ = β‘-cong (Ξ» x β x βͺ [(n , Unique (Ref-β a))]) (β‘-sym $ tβ[]β‘t $ types v)
inc-β : β {a} n β Transformer! [(n , Unique (Ref-β a))] [(n , Unique (Ref-β (suc a)))]
inc-β {a} n ctx nr-v nβv nr-vβͺn = context w , (β‘ββ $ β‘-trans pβ pβ) where
v = Context.get ctx
r = unique β proofInc-β β Unique.get β getBySignature β nβv $ here refl
w = v ββ [ n ] βͺ [(n , Unique (Ref-β $ suc a) , r)]
pβ : types (v ββ [ n ] βͺ [(n , Unique (Ref-β $ suc a) , r)]) β‘ types (v ββ [ n ]) βͺ [(n , Unique (Ref-β $ suc _))]
pβ = t-xβͺy (v ββ [ n ]) _
pβ : types (v ββ [ n ]) βͺ [(n , Unique (Ref-β $ suc a))] β‘ types v ββ [ n ] βͺ [(n , Unique (Ref-β $ suc _))]
pβ = β‘-cong (Ξ» x β x βͺ [(n , Unique (Ref-β $ suc a))]) (t-xβy v [ n ])
get-β : (r n : String) {rβ’!n : r s-β’! n} {a : β} β
Transformer ([(r , Unique (Ref-β a))] , nr-[a]) ((r , Unique (Ref-β a)) β· [(n , Pure (Exact a))] , (xβ’yβxβlβxβyβ·l (s-β’!ββ’? rβ’!n) Ξ»()) β· nr-[a])
get-β r n {a = a} ctx nr-v hβv _ = context w , β-trans pβ (β-trans pβ pβ) where
v = Context.get ctx
pr : Pure (Exact a)
pr = pure β proofGet-β β Unique.get β getBySignature β hβv $ here refl
w = v βͺ [(n , Pure (Exact a) , pr)]
pβ : types (v βͺ [(n , Pure (Exact a) , pr)]) β types v βͺ [(n , Pure (Exact a))]
pβ = β‘ββ $ t-xβͺy v [(n , Pure (Exact a) , pr)]
pβ : types v βͺ [(n , Pure (Exact a))] β (types v ββ [ r ] βͺ [(r , Unique (Ref-β _))]) βͺ [(n , Pure (Exact a))]
pβ = xβxΜβxβͺyβxΜβͺy (β-trans gβ gβ) [(n , Pure (Exact a))] where
gβ : types v β [(r , Unique (Ref-β _))] βͺ types v ββ [ r ]
gβ = tββtββtββtββͺtββntβ nr-[a] (nr-xβnr-t-x nr-v) hβv
gβ : [(r , Unique (Ref-β _))] βͺ types v ββ [ r ] β types v ββ [ r ] βͺ [(r , Unique (Ref-β _))]
gβ = βͺ-sym [(r , Unique (Ref-β _))] (types v ββ [ r ])
pβ : (types v ββ [ r ] βͺ [(r , Unique (Ref-β a))]) βͺ [(n , Pure (Exact a))] β types v ββ [ r ] βͺ ((r , Unique (Ref-β _)) β· [(n , Pure (Exact a))])
pβ = β‘ββ $ βͺ-assoc (types v ββ [ r ]) [(r , Unique (Ref-β _))] [(n , Pure (Exact a))]
free-β : (h : String) {a : β} β Transformer! [(h , Unique (Ref-β a))] []
free-β h ctx nr-v hβv _ = u seq (context w , β‘ββ p) where
v = Context.get ctx
u = proofFree-β β Unique.get β getBySignature β hβv $ here refl
w = v ββ [ h ]
p : types (v ββ [ h ]) β‘ types v ββ [ h ] βͺ []
p = β‘-trans (t-xβy v [ h ]) (β‘-sym $ xβͺ[]β‘x (types v ββ [ h ]))
|
/-
Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.metric_space.emetric_space
import Mathlib.PostPort
universes u_1 u_4 u_2
namespace Mathlib
/-!
# `GΞ΄` sets
In this file we define `GΞ΄` sets and prove their basic properties.
## Main definitions
* `is_GΞ΄`: a set `s` is a `GΞ΄` set if it can be represented as an intersection
of countably many open sets;
* `residual`: the filter of residual sets. A set `s` is called *residual* if it includes a dense
`GΞ΄` set. In a Baire space (e.g., in a complete (e)metric space), residual sets form a filter.
For technical reasons, we define `residual` in any topological space but the definition agrees
with the description above only in Baire spaces.
## Main results
We prove that finite or countable intersections of GΞ΄ sets is a GΞ΄ set. We also prove that the
continuity set of a function from a topological space to an (e)metric space is a GΞ΄ set.
## Tags
GΞ΄ set, residual set
-/
/-- A GΞ΄ set is a countable intersection of open sets. -/
def is_GΞ΄ {Ξ± : Type u_1} [topological_space Ξ±] (s : set Ξ±) :=
β (T : set (set Ξ±)), (β (t : set Ξ±), t β T β is_open t) β§ set.countable T β§ s = ββT
/-- An open set is a GΞ΄ set. -/
theorem is_open.is_GΞ΄ {Ξ± : Type u_1} [topological_space Ξ±] {s : set Ξ±} (h : is_open s) : is_GΞ΄ s :=
sorry
theorem is_GΞ΄_univ {Ξ± : Type u_1} [topological_space Ξ±] : is_GΞ΄ set.univ :=
is_open.is_GΞ΄ is_open_univ
theorem is_GΞ΄_bInter_of_open {Ξ± : Type u_1} {ΞΉ : Type u_4} [topological_space Ξ±] {I : set ΞΉ}
(hI : set.countable I) {f : ΞΉ β set Ξ±} (hf : β (i : ΞΉ), i β I β is_open (f i)) :
is_GΞ΄ (set.Inter fun (i : ΞΉ) => set.Inter fun (H : i β I) => f i) :=
sorry
theorem is_GΞ΄_Inter_of_open {Ξ± : Type u_1} {ΞΉ : Type u_4} [topological_space Ξ±] [encodable ΞΉ]
{f : ΞΉ β set Ξ±} (hf : β (i : ΞΉ), is_open (f i)) : is_GΞ΄ (set.Inter fun (i : ΞΉ) => f i) :=
sorry
/-- A countable intersection of GΞ΄ sets is a GΞ΄ set. -/
theorem is_GΞ΄_sInter {Ξ± : Type u_1} [topological_space Ξ±] {S : set (set Ξ±)}
(h : β (s : set Ξ±), s β S β is_GΞ΄ s) (hS : set.countable S) : is_GΞ΄ (ββS) :=
sorry
theorem is_GΞ΄_Inter {Ξ± : Type u_1} {ΞΉ : Type u_4} [topological_space Ξ±] [encodable ΞΉ]
{s : ΞΉ β set Ξ±} (hs : β (i : ΞΉ), is_GΞ΄ (s i)) : is_GΞ΄ (set.Inter fun (i : ΞΉ) => s i) :=
is_GΞ΄_sInter (iff.mpr set.forall_range_iff hs) (set.countable_range s)
theorem is_GΞ΄_bInter {Ξ± : Type u_1} {ΞΉ : Type u_4} [topological_space Ξ±] {s : set ΞΉ}
(hs : set.countable s) {t : (i : ΞΉ) β i β s β set Ξ±}
(ht : β (i : ΞΉ) (H : i β s), is_GΞ΄ (t i H)) :
is_GΞ΄ (set.Inter fun (i : ΞΉ) => set.Inter fun (H : i β s) => t i H) :=
sorry
theorem is_GΞ΄.inter {Ξ± : Type u_1} [topological_space Ξ±] {s : set Ξ±} {t : set Ξ±} (hs : is_GΞ΄ s)
(ht : is_GΞ΄ t) : is_GΞ΄ (s β© t) :=
eq.mpr (id (Eq._oldrec (Eq.refl (is_GΞ΄ (s β© t))) set.inter_eq_Inter))
(is_GΞ΄_Inter (iff.mpr bool.forall_bool { left := ht, right := hs }))
/-- The union of two GΞ΄ sets is a GΞ΄ set. -/
theorem is_GΞ΄.union {Ξ± : Type u_1} [topological_space Ξ±] {s : set Ξ±} {t : set Ξ±} (hs : is_GΞ΄ s)
(ht : is_GΞ΄ t) : is_GΞ΄ (s βͺ t) :=
sorry
theorem is_GΞ΄_set_of_continuous_at_of_countably_generated_uniformity {Ξ± : Type u_1} {Ξ² : Type u_2}
[topological_space Ξ±] [uniform_space Ξ²] (hU : filter.is_countably_generated (uniformity Ξ²))
(f : Ξ± β Ξ²) : is_GΞ΄ (set_of fun (x : Ξ±) => continuous_at f x) :=
sorry
/-- The set of points where a function is continuous is a GΞ΄ set. -/
theorem is_GΞ΄_set_of_continuous_at {Ξ± : Type u_1} {Ξ² : Type u_2} [topological_space Ξ±]
[emetric_space Ξ²] (f : Ξ± β Ξ²) : is_GΞ΄ (set_of fun (x : Ξ±) => continuous_at f x) :=
is_GΞ΄_set_of_continuous_at_of_countably_generated_uniformity
emetric.uniformity_has_countable_basis f
/-- A set `s` is called *residual* if it includes a dense `GΞ΄` set. If `Ξ±` is a Baire space
(e.g., a complete metric space), then residual sets form a filter, see `mem_residual`.
For technical reasons we define the filter `residual` in any topological space but in a non-Baire
space it is not useful because it may contain some non-residual sets. -/
def residual (Ξ± : Type u_1) [topological_space Ξ±] : filter Ξ± :=
infi fun (t : set Ξ±) => infi fun (ht : is_GΞ΄ t) => infi fun (ht' : dense t) => filter.principal t
end Mathlib |
function [mi3] = cc2mi3(cc)
% Convert volume from cubic centimeters to cubic miles.
% Chad Greene 2012
mi3 = cc*2.3991275858e-16; |
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Algebra (Ξ£ : Signature) where
open import Level using (Level; _β_; suc)
open import Data.Vec using (Vec)
open import Data.Vec.Relation.Binary.Pointwise.Inductive using (Pointwise)
open import Relation.Binary using (Setoid; Rel; IsEquivalence)
private
variable
a β : Level
module _ (S : Setoid a β) where
open import Data.Vec.Relation.Binary.Equality.Setoid S using (_β_)
open Setoid S renaming (Carrier to A)
Interpretation : Set a
Interpretation = β {arity} β (f : ops Ξ£ arity) β Vec A arity β A
Congruence : Interpretation β Set (a β β)
Congruence β¦_β§ = β {arity}
β (f : ops Ξ£ arity)
β β {xs ys} β Pointwise _β_ xs ys β β¦ f β§ xs β β¦ f β§ ys
record IsAlgebra : Set (a β β) where
field
β¦_β§ : Interpretation
β¦β§-cong : Congruence β¦_β§
record Algebra : Set (suc a β suc β) where
constructor algebra
field
β₯_β₯/β : Setoid a β
β₯_β₯/β-isAlgebra : IsAlgebra β₯_β₯/β
β₯_β₯ : Set a
β₯_β₯ = Setoid.Carrier β₯_β₯/β
infix 10 _β¦_β§_
_β¦_β§_ : Interpretation (β₯_β₯/β)
_β¦_β§_ = IsAlgebra.β¦_β§ β₯_β₯/β-isAlgebra
_β¦_β§-cong : Congruence (β₯_β₯/β) (_β¦_β§_)
_β¦_β§-cong = IsAlgebra.β¦β§-cong β₯_β₯/β-isAlgebra
β[_] : Rel β₯_β₯ β
β[_] = Setoid._β_ β₯_β₯/β
β[_]-isEquivalence : IsEquivalence β[_]
β[_]-isEquivalence = Setoid.isEquivalence β₯_β₯/β
open Algebra public
infix 5 β-syntax
β-syntax : (A : Algebra {a} {β}) β β₯ A β₯ β β₯ A β₯ β Set β
β-syntax A x y = Setoid._β_ β₯ A β₯/β x y
syntax β-syntax A x y = x =[ A ] y
|
/-
Copyright (c) 2022 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import algebra.big_operators.finsupp
import data.finset.pointwise
import data.finsupp.indicator
import data.fintype.big_operators
/-!
# Finitely supported product of finsets
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the finitely supported product of finsets as a `finset (ΞΉ ββ Ξ±)`.
## Main declarations
* `finset.finsupp`: Finitely supported product of finsets. `s.finset t` is the product of the `t i`
over all `i β s`.
* `finsupp.pi`: `f.pi` is the finset of `finsupp`s whose `i`-th value lies in `f i`. This is the
special case of `finset.finsupp` where we take the product of the `f i` over the support of `f`.
## Implementation notes
We make heavy use of the fact that `0 : finset Ξ±` is `{0}`. This scalar actions convention turns out
to be precisely what we want here too.
-/
noncomputable theory
open finsupp
open_locale big_operators classical pointwise
variables {ΞΉ Ξ± : Type*} [has_zero Ξ±] {s : finset ΞΉ} {f : ΞΉ ββ Ξ±}
namespace finset
/-- Finitely supported product of finsets. -/
protected def finsupp (s : finset ΞΉ) (t : ΞΉ β finset Ξ±) : finset (ΞΉ ββ Ξ±) :=
(s.pi t).map β¨indicator s, indicator_injective sβ©
lemma mem_finsupp_iff {t : ΞΉ β finset Ξ±} : f β s.finsupp t β f.support β s β§ β i β s, f i β t i :=
begin
refine mem_map.trans β¨_, _β©,
{ rintro β¨f, hf, rflβ©,
refine β¨support_indicator_subset _ _, Ξ» i hi, _β©,
convert mem_pi.1 hf i hi,
exact indicator_of_mem hi _ },
{ refine Ξ» h, β¨Ξ» i _, f i, mem_pi.2 h.2, _β©,
ext i,
exact ite_eq_left_iff.2 (Ξ» hi, (not_mem_support_iff.1 $ Ξ» H, hi $ h.1 H).symm) }
end
/-- When `t` is supported on `s`, `f β s.finsupp t` precisely means that `f` is pointwise in `t`. -/
@[simp] lemma mem_finsupp_iff_of_support_subset {t : ΞΉ ββ finset Ξ±} (ht : t.support β s) :
f β s.finsupp t β β i, f i β t i :=
begin
refine mem_finsupp_iff.trans (forall_and_distrib.symm.trans $ forall_congr $ Ξ» i, β¨Ξ» h, _,
Ξ» h, β¨Ξ» hi, ht $ mem_support_iff.2 $ Ξ» H, mem_support_iff.1 hi _, Ξ» _, hβ©β©),
{ by_cases hi : i β s,
{ exact h.2 hi },
{ rw [not_mem_support_iff.1 (mt h.1 hi), not_mem_support_iff.1 (Ξ» H, hi $ ht H)],
exact zero_mem_zero } },
{ rwa [H, mem_zero] at h }
end
@[simp] lemma card_finsupp (s : finset ΞΉ) (t : ΞΉ β finset Ξ±) :
(s.finsupp t).card = β i in s, (t i).card :=
(card_map _).trans $ card_pi _ _
end finset
open finset
namespace finsupp
/-- Given a finitely supported function `f : ΞΉ ββ finset Ξ±`, one can define the finset
`f.pi` of all finitely supported functions whose value at `i` is in `f i` for all `i`. -/
def pi (f : ΞΉ ββ finset Ξ±) : finset (ΞΉ ββ Ξ±) := f.support.finsupp f
@[simp] lemma mem_pi {f : ΞΉ ββ finset Ξ±} {g : ΞΉ ββ Ξ±} : g β f.pi β β i, g i β f i :=
mem_finsupp_iff_of_support_subset $ subset.refl _
@[simp] lemma card_pi (f : ΞΉ ββ finset Ξ±) : f.pi.card = f.prod (Ξ» i, (f i).card) :=
begin
rw [pi, card_finsupp],
exact finset.prod_congr rfl (Ξ» i _, by simp only [pi.nat_apply, nat.cast_id]),
end
end finsupp
|
module Inigo.Async.CloudFlare.KV
import Inigo.Async.Promise
import Inigo.Async.Util
%foreign (promisifyPrim "(ns,key)=>this[ns] ? this[ns].get(key).then((r) => r || '') : Promise.reject('Unknown KV namespace ' + ns)")
read__prim : String -> String -> promise String
%foreign (promisifyPrim "(ns,key,value)=>this[ns] ? this[ns].put(key,value) : Promise.reject('Unknown KV namespace ' + ns)")
write__prim : String -> String -> String -> promise ()
%foreign (promisifyPrim "(ns,key,value,expirationTtl)=>this[ns] ? this[ns].put(key,value,{expirationTtl: expirationTtl}) : Promise.reject('Unknown KV namespace ' + ns)")
writeTTL__prim : String -> String -> String -> Int -> promise ()
export
read: String -> String -> Promise String
read ns key =
promisify (read__prim ns key)
export
write: String -> String -> String -> Promise ()
write ns key value =
promisify (write__prim ns key value)
export
writeTTL: String -> String -> String -> Int -> Promise ()
writeTTL ns key value ttl =
promisify (writeTTL__prim ns key value ttl)
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Unary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Unary where
open import Data.Empty
open import Data.Unit.Base using (β€)
open import Data.Product
open import Data.Sum using (_β_; [_,_])
open import Function
open import Level
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality.Core using (_β‘_)
------------------------------------------------------------------------
-- Unary relations
Pred : β {a} β Set a β (β : Level) β Set (a β suc β)
Pred A β = A β Set β
------------------------------------------------------------------------
-- Unary relations can be seen as sets
-- i.e. they can be seen as subsets of the universe of discourse.
module _ {a} {A : Set a} where
----------------------------------------------------------------------
-- Special sets
-- The empty set
β
: Pred A zero
β
= Ξ» _ β β₯
-- The singleton set
ο½_ο½ : A β Pred A a
ο½ x ο½ = x β‘_
-- The universe
U : Pred A zero
U = Ξ» _ β β€
----------------------------------------------------------------------
-- Membership
infix 4 _β_ _β_
_β_ : β {β} β A β Pred A β β Set _
x β P = P x
_β_ : β {β} β A β Pred A β β Set _
x β P = Β¬ x β P
----------------------------------------------------------------------
-- Subsets
infix 4 _β_ _β_ _β_ _β_ _β_ _β_ _β_ _β
_
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β Q = β {x} β x β P β x β Q
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β Q = Q β P
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β Q = Β¬ (P β Q)
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β Q = Β¬ (P β Q)
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β Q = P β Q Γ Q β P
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β Q = Q β P
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β Q = Β¬ (P β Q)
_β
_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β
Q = Β¬ (P β Q)
-- Dashed variants of _β_ for when 'x' can't be inferred from 'x β P'.
infix 4 _ββ²_ _ββ²_ _ββ²_ _ββ²_ _ββ²_ _ββ²_ _ββ²_ _β
β²_
_ββ²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P ββ² Q = β x β x β P β x β Q
_ββ²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
Q ββ² P = P ββ² Q
_ββ²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P ββ² Q = Β¬ (P ββ² Q)
_ββ²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P ββ² Q = Β¬ (P ββ² Q)
_ββ²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P ββ² Q = P ββ² Q Γ Q ββ² P
_ββ²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P ββ² Q = Q ββ² P
_ββ²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P ββ² Q = Β¬ (P ββ² Q)
_β
β²_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β
β² Q = Β¬ (P ββ² Q)
----------------------------------------------------------------------
-- Properties of sets
-- Emptiness
Empty : β {β} β Pred A β β Set _
Empty P = β x β x β P
-- Satisfiable
Satisfiable : β {β} β Pred A β β Set _
Satisfiable P = β Ξ» x β x β P
-- Universality
infix 10 Universal IUniversal
Universal : β {β} β Pred A β β Set _
Universal P = β x β x β P
IUniversal : β {β} β Pred A β β Set _
IUniversal P = β {x} β x β P
syntax Universal P = Ξ [ P ]
syntax IUniversal P = β[ P ]
-- Decidability
Decidable : β {β} β Pred A β β Set _
Decidable P = β x β Dec (P x)
-- Irrelevance
Irrelevant : β {β} β Pred A β β Set _
Irrelevant P = β {x} (a : P x) (b : P x) β a β‘ b
----------------------------------------------------------------------
-- Operations on sets
-- Set complement.
β : β {β} β Pred A β β Pred A β
β P = Ξ» x β x β P
-- Positive version of non-disjointness, dual to inclusion.
infix 4 _β¬_
_β¬_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Set _
P β¬ Q = β Ξ» x β x β P Γ x β Q
-- Set union.
infixr 6 _βͺ_
_βͺ_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Pred A _
P βͺ Q = Ξ» x β x β P β x β Q
-- Set intersection.
infixr 7 _β©_
_β©_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Pred A _
P β© Q = Ξ» x β x β P Γ x β Q
-- Implication.
infixr 8 _β_
_β_ : β {ββ ββ} β Pred A ββ β Pred A ββ β Pred A _
P β Q = Ξ» x β x β P β x β Q
-- Infinitary union and intersection.
infix 10 β β
β : β {β i} (I : Set i) β (I β Pred A β) β Pred A _
β I P = Ξ» x β Ξ£[ i β I ] P i x
syntax β I (Ξ» i β P) = β[ i βΆ I ] P
β : β {β i} (I : Set i) β (I β Pred A β) β Pred A _
β I P = Ξ» x β (i : I) β P i x
syntax β I (Ξ» i β P) = β[ i βΆ I ] P
-- Update.
infixr 9 _β’_
_β’_ : β {a b} {A : Set a} {B : Set b} {β} β (A β B) β Pred B β β Pred A β
f β’ P = Ξ» x β P (f x)
------------------------------------------------------------------------
-- Unary relation combinators
infixr 2 _β¨Γβ©_
infixr 2 _β¨ββ©_
infixr 1 _β¨ββ©_
infixr 0 _β¨ββ©_
infixl 9 _β¨Β·β©_
infix 10 _~
infixr 9 _β¨ββ©_
infixr 2 _//_ _\\_
_β¨Γβ©_ : β {a b ββ ββ} {A : Set a} {B : Set b} β
Pred A ββ β Pred B ββ β Pred (A Γ B) _
(P β¨Γβ© Q) (x , y) = x β P Γ y β Q
_β¨ββ©_ : β {a b ββ ββ} {A : Set a} {B : Set b} β
Pred A ββ β Pred B ββ β Pred (A Γ B) _
(P β¨ββ© Q) (x , y) = x β P β y β Q
_β¨ββ©_ : β {a b β} {A : Set a} {B : Set b} β
Pred A β β Pred B β β Pred (A β B) _
P β¨ββ© Q = [ P , Q ]
_β¨ββ©_ : β {a b ββ ββ} {A : Set a} {B : Set b} β
Pred A ββ β Pred B ββ β Pred (A β B) _
(P β¨ββ© Q) f = P β Q β f
_β¨Β·β©_ : β {a b ββ ββ} {A : Set a} {B : Set b}
(P : Pred A ββ) (Q : Pred B ββ) β
(P β¨Γβ© (P β¨ββ© Q)) β Q β uncurry (flip _$_)
(P β¨Β·β© Q) (p , f) = f p
-- Converse.
_~ : β {a b β} {A : Set a} {B : Set b} β
Pred (A Γ B) β β Pred (B Γ A) β
P ~ = P β swap
-- Composition.
_β¨ββ©_ : β {a b c ββ ββ} {A : Set a} {B : Set b} {C : Set c} β
Pred (A Γ B) ββ β Pred (B Γ C) ββ β Pred (A Γ C) _
(P β¨ββ© Q) (x , z) = β Ξ» y β (x , y) β P Γ (y , z) β Q
-- Post and pre-division.
_//_ : β {a b c ββ ββ} {A : Set a} {B : Set b} {C : Set c} β
Pred (A Γ C) ββ β Pred (B Γ C) ββ β Pred (A Γ B) _
(P // Q) (x , y) = Q β _,_ y β P β _,_ x
_\\_ : β {a b c ββ ββ} {A : Set a} {B : Set b} {C : Set c} β
Pred (A Γ C) ββ β Pred (A Γ B) ββ β Pred (B Γ C) _
P \\ Q = (P ~ // Q ~) ~
|
Load LFindLoad.
From lfind Require Import LFind.
From QuickChick Require Import QuickChick.
From adtind Require Import goal33.
Derive Show for natural.
Derive Arbitrary for natural.
Instance Dec_Eq_natural : Dec_Eq natural.
Proof. dec_eq. Qed.
Lemma conj7synthconj4 : forall (lv0 : natural) (lv1 : natural) (lv2 : natural) (lv3 : natural), (@eq natural (plus lv0 Zero) (plus (plus (mult lv1 lv2) lv2) (mult lv3 lv2))).
Admitted.
QuickChick conj7synthconj4.
|
[STATEMENT]
lemma pconj_nneg[intro,simp]:
"0 \<le> a .& b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. 0 \<le> a .& b
[PROOF STEP]
unfolding pconj_def tminus_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. 0 \<le> max (a + b - 1) 0
[PROOF STEP]
by(auto) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.